Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /branches/ttcomtester/teraterm/teraterm/setupdirdlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9917 - (hide annotations) (download) (as text)
Thu May 12 13:55:46 2022 UTC (23 months ago) by zmatsuo
Original Path: trunk/teraterm/teraterm/setupdirdlg.cpp
File MIME type: text/x-c++src
File size: 18090 byte(s)
[Setup]/[Setup directory...] の従来のコントロールを削除

- エディット、ボタンを削除
- リストのサイズを変更
1 zmatsuo 9339 /*
2     * Copyright (C) 1994-1998 T. Teranishi
3     * (C) 2004- 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     #include "teraterm.h"
31     #include "tttypes.h"
32     #include "tttypes_key.h"
33    
34     #include "ttcommon.h"
35     #include "ttdialog.h"
36     #include "commlib.h"
37     #include "ttlib.h"
38     #include "dlglib.h"
39    
40     #include <stdio.h>
41     #define _CRTDBG_MAP_ALLOC
42     #include <stdlib.h>
43     #include <crtdbg.h>
44     #include <string.h>
45 zmatsuo 9503 #include <assert.h>
46 zmatsuo 9339
47     #include <shlobj.h>
48     #include <windows.h>
49     #include <wchar.h>
50     #include <htmlhelp.h>
51    
52     #include "tt_res.h"
53     #include "vtwin.h"
54     #include "compat_win.h"
55     #include "codeconv.h"
56     #include "asprintf.h"
57 zmatsuo 9412 #include "helpid.h"
58 zmatsuo 9543 #include "win32helper.h"
59 zmatsuo 9339
60     #include "setupdirdlg.h"
61    
62 zmatsuo 9340 // Virtual Store���L���������������������������B
63 zmatsuo 9339 //
64 zmatsuo 9340 // [Windows 95-XP]
65     // return FALSE (always)
66     //
67     // [Windows Vista-10]
68     // return TRUE: Virtual Store Enabled
69     // FALSE: Virtual Store Disabled or Unknown
70     //
71     static BOOL GetVirtualStoreEnvironment(void)
72     {
73     #if _MSC_VER == 1400 // VSC2005(VC8.0)
74     typedef struct _TOKEN_ELEVATION {
75     DWORD TokenIsElevated;
76     } TOKEN_ELEVATION, *PTOKEN_ELEVATION;
77     int TokenElevation = 20;
78     #endif
79     BOOL ret = FALSE;
80     int flag = 0;
81     HANDLE hToken;
82     DWORD dwLength;
83     TOKEN_ELEVATION tokenElevation;
84     LONG lRet;
85     HKEY hKey;
86     char lpData[256];
87     DWORD dwDataSize;
88     DWORD dwType;
89     BYTE bValue;
90    
91     // Windows Vista���O�����������B
92     if (!IsWindowsVistaOrLater())
93     goto error;
94    
95     // UAC���L�����������B
96     // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System��EnableLUA(DWORD�l)��0�������������f��������(0��UAC�����A1��UAC�L��)�B
97     flag = 0;
98 zmatsuo 9543 lRet = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
99     "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System",
100     0, KEY_QUERY_VALUE, &hKey);
101 zmatsuo 9340 if (lRet == ERROR_SUCCESS) {
102     dwDataSize = sizeof(lpData) / sizeof(lpData[0]);
103 zmatsuo 9543 lRet = RegQueryValueExA(
104 zmatsuo 9340 hKey,
105 zmatsuo 9543 "EnableLUA",
106 zmatsuo 9340 0,
107     &dwType,
108     (LPBYTE)lpData,
109     &dwDataSize);
110     if (lRet == ERROR_SUCCESS) {
111     bValue = ((LPBYTE)lpData)[0];
112     if (bValue == 1)
113     // UAC���L���������AVirtual Store�������B
114     flag = 1;
115     }
116     RegCloseKey(hKey);
117     }
118     if (flag == 0)
119     goto error;
120    
121     // UAC���L�����A�v���Z�X�����������������i�����������B
122     flag = 0;
123     if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_ADJUST_DEFAULT, &hToken)) {
124     if (GetTokenInformation(hToken, (TOKEN_INFORMATION_CLASS)TokenElevation, &tokenElevation, sizeof(TOKEN_ELEVATION), &dwLength)) {
125     // (0�����i�����������A��0�����i��������)�B
126     if (tokenElevation.TokenIsElevated == 0) {
127     // �����������������������������AVirtual Store�������B
128     flag = 1;
129     }
130     }
131     CloseHandle(hToken);
132     }
133     if (flag == 0)
134     goto error;
135    
136     ret = TRUE;
137     return (ret);
138    
139     error:
140     return (ret);
141     }
142    
143     //
144 zmatsuo 9339 // �w�������A�v���P�[�V�������t�@�C�����J���B
145     //
146     // return TRUE: success
147     // FALSE: failure
148     //
149 zmatsuo 9543 static BOOL openFileWithApplication(const wchar_t *filename, const char *editor, const wchar_t *UILanguageFile)
150 zmatsuo 9339 {
151 zmatsuo 9340 wchar_t *commandW = NULL;
152 zmatsuo 9339 BOOL ret = FALSE;
153    
154 zmatsuo 9340 if (GetFileAttributesW(filename) == INVALID_FILE_ATTRIBUTES) {
155     // �t�@�C��������������
156     DWORD no = GetLastError();
157     static const TTMessageBoxInfoW info = {
158     "Tera Term",
159     "MSG_ERROR", L"ERROR",
160 zmatsuo 9342 "DLG_SETUPDIR_NOFILE_ERROR", L"File does not exist.(%d)",
161     MB_OK | MB_ICONWARNING
162     };
163 zmatsuo 9543 TTMessageBoxW(NULL, &info, UILanguageFile, no);
164 zmatsuo 9339
165     goto error;
166     }
167    
168 zmatsuo 9340 aswprintf(&commandW, L"%hs \"%s\"", editor, filename);
169 zmatsuo 9339
170 zmatsuo 9340 STARTUPINFOW si;
171     PROCESS_INFORMATION pi;
172 zmatsuo 9339 memset(&si, 0, sizeof(si));
173 zmatsuo 9340 GetStartupInfoW(&si);
174 zmatsuo 9339 memset(&pi, 0, sizeof(pi));
175    
176 zmatsuo 9340 if (CreateProcessW(NULL, commandW, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi) == 0) {
177     // �N�����s
178 zmatsuo 9339 DWORD no = GetLastError();
179 zmatsuo 9340 static const TTMessageBoxInfoW info = {
180     "Tera Term",
181     "MSG_ERROR", L"ERROR",
182 zmatsuo 9342 "DLG_SETUPDIR_OPENFILE_ERROR", L"Cannot open file.(%d)",
183     MB_OK | MB_ICONWARNING
184     };
185 zmatsuo 9543 TTMessageBoxW(NULL, &info, UILanguageFile, no);
186 zmatsuo 9340
187 zmatsuo 9339 goto error;
188 zmatsuo 9340 }
189     else {
190 zmatsuo 9339 CloseHandle(pi.hThread);
191     CloseHandle(pi.hProcess);
192     }
193    
194     ret = TRUE;
195    
196     error:;
197 zmatsuo 9340 free(commandW);
198    
199 zmatsuo 9339 return (ret);
200     }
201    
202 zmatsuo 9543 /**
203     * �G�N�X�v���[�����w���t�@�C�����t�H���_���J��
204     * �t�@�C�������������������t�@�C�����I�������������J��
205     * �t�@�C���������������������t�H���_���J��
206     *
207     * @param file �t�@�C��
208     * @retval TRUE: success
209     * @retval FALSE: failure
210     */
211     static BOOL openDirectoryWithExplorer(const wchar_t *file, const wchar_t *UILanguageFile)
212 zmatsuo 9339 {
213 zmatsuo 9340 BOOL ret;
214 zmatsuo 9339
215 zmatsuo 9543 DWORD attr = GetFileAttributesW(file);
216 zmatsuo 9340 if (attr == INVALID_FILE_ATTRIBUTES) {
217 zmatsuo 9543 // �t�@�C��������������, �f�B���N�g�����I�[�v������
218     wchar_t *dir = ExtractDirNameW(file);
219     attr = GetFileAttributesW(dir);
220     if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) {
221     // �t�H���_���J��
222     INT_PTR h = (INT_PTR)ShellExecuteW(NULL, L"open", L"explorer.exe", dir, NULL, SW_NORMAL);
223     ret = h > 32 ? TRUE : FALSE;
224     }
225     else {
226     // �t�@�C�����t�H���_������������
227     DWORD no = GetLastError();
228     static const TTMessageBoxInfoW info = {
229     "Tera Term",
230     "MSG_ERROR", L"ERROR",
231     "DLG_SETUPDIR_NOFILE_ERROR", L"File does not exist.(%d)",
232     MB_OK | MB_ICONWARNING
233     };
234     TTMessageBoxW(NULL, &info, UILanguageFile, no);
235     ret = FALSE;
236     }
237     free(dir);
238 zmatsuo 9340 } else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) {
239 zmatsuo 9543 // �w�������������t�H���_�������A�t�H���_���J��
240     INT_PTR h = (INT_PTR)ShellExecuteW(NULL, L"open", L"explorer.exe", file, NULL, SW_NORMAL);
241 zmatsuo 9340 ret = h > 32 ? TRUE : FALSE;
242     } else {
243     // �t�H���_���J�� + �t�@�C���I��
244     wchar_t *param;
245 zmatsuo 9543 aswprintf(&param, L"/select,%s", file);
246 zmatsuo 9340 INT_PTR h = (INT_PTR)ShellExecuteW(NULL, L"open", L"explorer.exe", param, NULL, SW_NORMAL);
247     free(param);
248     ret = h > 32 ? TRUE : FALSE;
249 zmatsuo 9339 }
250 zmatsuo 9340 return ret;
251 zmatsuo 9339 }
252    
253 zmatsuo 9340 /**
254     * �t���p�X�t�@�C������ Virtual Store�p�X�����������B
255     * @param[in] filename �����O���t�@�C����
256     * @param[out] vstore_filename Virtual Store���t�@�C����
257     * @retval TRUE ��������
258     * FALSE ��������������(Virtual Store������������������)
259     */
260     static BOOL convertVirtualStoreW(const wchar_t *filename, wchar_t **vstore_filename)
261 zmatsuo 9339 {
262 zmatsuo 9340 wchar_t *path = ExtractDirNameW(filename);
263     wchar_t *file = ExtractFileNameW(filename);
264    
265     // �s�v���h���C�u���^�[�����������B
266     // �h���C�u���^�[���������������������_�������B(1��������?)
267     wchar_t *path_nodrive = wcsstr(path, L":\\");
268     if (path_nodrive == NULL) {
269     // �t���p�X��������, VS���l������������ok
270     free(path);
271     free(file);
272     return FALSE;
273 zmatsuo 9339 }
274 zmatsuo 9340 path_nodrive++;
275 zmatsuo 9339
276     BOOL ret = FALSE;
277 zmatsuo 9340 static const wchar_t* virstore_env[] = {
278     L"ProgramFiles",
279     L"ProgramData",
280     L"SystemRoot",
281 zmatsuo 9339 NULL
282     };
283 zmatsuo 9340 const wchar_t** p = virstore_env;
284 zmatsuo 9339
285 zmatsuo 9340 if (GetVirtualStoreEnvironment() == FALSE)
286 zmatsuo 9339 goto error;
287    
288     // Virtual Store�����������t�H���_���B
289     while (*p) {
290 zmatsuo 9340 const wchar_t *s = _wgetenv(*p);
291     if (s != NULL && wcsstr(path, s) != NULL) {
292 zmatsuo 9339 break;
293     }
294     p++;
295     }
296     if (*p == NULL)
297     goto error;
298    
299    
300     // Virtual Store�p�X�������B
301 zmatsuo 9421 wchar_t *local_appdata;
302     _SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &local_appdata);
303     wchar_t *vs_file;
304 zmatsuo 9503 aswprintf(&vs_file, L"%s\\VirtualStore%s\\%s", local_appdata, path_nodrive, file);
305 zmatsuo 9421 free(local_appdata);
306 zmatsuo 9339
307     // �������AVirtual Store���t�@�C�������������������������B
308 zmatsuo 9340 if (GetFileAttributesW(vs_file) == INVALID_FILE_ATTRIBUTES) {
309     free(vs_file);
310 zmatsuo 9339 goto error;
311     }
312    
313 zmatsuo 9340 *vstore_filename = vs_file;
314 zmatsuo 9339
315     ret = TRUE;
316 zmatsuo 9340 goto epilogue;
317 zmatsuo 9339
318     error:
319 zmatsuo 9340 *vstore_filename = NULL;
320     ret = FALSE;
321     epilogue:
322     free(path);
323     free(file);
324     return ret;
325 zmatsuo 9339 }
326    
327 zmatsuo 9916 /**
328     * ���X�g���`�p�\����
329     */
330     typedef enum {
331     LIST_PARAM_STR = 1, // ������
332     LIST_PARAM_FUNC = 2, // ����
333     } SetupListParam;
334     typedef struct {
335     const char *key; // �e�L�X�g���L�[
336     const wchar_t *def_text; // �f�t�H���g�e�L�X�g
337     SetupListParam param; // param_ptr �����e������
338     void *param_ptr; // param�������l
339     void *data_ptr; // ���������g�p�����f�[�^
340     } SetupList;
341    
342     /**
343     * ���j���[���o�����I�����������������s����
344     */
345     static void PopupAndExec(HWND hWnd, const POINT *pointer_pos, const wchar_t *path, const TTTSet *pts)
346     {
347     const wchar_t *UILanguageFile = pts->UILanguageFileW;
348     const DWORD file_stat = GetFileAttributesW(path);
349     const BOOL dir = (file_stat & FILE_ATTRIBUTE_DIRECTORY) != 0 ? TRUE : FALSE;
350    
351     HMENU hMenu= CreatePopupMenu();
352     AppendMenuW(hMenu, (dir ? MF_DISABLED : MF_ENABLED) | MF_STRING | 0, 1, L"&Open file");
353     AppendMenuW(hMenu, MF_ENABLED | MF_STRING | 0, 2, L"Open folder(with explorer)");
354     AppendMenuW(hMenu, MF_ENABLED | MF_STRING | 0, 3, L"Send path to clipboard");
355     int result = TrackPopupMenu(hMenu, TPM_RETURNCMD, pointer_pos->x, pointer_pos->y, 0 , hWnd, NULL);
356     DestroyMenu(hMenu);
357     switch (result) {
358     case 1: {
359     // �A�v�����J��
360     const char *editor = pts->ViewlogEditor;
361     openFileWithApplication(path, editor, UILanguageFile);
362     break;
363     }
364     case 2: {
365     // �t�H���_���J�����A�t�@�C�����I������
366     openDirectoryWithExplorer(path, UILanguageFile);
367     break;
368     }
369     case 3: {
370     // �N���b�v�{�[�h�����������M
371     CBSetTextW(hWnd, path, 0);
372     break;
373     }
374     default:
375     break;
376     }
377     }
378    
379     static wchar_t *GetCygtermIni(const SetupList *list, const TTTSet *pts)
380     {
381     wchar_t *cygterm_ini;
382     aswprintf(&cygterm_ini, L"%s\\cygterm.cfg", pts->HomeDirW);
383     if (list->data_ptr != 0) {
384     wchar_t *virtual_store_path;
385     BOOL ret = convertVirtualStoreW(cygterm_ini, &virtual_store_path);
386     free(cygterm_ini);
387     if (ret) {
388     return virtual_store_path;
389     } else {
390     return NULL;
391     }
392     }
393     return cygterm_ini;
394     }
395    
396     static wchar_t *GetTTXSSHKwnownHostFile(const SetupList *list, const TTTSet *)
397     {
398     HMODULE h = GetModuleHandle("ttxssh.dll");
399     if (h == NULL) {
400     return NULL;
401     }
402    
403     size_t (CALLBACK *func)(wchar_t *, size_t) = NULL;
404     void **pfunc = (void **)&func;
405     *pfunc = (void *)GetProcAddress(h, "TTXReadKnownHostsFile");
406     if (func == NULL) {
407     return NULL;
408     }
409    
410     size_t size = func(NULL, 0);
411     if (size == 0) {
412     return NULL;
413     }
414    
415     wchar_t *temp = (wchar_t *)malloc(sizeof(wchar_t) * size);
416     func(temp, size);
417     assert(!IsRelativePathW(temp));
418    
419     if (list->data_ptr != 0) {
420     wchar_t *virtual_store_path;
421     BOOL ret = convertVirtualStoreW(temp, &virtual_store_path);
422     if (ret) {
423     return virtual_store_path;
424     } else {
425     return NULL;
426     }
427     }
428    
429     return temp;
430     }
431    
432     /**
433     * Virtaul Store�����p�X������
434     */
435     static wchar_t *GetVirtualStorePath(const SetupList *list, const TTTSet *)
436     {
437     const wchar_t *path = (wchar_t *)list->data_ptr;
438     wchar_t *virtual_store_path;
439     BOOL ret = convertVirtualStoreW(path, &virtual_store_path);
440     if (ret) {
441     return virtual_store_path;
442     } else {
443     // virtual store���g�p������������
444     return NULL;
445     }
446     }
447    
448     /**
449     * Susie plug-in �p�X
450     */
451     static wchar_t *GetSusiePluginPath(const SetupList *, const TTTSet *pts)
452     {
453     const char *spi_path = pts->EtermLookfeel.BGSPIPath;
454     wchar_t *path;
455     aswprintf(&path, L"%s\\%hs", pts->ExeDirW, spi_path);
456     return path;
457     }
458    
459     /**
460     * Susie plug-in �p�X
461     */
462     static wchar_t *GetCurrentPath(const SetupList *, const TTTSet *)
463     {
464     wchar_t *path;
465     hGetCurrentDirectoryW(&path);
466     return path;
467     }
468    
469 zmatsuo 9339 static INT_PTR CALLBACK OnSetupDirectoryDlgProc(HWND hDlgWnd, UINT msg, WPARAM wp, LPARAM lp)
470     {
471     static const DlgTextInfo TextInfos[] = {
472     { 0, "DLG_SETUPDIR_TITLE" },
473     };
474 zmatsuo 9340 TTTSet *pts = (TTTSet *)GetWindowLongPtr(hDlgWnd, DWLP_USER);
475 zmatsuo 9339
476     switch (msg) {
477 zmatsuo 9340 case WM_INITDIALOG: {
478     pts = (TTTSet *)lp;
479     SetWindowLongPtr(hDlgWnd, DWLP_USER, (LONG_PTR)pts);
480    
481 zmatsuo 9339 // I18N
482 zmatsuo 9359 SetDlgTextsW(hDlgWnd, TextInfos, _countof(TextInfos), pts->UILanguageFileW);
483 zmatsuo 9339
484 zmatsuo 9916 HWND hWndList = GetDlgItem(hDlgWnd, IDC_SETUP_DIR_LIST);
485     ListView_SetExtendedListViewStyleEx(hWndList, LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
486    
487     LV_COLUMNA lvcol;
488     lvcol.mask = LVCF_TEXT | LVCF_SUBITEM;
489     lvcol.pszText = (LPSTR)"name";
490     lvcol.iSubItem = 0;
491     //ListView_InsertColumn(hWndList, 0, &lvcol);
492     SendMessage(hWndList, LVM_INSERTCOLUMNA, 0, (LPARAM)&lvcol);
493    
494     lvcol.pszText = (LPSTR)"path/file";
495     lvcol.iSubItem = 1;
496     //ListView_InsertColumn(hWndList, 1, &lvcol);
497     SendMessage(hWndList, LVM_INSERTCOLUMNA, 1, (LPARAM)&lvcol);
498    
499     // ��������
500     static const SetupList setup_list[] = {
501     { "DLG_SETUPDIR_INIFILE", L"Tera Term Configuration File",
502     LIST_PARAM_STR, pts->SetupFNameW, },
503     { NULL, L" Virtual Store",
504     LIST_PARAM_FUNC, (void *)GetVirtualStorePath, pts->SetupFNameW },
505     { "DLG_SETUPDIR_KEYBOARDFILE", L"Keyboard Configuration File",
506     LIST_PARAM_STR, pts->KeyCnfFNW },
507     { NULL, L" Virtual Store",
508     LIST_PARAM_FUNC, (void*)GetVirtualStorePath, pts->KeyCnfFNW },
509     { "DLG_SETUPDIR_CYGTERMFILE", L"CygTerm Configuration File",
510     LIST_PARAM_FUNC, (void*)GetCygtermIni, (void *)0 },
511     { NULL, L" Virtual Store",
512     LIST_PARAM_FUNC, (void*)GetCygtermIni, (void *)1 },
513     { "DLG_SETUPDIR_KNOWNHOSTSFILE", L"SSH known_hosts File",
514     LIST_PARAM_FUNC, (void*)GetTTXSSHKwnownHostFile, (void *)0 },
515     { NULL, L" Virtual Store",
516     LIST_PARAM_FUNC, (void*)GetTTXSSHKwnownHostFile, (void *)1 },
517     { NULL, L"CurrentDirectry",
518     LIST_PARAM_FUNC, (void*)GetCurrentPath },
519     { NULL, L"HomeDir",
520     LIST_PARAM_STR, pts->HomeDirW },
521     { NULL, L"ExeDir",
522     LIST_PARAM_STR, pts->ExeDirW },
523     { NULL, L"LogDir",
524     LIST_PARAM_STR, pts->LogDirW },
525     { NULL, L"LogDefaultPathW",
526     LIST_PARAM_STR, pts->LogDefaultPathW },
527     { NULL, L"Download",
528     LIST_PARAM_STR, pts->FileDirW },
529     { NULL, L"Susie Plugin Path",
530     LIST_PARAM_FUNC, (void*)GetSusiePluginPath },
531     { NULL, L"UI language file",
532     LIST_PARAM_STR, pts->UILanguageFileW },
533     };
534    
535     int y = 0;
536     for (const SetupList *list = &setup_list[0]; list != &setup_list[_countof(setup_list)]; list++) {
537    
538     const SetupListParam param = list->param;
539     wchar_t *s;
540     if (param & LIST_PARAM_STR) {
541     // �����������|�C���^
542     s = (wchar_t *)list->param_ptr;
543     } else if (param & LIST_PARAM_FUNC) {
544     // ����������������������
545     typedef wchar_t *(*func_t)(const SetupList *list, TTTSet *pts);
546     func_t func = (func_t)list->param_ptr;
547     s = func(list, pts);
548     } else {
549     assert("bad list?");
550     s = NULL;
551     }
552     if (s == NULL) {
553     // �\���s�v
554     continue;
555     }
556    
557     const char *key = list->key;
558     const wchar_t *def_text = list->def_text;
559     wchar_t *text;
560     GetI18nStrWW("Tera Term", key, def_text, pts->UILanguageFileW, &text);
561    
562     LVITEMW item;
563     item.mask = LVIF_TEXT;
564     item.iItem = y;
565     item.iSubItem = 0;
566     item.pszText = text;
567     SendMessage(hWndList, LVM_INSERTITEMW, 0, (LPARAM)&item);
568     free(text);
569    
570     item.mask = LVIF_TEXT;
571     item.iItem = y;
572     item.iSubItem = 1;
573     item.pszText = s;
574     SendMessage(hWndList, LVM_SETITEMW, 0, (LPARAM)&item);
575    
576     y++;
577    
578     if (param & LIST_PARAM_FUNC) {
579     // �\���p�������������������J��
580     free(s);
581     }
582     }
583    
584     // ��������
585     for (int i = 0; i < 2; i++) {
586     ListView_SetColumnWidth(hWndList, i, LVSCW_AUTOSIZE);
587     }
588    
589 zmatsuo 9341 CenterWindow(hDlgWnd, GetParent(hDlgWnd));
590    
591 zmatsuo 9339 return TRUE;
592 zmatsuo 9340 }
593 zmatsuo 9339
594 zmatsuo 9340 case WM_COMMAND: {
595 zmatsuo 9339 switch (LOWORD(wp)) {
596 zmatsuo 9412 case IDHELP:
597     OpenHelp(HH_HELP_CONTEXT, HlpMenuSetupDir, pts->UILanguageFile);
598     break;
599    
600     case IDOK:
601     TTEndDialog(hDlgWnd, IDOK);
602     return TRUE;
603     break;
604    
605 zmatsuo 9339 case IDCANCEL:
606     TTEndDialog(hDlgWnd, IDCANCEL);
607     return TRUE;
608     break;
609    
610     default:
611     return FALSE;
612     }
613     return FALSE;
614 zmatsuo 9340 }
615 zmatsuo 9339 case WM_CLOSE:
616     TTEndDialog(hDlgWnd, 0);
617     return TRUE;
618    
619 zmatsuo 9916 case WM_NOTIFY: {
620     NMHDR *nmhdr = (NMHDR *)lp;
621     if (nmhdr->idFrom == IDC_SETUP_DIR_LIST) {
622     NMLISTVIEW *nmlist = (NMLISTVIEW *)lp;
623     switch (nmlist->hdr.code) {
624     // case NM_CLICK:
625     case NM_RCLICK: {
626     POINT pointer_pos;
627     GetCursorPos(&pointer_pos);
628     LVHITTESTINFO ht = {};
629     ht.pt = pointer_pos;
630     ScreenToClient(nmlist->hdr.hwndFrom, &ht.pt);
631     ListView_HitTest(nmlist->hdr.hwndFrom, &ht);
632     if (ht.flags & LVHT_ONITEM) {
633     int hit_item = ht.iItem;
634    
635     wchar_t path[MAX_PATH];
636     LV_ITEMW item;
637     item.mask = TVIF_TEXT;
638     item.iItem = hit_item;
639     item.iSubItem = 1;
640     item.pszText = path;
641     item.cchTextMax = _countof(path);
642     SendMessageW(nmlist->hdr.hwndFrom, LVM_GETITEMW, 0, (LPARAM)&item);
643    
644     PopupAndExec(nmlist->hdr.hwndFrom, &pointer_pos, path, pts);
645     }
646     break;
647     }
648     }
649     }
650     break;
651     }
652 zmatsuo 9339 default:
653     return FALSE;
654     }
655     return TRUE;
656     }
657    
658 zmatsuo 9340 void SetupDirectoryDialog(HINSTANCE hInst, HWND hWnd, TTTSet *pts)
659 zmatsuo 9339 {
660 zmatsuo 9340 TTDialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SETUP_DIR_DIALOG),
661     hWnd, OnSetupDirectoryDlgProc, (LPARAM)pts);
662 zmatsuo 9339 }

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