|
|
1.1 ! root 1: /*==============================================================*\ ! 2: * Dialog.c - window procedures for the dialog boxes as well ! 3: * as utility procedures used by them ! 4: * Created 1990, Microsoft, IBM Corp. ! 5: *-------------------------------------------------------------- ! 6: * ! 7: * This module contains the Dialog Procedures for the user ! 8: * defined dialogs as well as any support code they need ! 9: * ! 10: *-------------------------------------------------------------- ! 11: * ! 12: * This source file contains the following functions: ! 13: * ! 14: * DemoDlgProc(hwnd, msg, mp1, mp2) ! 15: * PresParamDemoDlgProc(hwnd, msg, mp1, mp2) ! 16: * AboutBoxDlgProc(hwnd, msg, mp1, mp2) ! 17: * LoadListBox(hwnd) ! 18: * InitPresParamDemoDlg(hwnd) ! 19: * UpdatePresParamDemoDlg(hwnd) ! 20: * ! 21: \*==============================================================*/ ! 22: ! 23: /*--------------------------------------------------------------*\ ! 24: * Include files, macros, defined constants, and externs ! 25: \*--------------------------------------------------------------*/ ! 26: ! 27: #define INCL_WINWINDOWMGR ! 28: #define INCL_WININPUT ! 29: #define INCL_WINLISTBOXES ! 30: #define INCL_WINENTRYFIELDS ! 31: #define INCL_WINSYS ! 32: #define INCL_GPILCIDS ! 33: #define INCL_DOSMEMMGR ! 34: ! 35: #include <os2.h> ! 36: #include <string.h> ! 37: #include "sty_main.h" ! 38: #include "sty_dlg.h" ! 39: #include "sty_xtrn.h" ! 40: #include "sty_help.h" ! 41: ! 42: #define COLORNAMELEN 20 ! 43: #define NUMCOLORS 15 /* number of colors used in PP Demo */ ! 44: #define NUMFONTS 4 /* number of fonts used in PP Demo */ ! 45: #define FONTPOINTSIZE 80 /* point size to use in PP Demo */ ! 46: #define PPFONTPOINTSIZE 2 /* length of font point prefix */ ! 47: ! 48: /*--------------------------------------------------------------*\ ! 49: * Global variables ! 50: \*--------------------------------------------------------------*/ ! 51: static CHAR apszPresParamColor[NUMCOLORS][COLORNAMELEN]; /* array of clr names */ ! 52: static PSZ *apszPresParamFont = NULL; ! 53: static LONG lNumFonts; ! 54: ! 55: /* set up an array of colors in the same order as the stringtable ! 56: constants */ ! 57: static ULONG aulColor[NUMCOLORS-1] = { CLR_BLUE, ! 58: CLR_RED, ! 59: CLR_PINK, ! 60: CLR_GREEN, ! 61: CLR_CYAN, ! 62: CLR_YELLOW, ! 63: CLR_DARKGRAY, ! 64: CLR_DARKBLUE, ! 65: CLR_DARKRED, ! 66: CLR_DARKPINK, ! 67: CLR_DARKGREEN, ! 68: CLR_DARKCYAN, ! 69: CLR_BROWN, ! 70: CLR_PALEGRAY ! 71: }; ! 72: ! 73: ! 74: /*--------------------------------------------------------------*\ ! 75: * Entry point declarations ! 76: \*--------------------------------------------------------------*/ ! 77: ! 78: MRESULT EXPENTRY AboutBoxDlgProc(HWND hwnd, USHORT msg, ! 79: MPARAM mp1, MPARAM mp2); ! 80: MRESULT EXPENTRY DemoDlgProc(HWND hwnd, USHORT msg, ! 81: MPARAM mp1, MPARAM mp2); ! 82: MRESULT EXPENTRY PresParamDemoDlgProc(HWND hwnd, USHORT msg, ! 83: MPARAM mp1, MPARAM mp2); ! 84: BOOL LoadListBox(HWND hwnd); ! 85: BOOL InitPresParamDemoDlg(HWND hwnd); ! 86: BOOL UpdatePresParamDemoDlg(HWND hwnd); ! 87: VOID ShowDlgHelp(HWND hwnd); ! 88: ! 89: ! 90: /****************************************************************\ ! 91: * Dialog procedure for the About dialog box ! 92: *-------------------------------------------------------------- ! 93: * ! 94: * Name: AboutBoxDlgProc(hwnd, msg, mp1, mp2) ! 95: * ! 96: * Purpose: Processes all messages sent to the About Box ! 97: * ! 98: * Usage: Called for each message sent to the About Box ! 99: * dialog box. ! 100: * ! 101: * Method: the about box only has a button control so this ! 102: * routine only processes WM_COMMAND messages. Any ! 103: * WM_COMMAND posted must have come from the Ok ! 104: * button so we dismiss the dialog upon receiving it. ! 105: * ! 106: * Returns: Dependent upon message sent ! 107: * ! 108: \****************************************************************/ ! 109: MRESULT EXPENTRY AboutBoxDlgProc(hwnd, msg, mp1, mp2) ! 110: HWND hwnd; /* handle of window */ ! 111: USHORT msg; /* id of message */ ! 112: MPARAM mp1; /* first message parameter */ ! 113: MPARAM mp2; /* second message parameter */ ! 114: { ! 115: switch(msg) { ! 116: case WM_COMMAND: ! 117: /* no matter what the command, close the dialog */ ! 118: WinDismissDlg(hwnd, TRUE); ! 119: break; ! 120: ! 121: case WM_HELP: ! 122: ShowDlgHelp(hwnd); ! 123: break; ! 124: ! 125: default: ! 126: return(WinDefDlgProc(hwnd, msg, mp1, mp2)); ! 127: break; ! 128: } ! 129: ! 130: return 0L; ! 131: ! 132: } /* AboutBoxDlgProc() */ ! 133: ! 134: /****************************************************************\ ! 135: * Dialog procedure for the Dialog control demo dialogs ! 136: *-------------------------------------------------------------- ! 137: * ! 138: * Name: DemoDlgProc(hwnd, msg, mp1, mp2) ! 139: * ! 140: * Purpose: Processes all messages sent to all Demo dialogs. ! 141: * The Demo dialogs only have an Ok and a Help button ! 142: * so they can all share this dialog proc. ! 143: * ! 144: * Usage: Called for each message sent to a demo dialog box. ! 145: * ! 146: * Method: a switch statement branches to the routines to be ! 147: * performed for each message processed. Any messages ! 148: * not specifically process are passed to the default ! 149: * window procedure WinDefDlgProc() ! 150: * ! 151: * Returns: Dependent upon message sent ! 152: * ! 153: \****************************************************************/ ! 154: MRESULT EXPENTRY DemoDlgProc(hwnd, msg, mp1, mp2) ! 155: HWND hwnd; /* handle of window */ ! 156: USHORT msg; /* id of message */ ! 157: MPARAM mp1; /* first message parameter */ ! 158: MPARAM mp2; /* second message parameter */ ! 159: { ! 160: switch(msg) { ! 161: case WM_INITDLG: ! 162: switch(SHORT1FROMMP(mp2)) { ! 163: /*---------------------------------------------* ! 164: * The ShowDemoDlg() filled mp2 with the id of ! 165: * the dialog template used to create the ! 166: * dialog box. If the dialog contains listboxes ! 167: * or comboboxes, fill them with text. ! 168: *---------------------------------------------*/ ! 169: ! 170: case IDD_LISTBOXDLG: ! 171: /* Load some text into the list boxes. If any of the ! 172: LoadListBox() routines fail, abort the dialog */ ! 173: if( ! 174: !LoadListBox(WinWindowFromID(hwnd, IDC_LISTBOX)) || ! 175: !LoadListBox(WinWindowFromID(hwnd, IDC_MULTISELLISTBOX))) ! 176: WinDismissDlg(hwnd, FALSE); ! 177: break; ! 178: ! 179: case IDD_COMBOBOXDLG: ! 180: /* Load some text into the combo boxes. If any of the ! 181: LoadListBox() routines fail, abort the dialog */ ! 182: if(!LoadListBox(WinWindowFromID(hwnd, IDC_SIMPLE)) || ! 183: !LoadListBox(WinWindowFromID(hwnd, IDC_DROPDOWN)) || ! 184: !LoadListBox(WinWindowFromID(hwnd, IDC_DROPDOWNLIST))) ! 185: WinDismissDlg(hwnd, FALSE); ! 186: break; ! 187: ! 188: default: ! 189: break; ! 190: } ! 191: return FALSE; ! 192: break; ! 193: ! 194: case WM_COMMAND: ! 195: if(SHORT1FROMMP(mp1) == IDC_OK || SHORT1FROMMP(mp1) == IDC_CANCEL) ! 196: /* close the dialog if the Ok button is presssed */ ! 197: WinDismissDlg(hwnd, TRUE); ! 198: break; ! 199: ! 200: case WM_HELP: ! 201: ShowDlgHelp(hwnd); ! 202: break; ! 203: ! 204: default: ! 205: return(WinDefDlgProc(hwnd, msg, mp1, mp2)); ! 206: break; ! 207: } ! 208: ! 209: return 0L; ! 210: ! 211: } /* DemoDlgProc() */ ! 212: ! 213: /****************************************************************\ ! 214: * Loads the given listbox with strings of 0 to 9 ! 215: *-------------------------------------------------------------- ! 216: * ! 217: * Name: LoadListBox(hwnd) ! 218: * ! 219: * Purpose: Loads the demo list box with 0 through 9 ! 220: * ! 221: * Usage: Called each time a demo list box is initialized ! 222: * ! 223: * Method: a for 0 to 9 loop is converts the INT to a string ! 224: * which is added to the listbo via LM_INSERTITEM ! 225: * ! 226: * Returns: TRUE if list box is loaded successfully, FALSE otherwise ! 227: * ! 228: \****************************************************************/ ! 229: BOOL LoadListBox(hwnd) ! 230: HWND hwnd; /* handle of list box window */ ! 231: { ! 232: register SHORT sT; ! 233: CHAR szT[MESSAGELEN]; ! 234: SHORT sRet; ! 235: ! 236: for(sT = 0; sT < 10; sT++) { ! 237: if(!WinLoadString(hab, ! 238: NULL, ! 239: IDS_LISTBOX1 + sT, ! 240: MESSAGELEN, ! 241: (PSZ)szT)) { ! 242: ! 243: MessageBox(hwndMain, ! 244: IDMSG_CANNOTLOADSTRING, ! 245: MB_OK | MB_ERROR, ! 246: FALSE); ! 247: ! 248: return FALSE; ! 249: } ! 250: ! 251: sRet = (SHORT)WinSendMsg(hwnd, ! 252: LM_INSERTITEM, ! 253: MPFROMSHORT(LIT_SORTASCENDING), ! 254: MPFROMP((PSZ)szT)); ! 255: ! 256: if(sRet == LIT_ERROR || sRet == LIT_MEMERROR) { ! 257: MessageBox(hwndMain, ! 258: IDMSG_CANNOTLOADSTRING, ! 259: MB_OK | MB_ERROR, ! 260: FALSE); ! 261: ! 262: return FALSE; ! 263: } ! 264: } ! 265: ! 266: return TRUE; ! 267: ! 268: } /* LoadListBox() */ ! 269: ! 270: ! 271: /****************************************************************\ ! 272: * Dialog procedure for the Presentation Parameter demo dialog ! 273: *-------------------------------------------------------------- ! 274: * ! 275: * Name: PresParamDemoDlgProc(hwnd, msg, mp1, mp2) ! 276: * ! 277: * Purpose: Processes all messages sent to the PresParamDemo dialog ! 278: * ! 279: * Usage: Called for each message sent to the PresParamDemo ! 280: * dialog box. ! 281: * ! 282: * Method: a switch statement branches to the routines to be ! 283: * performed for each message processed. Any messages ! 284: * not specifically process are passed to the default ! 285: * window procedure WinDefDlgProc() ! 286: * ! 287: * Returns: Dependent upon message sent ! 288: * ! 289: \****************************************************************/ ! 290: MRESULT EXPENTRY PresParamDemoDlgProc(hwnd, msg, mp1, mp2) ! 291: HWND hwnd; /* handle of window */ ! 292: USHORT msg; /* id of message */ ! 293: MPARAM mp1; /* first message parameter */ ! 294: MPARAM mp2; /* second message parameter */ ! 295: { ! 296: switch(msg) { ! 297: case WM_INITDLG: ! 298: /* if initialization fails, abort the dialog */ ! 299: if(!InitPresParamDemoDlg(hwnd)) ! 300: WinDismissDlg(hwnd, FALSE); ! 301: return FALSE; ! 302: break; ! 303: ! 304: case WM_COMMAND: ! 305: switch(SHORT1FROMMP(mp1)) { ! 306: case IDC_CANCEL: /* if done, close the dialog */ ! 307: WinDismissDlg(hwnd, TRUE); ! 308: break; ! 309: ! 310: case IDC_APPLY: /* update the dialog */ ! 311: UpdatePresParamDemoDlg(hwnd); ! 312: break; ! 313: ! 314: default: ! 315: break; ! 316: } ! 317: break; ! 318: ! 319: case WM_HELP: ! 320: ShowDlgHelp(hwnd); ! 321: break; ! 322: ! 323: default: ! 324: return(WinDefDlgProc(hwnd, msg, mp1, mp2)); ! 325: break; ! 326: } ! 327: ! 328: return 0L; ! 329: ! 330: } /* PresParamDemoDlgProc() */ ! 331: ! 332: /****************************************************************\ ! 333: * Initializes the Presentation Parameter Dialog ! 334: *-------------------------------------------------------------- ! 335: * ! 336: * Name: InitPresParamDemoDlg(hwnd) ! 337: * ! 338: * Purpose: Places the colors and fonts into the PresParamDemoDlg's ! 339: * comboboxes ! 340: * ! 341: * Usage: Called when the PP demo dialog is initialized ! 342: * ! 343: * Method: LM_INSERTITEM is sent to each combobox for the ! 344: * color or font string added to the combobox ! 345: * ! 346: * Returns: TRUE if initialization is successfull, FALSE if not ! 347: * ! 348: \****************************************************************/ ! 349: BOOL InitPresParamDemoDlg(hwnd) ! 350: HWND hwnd; /* handle of the dialog window */ ! 351: { ! 352: HWND hwndT; ! 353: register SHORT sT; ! 354: SHORT sRet; ! 355: PFONTMETRICS pfm, pfmSave; ! 356: LONG lT, lFonts; ! 357: HPS hps; ! 358: PSZ *ppszT; ! 359: BOOL fHaveFont; ! 360: ! 361: ! 362: /* load the color table */ ! 363: for(sT = 0; sT < NUMCOLORS; sT++) { ! 364: if(!WinLoadString(hab, ! 365: NULL, ! 366: sT + IDS_FIRSTCOLOR, ! 367: COLORNAMELEN, ! 368: (PSZ)apszPresParamColor[sT])) { ! 369: ! 370: MessageBox(hwndMain, ! 371: IDMSG_CANNOTLOADSTRING, ! 372: MB_OK | MB_ERROR, ! 373: FALSE); ! 374: ! 375: return FALSE; ! 376: } ! 377: } ! 378: ! 379: /* load foreground color combo box */ ! 380: hwndT = WinWindowFromID(hwnd, IDC_FORECOLORLIST); ! 381: ! 382: for(sT = 0; sT < NUMCOLORS; sT++) { ! 383: sRet = (SHORT)WinSendMsg(hwndT, ! 384: LM_INSERTITEM, ! 385: MPFROMSHORT(LIT_SORTASCENDING), ! 386: MPFROMP((PSZ)apszPresParamColor[sT])); ! 387: ! 388: if(sT == LIT_ERROR || sT == LIT_MEMERROR) { ! 389: MessageBox(hwndMain, ! 390: IDMSG_CANNOTLOADSTRING, ! 391: MB_OK | MB_ERROR, ! 392: FALSE); ! 393: ! 394: return FALSE; ! 395: } ! 396: ! 397: } ! 398: ! 399: /* load background color combo box */ ! 400: hwndT = WinWindowFromID(hwnd, IDC_BACKCOLORLIST); ! 401: ! 402: for(sT = 0; sT < NUMCOLORS; sT++) { ! 403: sRet = (SHORT)WinSendMsg(hwndT, ! 404: LM_INSERTITEM, ! 405: MPFROMSHORT(LIT_SORTASCENDING), ! 406: MPFROMP((PSZ)apszPresParamColor[sT])); ! 407: ! 408: if(sT == LIT_ERROR || sT == LIT_MEMERROR) { ! 409: MessageBox(hwndMain, ! 410: IDMSG_CANNOTLOADSTRING, ! 411: MB_OK | MB_ERROR, ! 412: FALSE); ! 413: ! 414: return FALSE; ! 415: } ! 416: } ! 417: ! 418: ! 419: /* Fonts. Find all of the fonts of point size desired and normal ! 420: weight. Put the facenames in the combo box */ ! 421: hwndT = WinWindowFromID(hwnd, IDC_FONTLIST); ! 422: hps = WinGetPS(hwndT); ! 423: ! 424: /* determine the number of fonts available */ ! 425: lFonts = 0L; ! 426: lT = 0L; ! 427: lFonts = GpiQueryFonts(hps, ! 428: QF_PUBLIC, ! 429: NULL, ! 430: &lT, ! 431: (ULONG)sizeof(FONTMETRICS), ! 432: (PFONTMETRICS)NULL); ! 433: ! 434: if(lFonts == GPI_ALTERROR) { ! 435: MessageBox(hwndMain, ! 436: IDMSG_CANNOTLOADFONTS, ! 437: MB_OK | MB_ERROR, ! 438: FALSE); ! 439: ! 440: WinReleasePS(hps); ! 441: return FALSE; ! 442: } ! 443: ! 444: ! 445: /* allocate buffer for fontmetric structures */ ! 446: if(DosAllocMem((PPVOID)&pfm, ! 447: lFonts * (ULONG)sizeof(FONTMETRICS), ! 448: fALLOC)) { ! 449: MessageBox(hwndMain, ! 450: IDMSG_CANNOTALLOCATEMEMORY, ! 451: MB_OK | MB_ERROR, ! 452: FALSE); ! 453: ! 454: WinReleasePS(hps); ! 455: return FALSE; ! 456: } ! 457: pfmSave = pfm; ! 458: ! 459: /* get all fonts */ ! 460: lT = GpiQueryFonts(hps, ! 461: QF_PUBLIC, ! 462: NULL, ! 463: &lFonts, ! 464: (ULONG)sizeof(FONTMETRICS), ! 465: (PFONTMETRICS)pfm); ! 466: ! 467: WinReleasePS(hps); ! 468: ! 469: if(lT == GPI_ALTERROR) { ! 470: MessageBox(hwndMain, ! 471: IDMSG_CANNOTLOADFONTS, ! 472: MB_OK | MB_ERROR, ! 473: FALSE); ! 474: ! 475: return FALSE; ! 476: } ! 477: ! 478: /* allocate buffer for array of string names, freeing the first ! 479: buffer if necessary */ ! 480: if(apszPresParamFont) { ! 481: ppszT = apszPresParamFont; ! 482: while(*ppszT) { ! 483: DosFreeMem(*ppszT++); ! 484: } ! 485: ! 486: DosFreeMem(apszPresParamFont); ! 487: } ! 488: ! 489: if(DosAllocMem((PPVOID)&apszPresParamFont, ! 490: (lFonts + 1L) * (ULONG)sizeof(PSZ), ! 491: fALLOC)) { ! 492: MessageBox(hwndMain, ! 493: IDMSG_CANNOTALLOCATEMEMORY, ! 494: MB_OK | MB_ERROR, ! 495: FALSE); ! 496: ! 497: DosFreeMem((PVOID)pfmSave); ! 498: apszPresParamFont = NULL; ! 499: return FALSE; ! 500: } ! 501: ! 502: /* initialize array to NULL */ ! 503: lT = 0L; ! 504: ppszT = apszPresParamFont; ! 505: while(lT++ < lFonts) ! 506: *ppszT++ = (PSZ)NULL; ! 507: *ppszT = (PSZ)NULL; ! 508: ! 509: ! 510: /* walk through all fonts. If the font matches the point size ! 511: desired and has a weight and width class of normal (5) and ! 512: no special attributes (e. g. italic, underline, etc.). If ! 513: it does, then add its string to the combo box */ ! 514: lNumFonts = 0L; ! 515: ppszT = apszPresParamFont; ! 516: ! 517: while(lFonts--) { ! 518: if(pfm->sNominalPointSize == FONTPOINTSIZE && ! 519: pfm->usWeightClass == 5 && ! 520: pfm->usWidthClass == 5 && ! 521: pfm->fsSelection == 0) { ! 522: ! 523: /* make sure we don't have this font. If we don't, ! 524: then add the font to the list */ ! 525: lT = 0L; ! 526: fHaveFont = FALSE; ! 527: while(lT < lNumFonts) { ! 528: if(!strcmp(pfm->szFacename, ! 529: apszPresParamFont[(INT)lT])) { ! 530: fHaveFont = TRUE; ! 531: break; ! 532: } else ! 533: lT++; ! 534: } ! 535: ! 536: if(!fHaveFont) { ! 537: if(DosAllocMem((PPVOID)ppszT, ! 538: (LONG)(FACESIZE * sizeof(CHAR)), ! 539: fALLOC)) { ! 540: ! 541: MessageBox(hwndMain, ! 542: IDMSG_CANNOTALLOCATEMEMORY, ! 543: MB_OK | MB_ERROR, ! 544: FALSE); ! 545: ! 546: DosFreeMem((PVOID)pfmSave); ! 547: return FALSE; ! 548: } ! 549: ! 550: strcpy(*ppszT++, pfm->szFacename); ! 551: lNumFonts++; ! 552: } ! 553: } ! 554: ! 555: pfm++; ! 556: } ! 557: ! 558: ! 559: /* install the name of each font into the combo box */ ! 560: ppszT = apszPresParamFont; ! 561: while(*ppszT) { ! 562: lT = (LONG)WinSendMsg(hwndT, ! 563: LM_INSERTITEM, ! 564: MPFROMSHORT(LIT_SORTASCENDING), ! 565: MPFROMP((PSZ)*ppszT++)); ! 566: ! 567: if(sT == LIT_ERROR || sT == LIT_MEMERROR) { ! 568: MessageBox(hwndMain, ! 569: IDMSG_CANNOTLOADSTRING, ! 570: MB_OK | MB_ERROR, ! 571: FALSE); ! 572: ! 573: DosFreeMem((PVOID)pfmSave); ! 574: return FALSE; ! 575: } ! 576: } ! 577: ! 578: /* add "Default" text onto the end */ ! 579: lT = (LONG)WinSendMsg(hwndT, ! 580: LM_INSERTITEM, ! 581: MPFROMSHORT(LIT_SORTASCENDING), ! 582: MPFROMP(apszPresParamColor[IDS_DEFAULT - IDS_FIRSTCOLOR])); ! 583: ! 584: if(sT == LIT_ERROR || sT == LIT_MEMERROR) { ! 585: MessageBox(hwndMain, ! 586: IDMSG_CANNOTLOADSTRING, ! 587: MB_OK | MB_ERROR, ! 588: FALSE); ! 589: ! 590: DosFreeMem((PVOID)pfmSave); ! 591: return FALSE; ! 592: } ! 593: ! 594: ! 595: DosFreeMem((PVOID)pfmSave); ! 596: ! 597: return TRUE; ! 598: ! 599: } /* InitPresParamDemoDlg() */ ! 600: ! 601: /****************************************************************\ ! 602: * Updates the Presentation Parameters in the PP Demo Dialog ! 603: *-------------------------------------------------------------- ! 604: * ! 605: * Name: UpdatePresParamDemoDlg(hwnd) ! 606: * ! 607: * Purpose: Sets/Removes the Presentation Parameter of the ! 608: * sample text window depending upon the parameters ! 609: * chosen ! 610: * ! 611: * Usage: Called when user wants to update the window ! 612: * ! 613: * Method: The string of each combobox is queried and then the ! 614: * color or font is set depending upon the string ! 615: * chosen ! 616: * ! 617: * Returns: ! 618: * ! 619: \****************************************************************/ ! 620: BOOL UpdatePresParamDemoDlg(hwnd) ! 621: HWND hwnd; /* handle of the dialog window */ ! 622: { ! 623: HWND hwndT, hwndSampleText, hwndSampleButton; ! 624: CHAR szT[COLORNAMELEN]; ! 625: BYTE abBuf[FACESIZE + PPFONTPOINTSIZE]; ! 626: LONG clr, lPP; ! 627: SHORT sT; ! 628: ! 629: /* get window handle of the sample text box */ ! 630: hwndSampleText = WinWindowFromID(hwnd, IDC_SAMPLETEXT); ! 631: hwndSampleButton = WinWindowFromID(hwnd, IDC_CHECKBOX); ! 632: ! 633: /* get the text of the foreground color combobox */ ! 634: hwndT = WinWindowFromID(hwnd, IDC_FORECOLORLIST); ! 635: ! 636: if(WinQueryWindowText(hwndT, COLORNAMELEN, (PSZ)szT)) { ! 637: ! 638: /* find the text in the list of color names */ ! 639: sT = 0; ! 640: while(sT < NUMCOLORS) { ! 641: if(!strcmp(szT, apszPresParamColor[sT])) { ! 642: clr = aulColor[sT]; ! 643: break; ! 644: } else ! 645: sT++; ! 646: } ! 647: ! 648: /* if color is not default, set the color. If the default is ! 649: selected, then remove the color presentation parameter if ! 650: it exists. If the value is not a valid color, then don't ! 651: don't do anything */ ! 652: if(sT < NUMCOLORS) { ! 653: sT += IDS_FIRSTCOLOR; ! 654: if(sT < IDS_DEFAULT) { ! 655: if(!WinSetPresParam(hwndSampleText, ! 656: PP_FOREGROUNDCOLORINDEX, ! 657: (ULONG)sizeof(LONG), ! 658: (PVOID)&clr) || ! 659: !WinSetPresParam(hwndSampleButton, ! 660: PP_FOREGROUNDCOLORINDEX, ! 661: (ULONG)sizeof(LONG), ! 662: (PVOID)&clr)) { ! 663: ! 664: MessageBox(hwndMain, ! 665: IDMSG_CANNOTSETPP, ! 666: MB_OK | MB_ERROR, ! 667: FALSE); ! 668: } ! 669: ! 670: ! 671: } else { ! 672: /* If setting presentation parameter to the default, remove ! 673: the presentation parameter, but only if it has been ! 674: set */ ! 675: if(sT == IDS_DEFAULT && ! 676: WinQueryPresParam(hwndSampleText, ! 677: PP_FOREGROUNDCOLORINDEX, ! 678: 0L, ! 679: &lPP, ! 680: (LONG)sizeof(LONG), ! 681: (PVOID)&clr, ! 682: QPF_NOINHERIT) != NULL) { ! 683: ! 684: if(!WinRemovePresParam(hwndSampleText, ! 685: PP_FOREGROUNDCOLORINDEX) || ! 686: !WinRemovePresParam(hwndSampleButton, ! 687: PP_FOREGROUNDCOLORINDEX)) { ! 688: ! 689: MessageBox(hwndMain, ! 690: IDMSG_CANNOTSETPP, ! 691: MB_OK | MB_ERROR, ! 692: FALSE); ! 693: } ! 694: } ! 695: } ! 696: } ! 697: } ! 698: ! 699: ! 700: ! 701: /* Do the same for the background color combobox */ ! 702: hwndT = WinWindowFromID(hwnd, IDC_BACKCOLORLIST); ! 703: if(WinQueryWindowText(hwndT, COLORNAMELEN, (PSZ)szT)) { ! 704: ! 705: /* find the text in the list of color names */ ! 706: sT = 0; ! 707: while(sT < NUMCOLORS) { ! 708: if(!strcmp(szT, apszPresParamColor[sT])) { ! 709: clr = aulColor[sT]; ! 710: break; ! 711: } else ! 712: sT++; ! 713: } ! 714: ! 715: /* if color is not default, set the color. If the default is ! 716: selected, then remove the color presentation parameter. If ! 717: the value is not a valid color, the don't do anything */ ! 718: if(sT < NUMCOLORS) { ! 719: sT += IDS_FIRSTCOLOR; ! 720: if(sT < IDS_DEFAULT) { ! 721: if(!WinSetPresParam(hwndSampleText, ! 722: PP_BACKGROUNDCOLORINDEX, ! 723: (ULONG)sizeof(LONG), ! 724: (PVOID)&clr) || ! 725: !WinSetPresParam(hwndSampleButton, ! 726: PP_BACKGROUNDCOLORINDEX, ! 727: (ULONG)sizeof(LONG), ! 728: (PVOID)&clr)) { ! 729: ! 730: MessageBox(hwndMain, ! 731: IDMSG_CANNOTSETPP, ! 732: MB_OK | MB_ERROR, ! 733: FALSE); ! 734: } ! 735: ! 736: } else { ! 737: if(sT == IDS_DEFAULT && ! 738: WinQueryPresParam(hwndSampleText, ! 739: PP_BACKGROUNDCOLORINDEX, ! 740: 0L, ! 741: &lPP, ! 742: (LONG)sizeof(LONG), ! 743: (PVOID)&clr, ! 744: QPF_NOINHERIT) != NULL) { ! 745: ! 746: if(!WinRemovePresParam(hwndSampleText, ! 747: PP_BACKGROUNDCOLORINDEX) || ! 748: !WinRemovePresParam(hwndSampleButton, ! 749: PP_BACKGROUNDCOLORINDEX)) { ! 750: ! 751: MessageBox(hwndMain, ! 752: IDMSG_CANNOTSETPP, ! 753: MB_OK | MB_ERROR, ! 754: FALSE); ! 755: } ! 756: } ! 757: } ! 758: } ! 759: } ! 760: ! 761: ! 762: /* get the text of the font combobox */ ! 763: hwndT = WinWindowFromID(hwnd, IDC_FONTLIST); ! 764: if(WinQueryWindowText(hwndT, FACESIZE, (PSZ)szT)) { ! 765: ! 766: /* if Font selected is "Default", remove font pres. param. */ ! 767: if(!strcmp(szT, apszPresParamColor[IDS_DEFAULT - IDS_FIRSTCOLOR])) { ! 768: if(WinQueryPresParam(hwndSampleText, ! 769: PP_FONTNAMESIZE, ! 770: 0L, ! 771: &lPP, ! 772: (LONG)(FACESIZE + PPFONTPOINTSIZE), ! 773: (PVOID)abBuf, ! 774: QPF_NOINHERIT) != NULL) { ! 775: if(!WinRemovePresParam(hwndSampleText, PP_FONTNAMESIZE) || ! 776: !WinRemovePresParam(hwndSampleButton, PP_FONTNAMESIZE)) { ! 777: MessageBox(hwndMain, ! 778: IDMSG_CANNOTSETPP, ! 779: MB_OK | MB_ERROR, ! 780: FALSE); ! 781: } ! 782: } ! 783: } else { /* font is not default */ ! 784: ! 785: /*----------------------------------------------------*\ ! 786: * abBuf will hold the font point size and name in ! 787: * the form <pt>.<name>. First we fill abBuf with the ! 788: * font point prefix and then append the font name ! 789: * retrieved from the combobox. ! 790: \*----------------------------------------------------*/ ! 791: ! 792: if(!WinLoadString(hab, ! 793: NULL, ! 794: IDS_PPFONTPOINT, ! 795: COLORNAMELEN, ! 796: (PSZ)abBuf)) { ! 797: ! 798: MessageBox(hwndMain, ! 799: IDMSG_CANNOTLOADSTRING, ! 800: MB_OK | MB_ERROR, ! 801: FALSE); ! 802: ! 803: return FALSE; ! 804: } ! 805: ! 806: strcat((PSZ)abBuf, szT); ! 807: ! 808: if(!WinSetPresParam(hwndSampleText, ! 809: PP_FONTNAMESIZE, ! 810: (ULONG)strlen((PSZ)abBuf) + 1L, ! 811: (PVOID)abBuf) || ! 812: !WinSetPresParam(hwndSampleButton, ! 813: PP_FONTNAMESIZE, ! 814: (ULONG)strlen((PSZ)abBuf) + 1L, ! 815: (PVOID)abBuf)) { ! 816: ! 817: MessageBox(hwndMain, ! 818: IDMSG_CANNOTSETPP, ! 819: MB_OK | MB_ERROR, ! 820: FALSE); ! 821: } ! 822: } ! 823: } ! 824: ! 825: return TRUE; ! 826: ! 827: } /* UpdatePresParamDemoDlg() */ ! 828: ! 829: /****************************************************************\ ! 830: * Shows the help panel for the given dialog window ! 831: *-------------------------------------------------------------- ! 832: * ! 833: * Name: ShowDlgHelp(hwnd) ! 834: * ! 835: * Purpose: Displays the help panel for the current selected ! 836: * item in the dialog window ! 837: * ! 838: * Usage: Called each time a WM_HELP message is posted to ! 839: * a dialog ! 840: * ! 841: * Method: gets the id value of the window and determine which ! 842: * help panel to display. Then sends a message to ! 843: * the help instance to display the panel. If the dialog ! 844: * or item is not included here, then the unknown dialog ! 845: * or unknown item panel is displayed. ! 846: * ! 847: * Returns: ! 848: * ! 849: \****************************************************************/ ! 850: VOID ShowDlgHelp(hwnd) ! 851: HWND hwnd; /* handle of list box window */ ! 852: { ! 853: SHORT idPanel, idDlg, idItem; ! 854: HWND hwndFocus; ! 855: ! 856: /* get the id of the dialog box */ ! 857: idDlg = WinQueryWindowUShort(hwnd, QWS_ID); ! 858: ! 859: /* finds which window has the focus and gets its id */ ! 860: hwndFocus = WinQueryFocus(HWND_DESKTOP, FALSE); ! 861: idItem = WinQueryWindowUShort(hwndFocus, QWS_ID); ! 862: ! 863: switch(idDlg) { ! 864: case IDD_BUTTONSDLG: ! 865: switch(idItem) { ! 866: case IDC_RADIO1: ! 867: case IDC_RADIO2: ! 868: case IDC_RADIO3: ! 869: idPanel = PANEL_BUTTONSDLG_RADIO; ! 870: break; ! 871: ! 872: case IDC_CHECKBOX: ! 873: idPanel = PANEL_BUTTONSDLG_CHECKBOX; ! 874: break; ! 875: ! 876: case IDC_3STATE: ! 877: idPanel = PANEL_BUTTONSDLG_THREESTATE; ! 878: break; ! 879: ! 880: case IDC_PUSHBUTTON: ! 881: idPanel = PANEL_BUTTONSDLG_PUSHBUTTON; ! 882: break; ! 883: ! 884: case IDC_OK: ! 885: idPanel = PANEL_BUTTONSDLG_OK; ! 886: break; ! 887: ! 888: case IDC_HELP: ! 889: idPanel = PANEL_BUTTONSDLG_HELP; ! 890: break; ! 891: ! 892: default: ! 893: idPanel = PANEL_UNKNOWN; ! 894: break; ! 895: } ! 896: break; ! 897: ! 898: case IDD_LISTBOXDLG: ! 899: switch(idItem) { ! 900: case IDC_LISTBOX: ! 901: idPanel = PANEL_LISTBOXDLG_SINGLE; ! 902: break; ! 903: ! 904: case IDC_MULTISELLISTBOX: ! 905: idPanel = PANEL_LISTBOXDLG_MULTIPLE; ! 906: break; ! 907: ! 908: case IDC_OK: ! 909: idPanel = PANEL_LISTBOXDLG_OK; ! 910: break; ! 911: ! 912: case IDC_HELP: ! 913: idPanel = PANEL_LISTBOXDLG_HELP; ! 914: break; ! 915: ! 916: default: ! 917: idPanel = PANEL_UNKNOWN; ! 918: break; ! 919: } ! 920: break; ! 921: ! 922: case IDD_COMBOBOXDLG: ! 923: switch(idItem) { ! 924: case IDC_SIMPLE: ! 925: idPanel = PANEL_COMBOBOXDLG_SIMPLE; ! 926: break; ! 927: ! 928: case IDC_DROPDOWN: ! 929: idPanel = PANEL_COMBOBOXDLG_DROPDOWN; ! 930: break; ! 931: ! 932: case IDC_DROPDOWNLIST: ! 933: idPanel = PANEL_COMBOBOXDLG_DROPDOWNLIST; ! 934: break; ! 935: ! 936: case IDC_OK: ! 937: idPanel = PANEL_COMBOBOXDLG_OK; ! 938: break; ! 939: ! 940: case IDC_HELP: ! 941: idPanel = PANEL_COMBOBOXDLG_HELP; ! 942: break; ! 943: ! 944: default: ! 945: /* check to see if window that has the focus is the ! 946: entry field of the combobox. If it is, then ! 947: call the appropriate combobox help panel. If ! 948: not, then call the unknown panel */ ! 949: if(WinWindowFromID(WinWindowFromID(hwnd, IDC_SIMPLE), ! 950: CBID_EDIT) == hwndFocus) ! 951: idPanel = PANEL_COMBOBOXDLG_SIMPLE; ! 952: else ! 953: if(WinWindowFromID(WinWindowFromID(hwnd, IDC_DROPDOWN), ! 954: CBID_EDIT) == hwndFocus) ! 955: idPanel = PANEL_COMBOBOXDLG_DROPDOWN; ! 956: else ! 957: if(WinWindowFromID( ! 958: WinWindowFromID(hwnd, IDC_DROPDOWNLIST), ! 959: CBID_EDIT) == hwndFocus) ! 960: idPanel = PANEL_COMBOBOXDLG_DROPDOWNLIST; ! 961: else ! 962: idPanel = PANEL_UNKNOWN; ! 963: break; ! 964: } ! 965: break; ! 966: ! 967: case IDD_ENTRYFIELDDLG: ! 968: switch(idItem) { ! 969: case IDC_ENTRY: ! 970: idPanel = PANEL_ENTRYFIELDDLG_ENTRY; ! 971: break; ! 972: ! 973: case IDC_MLE: ! 974: idPanel = PANEL_ENTRYFIELDDLG_MLE; ! 975: break; ! 976: ! 977: case IDC_OK: ! 978: idPanel = PANEL_ENTRYFIELDDLG_OK; ! 979: break; ! 980: ! 981: case IDC_HELP: ! 982: idPanel = PANEL_ENTRYFIELDDLG_HELP; ! 983: break; ! 984: ! 985: default: ! 986: idPanel = PANEL_UNKNOWN; ! 987: break; ! 988: } ! 989: break; ! 990: ! 991: case IDD_STATICDLG: ! 992: switch(idItem) { ! 993: case IDC_OK: ! 994: idPanel = PANEL_STATICDLG_OK; ! 995: break; ! 996: ! 997: case IDC_HELP: ! 998: idPanel = PANEL_STATICDLG_HELP; ! 999: break; ! 1000: ! 1001: default: ! 1002: idPanel = PANEL_UNKNOWN; ! 1003: break; ! 1004: } ! 1005: break; ! 1006: ! 1007: case IDD_PPDEMODLG: ! 1008: switch(idItem) { ! 1009: case IDC_FORECOLORLIST: ! 1010: idPanel = PANEL_PPDEMODLG_FORECOLORLIST; ! 1011: break; ! 1012: ! 1013: case IDC_BACKCOLORLIST: ! 1014: idPanel = PANEL_PPDEMODLG_BACKCOLORLIST; ! 1015: break; ! 1016: ! 1017: case IDC_FONTLIST: ! 1018: idPanel = PANEL_PPDEMODLG_FONTLIST; ! 1019: break; ! 1020: ! 1021: case IDC_CHECKBOX: ! 1022: idPanel = PANEL_PPDEMODLG_TESTBUTTON; ! 1023: break; ! 1024: ! 1025: case IDC_CANCEL: ! 1026: idPanel = PANEL_PPDEMODLG_CANCEL; ! 1027: break; ! 1028: ! 1029: case IDC_APPLY: ! 1030: idPanel = PANEL_PPDEMODLG_APPLY; ! 1031: break; ! 1032: ! 1033: case IDC_HELP: ! 1034: idPanel = PANEL_PPDEMODLG_HELP; ! 1035: break; ! 1036: ! 1037: default: ! 1038: /* check to see if window that has the focus is the ! 1039: entry field of the combobox. If it is, then ! 1040: call the appropriate combobox help panel. If ! 1041: not, then call the unknown panel */ ! 1042: if(WinWindowFromID( ! 1043: WinWindowFromID(hwnd, IDC_FORECOLORLIST), ! 1044: CBID_EDIT) == hwndFocus) ! 1045: idPanel = PANEL_PPDEMODLG_FORECOLORLIST; ! 1046: else ! 1047: if(WinWindowFromID( ! 1048: WinWindowFromID(hwnd, IDC_BACKCOLORLIST), ! 1049: CBID_EDIT) == hwndFocus) ! 1050: idPanel = PANEL_PPDEMODLG_BACKCOLORLIST; ! 1051: else ! 1052: if(WinWindowFromID( ! 1053: WinWindowFromID(hwnd, IDC_FONTLIST), ! 1054: CBID_EDIT) == hwndFocus) ! 1055: idPanel = PANEL_PPDEMODLG_FONTLIST; ! 1056: else ! 1057: idPanel = PANEL_UNKNOWN; ! 1058: break; ! 1059: } ! 1060: break; ! 1061: ! 1062: case IDD_ABOUTBOX: ! 1063: idPanel = PANEL_ABOUTBOX; ! 1064: break; ! 1065: ! 1066: default: ! 1067: idPanel = PANEL_UNKNOWNDLG; ! 1068: break; ! 1069: ! 1070: } ! 1071: ! 1072: DisplayHelpPanel(idPanel); ! 1073: ! 1074: } /* ShowDlgHelp() */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.