Annotation of mstools/ole20/samples/outline/dialogs.c, revision 1.1.1.1

1.1       root        1: /*************************************************************************
                      2: ** 
                      3: **    OLE 2 Sample Code
                      4: **    
                      5: **    dialogs.c
                      6: **    
                      7: **    This file contains dialog functions and support function
                      8: **    
                      9: **    (c) Copyright Microsoft Corp. 1992 - 1993 All Rights Reserved
                     10: **
                     11: *************************************************************************/
                     12: 
                     13: #include "outline.h"
                     14: 
                     15: OLEDBGDATA
                     16: 
                     17: extern LPOUTLINEAPP g_lpApp;
                     18: 
                     19: static char g_szBuf[MAXSTRLEN+1];
                     20: static LPSTR g_lpszDlgTitle;
                     21: 
                     22: // REVIEW: should use string resource for messages
                     23: static char ErrMsgInvalidRange[] = "Invalid Range entered!";
                     24: static char ErrMsgInvalidValue[] = "Invalid Value entered!";
                     25: static char ErrMsgInvalidName[] = "Invalid Name entered!";
                     26: static char ErrMsgNullName[] = "NULL string disallowed!";
                     27: static char ErrMsgNameNotFound[] = "Name doesn't exist!";
                     28: 
                     29: /* InputTextDlg
                     30:  * ------------
                     31:  *
                     32:  *      Put up a dialog box to allow the user to edit text
                     33:  */
                     34: BOOL InputTextDlg(HWND hWnd, LPSTR lpszText, LPSTR lpszDlgTitle)
                     35: {
                     36:     int nResult;
                     37: 
                     38:     g_lpszDlgTitle = lpszDlgTitle;  
                     39:     lstrcpy((LPSTR)g_szBuf, lpszText);  // preload dialog with input text
                     40: 
                     41:     nResult = DialogBox(g_lpApp->m_hInst, (LPSTR)"AddEditLine", hWnd, 
                     42:                         (DLGPROC)AddEditDlgProc);
                     43:     if (nResult) {
                     44:         lstrcpy(lpszText, (LPSTR)g_szBuf);
                     45:         return TRUE;
                     46:     } else {
                     47:         return FALSE;       
                     48:     }
                     49: }
                     50: 
                     51: 
                     52: 
                     53: /* AddEditDlgProc
                     54:  * --------------
                     55:  *
                     56:  * This procedure is associated with the dialog box that is included in
                     57:  * the function name of the procedure. It provides the service routines 
                     58:  * for the events (messages) that occur because the end user operates  
                     59:  * one of the dialog box's buttons, entry fields, or controls.         
                     60:  */
                     61: BOOL CALLBACK EXPORT AddEditDlgProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
                     62: {
                     63:     HWND hEdit;
                     64: 
                     65:     switch(Message) {
                     66:         case WM_INITDIALOG:
                     67:             /* initialize working variables */
                     68:             hEdit=GetDlgItem(hDlg,IDD_EDIT);
                     69:             SendMessage(hEdit,EM_LIMITTEXT,(WPARAM)MAXSTRLEN,0L);
                     70:             SetWindowText(hDlg, g_lpszDlgTitle);
                     71:             SetDlgItemText(hDlg,IDD_EDIT, g_szBuf);
                     72:             break; /* End of WM_INITDIALOG */
                     73: 
                     74:         case WM_CLOSE:
                     75:             /* Closing the Dialog behaves the same as Cancel */
                     76:             PostMessage(hDlg, WM_COMMAND, IDCANCEL, 0L);
                     77:             break; /* End of WM_CLOSE */
                     78: 
                     79:         case WM_COMMAND:
                     80:             switch (wParam) {
                     81:                 case IDOK:
                     82:                     /* save data values entered into the controls
                     83:                     ** and dismiss the dialog box returning TRUE
                     84:                     */
                     85:                     GetDlgItemText(hDlg,IDD_EDIT,(LPSTR)g_szBuf,MAXSTRLEN+1);
                     86:                     EndDialog(hDlg, TRUE);
                     87:                     break;
                     88: 
                     89:                 case IDCANCEL:
                     90:                     /* ignore data values entered into the controls
                     91:                     ** and dismiss the dialog box returning FALSE
                     92:                     */
                     93:                     EndDialog(hDlg, FALSE);
                     94:                     break;
                     95:             }
                     96:             break;    /* End of WM_COMMAND */
                     97: 
                     98:         default:
                     99:             return FALSE;
                    100:     }
                    101: 
                    102:     return TRUE;
                    103: } /* End of AddEditDlgProc */
                    104: 
                    105: 
                    106: /* SetLineHeightDlgProc
                    107:  * --------------------
                    108:  *
                    109:  *      Dialog procedure for set line height
                    110:  */
                    111: BOOL CALLBACK EXPORT SetLineHeightDlgProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
                    112: {
                    113:     BOOL    fTranslated;
                    114:     BOOL    fEnable;
                    115:     static LPINT    lpint;
                    116:     int     nHeight;
                    117:     static int nMaxHeight;
                    118:     
                    119:     switch (Message) {
                    120:         case WM_INITDIALOG:
                    121:         {
                    122:             char cBuf[80];
                    123:             
                    124:             nMaxHeight = XformHeightInPixelsToHimetric(NULL, 
                    125:                                 LISTBOX_HEIGHT_LIMIT);
                    126:             lpint = (LPINT)lParam;
                    127:             SetDlgItemInt(hDlg, IDD_EDIT, *lpint, FALSE);
                    128:             wsprintf(cBuf, "Maximum value is %d units", nMaxHeight);
                    129:             SetDlgItemText(hDlg, IDD_LIMIT, (LPSTR)cBuf);
                    130:             break;
                    131:         }
                    132:         
                    133:         case WM_COMMAND:
                    134:             switch (wParam) {
                    135:                 case IDOK:
                    136:                     if (IsDlgButtonChecked(hDlg, IDD_CHECK)) {
                    137:                         *lpint = -1;
                    138:                     }
                    139:                     else {
                    140:                         /* save the value in the edit control */
                    141:                         nHeight = GetDlgItemInt(hDlg, IDD_EDIT,
                    142:                                 (BOOL FAR*)&fTranslated, FALSE);
                    143:                         if (!fTranslated || !nHeight || (nHeight>nMaxHeight)){
                    144:                             OutlineApp_ErrorMessage(g_lpApp, 
                    145:                                     ErrMsgInvalidValue);
                    146:                             break;
                    147:                         }
                    148:                         *lpint = nHeight;
                    149:                     }
                    150:                     EndDialog(hDlg, TRUE);
                    151:                     break;
                    152:                         
                    153:                 case IDCANCEL:
                    154:                     *lpint = 0;
                    155:                     EndDialog(hDlg, FALSE);
                    156:                     break;
                    157:                 
                    158:                 
                    159:                 case IDD_CHECK:
                    160:                     fEnable = !IsDlgButtonChecked(hDlg, IDD_CHECK);
                    161:                     EnableWindow(GetDlgItem(hDlg, IDD_EDIT), fEnable);
                    162:                     EnableWindow(GetDlgItem(hDlg, IDD_TEXT), fEnable);
                    163:                     break;
                    164:             }
                    165:             break;  /* WM_COMMAND */
                    166:             
                    167:         case WM_CLOSE:  /* Closing the Dialog behaves the same as Cancel */
                    168:             PostMessage(hDlg, WM_COMMAND, IDCANCEL, 0L);
                    169:             break; /* End of WM_CLOSE */
                    170:             
                    171:         default:
                    172:             return FALSE;
                    173:     }
                    174:     
                    175:     return TRUE;
                    176:     
                    177: } /* end of SetLineHeightProc */
                    178: 
                    179: 
                    180: 
                    181: 
                    182: 
                    183: /* DefineNameDlgProc
                    184:  * -----------------
                    185:  *
                    186:  *      Dialog procedure for define name
                    187:  */
                    188: BOOL CALLBACK EXPORT DefineNameDlgProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
                    189: { 
                    190:     static HWND hCombo;
                    191:     static LPOUTLINEDOC lpOutlineDoc = NULL;
                    192:     static LPOUTLINENAMETABLE lpOutlineNameTable = NULL;
                    193:     LPOUTLINENAME lpOutlineName = NULL;
                    194:     UINT nIndex;
                    195:     LINERANGE lrSel;
                    196:     BOOL fTranslated;
                    197: 
                    198:     switch(Message) {
                    199:         case WM_INITDIALOG:
                    200:         /* initialize working variables */
                    201:             hCombo=GetDlgItem(hDlg,IDD_COMBO);
                    202:             lpOutlineDoc = (LPOUTLINEDOC) lParam;
                    203:             lpOutlineNameTable = OutlineDoc_GetNameTable(lpOutlineDoc);
                    204: 
                    205:             SendMessage(hCombo,CB_LIMITTEXT,(WPARAM)MAXNAMESIZE,0L);
                    206:             NameDlg_LoadComboBox(lpOutlineNameTable, hCombo);
                    207: 
                    208:             OutlineDoc_GetSel(lpOutlineDoc, (LPLINERANGE)&lrSel);
                    209:             lpOutlineName = OutlineNameTable_FindNamedRange(
                    210:                     lpOutlineNameTable,
                    211:                     &lrSel
                    212:             );
                    213:             
                    214:             /* if current selection already has a name, hilight it */
                    215:             if (lpOutlineName) {
                    216:                 nIndex = (int) SendMessage(
                    217:                         hCombo,
                    218:                         CB_FINDSTRINGEXACT,
                    219:                         (WPARAM)0xffff,
                    220:                         (LPARAM)(LPCSTR)lpOutlineName->m_szName
                    221:                 );
                    222:                 if (nIndex != CB_ERR) {
                    223:                     SendMessage(hCombo, CB_SETCURSEL, (WPARAM)nIndex, 0L);
                    224:                 }
                    225:             } 
                    226: 
                    227:             SetDlgItemInt(hDlg, IDD_FROM, (UINT)lrSel.m_nStartLine+1,FALSE);
                    228:             SetDlgItemInt(hDlg, IDD_TO, (UINT)lrSel.m_nEndLine+1, FALSE);
                    229:             
                    230:             break; /* End of WM_INITDIALOG */
                    231: 
                    232:         case WM_CLOSE:
                    233:         /* Closing the Dialog behaves the same as Cancel */
                    234:             PostMessage(hDlg, WM_COMMAND, IDD_CLOSE, 0L);
                    235:             break; /* End of WM_CLOSE */
                    236: 
                    237:         case WM_COMMAND:
                    238:             switch(wParam) {
                    239:                 case IDOK:
                    240:                     GetDlgItemText(hDlg,IDD_COMBO,(LPSTR)g_szBuf,MAXNAMESIZE);
                    241:                     if(! SendMessage(hCombo,WM_GETTEXTLENGTH,0,0L)) {
                    242:                         MessageBox(
                    243:                                 hDlg,
                    244:                                 ErrMsgNullName,
                    245:                                 NULL,
                    246:                                 MB_ICONEXCLAMATION
                    247:                         );
                    248:                         break;
                    249:                     } else if(SendMessage(hCombo,CB_GETCURSEL,0,0L)==CB_ERR &&
                    250:                             _fstrchr(g_szBuf, ' ')) {
                    251:                         MessageBox(
                    252:                                 hDlg, 
                    253:                                 ErrMsgInvalidName, 
                    254:                                 NULL, 
                    255:                                 MB_ICONEXCLAMATION
                    256:                         );
                    257:                         break;
                    258:                     } else {
                    259:                         nIndex = (int) SendMessage(hCombo,CB_FINDSTRINGEXACT,
                    260:                             (WPARAM)0xffff,(LPARAM)(LPCSTR)g_szBuf);
                    261: 
                    262:                         /* Line indices are 1 less than the number in
                    263:                         **    the row heading 
                    264:                         */
                    265:                         lrSel.m_nStartLine = GetDlgItemInt(hDlg, IDD_FROM,
                    266:                                 (BOOL FAR*)&fTranslated, FALSE) - 1;
                    267:                         if(! fTranslated) {
                    268:                             OutlineApp_ErrorMessage(g_lpApp,
                    269:                                     ErrMsgInvalidRange);
                    270:                             break;
                    271:                         }
                    272:                         lrSel.m_nEndLine = GetDlgItemInt(hDlg, IDD_TO,
                    273:                                 (BOOL FAR*)&fTranslated, FALSE) - 1;
                    274:                         if (!fTranslated ||
                    275:                             (lrSel.m_nStartLine < 0) ||
                    276:                             (lrSel.m_nEndLine < lrSel.m_nStartLine) ||
                    277:                             (lrSel.m_nEndLine >= OutlineDoc_GetLineCount(
                    278:                                     lpOutlineDoc))) {
                    279:                             OutlineApp_ErrorMessage(g_lpApp,
                    280:                                     ErrMsgInvalidRange);
                    281:                             break;
                    282:                         }
                    283: 
                    284:                         if(nIndex != CB_ERR) {
                    285:                             NameDlg_UpdateName(
                    286:                                     hCombo,
                    287:                                     lpOutlineDoc,
                    288:                                     nIndex, 
                    289:                                     g_szBuf,
                    290:                                     &lrSel
                    291:                             );
                    292:                         } else {
                    293:                             NameDlg_AddName(
                    294:                                     hCombo,
                    295:                                     lpOutlineDoc,
                    296:                                     g_szBuf,
                    297:                                     &lrSel
                    298:                             );
                    299:                         }
                    300:                     }
                    301:                     // fall through
                    302:                     
                    303:                 case IDD_CLOSE:
                    304:                     /* Ignore data values entered into the controls */
                    305:                     /* and dismiss the dialog window returning FALSE */
                    306:                     EndDialog(hDlg,0);
                    307:                     break;
                    308: 
                    309:                 case IDD_DELETE:
                    310:                     GetDlgItemText(hDlg,IDD_COMBO,(LPSTR)g_szBuf,MAXNAMESIZE);
                    311:                     if((nIndex=(int)SendMessage(hCombo,CB_FINDSTRINGEXACT,
                    312:                     (WPARAM)0xffff,(LPARAM)(LPCSTR)g_szBuf))==CB_ERR)
                    313:                         MessageBox(hDlg, ErrMsgNameNotFound, NULL, MB_ICONEXCLAMATION);
                    314:                     else {
                    315:                         NameDlg_DeleteName(hCombo, lpOutlineDoc, nIndex);
                    316:                     }
                    317:                     break;
                    318:                     
                    319:                 case IDD_COMBO: 
                    320:                     if(HIWORD(lParam) == CBN_SELCHANGE) {
                    321:                         nIndex=(int)SendMessage(hCombo, CB_GETCURSEL, 0, 0L);
                    322:                         lpOutlineName = (LPOUTLINENAME)SendMessage(
                    323:                                 hCombo, 
                    324:                                 CB_GETITEMDATA,
                    325:                                 (WPARAM)nIndex,
                    326:                                 0L
                    327:                         );
                    328:                         SetDlgItemInt(
                    329:                                 hDlg, 
                    330:                                 IDD_FROM, 
                    331:                                 (UINT) lpOutlineName->m_nStartLine + 1,
                    332:                                 FALSE
                    333:                         );
                    334:                         SetDlgItemInt(
                    335:                                 hDlg, 
                    336:                                 IDD_TO, 
                    337:                                 (UINT) lpOutlineName->m_nEndLine + 1,
                    338:                                 FALSE
                    339:                         );
                    340:                     }
                    341:             }
                    342:             break;    /* End of WM_COMMAND */
                    343: 
                    344:         default:
                    345:             return FALSE;
                    346:     }
                    347: 
                    348:     return TRUE;
                    349: } /* End of DefineNameDlgProc */
                    350: 
                    351: 
                    352: /* GotoNameDlgProc
                    353:  * ---------------
                    354:  *
                    355:  *      Dialog procedure for goto name
                    356:  */
                    357: BOOL CALLBACK EXPORT GotoNameDlgProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
                    358: {
                    359:     static HWND hLBName;
                    360:     static LPOUTLINEDOC lpOutlineDoc = NULL;
                    361:     static LPOUTLINENAMETABLE lpOutlineNameTable = NULL;
                    362:     UINT nIndex;
                    363:     LINERANGE lrLineRange;
                    364:     LPOUTLINENAME lpOutlineName;
                    365: 
                    366:     switch(Message) {
                    367:         case WM_INITDIALOG:
                    368:         /* initialize working variables */
                    369:             lpOutlineDoc = (LPOUTLINEDOC) lParam;
                    370:             lpOutlineNameTable = OutlineDoc_GetNameTable(lpOutlineDoc);
                    371: 
                    372:             hLBName=GetDlgItem(hDlg,IDD_LINELISTBOX);
                    373:             NameDlg_LoadListBox(lpOutlineNameTable, hLBName);
                    374:             
                    375:             // highlight 1st item
                    376:             SendMessage(hLBName, LB_SETCURSEL, 0, 0L); 
                    377:             // trigger to initialize edit control 
                    378:             SendMessage(hDlg, WM_COMMAND, (WPARAM)IDD_LINELISTBOX, 
                    379:                 MAKELONG(hLBName, LBN_SELCHANGE));
                    380:             
                    381:             break; /* End of WM_INITDIALOG */
                    382: 
                    383:         case WM_CLOSE:
                    384:         /* Closing the Dialog behaves the same as Cancel */
                    385:             PostMessage(hDlg, WM_COMMAND, IDCANCEL, 0L);
                    386:             break; /* End of WM_CLOSE */
                    387: 
                    388:         case WM_COMMAND:
                    389:             switch(wParam) {
                    390:                 case IDD_LINELISTBOX:
                    391:                     if(HIWORD(lParam) == LBN_SELCHANGE) {
                    392:                         // update the line range display
                    393:                         nIndex=(int)SendMessage(hLBName, LB_GETCURSEL, 0, 0L);
                    394:                         lpOutlineName = (LPOUTLINENAME)SendMessage(hLBName, LB_GETITEMDATA,
                    395:                                             (WPARAM)nIndex,0L);
                    396:                         if (lpOutlineName) {
                    397:                             SetDlgItemInt(
                    398:                                     hDlg, 
                    399:                                     IDD_FROM, 
                    400:                                     (UINT) lpOutlineName->m_nStartLine + 1,
                    401:                                     FALSE
                    402:                             );
                    403:                             SetDlgItemInt(
                    404:                                     hDlg, 
                    405:                                     IDD_TO, 
                    406:                                     (UINT) lpOutlineName->m_nEndLine + 1,
                    407:                                     FALSE
                    408:                             );
                    409:                         }
                    410:                         break;
                    411:                     }
                    412:                     // double click will fall through
                    413:                     else if(HIWORD(lParam) != LBN_DBLCLK)
                    414:                         break;
                    415:                     
                    416:                 case IDOK:
                    417:                     nIndex=(int)SendMessage(hLBName,LB_GETCURSEL,0,0L);
                    418:                     if(nIndex!=LB_ERR) {
                    419:                         lpOutlineName = (LPOUTLINENAME)SendMessage(hLBName,
                    420:                                 LB_GETITEMDATA, (WPARAM)nIndex, 0L);
                    421:                         lrLineRange.m_nStartLine=lpOutlineName->m_nStartLine;
                    422:                         lrLineRange.m_nEndLine = lpOutlineName->m_nEndLine;
                    423:                         OutlineDoc_SetSel(lpOutlineDoc, &lrLineRange);
                    424:                     }   // fall through
                    425:                     
                    426:                 case IDCANCEL:
                    427:                 /* Ignore data values entered into the controls */
                    428:                 /* and dismiss the dialog window returning FALSE */
                    429:                     EndDialog(hDlg,0);
                    430:                     break;
                    431: 
                    432:             }
                    433:             break;    /* End of WM_COMMAND */
                    434: 
                    435:         default:
                    436:             return FALSE;
                    437:     }
                    438: 
                    439:     return TRUE;
                    440: } /* End of GotoNameDlgProc */
                    441: 
                    442: 
                    443: 
                    444: /* NameDlg_LoadComboBox
                    445:  * --------------------
                    446:  *
                    447:  *      Load defined names into combo box
                    448:  */
                    449: void NameDlg_LoadComboBox(LPOUTLINENAMETABLE lpOutlineNameTable,HWND hCombo)
                    450: {
                    451:     LPOUTLINENAME lpOutlineName;
                    452:     int i, nIndex;
                    453:     int nCount;
                    454: 
                    455:     nCount=OutlineNameTable_GetCount((LPOUTLINENAMETABLE)lpOutlineNameTable);
                    456:     if(!nCount) return;
                    457: 
                    458:     SendMessage(hCombo,WM_SETREDRAW,(WPARAM)FALSE,0L);
                    459:     for(i=0; i<nCount; i++) {
                    460:         lpOutlineName=OutlineNameTable_GetName((LPOUTLINENAMETABLE)lpOutlineNameTable,i);
                    461:         nIndex = (int)SendMessage(
                    462:                 hCombo,
                    463:                 CB_ADDSTRING,
                    464:                 0,
                    465:                 (LPARAM)(LPCSTR)lpOutlineName->m_szName
                    466:         );
                    467:         SendMessage(hCombo,CB_SETITEMDATA,(WPARAM)nIndex,(LPARAM)lpOutlineName);
                    468:     }
                    469:     SendMessage(hCombo,WM_SETREDRAW,(WPARAM)TRUE,0L);
                    470: }
                    471: 
                    472: 
                    473: /* NameDlg_LoadListBox
                    474:  * -------------------
                    475:  * 
                    476:  *      Load defined names into list box
                    477:  */
                    478: void NameDlg_LoadListBox(LPOUTLINENAMETABLE lpOutlineNameTable,HWND hListBox)
                    479: {
                    480:     int i;
                    481:     int nCount;
                    482:     int nIndex;
                    483:     LPOUTLINENAME lpOutlineName;
                    484: 
                    485:     nCount=OutlineNameTable_GetCount((LPOUTLINENAMETABLE)lpOutlineNameTable);
                    486: 
                    487:     SendMessage(hListBox,WM_SETREDRAW,(WPARAM)FALSE,0L);
                    488:     for(i=0; i<nCount; i++) {
                    489:         lpOutlineName=OutlineNameTable_GetName((LPOUTLINENAMETABLE)lpOutlineNameTable,i);
                    490:         nIndex = (int)SendMessage(
                    491:                 hListBox,
                    492:                 LB_ADDSTRING,
                    493:                 0,
                    494:                 (LPARAM)(LPCSTR)lpOutlineName->m_szName
                    495:         );
                    496:         SendMessage(hListBox,LB_SETITEMDATA,(WPARAM)nIndex,(LPARAM)lpOutlineName);
                    497:     }
                    498:     SendMessage(hListBox,WM_SETREDRAW,(WPARAM)TRUE,0L);
                    499: }
                    500: 
                    501: 
                    502: /* NameDlg_AddName
                    503:  * ---------------
                    504:  *
                    505:  *      Add a name to the name table corresponding to the name dialog 
                    506:  *      combo box.
                    507:  */
                    508: void NameDlg_AddName(HWND hCombo, LPOUTLINEDOC lpOutlineDoc, LPSTR lpszName, LPLINERANGE lplrSel)
                    509: {
                    510:     LPOUTLINEAPP lpOutlineApp = (LPOUTLINEAPP)g_lpApp;
                    511:     LPOUTLINENAME lpOutlineName;
                    512: 
                    513:     lpOutlineName = OutlineApp_CreateName(lpOutlineApp);
                    514:                         
                    515:     if (lpOutlineName) {
                    516:         lstrcpy(lpOutlineName->m_szName, lpszName);
                    517:         lpOutlineName->m_nStartLine = lplrSel->m_nStartLine;
                    518:         lpOutlineName->m_nEndLine = lplrSel->m_nEndLine;
                    519:         OutlineDoc_AddName(lpOutlineDoc, lpOutlineName);
                    520:     } else {
                    521:         // REVIEW: do we need error message here?
                    522:     }
                    523: }
                    524: 
                    525: 
                    526: /* NameDlg_UpdateName
                    527:  * ------------------
                    528:  *
                    529:  *      Update a name in the name table corresponding to a name in
                    530:  *      the name dialog combo box.
                    531:  */
                    532: void NameDlg_UpdateName(HWND hCombo, LPOUTLINEDOC lpOutlineDoc, int nIndex, LPSTR lpszName, LPLINERANGE lplrSel)
                    533: {
                    534:     LPOUTLINENAME lpOutlineName;
                    535: 
                    536:     lpOutlineName = (LPOUTLINENAME)SendMessage(
                    537:             hCombo, 
                    538:             CB_GETITEMDATA,
                    539:             (WPARAM)nIndex,
                    540:             0L
                    541:     );
                    542: 
                    543:     OutlineName_SetName(lpOutlineName, lpszName);
                    544:     OutlineName_SetSel(lpOutlineName, lplrSel, TRUE /* name modified */);
                    545:     OutlineDoc_SetModified(lpOutlineDoc, TRUE, FALSE, FALSE);
                    546: }
                    547: 
                    548: 
                    549: /* NameDlg_DeleteName
                    550:  * ------------------
                    551:  *
                    552:  *      Delete a name from the name dialog combo box and corresponding 
                    553:  *      name table.
                    554:  */
                    555: void NameDlg_DeleteName(HWND hCombo, LPOUTLINEDOC lpOutlineDoc, UINT nIndex)
                    556: {
                    557:     SendMessage(hCombo,CB_DELETESTRING,(WPARAM)nIndex,0L);
                    558:     OutlineDoc_DeleteName(lpOutlineDoc, nIndex);
                    559: }
                    560: 
                    561: /* PlaceBitmap
                    562:  * -----------
                    563:  * 
                    564:  *      Places a bitmap centered in the specified control in the dialog on the
                    565:  *      specified DC.
                    566:  *
                    567:  */
                    568:  
                    569: PlaceBitmap(HWND hDlg, int control, HDC hDC, HBITMAP hBitmap) 
                    570: {
                    571:     BITMAP bm;
                    572:     HDC hdcmem;
                    573:     HBITMAP hbmOld;
                    574:     RECT rcControl;     // Rect of dialog control
                    575:     int width, height;
                    576:       
                    577:     GetObject(hBitmap, sizeof(BITMAP), &bm);
                    578:     
                    579:     hdcmem= CreateCompatibleDC(hDC);
                    580:     hbmOld = SelectObject(hdcmem, hBitmap);
                    581:  
                    582:     // Get rect of control in screen coords, and translate to our dialog
                    583:     // box's coordinates
                    584:     GetWindowRect(GetDlgItem(hDlg, control), &rcControl);
                    585:     MapWindowPoints(NULL, hDlg, (LPPOINT)&rcControl, 2);
                    586:     
                    587:     width  = rcControl.right - rcControl.left;
                    588:     height = rcControl.bottom - rcControl.top;
                    589:     
                    590:     BitBlt(hDC, rcControl.left + (width - bm.bmWidth) / 2,
                    591:                 rcControl.top + (height - bm.bmHeight) /2,
                    592:                 bm.bmWidth, bm.bmHeight,
                    593:                 hdcmem, 0, 0, SRCCOPY);
                    594:         
                    595:     SelectObject(hdcmem, hbmOld);            
                    596:     DeleteDC(hdcmem);
                    597:     return 1;
                    598: }
                    599:     
                    600: 
                    601: 
                    602: /* AboutDlgProc
                    603:  * ------------
                    604:  *
                    605:  *      Dialog procedure for the About function
                    606:  */
                    607: BOOL CALLBACK EXPORT AboutDlgProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
                    608: {
                    609:     int  narrVersion[2];
                    610:     static HBITMAP hbmLogo;
                    611:     
                    612:     switch(Message) {
                    613:         
                    614:         case WM_INITDIALOG:
                    615:             // get version number of app
                    616:             wsprintf(g_szBuf, "About %s", (LPCSTR)APPNAME);
                    617:             SetWindowText(hDlg, (LPCSTR)g_szBuf);
                    618:             OutlineApp_GetAppVersionNo(g_lpApp, narrVersion);
                    619:             wsprintf(g_szBuf, "%s version %d.%d", (LPSTR) APPDESC, 
                    620:                 narrVersion[0], narrVersion[1]);
                    621:             SetDlgItemText(hDlg, IDD_APPTEXT, (LPCSTR)g_szBuf);
                    622:             
                    623:             // Load bitmap for displaying later
                    624:             hbmLogo = LoadBitmap(g_lpApp->m_hInst, "LogoBitmap");
                    625:             TraceDebug(hDlg, IDD_BITMAPLOCATION);
                    626:             ShowWindow(GetDlgItem(hDlg, IDD_BITMAPLOCATION), SW_HIDE);
                    627:             break;
                    628:             
                    629:         case WM_PAINT:
                    630:             {
                    631:             PAINTSTRUCT ps;
                    632:             BeginPaint(hDlg, &ps);
                    633:             
                    634:             // Display bitmap in IDD_BITMAPLOCATION control area
                    635:             PlaceBitmap(hDlg, IDD_BITMAPLOCATION, ps.hdc, hbmLogo);
                    636:             EndPaint(hDlg, &ps);
                    637:             }
                    638:             break;
                    639:             
                    640:         case WM_CLOSE :
                    641:             PostMessage(hDlg, WM_COMMAND, IDOK, 0L);
                    642:             break;
                    643:         
                    644:         case WM_COMMAND :
                    645:             switch(wParam) {
                    646:                 case IDOK:
                    647:                     if (hbmLogo) DeleteObject(hbmLogo);
                    648:                     EndDialog(hDlg,0);
                    649:                     break;
                    650:             }
                    651:             break;
                    652:             
                    653:         default :
                    654:             return FALSE;
                    655:             
                    656:     }
                    657:     return TRUE;
                    658: }
                    659: 
                    660: 
                    661: #if defined( OLE_CNTR )
                    662: 
                    663: /* ProcessError
                    664:  * ------------
                    665:  *
                    666:  *     Popup up appropriate message according to the error and/or take action
                    667:  * specified button pressed by the user.
                    668:  */
                    669: void ProcessError(HRESULT hrErr, LPCONTAINERLINE lpContainerLine, BOOL fAction)
                    670: {
                    671:        LPOUTLINEDOC    lpOutlineDoc = (LPOUTLINEDOC)lpContainerLine->m_lpDoc;
                    672:        HWND                    hwndParent = OutlineDoc_GetWindow(lpOutlineDoc);
                    673:     SCODE           sc = GetScode(hrErr);
                    674: 
                    675:     OleDbgOutHResult("ProcessError", hrErr);
                    676: 
                    677:        if ((sc >= MK_E_FIRST) && (sc <= MK_E_LAST))
                    678:                goto LinkSourceUnavailable;
                    679:        if (sc == OLE_E_CANT_BINDTOSOURCE)
                    680:                goto LinkSourceUnavailable;
                    681:        if (sc == STG_E_PATHNOTFOUND)
                    682:                goto LinkSourceUnavailable;
                    683:        if (sc == REGDB_E_CLASSNOTREG)
                    684:                goto ServerNotReg;
                    685:        if (sc == OLE_E_STATIC)
                    686:                goto ServerNotReg;  // user dblclk'ed a static object w/ no svr reg'd
                    687:        if (sc == OLE_E_CLASSDIFF)
                    688:         goto LinkTypeChanged;
                    689:        if (sc == CO_E_APPDIDNTREG)
                    690:         goto ServerNotFound;
                    691:        if (sc == CO_E_APPNOTFOUND)
                    692:                goto ServerNotFound;
                    693:        
                    694:        if (ContainerLine_IsOleLink(lpContainerLine))
                    695:                goto LinkSourceUnavailable;
                    696:        else
                    697:                goto ServerNotFound;
                    698: 
                    699: 
                    700: /*************************************************************************
                    701: ** Error handling routines                                              **
                    702: *************************************************************************/
                    703: LinkSourceUnavailable:
                    704:        if (ID_PU_LINKS == OleUIPromptUser(
                    705:                                IDD_LINKSOURCEUNAVAILABLE, 
                    706:                                hwndParent,
                    707:                                (LPSTR)APPNAME)) {
                    708:                if (fAction) {
                    709:                        ContainerDoc_EditLinksCommand(lpContainerLine->m_lpDoc);
                    710:                }
                    711:        }
                    712:        return;
                    713: 
                    714: ServerNotReg:
                    715: {
                    716:        LPSTR lpszUserType = NULL;
                    717:        CLIPFORMAT  cfFormat;           // not used
                    718:        
                    719:        hrErr = ReadFmtUserTypeStg(
                    720:                        lpContainerLine->m_lpStg, &cfFormat, &lpszUserType);
                    721:        
                    722:        if (ID_PU_CONVERT == OleUIPromptUser(
                    723:                        IDD_SERVERNOTREG, 
                    724:                        hwndParent,
                    725:                        (LPSTR)APPNAME,
                    726:                        (hrErr == NOERROR) ? lpszUserType : (LPSTR)"Object")) {
                    727:                if (fAction) {
                    728:                        ContainerDoc_ConvertCommand(
                    729:                                        lpContainerLine->m_lpDoc, 
                    730:                                        TRUE            // fMustActivate
                    731:                        );
                    732:                }
                    733:        }
                    734:        
                    735:        if (lpszUserType)
                    736:                OleStdFreeString(lpszUserType, NULL);
                    737:        
                    738:        return;
                    739: }
                    740: 
                    741: 
                    742: LinkTypeChanged:
                    743:        OleUIPromptUser(
                    744:                        IDD_LINKTYPECHANGED, 
                    745:                        hwndParent,
                    746:                        (LPSTR)APPNAME);
                    747:        return;
                    748: 
                    749:        
                    750: ServerNotFound:
                    751:        OleUIPromptUser(
                    752:                        IDD_SERVERNOTFOUND, 
                    753:                        hwndParent,
                    754:                        (LPSTR)APPNAME);
                    755:        return;
                    756: 
                    757: // OutOfMemory:
                    758:        OleUIPromptUser(
                    759:                        IDD_OUTOFMEMORY, 
                    760:                        hwndParent,
                    761:                        (LPSTR)APPNAME);
                    762:        return;
                    763: 
                    764: }
                    765: 
                    766: 
                    767: #endif

unix.superglobalmegacorp.com

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