* Sync up to trunk HEAD (r62285). Branch guys deserve the significant speedups too ;)
[reactos.git] / dll / cpl / desk / advappdlg.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Display Control Panel
4 * FILE: dll/cpl/desk/advappdlg.c
5 * PURPOSE: Advanced appearance dialog
6 *
7 * PROGRAMMER: Timo Kreuzer (timo[dot]kreuzer[at]web[dot]de)
8 *
9 */
10
11 #include "desk.h"
12
13 /******************************************************************************/
14
15 typedef struct
16 {
17 int Size;
18 int Size2;
19 int Color1;
20 int Color2;
21 int Font;
22 int FontColor;
23 } ASSIGNMENT;
24
25 /* This const assigns the color and metric numbers to the elements from the elements list */
26
27 /* Size 1 (width) Size 2 (height) Color 1 Color 2 Font Fontcolor */
28 const ASSIGNMENT g_Assignment[NUM_ELEMENTS] =
29 { {-1, -1, COLOR_DESKTOP, -1, -1, -1}, /* -Desktop */
30 {SIZE_CAPTION_HEIGHT, -1, COLOR_INACTIVECAPTION, COLOR_GRADIENTINACTIVECAPTION, FONT_CAPTION, -1}, /* inactive window caption */
31 {SIZE_BORDER_WIDTH, -1, COLOR_INACTIVEBORDER, -1, -1, -1}, /* inactive window border */
32 {SIZE_CAPTION_HEIGHT, -1, COLOR_ACTIVECAPTION, COLOR_GRADIENTACTIVECAPTION, FONT_CAPTION, COLOR_CAPTIONTEXT}, /* -active window caption */
33 {SIZE_BORDER_WIDTH, -1, COLOR_ACTIVEBORDER, -1, -1, -1}, /* active window border */
34 {SIZE_MENU_HEIGHT, SIZE_MENU_WIDTH, COLOR_MENU, -1, FONT_MENU, COLOR_MENUTEXT}, /* menu */
35 {SIZE_MENU_HEIGHT, SIZE_MENU_WIDTH, COLOR_HIGHLIGHT, -1, -1, COLOR_HIGHLIGHTTEXT},/* marked element */
36 {-1, -1, COLOR_WINDOW, -1 /*COLOR_WINDOWFRAME*/, -1, COLOR_WINDOWTEXT}, /* window */
37 {SIZE_SCROLL_WIDTH, SIZE_SCROLL_HEIGHT, COLOR_SCROLLBAR, -1, -1, -1}, /* scroll bar */
38 {-1, -1, COLOR_3DFACE, -1, -1, COLOR_BTNTEXT}, /* 3d objects */
39 {SIZE_SM_CAPTION_HEIGHT, -1, -1, -1, FONT_SMCAPTION, -1}, /* palette window caption */
40 {-1, -1, -1, -1, -1, -1}, /* symbol caption FIXME: Access? */
41 {SIZE_CAPTION_HEIGHT, -1, -1, -1, -1, -1}, /* caption bar */
42 {-1, -1, -1, -1, -1, COLOR_GRAYTEXT}, /* inactive menu item FIXME: Access? */
43 {-1, -1, -1, -1, FONT_MESSAGE, COLOR_WINDOWTEXT}, /* dialog */
44 {-1, -1, -1, -1, -1, -1}, /* scrollbar controls FIXME: Access? */
45 {-1, -1, COLOR_APPWORKSPACE, -1, -1, -1}, /* application background */
46 {-1, -1, -1, -1, -1, -1}, /* small caption bar FIXME: Access? */
47 {SIZE_ICON_SPACE_X, -1, -1, -1, -1, -1}, /* symbol distance horiz. */
48 {SIZE_ICON_SPACE_Y, -1, -1, -1, -1, -1}, /* symbol distance vert. */
49 {-1, -1, COLOR_INFOBK, -1, FONT_STATUS, COLOR_INFOTEXT}, /* quickinfo */
50 {SIZE_ICON, -1, -1, -1, FONT_ICON, -1}}; /* symbol */
51
52 /******************************************************************************/
53
54 /* Draw the current color on the color picker buttons */
55 static VOID
56 UpdateButtonColor(HWND hwndDlg, GLOBALS* g, INT ID, INT nButton, INT nColor)
57 {
58 HDC hdcColorButton, hdcCompat;
59 RECT rect;
60 HBRUSH hbrush;
61 HWND hwndColorButton;
62 HGDIOBJ hgdiTmp;
63
64 if (nColor != -1)
65 {
66 /* Create a DC to draw on */
67 hwndColorButton = GetDlgItem(hwndDlg, ID);
68 hdcColorButton = GetDC(hwndColorButton);
69 hdcCompat = CreateCompatibleDC(hdcColorButton);
70 ReleaseDC(hwndColorButton, hdcColorButton);
71
72 /* Select the button image to it */
73 hgdiTmp = SelectObject(hdcCompat, g->hbmpColor[nButton]);
74
75 /* Create a brush and draw the rectangle */
76 rect.left = 2;
77 rect.top = 2;
78 rect.right = 22;
79 rect.bottom = 13;
80 hbrush = CreateSolidBrush(g->SchemeAdv.crColor[nColor]);
81 FillRect(hdcCompat, &rect, hbrush);
82 DeleteObject(hbrush);
83
84 /* hdcCompat is not needed anymore */
85 SelectObject(hdcCompat,hgdiTmp);
86 DeleteDC(hdcCompat);
87
88 SendDlgItemMessage(hwndDlg, ID, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)g->hbmpColor[nButton]);
89 EnableWindow(GetDlgItem(hwndDlg, ID), TRUE);
90 }
91 else
92 {
93 SendDlgItemMessage(hwndDlg, ID, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)NULL);
94 EnableWindow(GetDlgItem(hwndDlg, ID), FALSE);
95 }
96 }
97
98
99 /* Create the basic bitmaps for the color picker buttons */
100 static VOID
101 InitColorButtons(HWND hwndDlg, GLOBALS* g)
102 {
103 INT i;
104 HDC hdcColorButton, hdcCompat;
105 RECT rect;
106 HBRUSH hbrush;
107 HPEN hPen;
108 HWND hwndColorButton;
109 HGDIOBJ hgdiTemp;
110 COLOR_SCHEME *scheme = &g->SchemeAdv;
111
112 const POINT Points[3] = {{29,6},{33,6},{31,8}};
113
114 hwndColorButton = GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_COLOR1_B);
115 hdcColorButton = GetDC(hwndColorButton);
116 for (i = 0; i <= 2; i++)
117 {
118 /* Create a DC to draw on */
119 hdcCompat = CreateCompatibleDC(hdcColorButton);
120
121 /* Create the button image */
122 g->hbmpColor[i] = CreateCompatibleBitmap(hdcColorButton, 36, 15);
123
124 /* Select the button image to the DC */
125 hgdiTemp = SelectObject(hdcCompat, g->hbmpColor[i]);
126
127 /* Draw the buttons background color */
128 rect.left = 0;
129 rect.top = 0;
130 rect.right = 36;
131 rect.bottom = 15;
132 hbrush = CreateSolidBrush(scheme->crColor[COLOR_BTNFACE]);
133 FillRect(hdcCompat, &rect, hbrush);
134 DeleteObject(hbrush);
135
136 /* Draw the rectangle */
137 rect.left = 1;
138 rect.top = 1;
139 rect.right = 23;
140 rect.bottom = 14;
141 hbrush = CreateSolidBrush(scheme->crColor[COLOR_BTNTEXT]);
142 FillRect(hdcCompat, &rect, hbrush);
143 DeleteObject(hbrush);
144
145 /* Draw left side of line */
146 hPen = CreatePen(PS_SOLID, 1, scheme->crColor[COLOR_BTNSHADOW]);
147 SelectObject(hdcCompat, hPen);
148 MoveToEx(hdcCompat, 26, 1, NULL);
149 LineTo(hdcCompat, 26, 14);
150 SelectObject(hdcCompat, GetStockObject(BLACK_PEN));
151 DeleteObject(hPen);
152
153 /* Draw right side of line */
154 hPen = CreatePen(PS_SOLID, 1, scheme->crColor[COLOR_BTNHIGHLIGHT]);
155 SelectObject(hdcCompat,hPen);
156 MoveToEx(hdcCompat, 27, 1, NULL);
157 LineTo(hdcCompat, 27, 14);
158 SelectObject(hdcCompat, GetStockObject(BLACK_PEN));
159 DeleteObject(hPen);
160
161 /* Draw triangle */
162 hPen = CreatePen(PS_SOLID, 1, scheme->crColor[COLOR_BTNTEXT]);
163 hbrush = CreateSolidBrush(scheme->crColor[COLOR_BTNTEXT]);
164 SelectObject(hdcCompat, hPen);
165 SelectObject(hdcCompat, hbrush);
166 SetPolyFillMode(hdcCompat, WINDING);
167
168 /* FIXME: HACK, see Points definition */
169 Polygon(hdcCompat, Points, 3);
170
171 /* Cleanup */
172 SelectObject(hdcCompat,hgdiTemp);
173 DeleteDC(hdcCompat);
174 DeleteObject(hPen);
175 DeleteObject(hbrush);
176 }
177
178 ReleaseDC(hwndColorButton, hdcColorButton);
179
180 /* Set the images of the buttons */
181 SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_COLOR1_B, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)g->hbmpColor[0]);
182 SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_COLOR2_B, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)g->hbmpColor[1]);
183 SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTCOLOR_B, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)g->hbmpColor[2]);
184 }
185
186
187 /* This is the callback function to add the installed fonts to the font combo */
188 static int CALLBACK
189 EnumFontFamExProc(ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme, DWORD dwFontType, LPARAM lParam)
190 {
191 /* Don't enumerate more than 100 fonts */
192 if (SendMessage((HWND)lParam, CB_GETCOUNT, 0, 0) >= 100)
193 return 0;
194
195 /* Only add the string once */
196 if (SendMessage((HWND)lParam, CB_FINDSTRINGEXACT, -1, (WPARAM)&(lpelfe->elfLogFont.lfFaceName)) != CB_ERR)
197 return 2;
198
199 SendMessage((HWND)lParam, CB_ADDSTRING, 0, (WPARAM)&(lpelfe->elfLogFont.lfFaceName));
200
201 return 1;
202 }
203
204
205 /* Update all the controls with the current values for the selected screen element */
206 static VOID
207 UpdateControls(HWND hwndDlg, GLOBALS *g)
208 {
209 INT iElement;
210 HDC hdcDlg;
211
212 iElement = g->CurrentElement;
213
214 /* First enable / disable the controls */
215 EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_SIZE_E), (g_Assignment[iElement].Size != -1));
216 EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_SIZE_UD), (g_Assignment[iElement].Size != -1));
217 EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_SIZE_T), (g_Assignment[iElement].Size != -1));
218 EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_COLOR1_T), (g_Assignment[iElement].Color1 != -1));
219 EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_COLOR2_T), (g_Assignment[iElement].Color2 != -1));
220 EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_FONT_T), (g_Assignment[iElement].Font != -1));
221 EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_FONT_C), (g_Assignment[iElement].Font != -1));
222 EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_FONTSIZE_T), (g_Assignment[iElement].Font != -1));
223 EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_FONTSIZE_E), (g_Assignment[iElement].Font != -1));
224 EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_FONTCOLOR_T), (g_Assignment[iElement].FontColor != -1));
225 EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_FONTBOLD), (g_Assignment[iElement].Font != -1));
226 EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_FONTITALIC), (g_Assignment[iElement].Font != -1));
227
228 /* Update the colors of the color buttons */
229 UpdateButtonColor(hwndDlg, g, IDC_ADVAPPEARANCE_COLOR1_B, 0, g_Assignment[iElement].Color1);
230 UpdateButtonColor(hwndDlg, g, IDC_ADVAPPEARANCE_COLOR2_B, 1, g_Assignment[iElement].Color2);
231 UpdateButtonColor(hwndDlg, g, IDC_ADVAPPEARANCE_FONTCOLOR_B, 2, g_Assignment[iElement].FontColor);
232
233 if (g_Assignment[iElement].Size != -1)
234 SetDlgItemInt(hwndDlg, IDC_ADVAPPEARANCE_SIZE_E, SchemeGetMetric(&g->SchemeAdv, g_Assignment[iElement].Size), FALSE);
235 else
236 SetDlgItemText(hwndDlg, IDC_ADVAPPEARANCE_SIZE_E, TEXT(""));
237
238 hdcDlg = GetDC(hwndDlg);
239 if (g_Assignment[iElement].Font != -1)
240 {
241 PLOGFONTW plfFont = SchemeGetFont(&g->SchemeAdv, g_Assignment[iElement].Font);
242
243 SetDlgItemText(hwndDlg, IDC_ADVAPPEARANCE_FONT_C, plfFont->lfFaceName);
244 SetDlgItemInt(hwndDlg, IDC_ADVAPPEARANCE_FONTSIZE_E, -MulDiv(plfFont->lfHeight, 72, GetDeviceCaps(hdcDlg, LOGPIXELSY)),FALSE);
245 SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONT_C, CB_FINDSTRINGEXACT, -1, (WPARAM)plfFont->lfFaceName);
246 SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTBOLD, BM_SETCHECK, plfFont->lfWeight == FW_BOLD?1:0, 0);
247 SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTITALIC, BM_SETCHECK, plfFont->lfItalic, 0);
248 }
249 else
250 {
251 SetDlgItemText(hwndDlg, IDC_ADVAPPEARANCE_FONT_C, NULL);
252 SetDlgItemText(hwndDlg, IDC_ADVAPPEARANCE_FONTSIZE_E, NULL);
253 SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTBOLD, BM_SETCHECK, 0, 0);
254 SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTITALIC, BM_SETCHECK, 0, 0);
255 }
256
257 ReleaseDC(hwndDlg, hdcDlg);
258 }
259
260
261 static VOID
262 SaveCurrentValues(HWND hwndDlg, GLOBALS *g)
263 {
264 BOOL bTranslated;
265 HDC hdcDlg = GetDC(hwndDlg);
266
267 if (g_Assignment[g->CurrentElement].Size != -1)
268 {
269 SchemeSetMetric(&g->SchemeAdv, g_Assignment[g->CurrentElement].Size, GetDlgItemInt(hwndDlg, IDC_ADVAPPEARANCE_SIZE_E, &bTranslated, FALSE));
270 }
271
272 if (g_Assignment[g->CurrentElement].Font != -1)
273 {
274 PLOGFONTW plfFont = SchemeGetFont(&g->SchemeAdv, g_Assignment[g->CurrentElement].Font);
275 plfFont->lfHeight = -MulDiv(GetDlgItemInt(hwndDlg, IDC_ADVAPPEARANCE_FONTSIZE_E, &bTranslated, FALSE), GetDeviceCaps(hdcDlg, LOGPIXELSY), 72);
276 plfFont->lfWeight = (SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTBOLD, BM_GETCHECK, 0, 0) == 1) ? FW_BOLD : FW_NORMAL;
277 plfFont->lfItalic = (BYTE)SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTITALIC, BM_GETCHECK, 0, 0);
278 GetDlgItemText(hwndDlg, IDC_ADVAPPEARANCE_FONT_C, plfFont->lfFaceName, LF_FACESIZE * sizeof(TCHAR));
279 }
280
281 ReleaseDC(hwndDlg, hdcDlg);
282 }
283
284
285 /* Select a color using a color picker */
286 static BOOL
287 GetColor(HWND hwndDlg, GLOBALS* g, INT nButton)
288 {
289 CHOOSECOLOR cc;
290 COLORREF crCustom[16] = { 0 };
291 COLORREF crColor;
292 INT ID = 0;
293 INT ColorIndex = 0;
294
295 /* Get the color index from the element index and button number */
296 switch (nButton)
297 {
298 case 0:
299 ColorIndex = g_Assignment[g->CurrentElement].Color1;
300 ID = IDC_ADVAPPEARANCE_COLOR1_B;
301 break;
302
303 case 1:
304 ColorIndex = g_Assignment[g->CurrentElement].Color2;
305 ID = IDC_ADVAPPEARANCE_COLOR2_B;
306 break;
307
308 case 2:
309 ColorIndex = g_Assignment[g->CurrentElement].FontColor;
310 ID = IDC_ADVAPPEARANCE_FONTCOLOR_B;
311 break;
312 }
313
314 crColor = g->SchemeAdv.crColor[ColorIndex];
315
316 /* Prepare cc structure */
317 cc.lStructSize = sizeof(CHOOSECOLOR);
318 cc.hwndOwner = hwndDlg;
319 cc.hInstance = NULL;
320 cc.rgbResult = crColor;
321 cc.lpCustColors = crCustom;
322 cc.Flags = CC_ANYCOLOR | CC_FULLOPEN | CC_RGBINIT;
323 cc.lCustData = 0;
324 cc.lpfnHook = NULL;
325 cc.lpTemplateName = NULL;
326
327 /* Create the colorpicker */
328 if (ChooseColor(&cc))
329 {
330 g->SchemeAdv.crColor[ColorIndex] = cc.rgbResult;
331 if (crColor != cc.rgbResult)
332 {
333 UpdateButtonColor(hwndDlg, g, ID, nButton, ColorIndex);
334 SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->SchemeAdv);
335 return TRUE;
336 }
337 }
338
339 return FALSE;
340 }
341
342
343 /* Initialize the advanced appearance dialog */
344 static VOID
345 AdvAppearanceDlg_Init(HWND hwndDlg, GLOBALS *g)
346 {
347 INT i, iElement, iListIndex, iDeskIndex = 0;
348 TCHAR tstrText[80];
349 LOGFONT lfFont;
350 LOGFONT lfButtonFont;
351 HFONT hMyFont;
352 HDC hScreenDC;
353 TCHAR Size[4];
354
355 /* Copy the current theme values */
356 g->SchemeAdv = g->Scheme;
357
358 SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->SchemeAdv);
359
360
361 /* Add the elements to the combo */
362 for (iElement = 0; iElement < NUM_ELEMENTS; iElement++)
363 {
364 LoadString(hApplet, IDS_ELEMENT_1 + iElement, (LPTSTR)&tstrText, 79);
365 iListIndex = SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_ELEMENT, CB_ADDSTRING, 0, (LPARAM)&tstrText);
366 SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_ELEMENT, CB_SETITEMDATA, (WPARAM)iListIndex, (LPARAM)iElement);
367 }
368
369 /* Get the list index of the desktop element */
370 for (iListIndex = 0; iListIndex < NUM_ELEMENTS; iListIndex++)
371 {
372 iElement = SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_ELEMENT, CB_GETITEMDATA, (WPARAM)iListIndex, 0);
373 if (iElement == 0)
374 {
375 iDeskIndex = iListIndex;
376 break;
377 }
378 }
379
380 SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_ELEMENT, CB_SETCURSEL, iDeskIndex, 0);
381
382 /* Create font for bold button */
383 lfButtonFont = g->Scheme.ncMetrics.lfMessageFont;
384 lfButtonFont.lfWeight = FW_BOLD;
385 lfButtonFont.lfItalic = FALSE;
386 hMyFont = CreateFontIndirect(&lfButtonFont);
387 if (hMyFont)
388 {
389 if (g->hBoldFont)
390 DeleteObject(g->hBoldFont);
391
392 g->hBoldFont = hMyFont;
393 }
394
395 /* Create font for italic button */
396 lfButtonFont.lfWeight = FW_REGULAR;
397 lfButtonFont.lfItalic = TRUE;
398 hMyFont = CreateFontIndirect(&lfButtonFont);
399 if (hMyFont)
400 {
401 if (g->hItalicFont)
402 DeleteObject(g->hItalicFont);
403
404 g->hItalicFont = hMyFont;
405 }
406
407 /* Set the fonts for the font style buttons */
408 SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTBOLD, WM_SETFONT, (WPARAM)g->hBoldFont, (LPARAM)TRUE);
409 SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTITALIC, WM_SETFONT, (WPARAM)g->hItalicFont, (LPARAM)TRUE);
410
411 /* Draw Bitmaps for the colorbuttons */
412 InitColorButtons(hwndDlg, g);
413
414 /* Make the UpDown control count correctly */
415 SendMessage(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_SIZE_UD), UDM_SETRANGE, 0L, MAKELONG (200, 1));
416
417 /* Fill font selection combo */
418 lfFont.lfCharSet = DEFAULT_CHARSET;
419 lfFont.lfFaceName[0] = (TCHAR)0;
420 lfFont.lfPitchAndFamily = 0;
421 hScreenDC = GetDC(0);
422 EnumFontFamiliesEx(hScreenDC, &lfFont, (FONTENUMPROC)EnumFontFamExProc, (LPARAM)GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_FONT_C), 0);
423 ReleaseDC(0, hScreenDC);
424
425 /* Fill font size combo */
426 for (i = 6; i <= 24; i++)
427 {
428 StringCbPrintf(Size, sizeof(Size), TEXT("%d"), i);
429 SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTSIZE_E, CB_ADDSTRING, 0, (LPARAM)&Size);
430 }
431
432 /* Update the controls */
433 iListIndex = SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_ELEMENT, CB_GETCURSEL, 0, 0);
434 g->CurrentElement = SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_ELEMENT, CB_GETITEMDATA, (WPARAM)iListIndex, 0);
435 UpdateControls(hwndDlg, g);
436 }
437
438
439 static VOID
440 AdvAppearanceDlg_CleanUp(HWND hwndDlg, GLOBALS* g)
441 {
442 DeleteObject(g->hBoldFont);
443 DeleteObject(g->hItalicFont);
444 }
445
446
447 static VOID
448 SelectComboByElement(HWND hwnd, INT id, LPARAM lParam)
449 {
450 INT nCount;
451 INT i;
452
453 nCount = SendDlgItemMessage(hwnd, id, CB_GETCOUNT, 0, 0);
454 if (nCount == CB_ERR)
455 return;
456
457 for (i = 0; i < nCount; i++)
458 {
459 if (SendDlgItemMessage(hwnd, id, CB_GETITEMDATA, (WPARAM)i, 0) == lParam)
460 {
461 SendDlgItemMessage(hwnd, id, CB_SETCURSEL, (WPARAM)i, 0);
462 break;
463 }
464 }
465 }
466
467
468 static VOID
469 GetSelectedComboText(HWND hwnd, INT id, LPWSTR lpStr)
470 {
471 INT nCount;
472
473 nCount = SendDlgItemMessage(hwnd, id, CB_GETCURSEL, 0, 0);
474 if (nCount == CB_ERR)
475 {
476 *lpStr = 0;
477 return;
478 }
479
480 nCount = SendDlgItemMessage(hwnd, id, CB_GETLBTEXT, (WPARAM)nCount, (LPARAM)lpStr);
481 if (nCount == CB_ERR)
482 {
483 *lpStr = 0;
484 }
485 }
486
487
488 static INT
489 GetSelectedComboInt(HWND hwnd, INT id)
490 {
491 TCHAR szBuffer[80];
492 INT nCount;
493
494 nCount = SendDlgItemMessage(hwnd, id, CB_GETCURSEL, 0, 0);
495 if (nCount == CB_ERR)
496 return 0;
497
498 nCount = SendDlgItemMessage(hwnd, id, CB_GETLBTEXT, (WPARAM)nCount, (LPARAM)szBuffer);
499 if (nCount == CB_ERR)
500 return 0;
501
502 return _ttoi(szBuffer);
503 }
504
505 INT_PTR CALLBACK
506 AdvAppearanceDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
507 {
508 INT iSelection, iProperty;
509 GLOBALS* g;
510 PLOGFONTW plfFont;
511
512 g = (GLOBALS*)GetWindowLongPtr(hwndDlg, DWLP_USER);
513
514 switch (uMsg)
515 {
516 case WM_INITDIALOG:
517 g = (GLOBALS*)lParam;
518 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)g);
519 AdvAppearanceDlg_Init(hwndDlg, g);
520 break;
521
522 case WM_DESTROY:
523 AdvAppearanceDlg_CleanUp(hwndDlg, g);
524 break;
525
526 case WM_COMMAND:
527 if(g == NULL)
528 return TRUE;
529
530 switch(LOWORD(wParam))
531 {
532 case IDOK:
533 SaveCurrentValues(hwndDlg, g);
534 EndDialog(hwndDlg, IDOK);
535 break;
536
537 case IDCANCEL:
538 g->SchemeAdv = g->Scheme;
539 EndDialog(hwndDlg, IDCANCEL);
540 break;
541
542 case IDC_APPEARANCE_PREVIEW:
543 SaveCurrentValues(hwndDlg, g);
544 SelectComboByElement(hwndDlg, IDC_ADVAPPEARANCE_ELEMENT, lParam);
545 g->CurrentElement = (INT)lParam;
546 UpdateControls(hwndDlg, g);
547 break;
548
549 case IDC_ADVAPPEARANCE_ELEMENT:
550 if (HIWORD(wParam) == CBN_SELCHANGE)
551 {
552 SaveCurrentValues(hwndDlg, g);
553 iSelection = SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_ELEMENT, CB_GETCURSEL, 0, 0);
554 g->CurrentElement = SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_ELEMENT, CB_GETITEMDATA, iSelection, 0);
555 UpdateControls(hwndDlg, g);
556 }
557 break;
558
559 case IDC_ADVAPPEARANCE_SIZE_E:
560 if (HIWORD(wParam) == EN_CHANGE)
561 {
562 iProperty = g_Assignment[g->CurrentElement].Size;
563 if(iProperty == -1)
564 return TRUE;
565
566 iSelection = LOWORD(SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_SIZE_UD, UDM_GETPOS,0,0L));
567 SchemeSetMetric(&g->SchemeAdv, iProperty, iSelection);
568 SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETSIZE, iProperty, iSelection);
569
570 iProperty = g_Assignment[g->CurrentElement].Size2;
571 if(iProperty != -1)
572 SchemeSetMetric(&g->SchemeAdv, iProperty, iSelection);
573 }
574 break;
575
576 case IDC_ADVAPPEARANCE_FONT_C:
577 if (HIWORD(wParam) == CBN_SELCHANGE)
578 {
579 iProperty = g_Assignment[g->CurrentElement].Font;
580 if(iProperty == -1)
581 return TRUE;
582
583 plfFont = SchemeGetFont(&g->SchemeAdv, iProperty);
584 GetSelectedComboText(hwndDlg, IDC_ADVAPPEARANCE_FONT_C, plfFont->lfFaceName);
585 SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETFONT, iProperty, (LPARAM)plfFont);
586 }
587 break;
588
589 case IDC_ADVAPPEARANCE_FONTSIZE_E:
590 if ((HIWORD(wParam) == CBN_SELCHANGE || HIWORD(wParam) == CBN_EDITCHANGE))
591 {
592 HDC hdcDlg;
593
594 iProperty = g_Assignment[g->CurrentElement].Font;
595 if(iProperty == -1)
596 return TRUE;
597
598 hdcDlg = GetDC(hwndDlg);
599
600 plfFont = SchemeGetFont(&g->SchemeAdv, iProperty);
601 iSelection = GetSelectedComboInt(hwndDlg, IDC_ADVAPPEARANCE_FONTSIZE_E);
602 plfFont->lfHeight = -MulDiv(iSelection , GetDeviceCaps(hdcDlg, LOGPIXELSY), 72);
603 SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->SchemeAdv);
604
605 ReleaseDC(hwndDlg, hdcDlg);
606 }
607 break;
608
609 case IDC_ADVAPPEARANCE_FONTBOLD:
610 if (HIWORD(wParam) == BN_CLICKED)
611 {
612 iProperty = g_Assignment[g->CurrentElement].Font;
613 if(iProperty == -1)
614 return TRUE;
615
616 plfFont = SchemeGetFont(&g->SchemeAdv, iProperty);
617 iSelection = (INT)SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTBOLD, BM_GETCHECK, 0, 0);
618 plfFont->lfWeight = (iSelection == BST_CHECKED) ? FW_BOLD : FW_NORMAL;
619 SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETFONT, iProperty, (LPARAM)plfFont);
620 }
621 break;
622
623 case IDC_ADVAPPEARANCE_FONTITALIC:
624 if (HIWORD(wParam) == BN_CLICKED)
625 {
626 iProperty = g_Assignment[g->CurrentElement].Font;
627 if(iProperty == -1)
628 return TRUE;
629
630 plfFont = SchemeGetFont(&g->SchemeAdv, iProperty);
631 iSelection = (INT)SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTITALIC, BM_GETCHECK, 0, 0);
632 plfFont->lfItalic = (iSelection == BST_CHECKED) ? TRUE : FALSE;
633 SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETFONT, iProperty, (LPARAM)plfFont);
634 }
635 break;
636
637 case IDC_ADVAPPEARANCE_COLOR1_B:
638 GetColor(hwndDlg, g, 0);
639 break;
640
641 case IDC_ADVAPPEARANCE_COLOR2_B:
642 GetColor(hwndDlg, g, 1);
643 break;
644
645 case IDC_ADVAPPEARANCE_FONTCOLOR_B:
646 GetColor(hwndDlg, g, 2);
647 break;
648
649 default:
650 return FALSE;
651 }
652 break;
653
654 default:
655 return FALSE;
656 }
657
658 return TRUE;
659 }