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 10134 - (hide annotations) (download) (as text)
Tue Aug 9 15:11:40 2022 UTC (20 months ago) by zmatsuo
Original Path: trunk/teraterm/teraterm/themedlg.cpp
File MIME type: text/x-c++src
File size: 25854 byte(s)
Theme Editor Dialog を追加

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

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