Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/teraterm/teraterm/themedlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10396 - (show annotations) (download) (as text)
Sun Dec 4 15:29:25 2022 UTC (17 months, 3 weeks ago) by zmatsuo
File MIME type: text/x-c++src
File size: 34919 byte(s)
背景テーマの表示と設定UIを調整

- 色設定で数値ではなくカラーサンプルを表示するようにした
- alpha値をスライダーで設定できるようにした
- コントロールを適宜無効/有効を切り替えるようにした
- 背景画像が不透明の時でも指定色でalpha blendできるようにした
1 /*
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 "helpid.h"
58 #include "vtdisp.h"
59 #include "tmfc.h"
60 #include "tmfc_propdlg.h"
61
62 #include "theme.h"
63 #include "themedlg_res.h"
64 #include "themedlg.h"
65
66 typedef struct ColorSampleDataSt ColorSampleData_t;
67
68 //////////////////////////////////////////////////////////////////////////////
69 typedef struct ColorSampleDataSt {
70 int dummy;
71 WNDPROC OrigProc;
72 HWND hWnd;
73 COLORREF color;
74 } ColorSampleData_t;
75
76 static void DispColorSample(HWND hWnd, COLORREF color)
77 {
78 RECT rect;
79 HDC hDC = GetDC(hWnd);
80 HBRUSH hBrush = CreateSolidBrush(color);
81 GetClientRect(hWnd, &rect);
82 FillRect(hDC, &rect, hBrush);
83 DeleteObject(hBrush);
84 ReleaseDC(hWnd, hDC);
85 }
86
87 static LRESULT CALLBACK ColorSampleProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
88 {
89 ColorSampleData_t *self = (ColorSampleData_t *)GetWindowLongPtr(hWnd, GWLP_USERDATA);
90 LRESULT result;
91
92 result = CallWindowProcW(self->OrigProc, hWnd, msg, wParam, lParam);
93
94 switch (msg) {
95 case WM_PAINT: {
96 DispColorSample(hWnd, self->color);
97 result = TRUE;
98 break;
99 }
100 case WM_NCDESTROY:
101 free(self);
102 SetWindowLongPtr(hWnd, GWLP_USERDATA, 0);
103 break;
104 default:
105 break;
106 }
107 return result;
108 }
109
110 /**
111 * �_�C�A���O�����t���[�����J���[�T���v��������
112 * ColorSampleSetColor()���F����������
113 * �_�C�A���O�������������������I���j��������
114 *
115 */
116 ColorSampleData_t *ColorSampleInit(HWND hDlg, int ID, COLORREF color)
117 {
118 ColorSampleData_t *self = (ColorSampleData_t *)calloc(sizeof(ColorSampleData_t), 1);
119 HWND hWnd = GetDlgItem(hDlg, ID);
120 self->color = color;
121 self->hWnd = hWnd;
122 SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)self);
123 self->OrigProc = (WNDPROC)GetWindowLongPtrW(hWnd, GWLP_WNDPROC);
124 SetWindowLongPtrW(hWnd, GWLP_WNDPROC, (LONG_PTR)ColorSampleProc);
125 return self;
126 }
127
128 /**
129 * �F����������
130 */
131 void ColorSampleSetColor(ColorSampleData_t *cs, COLORREF color)
132 {
133 ColorSampleData_t *self = cs;
134 self->color = color;
135 InvalidateRect(self->hWnd, NULL, FALSE);
136 }
137
138 //////////////////////////////////////////////////////////////////////////////
139
140 typedef struct {
141 // ����
142 HINSTANCE hInst;
143 TComVar *pcv;
144 TTTSet *pts;
145 HWND hVTWin;
146 // file tab
147 struct {
148 int dummy;
149 } FileTab;
150 // bg theme tab
151 struct {
152 ColorSampleData_t *cs_bg;
153 ColorSampleData_t *cs_splane;
154 BGTheme bg_theme;
155 } BGTab;
156 // color theme tab
157 struct {
158 TipWin2 *tipwin;
159 TColorTheme color_theme;
160 } ColorTab;
161 struct {
162 BGTheme bg_theme;
163 TColorTheme color_theme;
164 } Backup;
165 } ThemeDlgData;
166
167 static void SetWindowTextColor(HWND hWnd, COLORREF color)
168 {
169 char str[32];
170 sprintf_s(str, "%02x%02x%02x", GetRValue(color), GetGValue(color), GetBValue(color));
171 SetWindowTextA(hWnd, str);
172 }
173
174 static void SetDlgItemTextColor(HWND hDlg, int ID, COLORREF color)
175 {
176 SetWindowTextColor(GetDlgItem(hDlg, ID), color);
177 }
178
179 static COLORREF GetWindowTextColor(HWND hWnd)
180 {
181 char str[32];
182 unsigned int r, g, b;
183 char elem[3];
184
185 GetWindowTextA(hWnd, str, _countof(str));
186
187 memcpy(elem, &str[0], 2);
188 elem[2] = 0;
189 r = 0;
190 sscanf_s(elem, "%x", &r);
191
192 memcpy(elem, &str[2], 2);
193 elem[2] = 0;
194 g = 0;
195 sscanf_s(elem, "%x", &g);
196
197 memcpy(elem, &str[4], 2);
198 elem[2] = 0;
199 b = 0;
200 sscanf_s(elem, "%x", &b);
201
202 return RGB(r, g, b);
203 }
204
205 static COLORREF GetDlgItemTextColor(HWND hDlg, int ID)
206 {
207 return GetWindowTextColor(GetDlgItem(hDlg, ID));
208 }
209
210 static void ResetControls(HWND hWnd, ThemeDlgData* dlg_data)
211 {
212 const BGTheme *bg_theme = &dlg_data->BGTab.bg_theme;
213
214 // bg image
215 SendDlgItemMessageA(hWnd, IDC_BGIMG_CHECK, BM_SETCHECK, bg_theme->BGDest.enable, 0);
216 SetDlgItemTextW(hWnd, IDC_BGIMG_EDIT, bg_theme->BGDest.file);
217 {
218 LRESULT count = SendDlgItemMessageA(hWnd, IDC_BGIMG_COMBO, CB_GETCOUNT, 0, 0);
219 int sel = 0;
220 int i;
221 for (i = 0; i < count; i++) {
222 BG_PATTERN pattern = (BG_PATTERN)SendDlgItemMessageW(hWnd, IDC_BGIMG_COMBO, CB_GETITEMDATA, i, 0);
223 if (pattern == bg_theme->BGDest.pattern) {
224 sel = i;
225 break;
226 }
227 }
228 SendDlgItemMessageA(hWnd, IDC_BGIMG_COMBO, CB_SETCURSEL, sel, 0);
229 }
230 SendDlgItemMessageA(hWnd, IDC_BGIMG_ALPHA_SLIDER, TBM_SETPOS, TRUE, bg_theme->BGDest.alpha);
231 ColorSampleSetColor(dlg_data->BGTab.cs_bg, bg_theme->BGDest.color);
232
233 // wall paper
234 SendDlgItemMessageA(hWnd, IDC_WALLPAPER_CHECK, BM_SETCHECK, bg_theme->BGSrc1.enable, 0);
235
236 // simple color plane
237 SendDlgItemMessageA(hWnd, IDC_SIMPLE_COLOR_PLANE_CHECK, BM_SETCHECK, bg_theme->BGSrc2.enable, 0);
238 SendDlgItemMessageA(hWnd, IDC_SIMPLE_COLOR_PLANE_ALPHA_SLIDER, TBM_SETPOS, TRUE, bg_theme->BGSrc2.alpha);
239 ColorSampleSetColor(dlg_data->BGTab.cs_splane, bg_theme->BGSrc2.color);
240 }
241
242 static void ControlEnable(HWND hWnd)
243 {
244 static const int scp_controls[] = {
245 IDC_SIMPLE_COLOR_PLANE_COLOR_TITLE,
246 IDC_SIMPLE_COLOR_PLANE_SAMPLE,
247 IDC_SIMPLE_COLOR_PLANE_BUTTON,
248 IDC_SIMPLE_COLOR_PLANE_ALPHA_TITLE,
249 IDC_SIMPLE_COLOR_PLANE_ALPHA_SLIDER,
250 };
251 static const int bg_controls[] = {
252 IDC_BGIMG_FILE_TITLE,
253 IDC_BGIMG_EDIT,
254 IDC_BGIMG_BUTTON,
255 IDC_BGIMG_PATTERN_TITLE,
256 IDC_BGIMG_COMBO,
257 IDC_BGIMG_COLOR_TITLE,
258 IDC_BGIMG_COLOR_SAMPLE,
259 IDC_BGIMG_COLOR_BUTTON,
260 IDC_BGIMG_ALPHA_TITLE,
261 IDC_BGIMG_ALPHA_SLIDER
262 };
263 int i;
264 BOOL enable;
265
266 BOOL scp_enable = (BOOL)SendDlgItemMessageA(hWnd, IDC_SIMPLE_COLOR_PLANE_CHECK, BM_GETCHECK, 0, 0);
267 BOOL bg_enable = (BOOL)SendDlgItemMessageA(hWnd, IDC_BGIMG_CHECK, BM_GETCHECK, 0, 0);
268 BOOL wp_enable = (BOOL)SendDlgItemMessageA(hWnd, IDC_WALLPAPER_CHECK, BM_GETCHECK, 0, 0);
269
270 // Simple color plane
271 enable = scp_enable;
272 for (i = 0; i < _countof(scp_controls); i++) {
273 EnableWindow(GetDlgItem(hWnd, scp_controls[i]), enable);
274 }
275 enable = scp_enable && (bg_enable || wp_enable) ? TRUE : FALSE;
276 EnableWindow(GetDlgItem(hWnd, IDC_SIMPLE_COLOR_PLANE_ALPHA_TITLE), enable);
277 EnableWindow(GetDlgItem(hWnd, IDC_SIMPLE_COLOR_PLANE_ALPHA_SLIDER), enable);
278
279 // BG image
280 enable = bg_enable;
281 for (i = 0; i < _countof(bg_controls); i++) {
282 EnableWindow(GetDlgItem(hWnd, bg_controls[i]), enable);
283 }
284 }
285
286 static void ReadFromDialog(HWND hWnd, BGTheme* bg_theme)
287 {
288 LRESULT checked;
289 LRESULT index;
290
291 // bg_image
292 checked = SendDlgItemMessageA(hWnd, IDC_BGIMG_CHECK, BM_GETCHECK, 0, 0);
293 bg_theme->BGDest.enable = checked & BST_CHECKED;
294 GetDlgItemTextW(hWnd, IDC_BGIMG_EDIT, bg_theme->BGDest.file, _countof(bg_theme->BGDest.file));
295 index = SendDlgItemMessageA(hWnd, IDC_BGIMG_COMBO, CB_GETCURSEL, 0, 0);
296 bg_theme->BGDest.pattern = (BG_PATTERN)SendDlgItemMessageA(hWnd, IDC_BGIMG_COMBO, CB_GETITEMDATA, index, 0);
297 bg_theme->BGDest.alpha = (BYTE)SendDlgItemMessageA(hWnd, IDC_BGIMG_ALPHA_SLIDER, TBM_GETPOS, 0, 0);
298
299 // wall paper
300 checked = SendDlgItemMessageA(hWnd, IDC_WALLPAPER_CHECK, BM_GETCHECK, 0, 0);
301 bg_theme->BGSrc1.enable = checked & BST_CHECKED;
302
303 // simple color plane
304 checked = SendDlgItemMessageA(hWnd, IDC_SIMPLE_COLOR_PLANE_CHECK, BM_GETCHECK, 0, 0);
305 bg_theme->BGSrc2.enable = checked & BST_CHECKED;
306 bg_theme->BGSrc2.alpha = (BYTE)SendDlgItemMessageA(hWnd, IDC_SIMPLE_COLOR_PLANE_ALPHA_SLIDER, TBM_GETPOS, 0, 0);
307 }
308
309 static BOOL ChooseColor(HWND hWnd, COLORREF *color_ptr)
310 {
311 static COLORREF CustColors[16];
312 CHOOSECOLORA cc = {};
313 cc.lStructSize = sizeof(cc);
314 cc.hwndOwner = hWnd;
315 cc.rgbResult = *color_ptr;
316 cc.lpCustColors = CustColors;
317 cc.Flags = CC_FULLOPEN | CC_RGBINIT;
318 if (ChooseColorA(&cc)) {
319 *color_ptr = cc.rgbResult;
320 return TRUE;
321 }
322 return FALSE;
323 }
324
325 static INT_PTR CALLBACK BGThemeProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
326 {
327 ThemeDlgData* dlg_data = (ThemeDlgData*)GetWindowLongPtr(hWnd, DWLP_USER);
328
329 switch (msg) {
330 case WM_INITDIALOG: {
331 static const DlgTextInfo TextInfos[] = {
332 { IDC_BGIMG_CHECK, "DLG_THEME_BG_IMAGEFILE" },
333 };
334 dlg_data = (ThemeDlgData*)(((PROPSHEETPAGEW_V1 *)lp)->lParam);
335 SetWindowLongPtr(hWnd, DWLP_USER, (LONG_PTR)dlg_data);
336
337 SetDlgTextsW(hWnd, TextInfos, _countof(TextInfos), dlg_data->pts->UILanguageFileW);
338
339 SendDlgItemMessageA(hWnd, IDC_SIMPLE_COLOR_PLANE_ALPHA_SLIDER, TBM_SETRANGE, TRUE, MAKELONG(0, 255));
340 SendDlgItemMessageA(hWnd, IDC_BGIMG_ALPHA_SLIDER, TBM_SETRANGE, TRUE, MAKELONG(0, 255));
341
342 for (int i = 0;; i++) {
343 LRESULT index;
344 const BG_PATTERN_ST *st = ThemeBGPatternList(i);
345 if (st == NULL) {
346 break;
347 }
348 index = SendDlgItemMessageW(hWnd, IDC_BGIMG_COMBO, CB_ADDSTRING, 0, (LPARAM)st->str);
349 SendDlgItemMessageW(hWnd, IDC_BGIMG_COMBO, CB_SETITEMDATA, index, st->id);
350 }
351
352 dlg_data->BGTab.cs_bg =
353 ColorSampleInit(hWnd, IDC_BGIMG_COLOR_SAMPLE, dlg_data->BGTab.bg_theme.BGDest.color);
354 dlg_data->BGTab.cs_splane =
355 ColorSampleInit(hWnd, IDC_SIMPLE_COLOR_PLANE_SAMPLE, dlg_data->BGTab.bg_theme.BGSrc2.color);
356 ResetControls(hWnd, dlg_data);
357
358 return TRUE;
359 break;
360 }
361 case WM_COMMAND: {
362 switch (wp) {
363 case IDC_BGIMG_BUTTON | (BN_CLICKED << 16): {
364 // �����t�@�C���I��
365 OPENFILENAMEW ofn = {};
366 wchar_t bg_file[MAX_PATH];
367 wchar_t *bg_file_in;
368
369 hGetDlgItemTextW(hWnd, IDC_BGIMG_EDIT, &bg_file_in);
370 wcscpy_s(bg_file, _countof(bg_file), bg_file_in);
371 free(bg_file_in);
372
373 ofn.lStructSize = get_OPENFILENAME_SIZEW();
374 ofn.hwndOwner = hWnd;
375 ofn.lpstrFile = bg_file;
376 ofn.nMaxFile = _countof(bg_file);
377 //ofn.lpstrFilter = "";
378 ofn.nFilterIndex = 1;
379 ofn.hInstance = dlg_data->hInst;
380 ofn.lpstrDefExt = L"jpg";
381 ofn.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
382 ofn.lpstrTitle = L"select bg image file";
383
384 if (GetOpenFileNameW(&ofn)) {
385 SetDlgItemTextW(hWnd, IDC_BGIMG_EDIT, bg_file);
386 }
387 break;
388 }
389 case IDC_BGIMG_COLOR_BUTTON | (BN_CLICKED << 16):
390 if (ChooseColor(hWnd, &dlg_data->BGTab.bg_theme.BGDest.color)) {
391 ColorSampleSetColor(dlg_data->BGTab.cs_bg,
392 dlg_data->BGTab.bg_theme.BGDest.color);
393 }
394 break;
395 case IDC_SIMPLE_COLOR_PLANE_BUTTON | (BN_CLICKED << 16):
396 if (ChooseColor(hWnd, &dlg_data->BGTab.bg_theme.BGSrc2.color)) {
397 ColorSampleSetColor(dlg_data->BGTab.cs_splane,
398 dlg_data->BGTab.bg_theme.BGSrc2.color);
399 }
400 break;
401 case IDC_SIMPLE_COLOR_PLANE_CHECK | (BN_CLICKED << 16):
402 case IDC_BGIMG_CHECK | (BN_CLICKED << 16):
403 case IDC_WALLPAPER_CHECK | (BN_CLICKED << 16): {
404 ControlEnable(hWnd);
405 break;
406 }
407 default:
408 break;
409 }
410 break;
411 }
412 case WM_NOTIFY: {
413 NMHDR *nmhdr = (NMHDR *)lp;
414 switch (nmhdr->code) {
415 case PSN_APPLY: {
416 break;
417 }
418 case PSN_HELP:
419 OpenHelpCV(dlg_data->pcv, HH_HELP_CONTEXT, HlpMenuSetupAdditionalTheme);
420 break;
421 case PSN_KILLACTIVE: {
422 ReadFromDialog(hWnd, &dlg_data->BGTab.bg_theme);
423 break;
424 }
425 case PSN_SETACTIVE: {
426 ResetControls(hWnd, dlg_data);
427 break;
428 }
429 default:
430 break;
431 }
432 break;
433 }
434 default:
435 return FALSE;
436 }
437 return FALSE;
438 }
439
440 static UINT CALLBACK BGCallBack(HWND hwnd, UINT uMsg, struct _PROPSHEETPAGEW *ppsp)
441 {
442 UINT ret_val = 0;
443 (void)hwnd;
444 switch (uMsg) {
445 case PSPCB_CREATE:
446 ret_val = 1;
447 break;
448 case PSPCB_RELEASE:
449 free((void *)ppsp->pResource);
450 ppsp->pResource = NULL;
451 break;
452 default:
453 break;
454 }
455 return ret_val;
456 }
457
458 static HPROPSHEETPAGE ThemeEditorCreate(ThemeDlgData *dlg_data)
459 {
460 const int id = IDD_TABSHEET_BG_THEME_EDITOR;
461 HINSTANCE inst = dlg_data->hInst;
462
463 wchar_t *title;
464 GetI18nStrWW("Tera Term", "DLG_THEME_BG_TITLE",
465 L"Background", dlg_data->pts->UILanguageFileW, &title);
466
467 PROPSHEETPAGEW_V1 psp = {};
468 psp.dwSize = sizeof(psp);
469 psp.dwFlags = PSP_DEFAULT | PSP_USECALLBACK | PSP_USETITLE | PSP_HASHELP;
470 psp.hInstance = inst;
471 psp.pfnCallback = BGCallBack;
472 psp.pszTitle = title;
473 psp.pszTemplate = MAKEINTRESOURCEW(id);
474 psp.dwFlags |= PSP_DLGINDIRECT;
475 psp.pResource = TTGetDlgTemplate(inst, MAKEINTRESOURCEA(id));
476
477 psp.pfnDlgProc = BGThemeProc;
478 psp.lParam = (LPARAM)dlg_data;
479
480 HPROPSHEETPAGE hpsp = CreatePropertySheetPageW((LPPROPSHEETPAGEW)&psp);
481 free(title);
482 return hpsp;
483 }
484
485 //////////////////////////////////////////////////////////////////////////////
486
487 static struct {
488 const wchar_t *name;
489 COLORREF color;
490 } list[] = {
491 { L"VTColor Fore", RGB(0,0,0) },
492 { L"VTColor Back", RGB(0,0,0) },
493 { L"VTBoldColor Fore", RGB(0,0,0) },
494 { L"VTBoldColor Back", RGB(0,0,0) },
495 { L"VTUnderlineColor Fore", RGB(0,0,0) },
496 { L"VTUnderlineColor Back", RGB(0,0,0) },
497 { L"VTBlinkColor Fore", RGB(0,0,0) },
498 { L"VTBlinkColor Back", RGB(0,0,0) },
499 { L"VTReverseColor Fore", RGB(0,0,0) },
500 { L"VTReverseColor Back", RGB(0,0,0) },
501 { L"URLColor Fore", RGB(0,0,0) },
502 { L"URLColor Back", RGB(0,0,0) },
503 { L"ANSI 0 / Black", RGB(0,0,0) },
504 { L"ANSI 1 / Red", RGB(197,15,31) },
505 { L"ANSI 2 / Green", RGB(19, 161, 14) },
506 { L"ANSI 3 / Yellow", RGB(193, 156, 0) },
507 { L"ANSI 4 / Blue", RGB(0, 55, 218) },
508 { L"ANSI 5 / Magenta", RGB(136, 23, 152) },
509 { L"ANSI 6 / Cyan", RGB(58, 150, 221) },
510 { L"ANSI 7 / White", RGB(204, 204, 204) },
511 { L"ANSI 8 / Bright Black (Gray)", RGB(118, 118, 118) },
512 { L"ANSI 9 / Bright Red", RGB(231, 72, 86) },
513 { L"ANSI 10 / Bright Green", RGB(22, 198, 12) },
514 { L"ANSI 11 / Bright Yellow", RGB(249, 241, 165) },
515 { L"ANSI 12 / Bright Blue", RGB(59, 120, 255) },
516 { L"ANSI 13 / Bright Magenta", RGB(180, 0, 158) },
517 { L"ANSI 14 / Bright Cyan", RGB(97, 214, 214) },
518 { L"ANSI 15 / Bright White", RGB(242, 242, 242) },
519 };
520
521 static void SetColor(const TColorTheme *data)
522 {
523 list[0].color = data->vt.fg;
524 list[1].color = data->vt.bg;
525 list[2].color = data->bold.fg;
526 list[3].color = data->bold.bg;
527 list[4].color = data->underline.fg;
528 list[5].color = data->underline.bg;
529 list[6].color = data->blink.fg;
530 list[7].color = data->blink.bg;
531 list[8].color = data->reverse.fg;
532 list[9].color = data->reverse.bg;
533 list[10].color = data->url.fg;
534 list[11].color = data->url.bg;
535 for (int i = 0; i < 16; i++) {
536 list[12+i].color = data->ansicolor.color[i];
537 }
538 }
539
540 static void RestoreColor(TColorTheme *data)
541 {
542 data->vt.fg = list[0].color;
543 data->vt.bg = list[1].color;
544 data->bold.fg = list[2].color;
545 data->bold.bg = list[3].color;
546 data->underline.fg = list[4].color;
547 data->underline.bg = list[5].color;
548 data->blink.fg = list[6].color;
549 data->blink.bg = list[7].color;
550 data->reverse.fg = list[8].color;
551 data->reverse.bg = list[9].color;
552 data->url.fg = list[10].color;
553 data->url.bg = list[11].color;
554 for (int i = 0; i < 16; i++) {
555 data->ansicolor.color[i] = list[12+i].color;
556 }
557 }
558
559 static void SetColorListCtrlValue(HWND hWndList, int y)
560 {
561 LVITEMW item;
562
563 const COLORREF c = list[y].color;
564 const int r = GetRValue(c);
565 const int g = GetGValue(c);
566 const int b = GetBValue(c);
567
568 wchar_t color_str[64];
569 swprintf_s(color_str, L"#%02x%02x%02x", r,g,b);
570 item.mask = LVIF_TEXT;
571 item.iItem = y;
572 item.iSubItem = 2;
573 item.pszText = color_str;
574 SendMessage(hWndList, LVM_SETITEMW, 0, (LPARAM)&item);
575
576 swprintf_s(color_str, L"%d,%d,%d", r,g,b);
577 item.iSubItem = 3;
578 item.pszText = color_str;
579 SendMessage(hWndList, LVM_SETITEMW, 0, (LPARAM)&item);
580 }
581
582 static void SetColorListCtrl(HWND hWnd)
583 {
584 HWND hWndList = GetDlgItem(hWnd, IDC_COLOR_LIST);
585 ListView_SetExtendedListViewStyleEx(hWndList, LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
586
587 SendMessage(hWndList, LVM_DELETEALLITEMS, 0, 0);
588
589 for (int y = 0; y< _countof(list); y++) {
590 LVITEMW item;
591 item.mask = LVIF_TEXT;
592 item.iItem = y;
593 item.iSubItem = 0;
594 item.pszText = (LPWSTR)list[y].name;
595 SendMessage(hWndList, LVM_INSERTITEMW, 0, (LPARAM)&item);
596
597 item.iSubItem = 1;
598 item.pszText = NULL;
599 SendMessage(hWndList, LVM_SETITEMW, 0, (LPARAM)&item);
600
601 SetColorListCtrlValue(hWndList, y);
602 }
603
604 // ��������
605 for (int i = 0; i < 4; i++) {
606 ListView_SetColumnWidth(hWndList, i, i == 1 ? LVSCW_AUTOSIZE_USEHEADER : LVSCW_AUTOSIZE);
607 }
608 }
609
610 static INT_PTR CALLBACK ColorThemeProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
611 {
612 static const DlgTextInfo TextInfos[] = {
613 {IDC_COLOR_DEFAULT_BUTTON, "BTN_DEFAULT"},
614 };
615 ThemeDlgData *dlg_data = (ThemeDlgData *)GetWindowLongPtr(hWnd, DWLP_USER);
616 TTTSet *ts = dlg_data == NULL ? NULL : dlg_data->pts;
617
618 switch (msg) {
619 case WM_INITDIALOG: {
620 dlg_data = (ThemeDlgData *)(((PROPSHEETPAGEW_V1 *)lp)->lParam);
621 ts = dlg_data->pts;
622 SetWindowLongPtr(hWnd, DWLP_USER, (LONG_PTR)dlg_data);
623 SetDlgTextsW(hWnd, TextInfos, _countof(TextInfos), ts->UILanguageFileW);
624
625 dlg_data->ColorTab.tipwin = TipWin2Create(NULL, hWnd);
626 TipWin2SetTextW(dlg_data->ColorTab.tipwin, IDC_COLOR_LIST, L"Double click to open color picker");
627
628 {
629 HWND hWndList = GetDlgItem(hWnd, IDC_COLOR_LIST);
630 LV_COLUMNA lvcol;
631 lvcol.mask = LVCF_TEXT | LVCF_SUBITEM;
632 lvcol.pszText = (LPSTR)"name";
633 lvcol.iSubItem = 0;
634 //ListView_InsertColumn(hWndList, 0, &lvcol);
635 SendMessage(hWndList, LVM_INSERTCOLUMNA, 0, (LPARAM)&lvcol);
636
637 lvcol.pszText = (LPSTR)"color";
638 lvcol.iSubItem = 1;
639 //ListView_InsertColumn(hWndList, 1, &lvcol);
640 SendMessage(hWndList, LVM_INSERTCOLUMNA, 1, (LPARAM)&lvcol);
641
642 lvcol.pszText = (LPSTR)"value(#RRGGBB)";
643 lvcol.iSubItem = 2;
644 //ListView_InsertColumn(hWndList, 1, &lvcol);
645 SendMessage(hWndList, LVM_INSERTCOLUMNA, 2, (LPARAM)&lvcol);
646
647 lvcol.pszText = (LPSTR)"value(R, G, B)";
648 lvcol.iSubItem = 3;
649 //ListView_InsertColumn(hWndList, 1, &lvcol);
650 SendMessage(hWndList, LVM_INSERTCOLUMNA, 3, (LPARAM)&lvcol);
651 }
652
653 SetColor(&dlg_data->ColorTab.color_theme);
654 SetColorListCtrl(hWnd);
655 break;
656 }
657 case WM_COMMAND: {
658 switch (wp) {
659 case IDC_COLOR_DEFAULT_BUTTON | (BN_CLICKED << 16): {
660 // �f�t�H���g
661 ThemeGetColorDefault(&dlg_data->ColorTab.color_theme);
662 SetColor(&dlg_data->ColorTab.color_theme);
663 SetColorListCtrl(hWnd);
664 break;
665 }
666 default:
667 break;
668 }
669 break;
670 }
671 case WM_NOTIFY: {
672 NMHDR *nmhdr = (NMHDR *)lp;
673 switch (nmhdr->idFrom) {
674 case IDC_COLOR_LIST: {
675 NMLISTVIEW *nmlist = (NMLISTVIEW *)lp;
676 switch (nmlist->hdr.code) {
677 case NM_CUSTOMDRAW: {
678 NMLVCUSTOMDRAW *lpLvCustomDraw = (LPNMLVCUSTOMDRAW)lp;
679 switch (lpLvCustomDraw->nmcd.dwDrawStage) {
680 case CDDS_PREPAINT: {
681 // go CDDS_ITEMPREPAINT stage
682 SetWindowLongW(hWnd, DWLP_MSGRESULT, (LONG)CDRF_NOTIFYITEMDRAW);
683 return TRUE;
684 }
685 case CDDS_ITEMPREPAINT: {
686 // go CDDS_SUBITEM stage
687 SetWindowLongW(hWnd, DWLP_MSGRESULT, (LONG)CDRF_NOTIFYSUBITEMDRAW);
688 return TRUE;
689 }
690 case (CDDS_ITEMPREPAINT | CDDS_SUBITEM):
691 case CDDS_SUBITEM: {
692 // �s�����w��
693 // if (lpLvCustomDraw->nmcd.dwItemSpec == 1 && lpLvCustomDraw->iSubItem == 1) {
694 if (lpLvCustomDraw->iSubItem == 1) {
695 lpLvCustomDraw->clrText = RGB(0x80, 0x80, 0x80);
696 lpLvCustomDraw->clrTextBk = list[lpLvCustomDraw->nmcd.dwItemSpec].color;
697 }
698 else
699 {
700 // �F�����X�������Z�����f�t�H���g�F���w��
701 // �������w�������������A�F�����X���������~���A�����F��������������
702
703 // �������f�t�H���g�F
704 lpLvCustomDraw->clrText = GetSysColor(COLOR_WINDOWTEXT);
705
706 // �w�i���f�t�H���g�F
707 lpLvCustomDraw->clrTextBk = GetSysColor(COLOR_WINDOW);
708 }
709 SetWindowLongW(hWnd, DWLP_MSGRESULT, (LONG)CDRF_NEWFONT);
710 return TRUE;
711 }
712 default:
713 SetWindowLongW(hWnd, DWLP_MSGRESULT, (LONG)CDRF_DODEFAULT);
714 return TRUE;
715 }
716 break;
717 }
718 // case NM_CLICK:
719 case NM_DBLCLK:
720 case NM_RCLICK: {
721 static COLORREF CustColors[16]; // TODO �����I���F�����K�v?
722 int i = nmlist->iItem;
723 CHOOSECOLORA cc = {};
724 cc.lStructSize = sizeof(cc);
725 cc.hwndOwner = hWnd;
726 cc.rgbResult = list[i].color;
727 cc.lpCustColors = CustColors;
728 cc.Flags = CC_FULLOPEN | CC_RGBINIT;
729 if (ChooseColorA(&cc)) {
730 list[i].color = cc.rgbResult;
731 SetColorListCtrlValue(nmlist->hdr.hwndFrom, i);
732 InvalidateRect(nmlist->hdr.hwndFrom, NULL, TRUE);
733 }
734 break;
735 }
736 default:
737 break;
738 }
739 break;
740 }
741 default:
742 break;
743 }
744 switch (nmhdr->code) {
745 case PSN_APPLY: {
746 break;
747 }
748 case PSN_HELP:
749 OpenHelpCV(dlg_data->pcv, HH_HELP_CONTEXT, HlpMenuSetupAdditionalTheme);
750 break;
751 case PSN_KILLACTIVE: {
752 RestoreColor(&dlg_data->ColorTab.color_theme);
753 break;
754 }
755 case PSN_SETACTIVE: {
756 SetColor(&dlg_data->ColorTab.color_theme);
757 SetColorListCtrl(hWnd);
758 break;
759 }
760 case TTN_POP:
761 // 1�������\�����������A����������������
762 TipWin2SetTextW(dlg_data->ColorTab.tipwin, IDC_COLOR_LIST, NULL);
763 break;
764 default:
765 break;
766 }
767 break;
768 }
769 case WM_DESTROY:
770 TipWin2Destroy(dlg_data->ColorTab.tipwin);
771 dlg_data->ColorTab.tipwin = NULL;
772 break;
773
774 default:
775 return FALSE;
776 }
777 return FALSE;
778 }
779
780 static UINT CALLBACK ColorCallBack(HWND hwnd, UINT uMsg, struct _PROPSHEETPAGEW *ppsp)
781 {
782 (void)hwnd;
783 UINT ret_val = 0;
784 switch (uMsg) {
785 case PSPCB_CREATE:
786 ret_val = 1;
787 break;
788 case PSPCB_RELEASE:
789 free((void *)ppsp->pResource);
790 ppsp->pResource = NULL;
791 break;
792 default:
793 break;
794 }
795 return ret_val;
796 }
797
798 static HPROPSHEETPAGE ColorThemeEditorCreate(ThemeDlgData *dlg_data)
799 {
800 const int id = IDD_TABSHEET_COLOR_THEME_EDITOR;
801 HINSTANCE inst = dlg_data->hInst;
802
803 wchar_t *title;
804 GetI18nStrWW("Tera Term", "DLG_THEME_COLOR_TITLE",
805 L"color", dlg_data->pts->UILanguageFileW, &title);
806
807 PROPSHEETPAGEW_V1 psp = {};
808 psp.dwSize = sizeof(psp);
809 psp.dwFlags = PSP_DEFAULT | PSP_USECALLBACK | PSP_USETITLE | PSP_HASHELP;
810 psp.hInstance = inst;
811 psp.pfnCallback = ColorCallBack;
812 psp.pszTitle = title;
813 psp.pszTemplate = MAKEINTRESOURCEW(id);
814 #if 1
815 psp.dwFlags |= PSP_DLGINDIRECT;
816 psp.pResource = TTGetDlgTemplate(inst, MAKEINTRESOURCEA(id));
817 #endif
818
819 psp.pfnDlgProc = ColorThemeProc;
820 psp.lParam = (LPARAM)dlg_data;
821
822 HPROPSHEETPAGE hpsp = CreatePropertySheetPageW((LPPROPSHEETPAGEW)&psp);
823 free(title);
824 return hpsp;
825 }
826
827 //////////////////////////////////////////////////////////////////////////////
828
829 static INT_PTR CALLBACK FileProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
830 {
831 static const DlgTextInfo TextInfos[] = {
832 { IDC_FILE_LOAD_BUTTON, "DLG_THEME_PREVIEW_FILE_LOAD" },
833 { IDC_FILE_SAVE_BUTTON, "DLG_THEME_PREVIEW_FILE_SAVE" },
834 };
835 ThemeDlgData *dlg_data = (ThemeDlgData *)GetWindowLongPtr(hWnd, DWLP_USER);
836 TTTSet *ts = dlg_data == NULL ? NULL : dlg_data->pts;
837
838 switch (msg) {
839 case WM_INITDIALOG: {
840 dlg_data = (ThemeDlgData *)(((PROPSHEETPAGEW_V1 *)lp)->lParam);
841 ts = dlg_data->pts;
842 SetWindowLongPtr(hWnd, DWLP_USER, (LONG_PTR)dlg_data);
843 SetDlgTextsW(hWnd, TextInfos, _countof(TextInfos), dlg_data->pts->UILanguageFileW);
844
845 EnableWindow(GetDlgItem(hWnd, IDC_FILE_SAVE_BUTTON), FALSE);
846 return TRUE;
847 break;
848 }
849 case WM_NOTIFY: {
850 NMHDR *nmhdr = (NMHDR *)lp;
851 switch (nmhdr->code) {
852 case PSN_APPLY: {
853 // OK
854 #if 0
855 TipWin2Destroy(dlg_data->tipwin);
856 dlg_data->tipwin = NULL;
857 #endif
858 break;
859 }
860 case PSN_HELP:
861 OpenHelpCV(dlg_data->pcv, HH_HELP_CONTEXT, HlpMenuSetupAdditionalTheme);
862 break;
863 default:
864 break;
865 }
866 break;
867 }
868 case WM_COMMAND: {
869 switch (wp) {
870 case IDC_FILE_UNDO_BUTTON | (BN_CLICKED << 16): {
871 // undo,��������
872 dlg_data->BGTab.bg_theme = dlg_data->Backup.bg_theme;
873 dlg_data->ColorTab.color_theme = dlg_data->Backup.color_theme;
874 goto set;
875 break;
876 }
877 case IDC_FILE_PREVIEW_BUTTON | (BN_CLICKED << 16): {
878 set:
879 // preview
880 ThemeSetBG(&dlg_data->BGTab.bg_theme);
881 ThemeSetColor(&dlg_data->ColorTab.color_theme);
882 BGSetupPrimary(TRUE);
883 InvalidateRect(dlg_data->hVTWin, NULL, FALSE);
884 break;
885 }
886 case IDC_FILE_LOAD_BUTTON | (BN_CLICKED << 16): {
887 // load
888 // �e�[�}�t�@�C����������
889 OPENFILENAMEW ofn = {};
890 wchar_t theme_file[MAX_PATH];
891
892 if (ts->EtermLookfeel.BGThemeFileW != NULL) {
893 wcscpy_s(theme_file, _countof(theme_file), ts->EtermLookfeel.BGThemeFileW);
894 }
895 else {
896 theme_file[0] = 0;
897 }
898
899 ofn.lStructSize = get_OPENFILENAME_SIZEW();
900 ofn.hwndOwner = hWnd;
901 ofn.lpstrFile = theme_file;
902 ofn.nMaxFile = _countof(theme_file);
903 ofn.nFilterIndex = 1;
904 ofn.hInstance = dlg_data->hInst;
905 ofn.lpstrDefExt = L"ini";
906 ofn.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
907 ofn.lpstrTitle = L"select theme file";
908
909 if (GetOpenFileNameW(&ofn)) {
910 ThemeLoad(theme_file, &dlg_data->BGTab.bg_theme, &dlg_data->ColorTab.color_theme);
911
912 static const TTMessageBoxInfoW info = {
913 "Tera Term",
914 NULL, L"Info",
915 NULL, L"Preview?",
916 MB_YESNO | MB_ICONWARNING
917 };
918 if (TTMessageBoxW(hWnd, &info, ts->UILanguageFileW) == IDYES) {
919 ThemeSetColor(&dlg_data->ColorTab.color_theme);
920 ThemeSetBG(&dlg_data->BGTab.bg_theme);
921
922 BGSetupPrimary(TRUE);
923 InvalidateRect(dlg_data->hVTWin, NULL, FALSE);
924 }
925 }
926
927 break;
928 }
929 case IDC_FILE_SAVE_BUTTON | (BN_CLICKED << 16): {
930 // save
931 // �e�[�}�t�@�C�������o��
932 wchar_t theme_file[MAX_PATH];
933 OPENFILENAMEW ofn = {};
934
935 theme_file[0] = 0;
936
937 ofn.lStructSize = get_OPENFILENAME_SIZEW();
938 ofn.hwndOwner = hWnd;
939 ofn.lpstrFile = theme_file;
940 ofn.nMaxFile = _countof(theme_file);
941 //ofn.lpstrFilter = "";
942 ofn.nFilterIndex = 1;
943 ofn.hInstance = dlg_data->hInst;
944 ofn.lpstrDefExt = L"ini";
945 ofn.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
946 ofn.lpstrTitle = L"save theme file";
947
948 if (GetSaveFileNameW(&ofn)) {
949 LRESULT checked = SendDlgItemMessageA(hWnd, IDC_FILE_SAVE_BG_CHECK, BM_GETCHECK, 0, 0);
950 if (checked & BST_CHECKED) {
951 ThemeSaveBG(&dlg_data->BGTab.bg_theme, theme_file);
952 }
953 checked = SendDlgItemMessageA(hWnd, IDC_FILE_SAVE_COLOR_CHECK, BM_GETCHECK, 0, 0);
954 if (checked & BST_CHECKED) {
955 ThemeSaveColor(&dlg_data->ColorTab.color_theme, theme_file);
956 }
957 }
958 break;
959 }
960 case IDC_FILE_SAVE_BG_CHECK:
961 case IDC_FILE_SAVE_COLOR_CHECK: {
962 LRESULT bg = SendDlgItemMessageA(hWnd, IDC_FILE_SAVE_BG_CHECK, BM_GETCHECK, 0, 0);
963 LRESULT color = SendDlgItemMessageA(hWnd, IDC_FILE_SAVE_COLOR_CHECK, BM_GETCHECK, 0, 0);
964 EnableWindow(GetDlgItem(hWnd, IDC_FILE_SAVE_BUTTON),
965 ((bg & BST_CHECKED) || (color & BST_CHECKED)) ? TRUE : FALSE);
966 break;
967 }
968 default:
969 break;
970 }
971 break;
972 }
973 default:
974 return FALSE;
975 }
976 return FALSE;
977 }
978
979 static UINT CALLBACK FileCallBack(HWND hwnd, UINT uMsg, struct _PROPSHEETPAGEW *ppsp)
980 {
981 UINT ret_val = 0;
982 (void)hwnd;
983 switch (uMsg) {
984 case PSPCB_CREATE:
985 ret_val = 1;
986 break;
987 case PSPCB_RELEASE:
988 free((void *)ppsp->pResource);
989 ppsp->pResource = NULL;
990 break;
991 default:
992 break;
993 }
994 return ret_val;
995 }
996
997 static HPROPSHEETPAGE ThemeEditorFile(ThemeDlgData* dlg_data)
998 {
999 const int id = IDD_TABSHEET_THEME_FILE;
1000
1001 HINSTANCE inst = dlg_data->hInst;
1002
1003 wchar_t *title;
1004 GetI18nStrWW("Tera Term", "DLG_THEME_PREVIEW_FILE_TITLE",
1005 L"preview/file", dlg_data->pts->UILanguageFileW, &title);
1006
1007 PROPSHEETPAGEW_V1 psp = {};
1008 psp.dwSize = sizeof(psp);
1009 psp.dwFlags = PSP_DEFAULT | PSP_USECALLBACK | PSP_USETITLE | PSP_HASHELP;
1010 psp.hInstance = inst;
1011 psp.pfnCallback = FileCallBack;
1012 psp.pszTitle = title;
1013 psp.pszTemplate = MAKEINTRESOURCEW(id);
1014 #if 1
1015 psp.dwFlags |= PSP_DLGINDIRECT;
1016 psp.pResource = TTGetDlgTemplate(inst, MAKEINTRESOURCEA(id));
1017 #endif
1018
1019 psp.pfnDlgProc = FileProc;
1020 psp.lParam = (LPARAM)dlg_data;
1021
1022 HPROPSHEETPAGE hpsp = CreatePropertySheetPageW((LPPROPSHEETPAGEW)&psp);
1023 free(title);
1024 return hpsp;
1025 }
1026
1027 //////////////////////////////////////////////////////////////////////////////
1028
1029 static INT_PTR CALLBACK BGAlphaProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
1030 {
1031 static const DlgTextInfo TextInfos[] = {
1032 { 0, "DLG_THEME_BG_ALPHA_TITLE"},
1033 { IDC_TEXT_BACK_ALPHA_TITLE, "DLG_THEME_BG_ALPHA_TEXT_BACK_ALPHA_TITLE" },
1034 { IDC_REVERSE_TEXT_BACK_ALPHA_TITLE, "DLG_THEME_BG_ALPHA_REVERSE_TEXT_BACK_ALPHA_TITLE" },
1035 { IDC_OTHER_TEXT_BACK_ALPHA_TITLE, "DLG_THEME_BG_ALPHA_OTHER_BACK_TITLE" },
1036 };
1037 ThemeDlgData *dlg_data = (ThemeDlgData *)GetWindowLongPtr(hWnd, DWLP_USER);
1038
1039 switch (msg) {
1040 case WM_INITDIALOG: {
1041 dlg_data = (ThemeDlgData *)(((PROPSHEETPAGEW_V1 *)lp)->lParam);
1042 SetWindowLongPtr(hWnd, DWLP_USER, (LONG_PTR)dlg_data);
1043 SetDlgTextsW(hWnd, TextInfos, _countof(TextInfos), dlg_data->pts->UILanguageFileW);
1044
1045 SendDlgItemMessageA(hWnd, IDC_REVERSE_TEXT_ALPHA_SLIDER, TBM_SETRANGE, TRUE, MAKELONG(0, 255));
1046 SendDlgItemMessageA(hWnd, IDC_TEXT_ALPHA_SLIDER, TBM_SETRANGE, TRUE, MAKELONG(0, 255));
1047 SendDlgItemMessageA(hWnd, IDC_BACK_ALPHA_SLIDER, TBM_SETRANGE, TRUE, MAKELONG(0, 255));
1048
1049 break;
1050 }
1051 case WM_NOTIFY: {
1052 NMHDR *nmhdr = (NMHDR *)lp;
1053 switch (nmhdr->code) {
1054 case PSN_APPLY: {
1055 break;
1056 }
1057 case PSN_HELP:
1058 OpenHelpCV(dlg_data->pcv, HH_HELP_CONTEXT, HlpMenuSetupAdditionalTheme);
1059 break;
1060 case PSN_KILLACTIVE: {
1061 BGTheme *bg_theme = &dlg_data->BGTab.bg_theme;
1062 bg_theme->BGReverseTextAlpha = (BYTE)SendDlgItemMessageA(hWnd, IDC_REVERSE_TEXT_ALPHA_SLIDER, TBM_GETPOS, 0, 0);
1063 bg_theme->TextBackAlpha = (BYTE)SendDlgItemMessageA(hWnd, IDC_TEXT_ALPHA_SLIDER, TBM_GETPOS, 0, 0);
1064 bg_theme->BackAlpha = (BYTE)SendDlgItemMessageA(hWnd, IDC_BACK_ALPHA_SLIDER, TBM_GETPOS, 0, 0);
1065 break;
1066 }
1067 case PSN_SETACTIVE: {
1068 BGTheme *bg_theme = &dlg_data->BGTab.bg_theme;
1069 SendDlgItemMessageA(hWnd, IDC_REVERSE_TEXT_ALPHA_SLIDER, TBM_SETPOS, TRUE, bg_theme->BGReverseTextAlpha);
1070 SendDlgItemMessageA(hWnd, IDC_TEXT_ALPHA_SLIDER, TBM_SETPOS, TRUE, bg_theme->TextBackAlpha);
1071 SendDlgItemMessageA(hWnd, IDC_BACK_ALPHA_SLIDER, TBM_SETPOS, TRUE, bg_theme->BackAlpha);
1072 break;
1073 }
1074 default:
1075 break;
1076 }
1077 break;
1078 }
1079 default:
1080 return FALSE;
1081 }
1082 return FALSE;
1083 }
1084
1085 static UINT CALLBACK BGAlphaCallBack(HWND hwnd, UINT uMsg, struct _PROPSHEETPAGEW *ppsp)
1086 {
1087 (void)hwnd;
1088 UINT ret_val = 0;
1089 switch (uMsg) {
1090 case PSPCB_CREATE:
1091 ret_val = 1;
1092 break;
1093 case PSPCB_RELEASE:
1094 free((void *)ppsp->pResource);
1095 ppsp->pResource = NULL;
1096 break;
1097 default:
1098 break;
1099 }
1100 return ret_val;
1101 }
1102
1103 static HPROPSHEETPAGE BGAlphaCreate(ThemeDlgData *dlg_data)
1104 {
1105 const int id = IDD_TABSHEET_BG_THEME_ALPHA_EDITOR;
1106 HINSTANCE inst = dlg_data->hInst;
1107
1108 wchar_t *title;
1109 GetI18nStrWW("Tera Term", "DLG_THEME_BG_ALPHA_TITLE",
1110 L"background image alpha", dlg_data->pts->UILanguageFileW, &title);
1111
1112 PROPSHEETPAGEW_V1 psp = {};
1113 psp.dwSize = sizeof(psp);
1114 psp.dwFlags = PSP_DEFAULT | PSP_USECALLBACK | PSP_USETITLE | PSP_HASHELP;
1115 psp.hInstance = inst;
1116 psp.pfnCallback = BGAlphaCallBack;
1117 psp.pszTitle = title;
1118 psp.pszTemplate = MAKEINTRESOURCEW(id);
1119 #if 1
1120 psp.dwFlags |= PSP_DLGINDIRECT;
1121 psp.pResource = TTGetDlgTemplate(inst, MAKEINTRESOURCEA(id));
1122 #endif
1123
1124 psp.pfnDlgProc = BGAlphaProc;
1125 psp.lParam = (LPARAM)dlg_data;
1126
1127 HPROPSHEETPAGE hpsp = CreatePropertySheetPageW((LPPROPSHEETPAGEW)&psp);
1128 free(title);
1129 return hpsp;
1130 }
1131
1132 //////////////////////////////////////////////////////////////////////////////
1133
1134 // Theme dialog
1135 class CThemeDlg: public TTCPropSheetDlg
1136 {
1137 public:
1138 CThemeDlg(HINSTANCE hInstance, HWND hParentWnd, ThemeDlgData *dlg_data):
1139 TTCPropSheetDlg(hInstance, hParentWnd, dlg_data->pts->UILanguageFileW)
1140 {
1141 HPROPSHEETPAGE page;
1142 page = ThemeEditorFile(dlg_data);
1143 AddPage(page);
1144 page = ThemeEditorCreate(dlg_data);
1145 AddPage(page);
1146 page = BGAlphaCreate(dlg_data);
1147 AddPage(page);
1148 page = ColorThemeEditorCreate(dlg_data);
1149 AddPage(page);
1150
1151 SetCaption(L"Theme Editor");
1152 }
1153 ~CThemeDlg() {
1154 ;
1155 }
1156
1157 private:
1158 ;
1159 };
1160
1161 void ThemeDialog(HINSTANCE hInst, HWND hWnd, TComVar *pcv)
1162 {
1163 ThemeDlgData *dlg_data = (ThemeDlgData*)calloc(sizeof(*dlg_data), 1);
1164 dlg_data->hInst = hInst;
1165 dlg_data->pcv = pcv;
1166 dlg_data->pts = pcv->ts;
1167 dlg_data->hVTWin = pcv->HWin;
1168 ThemeGetBG(&dlg_data->BGTab.bg_theme);
1169 dlg_data->Backup.bg_theme = dlg_data->BGTab.bg_theme;
1170 ThemeGetColor(&dlg_data->ColorTab.color_theme);
1171 dlg_data->Backup.color_theme = dlg_data->ColorTab.color_theme;
1172
1173 CThemeDlg dlg(hInst, hWnd, dlg_data);
1174 INT_PTR r = dlg.DoModal();
1175 if (r == 0) {
1176 // cancel���A�o�b�N�A�b�v���e������
1177 ThemeSetBG(&dlg_data->Backup.bg_theme);
1178 ThemeSetColor(&dlg_data->Backup.color_theme);
1179 BGSetupPrimary(TRUE);
1180 InvalidateRect(dlg_data->hVTWin, NULL, FALSE);
1181 }
1182 else if (r >= 1) {
1183 // ok����(Changes were saved by the user)
1184 ThemeSetBG(&dlg_data->BGTab.bg_theme);
1185 ThemeSetColor(&dlg_data->ColorTab.color_theme);
1186 BGSetupPrimary(TRUE);
1187 InvalidateRect(dlg_data->hVTWin, NULL, FALSE);
1188 }
1189
1190 free(dlg_data);
1191 }

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