Develop and Download Open Source Software

Browse Subversion Repository

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10188 - (hide annotations) (download) (as text)
Fri Aug 26 14:28:25 2022 UTC (19 months, 2 weeks ago) by zmatsuo
Original Path: trunk/teraterm/teraterm/themedlg.cpp
File MIME type: text/x-c++src
File size: 26152 byte(s)
BGテーマファイルのBGReverseTextAlphaを読み書きができるようにした

- BGテーマファイルのサンプルに BGReverseTextAlpha を追加
  - sample_bg.ini
  - sample_wallpaper.ini
- テーマダイアログ/BG tab (themedlg.cpp)
  - BGReverseTextAlpha 設定用スライダーを追加
  - SendDlgItemMessage() -> SendDlgItemMessageA()
- BGテーマファイル (vtdisp.c)
  - BGReverseTextAlpha の読み込み/書き込みを追加
- WritePrivateProfileIntW() を追加
- BGSaveColorANSI()サイズ指定を誤っていたので修正
1 zmatsuo 10134 /*
2     * Copyright (C) 1994-1998 T. Teranishi
3     * (C) 2022- 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    
33     #include "ttcommon.h"
34     #include "ttdialog.h"
35     #include "commlib.h"
36     #include "ttlib.h"
37     #include "dlglib.h"
38    
39     #include <stdio.h>
40     #define _CRTDBG_MAP_ALLOC
41     #include <stdlib.h>
42     #include <crtdbg.h>
43     #include <string.h>
44     #include <assert.h>
45    
46     #include <shlobj.h>
47     #include <windows.h>
48     #include <wchar.h>
49     #include <htmlhelp.h>
50    
51     #include "compat_win.h"
52     #include "codeconv.h"
53     #include "asprintf.h"
54     #include "win32helper.h"
55     #include "tipwin2.h"
56     #include "dlglib.h"
57     #include "inifile_com.h"
58     #include "helpid.h"
59     #include "vtdisp.h"
60     #include "tmfc.h"
61     #include "tmfc_propdlg.h"
62    
63     #include "bg_theme.h"
64     #include "themedlg_res.h"
65     #include "themedlg.h"
66    
67     typedef struct {
68     // ����
69     HINSTANCE hInst;
70     TComVar *pcv;
71     TTTSet *pts;
72     DLGTEMPLATE *dlg_templ;
73     TipWin2 *tipwin;
74     HWND hVTWin;
75     // file tab
76     struct {
77     DLGTEMPLATE *dlg_templ;
78     } FileTab;
79     // bg theme tab
80     BGTheme bg_theme;
81     struct {
82     DLGTEMPLATE *dlg_templ;
83     TipWin2 *tipwin;
84     BGTheme bg_theme;
85     } BGTab;
86     // color theme tab
87     struct {
88     TColorTheme color_theme;
89     } color_tab;
90     struct {
91     BGTheme bg_theme;
92     TColorTheme color_theme;
93     } backup;
94     } ThemeDlgData;
95    
96     static void SetWindowTextColor(HWND hWnd, COLORREF color)
97     {
98     char str[32];
99     sprintf(str, "%02x%02x%02x", GetRValue(color), GetGValue(color), GetBValue(color));
100     SetWindowTextA(hWnd, str);
101     }
102    
103     static void SetDlgItemTextColor(HWND hDlg, int ID, COLORREF color)
104     {
105     SetWindowTextColor(GetDlgItem(hDlg, ID), color);
106     }
107    
108     static COLORREF GetWindowTextColor(HWND hWnd)
109     {
110     char str[32];
111     unsigned int r, g, b;
112     char elem[3];
113    
114     GetWindowTextA(hWnd, str, _countof(str));
115    
116     memcpy(elem, &str[0], 2);
117     elem[2] = 0;
118     r = 0;
119     sscanf(elem, "%x", &r);
120    
121     memcpy(elem, &str[2], 2);
122     elem[2] = 0;
123     g = 0;
124     sscanf(elem, "%x", &g);
125    
126     memcpy(elem, &str[4], 2);
127     elem[2] = 0;
128     b = 0;
129     sscanf(elem, "%x", &b);
130    
131     return RGB(r, g, b);
132     }
133    
134     static COLORREF GetDlgItemTextColor(HWND hDlg, int ID)
135     {
136     return GetWindowTextColor(GetDlgItem(hDlg, ID));
137     }
138    
139     static void ResetControls(HWND hWnd, const BGTheme *bg_theme)
140     {
141 zmatsuo 10188 SendDlgItemMessageA(hWnd, IDC_BGIMG_CHECK, BM_SETCHECK, (bg_theme->BGDest.type == BG_PICTURE) ? TRUE : FALSE, 0);
142 zmatsuo 10134 SetDlgItemTextA(hWnd, IDC_BGIMG_EDIT, bg_theme->BGDest.file);
143     SetDlgItemTextColor(hWnd, IDC_BGIMG_COLOR_EDIT, bg_theme->BGDest.color);
144     {
145     LRESULT count = SendDlgItemMessageA(hWnd, IDC_BGIMG_COMBO, CB_GETCOUNT, 0, 0);
146     int sel = 0;
147     int i;
148     for (i = 0; i < count; i++) {
149     BG_PATTERN pattern = (BG_PATTERN)SendDlgItemMessageW(hWnd, IDC_BGIMG_COMBO, CB_GETITEMDATA, i, 0);
150     if (pattern == bg_theme->BGDest.pattern) {
151     sel = i;
152     break;
153     }
154     }
155 zmatsuo 10188 SendDlgItemMessageA(hWnd, IDC_BGIMG_COMBO, CB_SETCURSEL, sel, 0);
156 zmatsuo 10134 }
157    
158 zmatsuo 10188 SendDlgItemMessageA(hWnd, IDC_WALLPAPER_CHECK, BM_SETCHECK, bg_theme->BGSrc1.alpha != 0, 0);
159 zmatsuo 10134 SetDlgItemInt(hWnd, IDC_WALLPAPER_ALPHA_EDIT, bg_theme->BGSrc1.alpha, FALSE);
160    
161 zmatsuo 10188 SendDlgItemMessageA(hWnd, IDC_SIMPLE_COLOR_PLANE_CHECK, BM_SETCHECK, bg_theme->BGSrc2.alpha != 0, 0);
162 zmatsuo 10134 SetDlgItemInt(hWnd, IDC_SIMPLE_COLOR_PLANE_ALPHA, bg_theme->BGSrc2.alpha, FALSE);
163     SetDlgItemTextColor(hWnd, IDC_SIMPLE_COLOR_PLANE_COLOR, bg_theme->BGSrc2.color);
164 zmatsuo 10188
165     SendDlgItemMessageA(hWnd, IDC_REVERSE_TEXT_ALPHA_SLIDER, TBM_SETPOS, TRUE, bg_theme->BGReverseTextAlpha);
166 zmatsuo 10134 }
167    
168     static void ReadFromDialog(HWND hWnd, BGTheme* bg_theme)
169     {
170     LRESULT checked;
171     LRESULT index;
172     checked = SendDlgItemMessageA(hWnd, IDC_BGIMG_CHECK, BM_GETCHECK, 0, 0);
173     bg_theme->BGDest.type = checked & BST_CHECKED ? BG_PICTURE : BG_NONE;
174     GetDlgItemTextA(hWnd, IDC_BGIMG_EDIT, bg_theme->BGDest.file, sizeof(bg_theme->BGDest.file));
175     bg_theme->BGDest.color = GetDlgItemTextColor(hWnd, IDC_BGIMG_COLOR_EDIT);
176 zmatsuo 10188 index = SendDlgItemMessageA(hWnd, IDC_BGIMG_COMBO, CB_GETCURSEL, 0, 0);
177     bg_theme->BGDest.pattern = (BG_PATTERN)SendDlgItemMessageA(hWnd, IDC_BGIMG_COMBO, CB_GETITEMDATA, index, 0);
178 zmatsuo 10134
179     checked = SendDlgItemMessageA(hWnd, IDC_WALLPAPER_CHECK, BM_GETCHECK, 0, 0);
180     if (checked & BST_CHECKED) {
181     bg_theme->BGSrc1.type = BG_WALLPAPER;
182     bg_theme->BGSrc1.alpha = GetDlgItemInt(hWnd, IDC_WALLPAPER_ALPHA_EDIT, NULL, FALSE);
183     } else {
184     bg_theme->BGSrc1.type = BG_NONE;
185     bg_theme->BGSrc1.alpha = 0;
186     }
187    
188     checked = SendDlgItemMessageA(hWnd, IDC_SIMPLE_COLOR_PLANE_CHECK, BM_GETCHECK, 0, 0);
189     if (checked & BST_CHECKED) {
190     bg_theme->BGSrc2.type = BG_COLOR;
191     bg_theme->BGSrc2.alpha = GetDlgItemInt(hWnd, IDC_SIMPLE_COLOR_PLANE_ALPHA, NULL, FALSE);
192     } else {
193     bg_theme->BGSrc2.type = BG_NONE;
194     bg_theme->BGSrc2.alpha = 0;
195     }
196     bg_theme->BGSrc2.color = GetDlgItemTextColor(hWnd, IDC_SIMPLE_COLOR_PLANE_COLOR);
197 zmatsuo 10188
198     bg_theme->BGReverseTextAlpha = SendDlgItemMessageA(hWnd, IDC_REVERSE_TEXT_ALPHA_SLIDER, TBM_GETPOS, 0, 0);
199 zmatsuo 10134 }
200    
201     static INT_PTR CALLBACK BGThemeProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
202     {
203     ThemeDlgData* dlg_data = (ThemeDlgData*)GetWindowLongPtr(hWnd, DWLP_USER);
204    
205     switch (msg) {
206     case WM_INITDIALOG: {
207     int i;
208     dlg_data = (ThemeDlgData*)(((PROPSHEETPAGEW_V1 *)lp)->lParam);
209     SetWindowLongPtr(hWnd, DWLP_USER, (LONG_PTR)dlg_data);
210    
211     SetDlgItemTextW(hWnd, IDC_BG_THEME_HELP,
212     L"Mix order:\n"
213     L" base\n"
214     L" v\n"
215     L" Background Image\n"
216     L" v\n"
217     L" wallpaper\n"
218     L" v\n"
219     L" simple color plane"
220     );
221    
222     for (i = 0;; i++) {
223     LRESULT index;
224     const BG_PATTERN_ST *st = GetBGPatternList(i);
225     if (st == NULL) {
226     break;
227     }
228     index = SendDlgItemMessageA(hWnd, IDC_BGIMG_COMBO, CB_ADDSTRING, 0, (LPARAM)st->str);
229     SendDlgItemMessageW(hWnd, IDC_BGIMG_COMBO, CB_SETITEMDATA, index, st->id);
230     }
231    
232 zmatsuo 10188 SendDlgItemMessageA(hWnd, IDC_REVERSE_TEXT_ALPHA_SLIDER, TBM_SETRANGE, TRUE, MAKELONG(0, 255));
233    
234 zmatsuo 10134 ResetControls(hWnd, &dlg_data->bg_theme);
235     return TRUE;
236     break;
237     }
238     case WM_COMMAND: {
239     switch (wp) {
240     case IDC_BGIMG_BUTTON | (BN_CLICKED << 16): {
241     // �����t�@�C���I��
242     OPENFILENAMEW ofn = {};
243     wchar_t bg_file[MAX_PATH];
244     wchar_t *bg_file_in;
245    
246     hGetDlgItemTextW(hWnd, IDC_BGIMG_EDIT, &bg_file_in);
247     wcscpy_s(bg_file, _countof(bg_file), bg_file_in);
248     free(bg_file_in);
249    
250     ofn.lStructSize = get_OPENFILENAME_SIZEW();
251     ofn.hwndOwner = hWnd;
252     ofn.lpstrFile = bg_file;
253     ofn.nMaxFile = _countof(bg_file);
254     //ofn.lpstrFilter = "";
255     ofn.nFilterIndex = 1;
256     ofn.hInstance = dlg_data->hInst;
257     ofn.lpstrDefExt = L"jpg";
258     ofn.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
259     ofn.lpstrTitle = L"select bg image file";
260    
261     if (GetOpenFileNameW(&ofn)) {
262     SetDlgItemTextW(hWnd, IDC_BGIMG_EDIT, bg_file);
263     }
264     break;
265     }
266     default:
267     break;
268     }
269     break;
270     }
271     case WM_NOTIFY: {
272     NMHDR *nmhdr = (NMHDR *)lp;
273     switch (nmhdr->code) {
274     case PSN_APPLY: {
275     break;
276     }
277     case PSN_HELP:
278     OpenHelpCV(dlg_data->pcv, HH_HELP_CONTEXT, HlpMenuSetupAdditionalTheme);
279     break;
280     case PSN_KILLACTIVE: {
281     ReadFromDialog(hWnd, &dlg_data->bg_theme);
282     break;
283     }
284     case PSN_SETACTIVE: {
285     ResetControls(hWnd, &dlg_data->bg_theme);
286     break;
287     }
288     default:
289     break;
290     }
291     break;
292     }
293     default:
294     return FALSE;
295     }
296     return FALSE;
297     }
298    
299     static UINT CALLBACK BGCallBack(HWND hwnd, UINT uMsg, struct _PROPSHEETPAGEW *ppsp)
300     {
301     UINT ret_val = 0;
302     (void)hwnd;
303     switch (uMsg) {
304     case PSPCB_CREATE:
305     ret_val = 1;
306     break;
307     case PSPCB_RELEASE:
308     free((void *)ppsp->pResource);
309     ppsp->pResource = NULL;
310     break;
311     default:
312     break;
313     }
314     return ret_val;
315     }
316    
317     static HPROPSHEETPAGE ThemeEditorCreate2(ThemeDlgData *dlg_data)
318     {
319     const int id = IDD_TABSHEET_THEME_EDITOR;
320     HINSTANCE inst = dlg_data->hInst;
321    
322     PROPSHEETPAGEW_V1 psp = {};
323     psp.dwSize = sizeof(psp);
324     psp.dwFlags = PSP_DEFAULT | PSP_USECALLBACK | PSP_USETITLE | PSP_HASHELP;
325     psp.hInstance = inst;
326     psp.pfnCallback = BGCallBack;
327     psp.pszTitle = L"Background(BG)"; // TODO lng �t�@�C����������
328     psp.pszTemplate = MAKEINTRESOURCEW(id);
329     psp.dwFlags |= PSP_DLGINDIRECT;
330     psp.pResource = TTGetDlgTemplate(inst, MAKEINTRESOURCEA(id));
331    
332     psp.pfnDlgProc = BGThemeProc;
333     psp.lParam = (LPARAM)dlg_data;
334    
335     return CreatePropertySheetPageW((LPPROPSHEETPAGEW)&psp);
336     }
337    
338     //////////////////////////////////////////////////////////////////////////////
339    
340     static struct {
341     const wchar_t *name;
342     COLORREF color;
343     } list[] = {
344     { L"VTColor Fore", RGB(0,0,0) },
345     { L"VTColor Back", RGB(0,0,0) },
346     { L"VTBoldColor Fore", RGB(0,0,0) },
347     { L"VTBoldColor Back", RGB(0,0,0) },
348     { L"VTBlinkColor Fore", RGB(0,0,0) },
349     { L"VTBlinkColor Back", RGB(0,0,0) },
350     { L"VTReverseColor Fore", RGB(0,0,0) },
351     { L"VTReverseColor Back", RGB(0,0,0) },
352     { L"URLColor Fore", RGB(0,0,0) },
353     { L"URLColor Back", RGB(0,0,0) },
354     { L"ANSI 0 / Black", RGB(0,0,0) },
355     { L"ANSI 1 / Red", RGB(197,15,31) },
356     { L"ANSI 2 / Green", RGB(19, 161, 14) },
357     { L"ANSI 3 / Yellow", RGB(193, 156, 0) },
358     { L"ANSI 4 / Blue", RGB(0, 55, 218) },
359     { L"ANSI 5 / Magenta", RGB(136, 23, 152) },
360     { L"ANSI 6 / Cyan", RGB(58, 150, 221) },
361     { L"ANSI 7 / White", RGB(204, 204, 204) },
362     { L"ANSI 8 / Bright Black (Gray)", RGB(118, 118, 118) },
363     { L"ANSI 9 / Bright Red", RGB(231, 72, 86) },
364     { L"ANSI 10 / Bright Green", RGB(22, 198, 12) },
365     { L"ANSI 11 / Bright Yellow", RGB(249, 241, 165) },
366     { L"ANSI 12 / Bright Blue", RGB(59, 120, 255) },
367     { L"ANSI 13 / Bright Magenta", RGB(180, 0, 158) },
368     { L"ANSI 14 / Bright Cyan", RGB(97, 214, 214) },
369     { L"ANSI 15 / Bright White", RGB(242, 242, 242) },
370     };
371    
372     static void SetColor(const TColorTheme *data)
373     {
374     list[0].color = data->vt.fg;
375     list[1].color = data->vt.bg;
376     list[2].color = data->bold.fg;
377     list[3].color = data->bold.bg;
378     list[4].color = data->blink.fg;
379     list[5].color = data->blink.bg;
380     list[6].color = data->reverse.fg;
381     list[7].color = data->reverse.bg;
382     list[8].color = data->url.fg;
383     list[9].color = data->url.bg;
384     for (int i = 0; i < 16; i++) {
385     list[10+i].color = data->ansicolor.color[i];
386     }
387     }
388    
389     static void RestoreColor(TColorTheme *data)
390     {
391     data->vt.fg = list[0].color;
392     data->vt.bg = list[1].color;
393     data->bold.fg = list[2].color;
394     data->bold.bg = list[3].color;
395     data->blink.fg = list[4].color;
396     data->blink.bg = list[5].color;
397     data->reverse.fg = list[6].color;
398     data->reverse.bg = list[7].color;
399     data->url.fg = list[8].color;
400     data->url.bg = list[9].color;
401     for (int i = 0; i < 16; i++) {
402     data->ansicolor.color[i] = list[10+i].color;
403     }
404     }
405    
406     static void SetColorListCtrlValue(HWND hWndList, int y)
407     {
408     LVITEMW item;
409    
410     const COLORREF c = list[y].color;
411     const int r = GetRValue(c);
412     const int g = GetGValue(c);
413     const int b = GetBValue(c);
414    
415     wchar_t color_str[64];
416     swprintf_s(color_str, L"0x%02x%02x%02x", r,g,b);
417     item.mask = LVIF_TEXT;
418     item.iItem = y;
419     item.iSubItem = 2;
420     item.pszText = color_str;
421     SendMessage(hWndList, LVM_SETITEMW, 0, (LPARAM)&item);
422    
423     swprintf_s(color_str, L"%d,%d,%d", r,g,b);
424     item.iSubItem = 3;
425     item.pszText = color_str;
426     SendMessage(hWndList, LVM_SETITEMW, 0, (LPARAM)&item);
427     }
428    
429     static void SetColorListCtrl(HWND hWnd)
430     {
431     HWND hWndList = GetDlgItem(hWnd, IDC_COLOR_LIST);
432     ListView_SetExtendedListViewStyleEx(hWndList, LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
433    
434     SendMessage(hWndList, LVM_DELETEALLITEMS, 0, 0);
435    
436     for (int y = 0; y< _countof(list); y++) {
437     LVITEMW item;
438     item.mask = LVIF_TEXT;
439     item.iItem = y;
440     item.iSubItem = 0;
441     item.pszText = (LPWSTR)list[y].name;
442     SendMessage(hWndList, LVM_INSERTITEMW, 0, (LPARAM)&item);
443    
444     item.iSubItem = 1;
445     item.pszText = NULL;
446     SendMessage(hWndList, LVM_SETITEMW, 0, (LPARAM)&item);
447    
448     SetColorListCtrlValue(hWndList, y);
449     }
450    
451     // ��������
452     for (int i = 0; i < 4; i++) {
453     ListView_SetColumnWidth(hWndList, i, i == 1 ? LVSCW_AUTOSIZE_USEHEADER : LVSCW_AUTOSIZE);
454     }
455     }
456    
457     static INT_PTR CALLBACK ColorThemeProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
458     {
459     static const DlgTextInfo TextInfos[] = {
460     {0, "DLG_GEN_TITLE"},
461     };
462     ThemeDlgData *dlg_data = (ThemeDlgData *)GetWindowLongPtr(hWnd, DWLP_USER);
463    
464     switch (msg) {
465     case WM_INITDIALOG: {
466     dlg_data = (ThemeDlgData *)(((PROPSHEETPAGEW_V1 *)lp)->lParam);
467     SetWindowLongPtr(hWnd, DWLP_USER, (LONG_PTR)dlg_data);
468    
469     {
470     HWND hWndList = GetDlgItem(hWnd, IDC_COLOR_LIST);
471     LV_COLUMNA lvcol;
472     lvcol.mask = LVCF_TEXT | LVCF_SUBITEM;
473     lvcol.pszText = (LPSTR)"name";
474     lvcol.iSubItem = 0;
475     //ListView_InsertColumn(hWndList, 0, &lvcol);
476     SendMessage(hWndList, LVM_INSERTCOLUMNA, 0, (LPARAM)&lvcol);
477    
478     lvcol.pszText = (LPSTR)"color";
479     lvcol.iSubItem = 1;
480     //ListView_InsertColumn(hWndList, 1, &lvcol);
481     SendMessage(hWndList, LVM_INSERTCOLUMNA, 1, (LPARAM)&lvcol);
482    
483     lvcol.pszText = (LPSTR)"value(RRGGBB)";
484     lvcol.iSubItem = 2;
485     //ListView_InsertColumn(hWndList, 1, &lvcol);
486     SendMessage(hWndList, LVM_INSERTCOLUMNA, 2, (LPARAM)&lvcol);
487    
488     lvcol.pszText = (LPSTR)"value(R, G, B)";
489     lvcol.iSubItem = 3;
490     //ListView_InsertColumn(hWndList, 1, &lvcol);
491     SendMessage(hWndList, LVM_INSERTCOLUMNA, 3, (LPARAM)&lvcol);
492     }
493    
494     SetColor(&dlg_data->color_tab.color_theme);
495     SetColorListCtrl(hWnd);
496     break;
497     }
498     case WM_COMMAND: {
499     switch (wp) {
500     case IDC_COLOR_DEFAULT_BUTTON | (BN_CLICKED << 16): {
501     // �f�t�H���g
502     BGGetColorDefault(&dlg_data->color_tab.color_theme);
503     SetColor(&dlg_data->color_tab.color_theme);
504     SetColorListCtrl(hWnd);
505     break;
506     }
507     default:
508     break;
509     }
510     break;
511     }
512     case WM_NOTIFY: {
513     NMHDR *nmhdr = (NMHDR *)lp;
514     switch (nmhdr->idFrom) {
515     case IDC_COLOR_LIST: {
516     NMLISTVIEW *nmlist = (NMLISTVIEW *)lp;
517     switch (nmlist->hdr.code) {
518     case NM_CUSTOMDRAW: {
519     NMLVCUSTOMDRAW *lpLvCustomDraw = (LPNMLVCUSTOMDRAW)lp;
520     switch (lpLvCustomDraw->nmcd.dwDrawStage) {
521     case CDDS_PREPAINT: {
522     // go CDDS_ITEMPREPAINT stage
523     SetWindowLongW(hWnd, DWLP_MSGRESULT, (LONG)CDRF_NOTIFYITEMDRAW);
524     return TRUE;
525     }
526     case CDDS_ITEMPREPAINT: {
527     // go CDDS_SUBITEM stage
528     SetWindowLongW(hWnd, DWLP_MSGRESULT, (LONG)CDRF_NOTIFYSUBITEMDRAW);
529     return TRUE;
530     }
531     case (CDDS_ITEMPREPAINT | CDDS_SUBITEM):
532     case CDDS_SUBITEM: {
533     // �s�����w��
534     // if (lpLvCustomDraw->nmcd.dwItemSpec == 1 && lpLvCustomDraw->iSubItem == 1) {
535     if (lpLvCustomDraw->iSubItem == 1) {
536     lpLvCustomDraw->clrText = RGB(0x80, 0x80, 0x80);
537     lpLvCustomDraw->clrTextBk = list[lpLvCustomDraw->nmcd.dwItemSpec].color;
538     }
539     else
540     {
541     // �F�����X�������Z�����f�t�H���g�F���w��
542     // �������w�������������A�F�����X���������~���A�����F��������������
543    
544     // �������f�t�H���g�F
545     lpLvCustomDraw->clrText = GetSysColor(COLOR_WINDOWTEXT);
546    
547     // �w�i���f�t�H���g�F
548     lpLvCustomDraw->clrTextBk = GetSysColor(COLOR_WINDOW);
549     }
550     SetWindowLongW(hWnd, DWLP_MSGRESULT, (LONG)CDRF_NEWFONT);
551     return TRUE;
552     }
553     default:
554     SetWindowLongW(hWnd, DWLP_MSGRESULT, (LONG)CDRF_DODEFAULT);
555     return TRUE;
556     }
557     break;
558     }
559     // case NM_CLICK:
560     case NM_DBLCLK:
561     case NM_RCLICK: {
562     static COLORREF CustColors[16]; // TODO �����I���F�����K�v?
563     int i = nmlist->iItem;
564     CHOOSECOLORA cc = {};
565     cc.lStructSize = sizeof(cc);
566     cc.hwndOwner = hWnd;
567     cc.rgbResult = list[i].color;
568     cc.lpCustColors = CustColors;
569     cc.Flags = CC_FULLOPEN | CC_RGBINIT;
570     if (ChooseColorA(&cc)) {
571     list[i].color = cc.rgbResult;
572     SetColorListCtrlValue(nmlist->hdr.hwndFrom, i);
573     InvalidateRect(nmlist->hdr.hwndFrom, NULL, TRUE);
574     }
575     break;
576     }
577     default:
578     break;
579     }
580     break;
581     }
582     default:
583     break;
584     }
585     switch (nmhdr->code) {
586     case PSN_APPLY: {
587     break;
588     }
589     case PSN_HELP:
590     OpenHelpCV(dlg_data->pcv, HH_HELP_CONTEXT, HlpMenuSetupAdditionalTheme);
591     break;
592     case PSN_KILLACTIVE: {
593     RestoreColor(&dlg_data->color_tab.color_theme);
594     break;
595     }
596     case PSN_SETACTIVE: {
597     SetColor(&dlg_data->color_tab.color_theme);
598     SetColorListCtrl(hWnd);
599     break;
600     }
601     default:
602     break;
603     }
604     break;
605     }
606     default:
607     return FALSE;
608     }
609     return FALSE;
610     }
611    
612     static UINT CALLBACK ColorCallBack(HWND hwnd, UINT uMsg, struct _PROPSHEETPAGEW *ppsp)
613     {
614     (void)hwnd;
615     UINT ret_val = 0;
616     switch (uMsg) {
617     case PSPCB_CREATE:
618     ret_val = 1;
619     break;
620     case PSPCB_RELEASE:
621     free((void *)ppsp->pResource);
622     ppsp->pResource = NULL;
623     break;
624     default:
625     break;
626     }
627     return ret_val;
628     }
629    
630     static HPROPSHEETPAGE ColorThemeEditorCreate2(ThemeDlgData *dlg_data)
631     {
632     const int id = IDD_TABSHEET_COLOR_THEME_EDITOR;
633     HINSTANCE inst = dlg_data->hInst;
634    
635     PROPSHEETPAGEW_V1 psp = {};
636     psp.dwSize = sizeof(psp);
637     psp.dwFlags = PSP_DEFAULT | PSP_USECALLBACK | PSP_USETITLE | PSP_HASHELP;
638     psp.hInstance = inst;
639     psp.pfnCallback = ColorCallBack;
640     psp.pszTitle = L"color"; // TODO lng �t�@�C����������
641     psp.pszTemplate = MAKEINTRESOURCEW(id);
642     #if 1
643     psp.dwFlags |= PSP_DLGINDIRECT;
644     psp.pResource = TTGetDlgTemplate(inst, MAKEINTRESOURCEA(id));
645     #endif
646    
647     psp.pfnDlgProc = ColorThemeProc;
648     psp.lParam = (LPARAM)dlg_data;
649    
650     HPROPSHEETPAGE hpsp = CreatePropertySheetPageW((LPPROPSHEETPAGEW)&psp);
651     return hpsp;
652     }
653    
654     //////////////////////////////////////////////////////////////////////////////
655    
656     static INT_PTR CALLBACK FileProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
657     {
658     static const DlgTextInfo TextInfos[] = {
659     {0, "DLG_GEN_TITLE"},
660     };
661     ThemeDlgData *dlg_data = (ThemeDlgData *)GetWindowLongPtr(hWnd, DWLP_USER);
662     TTTSet *ts = dlg_data == NULL ? NULL : dlg_data->pts;
663    
664     switch (msg) {
665     case WM_INITDIALOG: {
666     dlg_data = (ThemeDlgData *)(((PROPSHEETPAGEW_V1 *)lp)->lParam);
667     ts = dlg_data->pts;
668     SetWindowLongPtr(hWnd, DWLP_USER, (LONG_PTR)dlg_data);
669    
670     dlg_data->tipwin = TipWin2Create(NULL, hWnd);
671     #if 0
672     TipWin2SetTextW(dlg_data->tipwin, IDC_BUTTON1,
673     L"�e�[�}�t�B�A������������\n"
674     );
675     TipWin2SetTextW(dlg_data->tipwin, IDC_BUTTON3,
676     L"�������_�C�A���O�����������������e�[�}�t�@�C������������\n"
677     );
678     TipWin2SetTextW(dlg_data->tipwin, IDC_BUTTON4,
679     L"�������_�C�A���O����������������\n"
680     L"�����y�[�W�������������o����������������\n"
681     );
682     #endif
683     EnableWindow(GetDlgItem(hWnd, IDC_FILE_SAVE_BUTTON), FALSE);
684     return TRUE;
685     break;
686     }
687     case WM_NOTIFY: {
688     NMHDR *nmhdr = (NMHDR *)lp;
689     switch (nmhdr->code) {
690     case PSN_APPLY: {
691     // OK
692     TipWin2Destroy(dlg_data->tipwin);
693     dlg_data->tipwin = NULL;
694     break;
695     }
696     case PSN_HELP:
697     OpenHelpCV(dlg_data->pcv, HH_HELP_CONTEXT, HlpMenuSetupAdditionalTheme);
698     break;
699     default:
700     break;
701     }
702     break;
703     }
704     case WM_COMMAND: {
705     switch (wp) {
706     case IDC_FILE_UNDO_BUTTON | (BN_CLICKED << 16): {
707     // undo,��������
708     dlg_data->bg_theme = dlg_data->backup.bg_theme;
709     dlg_data->color_tab.color_theme = dlg_data->backup.color_theme;
710     goto set;
711     break;
712     }
713     case IDC_FILE_PREVIEW_BUTTON | (BN_CLICKED << 16): {
714     set:
715     // preview
716     BGSet(&dlg_data->bg_theme);
717     BGSetColorData(&dlg_data->color_tab.color_theme);
718     BGSetupPrimary(TRUE);
719     InvalidateRect(dlg_data->hVTWin, NULL, FALSE);
720     break;
721     }
722     case IDC_FILE_LOAD_BUTTON | (BN_CLICKED << 16): {
723     // load
724     // �e�[�}�t�@�C����������
725     OPENFILENAMEW ofn = {};
726     wchar_t theme_file[MAX_PATH];
727    
728     wcscpy_s(theme_file, _countof(theme_file), ts->EtermLookfeel.BGThemeFileW);
729    
730     ofn.lStructSize = get_OPENFILENAME_SIZEW();
731     ofn.hwndOwner = hWnd;
732     ofn.lpstrFile = theme_file;
733     ofn.nMaxFile = _countof(theme_file);
734     ofn.nFilterIndex = 1;
735     ofn.hInstance = dlg_data->hInst;
736     ofn.lpstrDefExt = L"ini";
737     ofn.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
738     ofn.lpstrTitle = L"select theme file";
739    
740     if (GetOpenFileNameW(&ofn)) {
741     BGLoad(theme_file, &dlg_data->bg_theme, &dlg_data->color_tab.color_theme);
742    
743     static const TTMessageBoxInfoW info = {
744     "Tera Term",
745     NULL, L"Info",
746     NULL, L"Preview?",
747     MB_YESNO | MB_ICONWARNING
748     };
749     if (TTMessageBoxW(hWnd, &info, ts->UILanguageFileW) == IDYES) {
750     BGSetColorData(&dlg_data->color_tab.color_theme);
751     BGSet(&dlg_data->bg_theme);
752     //SetColor(&dlg_data->color_tab.color_theme);
753    
754     BGSetupPrimary(TRUE);
755     InvalidateRect(dlg_data->hVTWin, NULL, FALSE);
756     }
757     }
758    
759     break;
760     }
761     case IDC_FILE_SAVE_BUTTON | (BN_CLICKED << 16): {
762     // save
763     // �e�[�}�t�@�C�������o��
764     wchar_t theme_file[MAX_PATH];
765     OPENFILENAMEW ofn = {};
766    
767     theme_file[0] = 0;
768    
769     ofn.lStructSize = get_OPENFILENAME_SIZEW();
770     ofn.hwndOwner = hWnd;
771     ofn.lpstrFile = theme_file;
772     ofn.nMaxFile = _countof(theme_file);
773     //ofn.lpstrFilter = "";
774     ofn.nFilterIndex = 1;
775     ofn.hInstance = dlg_data->hInst;
776     ofn.lpstrDefExt = L"ini";
777     ofn.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
778     ofn.lpstrTitle = L"save theme file";
779    
780     if (GetSaveFileNameW(&ofn)) {
781     LRESULT checked = SendDlgItemMessageA(hWnd, IDC_FILE_SAVE_BG_CHECK, BM_GETCHECK, 0, 0);
782     if (checked & BST_CHECKED) {
783     BGSave(&dlg_data->bg_theme, theme_file);
784     }
785     checked = SendDlgItemMessageA(hWnd, IDC_FILE_SAVE_COLOR_CHECK, BM_GETCHECK, 0, 0);
786     if (checked & BST_CHECKED) {
787     BGSaveColor(&dlg_data->color_tab.color_theme, theme_file);
788     }
789     }
790     break;
791     }
792     case IDC_FILE_SAVE_BG_CHECK:
793     case IDC_FILE_SAVE_COLOR_CHECK: {
794     LRESULT bg = SendDlgItemMessageA(hWnd, IDC_FILE_SAVE_BG_CHECK, BM_GETCHECK, 0, 0);
795     LRESULT color = SendDlgItemMessageA(hWnd, IDC_FILE_SAVE_COLOR_CHECK, BM_GETCHECK, 0, 0);
796     EnableWindow(GetDlgItem(hWnd, IDC_FILE_SAVE_BUTTON),
797     ((bg & BST_CHECKED) || (color & BST_CHECKED)) ? TRUE : FALSE);
798     break;
799     }
800     default:
801     break;
802     }
803     break;
804     }
805     default:
806     return FALSE;
807     }
808     return FALSE;
809     }
810    
811     static UINT CALLBACK FileCallBack(HWND hwnd, UINT uMsg, struct _PROPSHEETPAGEW *ppsp)
812     {
813     UINT ret_val = 0;
814     (void)hwnd;
815     switch (uMsg) {
816     case PSPCB_CREATE:
817     ret_val = 1;
818     break;
819     case PSPCB_RELEASE:
820     free((void *)ppsp->pResource);
821     ppsp->pResource = NULL;
822     break;
823     default:
824     break;
825     }
826     return ret_val;
827     }
828    
829     static HPROPSHEETPAGE ThemeEditorFile(ThemeDlgData* dlg_data)
830     {
831     const int id = IDD_TABSHEET_THEME_FILE;
832    
833     HINSTANCE inst = dlg_data->hInst;
834    
835     PROPSHEETPAGEW_V1 psp = {};
836     psp.dwSize = sizeof(psp);
837     psp.dwFlags = PSP_DEFAULT | PSP_USECALLBACK | PSP_USETITLE | PSP_HASHELP;
838     psp.hInstance = inst;
839     psp.pfnCallback = FileCallBack;
840     psp.pszTitle = L"preview/file"; // TODO lng �t�@�C����������
841     psp.pszTemplate = MAKEINTRESOURCEW(id);
842     #if 1
843     psp.dwFlags |= PSP_DLGINDIRECT;
844     psp.pResource = TTGetDlgTemplate(inst, MAKEINTRESOURCEA(id));
845     #endif
846    
847     psp.pfnDlgProc = FileProc;
848     psp.lParam = (LPARAM)dlg_data;
849    
850     HPROPSHEETPAGE hpsp = CreatePropertySheetPageW((LPPROPSHEETPAGEW)&psp);
851     return hpsp;
852     }
853    
854     //////////////////////////////////////////////////////////////////////////////
855    
856     // Theme dialog
857     class CThemeDlg: public TTCPropSheetDlg
858     {
859     public:
860     CThemeDlg(HINSTANCE hInstance, HWND hParentWnd, ThemeDlgData *dlg_data):
861     TTCPropSheetDlg(hInstance, hParentWnd, dlg_data->pts->UILanguageFileW)
862     {
863     HPROPSHEETPAGE page;
864     page = ThemeEditorFile(dlg_data);
865     AddPage(page);
866     page = ThemeEditorCreate2(dlg_data);
867     AddPage(page);
868     page = ColorThemeEditorCreate2(dlg_data);
869     AddPage(page);
870    
871     SetCaption(L"Theme Editor");
872     }
873     ~CThemeDlg() {
874     ;
875     }
876    
877     private:
878     ;
879     };
880    
881     void ThemeDialog(HINSTANCE hInst, HWND hWnd, TComVar *pcv)
882     {
883     ThemeDlgData *dlg_data = (ThemeDlgData*)calloc(sizeof(*dlg_data), 1);
884     dlg_data->hInst = hInst;
885     dlg_data->pcv = pcv;
886     dlg_data->pts = pcv->ts;
887     dlg_data->hVTWin = pcv->HWin;
888     BGGet(&dlg_data->bg_theme);
889     dlg_data->backup.bg_theme = dlg_data->bg_theme;
890     GetColorData(&dlg_data->color_tab.color_theme);
891     dlg_data->backup.color_theme = dlg_data->color_tab.color_theme;
892    
893     CThemeDlg dlg(hInst, hWnd, dlg_data);
894     INT_PTR r = dlg.DoModal();
895     if (r == 0) {
896     // cancel���A�o�b�N�A�b�v���e������
897     BGSet(&dlg_data->backup.bg_theme);
898     BGSetColorData(&dlg_data->color_tab.color_theme);
899     BGSetupPrimary(TRUE);
900     InvalidateRect(dlg_data->hVTWin, NULL, FALSE);
901     }
902     else if (r >= 1) {
903     // ok����(Changes were saved by the user)
904     BGSet(&dlg_data->bg_theme);
905     BGSetColorData(&dlg_data->color_tab.color_theme);
906     BGSetupPrimary(TRUE);
907     InvalidateRect(dlg_data->hVTWin, NULL, FALSE);
908     }
909    
910     free(dlg_data);
911     }

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