Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1514 lines
41 KiB

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