|
|
1.1 ! root 1: /************************************************************************* ! 2: ** ! 3: ** OLE 2 Sample Code ! 4: ** ! 5: ** outlapp.c ! 6: ** ! 7: ** This file contains OutlineApp functions. ! 8: ** ! 9: ** (c) Copyright Microsoft Corp. 1992 - 1993 All Rights Reserved ! 10: ** ! 11: *************************************************************************/ ! 12: ! 13: #include "outline.h" ! 14: ! 15: #if defined( USE_STATUSBAR ) ! 16: #include "status.h" ! 17: #endif ! 18: ! 19: #if !defined( WIN32 ) ! 20: #include <print.h> ! 21: #endif ! 22: ! 23: OLEDBGDATA ! 24: ! 25: extern LPOUTLINEAPP g_lpApp; ! 26: extern RECT g_rectNull; ! 27: ! 28: // REVIEW: should use string resource for messages ! 29: char ErrMsgClass[] = "Can't register window classes!"; ! 30: char ErrMsgFrame[] = "Can't create Frame Window!"; ! 31: char ErrMsgPrinting[] = "Can't access printer!"; ! 32: ! 33: ! 34: /* OutlineApp_InitApplication ! 35: ** -------------------------- ! 36: ** Sets up the class data structures and does a one-time ! 37: ** initialization of the app by registering the window classes. ! 38: ** Returns TRUE if initialization is successful ! 39: ** FALSE otherwise ! 40: */ ! 41: ! 42: BOOL OutlineApp_InitApplication(LPOUTLINEAPP lpOutlineApp, HINSTANCE hInst) ! 43: { ! 44: WNDCLASS wndclass; ! 45: ! 46: // REVIEW: should load msg strings from string resource ! 47: ! 48: /* Register the app frame class */ ! 49: wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_BYTEALIGNWINDOW; ! 50: wndclass.lpfnWndProc = AppWndProc; ! 51: /* Extra storage for Class and Window objects */ ! 52: wndclass.cbClsExtra = 0; ! 53: wndclass.cbWndExtra = sizeof(LPOUTLINEAPP); /* to store lpApp */ ! 54: wndclass.hInstance = hInst; ! 55: wndclass.hIcon = LoadIcon(hInst, APPICON); ! 56: wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); ! 57: /* Create brush for erasing background */ ! 58: wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); ! 59: wndclass.lpszMenuName = APPMENU; /* Menu Name is App Name */ ! 60: wndclass.lpszClassName = APPWNDCLASS; /* Class Name is App Name */ ! 61: ! 62: if(! RegisterClass(&wndclass)) { ! 63: OutlineApp_ErrorMessage(lpOutlineApp, ErrMsgFrame); ! 64: return FALSE; ! 65: } ! 66: ! 67: /* Register the document window class */ ! 68: wndclass.style = CS_BYTEALIGNWINDOW; ! 69: wndclass.lpfnWndProc = DocWndProc; ! 70: wndclass.hIcon = NULL; ! 71: wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); ! 72: wndclass.lpszMenuName = NULL; ! 73: wndclass.lpszClassName = DOCWNDCLASS; ! 74: wndclass.cbWndExtra = sizeof(LPOUTLINEDOC); /* to store lpDoc */ ! 75: if(! RegisterClass(&wndclass)) { ! 76: OutlineApp_ErrorMessage(lpOutlineApp, ErrMsgClass); ! 77: return FALSE; ! 78: } ! 79: ! 80: #if defined( USE_STATUSBAR ) ! 81: if (! RegisterStatusClass(hInst)) ! 82: return FALSE; ! 83: #endif ! 84: ! 85: #if defined( USE_FRAMETOOLS ) ! 86: if (! FrameToolsRegisterClass(hInst)) { ! 87: return FALSE; ! 88: } ! 89: #endif ! 90: ! 91: #if defined( INPLACE_SVR ) ! 92: // We should only register the hatch window class ! 93: // in the UI Library once per application. ! 94: RegisterHatchWindowClass(hInst); ! 95: ! 96: #endif ! 97: ! 98: return TRUE; ! 99: } ! 100: ! 101: ! 102: /* OutlineApp_InitInstance ! 103: * ----------------------- ! 104: * ! 105: * Performs a per-instance initialization of app. ! 106: * This method creates the frame window. ! 107: * ! 108: * RETURNS : TRUE - If initialization was successful. ! 109: * FALSE - otherwise. ! 110: */ ! 111: ! 112: BOOL OutlineApp_InitInstance(LPOUTLINEAPP lpOutlineApp, HINSTANCE hInst, int nCmdShow) ! 113: { ! 114: lpOutlineApp->m_hInst = hInst; ! 115: ! 116: /* create application's Frame window */ ! 117: lpOutlineApp->m_hWndApp = CreateWindow( ! 118: APPWNDCLASS, /* Window class name */ ! 119: APPNAME, /* initial Window title */ ! 120: WS_OVERLAPPEDWINDOW| ! 121: WS_CLIPCHILDREN, ! 122: CW_USEDEFAULT, 0, /* Use default X, Y */ ! 123: CW_USEDEFAULT, 0, /* Use default X, Y */ ! 124: HWND_DESKTOP, /* Parent window's handle */ ! 125: NULL, /* Default to Class Menu */ ! 126: hInst, /* Instance of window */ ! 127: NULL /* Create struct for WM_CREATE */ ! 128: ); ! 129: ! 130: if(! lpOutlineApp->m_hWndApp) { ! 131: // REVIEW: should load string from string resource ! 132: OutlineApp_ErrorMessage(lpOutlineApp, ErrMsgFrame); ! 133: return FALSE; ! 134: } ! 135: ! 136: SetWindowLong(lpOutlineApp->m_hWndApp, 0, (LONG) lpOutlineApp); ! 137: ! 138: /* defer creating the user's SDI document until we parse the cmd line. */ ! 139: lpOutlineApp->m_lpDoc = NULL; ! 140: ! 141: /* Initialize clipboard. ! 142: */ ! 143: lpOutlineApp->m_lpClipboardDoc = NULL; ! 144: if(!(lpOutlineApp->m_cfOutline = RegisterClipboardFormat(OUTLINEDOCFORMAT))) { ! 145: // REVIEW: should load string from string resource ! 146: OutlineApp_ErrorMessage(lpOutlineApp, "Can't register clipboard format!"); ! 147: return FALSE; ! 148: } ! 149: ! 150: /* init the standard font to be used for drawing/printing text ! 151: * request a Roman style True Type font of the desired size ! 152: */ ! 153: lpOutlineApp->m_hStdFont = CreateFont( ! 154: -DEFFONTSIZE, ! 155: 0,0,0,0,0,0,0,0, ! 156: OUT_TT_PRECIS, // use TrueType ! 157: CLIP_DEFAULT_PRECIS, ! 158: DEFAULT_QUALITY, ! 159: VARIABLE_PITCH | FF_ROMAN, ! 160: DEFFONTFACE ! 161: ); ! 162: ! 163: // Load special cursor for selection of Lines in ListBox. ! 164: lpOutlineApp->m_hcursorSelCur = LoadCursor ( hInst, "SelCur" ); ! 165: ! 166: /* init the Print Dialog structure */ ! 167: _fmemset((LPVOID)&lpOutlineApp->m_PrintDlg,0,sizeof(PRINTDLG)); ! 168: lpOutlineApp->m_PrintDlg.lStructSize = sizeof(PRINTDLG); ! 169: lpOutlineApp->m_PrintDlg.hDevMode = NULL; ! 170: lpOutlineApp->m_PrintDlg.hDevNames = NULL; ! 171: lpOutlineApp->m_PrintDlg.Flags = PD_RETURNDC | PD_NOSELECTION | PD_NOPAGENUMS | ! 172: PD_HIDEPRINTTOFILE; ! 173: lpOutlineApp->m_PrintDlg.nCopies = 1; ! 174: lpOutlineApp->m_PrintDlg.hwndOwner = lpOutlineApp->m_hWndApp; ! 175: ! 176: #if defined( USE_STATUSBAR ) ! 177: lpOutlineApp->m_hWndStatusBar = CreateStatusWindow(lpOutlineApp->m_hWndApp, hInst); ! 178: if (! lpOutlineApp->m_hWndStatusBar) ! 179: return FALSE; ! 180: ! 181: lpOutlineApp->m_hMenuApp = GetMenu(lpOutlineApp->m_hWndApp); ! 182: ! 183: /* setup status messages for the application menus */ ! 184: { ! 185: HMENU hMenuFile = GetSubMenu(lpOutlineApp->m_hMenuApp, 0); ! 186: HMENU hMenuEdit = GetSubMenu(lpOutlineApp->m_hMenuApp, 1); ! 187: HMENU hMenuLine = GetSubMenu(lpOutlineApp->m_hMenuApp, 2); ! 188: HMENU hMenuName = GetSubMenu(lpOutlineApp->m_hMenuApp, 3); ! 189: HMENU hMenuHelp = GetSubMenu(lpOutlineApp->m_hMenuApp, 4); ! 190: HMENU hMenuSys = GetSystemMenu(lpOutlineApp->m_hWndApp, FALSE); ! 191: ! 192: AssignPopupMessage(hMenuFile, "Create, open, save, print outlines or quit application"); ! 193: AssignPopupMessage(hMenuEdit, "Cut, copy, paste or clear selection"); ! 194: AssignPopupMessage(hMenuLine, "Create, edit, and indent lines"); ! 195: AssignPopupMessage(hMenuName, "Create, edit, delete and goto names"); ! 196: AssignPopupMessage(hMenuHelp, "Get help on using the application"); ! 197: AssignPopupMessage(hMenuSys,"Move, size or close application window"); ! 198: } ! 199: #endif ! 200: ! 201: #if defined ( USE_FRAMETOOLS ) || defined ( INPLACE_CNTR ) ! 202: lpOutlineApp->m_FrameToolWidths = g_rectNull; ! 203: #endif // USE_FRAMETOOLS || INPLACE_CNTR ! 204: ! 205: #if defined( USE_FRAMETOOLS ) ! 206: if (! FrameTools_Init(&lpOutlineApp->m_frametools, ! 207: lpOutlineApp->m_hWndApp, lpOutlineApp->m_hInst)) ! 208: return FALSE; ! 209: #endif ! 210: ! 211: #if defined( OLE_VERSION ) ! 212: ! 213: /* OLE2NOTE: perform initialization required for OLE */ ! 214: if (! OleApp_InitInstance((LPOLEAPP)lpOutlineApp, hInst, nCmdShow)) ! 215: return FALSE; ! 216: #else ! 217: /* OLE2NOTE: Although no OLE call is made in the base outline, ! 218: ** OLE memory allocator is used and thus CoInitialize() neeed to ! 219: ** be called ! 220: */ ! 221: { ! 222: HRESULT hrErr; ! 223: ! 224: hrErr = CoInitialize(NULL); ! 225: if (hrErr != NOERROR) { ! 226: OutlineApp_ErrorMessage(lpOutlineApp, ! 227: "CoInitialize initialization failed!"); ! 228: return FALSE; ! 229: } ! 230: } ! 231: #endif ! 232: ! 233: return TRUE; ! 234: } ! 235: ! 236: ! 237: /* OutlineApp_ParseCmdLine ! 238: * ----------------------- ! 239: * ! 240: * Parse the command line for any execution flags/arguments. ! 241: */ ! 242: BOOL OutlineApp_ParseCmdLine(LPOUTLINEAPP lpOutlineApp, LPSTR lpszCmdLine, int nCmdShow) ! 243: { ! 244: ! 245: #if defined( OLE_VERSION ) ! 246: // Call OLE version of this function instead ! 247: return OleApp_ParseCmdLine((LPOLEAPP)lpOutlineApp,lpszCmdLine,nCmdShow); ! 248: ! 249: #else ! 250: ! 251: BOOL fStatus = TRUE; ! 252: char szFileName[256]; /* buffer for filename in command line */ ! 253: ! 254: szFileName[0] = '\0'; ! 255: ParseCmdLine(lpszCmdLine, NULL, (LPSTR)szFileName); ! 256: ! 257: if(*szFileName) { ! 258: // allocate a new document ! 259: lpOutlineApp->m_lpDoc = OutlineApp_CreateDoc(lpOutlineApp, FALSE); ! 260: if (! lpOutlineApp->m_lpDoc) goto error; ! 261: ! 262: // open the specified file ! 263: if (! OutlineDoc_LoadFromFile(lpOutlineApp->m_lpDoc, szFileName)) ! 264: goto error; ! 265: } else { ! 266: // create a new document ! 267: lpOutlineApp->m_lpDoc = OutlineApp_CreateDoc(lpOutlineApp, FALSE); ! 268: if (! lpOutlineApp->m_lpDoc) goto error; ! 269: ! 270: // set the doc to an (Untitled) doc. ! 271: if (! OutlineDoc_InitNewFile(lpOutlineApp->m_lpDoc)) ! 272: goto error; ! 273: } ! 274: ! 275: // position and size the new doc window ! 276: OutlineApp_ResizeWindows(lpOutlineApp); ! 277: OutlineDoc_ShowWindow(lpOutlineApp->m_lpDoc); ! 278: ! 279: // show main app window ! 280: ShowWindow(lpOutlineApp->m_hWndApp, nCmdShow); ! 281: UpdateWindow(lpOutlineApp->m_hWndApp); ! 282: ! 283: return TRUE; ! 284: ! 285: error: ! 286: // REVIEW: should load string from string resource ! 287: OutlineApp_ErrorMessage(lpOutlineApp, "Could not create new document"); ! 288: ! 289: if (lpOutlineApp->m_lpDoc) { ! 290: OutlineDoc_Destroy(lpOutlineApp->m_lpDoc); ! 291: lpOutlineApp->m_lpDoc = NULL; ! 292: } ! 293: ! 294: return FALSE; ! 295: ! 296: #endif ! 297: } ! 298: ! 299: ! 300: /* OutlineApp_InitMenu ! 301: * ------------------- ! 302: * ! 303: * Enable or Disable menu items depending on the state of ! 304: * the appliation ! 305: */ ! 306: void OutlineApp_InitMenu(LPOUTLINEAPP lpOutlineApp, LPOUTLINEDOC lpOutlineDoc, HMENU hMenu) ! 307: { ! 308: WORD status; ! 309: static UINT uCurrentZoom = (UINT)-1; ! 310: static UINT uCurrentMargin = (UINT)-1; ! 311: static UINT uBBState = (UINT)-1; ! 312: static UINT uFBState = (UINT)-1; ! 313: ! 314: if (!lpOutlineApp || !lpOutlineDoc || !hMenu) ! 315: return; ! 316: ! 317: EnableMenuItem(lpOutlineApp->m_hMenuApp, IDM_E_UNDO, MF_GRAYED); ! 318: ! 319: status = (WORD)(OutlineDoc_GetLineCount(lpOutlineDoc) ? MF_ENABLED : MF_GRAYED); ! 320: ! 321: EnableMenuItem(lpOutlineApp->m_hMenuApp, IDM_E_CUT ,status); ! 322: EnableMenuItem(lpOutlineApp->m_hMenuApp, IDM_E_COPY ,status); ! 323: EnableMenuItem(lpOutlineApp->m_hMenuApp, IDM_E_CLEAR ,status); ! 324: EnableMenuItem(lpOutlineApp->m_hMenuApp, IDM_E_SELECTALL ,status); ! 325: ! 326: EnableMenuItem(lpOutlineApp->m_hMenuApp, IDM_L_EDITLINE ,status); ! 327: EnableMenuItem(lpOutlineApp->m_hMenuApp, IDM_L_INDENTLINE ,status); ! 328: EnableMenuItem(lpOutlineApp->m_hMenuApp, IDM_L_UNINDENTLINE ,status); ! 329: EnableMenuItem(lpOutlineApp->m_hMenuApp, IDM_L_SETLINEHEIGHT ,status); ! 330: ! 331: EnableMenuItem(lpOutlineApp->m_hMenuApp, IDM_N_DEFINENAME ,status); ! 332: ! 333: status = (WORD)(OutlineDoc_GetNameCount(lpOutlineDoc) ? MF_ENABLED : MF_GRAYED); ! 334: ! 335: EnableMenuItem(lpOutlineApp->m_hMenuApp, IDM_N_GOTONAME, status); ! 336: ! 337: if (uCurrentZoom != (UINT)-1) ! 338: CheckMenuItem(lpOutlineApp->m_hMenuApp, uCurrentZoom, MF_UNCHECKED); ! 339: uCurrentZoom = OutlineDoc_GetCurrentZoomMenuCheck(lpOutlineDoc); ! 340: CheckMenuItem(lpOutlineApp->m_hMenuApp, uCurrentZoom, MF_CHECKED); ! 341: ! 342: if (uCurrentMargin != (UINT)-1) ! 343: CheckMenuItem(lpOutlineApp->m_hMenuApp, uCurrentMargin, MF_UNCHECKED); ! 344: uCurrentMargin = OutlineDoc_GetCurrentMarginMenuCheck(lpOutlineDoc); ! 345: CheckMenuItem(lpOutlineApp->m_hMenuApp, uCurrentMargin, MF_CHECKED); ! 346: ! 347: #if defined( USE_FRAMETOOLS ) ! 348: if (uBBState != (UINT)-1) ! 349: CheckMenuItem(lpOutlineApp->m_hMenuApp, uBBState, MF_UNCHECKED); ! 350: if (lpOutlineDoc->m_lpFrameTools) { ! 351: switch (FrameTools_BB_GetState(lpOutlineDoc->m_lpFrameTools)) { ! 352: case BARSTATE_TOP: ! 353: uBBState = IDM_O_BB_TOP; ! 354: break; ! 355: case BARSTATE_BOTTOM: ! 356: uBBState = IDM_O_BB_BOTTOM; ! 357: break; ! 358: case BARSTATE_POPUP: ! 359: uBBState = IDM_O_BB_POPUP; ! 360: break; ! 361: case BARSTATE_HIDE: ! 362: uBBState = IDM_O_BB_HIDE; ! 363: break; ! 364: } ! 365: CheckMenuItem(lpOutlineApp->m_hMenuApp, uBBState, MF_CHECKED); ! 366: } ! 367: ! 368: if (uFBState != (UINT)-1) ! 369: CheckMenuItem(lpOutlineApp->m_hMenuApp, uFBState, MF_UNCHECKED); ! 370: if (lpOutlineDoc->m_lpFrameTools) { ! 371: switch (FrameTools_FB_GetState(lpOutlineDoc->m_lpFrameTools)) { ! 372: case BARSTATE_TOP: ! 373: uFBState = IDM_O_FB_TOP; ! 374: break; ! 375: case BARSTATE_BOTTOM: ! 376: uFBState = IDM_O_FB_BOTTOM; ! 377: break; ! 378: case BARSTATE_POPUP: ! 379: uFBState = IDM_O_FB_POPUP; ! 380: break; ! 381: } ! 382: CheckMenuItem(lpOutlineApp->m_hMenuApp, uFBState, MF_CHECKED); ! 383: } ! 384: #endif // USE_FRAMETOOLS ! 385: ! 386: #if defined( OLE_VERSION ) ! 387: /* OLE2NOTE: perform OLE specific menu initialization. ! 388: ** the OLE versions use the OleGetClipboard mechanism for ! 389: ** clipboard handling. thus, they determine if the Paste and ! 390: ** PasteSpecial commands should be enabled in an OLE specific ! 391: ** manner. ! 392: ** (Container only) build the OLE object verb menu if necessary. ! 393: */ ! 394: OleApp_InitMenu( ! 395: (LPOLEAPP)lpOutlineApp, ! 396: (LPOLEDOC)lpOutlineDoc, ! 397: lpOutlineApp->m_hMenuApp ! 398: ); ! 399: ! 400: /* OLE2NOTE: To avoid the overhead of initializing the Edit menu, ! 401: ** we do it only when it is popped up. Thus we just set a flag ! 402: ** in the OleDoc saying that the Edit menu needs to be updated ! 403: ** but we don't do it immediately ! 404: */ ! 405: OleDoc_SetUpdateEditMenuFlag((LPOLEDOC)lpOutlineDoc, TRUE); ! 406: ! 407: #else ! 408: // Base Outline version uses standard Windows clipboard handling ! 409: if(IsClipboardFormatAvailable(lpOutlineApp->m_cfOutline) || ! 410: IsClipboardFormatAvailable(CF_TEXT)) ! 411: status = MF_ENABLED; ! 412: else ! 413: status = MF_GRAYED; ! 414: EnableMenuItem(lpOutlineApp->m_hMenuApp, IDM_E_PASTE, status); ! 415: ! 416: #endif ! 417: ! 418: #if defined( USE_FRAMETOOLS ) ! 419: if (! OutlineDoc_IsEditFocusInFormulaBar(lpOutlineDoc)) { ! 420: EnableMenuItem(lpOutlineApp->m_hMenuApp, IDM_L_ADDLINE, MF_GRAYED); ! 421: EnableMenuItem(lpOutlineApp->m_hMenuApp, IDM_L_EDITLINE, MF_GRAYED); ! 422: } ! 423: else ! 424: EnableMenuItem(lpOutlineApp->m_hMenuApp, IDM_L_ADDLINE, MF_ENABLED); ! 425: ! 426: #endif // USE_FRAMETOOLS ! 427: ! 428: } ! 429: ! 430: ! 431: /* OutlineApp_GetWindow ! 432: * -------------------- ! 433: * ! 434: * Get the window handle of the application frame. ! 435: */ ! 436: HWND OutlineApp_GetWindow(LPOUTLINEAPP lpOutlineApp) ! 437: { ! 438: if (!lpOutlineApp) ! 439: return NULL; ! 440: ! 441: return lpOutlineApp->m_hWndApp; ! 442: } ! 443: ! 444: ! 445: /* OutlineApp_GetFrameWindow ! 446: ** ------------------------- ! 447: ** Gets the current frame window to use as a parent to any dialogs ! 448: ** this app uses. ! 449: ** ! 450: ** OLE2NOTE: normally this is simply the main hWnd of the app. but, ! 451: ** if the app is currently supporting an in-place server document, ! 452: ** then the frame window of the top in-place container must be used. ! 453: */ ! 454: HWND OutlineApp_GetFrameWindow(LPOUTLINEAPP lpOutlineApp) ! 455: { ! 456: HWND hWndApp = OutlineApp_GetWindow(lpOutlineApp); ! 457: ! 458: #if defined( INPLACE_SVR ) ! 459: LPSERVERDOC lpServerDoc = ! 460: (LPSERVERDOC)OutlineApp_GetActiveDoc(lpOutlineApp); ! 461: if (lpServerDoc && lpServerDoc->m_fUIActive) ! 462: return lpServerDoc->m_lpIPData->frameInfo.hwndFrame; ! 463: #endif ! 464: ! 465: return hWndApp; ! 466: } ! 467: ! 468: ! 469: /* OutlineApp_GetInstance ! 470: * ---------------------- ! 471: * ! 472: * Get the process instance of the application. ! 473: */ ! 474: HINSTANCE OutlineApp_GetInstance(LPOUTLINEAPP lpOutlineApp) ! 475: { ! 476: if (!lpOutlineApp) ! 477: return NULL; ! 478: ! 479: return lpOutlineApp->m_hInst; ! 480: } ! 481: ! 482: ! 483: /* OutlineApp_CreateDoc ! 484: * -------------------- ! 485: * ! 486: * Allocate a new document of the appropriate type. ! 487: * OutlineApp --> creates OutlineDoc type documents ! 488: * ! 489: * Returns lpOutlineDoc for successful, NULL if error. ! 490: */ ! 491: LPOUTLINEDOC OutlineApp_CreateDoc( ! 492: LPOUTLINEAPP lpOutlineApp, ! 493: BOOL fDataTransferDoc ! 494: ) ! 495: { ! 496: LPOUTLINEDOC lpOutlineDoc; ! 497: ! 498: OLEDBG_BEGIN3("OutlineApp_CreateDoc\r\n") ! 499: ! 500: #if defined( OLE_SERVER ) ! 501: lpOutlineDoc = (LPOUTLINEDOC)New((DWORD)sizeof(SERVERDOC)); ! 502: #elif defined( OLE_CNTR ) ! 503: lpOutlineDoc = (LPOUTLINEDOC)New((DWORD)sizeof(CONTAINERDOC)); ! 504: #else ! 505: lpOutlineDoc = (LPOUTLINEDOC)New((DWORD)sizeof(OUTLINEDOC)); ! 506: #endif ! 507: ! 508: if (! OleDbgVerifySz(lpOutlineDoc != NULL, "Error allocating OutlineDoc")) ! 509: return NULL; ! 510: ! 511: // initialize new document ! 512: if (! OutlineDoc_Init(lpOutlineDoc, fDataTransferDoc)) ! 513: goto error; ! 514: ! 515: OLEDBG_END3 ! 516: return lpOutlineDoc; ! 517: ! 518: error: ! 519: if (lpOutlineDoc) ! 520: Delete(lpOutlineDoc); ! 521: ! 522: OLEDBG_END3 ! 523: return NULL; ! 524: } ! 525: ! 526: ! 527: /* OutlineApp_CreateName ! 528: * --------------------- ! 529: * ! 530: * Allocate a new Name of the appropriate type. ! 531: * OutlineApp --> creates standard OutlineName type names. ! 532: * ServerApp --> creates enhanced SeverName type names. ! 533: * ! 534: * Returns lpOutlineName for successful, NULL if error. ! 535: */ ! 536: LPOUTLINENAME OutlineApp_CreateName(LPOUTLINEAPP lpOutlineApp) ! 537: { ! 538: LPOUTLINENAME lpOutlineName; ! 539: ! 540: #if defined( OLE_SERVER ) ! 541: lpOutlineName = (LPOUTLINENAME)New((DWORD)sizeof(SERVERNAME)); ! 542: #else ! 543: lpOutlineName = (LPOUTLINENAME)New((DWORD)sizeof(OUTLINENAME)); ! 544: #endif ! 545: ! 546: if (! OleDbgVerifySz(lpOutlineName != NULL, "Error allocating Name")) ! 547: return NULL; ! 548: ! 549: #if defined( OLE_SERVER ) ! 550: _fmemset((LPVOID)lpOutlineName,0,sizeof(SERVERNAME)); ! 551: #else ! 552: _fmemset((LPVOID)lpOutlineName,0,sizeof(OUTLINENAME)); ! 553: #endif ! 554: ! 555: return lpOutlineName; ! 556: } ! 557: ! 558: ! 559: /* OutlineApp_DocUnlockApp ! 560: ** ----------------------- ! 561: ** Forget all references to a closed document. ! 562: */ ! 563: void OutlineApp_DocUnlockApp(LPOUTLINEAPP lpOutlineApp, LPOUTLINEDOC lpOutlineDoc) ! 564: { ! 565: /* forget pointers to destroyed document */ ! 566: if (lpOutlineApp->m_lpDoc == lpOutlineDoc) ! 567: lpOutlineApp->m_lpDoc = NULL; ! 568: else if (lpOutlineApp->m_lpClipboardDoc == lpOutlineDoc) ! 569: lpOutlineApp->m_lpClipboardDoc = NULL; ! 570: ! 571: #if defined( OLE_VERSION ) ! 572: /* OLE2NOTE: when there are no open documents and the app is not ! 573: ** under the control of the user then revoke our ClassFactory to ! 574: ** enable the app to shut down. ! 575: ** ! 576: ** NOTE: data transfer documents (non-user documents) do NOT ! 577: ** hold the app alive. therefore they do not Lock the app. ! 578: */ ! 579: if (! lpOutlineDoc->m_fDataTransferDoc) ! 580: OleApp_DocUnlockApp((LPOLEAPP)lpOutlineApp, lpOutlineDoc); ! 581: #endif ! 582: } ! 583: ! 584: ! 585: /* OutlineApp_NewCommand ! 586: * --------------------- ! 587: * ! 588: * Start a new untitled document (File.New command). ! 589: */ ! 590: void OutlineApp_NewCommand(LPOUTLINEAPP lpOutlineApp) ! 591: { ! 592: #if defined( OLE_VERSION ) ! 593: // Call OLE version of this function instead ! 594: OleApp_NewCommand((LPOLEAPP)lpOutlineApp); ! 595: ! 596: #else ! 597: ! 598: LPOUTLINEDOC lpOutlineDoc = lpOutlineApp->m_lpDoc; ! 599: ! 600: if (! OutlineDoc_Close(lpOutlineDoc, OLECLOSE_PROMPTSAVE)) ! 601: return; ! 602: ! 603: OleDbgAssertSz(lpOutlineApp->m_lpDoc==NULL,"Closed doc NOT properly destroyed"); ! 604: ! 605: lpOutlineApp->m_lpDoc = OutlineApp_CreateDoc(lpOutlineApp, FALSE); ! 606: if (! lpOutlineApp->m_lpDoc) goto error; ! 607: ! 608: // set the doc to an (Untitled) doc. ! 609: if (! OutlineDoc_InitNewFile(lpOutlineApp->m_lpDoc)) ! 610: goto error; ! 611: ! 612: // position and size the new doc window ! 613: OutlineApp_ResizeWindows(lpOutlineApp); ! 614: OutlineDoc_ShowWindow(lpOutlineApp->m_lpDoc); // calls OleDoc_Lock ! 615: ! 616: return; ! 617: ! 618: error: ! 619: // REVIEW: should load string from string resource ! 620: OutlineApp_ErrorMessage(lpOutlineApp, "Could not create new document"); ! 621: ! 622: if (lpOutlineApp->m_lpDoc) { ! 623: OutlineDoc_Destroy(lpOutlineApp->m_lpDoc); ! 624: lpOutlineApp->m_lpDoc = NULL; ! 625: } ! 626: ! 627: return; ! 628: ! 629: #endif ! 630: } ! 631: ! 632: ! 633: /* OutlineApp_OpenCommand ! 634: * ---------------------- ! 635: * ! 636: * Load a document from file (File.Open command). ! 637: */ ! 638: void OutlineApp_OpenCommand(LPOUTLINEAPP lpOutlineApp) ! 639: { ! 640: #if defined( OLE_VERSION ) ! 641: // Call OLE version of this function instead ! 642: OleApp_OpenCommand((LPOLEAPP)lpOutlineApp); ! 643: ! 644: #else ! 645: ! 646: OPENFILENAME ofn; ! 647: char szFilter[]=APPFILENAMEFILTER; ! 648: char szFileName[256]; ! 649: UINT i; ! 650: BOOL fStatus = TRUE; ! 651: ! 652: if (! OutlineDoc_CheckSaveChanges(lpOutlineApp->m_lpDoc, OLECLOSE_PROMPTSAVE)) ! 653: return; // abort opening new doc ! 654: ! 655: for(i=0; szFilter[i]; i++) ! 656: if(szFilter[i]=='|') szFilter[i]='\0'; ! 657: ! 658: _fmemset((LPOPENFILENAME)&ofn,0,sizeof(OPENFILENAME)); ! 659: ! 660: szFileName[0]='\0'; ! 661: ! 662: ofn.lStructSize=sizeof(OPENFILENAME); ! 663: ofn.hwndOwner=lpOutlineApp->m_hWndApp; ! 664: ofn.lpstrFilter=(LPSTR)szFilter; ! 665: ofn.lpstrFile=(LPSTR)szFileName; ! 666: ofn.nMaxFile=sizeof(szFileName); ! 667: ofn.Flags=OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; ! 668: ofn.lpstrDefExt=DEFEXTENSION; ! 669: ! 670: if(! GetOpenFileName((LPOPENFILENAME)&ofn)) ! 671: return; // user canceled file open dialog ! 672: ! 673: OutlineDoc_Close(lpOutlineApp->m_lpDoc, OLECLOSE_NOSAVE); ! 674: OleDbgAssertSz( ! 675: lpOutlineApp->m_lpDoc==NULL,"Closed doc NOT properly destroyed"); ! 676: ! 677: lpOutlineApp->m_lpDoc = OutlineApp_CreateDoc(lpOutlineApp, FALSE); ! 678: if (! lpOutlineApp->m_lpDoc) goto error; ! 679: ! 680: fStatus=OutlineDoc_LoadFromFile(lpOutlineApp->m_lpDoc, (LPSTR)szFileName); ! 681: ! 682: if (! fStatus) { ! 683: // loading the doc failed; create an untitled instead ! 684: OutlineDoc_Destroy(lpOutlineApp->m_lpDoc); // destroy unused doc ! 685: lpOutlineApp->m_lpDoc = OutlineApp_CreateDoc(lpOutlineApp, FALSE); ! 686: if (! lpOutlineApp->m_lpDoc) goto error; ! 687: if (! OutlineDoc_InitNewFile(lpOutlineApp->m_lpDoc)) ! 688: goto error; ! 689: } ! 690: ! 691: // position and size the new doc window ! 692: OutlineApp_ResizeWindows(lpOutlineApp); ! 693: OutlineDoc_ShowWindow(lpOutlineApp->m_lpDoc); ! 694: ! 695: return; ! 696: ! 697: error: ! 698: // REVIEW: should load string from string resource ! 699: OutlineApp_ErrorMessage(lpOutlineApp, "Could not create new document"); ! 700: ! 701: if (lpOutlineApp->m_lpDoc) { ! 702: OutlineDoc_Destroy(lpOutlineApp->m_lpDoc); ! 703: lpOutlineApp->m_lpDoc = NULL; ! 704: } ! 705: ! 706: return; ! 707: ! 708: #endif ! 709: } ! 710: ! 711: ! 712: /* OutlineApp_PrintCommand ! 713: * ----------------------- ! 714: * ! 715: * Print the document ! 716: */ ! 717: void OutlineApp_PrintCommand(LPOUTLINEAPP lpOutlineApp) ! 718: { ! 719: LPOUTLINEDOC lpOutlineDoc = lpOutlineApp->m_lpDoc; ! 720: HDC hDC=NULL; ! 721: BOOL fMustDeleteDC = FALSE; ! 722: ! 723: if (!PrintDlg((LPPRINTDLG)&lpOutlineApp->m_PrintDlg)) { ! 724: if (!CommDlgExtendedError()) { // Cancel button pressed ! 725: return; ! 726: } ! 727: } ! 728: else { ! 729: hDC = OutlineApp_GetPrinterDC(lpOutlineApp); ! 730: if (hDC) { ! 731: ! 732: #if defined( OLE_VERSION ) ! 733: /* OLE2NOTE: while we are printing we do NOT want to ! 734: ** receive any OnDataChange notifications or other OLE ! 735: ** interface calls which could disturb the printing of ! 736: ** the document. we will temporarily reply ! 737: ** SERVERCALL_RETRYLATER ! 738: */ ! 739: OleApp_RejectInComingCalls((LPOLEAPP)lpOutlineApp, TRUE); ! 740: #endif ! 741: ! 742: OutlineDoc_Print(lpOutlineDoc, hDC); ! 743: DeleteDC(hDC); ! 744: ! 745: #if defined( OLE_VERSION ) ! 746: // re-enable LRPC calls ! 747: OleApp_RejectInComingCalls((LPOLEAPP)lpOutlineApp, FALSE); ! 748: #endif ! 749: ! 750: return; // Printing completed ! 751: } ! 752: } ! 753: ! 754: // REVIEW: should load string from string resource ! 755: OutlineApp_ErrorMessage(lpOutlineApp, ErrMsgPrinting); ! 756: } ! 757: ! 758: ! 759: /* OutlineApp_PrinterSetupCommand ! 760: * ------------------------------ ! 761: * ! 762: * Setup a different printer for printing ! 763: */ ! 764: void OutlineApp_PrinterSetupCommand(LPOUTLINEAPP lpOutlineApp) ! 765: { ! 766: DWORD FlagSave; ! 767: ! 768: FlagSave = lpOutlineApp->m_PrintDlg.Flags; ! 769: lpOutlineApp->m_PrintDlg.Flags |= PD_PRINTSETUP; ! 770: PrintDlg((LPPRINTDLG)&lpOutlineApp->m_PrintDlg); ! 771: lpOutlineApp->m_PrintDlg.Flags = FlagSave; ! 772: } ! 773: ! 774: /* ! 775: * FUNCTION : OutlineApp_GetPrinterDC () ! 776: * ! 777: * PURPOSE : Creates a printer display context for the printer ! 778: * ! 779: * RETURNS : HDC - A handle to printer DC. ! 780: */ ! 781: HDC OutlineApp_GetPrinterDC(LPOUTLINEAPP lpApp) ! 782: { ! 783: ! 784: HDC hDC; ! 785: LPDEVMODE lpDevMode = NULL; ! 786: LPDEVNAMES lpDevNames; ! 787: LPSTR lpszDriverName; ! 788: LPSTR lpszDeviceName; ! 789: LPSTR lpszPortName; ! 790: ! 791: if(lpApp->m_PrintDlg.hDC) { ! 792: hDC = lpApp->m_PrintDlg.hDC; ! 793: } else { ! 794: if(! lpApp->m_PrintDlg.hDevNames) ! 795: return(NULL); ! 796: lpDevNames = (LPDEVNAMES)GlobalLock(lpApp->m_PrintDlg.hDevNames); ! 797: lpszDriverName = (LPSTR)lpDevNames + lpDevNames->wDriverOffset; ! 798: lpszDeviceName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset; ! 799: lpszPortName = (LPSTR)lpDevNames + lpDevNames->wOutputOffset; ! 800: GlobalUnlock(lpApp->m_PrintDlg.hDevNames); ! 801: ! 802: if(lpApp->m_PrintDlg.hDevMode) ! 803: lpDevMode = (LPDEVMODE)GlobalLock(lpApp->m_PrintDlg.hDevMode); ! 804: #if defined( WIN32 ) ! 805: hDC = CreateDC( ! 806: lpszDriverName, ! 807: lpszDeviceName, ! 808: lpszPortName, ! 809: (CONST DEVMODE FAR*)lpDevMode); ! 810: #else ! 811: hDC = CreateDC( ! 812: lpszDriverName, ! 813: lpszDeviceName, ! 814: lpszPortName, ! 815: (LPSTR)lpDevMode); ! 816: #endif ! 817: ! 818: if(lpApp->m_PrintDlg.hDevMode && lpDevMode) ! 819: GlobalUnlock(lpApp->m_PrintDlg.hDevMode); ! 820: } ! 821: ! 822: return(hDC); ! 823: } ! 824: ! 825: ! 826: /* OutlineApp_SaveCommand ! 827: * ---------------------- ! 828: * ! 829: * Save the document with same name. If no name exists, prompt the user ! 830: * for a name (via SaveAsCommand) ! 831: * ! 832: * Parameters: ! 833: * ! 834: * Returns: ! 835: * TRUE if succesfully ! 836: * FALSE if failed or aborted ! 837: */ ! 838: BOOL OutlineApp_SaveCommand(LPOUTLINEAPP lpOutlineApp) ! 839: { ! 840: LPOUTLINEDOC lpOutlineDoc = OutlineApp_GetActiveDoc(lpOutlineApp); ! 841: ! 842: if(lpOutlineDoc->m_docInitType == DOCTYPE_NEW) /* file with no name */ ! 843: return OutlineApp_SaveAsCommand(lpOutlineApp); ! 844: ! 845: ! 846: if(OutlineDoc_IsModified(lpOutlineDoc)) { ! 847: ! 848: #if defined( OLE_SERVER ) ! 849: ! 850: if (lpOutlineDoc->m_docInitType == DOCTYPE_EMBEDDED) { ! 851: LPSERVERDOC lpServerDoc = (LPSERVERDOC)lpOutlineDoc; ! 852: HRESULT hrErr; ! 853: ! 854: /* OLE2NOTE: if the document is an embedded object, then ! 855: ** the "File.Save" command is changed to "File.Update". ! 856: ** in order to update our container, we must ask our ! 857: ** container to save us. ! 858: */ ! 859: OleDbgAssert(lpServerDoc->m_lpOleClientSite != NULL); ! 860: OLEDBG_BEGIN2("IOleClientSite::SaveObject called\r\n") ! 861: hrErr = lpServerDoc->m_lpOleClientSite->lpVtbl->SaveObject( ! 862: lpServerDoc->m_lpOleClientSite ! 863: ); ! 864: OLEDBG_END2 ! 865: ! 866: if (hrErr != NOERROR) { ! 867: OleDbgOutHResult("IOleClientSite::SaveObject returned",hrErr); ! 868: return FALSE; ! 869: } ! 870: } else ! 871: // document is file-base user document, save it to its file. ! 872: ! 873: #endif // OLE_SERVER ! 874: ! 875: (void)OutlineDoc_SaveToFile( ! 876: lpOutlineDoc, ! 877: NULL, ! 878: lpOutlineDoc->m_cfSaveFormat, ! 879: TRUE ! 880: ); ! 881: } ! 882: ! 883: return TRUE; ! 884: } ! 885: ! 886: ! 887: /* OutlineApp_SaveAsCommand ! 888: * ------------------------ ! 889: * ! 890: * Save the document as another name ! 891: * ! 892: * Parameters: ! 893: * ! 894: * Returns: ! 895: * TRUE if saved successful ! 896: * FALSE if failed or aborted ! 897: */ ! 898: BOOL OutlineApp_SaveAsCommand(LPOUTLINEAPP lpOutlineApp) ! 899: { ! 900: LPOUTLINEDOC lpOutlineDoc = lpOutlineApp->m_lpDoc; ! 901: OPENFILENAME ofn; ! 902: char szFilter[]=APPFILENAMEFILTER; ! 903: char szFileName[256]=""; ! 904: int i; ! 905: UINT uFormat; ! 906: BOOL fNoError = TRUE; ! 907: BOOL fRemember = TRUE; ! 908: ! 909: for(i=0; szFilter[i]; i++) ! 910: if(szFilter[i]=='|') szFilter[i]='\0'; ! 911: ! 912: _fmemset((LPOPENFILENAME)&ofn,0,sizeof(OPENFILENAME)); ! 913: ! 914: ofn.lStructSize=sizeof(OPENFILENAME); ! 915: ofn.hwndOwner=lpOutlineDoc->m_hWndDoc; ! 916: ofn.lpstrFilter=(LPSTR)szFilter; ! 917: ofn.lpstrFile=(LPSTR)szFileName; ! 918: ofn.nMaxFile=sizeof(szFileName); ! 919: ! 920: ofn.Flags=OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY; ! 921: ofn.lpstrDefExt=DEFEXTENSION; ! 922: ! 923: if (GetSaveFileName((LPOPENFILENAME)&ofn)) { ! 924: ! 925: #if defined( OLE_CNTR ) ! 926: // determine which file type the user selected. ! 927: switch (ofn.nFilterIndex) { ! 928: case 1: ! 929: uFormat = ((LPCONTAINERAPP)lpOutlineApp)->m_cfCntrOutl; ! 930: break; ! 931: case 2: ! 932: uFormat = lpOutlineApp->m_cfOutline; ! 933: break; ! 934: default: ! 935: uFormat = ((LPCONTAINERAPP)lpOutlineApp)->m_cfCntrOutl; ! 936: break; ! 937: } ! 938: #else ! 939: uFormat = lpOutlineApp->m_cfOutline; ! 940: #endif ! 941: ! 942: #if defined( OLE_SERVER ) ! 943: /* OLE2NOTE: if the document is an embedded object, then the ! 944: ** File.SaveAs command is changed to File.SaveCopyAs. with the ! 945: ** Save Copy As operation, the document does NOT remember the ! 946: ** saved file as the associated file for the document. ! 947: */ ! 948: if (lpOutlineDoc->m_docInitType == DOCTYPE_EMBEDDED) ! 949: fRemember = FALSE; ! 950: #endif ! 951: ! 952: (void)OutlineDoc_SaveToFile( ! 953: lpOutlineDoc, ! 954: szFileName, ! 955: uFormat, ! 956: fRemember ! 957: ); ! 958: ! 959: } ! 960: else ! 961: fNoError = FALSE; ! 962: ! 963: return fNoError; ! 964: ! 965: } ! 966: ! 967: ! 968: /* OutlineApp_AboutCommand ! 969: * ----------------------- ! 970: * ! 971: * Show the About dialog box ! 972: */ ! 973: void OutlineApp_AboutCommand(LPOUTLINEAPP lpOutlineApp) ! 974: { ! 975: DialogBox( ! 976: lpOutlineApp->m_hInst, ! 977: (LPSTR)"About", ! 978: OutlineApp_GetFrameWindow(lpOutlineApp), ! 979: (DLGPROC)AboutDlgProc ! 980: ); ! 981: } ! 982: ! 983: ! 984: /* OutlineApp_CloseAllDocsAndExitCommand ! 985: * ------------------------------------- ! 986: * ! 987: * Close all active documents and exit the app. ! 988: * Because this is an SDI, there is only one document ! 989: * If the doc was modified, prompt the user if he wants to save it. ! 990: * ! 991: * Returns: ! 992: * TRUE if the app is successfully closed ! 993: * FALSE if failed or aborted ! 994: */ ! 995: BOOL OutlineApp_CloseAllDocsAndExitCommand(LPOUTLINEAPP lpOutlineApp) ! 996: { ! 997: BOOL fResult; ! 998: ! 999: OLEDBG_BEGIN2("OutlineApp_CloseAllDocsAndExitCommand\r\n") ! 1000: ! 1001: #if defined( OLE_VERSION ) ! 1002: // Call OLE specific version of this function ! 1003: fResult = OleApp_CloseAllDocsAndExitCommand((LPOLEAPP)lpOutlineApp); ! 1004: ! 1005: #else ! 1006: ! 1007: /* Because this is an SDI app, there is only one document. ! 1008: ** Close the doc. if it is successfully closed and the app will ! 1009: ** not automatically exit, then also exit the app. ! 1010: ** if this were an MDI app, we would loop through and close all ! 1011: ** open MDI child documents. ! 1012: */ ! 1013: if (OutlineDoc_Close(lpOutlineApp->m_lpDoc, OLECLOSE_PROMPTSAVE)) { ! 1014: ! 1015: OleDbgAssertSz( ! 1016: lpOutlineApp->m_lpDoc==NULL, ! 1017: "Closed doc NOT properly destroyed" ! 1018: ); ! 1019: ! 1020: OutlineApp_Destroy(lpOutlineApp); ! 1021: fResult = TRUE; ! 1022: ! 1023: } // else User Canceled shutdown ! 1024: else ! 1025: fResult = FALSE; ! 1026: ! 1027: #endif ! 1028: ! 1029: OLEDBG_END2 ! 1030: ! 1031: return fResult; ! 1032: } ! 1033: ! 1034: ! 1035: /* OutlineApp_Destroy ! 1036: * ------------------ ! 1037: * ! 1038: * Destroy all data structures used by the app and force the ! 1039: * app to shut down. This should be called after all documents have ! 1040: * been closed. ! 1041: */ ! 1042: void OutlineApp_Destroy(LPOUTLINEAPP lpOutlineApp) ! 1043: { ! 1044: OLEDBG_BEGIN3("OutlineApp_Destroy\r\n"); ! 1045: ! 1046: #if defined( OLE_VERSION ) ! 1047: /* OLE2NOTE: perform processing required for OLE */ ! 1048: OleApp_Destroy((LPOLEAPP)lpOutlineApp); ! 1049: #endif ! 1050: ! 1051: SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW))); ! 1052: DestroyCursor(lpOutlineApp->m_hcursorSelCur); ! 1053: ! 1054: #if defined( USE_FRAMETOOLS ) ! 1055: FrameTools_Destroy(&lpOutlineApp->m_frametools); ! 1056: #endif ! 1057: ! 1058: DeleteObject(lpOutlineApp->m_hStdFont); ! 1059: if(lpOutlineApp->m_PrintDlg.hDevMode) ! 1060: GlobalFree(lpOutlineApp->m_PrintDlg.hDevMode); ! 1061: if(lpOutlineApp->m_PrintDlg.hDevNames) ! 1062: GlobalFree(lpOutlineApp->m_PrintDlg.hDevNames); ! 1063: ! 1064: #if defined( USE_STATUSBAR ) ! 1065: if(lpOutlineApp->m_hWndStatusBar) { ! 1066: DestroyStatusWindow(lpOutlineApp->m_hWndStatusBar); ! 1067: lpOutlineApp->m_hWndStatusBar = NULL; ! 1068: } ! 1069: #endif ! 1070: ! 1071: OutlineApp_DestroyWindow(lpOutlineApp); ! 1072: ! 1073: OleDbgOut1("@@@@ APP DESTROYED\r\n"); ! 1074: ! 1075: OLEDBG_END3 ! 1076: } ! 1077: ! 1078: ! 1079: /* OutlineApp_DestroyWindow ! 1080: * ------------------------ ! 1081: * ! 1082: * Destroy all windows created by the App. ! 1083: */ ! 1084: void OutlineApp_DestroyWindow(LPOUTLINEAPP lpOutlineApp) ! 1085: { ! 1086: HWND hWndApp = lpOutlineApp->m_hWndApp; ! 1087: ! 1088: if(hWndApp) { ! 1089: lpOutlineApp->m_hWndApp = NULL; ! 1090: lpOutlineApp->m_hWndAccelTarget = NULL; ! 1091: DestroyWindow(hWndApp); /* Quit the app */ ! 1092: } ! 1093: } ! 1094: ! 1095: ! 1096: /* OutlineApp_GetFrameRect ! 1097: ** ----------------------- ! 1098: ** Get the rectangle of the app frame window EXCLUDING space for the ! 1099: ** status line. ! 1100: ** ! 1101: ** OLE2NOTE: this is the rectangle that an in-place container can ! 1102: ** offer to an in-place active object from which to get frame tool ! 1103: ** space. ! 1104: */ ! 1105: void OutlineApp_GetFrameRect(LPOUTLINEAPP lpOutlineApp, LPRECT lprcFrameRect) ! 1106: { ! 1107: GetClientRect(lpOutlineApp->m_hWndApp, lprcFrameRect); ! 1108: ! 1109: #if defined( USE_STATUSBAR ) ! 1110: lprcFrameRect->bottom -= STATUS_HEIGHT; ! 1111: #endif ! 1112: ! 1113: } ! 1114: ! 1115: ! 1116: /* OutlineApp_GetClientAreaRect ! 1117: ** ---------------------------- ! 1118: ** Get the rectangle of the app frame window EXCLUDING space for the ! 1119: ** status line AND EXCLUDING space for any frame-level tools. ! 1120: ** ! 1121: ** OLE2NOTE: this is the rectangle that an in-place container gives ! 1122: ** to its in-place active object as the lpClipRect in ! 1123: ** IOleInPlaceSite::GetWindowContext. ! 1124: */ ! 1125: void OutlineApp_GetClientAreaRect( ! 1126: LPOUTLINEAPP lpOutlineApp, ! 1127: LPRECT lprcClientAreaRect ! 1128: ) ! 1129: { ! 1130: OutlineApp_GetFrameRect(lpOutlineApp, lprcClientAreaRect); ! 1131: ! 1132: /* if the app either uses frame-level tools itself or, as in-place ! 1133: ** container, is prepared to allow an in-place active object to ! 1134: ** have space for tools, then it must subtract away the space ! 1135: ** required for the tools. ! 1136: */ ! 1137: #if defined ( USE_FRAMETOOLS ) || defined ( INPLACE_CNTR ) ! 1138: ! 1139: lprcClientAreaRect->top += lpOutlineApp->m_FrameToolWidths.top; ! 1140: lprcClientAreaRect->left += lpOutlineApp->m_FrameToolWidths.left; ! 1141: lprcClientAreaRect->right -= lpOutlineApp->m_FrameToolWidths.right; ! 1142: lprcClientAreaRect->bottom -= lpOutlineApp->m_FrameToolWidths.bottom; ! 1143: #endif // USE_FRAMETOOLS || INPLACE_CNTR ! 1144: ! 1145: } ! 1146: ! 1147: ! 1148: /* OutlineApp_GetStatusLineRect ! 1149: ** ---------------------------- ! 1150: ** Get the rectangle required for the status line. ! 1151: ** ! 1152: ** OLE2NOTE: the top frame-level in-place container displays its ! 1153: ** status line even when an object is active in-place. ! 1154: */ ! 1155: void OutlineApp_GetStatusLineRect( ! 1156: LPOUTLINEAPP lpOutlineApp, ! 1157: LPRECT lprcStatusLineRect ! 1158: ) ! 1159: { ! 1160: RECT rcFrameRect; ! 1161: GetClientRect(lpOutlineApp->m_hWndApp, (LPRECT)&rcFrameRect); ! 1162: lprcStatusLineRect->left = rcFrameRect.left; ! 1163: lprcStatusLineRect->top = rcFrameRect.bottom - STATUS_HEIGHT; ! 1164: lprcStatusLineRect->right = rcFrameRect.right; ! 1165: lprcStatusLineRect->bottom = rcFrameRect.bottom; ! 1166: } ! 1167: ! 1168: ! 1169: /* OutlineApp_ResizeWindows ! 1170: * ------------------------ ! 1171: * ! 1172: * Changes the size and position of the SDI document and tool windows. ! 1173: * Normally called on a WM_SIZE message. ! 1174: * ! 1175: * Currently the app supports a status bar and a single SDI document window. ! 1176: * In the future it will have a formula bar and possibly multiple MDI ! 1177: * document windows. ! 1178: * ! 1179: * CUSTOMIZATION: Change positions of windows. ! 1180: */ ! 1181: void OutlineApp_ResizeWindows(LPOUTLINEAPP lpOutlineApp) ! 1182: { ! 1183: LPOUTLINEDOC lpOutlineDoc = OutlineApp_GetActiveDoc(lpOutlineApp); ! 1184: RECT rcStatusLineRect; ! 1185: ! 1186: if (! lpOutlineApp) ! 1187: return; ! 1188: ! 1189: #if defined( INPLACE_CNTR ) ! 1190: if (lpOutlineDoc) ! 1191: ContainerDoc_FrameWindowResized((LPCONTAINERDOC)lpOutlineDoc); ! 1192: #elif defined( USE_FRAMETOOLS ) ! 1193: if (lpOutlineDoc) ! 1194: OutlineDoc_AddFrameLevelTools(lpOutlineDoc); ! 1195: #else ! 1196: OutlineApp_ResizeClientArea(lpOutlineApp); ! 1197: #endif ! 1198: ! 1199: #if defined( USE_STATUSBAR ) ! 1200: if (lpOutlineApp->m_hWndStatusBar) { ! 1201: OutlineApp_GetStatusLineRect(lpOutlineApp, (LPRECT)&rcStatusLineRect); ! 1202: MoveWindow( ! 1203: lpOutlineApp->m_hWndStatusBar, ! 1204: rcStatusLineRect.left, ! 1205: rcStatusLineRect.top, ! 1206: rcStatusLineRect.right - rcStatusLineRect.left, ! 1207: rcStatusLineRect.bottom - rcStatusLineRect.top, ! 1208: TRUE /* fRepaint */ ! 1209: ); ! 1210: } ! 1211: #endif // USE_STATUSBAR ! 1212: } ! 1213: ! 1214: ! 1215: #if defined( USE_FRAMETOOLS ) || defined( INPLACE_CNTR ) ! 1216: ! 1217: void OutlineApp_SetBorderSpace( ! 1218: LPOUTLINEAPP lpOutlineApp, ! 1219: LPBORDERWIDTHS lpBorderWidths ! 1220: ) ! 1221: { ! 1222: lpOutlineApp->m_FrameToolWidths = *lpBorderWidths; ! 1223: OutlineApp_ResizeClientArea(lpOutlineApp); ! 1224: } ! 1225: #endif // USE_FRAMETOOLS || INPLACE_CNTR ! 1226: ! 1227: ! 1228: void OutlineApp_ResizeClientArea(LPOUTLINEAPP lpOutlineApp) ! 1229: { ! 1230: RECT rcClientAreaRect; ! 1231: ! 1232: #if defined( MDI_VERSION ) ! 1233: ! 1234: // Resize MDI Client Area Window here ! 1235: ! 1236: #else ! 1237: ! 1238: if (lpOutlineApp->m_lpDoc) { ! 1239: OutlineApp_GetClientAreaRect( ! 1240: lpOutlineApp, (LPRECT)&rcClientAreaRect); ! 1241: OutlineDoc_Resize(lpOutlineApp->m_lpDoc, ! 1242: (LPRECT)&rcClientAreaRect); ! 1243: } ! 1244: ! 1245: #endif ! 1246: ! 1247: } ! 1248: ! 1249: ! 1250: /* OutlineApp_GetActiveDoc ! 1251: * ----------------------- ! 1252: * ! 1253: * Return the document in focus. For SDI, the same (only one) document is ! 1254: * always returned. ! 1255: */ ! 1256: LPOUTLINEDOC OutlineApp_GetActiveDoc(LPOUTLINEAPP lpOutlineApp) ! 1257: { ! 1258: return lpOutlineApp->m_lpDoc; ! 1259: } ! 1260: ! 1261: /* OutlineApp_GetMenu ! 1262: * ------------------ ! 1263: * ! 1264: * Return the menu handle of the app ! 1265: */ ! 1266: HMENU OutlineApp_GetMenu(LPOUTLINEAPP lpOutlineApp) ! 1267: { ! 1268: if (!lpOutlineApp) { ! 1269: return NULL; ! 1270: } ! 1271: ! 1272: return lpOutlineApp->m_hMenuApp; ! 1273: } ! 1274: ! 1275: ! 1276: #if defined( USE_FRAMETOOLS ) ! 1277: ! 1278: /* OutlineApp_GetFrameTools ! 1279: * --------------------- ! 1280: * ! 1281: * Return the pointer to the toolbar object ! 1282: */ ! 1283: LPFRAMETOOLS OutlineApp_GetFrameTools(LPOUTLINEAPP lpOutlineApp) ! 1284: { ! 1285: return (LPFRAMETOOLS)&lpOutlineApp->m_frametools; ! 1286: } ! 1287: #endif ! 1288: ! 1289: ! 1290: /* OutlineApp_GetStatusWindow ! 1291: * -------------------------- ! 1292: * ! 1293: * Return the status bar window handle. ! 1294: */ ! 1295: HWND OutlineApp_GetStatusWindow(LPOUTLINEAPP lpOutlineApp) ! 1296: { ! 1297: return lpOutlineApp->m_hWndStatusBar; ! 1298: } ! 1299: ! 1300: ! 1301: /* OutlineApp_GetActiveFont ! 1302: * ------------------------ ! 1303: * ! 1304: * Return the font used by the application ! 1305: */ ! 1306: HFONT OutlineApp_GetActiveFont(LPOUTLINEAPP lpOutlineApp) ! 1307: { ! 1308: return lpOutlineApp->m_hStdFont; ! 1309: } ! 1310: ! 1311: ! 1312: /* OutlineApp_GetAppName ! 1313: * --------------------- ! 1314: * ! 1315: * Retrieve the application name ! 1316: */ ! 1317: void OutlineApp_GetAppName(LPOUTLINEAPP lpOutlineApp, LPSTR lpszAppName) ! 1318: { ! 1319: lstrcpy(lpszAppName, APPNAME); ! 1320: } ! 1321: ! 1322: ! 1323: /* OutlineApp_GetAppVersionNo ! 1324: * -------------------------- ! 1325: * ! 1326: * Get the version number (major and minor) of the application ! 1327: */ ! 1328: void OutlineApp_GetAppVersionNo(LPOUTLINEAPP lpOutlineApp, int narrAppVersionNo[]) ! 1329: { ! 1330: narrAppVersionNo[0] = APPMAJORVERSIONNO; ! 1331: narrAppVersionNo[1] = APPMINORVERSIONNO; ! 1332: } ! 1333: ! 1334: ! 1335: /* OutlineApp_VersionNoCheck ! 1336: * ------------------------- ! 1337: * ! 1338: * Check if the version stamp read from a file is compatible ! 1339: * with the current instance of the application. ! 1340: * returns TRUE if the file can be read, else FALSE. ! 1341: */ ! 1342: BOOL OutlineApp_VersionNoCheck(LPOUTLINEAPP lpOutlineApp, LPSTR lpszFormatName, int narrAppVersionNo[]) ! 1343: { ! 1344: #if defined( OLE_CNTR ) ! 1345: ! 1346: /* ContainerApp accepts both CF_OUTLINE and CF_CONTAINEROUTLINE formats */ ! 1347: if (lstrcmp(lpszFormatName, CONTAINERDOCFORMAT) != 0 && ! 1348: lstrcmp(lpszFormatName, OUTLINEDOCFORMAT) != 0) { ! 1349: // REVIEW: should load string from string resource ! 1350: OutlineApp_ErrorMessage( ! 1351: lpOutlineApp, ! 1352: "File is either corrupted or not of proper type." ! 1353: ); ! 1354: return FALSE; ! 1355: } ! 1356: ! 1357: #else ! 1358: ! 1359: /* OutlineApp accepts CF_OUTLINE format only */ ! 1360: if (lstrcmp(lpszFormatName, OUTLINEDOCFORMAT) != 0) { ! 1361: // REVIEW: should load string from string resource ! 1362: OutlineApp_ErrorMessage( ! 1363: lpOutlineApp, ! 1364: "File is either corrupted or not of proper type." ! 1365: ); ! 1366: return FALSE; ! 1367: } ! 1368: #endif ! 1369: ! 1370: if (narrAppVersionNo[0] < APPMAJORVERSIONNO) { ! 1371: // REVIEW: should load string from string resource ! 1372: OutlineApp_ErrorMessage( ! 1373: lpOutlineApp, ! 1374: "File was created by an older version; it can not be read." ! 1375: ); ! 1376: return FALSE; ! 1377: } ! 1378: ! 1379: return TRUE; ! 1380: } ! 1381: ! 1382: ! 1383: /* OutlineApp_ErrorMessage ! 1384: * ----------------------- ! 1385: * ! 1386: * Display an error message box ! 1387: */ ! 1388: void OutlineApp_ErrorMessage(LPOUTLINEAPP lpOutlineApp, LPSTR lpszErrMsg) ! 1389: { ! 1390: HWND hWndFrame = OutlineApp_GetFrameWindow(lpOutlineApp); ! 1391: ! 1392: // OLE2NOTE: only put up user message boxes if app is visible ! 1393: if (IsWindowVisible(hWndFrame)) ! 1394: MessageBox(hWndFrame, lpszErrMsg, NULL, MB_ICONEXCLAMATION | MB_OK); ! 1395: } ! 1396: ! 1397: ! 1398: #if defined( USE_FRAMETOOLS ) ! 1399: ! 1400: /* OutlineApp_SetFormulaBarAccel ! 1401: * ----------------------------- ! 1402: * ! 1403: * Set accelerator table based on state of formula bar. ! 1404: */ ! 1405: void OutlineApp_SetFormulaBarAccel( ! 1406: LPOUTLINEAPP lpOutlineApp, ! 1407: BOOL fEditFocus ! 1408: ) ! 1409: { ! 1410: if (fEditFocus) ! 1411: lpOutlineApp->m_hAccel = lpOutlineApp->m_hAccelFocusEdit; ! 1412: else ! 1413: lpOutlineApp->m_hAccel = lpOutlineApp->m_hAccelApp; ! 1414: } ! 1415: ! 1416: #endif // USE_FRAMETOOLS
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.