Annotation of mstools/samples/sdktools/dlgedit/viewinc.c, revision 1.1

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: viewinc.c
        !            14: *
        !            15: * Manages the Symbols dialog box (view include file).
        !            16: *
        !            17: * Functions:
        !            18: *   ViewInclude()
        !            19: *   ViewIncludeDlgProc()
        !            20: *   ViewIncInit()
        !            21: *   FillIncludeLB()
        !            22: *   AddItemToIncLB()
        !            23: *   SelectDefItem()
        !            24: *   FillEditsFromLB()
        !            25: *   SetIncButtonEnable()
        !            26: *   ViewIncAdd()
        !            27: *   ViewIncDelete()
        !            28: *   ViewIncChange()
        !            29: *   CopyLabels()
        !            30: *   ViewIncCancel()
        !            31: *
        !            32: * Comments:
        !            33: *
        !            34: ****************************************************************************/
        !            35: 
        !            36: #include "dlgedit.h"
        !            37: #include "dlgfuncs.h"
        !            38: #include "dlgextrn.h"
        !            39: #include "dialogs.h"
        !            40: #include "dlghelp.h"
        !            41: 
        !            42: #include <string.h>
        !            43: 
        !            44: 
        !            45: /*
        !            46:  * Tabstop in the list box.
        !            47:  */
        !            48: #define DEFSYMBOLTABSTOP    146
        !            49: 
        !            50: static NPLABEL plNewInclude = NULL;     /* Pointer to new include data. */
        !            51: static NPLABEL plNewDelInclude = NULL;  /* Pointer to new deleted incs. */
        !            52: static BOOL fNewIncChanged;             /* TRUE if new incs are changed.*/
        !            53: 
        !            54: STATICFN BOOL ViewIncInit(HWND hwnd);
        !            55: STATICFN VOID FillIncludeLB(HWND hwnd, BOOL fUnusedOnly,
        !            56:     BOOL fSelectAnchor);
        !            57: STATICFN INT AddItemToIncLB(NPLABEL npLabel, HWND hwndLB);
        !            58: STATICFN VOID SelectDefItem(HWND hwnd, INT lastItem);
        !            59: STATICFN VOID FillEditsFromLB(HWND hwnd);
        !            60: STATICFN VOID SetIncButtonEnable(HWND hwnd);
        !            61: STATICFN BOOL ViewIncAdd(HWND hwnd);
        !            62: STATICFN BOOL ViewIncDelete(HWND hwnd);
        !            63: STATICFN BOOL ViewIncChange(HWND hwnd);
        !            64: STATICFN BOOL CopyLabels(NPLABEL plSrc, NPLABEL *pplDest);
        !            65: STATICFN VOID ViewIncCancel(HWND hwnd);
        !            66: 
        !            67: 
        !            68: 
        !            69: /************************************************************************
        !            70: * ViewInclude
        !            71: *
        !            72: * This function sets up for the View include dialog box, and invokes
        !            73: * it.
        !            74: *
        !            75: ************************************************************************/
        !            76: 
        !            77: VOID ViewInclude(VOID)
        !            78: {
        !            79:     if (CopyLabels(plInclude, &plNewInclude) &&
        !            80:             CopyLabels(plDelInclude, &plNewDelInclude)) {
        !            81:         fNewIncChanged = FALSE;
        !            82:         if (DlgBox(DID_SYMBOLS, (WNDPROC)ViewIncludeDlgProc) == IDOK)
        !            83:             /*
        !            84:              * Update the status window in case the currently selected
        !            85:              * controls id was one of the labels changed.
        !            86:              */
        !            87:             StatusUpdate();
        !            88:     }
        !            89: }
        !            90: 
        !            91: 
        !            92: 
        !            93: /************************************************************************
        !            94: * ViewIncludeDlgProc
        !            95: *
        !            96: * This is the View Include dialog procedure.
        !            97: *
        !            98: * Comments:
        !            99: *     May change the list of LABELs in plNewInclude, including their
        !           100: *       strings and including more or less memory.
        !           101: *     May put up a message box.
        !           102: *
        !           103: ************************************************************************/
        !           104: 
        !           105: DIALOGPROC ViewIncludeDlgProc(
        !           106:     HWND hwnd,
        !           107:     UINT msg,
        !           108:     WPARAM wParam,
        !           109:     LPARAM lParam)
        !           110: {
        !           111:     switch (msg) {
        !           112:         case WM_INITDIALOG:
        !           113:             return ViewIncInit(hwnd);
        !           114: 
        !           115:         case WM_COMMAND:
        !           116:             switch (LOWORD(wParam)) {
        !           117:                 case DID_SYMBOLSADD:
        !           118:                     ViewIncAdd(hwnd);
        !           119:                     break;
        !           120: 
        !           121:                 case DID_SYMBOLSDELETE:
        !           122:                     ViewIncDelete(hwnd);
        !           123:                     break;
        !           124: 
        !           125:                 case DID_SYMBOLSCHANGE:
        !           126:                     ViewIncChange(hwnd);
        !           127:                     break;
        !           128: 
        !           129:                 case DID_SYMBOLSLIST:
        !           130:                     /*
        !           131:                      * Make edit controls reflect the listbox selection.
        !           132:                      */
        !           133:                     if (HIWORD(wParam) == LBN_SELCHANGE)
        !           134:                         FillEditsFromLB(hwnd);
        !           135: 
        !           136:                     break;
        !           137: 
        !           138:                 case DID_SYMBOLSUNUSED:
        !           139:                     if (HIWORD(wParam) == BN_CLICKED) {
        !           140:                         if (IsDlgButtonChecked(hwnd, DID_SYMBOLSUNUSED))
        !           141:                             FillIncludeLB(hwnd, TRUE, FALSE);
        !           142:                         else
        !           143:                             FillIncludeLB(hwnd, FALSE, FALSE);
        !           144:                     }
        !           145: 
        !           146:                     break;
        !           147: 
        !           148:                 case IDOK:
        !           149:                     FreeLabels(&plInclude);
        !           150:                     FreeLabels(&plDelInclude);
        !           151:                     plInclude = plNewInclude;
        !           152:                     plDelInclude = plNewDelInclude;
        !           153: 
        !           154:                     if (fNewIncChanged) {
        !           155:                         gfIncChged = TRUE;
        !           156:                         ShowFileStatus(FALSE);
        !           157: 
        !           158:                         /*
        !           159:                          * Update the status windows symbol and name
        !           160:                          * combo boxes.
        !           161:                          */
        !           162:                         StatusFillSymbolList(plInclude);
        !           163:                     }
        !           164: 
        !           165:                     EndDialog(hwnd, IDOK);
        !           166:                     break;
        !           167: 
        !           168:                 case IDCANCEL:
        !           169:                     ViewIncCancel(hwnd);
        !           170:                     break;
        !           171: 
        !           172:                 case IDHELP:
        !           173:                     WinHelp(ghwndMain, gszHelpFile, HELP_CONTEXT,
        !           174:                             HELPID_SYMBOLS);
        !           175:                     break;
        !           176:             }
        !           177: 
        !           178:             return TRUE;
        !           179: 
        !           180:         default:
        !           181:             return FALSE;
        !           182:     }
        !           183: }
        !           184: 
        !           185: 
        !           186: 
        !           187: /************************************************************************
        !           188: * ViewIncInit
        !           189: *
        !           190: * Processes the WM_INITDIALOG message for the View Include dialog procedure.
        !           191: *
        !           192: * Argements:
        !           193: *   HWND hwnd - handle to the dialog
        !           194: *
        !           195: * Returns:
        !           196: *   FALSE
        !           197: *
        !           198: ************************************************************************/
        !           199: 
        !           200: STATICFN BOOL ViewIncInit(
        !           201:     HWND hwnd)
        !           202: {
        !           203:     INT nTabStops = DEFSYMBOLTABSTOP;
        !           204: 
        !           205:     SendDlgItemMessage(hwnd, DID_SYMBOLSEDITID, EM_LIMITTEXT, CCHIDMAX, 0L);
        !           206: 
        !           207:     SendDlgItemMessage(hwnd, DID_SYMBOLSLIST, LB_SETTABSTOPS, 1,
        !           208:             (DWORD)&nTabStops);
        !           209: 
        !           210:     FillIncludeLB(hwnd, FALSE, TRUE);
        !           211: 
        !           212:     /*
        !           213:      * Disable some controls if Translating.
        !           214:      */
        !           215:     if (gfTranslateMode) {
        !           216:         EnableWindow(GetDlgItem(hwnd, DID_SYMBOLSEDITSYM), FALSE);
        !           217:         EnableWindow(GetDlgItem(hwnd, DID_SYMBOLSEDITID), FALSE);
        !           218:         EnableWindow(GetDlgItem(hwnd, DID_SYMBOLSADD), FALSE);
        !           219:     }
        !           220: 
        !           221:     CenterWindow(hwnd);
        !           222: 
        !           223:     /*
        !           224:      * Yes, we changed the focus...
        !           225:      */
        !           226:     return FALSE;
        !           227: }
        !           228: 
        !           229: 
        !           230: 
        !           231: /************************************************************************
        !           232: * FillIncludeLB
        !           233: *
        !           234: * Fills the include listbox with the include items.
        !           235: *
        !           236: * Arguments:
        !           237: *   HWND hwnd - handle to the include dialog.
        !           238: *   BOOL fUnusedOnly - unused items?
        !           239: *   BOOL fSelectAnchor - anchor control?
        !           240: *
        !           241: ************************************************************************/
        !           242: 
        !           243: STATICFN VOID FillIncludeLB(
        !           244:     HWND hwnd,
        !           245:     BOOL fUnusedOnly,
        !           246:     BOOL fSelectAnchor)
        !           247: {
        !           248:     NPLABEL npLabel;
        !           249:     HWND hwndLB;
        !           250:     INT iSelect;
        !           251:     INT cIncs = 0;
        !           252: 
        !           253:     hwndLB = GetDlgItem(hwnd, DID_SYMBOLSLIST);
        !           254: 
        !           255:     SendMessage(hwndLB, WM_SETREDRAW, FALSE, 0L);
        !           256: 
        !           257:     /*
        !           258:      * Delete any existing items from the listbox.
        !           259:      */
        !           260:     SendMessage(hwndLB, LB_RESETCONTENT, 0, 0L);
        !           261: 
        !           262:     /*
        !           263:      * Fill the list box with the items.
        !           264:      */
        !           265:     for (npLabel = plNewInclude; npLabel; npLabel = npLabel->npNext) {
        !           266:         if (!fUnusedOnly || !FindIDInRes(npLabel->id)) {
        !           267:             AddItemToIncLB(npLabel, hwndLB);
        !           268:             cIncs++;
        !           269:         }
        !           270:     }
        !           271: 
        !           272:     /*
        !           273:      * Are there any items in the listbox?
        !           274:      */
        !           275:     if (cIncs) {
        !           276:         /*
        !           277:          * If there is a currently selected control, search for the
        !           278:          * symbol that corresponds to it.  This will be the default
        !           279:          * selected control.  If there is not a currently selected
        !           280:          * control, select the first symbol in the listbox.
        !           281:          *
        !           282:          * Only select the anchor control if fSelectAnchor is TRUE,
        !           283:          * however.  Also, if the dialog is selected, it does not
        !           284:          * have an id so we skip this case as well.
        !           285:          */
        !           286:         iSelect = 0;
        !           287:         if (fSelectAnchor && gnpcSel && !gfDlgSelected) {
        !           288:             if (npLabel = FindID(gnpcSel->id, plNewInclude)) {
        !           289:                 /*
        !           290:                  * Search the list box for the symbol.
        !           291:                  */
        !           292:                 iSelect = (INT)SendMessage(hwndLB, LB_FINDSTRING,
        !           293:                         (WPARAM)-1, (DWORD)npLabel->pszLabel);
        !           294: 
        !           295:                 if (iSelect == LB_ERR)
        !           296:                     iSelect = 0;
        !           297:             }
        !           298:         }
        !           299: 
        !           300:         SendMessage(hwndLB, LB_SETCURSEL, iSelect, 0L);
        !           301: 
        !           302:         /*
        !           303:          * Set the focus to the listbox initially (so arrow keys work).
        !           304:          */
        !           305:         SetFocus(hwndLB);
        !           306:     }
        !           307:     else {
        !           308:         SetFocus(GetDlgItem(hwnd, DID_SYMBOLSEDITSYM));
        !           309:     }
        !           310: 
        !           311:     SendMessage(hwndLB, WM_SETREDRAW, TRUE, 0L);
        !           312:     InvalidateRect(hwndLB, NULL, FALSE);
        !           313: 
        !           314:     FillEditsFromLB(hwnd);
        !           315:     SetIncButtonEnable(hwnd);
        !           316: }
        !           317: 
        !           318: 
        !           319: 
        !           320: /****************************************************************************
        !           321: * AddItemToIncLB
        !           322: *
        !           323: * Adds a symbol and id to the View Include listbox and associates it's
        !           324: * label pointer with the added item.
        !           325: *
        !           326: * Arguments:
        !           327: *   NPLABEL npLabel - list of label pointers.
        !           328: *   HWND hwnd LB - handle to the listbox
        !           329: *
        !           330: * Returns: 
        !           331: *
        !           332: * List box id of the newly added item.
        !           333: *
        !           334: ****************************************************************************/
        !           335: 
        !           336: STATICFN INT AddItemToIncLB(
        !           337:     NPLABEL npLabel,
        !           338:     HWND hwndLB)
        !           339: {
        !           340:     INT idTemp;
        !           341:     TCHAR szBuf[CCHTEXTMAX];
        !           342:     LPTSTR psz;
        !           343: 
        !           344:     /*
        !           345:      * Start building the string to add.  Take the label and tack on
        !           346:      * a tab character.
        !           347:      */
        !           348:     lstrcpy(szBuf, npLabel->pszLabel);
        !           349:     psz = szBuf + lstrlen(szBuf);
        !           350:     *psz++ = CHAR_TAB;
        !           351: 
        !           352:     /*
        !           353:      * Now add the id to the end, using the current hex mode.
        !           354:      */
        !           355:     Myitoa(npLabel->id, psz);
        !           356:     idTemp = (INT)SendMessage(hwndLB, LB_ADDSTRING, 0, (DWORD)szBuf);
        !           357:     SendMessage(hwndLB, LB_SETITEMDATA, idTemp, (DWORD)npLabel);
        !           358: 
        !           359:     return idTemp;
        !           360: }
        !           361: 
        !           362: 
        !           363: 
        !           364: /****************************************************************************
        !           365: * SelectDefItem
        !           366: *
        !           367: * Select an item in the listbox near lastItem.
        !           368: *
        !           369: * Arguments:
        !           370: *   HWND hwnd - handle to the dialog
        !           371: *   INT lastItem - lastitem to select.
        !           372: *
        !           373: ****************************************************************************/
        !           374: 
        !           375: STATICFN VOID SelectDefItem(
        !           376:     HWND hwnd,
        !           377:     INT lastItem)
        !           378: {
        !           379:     INT cItems;
        !           380:     HWND hwndLB;
        !           381: 
        !           382:     hwndLB = GetDlgItem(hwnd, DID_SYMBOLSLIST);
        !           383: 
        !           384:     if ((cItems = (INT)SendMessage(hwndLB, LB_GETCOUNT, 0, 0L))
        !           385:             != LB_ERR && cItems > 0)
        !           386:         SendMessage(hwndLB, LB_SETCURSEL, lastItem >= cItems ?
        !           387:                 (cItems - 1) : lastItem, 0L);
        !           388: 
        !           389:     FillEditsFromLB(hwnd);
        !           390: }
        !           391: 
        !           392: 
        !           393: 
        !           394: /****************************************************************************
        !           395: * FillEditsFromLB
        !           396: *
        !           397: * Fill the edit controls from the selected item in the listbox.
        !           398: *
        !           399: * Arguments:
        !           400: *   HWND hwnd - handle to the dialog.
        !           401: *
        !           402: ****************************************************************************/
        !           403: 
        !           404: STATICFN VOID FillEditsFromLB(
        !           405:     HWND hwnd)
        !           406: {
        !           407:     TCHAR szID[CCHIDMAX + 1];
        !           408:     INT iItem;
        !           409:     NPLABEL npLabel;
        !           410:     HWND hwndLB;
        !           411:     HWND hwndID;
        !           412:     HWND hwndSym;
        !           413: 
        !           414:     hwndLB = GetDlgItem(hwnd, DID_SYMBOLSLIST);
        !           415:     hwndSym = GetDlgItem(hwnd, DID_SYMBOLSEDITSYM);
        !           416:     hwndID = GetDlgItem(hwnd, DID_SYMBOLSEDITID);
        !           417: 
        !           418:     /*
        !           419:      * Is there a selected item?
        !           420:      */
        !           421:     if ((iItem = (INT)SendMessage(hwndLB, LB_GETCURSEL, 0, 0L))
        !           422:             != LB_ERR) {
        !           423:         npLabel = (NPLABEL)SendMessage(hwndLB, LB_GETITEMDATA,
        !           424:                 iItem, 0L);
        !           425:         SetWindowText(hwndSym, npLabel->pszLabel);
        !           426: 
        !           427:         Myitoa(npLabel->id, szID);
        !           428:         SetWindowText(hwndID, szID);
        !           429:     }
        !           430:     else {
        !           431:         /*
        !           432:          * No, clear the fields.
        !           433:          */
        !           434:         SetWindowText(hwndSym, szEmpty);
        !           435:         SetWindowText(hwndID, szEmpty);
        !           436:     }
        !           437: }
        !           438: 
        !           439: 
        !           440: 
        !           441: /****************************************************************************
        !           442: * SetIncButtonEnable
        !           443: *
        !           444: * Enable/disable the Symbols change and delete buttons.
        !           445: *
        !           446: * Arguments:
        !           447: *   HWND hwnd - handle to the dialog.
        !           448: *
        !           449: ****************************************************************************/
        !           450: 
        !           451: STATICFN VOID SetIncButtonEnable(
        !           452:     HWND hwnd)
        !           453: {
        !           454:     BOOL fEnable = TRUE;
        !           455: 
        !           456:     /*
        !           457:      * If the list box doesn't have items, or we are in translate mode,
        !           458:      * disable the Delete and Change buttons.
        !           459:      */
        !           460:     if (gfTranslateMode || SendDlgItemMessage(hwnd, DID_SYMBOLSLIST,
        !           461:             LB_GETCOUNT, 0, 0L) == 0)
        !           462:         fEnable = FALSE;
        !           463: 
        !           464:     EnableWindow(GetDlgItem(hwnd, DID_SYMBOLSDELETE), fEnable);
        !           465:     EnableWindow(GetDlgItem(hwnd, DID_SYMBOLSCHANGE), fEnable);
        !           466: }
        !           467: 
        !           468: 
        !           469: 
        !           470: /************************************************************************
        !           471: * ViewIncAdd
        !           472: *
        !           473: * Processes the "Add" command for the View Include dialog procedure.
        !           474: *
        !           475: * Arguments:
        !           476: *   HWND hwnd - handle to the dialog.
        !           477: *
        !           478: ************************************************************************/
        !           479: 
        !           480: STATICFN BOOL ViewIncAdd(
        !           481:     HWND hwnd)
        !           482: {
        !           483:     TCHAR szSym[CCHTEXTMAX];
        !           484:     TCHAR szID[CCHIDMAX + 1];
        !           485:     HWND hwndLB;
        !           486:     INT idNew;
        !           487:     NPLABEL npLabel;
        !           488: 
        !           489:     /*
        !           490:      * Get current symbol & ID.
        !           491:      */
        !           492:     GetDlgItemText(hwnd, DID_SYMBOLSEDITID, szID, CCHIDMAX + 1);
        !           493:     GetDlgItemText(hwnd, DID_SYMBOLSEDITSYM, szSym, CCHTEXTMAX);
        !           494: 
        !           495:     /*
        !           496:      * If they didn't specify a new id as well as a new symbol,
        !           497:      * pick a default number.
        !           498:      */
        !           499:     if (*szID == CHAR_NULL)
        !           500:         Myitoa(NextID(NEXTID_LABEL, plNewInclude, 0), szID);
        !           501: 
        !           502:     /*
        !           503:      * Validate them.
        !           504:      */
        !           505:     if (!IsSymbol(szSym) || !IsValue(szID)) {
        !           506:         Message(MSG_BADSYMBOLID);
        !           507:         return FALSE;
        !           508:     }
        !           509: 
        !           510:     idNew = valtoi(szID);
        !           511: 
        !           512:     if (!(npLabel = AddLabel(szSym, idNew, FPOS_MAX, 0,
        !           513:             &plNewInclude, &plNewDelInclude, NULL, NULL)))
        !           514:         return FALSE;
        !           515: 
        !           516:     fNewIncChanged = TRUE;
        !           517: 
        !           518:     /*
        !           519:      * Add the new symbol to the listbox, but not if they only want to
        !           520:      * show unused id's and this id is in use.
        !           521:      */
        !           522:     if (!IsDlgButtonChecked(hwnd, DID_SYMBOLSUNUSED) ||
        !           523:             !FindIDInRes(idNew)) {
        !           524:         hwndLB = GetDlgItem(hwnd, DID_SYMBOLSLIST);
        !           525:         SendMessage(hwndLB, LB_SETCURSEL,
        !           526:                 AddItemToIncLB(npLabel, hwndLB), 0L);
        !           527:     }
        !           528: 
        !           529:     SetIncButtonEnable(hwnd);
        !           530:     FillEditsFromLB(hwnd);
        !           531: 
        !           532:     return TRUE;
        !           533: }
        !           534: 
        !           535: 
        !           536: 
        !           537: /************************************************************************
        !           538: * ViewIncDelete
        !           539: *
        !           540: * Processes the "Delete" command for the View Include dialog procedure.
        !           541: *
        !           542: * Arguments:
        !           543: *   HWND hwnd - handle to the dialog.
        !           544: *
        !           545: ************************************************************************/
        !           546: 
        !           547: STATICFN BOOL ViewIncDelete(
        !           548:     HWND hwnd)
        !           549: {
        !           550:     TCHAR szSym[CCHTEXTMAX];
        !           551:     HWND hwndLB;
        !           552:     INT iItem;
        !           553: 
        !           554:     /*
        !           555:      * Get current symbol and listbox hwnd.
        !           556:      */
        !           557:     GetDlgItemText(hwnd, DID_SYMBOLSEDITSYM, szSym, CCHTEXTMAX);
        !           558:     hwndLB = GetDlgItem(hwnd, DID_SYMBOLSLIST);
        !           559: 
        !           560:     /*
        !           561:      * Search the list box for the symbol.  This will probably be
        !           562:      * the same as the selection, but if they type in a symbol
        !           563:      * then it will not be.
        !           564:      */
        !           565:     iItem = (INT)SendMessage(hwndLB, LB_FINDSTRING, (WPARAM)-1, (DWORD)szSym);
        !           566: 
        !           567:     /*
        !           568:      * Fail if the symbol was not found.
        !           569:      */
        !           570:     if (iItem == LB_ERR) {
        !           571:         Message(MSG_SYMNOTFOUND);
        !           572:         return FALSE;
        !           573:     }
        !           574: 
        !           575:     DeleteLabel(szSym, &plNewInclude, &plNewDelInclude);
        !           576:     fNewIncChanged = TRUE;
        !           577: 
        !           578:     SendMessage(hwndLB, LB_DELETESTRING, iItem, 0L);
        !           579:     SelectDefItem(hwnd, iItem);
        !           580:     SetIncButtonEnable(hwnd);
        !           581: 
        !           582:     return TRUE;
        !           583: }
        !           584: 
        !           585: 
        !           586: 
        !           587: /************************************************************************
        !           588: * ViewIncChange
        !           589: *
        !           590: * Processes the "Change" command for the View Include dialog procedure.
        !           591: *
        !           592: * Arguments:
        !           593: *   HWND hwnd - handle to the dialog.
        !           594: *
        !           595: ************************************************************************/
        !           596: 
        !           597: STATICFN BOOL ViewIncChange(
        !           598:     HWND hwnd)
        !           599: {
        !           600:     TCHAR szSym[CCHTEXTMAX];
        !           601:     TCHAR szID[CCHIDMAX + 1];
        !           602:     HWND hwndLB;
        !           603:     NPLABEL npLabel;
        !           604:     NPLABEL npLabelNew;
        !           605:     INT idNew;
        !           606:     INT iItem;
        !           607: 
        !           608:     /*
        !           609:      * Get current symbol & ID.
        !           610:      */
        !           611:     GetDlgItemText(hwnd, DID_SYMBOLSEDITID, szID, CCHIDMAX + 1);
        !           612:     GetDlgItemText(hwnd, DID_SYMBOLSEDITSYM, szSym, CCHTEXTMAX);
        !           613: 
        !           614:     /*
        !           615:      * Validate them.
        !           616:      */
        !           617:     if (!IsSymbol(szSym) || !IsValue(szID)) {
        !           618:         Message(MSG_BADSYMBOLID);
        !           619:         return FALSE;
        !           620:     }
        !           621: 
        !           622:     hwndLB = GetDlgItem(hwnd, DID_SYMBOLSLIST);
        !           623: 
        !           624:     /*
        !           625:      * Make sure a selection is made.
        !           626:      */
        !           627:     if ((iItem = (INT)SendMessage(hwndLB, LB_GETCURSEL, 0, 0L))
        !           628:             == LB_ERR) {
        !           629:         Message(MSG_SELECTFIRST);
        !           630:         return FALSE;
        !           631:     }
        !           632: 
        !           633:     /*
        !           634:      * Get the item handle.
        !           635:      */
        !           636:     npLabel = (NPLABEL)SendMessage(hwndLB, LB_GETITEMDATA, iItem, 0L);
        !           637: 
        !           638:     /*
        !           639:      * Check if the symbol is changing.
        !           640:      */
        !           641:     idNew = valtoi(szID);
        !           642:     if (lstrcmp(npLabel->pszLabel, szSym) != 0) {
        !           643:         if (!(npLabelNew = AddLabel(szSym, idNew, FPOS_MAX, 0,
        !           644:                 &plNewInclude, &plNewDelInclude, npLabel, NULL)))
        !           645:             return FALSE;
        !           646: 
        !           647:         DeleteLabel(npLabel->pszLabel, &plNewInclude, &plNewDelInclude);
        !           648:         npLabel = npLabelNew;
        !           649:     }
        !           650:     /*
        !           651:      * The symbol didn't change.  Did the id change?
        !           652:      */
        !           653:     else if (idNew != npLabel->id) {
        !           654:         /*
        !           655:          * First check for a duplicate id.
        !           656:          */
        !           657:         if (FindID(idNew, plNewInclude)) {
        !           658:             Message(MSG_LABELDUPID);
        !           659:             return FALSE;
        !           660:         }
        !           661: 
        !           662:         npLabel->id = idNew;
        !           663:     }
        !           664:     else {
        !           665:         /*
        !           666:          * Nothing changed.
        !           667:          */
        !           668:         Message(MSG_SYMNOCHANGE);
        !           669:         return FALSE;
        !           670:     }
        !           671: 
        !           672:     fNewIncChanged = TRUE;
        !           673:     SendMessage(hwndLB, WM_SETREDRAW, FALSE, 0L);
        !           674:     SendMessage(hwndLB, LB_DELETESTRING, iItem, 0L);
        !           675: 
        !           676:     /*
        !           677:      * Add the changed symbol to the listbox, but not if they only want to
        !           678:      * show unused id's and this id is in use.
        !           679:      */
        !           680:     if (!IsDlgButtonChecked(hwnd, DID_SYMBOLSUNUSED) || !FindIDInRes(idNew))
        !           681:         SendMessage(hwndLB, LB_SETCURSEL,
        !           682:                 AddItemToIncLB(npLabel, hwndLB), 0L);
        !           683: 
        !           684:     SendMessage(hwndLB, WM_SETREDRAW, TRUE, 0L);
        !           685:     InvalidateRect(hwndLB, NULL, FALSE);
        !           686:     FillEditsFromLB(hwnd);
        !           687:     SetIncButtonEnable(hwnd);
        !           688: 
        !           689:     return TRUE;
        !           690: }
        !           691: 
        !           692: 
        !           693: 
        !           694: /****************************************************************************
        !           695: * CopyLabels
        !           696: *
        !           697: * This function creates a copy of the LABEL structure list in plSrc,
        !           698: * including copying all strings.  This is put in local memory and
        !           699: * the head pointer is returned in *pplDest.
        !           700: *
        !           701: * Arguments:
        !           702: *   NPLABEL plSrc - label list source.
        !           703: *   NPLABEL pplDest - label list destination.
        !           704: *
        !           705: * Returns:
        !           706: *
        !           707: *  TRUE if all went well, FALSE if there was a problem.
        !           708: *
        !           709: * Comments: 
        !           710: *
        !           711: * Locally allocates a copy of plSrc and its strings.
        !           712: *
        !           713: * Caution: If pplDest points to a valid list it must be freed before
        !           714: *          calling this function.
        !           715: *
        !           716: ****************************************************************************/
        !           717: 
        !           718: STATICFN BOOL CopyLabels(
        !           719:     NPLABEL plSrc,
        !           720:     NPLABEL *pplDest)
        !           721: {
        !           722:     NPLABEL plNew;
        !           723:     NPLABEL plPrev;
        !           724: 
        !           725:     plPrev = NULL;
        !           726:     *pplDest = NULL;
        !           727:     while (plSrc) {
        !           728:         if (!(plNew = (NPLABEL)MyAlloc(sizeof(LABEL)))) {
        !           729:             FreeLabels(pplDest);
        !           730:             return FALSE;
        !           731:         }
        !           732: 
        !           733:         /*
        !           734:          * Are we on the first one?
        !           735:          */
        !           736:         if (*pplDest == NULL)
        !           737:             *pplDest = plNew;
        !           738:         else
        !           739:             plPrev->npNext = plNew;
        !           740: 
        !           741:         /*
        !           742:          * Start by copying the whole label structure.
        !           743:          */
        !           744:         memcpy((PBYTE)plNew, (PBYTE)plSrc, sizeof(LABEL));
        !           745: 
        !           746:         /*
        !           747:          * Make a private copy of the pszLabel string.
        !           748:          */
        !           749:         if (!(plNew->pszLabel =
        !           750:                 MyAlloc((lstrlen(plSrc->pszLabel) + 1) * sizeof(TCHAR)))) {
        !           751:             MyFree(plNew);
        !           752:             FreeLabels(pplDest);
        !           753:             return FALSE;
        !           754:         }
        !           755: 
        !           756:         lstrcpy(plNew->pszLabel, plSrc->pszLabel);
        !           757: 
        !           758:         plNew->npNext = NULL;           /* In case this is the last one.*/
        !           759:         plPrev = plNew;                 /* Save so we can update npNext.*/
        !           760:         plSrc = plSrc->npNext;          /* Get next one to copy.        */
        !           761:     }
        !           762: 
        !           763:     return TRUE;
        !           764: }
        !           765: 
        !           766: 
        !           767: 
        !           768: /************************************************************************
        !           769: * ViewIncCancel
        !           770: *
        !           771: * Called when cancelling the Symbols dialog box.
        !           772: *
        !           773: * Argements:
        !           774: *    HWND hwnd - handle to the dialog
        !           775: *
        !           776: ************************************************************************/
        !           777: 
        !           778: STATICFN VOID ViewIncCancel(
        !           779:     HWND hwnd)
        !           780: {
        !           781:     /*
        !           782:      * If they changed anything, confirm that they
        !           783:      * want to throw away the changes.
        !           784:      */
        !           785:     if (fNewIncChanged &&
        !           786:             Message(MSG_CONFIRMDISCARD) != IDYES)
        !           787:         return;
        !           788: 
        !           789:     /*
        !           790:      * Free up the temporary label lists and get out.
        !           791:      */
        !           792:     FreeLabels(&plNewInclude);
        !           793:     FreeLabels(&plNewDelInclude);
        !           794: 
        !           795:     /*
        !           796:      * Flag the dialog to be dismissed.
        !           797:      */
        !           798:     EndDialog(hwnd, IDCANCEL);
        !           799: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.