|
|
1.1 root 1:
2: /******************************************************************************\
3: * This is a part of the Microsoft Source Code Samples.
4: * Copyright (C) 1993 Microsoft Corporation.
5: * All rights reserved.
6: * This source code is only intended as a supplement to
7: * Microsoft Development Tools and/or WinHelp documentation.
8: * See these sources for detailed information regarding the
9: * Microsoft samples programs.
10: \******************************************************************************/
11:
12: /****************************** Module Header *******************************
13: * Module Name: styles.c
14: *
15: * Handles the control styles selection, including the styles dialogs.
16: *
17: * Functions:
18: *
19: * StylesDialog()
20: * GenericStylesDlgProc()
21: * CheckBoxStylesDlgProc()
22: * RadioButtonStylesDlgProc()
23: * PushButtonStylesDlgProc()
24: * ComboBoxStylesDlgProc()
25: * EditStylesDlgProc()
26: * ListBoxStylesDlgProc()
27: * CustomStylesDlgProc()
28: * DialogStylesDlgProc()
29: * FontNameEnumFunc()
30: * PointSizeEnumFunc()
31: * EnableComboBoxStyles()
32: * EnableEditStyles()
33: * EnableListBoxStyles()
34: * SetCustomStylesField()
35: * GetCustomStylesField()
36: * EnableDialogStyles()
37: * FillFontNameCombo()
38: * FillPointSizeCombo()
39: * AddToPointSizeCombo()
40: * FillLanguageCombo()
41: * FillSubLanguageCombo()
42: * CheckStyleBoxes()
43: * QueryCheckedStyles()
44: * StylesHelp()
45: *
46: * Comments:
47: *
48: ****************************************************************************/
49:
50: #include "dlgedit.h"
51: #include "dlgfuncs.h"
52: #include "dlgextrn.h"
53: #include "dialogs.h"
54:
55:
56: STATICFN VOID EnableComboBoxStyles(HWND hwnd, INT idCtrl);
57: STATICFN VOID EnableEditStyles(HWND hwnd, INT idCtrl);
58: STATICFN VOID EnableListBoxStyles(HWND hwnd, INT idCtrl);
59: STATICFN VOID SetCustomStylesField(HWND hwnd, DWORD flStyle);
60: STATICFN DWORD GetCustomStylesField(HWND hwnd);
61: STATICFN VOID EnableDialogStyles(HWND hwnd, INT idCtrl);
62: STATICFN VOID FillFontNameCombo(HWND hwndDlg);
63: STATICFN VOID FillPointSizeCombo(HWND hwndDlg, LPTSTR pszFaceName);
64: STATICFN VOID AddToPointSizeCombo(HWND hwndCombo, INT nPointSize);
65: STATICFN VOID FillLanguageCombo(HWND hwndDlg);
66: STATICFN VOID FillSubLanguageCombo(HWND hwndDlg, INT iLang);
67: STATICFN VOID CheckStyleBoxes(HWND hwnd, INT iClass, DWORD flStyle);
68: STATICFN VOID QueryCheckedStyles(HWND hwnd, INT iClass, DWORD *pflStyle);
69: STATICFN VOID StylesHelp(VOID);
70:
71: /*
72: * Global pointer to the CTYPE for the control or dialog whose styles
73: * are being worked on. All the styles dialog procs and workers use
74: * this pointer.
75: */
76: static NPCTYPE npcStyles;
77:
78: /*
79: * Globals that receive the new styles the user selected.
80: */
81: static DWORD flStyleNew;
82: static DWORD flExtStyleNew;
83: static LPTSTR pszTextNew;
84: static DIALOGINFO diNew;
85:
86:
87:
88: /************************************************************************
89: * StylesDialog
90: *
91: * Displays the appropriate styles dialog for the currently selected
92: * control. If the user OK's the changes, this function sets the
93: * style of the control.
94: *
95: ************************************************************************/
96:
97: VOID StylesDialog(VOID)
98: {
99: NPCTYPE npc;
100: HWND hwndOld;
101: INT fDlgResult;
102: BOOL fChanged = FALSE;
103: BOOL fFontChanged = FALSE;
104: TCHAR szClassNew[CCHTEXTMAX];
105: TCHAR szMenuNew[CCHTEXTMAX];
106: TCHAR szTextNew[CCHTEXTMAX];
107:
108: /*
109: * Quit if nothing was selected, or if we are in translate mode.
110: */
111: if (!gnpcSel || gfTranslateMode)
112: return;
113:
114: /*
115: * Set globals that the styles dialogs and worker routines will use.
116: */
117: npcStyles = gnpcSel;
118: flStyleNew = npcStyles->flStyle;
119: flExtStyleNew = npcStyles->flExtStyle;
120:
121: if (npcStyles->text)
122: NameOrdCpy(szTextNew, npcStyles->text);
123: else
124: *szTextNew = CHAR_NULL;
125:
126: pszTextNew = szTextNew;
127:
128: /*
129: * Set some other globals if this is the dialog instead of a control.
130: */
131: if (gfDlgSelected) {
132: diNew.fResFlags = gcd.di.fResFlags;
133: diNew.wLanguage = gcd.di.wLanguage;
134: diNew.DataVersion = gcd.di.DataVersion;
135: diNew.Version = gcd.di.Version;
136: diNew.Characteristics = gcd.di.Characteristics;
137:
138: lstrcpy(diNew.szFontName, gcd.di.szFontName);
139: diNew.nPointSize = gcd.di.nPointSize;
140:
141: diNew.pszClass = szClassNew;
142: if (gcd.di.pszClass)
143: NameOrdCpy(szClassNew, gcd.di.pszClass);
144: else
145: *szClassNew = CHAR_NULL;
146:
147: diNew.pszMenu = szMenuNew;
148: if (gcd.di.pszMenu)
149: NameOrdCpy(szMenuNew, gcd.di.pszMenu);
150: else
151: *szMenuNew = CHAR_NULL;
152: }
153:
154: /*
155: * Is this a custom control that has a styles proc to use?
156: */
157: if (npcStyles->pwcd->iType == W_CUSTOM && npcStyles->pwcd->lpfnStyle) {
158: fDlgResult = CallCustomStyle(npcStyles, &flStyleNew, &flExtStyleNew,
159: szTextNew);
160: }
161: else {
162: /*
163: * Show the appropriate styles dialog.
164: */
165: fDlgResult = DlgBox(npcStyles->pwcd->idStylesDialog,
166: (WNDPROC)npcStyles->pwcd->pfnStylesDlgProc);
167: }
168:
169: if (fDlgResult == IDOK) {
170: /*
171: * Now go through and determine if anything was really changed.
172: */
173: if (npcStyles->flStyle != flStyleNew ||
174: npcStyles->flExtStyle != flExtStyleNew ||
175: NameOrdCmp(npcStyles->text ?
176: npcStyles->text : szEmpty, szTextNew) != 0)
177: fChanged = TRUE;
178:
179: /*
180: * If this is the dialog, check if some other things were changed.
181: */
182: if (gfDlgSelected) {
183: if (gcd.di.fResFlags != diNew.fResFlags ||
184: gcd.di.wLanguage != diNew.wLanguage ||
185: NameOrdCmp(gcd.di.pszClass ?
186: gcd.di.pszClass : szEmpty, diNew.pszClass) != 0 ||
187: NameOrdCmp(gcd.di.pszMenu ?
188: gcd.di.pszMenu : szEmpty, diNew.pszMenu) != 0)
189: fChanged = TRUE;
190:
191: if (lstrcmp(gcd.di.szFontName, diNew.szFontName) != 0 ||
192: (*diNew.szFontName &&
193: gcd.di.nPointSize != diNew.nPointSize))
194: fChanged = fFontChanged = TRUE;
195: }
196: }
197:
198: /*
199: * Did something change?
200: */
201: if (fChanged) {
202: if (gfDlgSelected) {
203: hwndOld = npcStyles->hwnd;
204: CreateControl(npcStyles, pszTextNew, flStyleNew, flExtStyleNew,
205: npcStyles->id, &npcStyles->rc, (HWND)NULL, &diNew);
206:
207: /*
208: * Create all the control windows in the new dialog.
209: * They must be created (not just moved over by changing
210: * the parent and owner) because some controls have
211: * allocated memory on the old dialogs heap, and this
212: * heap will become invalid after the old dialog
213: * is destroyed below.
214: */
215: for (npc = npcHead; npc; npc = npc->npcNext) {
216: /*
217: * If this is an icon control and the dialog font
218: * was just changed, we need to resize the control
219: * based on the new default icon size.
220: */
221: if (npc->pwcd->iType == W_ICON && fFontChanged) {
222: npc->rc.right = npc->rc.left + awcd[W_ICON].cxDefault;
223: npc->rc.bottom = npc->rc.top + awcd[W_ICON].cyDefault;
224: }
225:
226: CreateControl(npc, npc->text, npc->flStyle, npc->flExtStyle,
227: npc->id, &npc->rc, (HWND)NULL, NULL);
228: }
229:
230: /*
231: * Now move all the drag windows over to the new dialog.
232: * This must be done after creating all the controls
233: * because of the touchy Z-order that the drag windows
234: * and the controls must have for painting and selection
235: * of the drag windows to work properly. Note that we
236: * rely on SetParent to add the window at
237: * the TOP in Z-order.
238: */
239: for (npc = npcHead; npc; npc = npc->npcNext) {
240: SetParent(npc->hwndDrag, npcStyles->hwnd);
241:
242: /*
243: * Adjust the position of the drag window.
244: */
245: SizeDragToControl(npc);
246: }
247:
248: ShowWindow(npcStyles->hwnd, SW_SHOWNA);
249: ToolboxOnTop();
250: DestroyWindow(hwndOld);
251: }
252: else {
253: hwndOld = npcStyles->hwnd;
254:
255: if (CreateControl(npcStyles, pszTextNew, flStyleNew, flExtStyleNew,
256: npcStyles->id, &npcStyles->rc, hwndOld, NULL)) {
257: /*
258: * Get rid of the old control window.
259: */
260: DestroyWindow(hwndOld);
261:
262: /*
263: * Adjust the size and position of its drag window.
264: */
265: SizeDragToControl(npcStyles);
266: }
267: }
268:
269: gfResChged = gfDlgChanged = TRUE;
270: ShowFileStatus(FALSE);
271: StatusUpdate();
272: StatusSetEnable();
273: }
274: }
275:
276:
277:
278: /************************************************************************
279: * GenericStylesDlgProc
280: *
281: * Dialog procedure for styles.
282: *
283: ************************************************************************/
284:
285: DIALOGPROC GenericStylesDlgProc(
286: HWND hwnd,
287: UINT msg,
288: WPARAM wParam,
289: LPARAM lParam)
290: {
291: switch (msg) {
292: case WM_INITDIALOG:
293: CheckStyleBoxes(hwnd, npcStyles->pwcd->iClass,
294: npcStyles->flStyle);
295: CheckStyleBoxes(hwnd, IC_WINDOW, npcStyles->flStyle);
296:
297: CenterWindow(hwnd);
298:
299: return TRUE;
300:
301: case WM_COMMAND:
302: switch (LOWORD(wParam)) {
303: case IDOK:
304: QueryCheckedStyles(hwnd, npcStyles->pwcd->iClass,
305: &flStyleNew);
306: QueryCheckedStyles(hwnd, IC_WINDOW, &flStyleNew);
307: EndDialog(hwnd, IDOK);
308: return TRUE;
309:
310: case IDCANCEL:
311: EndDialog(hwnd, IDCANCEL);
312: return TRUE;
313:
314: case IDHELP:
315: StylesHelp();
316: break;
317: }
318:
319: return FALSE;
320:
321: default:
322: return FALSE;
323: }
324: }
325:
326:
327:
328: /************************************************************************
329: * CheckBoxStylesDlgProc
330: *
331: * Dialog procedure for checkboxes.
332: *
333: ************************************************************************/
334:
335: DIALOGPROC CheckBoxStylesDlgProc(
336: HWND hwnd,
337: UINT msg,
338: WPARAM wParam,
339: LPARAM lParam)
340: {
341: DWORD dwType;
342: BOOL f3State;
343: BOOL fAuto;
344:
345: switch (msg) {
346: case WM_INITDIALOG:
347: CheckStyleBoxes(hwnd, npcStyles->pwcd->iClass,
348: npcStyles->flStyle);
349: CheckStyleBoxes(hwnd, IC_WINDOW, npcStyles->flStyle);
350:
351: dwType = npcStyles->flStyle & BS_ALL;
352: if (dwType == BS_AUTOCHECKBOX || dwType == BS_AUTO3STATE)
353: CheckDlgButton(hwnd, DID_BS_AUTOXXX, 1);
354:
355: if (dwType == BS_3STATE || dwType == BS_AUTO3STATE)
356: CheckDlgButton(hwnd, DID_BS_3STATE, 1);
357:
358: CenterWindow(hwnd);
359:
360: return TRUE;
361:
362: case WM_COMMAND:
363: switch (LOWORD(wParam)) {
364: case IDOK:
365: QueryCheckedStyles(hwnd, npcStyles->pwcd->iClass,
366: &flStyleNew);
367: QueryCheckedStyles(hwnd, IC_WINDOW, &flStyleNew);
368:
369: fAuto = IsDlgButtonChecked(hwnd, DID_BS_AUTOXXX);
370: f3State = IsDlgButtonChecked(hwnd, DID_BS_3STATE);
371: flStyleNew &= ~BS_ALL;
372: if (fAuto) {
373: if (f3State)
374: flStyleNew |= BS_AUTO3STATE;
375: else
376: flStyleNew |= BS_AUTOCHECKBOX;
377: }
378: else {
379: if (f3State)
380: flStyleNew |= BS_3STATE;
381: else
382: flStyleNew |= BS_CHECKBOX;
383: }
384:
385: EndDialog(hwnd, IDOK);
386: return TRUE;
387:
388: case IDCANCEL:
389: EndDialog(hwnd, IDCANCEL);
390: return TRUE;
391:
392: case IDHELP:
393: StylesHelp();
394: break;
395: }
396:
397: return FALSE;
398:
399: default:
400: return FALSE;
401: }
402: }
403:
404:
405:
406: /************************************************************************
407: * RadioButtonStylesDlgProc
408: *
409: * Dialog box procedure for radio buttons.
410: *
411: ************************************************************************/
412:
413: DIALOGPROC RadioButtonStylesDlgProc(
414: HWND hwnd,
415: UINT msg,
416: WPARAM wParam,
417: LPARAM lParam)
418: {
419: switch (msg) {
420: case WM_INITDIALOG:
421: CheckStyleBoxes(hwnd, npcStyles->pwcd->iClass,
422: npcStyles->flStyle);
423: CheckStyleBoxes(hwnd, IC_WINDOW, npcStyles->flStyle);
424:
425: if ((npcStyles->flStyle & BS_ALL) == BS_AUTORADIOBUTTON)
426: CheckDlgButton(hwnd, DID_BS_AUTOXXX, 1);
427:
428: CenterWindow(hwnd);
429:
430: return TRUE;
431:
432: case WM_COMMAND:
433: switch (LOWORD(wParam)) {
434: case IDOK:
435: QueryCheckedStyles(hwnd, npcStyles->pwcd->iClass,
436: &flStyleNew);
437: QueryCheckedStyles(hwnd, IC_WINDOW, &flStyleNew);
438:
439: flStyleNew &= ~BS_ALL;
440: if (IsDlgButtonChecked(hwnd, DID_BS_AUTOXXX))
441: flStyleNew |= BS_AUTORADIOBUTTON;
442: else
443: flStyleNew |= BS_RADIOBUTTON;
444:
445: EndDialog(hwnd, IDOK);
446: return TRUE;
447:
448: case IDCANCEL:
449: EndDialog(hwnd, IDCANCEL);
450: return TRUE;
451:
452: case IDHELP:
453: StylesHelp();
454: break;
455: }
456:
457: return FALSE;
458:
459: default:
460: return FALSE;
461: }
462: }
463:
464:
465:
466: /************************************************************************
467: * PushButtonStylesDlgProc
468: *
469: * We do not normally allow more than one default push button in a
470: * dialog. but if this button is already a default button, we must
471: * allow them to change it to a normal one, even if there is already
472: * another default button in the dialog. Note that this condition
473: * would normally never happen, unless they read in a res file with
474: * this condition already.
475: *
476: ************************************************************************/
477:
478: DIALOGPROC PushButtonStylesDlgProc(
479: HWND hwnd,
480: UINT msg,
481: WPARAM wParam,
482: LPARAM lParam)
483: {
484: NPCTYPE npc;
485:
486: switch (msg) {
487: case WM_INITDIALOG:
488: CheckStyleBoxes(hwnd, npcStyles->pwcd->iClass,
489: npcStyles->flStyle);
490: CheckStyleBoxes(hwnd, IC_WINDOW, npcStyles->flStyle);
491:
492: /*
493: * Only test for possibly disabling the "default"
494: * checkbox if the current control does not have the
495: * "default" style. If it does, we must always allow
496: * them to turn it off.
497: */
498: if ((npcStyles->flStyle & BS_ALL) != BS_DEFPUSHBUTTON) {
499: /*
500: * Loop through all the controls. If any pushbutton
501: * is found with the "default" style, we disable the
502: * "Default" checkbox in the styles dialog.
503: */
504: for (npc = npcHead; npc; npc = npc->npcNext)
505: if ((npc->pwcd->iType == W_PUSHBUTTON) &&
506: (npc->flStyle & BS_ALL) == BS_DEFPUSHBUTTON) {
507: EnableWindow(GetDlgItem(hwnd, DID_BS_DEFPUSHBUTTON),
508: FALSE);
509: break;
510: }
511: }
512:
513: CenterWindow(hwnd);
514:
515: return TRUE;
516:
517: case WM_COMMAND:
518: switch (LOWORD(wParam)) {
519: case IDOK:
520: QueryCheckedStyles(hwnd, npcStyles->pwcd->iClass,
521: &flStyleNew);
522: QueryCheckedStyles(hwnd, IC_WINDOW, &flStyleNew);
523:
524: EndDialog(hwnd, IDOK);
525: return TRUE;
526:
527: case IDCANCEL:
528: EndDialog(hwnd, IDCANCEL);
529: return TRUE;
530:
531: case IDHELP:
532: StylesHelp();
533: break;
534: }
535:
536: return FALSE;
537:
538: default:
539: return FALSE;
540: }
541: }
542:
543:
544:
545: /************************************************************************
546: * ComboBoxStylesDlgProc
547: *
548: * Dialog procedure for combo boxes.
549: *
550: ************************************************************************/
551:
552: DIALOGPROC ComboBoxStylesDlgProc(
553: HWND hwnd,
554: UINT msg,
555: WPARAM wParam,
556: LPARAM lParam)
557: {
558: switch (msg) {
559: case WM_INITDIALOG:
560: CheckStyleBoxes(hwnd, npcStyles->pwcd->iClass,
561: npcStyles->flStyle);
562: CheckStyleBoxes(hwnd, IC_WINDOW, npcStyles->flStyle);
563:
564: EnableComboBoxStyles(hwnd, 0);
565:
566: CenterWindow(hwnd);
567:
568: return TRUE;
569:
570: case WM_COMMAND:
571: switch (LOWORD(wParam)) {
572: case DID_CBS_OWNERDRAWFIXED:
573: case DID_CBS_OWNERDRAWVARIABLE:
574: if (HIWORD(wParam) == BN_CLICKED)
575: EnableComboBoxStyles(hwnd,
576: LOWORD(wParam));
577:
578: return TRUE;
579:
580: case IDOK:
581: QueryCheckedStyles(hwnd, npcStyles->pwcd->iClass,
582: &flStyleNew);
583: QueryCheckedStyles(hwnd, IC_WINDOW, &flStyleNew);
584: EndDialog(hwnd, IDOK);
585: return TRUE;
586:
587: case IDCANCEL:
588: EndDialog(hwnd, IDCANCEL);
589: return TRUE;
590:
591: case IDHELP:
592: StylesHelp();
593: break;
594: }
595:
596: return FALSE;
597:
598: default:
599: return FALSE;
600: }
601: }
602:
603:
604:
605: /************************************************************************
606: * EnableComboBoxStyles
607: *
608: * Checks/unchecks, disables/enables various checkboxes that are
609: * mutually exclusive and/or dependant for the Combo Box Styles dialog.
610: *
611: * Arguments:
612: * HWND hwnd - Dialog window handle.
613: * INT idCtrl - ID of the control that was clicked on.
614: *
615: ************************************************************************/
616:
617: STATICFN VOID EnableComboBoxStyles(
618: HWND hwnd,
619: INT idCtrl)
620: {
621: BOOL fFixedChecked;
622: BOOL fVariableChecked;
623:
624: fFixedChecked = IsDlgButtonChecked(hwnd, DID_CBS_OWNERDRAWFIXED);
625: fVariableChecked = IsDlgButtonChecked(hwnd, DID_CBS_OWNERDRAWVARIABLE);
626:
627: if (fFixedChecked || fVariableChecked) {
628: EnableWindow(GetDlgItem(hwnd, DID_CBS_HASSTRINGS), TRUE);
629: }
630: else {
631: EnableWindow(GetDlgItem(hwnd, DID_CBS_HASSTRINGS), FALSE);
632: CheckDlgButton(hwnd, DID_CBS_HASSTRINGS, 0);
633: }
634:
635: switch (idCtrl) {
636: case DID_CBS_OWNERDRAWFIXED:
637: if (fFixedChecked)
638: CheckDlgButton(hwnd, DID_CBS_OWNERDRAWVARIABLE, 0);
639:
640: break;
641:
642: case DID_CBS_OWNERDRAWVARIABLE:
643: if (fVariableChecked)
644: CheckDlgButton(hwnd, DID_CBS_OWNERDRAWFIXED, 0);
645:
646: break;
647: }
648: }
649:
650:
651:
652: /************************************************************************
653: * EditStylesDlgProc
654: *
655: * Dialog procedure for edit boxes.
656: *
657: ************************************************************************/
658:
659: DIALOGPROC EditStylesDlgProc(
660: HWND hwnd,
661: UINT msg,
662: WPARAM wParam,
663: LPARAM lParam)
664: {
665: switch (msg) {
666: case WM_INITDIALOG:
667: CheckStyleBoxes(hwnd, npcStyles->pwcd->iClass,
668: npcStyles->flStyle);
669: CheckStyleBoxes(hwnd, IC_WINDOW, npcStyles->flStyle);
670:
671: EnableEditStyles(hwnd, 0);
672:
673: CenterWindow(hwnd);
674:
675: return TRUE;
676:
677: case WM_COMMAND:
678: switch (LOWORD(wParam)) {
679: case DID_ES_UPPERCASE:
680: case DID_ES_LOWERCASE:
681: case DID_ES_MULTILINE:
682: if (HIWORD(wParam) == BN_CLICKED)
683: EnableEditStyles(hwnd,
684: LOWORD(wParam));
685:
686: return TRUE;
687:
688: case IDOK:
689: QueryCheckedStyles(hwnd, npcStyles->pwcd->iClass,
690: &flStyleNew);
691: QueryCheckedStyles(hwnd, IC_WINDOW, &flStyleNew);
692: EndDialog(hwnd, IDOK);
693: return TRUE;
694:
695: case IDCANCEL:
696: EndDialog(hwnd, IDCANCEL);
697: return TRUE;
698:
699: case IDHELP:
700: StylesHelp();
701: break;
702: }
703:
704: return FALSE;
705:
706: default:
707: return FALSE;
708: }
709: }
710:
711:
712:
713: /************************************************************************
714: * EnableEditStyles
715: *
716: * Checks/unchecks, disables/enables various checkboxes that are
717: * mutually exclusive and/or dependant for the Edit Field Styles dialog.
718: *
719: * Arguments:
720: * HWND hwnd - Dialog window handle.
721: * INT idCtrl - ID of the control that was clicked on.
722: *
723: ************************************************************************/
724:
725: STATICFN VOID EnableEditStyles(
726: HWND hwnd,
727: INT idCtrl)
728: {
729: if (IsDlgButtonChecked(hwnd, DID_ES_MULTILINE)) {
730: EnableWindow(GetDlgItem(hwnd, DID_ES_CENTER), TRUE);
731: EnableWindow(GetDlgItem(hwnd, DID_ES_RIGHT), TRUE);
732: EnableWindow(GetDlgItem(hwnd, DID_WS_VSCROLL), TRUE);
733: EnableWindow(GetDlgItem(hwnd, DID_ES_AUTOVSCROLL), TRUE);
734: EnableWindow(GetDlgItem(hwnd, DID_WS_HSCROLL), TRUE);
735: }
736: else {
737: EnableWindow(GetDlgItem(hwnd, DID_ES_CENTER), FALSE);
738: EnableWindow(GetDlgItem(hwnd, DID_ES_RIGHT), FALSE);
739: EnableWindow(GetDlgItem(hwnd, DID_WS_VSCROLL), FALSE);
740: EnableWindow(GetDlgItem(hwnd, DID_ES_AUTOVSCROLL), FALSE);
741: EnableWindow(GetDlgItem(hwnd, DID_WS_HSCROLL), FALSE);
742:
743: CheckDlgButton(hwnd, DID_ES_LEFT, 1);
744: CheckDlgButton(hwnd, DID_ES_CENTER, 0);
745: CheckDlgButton(hwnd, DID_ES_RIGHT, 0);
746: CheckDlgButton(hwnd, DID_WS_VSCROLL, 0);
747: CheckDlgButton(hwnd, DID_ES_AUTOVSCROLL, 0);
748: CheckDlgButton(hwnd, DID_WS_HSCROLL, 0);
749: }
750:
751: if (idCtrl == DID_ES_UPPERCASE) {
752: if (IsDlgButtonChecked(hwnd, DID_ES_UPPERCASE))
753: CheckDlgButton(hwnd, DID_ES_LOWERCASE, 0);
754: }
755: else if (idCtrl == DID_ES_LOWERCASE) {
756: if (IsDlgButtonChecked(hwnd, DID_ES_LOWERCASE))
757: CheckDlgButton(hwnd, DID_ES_UPPERCASE, 0);
758: }
759: }
760:
761:
762:
763: /************************************************************************
764: * ListBoxStylesDlgProc
765: *
766: * Dialog procedure for list boxes.
767: *
768: ************************************************************************/
769:
770: DIALOGPROC ListBoxStylesDlgProc(
771: HWND hwnd,
772: UINT msg,
773: WPARAM wParam,
774: LPARAM lParam)
775: {
776: switch (msg) {
777: case WM_INITDIALOG:
778: CheckStyleBoxes(hwnd, npcStyles->pwcd->iClass,
779: npcStyles->flStyle);
780: CheckStyleBoxes(hwnd, IC_WINDOW, npcStyles->flStyle);
781:
782: EnableListBoxStyles(hwnd, 0);
783:
784: CenterWindow(hwnd);
785:
786: return TRUE;
787:
788: case WM_COMMAND:
789: switch (LOWORD(wParam)) {
790: case DID_LBS_STANDARD:
791: case DID_LBS_NOTIFY:
792: case DID_LBS_SORT:
793: case DID_WS_VSCROLL:
794: case DID_WS_BORDER:
795: case DID_LBS_MULTIPLESEL:
796: case DID_LBS_EXTENDEDSEL:
797: case DID_LBS_OWNERDRAWFIXED:
798: case DID_LBS_OWNERDRAWVARIABLE:
799: case DID_LBS_NODATA:
800: case DID_LBS_HASSTRINGS:
801: if (HIWORD(wParam) == BN_CLICKED)
802: EnableListBoxStyles(hwnd,
803: LOWORD(wParam));
804:
805: return TRUE;
806:
807: case IDOK:
808: QueryCheckedStyles(hwnd, npcStyles->pwcd->iClass,
809: &flStyleNew);
810: QueryCheckedStyles(hwnd, IC_WINDOW, &flStyleNew);
811: EndDialog(hwnd, IDOK);
812: return TRUE;
813:
814: case IDCANCEL:
815: EndDialog(hwnd, IDCANCEL);
816: return TRUE;
817:
818: case IDHELP:
819: StylesHelp();
820: break;
821: }
822:
823: return FALSE;
824:
825: default:
826: return FALSE;
827: }
828: }
829:
830:
831:
832: /************************************************************************
833: * EnableListBoxStyles
834: *
835: * Checks/unchecks, disables/enables various checkboxes that are
836: * mutually exclusive and/or dependant for the List Box Styles dialog.
837: *
838: * Arguments:
839: * HWND hwnd - Dialog window handle.
840: * INT idCtrl - ID of the control that was clicked on.
841: *
842: ************************************************************************/
843:
844: STATICFN VOID EnableListBoxStyles(
845: HWND hwnd,
846: INT idCtrl)
847: {
848: WORD fCheckState;
849: BOOL fFixedChecked;
850: BOOL fVariableChecked;
851:
852: fFixedChecked = IsDlgButtonChecked(hwnd, DID_LBS_OWNERDRAWFIXED);
853: fVariableChecked = IsDlgButtonChecked(hwnd, DID_LBS_OWNERDRAWVARIABLE);
854:
855: if (fFixedChecked || fVariableChecked) {
856: EnableWindow(GetDlgItem(hwnd, DID_LBS_HASSTRINGS), TRUE);
857: }
858: else {
859: EnableWindow(GetDlgItem(hwnd, DID_LBS_HASSTRINGS), FALSE);
860: CheckDlgButton(hwnd, DID_LBS_HASSTRINGS, 0);
861: }
862:
863: EnableWindow(GetDlgItem(hwnd, DID_LBS_NODATA), fFixedChecked);
864:
865: switch (idCtrl) {
866: case DID_LBS_STANDARD:
867: fCheckState = (WORD)(IsDlgButtonChecked(hwnd, DID_LBS_STANDARD)
868: ? 1 : 0);
869: CheckDlgButton(hwnd, DID_LBS_NOTIFY, fCheckState);
870: CheckDlgButton(hwnd, DID_LBS_SORT, fCheckState);
871: CheckDlgButton(hwnd, DID_WS_VSCROLL, fCheckState);
872: CheckDlgButton(hwnd, DID_WS_BORDER, fCheckState);
873:
874: if (fCheckState)
875: CheckDlgButton(hwnd, DID_LBS_NODATA, 0);
876:
877: break;
878:
879: case DID_LBS_OWNERDRAWFIXED:
880: if (fFixedChecked)
881: CheckDlgButton(hwnd, DID_LBS_OWNERDRAWVARIABLE, 0);
882: else
883: CheckDlgButton(hwnd, DID_LBS_NODATA, 0);
884:
885: break;
886:
887: case DID_LBS_OWNERDRAWVARIABLE:
888: if (fVariableChecked) {
889: CheckDlgButton(hwnd, DID_LBS_OWNERDRAWFIXED, 0);
890: CheckDlgButton(hwnd, DID_LBS_NODATA, 0);
891: EnableWindow(GetDlgItem(hwnd, DID_LBS_NODATA), FALSE);
892: }
893:
894: break;
895:
896: case DID_LBS_MULTIPLESEL:
897: if (IsDlgButtonChecked(hwnd, DID_LBS_MULTIPLESEL))
898: CheckDlgButton(hwnd, DID_LBS_EXTENDEDSEL, 0);
899:
900: break;
901:
902: case DID_LBS_EXTENDEDSEL:
903: if (IsDlgButtonChecked(hwnd, DID_LBS_EXTENDEDSEL))
904: CheckDlgButton(hwnd, DID_LBS_MULTIPLESEL, 0);
905:
906: break;
907:
908: case DID_LBS_NODATA:
909: if (IsDlgButtonChecked(hwnd, DID_LBS_NODATA)) {
910: CheckDlgButton(hwnd, DID_LBS_SORT, 0);
911: CheckDlgButton(hwnd, DID_LBS_HASSTRINGS, 0);
912: CheckDlgButton(hwnd, DID_LBS_STANDARD, 0);
913: }
914:
915: break;
916:
917: case DID_LBS_HASSTRINGS:
918: if (IsDlgButtonChecked(hwnd, DID_LBS_HASSTRINGS))
919: CheckDlgButton(hwnd, DID_LBS_NODATA, 0);
920:
921: break;
922:
923: default:
924: if (!IsDlgButtonChecked(hwnd, DID_LBS_NOTIFY) ||
925: !IsDlgButtonChecked(hwnd, DID_LBS_SORT) ||
926: !IsDlgButtonChecked(hwnd, DID_WS_VSCROLL) ||
927: !IsDlgButtonChecked(hwnd, DID_WS_BORDER))
928: fCheckState = 0;
929: else
930: fCheckState = 1;
931:
932: CheckDlgButton(hwnd, DID_LBS_STANDARD, fCheckState);
933:
934: if (IsDlgButtonChecked(hwnd, DID_LBS_SORT) ||
935: IsDlgButtonChecked(hwnd, DID_LBS_HASSTRINGS))
936: CheckDlgButton(hwnd, DID_LBS_NODATA, 0);
937:
938: break;
939: }
940: }
941:
942:
943:
944: /************************************************************************
945: * CustomStylesDlgProc
946: *
947: * Dialog procedure for custom controls.
948: *
949: ************************************************************************/
950:
951: DIALOGPROC CustomStylesDlgProc(
952: HWND hwnd,
953: UINT msg,
954: WPARAM wParam,
955: LPARAM lParam)
956: {
957: switch (msg) {
958: case WM_INITDIALOG:
959: SetDlgItemText(hwnd, DID_CUSTOMSTYLESCLASS,
960: npcStyles->pwcd->pszClass);
961: SendDlgItemMessage(hwnd, DID_CUSTOMSTYLESSTYLES, EM_LIMITTEXT,
962: CCHHEXLONGMAX, 0L);
963: SetCustomStylesField(hwnd, npcStyles->flStyle);
964: CheckStyleBoxes(hwnd, IC_WINDOW, npcStyles->flStyle);
965:
966: CenterWindow(hwnd);
967:
968: return TRUE;
969:
970: case WM_COMMAND:
971: switch (LOWORD(wParam)) {
972: case DID_CUSTOMSTYLESSTYLES:
973: if (HIWORD(wParam) == EN_CHANGE) {
974: flStyleNew = GetCustomStylesField(hwnd);
975: CheckStyleBoxes(hwnd, IC_WINDOW, flStyleNew);
976: }
977:
978: break;
979:
980: case DID_WS_VISIBLE:
981: case DID_WS_DISABLED:
982: case DID_WS_GROUP:
983: case DID_WS_TABSTOP:
984: if (HIWORD(wParam) == BN_CLICKED) {
985: flStyleNew = GetCustomStylesField(hwnd);
986: QueryCheckedStyles(hwnd, IC_WINDOW, &flStyleNew);
987: SetCustomStylesField(hwnd, flStyleNew);
988: }
989:
990: break;
991:
992: case IDOK:
993: flStyleNew = GetCustomStylesField(hwnd);
994:
995: EndDialog(hwnd, IDOK);
996:
997: return TRUE;
998:
999: case IDCANCEL:
1000: EndDialog(hwnd, IDCANCEL);
1001: return TRUE;
1002:
1003: case IDHELP:
1004: StylesHelp();
1005: break;
1006: }
1007:
1008: return FALSE;
1009:
1010: default:
1011: return FALSE;
1012: }
1013: }
1014:
1015:
1016:
1017: /************************************************************************
1018: * SetCustomStylesField
1019: *
1020: * Sets the style bits in a custom control.
1021: *
1022: * Arguments:
1023: * HWND hwnd - handle to the custom control
1024: * DWORD flStyle - style of the custom control
1025: *
1026: ************************************************************************/
1027:
1028: STATICFN VOID SetCustomStylesField(
1029: HWND hwnd,
1030: DWORD flStyle)
1031: {
1032: TCHAR szBuf[32];
1033:
1034: wsprintf(szBuf, L"%#.8lx", flStyle);
1035: SetDlgItemText(hwnd, DID_CUSTOMSTYLESSTYLES, szBuf);
1036: }
1037:
1038:
1039:
1040: /************************************************************************
1041: * GetCustomStylesField
1042: *
1043: * Gets the style bits of a custom control.
1044: *
1045: * Arguments:
1046: * HWND hwnd - handle to the custom control.
1047: *
1048: * Returns:
1049: *
1050: * The style bits specified for the custom control.
1051: *
1052: ************************************************************************/
1053:
1054: STATICFN DWORD GetCustomStylesField(
1055: HWND hwnd)
1056: {
1057: TCHAR szBuf[CCHTEXTMAX];
1058:
1059: GetDlgItemText(hwnd, DID_CUSTOMSTYLESSTYLES, szBuf, CCHTEXTMAX);
1060:
1061: return valtoi(szBuf);
1062: }
1063:
1064:
1065:
1066: /************************************************************************
1067: * DialogStylesDlgProc
1068: *
1069: * Dialog procedure for a dialog box.
1070: *
1071: ************************************************************************/
1072:
1073: DIALOGPROC DialogStylesDlgProc(
1074: HWND hwnd,
1075: UINT msg,
1076: WPARAM wParam,
1077: LPARAM lParam)
1078: {
1079: DWORD flResFlagsNew;
1080: INT nPointSize;
1081: INT iLang;
1082: INT iSubLang;
1083: TCHAR szFontName[LF_FACESIZE];
1084: INT nIndex;
1085:
1086: switch (msg) {
1087: case WM_INITDIALOG:
1088: CheckStyleBoxes(hwnd, IC_RESFLAGS, (DWORD)diNew.fResFlags);
1089: CheckStyleBoxes(hwnd, IC_DIALOG, npcStyles->flStyle);
1090: CheckStyleBoxes(hwnd, IC_WINDOW, npcStyles->flStyle);
1091:
1092: if (IsDlgButtonChecked(hwnd, DID_WS_CAPTION)) {
1093: CheckDlgButton(hwnd, DID_WS_BORDER, 1);
1094: CheckDlgButton(hwnd, DID_WS_DLGFRAME, 1);
1095: }
1096:
1097: FillFontNameCombo(hwnd);
1098: FillLanguageCombo(hwnd);
1099:
1100: if (IsOrd(diNew.pszClass))
1101: SetDlgItemInt(hwnd, DID_DLGSTYLECLASS,
1102: OrdID(diNew.pszClass), FALSE);
1103: else
1104: SetDlgItemText(hwnd, DID_DLGSTYLECLASS, diNew.pszClass);
1105:
1106: if (IsOrd(diNew.pszMenu))
1107: SetDlgItemInt(hwnd, DID_DLGSTYLEMENU,
1108: OrdID(diNew.pszMenu), FALSE);
1109: else
1110: SetDlgItemText(hwnd, DID_DLGSTYLEMENU, diNew.pszMenu);
1111:
1112: EnableDialogStyles(hwnd, 0);
1113:
1114: CenterWindow(hwnd);
1115:
1116: return TRUE;
1117:
1118: case WM_COMMAND:
1119: switch (LOWORD(wParam)) {
1120: case DID_WS_BORDER:
1121: case DID_WS_DLGFRAME:
1122: case DID_WS_CAPTION:
1123: case DID_WS_POPUP:
1124: case DID_WS_CHILD:
1125: if (HIWORD(wParam) == BN_CLICKED)
1126: EnableDialogStyles(hwnd,
1127: LOWORD(wParam));
1128:
1129: return TRUE;
1130:
1131: case DID_DLGSTYLEFONTNAME:
1132: /*
1133: * Did the font name combo change?
1134: */
1135: if (HIWORD(wParam) == CBN_EDITCHANGE ||
1136: HIWORD(wParam) == CBN_SELCHANGE) {
1137: /*
1138: * Get the font name and begin looking for it.
1139: */
1140: if (HIWORD(wParam) == CBN_EDITCHANGE) {
1141: /*
1142: * The edit field was typed into. Get the
1143: * new text from there.
1144: */
1145: GetDlgItemText(hwnd, DID_DLGSTYLEFONTNAME,
1146: szFontName, LF_FACESIZE);
1147: }
1148: else {
1149: /*
1150: * A new string was selected from the list
1151: * box. Get it from the list box, because
1152: * at this point the new text is not yet set
1153: * into the edit control!
1154: */
1155: nIndex = (INT)SendDlgItemMessage(hwnd,
1156: DID_DLGSTYLEFONTNAME, CB_GETCURSEL, 0, 0L);
1157:
1158: if (nIndex != CB_ERR)
1159: SendDlgItemMessage(hwnd,
1160: DID_DLGSTYLEFONTNAME, CB_GETLBTEXT,
1161: nIndex, (DWORD)szFontName);
1162: else
1163: *szFontName = CHAR_NULL;
1164: }
1165:
1166: FillPointSizeCombo(hwnd, szFontName);
1167: }
1168:
1169: return TRUE;
1170:
1171: case DID_DLGSTYLELANG:
1172: /*
1173: * Did the language combo change?
1174: */
1175: if (HIWORD(wParam) == CBN_SELCHANGE) {
1176: nIndex = (INT)SendDlgItemMessage(hwnd,
1177: DID_DLGSTYLELANG, CB_GETCURSEL, 0, 0L);
1178: iLang = (INT)SendDlgItemMessage(hwnd,
1179: DID_DLGSTYLELANG, CB_GETITEMDATA, nIndex, 0);
1180: FillSubLanguageCombo(hwnd, iLang);
1181: }
1182:
1183: return TRUE;
1184:
1185: case IDOK:
1186: /*
1187: * If they have entered a font name and an empty
1188: * or zero point size, display an error.
1189: */
1190: nPointSize = GetDlgItemInt(
1191: hwnd, DID_DLGSTYLEPOINTSIZE, NULL, FALSE);
1192: if (!nPointSize &&
1193: SendDlgItemMessage(hwnd,
1194: DID_DLGSTYLEFONTNAME, WM_GETTEXTLENGTH, 0, 0L)) {
1195: Message(MSG_ZEROPOINTSIZE);
1196: SetFocus(GetDlgItem(hwnd, DID_DLGSTYLEPOINTSIZE));
1197: return TRUE;
1198: }
1199:
1200: GetDlgItemText(hwnd, DID_DLGSTYLEFONTNAME,
1201: diNew.szFontName, LF_FACESIZE);
1202: diNew.nPointSize = nPointSize;
1203:
1204: /*
1205: * Get the Language.
1206: */
1207: nIndex = (INT)SendDlgItemMessage(hwnd,
1208: DID_DLGSTYLELANG, CB_GETCURSEL, 0, 0L);
1209: iLang = (INT)SendDlgItemMessage(hwnd,
1210: DID_DLGSTYLELANG, CB_GETITEMDATA,
1211: nIndex, 0);
1212: nIndex = (INT)SendDlgItemMessage(hwnd,
1213: DID_DLGSTYLESUBLANG, CB_GETCURSEL, 0, 0L);
1214: iSubLang = (INT)SendDlgItemMessage(hwnd,
1215: DID_DLGSTYLESUBLANG, CB_GETITEMDATA,
1216: nIndex, 0);
1217: diNew.wLanguage = MAKELANGID(gaLangTable[iLang].wPrimary,
1218: gaLangTable[iLang].asl[iSubLang].wSubLang);
1219:
1220: /*
1221: * Get the resource flags. We need to use a temporary
1222: * long variable because QueryCheckedStyles requires
1223: * a long.
1224: */
1225: flResFlagsNew = diNew.fResFlags;
1226: QueryCheckedStyles(hwnd, IC_RESFLAGS, &flResFlagsNew);
1227: diNew.fResFlags = (WORD)flResFlagsNew;
1228:
1229: QueryCheckedStyles(hwnd, IC_DIALOG, &flStyleNew);
1230: QueryCheckedStyles(hwnd, IC_WINDOW, &flStyleNew);
1231:
1232: /*
1233: * Set the DS_SETFONT style, if they specified
1234: * a font.
1235: */
1236: if (*diNew.szFontName)
1237: flStyleNew |= DS_SETFONT;
1238: else
1239: flStyleNew &= ~DS_SETFONT;
1240:
1241: GetDlgItemText(hwnd, DID_DLGSTYLECLASS,
1242: diNew.pszClass, CCHTEXTMAX);
1243:
1244: /*
1245: * Convert the class to an ordinal, if necessary.
1246: */
1247: StrToNameOrd(diNew.pszClass, FALSE);
1248:
1249: GetDlgItemText(hwnd, DID_DLGSTYLEMENU,
1250: diNew.pszMenu, CCHTEXTMAX);
1251:
1252: /*
1253: * Convert the menu name to an ordinal, if necessary.
1254: */
1255: StrToNameOrd(diNew.pszMenu, FALSE);
1256:
1257: /*
1258: * If they just removed the caption style,
1259: * clear the dialog's caption text at the
1260: * same time.
1261: */
1262: if ((npcStyles->flStyle & WS_CAPTION) == WS_CAPTION &&
1263: (flStyleNew & WS_CAPTION) != WS_CAPTION)
1264: *pszTextNew = CHAR_NULL;
1265:
1266: EndDialog(hwnd, IDOK);
1267: return TRUE;
1268:
1269: case IDCANCEL:
1270: EndDialog(hwnd, IDCANCEL);
1271: return TRUE;
1272:
1273: case IDHELP:
1274: StylesHelp();
1275: break;
1276: }
1277:
1278: return FALSE;
1279:
1280: default:
1281: return FALSE;
1282: }
1283: }
1284:
1285:
1286:
1287: /************************************************************************
1288: * EnableDialogStyles
1289: *
1290: * Checks and unchecks various checkboxes that are mutually exclusive
1291: * for the Dialog Styles dialog.
1292: *
1293: * Arguments:
1294: * HWND hwnd - Dialog window handle.
1295: * INT idCtrl - ID of the control that was clicked on.
1296: *
1297: ************************************************************************/
1298:
1299: STATICFN VOID EnableDialogStyles(
1300: HWND hwnd,
1301: INT idCtrl)
1302: {
1303: switch (idCtrl) {
1304: case DID_WS_CAPTION:
1305: if (IsDlgButtonChecked(hwnd, DID_WS_CAPTION)) {
1306: CheckDlgButton(hwnd, DID_WS_BORDER, 1);
1307: CheckDlgButton(hwnd, DID_WS_DLGFRAME, 1);
1308: }
1309: else {
1310: CheckDlgButton(hwnd, DID_WS_BORDER, 0);
1311: CheckDlgButton(hwnd, DID_WS_DLGFRAME, 0);
1312: }
1313:
1314: break;
1315:
1316: case DID_WS_BORDER:
1317: case DID_WS_DLGFRAME:
1318: if (IsDlgButtonChecked(hwnd, DID_WS_BORDER) &&
1319: IsDlgButtonChecked(hwnd, DID_WS_DLGFRAME))
1320: CheckDlgButton(hwnd, DID_WS_CAPTION, 1);
1321: else
1322: CheckDlgButton(hwnd, DID_WS_CAPTION, 0);
1323:
1324: break;
1325:
1326: case DID_WS_CHILD:
1327: if (IsDlgButtonChecked(hwnd, DID_WS_CHILD))
1328: CheckDlgButton(hwnd, DID_WS_POPUP, 0);
1329:
1330: break;
1331:
1332: case DID_WS_POPUP:
1333: if (IsDlgButtonChecked(hwnd, DID_WS_POPUP))
1334: CheckDlgButton(hwnd, DID_WS_CHILD, 0);
1335:
1336: break;
1337: }
1338: }
1339:
1340:
1341:
1342: /************************************************************************
1343: * FillFontNameCombo
1344: *
1345: * Fills combo box with available fonts for dialog.
1346: *
1347: * Arguments:
1348: * HWND hwndDlg - Dialog window handle.
1349: *
1350: ************************************************************************/
1351:
1352: STATICFN VOID FillFontNameCombo(
1353: HWND hwndDlg)
1354: {
1355: HDC hDC;
1356: HWND hwndCombo;
1357: TCHAR szName1[LF_FACESIZE];
1358: TCHAR szName2[LF_FACESIZE];
1359: LPTSTR pszName;
1360: LPTSTR pszNameLast;
1361: LPTSTR pszNameTemp;
1362: INT iIndex;
1363: INT iItems;
1364:
1365: hwndCombo = GetDlgItem(hwndDlg, DID_DLGSTYLEFONTNAME);
1366:
1367: if (hDC = GetDC(ghwndMain)) {
1368: EnumFonts(hDC, NULL, (FONTENUMPROC) FontNameEnumFunc, (LPARAM)&hwndCombo);
1369: ReleaseDC(ghwndMain, hDC);
1370: }
1371:
1372: /*
1373: * Strip out any duplicate names in the combobox. This routine
1374: * relies on the items being sorted first.
1375: */
1376: iItems = (INT)SendMessage(hwndCombo, CB_GETCOUNT, 0, 0);
1377: *szName1 = CHAR_NULL;
1378: *szName2 = CHAR_NULL;
1379: pszName = szName1;
1380: pszNameLast = szName2;
1381: for (iIndex = 0; iIndex < iItems;) {
1382: /*
1383: * Get the text of the next item.
1384: */
1385: SendMessage(hwndCombo, CB_GETLBTEXT, iIndex, (DWORD)pszName);
1386:
1387: /*
1388: * If it matches the previous item, delete it. Otherwise,
1389: * flip the buffers to save the current items text and
1390: * go on to the next item.
1391: */
1392: if (lstrcmp(pszName, pszNameLast) == 0) {
1393: SendMessage(hwndCombo, CB_DELETESTRING, iIndex, 0);
1394: iItems--;
1395: }
1396: else {
1397: pszNameTemp = pszNameLast;
1398: pszNameLast = pszName;
1399: pszName = pszNameTemp;
1400: iIndex++;
1401: }
1402: }
1403:
1404: /*
1405: * Initialize the font fields. The order the fields are set
1406: * is important, because setting the face name clears out the
1407: * point size combo.
1408: */
1409: SetDlgItemText(hwndDlg, DID_DLGSTYLEFONTNAME, diNew.szFontName);
1410: FillPointSizeCombo(hwndDlg, diNew.szFontName);
1411: }
1412:
1413:
1414:
1415: /************************************************************************
1416: * FontNameEnumFunc
1417: *
1418: * Enumeration function that adds all the font face names to the
1419: * Font Face Name combo box in the Dialog Styles dialog.
1420: *
1421: * Arguments:
1422: * LPLOGFONT lpLogFont - pointer to font structure
1423: * LPTEXTMETRIC lpTextMetric - pointer to textmetric struct for font
1424: * INT nFontType - type of font
1425: * LPVOID lpData - font data
1426: *
1427: ************************************************************************/
1428:
1429: BOOL APIENTRY FontNameEnumFunc(
1430: LPLOGFONT lpLogFont,
1431: LPTEXTMETRIC lpTextMetric,
1432: INT nFontType,
1433: LPVOID lpData)
1434: {
1435: /*
1436: * Add this name to the combo box.
1437: */
1438: SendMessage(*((LPHWND)lpData), CB_ADDSTRING, 0,
1439: (DWORD)lpLogFont->lfFaceName);
1440:
1441: /*
1442: * Keep on going...
1443: */
1444: return TRUE;
1445: }
1446:
1447:
1448:
1449: /************************************************************************
1450: * FillPointSizeCombo
1451: *
1452: * This function fills the Point Size combobox with the point sizes
1453: * that are available for the given face name. It should be called
1454: * whenever the Font Name combobox is changed to keep them in sync.
1455: *
1456: * Arguments:
1457: * HWND hwndDlg - Dialog window handle.
1458: * LPTSTR pszFaceName - Face name for the selected font.
1459: *
1460: ************************************************************************/
1461:
1462: STATICFN VOID FillPointSizeCombo(
1463: HWND hwndDlg,
1464: LPTSTR pszFaceName)
1465: {
1466: HDC hDC;
1467: HWND hwndCombo;
1468:
1469: hwndCombo = GetDlgItem(hwndDlg, DID_DLGSTYLEPOINTSIZE);
1470: SendMessage(hwndCombo, CB_RESETCONTENT, 0, 0L);
1471:
1472: if (*pszFaceName && (hDC = GetDC(ghwndMain))) {
1473: EnumFonts(hDC, pszFaceName, (FONTENUMPROC) PointSizeEnumFunc, (LPARAM)&hwndCombo);
1474: ReleaseDC(ghwndMain, hDC);
1475: }
1476:
1477: /*
1478: * Select a default one. This is the point size that is currently
1479: * selected if the face name is the current one, or else it is the
1480: * first point size in the list.
1481: */
1482: if (gcd.fFontSpecified && lstrcmp(pszFaceName, gcd.di.szFontName) == 0)
1483: SetDlgItemInt(hwndDlg, DID_DLGSTYLEPOINTSIZE, gcd.di.nPointSize, FALSE);
1484: else
1485: SendDlgItemMessage(hwndDlg, DID_DLGSTYLEPOINTSIZE,
1486: CB_SETCURSEL, 0, 0L);
1487: }
1488:
1489:
1490:
1491: /************************************************************************
1492: * PointSizeEnumFunc
1493: *
1494: * Enumeration function that adds all the point sizes to the
1495: * Pt. Size combo box in the Dialog Styles dialog.
1496: *
1497: * Arguments:
1498: * LPLOGFONT lpLogFont - pointer to font structure
1499: * LPTEXTMETRIC lpTextMetric - pointer to textmetric struct for font
1500: * INT nFontType - type of font
1501: * LPVOID lpData - font data
1502: *
1503: ************************************************************************/
1504:
1505: BOOL APIENTRY PointSizeEnumFunc(
1506: LPLOGFONT lpLogFont,
1507: LPTEXTMETRIC lpTextMetric,
1508: INT nFontType,
1509: LPVOID lpData)
1510: {
1511: HWND hwndCombo;
1512: INT nPointSize;
1513:
1514: hwndCombo = *((LPHWND)lpData);
1515:
1516: if (nFontType == RASTER_FONTTYPE) {
1517: /*
1518: * Convert the pixels to point size. Note that because of the
1519: * definition of the tmHeight field, the tmInternalLeading has
1520: * to be subtracted from it before converting to get the proper
1521: * font point size. This is done automatically by the Windows
1522: * CreateFont call if you pass in a nHeight parameter that is
1523: * negative, so be aware of this when doing the reverse calculation
1524: * to create a font of the proper height!
1525: */
1526: nPointSize = PixelsToPointSize(
1527: lpTextMetric->tmHeight - lpTextMetric->tmInternalLeading);
1528:
1529: AddToPointSizeCombo(hwndCombo, nPointSize);
1530: }
1531: else {
1532: /*
1533: * For scalable (TrueType, ATM or vector) fonts, add the
1534: * common point sizes. This list was pulled out of the
1535: ( commdlg.dll Font dialog.
1536: */
1537: AddToPointSizeCombo(hwndCombo, 8);
1538: AddToPointSizeCombo(hwndCombo, 9);
1539: AddToPointSizeCombo(hwndCombo, 10);
1540: AddToPointSizeCombo(hwndCombo, 11);
1541: AddToPointSizeCombo(hwndCombo, 12);
1542: AddToPointSizeCombo(hwndCombo, 14);
1543: AddToPointSizeCombo(hwndCombo, 16);
1544: AddToPointSizeCombo(hwndCombo, 18);
1545: AddToPointSizeCombo(hwndCombo, 20);
1546: AddToPointSizeCombo(hwndCombo, 22);
1547: AddToPointSizeCombo(hwndCombo, 24);
1548: AddToPointSizeCombo(hwndCombo, 26);
1549: AddToPointSizeCombo(hwndCombo, 28);
1550: AddToPointSizeCombo(hwndCombo, 36);
1551: AddToPointSizeCombo(hwndCombo, 48);
1552: AddToPointSizeCombo(hwndCombo, 72);
1553: }
1554:
1555: /*
1556: * Keep on going...
1557: */
1558: return TRUE;
1559: }
1560:
1561:
1562:
1563: /************************************************************************
1564: * AddToPointSizeCombo
1565: *
1566: * This function adds a point size to the point size combobox.
1567: * It does not allow duplicate point sizes, and the sizes will
1568: * be inserted in order.
1569: *
1570: * Arguments:
1571: * HWND hwndCombo - The combobox window handle.
1572: * INT nPointSize - The point size to add.
1573: *
1574: ************************************************************************/
1575:
1576: STATICFN VOID AddToPointSizeCombo(
1577: HWND hwndCombo,
1578: INT nPointSize)
1579: {
1580: TCHAR szPointSize[31];
1581: INT nPoints2;
1582: INT iIndex;
1583: INT iIndexAdd;
1584: INT iItems;
1585:
1586: iItems = (INT)SendMessage(hwndCombo, CB_GETCOUNT, 0, 0);
1587: for (iIndex = 0, iIndexAdd = -1; iIndex < iItems; iIndex++) {
1588: nPoints2 = (INT)SendMessage(hwndCombo, CB_GETITEMDATA, iIndex, 0);
1589:
1590: if (nPoints2 == nPointSize) {
1591: /*
1592: * A duplicate was found. Skip this one.
1593: */
1594: return;
1595: }
1596: else if (nPoints2 > nPointSize) {
1597: iIndexAdd = iIndex;
1598: break;
1599: }
1600: }
1601:
1602: /*
1603: * Add this point size to the combo box.
1604: */
1605: itoaw(nPointSize, szPointSize, 10);
1606: iIndex = (INT)SendMessage(hwndCombo, CB_INSERTSTRING,
1607: iIndexAdd, (DWORD)szPointSize);
1608: SendMessage(hwndCombo, CB_SETITEMDATA, iIndex, (DWORD)nPointSize);
1609: }
1610:
1611:
1612:
1613: /************************************************************************
1614: * FillLanguageCombo
1615: *
1616: * This function fills the Language combobox with the known languages.
1617: *
1618: * Arguments:
1619: * HWND hwndDlg - Dialog window handle.
1620: *
1621: ************************************************************************/
1622:
1623: STATICFN VOID FillLanguageCombo(
1624: HWND hwndDlg)
1625: {
1626: HWND hwndCombo;
1627: INT i;
1628: INT iIndex;
1629: INT iSel;
1630: INT iLang;
1631: WORD wPrimary;
1632:
1633: hwndCombo = GetDlgItem(hwndDlg, DID_DLGSTYLELANG);
1634: SendMessage(hwndCombo, CB_RESETCONTENT, 0, 0L);
1635:
1636: for (i = 0; i < gcLanguages; i++) {
1637: iIndex = (INT)SendMessage(hwndCombo, CB_ADDSTRING,
1638: 0, (DWORD)ids(gaLangTable[i].idsLangDesc));
1639: SendMessage(hwndCombo, CB_SETITEMDATA, iIndex, (DWORD)i);
1640: }
1641:
1642: wPrimary = (WORD)PRIMARYLANGID(diNew.wLanguage);
1643: for (i = 0, iSel = 0; i < gcLanguages; i++) {
1644: iLang = (INT)SendMessage(hwndCombo, CB_GETITEMDATA, i, 0);
1645:
1646: if (gaLangTable[iLang].wPrimary == wPrimary) {
1647: iSel = i;
1648: break;
1649: }
1650: }
1651:
1652: SendMessage(hwndCombo, CB_SETCURSEL, iSel, 0L);
1653:
1654: FillSubLanguageCombo(hwndDlg,
1655: (INT)SendMessage(hwndCombo, CB_GETITEMDATA, iSel, 0));
1656: }
1657:
1658:
1659:
1660: /************************************************************************
1661: * FillSubLanguageCombo
1662: *
1663: * This function fills the Sub-Language combobox with the sub-languages
1664: * for the specified language.
1665: *
1666: * Arguments:
1667: * HWND hwndDlg - Dialog window handle.
1668: * INT iLang - Index to the language in the language table.
1669: *
1670: ************************************************************************/
1671:
1672: STATICFN VOID FillSubLanguageCombo(
1673: HWND hwndDlg,
1674: INT iLang)
1675: {
1676: HWND hwndCombo;
1677: INT i;
1678: INT iIndex;
1679: INT iSel = 0;
1680: WORD wSubLang;
1681:
1682: hwndCombo = GetDlgItem(hwndDlg, DID_DLGSTYLESUBLANG);
1683: SendMessage(hwndCombo, CB_RESETCONTENT, 0, 0L);
1684:
1685: for (i = 0; i < gaLangTable[iLang].cSubLangs; i++) {
1686: iIndex = (INT)SendMessage(hwndCombo, CB_ADDSTRING, 0,
1687: (DWORD)ids(gaLangTable[iLang].asl[i].idsSubLangDesc));
1688: SendMessage(hwndCombo, CB_SETITEMDATA, iIndex, (DWORD)i);
1689: }
1690:
1691: /*
1692: * Is this the language set for the dialog? If so, find the
1693: * sublanguage and make that the default.
1694: */
1695: if (gaLangTable[iLang].wPrimary == (WORD)PRIMARYLANGID(diNew.wLanguage)) {
1696: wSubLang = SUBLANGID(diNew.wLanguage);
1697: for (i = 0; i < gaLangTable[iLang].cSubLangs; i++) {
1698: iIndex = (INT)SendMessage(hwndCombo, CB_GETITEMDATA, i, 0);
1699: if (wSubLang == gaLangTable[iLang].asl[iIndex].wSubLang) {
1700: iSel = i;
1701: break;
1702: }
1703: }
1704: }
1705:
1706: SendMessage(hwndCombo, CB_SETCURSEL, iSel, 0L);
1707: }
1708:
1709:
1710:
1711: /************************************************************************
1712: * CheckStyleBoxes
1713: *
1714: * This function takes the given style and checks the appropriate
1715: * check boxes and radio buttons in the styles dialog. The iClass
1716: * determines the lookup table to use.
1717: *
1718: * Arguments:
1719: * HWND hwnd - Dialog window handle.
1720: * INT iClass - Control class (determines the style lookup table).
1721: * DWORD flStyle - Style of the control.
1722: *
1723: ************************************************************************/
1724:
1725: STATICFN VOID CheckStyleBoxes(
1726: HWND hwnd,
1727: INT iClass,
1728: DWORD flStyle)
1729: {
1730: register INT i;
1731: PCLASSSTYLE pcs;
1732: HWND hwndControl;
1733: DWORD flStyleMask;
1734:
1735: i = acsd[iClass].cClassStyles;
1736: pcs = acsd[iClass].pacs;
1737:
1738: while (i--) {
1739: /*
1740: * Is there a DID_* defined for this style?
1741: */
1742: if (pcs->idControl) {
1743: /*
1744: * Does the dialog have a control with this id?
1745: */
1746: if (hwndControl = GetDlgItem(hwnd, pcs->idControl)) {
1747: flStyleMask =
1748: pcs->flStyleMask ? pcs->flStyleMask : pcs->flStyle;
1749:
1750: /*
1751: * If there is a match, check the box. Otherwise,
1752: * uncheck it.
1753: */
1754: SendMessage(hwndControl, BM_SETCHECK,
1755: ((flStyle & flStyleMask) == pcs->flStyle) ? 1 : 0,
1756: 0L);
1757: }
1758: }
1759:
1760: pcs++;
1761: }
1762: }
1763:
1764:
1765:
1766: /************************************************************************
1767: * QueryCheckedStyles
1768: *
1769: * This function returns the new style that the user has selected from
1770: * dialog. It reads all the checkboxes and builds up the style.
1771: * Upon entry, the DWORD that is at pflStyle should be set to the
1772: * original style for the control. Chosen bits will be masked off
1773: * and set as appropriate. This allows bits that are not settable
1774: * from within this styles dialog to be left untouched.
1775: *
1776: * Arguments:
1777: * HWND hwnd - Dialog window handle.
1778: * INT iClass - Control class (determines the style lookup table).
1779: * DWORD *pflStyle - Where to return the style of the control. What
1780: * this points to should initially have the original
1781: * styles of the control.
1782: *
1783: ************************************************************************/
1784:
1785: STATICFN VOID QueryCheckedStyles(
1786: HWND hwnd,
1787: INT iClass,
1788: DWORD *pflStyle)
1789: {
1790: register INT i;
1791: PCLASSSTYLE pcs;
1792: HWND hwndControl;
1793: DWORD flStyleMask;
1794: DWORD flStyle;
1795:
1796: /*
1797: * The first step is to strip off all bits that may be changed by
1798: * the current dialog.
1799: */
1800: flStyle = *pflStyle;
1801: i = acsd[iClass].cClassStyles;
1802: pcs = acsd[iClass].pacs;
1803: while (i--) {
1804: /*
1805: * Is this a style that is settable by a dialog, and does the
1806: * current dialog have this style control?
1807: */
1808: if (pcs->idControl && GetDlgItem(hwnd, pcs->idControl)) {
1809: flStyleMask =
1810: pcs->flStyleMask ? pcs->flStyleMask : pcs->flStyle;
1811:
1812: /*
1813: * Strip off all bits in the mask for this style.
1814: */
1815: flStyle &= ~flStyleMask;
1816: }
1817:
1818: pcs++;
1819: }
1820:
1821: /*
1822: * Now we go through all bits that may be set and set any that the
1823: * user has selected.
1824: */
1825: i = acsd[iClass].cClassStyles;
1826: pcs = acsd[iClass].pacs;
1827: while (i--) {
1828: if (pcs->idControl &&
1829: (hwndControl = GetDlgItem(hwnd, pcs->idControl))) {
1830: if (SendMessage(hwndControl, BM_GETCHECK, 0, 0L))
1831: flStyle |= pcs->flStyle;
1832: }
1833:
1834: pcs++;
1835: }
1836:
1837: *pflStyle = flStyle;
1838: }
1839:
1840:
1841:
1842: /************************************************************************
1843: * StylesHelp
1844: *
1845: * This function shows the appropriate help context from any of the
1846: * styles dialogs. It uses the type of control in npcStyles to
1847: * determine what help to show.
1848: *
1849: ************************************************************************/
1850:
1851: STATICFN VOID StylesHelp(VOID)
1852: {
1853: WinHelp(ghwndMain, gszHelpFile, HELP_CONTEXT,
1854: npcStyles->pwcd->HelpContext);
1855: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.