Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/teraterm/ttpmacro/ttmdlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10617 - (show annotations) (download) (as text)
Fri Mar 3 15:15:04 2023 UTC (12 months ago) by zmatsuo
File MIME type: text/x-c++src
File size: 8127 byte(s)
lngファイル名変数を ANSI版から Unicode 版へ切り替え

- get_lang_msgW() -> GetI18nStrWW()
- SetDlgTexts() -> SetDlgTextsW()
- SetWinMenu() を SetWinMenuW() に置き換え
  - ttpcmn/ttcmn.c, def
1 /*
2 * Copyright (C) 1994-1998 T. Teranishi
3 * (C) 2006- TeraTerm Project
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 /* TTMACRO.EXE, dialog boxes */
31
32 #include <windows.h>
33 #include <direct.h>
34 #include <commdlg.h>
35 #if !defined(_CRTDBG_MAP_ALLOC)
36 #define _CRTDBG_MAP_ALLOC
37 #endif
38 #include <stdlib.h>
39 #include <crtdbg.h>
40 #include <assert.h>
41
42 #include "teraterm.h"
43 #include "ttm_res.h"
44 #include "tttypes.h"
45 #include "ttlib.h"
46 #include "ttmdef.h"
47 #include "errdlg.h"
48 #include "inpdlg.h"
49 #include "msgdlg.h"
50 #include "statdlg.h"
51 #include "ListDlg.h"
52 #include "ttmlib.h"
53 #include "ttmdlg.h"
54 #include "ttmacro.h"
55
56 #include "ttmdlg.h"
57
58 wchar_t *HomeDirW;
59 wchar_t FileName[MAX_PATH];
60 wchar_t TopicName[11];
61 wchar_t ShortName[MAX_PATH];
62 wchar_t **Params = NULL;
63 int ParamCnt;
64 int ParamsSize;
65 BOOL SleepFlag;
66
67 // (x,y) = (CW_USEDEFAULT, CW_USEDEFAULT)�������Z���^�[���\��
68 static int DlgPosX = CW_USEDEFAULT;
69 static int DlgPosY = CW_USEDEFAULT;
70
71 static CStatDlg *StatDlg = NULL;
72
73 void ParseParam(PBOOL IOption, PBOOL VOption)
74 {
75 wchar_t *Param, **ptmp;
76 wchar_t Temp[MaxStrLen];
77 wchar_t *start, *cur, *next;
78
79 // go home directory
80 SetCurrentDirectoryW(HomeDirW);
81
82 // Get command line parameters
83 FileName[0] = 0;
84 TopicName[0] = 0;
85 SleepFlag = FALSE;
86 *IOption = FALSE;
87 *VOption = FALSE;
88 Param = GetCommandLineW();
89
90 ParamsSize = 50;
91 Params = (wchar_t **)malloc(sizeof(wchar_t *) * ParamsSize);
92 if (Params) {
93 Params[0] = _wcsdup(Param);
94 Params[1] = NULL;
95 }
96
97 // the first term shuld be executable filename of TTMACRO
98 start = GetParam(Temp, _countof(Temp), Param);
99 ParamCnt = 0;
100
101 for (cur = start; next = GetParam(Temp, sizeof(Temp), cur); cur = next) {
102 DequoteParam(Temp, _countof(Temp), Temp);
103 if (ParamCnt == 0) {
104 if (_wcsnicmp(Temp,L"/D=",3)==0) { // DDE option
105 wcsncpy_s(TopicName, _countof(TopicName), &Temp[3], _TRUNCATE);
106 continue;
107 }
108 else if (_wcsicmp(Temp, L"/I")==0) {
109 *IOption = TRUE;
110 continue;
111 }
112 else if (_wcsicmp(Temp, L"/S")==0) {
113 SleepFlag = TRUE;
114 continue;
115 }
116 else if (_wcsicmp(Temp, L"/V")==0) {
117 *VOption = TRUE;
118 continue;
119 }
120 }
121
122 if (++ParamCnt == 1) {
123 wcsncpy_s(FileName, _countof(FileName), Temp, _TRUNCATE);
124 if (Params == NULL) {
125 break;
126 }
127 }
128 else {
129 if (ParamsSize <= ParamCnt) {
130 ParamsSize += 10;
131 ptmp = (wchar_t **)realloc(Params, sizeof(wchar_t*) * ParamsSize);
132 if (ptmp == NULL) {
133 ParamCnt--;
134 break;
135 }
136 Params = ptmp;
137 }
138 Params[ParamCnt] = _wcsdup(Temp);
139 }
140 }
141
142 if (FileName[0]=='*') {
143 FileName[0] = 0;
144 }
145 else if (FileName[0]!=0) {
146 size_t dirlen, fnpos;
147 if (GetFileNamePosW(FileName, &dirlen, &fnpos)) {
148 FitFileNameW(&FileName[fnpos], _countof(FileName) - fnpos, L".TTL");
149 wcsncpy_s(ShortName, _countof(ShortName), &FileName[fnpos], _TRUNCATE);
150 if (dirlen==0) {
151 wcsncpy_s(FileName, _countof(FileName), HomeDirW, _TRUNCATE);
152 AppendSlashW(FileName, _countof(FileName));
153 wcsncat_s(FileName, _countof(FileName), ShortName, _TRUNCATE);
154 }
155
156 if (Params) {
157 Params[1] = _wcsdup(ShortName);
158 }
159 }
160 else {
161 FileName[0] = 0;
162 }
163 }
164 }
165
166 BOOL GetFileName(HWND HWin)
167 {
168 wchar_t *FNFilter;
169 wchar_t *title;
170 OPENFILENAMEW FNameRec;
171
172 if (FileName[0]!=0) {
173 return FALSE;
174 }
175
176 memset(&FNameRec, 0, sizeof(OPENFILENAME));
177 GetI18nStrWW("Tera Term", "FILEDLG_OPEN_MACRO_FILTER", L"Macro files (*.ttl)\\0*.ttl\\0\\0", UILanguageFileW, &FNFilter);
178 GetI18nStrWW("Tera Term", "FILEDLG_OPEN_MACRO_TITLE", L"MACRO: Open macro", UILanguageFileW, &title);
179
180 // sizeof(OPENFILENAME) ���� Windows98/NT ���I���������������� (2006.8.14 maya)
181 FNameRec.lStructSize = get_OPENFILENAME_SIZEW();
182 FNameRec.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
183 FNameRec.hwndOwner = HWin;
184 FNameRec.lpstrFilter = FNFilter;
185 FNameRec.nFilterIndex = 1;
186 FNameRec.lpstrFile = FileName;
187 FNameRec.nMaxFile = sizeof(FileName);
188 // ���O���������� .ttl �t�@�C�����p�X���L���������������A�����f�B���N�g�����������������B
189 // (2008.4.7 yutaka)
190 #if 0
191 FNameRec.lpstrInitialDir = HomeDirW;
192 #endif
193 FNameRec.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
194 FNameRec.lpstrDefExt = L"TTL";
195 FNameRec.lpstrTitle = title;
196 if (GetOpenFileNameW(&FNameRec)) {
197 wcsncpy_s(ShortName, _countof(ShortName), &(FileName[FNameRec.nFileOffset]), _TRUNCATE);
198 }
199 else {
200 FileName[0] = 0;
201 }
202 free(FNFilter);
203 free(title);
204
205 if (FileName[0]==0) {
206 ShortName[0] = 0;
207 return FALSE;
208 }
209 else {
210 return TRUE;
211 }
212 }
213
214 void SetDlgPos(int x, int y)
215 {
216 DlgPosX = x;
217 DlgPosY = y;
218 if (StatDlg!=NULL) { // update status box position
219 StatDlg->Update(NULL,NULL,DlgPosX,DlgPosY);
220 }
221 }
222
223 void OpenInpDlg(wchar_t *Buff, const wchar_t *Text, const wchar_t *Caption,
224 const wchar_t *Default, BOOL Paswd)
225 {
226 HINSTANCE hInst = GetInstance();
227 HWND hWndParent = GetHWND();
228 CInpDlg InpDlg(Buff,Text,Caption,Default,Paswd,DlgPosX,DlgPosY);
229 InpDlg.DoModal(hInst, hWndParent);
230 }
231
232 int OpenErrDlg(const char *Msg, const char *Line, int lineno, int start, int end, const char *FileName)
233 {
234 HINSTANCE hInst = GetInstance();
235 HWND hWndParent = GetHWND();
236 CErrDlg ErrDlg(Msg,Line,DlgPosX,DlgPosY, lineno, start, end, FileName);
237 return ErrDlg.DoModal(hInst, hWndParent);
238 }
239
240 int OpenMsgDlg(const wchar_t *Text, const wchar_t *Caption, BOOL YesNo)
241 {
242 HINSTANCE hInst = GetInstance();
243 HWND hWndParent = GetHWND();
244 CMsgDlg MsgDlg(Text,Caption,YesNo,DlgPosX,DlgPosY);
245 return MsgDlg.DoModal(hInst, hWndParent);
246 }
247
248 void OpenStatDlg(const wchar_t *Text, const wchar_t *Caption)
249 {
250 if (StatDlg==NULL) {
251 HINSTANCE hInst = GetInstance();
252 StatDlg = new CStatDlg();
253 StatDlg->Create(hInst,Text,Caption,DlgPosX,DlgPosY);
254 }
255 else {// if status box already exists,
256 // update text and caption only.
257 StatDlg->Update(Text,Caption,32767,0);
258 }
259 }
260
261 void CloseStatDlg()
262 {
263 if (StatDlg==NULL) {
264 return;
265 }
266 assert(_CrtCheckMemory());
267 StatDlg->DestroyWindow();
268 assert(_CrtCheckMemory());
269 StatDlg = NULL;
270 }
271
272 void BringupStatDlg()
273 {
274 if (StatDlg==NULL) {
275 return;
276 }
277 StatDlg->Bringup();
278 }
279
280 /**
281 * @retval 0���� �I������
282 * @retval -1 cancel�{�^��
283 * @retval -2 close�{�^��
284 */
285 int OpenListDlg(const wchar_t *Text, const wchar_t *Caption, wchar_t **Lists, int Selected)
286 {
287 HINSTANCE hInst = GetInstance();
288 HWND hWndParent = GetHWND();
289 CListDlg ListDlg(Text, Caption, Lists, Selected, DlgPosX, DlgPosY);
290 INT_PTR r = ListDlg.DoModal(hInst, hWndParent);
291 if (r == IDOK) {
292 return ListDlg.m_SelectItem;
293 }
294 return r == IDCANCEL ? -1 : -2;
295 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26