|
|
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: status.c ! 14: * ! 15: * Support for the Status window. ! 16: * ! 17: * Functions: ! 18: * ! 19: * StatusDlgProc() ! 20: * StatusApplyChanges() ! 21: * StatusFillSymbolList() ! 22: * StatusSetCoords() ! 23: * StatusUpdate() ! 24: * StatusSetEnable() ! 25: * StatusInit() ! 26: * StatusProcessCommand() ! 27: * ValidateNewName() ! 28: * ValidateNewID() ! 29: * ApplyNewName() ! 30: * ApplyNewID() ! 31: * ApplyNewText() ! 32: * StatusSetText() ! 33: * StatusSetTextLabels() ! 34: * StatusSetID() ! 35: * StatusSetName() ! 36: * StatusSetNameID() ! 37: * StatusClearID() ! 38: * StatusClearName() ! 39: * StatusClear() ! 40: * StatusShowFields() ! 41: * ! 42: * Comments: ! 43: * ! 44: ****************************************************************************/ ! 45: ! 46: #include "dlgedit.h" ! 47: #include "dlgfuncs.h" ! 48: #include "dlgextrn.h" ! 49: #include "dialogs.h" ! 50: ! 51: ! 52: STATICFN BOOL StatusInit(HWND hwnd); ! 53: STATICFN VOID StatusProcessCommand(HWND hwnd, INT idCtrl, ! 54: INT NotifyCode); ! 55: STATICFN BOOL ValidateNewName(NPCTYPE npc, LPTSTR pszName, ! 56: LPTSTR pszID, LPTSTR pszSym, PINT pidNew, BOOL *pfAddLabel); ! 57: STATICFN BOOL ValidateNewID(NPCTYPE npc, LPTSTR pszSym, LPTSTR pszID, ! 58: PINT pidNew, BOOL *pfAddLabel); ! 59: STATICFN BOOL ApplyNewName(NPCTYPE npc, LPTSTR pszName, ! 60: BOOL fAddLabel, LPTSTR pszSym, INT idNew); ! 61: STATICFN BOOL ApplyNewID(NPCTYPE npc, INT idNew, BOOL fAddLabel, ! 62: LPTSTR pszSym); ! 63: STATICFN BOOL ApplyNewText(NPCTYPE npc, LPTSTR pszNewText); ! 64: STATICFN VOID StatusSetText(LPTSTR pszText, INT Type); ! 65: STATICFN VOID StatusSetTextLabels(INT Type, BOOL fIsOrd); ! 66: STATICFN VOID StatusSetID(INT id, BOOL fSymAlso); ! 67: STATICFN VOID StatusSetName(LPTSTR pszName, INT Type); ! 68: STATICFN VOID StatusSetNameID(INT id, INT Type); ! 69: STATICFN VOID StatusClearID(VOID); ! 70: STATICFN VOID StatusClearName(VOID); ! 71: STATICFN VOID StatusClear(VOID); ! 72: STATICFN VOID StatusShowFields(INT Type); ! 73: ! 74: /* ! 75: * TRUE if the user has changed the entry fields in the status window. ! 76: * This will be reset to FALSE whenever new information is placed ! 77: * into the fields. ! 78: */ ! 79: static BOOL gfStatusChanged = FALSE; ! 80: ! 81: /* ! 82: * These globals save the window positions of the upper and lower ! 83: * combo boxes and edit controls. This is used to position them ! 84: * depending on what type of control is selected. ! 85: */ ! 86: static RECT grcTopCombo; ! 87: static RECT grcBottomCombo; ! 88: static RECT grcTopEdit; ! 89: static RECT grcBottomEdit; ! 90: ! 91: ! 92: ! 93: /************************************************************************ ! 94: * StatusDlgProc ! 95: * ! 96: * This is the dialog procedure for the Status ribbon window. ! 97: * ! 98: ************************************************************************/ ! 99: ! 100: DIALOGPROC StatusDlgProc( ! 101: HWND hwnd, ! 102: UINT msg, ! 103: WPARAM wParam, ! 104: LPARAM lParam) ! 105: { ! 106: switch (msg) { ! 107: case WM_INITDIALOG: ! 108: return StatusInit(hwnd); ! 109: ! 110: case WM_PAINT: ! 111: { ! 112: HDC hdc; ! 113: RECT rc; ! 114: PAINTSTRUCT ps; ! 115: HPEN hpenWindowFrame; ! 116: ! 117: /* ! 118: * Draw our border lines. ! 119: */ ! 120: GetClientRect(hwnd, &rc); ! 121: hdc = BeginPaint(hwnd, &ps); ! 122: ! 123: SelectObject(hdc, GetStockObject(WHITE_PEN)); ! 124: MoveToEx(hdc, rc.left, rc.top, NULL); ! 125: LineTo(hdc, rc.right, rc.top); ! 126: ! 127: SelectObject(hdc, hpenDarkGray); ! 128: MoveToEx(hdc, rc.left, (rc.top + gcyStatus) - gcyBorder - 1, NULL); ! 129: LineTo(hdc, rc.right, (rc.top + gcyStatus) - gcyBorder - 1); ! 130: ! 131: hpenWindowFrame = CreatePen(PS_SOLID, gcyBorder, ! 132: GetSysColor(COLOR_WINDOWFRAME)); ! 133: SelectObject(hdc, hpenWindowFrame); ! 134: MoveToEx(hdc, rc.left, (rc.top + gcyStatus) - gcyBorder, NULL); ! 135: LineTo(hdc, rc.right, (rc.top + gcyStatus) - gcyBorder); ! 136: ! 137: EndPaint(hwnd, &ps); ! 138: DeleteObject(hpenWindowFrame); ! 139: } ! 140: ! 141: break; ! 142: ! 143: case WM_CTLCOLORDLG: ! 144: case WM_CTLCOLORLISTBOX: ! 145: case WM_CTLCOLORSTATIC: ! 146: switch ((WORD)(msg - WM_CTLCOLORMSGBOX)) { ! 147: case CTLCOLOR_DLG: ! 148: case CTLCOLOR_LISTBOX: ! 149: return (BOOL)GetStockObject(LTGRAY_BRUSH); ! 150: ! 151: case CTLCOLOR_STATIC: ! 152: SetBkColor((HDC)(wParam), ! 153: LIGHTGRAY); ! 154: return (BOOL)GetStockObject(LTGRAY_BRUSH); ! 155: } ! 156: ! 157: return (BOOL)NULL; ! 158: ! 159: case WM_COMMAND: ! 160: StatusProcessCommand(hwnd, ! 161: LOWORD(wParam), ! 162: HIWORD(wParam)); ! 163: break; ! 164: ! 165: default: ! 166: return FALSE; ! 167: } ! 168: ! 169: return FALSE; ! 170: } ! 171: ! 172: ! 173: ! 174: /************************************************************************ ! 175: * StatusInit ! 176: * ! 177: * Initializes the Status ribbon window. ! 178: * ! 179: * Arguments: ! 180: * HWND hwnd = The window handle. ! 181: * ! 182: * Returns: ! 183: * ! 184: * TRUE ! 185: * ! 186: ************************************************************************/ ! 187: ! 188: STATICFN BOOL StatusInit( ! 189: HWND hwnd) ! 190: { ! 191: /* ! 192: * Set this global right away. Other routines that will be called ! 193: * before CreateDialog returns depend on this global. ! 194: */ ! 195: hwndStatus = hwnd; ! 196: ! 197: GetChildRect(GetDlgItem(hwnd, DID_STATUSSYM), &grcTopCombo); ! 198: GetChildRect(GetDlgItem(hwnd, DID_STATUSSYMID), &grcTopEdit); ! 199: GetChildRect(GetDlgItem(hwnd, DID_STATUSNAME), &grcBottomCombo); ! 200: GetChildRect(GetDlgItem(hwnd, DID_STATUSNAMEID), &grcBottomEdit); ! 201: ! 202: SendDlgItemMessage(hwnd, DID_STATUSSYM, EM_LIMITTEXT, CCHTEXTMAX, 0L); ! 203: SendDlgItemMessage(hwnd, DID_STATUSNAME, EM_LIMITTEXT, CCHTEXTMAX, 0L); ! 204: SendDlgItemMessage(hwnd, DID_STATUSSYMID, EM_LIMITTEXT, CCHIDMAX, 0L); ! 205: SendDlgItemMessage(hwnd, DID_STATUSNAMEID, EM_LIMITTEXT, CCHIDMAX, 0L); ! 206: SendDlgItemMessage(hwnd, DID_STATUSTEXT, EM_LIMITTEXT, CCHTEXTMAX, 0L); ! 207: ! 208: StatusFillSymbolList(plInclude); ! 209: StatusUpdate(); ! 210: StatusSetEnable(); ! 211: ! 212: /* ! 213: * Return TRUE so that the dialog manager does NOT set the focus ! 214: * for me. This prevents the status window from initially having ! 215: * the focus when the editor is started. ! 216: */ ! 217: return TRUE; ! 218: } ! 219: ! 220: ! 221: ! 222: /************************************************************************ ! 223: * StatusProcessCommand ! 224: * ! 225: * Function that processes commands sent to the status window. ! 226: * ! 227: * Arguments: ! 228: * HWND hwnd - The window handle. ! 229: * INT idCtrl - The id of the control the WM_COMMAND is for. ! 230: * INT NotifyCode - The control's notification code. ! 231: * ! 232: * ! 233: ************************************************************************/ ! 234: ! 235: STATICFN VOID StatusProcessCommand( ! 236: HWND hwnd, ! 237: INT idCtrl, ! 238: INT NotifyCode) ! 239: { ! 240: TCHAR szSym[CCHTEXTMAX]; ! 241: TCHAR szID[CCHIDMAX + 1]; ! 242: NPLABEL npLabel; ! 243: INT id; ! 244: INT nIndex; ! 245: LPTSTR pszOldName; ! 246: ! 247: switch (idCtrl) { ! 248: case DID_STATUSSYM: ! 249: /* ! 250: * Did the symbol edit field change and is ! 251: * something selected? ! 252: */ ! 253: if (gnpcSel && (NotifyCode == CBN_EDITCHANGE || ! 254: NotifyCode == CBN_SELCHANGE)) { ! 255: /* ! 256: * Get the symbol and begin looking for it. ! 257: */ ! 258: if (NotifyCode == CBN_EDITCHANGE) { ! 259: /* ! 260: * The edit field was typed into. Get the ! 261: * new text from there. ! 262: */ ! 263: GetDlgItemText(hwnd, DID_STATUSSYM, szSym, CCHTEXTMAX); ! 264: } ! 265: else { ! 266: /* ! 267: * A new string was selected from the list ! 268: * box. Get it from the list box, because ! 269: * at this point the new text is not yet set ! 270: * into the edit control! ! 271: */ ! 272: nIndex = (INT)SendDlgItemMessage(hwnd, ! 273: DID_STATUSSYM, CB_GETCURSEL, 0, 0L); ! 274: ! 275: if (nIndex != CB_ERR) ! 276: SendDlgItemMessage(hwnd, DID_STATUSSYM, CB_GETLBTEXT, ! 277: nIndex, (DWORD)szSym); ! 278: else ! 279: *szSym = CHAR_NULL; ! 280: } ! 281: ! 282: /* ! 283: * Convert the symbol field to the associated id value, ! 284: * taking into account the special IDOK values, etc. ! 285: */ ! 286: if (!LabelToID(szSym, &id)) { ! 287: /* ! 288: * The symbol was not found. ! 289: * If the symbol is not blank, and the ! 290: * id of the control is already taken ! 291: * by another label, fill the id field ! 292: * with the next available id. Otherwise, ! 293: * fill the id field with the controls ! 294: * id value. It is assumed here that the ! 295: * dialog cannot be selected if the symbol ! 296: * field was able to be changed. ! 297: */ ! 298: if (*szSym && FindID(gnpcSel->id, plInclude)) ! 299: id = NextID(NEXTID_CONTROL, plInclude, 0); ! 300: else ! 301: id = gnpcSel->id; ! 302: } ! 303: ! 304: StatusSetID(id, FALSE); ! 305: ! 306: gfStatusChanged = TRUE; ! 307: } ! 308: ! 309: break; ! 310: ! 311: case DID_STATUSNAME: ! 312: /* ! 313: * Did the name edit field change and is ! 314: * something selected? ! 315: */ ! 316: if (gnpcSel && (NotifyCode == CBN_EDITCHANGE || ! 317: NotifyCode == CBN_SELCHANGE)) { ! 318: /* ! 319: * Get the symbol and begin looking for it. ! 320: */ ! 321: if (NotifyCode == CBN_EDITCHANGE) { ! 322: /* ! 323: * The edit field was typed into. Get the ! 324: * new text from there. ! 325: */ ! 326: GetDlgItemText(hwnd, DID_STATUSNAME, szSym, CCHTEXTMAX); ! 327: } ! 328: else { ! 329: /* ! 330: * A new string was selected from the list ! 331: * box. Get it from the list box, because ! 332: * at this point the new text is not yet set ! 333: * into the edit control! ! 334: */ ! 335: nIndex = (INT)SendDlgItemMessage(hwnd, ! 336: DID_STATUSNAME, CB_GETCURSEL, 0, 0L); ! 337: ! 338: if (nIndex != CB_ERR) ! 339: SendDlgItemMessage(hwnd, DID_STATUSNAME, CB_GETLBTEXT, ! 340: nIndex, (DWORD)szSym); ! 341: else ! 342: *szSym = CHAR_NULL; ! 343: } ! 344: ! 345: /* ! 346: * Try and convert the name to an ordinal. ! 347: */ ! 348: StrToNameOrd(szSym, (gnpcSel->pwcd->iType == W_DIALOG) ? ! 349: TRUE : FALSE); ! 350: ! 351: /* ! 352: * Was the name converted to an ordinal? ! 353: */ ! 354: if (IsOrd(szSym)) { ! 355: id = OrdID(szSym); ! 356: } ! 357: /* ! 358: * Is it an existing label? ! 359: */ ! 360: else if (npLabel = FindLabel(szSym, plInclude)) { ! 361: id = npLabel->id; ! 362: } ! 363: else { ! 364: /* ! 365: * Get a pointer to the original name. ! 366: */ ! 367: pszOldName = (gnpcSel->pwcd->iType == W_DIALOG) ? ! 368: gcd.pszDlgName : gnpcSel->text; ! 369: ! 370: /* ! 371: * If the old name was originally an ordinal, and ! 372: * there was no corresponding label for it, ! 373: * assume that the user is trying to enter a ! 374: * define for it and leave it alone. Otherwise, ! 375: * pick the next available id. But if the user ! 376: * completely blanks out the field, leave it ! 377: * alone also (this is a benign case). ! 378: */ ! 379: if (IsOrd(pszOldName) && ! 380: (!*szSym || !FindID(OrdID(pszOldName), plInclude))) ! 381: id = OrdID(pszOldName); ! 382: else ! 383: id = NextID((gnpcSel->pwcd->iType == W_DIALOG) ? ! 384: NEXTID_DIALOG : NEXTID_CONTROL, plInclude, 0); ! 385: } ! 386: ! 387: StatusSetNameID(id, gnpcSel->pwcd->iType); ! 388: ! 389: /* ! 390: * Change the labels to reflect that the entered name ! 391: * is an ID instead of a name. ! 392: */ ! 393: StatusSetTextLabels(gnpcSel->pwcd->iType, TRUE); ! 394: ! 395: gfStatusChanged = TRUE; ! 396: } ! 397: ! 398: break; ! 399: ! 400: case DID_STATUSSYMID: ! 401: case DID_STATUSNAMEID: ! 402: case DID_STATUSTEXT: ! 403: if (!gnpcSel) ! 404: break; ! 405: ! 406: if (NotifyCode == EN_CHANGE) ! 407: gfStatusChanged = TRUE; ! 408: ! 409: if (idCtrl == DID_STATUSNAMEID) { ! 410: GetDlgItemText(hwnd, DID_STATUSNAME, szSym, CCHTEXTMAX); ! 411: GetDlgItemText(hwnd, DID_STATUSNAMEID, szID, CCHIDMAX + 1); ! 412: StrToNameOrd(szSym, (gnpcSel->pwcd->iType == W_DIALOG) ? ! 413: TRUE : FALSE); ! 414: ! 415: /* ! 416: * Change the labels to reflect whether the entered name ! 417: * is an ID or a name. It is considered an id if the ! 418: * edit field has something in it, or if the name field ! 419: * is a valid label, or if the name field represents an ! 420: * ordinal (it is numeric). ! 421: */ ! 422: StatusSetTextLabels(gnpcSel->pwcd->iType, ! 423: (IsOrd(szSym) || *szID || ! 424: FindLabel(szSym, plInclude)) ? TRUE : FALSE); ! 425: } ! 426: ! 427: break; ! 428: ! 429: case IDOK: ! 430: if (StatusApplyChanges()) ! 431: SetFocus(ghwndMain); ! 432: ! 433: break; ! 434: ! 435: case IDCANCEL: ! 436: StatusUpdate(); ! 437: SetFocus(ghwndMain); ! 438: break; ! 439: } ! 440: } ! 441: ! 442: ! 443: ! 444: /************************************************************************ ! 445: * StatusApplyChanges ! 446: * ! 447: * Processes the Enter command from the "Status" bar window to apply ! 448: * the current value of the fields to the current control. ! 449: * ! 450: * Returns: ! 451: * ! 452: * TRUE is successful; otherwise, FALSE is returned. ! 453: * ! 454: ************************************************************************/ ! 455: ! 456: BOOL StatusApplyChanges(VOID) ! 457: { ! 458: TCHAR szText[CCHTEXTMAX]; ! 459: TCHAR szSym[CCHTEXTMAX]; ! 460: TCHAR szName[CCHTEXTMAX]; ! 461: TCHAR szSymID[CCHIDMAX + 1]; ! 462: TCHAR szNameID[CCHIDMAX + 1]; ! 463: TCHAR szNameSym[CCHTEXTMAX]; ! 464: INT idSymNew; ! 465: INT idNameNew; ! 466: BOOL fAddSymLabel; ! 467: BOOL fAddNameLabel; ! 468: BOOL fSuccess = FALSE; ! 469: ! 470: /* ! 471: * Quit if nothing is selected, or if nothing was changed. ! 472: */ ! 473: if (!gnpcSel || !gfStatusChanged) ! 474: return TRUE; ! 475: ! 476: idSymNew = gnpcSel->id; ! 477: ! 478: switch (gnpcSel->pwcd->iType) { ! 479: case W_DIALOG: ! 480: GetDlgItemText(hwndStatus, DID_STATUSNAME, szName, CCHTEXTMAX); ! 481: GetDlgItemText(hwndStatus, DID_STATUSNAMEID, szNameID, CCHIDMAX + 1); ! 482: GetDlgItemText(hwndStatus, DID_STATUSTEXT, szText, CCHTEXTMAX); ! 483: if (!ValidateNewName(gnpcSel, szName, szNameID, szNameSym, ! 484: &idNameNew, &fAddNameLabel)) ! 485: return FALSE; ! 486: ! 487: if (ApplyNewName(gnpcSel, szName, fAddNameLabel, ! 488: szNameSym, idNameNew) && ! 489: ApplyNewText(gnpcSel, szText)) ! 490: fSuccess = TRUE; ! 491: ! 492: break; ! 493: ! 494: case W_ICON: ! 495: GetDlgItemText(hwndStatus, DID_STATUSNAME, szName, CCHTEXTMAX); ! 496: GetDlgItemText(hwndStatus, DID_STATUSNAMEID, szNameID, CCHIDMAX + 1); ! 497: GetDlgItemText(hwndStatus, DID_STATUSSYM, szSym, CCHTEXTMAX); ! 498: GetDlgItemText(hwndStatus, DID_STATUSSYMID, szSymID, CCHIDMAX + 1); ! 499: if (!ValidateNewName(gnpcSel, szName, szNameID, szNameSym, ! 500: &idNameNew, &fAddNameLabel) || ! 501: !ValidateNewID(gnpcSel, szSym, szSymID, ! 502: &idSymNew, &fAddSymLabel)) ! 503: return FALSE; ! 504: ! 505: if (ApplyNewID(gnpcSel, idSymNew, fAddSymLabel, szSym) && ! 506: ApplyNewName(gnpcSel, szName, fAddNameLabel, ! 507: szNameSym, idNameNew)) ! 508: fSuccess = TRUE; ! 509: ! 510: break; ! 511: ! 512: default: ! 513: GetDlgItemText(hwndStatus, DID_STATUSSYM, szSym, CCHTEXTMAX); ! 514: GetDlgItemText(hwndStatus, DID_STATUSSYMID, szSymID, CCHIDMAX + 1); ! 515: GetDlgItemText(hwndStatus, DID_STATUSTEXT, szText, CCHTEXTMAX); ! 516: if (!ValidateNewID(gnpcSel, szSym, szSymID, &idSymNew, &fAddSymLabel)) ! 517: return FALSE; ! 518: ! 519: if (ApplyNewID(gnpcSel, idSymNew, fAddSymLabel, szSym) && ! 520: ApplyNewText(gnpcSel, szText)) ! 521: fSuccess = TRUE; ! 522: ! 523: break; ! 524: } ! 525: ! 526: if (fSuccess) { ! 527: ShowFileStatus(FALSE); ! 528: StatusUpdate(); ! 529: } ! 530: ! 531: return fSuccess; ! 532: } ! 533: ! 534: ! 535: ! 536: /************************************************************************ ! 537: * ValidateNewName ! 538: * ! 539: * Validates the new name from the processing of the OK command ! 540: * from the Status ribbon window. ! 541: * ! 542: * The name is considered valid if it does not have any blanks in it, ! 543: * it is not already used by another dialog in the resource file, and ! 544: * it is not an empty string. ! 545: * ! 546: * Arguments: ! 547: * NPCTYPE npc - Pointer to the control. ! 548: * LPTSTR pszName - The new name. ! 549: * LPTSTR pszID - The ID. ! 550: * LPTSTR pszSym - The symbol. ! 551: * PINT pidNew - Where to return the new ID if successful. ! 552: * BOOL *pfAddLabel - Set to TRUE if this symbol/id should be added ! 553: * to the include list. Not touched otherwise. ! 554: * ! 555: * Returns: ! 556: * TRUE if the new name is valid, FALSE otherwise. ! 557: * ! 558: ************************************************************************/ ! 559: ! 560: STATICFN BOOL ValidateNewName( ! 561: NPCTYPE npc, ! 562: LPTSTR pszName, ! 563: LPTSTR pszID, ! 564: LPTSTR pszSym, ! 565: PINT pidNew, ! 566: BOOL *pfAddLabel) ! 567: { ! 568: NPLABEL npLabel; ! 569: BOOL fIDEmpty = FALSE; ! 570: BOOL fNameEmpty = FALSE; ! 571: BOOL fAddLabel = FALSE; ! 572: INT idNew; ! 573: TCHAR szIDTemp[CCHIDMAX + 1]; ! 574: ! 575: /* ! 576: * Start by assuming that the label will NOT be added. ! 577: */ ! 578: *pfAddLabel = FALSE; ! 579: ! 580: /* ! 581: * Is the ID field non-blank? ! 582: */ ! 583: if (*pszID) { ! 584: /* ! 585: * Is the id valid? ! 586: */ ! 587: if (!IsValue(pszID)) { ! 588: Message(MSG_BADSYMBOLID); ! 589: SetFocus(GetDlgItem(hwndStatus, DID_STATUSNAMEID)); ! 590: return FALSE; ! 591: } ! 592: ! 593: idNew = valtoi(pszID); ! 594: } ! 595: else { ! 596: /* ! 597: * The id field is blank. ! 598: */ ! 599: fIDEmpty = TRUE; ! 600: } ! 601: ! 602: /* ! 603: * Is the name field blank? ! 604: */ ! 605: if (!(*pszName)) ! 606: fNameEmpty = TRUE; ! 607: ! 608: if (fNameEmpty) { ! 609: if (fIDEmpty) { ! 610: Message((npc->pwcd->iType == W_DIALOG) ? ! 611: MSG_NODLGNAME : MSG_NOICONNAME); ! 612: SetFocus(GetDlgItem(hwndStatus, DID_STATUSNAME)); ! 613: return FALSE; ! 614: } ! 615: else { ! 616: WriteOrd((PORDINAL)pszName, idNew); ! 617: } ! 618: } ! 619: else { ! 620: /* ! 621: * Error if there are imbedded blanks. ! 622: */ ! 623: if (HasBlanks(pszName)) { ! 624: Message((npc->pwcd->iType == W_DIALOG) ? ! 625: MSG_DLGNAMEHASBLANKS : MSG_ICONNAMEHASBLANKS); ! 626: SetFocus(GetDlgItem(hwndStatus, DID_STATUSNAME)); ! 627: return FALSE; ! 628: } ! 629: ! 630: /* ! 631: * Convert the name to an ordinal, if appropriate. ! 632: */ ! 633: StrToNameOrd(pszName, (npc->pwcd->iType == W_DIALOG) ? TRUE : FALSE); ! 634: ! 635: /* ! 636: * If the name was translated to an ordinal, we are done. ! 637: * Otherwise, keep trying to figure out whether it is a ! 638: * name or a define. ! 639: */ ! 640: if (!IsOrd(pszName)) { ! 641: /* ! 642: * Is the name a symbol in the current include list? ! 643: */ ! 644: if (npLabel = FindLabel(pszName, plInclude)) { ! 645: /* ! 646: * Yes. If the id field was blank, just assume they ! 647: * wanted the corresponding id. ! 648: */ ! 649: if (fIDEmpty) ! 650: idNew = npLabel->id; ! 651: ! 652: /* ! 653: * If they somehow entered a valid define but tried to ! 654: * give it a different id value, show an error. ! 655: */ ! 656: if (npLabel->id != idNew) { ! 657: Myitoa(npLabel->id, szIDTemp); ! 658: Message(MSG_IDSYMMISMATCH, szIDTemp); ! 659: SetFocus(GetDlgItem(hwndStatus, DID_STATUSNAMEID)); ! 660: return FALSE; ! 661: } ! 662: ! 663: /* ! 664: * Make the name field into an ordinal. ! 665: */ ! 666: WriteOrd((PORDINAL)pszName, idNew); ! 667: } ! 668: else { ! 669: /* ! 670: * The name was not found as a label. Is the id field ! 671: * empty? ! 672: */ ! 673: if (fIDEmpty) { ! 674: /* ! 675: * Since the id field is empty, we can assume that ! 676: * what they entered is a name (not a define) ! 677: * and we are done. ! 678: */ ! 679: } ! 680: else { ! 681: /* ! 682: * At this point we know the name field is not empty, ! 683: * and there is an id entered along with it. We also ! 684: * know that the name (which we can now assume is ! 685: * a symbol) is not already found in the include file. ! 686: * We will check it for validity, copy it to the ! 687: * pszSym buffer, translate the name to an ordinal ! 688: * and set a flag saying that the sym/id pair should ! 689: * be added to the include list. ! 690: */ ! 691: if (!IsSymbol(pszName)) { ! 692: Message(MSG_BADSYMBOLID); ! 693: SetFocus(GetDlgItem(hwndStatus, DID_STATUSNAME)); ! 694: return FALSE; ! 695: } ! 696: ! 697: /* ! 698: * Pass back the values. ! 699: */ ! 700: lstrcpy(pszSym, pszName); ! 701: WriteOrd((PORDINAL)pszName, idNew); ! 702: *pidNew = idNew; ! 703: ! 704: fAddLabel = TRUE; ! 705: } ! 706: } ! 707: } ! 708: } ! 709: ! 710: /* ! 711: * Inform caller whether they should add this id/symbol ! 712: * as a label to the include list. ! 713: */ ! 714: *pfAddLabel = fAddLabel; ! 715: ! 716: /* ! 717: * Return success. ! 718: */ ! 719: return TRUE; ! 720: } ! 721: ! 722: ! 723: ! 724: /************************************************************************ ! 725: * ValidateNewID ! 726: * ! 727: * Validates the new ID from the processing of the OK command from ! 728: * the Status ribbon window. It will return the new id in *pidNew. ! 729: * Note that the control is not actually updated by this routine. This ! 730: * is so that if other validations fail nothing will have been done to the ! 731: * control. It is assumed that ApplyNewID will be called later to do ! 732: * the actual update of the control. ! 733: * ! 734: * Arguments: ! 735: * NPCTYPE npc = Pointer to the control. ! 736: * LPTSTR pszSym = The symbol. ! 737: * LPTSTR pszID = The ID. ! 738: * PINT pidNew = Where to return the new ID if successful. ! 739: * BOOL *pfAddLabel = Set to TRUE if this symbol/id should be added ! 740: * to the include list. Not touched otherwise. ! 741: * ! 742: * Returns: ! 743: * TRUE if successful, FALSE otherwise. If TRUE is returned and they ! 744: * changed the id, the new id will have been placed in *pidNew. ! 745: * ! 746: ************************************************************************/ ! 747: ! 748: STATICFN BOOL ValidateNewID( ! 749: NPCTYPE npc, ! 750: LPTSTR pszSym, ! 751: LPTSTR pszID, ! 752: PINT pidNew, ! 753: BOOL *pfAddLabel) ! 754: { ! 755: NPLABEL npLabel; ! 756: BOOL fIDEmpty = FALSE; ! 757: BOOL fIDChanged = FALSE; ! 758: BOOL fSymEmpty = FALSE; ! 759: BOOL fSymChanged = FALSE; ! 760: BOOL fAddLabel = FALSE; ! 761: INT idNew; ! 762: TCHAR szIDTemp[CCHIDMAX + 1]; ! 763: ! 764: /* ! 765: * Start by assuming that the label will NOT be added. ! 766: */ ! 767: *pfAddLabel = FALSE; ! 768: ! 769: /* ! 770: * If in translate mode, they cannot change the symbol or id, ! 771: * and so it should not be validated. Even if there was a ! 772: * problem, they could not fix it. ! 773: */ ! 774: if (gfTranslateMode) ! 775: return TRUE; ! 776: ! 777: /* ! 778: * Special case if they selected the "unused" label. ! 779: * Blank out the symbol so it doesn't cause trouble ! 780: * later, force the id to be zero, and then check if ! 781: * the id was changed. ! 782: */ ! 783: if (lstrcmp(pszSym, ids(IDS_UNUSED)) == 0) { ! 784: pszSym = szEmpty; ! 785: idNew = IDUNUSED; ! 786: if (idNew != npc->id) ! 787: fIDChanged = TRUE; ! 788: } ! 789: else if (lstrcmp(pszSym, ids(IDS_IDOK)) == 0 && ! 790: !FindLabel(ids(IDS_IDOK), plInclude)) { ! 791: pszSym = szEmpty; ! 792: idNew = IDOK; ! 793: if (idNew != npc->id) ! 794: fIDChanged = TRUE; ! 795: } ! 796: else if (lstrcmp(pszSym, ids(IDS_IDCANCEL)) == 0 && ! 797: !FindLabel(ids(IDS_IDCANCEL), plInclude)) { ! 798: pszSym = szEmpty; ! 799: idNew = IDCANCEL; ! 800: if (idNew != npc->id) ! 801: fIDChanged = TRUE; ! 802: } ! 803: /* ! 804: * Is the ID field non-blank? ! 805: */ ! 806: else if (*pszID) { ! 807: /* ! 808: * Is the id valid? ! 809: */ ! 810: if (!IsValue(pszID)) { ! 811: Message(MSG_BADSYMBOLID); ! 812: SetFocus(GetDlgItem(hwndStatus, DID_STATUSSYMID)); ! 813: return FALSE; ! 814: } ! 815: ! 816: /* ! 817: * Did they change the id value? ! 818: */ ! 819: idNew = valtoi(pszID); ! 820: if (idNew != npc->id) ! 821: fIDChanged = TRUE; ! 822: } ! 823: else { ! 824: /* ! 825: * The id field is blank. This implies they changed it. ! 826: */ ! 827: fIDEmpty = TRUE; ! 828: fIDChanged = TRUE; ! 829: } ! 830: ! 831: /* ! 832: * Is the symbol field blank? ! 833: */ ! 834: if (!(*pszSym)) ! 835: fSymEmpty = TRUE; ! 836: ! 837: /* ! 838: * Determine if they have changed the symbol. ! 839: * Did the original id have a symbol associated with it? ! 840: */ ! 841: if (npLabel = FindID(npc->id, plInclude)) { ! 842: if (lstrcmp(npLabel->pszLabel, pszSym) != 0) ! 843: fSymChanged = TRUE; ! 844: } ! 845: else { ! 846: /* ! 847: * Since the original id did not have a symbol, if they ! 848: * have entered a symbol it is changed. ! 849: */ ! 850: if (!fSymEmpty) ! 851: fSymChanged = TRUE; ! 852: } ! 853: ! 854: /* ! 855: * Quit if nothing changed. ! 856: */ ! 857: if (!fSymChanged && !fIDChanged) ! 858: return TRUE; ! 859: ! 860: /* ! 861: * Is the symbol field empty? ! 862: */ ! 863: if (fSymEmpty) { ! 864: /* ! 865: * If the id field is empty also, return an error. ! 866: */ ! 867: if (fIDEmpty) { ! 868: Message(MSG_BADSYMBOLID); ! 869: SetFocus(GetDlgItem(hwndStatus, DID_STATUSSYMID)); ! 870: return FALSE; ! 871: } ! 872: else { ! 873: /* ! 874: * Otherwise, go on to the final test. It doesn't matter ! 875: * if this new id has a symbol or not. ! 876: */ ! 877: goto CheckForDups; ! 878: } ! 879: } ! 880: ! 881: /* ! 882: * At this point we know the symbol field is not empty. ! 883: * Is it a valid symbol? ! 884: */ ! 885: if (!IsSymbol(pszSym)) { ! 886: Message(MSG_BADSYMBOLID); ! 887: SetFocus(GetDlgItem(hwndStatus, DID_STATUSSYM)); ! 888: return FALSE; ! 889: } ! 890: ! 891: /* ! 892: * Does this symbol already exist? ! 893: */ ! 894: if (npLabel = FindLabel(pszSym, plInclude)) { ! 895: /* ! 896: * Since the symbol exists, if they blanked the id field ! 897: * be friendly and assume they want the matching id value. ! 898: */ ! 899: if (fIDEmpty) ! 900: idNew = npLabel->id; ! 901: ! 902: /* ! 903: * Does the id that is in the id field match the id of the ! 904: * symbol they entered? ! 905: */ ! 906: if (npLabel->id == idNew) { ! 907: /* ! 908: * Yes, go on to the final test. ! 909: */ ! 910: goto CheckForDups; ! 911: } ! 912: else { ! 913: /* ! 914: * No, give them an error message saying that it has to. ! 915: */ ! 916: Myitoa(npLabel->id, szIDTemp); ! 917: Message(MSG_IDSYMMISMATCH, szIDTemp); ! 918: SetFocus(GetDlgItem(hwndStatus, DID_STATUSSYMID)); ! 919: return FALSE; ! 920: } ! 921: } ! 922: else { ! 923: /* ! 924: * Since the symbol doesn't exist, if they left the id field ! 925: * blank, assume they want the next available id. ! 926: */ ! 927: if (fIDEmpty) ! 928: idNew = NextID(NEXTID_CONTROL, plInclude, 0); ! 929: ! 930: /* ! 931: * They should add this id/symbol as a label to the ! 932: * include list. ! 933: */ ! 934: fAddLabel = TRUE; ! 935: goto CheckForDups; ! 936: } ! 937: ! 938: CheckForDups: ! 939: /* ! 940: * If the id changed, it is not the special "unused" id, ! 941: * and it is a duplicate of another id, don't allow it. ! 942: */ ! 943: if (idNew != npc->id && !IsUniqueID(idNew)) { ! 944: Message(MSG_CTRLDUPID); ! 945: SetFocus(GetDlgItem(hwndStatus, DID_STATUSSYM)); ! 946: return FALSE; ! 947: } ! 948: else { ! 949: /* ! 950: * Pass back the new id value. ! 951: */ ! 952: *pidNew = idNew; ! 953: ! 954: /* ! 955: * Inform caller whether they should add this id/symbol ! 956: * as a label to the include list. ! 957: */ ! 958: *pfAddLabel = fAddLabel; ! 959: ! 960: /* ! 961: * Return success. ! 962: */ ! 963: return TRUE; ! 964: } ! 965: } ! 966: ! 967: ! 968: ! 969: /************************************************************************ ! 970: * ApplyNewName ! 971: * ! 972: * Updates an icon control's or dialog's name with a new name. ! 973: * ! 974: * If fAddLabel is TRUE, pszSym is assumed to be a string that is ! 975: * the symbol to be added and idNew contains the value associated with ! 976: * it. This will cause a new define to be added to the current include ! 977: * file. In either event, pszName will contain either a new name or ! 978: * an ordinal that is to be the name. For dialogs, the dialog name will ! 979: * be updated. For icon controls, the icon's text is updated with the ! 980: * name/ordinal. ! 981: * ! 982: * Arguments: ! 983: * NPCTYPE npc = Pointer to the control. ! 984: * LPTSTR pszName = New name. A string or ordinal. ! 985: * BOOL fAddLabel = TRUE if a new label for this id/name should be added. ! 986: * LPTSTR pszSym = The new symbol to add (only valid if fAddLabel is TRUE). ! 987: * INT idNew = The new ID (only valid if fAddLabel is TRUE). ! 988: * ! 989: * Returns: ! 990: * ! 991: * TRUE if successful; otherwise, FALSE is returned. ! 992: * ! 993: ************************************************************************/ ! 994: ! 995: STATICFN BOOL ApplyNewName( ! 996: NPCTYPE npc, ! 997: LPTSTR pszName, ! 998: BOOL fAddLabel, ! 999: LPTSTR pszSym, ! 1000: INT idNew) ! 1001: { ! 1002: LPTSTR psz; ! 1003: ! 1004: if (fAddLabel) { ! 1005: /* ! 1006: * Go ahead and quietly add the label for them. ! 1007: */ ! 1008: if (AddLabel(pszSym, idNew, FPOS_MAX, 0, &plInclude, ! 1009: &plDelInclude, NULL, NULL)) { ! 1010: /* ! 1011: * Return the controls new id, update the status ! 1012: * windows symbol combo box, mark the fact that ! 1013: * we have changed the include file, and return ! 1014: * success. ! 1015: */ ! 1016: gfIncChged = TRUE; ! 1017: StatusFillSymbolList(plInclude); ! 1018: } ! 1019: else { ! 1020: /* ! 1021: * An error occurred on the AddLabel. The most likely ! 1022: * cause of this is if they are trying to add a symbol ! 1023: * with a duplicate id. ! 1024: */ ! 1025: SetFocus(GetDlgItem(hwndStatus, DID_STATUSNAMEID)); ! 1026: return FALSE; ! 1027: } ! 1028: } ! 1029: ! 1030: switch (npc->pwcd->iType) { ! 1031: case W_ICON: ! 1032: /* ! 1033: * The resource name for an icon is stored in it's text. ! 1034: */ ! 1035: ApplyNewText(npc, pszName); ! 1036: break; ! 1037: ! 1038: case W_DIALOG: ! 1039: /* ! 1040: * We are done if the name was not changed. ! 1041: */ ! 1042: if (NameOrdCmp(gcd.pszDlgName, pszName) == 0) ! 1043: break; ! 1044: ! 1045: /* ! 1046: * Allocate room for the new name (it can be an ordinal!). ! 1047: */ ! 1048: if (!(psz = MyAlloc(NameOrdLen(pszName)))) ! 1049: return FALSE; ! 1050: ! 1051: NameOrdCpy(psz, pszName); ! 1052: ! 1053: if (gcd.pszDlgName) ! 1054: MyFree(gcd.pszDlgName); ! 1055: ! 1056: gcd.pszDlgName = psz; ! 1057: ! 1058: /* ! 1059: * If the new name is an ordinal, update the base id of ! 1060: * the dialog with it. ! 1061: */ ! 1062: if (IsOrd(gcd.pszDlgName)) ! 1063: gcd.npc->id = OrdID(gcd.pszDlgName); ! 1064: ! 1065: /* ! 1066: * Finally, set the "changed" flag. ! 1067: */ ! 1068: gfResChged = gfDlgChanged = TRUE; ! 1069: ! 1070: break; ! 1071: } ! 1072: ! 1073: return TRUE; ! 1074: } ! 1075: ! 1076: ! 1077: ! 1078: /************************************************************************ ! 1079: * ApplyNewID ! 1080: * ! 1081: * Updates the control with the new id. ! 1082: * ! 1083: * Arguments: ! 1084: * NPCTYPE npc = Pointer to the control. ! 1085: * INT idNew = The ID. ! 1086: * BOOL fAddLabel = TRUE if a new label for this id/symbol should be added. ! 1087: * LPTSTR pszSym = Symbol to add if fAddLabel is TRUE. ! 1088: * ! 1089: * Returns: ! 1090: * ! 1091: * TRUE if successful; otherwise, FALSE is returned. ! 1092: * ! 1093: ************************************************************************/ ! 1094: ! 1095: STATICFN BOOL ApplyNewID( ! 1096: NPCTYPE npc, ! 1097: INT idNew, ! 1098: BOOL fAddLabel, ! 1099: LPTSTR pszSym) ! 1100: { ! 1101: if (fAddLabel) { ! 1102: /* ! 1103: * Go ahead and quietly add the label for them. ! 1104: */ ! 1105: if (AddLabel(pszSym, idNew, FPOS_MAX, 0, &plInclude, ! 1106: &plDelInclude, NULL, NULL)) { ! 1107: /* ! 1108: * Return the controls new id, update the status ! 1109: * windows symbol combo box, mark the fact that ! 1110: * we have changed the include file, and return ! 1111: * success. ! 1112: */ ! 1113: gfIncChged = TRUE; ! 1114: StatusFillSymbolList(plInclude); ! 1115: } ! 1116: else { ! 1117: /* ! 1118: * An error occurred on the AddLabel. The most likely ! 1119: * cause of this is if they are trying to add a symbol ! 1120: * with a duplicate id. ! 1121: */ ! 1122: SetFocus(GetDlgItem(hwndStatus, DID_STATUSSYMID)); ! 1123: return FALSE; ! 1124: } ! 1125: } ! 1126: ! 1127: /* ! 1128: * Return if the id wasn't changed. ! 1129: */ ! 1130: if (npc->id == idNew) ! 1131: return TRUE; ! 1132: ! 1133: /* ! 1134: * Update the controls id and set the resource changed flag. ! 1135: */ ! 1136: npc->id = idNew; ! 1137: gfResChged = gfDlgChanged = TRUE; ! 1138: return TRUE; ! 1139: } ! 1140: ! 1141: ! 1142: ! 1143: /************************************************************************ ! 1144: * ApplyNewText ! 1145: * ! 1146: * Sets the new text from the processing of the OK command from ! 1147: * the Status ribbon window. If the text was changed, the selected ! 1148: * control will have its text updated. ! 1149: * ! 1150: * Arguments: ! 1151: * NPCTYPE npc = Pointer to the control. ! 1152: * LPTSTR pszNewText = The new text. ! 1153: * ! 1154: * Returns: ! 1155: * ! 1156: * TRUE if successful, FALSE otherwise. ! 1157: * ! 1158: ************************************************************************/ ! 1159: ! 1160: STATICFN BOOL ApplyNewText( ! 1161: NPCTYPE npc, ! 1162: LPTSTR pszNewText) ! 1163: { ! 1164: INT cb; ! 1165: LPTSTR psz; ! 1166: ! 1167: /* ! 1168: * Did the text change? ! 1169: */ ! 1170: if ((npc->text == NULL && *pszNewText) || ! 1171: (npc->text != NULL && NameOrdCmp(npc->text, pszNewText) != 0)) { ! 1172: if (*pszNewText) { ! 1173: cb = NameOrdLen(pszNewText); ! 1174: ! 1175: if (npc->text == NULL) ! 1176: psz = MyAlloc(cb); ! 1177: else ! 1178: psz = MyRealloc(npc->text, cb); ! 1179: ! 1180: if (psz == NULL) { ! 1181: return FALSE; ! 1182: } ! 1183: else { ! 1184: NameOrdCpy(psz, pszNewText); ! 1185: npc->text = psz; ! 1186: } ! 1187: } ! 1188: else { ! 1189: if (npc->text) { ! 1190: MyFree(npc->text); ! 1191: npc->text = NULL; ! 1192: } ! 1193: } ! 1194: ! 1195: /* ! 1196: * Change the text of the control, except for W_ICON controls ! 1197: * because they have resource names. In that case, we don't ! 1198: * want to change the text of the actual control because ! 1199: * the resource would probably not be found. ! 1200: */ ! 1201: if (npc->pwcd->iType != W_ICON) { ! 1202: SetWindowText(npc->hwnd, pszNewText); ! 1203: ! 1204: /* ! 1205: * Redraw the control after the text changed. This is ! 1206: * necessary because changing the text probably caused ! 1207: * the drag handles to get overwritten. ! 1208: */ ! 1209: if (npc->pwcd->iType == W_DIALOG) ! 1210: /* ! 1211: * Redraw the frame, which just overwrote the drag ! 1212: * handles when the text was changed. ! 1213: */ ! 1214: SetWindowPos(npc->hwnd, NULL, 0, 0, 0, 0, ! 1215: SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOMOVE | ! 1216: SWP_NOSIZE | SWP_NOZORDER); ! 1217: else ! 1218: /* ! 1219: * Redraw the control(s). ! 1220: */ ! 1221: RedrawSelection(); ! 1222: } ! 1223: ! 1224: gfResChged = gfDlgChanged = TRUE; ! 1225: } ! 1226: ! 1227: return TRUE; ! 1228: } ! 1229: ! 1230: ! 1231: ! 1232: /************************************************************************ ! 1233: * StatusFillSymbolList ! 1234: * ! 1235: * This function fills the Symbol and Name combo boxes with ! 1236: * the given list of labels. ! 1237: * ! 1238: * Arguments: ! 1239: * NPLABEL plHead - pointer to the list of labels. ! 1240: * ! 1241: ************************************************************************/ ! 1242: ! 1243: VOID StatusFillSymbolList( ! 1244: NPLABEL plHead) ! 1245: { ! 1246: NPLABEL npLabel; ! 1247: HWND hwndSymCB; ! 1248: HWND hwndNameCB; ! 1249: HCURSOR hcurSave; ! 1250: ! 1251: hcurSave = SetCursor(hcurWait); ! 1252: ! 1253: /* ! 1254: * Get the handles to the combo boxes and clear out all items. ! 1255: */ ! 1256: hwndSymCB = GetDlgItem(hwndStatus, DID_STATUSSYM); ! 1257: hwndNameCB = GetDlgItem(hwndStatus, DID_STATUSNAME); ! 1258: SendMessage(hwndSymCB, CB_RESETCONTENT, 0, 0L); ! 1259: SendMessage(hwndNameCB, CB_RESETCONTENT, 0, 0L); ! 1260: ! 1261: /* ! 1262: * Fill the combo boxes with the items. ! 1263: */ ! 1264: for (npLabel = plHead; npLabel; npLabel = npLabel->npNext) { ! 1265: SendMessage(hwndSymCB, CB_ADDSTRING, 0, (DWORD)npLabel->pszLabel); ! 1266: SendMessage(hwndNameCB, CB_ADDSTRING, 0, (DWORD)npLabel->pszLabel); ! 1267: } ! 1268: ! 1269: /* ! 1270: * Put some special entries into the symbol combo. Note that we allow ! 1271: * the user to have defined IDOK and IDCANCEL to be something else, ! 1272: * in which case we will NOT add these special entries after all. ! 1273: */ ! 1274: SendMessage(hwndSymCB, CB_ADDSTRING, 0, (DWORD)ids(IDS_UNUSED)); ! 1275: ! 1276: if (!FindLabel(ids(IDS_IDOK), plInclude)) ! 1277: SendMessage(hwndSymCB, CB_ADDSTRING, 0, (DWORD)ids(IDS_IDOK)); ! 1278: ! 1279: if (!FindLabel(ids(IDS_IDCANCEL), plInclude)) ! 1280: SendMessage(hwndSymCB, CB_ADDSTRING, 0, (DWORD)ids(IDS_IDCANCEL)); ! 1281: ! 1282: SetCursor(hcurSave); ! 1283: } ! 1284: ! 1285: ! 1286: ! 1287: /************************************************************************ ! 1288: * StatusSetCoords ! 1289: * ! 1290: * This function sets the coordinates in the status display ! 1291: * to the given rectangle. ! 1292: * ! 1293: * Arguments: ! 1294: * PRECT prc - coordinates. ! 1295: * ! 1296: ************************************************************************/ ! 1297: ! 1298: VOID StatusSetCoords( ! 1299: PRECT prc) ! 1300: { ! 1301: static INT xSave = 0x7FFF; ! 1302: static INT ySave = 0x7FFF; ! 1303: static INT cxSave = 0x7FFF; ! 1304: static INT cySave = 0x7FFF; ! 1305: static INT x2Save = 0x7FFF; ! 1306: static INT y2Save = 0x7FFF; ! 1307: TCHAR szBuf[CCHTEXTMAX]; ! 1308: ! 1309: if (prc) { ! 1310: if (prc->bottom - prc->top != cySave) { ! 1311: /* ! 1312: * Save it for the next time. ! 1313: */ ! 1314: cySave = prc->bottom - prc->top; ! 1315: ! 1316: wsprintf(szBuf, ids(IDS_CYFMTSTR), cySave); ! 1317: SetDlgItemText(hwndStatus, DID_STATUSCY, szBuf); ! 1318: } ! 1319: ! 1320: if (prc->right != x2Save || prc->bottom != y2Save) { ! 1321: /* ! 1322: * Save them for the next time. ! 1323: */ ! 1324: x2Save = prc->right; ! 1325: y2Save = prc->bottom; ! 1326: ! 1327: wsprintf(szBuf, L"(%d, %d)", x2Save, y2Save); ! 1328: SetDlgItemText(hwndStatus, DID_STATUSX2Y2, szBuf); ! 1329: } ! 1330: ! 1331: if (prc->left != xSave || prc->top != ySave) { ! 1332: /* ! 1333: * Save them for the next time. ! 1334: */ ! 1335: xSave = prc->left; ! 1336: ySave = prc->top; ! 1337: ! 1338: wsprintf(szBuf, L"(%d, %d)", xSave, ySave); ! 1339: SetDlgItemText(hwndStatus, DID_STATUSXY, szBuf); ! 1340: } ! 1341: ! 1342: if (prc->right - prc->left != cxSave) { ! 1343: /* ! 1344: * Save it for the next time. ! 1345: */ ! 1346: cxSave = prc->right - prc->left; ! 1347: ! 1348: wsprintf(szBuf, ids(IDS_CXFMTSTR), cxSave); ! 1349: SetDlgItemText(hwndStatus, DID_STATUSCX, szBuf); ! 1350: } ! 1351: } ! 1352: else { ! 1353: /* ! 1354: * Clear the fields. ! 1355: */ ! 1356: SetDlgItemText(hwndStatus, DID_STATUSXY, szEmpty); ! 1357: SetDlgItemText(hwndStatus, DID_STATUSX2Y2, szEmpty); ! 1358: SetDlgItemText(hwndStatus, DID_STATUSCX, szEmpty); ! 1359: SetDlgItemText(hwndStatus, DID_STATUSCY, szEmpty); ! 1360: ! 1361: /* ! 1362: * Reset the cache variables so that the next "set" of ! 1363: * the coords is sure to update the display fields. ! 1364: */ ! 1365: xSave = ! 1366: ySave = ! 1367: cxSave = ! 1368: cySave = ! 1369: x2Save = ! 1370: y2Save = 0x7FFF; ! 1371: } ! 1372: } ! 1373: ! 1374: ! 1375: ! 1376: /************************************************************************ ! 1377: * StatusSetText ! 1378: * ! 1379: * This function sets the "Text" field in the status display ! 1380: * to the given text. ! 1381: * ! 1382: * Arguments: ! 1383: * LPTSTR pszText - The text to display. This can be NULL. ! 1384: * INT Type - Type of control. One of the W_* constants. ! 1385: * ! 1386: ************************************************************************/ ! 1387: ! 1388: STATICFN VOID StatusSetText( ! 1389: LPTSTR pszText, ! 1390: INT Type) ! 1391: { ! 1392: /* ! 1393: * Protect against getting a null value. ! 1394: */ ! 1395: if (!pszText) ! 1396: pszText = szEmpty; ! 1397: ! 1398: /* ! 1399: * If this is an icon control, set the name instead (the text ! 1400: * of an icon is really a resource name). ! 1401: */ ! 1402: if (Type == W_ICON) ! 1403: StatusSetName(pszText, Type); ! 1404: else ! 1405: SetDlgItemText(hwndStatus, DID_STATUSTEXT, pszText); ! 1406: } ! 1407: ! 1408: ! 1409: ! 1410: /************************************************************************ ! 1411: * StatusSetTextLabels ! 1412: * ! 1413: * This function sets the labels of the descriptive text fields in ! 1414: * Status window based on the type of control that is selected. ! 1415: * ! 1416: * Arguments: ! 1417: * INT Type - Type of control. One of the W_* constants. ! 1418: * BOOL fIsOrd - TRUE if the name is an ordinal. This is ignored ! 1419: * unless Type is W_DIALOG or W_ICON. ! 1420: * ! 1421: ************************************************************************/ ! 1422: ! 1423: STATICFN VOID StatusSetTextLabels( ! 1424: INT Type, ! 1425: BOOL fIsOrd) ! 1426: { ! 1427: WORD ids1; ! 1428: WORD ids2; ! 1429: ! 1430: switch (Type) { ! 1431: case W_DIALOG: ! 1432: ids1 = (WORD)(fIsOrd ? IDS_DLGIDLABEL : IDS_DLGNAMELABEL); ! 1433: ids2 = IDS_CAPTIONLABEL; ! 1434: break; ! 1435: ! 1436: case W_ICON: ! 1437: ids1 = IDS_SYMBOLLABEL; ! 1438: ids2 = (WORD)(fIsOrd ? IDS_ICONIDLABEL : IDS_ICONNAMELABEL); ! 1439: break; ! 1440: ! 1441: default: ! 1442: ids1 = IDS_SYMBOLLABEL; ! 1443: ids2 = IDS_TEXTLABEL; ! 1444: break; ! 1445: } ! 1446: ! 1447: SetDlgItemText(hwndStatus, DID_STATUSLABEL1, ids(ids1)); ! 1448: SetDlgItemText(hwndStatus, DID_STATUSLABEL2, ids(ids2)); ! 1449: } ! 1450: ! 1451: ! 1452: ! 1453: /************************************************************************ ! 1454: * StatusSetID ! 1455: * ! 1456: * Updates the id field of the given label. ! 1457: * ! 1458: * Arguments: ! 1459: * INT id = The id. ! 1460: * BOOL fSymAlso = Find the corresponding label and update the ! 1461: * symbol field also. ! 1462: * ! 1463: ************************************************************************/ ! 1464: ! 1465: STATICFN VOID StatusSetID( ! 1466: INT id, ! 1467: BOOL fSymAlso) ! 1468: { ! 1469: TCHAR szValue[CCHIDMAX + 1]; ! 1470: NPLABEL npLabel; ! 1471: LPTSTR pszLabel; ! 1472: ! 1473: Myitoa(id, szValue); ! 1474: SetDlgItemText(hwndStatus, DID_STATUSSYMID, szValue); ! 1475: ! 1476: if (fSymAlso) { ! 1477: /* ! 1478: * If a matching label is found, the text is used. ! 1479: * Otherwise, if the id is zero, we use the "unused" ! 1480: * label. Otherwise, we just use an empty string. ! 1481: */ ! 1482: if (npLabel = FindID(id, plInclude)) ! 1483: pszLabel = npLabel->pszLabel; ! 1484: else if (id == IDUNUSED) ! 1485: pszLabel = ids(IDS_UNUSED); ! 1486: else if (id == IDOK && !FindLabel(ids(IDS_IDOK), plInclude)) ! 1487: pszLabel = ids(IDS_IDOK); ! 1488: else if (id == IDCANCEL && !FindLabel(ids(IDS_IDCANCEL), plInclude)) ! 1489: pszLabel = ids(IDS_IDCANCEL); ! 1490: else ! 1491: pszLabel = szEmpty; ! 1492: ! 1493: SetDlgItemText(hwndStatus, DID_STATUSSYM, pszLabel); ! 1494: } ! 1495: } ! 1496: ! 1497: ! 1498: ! 1499: /************************************************************************ ! 1500: * StatusSetName ! 1501: * ! 1502: * This function sets the "Res. Name" field in the status display ! 1503: * to the given text. ! 1504: * ! 1505: * Arguments: ! 1506: * ! 1507: * LPTSTR pszName - The name to display. NULL values and ordinals ! 1508: * are handled properly. ! 1509: * INT Type - Type of control. One of the W_* constants. ! 1510: * ! 1511: ************************************************************************/ ! 1512: ! 1513: STATICFN VOID StatusSetName( ! 1514: LPTSTR pszName, ! 1515: INT Type) ! 1516: { ! 1517: NPLABEL npLabel; ! 1518: ! 1519: /* ! 1520: * Protect against getting a null value. ! 1521: */ ! 1522: if (!pszName) ! 1523: pszName = szEmpty; ! 1524: ! 1525: /* ! 1526: * Does the name represent an ordinal? If so, set the nameid ! 1527: * field to the value and fill in the name field with the ! 1528: * associated symbol, if there is one. ! 1529: * ! 1530: * Note that this does NOT produce a hex value in Hex Mode for ! 1531: * dialog names, because rc.exe does not parse hex ordinals ! 1532: * for dialog names. ! 1533: */ ! 1534: if (IsOrd(pszName)) { ! 1535: StatusSetNameID(OrdID(pszName), Type); ! 1536: ! 1537: if (npLabel = FindID(OrdID(pszName), plInclude)) ! 1538: pszName = npLabel->pszLabel; ! 1539: else ! 1540: pszName = szEmpty; ! 1541: } ! 1542: else { ! 1543: SetDlgItemText(hwndStatus, DID_STATUSNAMEID, szEmpty); ! 1544: } ! 1545: ! 1546: SetDlgItemText(hwndStatus, DID_STATUSNAME, pszName); ! 1547: } ! 1548: ! 1549: ! 1550: ! 1551: /************************************************************************ ! 1552: * StatusSetNameID ! 1553: * ! 1554: * This function sets the id edit field associated with the ! 1555: * "Res. Name" field in the status display ! 1556: * ! 1557: * Arguments: ! 1558: * ! 1559: * INT id - The id to set into the field. ! 1560: * INT Type - Type of control. One of the W_* constants. ! 1561: * ! 1562: ************************************************************************/ ! 1563: ! 1564: STATICFN VOID StatusSetNameID( ! 1565: INT id, ! 1566: INT Type) ! 1567: { ! 1568: TCHAR szValue[CCHIDMAX + 1]; ! 1569: ! 1570: /* ! 1571: * If the current control is a dialog, do NOT produce a hex ! 1572: * value, even if the hex mode is on. RC.Exe doesn't recognize ! 1573: * hex values for the dialog name as ordinals. ! 1574: */ ! 1575: if (Type == W_DIALOG) ! 1576: itoaw(id, szValue, 10); ! 1577: else ! 1578: Myitoa(id, szValue); ! 1579: ! 1580: SetDlgItemText(hwndStatus, DID_STATUSNAMEID, szValue); ! 1581: } ! 1582: ! 1583: ! 1584: ! 1585: /************************************************************************ ! 1586: * StatusClearID ! 1587: * ! 1588: * Clears the id of the status window.. ! 1589: * ! 1590: ************************************************************************/ ! 1591: ! 1592: STATICFN VOID StatusClearID(VOID) ! 1593: { ! 1594: SetDlgItemText(hwndStatus, DID_STATUSSYM, szEmpty); ! 1595: SetDlgItemText(hwndStatus, DID_STATUSSYMID, szEmpty); ! 1596: } ! 1597: ! 1598: ! 1599: ! 1600: /************************************************************************ ! 1601: * StatusClearName ! 1602: * ! 1603: * Clears the name of the status window. ! 1604: * ! 1605: ************************************************************************/ ! 1606: ! 1607: STATICFN VOID StatusClearName(VOID) ! 1608: { ! 1609: SetDlgItemText(hwndStatus, DID_STATUSNAME, szEmpty); ! 1610: SetDlgItemText(hwndStatus, DID_STATUSNAMEID, szEmpty); ! 1611: } ! 1612: ! 1613: ! 1614: ! 1615: /************************************************************************ ! 1616: * StatusClear ! 1617: * ! 1618: * Clears the status window. ! 1619: * ! 1620: ************************************************************************/ ! 1621: ! 1622: STATICFN VOID StatusClear(VOID) ! 1623: { ! 1624: StatusSetCoords(NULL); ! 1625: StatusSetText(NULL, W_NOTHING); ! 1626: StatusShowFields(W_NOTHING); ! 1627: StatusClearID(); ! 1628: StatusClearName(); ! 1629: gfStatusChanged = FALSE; ! 1630: } ! 1631: ! 1632: ! 1633: ! 1634: /************************************************************************ ! 1635: * StatusUpdate ! 1636: * ! 1637: * Updates the status window to the current selection. ! 1638: * ! 1639: ************************************************************************/ ! 1640: ! 1641: VOID StatusUpdate(VOID) ! 1642: { ! 1643: if (gnpcSel) { ! 1644: StatusSetCoords(&gnpcSel->rc); ! 1645: StatusSetText(gnpcSel->text, gnpcSel->pwcd->iType); ! 1646: ! 1647: if (gfDlgSelected) ! 1648: StatusSetName(gcd.pszDlgName, W_DIALOG); ! 1649: else ! 1650: StatusSetID(gnpcSel->id, TRUE); ! 1651: ! 1652: StatusShowFields(gnpcSel->pwcd->iType); ! 1653: ! 1654: gfStatusChanged = FALSE; ! 1655: } ! 1656: else { ! 1657: StatusClear(); ! 1658: } ! 1659: } ! 1660: ! 1661: ! 1662: ! 1663: /************************************************************************ ! 1664: * StatusShowFields ! 1665: * ! 1666: * This function shows and hides fields in the Status ribbon based on ! 1667: * whether the dialog is currently selected or not. This is necessary ! 1668: * because dialogs have a name, whereas controls do not, and controls ! 1669: * have an id that dialogs do not have, etc. ! 1670: * ! 1671: * It will also call StatusSetTextLabels to set the text for the ! 1672: * descriptive labels in front of the fields. ! 1673: * ! 1674: * This function should be called whenever it is possible that the current ! 1675: * selection has been changed. ! 1676: * ! 1677: * Arguments: ! 1678: * INT Type - Type of control that is selected (W_* constant). ! 1679: * ! 1680: ************************************************************************/ ! 1681: ! 1682: STATICFN VOID StatusShowFields( ! 1683: INT Type) ! 1684: { ! 1685: /* ! 1686: * This static caches the type of the selected control. ! 1687: */ ! 1688: static INT TypeSave = W_NOTHING; ! 1689: ! 1690: /* ! 1691: * We only have special cases for the dialog and for icon controls. ! 1692: * All other types are treated the same (we use W_CHECKBOX arbitrarily). ! 1693: * This prevents some repainting when switching between controls that ! 1694: * have the same layout of fields in the status window. ! 1695: */ ! 1696: if (Type != W_DIALOG && Type != W_ICON) ! 1697: Type = W_CHECKBOX; ! 1698: ! 1699: if (Type != TypeSave) { ! 1700: switch (Type) { ! 1701: case W_DIALOG: ! 1702: MoveWindow(GetDlgItem(hwndStatus, DID_STATUSNAME), ! 1703: grcTopCombo.left, grcTopCombo.top, ! 1704: grcTopCombo.right - grcTopCombo.left, ! 1705: grcTopCombo.bottom - grcTopCombo.top, TRUE); ! 1706: MoveWindow(GetDlgItem(hwndStatus, DID_STATUSNAMEID), ! 1707: grcTopEdit.left, grcTopEdit.top, ! 1708: grcTopEdit.right - grcTopEdit.left, ! 1709: grcTopEdit.bottom - grcTopEdit.top, TRUE); ! 1710: ! 1711: ShowWindow(GetDlgItem(hwndStatus, DID_STATUSNAME), SW_SHOW); ! 1712: ShowWindow(GetDlgItem(hwndStatus, DID_STATUSNAMEID), SW_SHOW); ! 1713: ShowWindow(GetDlgItem(hwndStatus, DID_STATUSTEXT), SW_SHOW); ! 1714: ShowWindow(GetDlgItem(hwndStatus, DID_STATUSSYM), SW_HIDE); ! 1715: ShowWindow(GetDlgItem(hwndStatus, DID_STATUSSYMID), SW_HIDE); ! 1716: ! 1717: StatusSetTextLabels(Type, IsOrd(gcd.pszDlgName)); ! 1718: ! 1719: break; ! 1720: ! 1721: case W_ICON: ! 1722: MoveWindow(GetDlgItem(hwndStatus, DID_STATUSNAME), ! 1723: grcBottomCombo.left, grcBottomCombo.top, ! 1724: grcBottomCombo.right - grcBottomCombo.left, ! 1725: grcBottomCombo.bottom - grcBottomCombo.top, TRUE); ! 1726: MoveWindow(GetDlgItem(hwndStatus, DID_STATUSNAMEID), ! 1727: grcBottomEdit.left, grcBottomEdit.top, ! 1728: grcBottomEdit.right - grcBottomEdit.left, ! 1729: grcBottomEdit.bottom - grcBottomEdit.top, TRUE); ! 1730: ! 1731: ShowWindow(GetDlgItem(hwndStatus, DID_STATUSNAME), SW_SHOW); ! 1732: ShowWindow(GetDlgItem(hwndStatus, DID_STATUSNAMEID), SW_SHOW); ! 1733: ShowWindow(GetDlgItem(hwndStatus, DID_STATUSTEXT), SW_HIDE); ! 1734: ShowWindow(GetDlgItem(hwndStatus, DID_STATUSSYM), SW_SHOW); ! 1735: ShowWindow(GetDlgItem(hwndStatus, DID_STATUSSYMID), SW_SHOW); ! 1736: ! 1737: StatusSetTextLabels(Type, ! 1738: gnpcSel->text ? IsOrd(gnpcSel->text) : FALSE); ! 1739: ! 1740: break; ! 1741: ! 1742: default: ! 1743: ShowWindow(GetDlgItem(hwndStatus, DID_STATUSTEXT), SW_SHOW); ! 1744: ShowWindow(GetDlgItem(hwndStatus, DID_STATUSSYM), SW_SHOW); ! 1745: ShowWindow(GetDlgItem(hwndStatus, DID_STATUSSYMID), SW_SHOW); ! 1746: ShowWindow(GetDlgItem(hwndStatus, DID_STATUSNAME), SW_HIDE); ! 1747: ShowWindow(GetDlgItem(hwndStatus, DID_STATUSNAMEID), SW_HIDE); ! 1748: ! 1749: StatusSetTextLabels(Type, FALSE); ! 1750: ! 1751: break; ! 1752: } ! 1753: ! 1754: TypeSave = Type; ! 1755: } ! 1756: } ! 1757: ! 1758: ! 1759: ! 1760: /************************************************************************ ! 1761: * StatusSetEnable ! 1762: * ! 1763: * This routine sets the enable state of the editable controls in the ! 1764: * status window based on various state globals. ! 1765: * ! 1766: * The controls will be disabled on the following conditions: ! 1767: * ! 1768: * 1. Nothing is selected. ! 1769: * 2. We are in Test mode. ! 1770: * 3. One of the editors own dialogs is up (gfDisabled == TRUE). ! 1771: * ! 1772: * In addition, some controls will always be disabled if in Translate ! 1773: * mode, and the text field will be disabled if this control cannot ! 1774: * have text. ! 1775: * ! 1776: ************************************************************************/ ! 1777: ! 1778: VOID StatusSetEnable(VOID) ! 1779: { ! 1780: BOOL fEnableText = TRUE; ! 1781: BOOL fEnableSym = TRUE; ! 1782: BOOL fEnableName = TRUE; ! 1783: ! 1784: if (!gnpcSel || gfTestMode || gfDisabled) ! 1785: fEnableText = fEnableSym = fEnableName = FALSE; ! 1786: ! 1787: /* ! 1788: * Disable the text field if this control cannot have text. ! 1789: */ ! 1790: if (gnpcSel && !gnpcSel->pwcd->fHasText) ! 1791: fEnableText = FALSE; ! 1792: ! 1793: /* ! 1794: * If the dialog is selected and the style does not include ! 1795: * a caption, disable the text field. ! 1796: */ ! 1797: if (gfDlgSelected && (gnpcSel->flStyle & WS_CAPTION) != WS_CAPTION) ! 1798: fEnableText = FALSE; ! 1799: ! 1800: /* ! 1801: * Always disable the symbol and name fields if Translating. ! 1802: */ ! 1803: if (gfTranslateMode) ! 1804: fEnableSym = fEnableName = FALSE; ! 1805: ! 1806: EnableWindow(GetDlgItem(hwndStatus, DID_STATUSTEXT), fEnableText); ! 1807: ! 1808: EnableWindow(GetDlgItem(hwndStatus, DID_STATUSSYM), fEnableSym); ! 1809: EnableWindow(GetDlgItem(hwndStatus, DID_STATUSSYMID), fEnableSym); ! 1810: ! 1811: EnableWindow(GetDlgItem(hwndStatus, DID_STATUSNAME), fEnableName); ! 1812: EnableWindow(GetDlgItem(hwndStatus, DID_STATUSNAMEID), fEnableName); ! 1813: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.