Source code of Windows XP (NT5)
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.

6722 lines
162 KiB

  1. //
  2. // MWND.CPP
  3. // Main WB Window
  4. //
  5. // Copyright Microsoft 1998-
  6. //
  7. // PRECOMP
  8. #include "precomp.h"
  9. #include <dde.h>
  10. #include "version.h"
  11. #include "nmwbobj.h"
  12. static const TCHAR s_cszHtmlHelpFile[] = TEXT("nmwhiteb.chm");
  13. // Class name
  14. TCHAR szMainClassName[] = "T126WBMainWindowClass";
  15. extern TCHAR g_PassedFileName[];
  16. //
  17. // Scroll accelerators
  18. //
  19. typedef struct tagSCROLL
  20. {
  21. UINT uiMenuId;
  22. UINT uiMessage;
  23. UINT uiScrollCode;
  24. }
  25. SCROLL;
  26. static const SCROLL s_MenuToScroll[] =
  27. {
  28. { IDM_PAGEUP, WM_VSCROLL, SB_PAGEUP },
  29. { IDM_PAGEDOWN, WM_VSCROLL, SB_PAGEDOWN },
  30. { IDM_SHIFTPAGEUP, WM_HSCROLL, SB_PAGEUP },
  31. { IDM_SHIFTPAGEDOWN, WM_HSCROLL, SB_PAGEDOWN },
  32. { IDM_HOME, WM_HSCROLL, SB_TOP },
  33. { IDM_HOME, WM_VSCROLL, SB_TOP },
  34. { IDM_END, WM_HSCROLL, SB_BOTTOM },
  35. { IDM_END, WM_VSCROLL, SB_BOTTOM },
  36. { IDM_LINEUP, WM_VSCROLL, SB_LINEUP },
  37. { IDM_LINEDOWN, WM_VSCROLL, SB_LINEDOWN },
  38. { IDM_SHIFTLINEUP, WM_HSCROLL, SB_LINEUP },
  39. { IDM_SHIFTLINEDOWN, WM_HSCROLL, SB_LINEDOWN }
  40. };
  41. // tooltip data
  42. // check codes
  43. #define NA 0 // dont't check checked state
  44. #define TB 1 // check toolbar for checked state
  45. #define BT 2 // check tipped wnd (a button) for checked state
  46. typedef struct
  47. {
  48. UINT nID;
  49. UINT nCheck;
  50. UINT nUpTipID;
  51. UINT nDownTipID;
  52. }
  53. TIPIDS;
  54. TIPIDS g_tipIDsArray[] =
  55. {
  56. {IDM_SELECT, TB, IDS_HINT_SELECT, IDS_HINT_SELECT},
  57. {IDM_ERASER, TB, IDS_HINT_ERASER, IDS_HINT_ERASER},
  58. {IDM_TEXT, TB, IDS_HINT_TEXT, IDS_HINT_TEXT},
  59. {IDM_HIGHLIGHT, TB, IDS_HINT_HIGHLIGHT, IDS_HINT_HIGHLIGHT},
  60. {IDM_PEN, TB, IDS_HINT_PEN, IDS_HINT_PEN},
  61. {IDM_LINE, TB, IDS_HINT_LINE, IDS_HINT_LINE},
  62. {IDM_BOX, TB, IDS_HINT_BOX, IDS_HINT_BOX},
  63. {IDM_FILLED_BOX, TB, IDS_HINT_FBOX, IDS_HINT_FBOX},
  64. {IDM_ELLIPSE, TB, IDS_HINT_ELLIPSE, IDS_HINT_ELLIPSE},
  65. {IDM_FILLED_ELLIPSE, TB, IDS_HINT_FELLIPSE, IDS_HINT_FELLIPSE},
  66. {IDM_ZOOM, TB, IDS_HINT_ZOOM_UP, IDS_HINT_ZOOM_DOWN},
  67. {IDM_REMOTE, TB, IDS_HINT_REMOTE_UP, IDS_HINT_REMOTE_DOWN},
  68. {IDM_LOCK, TB, IDS_HINT_LOCK_UP, IDS_HINT_LOCK_DOWN},
  69. {IDM_SYNC, TB, IDS_HINT_SYNC_UP, IDS_HINT_SYNC_DOWN},
  70. {IDM_GRAB_AREA, TB, IDS_HINT_GRAB_AREA, IDS_HINT_GRAB_AREA},
  71. {IDM_GRAB_WINDOW, TB, IDS_HINT_GRAB_WINDOW, IDS_HINT_GRAB_WINDOW},
  72. {IDM_WIDTH_1, NA, IDS_HINT_WIDTH_1, IDS_HINT_WIDTH_1},
  73. {IDM_WIDTH_2, NA, IDS_HINT_WIDTH_2, IDS_HINT_WIDTH_2},
  74. {IDM_WIDTH_3, NA, IDS_HINT_WIDTH_3, IDS_HINT_WIDTH_3},
  75. {IDM_WIDTH_4, NA, IDS_HINT_WIDTH_4, IDS_HINT_WIDTH_4},
  76. {IDM_PAGE_FIRST, BT, IDS_HINT_PAGE_FIRST, IDS_HINT_PAGE_FIRST},
  77. {IDM_PAGE_PREV, BT, IDS_HINT_PAGE_PREVIOUS, IDS_HINT_PAGE_PREVIOUS},
  78. {IDM_PAGE_ANY, NA, IDS_HINT_PAGE_ANY, IDS_HINT_PAGE_ANY},
  79. {IDM_PAGE_NEXT, BT, IDS_HINT_PAGE_NEXT, IDS_HINT_PAGE_NEXT},
  80. {IDM_PAGE_LAST, BT, IDS_HINT_PAGE_LAST, IDS_HINT_PAGE_LAST},
  81. {IDM_PAGE_INSERT_AFTER, BT, IDS_HINT_PAGE_INSERT, IDS_HINT_PAGE_INSERT}
  82. };
  83. ////////////
  84. HRESULT WbMainWindow::WB_LoadFile(LPCTSTR szFile)
  85. {
  86. //
  87. // If a file name was passed
  88. //
  89. if (szFile && g_pMain)
  90. {
  91. int cchLength;
  92. BOOL fSkippedQuote;
  93. // Skip past first quote
  94. if (fSkippedQuote = (*szFile == '"'))
  95. szFile++;
  96. cchLength = lstrlen(szFile);
  97. //
  98. // NOTE:
  99. // There may be DBCS implications with this. Hence we check to see
  100. // if we skipped the first quote; we assume that if the file name
  101. // starts with a quote it must end with one also. But we need to check
  102. // it out.
  103. //
  104. // Strip last quote
  105. if (fSkippedQuote && (cchLength > 0) && (szFile[cchLength - 1] == '"'))
  106. {
  107. BYTE * pLastQuote = (BYTE *)&szFile[cchLength - 1];
  108. TRACE_MSG(("Skipping last quote in file name %s", szFile));
  109. *pLastQuote = '\0';
  110. }
  111. g_pMain->OnOpen(szFile);
  112. }
  113. return S_OK;
  114. }
  115. void WbMainWindow::BringToFront(void)
  116. {
  117. if (NULL != m_hwnd)
  118. {
  119. int nCmdShow = SW_SHOW;
  120. WINDOWPLACEMENT wp;
  121. ::ZeroMemory(&wp, sizeof(wp));
  122. wp.length = sizeof(wp);
  123. if (::GetWindowPlacement(m_hwnd, &wp))
  124. {
  125. if (SW_MINIMIZE == wp.showCmd || SW_SHOWMINIMIZED == wp.showCmd)
  126. {
  127. // The window is minimized - restore it:
  128. nCmdShow = SW_RESTORE;
  129. }
  130. }
  131. // show the window now
  132. ::ShowWindow(m_hwnd, nCmdShow);
  133. // bring it to the foreground
  134. ::SetForegroundWindow(m_hwnd);
  135. }
  136. }
  137. //
  138. //
  139. // Function: WbMainWindow constructor
  140. //
  141. // Purpose: Create the main Whiteboard window. An exception is thrown
  142. // if an error occurs during construction.
  143. //
  144. //
  145. WbMainWindow::WbMainWindow(void)
  146. {
  147. OSVERSIONINFO OsData;
  148. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::WbMainWindow");
  149. //
  150. // Initialize member vars first!
  151. //
  152. ZeroMemory(m_ToolArray, sizeof(m_ToolArray));
  153. m_hwnd = NULL;
  154. m_hwndToolTip = NULL;
  155. ZeroMemory(&m_tiLastHit, sizeof(m_tiLastHit));
  156. m_nLastHit = -1;
  157. m_bInitOk = FALSE;
  158. m_bDisplayingError = FALSE;
  159. m_hwndSB = NULL;
  160. m_bStatusBarOn = TRUE;
  161. m_bToolBarOn = TRUE;
  162. // Load the main accelerator table
  163. m_hAccelTable =
  164. ::LoadAccelerators(g_hInstance, MAKEINTRESOURCE(MAINACCELTABLE));
  165. m_hwndQuerySaveDlg = NULL;
  166. m_hwndWaitForEventDlg = NULL;
  167. m_hwndWaitForLockDlg = NULL;
  168. m_pCurrentTool = NULL;
  169. ZeroMemory(m_strFileName, sizeof(m_strFileName));
  170. m_pTitleFileName = NULL;
  171. // Load the alternative accelerator table for the pages edit
  172. // field and text editor
  173. m_hAccelPagesGroup =
  174. ::LoadAccelerators(g_hInstance, MAKEINTRESOURCE(PAGESGROUPACCELTABLE));
  175. m_hAccelTextEdit =
  176. ::LoadAccelerators(g_hInstance, MAKEINTRESOURCE(TEXTEDITACCELTABLE));
  177. // Show that we are not yet in a call
  178. m_uiSubState = SUBSTATE_IDLE;
  179. // We are not currently displaying a menu
  180. m_hContextMenuBar = NULL;
  181. m_hContextMenu = NULL;
  182. m_hGrobjContextMenuBar = NULL;
  183. m_hGrobjContextMenu = NULL;
  184. m_bInSaveDialog = FALSE;
  185. m_bSelectAllInProgress = FALSE;
  186. m_bUnlockStateSettled = TRUE;
  187. m_bQuerySysShutdown = FALSE;
  188. // figure out if we're on Win95
  189. m_bIsWin95 = FALSE;
  190. OsData.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  191. if( GetVersionEx( &OsData ) )
  192. {
  193. if( OsData.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS )
  194. m_bIsWin95 = TRUE;
  195. }
  196. m_cancelModeSent = FALSE;
  197. //
  198. // We only do this once for the lifetime of the DLL. There is no
  199. // way really to clean up registered window messages, and each register
  200. // bumps up a ref count. If we registered each time WB was started up
  201. // during one session of CONF, we'd overflow the refcount.
  202. //
  203. if (!g_uConfShutdown)
  204. {
  205. g_uConfShutdown = ::RegisterWindowMessage( NM_ENDSESSION_MSG_NAME );
  206. }
  207. m_pLocalRemotePointer = NULL;
  208. m_localRemotePointerPosition.x = -50;
  209. m_localRemotePointerPosition.y = -50;
  210. }
  211. //
  212. // Open()
  213. // Do Main window initialization (stuff that can fail). After this,
  214. // the run code will try to join the current domain and do message loop
  215. // stuff.
  216. //
  217. BOOL WbMainWindow::Open(int iCommand)
  218. {
  219. WNDCLASSEX wc;
  220. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::Open");
  221. //
  222. // CREATE OTHER GLOBALS
  223. //
  224. if (!InitToolArray())
  225. {
  226. ERROR_OUT(("Can't create tools; failing to start up"));
  227. return(FALSE);
  228. }
  229. //
  230. // Init comon controls
  231. //
  232. InitCommonControls();
  233. //
  234. // CREATE THE MAIN FRAME WINDOW
  235. //
  236. ASSERT(!m_hwnd);
  237. //
  238. // Get the class info for it, and change the name.
  239. //
  240. ZeroMemory(&wc, sizeof(wc));
  241. wc.cbSize = sizeof(wc);
  242. wc.style = CS_DBLCLKS; // CS_HREDRAW | CS_VREDRAW?
  243. wc.lpfnWndProc = WbMainWindowProc;
  244. wc.hInstance = g_hInstance;
  245. wc.hIcon = ::LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_APP));
  246. wc.hCursor = ::LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
  247. wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
  248. wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU_WB_WITHFILE);
  249. wc.lpszClassName = szMainClassName;
  250. if (!::RegisterClassEx(&wc))
  251. {
  252. ERROR_OUT(("Can't register private frame window class"));
  253. return(FALSE);
  254. }
  255. // Create the main drawing window.
  256. if (!::CreateWindowEx(WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, szMainClassName,
  257. NULL, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
  258. CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, g_hInstance, this))
  259. {
  260. // Could not create the main window
  261. ERROR_OUT(("Failed to create main window"));
  262. return(FALSE);
  263. }
  264. ASSERT(m_hwnd);
  265. //
  266. // Create the pop-up context menu
  267. //
  268. if (!CreateContextMenus())
  269. {
  270. ERROR_OUT(("Failed to create context menus"));
  271. return(FALSE);
  272. }
  273. //
  274. // Register the the main window for Drag/Drop messages.
  275. //
  276. DragAcceptFiles(m_hwnd, TRUE);
  277. //
  278. // CREATE THE CHILD WINDOWS
  279. //
  280. // Create the drawing pane
  281. // (the Create call throws an exception on error)
  282. RECT clientRect;
  283. RECT drawingAreaRect;
  284. ::GetClientRect(m_hwnd, &clientRect);
  285. drawingAreaRect.top=0;
  286. drawingAreaRect.bottom = DRAW_HEIGHT;
  287. drawingAreaRect.left = 0;
  288. drawingAreaRect.right = DRAW_WIDTH;
  289. // Every control in the main window has a border on it, so increase the
  290. // client size by 1 to force these borders to be drawn under the inside
  291. // black line in the window frame. This prevents a 2 pel wide border
  292. // being drawn
  293. ::InflateRect(&clientRect, 1, 1);
  294. SIZE sizeAG;
  295. m_AG.GetNaturalSize(&sizeAG);
  296. if (!m_drawingArea.Create(m_hwnd, &drawingAreaRect))
  297. {
  298. ERROR_OUT(("Failed to create drawing area"));
  299. return(FALSE);
  300. }
  301. //
  302. // Create the toolbar
  303. //
  304. if (!m_TB.Create(m_hwnd))
  305. {
  306. ERROR_OUT(("Failed to create tool window"));
  307. return(FALSE);
  308. }
  309. //
  310. // Create the attributes group
  311. // The attributes group is on the bottom, underneath the
  312. // drawing area, above the status bar.
  313. //
  314. RECT rectAG;
  315. rectAG.left = clientRect.left;
  316. rectAG.right = clientRect.right;
  317. rectAG.top = drawingAreaRect.bottom;
  318. rectAG.bottom = rectAG.top + sizeAG.cy;
  319. if (!m_AG.Create(m_hwnd, &rectAG))
  320. {
  321. ERROR_OUT(("Failed to create attributes group window"));
  322. return(FALSE);
  323. }
  324. //
  325. // Create the widths group.
  326. // The widths group is on the left side, underneath the tools group
  327. //
  328. SIZE sizeWG;
  329. RECT rectWG;
  330. // The widths group is on the left side, underneath the toolbar
  331. m_WG.GetNaturalSize(&sizeWG);
  332. rectWG.left = 0;
  333. rectWG.right = rectWG.left + sizeWG.cx;
  334. rectWG.bottom = rectAG.top;
  335. rectWG.top = rectWG.bottom - sizeWG.cy;
  336. if (!m_WG.Create(m_hwnd, &rectWG))
  337. {
  338. ERROR_OUT(("Failed to create widths group window"));
  339. return(FALSE);
  340. }
  341. //
  342. // Create the status bar
  343. //
  344. m_hwndSB = ::CreateWindowEx(0, STATUSCLASSNAME, NULL,
  345. WS_CHILD | WS_VISIBLE | CCS_NOPARENTALIGN | CCS_NOMOVEY |
  346. CCS_NORESIZE | SBARS_SIZEGRIP,
  347. clientRect.left, clientRect.bottom - STATUSBAR_HEIGHT,
  348. (clientRect.right - clientRect.left), STATUSBAR_HEIGHT,
  349. m_hwnd, 0, g_hInstance, NULL);
  350. if (!m_hwndSB)
  351. {
  352. ERROR_OUT(("Failed to create status bar window"));
  353. return(FALSE);
  354. }
  355. // Initialize the color, width and tool menus
  356. InitializeMenus();
  357. m_currentMenuTool = IDM_SELECT;
  358. m_pCurrentTool = m_ToolArray[TOOL_INDEX(IDM_SELECT)];
  359. OnSelectTool(m_currentMenuTool);
  360. m_hwndToolTip = ::CreateWindowEx(NULL, TOOLTIPS_CLASS, NULL,
  361. WS_POPUP | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT,
  362. CW_USEDEFAULT, CW_USEDEFAULT, m_hwnd, NULL, g_hInstance, NULL);
  363. if (!m_hwndToolTip)
  364. {
  365. ERROR_OUT(("Unable to create tooltip window"));
  366. return(FALSE);
  367. }
  368. // Add a dead-area tooltip
  369. TOOLINFO ti;
  370. ZeroMemory(&ti, sizeof(ti));
  371. ti.cbSize = sizeof(TOOLINFO);
  372. ti.uFlags = TTF_IDISHWND;
  373. ti.hwnd = m_hwnd;
  374. ti.uId = (UINT_PTR)m_hwnd;
  375. ::SendMessage(m_hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&ti);
  376. // Ensure the page buttons are disabled while starting
  377. UpdatePageButtons();
  378. // If this is the first time we have created a clipboard object,
  379. // register the private Whiteboard formats.
  380. if (g_ClipboardFormats[CLIPBOARD_PRIVATE] == 0)
  381. {
  382. g_ClipboardFormats[CLIPBOARD_PRIVATE] =
  383. (int) ::RegisterClipboardFormat("NMWT126");
  384. }
  385. m_bInitOk = TRUE;
  386. BOOL bSuccess = TRUE; // indicates whether window opened successfully
  387. // Get the position of the window from options
  388. RECT rectWindow;
  389. OPT_GetWindowRectOption(&rectWindow);
  390. ::MoveWindow(m_hwnd, rectWindow.left, rectWindow.top,
  391. rectWindow.right - rectWindow.left,
  392. rectWindow.bottom - rectWindow.top, FALSE );
  393. //
  394. // Inititalize the fake GCC handle, it will be used when we are not in a conference and need
  395. // handles for workspaces/drawings/bitmaps etc...
  396. //
  397. g_localGCCHandle = 1;
  398. //
  399. // Create a standard workspace
  400. //
  401. if(g_pCurrentWorkspace)
  402. {
  403. m_drawingArea.Attach(g_pCurrentWorkspace);
  404. }
  405. else
  406. {
  407. if(g_numberOfWorkspaces < WB_MAX_WORKSPACES)
  408. {
  409. m_drawingArea.Detach();
  410. WorkspaceObj * pObj;
  411. DBG_SAVE_FILE_LINE
  412. pObj = new WorkspaceObj();
  413. pObj->AddToWorkspace();
  414. g_pConferenceWorkspace = pObj;
  415. }
  416. }
  417. CheckMenuItem(IDM_STATUS_BAR_TOGGLE);
  418. CheckMenuItem(IDM_TOOL_BAR_TOGGLE);
  419. //
  420. // Start synced
  421. //
  422. Sync();
  423. if(!OPT_GetBooleanOption(OPT_MAIN_STATUSBARVISIBLE, DFLT_MAIN_STATUSBARVISIBLE))
  424. {
  425. OnStatusBarToggle();
  426. }
  427. if(!OPT_GetBooleanOption(OPT_MAIN_TOOLBARVISIBLE, DFLT_MAIN_TOOLBARVISIBLE))
  428. {
  429. OnToolBarToggle();
  430. }
  431. ::ShowWindow(m_hwnd, iCommand);
  432. ::UpdateWindow(m_hwnd);
  433. // Update the window title with no file name
  434. UpdateWindowTitle();
  435. // Return value indicating success or failure
  436. return(bSuccess);
  437. }
  438. //
  439. //
  440. // Function : OnMenuSelect
  441. //
  442. // Purpose : Update the text in the help bar
  443. //
  444. //
  445. void WbMainWindow::OnMenuSelect(UINT uiItemID, UINT uiFlags, HMENU hSysMenu)
  446. {
  447. UINT firstMenuId;
  448. UINT statusId;
  449. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnMenuSelect");
  450. //
  451. // Work out the help ID for the menu item. We have to store this now
  452. // because when the user presses F1 from a menu item, we can't tell
  453. // which item it was.
  454. //
  455. if ((uiFlags & MF_POPUP) && (uiFlags & MF_SYSMENU))
  456. {
  457. //
  458. // System menu selected
  459. //
  460. statusId = IDS_MENU_SYSTEM;
  461. }
  462. else if (uiFlags & MF_POPUP)
  463. {
  464. // get popup menu handle and first item (bug NM4db:463)
  465. HMENU hPopup = ::GetSubMenu( hSysMenu, uiItemID );
  466. firstMenuId = ::GetMenuItemID( hPopup, 0 );
  467. // figure out which popup it is so we can display the right help text
  468. switch (firstMenuId)
  469. {
  470. case IDM_NEW:
  471. statusId = IDS_MENU_FILE;
  472. break;
  473. case IDM_DELETE:
  474. statusId = IDS_MENU_EDIT;
  475. break;
  476. case IDM_TOOL_BAR_TOGGLE:
  477. statusId = IDS_MENU_VIEW;
  478. break;
  479. case IDM_EDITCOLOR:
  480. case IDM_TOOLS_START:
  481. statusId = IDS_MENU_TOOLS;
  482. break;
  483. case IDM_HELP:
  484. statusId = IDS_MENU_HELP;
  485. break;
  486. case IDM_WIDTH_1: // (added for bug NM4db:463)
  487. statusId = IDS_MENU_WIDTH;
  488. break;
  489. default:
  490. statusId = IDS_DEFAULT;
  491. break;
  492. }
  493. }
  494. else
  495. {
  496. //
  497. // A normal menu item has been selected
  498. //
  499. statusId = uiItemID;
  500. }
  501. // Set the new help text
  502. TCHAR szStatus[256];
  503. if (::LoadString(g_hInstance, statusId, szStatus, 256))
  504. {
  505. ::SetWindowText(m_hwndSB, szStatus);
  506. }
  507. }
  508. //
  509. // WbMainWindowProc()
  510. // Frame window message handler
  511. //
  512. LRESULT WbMainWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  513. {
  514. LRESULT lResult = 0;
  515. WbMainWindow * pMain;
  516. pMain = (WbMainWindow *)::GetWindowLongPtr(hwnd, GWLP_USERDATA);
  517. switch (message)
  518. {
  519. case WM_NCCREATE:
  520. pMain = (WbMainWindow *)((LPCREATESTRUCT)lParam)->lpCreateParams;
  521. ASSERT(pMain);
  522. pMain->m_hwnd = hwnd;
  523. ::SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)pMain);
  524. goto DefWndProc;
  525. break;
  526. case WM_DESTROY:
  527. ShutDownHelp();
  528. break;
  529. case WM_NCDESTROY:
  530. pMain->m_hwnd = NULL;
  531. break;
  532. case WM_SIZE:
  533. pMain->OnSize((UINT)wParam, (short)LOWORD(lParam), (short)HIWORD(lParam));
  534. break;
  535. case WM_ACTIVATE:
  536. if (GET_WM_ACTIVATE_STATE(wParam, lParam) == WA_INACTIVE)
  537. {
  538. // Cancel the tooltip if it's around
  539. if (pMain->m_hwndToolTip)
  540. ::SendMessage(pMain->m_hwndToolTip, TTM_ACTIVATE, FALSE, 0);
  541. }
  542. goto DefWndProc;
  543. break;
  544. case WM_SETFOCUS:
  545. pMain->OnSetFocus();
  546. break;
  547. case WM_CANCELMODE:
  548. pMain->OnCancelMode();
  549. break;
  550. case WM_INITMENUPOPUP:
  551. pMain->OnInitMenuPopup((HMENU)wParam, LOWORD(lParam), HIWORD(lParam));
  552. break;
  553. case WM_MENUSELECT:
  554. pMain->OnMenuSelect(GET_WM_MENUSELECT_CMD(wParam, lParam),
  555. GET_WM_MENUSELECT_FLAGS(wParam, lParam),
  556. GET_WM_MENUSELECT_HMENU(wParam, lParam));
  557. break;
  558. case WM_MEASUREITEM:
  559. pMain->OnMeasureItem((UINT)wParam, (LPMEASUREITEMSTRUCT)lParam);
  560. break;
  561. case WM_DRAWITEM:
  562. pMain->OnDrawItem((UINT)wParam, (LPDRAWITEMSTRUCT)lParam);
  563. break;
  564. case WM_QUERYNEWPALETTE:
  565. lResult = pMain->OnQueryNewPalette();
  566. break;
  567. case WM_PALETTECHANGED:
  568. pMain->OnPaletteChanged((HWND)wParam);
  569. break;
  570. case WM_HELP:
  571. pMain->OnCommand(IDM_HELP, 0, NULL);
  572. break;
  573. case WM_CLOSE:
  574. pMain->OnClose();
  575. break;
  576. case WM_QUERYENDSESSION:
  577. lResult = pMain->OnQueryEndSession();
  578. break;
  579. case WM_ENDSESSION:
  580. pMain->OnEndSession((UINT)wParam);
  581. break;
  582. case WM_SYSCOLORCHANGE:
  583. pMain->OnSysColorChange();
  584. break;
  585. case WM_USER_PRIVATE_PARENTNOTIFY:
  586. pMain->OnParentNotify(GET_WM_PARENTNOTIFY_MSG(wParam, lParam));
  587. break;
  588. case WM_GETMINMAXINFO:
  589. if (pMain)
  590. pMain->OnGetMinMaxInfo((LPMINMAXINFO)lParam);
  591. break;
  592. case WM_COMMAND:
  593. pMain->OnCommand(LOWORD(wParam), HIWORD(wParam), (HWND)lParam);
  594. break;
  595. case WM_NOTIFY:
  596. pMain->OnNotify((UINT)wParam, (NMHDR *)lParam);
  597. break;
  598. case WM_DROPFILES:
  599. pMain->OnDropFiles((HDROP)wParam);
  600. break;
  601. case WM_USER_DISPLAY_ERROR:
  602. pMain->OnDisplayError(wParam, lParam);
  603. break;
  604. case WM_USER_UPDATE_ATTRIBUTES:
  605. pMain->m_AG.DisplayTool(pMain->m_pCurrentTool);
  606. break;
  607. case WM_USER_LOAD_FILE:
  608. pMain->WB_LoadFile(g_PassedFileName);
  609. // Fall through.
  610. case WM_USER_BRING_TO_FRONT_WINDOW:
  611. pMain->BringToFront();
  612. break;
  613. default:
  614. if (message == g_uConfShutdown)
  615. {
  616. lResult = pMain->OnConfShutdown(wParam, lParam);
  617. }
  618. else
  619. {
  620. DefWndProc:
  621. lResult = DefWindowProc(hwnd, message, wParam, lParam);
  622. }
  623. break;
  624. }
  625. return(lResult);
  626. }
  627. //
  628. // OnCommand()
  629. // Command dispatcher for the main window
  630. //
  631. void WbMainWindow::OnCommand(UINT cmd, UINT code, HWND hwndCtl)
  632. {
  633. switch (cmd)
  634. {
  635. //
  636. // FILE MENU
  637. //
  638. case IDM_NEW:
  639. OnNew();
  640. break;
  641. case IDM_OPEN:
  642. OnOpen();
  643. break;
  644. case IDM_SAVE:
  645. OnSave(FALSE);
  646. break;
  647. case IDM_SAVE_AS:
  648. OnSave(TRUE);
  649. break;
  650. case IDM_PRINT:
  651. OnPrint();
  652. break;
  653. case IDM_EXIT:
  654. ::PostMessage(m_hwnd, WM_CLOSE, 0, 0);
  655. break;
  656. //
  657. // EDIT MENU
  658. //
  659. case IDM_DELETE:
  660. OnDelete();
  661. break;
  662. case IDM_UNDELETE:
  663. OnUndelete();
  664. break;
  665. case IDM_CUT:
  666. OnCut();
  667. break;
  668. case IDM_COPY:
  669. OnCopy();
  670. break;
  671. case IDM_PASTE:
  672. OnPaste();
  673. break;
  674. case IDM_SELECTALL:
  675. OnSelectAll();
  676. break;
  677. case IDM_BRING_TO_TOP:
  678. m_drawingArea.BringToTopSelection(TRUE, 0);
  679. break;
  680. case IDM_SEND_TO_BACK:
  681. m_drawingArea.SendToBackSelection(TRUE, 0);
  682. break;
  683. case IDM_CLEAR_PAGE:
  684. OnClearPage();
  685. break;
  686. case IDM_DELETE_PAGE:
  687. OnDeletePage();
  688. break;
  689. case IDM_PAGE_INSERT_AFTER:
  690. OnInsertPageAfter();
  691. break;
  692. //
  693. // VIEW MENU
  694. //
  695. case IDM_TOOL_BAR_TOGGLE:
  696. OnToolBarToggle();
  697. break;
  698. case IDM_STATUS_BAR_TOGGLE:
  699. OnStatusBarToggle();
  700. break;
  701. case IDM_ZOOM:
  702. OnZoom();
  703. break;
  704. //
  705. // TOOLS MENU
  706. //
  707. case IDM_SELECT:
  708. case IDM_PEN:
  709. case IDM_HIGHLIGHT:
  710. case IDM_TEXT:
  711. case IDM_ERASER:
  712. case IDM_LINE:
  713. case IDM_BOX:
  714. case IDM_FILLED_BOX:
  715. case IDM_ELLIPSE:
  716. case IDM_FILLED_ELLIPSE:
  717. OnSelectTool(cmd);
  718. break;
  719. case IDM_REMOTE:
  720. OnRemotePointer();
  721. //
  722. // Are we turnig remote pointer on
  723. //
  724. if(m_pLocalRemotePointer)
  725. {
  726. //put us in select-tool mode
  727. OnSelectTool(IDM_SELECT);
  728. }
  729. break;
  730. case IDM_GRAB_AREA:
  731. OnGrabArea();
  732. break;
  733. case IDM_GRAB_WINDOW:
  734. OnGrabWindow();
  735. break;
  736. case IDM_SYNC:
  737. OnSync();
  738. break;
  739. case IDM_LOCK:
  740. OnLock();
  741. break;
  742. case IDM_COLOR:
  743. OnSelectColor();
  744. break;
  745. case IDM_EDITCOLOR:
  746. m_AG.OnEditColors();
  747. break;
  748. case IDM_FONT:
  749. OnChooseFont();
  750. break;
  751. case IDM_WIDTH_1:
  752. case IDM_WIDTH_2:
  753. case IDM_WIDTH_3:
  754. case IDM_WIDTH_4:
  755. OnSelectWidth(cmd);
  756. break;
  757. //
  758. // HELP MENU
  759. //
  760. case IDM_ABOUT:
  761. OnAbout();
  762. break;
  763. case IDM_HELP:
  764. ShowHelp();
  765. break;
  766. //
  767. // PAGE BAR
  768. //
  769. case IDM_PAGE_FIRST:
  770. OnFirstPage();
  771. break;
  772. case IDM_PAGE_PREV:
  773. OnPrevPage();
  774. break;
  775. case IDM_PAGE_GOTO:
  776. OnGotoPage();
  777. break;
  778. case IDM_PAGE_NEXT:
  779. OnNextPage();
  780. break;
  781. case IDM_PAGE_LAST:
  782. OnLastPage();
  783. break;
  784. //
  785. // SCROLLING
  786. //
  787. case IDM_PAGEUP:
  788. case IDM_PAGEDOWN:
  789. case IDM_SHIFTPAGEUP:
  790. case IDM_SHIFTPAGEDOWN:
  791. case IDM_HOME:
  792. case IDM_END:
  793. case IDM_LINEUP:
  794. case IDM_LINEDOWN:
  795. case IDM_SHIFTLINEUP:
  796. case IDM_SHIFTLINEDOWN:
  797. OnScrollAccelerator(cmd);
  798. break;
  799. }
  800. }
  801. //
  802. //
  803. // Function: OnInitMenuPopup
  804. //
  805. // Purpose: Process a WM_INITMENUPOPUP event
  806. //
  807. //
  808. void WbMainWindow::OnInitMenuPopup
  809. (
  810. HMENU hMenu,
  811. UINT uiIndex,
  812. BOOL bSystemMenu
  813. )
  814. {
  815. // Ignore the event if it relates to the system menu
  816. if (!bSystemMenu)
  817. {
  818. if (hMenu)
  819. {
  820. SetMenuStates(hMenu);
  821. m_hInitMenu = hMenu;
  822. }
  823. else
  824. {
  825. m_hInitMenu = NULL;
  826. }
  827. // Save the last menu we handled, so that we can alter its state
  828. // if necessary whilst it is still visible
  829. }
  830. }
  831. //
  832. //
  833. // Function: GetMenuWithItem
  834. //
  835. // Purpose: Return the menu which contains the specified item.
  836. //
  837. //
  838. HMENU WbMainWindow::GetMenuWithItem(HMENU hMenu, UINT uiID)
  839. {
  840. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::GetMenuWithItem");
  841. ASSERT(hMenu != NULL);
  842. HMENU hMenuResult = NULL;
  843. // Get the number ofitems in the menu
  844. UINT uiNumItems = ::GetMenuItemCount(hMenu);
  845. UINT uiPos;
  846. UINT uiNextID;
  847. // Look for the item through the menu
  848. for (uiPos = 0; uiPos < uiNumItems; uiPos++)
  849. {
  850. // Get the ID of the item at this position
  851. uiNextID = ::GetMenuItemID(hMenu, uiPos);
  852. if (uiNextID == uiID)
  853. {
  854. // We have found the item
  855. hMenuResult = hMenu;
  856. break;
  857. }
  858. }
  859. // If we have not yet found the item
  860. if (hMenuResult == NULL)
  861. {
  862. // Look through each of the submenus of the current menu
  863. HMENU hSubMenu;
  864. for (uiPos = 0; uiPos < uiNumItems; uiPos++)
  865. {
  866. // Get the ID of the item at this position
  867. uiNextID = ::GetMenuItemID(hMenu, uiPos);
  868. // If the item is a submenu
  869. if (uiNextID == -1)
  870. {
  871. // Get the submenu
  872. hSubMenu = ::GetSubMenu(hMenu, (int) uiPos);
  873. // Search the submenu
  874. hMenuResult = GetMenuWithItem(hSubMenu, uiID);
  875. if (hMenuResult != NULL)
  876. {
  877. // We have found the menu with the requested item
  878. break;
  879. }
  880. }
  881. }
  882. }
  883. return hMenuResult;
  884. }
  885. //
  886. //
  887. // Function: WbMainWindow::InitializeMenus
  888. //
  889. // Purpose: Initialise the menus: set up owner-drawn menu items and
  890. // those read from options file.
  891. //
  892. //
  893. void WbMainWindow::InitializeMenus(void)
  894. {
  895. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::InitializeMenus");
  896. // Make the width menu ownerdraw
  897. HMENU hMenu = GetMenuWithItem(::GetMenu(m_hwnd), IDM_WIDTH_1);
  898. if (hMenu != NULL)
  899. {
  900. // Change each entry to be ownerdraw (loop until failure)
  901. int iIndex;
  902. UINT uiId;
  903. int iCount = ::GetMenuItemCount(hMenu);
  904. for (iIndex = 0; iIndex < iCount; iIndex++)
  905. {
  906. uiId = ::GetMenuItemID(hMenu, iIndex);
  907. ::ModifyMenu(hMenu, iIndex,
  908. MF_BYPOSITION
  909. | MF_ENABLED
  910. | MF_OWNERDRAW,
  911. uiId,
  912. NULL);
  913. }
  914. }
  915. }
  916. //
  917. //
  918. // Function: CheckMenuItem
  919. //
  920. // Purpose: Check an item on the application menus (main and context
  921. // menu.)
  922. //
  923. //
  924. void WbMainWindow::CheckMenuItem(UINT uiId)
  925. {
  926. CheckMenuItemRecursive(::GetMenu(m_hwnd), uiId, MF_BYCOMMAND | MF_CHECKED);
  927. CheckMenuItemRecursive(m_hContextMenu, uiId, MF_BYCOMMAND | MF_CHECKED);
  928. CheckMenuItemRecursive(m_hGrobjContextMenu, uiId, MF_BYCOMMAND | MF_CHECKED);
  929. }
  930. //
  931. //
  932. // Function: UncheckMenuItem
  933. //
  934. // Purpose: Uncheck an item on the application menus (main and context
  935. // menus.)
  936. //
  937. //
  938. void WbMainWindow::UncheckMenuItem(UINT uiId)
  939. {
  940. CheckMenuItemRecursive(::GetMenu(m_hwnd), uiId, MF_BYCOMMAND | MF_UNCHECKED);
  941. CheckMenuItemRecursive(m_hContextMenu, uiId, MF_BYCOMMAND | MF_UNCHECKED);
  942. CheckMenuItemRecursive(m_hGrobjContextMenu, uiId, MF_BYCOMMAND | MF_UNCHECKED);
  943. }
  944. //
  945. //
  946. // Function: CheckMenuItemRecursive
  947. //
  948. // Purpose: Check or uncheck an item on the any of the Whiteboard menus.
  949. // This function recursively searches through the menus until
  950. // it finds the specified item. The menu item Ids must be
  951. // unique for this function to work.
  952. //
  953. //
  954. BOOL WbMainWindow::CheckMenuItemRecursive(HMENU hMenu,
  955. UINT uiId,
  956. BOOL bCheck)
  957. {
  958. UINT uiNumItems = ::GetMenuItemCount(hMenu);
  959. // Attempt to check the menu item
  960. UINT uiCheck = MF_BYCOMMAND | (bCheck ? MF_CHECKED : MF_UNCHECKED);
  961. // A return code of -1 from CheckMenuItem implies that
  962. // the menu item was not found
  963. BOOL bChecked = ((::CheckMenuItem(hMenu, uiId, uiCheck) == -1) ? FALSE : TRUE);
  964. if (bChecked)
  965. {
  966. //
  967. // If this item is on the active menu, ensure it's redrawn now
  968. //
  969. if (hMenu == m_hInitMenu)
  970. {
  971. InvalidateActiveMenu();
  972. }
  973. }
  974. else
  975. {
  976. UINT uiPos;
  977. HMENU hSubMenu;
  978. // Recurse through the submenus of the specified menu
  979. for (uiPos = 0; uiPos < uiNumItems; uiPos++)
  980. {
  981. // Assume that the next item is a submenu
  982. // and try to get a pointer to it
  983. hSubMenu = ::GetSubMenu(hMenu, (int)uiPos);
  984. // NULL return implies the item is a not submenu
  985. if (hSubMenu != NULL)
  986. {
  987. // Item is a submenu, make recursive call to search it
  988. bChecked = CheckMenuItemRecursive(hSubMenu, uiId, bCheck);
  989. if (bChecked)
  990. {
  991. // We have found the item
  992. break;
  993. }
  994. }
  995. }
  996. }
  997. return bChecked;
  998. }
  999. //
  1000. //
  1001. // Function: InvalidateActiveMenu
  1002. //
  1003. // Purpose: If a menu is currently active, gray items according to
  1004. // the current state, and force it to redraw.
  1005. //
  1006. //
  1007. void WbMainWindow::InvalidateActiveMenu()
  1008. {
  1009. if (m_hInitMenu != NULL)
  1010. {
  1011. // A menu is displayed, so set the state appropriately and force a
  1012. // repaint to show the new state
  1013. SetMenuStates(m_hInitMenu);
  1014. ::RedrawWindow(::GetTopWindow(::GetDesktopWindow()),
  1015. NULL, NULL,
  1016. RDW_FRAME | RDW_INVALIDATE | RDW_ERASE |
  1017. RDW_ERASENOW | RDW_ALLCHILDREN);
  1018. }
  1019. }
  1020. //
  1021. //
  1022. // Function: SetMenuState
  1023. //
  1024. // Purpose: Sets menu contents to their correct enabled/disabled state
  1025. //
  1026. //
  1027. void WbMainWindow::SetMenuStates(HMENU hInitMenu)
  1028. {
  1029. BOOL bLocked;
  1030. BOOL bPageOrderLocked;
  1031. BOOL bPresentationMode;
  1032. UINT uiEnable;
  1033. UINT uiCountPages;
  1034. BOOL bIdle;
  1035. BOOL bSelected;
  1036. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::SetMenuStates");
  1037. //
  1038. // Check menu exists
  1039. //
  1040. if (hInitMenu == NULL)
  1041. {
  1042. WARNING_OUT(("Menu doesn't exist"));
  1043. return;
  1044. }
  1045. HMENU hMainMenu = ::GetMenu(m_hwnd);
  1046. // Get the window's main menu and check that the menu
  1047. // now being popped up is one on the top-level. (We do not
  1048. // seem to be able to associate the index number passed with
  1049. // sub-menus easily.)
  1050. if ((hInitMenu != m_hContextMenu) && (hInitMenu != m_hGrobjContextMenu))
  1051. {
  1052. BOOL bTopLevel = FALSE;
  1053. int nCount = ::GetMenuItemCount(hMainMenu);
  1054. for (int nNext = 0; nNext < nCount; nNext++)
  1055. {
  1056. HMENU hNextMenu = ::GetSubMenu(hMainMenu, nNext);
  1057. if (hNextMenu != NULL)
  1058. {
  1059. if (hNextMenu == hInitMenu)
  1060. {
  1061. bTopLevel = TRUE;
  1062. break;
  1063. }
  1064. }
  1065. }
  1066. // not a top level, so leave the function now
  1067. if (!bTopLevel)
  1068. {
  1069. TRACE_DEBUG(("Not top-level menu"));
  1070. return;
  1071. }
  1072. }
  1073. BOOL bImNotLocked = (g_pCurrentWorkspace ? (g_pCurrentWorkspace->GetUpdatesEnabled() ? TRUE : g_pNMWBOBJ->m_LockerID == g_MyMemberID) :FALSE);
  1074. BOOL bIsThereAnything = IsThereAnythingInAnyWorkspace();
  1075. BOOL bIsThereSomethig = bImNotLocked && (g_pCurrentWorkspace && g_pCurrentWorkspace->GetHead() != NULL) ? TRUE : FALSE;
  1076. BOOL bIsThereTrash = bImNotLocked && (g_pTrash->GetHead() != NULL) && (g_pCurrentWorkspace != NULL);
  1077. BOOL bIsSomethingSelected = bImNotLocked && g_pDraw->GraphicSelected() && g_pDraw->GetSelectedGraphic()->GraphicTool() != TOOLTYPE_REMOTEPOINTER && g_pCurrentWorkspace != NULL;
  1078. BOOL bIsSynced = g_pDraw->IsSynced();
  1079. BOOL bOnlyOnePage = (g_pListOfWorkspaces->GetHead() == g_pListOfWorkspaces->GetTail());
  1080. //
  1081. // Functions which are disabled when contents is locked
  1082. //
  1083. uiEnable = MF_BYCOMMAND | (bImNotLocked && bIsSynced ? MF_ENABLED : MF_GRAYED);
  1084. //
  1085. // File menu
  1086. //
  1087. ::EnableMenuItem(hInitMenu, IDM_NEW, uiEnable);
  1088. ::EnableMenuItem(hInitMenu, IDM_OPEN, uiEnable);
  1089. uiEnable = MF_BYCOMMAND | (bIsThereAnything ? MF_ENABLED : MF_GRAYED);
  1090. ::EnableMenuItem(hInitMenu, IDM_SAVE, uiEnable);
  1091. ::EnableMenuItem(hInitMenu, IDM_SAVE_AS, uiEnable);
  1092. ::EnableMenuItem(hInitMenu, IDM_PRINT, uiEnable);
  1093. //
  1094. // Tools menu
  1095. //
  1096. uiEnable = MF_BYCOMMAND | (bImNotLocked ? MF_ENABLED : MF_GRAYED);
  1097. ::EnableMenuItem(hInitMenu, IDM_SELECT, uiEnable);
  1098. ::EnableMenuItem(hInitMenu, IDM_ERASER, uiEnable);
  1099. ::EnableMenuItem(hInitMenu, IDM_PEN, uiEnable);
  1100. ::EnableMenuItem(hInitMenu, IDM_HIGHLIGHT, uiEnable);
  1101. ::EnableMenuItem(hInitMenu, IDM_GRAB_AREA, uiEnable);
  1102. ::EnableMenuItem(hInitMenu, IDM_GRAB_WINDOW, uiEnable);
  1103. ::EnableMenuItem(hInitMenu, IDM_LINE, uiEnable);
  1104. ::EnableMenuItem(hInitMenu, IDM_BOX, uiEnable);
  1105. ::EnableMenuItem(hInitMenu, IDM_FILLED_BOX, uiEnable);
  1106. ::EnableMenuItem(hInitMenu, IDM_ELLIPSE, uiEnable);
  1107. ::EnableMenuItem(hInitMenu, IDM_FILLED_ELLIPSE, uiEnable);
  1108. ::EnableMenuItem(hInitMenu, IDM_TEXT, m_drawingArea.Zoomed() ? MF_BYCOMMAND | MF_GRAYED : uiEnable);
  1109. ::EnableMenuItem(hInitMenu, IDM_ZOOM, uiEnable);
  1110. ::EnableMenuItem(hInitMenu, IDM_REMOTE, uiEnable);
  1111. ::EnableMenuItem(hInitMenu, IDM_FONT, MF_BYCOMMAND | bImNotLocked && m_pCurrentTool->HasFont() ? MF_ENABLED : MF_GRAYED);
  1112. ::EnableMenuItem(hInitMenu, IDM_EDITCOLOR, MF_BYCOMMAND | bImNotLocked && m_pCurrentTool->HasColor() ? MF_ENABLED : MF_GRAYED);
  1113. HMENU hToolsMenu = ::GetSubMenu(hMainMenu, MENUPOS_TOOLS);
  1114. uiEnable = (bImNotLocked && m_pCurrentTool->HasWidth()) ? MF_ENABLED : MF_GRAYED;
  1115. if (hToolsMenu == hInitMenu )
  1116. {
  1117. ::EnableMenuItem(hToolsMenu, TOOLSPOS_WIDTH, MF_BYPOSITION | uiEnable );
  1118. }
  1119. UINT i;
  1120. UINT uIdmCurWidth = 0;
  1121. if( uiEnable == MF_ENABLED )
  1122. uIdmCurWidth = m_pCurrentTool->GetWidthIndex() + IDM_WIDTH_1;
  1123. for( i=IDM_WIDTH_1; i<=IDM_WIDTH_4; i++ )
  1124. {
  1125. ::EnableMenuItem(hInitMenu, i, uiEnable );
  1126. if( uiEnable == MF_ENABLED )
  1127. {
  1128. if( uIdmCurWidth == i )
  1129. ::CheckMenuItem(hInitMenu, i, MF_CHECKED );
  1130. else
  1131. ::CheckMenuItem(hInitMenu, i, MF_UNCHECKED );
  1132. }
  1133. }
  1134. //
  1135. // Edit Menu
  1136. //
  1137. uiEnable = MF_BYCOMMAND | (bIsSomethingSelected? MF_ENABLED : MF_GRAYED);
  1138. ::EnableMenuItem(hInitMenu, IDM_DELETE, uiEnable );
  1139. ::EnableMenuItem(hInitMenu, IDM_CUT, uiEnable );
  1140. ::EnableMenuItem(hInitMenu, IDM_COPY, uiEnable);
  1141. ::EnableMenuItem(hInitMenu, IDM_BRING_TO_TOP, uiEnable);
  1142. ::EnableMenuItem(hInitMenu, IDM_SEND_TO_BACK, uiEnable);
  1143. uiEnable = MF_BYCOMMAND | (bIsThereSomethig ?MF_ENABLED : MF_GRAYED);
  1144. ::EnableMenuItem(hInitMenu, IDM_CLEAR_PAGE, uiEnable);
  1145. ::EnableMenuItem(hInitMenu, IDM_SELECTALL, uiEnable);
  1146. ::EnableMenuItem(hInitMenu, IDM_PASTE, MF_BYCOMMAND | CLP_AcceptableClipboardFormat() && bImNotLocked ? MF_ENABLED : MF_GRAYED);
  1147. ::EnableMenuItem(hInitMenu, IDM_UNDELETE, MF_BYCOMMAND | (bIsThereTrash? MF_ENABLED : MF_GRAYED) );
  1148. ::EnableMenuItem(hInitMenu, IDM_DELETE_PAGE, MF_BYCOMMAND | bIsSynced && bImNotLocked && !bOnlyOnePage ? MF_ENABLED : MF_GRAYED);
  1149. ::EnableMenuItem(hInitMenu, IDM_PAGE_INSERT_AFTER, MF_BYCOMMAND | bIsSynced && bImNotLocked && g_numberOfWorkspaces < WB_MAX_WORKSPACES ? MF_ENABLED : MF_GRAYED);
  1150. //
  1151. // View Menu
  1152. //
  1153. ::EnableMenuItem(hInitMenu, IDM_SYNC, MF_BYCOMMAND | (bImNotLocked && !m_drawingArea.IsLocked()? MF_ENABLED : MF_GRAYED));
  1154. ::EnableMenuItem(hInitMenu, IDM_LOCK, MF_BYCOMMAND |((bImNotLocked && bIsSynced) ? MF_ENABLED : MF_GRAYED));
  1155. //
  1156. // Enable toolbar
  1157. //
  1158. EnableToolbar(bImNotLocked);
  1159. //
  1160. // Enable page controls
  1161. //
  1162. m_AG.EnablePageCtrls(bImNotLocked);
  1163. }
  1164. //
  1165. //
  1166. // Function: WbMainWindow destructor
  1167. //
  1168. // Purpose: Tidy up main window on destruction.
  1169. //
  1170. //
  1171. WbMainWindow::~WbMainWindow()
  1172. {
  1173. //
  1174. // Destroy the tooltip window
  1175. //
  1176. if (m_hwndToolTip)
  1177. {
  1178. ::DestroyWindow(m_hwndToolTip);
  1179. m_hwndToolTip = NULL;
  1180. }
  1181. if (m_hGrobjContextMenuBar != NULL)
  1182. {
  1183. ::DestroyMenu(m_hGrobjContextMenuBar);
  1184. m_hGrobjContextMenuBar = NULL;
  1185. }
  1186. m_hGrobjContextMenu = NULL;
  1187. if (m_hContextMenuBar != NULL)
  1188. {
  1189. ::DestroyMenu(m_hContextMenuBar);
  1190. m_hContextMenuBar = NULL;
  1191. }
  1192. m_hContextMenu = NULL;
  1193. POSITION position = m_pageToPosition.GetHeadPosition();
  1194. PAGE_POSITION * pPoint;
  1195. while (position)
  1196. {
  1197. pPoint = (PAGE_POSITION*)m_pageToPosition.GetNext(position);
  1198. delete pPoint;
  1199. }
  1200. m_pageToPosition.EmptyList();
  1201. //
  1202. // Free the palette
  1203. //
  1204. if (g_hRainbowPaletteDisplay)
  1205. {
  1206. if (g_pDraw && g_pDraw->m_hDCCached)
  1207. {
  1208. // Select out the rainbow palette so we can delete it
  1209. ::SelectPalette(g_pDraw->m_hDCCached, (HPALETTE)::GetStockObject(DEFAULT_PALETTE), TRUE);
  1210. }
  1211. DeletePalette(g_hRainbowPaletteDisplay);
  1212. g_hRainbowPaletteDisplay = NULL;
  1213. }
  1214. g_bPalettesInitialized = FALSE;
  1215. g_bUsePalettes = FALSE;
  1216. if (g_pIcons)
  1217. {
  1218. delete g_pIcons;
  1219. g_pIcons = NULL;
  1220. }
  1221. if(m_pTitleFileName)
  1222. {
  1223. delete m_pTitleFileName;
  1224. m_pTitleFileName = NULL;
  1225. }
  1226. //
  1227. // Delete all the objectsb in global lists
  1228. //
  1229. DeleteAllWorkspaces(FALSE);
  1230. ASSERT(g_pListOfWorkspaces);
  1231. g_pListOfWorkspaces->EmptyList();
  1232. ASSERT(g_pListOfObjectsThatRequestedHandles);
  1233. g_pListOfObjectsThatRequestedHandles->EmptyList();
  1234. g_numberOfWorkspaces = 0;
  1235. //
  1236. // Delete objects in limbo, sitting in the undelete trash
  1237. //
  1238. ASSERT(g_pTrash);
  1239. T126Obj* pGraphic;
  1240. //
  1241. // Burn trash
  1242. //
  1243. pGraphic = (T126Obj *)g_pTrash->RemoveTail();
  1244. while (pGraphic != NULL)
  1245. {
  1246. delete pGraphic;
  1247. pGraphic = (T126Obj *) g_pTrash->RemoveTail();
  1248. }
  1249. DeleteAllRetryPDUS();
  1250. DestroyToolArray();
  1251. ::DestroyWindow(m_hwnd);
  1252. ::UnregisterClass(szMainClassName, g_hInstance);
  1253. }
  1254. //
  1255. // OnToolHitTest()
  1256. // This handles tooltips for child windows.
  1257. //
  1258. int WbMainWindow::OnToolHitTest(POINT pt, TOOLINFO* pTI) const
  1259. {
  1260. HWND hwnd;
  1261. int status;
  1262. int nHit;
  1263. ASSERT(!IsBadWritePtr(pTI, sizeof(TOOLINFO)));
  1264. hwnd = ::ChildWindowFromPointEx(m_hwnd, pt, CWP_SKIPINVISIBLE);
  1265. if (hwnd == m_AG.m_hwnd)
  1266. {
  1267. ::MapWindowPoints(m_hwnd, m_AG.m_hwnd, &pt, 1);
  1268. hwnd = ::ChildWindowFromPointEx(m_AG.m_hwnd, pt, CWP_SKIPINVISIBLE);
  1269. if (hwnd != NULL)
  1270. {
  1271. nHit = ::GetDlgCtrlID(hwnd);
  1272. pTI->hwnd = m_hwnd;
  1273. pTI->uId = (UINT_PTR)hwnd;
  1274. pTI->uFlags |= TTF_IDISHWND;
  1275. pTI->lpszText = LPSTR_TEXTCALLBACK;
  1276. return(nHit);
  1277. }
  1278. }
  1279. else if (hwnd == m_WG.m_hwnd)
  1280. {
  1281. int iItem;
  1282. ::MapWindowPoints(m_hwnd, m_WG.m_hwnd, &pt, 1);
  1283. iItem = m_WG.ItemFromPoint(pt.x, pt.y);
  1284. pTI->hwnd = m_WG.m_hwnd;
  1285. pTI->uId = iItem;
  1286. // Since the area isn't a window, we must fill in the rect ourself
  1287. m_WG.GetItemRect(iItem, &pTI->rect);
  1288. pTI->lpszText = LPSTR_TEXTCALLBACK;
  1289. return(iItem);
  1290. }
  1291. else if (hwnd == m_TB.m_hwnd)
  1292. {
  1293. RECT rect;
  1294. TBBUTTON button;
  1295. int i;
  1296. for (i = 0; i < TOOLBAR_MAXBUTTON; i++)
  1297. {
  1298. if (::SendMessage(m_TB.m_hwnd, TB_GETITEMRECT, i, (LPARAM)&rect) &&
  1299. ::PtInRect(&rect, pt) &&
  1300. ::SendMessage(m_TB.m_hwnd, TB_GETBUTTON, i, (LPARAM)&button) &&
  1301. !(button.fsStyle & TBSTYLE_SEP))
  1302. {
  1303. int nHit = button.idCommand;
  1304. pTI->hwnd = m_TB.m_hwnd;
  1305. pTI->uId = nHit;
  1306. pTI->rect = rect;
  1307. pTI->lpszText = LPSTR_TEXTCALLBACK;
  1308. // found matching rect, return the ID of the button
  1309. return(nHit);
  1310. }
  1311. }
  1312. }
  1313. return(-1);
  1314. }
  1315. //
  1316. // WinHelp() wrapper
  1317. //
  1318. LRESULT WbMainWindow::ShowHelp(void)
  1319. {
  1320. HWND hwndCapture;
  1321. // Get the main window out of any mode
  1322. ::SendMessage(m_hwnd, WM_CANCELMODE, 0, 0);
  1323. // Cancel any other tracking
  1324. if (hwndCapture = ::GetCapture())
  1325. ::SendMessage(hwndCapture, WM_CANCELMODE, 0, 0);
  1326. // finally, run the NetMeeting Help engine
  1327. ShowNmHelp(s_cszHtmlHelpFile);
  1328. return S_OK;
  1329. }
  1330. //
  1331. // TimedDlgProc()
  1332. // This puts up a visible or invisible dialog which only goes away when
  1333. // an event occurs or a certain amount of time has passed. We store the
  1334. // DialogBoxParam parameter, a TMDLG pointer, in our user data. That is
  1335. // from the stack of the DialogBoxParam() caller, so it is valid until that
  1336. // function returns, which won't be until a bit after the dialog has been
  1337. // destroyed.
  1338. //
  1339. INT_PTR CALLBACK TimedDlgProc(HWND hwnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
  1340. {
  1341. BOOL fHandled = FALSE;
  1342. TMDLG * ptm;
  1343. switch (uMessage)
  1344. {
  1345. case WM_INITDIALOG:
  1346. ptm = (TMDLG *)lParam;
  1347. ASSERT(!IsBadWritePtr(ptm, sizeof(TMDLG)));
  1348. ::SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)ptm);
  1349. //
  1350. // Set the WbMainWindow hwnd
  1351. //
  1352. if (ptm->bLockNotEvent)
  1353. {
  1354. g_pMain->m_hwndWaitForLockDlg = hwnd;
  1355. }
  1356. else
  1357. {
  1358. g_pMain->m_hwndWaitForEventDlg = hwnd;
  1359. }
  1360. //
  1361. // Set max timer
  1362. //
  1363. ::SetTimer(hwnd, TIMERID_MAXDISPLAY, ptm->uiMaxDisplay, NULL);
  1364. //
  1365. // Change the cursor if invisible
  1366. //
  1367. if (!ptm->bVisible)
  1368. ::SetCursor(::LoadCursor(NULL, IDC_WAIT));
  1369. fHandled = TRUE;
  1370. break;
  1371. case WM_TIMER:
  1372. ASSERT(wParam == TIMERID_MAXDISPLAY);
  1373. // End the dialog--since we timed out, it acts like cancel
  1374. ::SendMessage(hwnd, WM_COMMAND, MAKELONG(IDCANCEL, BN_CLICKED), 0);
  1375. fHandled = TRUE;
  1376. break;
  1377. case WM_COMMAND:
  1378. switch (GET_WM_COMMAND_ID(wParam, lParam))
  1379. {
  1380. case IDOK:
  1381. case IDCANCEL:
  1382. if (GET_WM_COMMAND_CMD(wParam, lParam) == BN_CLICKED)
  1383. {
  1384. ptm = (TMDLG *)::GetWindowLongPtr(hwnd, GWLP_USERDATA);
  1385. ASSERT(!IsBadWritePtr(ptm, sizeof(TMDLG)));
  1386. // Clear out the HWND variable
  1387. if (ptm->bLockNotEvent)
  1388. {
  1389. g_pMain->m_hwndWaitForLockDlg = NULL;
  1390. }
  1391. else
  1392. {
  1393. g_pMain->m_hwndWaitForEventDlg = NULL;
  1394. }
  1395. // Restore the cursor
  1396. if (!ptm->bVisible)
  1397. ::SetCursor(::LoadCursor(NULL, IDC_ARROW));
  1398. ::KillTimer(hwnd, TIMERID_MAXDISPLAY);
  1399. ::EndDialog(hwnd, GET_WM_COMMAND_ID(wParam, lParam));
  1400. }
  1401. break;
  1402. }
  1403. fHandled = TRUE;
  1404. break;
  1405. //
  1406. // Don't let these dialogs be killed by any other means than our
  1407. // getting an event or timing out.
  1408. //
  1409. case WM_CLOSE:
  1410. fHandled = TRUE;
  1411. break;
  1412. }
  1413. return(fHandled);
  1414. }
  1415. //
  1416. // FilterMessage()
  1417. //
  1418. // This does tooltip message filtering, then translates accelerators.
  1419. //
  1420. BOOL WbMainWindow::FilterMessage(MSG* pMsg)
  1421. {
  1422. BOOL bResult = FALSE;
  1423. if ((pMsg->message >= WM_KEYFIRST && pMsg->message <= WM_KEYLAST) ||
  1424. (pMsg->message == WM_LBUTTONDOWN || pMsg->message == WM_LBUTTONDBLCLK) ||
  1425. (pMsg->message == WM_RBUTTONDOWN || pMsg->message == WM_RBUTTONDBLCLK) ||
  1426. (pMsg->message == WM_MBUTTONDOWN || pMsg->message == WM_MBUTTONDBLCLK) ||
  1427. (pMsg->message == WM_NCLBUTTONDOWN || pMsg->message == WM_NCLBUTTONDBLCLK) ||
  1428. (pMsg->message == WM_NCRBUTTONDOWN || pMsg->message == WM_NCRBUTTONDBLCLK) ||
  1429. (pMsg->message == WM_NCMBUTTONDOWN || pMsg->message == WM_NCMBUTTONDBLCLK))
  1430. {
  1431. // Cancel any tooltip up
  1432. ::SendMessage(m_hwndToolTip, TTM_ACTIVATE, FALSE, 0);
  1433. }
  1434. // handle tooltip messages (some messages cancel, some may cause it to popup)
  1435. if ((pMsg->message == WM_MOUSEMOVE || pMsg->message == WM_NCMOUSEMOVE ||
  1436. pMsg->message == WM_LBUTTONUP || pMsg->message == WM_RBUTTONUP ||
  1437. pMsg->message == WM_MBUTTONUP) &&
  1438. (GetKeyState(VK_LBUTTON) >= 0 && GetKeyState(VK_RBUTTON) >= 0 &&
  1439. GetKeyState(VK_MBUTTON) >= 0))
  1440. {
  1441. #if 0
  1442. //
  1443. // If this mouse move isn't for a descendant of the main window, skip
  1444. // it. For example, when the tooltip is shown, it gets a mousemove
  1445. // to itself, which if we didn't check for it, would cause us to
  1446. // immediately dismiss this!
  1447. //
  1448. HWND hwndTmp = pMsg->hwnd;
  1449. while (hwndTmp && (::GetWindowLong(hwndTmp, GWL_STYLE) & WS_CHILD))
  1450. {
  1451. hwndTmp = ::GetParent(hwndTmp);
  1452. }
  1453. if (hwndTmp != m_hwnd)
  1454. {
  1455. // This is not for us, it's for another top level window in
  1456. // our app.
  1457. goto DoneToolTipFiltering;
  1458. }
  1459. #endif
  1460. // determine which tool was hit
  1461. POINT pt;
  1462. pt = pMsg->pt;
  1463. ::ScreenToClient(m_hwnd, &pt);
  1464. TOOLINFO tiHit;
  1465. ZeroMemory(&tiHit, sizeof(tiHit));
  1466. tiHit.cbSize = sizeof(TOOLINFO);
  1467. int nHit = OnToolHitTest(pt, &tiHit);
  1468. if (m_nLastHit != nHit)
  1469. {
  1470. if (nHit != -1)
  1471. {
  1472. // add new tool and activate the tip
  1473. if (!::SendMessage(m_hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&tiHit))
  1474. {
  1475. ERROR_OUT(("TTM_ADDTOOL failed"));
  1476. }
  1477. if (::GetActiveWindow() == m_hwnd)
  1478. {
  1479. // allow the tooltip to popup when it should
  1480. ::SendMessage(m_hwndToolTip, TTM_ACTIVATE, TRUE, 0);
  1481. // bring the tooltip window above other popup windows
  1482. ::SetWindowPos(m_hwndToolTip, HWND_TOP, 0, 0, 0, 0,
  1483. SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE);
  1484. }
  1485. }
  1486. // relay mouse event before deleting old tool
  1487. ::SendMessage(m_hwndToolTip, TTM_RELAYEVENT, 0, (LPARAM)pMsg);
  1488. // now safe to delete the old tool
  1489. if (m_tiLastHit.cbSize != 0)
  1490. ::SendMessage(m_hwndToolTip, TTM_DELTOOL, 0, (LPARAM)&m_tiLastHit);
  1491. m_nLastHit = nHit;
  1492. m_tiLastHit = tiHit;
  1493. }
  1494. else
  1495. {
  1496. // relay mouse events through the tooltip
  1497. if (nHit != -1)
  1498. ::SendMessage(m_hwndToolTip, TTM_RELAYEVENT, 0, (LPARAM)pMsg);
  1499. }
  1500. }
  1501. #if 0
  1502. DoneToolTipFiltering:
  1503. #endif
  1504. // Assume we will use the main accelerator table
  1505. HACCEL hAccelTable = m_hAccelTable;
  1506. // If this window has focus, just continue
  1507. HWND hwndFocus = ::GetFocus();
  1508. if (hwndFocus && (hwndFocus != m_hwnd))
  1509. {
  1510. // Check whether an edit field in the pages group has the focus
  1511. if (m_AG.IsChildEditField(hwndFocus))
  1512. {
  1513. hAccelTable = m_hAccelPagesGroup;
  1514. }
  1515. // Check whether text editor has the focus and is active
  1516. else if ( (hwndFocus == m_drawingArea.m_hwnd)
  1517. && (m_drawingArea.TextEditActive()))
  1518. {
  1519. // Let editbox do its own acceleration.
  1520. hAccelTable = NULL;
  1521. }
  1522. }
  1523. return ( (hAccelTable != NULL)
  1524. && ::TranslateAccelerator(m_hwnd, hAccelTable, pMsg));
  1525. }
  1526. //
  1527. //
  1528. // Function: OnDisplayError
  1529. //
  1530. // Purpose: Display an error message
  1531. //
  1532. //
  1533. void WbMainWindow::OnDisplayError(WPARAM uiFEReturnCode, LPARAM uiDCGReturnCode)
  1534. {
  1535. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnDisplayError");
  1536. // Only continue if we are not currently displaying an error
  1537. if (!m_bDisplayingError)
  1538. {
  1539. // Show that we are currently displaying an error message
  1540. m_bDisplayingError = TRUE;
  1541. // Display the error
  1542. ::ErrorMessage((UINT)uiFEReturnCode, (UINT)uiDCGReturnCode);
  1543. // Show that we are no longer displaying an error
  1544. m_bDisplayingError = FALSE;
  1545. }
  1546. }
  1547. //
  1548. //
  1549. // Function: OnPaletteChanged
  1550. //
  1551. // Purpose: The palette has changed.
  1552. //
  1553. //
  1554. void WbMainWindow::OnPaletteChanged(HWND hwndPalette)
  1555. {
  1556. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnPaletteChanged");
  1557. if ((hwndPalette != m_hwnd) &&
  1558. (hwndPalette != m_drawingArea.m_hwnd))
  1559. {
  1560. // Tell the drawing area to realize its palette
  1561. m_drawingArea.RealizePalette( TRUE );
  1562. }
  1563. }
  1564. //
  1565. //
  1566. // Function: OnQueryNewPalette
  1567. //
  1568. // Purpose: We are getting focus and must realize our palette
  1569. //
  1570. //
  1571. LRESULT WbMainWindow::OnQueryNewPalette(void)
  1572. {
  1573. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnQueryNewPalette");
  1574. // Tell the drawing area to realize its palette
  1575. m_drawingArea.RealizePalette( FALSE );
  1576. return TRUE;
  1577. }
  1578. //
  1579. //
  1580. // Function: PopupContextMenu
  1581. //
  1582. // Purpose: Popup the context menu for the drawing area. This is called
  1583. // by the drawing area window on a right mouse click.
  1584. //
  1585. //
  1586. void WbMainWindow::PopupContextMenu(int x, int y)
  1587. {
  1588. POINT surfacePos;
  1589. RECT clientRect;
  1590. T126Obj * pGraphic;
  1591. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::PopupContextMenu");
  1592. surfacePos.x = x;
  1593. surfacePos.y = y;
  1594. m_drawingArea.ClientToSurface(&surfacePos);
  1595. if( (pGraphic = m_drawingArea.GetHitObject( surfacePos )) != NULL
  1596. && pGraphic->GraphicTool() != TOOLTYPE_REMOTEPOINTER )
  1597. {
  1598. if(!pGraphic->IsSelected() )
  1599. {
  1600. g_pDraw->SelectGraphic(pGraphic);
  1601. }
  1602. // selector tool is active, and one or more objects are selected
  1603. m_hInitMenu = m_hGrobjContextMenu;
  1604. }
  1605. else
  1606. {
  1607. // no current selection, show drawing menu
  1608. m_hInitMenu = m_hContextMenu;
  1609. }
  1610. // set up current menu state
  1611. SetMenuStates(m_hInitMenu);
  1612. // pop it up
  1613. ::GetClientRect(m_drawingArea.m_hwnd, &clientRect);
  1614. ::MapWindowPoints(m_drawingArea.m_hwnd, NULL, (LPPOINT)&clientRect.left, 2);
  1615. ::TrackPopupMenu(m_hInitMenu, TPM_RIGHTALIGN | TPM_RIGHTBUTTON,
  1616. x + clientRect.left,
  1617. y + clientRect.top,
  1618. 0,
  1619. m_hwnd,
  1620. NULL);
  1621. // reset m_hInitMenu to indicate the popup menu isn't being shown anymore
  1622. m_hInitMenu = NULL;
  1623. }
  1624. //
  1625. //
  1626. // Function: OnSize
  1627. //
  1628. // Purpose: The window has been resized.
  1629. //
  1630. //
  1631. void WbMainWindow::OnSize(UINT nType, int cx, int cy )
  1632. {
  1633. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnSize");
  1634. // Only process this message if the window is not minimized
  1635. if (nType != SIZE_MINIMIZED)
  1636. {
  1637. // The user's view has changed
  1638. PositionUpdated();
  1639. if (m_bStatusBarOn)
  1640. {
  1641. ::ShowWindow(m_hwndSB, SW_HIDE);
  1642. }
  1643. // Resize the subpanes of the window
  1644. ResizePanes();
  1645. // Show it again
  1646. if (m_bStatusBarOn)
  1647. {
  1648. ::ShowWindow(m_hwndSB, SW_SHOW);
  1649. }
  1650. // If the status has changed, set the option
  1651. if (m_uiWindowSize != nType)
  1652. {
  1653. m_uiWindowSize = nType;
  1654. // Write the new option values to file
  1655. OPT_SetBooleanOption(OPT_MAIN_MAXIMIZED,
  1656. (m_uiWindowSize == SIZE_MAXIMIZED));
  1657. OPT_SetBooleanOption(OPT_MAIN_MINIMIZED,
  1658. (m_uiWindowSize == SIZE_MINIMIZED));
  1659. }
  1660. }
  1661. }
  1662. //
  1663. //
  1664. // Function: SaveWindowPosition
  1665. //
  1666. // Purpose: Save the current window position to the options file.
  1667. //
  1668. //
  1669. void WbMainWindow::SaveWindowPosition(void)
  1670. {
  1671. RECT rectWindow;
  1672. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::SaveWindowPosition");
  1673. // Get the new window rectangle
  1674. ::GetWindowRect(m_hwnd, &rectWindow);
  1675. // Write the new option values to file
  1676. OPT_SetWindowRectOption(&rectWindow);
  1677. }
  1678. //
  1679. //
  1680. // Function: ResizePanes
  1681. //
  1682. // Purpose: Resize the subpanes of the main window.
  1683. //
  1684. //
  1685. void WbMainWindow::ResizePanes(void)
  1686. {
  1687. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::ResizePanes");
  1688. //
  1689. //
  1690. // The client area is organized as follows:
  1691. //
  1692. // -------------------------------------
  1693. // | | |
  1694. // | T | |
  1695. // | o | Drawing Area |
  1696. // | o | |
  1697. // | l | |
  1698. // | s | |
  1699. // |---| |
  1700. // | W | |
  1701. // | i | |
  1702. // | d | |
  1703. // | t | |
  1704. // | h | |
  1705. // | s | |
  1706. // |-----------------------------------|
  1707. // | Attributes (colors) | Pages |
  1708. // |-----------------------------------|
  1709. // | Status |
  1710. // -------------------------------------
  1711. //
  1712. //
  1713. RECT clientRect;
  1714. RECT rectStatusBar;
  1715. RECT rectToolBar;
  1716. RECT rectWG;
  1717. RECT rectAG;
  1718. RECT rectDraw;
  1719. SIZE size;
  1720. SIZE sizeAG;
  1721. // Get the client rectangle
  1722. ::GetClientRect(m_hwnd, &clientRect);
  1723. rectStatusBar = clientRect;
  1724. // Resize the help bar and progress meter
  1725. if (m_bStatusBarOn)
  1726. {
  1727. rectStatusBar.top = rectStatusBar.bottom - STATUSBAR_HEIGHT;
  1728. ::MoveWindow(m_hwndSB, rectStatusBar.left, rectStatusBar.top,
  1729. rectStatusBar.right - rectStatusBar.left,
  1730. rectStatusBar.bottom - rectStatusBar.top, TRUE);
  1731. }
  1732. else
  1733. {
  1734. // Status bar is off - set it's height to zero
  1735. rectStatusBar.top = rectStatusBar.bottom;
  1736. }
  1737. // Resize the tool and width windows
  1738. m_TB.GetNaturalSize(&size);
  1739. rectToolBar.left = 0;
  1740. rectToolBar.right = rectToolBar.left + size.cx;
  1741. rectToolBar.top = 0;
  1742. rectToolBar.bottom = rectToolBar.top + size.cy;
  1743. m_WG.GetNaturalSize(&size);
  1744. rectWG.left = rectToolBar.left;
  1745. rectWG.top = rectToolBar.bottom;
  1746. rectWG.bottom = rectWG.top + size.cy;
  1747. if (!m_bToolBarOn)
  1748. {
  1749. // Toolbar is either off or floating - set its width to zero
  1750. rectToolBar.right = rectToolBar.left;
  1751. }
  1752. rectWG.right = rectToolBar.right;
  1753. // Position attribute group
  1754. m_AG.GetNaturalSize(&sizeAG);
  1755. ::MoveWindow(m_AG.m_hwnd, rectToolBar.left, rectStatusBar.top - sizeAG.cy,
  1756. clientRect.right - rectToolBar.left, sizeAG.cy, TRUE);
  1757. // finish fiddling with tools and widths bars
  1758. if (m_bToolBarOn)
  1759. {
  1760. //
  1761. // We make the toolbar, which includes the width bar, extend all
  1762. // down the left side.
  1763. //
  1764. rectToolBar.bottom = rectStatusBar.top - sizeAG.cy;
  1765. rectWG.left += TOOLBAR_MARGINX;
  1766. rectWG.right -= 2*TOOLBAR_MARGINX;
  1767. ::MoveWindow(m_TB.m_hwnd, rectToolBar.left,
  1768. rectToolBar.top, rectToolBar.right - rectToolBar.left,
  1769. rectToolBar.bottom - rectToolBar.top, TRUE);
  1770. ::MoveWindow(m_WG.m_hwnd, rectWG.left, rectWG.top,
  1771. rectWG.right - rectWG.left, rectWG.bottom - rectWG.top, TRUE);
  1772. ::BringWindowToTop(m_WG.m_hwnd);
  1773. }
  1774. // Resize the drawing pane
  1775. rectDraw = clientRect;
  1776. rectDraw.bottom = rectStatusBar.top - sizeAG.cy;
  1777. rectDraw.left = rectToolBar.right;
  1778. ::MoveWindow(m_drawingArea.m_hwnd, rectDraw.left, rectDraw.top,
  1779. rectDraw.right - rectDraw.left, rectDraw.bottom - rectDraw.top, TRUE);
  1780. // Check to see if Width group is overlapping Attributes group. This can happen if
  1781. // the menu bar has wrapped because the window isn't wide enough (bug 424)
  1782. RECT crWidthWnd;
  1783. RECT crAttrWnd;
  1784. ::GetWindowRect(m_WG.m_hwnd, &crWidthWnd);
  1785. ::GetWindowRect(m_AG.m_hwnd, &crAttrWnd);
  1786. if (crAttrWnd.top < crWidthWnd.bottom)
  1787. {
  1788. // the menu bar has wrapped and our height placements are wrong. Adjust window
  1789. // by difference and try again
  1790. RECT crMainWnd;
  1791. ::GetWindowRect(m_hwnd, &crMainWnd);
  1792. crMainWnd.bottom += (crWidthWnd.bottom - crAttrWnd.top + ::GetSystemMetrics(SM_CYFIXEDFRAME));
  1793. ::MoveWindow(m_hwnd, crMainWnd.left, crMainWnd.top,
  1794. crMainWnd.right - crMainWnd.left, crMainWnd.bottom - crMainWnd.top,
  1795. FALSE);
  1796. // this is going to recurse but the adjustment will happen only once.....
  1797. }
  1798. }
  1799. //
  1800. //
  1801. // Function: WbMainWindow::OnGetMinMaxInfo
  1802. //
  1803. // Purpose: Set the minimum and maximum tracking sizes of the window
  1804. //
  1805. //
  1806. void WbMainWindow::OnGetMinMaxInfo(LPMINMAXINFO lpmmi)
  1807. {
  1808. if (m_TB.m_hwnd == NULL)
  1809. return; // not ready to do this yet
  1810. SIZE csFrame;
  1811. SIZE csSeparator;
  1812. SIZE csAG;
  1813. SIZE csToolBar;
  1814. SIZE csWidthBar;
  1815. SIZE csMaxSize;
  1816. SIZE csScrollBars;
  1817. csFrame.cx = ::GetSystemMetrics(SM_CXSIZEFRAME);
  1818. csFrame.cy = ::GetSystemMetrics(SM_CYSIZEFRAME);
  1819. csSeparator.cx = ::GetSystemMetrics(SM_CXEDGE);
  1820. csSeparator.cy = ::GetSystemMetrics(SM_CYEDGE);
  1821. csScrollBars.cx = ::GetSystemMetrics(SM_CXVSCROLL);
  1822. csScrollBars.cy = ::GetSystemMetrics(SM_CYHSCROLL);
  1823. m_AG.GetNaturalSize(&csAG);
  1824. m_TB.GetNaturalSize(&csToolBar);
  1825. m_WG.GetNaturalSize(&csWidthBar);
  1826. // Set the minimum width and height of the window
  1827. lpmmi->ptMinTrackSize.x =
  1828. csFrame.cx + csAG.cx + csFrame.cx;
  1829. lpmmi->ptMinTrackSize.y =
  1830. csFrame.cy +
  1831. GetSystemMetrics( SM_CYCAPTION ) +
  1832. GetSystemMetrics( SM_CYMENU ) +
  1833. csToolBar.cy +
  1834. csWidthBar.cy +
  1835. csSeparator.cy +
  1836. csAG.cy +
  1837. csSeparator.cy +
  1838. csFrame.cy +
  1839. STATUSBAR_HEIGHT;
  1840. //
  1841. // Retrieves the size of the work area on the primary display monitor. The work
  1842. // area is the portion of the screen not obscured by the system taskbar or by
  1843. // application desktop toolbars
  1844. //
  1845. RECT rcWorkArea;
  1846. ::SystemParametersInfo( SPI_GETWORKAREA, 0, (&rcWorkArea), NULL );
  1847. csMaxSize.cx = rcWorkArea.right - rcWorkArea.left;
  1848. csMaxSize.cy = rcWorkArea.bottom - rcWorkArea.top;
  1849. lpmmi->ptMaxPosition.x = 0;
  1850. lpmmi->ptMaxPosition.y = 0;
  1851. lpmmi->ptMaxSize.x = csMaxSize.cx;
  1852. lpmmi->ptMaxSize.y = csMaxSize.cy;
  1853. lpmmi->ptMaxTrackSize.x = csMaxSize.cx;
  1854. lpmmi->ptMaxTrackSize.y = csMaxSize.cy;
  1855. }
  1856. //
  1857. //
  1858. // Function: WbMainWindow::CreateContextMenus
  1859. //
  1860. // Purpose: Create the pop-up context menus: used within the application
  1861. // drawing area.
  1862. //
  1863. //
  1864. BOOL WbMainWindow::CreateContextMenus(void)
  1865. {
  1866. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::CreateContextMenus");
  1867. m_hContextMenuBar = ::LoadMenu(g_hInstance, MAKEINTRESOURCE(CONTEXTMENU));
  1868. if (!m_hContextMenuBar)
  1869. {
  1870. ERROR_OUT(("Failed to create context menu"));
  1871. DefaultExceptionHandler(WBFE_RC_WINDOWS, 0);
  1872. return FALSE;
  1873. }
  1874. m_hContextMenu = ::GetSubMenu(m_hContextMenuBar, 0);
  1875. m_hGrobjContextMenuBar = ::LoadMenu(g_hInstance, MAKEINTRESOURCE(GROBJMENU));
  1876. if (!m_hGrobjContextMenuBar)
  1877. {
  1878. ERROR_OUT(("Failed to create grobj context menu"));
  1879. DefaultExceptionHandler(WBFE_RC_WINDOWS, 0);
  1880. return FALSE;
  1881. }
  1882. m_hGrobjContextMenu = ::GetSubMenu(m_hGrobjContextMenuBar, 0);
  1883. // make parts of m_hGrobjContextMenu be owner draw
  1884. ::ModifyMenu(m_hGrobjContextMenu, IDM_WIDTH_1, MF_ENABLED | MF_OWNERDRAW,
  1885. IDM_WIDTH_1, NULL);
  1886. ::ModifyMenu(m_hGrobjContextMenu, IDM_WIDTH_2, MF_ENABLED | MF_OWNERDRAW,
  1887. IDM_WIDTH_2, NULL);
  1888. ::ModifyMenu(m_hGrobjContextMenu, IDM_WIDTH_3, MF_ENABLED | MF_OWNERDRAW,
  1889. IDM_WIDTH_3, NULL);
  1890. ::ModifyMenu(m_hGrobjContextMenu, IDM_WIDTH_4, MF_ENABLED | MF_OWNERDRAW,
  1891. IDM_WIDTH_4, NULL);
  1892. return TRUE;
  1893. }
  1894. //
  1895. //
  1896. // Function: WbMainWindow::OnMeasureItem
  1897. //
  1898. // Purpose: Return the size of an item in the widths menu
  1899. //
  1900. //
  1901. void WbMainWindow::OnMeasureItem
  1902. (
  1903. int nIDCtl,
  1904. LPMEASUREITEMSTRUCT measureStruct
  1905. )
  1906. {
  1907. // Check that this is for a color menu item
  1908. if ( (measureStruct->itemID >= IDM_WIDTHS_START)
  1909. && (measureStruct->itemID < IDM_WIDTHS_END))
  1910. {
  1911. measureStruct->itemWidth = ::GetSystemMetrics(SM_CXMENUCHECK) +
  1912. (2 * CHECKMARK_BORDER_X) + COLOR_MENU_WIDTH;
  1913. measureStruct->itemHeight = ::GetSystemMetrics(SM_CYMENUCHECK) +
  1914. (2 * CHECKMARK_BORDER_Y);
  1915. }
  1916. }
  1917. //
  1918. //
  1919. // Function: WbMainWindow::OnDrawItem
  1920. //
  1921. // Purpose: Draw an item in the color menu
  1922. //
  1923. //
  1924. void WbMainWindow::OnDrawItem
  1925. (
  1926. int nIDCtl,
  1927. LPDRAWITEMSTRUCT drawStruct
  1928. )
  1929. {
  1930. COLORREF crMenuBackground;
  1931. COLORREF crMenuText;
  1932. HPEN hOldPen;
  1933. HBRUSH hOldBrush;
  1934. COLORREF crOldBkgnd;
  1935. COLORREF crOldText;
  1936. int nOldBkMode;
  1937. HBITMAP hbmp = NULL;
  1938. BITMAP bitmap;
  1939. UINT uiCheckWidth;
  1940. UINT uiCheckHeight;
  1941. RECT rect;
  1942. RECT rectCheck;
  1943. RECT rectLine;
  1944. HDC hMemDC;
  1945. UINT uiWidthIndex;
  1946. UINT uiWidth;
  1947. HPEN hPenMenu;
  1948. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnDrawItem");
  1949. // Check that this is a width menu item
  1950. if( (drawStruct->itemID < IDM_WIDTHS_START) ||
  1951. (drawStruct->itemID >= IDM_WIDTHS_END) )
  1952. {
  1953. return;
  1954. }
  1955. // get menu item colors
  1956. if( (drawStruct->itemState & ODS_SELECTED) ||
  1957. ((drawStruct->itemState & (ODS_SELECTED |ODS_CHECKED)) ==
  1958. (ODS_SELECTED |ODS_CHECKED))
  1959. )
  1960. {
  1961. crMenuBackground = COLOR_HIGHLIGHT;
  1962. crMenuText = COLOR_HIGHLIGHTTEXT;
  1963. }
  1964. else if( drawStruct->itemState & ODS_GRAYED)
  1965. {
  1966. crMenuBackground = COLOR_MENU;
  1967. crMenuText = COLOR_GRAYTEXT;
  1968. }
  1969. else
  1970. {
  1971. crMenuBackground = COLOR_MENU;
  1972. crMenuText = COLOR_MENUTEXT;
  1973. }
  1974. hPenMenu = ::CreatePen(PS_SOLID, 0, ::GetSysColor(crMenuBackground));
  1975. if (!hPenMenu)
  1976. {
  1977. TRACE_MSG(("Failed to create penMenu"));
  1978. ::PostMessage(m_hwnd, WM_USER_DISPLAY_ERROR, WBFE_RC_WINDOWS, 0);
  1979. goto bail_out;
  1980. }
  1981. rect = drawStruct->rcItem;
  1982. // Fill the whole box with current menu background color
  1983. hOldPen = SelectPen(drawStruct->hDC, hPenMenu);
  1984. hOldBrush = SelectBrush(drawStruct->hDC, GetSysColorBrush(crMenuBackground));
  1985. ::Rectangle(drawStruct->hDC, rect.left, rect.top, rect.right, rect.bottom);
  1986. SelectBrush(drawStruct->hDC, hOldBrush);
  1987. SelectPen(drawStruct->hDC, hOldPen);
  1988. if( (hbmp = (HBITMAP)LoadImage( NULL, MAKEINTRESOURCE( OBM_CHECK ), IMAGE_BITMAP,
  1989. 0,0, 0 ))
  1990. == NULL )
  1991. {
  1992. TRACE_MSG(("Failed to create check image"));
  1993. ::PostMessage(m_hwnd, WM_USER_DISPLAY_ERROR, WBFE_RC_WINDOWS, 0);
  1994. goto bail_out;
  1995. }
  1996. // Get the width and height of the bitmap (allowing some border)
  1997. ::GetObject(hbmp, sizeof(BITMAP), &bitmap);
  1998. uiCheckWidth = bitmap.bmWidth + (2 * CHECKMARK_BORDER_X);
  1999. uiCheckHeight = bitmap.bmHeight;
  2000. // Draw in a checkmark (if needed)
  2001. if (drawStruct->itemState & ODS_CHECKED)
  2002. {
  2003. hMemDC = ::CreateCompatibleDC(drawStruct->hDC);
  2004. if (!hMemDC)
  2005. {
  2006. ERROR_OUT(("Failed to create memDC"));
  2007. ::PostMessage(m_hwnd, WM_USER_DISPLAY_ERROR, WBFE_RC_WINDOWS, 0);
  2008. goto bail_out;
  2009. }
  2010. crOldBkgnd = ::SetBkColor(drawStruct->hDC, GetSysColor( crMenuBackground ) );
  2011. crOldText = ::SetTextColor(drawStruct->hDC, GetSysColor( crMenuText ) );
  2012. nOldBkMode = ::SetBkMode(drawStruct->hDC, OPAQUE );
  2013. HBITMAP hOld = SelectBitmap(hMemDC, hbmp);
  2014. if (hOld != NULL)
  2015. {
  2016. rectCheck = rect;
  2017. rectCheck.top += ((rectCheck.bottom - rectCheck.top)/2 - uiCheckHeight/2);
  2018. rectCheck.right = rectCheck.left + uiCheckWidth;
  2019. rectCheck.bottom = rectCheck.top + uiCheckHeight;
  2020. ::BitBlt(drawStruct->hDC, rectCheck.left,
  2021. rectCheck.top,
  2022. rectCheck.right - rectCheck.left,
  2023. rectCheck.bottom - rectCheck.top,
  2024. hMemDC,
  2025. 0,
  2026. 0,
  2027. SRCCOPY);
  2028. SelectBitmap(hMemDC, hOld);
  2029. }
  2030. ::SetBkMode(drawStruct->hDC, nOldBkMode);
  2031. ::SetTextColor(drawStruct->hDC, crOldText);
  2032. ::SetBkColor(drawStruct->hDC, crOldBkgnd);
  2033. ::DeleteDC(hMemDC);
  2034. }
  2035. DeleteBitmap(hbmp);
  2036. // Allow room for the checkmark to the left of the color
  2037. rect.left += uiCheckWidth;
  2038. uiWidthIndex = drawStruct->itemID - IDM_WIDTHS_START;
  2039. uiWidth = g_PenWidths[uiWidthIndex];
  2040. // If pens are very wide they can be larger than the allowed rectangle.
  2041. // So we reduce the clipping rectangle here. We save the DC so that we
  2042. // can restore it - getting the clip region back.
  2043. if (::SaveDC(drawStruct->hDC) == 0)
  2044. {
  2045. ERROR_OUT(("Failed to save DC"));
  2046. ::PostMessage(m_hwnd, WM_USER_DISPLAY_ERROR, WBFE_RC_WINDOWS, 0);
  2047. goto bail_out;
  2048. }
  2049. if (::IntersectClipRect(drawStruct->hDC, rect.left, rect.top,
  2050. rect.right, rect.bottom) == ERROR)
  2051. {
  2052. ERROR_OUT(("Failed to set clip rect"));
  2053. ::RestoreDC(drawStruct->hDC, -1);
  2054. ::PostMessage(m_hwnd, WM_USER_DISPLAY_ERROR, WBFE_RC_WINDOWS, 0);
  2055. goto bail_out;
  2056. }
  2057. hOldPen = SelectPen(drawStruct->hDC, hPenMenu);
  2058. hOldBrush = SelectBrush(drawStruct->hDC, GetSysColorBrush(crMenuText));
  2059. rectLine.left = rect.left;
  2060. rectLine.top = rect.top + ((rect.bottom - rect.top) / 2) - uiWidth/2;
  2061. rectLine.right= rect.right - ((rect.right - rect.left) / 6);
  2062. rectLine.bottom = rectLine.top + uiWidth + 2;
  2063. ::Rectangle(drawStruct->hDC, rectLine.left, rectLine.top,
  2064. rectLine.right, rectLine.bottom);
  2065. SelectBrush(drawStruct->hDC, hOldBrush);
  2066. SelectPen(drawStruct->hDC, hOldPen);
  2067. ::RestoreDC(drawStruct->hDC, -1);
  2068. bail_out:
  2069. if (hPenMenu != NULL)
  2070. {
  2071. ::DeletePen(hPenMenu);
  2072. }
  2073. }
  2074. //
  2075. //
  2076. // Function: OnSetFocus
  2077. //
  2078. // Purpose: The window is getting the focus
  2079. //
  2080. //
  2081. void WbMainWindow::OnSetFocus(void)
  2082. {
  2083. // We pass the focus on to the main drawing area
  2084. ::SetFocus(m_drawingArea.m_hwnd);
  2085. }
  2086. //
  2087. //
  2088. // Function: OnParentNotfiy
  2089. //
  2090. // Purpose: Process a message coming from a child window
  2091. //
  2092. //
  2093. void WbMainWindow::OnParentNotify(UINT uiMessage)
  2094. {
  2095. switch (uiMessage)
  2096. {
  2097. // Scroll message from the drawing area. These are sent when the user
  2098. // scrolls the area using the scroll bars. We queue an update of the
  2099. // current sync position.
  2100. case WM_HSCROLL:
  2101. case WM_VSCROLL:
  2102. // The user's view has changed
  2103. PositionUpdated();
  2104. break;
  2105. }
  2106. }
  2107. //
  2108. //
  2109. // Function: QuerySaveRequired
  2110. //
  2111. // Purpose: Check whether the drawing pane contents are to be saved
  2112. // before a destructive function is performed.
  2113. //
  2114. //
  2115. int WbMainWindow::QuerySaveRequired(BOOL bCancelBtn)
  2116. {
  2117. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::QuerySaveRequired");
  2118. // If we are not maximized
  2119. if (!::IsZoomed(m_hwnd) && !::IsIconic(m_hwnd))
  2120. {
  2121. // Save the new position of the window
  2122. SaveWindowPosition();
  2123. }
  2124. // Default the response to "no save required"
  2125. int iResult = IDNO;
  2126. //
  2127. // If we are already displaying a "Save As" dialog, dismiss it.
  2128. //
  2129. if (m_hwndQuerySaveDlg != NULL)
  2130. {
  2131. ::SendMessage(m_hwndQuerySaveDlg, WM_COMMAND,
  2132. MAKELONG(IDCANCEL, BN_CLICKED), 0);
  2133. ASSERT(m_hwndQuerySaveDlg == NULL);
  2134. }
  2135. // If any of the pages has changed - ask the user if they want to
  2136. // save the contents of the Whiteboard.
  2137. if (g_bContentsChanged && IsThereAnythingInAnyWorkspace())
  2138. {
  2139. ::SetForegroundWindow(m_hwnd); //bring us to the top first
  2140. // SetForegroundWindow() does not work properly in Memphis when its called during a
  2141. // SendMessage handler, specifically, when conf calls me to shutdown. The window activation
  2142. // state is messed up or something and my window does not pop to the top. So I have to
  2143. // force my window to the top using SetWindowPos. But even after that the titlebar is not
  2144. // highlighted properly. I tried combinations of SetActiveWindow, SetFocus, etc but to no
  2145. // avail. But, at least the dialog is visible so you can clear it thus fixing the
  2146. // bug (NM4db:2103). SetForegroundWindow() works ok for Win95 and NT here without
  2147. // having to use SetWindowPos (it doesn't hurt anyting to do it anyway so I didn't
  2148. // do a platform check).
  2149. ::SetWindowPos(m_hwnd, HWND_TOPMOST, 0,0, 0,0, SWP_NOMOVE | SWP_NOSIZE ); // force to top
  2150. ::SetWindowPos(m_hwnd, HWND_NOTOPMOST, 0,0, 0,0, SWP_NOMOVE | SWP_NOSIZE ); // let go of topmost
  2151. //
  2152. // Display a dialog box with the relevant question
  2153. // LOWORD of user data is "cancel command is allowed"
  2154. // HIWORD of user data is "disable cancel button"
  2155. //
  2156. iResult = (int)DialogBoxParam(g_hInstance,
  2157. bCancelBtn ? MAKEINTRESOURCE(QUERYSAVEDIALOGCANCEL)
  2158. : MAKEINTRESOURCE(QUERYSAVEDIALOG),
  2159. m_hwnd,
  2160. QuerySaveDlgProc,
  2161. MAKELONG(bCancelBtn, FALSE));
  2162. }
  2163. return iResult;
  2164. }
  2165. //
  2166. // QuerySaveDlgProc()
  2167. // Handler for query save dialogs. We save some flags in GWL_USER
  2168. //
  2169. INT_PTR CALLBACK QuerySaveDlgProc(HWND hwnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
  2170. {
  2171. BOOL fHandled = FALSE;
  2172. switch (uMessage)
  2173. {
  2174. case WM_INITDIALOG:
  2175. //
  2176. // Save away our HWND so this dialog can be cancelled if necessary
  2177. //
  2178. g_pMain->m_hwndQuerySaveDlg = hwnd;
  2179. // Remember the flags we passed
  2180. ::SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
  2181. // Should the cancel button be disabled?
  2182. if (HIWORD(lParam))
  2183. ::EnableWindow(::GetDlgItem(hwnd, IDCANCEL), FALSE);
  2184. // Bring us to the front
  2185. ::SetForegroundWindow(hwnd);
  2186. fHandled = TRUE;
  2187. break;
  2188. case WM_CLOSE:
  2189. // Even if the cancel button is disabled, kill the dialog
  2190. ::PostMessage(hwnd, WM_COMMAND, IDCANCEL, 0);
  2191. fHandled = TRUE;
  2192. break;
  2193. case WM_COMMAND:
  2194. switch (GET_WM_COMMAND_ID(wParam, lParam))
  2195. {
  2196. case IDCANCEL:
  2197. //
  2198. // If a dialog doesn't have a cancel button or it's
  2199. // disabled and the user pressed the close btn, we can
  2200. // get here.
  2201. //
  2202. if (!LOWORD(::GetWindowLongPtr(hwnd, GWLP_USERDATA)))
  2203. wParam = MAKELONG(IDNO, HIWORD(wParam));
  2204. // FALL THRU
  2205. case IDYES:
  2206. case IDNO:
  2207. if (GET_WM_COMMAND_CMD(wParam, lParam) == BN_CLICKED)
  2208. {
  2209. g_pMain->m_hwndQuerySaveDlg = NULL;
  2210. ::EndDialog(hwnd, GET_WM_COMMAND_ID(wParam, lParam));
  2211. break;
  2212. }
  2213. break;
  2214. }
  2215. fHandled = TRUE;
  2216. break;
  2217. }
  2218. return(fHandled);
  2219. }
  2220. //
  2221. //
  2222. // Function: OnNew
  2223. //
  2224. // Purpose: Clear the workspace and associated filenames
  2225. //
  2226. //
  2227. LRESULT WbMainWindow::OnNew(void)
  2228. {
  2229. int iDoNew;
  2230. if( UsersMightLoseData( NULL, NULL ) ) // bug NM4db:418
  2231. return S_OK;
  2232. // check state before proceeding - if we're already doing a new, then abort
  2233. if (m_uiSubState == SUBSTATE_NEW_IN_PROGRESS)
  2234. {
  2235. // post an error message indicating the whiteboard is busy
  2236. ::PostMessage(m_hwnd, WM_USER_DISPLAY_ERROR, WBFE_RC_WB, WB_RC_BUSY);
  2237. return S_OK;
  2238. }
  2239. // if we're currently loading, then cancel the load and proceed (don't
  2240. // prompt to save).
  2241. else if (m_uiSubState == SUBSTATE_LOADING)
  2242. {
  2243. // cancel load, not releasing the page order lock, because
  2244. // we need it immediately afterwards
  2245. CancelLoad(FALSE);
  2246. iDoNew = IDNO;
  2247. }
  2248. // otherwise prompt to save if necessary
  2249. else
  2250. {
  2251. // Get confirmation for the new
  2252. iDoNew = QuerySaveRequired(TRUE);
  2253. }
  2254. if (iDoNew == IDYES)
  2255. {
  2256. // Save the changes
  2257. iDoNew = (int)OnSave(FALSE);
  2258. }
  2259. // If the user did not cancel the operation, clear the drawing area
  2260. if (iDoNew != IDCANCEL)
  2261. {
  2262. //
  2263. // Remember if we had a remote pointer.
  2264. // In OldWB, the remote pointer is a global thing that clearing
  2265. // doesn't get rid of.
  2266. // In T.126WB, it's just an object on a page, so we need to add
  2267. // it back because we're deleting the old pages and creating
  2268. // new ones.
  2269. //
  2270. BOOL bRemote = FALSE;
  2271. if (m_pLocalRemotePointer)
  2272. {
  2273. // Remove remote pointer from pages
  2274. bRemote = TRUE;
  2275. OnRemotePointer();
  2276. }
  2277. ::InvalidateRect(g_pDraw->m_hwnd, NULL, TRUE);
  2278. DeleteAllWorkspaces(TRUE);
  2279. WorkspaceObj * pObj;
  2280. DBG_SAVE_FILE_LINE
  2281. pObj = new WorkspaceObj();
  2282. pObj->AddToWorkspace();
  2283. if (bRemote)
  2284. {
  2285. // Put it back
  2286. OnRemotePointer();
  2287. }
  2288. // Clear the associated file name
  2289. ZeroMemory(m_strFileName, sizeof(m_strFileName));
  2290. // Update the window title with no file name
  2291. UpdateWindowTitle();
  2292. }
  2293. return S_OK;
  2294. }
  2295. //
  2296. //
  2297. // Function: OnNextPage
  2298. //
  2299. // Purpose: Move to the next worksheet in the pages list
  2300. //
  2301. //
  2302. LRESULT WbMainWindow::OnNextPage(void)
  2303. {
  2304. // Go to the next page
  2305. if(g_pCurrentWorkspace)
  2306. {
  2307. WBPOSITION pos = g_pCurrentWorkspace->GetMyPosition();
  2308. g_pListOfWorkspaces->GetNext(pos);
  2309. if(pos)
  2310. {
  2311. WorkspaceObj* pWorkspace = (WorkspaceObj*)g_pListOfWorkspaces->GetNext(pos);
  2312. GotoPage(pWorkspace);
  2313. }
  2314. }
  2315. return S_OK;
  2316. }
  2317. //
  2318. //
  2319. // Function: OnPrevPage
  2320. //
  2321. // Purpose: Move to the previous worksheet in the pages list
  2322. //
  2323. //
  2324. LRESULT WbMainWindow::OnPrevPage(void)
  2325. {
  2326. if(g_pCurrentWorkspace)
  2327. {
  2328. WBPOSITION pos = g_pCurrentWorkspace->GetMyPosition();
  2329. g_pListOfWorkspaces->GetPrevious(pos);
  2330. if(pos)
  2331. {
  2332. WorkspaceObj* pWorkspace = (WorkspaceObj*)g_pListOfWorkspaces->GetPrevious(pos);
  2333. GotoPage(pWorkspace);
  2334. }
  2335. }
  2336. return S_OK;
  2337. }
  2338. //
  2339. //
  2340. // Function: OnFirstPage
  2341. //
  2342. // Purpose: Move to the first worksheet in the pages list
  2343. //
  2344. //
  2345. LRESULT WbMainWindow::OnFirstPage(void)
  2346. {
  2347. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnFirstPage");
  2348. WorkspaceObj * pWorkspace = (WorkspaceObj *)g_pListOfWorkspaces->GetHead();
  2349. GotoPage(pWorkspace);
  2350. return S_OK;
  2351. }
  2352. //
  2353. //
  2354. // Function: OnLastPage
  2355. //
  2356. // Purpose: Move to the last worksheet in the pages list
  2357. //
  2358. //
  2359. LRESULT WbMainWindow::OnLastPage(void)
  2360. {
  2361. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnLastPage");
  2362. WorkspaceObj * pWorkspace = (WorkspaceObj *)g_pListOfWorkspaces->GetTail();
  2363. GotoPage(pWorkspace);
  2364. return S_OK;
  2365. }
  2366. //
  2367. //
  2368. // Function: OnGotoPage
  2369. //
  2370. // Purpose: Move to the specified page (if it exists)
  2371. //
  2372. //
  2373. LRESULT WbMainWindow::OnGotoPage(void)
  2374. {
  2375. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnGotoPage");
  2376. // Get the requested page number from the pages group
  2377. UINT uiPageNumber = m_AG.GetCurrentPageNumber() - 1;
  2378. WBPOSITION pos;
  2379. WorkspaceObj* pWorkspace = NULL;
  2380. pos = g_pListOfWorkspaces->GetHeadPosition();
  2381. while(pos && uiPageNumber != 0)
  2382. {
  2383. g_pListOfWorkspaces->GetNext(pos);
  2384. uiPageNumber--;
  2385. }
  2386. if(pos)
  2387. {
  2388. pWorkspace = (WorkspaceObj *)g_pListOfWorkspaces->GetNext(pos);
  2389. GotoPage(pWorkspace);
  2390. }
  2391. return S_OK;
  2392. }
  2393. //
  2394. // Check if remote pointer was on before we go to page
  2395. //
  2396. void WbMainWindow::GotoPage(WorkspaceObj * pNewWorkspace, BOOL bSend)
  2397. {
  2398. //
  2399. // If we were editing text
  2400. //
  2401. if (g_pDraw->TextEditActive())
  2402. {
  2403. g_pDraw->EndTextEntry(TRUE);
  2404. }
  2405. //
  2406. // If we had a remote pointer
  2407. //
  2408. BOOL bRemote = FALSE;
  2409. if(m_pLocalRemotePointer)
  2410. {
  2411. bRemote = TRUE;
  2412. OnRemotePointer();
  2413. }
  2414. //
  2415. // Undraw remote pointers
  2416. //
  2417. T126Obj * pPointer = g_pCurrentWorkspace->GetTail();
  2418. WBPOSITION pos = g_pCurrentWorkspace->GetTailPosition();
  2419. while(pos && pPointer->GraphicTool() == TOOLTYPE_REMOTEPOINTER)
  2420. {
  2421. pPointer->UnDraw();
  2422. pPointer = (T126Obj*) g_pCurrentWorkspace->GetPreviousObject(pos);
  2423. }
  2424. GoPage(pNewWorkspace, bSend);
  2425. //
  2426. // Draw remote pointers back
  2427. //
  2428. pPointer = g_pCurrentWorkspace->GetTail();
  2429. pos = g_pCurrentWorkspace->GetTailPosition();
  2430. while(pos && pPointer->GraphicTool() == TOOLTYPE_REMOTEPOINTER)
  2431. {
  2432. pPointer->Draw();
  2433. pPointer = (T126Obj*) g_pCurrentWorkspace->GetPreviousObject(pos);
  2434. }
  2435. //
  2436. // If we had a remote pointer
  2437. //
  2438. if(bRemote)
  2439. {
  2440. OnRemotePointer();
  2441. }
  2442. }
  2443. //
  2444. //
  2445. // Function: GoPage
  2446. //
  2447. // Purpose: Move to the specified page
  2448. //
  2449. //
  2450. void WbMainWindow::GoPage(WorkspaceObj * pNewWorkspace, BOOL bSend)
  2451. {
  2452. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::GotoPage");
  2453. // If we are changing pages
  2454. if (pNewWorkspace != g_pCurrentWorkspace)
  2455. {
  2456. m_drawingArea.CancelDrawingMode();
  2457. // Attach the new page to the drawing area
  2458. m_drawingArea.Attach(pNewWorkspace);
  2459. // set the focus back to the drawing area
  2460. if (!(m_AG.IsChildEditField(::GetFocus())))
  2461. {
  2462. ::SetFocus(m_drawingArea.m_hwnd);
  2463. }
  2464. ::InvalidateRect(m_drawingArea.m_hwnd, NULL, TRUE );
  2465. ::UpdateWindow(m_drawingArea.m_hwnd);
  2466. //
  2467. // Tell the other nodes we moved to a different page.
  2468. //
  2469. if(bSend)
  2470. {
  2471. //
  2472. // Set the view state
  2473. //
  2474. pNewWorkspace->SetViewState(focus_chosen);
  2475. pNewWorkspace->SetViewActionChoice(editView_chosen);
  2476. pNewWorkspace->OnObjectEdit();
  2477. }
  2478. }
  2479. UpdatePageButtons();
  2480. }
  2481. //
  2482. //
  2483. // Function: GotoPosition
  2484. //
  2485. // Purpose: Move to the specified position within the page
  2486. //
  2487. //
  2488. void WbMainWindow::GotoPosition(int x, int y)
  2489. {
  2490. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::GotoPosition");
  2491. // Move the drawing area to the new position
  2492. m_drawingArea.GotoPosition(x, y);
  2493. // The user's view has changed
  2494. PositionUpdated();
  2495. }
  2496. //
  2497. //
  2498. // Function: LoadFile
  2499. //
  2500. // Purpose: Load a metafile into the application. Errors are reported
  2501. // to the caller by the return code.
  2502. //
  2503. //
  2504. void WbMainWindow::LoadFile
  2505. (
  2506. LPCSTR szLoadFileName
  2507. )
  2508. {
  2509. UINT uRes;
  2510. // Check we're in idle state
  2511. if (!IsIdle())
  2512. {
  2513. // post an error message indicating the whiteboard is busy
  2514. ::PostMessage(m_hwnd, WM_USER_DISPLAY_ERROR, WBFE_RC_WB, WB_RC_BUSY);
  2515. goto UserPointerCleanup;
  2516. }
  2517. if (*szLoadFileName)
  2518. {
  2519. // Change the cursor to "wait"
  2520. ::SetCursor(::LoadCursor(NULL, IDC_WAIT));
  2521. // Set the state to say that we are loading a file
  2522. SetSubstate(SUBSTATE_LOADING);
  2523. // Load the file
  2524. uRes = ContentsLoad(szLoadFileName);
  2525. if (uRes != 0)
  2526. {
  2527. DefaultExceptionHandler(WBFE_RC_WB, uRes);
  2528. goto UserPointerCleanup;
  2529. }
  2530. // Set the window title to the new file name
  2531. lstrcpy(m_strFileName, szLoadFileName);
  2532. // Update the window title with the new file name
  2533. g_bContentsChanged = FALSE;
  2534. }
  2535. UserPointerCleanup:
  2536. // Set the state to say that we are loading a file
  2537. SetSubstate(SUBSTATE_IDLE);
  2538. // Restore the cursor
  2539. ::SetCursor(::LoadCursor(NULL, IDC_ARROW));
  2540. }
  2541. //
  2542. //
  2543. // Function: OnDropFiles
  2544. //
  2545. // Purpose: Files have been dropped onto the Whiteboard window
  2546. //
  2547. //
  2548. void WbMainWindow::OnDropFiles(HDROP hDropInfo)
  2549. {
  2550. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnDropFiles");
  2551. UINT uiFilesDropped = 0;
  2552. UINT eachfile;
  2553. PT126WB_FILE_HEADER_AND_OBJECTS pHeader = NULL;
  2554. // Get the total number of files dropped
  2555. uiFilesDropped = ::DragQueryFile(hDropInfo, (UINT) -1, NULL, (UINT) 0);
  2556. // release mouse capture in case we report any errors (message boxes
  2557. // won't repsond to mouse clicks if we don't)
  2558. ReleaseCapture();
  2559. for (eachfile = 0; eachfile < uiFilesDropped; eachfile++)
  2560. {
  2561. // Retrieve each file name
  2562. char szDropFileName[256];
  2563. ::DragQueryFile(hDropInfo, eachfile,
  2564. szDropFileName, 256);
  2565. TRACE_MSG(("Loading file: %s", szDropFileName));
  2566. OnOpen(szDropFileName);
  2567. }
  2568. ::DragFinish(hDropInfo);
  2569. }
  2570. //
  2571. //
  2572. // Function: OnOpen
  2573. //
  2574. // Purpose: Load a metafile into the application.
  2575. //
  2576. //
  2577. LRESULT WbMainWindow::OnOpen(LPCSTR szLoadFileName)
  2578. {
  2579. int iOnSave;
  2580. if(g_pDraw->IsLocked() || !g_pDraw->IsSynced())
  2581. {
  2582. DefaultExceptionHandler(WBFE_RC_WB, WB_RC_BAD_STATE);
  2583. return S_FALSE;
  2584. }
  2585. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnOpen");
  2586. if( UsersMightLoseData( NULL, NULL ) ) // bug NM4db:418
  2587. return S_OK;
  2588. // Check we're in idle state
  2589. if ((m_uiSubState == SUBSTATE_NEW_IN_PROGRESS))
  2590. {
  2591. // post an error message indicating the whiteboard is busy
  2592. ::PostMessage(m_hwnd, WM_USER_DISPLAY_ERROR, WBFE_RC_WB, WB_RC_BUSY);
  2593. return S_OK;
  2594. }
  2595. // Don't prompt to save file if we're already loading
  2596. if (m_uiSubState != SUBSTATE_LOADING)
  2597. {
  2598. // Check whether there are changes to be saved
  2599. iOnSave = QuerySaveRequired(TRUE);
  2600. }
  2601. else
  2602. {
  2603. iOnSave = IDNO;
  2604. }
  2605. if (iOnSave == IDYES)
  2606. {
  2607. // User wants to save the drawing area contents
  2608. int iResult = (int)OnSave(TRUE);
  2609. if (iResult == IDOK)
  2610. {
  2611. }
  2612. else
  2613. {
  2614. // cancelled out of Save As, so cancel the open operation
  2615. iOnSave = IDCANCEL;
  2616. }
  2617. }
  2618. // Only continue if the user has not cancelled the operation
  2619. if (iOnSave != IDCANCEL)
  2620. {
  2621. //
  2622. // If the filename was passed
  2623. //
  2624. if(szLoadFileName)
  2625. {
  2626. LoadFile(szLoadFileName);
  2627. }
  2628. else
  2629. {
  2630. OPENFILENAME ofn;
  2631. TCHAR szFileName[_MAX_PATH];
  2632. TCHAR szFileTitle[64];
  2633. TCHAR strLoadFilter[2*_MAX_PATH];
  2634. TCHAR strDefaultExt[_MAX_PATH];
  2635. TCHAR strDefaultPath[2*_MAX_PATH];
  2636. TCHAR * pStr;
  2637. UINT strSize = 0;
  2638. UINT totalSize;
  2639. // Build the filter for loadable files
  2640. pStr = strLoadFilter;
  2641. totalSize = 2*_MAX_PATH;
  2642. // These must be NULL separated, with a double NULL at the end
  2643. strSize = ::LoadString(g_hInstance, IDS_FILTER_WHT, pStr, totalSize) + 1;
  2644. pStr += strSize;
  2645. ASSERT(totalSize > strSize);
  2646. totalSize -= strSize;
  2647. strSize = ::LoadString(g_hInstance, IDS_FILTER_WHT_SPEC, pStr, totalSize) + 1;
  2648. pStr += strSize;
  2649. ASSERT(totalSize > strSize);
  2650. totalSize -= strSize;
  2651. strSize = ::LoadString(g_hInstance, IDS_FILTER_ALL, pStr, totalSize) + 1;
  2652. pStr += strSize;
  2653. ASSERT(totalSize > strSize);
  2654. totalSize -= strSize;
  2655. strSize = ::LoadString(g_hInstance, IDS_FILTER_ALL_SPEC, pStr, totalSize) + 1;
  2656. pStr += strSize;
  2657. ASSERT(totalSize > strSize);
  2658. totalSize -= strSize;
  2659. *pStr = 0;
  2660. //
  2661. // Setup the OPENFILENAME struct
  2662. //
  2663. ZeroMemory(&ofn, sizeof(ofn));
  2664. ofn.lStructSize = sizeof(ofn);
  2665. ofn.hwndOwner = m_hwnd;
  2666. // No file name supplied to begin with
  2667. szFileName[0] = 0;
  2668. ofn.lpstrFile = szFileName;
  2669. ofn.nMaxFile = _MAX_PATH;
  2670. // Default Extension: .NMW
  2671. ::LoadString(g_hInstance, IDS_EXT_WHT, strDefaultExt, sizeof(strDefaultExt));
  2672. ofn.lpstrDefExt = strDefaultExt;
  2673. // Default file title is empty
  2674. szFileTitle[0] = 0;
  2675. ofn.lpstrFileTitle = szFileTitle;
  2676. ofn.nMaxFileTitle = 64;
  2677. // Open flags
  2678. ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_EXPLORER;
  2679. ofn.hInstance = g_hInstance;
  2680. // Filter
  2681. ofn.lpstrFilter = strLoadFilter;
  2682. // Default path
  2683. if (GetDefaultPath(strDefaultPath, sizeof(strDefaultPath)))
  2684. ofn.lpstrInitialDir = strDefaultPath;
  2685. // Get user input, continue only if the user selects the OK button
  2686. if (::GetOpenFileName(&ofn))
  2687. {
  2688. // Change the cursor to "wait"
  2689. ::SetCursor(::LoadCursor(NULL, IDC_WAIT));
  2690. // if we're currently loading a file, cancel it, not releasing
  2691. // the page order lock, because we need it immediately afterwards
  2692. if (m_uiSubState == SUBSTATE_LOADING)
  2693. {
  2694. CancelLoad(FALSE);
  2695. }
  2696. // Load the file
  2697. LoadFile(ofn.lpstrFile);
  2698. }
  2699. }
  2700. }
  2701. // Update the window title with no file name
  2702. UpdateWindowTitle();
  2703. return S_OK;
  2704. }
  2705. //
  2706. //
  2707. // Function: GetFileName
  2708. //
  2709. // Purpose: Get a file name for saving the contents
  2710. //
  2711. //
  2712. int WbMainWindow::GetFileName(void)
  2713. {
  2714. OPENFILENAME ofn;
  2715. int iResult;
  2716. TCHAR szFileTitle[64];
  2717. TCHAR strSaveFilter[2*_MAX_PATH];
  2718. TCHAR strDefaultExt[_MAX_PATH];
  2719. TCHAR strDefaultPath[2 * _MAX_PATH];
  2720. TCHAR szFileName[2*_MAX_PATH];
  2721. TCHAR * pStr;
  2722. UINT strSize = 0;
  2723. UINT totalSize;
  2724. //
  2725. // If we are already displaying a "Save As" dialog, dismiss it and create
  2726. // a new one. This can happen if Win95 shuts down whilst WB is
  2727. // displaying the "Save As" dialog and the use selects "Yes" when asked
  2728. // whether they want to save the contents - a second "Save As dialog
  2729. // appears on top of the first.
  2730. //
  2731. if (m_bInSaveDialog)
  2732. {
  2733. CancelSaveDialog();
  2734. }
  2735. // Build the filter for save files
  2736. pStr = strSaveFilter;
  2737. totalSize = 2*_MAX_PATH;
  2738. // These must be NULL separated, with a double NULL at the end
  2739. strSize = ::LoadString(g_hInstance, IDS_FILTER_WHT, pStr, totalSize) + 1;
  2740. pStr += strSize;
  2741. ASSERT(totalSize > strSize);
  2742. totalSize -= strSize;
  2743. strSize = ::LoadString(g_hInstance, IDS_FILTER_WHT_SPEC, pStr, totalSize) + 1;
  2744. pStr += strSize;
  2745. ASSERT(totalSize > strSize);
  2746. totalSize -= strSize;
  2747. strSize = ::LoadString(g_hInstance, IDS_FILTER_ALL, pStr, totalSize) + 1;
  2748. pStr += strSize;
  2749. ASSERT(totalSize > strSize);
  2750. totalSize -= strSize;
  2751. strSize = ::LoadString(g_hInstance, IDS_FILTER_ALL_SPEC, pStr, totalSize) + 1;
  2752. pStr += strSize;
  2753. ASSERT(totalSize > strSize);
  2754. totalSize -= strSize;
  2755. *pStr = 0;
  2756. //
  2757. // Setup the OPENFILENAME struct
  2758. //
  2759. ZeroMemory(&ofn, sizeof(ofn));
  2760. ofn.lStructSize = sizeof(ofn);
  2761. ofn.hwndOwner = m_hwnd;
  2762. lstrcpy(szFileName, m_strFileName);
  2763. ofn.lpstrFile = szFileName;
  2764. ofn.nMaxFile = _MAX_PATH;
  2765. // Build the default extension string
  2766. ::LoadString(g_hInstance, IDS_EXT_WHT, strDefaultExt, sizeof(strDefaultExt));
  2767. ofn.lpstrDefExt = strDefaultExt;
  2768. szFileTitle[0] = 0;
  2769. ofn.lpstrFileTitle = szFileTitle;
  2770. ofn.nMaxFileTitle = 64;
  2771. // Save flags
  2772. ofn.Flags = OFN_HIDEREADONLY | OFN_NOREADONLYRETURN |
  2773. OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST;
  2774. ofn.hInstance = g_hInstance;
  2775. // Filter
  2776. ofn.lpstrFilter = strSaveFilter;
  2777. // Default path
  2778. if (GetDefaultPath(strDefaultPath, sizeof(strDefaultPath)))
  2779. ofn.lpstrInitialDir = strDefaultPath;
  2780. m_bInSaveDialog = TRUE;
  2781. if (::GetSaveFileName(&ofn))
  2782. {
  2783. // The user selected OK
  2784. iResult = IDOK;
  2785. lstrcpy(m_strFileName, szFileName);
  2786. }
  2787. else
  2788. {
  2789. iResult = IDCANCEL;
  2790. }
  2791. m_bInSaveDialog = FALSE;
  2792. return iResult;
  2793. }
  2794. //
  2795. //
  2796. // Function: OnSave
  2797. //
  2798. // Purpose: Save the contents of the Whiteboard using the current file
  2799. // name (or prompting for a new name if there is no current).
  2800. //
  2801. //
  2802. LRESULT WbMainWindow::OnSave(BOOL bPrompt)
  2803. {
  2804. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnSave");
  2805. LRESULT iResult = IDOK;
  2806. // save the old file name in case there's an error
  2807. TCHAR strOldName[2*MAX_PATH];
  2808. UINT fileNameSize = lstrlen(m_strFileName);
  2809. lstrcpy(strOldName, m_strFileName);
  2810. BOOL bNewName = FALSE;
  2811. if (!IsIdle())
  2812. {
  2813. // post an error message indicating the whiteboard is busy
  2814. ::PostMessage(m_hwnd, WM_USER_DISPLAY_ERROR, WBFE_RC_WB, WB_RC_BUSY);
  2815. return(iResult);
  2816. }
  2817. // Check whether there is a filename available for use
  2818. if (!fileNameSize || (bPrompt))
  2819. {
  2820. // Get user input, continue only if the user selects the OK button
  2821. iResult = GetFileName();
  2822. if (iResult == IDOK)
  2823. {
  2824. // entering a blank file name is treated as cancelling the save
  2825. if (!lstrlen(m_strFileName))
  2826. {
  2827. lstrcpy(m_strFileName, strOldName);
  2828. iResult = IDCANCEL;
  2829. }
  2830. else
  2831. {
  2832. // flag that we've changed the contents file name
  2833. bNewName = TRUE;
  2834. }
  2835. }
  2836. }
  2837. // Now save the file
  2838. if ((iResult == IDOK) && lstrlen(m_strFileName))
  2839. {
  2840. WIN32_FIND_DATA findFileData;
  2841. HANDLE hFind;
  2842. // Get attributes
  2843. hFind = ::FindFirstFile(m_strFileName, &findFileData);
  2844. if (hFind != INVALID_HANDLE_VALUE)
  2845. {
  2846. ::FindClose(hFind);
  2847. // This is a read-only file; we can't change its contents
  2848. if (findFileData.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
  2849. {
  2850. WARNING_OUT(("Dest file %s is read only", m_strFileName));
  2851. ::Message(NULL, IDS_SAVE, IDS_SAVE_READ_ONLY);
  2852. // If the file name was changed for this save then undo
  2853. // the change
  2854. if (bNewName)
  2855. {
  2856. lstrcpy(m_strFileName, strOldName);
  2857. bNewName = FALSE;
  2858. }
  2859. // Change the return code to indicate no save was made
  2860. iResult = IDCANCEL;
  2861. return(iResult);
  2862. }
  2863. }
  2864. // Change the cursor to "wait"
  2865. ::SetCursor(::LoadCursor(NULL,IDC_WAIT));
  2866. // Write the file
  2867. if (ContentsSave(m_strFileName) != 0)
  2868. {
  2869. // Show that an error occurred saving the file.
  2870. WARNING_OUT(("Error saving file"));
  2871. ::Message(NULL, IDS_SAVE, IDS_SAVE_ERROR);
  2872. // If the file name was changed for this save then undo
  2873. // the change
  2874. if (bNewName)
  2875. {
  2876. lstrcpy(m_strFileName, strOldName);
  2877. bNewName = FALSE;
  2878. }
  2879. // Change the return code to indicate no save was made
  2880. iResult = IDCANCEL;
  2881. }
  2882. else
  2883. {
  2884. g_bContentsChanged = FALSE;
  2885. }
  2886. // Restore the cursor
  2887. ::SetCursor(::LoadCursor(NULL,IDC_ARROW));
  2888. }
  2889. // if the contents file name has changed as a result of the save then
  2890. // update the window title
  2891. if (bNewName)
  2892. {
  2893. UpdateWindowTitle();
  2894. }
  2895. return(iResult);
  2896. }
  2897. //
  2898. // CancelSaveDialog()
  2899. // This cancels the save as dialog if up and we need to kill it to continue.
  2900. // We walk back up the owner chain in case the save dialog puts up help or
  2901. // other owned windows.
  2902. //
  2903. void WbMainWindow::CancelSaveDialog(void)
  2904. {
  2905. WBFINDDIALOG wbf;
  2906. ASSERT(m_bInSaveDialog);
  2907. wbf.hwndOwner = m_hwnd;
  2908. wbf.hwndDialog = NULL;
  2909. EnumThreadWindows(::GetCurrentThreadId(), WbFindCurrentDialog, (LPARAM)&wbf);
  2910. if (wbf.hwndDialog)
  2911. {
  2912. // Found it!
  2913. ::SendMessage(wbf.hwndDialog, WM_COMMAND, IDCANCEL, 0);
  2914. }
  2915. m_bInSaveDialog = FALSE;
  2916. }
  2917. BOOL CALLBACK WbFindCurrentDialog(HWND hwndNext, LPARAM lParam)
  2918. {
  2919. WBFINDDIALOG * pwbf = (WBFINDDIALOG *)lParam;
  2920. // Is this a dialog, owned by the main window?
  2921. if ((::GetClassLong(hwndNext, GCW_ATOM) == 0x8002) &&
  2922. (::GetWindow(hwndNext, GW_OWNER) == pwbf->hwndOwner))
  2923. {
  2924. pwbf->hwndDialog = hwndNext;
  2925. return(FALSE);
  2926. }
  2927. return(TRUE);
  2928. }
  2929. //
  2930. //
  2931. // Function: OnClose
  2932. //
  2933. // Purpose: Close the Whiteboard
  2934. //
  2935. //
  2936. void WbMainWindow::OnClose()
  2937. {
  2938. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnClose");
  2939. int iOnSave = IDOK;
  2940. m_drawingArea.CancelDrawingMode();
  2941. m_AG.SaveSettings();
  2942. // If we got here, by way of OnDestroy from the DCL cores or
  2943. // by system shutdown, then assume that user responded already to the
  2944. // save-changes dialog that would have poped up during conf's global shutdown
  2945. // message. We don't need to ask 'em again. What tangled webs......
  2946. if ((!m_bQuerySysShutdown) && (IsIdle()))
  2947. {
  2948. // Check whether there are changes to be saved
  2949. iOnSave = QuerySaveRequired(TRUE);
  2950. if (iOnSave == IDYES)
  2951. {
  2952. // User wants to save the drawing area contents
  2953. iOnSave = (int)OnSave(TRUE);
  2954. }
  2955. }
  2956. // If the exit was not cancelled, close the application
  2957. if (iOnSave != IDCANCEL)
  2958. {
  2959. // Close the application
  2960. ::PostQuitMessage(0);
  2961. }
  2962. }
  2963. //
  2964. //
  2965. // Function: OnClearPage
  2966. //
  2967. // Purpose: Clear the Whiteboard drawing area. The user is prompted to
  2968. // choose clearing of foreground, background or both.
  2969. //
  2970. //
  2971. LRESULT WbMainWindow::OnClearPage(BOOL bClearAll)
  2972. {
  2973. LRESULT iResult;
  2974. BOOL bWasPosted;
  2975. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnClearPage");
  2976. if( UsersMightLoseData( &bWasPosted, NULL ) ) // bug NM4db:418
  2977. return S_OK;
  2978. if( bWasPosted )
  2979. iResult = IDYES;
  2980. else
  2981. iResult = ::Message(NULL, bClearAll == FALSE ? IDS_DELETE_PAGE : IDS_CLEAR_CAPTION, bClearAll == FALSE ? IDS_DELETE_PAGE_MESSAGE : IDS_CLEAR_MESSAGE, MB_YESNO | MB_ICONQUESTION);
  2982. if ((iResult == IDYES) && bClearAll)
  2983. {
  2984. OnSelectAll();
  2985. OnDelete();
  2986. TRACE_MSG(("User requested clear of page"));
  2987. }
  2988. return iResult;
  2989. }
  2990. //
  2991. //
  2992. // Function: OnDelete
  2993. //
  2994. // Purpose: Delete the current selection
  2995. //
  2996. //
  2997. LRESULT WbMainWindow::OnDelete()
  2998. {
  2999. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnDelete");
  3000. // cleanup select logic in case object context menu called us (bug 426)
  3001. m_drawingArea.SetLClickIgnore( FALSE );
  3002. // Delete the currently selected graphics and add to m_LastDeletedGraphic
  3003. m_drawingArea.EraseSelectedDrawings();
  3004. return S_OK;
  3005. }
  3006. //
  3007. //
  3008. // Function: OnUndelete
  3009. //
  3010. // Purpose: Undo the last delete operation
  3011. //
  3012. //
  3013. LRESULT WbMainWindow::OnUndelete()
  3014. {
  3015. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnUndelete");
  3016. // If there is a deleted graphic to restore
  3017. T126Obj * pObj;
  3018. pObj = (T126Obj *)g_pTrash->RemoveHead();
  3019. while (pObj != NULL)
  3020. {
  3021. if(!AddT126ObjectToWorkspace(pObj))
  3022. {
  3023. return S_FALSE;
  3024. }
  3025. if(pObj->GetMyWorkspace() == g_pCurrentWorkspace)
  3026. {
  3027. pObj->Draw(FALSE);
  3028. }
  3029. //
  3030. // Make sure it gets added back as unselected. It was selected
  3031. // when deleted.
  3032. //
  3033. pObj->ClearDeletionFlags();
  3034. pObj->SetAllAttribs();
  3035. pObj->SetViewState(unselected_chosen);
  3036. pObj->SendNewObjectToT126Apps();
  3037. pObj = (T126Obj *) g_pTrash->RemoveHead();
  3038. }
  3039. return S_OK;
  3040. }
  3041. //
  3042. //
  3043. // Function: OnSelectAll
  3044. //
  3045. // Purpose: Select all the objects in the current page
  3046. //
  3047. //
  3048. LRESULT WbMainWindow::OnSelectAll( void )
  3049. {
  3050. // Unselect every oject first.
  3051. m_drawingArea.RemoveMarker();
  3052. // turn off any selections
  3053. // cleanup select logic in case object context menu called us (bug 426)
  3054. m_drawingArea.SetLClickIgnore( FALSE );
  3055. // inhibit normal select-tool action
  3056. m_bSelectAllInProgress = TRUE;
  3057. //put us in select-tool mode first
  3058. OnSelectTool(IDM_SELECT);
  3059. // back to normal
  3060. m_bSelectAllInProgress = FALSE;
  3061. // now, select everything
  3062. m_drawingArea.SelectMarkerFromRect( NULL );
  3063. return S_OK;
  3064. }
  3065. //
  3066. //
  3067. // Function: OnCut
  3068. //
  3069. // Purpose: Cut the current selection
  3070. //
  3071. //
  3072. LRESULT WbMainWindow::OnCut()
  3073. {
  3074. // Copy all the selected graphics to the clipboard
  3075. BOOL bResult = CLP_Copy();
  3076. // If an error occurred during the copy, report it now
  3077. if (!bResult)
  3078. {
  3079. ::Message(NULL, IDM_CUT, IDS_COPY_ERROR);
  3080. return S_FALSE;
  3081. }
  3082. //
  3083. // Erase the selected objects
  3084. //
  3085. OnDelete();
  3086. return S_OK;
  3087. }
  3088. //
  3089. // OnCopy()
  3090. // Purpose: Copy the current selection to the clipboard
  3091. //
  3092. //
  3093. LRESULT WbMainWindow::OnCopy(void)
  3094. {
  3095. // Copy all the selected graphics to the clipboard
  3096. BOOL bResult = CLP_Copy();
  3097. // If an error occurred during the copy, report it now
  3098. if (!bResult)
  3099. {
  3100. ::Message(NULL, IDS_COPY, IDS_COPY_ERROR);
  3101. return S_FALSE;
  3102. }
  3103. return S_OK;
  3104. }
  3105. //
  3106. //
  3107. // Function: OnPaste
  3108. //
  3109. // Purpose: Paste the contents of the clipboard into the drawing pane
  3110. //
  3111. //
  3112. LRESULT WbMainWindow::OnPaste()
  3113. {
  3114. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnPaste");
  3115. BOOL bResult = CLP_Paste();
  3116. // If an error occurred during the copy, report it now
  3117. if (!bResult)
  3118. {
  3119. ::Message(NULL, IDS_PASTE, IDS_PASTE_ERROR);
  3120. return S_FALSE;
  3121. }
  3122. return S_OK;
  3123. }
  3124. //
  3125. //
  3126. // Function: OnScrollAccelerator
  3127. //
  3128. // Purpose: Called when a scroll accelerator is used
  3129. //
  3130. //
  3131. LRESULT WbMainWindow::OnScrollAccelerator(UINT uiMenuId)
  3132. {
  3133. int iScroll;
  3134. // Locate the scroll messages to be sent in the conversion table
  3135. for (iScroll = 0; iScroll < ARRAYSIZE(s_MenuToScroll); iScroll++)
  3136. {
  3137. if (s_MenuToScroll[iScroll].uiMenuId == uiMenuId)
  3138. {
  3139. // Found it;
  3140. break;
  3141. }
  3142. }
  3143. // Send the messages
  3144. if (iScroll < ARRAYSIZE(s_MenuToScroll))
  3145. {
  3146. while ((s_MenuToScroll[iScroll].uiMenuId == uiMenuId) && (iScroll < ARRAYSIZE(s_MenuToScroll)))
  3147. {
  3148. // Tell the drawing pane to scroll
  3149. ::PostMessage(m_drawingArea.m_hwnd, s_MenuToScroll[iScroll].uiMessage,
  3150. s_MenuToScroll[iScroll].uiScrollCode, 0);
  3151. iScroll++;
  3152. }
  3153. // Indicate that scrolling has completed (in both directions)
  3154. ::PostMessage(m_drawingArea.m_hwnd, WM_HSCROLL, SB_ENDSCROLL, 0L);
  3155. ::PostMessage(m_drawingArea.m_hwnd, WM_VSCROLL, SB_ENDSCROLL, 0L);
  3156. }
  3157. return S_OK;
  3158. }
  3159. //
  3160. //
  3161. // Function: OnZoom
  3162. //
  3163. // Purpose: Zoom or unzoom the drawing area
  3164. //
  3165. //
  3166. LRESULT WbMainWindow::OnZoom()
  3167. {
  3168. // If the drawing area is currently zoomed
  3169. if (m_drawingArea.Zoomed())
  3170. {
  3171. // Tell the tool bar of the new selection
  3172. m_TB.PopUp(IDM_ZOOM);
  3173. UncheckMenuItem(IDM_ZOOM);
  3174. }
  3175. else
  3176. {
  3177. // Tell the tool bar of the new selection
  3178. m_TB.PushDown(IDM_ZOOM);
  3179. CheckMenuItem(IDM_ZOOM);
  3180. }
  3181. // Zoom/unzoom the drawing area
  3182. m_drawingArea.Zoom();
  3183. // Restore the focus to the drawing area
  3184. ::SetFocus(m_drawingArea.m_hwnd);
  3185. return S_OK;
  3186. }
  3187. LRESULT WbMainWindow::OnLock()
  3188. {
  3189. // If the drawing area is currently Locked
  3190. if (m_drawingArea.IsLocked())
  3191. {
  3192. m_TB.PopUp(IDM_LOCK);
  3193. UncheckMenuItem(IDM_LOCK);
  3194. }
  3195. else
  3196. {
  3197. m_TB.PushDown(IDM_LOCK);
  3198. CheckMenuItem(IDM_LOCK);
  3199. g_pNMWBOBJ->m_LockerID = g_MyMemberID;
  3200. }
  3201. m_drawingArea.SetLock(!m_drawingArea.IsLocked());
  3202. TogleLockInAllWorkspaces(m_drawingArea.IsLocked(), TRUE);
  3203. EnableToolbar( TRUE );
  3204. return S_OK;
  3205. }
  3206. //
  3207. //
  3208. // Function: OnSelectTool
  3209. //
  3210. // Purpose: Select the current tool
  3211. //
  3212. //
  3213. LRESULT WbMainWindow::OnSelectTool(UINT uiMenuId)
  3214. {
  3215. UncheckMenuItem(m_currentMenuTool);
  3216. CheckMenuItem( uiMenuId);
  3217. UINT uiIndex;
  3218. // Save the new menu Id
  3219. m_currentMenuTool = uiMenuId;
  3220. // Tell the tool bar of the new selection
  3221. m_TB.PushDown(m_currentMenuTool);
  3222. // Get the new tool
  3223. m_pCurrentTool = m_ToolArray[TOOL_INDEX(m_currentMenuTool)];
  3224. // Set the current attributes
  3225. if( !m_bSelectAllInProgress )
  3226. {
  3227. m_AG.SetChoiceColor(m_pCurrentTool->GetColor() );
  3228. ::SendMessage(m_hwnd, WM_COMMAND, IDM_COLOR, 0L);
  3229. }
  3230. // Report the change of tool to the attributes group
  3231. m_AG.DisplayTool(m_pCurrentTool);
  3232. // Select the new tool into the drawing area
  3233. m_drawingArea.SelectTool(m_pCurrentTool);
  3234. // Restore the focus to the drawing area
  3235. ::SetFocus(m_drawingArea.m_hwnd);
  3236. return S_OK;
  3237. }
  3238. //
  3239. //
  3240. // Function: OnSelectColor
  3241. //
  3242. // Purpose: Set the current color
  3243. //
  3244. //
  3245. LRESULT WbMainWindow::OnSelectColor(void)
  3246. {
  3247. // Tell the attributes group of the new selection and get the
  3248. // new color value selected ino the current tool.
  3249. m_AG.SelectColor(m_pCurrentTool);
  3250. // Select the changed tool into the drawing area
  3251. m_drawingArea.SelectTool(m_pCurrentTool);
  3252. // If there is an object marked for changing
  3253. if (m_drawingArea.GraphicSelected() || m_drawingArea.TextEditActive())
  3254. {
  3255. // Update the object
  3256. m_drawingArea.SetSelectionColor(m_pCurrentTool->GetColor());
  3257. }
  3258. // Restore the focus to the drawing area
  3259. ::SetFocus(m_drawingArea.m_hwnd);
  3260. return S_OK;
  3261. }
  3262. //
  3263. //
  3264. // Function: OnSelectWidth
  3265. //
  3266. // Purpose: Set the current nib width
  3267. //
  3268. //
  3269. LRESULT WbMainWindow::OnSelectWidth(UINT uiMenuId)
  3270. {
  3271. // cleanup select logic in case object context menu called us (bug 426)
  3272. m_drawingArea.SetLClickIgnore( FALSE );
  3273. // Save the new pen width
  3274. m_currentMenuWidth = uiMenuId;
  3275. // Tell the attributes display of the new selection
  3276. m_WG.PushDown(uiMenuId - IDM_WIDTHS_START);
  3277. if (m_pCurrentTool != NULL)
  3278. {
  3279. m_pCurrentTool->SetWidthIndex(uiMenuId - IDM_WIDTHS_START);
  3280. }
  3281. // Tell the drawing pane of the new selection
  3282. m_drawingArea.SelectTool(m_pCurrentTool);
  3283. // If there is an object marked for changing
  3284. if (m_drawingArea.GraphicSelected())
  3285. {
  3286. // Update the object
  3287. m_drawingArea.SetSelectionWidth(uiMenuId - IDM_WIDTHS_START);
  3288. }
  3289. // Restore the focus to the drawing area
  3290. ::SetFocus(m_drawingArea.m_hwnd);
  3291. return S_OK;
  3292. }
  3293. //
  3294. //
  3295. // Function: OnChooseFont
  3296. //
  3297. // Purpose: Let the user select a font
  3298. //
  3299. //
  3300. LRESULT WbMainWindow::OnChooseFont(void)
  3301. {
  3302. HDC hdc;
  3303. LOGFONT lfont;
  3304. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnChooseFont");
  3305. // cleanup select logic in case object context menu called us (bug 426)
  3306. m_drawingArea.SetLClickIgnore( FALSE );
  3307. // It is only really sensible to be here when a text tool is selected.
  3308. // This is achieved by graying the Font selection menu entry when
  3309. // anything other than a text tool is in use.
  3310. // Get the font details from the current tool
  3311. ::GetObject(m_pCurrentTool->GetFont(), sizeof(LOGFONT), &lfont);
  3312. lfont.lfClipPrecision |= CLIP_DFA_OVERRIDE;
  3313. //
  3314. // The Font dialog is passed a LOGFONT structure which it uses to
  3315. // initialize all of its fields (face name, weight etc).
  3316. //
  3317. // The face name passed in the LOGFONT structure is checked by the dialog
  3318. // against the facenames of all available fonts. If the name does not
  3319. // match one of the available fonts, no name is displayed.
  3320. //
  3321. // WB stores the LOGFONT structure specifying the font used for a text
  3322. // object in the object. This LOGFONT is selected into a DC where the
  3323. // GDIs font mapper decides which physical font most closely matches the
  3324. // required logical font. On boxes where the original font is not
  3325. // supported the font is substituted for the closest matching font
  3326. // available.
  3327. //
  3328. // So, if we pass the LOGFONT structure for a font which is not supported
  3329. // into the Font dialog, no facename is displayed. To bypass this we
  3330. //
  3331. // - select the logical font into a DC
  3332. //
  3333. // - determine the textmetrics and get the face name of the physical font
  3334. // chosen by the Font Mapper
  3335. //
  3336. // - use these textmetrics to create a LOGFONT structure which matches
  3337. // the substituted font!
  3338. //
  3339. // The resulting LOGFONT will have the correct weight, dimensions and
  3340. // facename for the substituted font.
  3341. //
  3342. hdc = ::CreateCompatibleDC(NULL);
  3343. if (hdc != NULL)
  3344. {
  3345. TEXTMETRIC tm;
  3346. HFONT hFont;
  3347. HFONT hOldFont;
  3348. hFont = ::CreateFontIndirect(&lfont);
  3349. //
  3350. // Get the face name and text metrics of the selected font.
  3351. //
  3352. hOldFont = SelectFont(hdc, hFont);
  3353. if (hOldFont == NULL)
  3354. {
  3355. WARNING_OUT(("Failed to select font into DC"));
  3356. }
  3357. else
  3358. {
  3359. ::GetTextMetrics(hdc, &tm);
  3360. ::GetTextFace(hdc, LF_FACESIZE, lfont.lfFaceName);
  3361. //
  3362. // Restore the old font back into the DC.
  3363. //
  3364. SelectFont(hdc, hOldFont);
  3365. //
  3366. // Create a LOGFONT structure which matches the Text metrics
  3367. // of the font used by the DC so that the font dialog manages
  3368. // to initialise all of its fields properly, even for
  3369. // substituted fonts...
  3370. //
  3371. lfont.lfHeight = tm.tmHeight;
  3372. lfont.lfWidth = tm.tmAveCharWidth;
  3373. lfont.lfWeight = tm.tmWeight;
  3374. lfont.lfItalic = tm.tmItalic;
  3375. lfont.lfUnderline = tm.tmUnderlined;
  3376. lfont.lfStrikeOut = tm.tmStruckOut;
  3377. lfont.lfCharSet = tm.tmCharSet;
  3378. //ADDED BY RAND - to make lfHeight be a char height. This makes
  3379. // the font dlg show the same pt size that is
  3380. // displayed in the sample font toolbar
  3381. if( lfont.lfHeight > 0 )
  3382. {
  3383. lfont.lfHeight = -(lfont.lfHeight - tm.tmInternalLeading);
  3384. }
  3385. }
  3386. ::DeleteDC(hdc);
  3387. if (hFont != NULL)
  3388. {
  3389. ::DeleteFont(hFont);
  3390. }
  3391. }
  3392. else
  3393. {
  3394. WARNING_OUT(("Failed to get DC to select font into"));
  3395. }
  3396. CHOOSEFONT cf;
  3397. TCHAR szStyleName[64];
  3398. ZeroMemory(&cf, sizeof(cf));
  3399. ZeroMemory(szStyleName, sizeof(szStyleName));
  3400. cf.lStructSize = sizeof(cf);
  3401. cf.lpszStyle = szStyleName;
  3402. cf.rgbColors = m_pCurrentTool->GetColor() & 0x00ffffff; // blow off palette bits (NM4db:2304)
  3403. cf.Flags = CF_EFFECTS | CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS |
  3404. CF_NOVERTFONTS;
  3405. cf.lpLogFont = &lfont;
  3406. cf.hwndOwner = m_hwnd;
  3407. // Call up the ChooseFont dialog from COM DLG
  3408. if (::ChooseFont(&cf))
  3409. {
  3410. lfont.lfClipPrecision |= CLIP_DFA_OVERRIDE;
  3411. //ADDED BY RAND - set color selected in dialog.
  3412. m_pCurrentTool->SetColor(cf.rgbColors);
  3413. m_AG.DisplayTool( m_pCurrentTool );
  3414. ::SendMessage(m_hwnd, WM_COMMAND,
  3415. (WPARAM)MAKELONG( IDM_COLOR, BN_CLICKED ),
  3416. (LPARAM)0 );
  3417. // Inform the drawing pane of the new selection
  3418. HFONT hNewFont;
  3419. hNewFont = ::CreateFontIndirect(&lfont);
  3420. if (!hNewFont)
  3421. {
  3422. ERROR_OUT(("Failed to create font"));
  3423. DefaultExceptionHandler(WBFE_RC_WINDOWS, 0);
  3424. return S_FALSE;
  3425. }
  3426. //
  3427. // We need to set the text editor font after inserting it in the DC
  3428. // and querying the metrics, otherwise we may get a font with different
  3429. // metrics in zoomed mode
  3430. //
  3431. HFONT hNewFont2;
  3432. HDC hDC = m_drawingArea.GetCachedDC();
  3433. TEXTMETRIC textMetrics;
  3434. m_drawingArea.PrimeFont(hDC, hNewFont, &textMetrics);
  3435. lfont.lfHeight = textMetrics.tmHeight;
  3436. lfont.lfWidth = textMetrics.tmAveCharWidth;
  3437. lfont.lfPitchAndFamily = textMetrics.tmPitchAndFamily;
  3438. ::GetTextFace(hDC, sizeof(lfont.lfFaceName),
  3439. lfont.lfFaceName);
  3440. TRACE_MSG(("Font face name %s", lfont.lfFaceName));
  3441. // Inform the drawing pane of the new selection
  3442. hNewFont2 = ::CreateFontIndirect(&lfont);
  3443. if (!hNewFont2)
  3444. {
  3445. ERROR_OUT(("Failed to create font"));
  3446. DefaultExceptionHandler(WBFE_RC_WINDOWS, 0);
  3447. return S_FALSE;
  3448. }
  3449. m_drawingArea.SetSelectionColor(cf.rgbColors);
  3450. m_drawingArea.SetSelectionFont(hNewFont2);
  3451. if (m_pCurrentTool != NULL)
  3452. {
  3453. m_pCurrentTool->SetFont(hNewFont2);
  3454. }
  3455. m_drawingArea.SelectTool(m_pCurrentTool);
  3456. //
  3457. // discard the new font
  3458. //
  3459. m_drawingArea.UnPrimeFont( hDC );
  3460. // Delete the fonts we created--everybody above makes copies
  3461. ::DeleteFont(hNewFont2);
  3462. ::DeleteFont(hNewFont);
  3463. }
  3464. // Restore the focus to the drawing area
  3465. ::SetFocus(m_drawingArea.m_hwnd);
  3466. return S_OK;
  3467. }
  3468. //
  3469. //
  3470. // Function: OnToolBarToggle
  3471. //
  3472. // Purpose: Let the user toggle the tool bar on/off
  3473. //
  3474. //
  3475. LRESULT WbMainWindow::OnToolBarToggle(void)
  3476. {
  3477. RECT rectWnd;
  3478. // Toggle the flag
  3479. m_bToolBarOn = !m_bToolBarOn;
  3480. // Make the necessary updates
  3481. if (m_bToolBarOn)
  3482. {
  3483. // The tool bar was hidden, so show it
  3484. ::ShowWindow(m_TB.m_hwnd, SW_SHOW);
  3485. // The tool window is fixed so we must resize the other panes in
  3486. // the window to make room for it
  3487. ResizePanes();
  3488. // Check the associated menu item
  3489. CheckMenuItem(IDM_TOOL_BAR_TOGGLE);
  3490. }
  3491. else
  3492. {
  3493. // The tool bar was visible, so hide it
  3494. ::ShowWindow(m_TB.m_hwnd, SW_HIDE);
  3495. ResizePanes();
  3496. // Uncheck the associated menu item
  3497. UncheckMenuItem(IDM_TOOL_BAR_TOGGLE);
  3498. }
  3499. // Make sure things reflect current tool
  3500. m_AG.DisplayTool(m_pCurrentTool);
  3501. // Write the new option value to the options file
  3502. OPT_SetBooleanOption(OPT_MAIN_TOOLBARVISIBLE,
  3503. m_bToolBarOn);
  3504. ::GetWindowRect(m_hwnd, &rectWnd);
  3505. ::MoveWindow(m_hwnd, rectWnd.left, rectWnd.top, rectWnd.right - rectWnd.left, rectWnd.bottom - rectWnd.top, TRUE);
  3506. return S_OK;
  3507. }
  3508. //
  3509. //
  3510. // Function: OnStatusBarToggle
  3511. //
  3512. // Purpose: Let the user toggle the help bar on/off
  3513. //
  3514. //
  3515. void WbMainWindow::OnStatusBarToggle(void)
  3516. {
  3517. RECT rectWnd;
  3518. // Toggle the flag
  3519. m_bStatusBarOn = !m_bStatusBarOn;
  3520. // Make the necessary updates
  3521. if (m_bStatusBarOn)
  3522. {
  3523. // Resize the panes to give room for the help bar
  3524. ResizePanes();
  3525. // The help bar was hidden, so show it
  3526. ::ShowWindow(m_hwndSB, SW_SHOW);
  3527. // Check the associated menu item
  3528. CheckMenuItem(IDM_STATUS_BAR_TOGGLE);
  3529. }
  3530. else
  3531. {
  3532. // The help bar was visible, so hide it
  3533. ::ShowWindow(m_hwndSB, SW_HIDE);
  3534. // Uncheck the associated menu item
  3535. UncheckMenuItem(IDM_STATUS_BAR_TOGGLE);
  3536. // Resize the panes to take up the help bar space
  3537. ResizePanes();
  3538. }
  3539. // Write the new option value to the options file
  3540. OPT_SetBooleanOption(OPT_MAIN_STATUSBARVISIBLE, m_bStatusBarOn);
  3541. ::GetWindowRect(m_hwnd, &rectWnd);
  3542. ::MoveWindow(m_hwnd, rectWnd.left, rectWnd.top, rectWnd.right - rectWnd.left, rectWnd.bottom - rectWnd.top, TRUE);
  3543. }
  3544. //
  3545. //
  3546. // Function: OnAbout
  3547. //
  3548. // Purpose: Show the about box for the Whiteboard application. This
  3549. // method is called whenever a WM_COMMAND with IDM_ABOUT
  3550. // is issued by Windows.
  3551. //
  3552. //
  3553. LRESULT WbMainWindow::OnAbout()
  3554. {
  3555. ::DialogBoxParam(g_hInstance, MAKEINTRESOURCE(ABOUTBOX), m_hwnd,
  3556. AboutDlgProc, 0);
  3557. return S_OK;
  3558. }
  3559. INT_PTR AboutDlgProc(HWND hwnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
  3560. {
  3561. BOOL fHandled = FALSE;
  3562. switch (uMessage)
  3563. {
  3564. case WM_INITDIALOG:
  3565. {
  3566. TCHAR szFormat[256];
  3567. TCHAR szVersion[512];
  3568. ::GetDlgItemText(hwnd, IDC_ABOUTVERSION, szFormat, 256);
  3569. wsprintf(szVersion, szFormat, VER_PRODUCTRELEASE_STR,
  3570. VER_PRODUCTVERSION_STR);
  3571. ::SetDlgItemText(hwnd, IDC_ABOUTVERSION, szVersion);
  3572. fHandled = TRUE;
  3573. break;
  3574. }
  3575. case WM_COMMAND:
  3576. switch (GET_WM_COMMAND_ID(wParam, lParam))
  3577. {
  3578. case IDOK:
  3579. case IDCANCEL:
  3580. switch (GET_WM_COMMAND_CMD(wParam, lParam))
  3581. {
  3582. case BN_CLICKED:
  3583. ::EndDialog(hwnd, IDCANCEL);
  3584. break;
  3585. }
  3586. break;
  3587. }
  3588. fHandled = TRUE;
  3589. break;
  3590. }
  3591. return(fHandled);
  3592. }
  3593. void WbMainWindow::UpdateWindowTitle(void)
  3594. {
  3595. TCHAR szCaption[MAX_PATH * 2];
  3596. TCHAR szFileName[MAX_PATH * 2];
  3597. UINT captionID;
  3598. if (! g_pNMWBOBJ->IsInConference())
  3599. {
  3600. captionID = IDS_WB_NOT_IN_CALL_WINDOW_CAPTION;
  3601. }
  3602. else
  3603. {
  3604. captionID = IDS_WB_IN_CALL_WINDOW_CAPTION;
  3605. }
  3606. ::LoadString(g_hInstance, captionID, szFileName, sizeof(szFileName) );
  3607. wsprintf(szCaption, szFileName, GetFileNameStr(), g_pNMWBOBJ->m_cOtherMembers);
  3608. SetWindowText(m_hwnd, szCaption);
  3609. }
  3610. //
  3611. //
  3612. // Function: SelectWindow
  3613. //
  3614. // Purpose: Let the user select a window for grabbing
  3615. //
  3616. //
  3617. HWND WbMainWindow::SelectWindow(void)
  3618. {
  3619. POINT mousePos; // Mouse position
  3620. HWND hwndSelected = NULL; // Window clicked on
  3621. MSG msg; // Current message
  3622. // Load the grabbing cursors
  3623. HCURSOR hGrabCursor = ::LoadCursor(g_hInstance, MAKEINTRESOURCE( GRABCURSOR ) );
  3624. // Capture the mouse
  3625. UT_CaptureMouse(m_hwnd);
  3626. // Ensure we receive all keyboard messages.
  3627. ::SetFocus(m_hwnd);
  3628. // Reset the CancelMode state
  3629. ResetCancelMode();
  3630. // Change to the grab cursor
  3631. HCURSOR hOldCursor = ::SetCursor(hGrabCursor);
  3632. // Trap all mouse messages until a WM_LBUTTONUP is received
  3633. for ( ; ; )
  3634. {
  3635. // Wait for the next message
  3636. ::WaitMessage();
  3637. // Cancel if we have been sent a WM_CANCELMODE message
  3638. if (CancelModeSent())
  3639. {
  3640. break;
  3641. }
  3642. // If it is a mouse message, process it
  3643. if (::PeekMessage(&msg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE))
  3644. {
  3645. if (msg.message == WM_LBUTTONUP)
  3646. {
  3647. // Get mouse position
  3648. mousePos.x = (short)LOWORD(msg.lParam);
  3649. mousePos.y = (short)HIWORD(msg.lParam);
  3650. // Convert to screen coordinates
  3651. ::ClientToScreen(m_hwnd, &mousePos);
  3652. // Get the window under the mouse
  3653. hwndSelected = ::WindowFromPoint(mousePos);
  3654. // Leave the loop
  3655. break;
  3656. }
  3657. }
  3658. // Cancel if ESCAPE is pressed.
  3659. // or if another window receives the focus
  3660. else if (::PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
  3661. {
  3662. if (msg.wParam == VK_ESCAPE)
  3663. {
  3664. break;
  3665. }
  3666. }
  3667. }
  3668. // Release the mouse
  3669. UT_ReleaseMouse(m_hwnd);
  3670. // Restore the cursor
  3671. ::SetCursor(hOldCursor);
  3672. return(hwndSelected);
  3673. }
  3674. //
  3675. //
  3676. // Function: OnGrabWindow
  3677. //
  3678. // Purpose: Allows the user to grab a bitmap of a window
  3679. //
  3680. //
  3681. LRESULT WbMainWindow::OnGrabWindow(void)
  3682. {
  3683. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnGrabWindow");
  3684. if (::DialogBoxParam(g_hInstance, MAKEINTRESOURCE(WARNSELECTWINDOW),
  3685. m_hwnd, WarnSelectWindowDlgProc, 0) != IDOK)
  3686. {
  3687. // User cancelled; bail out
  3688. return S_OK;;
  3689. }
  3690. // Hide the application windows
  3691. ::ShowWindow(m_hwnd, SW_HIDE);
  3692. HWND mainUIhWnd = FindWindow("MPWClass\0" , NULL);
  3693. if(IsWindowVisible(mainUIhWnd))
  3694. {
  3695. ::UpdateWindow(mainUIhWnd);
  3696. }
  3697. // Get window selection from the user
  3698. HWND hwndSelected = SelectWindow();
  3699. if (hwndSelected != NULL)
  3700. {
  3701. // Walk back to the find the 'real' window ancestor
  3702. HWND hwndParent;
  3703. // The following piece of code attempts to find the frame window
  3704. // enclosing the selected window. This allows us to bring the
  3705. // enclosing window to the top, bringing the child window with it.
  3706. DWORD dwStyle;
  3707. while ((hwndParent = ::GetParent(hwndSelected)) != NULL)
  3708. {
  3709. // If we have reached a stand-alone window, stop the search
  3710. dwStyle = ::GetWindowLong(hwndSelected, GWL_STYLE);
  3711. if ( ((dwStyle & WS_POPUP) == WS_POPUP)
  3712. || ((dwStyle & WS_THICKFRAME) == WS_THICKFRAME)
  3713. || ((dwStyle & WS_DLGFRAME) == WS_DLGFRAME))
  3714. {
  3715. break;
  3716. }
  3717. // Move up to the parent window
  3718. hwndSelected = hwndParent;
  3719. }
  3720. // Bring the selected window to the top
  3721. ::BringWindowToTop(hwndSelected);
  3722. ::UpdateWindow(hwndSelected);
  3723. // Get an image copy of the window
  3724. RECT areaRect;
  3725. ::GetWindowRect(hwndSelected, &areaRect);
  3726. BitmapObj* dib;
  3727. DBG_SAVE_FILE_LINE
  3728. dib = new BitmapObj(TOOLTYPE_FILLEDBOX);
  3729. dib->FromScreenArea(&areaRect);
  3730. if(dib->m_lpbiImage == NULL)
  3731. {
  3732. delete dib;
  3733. return S_FALSE;
  3734. }
  3735. // Add the new grabbed bitmap
  3736. AddCapturedImage(dib);
  3737. // Force the selection tool to be selected
  3738. ::PostMessage(m_hwnd, WM_COMMAND, IDM_TOOLS_START, 0L);
  3739. }
  3740. // Show the windows again
  3741. ::ShowWindow(m_hwnd, SW_SHOW);
  3742. // Restore the focus to the drawing area
  3743. ::SetFocus(m_drawingArea.m_hwnd);
  3744. return S_OK;
  3745. }
  3746. //
  3747. // WarnSelectWindowDlgProc()
  3748. // This puts up the warning/explanation dialog. We use the default settings
  3749. // or whatever the user chose last time this dialog was up.
  3750. //
  3751. INT_PTR CALLBACK WarnSelectWindowDlgProc(HWND hwnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
  3752. {
  3753. BOOL fHandled = FALSE;
  3754. switch (uMessage)
  3755. {
  3756. case WM_INITDIALOG:
  3757. {
  3758. if (OPT_GetBooleanOption( OPT_MAIN_SELECTWINDOW_NOTAGAIN,
  3759. DFLT_MAIN_SELECTWINDOW_NOTAGAIN))
  3760. {
  3761. // End this right away, the user doesn't want a warning
  3762. ::EndDialog(hwnd, IDOK);
  3763. }
  3764. fHandled = TRUE;
  3765. break;
  3766. }
  3767. case WM_COMMAND:
  3768. switch (GET_WM_COMMAND_ID(wParam, lParam))
  3769. {
  3770. case IDOK:
  3771. switch (GET_WM_COMMAND_CMD(wParam, lParam))
  3772. {
  3773. case BN_CLICKED:
  3774. //
  3775. // Update settings -- note that we don't have to write out
  3776. // FALSE--we wouldn't be in the dialog in the first place
  3777. // if the current setting weren't already FALSE.
  3778. //
  3779. if (::IsDlgButtonChecked(hwnd, IDC_SWWARN_NOTAGAIN))
  3780. {
  3781. OPT_SetBooleanOption(OPT_MAIN_SELECTWINDOW_NOTAGAIN, TRUE);
  3782. }
  3783. ::EndDialog(hwnd, IDOK);
  3784. break;
  3785. }
  3786. break;
  3787. case IDCANCEL:
  3788. switch (GET_WM_COMMAND_CMD(wParam, lParam))
  3789. {
  3790. case BN_CLICKED:
  3791. ::EndDialog(hwnd, IDCANCEL);
  3792. break;
  3793. }
  3794. break;
  3795. }
  3796. fHandled = TRUE;
  3797. break;
  3798. }
  3799. return(fHandled);
  3800. }
  3801. //
  3802. //
  3803. // Function: ShowAllWindows
  3804. //
  3805. // Purpose: Show or hide the main window and associated windows
  3806. //
  3807. //
  3808. void WbMainWindow::ShowAllWindows(int iShow)
  3809. {
  3810. // Show/hide the main window
  3811. ::ShowWindow(m_hwnd, iShow);
  3812. // Show/hide the tool window
  3813. if (m_bToolBarOn)
  3814. {
  3815. ::ShowWindow(m_TB.m_hwnd, iShow);
  3816. }
  3817. }
  3818. //
  3819. //
  3820. // Function: OnGrabArea
  3821. //
  3822. // Purpose: Allows the user to grab a bitmap of an area of the screen
  3823. //
  3824. //
  3825. LRESULT WbMainWindow::OnGrabArea(void)
  3826. {
  3827. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnGrabArea");
  3828. if (::DialogBoxParam(g_hInstance, MAKEINTRESOURCE(WARNSELECTAREA),
  3829. m_hwnd, WarnSelectAreaDlgProc, 0) != IDOK)
  3830. {
  3831. // User cancelled, so bail out
  3832. return S_OK;;
  3833. }
  3834. // Hide the application windows
  3835. ::ShowWindow(m_hwnd, SW_HIDE);
  3836. HWND mainUIhWnd = FindWindow("MPWClass\0" , NULL);
  3837. if(IsWindowVisible(mainUIhWnd))
  3838. {
  3839. ::UpdateWindow(mainUIhWnd);
  3840. }
  3841. // Load the grabbing cursors
  3842. HCURSOR hGrabCursor = ::LoadCursor(g_hInstance, MAKEINTRESOURCE( PENCURSOR ) );
  3843. // Capture the mouse
  3844. UT_CaptureMouse(m_hwnd);
  3845. // Ensure we receive all keyboard messages.
  3846. ::SetFocus(m_hwnd);
  3847. // Reset the CancelMode status
  3848. ResetCancelMode();
  3849. // Change to the grab cursor
  3850. HCURSOR hOldCursor = ::SetCursor(hGrabCursor);
  3851. // Let the user select the area to be grabbed
  3852. RECT rect;
  3853. int tmp;
  3854. GetGrabArea(&rect);
  3855. // Normalize coords
  3856. if (rect.right < rect.left)
  3857. {
  3858. tmp = rect.left;
  3859. rect.left = rect.right;
  3860. rect.right = tmp;
  3861. }
  3862. if (rect.bottom < rect.top)
  3863. {
  3864. tmp = rect.top;
  3865. rect.top = rect.bottom;
  3866. rect.bottom = tmp;
  3867. }
  3868. BitmapObj* dib;
  3869. DBG_SAVE_FILE_LINE
  3870. dib = new BitmapObj(TOOLTYPE_FILLEDBOX);
  3871. if (!::IsRectEmpty(&rect))
  3872. {
  3873. // Get a bitmap copy of the screen area
  3874. dib->FromScreenArea(&rect);
  3875. }
  3876. // Show the windows again now - if we do it later we get the bitmap to
  3877. // be added re-drawn twice (once on the window show and once when the
  3878. // graphic added indication arrives).
  3879. ::ShowWindow(m_hwnd, SW_SHOW);
  3880. ::UpdateWindow(m_hwnd);
  3881. if (!::IsRectEmpty(&rect) && dib->m_lpbiImage)
  3882. {
  3883. // Add the bitmap
  3884. AddCapturedImage(dib);
  3885. // Force the selection tool to be selected
  3886. ::PostMessage(m_hwnd, WM_COMMAND, IDM_TOOLS_START, 0L);
  3887. }
  3888. else
  3889. {
  3890. delete dib;
  3891. dib = NULL;
  3892. }
  3893. // Release the mouse
  3894. UT_ReleaseMouse(m_hwnd);
  3895. // Restore the cursor
  3896. ::SetCursor(hOldCursor);
  3897. // Restore the focus to the drawing area
  3898. ::SetFocus(m_drawingArea.m_hwnd);
  3899. if(dib)
  3900. {
  3901. dib->Draw();
  3902. }
  3903. return S_OK;
  3904. }
  3905. //
  3906. // WarnSelectArea dialog handler
  3907. //
  3908. INT_PTR CALLBACK WarnSelectAreaDlgProc(HWND hwnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
  3909. {
  3910. BOOL fHandled = FALSE;
  3911. switch (uMessage)
  3912. {
  3913. case WM_INITDIALOG:
  3914. if (OPT_GetBooleanOption(OPT_MAIN_SELECTAREA_NOTAGAIN,
  3915. DFLT_MAIN_SELECTAREA_NOTAGAIN))
  3916. {
  3917. // End this right away, the user doesn't want a warning
  3918. ::EndDialog(hwnd, IDOK);
  3919. }
  3920. fHandled = TRUE;
  3921. break;
  3922. case WM_COMMAND:
  3923. switch (GET_WM_COMMAND_ID(wParam, lParam))
  3924. {
  3925. case IDOK:
  3926. switch (GET_WM_COMMAND_CMD(wParam, lParam))
  3927. {
  3928. case BN_CLICKED:
  3929. //
  3930. // Update settings -- note that we don't have to write out
  3931. // FALSE--we wouldn't be in the dialog in the first place
  3932. // if the current setting weren't already FALSE.
  3933. //
  3934. if (::IsDlgButtonChecked(hwnd, IDC_SAWARN_NOTAGAIN))
  3935. {
  3936. OPT_SetBooleanOption(OPT_MAIN_SELECTAREA_NOTAGAIN, TRUE);
  3937. }
  3938. ::EndDialog(hwnd, IDOK);
  3939. break;
  3940. }
  3941. break;
  3942. case IDCANCEL:
  3943. switch (GET_WM_COMMAND_CMD(wParam, lParam))
  3944. {
  3945. case BN_CLICKED:
  3946. ::EndDialog(hwnd, IDCANCEL);
  3947. break;
  3948. }
  3949. }
  3950. fHandled = TRUE;
  3951. break;
  3952. }
  3953. return(fHandled);
  3954. }
  3955. //
  3956. //
  3957. // Function: GetGrabArea
  3958. //
  3959. // Purpose: Allows the user to grab a bitmap of an area of the screen
  3960. //
  3961. //
  3962. void WbMainWindow::GetGrabArea(LPRECT lprect)
  3963. {
  3964. POINT mousePos; // Mouse position
  3965. MSG msg; // Current message
  3966. BOOL tracking = FALSE; // Flag indicating mouse button is down
  3967. HDC hDC = NULL;
  3968. POINT grabStartPoint; // Start point (when mouse button is pressed)
  3969. POINT grabEndPoint; // End point (when mouse button is released)
  3970. POINT grabCurrPoint; // Current mouse position
  3971. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::GetGrabArea");
  3972. // Set the result to an empty rectangle
  3973. ::SetRectEmpty(lprect);
  3974. // Create the rectangle to be used for tracking
  3975. DrawObj* pRectangle = NULL;
  3976. DBG_SAVE_FILE_LINE
  3977. pRectangle = new DrawObj(rectangle_chosen, TOOLTYPE_SELECT);
  3978. pRectangle->SetPenColor(RGB(0,0,0), TRUE);
  3979. pRectangle->SetFillColor(RGB(255,255,255), FALSE);
  3980. pRectangle->SetLineStyle(PS_DOT);
  3981. pRectangle->SetPenThickness(1);
  3982. // Get the DC for tracking
  3983. HWND hDesktopWnd = ::GetDesktopWindow();
  3984. hDC = ::GetWindowDC(hDesktopWnd);
  3985. if (hDC == NULL)
  3986. {
  3987. WARNING_OUT(("NULL desktop DC"));
  3988. goto GrabAreaCleanup;
  3989. }
  3990. RECT rect;
  3991. // Trap all mouse messages until a WM_LBUTTONUP is received
  3992. for ( ; ; )
  3993. {
  3994. // Wait for the next message
  3995. ::WaitMessage();
  3996. // Cancel if we have been sent a WM_CANCELMODE message
  3997. if (CancelModeSent())
  3998. {
  3999. TRACE_MSG(("canceling grab"));
  4000. // Erase the last tracking rectangle
  4001. if (!EqualPoint(grabStartPoint, grabEndPoint))
  4002. {
  4003. rect.top = grabStartPoint.y;
  4004. rect.left = grabStartPoint.x;
  4005. rect.bottom = grabEndPoint.y;
  4006. rect.right = grabEndPoint.x;
  4007. pRectangle->SetRect(&rect);
  4008. pRectangle->SetBoundsRect(&rect);
  4009. pRectangle->Draw(hDC);
  4010. }
  4011. break;
  4012. }
  4013. // If it is a mouse message, process it
  4014. if (::PeekMessage(&msg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE))
  4015. {
  4016. // Get mouse position
  4017. TRACE_MSG( ("msg = %x, lParam = %0x", msg.message, msg.lParam) );
  4018. mousePos.x = (short)LOWORD(msg.lParam);
  4019. mousePos.y = (short)HIWORD(msg.lParam);
  4020. TRACE_MSG( ("mousePos = %d,%d", mousePos.x, mousePos.y) );
  4021. // Convert to screen coordinates
  4022. ::ClientToScreen(m_hwnd, &mousePos);
  4023. grabCurrPoint = mousePos;
  4024. switch (msg.message)
  4025. {
  4026. // Starting the grab
  4027. case WM_LBUTTONDOWN:
  4028. // Save the starting position
  4029. TRACE_MSG(("grabbing start position"));
  4030. grabStartPoint = mousePos;
  4031. grabEndPoint = mousePos;
  4032. tracking = TRUE;
  4033. break;
  4034. // Completing the rectangle
  4035. case WM_LBUTTONUP:
  4036. {
  4037. tracking = FALSE;
  4038. // Check that there is an area to capture
  4039. TRACE_MSG(("grabbing end position"));
  4040. if (EqualPoint(grabStartPoint, grabCurrPoint))
  4041. {
  4042. TRACE_MSG(("start == end, skipping grab"));
  4043. goto GrabAreaCleanup;
  4044. }
  4045. // Erase the last tracking rectangle
  4046. if (!EqualPoint(grabStartPoint, grabEndPoint))
  4047. {
  4048. rect.top = grabStartPoint.y;
  4049. rect.left = grabStartPoint.x;
  4050. rect.bottom = grabEndPoint.y;
  4051. rect.right = grabEndPoint.x;
  4052. pRectangle->SetRect(&rect);
  4053. pRectangle->SetBoundsRect(&rect);
  4054. pRectangle->Draw(hDC);
  4055. }
  4056. // Update the rectangle object
  4057. rect.top = grabStartPoint.y;
  4058. rect.left = grabStartPoint.x;
  4059. rect.bottom = grabCurrPoint.y;
  4060. rect.right = grabCurrPoint.x;
  4061. pRectangle->SetRect(&rect);
  4062. pRectangle->SetBoundsRect(&rect);
  4063. pRectangle->GetBoundsRect(lprect);
  4064. // We are done
  4065. goto GrabAreaCleanup;
  4066. }
  4067. break;
  4068. // Continuing the rectangle
  4069. case WM_MOUSEMOVE:
  4070. if (tracking)
  4071. {
  4072. TRACE_MSG(("tracking grab"));
  4073. // Erase the last tracking rectangle
  4074. if (!EqualPoint(grabStartPoint, grabEndPoint))
  4075. {
  4076. rect.top = grabStartPoint.y;
  4077. rect.left = grabStartPoint.x;
  4078. rect.bottom = grabEndPoint.y;
  4079. rect.right = grabEndPoint.x;
  4080. pRectangle->SetRect(&rect);
  4081. pRectangle->SetBoundsRect(&rect);
  4082. pRectangle->Draw(hDC);
  4083. }
  4084. // Draw the new rectangle
  4085. if (!EqualPoint(grabStartPoint, grabCurrPoint))
  4086. {
  4087. // Save the new box end point
  4088. grabEndPoint = grabCurrPoint;
  4089. // Draw the rectangle
  4090. TRACE_MSG( ("grabStartPoint = %d,%d",
  4091. grabStartPoint.x, grabStartPoint.y) );
  4092. TRACE_MSG( ("grabEndPoint = %d,%d",
  4093. grabEndPoint.x, grabEndPoint.y) );
  4094. rect.top = grabStartPoint.y;
  4095. rect.left = grabStartPoint.x;
  4096. rect.bottom = grabEndPoint.y;
  4097. rect.right = grabEndPoint.x;
  4098. pRectangle->SetRect(&rect);
  4099. pRectangle->SetBoundsRect(&rect);
  4100. pRectangle->Draw(hDC);
  4101. }
  4102. }
  4103. break;
  4104. }
  4105. }
  4106. // Cancel if ESCAPE is pressed.
  4107. else if (::PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
  4108. {
  4109. if( ((msg.message == WM_KEYUP)||(msg.message == WM_SYSKEYUP))&&
  4110. (msg.wParam == VK_ESCAPE) )
  4111. {
  4112. TRACE_MSG(("grab cancelled by ESC"));
  4113. // Erase the last tracking rectangle
  4114. if (!EqualPoint(grabStartPoint, grabEndPoint))
  4115. {
  4116. rect.top = grabStartPoint.y;
  4117. rect.left = grabStartPoint.x;
  4118. rect.bottom = grabEndPoint.y;
  4119. rect.right = grabEndPoint.x;
  4120. pRectangle->SetRect(&rect);
  4121. pRectangle->Draw(hDC);
  4122. }
  4123. break;
  4124. }
  4125. }
  4126. }
  4127. GrabAreaCleanup:
  4128. // Release the device context (if we have it)
  4129. if (hDC != NULL)
  4130. {
  4131. ::ReleaseDC(hDesktopWnd, hDC);
  4132. }
  4133. delete pRectangle;
  4134. }
  4135. //
  4136. //
  4137. // Function: AddCapturedImage
  4138. //
  4139. // Purpose: Add a bitmap to the contents (adding a new page for it
  4140. // if necessary).
  4141. //
  4142. //
  4143. void WbMainWindow::AddCapturedImage(BitmapObj* dib)
  4144. {
  4145. // Position the grabbed object at the top left of the currently visible
  4146. // area.
  4147. RECT rcVis;
  4148. m_drawingArea.GetVisibleRect(&rcVis);
  4149. dib->MoveTo(rcVis.left, rcVis.top);
  4150. dib->Draw();
  4151. // Add the new grabbed bitmap
  4152. dib->AddToWorkspace();
  4153. }
  4154. //
  4155. //
  4156. // Function: OnPrint
  4157. //
  4158. // Purpose: Print the contents of the drawing pane
  4159. //
  4160. //
  4161. LRESULT WbMainWindow::OnPrint()
  4162. {
  4163. BOOL bPrintError = FALSE;
  4164. PRINTDLG pd;
  4165. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnPrint");
  4166. if (!IsIdle())
  4167. {
  4168. // post an error message indicating the whiteboard is busy
  4169. ::PostMessage(m_hwnd, WM_USER_DISPLAY_ERROR, WBFE_RC_WB, WB_RC_BUSY);
  4170. return S_FALSE;
  4171. }
  4172. //
  4173. // Initialize the PRINTDLG structure
  4174. //
  4175. ZeroMemory(&pd, sizeof(pd));
  4176. pd.lStructSize = sizeof(pd);
  4177. pd.hInstance = g_hInstance;
  4178. pd.hwndOwner = m_hwnd;
  4179. pd.Flags = PD_ALLPAGES | PD_RETURNDC | PD_PAGENUMS |
  4180. PD_HIDEPRINTTOFILE | PD_NOSELECTION;
  4181. pd.nMinPage = 1;
  4182. pd.nMaxPage = (WORD)g_numberOfWorkspaces;
  4183. pd.nFromPage = pd.nMinPage;
  4184. pd.nToPage = pd.nMaxPage;
  4185. // Put up the COMMDLG print dialog
  4186. if (::PrintDlg(&pd))
  4187. {
  4188. int nStartPage, nEndPage;
  4189. // Get the start and end page numbers to be printed
  4190. if (pd.Flags & PD_PAGENUMS)
  4191. {
  4192. nStartPage = pd.nFromPage;
  4193. nEndPage = pd.nToPage;
  4194. }
  4195. else
  4196. {
  4197. nStartPage = pd.nMinPage;
  4198. nEndPage = pd.nMaxPage;
  4199. }
  4200. // Check whether any pages are to be printed
  4201. if (nStartPage <= pd.nMaxPage)
  4202. {
  4203. // Ensure that the start and end pages lie within range.
  4204. nStartPage = max(nStartPage, pd.nMinPage);
  4205. nEndPage = min(nEndPage, pd.nMaxPage);
  4206. // Get the printer and output port names.
  4207. // These are written to the dialog for the user to see
  4208. // in the OnInitDialog member.
  4209. TCHAR szDeviceName[2*_MAX_PATH];
  4210. LPDEVNAMES lpDev;
  4211. // Device name
  4212. if (pd.hDevNames == NULL)
  4213. {
  4214. szDeviceName[0] = 0;
  4215. }
  4216. else
  4217. {
  4218. lpDev = (LPDEVNAMES)::GlobalLock(pd.hDevNames);
  4219. wsprintf(szDeviceName, "%s %s",
  4220. (LPCTSTR)lpDev + lpDev->wDeviceOffset,
  4221. (LPCTSTR)lpDev + lpDev->wOutputOffset);
  4222. ::GlobalUnlock(pd.hDevNames);
  4223. }
  4224. //
  4225. // Tell the printer we are starting the print.
  4226. // Note that the printer object handles the cancellation dialog.
  4227. WbPrinter printer(szDeviceName);
  4228. TCHAR szJobName[_MAX_PATH];
  4229. ::LoadString(g_hInstance, IDS_PRINT_NAME, szJobName, _MAX_PATH);
  4230. int nPrintResult = printer.StartDoc(pd.hDC, szJobName, nStartPage);
  4231. if (nPrintResult < 0)
  4232. {
  4233. WARNING_OUT(("Print result %d", nPrintResult));
  4234. bPrintError = TRUE;
  4235. }
  4236. else
  4237. {
  4238. // Find out how many copies to print
  4239. int copyNum;
  4240. copyNum = 0;
  4241. while ((copyNum < pd.nCopies) && !bPrintError)
  4242. {
  4243. // Loop through all pages
  4244. int nPrintPage = 0;
  4245. WBPOSITION pos;
  4246. WorkspaceObj * pWorkspace = NULL;
  4247. pos = g_pListOfWorkspaces->GetHeadPosition();
  4248. while(pos)
  4249. {
  4250. pWorkspace = (WorkspaceObj*) g_pListOfWorkspaces->GetNext(pos);
  4251. nPrintPage++;
  4252. if (nPrintPage >= nStartPage && nPrintPage <= nEndPage // We are in the range
  4253. && pWorkspace && pWorkspace->GetHead() != NULL) // is there anything in the workspace
  4254. {
  4255. // Tell the printer we are starting a new page
  4256. printer.StartPage(pd.hDC, nPrintPage);
  4257. if (!printer.Error())
  4258. {
  4259. RECT rectArea;
  4260. rectArea.left = 0;
  4261. rectArea.top = 0;
  4262. rectArea.right = DRAW_WIDTH;
  4263. rectArea.bottom = DRAW_HEIGHT;
  4264. // Print the page
  4265. PG_Print(pWorkspace, pd.hDC, &rectArea);
  4266. // Inform the printer that the page is complete
  4267. printer.EndPage(pd.hDC);
  4268. }
  4269. else
  4270. {
  4271. bPrintError = TRUE;
  4272. break;
  4273. }
  4274. }
  4275. }
  4276. copyNum++;
  4277. }
  4278. // The print has completed
  4279. nPrintResult = printer.EndDoc(pd.hDC);
  4280. if (nPrintResult < 0)
  4281. {
  4282. WARNING_OUT(("Print result %d", nPrintResult));
  4283. bPrintError = TRUE;
  4284. }
  4285. // reset the error if the user cancelled the print
  4286. if (printer.Aborted())
  4287. {
  4288. WARNING_OUT(("User cancelled print"));
  4289. bPrintError = FALSE;
  4290. }
  4291. }
  4292. }
  4293. }
  4294. // Inform the user if an error occurred
  4295. if (bPrintError)
  4296. {
  4297. // display a message informing the user the job terminated
  4298. ::PostMessage(m_hwnd, WM_USER_DISPLAY_ERROR, WBFE_RC_PRINTER, 0);
  4299. }
  4300. //
  4301. // Cleanup the hDevMode, hDevNames, and hdc blocks if allocated
  4302. //
  4303. if (pd.hDevMode != NULL)
  4304. {
  4305. ::GlobalFree(pd.hDevMode);
  4306. pd.hDevMode = NULL;
  4307. }
  4308. if (pd.hDevNames != NULL)
  4309. {
  4310. ::GlobalFree(pd.hDevNames);
  4311. pd.hDevNames = NULL;
  4312. }
  4313. if (pd.hDC != NULL)
  4314. {
  4315. ::DeleteDC(pd.hDC);
  4316. pd.hDC = NULL;
  4317. }
  4318. return S_OK;
  4319. }
  4320. //
  4321. //
  4322. // Function: InsertPageAfter
  4323. //
  4324. // Purpose: Insert a new page after the specified page.
  4325. //
  4326. //
  4327. void WbMainWindow::InsertPageAfter(WorkspaceObj * pCurrentWorkspace)
  4328. {
  4329. //
  4330. // Create a standard workspace
  4331. //
  4332. if(g_numberOfWorkspaces < WB_MAX_WORKSPACES)
  4333. {
  4334. //
  4335. // If we were editing text
  4336. //
  4337. if (g_pDraw->TextEditActive())
  4338. {
  4339. g_pDraw->EndTextEntry(TRUE);
  4340. }
  4341. BOOL bRemote = FALSE;
  4342. if(m_pLocalRemotePointer)
  4343. {
  4344. bRemote = TRUE;
  4345. OnRemotePointer();
  4346. }
  4347. WorkspaceObj * pObj;
  4348. DBG_SAVE_FILE_LINE
  4349. pObj = new WorkspaceObj();
  4350. pObj->AddToWorkspace();
  4351. if(bRemote)
  4352. {
  4353. OnRemotePointer();
  4354. }
  4355. }
  4356. }
  4357. //
  4358. //
  4359. // Function: OnInsertPageAfter
  4360. //
  4361. // Purpose: Insert a new page after the current page
  4362. //
  4363. //
  4364. LRESULT WbMainWindow::OnInsertPageAfter()
  4365. {
  4366. // Insert the new page
  4367. InsertPageAfter(g_pCurrentWorkspace);
  4368. return S_OK;
  4369. }
  4370. //
  4371. //
  4372. // Function: OnDeletePage
  4373. //
  4374. // Purpose: Delete the current page
  4375. //
  4376. //
  4377. LRESULT WbMainWindow::OnDeletePage()
  4378. {
  4379. //
  4380. // Clear the page
  4381. //
  4382. if(g_pListOfWorkspaces->GetHeadPosition() == g_pListOfWorkspaces->GetTailPosition())
  4383. {
  4384. OnClearPage(TRUE);
  4385. }
  4386. else
  4387. {
  4388. LRESULT result = OnClearPage(FALSE);
  4389. //
  4390. // If we had more pages move to the previous page
  4391. //
  4392. if(result == IDYES)
  4393. {
  4394. //
  4395. // Deleted locally
  4396. //
  4397. g_pCurrentWorkspace->DeletedLocally();
  4398. //
  4399. // If the text editor is active
  4400. //
  4401. if(m_drawingArea.TextEditActive())
  4402. {
  4403. m_drawingArea.DeactivateTextEditor();
  4404. }
  4405. BOOL remotePointerIsOn = FALSE;
  4406. if(g_pMain->m_pLocalRemotePointer)
  4407. {
  4408. g_pMain->OnRemotePointer();
  4409. remotePointerIsOn = TRUE;
  4410. }
  4411. //
  4412. // Remove the workspace and point current to the correct one.
  4413. //
  4414. WorkspaceObj * pWorkspace = RemoveWorkspace(g_pCurrentWorkspace);
  4415. g_pMain->GoPage(pWorkspace);
  4416. if(remotePointerIsOn)
  4417. {
  4418. g_pMain->OnRemotePointer();
  4419. }
  4420. }
  4421. }
  4422. return S_OK;
  4423. }
  4424. //
  4425. //
  4426. // Function: OnRemotePointer
  4427. //
  4428. // Purpose: Create a remote pointer
  4429. //
  4430. //
  4431. LRESULT WbMainWindow::OnRemotePointer(void)
  4432. {
  4433. if(m_pLocalRemotePointer == NULL)
  4434. {
  4435. BitmapObj* remotePtr;
  4436. DBG_SAVE_FILE_LINE
  4437. m_pLocalRemotePointer = new BitmapObj(TOOLTYPE_REMOTEPOINTER);
  4438. if(g_pMain->m_localRemotePointerPosition.x < 0 && g_pMain->m_localRemotePointerPosition.y < 0 )
  4439. {
  4440. // Position the remote pointer in center of the drawing area
  4441. RECT rcVis;
  4442. m_drawingArea.GetVisibleRect(&rcVis);
  4443. m_localRemotePointerPosition.x = rcVis.left + (rcVis.right - rcVis.left)/2;
  4444. m_localRemotePointerPosition.y = rcVis.top + (rcVis.bottom - rcVis.top)/2;
  4445. }
  4446. m_pLocalRemotePointer->MoveTo(m_localRemotePointerPosition.x ,m_localRemotePointerPosition.y);
  4447. COLORREF color;
  4448. color = g_crDefaultColors[g_MyIndex + 1];
  4449. m_pLocalRemotePointer->CreateColoredIcon(color);
  4450. //
  4451. // If we couldn't create an image for teh remote pointer bitmap
  4452. //
  4453. if(m_pLocalRemotePointer->m_lpbiImage == NULL)
  4454. {
  4455. delete m_pLocalRemotePointer;
  4456. m_pLocalRemotePointer = NULL;
  4457. return S_FALSE;
  4458. }
  4459. m_pLocalRemotePointer->Draw(FALSE);
  4460. // Add the new grabbed bitmap
  4461. m_pLocalRemotePointer->AddToWorkspace();
  4462. m_TB.PushDown(IDM_REMOTE);
  4463. CheckMenuItem(IDM_REMOTE);
  4464. // Start the timer for updating the graphic (this is only for updating
  4465. // the graphic when the user stops moving the pointer but keeps the
  4466. // mouse button down).
  4467. ::SetTimer(g_pDraw->m_hwnd, TIMER_REMOTE_POINTER_UPDATE, DRAW_REMOTEPOINTERDELAY, NULL);
  4468. }
  4469. else
  4470. {
  4471. ::KillTimer(g_pDraw->m_hwnd, TIMER_REMOTE_POINTER_UPDATE);
  4472. m_pLocalRemotePointer->DeletedLocally();
  4473. g_pCurrentWorkspace->RemoveT126Object(m_pLocalRemotePointer);
  4474. m_pLocalRemotePointer = NULL;
  4475. m_TB.PopUp(IDM_REMOTE);
  4476. UncheckMenuItem(IDM_REMOTE);
  4477. }
  4478. return S_OK;
  4479. }
  4480. //
  4481. //
  4482. // Function: OnSync
  4483. //
  4484. // Purpose: Sync or unsync the Whiteboard with other users
  4485. //
  4486. //
  4487. LRESULT WbMainWindow::OnSync(void)
  4488. {
  4489. // Determine whether we are currently synced
  4490. if (m_drawingArea.IsSynced())
  4491. {
  4492. // currently synced, so unsync
  4493. Unsync();
  4494. }
  4495. else
  4496. {
  4497. // currently unsynced, so sync
  4498. Sync();
  4499. }
  4500. m_drawingArea.SetSync(!m_drawingArea.IsSynced());
  4501. EnableToolbar( TRUE );
  4502. m_AG.EnablePageCtrls(TRUE);
  4503. return S_OK;
  4504. }
  4505. //
  4506. //
  4507. // Function: Sync
  4508. //
  4509. // Purpose: Sync the Whiteboard with other users
  4510. //
  4511. //
  4512. void WbMainWindow::Sync(void)
  4513. {
  4514. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::Sync");
  4515. m_TB.PushDown(IDM_SYNC);
  4516. CheckMenuItem(IDM_SYNC);
  4517. GotoPage(g_pConferenceWorkspace);
  4518. } // Sync
  4519. //
  4520. //
  4521. // Function: Unsync
  4522. //
  4523. // Purpose: Unsync the Whiteboard with other users
  4524. //
  4525. //
  4526. void WbMainWindow::Unsync(void)
  4527. {
  4528. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::Unsync");
  4529. m_TB.PopUp(IDM_SYNC);
  4530. UncheckMenuItem(IDM_SYNC);
  4531. } // Unsync
  4532. LRESULT WbMainWindow::OnConfShutdown( WPARAM, LPARAM )
  4533. {
  4534. if (OnQueryEndSession())
  4535. {
  4536. ::SendMessage(m_hwnd, WM_CLOSE, 0, 0); // do close immediately
  4537. // :
  4538. // DON'T DO ANYTHING else at this point except for exit.
  4539. return( 0 );// tell conf ok to shutdown
  4540. }
  4541. else
  4542. return( (LRESULT)g_cuEndSessionAbort ); // don't shutdown
  4543. }
  4544. //
  4545. //
  4546. // Function: OnQueryEndSession
  4547. //
  4548. // Purpose: Ensure user is prompted to save changes when windows is
  4549. // ended.
  4550. //
  4551. //
  4552. LRESULT WbMainWindow::OnQueryEndSession(void)
  4553. {
  4554. HWND hwndPopup;
  4555. if ((hwndPopup = ::GetLastActivePopup(m_hwnd)) != m_hwnd)
  4556. {
  4557. ::Message(NULL, IDS_DEFAULT, IDS_CANTCLOSE );
  4558. ::BringWindowToTop(hwndPopup);
  4559. return( FALSE );
  4560. }
  4561. // If changes are required then prompt the user to save
  4562. int iDoNew = IDYES;
  4563. if (IsIdle())
  4564. {
  4565. iDoNew = QuerySaveRequired(TRUE);
  4566. if (iDoNew == IDYES)
  4567. {
  4568. // Save the changes
  4569. iDoNew = (int)OnSave(FALSE);
  4570. }
  4571. }
  4572. // remember what we did so OnClose can act appropriately
  4573. m_bQuerySysShutdown = (iDoNew != IDCANCEL);
  4574. // If the user did not cancel, let windows exit
  4575. return( m_bQuerySysShutdown );
  4576. }
  4577. //
  4578. //
  4579. // Function: UnlockDrawingArea
  4580. //
  4581. // Purpose: Unlock the drawing area and enable the appropriate buttons
  4582. //
  4583. //
  4584. //
  4585. void WbMainWindow::UnlockDrawingArea()
  4586. {
  4587. m_drawingArea.Unlock();
  4588. {
  4589. EnableToolbar( TRUE );
  4590. m_AG.EnablePageCtrls(TRUE);
  4591. }
  4592. //
  4593. // Show the tool attributes group.
  4594. //
  4595. m_AG.DisplayTool(m_pCurrentTool);
  4596. }
  4597. //
  4598. //
  4599. // Function: LockDrawingArea
  4600. //
  4601. // Purpose: Lock the drawing area and enable the appropriate buttons
  4602. //
  4603. //
  4604. //
  4605. void WbMainWindow::LockDrawingArea()
  4606. {
  4607. m_drawingArea.Lock();
  4608. if(g_pNMWBOBJ->m_LockerID != g_MyMemberID)
  4609. {
  4610. // Disable tool-bar buttons that cannot be used while locked
  4611. EnableToolbar( FALSE );
  4612. m_AG.EnablePageCtrls(FALSE);
  4613. //
  4614. // Hide the tool attributes
  4615. //
  4616. if (m_WG.m_hwnd != NULL)
  4617. {
  4618. ::ShowWindow(m_WG.m_hwnd, SW_HIDE);
  4619. }
  4620. m_AG.Hide();
  4621. }
  4622. }
  4623. void WbMainWindow::EnableToolbar( BOOL bEnable )
  4624. {
  4625. if (bEnable)
  4626. {
  4627. m_TB.Enable(IDM_SELECT);
  4628. // don't allow text editing in zoom mode
  4629. if( m_drawingArea.Zoomed() )
  4630. m_TB.Disable(IDM_TEXT);
  4631. else
  4632. m_TB.Enable(IDM_TEXT);
  4633. m_TB.Enable(IDM_PEN);
  4634. m_TB.Enable(IDM_HIGHLIGHT);
  4635. m_TB.Enable(IDM_LINE);
  4636. m_TB.Enable(IDM_ZOOM);
  4637. m_TB.Enable(IDM_BOX);
  4638. m_TB.Enable(IDM_FILLED_BOX);
  4639. m_TB.Enable(IDM_ELLIPSE);
  4640. m_TB.Enable(IDM_FILLED_ELLIPSE);
  4641. m_TB.Enable(IDM_ERASER);
  4642. m_TB.Enable(IDM_GRAB_AREA);
  4643. m_TB.Enable(IDM_GRAB_WINDOW);
  4644. //
  4645. // If we are not synced we can't lock the other nodes
  4646. //
  4647. if(g_pDraw->IsSynced())
  4648. {
  4649. m_TB.PushDown(IDM_SYNC);
  4650. m_TB.Enable(IDM_LOCK);
  4651. }
  4652. else
  4653. {
  4654. m_TB.PopUp(IDM_SYNC);
  4655. m_TB.Disable(IDM_LOCK);
  4656. }
  4657. if(m_drawingArea.IsLocked())
  4658. {
  4659. m_TB.Disable(IDM_SYNC);
  4660. }
  4661. else
  4662. {
  4663. m_TB.Enable(IDM_SYNC);
  4664. }
  4665. m_TB.Enable(IDM_REMOTE);
  4666. }
  4667. else
  4668. {
  4669. m_TB.Disable(IDM_SELECT);
  4670. m_TB.Disable(IDM_PEN);
  4671. m_TB.Disable(IDM_HIGHLIGHT);
  4672. m_TB.Disable(IDM_TEXT);
  4673. m_TB.Disable(IDM_LINE);
  4674. m_TB.Disable(IDM_ZOOM);
  4675. m_TB.Disable(IDM_BOX);
  4676. m_TB.Disable(IDM_FILLED_BOX);
  4677. m_TB.Disable(IDM_ELLIPSE);
  4678. m_TB.Disable(IDM_FILLED_ELLIPSE);
  4679. m_TB.Disable(IDM_ERASER);
  4680. m_TB.Disable(IDM_REMOTE);
  4681. m_TB.Disable(IDM_GRAB_AREA);
  4682. m_TB.Disable(IDM_GRAB_WINDOW);
  4683. m_TB.Disable(IDM_LOCK);
  4684. m_TB.Disable(IDM_SYNC);
  4685. }
  4686. }
  4687. //
  4688. //
  4689. // Function: UpdatePageButtons
  4690. //
  4691. // Purpose: Enable or disable the page buttons, according to the current
  4692. // state.
  4693. //
  4694. //
  4695. //
  4696. void WbMainWindow::UpdatePageButtons()
  4697. {
  4698. BOOL bEnable = TRUE;
  4699. if(!g_pCurrentWorkspace)
  4700. {
  4701. g_numberOfWorkspaces = 0;
  4702. bEnable = FALSE;
  4703. }
  4704. else
  4705. {
  4706. //
  4707. // Can we update this workspace
  4708. //
  4709. bEnable = g_pCurrentWorkspace->GetUpdatesEnabled();
  4710. //
  4711. // If it is locked, is it locked by us
  4712. //
  4713. if(!bEnable)
  4714. {
  4715. bEnable |= g_pNMWBOBJ->m_LockerID == g_MyMemberID;
  4716. }
  4717. }
  4718. m_AG.EnablePageCtrls(bEnable);
  4719. WBPOSITION pos;
  4720. WorkspaceObj * pWorkspace;
  4721. UINT pageNumber = 0;
  4722. pos = g_pListOfWorkspaces->GetHeadPosition();
  4723. while(pos)
  4724. {
  4725. pageNumber++;
  4726. pWorkspace = (WorkspaceObj*)g_pListOfWorkspaces->GetNext(pos);
  4727. if(g_pCurrentWorkspace == pWorkspace)
  4728. {
  4729. break;
  4730. }
  4731. }
  4732. m_AG.SetCurrentPageNumber(pageNumber);
  4733. m_AG.SetLastPageNumber(g_numberOfWorkspaces);
  4734. EnableToolbar( bEnable );
  4735. }
  4736. //
  4737. //
  4738. // Function: CancelLoad
  4739. //
  4740. // Purpose: Cancel any load in progress
  4741. //
  4742. //
  4743. void WbMainWindow::CancelLoad(BOOL bReleaseLock)
  4744. {
  4745. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::CancelLoad");
  4746. // reset file name to untitled
  4747. ZeroMemory(m_strFileName, sizeof(m_strFileName));
  4748. // reset the whiteboard substate
  4749. SetSubstate(SUBSTATE_IDLE);
  4750. }
  4751. //
  4752. //
  4753. // Function: IsIdle
  4754. //
  4755. // Purpose: Returns true if the main window is idle (in a call and not
  4756. // loading a file/performing a new)
  4757. //
  4758. //
  4759. BOOL WbMainWindow::IsIdle()
  4760. {
  4761. return(m_uiSubState == SUBSTATE_IDLE);
  4762. }
  4763. //
  4764. //
  4765. // Function: SetSubstate
  4766. //
  4767. // Purpose: Sets the substate, informing the page sorter dialog of the
  4768. // change, if necessary.
  4769. //
  4770. //
  4771. void WbMainWindow::SetSubstate(UINT newSubState)
  4772. {
  4773. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::SetSubstate");
  4774. // substate only valid if in a call
  4775. if (newSubState != m_uiSubState)
  4776. {
  4777. DBG_SAVE_FILE_LINE
  4778. m_uiSubState = newSubState;
  4779. // Trace the substate change
  4780. switch (m_uiSubState)
  4781. {
  4782. case SUBSTATE_IDLE:
  4783. TRACE_DEBUG(("set substate to IDLE"));
  4784. break;
  4785. case SUBSTATE_LOADING:
  4786. TRACE_DEBUG(("set substate to LOADING"));
  4787. break;
  4788. case SUBSTATE_SAVING:
  4789. TRACE_DEBUG(("set substate to SAVING"));
  4790. break;
  4791. case SUBSTATE_NEW_IN_PROGRESS:
  4792. TRACE_DEBUG(("set substate to NEW_IN_PROGRESS"));
  4793. break;
  4794. default:
  4795. ERROR_OUT(("Unknown substate %hd",m_uiSubState));
  4796. break;
  4797. }
  4798. // update the page buttons (may have become enabled/disabled)
  4799. UpdatePageButtons();
  4800. }
  4801. }
  4802. //
  4803. //
  4804. // Function: PositionUpdated
  4805. //
  4806. // Purpose: Called when the drawing area position has changed.
  4807. // change, if necessary.
  4808. //
  4809. //
  4810. void WbMainWindow::PositionUpdated()
  4811. {
  4812. RECT rectDraw;
  4813. m_drawingArea.GetVisibleRect(&rectDraw);
  4814. g_pDraw->InvalidateSurfaceRect(&rectDraw,FALSE);
  4815. }
  4816. //
  4817. //
  4818. // Function : OnEndSession
  4819. //
  4820. // Purpose : Called when Windows is exiting
  4821. //
  4822. //
  4823. void WbMainWindow::OnEndSession(BOOL bEnding)
  4824. {
  4825. if (bEnding)
  4826. {
  4827. ::PostQuitMessage(0);
  4828. }
  4829. else
  4830. {
  4831. m_bQuerySysShutdown = FALSE; // never mind, cancel OnClose special handling
  4832. }
  4833. }
  4834. //
  4835. // Function: OnCancelMode()
  4836. //
  4837. // Purpose: Called whenever a WM_CANCELMODE message is sent to the frame
  4838. // window.
  4839. // WM_CANCELMODE is sent when another app or dialog receives the
  4840. // input focus. The frame simply records that a WM_CANCELMODE
  4841. // message has been sent. This fact is used by the SelectWindow
  4842. // code to determine if it should cancel the selecting of a
  4843. // window
  4844. //
  4845. //
  4846. void WbMainWindow::OnCancelMode()
  4847. {
  4848. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnCancelMode");
  4849. m_cancelModeSent = TRUE;
  4850. //
  4851. // Note: Not passed to the default handler as the default action on
  4852. // WM_CANCELMODE is to release mouse capture - we shall do this
  4853. // explicitly.
  4854. //
  4855. // blow off any dragging that might be in progress (bug 573)
  4856. POINT pt;
  4857. ::GetCursorPos( &pt );
  4858. ::ScreenToClient(m_drawingArea.m_hwnd, &pt);
  4859. ::SendMessage(m_drawingArea.m_hwnd, WM_LBUTTONUP, 0, MAKELONG( pt.x, pt.y ) );
  4860. }
  4861. void WbMainWindow::LoadCmdLine(LPCSTR szFilename)
  4862. {
  4863. int iOnSave;
  4864. if (szFilename && *szFilename)
  4865. {
  4866. if( UsersMightLoseData( NULL, NULL ) ) // bug NM4db:418
  4867. return;
  4868. // Don't prompt to save file if we're already loading
  4869. if (m_uiSubState != SUBSTATE_LOADING )
  4870. {
  4871. // Check whether there are changes to be saved
  4872. iOnSave = QuerySaveRequired(TRUE);
  4873. }
  4874. else
  4875. {
  4876. return;
  4877. }
  4878. if (iOnSave == IDYES)
  4879. {
  4880. // User wants to save the drawing area contents
  4881. int iResult = (int)OnSave(TRUE);
  4882. if( iResult == IDOK )
  4883. {
  4884. }
  4885. else
  4886. {
  4887. // cancelled out of save, so cancel the open operation
  4888. return;
  4889. }
  4890. }
  4891. // load filename
  4892. if( iOnSave != IDCANCEL )
  4893. LoadFile(szFilename);
  4894. }
  4895. }
  4896. //
  4897. // OnNotify()
  4898. // Handles TTN_NEEDTEXTA and TTN_NEEDTEXTW
  4899. //
  4900. void WbMainWindow::OnNotify(UINT id, NMHDR * pNM)
  4901. {
  4902. UINT nID;
  4903. HWND hwnd = NULL;
  4904. POINT ptCurPos;
  4905. UINT nTipStringID;
  4906. if (!pNM)
  4907. return;
  4908. if (pNM->code == TTN_NEEDTEXTA)
  4909. {
  4910. TOOLTIPTEXTA *pTA = (TOOLTIPTEXTA *)pNM;
  4911. // get id and hwnd
  4912. if( pTA->uFlags & TTF_IDISHWND )
  4913. {
  4914. // idFrom is actually the HWND of the tool
  4915. hwnd = (HWND)pNM->idFrom;
  4916. nID = ::GetDlgCtrlID(hwnd);
  4917. }
  4918. else
  4919. {
  4920. nID = (UINT)pNM->idFrom;
  4921. }
  4922. // get tip string id
  4923. nTipStringID = GetTipId(hwnd, nID);
  4924. if (nTipStringID == 0)
  4925. return;
  4926. // give it to em
  4927. pTA->lpszText = MAKEINTRESOURCE( nTipStringID );
  4928. pTA->hinst = g_hInstance;
  4929. }
  4930. else if (pNM->code == TTN_NEEDTEXTW)
  4931. {
  4932. TOOLTIPTEXTW *pTW = (TOOLTIPTEXTW *)pNM;
  4933. // get id and hwnd
  4934. if( pTW->uFlags & TTF_IDISHWND )
  4935. {
  4936. // idFrom is actually the HWND of the tool
  4937. hwnd = (HWND)pNM->idFrom;
  4938. nID = ::GetDlgCtrlID(hwnd);
  4939. }
  4940. else
  4941. {
  4942. nID = (UINT)pNM->idFrom;
  4943. }
  4944. // get tip string id
  4945. nTipStringID = GetTipId(hwnd, nID );
  4946. if (nTipStringID == 0)
  4947. return;
  4948. // give it to em
  4949. pTW->lpszText = (LPWSTR) MAKEINTRESOURCE( nTipStringID );
  4950. pTW->hinst = g_hInstance;
  4951. }
  4952. }
  4953. //
  4954. // GetTipId()
  4955. // Finds the tooltip for a control in Whiteboard
  4956. //
  4957. UINT WbMainWindow::GetTipId(HWND hwndTip, UINT nID)
  4958. {
  4959. WbTool * pTool;
  4960. BOOL bCheckedState;
  4961. int nTipID;
  4962. int nTipStringID;
  4963. int i;
  4964. // find tip stuff relevant for nID
  4965. nTipID = -1;
  4966. for( i=0; i<((sizeof g_tipIDsArray)/(sizeof (TIPIDS) )); i++ )
  4967. {
  4968. if( g_tipIDsArray[i].nID == nID )
  4969. {
  4970. nTipID = i;
  4971. break;
  4972. }
  4973. }
  4974. // valid?
  4975. if( nTipID < 0 )
  4976. return( 0 );
  4977. // get checked state
  4978. switch( g_tipIDsArray[ nTipID ].nCheck )
  4979. {
  4980. case TB:
  4981. bCheckedState =
  4982. (::SendMessage(m_TB.m_hwnd, TB_ISBUTTONCHECKED, nID, 0) != 0);
  4983. break;
  4984. case BT:
  4985. if (hwndTip != NULL)
  4986. {
  4987. bCheckedState =
  4988. (::SendMessage(hwndTip, BM_GETSTATE, 0, 0) & 0x0003) == 1;
  4989. }
  4990. else
  4991. bCheckedState = FALSE;
  4992. break;
  4993. case NA:
  4994. default:
  4995. bCheckedState = FALSE;
  4996. break;
  4997. }
  4998. // get tip string id
  4999. if( bCheckedState )
  5000. nTipStringID = g_tipIDsArray[ nTipID ].nDownTipID;
  5001. else
  5002. nTipStringID = g_tipIDsArray[ nTipID ].nUpTipID;
  5003. // done
  5004. return( nTipStringID );
  5005. }
  5006. // gets default path if no saves or opens have been done yet
  5007. // Returns FALSE if last default should be reused
  5008. BOOL WbMainWindow::GetDefaultPath(LPTSTR csDefaultPath , UINT size)
  5009. {
  5010. DWORD dwType;
  5011. DWORD dwBufLen = size;
  5012. HKEY hDefaultKey = NULL;
  5013. if( !lstrlen(m_strFileName) )
  5014. {
  5015. // a name has not been picked yet in this session, use path
  5016. // to "My Documents"
  5017. if( (RegOpenKeyEx( HKEY_CURRENT_USER,
  5018. "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
  5019. 0,
  5020. KEY_READ,
  5021. &hDefaultKey )
  5022. != ERROR_SUCCESS) ||
  5023. (RegQueryValueEx( hDefaultKey,
  5024. "Personal",
  5025. NULL,
  5026. &dwType,
  5027. (BYTE *)csDefaultPath,
  5028. &dwBufLen )
  5029. != ERROR_SUCCESS))
  5030. {
  5031. // reg failed, use desktop
  5032. GetWindowsDirectory( csDefaultPath, 2*_MAX_PATH );
  5033. lstrcpy(csDefaultPath,"\\Desktop");
  5034. }
  5035. if( hDefaultKey != NULL )
  5036. RegCloseKey( hDefaultKey );
  5037. return( TRUE );
  5038. }
  5039. else
  5040. {
  5041. return( FALSE );
  5042. }
  5043. }
  5044. void WbMainWindow::OnSysColorChange( void )
  5045. {
  5046. if (g_pCurrentWorkspace != NULL)
  5047. {
  5048. PG_ReinitPalettes();
  5049. ::InvalidateRect(m_hwnd, NULL, TRUE );
  5050. ::UpdateWindow(m_hwnd);
  5051. }
  5052. m_TB.RecolorButtonImages();
  5053. m_AG.RecolorButtonImages();
  5054. }
  5055. //
  5056. // posts a do-you-wana-do-that message if other users are in the conference
  5057. //
  5058. BOOL WbMainWindow::UsersMightLoseData( BOOL *pbWasPosted, HWND hwnd )
  5059. {
  5060. if (g_pNMWBOBJ->GetNumberOfMembers() > 0)
  5061. {
  5062. if( pbWasPosted != NULL )
  5063. *pbWasPosted = TRUE;
  5064. return( ::Message(hwnd, IDS_DEFAULT, IDS_MSG_USERSMIGHTLOSE, MB_YESNO | MB_ICONEXCLAMATION ) != IDYES );
  5065. }
  5066. if( pbWasPosted != NULL )
  5067. *pbWasPosted = FALSE;
  5068. return( FALSE );
  5069. }
  5070. //
  5071. //
  5072. // Name: ContentsSave
  5073. //
  5074. // Purpose: Save the contents of the WB.
  5075. //
  5076. // Returns: Error code
  5077. //
  5078. //
  5079. UINT WbMainWindow::ContentsSave(LPCSTR pFileName)
  5080. {
  5081. UINT result = 0;
  5082. UINT index;
  5083. HANDLE hFile;
  5084. ULONG cbSizeWritten;
  5085. T126WB_FILE_HEADER t126Header;
  5086. WB_OBJ endOfFile;
  5087. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::ContentsSave");
  5088. //
  5089. // Open the file
  5090. //
  5091. m_hFile = CreateFile(pFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
  5092. FILE_ATTRIBUTE_NORMAL, 0);
  5093. if (m_hFile == INVALID_HANDLE_VALUE)
  5094. {
  5095. result = WB_RC_CREATE_FAILED;
  5096. ERROR_OUT(("Error creating file, win32 err=%d", GetLastError()));
  5097. goto CleanUp;
  5098. }
  5099. //
  5100. // Create the file header.
  5101. //
  5102. memcpy(t126Header.functionProfile, T126WB_FP_NAME,sizeof(T126WB_FP_NAME));
  5103. t126Header.length = sizeof(T126WB_FILE_HEADER) + g_numberOfWorkspaces*sizeof(UINT);
  5104. t126Header.version = T126WB_VERSION;
  5105. t126Header.numberOfWorkspaces = g_numberOfWorkspaces;
  5106. //
  5107. // Save the header
  5108. //
  5109. if (!WriteFile(m_hFile, (void *) &t126Header, sizeof(T126WB_FILE_HEADER), &cbSizeWritten, NULL))
  5110. {
  5111. result = WB_RC_WRITE_FAILED;
  5112. ERROR_OUT(("Error writing length to file, win32 err=%d", GetLastError()));
  5113. goto CleanUp;
  5114. }
  5115. WorkspaceObj* pWorkspace;
  5116. WBPOSITION pos;
  5117. index = 0;
  5118. pos = g_pListOfWorkspaces->GetHeadPosition();
  5119. while(pos)
  5120. {
  5121. pWorkspace = (WorkspaceObj*)g_pListOfWorkspaces->GetNext(pos);
  5122. ASSERT(pWorkspace);
  5123. UINT numberOfObjects = pWorkspace->EnumerateObjectsInWorkspace();
  5124. //
  5125. // Save the number of objects in each page
  5126. //
  5127. if (!WriteFile(m_hFile, (void *) &numberOfObjects, sizeof(numberOfObjects), &cbSizeWritten, NULL))
  5128. {
  5129. result = WB_RC_WRITE_FAILED;
  5130. ERROR_OUT(("Error writing length to file, win32 err=%d", GetLastError()));
  5131. goto CleanUp;
  5132. }
  5133. index++;
  5134. }
  5135. ASSERT(index == g_numberOfWorkspaces);
  5136. //
  5137. // Loop through the pages, saving each as we go
  5138. //
  5139. g_bSavingFile = TRUE;
  5140. ResendAllObjects();
  5141. //
  5142. // The Last Object to be saved is the current workspace
  5143. //
  5144. g_pCurrentWorkspace->OnObjectEdit();
  5145. //
  5146. // If we have successfully written the contents, we write an end-of-page
  5147. // marker to the file.
  5148. //
  5149. ZeroMemory(&endOfFile, sizeof(endOfFile));
  5150. endOfFile.length = sizeof(endOfFile);
  5151. endOfFile.type = TYPE_T126_END_OF_FILE;
  5152. //
  5153. // Write the end-of-file object
  5154. //
  5155. if (!WriteFile(m_hFile, (void *) &endOfFile, sizeof(endOfFile), &cbSizeWritten, NULL))
  5156. {
  5157. result = WB_RC_WRITE_FAILED;
  5158. ERROR_OUT(("Error writing length to file, win32 err=%d", GetLastError()));
  5159. goto CleanUp;
  5160. }
  5161. CleanUp:
  5162. //
  5163. // Close the file
  5164. //
  5165. if (m_hFile != INVALID_HANDLE_VALUE)
  5166. {
  5167. CloseHandle(m_hFile);
  5168. }
  5169. //
  5170. // If an error occurred in saving the contents to file, and the file was
  5171. // opened, then delete it.
  5172. //
  5173. if (result != 0)
  5174. {
  5175. //
  5176. // If the file was opened successfully, delete it
  5177. //
  5178. if (m_hFile != INVALID_HANDLE_VALUE)
  5179. {
  5180. DeleteFile(pFileName);
  5181. }
  5182. }
  5183. g_bSavingFile = FALSE;
  5184. return(result);
  5185. }
  5186. //
  5187. //
  5188. // Name: ObjectSave
  5189. //
  5190. // Purpose: Save a structure to file
  5191. //
  5192. // Returns: Error code
  5193. //
  5194. //
  5195. UINT WbMainWindow::ObjectSave(UINT type, LPBYTE pData, UINT length)
  5196. {
  5197. ASSERT(m_hFile != INVALID_HANDLE_VALUE);
  5198. UINT result = 0;
  5199. ULONG cbSizeWritten;
  5200. WB_OBJ objectHeader;
  5201. objectHeader.length = sizeof(WB_OBJ) + length;
  5202. objectHeader.type = type;
  5203. //
  5204. // Save the Header
  5205. //
  5206. if (! WriteFile(m_hFile, (void *) &objectHeader, sizeof(WB_OBJ), &cbSizeWritten, NULL))
  5207. {
  5208. result = WB_RC_WRITE_FAILED;
  5209. ERROR_OUT(("Error writing length to file, win32 err=%d", GetLastError()));
  5210. goto bail;
  5211. }
  5212. ASSERT(cbSizeWritten == sizeof(WB_OBJ));
  5213. //
  5214. // Save the object data
  5215. //
  5216. if (! WriteFile(m_hFile, pData, length, &cbSizeWritten, NULL))
  5217. {
  5218. result = WB_RC_WRITE_FAILED;
  5219. ERROR_OUT(("Error writing data to file, win32 err=%d", GetLastError()));
  5220. goto bail;
  5221. }
  5222. ASSERT(cbSizeWritten == length);
  5223. bail:
  5224. return result;
  5225. }
  5226. //
  5227. //
  5228. // Function: ContentsLoad
  5229. //
  5230. // Purpose: Load a file and delete the current workspaces
  5231. //
  5232. //
  5233. UINT WbMainWindow::ContentsLoad(LPCSTR pFileName)
  5234. {
  5235. BOOL bRemote;
  5236. UINT result = 0;
  5237. PT126WB_FILE_HEADER_AND_OBJECTS pHeader = NULL;
  5238. //
  5239. // Validate the file, and get a handle to it.
  5240. // If there is an error, then no file handle is returned.
  5241. //
  5242. pHeader = ValidateFile(pFileName);
  5243. if (pHeader == NULL)
  5244. {
  5245. result = WB_RC_BAD_FILE_FORMAT;
  5246. goto bail;
  5247. }
  5248. delete pHeader;
  5249. //
  5250. // Remember if remote pointer is on
  5251. //
  5252. bRemote = FALSE;
  5253. if (m_pLocalRemotePointer)
  5254. {
  5255. // Remove remote pointer from pages
  5256. bRemote = TRUE;
  5257. OnRemotePointer();
  5258. }
  5259. //
  5260. // Just before loading anything delete all the workspaces
  5261. //
  5262. ::InvalidateRect(g_pDraw->m_hwnd, NULL, TRUE);
  5263. DeleteAllWorkspaces(TRUE);
  5264. result = ObjectLoad();
  5265. //
  5266. // Put remote pointer back if it was on
  5267. //
  5268. if (bRemote)
  5269. {
  5270. OnRemotePointer();
  5271. }
  5272. //
  5273. // The workspaces may have being saved as locked
  5274. // Unlock all workspaces, and make sure the drawing area is unlocked
  5275. //
  5276. TogleLockInAllWorkspaces(FALSE, FALSE); // Not locked, don't send updates
  5277. UnlockDrawingArea();
  5278. ResendAllObjects();
  5279. bail:
  5280. if(INVALID_HANDLE_VALUE != m_hFile)
  5281. {
  5282. CloseHandle(m_hFile);
  5283. }
  5284. return(result);
  5285. }
  5286. //
  5287. //
  5288. // Function: ObjectLoad
  5289. //
  5290. // Purpose: Load t126 ASN1 objects from the file
  5291. //
  5292. //
  5293. UINT WbMainWindow::ObjectLoad(void)
  5294. {
  5295. UINT result = 0;
  5296. LPSTR pData;
  5297. UINT length;
  5298. DWORD cbSizeRead;
  5299. BOOL readFileOk = TRUE;
  5300. WB_OBJ objectHeader;
  5301. while(readFileOk)
  5302. {
  5303. //
  5304. // Read objects header info
  5305. //
  5306. readFileOk = ReadFile(m_hFile, (void *) &objectHeader, sizeof(WB_OBJ), &cbSizeRead, NULL);
  5307. if ( !readFileOk )
  5308. {
  5309. //
  5310. // Make sure we return a sensible error.
  5311. //
  5312. ERROR_OUT(("reading object length, win32 err=%d, length=%d", GetLastError(), sizeof(WB_OBJ)));
  5313. result = WB_RC_BAD_FILE_FORMAT;
  5314. goto bail;
  5315. }
  5316. ASSERT(cbSizeRead == sizeof(WB_OBJ));
  5317. //
  5318. // Read the object's raw data
  5319. //
  5320. length = objectHeader.length - sizeof(WB_OBJ);
  5321. DBG_SAVE_FILE_LINE
  5322. pData = (LPSTR)new BYTE[length];
  5323. readFileOk = ReadFile(m_hFile, (LPBYTE) pData, length, &cbSizeRead, NULL);
  5324. if(! readFileOk)
  5325. {
  5326. //
  5327. // Make sure we return a sensible error.
  5328. //
  5329. ERROR_OUT(("Reading object from file: win32 err=%d, asked for %d got %d bytes", GetLastError(), length, cbSizeRead));
  5330. result = WB_RC_BAD_FILE_FORMAT;
  5331. goto bail;
  5332. }
  5333. ASSERT(cbSizeRead == length);
  5334. //
  5335. // It is an ASN1 t126 object
  5336. //
  5337. if(objectHeader.type == TYPE_T126_ASN_OBJECT)
  5338. {
  5339. //
  5340. // Try decoding and adding it to the workspace
  5341. //
  5342. if(!T126_MCSSendDataIndication(length, (LPBYTE)pData, g_MyMemberID, TRUE))
  5343. {
  5344. result = WB_RC_BAD_FILE_FORMAT;
  5345. goto bail;
  5346. }
  5347. }
  5348. //
  5349. // If it is an end of file do a last check
  5350. //
  5351. else if(objectHeader.type == TYPE_T126_END_OF_FILE)
  5352. {
  5353. if(objectHeader.length != sizeof(WB_OBJ))
  5354. {
  5355. result = WB_RC_BAD_FILE_FORMAT;
  5356. }
  5357. goto bail;
  5358. }
  5359. else
  5360. {
  5361. ERROR_OUT(("Don't know object type =%d , size=%d ; skipping to next object", objectHeader.type, length));
  5362. }
  5363. delete pData;
  5364. pData = NULL;
  5365. }
  5366. bail:
  5367. if(pData)
  5368. {
  5369. delete pData;
  5370. }
  5371. return(result);
  5372. }
  5373. //
  5374. //
  5375. // Function: ValidateFile
  5376. //
  5377. // Purpose: Open a T126 file and check if it is valid, if it is the it will
  5378. // return a pointer to the header structure
  5379. //
  5380. //
  5381. PT126WB_FILE_HEADER_AND_OBJECTS WbMainWindow::ValidateFile(LPCSTR pFileName)
  5382. {
  5383. UINT result = 0;
  5384. PT126WB_FILE_HEADER pFileHeader = NULL;
  5385. PT126WB_FILE_HEADER_AND_OBJECTS pCompleteFileHeader = NULL;
  5386. UINT length;
  5387. ULONG cbSizeRead;
  5388. BOOL fileOpen = FALSE;
  5389. DBG_SAVE_FILE_LINE
  5390. pFileHeader = new T126WB_FILE_HEADER[1];
  5391. if(pFileHeader == NULL)
  5392. {
  5393. WARNING_OUT(("Could not allocate memory to read the file header opening file, win32 err=%d", GetLastError()));
  5394. result = WB_RC_CREATE_FAILED;
  5395. goto bail;
  5396. }
  5397. //
  5398. // Open the file
  5399. //
  5400. m_hFile = CreateFile(pFileName, GENERIC_READ, 0, NULL,
  5401. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  5402. if (m_hFile == INVALID_HANDLE_VALUE)
  5403. {
  5404. WARNING_OUT(("Error opening file, win32 err=%d", GetLastError()));
  5405. result = WB_RC_CREATE_FAILED;
  5406. goto bail;
  5407. }
  5408. //
  5409. // Show that we have opened the file successfully
  5410. //
  5411. fileOpen = TRUE;
  5412. //
  5413. // Read the file header
  5414. //
  5415. if (! ReadFile(m_hFile, (void *) pFileHeader, sizeof(T126WB_FILE_HEADER), &cbSizeRead, NULL))
  5416. {
  5417. WARNING_OUT(("Error reading file header, win32 err=%d", GetLastError()));
  5418. result = WB_RC_READ_FAILED;
  5419. goto bail;
  5420. }
  5421. if (cbSizeRead != sizeof(T126WB_FILE_HEADER))
  5422. {
  5423. WARNING_OUT(("Could not read file header"));
  5424. result = WB_RC_BAD_FILE_FORMAT;
  5425. goto bail;
  5426. }
  5427. //
  5428. // Validate the file header
  5429. //
  5430. if (memcmp(pFileHeader->functionProfile, T126WB_FP_NAME, sizeof(T126WB_FP_NAME)))
  5431. {
  5432. WARNING_OUT(("Bad function profile in file header"));
  5433. result = WB_RC_BAD_FILE_FORMAT;
  5434. goto bail;
  5435. }
  5436. //
  5437. // Check for version
  5438. //
  5439. if( pFileHeader->version < T126WB_VERSION)
  5440. {
  5441. WARNING_OUT(("Bad version number"));
  5442. result = WB_RC_BAD_FILE_FORMAT;
  5443. goto bail;
  5444. }
  5445. DBG_SAVE_FILE_LINE
  5446. pCompleteFileHeader = (PT126WB_FILE_HEADER_AND_OBJECTS) new BYTE[sizeof(T126WB_FILE_HEADER) + pFileHeader->numberOfWorkspaces*sizeof(UINT)];
  5447. memcpy(pCompleteFileHeader, pFileHeader, sizeof(T126WB_FILE_HEADER));
  5448. //
  5449. // Read the rest of the file header
  5450. //
  5451. if(! ReadFile(m_hFile, (void *) &pCompleteFileHeader->numberOfObjects[0], pFileHeader->numberOfWorkspaces*sizeof(UINT), &cbSizeRead, NULL))
  5452. {
  5453. if(cbSizeRead != pFileHeader->numberOfWorkspaces)
  5454. result = WB_RC_BAD_FILE_FORMAT;
  5455. goto bail;
  5456. }
  5457. TRACE_DEBUG(("Opening file with %d workspaces", pFileHeader->numberOfWorkspaces));
  5458. #ifdef _DEBUG
  5459. INT i;
  5460. for(i = 0; i < (INT)pFileHeader->numberOfWorkspaces; i++)
  5461. {
  5462. TRACE_DEBUG(("Workspace %d contains %d objects", i+1, pCompleteFileHeader->numberOfObjects[i] ));
  5463. }
  5464. #endif
  5465. bail:
  5466. //
  5467. // Close the file if there has been an error
  5468. //
  5469. if ( (fileOpen) && (result != 0))
  5470. {
  5471. CloseHandle(m_hFile);
  5472. m_hFile = INVALID_HANDLE_VALUE;
  5473. }
  5474. //
  5475. // Delete allocated file header
  5476. //
  5477. if(pFileHeader)
  5478. {
  5479. delete pFileHeader;
  5480. }
  5481. //
  5482. // if there was an error delete the return header
  5483. //
  5484. if(result != 0)
  5485. {
  5486. if(pCompleteFileHeader)
  5487. {
  5488. delete pCompleteFileHeader;
  5489. pCompleteFileHeader = NULL;
  5490. }
  5491. }
  5492. return pCompleteFileHeader;
  5493. }
  5494. //
  5495. //
  5496. // Function: GetFileNameStr
  5497. //
  5498. // Purpose: Return a plain file name string
  5499. //
  5500. //
  5501. LPSTR WbMainWindow::GetFileNameStr(void)
  5502. {
  5503. UINT size = 2*_MAX_FNAME;
  5504. if(m_pTitleFileName)
  5505. {
  5506. delete m_pTitleFileName;
  5507. m_pTitleFileName = NULL;
  5508. }
  5509. DBG_SAVE_FILE_LINE
  5510. m_pTitleFileName = new TCHAR[size];
  5511. if (!m_pTitleFileName)
  5512. {
  5513. ERROR_OUT(("GetWindowTitle: failed to allocate TitleFileName"));
  5514. return(NULL);
  5515. }
  5516. // Set title to either the "Untitled" string, or the loaded file name
  5517. if( (!lstrlen(m_strFileName))|| (GetFileTitle( m_strFileName, m_pTitleFileName, (WORD)size ) != 0) )
  5518. {
  5519. ::LoadString(g_hInstance, IDS_UNTITLED , m_pTitleFileName, 2*_MAX_FNAME);
  5520. }
  5521. return (LPSTR)m_pTitleFileName;
  5522. }
  5523.