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.

1075 lines
28 KiB

  1. /*************************************************************************
  2. **
  3. ** OLE 2 Server Sample Code
  4. **
  5. ** frametls.c
  6. **
  7. ** This file contains all FrameTools methods and related support
  8. ** functions. The FrameTools object is an encapsulation of the apps
  9. ** formula bar and button bar.
  10. **
  11. ** (c) Copyright Microsoft Corp. 1992 - 1993 All Rights Reserved
  12. **
  13. *************************************************************************/
  14. #include "outline.h"
  15. OLEDBGDATA
  16. /* private function prototype */
  17. static void Bar_Move(LPBAR lpbar, LPRECT lprcClient, LPRECT lprcPopup);
  18. static void FB_ResizeEdit(LPBAR lpbar);
  19. extern LPOUTLINEAPP g_lpApp;
  20. extern RECT g_rectNull;
  21. /*
  22. * FrameToolsRegisterClass
  23. *
  24. * Purpose:
  25. * Register the popup toolbar window class
  26. *
  27. * Parameters:
  28. * hInst Process instance
  29. *
  30. * Return Value:
  31. * TRUE if successful
  32. * FALSE if failed
  33. *
  34. */
  35. BOOL FrameToolsRegisterClass(HINSTANCE hInst)
  36. {
  37. WNDCLASS wc;
  38. // Register Tool Palette Class
  39. wc.style = CS_BYTEALIGNWINDOW;
  40. wc.lpfnWndProc = FrameToolsWndProc;
  41. wc.cbClsExtra = 0;
  42. wc.cbWndExtra = 4;
  43. wc.hInstance = hInst;
  44. wc.hIcon = NULL;
  45. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  46. wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  47. wc.lpszMenuName = NULL;
  48. wc.lpszClassName = CLASS_PALETTE;
  49. if (!RegisterClass(&wc))
  50. return FALSE;
  51. else
  52. return TRUE;
  53. }
  54. static BOOL FrameTools_CreatePopupPalette(LPFRAMETOOLS lpft, HWND hWndFrame)
  55. {
  56. if (lpft->m_hWndPopupPalette)
  57. DestroyWindow(lpft->m_hWndPopupPalette);
  58. lpft->m_hWndPopupPalette = CreateWindow(
  59. CLASS_PALETTE,
  60. "Tool Palette",
  61. WS_POPUP | WS_CAPTION | WS_CLIPCHILDREN,
  62. CW_USEDEFAULT, 0, 0, 0,
  63. hWndFrame,
  64. (HMENU)NULL,
  65. g_lpApp->m_hInst,
  66. 0L
  67. );
  68. if (!lpft->m_hWndPopupPalette)
  69. return FALSE;
  70. SetWindowLong(lpft->m_hWndPopupPalette, 0, (LONG)lpft);
  71. return TRUE;
  72. }
  73. /*
  74. * FrameTools_Init
  75. *
  76. * Purpose:
  77. * Init and create the toolbar
  78. *
  79. * Parameters:
  80. * lpft FrameTools object
  81. * hWndParent The window which owns the toolbar
  82. * hInst Process instance
  83. *
  84. * Return Value:
  85. * TRUE if successful
  86. * FALSE if failed
  87. *
  88. */
  89. BOOL FrameTools_Init(LPFRAMETOOLS lpft, HWND hWndParent, HINSTANCE hInst)
  90. {
  91. RECT rc;
  92. UINT uPos;
  93. UINT dx;
  94. UINT dy;
  95. if (!lpft || !hWndParent || !hInst)
  96. return FALSE;
  97. //Get BTTNCUR's display information
  98. UIToolConfigureForDisplay(&lpft->m_tdd);
  99. dx=lpft->m_tdd.cxButton;
  100. dy=lpft->m_tdd.cyButton;
  101. // 15 is calculated from the total number of buttons and separators
  102. lpft->m_uPopupWidth = dx * 15;
  103. lpft->m_hWndApp = hWndParent;
  104. lpft->m_ButtonBar.m_nState = BARSTATE_TOP;
  105. lpft->m_FormulaBar.m_nState = BARSTATE_TOP;
  106. lpft->m_fInFormulaBar = FALSE;
  107. lpft->m_fToolsDisabled = FALSE;
  108. lpft->m_ButtonBar.m_uHeight = lpft->m_tdd.cyBar;
  109. lpft->m_FormulaBar.m_uHeight = lpft->m_tdd.cyBar;
  110. //Get our image bitmaps for the display type we're on
  111. if (72 == lpft->m_tdd.uDPI)
  112. lpft->m_hBmp = LoadBitmap(hInst, (LPCSTR)"Image72");
  113. if (96 == lpft->m_tdd.uDPI)
  114. lpft->m_hBmp = LoadBitmap(hInst, (LPCSTR)"Image96");
  115. if (120 == lpft->m_tdd.uDPI)
  116. lpft->m_hBmp = LoadBitmap(hInst, (LPCSTR)"Image120");
  117. if (!lpft->m_hBmp)
  118. return FALSE;
  119. /* Create Popup Tool Palette window */
  120. lpft->m_hWndPopupPalette = NULL;
  121. if (! FrameTools_CreatePopupPalette(lpft, hWndParent))
  122. return FALSE;
  123. uPos = 0;
  124. //Create the GizmoBar and the client area window
  125. GetClientRect(hWndParent, &rc);
  126. lpft->m_ButtonBar.m_hWnd = CreateWindow(
  127. CLASS_GIZMOBAR,
  128. "ButtonBar",
  129. WS_CHILD | WS_VISIBLE,
  130. 0, 0, rc.right-rc.left, lpft->m_tdd.cyBar,
  131. hWndParent,
  132. (HMENU)IDC_GIZMOBAR,
  133. hInst,
  134. 0L
  135. );
  136. if (!lpft->m_ButtonBar.m_hWnd)
  137. return FALSE;
  138. SendMessage(lpft->m_ButtonBar.m_hWnd, WM_SETREDRAW, FALSE, 0L);
  139. //File new, open, save, print
  140. GBGizmoAdd(lpft->m_ButtonBar.m_hWnd, GIZMOTYPE_BUTTONCOMMAND, uPos++, IDM_F_NEW, dx, dy, NULL, NULL, TOOLIMAGE_FILENEW, GIZMO_NORMAL);
  141. GBGizmoAdd(lpft->m_ButtonBar.m_hWnd, GIZMOTYPE_BUTTONCOMMAND, uPos++, IDM_F_OPEN, dx, dy, NULL, NULL, TOOLIMAGE_FILEOPEN, GIZMO_NORMAL);
  142. GBGizmoAdd(lpft->m_ButtonBar.m_hWnd, GIZMOTYPE_BUTTONCOMMAND, uPos++, IDM_F_SAVE, dx, dy, NULL, NULL, TOOLIMAGE_FILESAVE, GIZMO_NORMAL);
  143. GBGizmoAdd(lpft->m_ButtonBar.m_hWnd, GIZMOTYPE_BUTTONCOMMAND, uPos++, IDM_F_PRINT, dx, dy, NULL, NULL, TOOLIMAGE_FILEPRINT, GIZMO_NORMAL);
  144. // separator
  145. GBGizmoAdd(lpft->m_ButtonBar.m_hWnd, GIZMOTYPE_SEPARATOR, uPos++, 0, dx/2, dy, NULL, NULL, 0, GIZMO_NORMAL);
  146. // Edit cut, copy, paste
  147. GBGizmoAdd(lpft->m_ButtonBar.m_hWnd, GIZMOTYPE_BUTTONCOMMAND, uPos++, IDM_E_CUT, dx, dy, NULL, NULL, TOOLIMAGE_EDITCUT, GIZMO_NORMAL);
  148. GBGizmoAdd(lpft->m_ButtonBar.m_hWnd, GIZMOTYPE_BUTTONCOMMAND, uPos++, IDM_E_COPY, dx, dy, NULL, NULL, TOOLIMAGE_EDITCOPY, GIZMO_NORMAL);
  149. GBGizmoAdd(lpft->m_ButtonBar.m_hWnd, GIZMOTYPE_BUTTONCOMMAND, uPos++, IDM_E_PASTE, dx, dy, NULL, NULL, TOOLIMAGE_EDITPASTE, GIZMO_NORMAL);
  150. // separator
  151. GBGizmoAdd(lpft->m_ButtonBar.m_hWnd, GIZMOTYPE_SEPARATOR, uPos++, 0, dx/2, dy, NULL, NULL, 0, GIZMO_NORMAL);
  152. // Line indent, unindent
  153. GBGizmoAdd(lpft->m_ButtonBar.m_hWnd, GIZMOTYPE_BUTTONCOMMAND, uPos++, IDM_L_UNINDENTLINE, dx, dy, NULL, lpft->m_hBmp, IDB_UNINDENTLINE, GIZMO_NORMAL);
  154. GBGizmoAdd(lpft->m_ButtonBar.m_hWnd, GIZMOTYPE_BUTTONCOMMAND, uPos++, IDM_L_INDENTLINE, dx, dy, NULL, lpft->m_hBmp, IDB_INDENTLINE, GIZMO_NORMAL);
  155. // separator
  156. GBGizmoAdd(lpft->m_ButtonBar.m_hWnd, GIZMOTYPE_SEPARATOR, uPos++, 0, dx/2, dy, NULL, NULL, 0, GIZMO_NORMAL);
  157. // Help
  158. GBGizmoAdd(lpft->m_ButtonBar.m_hWnd, GIZMOTYPE_BUTTONCOMMAND, uPos++, IDM_H_ABOUT, dx, dy, NULL, NULL, TOOLIMAGE_HELP, GIZMO_NORMAL);
  159. SendMessage(lpft->m_ButtonBar.m_hWnd, WM_SETREDRAW, TRUE, 0L);
  160. uPos = 0;
  161. lpft->m_FormulaBar.m_hWnd = CreateWindow(
  162. CLASS_GIZMOBAR,
  163. "FormulaBar",
  164. WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS,
  165. 0, lpft->m_tdd.cyBar, rc.right-rc.left, lpft->m_tdd.cyBar,
  166. hWndParent,
  167. (HMENU)IDC_FORMULABAR,
  168. hInst,
  169. 0L
  170. );
  171. if (!lpft->m_FormulaBar.m_hWnd)
  172. return FALSE;
  173. SendMessage(lpft->m_FormulaBar.m_hWnd, WM_SETREDRAW, FALSE, 0L);
  174. // Line add line
  175. GBGizmoAdd(lpft->m_FormulaBar.m_hWnd, GIZMOTYPE_BUTTONCOMMAND, uPos++, IDM_L_ADDLINE, dx, dy, NULL, lpft->m_hBmp, IDB_ADDLINE, GIZMO_NORMAL);
  176. // separator
  177. GBGizmoAdd(lpft->m_FormulaBar.m_hWnd, GIZMOTYPE_SEPARATOR, uPos++, 0, dx/2, dy, NULL, NULL, 0, GIZMO_NORMAL);
  178. // Line edit line, Cancel
  179. GBGizmoAdd(lpft->m_FormulaBar.m_hWnd, GIZMOTYPE_BUTTONCOMMAND, uPos++, IDM_L_EDITLINE, dx, dy, NULL, lpft->m_hBmp, IDB_EDITLINE, GIZMO_NORMAL);
  180. GBGizmoAdd(lpft->m_FormulaBar.m_hWnd, GIZMOTYPE_BUTTONCOMMAND, uPos++, IDM_FB_CANCEL, dx, dy, NULL, lpft->m_hBmp, IDB_CANCEL, GIZMO_NORMAL);
  181. // separator
  182. GBGizmoAdd(lpft->m_FormulaBar.m_hWnd, GIZMOTYPE_SEPARATOR, uPos++, 0, dx/2, dy, NULL, NULL, 0, GIZMO_NORMAL);
  183. // Edit control for line input
  184. GBGizmoAdd(lpft->m_FormulaBar.m_hWnd, GIZMOTYPE_EDIT, uPos++, IDM_FB_EDIT, dx*10, lpft->m_tdd.cyBar-5, NULL, NULL, 0, GIZMO_NORMAL);
  185. SendMessage(lpft->m_FormulaBar.m_hWnd, WM_SETREDRAW, TRUE, 0L);
  186. // Limit the text lenght of edit control
  187. GBGizmoSendMessage(lpft->m_FormulaBar.m_hWnd, IDM_FB_EDIT, EM_LIMITTEXT,
  188. (WPARAM)MAXSTRLEN, 0L);
  189. //Set the GizmoBar's associate to be this client window
  190. GBHwndAssociateSet(lpft->m_ButtonBar.m_hWnd, hWndParent);
  191. //Set the FormulaBar's associate to be this client window
  192. GBHwndAssociateSet(lpft->m_FormulaBar.m_hWnd, hWndParent);
  193. return TRUE;
  194. }
  195. void FrameTools_AttachToFrame(LPFRAMETOOLS lpft, HWND hWndFrame)
  196. {
  197. if (! lpft)
  198. return;
  199. if (hWndFrame == NULL)
  200. hWndFrame = OutlineApp_GetFrameWindow((LPOUTLINEAPP)g_lpApp);
  201. if (lpft->m_hWndApp == hWndFrame)
  202. return; // already have this parent frame
  203. lpft->m_hWndApp = hWndFrame;
  204. /* parent the tool bars to the frame so we can safely
  205. ** destroy/recreate the palette window.
  206. */
  207. SetParent(lpft->m_ButtonBar.m_hWnd, hWndFrame);
  208. SetParent(lpft->m_FormulaBar.m_hWnd, hWndFrame);
  209. // recreate popup palette so that it is owned by the hWndFrame
  210. FrameTools_CreatePopupPalette(lpft, hWndFrame);
  211. // restore the correct parent for the tool bars
  212. FrameTools_BB_SetState(lpft, lpft->m_ButtonBar.m_nState);
  213. FrameTools_FB_SetState(lpft, lpft->m_FormulaBar.m_nState);
  214. }
  215. void FrameTools_AssociateDoc(LPFRAMETOOLS lpft, LPOUTLINEDOC lpOutlineDoc)
  216. {
  217. HWND hWnd = OutlineDoc_GetWindow(lpOutlineDoc);
  218. if (! lpft)
  219. return;
  220. // if no Doc is given, then associate with the App's frame window.
  221. if (lpOutlineDoc)
  222. hWnd = OutlineDoc_GetWindow(lpOutlineDoc);
  223. else
  224. hWnd = OutlineApp_GetWindow((LPOUTLINEAPP)g_lpApp);
  225. //Set the GizmoBar's associate to be this client window
  226. GBHwndAssociateSet(lpft->m_ButtonBar.m_hWnd, hWnd);
  227. //Set the FormulaBar's associate to be this client window
  228. GBHwndAssociateSet(lpft->m_FormulaBar.m_hWnd, hWnd);
  229. }
  230. /*
  231. * FrameTools_Destroy
  232. *
  233. * Purpose:
  234. * Destroy the toolbar
  235. *
  236. * Parameters:
  237. * lpft FrameTools object
  238. *
  239. * Return Value:
  240. * nil
  241. */
  242. void FrameTools_Destroy(LPFRAMETOOLS lpft)
  243. {
  244. if (!lpft)
  245. return;
  246. if (IsWindow(lpft->m_ButtonBar.m_hWnd))
  247. DestroyWindow(lpft->m_ButtonBar.m_hWnd);
  248. if (IsWindow(lpft->m_FormulaBar.m_hWnd))
  249. DestroyWindow(lpft->m_FormulaBar.m_hWnd);
  250. if (IsWindow(lpft->m_hWndPopupPalette))
  251. DestroyWindow(lpft->m_hWndPopupPalette);
  252. if (lpft->m_hBmp)
  253. DeleteObject(lpft->m_hBmp);
  254. }
  255. /*
  256. * FrameTools_Move
  257. *
  258. * Purpose:
  259. * Move and resize the toolbar
  260. *
  261. * Parameters:
  262. * lpft FrameTools object
  263. * lprc Pointer to client rectangle
  264. *
  265. * Return Value:
  266. * nil
  267. */
  268. void FrameTools_Move(LPFRAMETOOLS lpft, LPRECT lprcClient)
  269. {
  270. RECT rcPopup;
  271. LPRECT lprcPopup = (LPRECT)&rcPopup;
  272. int nCmdShow = SW_HIDE;
  273. if (!lpft || lpft->m_fToolsDisabled)
  274. return;
  275. lprcPopup->left = 0;
  276. lprcPopup->top = 0;
  277. lprcPopup->right = lpft->m_uPopupWidth;
  278. lprcPopup->bottom = lpft->m_ButtonBar.m_uHeight +
  279. lpft->m_FormulaBar.m_uHeight;
  280. switch (lpft->m_ButtonBar.m_nState) {
  281. case BARSTATE_HIDE:
  282. case BARSTATE_POPUP:
  283. case BARSTATE_TOP:
  284. Bar_Move(&lpft->m_ButtonBar, lprcClient, lprcPopup);
  285. Bar_Move(&lpft->m_FormulaBar, lprcClient, lprcPopup);
  286. break;
  287. case BARSTATE_BOTTOM:
  288. Bar_Move(&lpft->m_FormulaBar, lprcClient, lprcPopup);
  289. Bar_Move(&lpft->m_ButtonBar, lprcClient, lprcPopup);
  290. break;
  291. }
  292. if (lprcPopup->top) {
  293. SetWindowPos(lpft->m_hWndPopupPalette, NULL, 0, 0, lprcPopup->right,
  294. lprcPopup->top + GetSystemMetrics(SM_CYCAPTION),
  295. SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_SHOWWINDOW);
  296. }
  297. else
  298. ShowWindow(lpft->m_hWndPopupPalette, SW_HIDE);
  299. FB_ResizeEdit(&lpft->m_FormulaBar);
  300. InvalidateRect(lpft->m_ButtonBar.m_hWnd, NULL, TRUE);
  301. InvalidateRect(lpft->m_FormulaBar.m_hWnd, NULL, TRUE);
  302. }
  303. /*
  304. * FrameTools_PopupTools
  305. *
  306. * Purpose:
  307. * Put both formula bar and button bar in Popup Window.
  308. *
  309. * Parameters:
  310. * lpft FrameTools object
  311. *
  312. * Return Value:
  313. * nil
  314. */
  315. void FrameTools_PopupTools(LPFRAMETOOLS lpft)
  316. {
  317. if (! lpft)
  318. return;
  319. FrameTools_BB_SetState(lpft, BARSTATE_POPUP);
  320. FrameTools_FB_SetState(lpft, BARSTATE_POPUP);
  321. FrameTools_Move(lpft, NULL);
  322. }
  323. /*
  324. * FrameTools_Enable
  325. *
  326. * Purpose:
  327. * Enable/Disable(hide) all the tools of the toolbar.
  328. * this will hide both the buttonbar and the
  329. * formulabar independent of whether they are floating or anchored.
  330. *
  331. * Parameters:
  332. * lpft FrameTools object
  333. * fEnable
  334. *
  335. * Return Value:
  336. * nil
  337. */
  338. void FrameTools_Enable(LPFRAMETOOLS lpft, BOOL fEnable)
  339. {
  340. lpft->m_fToolsDisabled = !fEnable;
  341. if (lpft->m_fToolsDisabled) {
  342. ShowWindow(lpft->m_hWndPopupPalette, SW_HIDE);
  343. ShowWindow(lpft->m_ButtonBar.m_hWnd, SW_HIDE);
  344. ShowWindow(lpft->m_FormulaBar.m_hWnd, SW_HIDE);
  345. }
  346. }
  347. /*
  348. * FrameTools_EnableWindow
  349. *
  350. * Purpose:
  351. * EnableWindow for all the tools of the toolbar.
  352. * this enables/disables mouse and keyboard input to the tools.
  353. * while a modal dialog is up, it is inportant to disable the
  354. * floating tool windows.
  355. * this will NOT hide any windows; it will only call EnableWindow.
  356. *
  357. * Parameters:
  358. * lpft FrameTools object
  359. * fEnable
  360. *
  361. * Return Value:
  362. * nil
  363. */
  364. void FrameTools_EnableWindow(LPFRAMETOOLS lpft, BOOL fEnable)
  365. {
  366. EnableWindow(lpft->m_hWndPopupPalette, fEnable);
  367. EnableWindow(lpft->m_ButtonBar.m_hWnd, fEnable);
  368. EnableWindow(lpft->m_FormulaBar.m_hWnd, fEnable);
  369. }
  370. #if defined( INPLACE_CNTR ) || defined( INPLACE_SVR )
  371. /*
  372. * FrameTools_NegotiateForSpaceAndShow
  373. *
  374. * Purpose:
  375. * Negotiate for space for the toolbar tools with the given frame window.
  376. * and make them visible.
  377. * Negotiation steps:
  378. * 1. try to get enough space at top/bottom of window
  379. * 2. float the tools as a palette if space not available
  380. *
  381. * Parameters:
  382. * lpft FrameTools object
  383. *
  384. * Return Value:
  385. * none
  386. */
  387. void FrameTools_NegotiateForSpaceAndShow(
  388. LPFRAMETOOLS lpft,
  389. LPRECT lprcFrameRect,
  390. LPOLEINPLACEFRAME lpTopIPFrame
  391. )
  392. {
  393. BORDERWIDTHS borderwidths;
  394. RECT rectBorder;
  395. HRESULT hrErr;
  396. if (lprcFrameRect)
  397. rectBorder = *lprcFrameRect;
  398. else {
  399. /* OLE2NOTE: by calling GetBorder, the server can find out the
  400. ** size of the frame window. it can use this information to
  401. ** make decisions about how to orient/organize it tools (eg.
  402. ** if window is taller than wide put tools vertically at
  403. ** left edge).
  404. */
  405. OLEDBG_BEGIN2("IOleInPlaceFrame::GetBorder called\r\n")
  406. hrErr = lpTopIPFrame->lpVtbl->GetBorder(
  407. lpTopIPFrame,
  408. (LPRECT)&rectBorder
  409. );
  410. OLEDBG_END2
  411. }
  412. /* Try SetBorderSpace() with the space that you need. If it fails then
  413. ** you can negotiate for space and then do the SetBorderSpace().
  414. */
  415. FrameTools_GetRequiredBorderSpace(lpft,(LPBORDERWIDTHS)&borderwidths);
  416. OLEDBG_BEGIN2("IOleInPlaceFrame::SetBorderSpace called\r\n")
  417. hrErr = lpTopIPFrame->lpVtbl->SetBorderSpace(
  418. lpTopIPFrame,
  419. (LPCBORDERWIDTHS)&borderwidths
  420. );
  421. OLEDBG_END2
  422. #if defined( LATER )
  423. if (hrErr != NOERROR) {
  424. /* Frame did not give the toolsspace that we want. So negotiate */
  425. // REVIEW: try a different placement of the tools here
  426. OLEDBG_BEGIN2("IOleInPlaceFrame::RequestBorderSpace called\r\n")
  427. hrErr = lpTopIPFrame->lpVtbl->RequestBorderSpace(
  428. lpTopIPFrame,
  429. (LPCBORDERWIDTHS)&borderwidths
  430. );
  431. OLEDBG_END2
  432. if (hrErr == NOERROR) {
  433. OLEDBG_BEGIN2("IOleInPlaceFrame::SetBorderSpace called\r\n")
  434. hrErr = lpTopIPFrame->lpVtbl->SetBorderSpace(
  435. lpTopIPFrame,
  436. (LPCBORDERWIDTHS)&borderwidths
  437. );
  438. OLEDBG_END2
  439. }
  440. }
  441. #endif
  442. if (hrErr == NOERROR) {
  443. FrameTools_Move(lpft, (LPRECT)&rectBorder); // we got what we wanted
  444. } else {
  445. /* We did not get tool space, so POP them up.
  446. /* OLE2NOTE: since we are poping up our tools, we MUST inform
  447. ** the top in-place frame window that we need NO tool space
  448. ** BUT that it should NOT put its own tools up. if we were
  449. ** to pass NULL instead of (0,0,0,0), then the container
  450. ** would have the option to leave its own tools up.
  451. */
  452. OLEDBG_BEGIN2("IOleInPlaceFrame::SetBorderSpace(NULL) called\r\n")
  453. hrErr = lpTopIPFrame->lpVtbl->SetBorderSpace(
  454. lpTopIPFrame,
  455. (LPCBORDERWIDTHS)&g_rectNull
  456. );
  457. OLEDBG_END2
  458. FrameTools_PopupTools(lpft);
  459. }
  460. }
  461. #endif // INPLACE_CNTR || INPLACE_SVR
  462. /*
  463. * FrameTools_GetRequiredBorderSpace
  464. *
  465. * Purpose:
  466. * Calculate the desired space for the toolbar tools.
  467. *
  468. * Parameters:
  469. * lpft FrameTools object
  470. * lpBorderWidths Widths required at top,bottom,left,right
  471. *
  472. * Return Value:
  473. * nil
  474. */
  475. void FrameTools_GetRequiredBorderSpace(LPFRAMETOOLS lpft, LPBORDERWIDTHS lpBorderWidths)
  476. {
  477. *lpBorderWidths = g_rectNull;
  478. switch (lpft->m_ButtonBar.m_nState) {
  479. case BARSTATE_TOP:
  480. lpBorderWidths->top += lpft->m_ButtonBar.m_uHeight;
  481. break;
  482. case BARSTATE_BOTTOM:
  483. lpBorderWidths->bottom += lpft->m_ButtonBar.m_uHeight;
  484. break;
  485. }
  486. switch (lpft->m_FormulaBar.m_nState) {
  487. case BARSTATE_TOP:
  488. lpBorderWidths->top += lpft->m_FormulaBar.m_uHeight;
  489. break;
  490. case BARSTATE_BOTTOM:
  491. lpBorderWidths->bottom += lpft->m_FormulaBar.m_uHeight;
  492. break;
  493. }
  494. }
  495. /*
  496. * FrameTools_UpdateButtons
  497. *
  498. * Purpose:
  499. * Enable/disable individual buttons of the toolbar according to the
  500. * state of the app
  501. *
  502. * Parameters:
  503. * lpft FrameTools object
  504. *
  505. * Return Value:
  506. * nil
  507. */
  508. void FrameTools_UpdateButtons(LPFRAMETOOLS lpft, LPOUTLINEDOC lpOutlineDoc)
  509. {
  510. BOOL fEnable;
  511. #if defined( OLE_VERSION )
  512. LPDATAOBJECT lpClipboardDataObj;
  513. HRESULT hrErr;
  514. LPOLEAPP lpOleApp = (LPOLEAPP)g_lpApp;
  515. BOOL fPrevEnable1;
  516. BOOL fPrevEnable2;
  517. #endif
  518. if (!lpft)
  519. return;
  520. #if defined( INPLACE_CNTR )
  521. {
  522. LPCONTAINERDOC lpContainerDoc = (LPCONTAINERDOC)lpOutlineDoc;
  523. if (lpContainerDoc->m_lpLastUIActiveLine &&
  524. lpContainerDoc->m_lpLastUIActiveLine->m_fUIActive) {
  525. /* if there is a UIActive object, then we should disable
  526. ** all of our "active editor" commands. we should enable
  527. ** only those commands that are "workspace" commands.
  528. */
  529. if (lpft->m_FormulaBar.m_nState != BARSTATE_HIDE) {
  530. GBGizmoEnable(lpft->m_FormulaBar.m_hWnd,IDM_L_EDITLINE,FALSE);
  531. GBGizmoEnable(lpft->m_FormulaBar.m_hWnd,IDM_L_ADDLINE,FALSE);
  532. GBGizmoEnable(lpft->m_FormulaBar.m_hWnd,IDM_FB_CANCEL,FALSE);
  533. GBGizmoEnable(lpft->m_FormulaBar.m_hWnd,IDM_L_EDITLINE,FALSE);
  534. }
  535. if (lpft->m_ButtonBar.m_nState != BARSTATE_HIDE)
  536. {
  537. GBGizmoEnable(lpft->m_ButtonBar.m_hWnd, IDM_E_CUT, FALSE);
  538. GBGizmoEnable(lpft->m_ButtonBar.m_hWnd, IDM_E_COPY, FALSE);
  539. GBGizmoEnable(lpft->m_ButtonBar.m_hWnd, IDM_E_PASTE, FALSE);
  540. GBGizmoEnable(lpft->m_ButtonBar.m_hWnd,IDM_L_INDENTLINE,FALSE);
  541. GBGizmoEnable(lpft->m_ButtonBar.m_hWnd, IDM_L_UNINDENTLINE, FALSE);
  542. GBGizmoEnable(lpft->m_ButtonBar.m_hWnd, IDM_H_ABOUT, FALSE);
  543. GBGizmoEnable(lpft->m_ButtonBar.m_hWnd, IDM_FB_EDIT, FALSE);
  544. GBGizmoEnable(lpft->m_ButtonBar.m_hWnd, IDM_F_NEW, TRUE);
  545. GBGizmoEnable(lpft->m_ButtonBar.m_hWnd, IDM_F_OPEN, TRUE);
  546. GBGizmoEnable(lpft->m_ButtonBar.m_hWnd, IDM_F_SAVE, TRUE);
  547. }
  548. return;
  549. }
  550. }
  551. #endif // INPLACE_CNTR
  552. fEnable = (BOOL)OutlineDoc_GetLineCount(lpOutlineDoc);
  553. if (lpft->m_FormulaBar.m_nState != BARSTATE_HIDE) {
  554. GBGizmoEnable(lpft->m_FormulaBar.m_hWnd, IDM_L_EDITLINE, fEnable);
  555. if (! lpft->m_fInFormulaBar) {
  556. GBGizmoEnable(lpft->m_FormulaBar.m_hWnd, IDM_L_ADDLINE, FALSE);
  557. GBGizmoEnable(lpft->m_FormulaBar.m_hWnd, IDM_FB_CANCEL, FALSE);
  558. GBGizmoEnable(lpft->m_FormulaBar.m_hWnd, IDM_L_EDITLINE, FALSE);
  559. if (!fEnable) {
  560. GBGizmoTextSet(lpft->m_FormulaBar.m_hWnd, IDM_FB_EDIT, "");
  561. }
  562. } else {
  563. GBGizmoEnable(lpft->m_FormulaBar.m_hWnd, IDM_L_ADDLINE, TRUE);
  564. GBGizmoEnable(lpft->m_FormulaBar.m_hWnd, IDM_FB_CANCEL, TRUE);
  565. }
  566. }
  567. if (lpft->m_ButtonBar.m_nState != BARSTATE_HIDE)
  568. {
  569. GBGizmoEnable(lpft->m_ButtonBar.m_hWnd, IDM_E_CUT, fEnable);
  570. GBGizmoEnable(lpft->m_ButtonBar.m_hWnd, IDM_E_COPY, fEnable);
  571. GBGizmoEnable(lpft->m_ButtonBar.m_hWnd, IDM_L_INDENTLINE, fEnable);
  572. GBGizmoEnable(lpft->m_ButtonBar.m_hWnd, IDM_L_UNINDENTLINE, fEnable);
  573. #if defined( OLE_SERVER )
  574. {
  575. LPSERVERDOC lpServerDoc = (LPSERVERDOC)lpOutlineDoc;
  576. #if defined( INPLACE_SVR )
  577. fEnable = ((lpServerDoc->m_fUIActive) ? FALSE : TRUE);
  578. #else
  579. fEnable = (lpOutlineDoc->m_docInitType != DOCTYPE_EMBEDDED);
  580. #endif // INPLACE_SVR
  581. GBGizmoEnable(lpft->m_ButtonBar.m_hWnd, IDM_F_NEW, fEnable);
  582. GBGizmoEnable(lpft->m_ButtonBar.m_hWnd, IDM_F_OPEN, fEnable);
  583. GBGizmoEnable(lpft->m_ButtonBar.m_hWnd, IDM_F_SAVE, fEnable);
  584. }
  585. #endif // OLE_SERVER
  586. #if defined( OLE_VERSION )
  587. /* OLE2NOTE: we do not want to ever give the busy dialog when we
  588. ** are trying to enable or disable our tool bar buttons eg.
  589. ** even if the source of data on the clipboard is busy, we do
  590. ** not want put up the busy dialog. thus we will disable the
  591. ** dialog and at the end re-enable it.
  592. */
  593. OleApp_DisableBusyDialogs(lpOleApp, &fPrevEnable1, &fPrevEnable2);
  594. /* OLE2NOTE: perform OLE specific menu initialization.
  595. ** the OLE versions use the OleGetClipboard mechanism for
  596. ** clipboard handling. thus, they determine if the Paste
  597. ** command should be enabled in an OLE specific manner.
  598. */
  599. fEnable = FALSE;
  600. hrErr = OleGetClipboard((LPDATAOBJECT FAR*)&lpClipboardDataObj);
  601. if (hrErr == NOERROR) {
  602. int nFmtEtc;
  603. nFmtEtc = OleStdGetPriorityClipboardFormat(
  604. lpClipboardDataObj,
  605. lpOleApp->m_arrPasteEntries,
  606. lpOleApp->m_nPasteEntries
  607. );
  608. fEnable = (nFmtEtc >= 0); // there IS a format we like
  609. OleStdRelease((LPUNKNOWN)lpClipboardDataObj);
  610. }
  611. // re-enable the busy dialog
  612. OleApp_EnableBusyDialogs(lpOleApp, fPrevEnable1, fPrevEnable2);
  613. GBGizmoEnable(lpft->m_ButtonBar.m_hWnd, IDM_E_PASTE, fEnable);
  614. #else
  615. // Base Outline version uses standard Windows clipboard handling
  616. if(IsClipboardFormatAvailable(g_lpApp->m_cfOutline) ||
  617. IsClipboardFormatAvailable(CF_TEXT))
  618. GBGizmoEnable(lpft->m_ButtonBar.m_hWnd, IDM_E_PASTE, TRUE);
  619. else
  620. GBGizmoEnable(lpft->m_ButtonBar.m_hWnd, IDM_E_PASTE, FALSE);
  621. #endif // OLE_VERSION
  622. }
  623. }
  624. /*
  625. * FrameTools_FB_SetEditText
  626. *
  627. * Purpose:
  628. * Set text in the edit control in FormulaBar
  629. *
  630. * Parameters:
  631. * lpft FrameTools object
  632. * lpsz pointer to string to be set
  633. *
  634. * Return Value:
  635. * nil
  636. */
  637. void FrameTools_FB_SetEditText(LPFRAMETOOLS lpft, LPSTR lpsz)
  638. {
  639. GBGizmoTextSet(lpft->m_FormulaBar.m_hWnd, IDM_FB_EDIT, lpsz);
  640. }
  641. /*
  642. * FrameTools_FB_GetEditText
  643. *
  644. * Purpose:
  645. * Get text from the edit control in FormulaBar
  646. *
  647. * Parameters:
  648. * lpft FrameTools object
  649. * lpsz pointer to buffer to receive the text
  650. * cch buffer size
  651. *
  652. * Return Value:
  653. * nil
  654. */
  655. void FrameTools_FB_GetEditText(LPFRAMETOOLS lpft, LPSTR lpsz, UINT cch)
  656. {
  657. GBGizmoTextGet(lpft->m_FormulaBar.m_hWnd, IDM_FB_EDIT, lpsz, cch);
  658. }
  659. /*
  660. * FrameTools_FB_FocusEdit
  661. *
  662. * Purpose:
  663. * Set the focus in the edit control of FormulaBar
  664. *
  665. * Parameters:
  666. * lpft FrameTools object
  667. *
  668. * Return Value:
  669. * nil
  670. */
  671. void FrameTools_FB_FocusEdit(LPFRAMETOOLS lpft)
  672. {
  673. GBGizmoFocusSet(lpft->m_FormulaBar.m_hWnd, IDM_FB_EDIT);
  674. // select the whole text in the edit control
  675. GBGizmoSendMessage(lpft->m_FormulaBar.m_hWnd, IDM_FB_EDIT, EM_SETSEL,
  676. (WPARAM)TRUE, MAKELPARAM(0, -1));
  677. }
  678. /*
  679. * FrameTools_FB_SendMessage
  680. *
  681. * Purpose:
  682. * Send a message to the FormulaBar window gizmo
  683. *
  684. * Parameters:
  685. * lpft FrameTools object
  686. * uID gizmo ID
  687. * msg
  688. * wParam
  689. * lParam
  690. *
  691. * Return Value:
  692. * nil
  693. */
  694. void FrameTools_FB_SendMessage(LPFRAMETOOLS lpft, UINT uID, UINT msg, WPARAM wParam, LPARAM lParam)
  695. {
  696. GBGizmoSendMessage(lpft->m_FormulaBar.m_hWnd, uID, msg, wParam, lParam);
  697. }
  698. /*
  699. * FrameTools_FB_ForceRedraw
  700. *
  701. * Purpose:
  702. * Force the toolbar to draw itself
  703. *
  704. * Parameters:
  705. * lpft FrameTools object
  706. *
  707. * Return Value:
  708. * nil
  709. */
  710. void FrameTools_ForceRedraw(LPFRAMETOOLS lpft)
  711. {
  712. InvalidateRect(lpft->m_ButtonBar.m_hWnd, NULL, TRUE);
  713. InvalidateRect(lpft->m_FormulaBar.m_hWnd, NULL, TRUE);
  714. InvalidateRect(lpft->m_hWndPopupPalette, NULL, TRUE);
  715. }
  716. /*
  717. * FrameTools_BB_SetState
  718. *
  719. * Purpose:
  720. * Set display state of ButtonBar
  721. *
  722. * Parameters:
  723. * lpft FrameTools object
  724. * nState new display state
  725. *
  726. * Return Value:
  727. * nil
  728. */
  729. void FrameTools_BB_SetState(LPFRAMETOOLS lpft, int nState)
  730. {
  731. if (!lpft) {
  732. return;
  733. }
  734. lpft->m_ButtonBar.m_nState = nState;
  735. if (nState == BARSTATE_POPUP)
  736. SetParent(lpft->m_ButtonBar.m_hWnd, lpft->m_hWndPopupPalette);
  737. else
  738. SetParent(lpft->m_ButtonBar.m_hWnd, lpft->m_hWndApp);
  739. }
  740. /*
  741. * FrameTools_BB_GetState
  742. *
  743. * Purpose:
  744. * Get display state of ButtonBar
  745. *
  746. * Parameters:
  747. * lpft FrameTools object
  748. *
  749. * Return Value:
  750. * nState current display state
  751. */
  752. int FrameTools_BB_GetState(LPFRAMETOOLS lpft)
  753. {
  754. return lpft->m_ButtonBar.m_nState;
  755. }
  756. /*
  757. * FrameTools_FB_SetState
  758. *
  759. * Purpose:
  760. * Set display state of FormulaBar
  761. *
  762. * Parameters:
  763. * lpft FrameTools object
  764. * nState new display state
  765. *
  766. * Return Value:
  767. 4 * nil
  768. */
  769. void FrameTools_FB_SetState(LPFRAMETOOLS lpft, int nState)
  770. {
  771. if (!lpft) {
  772. return;
  773. }
  774. lpft->m_FormulaBar.m_nState = nState;
  775. if (nState == BARSTATE_POPUP)
  776. SetParent(lpft->m_FormulaBar.m_hWnd, lpft->m_hWndPopupPalette);
  777. #if defined( INPLACE_SVR )
  778. /* OLE2NOTE: it is dangerous for an in-place server to hide its
  779. ** toolbar window and leave it parented to the hWndFrame of the
  780. ** in-place container. if the in-place container call
  781. ** ShowOwnedPopups, then it could inadvertantly be made visible.
  782. ** to avoid this we will parent the toolbar window back to our
  783. ** own application main window. if we are not in-place active
  784. ** then this is the same as lpft->m_hWndApp.
  785. */
  786. else if (nState == BARSTATE_HIDE)
  787. SetParent(lpft->m_FormulaBar.m_hWnd, g_lpApp->m_hWndApp);
  788. #endif
  789. else
  790. SetParent(lpft->m_FormulaBar.m_hWnd, lpft->m_hWndApp);
  791. }
  792. /*
  793. * FrameTools_FB_GetState
  794. *
  795. * Purpose:
  796. * Get display state of FormulaBar
  797. *
  798. * Parameters:
  799. * lpft FrameTools object
  800. *
  801. * Return Value:
  802. * nState current display state
  803. */
  804. int FrameTools_FB_GetState(LPFRAMETOOLS lpft)
  805. {
  806. return lpft->m_FormulaBar.m_nState;
  807. }
  808. /*
  809. * FrameToolsWndProc
  810. *
  811. * Purpose:
  812. * WndProc for toolbar window
  813. *
  814. * Parameters:
  815. * hWnd
  816. * Message
  817. * wParam
  818. * lParam
  819. *
  820. * Return Value:
  821. * message dependent
  822. */
  823. LRESULT FAR PASCAL FrameToolsWndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
  824. {
  825. LPFRAMETOOLS lpft = (LPFRAMETOOLS)GetWindowLong(hWnd, 0);
  826. switch (Message) {
  827. case WM_MOUSEACTIVATE:
  828. return MA_NOACTIVATE;
  829. default:
  830. return DefWindowProc(hWnd, Message, wParam, lParam);
  831. }
  832. return 0L;
  833. }
  834. /*
  835. * Bar_Move
  836. *
  837. * Purpose:
  838. * Resize and reposition a bar
  839. *
  840. * Parameters:
  841. * lpbar Bar object
  842. * lprcClient pointer to Client rect
  843. * lprcPopup pointer to Popup rect
  844. *
  845. * Return Value:
  846. * nil
  847. */
  848. static void Bar_Move(LPBAR lpbar, LPRECT lprcClient, LPRECT lprcPopup)
  849. {
  850. if (lpbar->m_nState == BARSTATE_HIDE) {
  851. ShowWindow(lpbar->m_hWnd, SW_HIDE);
  852. }
  853. else {
  854. ShowWindow(lpbar->m_hWnd, SW_SHOW);
  855. switch (lpbar->m_nState) {
  856. case BARSTATE_POPUP:
  857. MoveWindow(lpbar->m_hWnd, lprcPopup->left, lprcPopup->top,
  858. lprcPopup->right - lprcPopup->left, lpbar->m_uHeight,
  859. TRUE);
  860. lprcPopup->top += lpbar->m_uHeight;
  861. break;
  862. case BARSTATE_TOP:
  863. MoveWindow(lpbar->m_hWnd, lprcClient->left, lprcClient->top,
  864. lprcClient->right - lprcClient->left,
  865. lpbar->m_uHeight, TRUE);
  866. lprcClient->top += lpbar->m_uHeight;
  867. break;
  868. case BARSTATE_BOTTOM:
  869. MoveWindow(lpbar->m_hWnd, lprcClient->left,
  870. lprcClient->bottom - lpbar->m_uHeight,
  871. lprcClient->right - lprcClient->left,
  872. lpbar->m_uHeight, TRUE);
  873. lprcClient->bottom -= lpbar->m_uHeight;
  874. break;
  875. }
  876. }
  877. }
  878. /*
  879. * FB_ResizeEdit
  880. *
  881. * Purpose:
  882. * Resize the edit control in FormulaBar
  883. *
  884. * Parameters:
  885. * lpft Bar object
  886. *
  887. * Return Value:
  888. * nil
  889. */
  890. static void FB_ResizeEdit(LPBAR lpbar)
  891. {
  892. RECT rcClient;
  893. RECT rcEdit;
  894. HWND hwndEdit;
  895. GetClientRect(lpbar->m_hWnd, (LPRECT)&rcClient);
  896. hwndEdit = GetDlgItem(lpbar->m_hWnd, IDM_FB_EDIT);
  897. GetWindowRect(hwndEdit, (LPRECT)&rcEdit);
  898. ScreenToClient(lpbar->m_hWnd, (LPPOINT)&rcEdit.left);
  899. ScreenToClient(lpbar->m_hWnd, (LPPOINT)&rcEdit.right);
  900. SetWindowPos(hwndEdit, NULL, 0, 0, rcClient.right - rcEdit.left - SPACE,
  901. rcEdit.bottom - rcEdit.top, SWP_NOMOVE | SWP_NOZORDER);
  902. }