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.

9681 lines
250 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. static const TCHAR s_cszHtmlHelpFile[] = TEXT("nmwhiteb.chm");
  12. // Class name
  13. TCHAR szMainClassName[] = "Wb32MainWindowClass";
  14. //
  15. // Scroll accelerators
  16. //
  17. typedef struct tagSCROLL
  18. {
  19. UINT uiMenuId;
  20. UINT uiMessage;
  21. UINT uiScrollCode;
  22. }
  23. SCROLL;
  24. static const SCROLL s_MenuToScroll[] =
  25. {
  26. { IDM_PAGEUP, WM_VSCROLL, SB_PAGEUP },
  27. { IDM_PAGEDOWN, WM_VSCROLL, SB_PAGEDOWN },
  28. { IDM_SHIFTPAGEUP, WM_HSCROLL, SB_PAGEUP },
  29. { IDM_SHIFTPAGEDOWN, WM_HSCROLL, SB_PAGEDOWN },
  30. { IDM_HOME, WM_HSCROLL, SB_TOP },
  31. { IDM_HOME, WM_VSCROLL, SB_TOP },
  32. { IDM_END, WM_HSCROLL, SB_BOTTOM },
  33. { IDM_END, WM_VSCROLL, SB_BOTTOM },
  34. { IDM_LINEUP, WM_VSCROLL, SB_LINEUP },
  35. { IDM_LINEDOWN, WM_VSCROLL, SB_LINEDOWN },
  36. { IDM_SHIFTLINEUP, WM_HSCROLL, SB_LINEUP },
  37. { IDM_SHIFTLINEDOWN, WM_HSCROLL, SB_LINEDOWN }
  38. };
  39. // tooltip data
  40. // check codes
  41. #define NA 0 // dont't check checked state
  42. #define TB 1 // check toolbar for checked state
  43. #define BT 2 // check tipped wnd (a button) for checked state
  44. typedef struct
  45. {
  46. UINT nID;
  47. UINT nCheck;
  48. UINT nUpTipID;
  49. UINT nDownTipID;
  50. }
  51. TIPIDS;
  52. TIPIDS g_tipIDsArray[] =
  53. {
  54. {IDM_SELECT, TB, IDS_HINT_SELECT, IDS_HINT_SELECT},
  55. {IDM_ERASER, TB, IDS_HINT_ERASER, IDS_HINT_ERASER},
  56. {IDM_TEXT, TB, IDS_HINT_TEXT, IDS_HINT_TEXT},
  57. {IDM_HIGHLIGHT, TB, IDS_HINT_HIGHLIGHT, IDS_HINT_HIGHLIGHT},
  58. {IDM_PEN, TB, IDS_HINT_PEN, IDS_HINT_PEN},
  59. {IDM_LINE, TB, IDS_HINT_LINE, IDS_HINT_LINE},
  60. {IDM_BOX, TB, IDS_HINT_BOX, IDS_HINT_BOX},
  61. {IDM_FILLED_BOX, TB, IDS_HINT_FBOX, IDS_HINT_FBOX},
  62. {IDM_ELLIPSE, TB, IDS_HINT_ELLIPSE, IDS_HINT_ELLIPSE},
  63. {IDM_FILLED_ELLIPSE, TB, IDS_HINT_FELLIPSE, IDS_HINT_FELLIPSE},
  64. {IDM_ZOOM, TB, IDS_HINT_ZOOM_UP, IDS_HINT_ZOOM_DOWN},
  65. {IDM_REMOTE, TB, IDS_HINT_REMOTE_UP, IDS_HINT_REMOTE_DOWN},
  66. {IDM_LOCK, TB, IDS_HINT_LOCK_UP, IDS_HINT_LOCK_DOWN},
  67. {IDM_SYNC, TB, IDS_HINT_SYNC_UP, IDS_HINT_SYNC_DOWN},
  68. {IDM_GRAB_AREA, TB, IDS_HINT_GRAB_AREA, IDS_HINT_GRAB_AREA},
  69. {IDM_GRAB_WINDOW, TB, IDS_HINT_GRAB_WINDOW, IDS_HINT_GRAB_WINDOW},
  70. {IDM_WIDTH_1, NA, IDS_HINT_WIDTH_1, IDS_HINT_WIDTH_1},
  71. {IDM_WIDTH_2, NA, IDS_HINT_WIDTH_2, IDS_HINT_WIDTH_2},
  72. {IDM_WIDTH_3, NA, IDS_HINT_WIDTH_3, IDS_HINT_WIDTH_3},
  73. {IDM_WIDTH_4, NA, IDS_HINT_WIDTH_4, IDS_HINT_WIDTH_4},
  74. {IDM_PAGE_FIRST, BT, IDS_HINT_PAGE_FIRST, IDS_HINT_PAGE_FIRST},
  75. {IDM_PAGE_PREV, BT, IDS_HINT_PAGE_PREVIOUS, IDS_HINT_PAGE_PREVIOUS},
  76. {IDM_PAGE_ANY, NA, IDS_HINT_PAGE_ANY, IDS_HINT_PAGE_ANY},
  77. {IDM_PAGE_NEXT, BT, IDS_HINT_PAGE_NEXT, IDS_HINT_PAGE_NEXT},
  78. {IDM_PAGE_LAST, BT, IDS_HINT_PAGE_LAST, IDS_HINT_PAGE_LAST},
  79. {IDM_PAGE_INSERT_AFTER, BT, IDS_HINT_PAGE_INSERT, IDS_HINT_PAGE_INSERT}
  80. };
  81. ////////////
  82. //
  83. //
  84. // Function: WbMainWindow constructor
  85. //
  86. // Purpose: Create the main Whiteboard window. An exception is thrown
  87. // if an error occurs during construction.
  88. //
  89. //
  90. WbMainWindow::WbMainWindow(void)
  91. {
  92. OSVERSIONINFO OsData;
  93. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::WbMainWindow");
  94. //
  95. // Initialize member vars first!
  96. //
  97. m_hwnd = NULL;
  98. ZeroMemory(m_ToolArray, sizeof(m_ToolArray));
  99. m_hwndToolTip = NULL;
  100. ZeroMemory(&m_tiLastHit, sizeof(m_tiLastHit));
  101. m_nLastHit = -1;
  102. m_bInitOk = FALSE;
  103. m_bDisplayingError = FALSE;
  104. g_pwbCore = NULL;
  105. m_dwDomain = 0;
  106. m_bTimerActive = FALSE;
  107. m_bSyncUpdateNeeded = FALSE;
  108. m_hPageClip = WB_PAGE_HANDLE_NULL;
  109. m_hGraphicClip = NULL;
  110. m_pDelayedGraphicClip = NULL;
  111. m_pDelayedDataClip = NULL;
  112. m_bToolBarOn = FALSE;
  113. // Load the main accelerator table
  114. m_hAccelTable =
  115. ::LoadAccelerators(g_hInstance, MAKEINTRESOURCE(MAINACCELTABLE));
  116. m_hwndPageSortDlg = NULL;
  117. m_hwndQuerySaveDlg = NULL;
  118. m_hwndWaitForEventDlg = NULL;
  119. m_hwndWaitForLockDlg = NULL;
  120. m_hwndInitDlg = NULL;
  121. m_hwndSB = NULL;
  122. m_bStatusBarOn = TRUE;
  123. m_pCurrentTool = NULL;
  124. m_uiSavedLockType = WB_LOCK_TYPE_NONE;
  125. ZeroMemory(m_strFileName, sizeof(m_strFileName));
  126. m_hCurrentPage = WB_PAGE_HANDLE_NULL;
  127. // Load the alternative accelerator table for the pages edit
  128. // field and text editor
  129. m_hAccelPagesGroup =
  130. ::LoadAccelerators(g_hInstance, MAKEINTRESOURCE(PAGESGROUPACCELTABLE));
  131. m_hAccelTextEdit =
  132. ::LoadAccelerators(g_hInstance, MAKEINTRESOURCE(TEXTEDITACCELTABLE));
  133. m_pLocalUser = NULL;
  134. m_pLockOwner = NULL;
  135. // Show that we are not yet in a call
  136. m_uiState = STARTING;
  137. m_uiSubState = SUBSTATE_IDLE;
  138. // We are not currently displaying a menu
  139. m_hContextMenuBar = NULL;
  140. m_hContextMenu = NULL;
  141. m_hGrobjContextMenuBar = NULL;
  142. m_hGrobjContextMenu = NULL;
  143. m_bPromptingJoinCall = FALSE;
  144. m_bInSaveDialog = FALSE;
  145. m_bJoinCallPending = FALSE;
  146. m_dwPendingDomain = 0;
  147. m_bPendingCallKeepContents = FALSE;
  148. m_dwJoinDomain = 0;
  149. m_bCallActive = FALSE;
  150. m_hInitMenu = NULL;
  151. m_numRemoteUsers = 0;
  152. m_bSelectAllInProgress = FALSE;
  153. m_bUnlockStateSettled = TRUE;
  154. m_bQuerySysShutdown = FALSE;
  155. // figure out if we're on Win95
  156. m_bIsWin95 = FALSE;
  157. OsData.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  158. if( GetVersionEx( &OsData ) )
  159. {
  160. if( OsData.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS )
  161. m_bIsWin95 = TRUE;
  162. }
  163. m_cancelModeSent = FALSE;
  164. //
  165. // We only do this once for the lifetime of the DLL. There is no
  166. // way really to clean up registered window messages, and each register
  167. // bumps up a ref count. If we registered each time WB was started up
  168. // during one session of CONF, we'd overflow the refcount.
  169. //
  170. if (!g_uConfShutdown)
  171. {
  172. g_uConfShutdown = ::RegisterWindowMessage( NM_ENDSESSION_MSG_NAME );
  173. }
  174. }
  175. //
  176. // Open()
  177. // Do Main window initialization (stuff that can fail). After this,
  178. // the run code will try to join the current domain and do message loop
  179. // stuff.
  180. //
  181. BOOL WbMainWindow::Open(int iCommand)
  182. {
  183. WNDCLASSEX wc;
  184. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::Open");
  185. //
  186. // CREATE OTHER GLOBALS
  187. //
  188. // Start the Whiteboard Core
  189. if (!CreateWBObject(WbMainWindowEventHandler, &g_pwbCore))
  190. {
  191. ERROR_OUT(("WBP_Start failed"));
  192. DefaultExceptionHandler(WBFE_RC_WB, UT_RC_NO_MEM);
  193. return FALSE;
  194. }
  195. if (!InitToolArray())
  196. {
  197. ERROR_OUT(("Can't create tools; failing to start up"));
  198. return(FALSE);
  199. }
  200. g_pUsers = new WbUserList;
  201. if (!g_pUsers)
  202. {
  203. ERROR_OUT(("Can't create g_pUsers"));
  204. return(FALSE);
  205. }
  206. g_pIcons = new DCWbColorToIconMap();
  207. if (!g_pIcons)
  208. {
  209. ERROR_OUT(("Can't create g_pIcons"));
  210. return(FALSE);
  211. }
  212. //
  213. // Init comon controls
  214. //
  215. InitCommonControls();
  216. //
  217. // CREATE THE MAIN FRAME WINDOW
  218. //
  219. ASSERT(!m_hwnd);
  220. // Get the class info for it, and change the name.
  221. ZeroMemory(&wc, sizeof(wc));
  222. wc.cbSize = sizeof(wc);
  223. wc.style = CS_DBLCLKS; // CS_HREDRAW | CS_VREDRAW?
  224. wc.lpfnWndProc = WbMainWindowProc;
  225. wc.hInstance = g_hInstance;
  226. wc.hIcon = ::LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_APP));
  227. wc.hCursor = ::LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
  228. wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
  229. wc.lpszMenuName = MAKEINTRESOURCE(MAINMENU);
  230. wc.lpszClassName = szMainClassName;
  231. if (!::RegisterClassEx(&wc))
  232. {
  233. ERROR_OUT(("Can't register private frame window class"));
  234. return(FALSE);
  235. }
  236. // Create the main drawing window.
  237. if (!::CreateWindowEx(WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, szMainClassName,
  238. NULL, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
  239. CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, g_hInstance, this))
  240. {
  241. // Could not create the main window
  242. ERROR_OUT(("Failed to create main window"));
  243. return(FALSE);
  244. }
  245. ASSERT(m_hwnd);
  246. // Create the pop-up context menu
  247. if (!CreateContextMenus())
  248. {
  249. ERROR_OUT(("Failed to create context menus"));
  250. return(FALSE);
  251. }
  252. // Register the the main window for Drag/Drop messages.
  253. DragAcceptFiles(m_hwnd, TRUE);
  254. //
  255. // CREATE THE CHILD WINDOWS
  256. //
  257. // Create the drawing pane
  258. // (the Create call throws an exception on error)
  259. RECT clientRect;
  260. RECT drawingAreaRect;
  261. ::GetClientRect(m_hwnd, &clientRect);
  262. drawingAreaRect = clientRect;
  263. // Every control in the main window has a border on it, so increase the
  264. // client size by 1 to force these borders to be drawn under the inside
  265. // black line in the window frame. This prevents a 2 pel wide border
  266. // being drawn
  267. ::InflateRect(&clientRect, 1, 1);
  268. SIZE sizeAG;
  269. m_AG.GetNaturalSize(&sizeAG);
  270. //
  271. // The drawing area is the top part of the client. The attributes group
  272. // and status bar are below it.
  273. //
  274. drawingAreaRect.bottom -= (STATUSBAR_HEIGHT
  275. + GetSystemMetrics(SM_CYBORDER)
  276. + sizeAG.cy);
  277. if (!m_drawingArea.Create(m_hwnd, &drawingAreaRect))
  278. {
  279. ERROR_OUT(("Failed to create drawing area"));
  280. return(FALSE);
  281. }
  282. if (!m_TB.Create(m_hwnd))
  283. {
  284. ERROR_OUT(("Failed to create tool window"));
  285. return(FALSE);
  286. }
  287. // Lock the drawing area initially. This prevents the user attempting
  288. // to make changes before we are in a call.
  289. LockDrawingArea();
  290. // disable remote pointer while we are initing (bug 4767)
  291. m_TB.Disable(IDM_REMOTE);
  292. m_hwndSB = ::CreateWindowEx(0, STATUSCLASSNAME, NULL,
  293. WS_CHILD | WS_VISIBLE | CCS_NOPARENTALIGN | CCS_NOMOVEY |
  294. CCS_NORESIZE | SBARS_SIZEGRIP,
  295. clientRect.left, clientRect.bottom - STATUSBAR_HEIGHT,
  296. (clientRect.right - clientRect.left), STATUSBAR_HEIGHT,
  297. m_hwnd, 0, g_hInstance, NULL);
  298. if (!m_hwndSB)
  299. {
  300. ERROR_OUT(("Failed to create status bar window"));
  301. return(FALSE);
  302. }
  303. //
  304. // Create the attributes group
  305. // The attributes group is on the bottom, underneath the
  306. // drawing area, above the status bar.
  307. //
  308. RECT rectAG;
  309. rectAG.left = clientRect.left;
  310. rectAG.right = clientRect.right;
  311. rectAG.top = drawingAreaRect.bottom;
  312. rectAG.bottom = rectAG.top + sizeAG.cy;
  313. if (!m_AG.Create(m_hwnd, &rectAG))
  314. {
  315. ERROR_OUT(("Failed to create attributes group window"));
  316. return(FALSE);
  317. }
  318. //
  319. // Create the widths group.
  320. // The widths group is on the left side, underneath the tools group
  321. //
  322. SIZE sizeWG;
  323. RECT rectWG;
  324. // The widths group is on the left side, underneath the toolbar
  325. m_WG.GetNaturalSize(&sizeWG);
  326. rectWG.left = 0;
  327. rectWG.right = rectWG.left + sizeWG.cx;
  328. rectWG.bottom = rectAG.top;
  329. rectWG.top = rectWG.bottom - sizeWG.cy;
  330. if (!m_WG.Create(m_hwnd, &rectWG))
  331. {
  332. ERROR_OUT(("Failed to create widths group window"));
  333. return(FALSE);
  334. }
  335. // The main window is created with the status bar visible. So make sure
  336. // that the relevant menu item is checked. This is subject to change
  337. // depending on options in the Open member function.
  338. CheckMenuItem(IDM_STATUS_BAR_TOGGLE);
  339. // Initialize the color, width and tool menus
  340. InitializeMenus();
  341. m_currentMenuTool = IDM_SELECT;
  342. m_pCurrentTool = m_ToolArray[TOOL_INDEX(IDM_SELECT)];
  343. m_hwndToolTip = ::CreateWindowEx(NULL, TOOLTIPS_CLASS, NULL,
  344. WS_POPUP | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT,
  345. CW_USEDEFAULT, CW_USEDEFAULT, m_hwnd, NULL, g_hInstance, NULL);
  346. if (!m_hwndToolTip)
  347. {
  348. ERROR_OUT(("Unable to create tooltip window"));
  349. return(FALSE);
  350. }
  351. // Add a dead-area tooltip
  352. TOOLINFO ti;
  353. ZeroMemory(&ti, sizeof(ti));
  354. ti.cbSize = sizeof(TOOLINFO);
  355. ti.uFlags = TTF_IDISHWND;
  356. ti.hwnd = m_hwnd;
  357. ti.uId = (UINT_PTR)m_hwnd;
  358. ::SendMessage(m_hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&ti);
  359. // Ensure the page buttons are disabled while starting
  360. UpdatePageButtons();
  361. // If this is the first time we have created a clipboard object,
  362. // register the private Whiteboard formats.
  363. if (g_ClipboardFormats[CLIPBOARD_PRIVATE_SINGLE_OBJ] == 0)
  364. {
  365. g_ClipboardFormats[CLIPBOARD_PRIVATE_SINGLE_OBJ] =
  366. (int) ::RegisterClipboardFormat("DCGWbClipFormat");
  367. }
  368. if (g_ClipboardFormats[CLIPBOARD_PRIVATE_MULTI_OBJ] == 0)
  369. {
  370. g_ClipboardFormats[CLIPBOARD_PRIVATE_MULTI_OBJ] =
  371. (int) ::RegisterClipboardFormat("DCGWbMultiObjClipFormat");
  372. }
  373. // There is no deleted graphic yet
  374. m_LastDeletedGraphic.BurnTrash();
  375. m_bInitOk = TRUE;
  376. BOOL bSuccess = TRUE; // indicates whether window opened successfully
  377. // Get the position of the window from options
  378. RECT rectWindow;
  379. RECT rectDefault;
  380. ::SetRectEmpty(&rectDefault);
  381. OPT_GetWindowRectOption(OPT_MAIN_MAINWINDOWRECT, &rectWindow, &rectDefault);
  382. if (!::IsRectEmpty(&rectWindow))
  383. {
  384. ::MoveWindow(m_hwnd, rectWindow.left, rectWindow.top,
  385. rectWindow.right - rectWindow.left,
  386. rectWindow.bottom - rectWindow.top, FALSE );
  387. }
  388. // Check whether the help bar is to be visible
  389. if (!OPT_GetBooleanOption(OPT_MAIN_STATUSBARVISIBLE, DFLT_MAIN_STATUSBARVISIBLE))
  390. {
  391. // Update the window to turn the help bar off
  392. OnStatusBarToggle();
  393. }
  394. //
  395. // Position the toolbar
  396. //
  397. // Hide the tool bar before moving it (otherwise we get some
  398. // problems redrawing it).
  399. ::ShowWindow(m_TB.m_hwnd, SW_HIDE);
  400. // Resize the window panes to allow room for the tools
  401. if (m_bToolBarOn)
  402. {
  403. ResizePanes();
  404. ::ShowWindow(m_TB.m_hwnd, SW_SHOW);
  405. }
  406. // Move the focus back from the tool window to the main window
  407. ::SetFocus(m_hwnd);
  408. // Check whether the tool window is to be visible
  409. if (OPT_GetBooleanOption(OPT_MAIN_TOOLBARVISIBLE, DFLT_MAIN_TOOLBARVISIBLE))
  410. {
  411. // Display the tool window, and check the associated menu item
  412. OnToolBarToggle();
  413. }
  414. // Set up the variable saving the maximized/minimized state of
  415. // the window and the extra style necessary for displaying the
  416. // window correctly initially.
  417. if (OPT_GetBooleanOption(OPT_MAIN_MAXIMIZED, DFLT_MAIN_MAXIMIZED))
  418. {
  419. m_uiWindowSize = SIZEFULLSCREEN;
  420. iCommand = SW_SHOWMAXIMIZED;
  421. }
  422. else if (OPT_GetBooleanOption(OPT_MAIN_MINIMIZED, DFLT_MAIN_MINIMIZED))
  423. {
  424. m_uiWindowSize = SIZEICONIC;
  425. iCommand = SW_SHOWMINIMIZED;
  426. }
  427. else
  428. {
  429. // Default
  430. m_uiWindowSize = SIZENORMAL;
  431. iCommand = SW_SHOWNORMAL;
  432. }
  433. UpdateWindowTitle();
  434. ::ShowWindow(m_hwnd, iCommand);
  435. ::UpdateWindow(m_hwnd);
  436. // Update the tool window
  437. ::UpdateWindow(m_TB.m_hwnd);
  438. // Select the tool
  439. m_currentMenuTool = IDM_SELECT;
  440. m_pCurrentTool = m_ToolArray[TOOL_INDEX(IDM_SELECT)];
  441. ::PostMessage(m_hwnd, WM_COMMAND, m_currentMenuTool, 0L);
  442. // Return value indicating success or failure
  443. return(bSuccess);
  444. }
  445. //
  446. //
  447. // Function: WbMainWindow destructor
  448. //
  449. // Purpose: Tidy up main window on destruction.
  450. //
  451. //
  452. WbMainWindow::~WbMainWindow()
  453. {
  454. //
  455. // Destroy the tooltip window
  456. //
  457. if (m_hwndToolTip)
  458. {
  459. ::DestroyWindow(m_hwndToolTip);
  460. m_hwndToolTip = NULL;
  461. }
  462. // Make sure the clipboard discards its saved graphic
  463. // before the drawingArea gets deleted.
  464. CLP_FreeDelayedGraphic();
  465. if (m_hGrobjContextMenuBar != NULL)
  466. {
  467. ::DestroyMenu(m_hGrobjContextMenuBar);
  468. m_hGrobjContextMenuBar = NULL;
  469. }
  470. m_hGrobjContextMenu = NULL;
  471. if (m_hContextMenuBar != NULL)
  472. {
  473. ::DestroyMenu(m_hContextMenuBar);
  474. m_hContextMenuBar = NULL;
  475. }
  476. m_hContextMenu = NULL;
  477. POSITION position = m_pageToPosition.GetHeadPosition();
  478. PAGE_POSITION * pPoint;
  479. while (position)
  480. {
  481. pPoint = (PAGE_POSITION*)m_pageToPosition.GetNext(position);
  482. delete pPoint;
  483. }
  484. m_pageToPosition.EmptyList();
  485. if (g_pwbCore)
  486. {
  487. //
  488. //We must call an explicit stop function, rather than 'delete'
  489. // because we need to pass in the event proc
  490. //
  491. g_pwbCore->WBP_Stop(WbMainWindowEventHandler);
  492. g_pwbCore = NULL;
  493. }
  494. DestroyToolArray();
  495. // Destroy our window
  496. if (m_hwnd != NULL)
  497. {
  498. ::DestroyWindow(m_hwnd);
  499. m_hwnd = NULL;
  500. }
  501. // Deregister our class
  502. ::UnregisterClass(szMainClassName, g_hInstance);
  503. //
  504. // Free the palette
  505. //
  506. if (g_hRainbowPaletteDisplay)
  507. {
  508. DeletePalette(g_hRainbowPaletteDisplay);
  509. g_hRainbowPaletteDisplay = NULL;
  510. }
  511. g_bPalettesInitialized = FALSE;
  512. g_bUsePalettes = FALSE;
  513. if (g_pIcons)
  514. {
  515. delete g_pIcons;
  516. g_pIcons = NULL;
  517. }
  518. if (g_pUsers)
  519. {
  520. delete g_pUsers;
  521. g_pUsers = NULL;
  522. }
  523. }
  524. //
  525. // JoinDomain()
  526. // Attach to the empty domain or current call
  527. //
  528. BOOL WbMainWindow::JoinDomain(void)
  529. {
  530. BOOL bSuccess;
  531. CM_STATUS cmStatus;
  532. // If there is a call available - join it.
  533. if (CMS_GetStatus(&cmStatus))
  534. {
  535. m_bCallActive = TRUE;
  536. // Get the domain ID of the call
  537. m_dwJoinDomain = (DWORD) cmStatus.callID;
  538. // Join the call
  539. bSuccess = JoinCall(FALSE);
  540. }
  541. else
  542. {
  543. // No call available so join the local domain
  544. // Set the domain ID to "no call"
  545. m_dwJoinDomain = (DWORD) OM_NO_CALL;
  546. // Join the call
  547. bSuccess = JoinCall(FALSE);
  548. }
  549. // Wait for the call to be joined, if not abandoned
  550. if (bSuccess)
  551. {
  552. bSuccess = WaitForJoinCallComplete();
  553. }
  554. // take down init dlg
  555. KillInitDlg();
  556. return(bSuccess);
  557. }
  558. //
  559. // KillInitDlg()
  560. // Take down the init dialog
  561. //
  562. void WbMainWindow::KillInitDlg(void)
  563. {
  564. if (m_hwndInitDlg != NULL )
  565. {
  566. ::DestroyWindow(m_hwndInitDlg);
  567. m_hwndInitDlg = NULL;
  568. ::EnableWindow(m_hwnd, TRUE);
  569. }
  570. }
  571. //
  572. // OnToolHitTest()
  573. // This handles tooltips for child windows.
  574. //
  575. int WbMainWindow::OnToolHitTest(POINT pt, TOOLINFO* pTI) const
  576. {
  577. HWND hwnd;
  578. int status;
  579. int nHit;
  580. ASSERT(!IsBadWritePtr(pTI, sizeof(TOOLINFO)));
  581. hwnd = ::ChildWindowFromPointEx(m_hwnd, pt, CWP_SKIPINVISIBLE);
  582. if (hwnd == m_AG.m_hwnd)
  583. {
  584. ::MapWindowPoints(m_hwnd, m_AG.m_hwnd, &pt, 1);
  585. hwnd = ::ChildWindowFromPointEx(m_AG.m_hwnd, pt, CWP_SKIPINVISIBLE);
  586. if (hwnd != NULL)
  587. {
  588. nHit = ::GetDlgCtrlID(hwnd);
  589. pTI->hwnd = m_hwnd;
  590. pTI->uId = (UINT_PTR)hwnd;
  591. pTI->uFlags |= TTF_IDISHWND;
  592. pTI->lpszText = LPSTR_TEXTCALLBACK;
  593. return(nHit);
  594. }
  595. }
  596. else if (hwnd == m_WG.m_hwnd)
  597. {
  598. int iItem;
  599. ::MapWindowPoints(m_hwnd, m_WG.m_hwnd, &pt, 1);
  600. iItem = m_WG.ItemFromPoint(pt.x, pt.y);
  601. pTI->hwnd = m_WG.m_hwnd;
  602. pTI->uId = iItem;
  603. // Since the area isn't a window, we must fill in the rect ourself
  604. m_WG.GetItemRect(iItem, &pTI->rect);
  605. pTI->lpszText = LPSTR_TEXTCALLBACK;
  606. return(iItem);
  607. }
  608. else if (hwnd == m_TB.m_hwnd)
  609. {
  610. RECT rect;
  611. TBBUTTON button;
  612. int i;
  613. for (i = 0; i < TOOLBAR_MAXBUTTON; i++)
  614. {
  615. if (::SendMessage(m_TB.m_hwnd, TB_GETITEMRECT, i, (LPARAM)&rect) &&
  616. ::PtInRect(&rect, pt) &&
  617. ::SendMessage(m_TB.m_hwnd, TB_GETBUTTON, i, (LPARAM)&button) &&
  618. !(button.fsStyle & TBSTYLE_SEP))
  619. {
  620. int nHit = button.idCommand;
  621. pTI->hwnd = m_TB.m_hwnd;
  622. pTI->uId = nHit;
  623. pTI->rect = rect;
  624. pTI->lpszText = LPSTR_TEXTCALLBACK;
  625. // found matching rect, return the ID of the button
  626. return(nHit);
  627. }
  628. }
  629. }
  630. return(-1);
  631. }
  632. //
  633. // WbMainWindowProc()
  634. // Frame window message handler
  635. //
  636. LRESULT WbMainWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  637. {
  638. LRESULT lResult = 0;
  639. WbMainWindow * pMain;
  640. pMain = (WbMainWindow *)::GetWindowLongPtr(hwnd, GWLP_USERDATA);
  641. switch (message)
  642. {
  643. case WM_NCCREATE:
  644. pMain = (WbMainWindow *)((LPCREATESTRUCT)lParam)->lpCreateParams;
  645. ASSERT(pMain);
  646. pMain->m_hwnd = hwnd;
  647. ::SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)pMain);
  648. goto DefWndProc;
  649. break;
  650. case WM_DESTROY:
  651. ShutDownHelp();
  652. break;
  653. case WM_NCDESTROY:
  654. pMain->m_hwnd = NULL;
  655. break;
  656. case WM_MOVE:
  657. pMain->OnMove();
  658. break;
  659. case WM_SIZE:
  660. pMain->OnSize((UINT)wParam, LOWORD(lParam), HIWORD(lParam));
  661. break;
  662. case WM_ACTIVATE:
  663. if (GET_WM_ACTIVATE_STATE(wParam, lParam) == WA_INACTIVE)
  664. {
  665. // Cancel the tooltip if it's around
  666. if (pMain->m_hwndToolTip)
  667. ::SendMessage(pMain->m_hwndToolTip, TTM_ACTIVATE, FALSE, 0);
  668. }
  669. goto DefWndProc;
  670. break;
  671. case WM_SETFOCUS:
  672. pMain->OnSetFocus();
  673. break;
  674. case WM_CANCELMODE:
  675. pMain->OnCancelMode();
  676. break;
  677. case WM_TIMER:
  678. pMain->OnTimer(wParam);
  679. break;
  680. case WM_INITMENUPOPUP:
  681. pMain->OnInitMenuPopup((HMENU)wParam, LOWORD(lParam), HIWORD(lParam));
  682. break;
  683. case WM_MENUSELECT:
  684. pMain->OnMenuSelect(GET_WM_MENUSELECT_CMD(wParam, lParam),
  685. GET_WM_MENUSELECT_FLAGS(wParam, lParam),
  686. GET_WM_MENUSELECT_HMENU(wParam, lParam));
  687. break;
  688. case WM_MEASUREITEM:
  689. pMain->OnMeasureItem((int)wParam, (LPMEASUREITEMSTRUCT)lParam);
  690. break;
  691. case WM_DRAWITEM:
  692. pMain->OnDrawItem((int)wParam, (LPDRAWITEMSTRUCT)lParam);
  693. break;
  694. case WM_QUERYNEWPALETTE:
  695. lResult = pMain->OnQueryNewPalette();
  696. break;
  697. case WM_PALETTECHANGED:
  698. pMain->OnPaletteChanged((HWND)wParam);
  699. break;
  700. case WM_HELP:
  701. pMain->OnCommand(IDM_HELP, 0, NULL);
  702. break;
  703. case WM_CLOSE:
  704. pMain->OnClose();
  705. break;
  706. case WM_QUERYENDSESSION:
  707. lResult = pMain->OnQueryEndSession();
  708. break;
  709. case WM_ENDSESSION:
  710. pMain->OnEndSession((BOOL)wParam);
  711. break;
  712. case WM_SYSCOLORCHANGE:
  713. pMain->OnSysColorChange();
  714. break;
  715. case WM_USER_PRIVATE_PARENTNOTIFY:
  716. pMain->OnParentNotify(GET_WM_PARENTNOTIFY_MSG(wParam, lParam));
  717. break;
  718. case WM_GETMINMAXINFO:
  719. if (pMain)
  720. pMain->OnGetMinMaxInfo((LPMINMAXINFO)lParam);
  721. break;
  722. case WM_RENDERALLFORMATS:
  723. pMain->OnRenderAllFormats();
  724. break;
  725. case WM_RENDERFORMAT:
  726. pMain->CLP_RenderFormat((int)wParam);
  727. break;
  728. case WM_COMMAND:
  729. pMain->OnCommand(LOWORD(wParam), HIWORD(wParam), (HWND)lParam);
  730. break;
  731. case WM_NOTIFY:
  732. pMain->OnNotify((UINT)wParam, (NMHDR *)lParam);
  733. break;
  734. case WM_DROPFILES:
  735. pMain->OnDropFiles((HDROP)wParam);
  736. break;
  737. case WM_USER_GOTO_USER_POSITION:
  738. pMain->OnGotoUserPosition(lParam);
  739. break;
  740. case WM_USER_GOTO_USER_POINTER:
  741. pMain->OnGotoUserPointer(lParam);
  742. break;
  743. case WM_USER_JOIN_CALL:
  744. pMain->OnJoinCall((BOOL)wParam, lParam);
  745. break;
  746. case WM_USER_DISPLAY_ERROR:
  747. pMain->OnDisplayError(wParam, lParam);
  748. break;
  749. case WM_USER_UPDATE_ATTRIBUTES:
  750. pMain->m_AG.DisplayTool(pMain->m_pCurrentTool);
  751. break;
  752. case WM_USER_JOIN_PENDING_CALL:
  753. pMain->OnJoinPendingCall();
  754. break;
  755. default:
  756. if (message == g_uConfShutdown)
  757. {
  758. lResult = pMain->OnConfShutdown(wParam, lParam);
  759. }
  760. else
  761. {
  762. DefWndProc:
  763. lResult = DefWindowProc(hwnd, message, wParam, lParam);
  764. }
  765. break;
  766. }
  767. return(lResult);
  768. }
  769. //
  770. // OnCommand()
  771. // Command dispatcher for the main window
  772. //
  773. void WbMainWindow::OnCommand(UINT cmd, UINT code, HWND hwndCtl)
  774. {
  775. switch (cmd)
  776. {
  777. //
  778. // FILE MENU
  779. //
  780. case IDM_NEW:
  781. OnNew();
  782. break;
  783. case IDM_OPEN:
  784. OnOpen();
  785. break;
  786. case IDM_SAVE:
  787. OnSave(FALSE);
  788. break;
  789. case IDM_SAVE_AS:
  790. OnSave(TRUE);
  791. break;
  792. case IDM_PRINT:
  793. OnPrint();
  794. break;
  795. case IDM_EXIT:
  796. ::PostMessage(m_hwnd, WM_CLOSE, 0, 0);
  797. break;
  798. //
  799. // EDIT MENU
  800. //
  801. case IDM_DELETE:
  802. OnDelete();
  803. break;
  804. case IDM_UNDELETE:
  805. OnUndelete();
  806. break;
  807. case IDM_CUT:
  808. OnCut();
  809. break;
  810. case IDM_COPY:
  811. OnCopy();
  812. break;
  813. case IDM_PASTE:
  814. OnPaste();
  815. break;
  816. case IDM_SELECTALL:
  817. OnSelectAll();
  818. break;
  819. case IDM_BRING_TO_TOP:
  820. m_drawingArea.BringToTopSelection();
  821. break;
  822. case IDM_SEND_TO_BACK:
  823. m_drawingArea.SendToBackSelection();
  824. break;
  825. case IDM_CLEAR_PAGE:
  826. OnClearPage();
  827. break;
  828. case IDM_DELETE_PAGE:
  829. OnDeletePage();
  830. break;
  831. case IDM_PAGE_INSERT_BEFORE:
  832. OnInsertPageBefore();
  833. break;
  834. case IDM_PAGE_INSERT_AFTER:
  835. OnInsertPageAfter();
  836. break;
  837. case IDM_PAGE_SORTER:
  838. OnPageSorter();
  839. break;
  840. //
  841. // VIEW MENU
  842. //
  843. case IDM_TOOL_BAR_TOGGLE:
  844. OnToolBarToggle();
  845. break;
  846. case IDM_STATUS_BAR_TOGGLE:
  847. OnStatusBarToggle();
  848. break;
  849. case IDM_ZOOM:
  850. OnZoom();
  851. break;
  852. //
  853. // TOOLS MENU
  854. //
  855. case IDM_SELECT:
  856. case IDM_PEN:
  857. case IDM_HIGHLIGHT:
  858. case IDM_TEXT:
  859. case IDM_ERASER:
  860. case IDM_LINE:
  861. case IDM_BOX:
  862. case IDM_FILLED_BOX:
  863. case IDM_ELLIPSE:
  864. case IDM_FILLED_ELLIPSE:
  865. OnSelectTool(cmd);
  866. break;
  867. case IDM_REMOTE:
  868. OnRemotePointer();
  869. break;
  870. case IDM_GRAB_AREA:
  871. OnGrabArea();
  872. break;
  873. case IDM_GRAB_WINDOW:
  874. OnGrabWindow();
  875. break;
  876. case IDM_SYNC:
  877. OnSync();
  878. break;
  879. case IDM_LOCK:
  880. OnLock();
  881. break;
  882. //
  883. // OPTIONS MENU
  884. //
  885. case IDM_COLOR:
  886. OnSelectColor();
  887. break;
  888. case IDM_EDITCOLOR:
  889. m_AG.OnEditColors();
  890. break;
  891. case IDM_FONT:
  892. OnChooseFont();
  893. break;
  894. case IDM_WIDTH_1:
  895. case IDM_WIDTH_2:
  896. case IDM_WIDTH_3:
  897. case IDM_WIDTH_4:
  898. OnSelectWidth(cmd);
  899. break;
  900. //
  901. // HELP MENU
  902. //
  903. case IDM_ABOUT:
  904. OnAbout();
  905. break;
  906. case IDM_HELP:
  907. ShowHelp();
  908. break;
  909. //
  910. // PAGE BAR
  911. //
  912. case IDM_PAGE_FIRST:
  913. OnFirstPage();
  914. break;
  915. case IDM_PAGE_PREV:
  916. OnPrevPage();
  917. break;
  918. case IDM_PAGE_GOTO:
  919. OnGotoPage();
  920. break;
  921. case IDM_PAGE_NEXT:
  922. OnNextPage();
  923. break;
  924. case IDM_PAGE_LAST:
  925. OnLastPage();
  926. break;
  927. //
  928. // SCROLLING
  929. //
  930. case IDM_PAGEUP:
  931. case IDM_PAGEDOWN:
  932. case IDM_SHIFTPAGEUP:
  933. case IDM_SHIFTPAGEDOWN:
  934. case IDM_HOME:
  935. case IDM_END:
  936. case IDM_LINEUP:
  937. case IDM_LINEDOWN:
  938. case IDM_SHIFTLINEUP:
  939. case IDM_SHIFTLINEDOWN:
  940. OnScrollAccelerator(cmd);
  941. break;
  942. }
  943. }
  944. //
  945. // WinHelp() wrapper
  946. //
  947. void WbMainWindow::ShowHelp(void)
  948. {
  949. HWND hwndCapture;
  950. // Get the main window out of any mode
  951. ::SendMessage(m_hwnd, WM_CANCELMODE, 0, 0);
  952. // Cancel any other tracking
  953. if (hwndCapture = ::GetCapture())
  954. ::SendMessage(hwndCapture, WM_CANCELMODE, 0, 0);
  955. // finally, run the Windows Help engine
  956. ShowNmHelp(s_cszHtmlHelpFile);
  957. }
  958. //
  959. //
  960. // Function: OnJoinCall
  961. //
  962. // Purpose: Join a call - displaying a dialog informing the user of
  963. // progress.
  964. //
  965. //
  966. void WbMainWindow::OnJoinCall(BOOL bKeep, LPARAM lParam)
  967. {
  968. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnJoinCall");
  969. // cancel the load if there's one in progress
  970. if ( (m_uiState == IN_CALL)
  971. && (m_uiSubState == SUBSTATE_LOADING))
  972. {
  973. CancelLoad();
  974. }
  975. // Get the parameters for JoinCall
  976. m_dwJoinDomain = (DWORD) lParam;
  977. // Start the process of joining the call
  978. BOOL bSuccess = JoinCall(bKeep);
  979. // Wait for the join call to complete, if not abandoned
  980. if (bSuccess)
  981. {
  982. bSuccess = WaitForJoinCallComplete();
  983. if (bSuccess)
  984. {
  985. TRACE_MSG(("Joined call OK"));
  986. }
  987. else
  988. {
  989. // WaitForJoinCallComplete displays appropriate error message
  990. TRACE_MSG(("Failed to join call"));
  991. // get into a good state
  992. Recover();
  993. }
  994. }
  995. // take down init dlg
  996. KillInitDlg();
  997. }
  998. //
  999. //
  1000. // Function: JoinCall
  1001. //
  1002. // Purpose: Join a call - displaying a dialog informing the user of
  1003. // progress.
  1004. //
  1005. //
  1006. BOOL WbMainWindow::JoinCall(BOOL bKeep)
  1007. {
  1008. BOOL bSuccess = TRUE;
  1009. UINT uiReturn;
  1010. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::JoinCall");
  1011. // We must not already be in a real call when we get here
  1012. if ((m_uiState == IN_CALL) && (m_dwDomain != OM_NO_CALL))
  1013. {
  1014. ERROR_OUT(("In a call already"));
  1015. }
  1016. //
  1017. // Prompt the user to save the current contents unless we are in
  1018. // application start-up (when there can be no contents to save) or we
  1019. // are keeping the contents (when there is no need to save).
  1020. //
  1021. if ((m_uiState != STARTING) && !bKeep)
  1022. {
  1023. //
  1024. // Close the page sorter dialog if it's up.
  1025. //
  1026. if (m_hwndPageSortDlg != NULL)
  1027. {
  1028. ::SendMessage(m_hwndPageSortDlg, WM_COMMAND,
  1029. MAKELONG(IDOK, BN_CLICKED), 0);
  1030. ASSERT(m_hwndPageSortDlg == NULL);
  1031. }
  1032. TRACE_MSG(("Not in STARTING state - check whether save wanted"));
  1033. if (m_hwndQuerySaveDlg != NULL)
  1034. {
  1035. ::SendMessage(m_hwndQuerySaveDlg, WM_COMMAND,
  1036. MAKELONG(IDCANCEL, BN_CLICKED), 0);
  1037. ASSERT(m_hwndQuerySaveDlg == NULL);
  1038. }
  1039. // flag that we are joining a call
  1040. m_bPromptingJoinCall = TRUE;
  1041. // ask the user whether to save changes (if required)
  1042. int iDoNew = QuerySaveRequired(FALSE);
  1043. // remove any save as dialog that is already up.
  1044. if (m_bInSaveDialog)
  1045. {
  1046. m_bPromptingJoinCall = FALSE;
  1047. CancelSaveDialog();
  1048. m_bPromptingJoinCall = TRUE;
  1049. }
  1050. if (iDoNew == IDYES)
  1051. {
  1052. TRACE_MSG(("User has elected to save the changes"));
  1053. // Save the changes
  1054. iDoNew = OnSave(FALSE);
  1055. }
  1056. if (!m_bPromptingJoinCall) // received end call notification
  1057. // (during save-as or query-save)
  1058. {
  1059. TRACE_MSG(("Call ended - abandon JoinCall"));
  1060. return(FALSE);
  1061. }
  1062. // flag we're no longer in a state where the join call can be
  1063. // cancelled
  1064. m_bPromptingJoinCall = FALSE;
  1065. //
  1066. // Reset the file name to Untitled, since we are receiving new
  1067. // contents
  1068. //
  1069. ZeroMemory(m_strFileName, sizeof(m_strFileName));
  1070. UpdateWindowTitle();
  1071. // if we have the lock then release it
  1072. if (WB_GotLock())
  1073. {
  1074. // Release the lock
  1075. g_pwbCore->WBP_Unlock();
  1076. // Set the locked check mark
  1077. UncheckMenuItem(IDM_LOCK);
  1078. // Pop up the lock button
  1079. m_TB.PopUp(IDM_LOCK);
  1080. }
  1081. if(m_pLocalUser != NULL)
  1082. {
  1083. // if the remote pointer is active then turn it off
  1084. DCWbGraphicPointer* pPointer = m_pLocalUser->GetPointer();
  1085. if (pPointer->IsActive())
  1086. {
  1087. OnRemotePointer();
  1088. }
  1089. }
  1090. // if sync is turned on then turn it off
  1091. Unsync();
  1092. // If we are not keeping the contents then the only valid current
  1093. // page is the first page.
  1094. g_pwbCore->WBP_PageHandle(WB_PAGE_HANDLE_NULL, PAGE_FIRST, &m_hCurrentPage);
  1095. }
  1096. //PUTBACK BY RAND - the progress timer meter is kinda the heart beat
  1097. // of this thing which I ripped out when I removed the
  1098. // progress meter. I put it back to fix 1476.
  1099. if (m_bTimerActive)
  1100. {
  1101. ::KillTimer(m_hwnd, TIMERID_PROGRESS_METER);
  1102. m_bTimerActive = FALSE;
  1103. }
  1104. //
  1105. // lock the drawing area until the joining of the call has succeeded
  1106. //
  1107. TRACE_MSG(("Locking drawing area"));
  1108. LockDrawingArea();
  1109. //
  1110. // Give the drawing area a null page during the joining process. This
  1111. // prevents the drawing area attempting to draw the objects in the page
  1112. // during the process of joining the call.
  1113. //
  1114. TRACE_MSG(("Detaching drawing area"));
  1115. m_drawingArea.Detach();
  1116. // Show that we are no longer in a call, but joining a new one
  1117. TRACE_MSG(("m_uiState %d", m_uiState));
  1118. if (m_uiState != STARTING)
  1119. {
  1120. m_uiState = JOINING;
  1121. UpdatePageButtons();
  1122. }
  1123. // put up init dlg
  1124. if (m_bCallActive)
  1125. {
  1126. ::UpdateWindow(m_hwnd);
  1127. //
  1128. // Our init dialog doesn't have a proc, since it has no UI to
  1129. // interact with. We destroy it when we are done. So, do the
  1130. // init stuff here.
  1131. //
  1132. m_hwndInitDlg = ::CreateDialogParam(g_hInstance,
  1133. MAKEINTRESOURCE(IM_INITIALIZING), m_hwnd, NULL, 0);
  1134. if (!m_hwndInitDlg)
  1135. {
  1136. ERROR_OUT(("Couldn't create startup screen for WB"));
  1137. }
  1138. else
  1139. {
  1140. RECT rcMovie;
  1141. HWND hwndMovieParent;
  1142. HWND hwndMovie;
  1143. // Get the rectangle to create the animation control in
  1144. hwndMovieParent = ::GetDlgItem(m_hwndInitDlg, IDC_INITIALIZING_ANIMATION);
  1145. ::GetClientRect(hwndMovieParent, &rcMovie);
  1146. hwndMovie = ::CreateWindowEx(0, ANIMATE_CLASS, NULL,
  1147. WS_CHILD | WS_VISIBLE | ACS_TRANSPARENT | ACS_CENTER,
  1148. rcMovie.left, rcMovie.top,
  1149. rcMovie.right - rcMovie.left, rcMovie.bottom - rcMovie.top,
  1150. hwndMovieParent, (HMENU)IDC_INITIALIZING_ANIMATION,
  1151. g_hInstance, NULL);
  1152. if (hwndMovie != NULL)
  1153. {
  1154. ::SendMessage(hwndMovie, ACM_OPEN, 0, (LPARAM)
  1155. MAKEINTRESOURCE(WBMOVIE));
  1156. }
  1157. // Disable the main window while the dialog is up.
  1158. ::EnableWindow(m_hwnd, FALSE);
  1159. ::ShowWindow(m_hwndInitDlg, SW_SHOW);
  1160. ::UpdateWindow(m_hwndInitDlg);
  1161. if (hwndMovie != NULL)
  1162. {
  1163. ::SendMessage(hwndMovie, ACM_PLAY, 0xFFFF,
  1164. MAKELPARAM(0, 0xFFFF));
  1165. }
  1166. }
  1167. }
  1168. //
  1169. // Start joining the call. Throws an exception on error.
  1170. //
  1171. ASSERT(g_pUsers);
  1172. g_pUsers->Clear();
  1173. uiReturn = g_pwbCore->WBP_JoinCall(bKeep, m_dwJoinDomain);
  1174. if (uiReturn != 0)
  1175. {
  1176. bSuccess = FALSE;
  1177. }
  1178. return(bSuccess);
  1179. }
  1180. //
  1181. //
  1182. // Function: WaitForJoinCallComplete
  1183. //
  1184. // Purpose: Join a call - displaying a dialog informing the user of
  1185. // progress.
  1186. //
  1187. //
  1188. BOOL WbMainWindow::WaitForJoinCallComplete(void)
  1189. {
  1190. BOOL bResult = FALSE;
  1191. TMDLG tmdlg;
  1192. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::WaitForJoinCallComplete");
  1193. //
  1194. // Bring up a dialog to wait for call joining to complete. This turns
  1195. // the asynchronous registration process into a synchronous process as
  1196. // far as this routine is concerned.
  1197. //
  1198. //
  1199. // Set the window title to show we're no longer registering/joining a
  1200. // call.
  1201. //
  1202. UpdateWindowTitle();
  1203. ASSERT(m_hwndWaitForEventDlg == NULL);
  1204. //
  1205. // This is the data we use in the timed dialog
  1206. //
  1207. ZeroMemory(&tmdlg, sizeof(tmdlg));
  1208. tmdlg.bVisible = FALSE;
  1209. tmdlg.bLockNotEvent = FALSE;
  1210. tmdlg.uiMaxDisplay = MAIN_REGISTRATION_TIMEOUT;
  1211. ::DialogBoxParam(g_hInstance, MAKEINTRESOURCE(INVISIBLEDIALOG),
  1212. m_hwnd, TimedDlgProc, (LPARAM)&tmdlg);
  1213. ASSERT(m_hwndWaitForEventDlg == NULL);
  1214. //
  1215. // Set the window title to show we're no longer registering/joining a
  1216. // call.
  1217. //
  1218. UpdateWindowTitle();
  1219. if (m_uiState != IN_CALL)
  1220. {
  1221. //
  1222. // We failed to join the call
  1223. //
  1224. WARNING_OUT(("User cancelled or joincall failed, m_uiState %d", m_uiState));
  1225. //
  1226. // We must display an error inline here because we will close
  1227. // shortly
  1228. //
  1229. OnDisplayError(WBFE_RC_JOIN_CALL_FAILED, 0);
  1230. }
  1231. else
  1232. {
  1233. bResult = TRUE;
  1234. }
  1235. return(bResult);
  1236. }
  1237. //
  1238. // TimedDlgProc()
  1239. // This puts up a visible or invisible dialog which only goes away when
  1240. // an event occurs or a certain amount of time has passed. We store the
  1241. // DialogBoxParam parameter, a TMDLG pointer, in our user data. That is
  1242. // from the stack of the DialogBoxParam() caller, so it is valid until that
  1243. // function returns, which won't be until a bit after the dialog has been
  1244. // destroyed.
  1245. //
  1246. INT_PTR CALLBACK TimedDlgProc(HWND hwnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
  1247. {
  1248. BOOL fHandled = FALSE;
  1249. TMDLG * ptm;
  1250. switch (uMessage)
  1251. {
  1252. case WM_INITDIALOG:
  1253. ptm = (TMDLG *)lParam;
  1254. ASSERT(!IsBadWritePtr(ptm, sizeof(TMDLG)));
  1255. ::SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)ptm);
  1256. //
  1257. // Set the WbMainWindow hwnd
  1258. //
  1259. if (ptm->bLockNotEvent)
  1260. {
  1261. g_pMain->m_hwndWaitForLockDlg = hwnd;
  1262. }
  1263. else
  1264. {
  1265. g_pMain->m_hwndWaitForEventDlg = hwnd;
  1266. }
  1267. //
  1268. // Set max timer
  1269. //
  1270. ::SetTimer(hwnd, TIMERID_MAXDISPLAY, ptm->uiMaxDisplay, NULL);
  1271. //
  1272. // Change the cursor if invisible
  1273. //
  1274. if (!ptm->bVisible)
  1275. ::SetCursor(::LoadCursor(NULL, IDC_WAIT));
  1276. fHandled = TRUE;
  1277. break;
  1278. case WM_TIMER:
  1279. ASSERT(wParam == TIMERID_MAXDISPLAY);
  1280. // End the dialog--since we timed out, it acts like cancel
  1281. ::SendMessage(hwnd, WM_COMMAND, MAKELONG(IDCANCEL, BN_CLICKED), 0);
  1282. fHandled = TRUE;
  1283. break;
  1284. case WM_COMMAND:
  1285. switch (GET_WM_COMMAND_ID(wParam, lParam))
  1286. {
  1287. case IDOK:
  1288. case IDCANCEL:
  1289. if (GET_WM_COMMAND_CMD(wParam, lParam) == BN_CLICKED)
  1290. {
  1291. ptm = (TMDLG *)::GetWindowLongPtr(hwnd, GWLP_USERDATA);
  1292. ASSERT(!IsBadWritePtr(ptm, sizeof(TMDLG)));
  1293. // Clear out the HWND variable
  1294. if (ptm->bLockNotEvent)
  1295. {
  1296. g_pMain->m_hwndWaitForLockDlg = NULL;
  1297. }
  1298. else
  1299. {
  1300. g_pMain->m_hwndWaitForEventDlg = NULL;
  1301. }
  1302. // Restore the cursor
  1303. if (!ptm->bVisible)
  1304. ::SetCursor(::LoadCursor(NULL, IDC_ARROW));
  1305. ::KillTimer(hwnd, TIMERID_MAXDISPLAY);
  1306. ::EndDialog(hwnd, GET_WM_COMMAND_ID(wParam, lParam));
  1307. }
  1308. break;
  1309. }
  1310. fHandled = TRUE;
  1311. break;
  1312. //
  1313. // Don't let these dialogs be killed by any other means than our
  1314. // getting an event or timing out.
  1315. //
  1316. case WM_CLOSE:
  1317. fHandled = TRUE;
  1318. break;
  1319. }
  1320. return(fHandled);
  1321. }
  1322. //
  1323. // FilterMessage()
  1324. //
  1325. // This does tooltip message filtering, then translates accelerators.
  1326. //
  1327. BOOL WbMainWindow::FilterMessage(MSG* pMsg)
  1328. {
  1329. BOOL bResult = FALSE;
  1330. if ((pMsg->message >= WM_KEYFIRST && pMsg->message <= WM_KEYLAST) ||
  1331. (pMsg->message == WM_LBUTTONDOWN || pMsg->message == WM_LBUTTONDBLCLK) ||
  1332. (pMsg->message == WM_RBUTTONDOWN || pMsg->message == WM_RBUTTONDBLCLK) ||
  1333. (pMsg->message == WM_MBUTTONDOWN || pMsg->message == WM_MBUTTONDBLCLK) ||
  1334. (pMsg->message == WM_NCLBUTTONDOWN || pMsg->message == WM_NCLBUTTONDBLCLK) ||
  1335. (pMsg->message == WM_NCRBUTTONDOWN || pMsg->message == WM_NCRBUTTONDBLCLK) ||
  1336. (pMsg->message == WM_NCMBUTTONDOWN || pMsg->message == WM_NCMBUTTONDBLCLK))
  1337. {
  1338. // Cancel any tooltip up
  1339. ::SendMessage(m_hwndToolTip, TTM_ACTIVATE, FALSE, 0);
  1340. }
  1341. // handle tooltip messages (some messages cancel, some may cause it to popup)
  1342. if ((pMsg->message == WM_MOUSEMOVE || pMsg->message == WM_NCMOUSEMOVE ||
  1343. pMsg->message == WM_LBUTTONUP || pMsg->message == WM_RBUTTONUP ||
  1344. pMsg->message == WM_MBUTTONUP) &&
  1345. (GetKeyState(VK_LBUTTON) >= 0 && GetKeyState(VK_RBUTTON) >= 0 &&
  1346. GetKeyState(VK_MBUTTON) >= 0))
  1347. {
  1348. #if 0
  1349. //
  1350. // If this mouse move isn't for a descendant of the main window, skip
  1351. // it. For example, when the tooltip is shown, it gets a mousemove
  1352. // to itself, which if we didn't check for it, would cause us to
  1353. // immediately dismiss this!
  1354. //
  1355. HWND hwndTmp = pMsg->hwnd;
  1356. while (hwndTmp && (::GetWindowLong(hwndTmp, GWL_STYLE) & WS_CHILD))
  1357. {
  1358. hwndTmp = ::GetParent(hwndTmp);
  1359. }
  1360. if (hwndTmp != m_hwnd)
  1361. {
  1362. // This is not for us, it's for another top level window in
  1363. // our app.
  1364. goto DoneToolTipFiltering;
  1365. }
  1366. #endif
  1367. // determine which tool was hit
  1368. POINT pt;
  1369. pt = pMsg->pt;
  1370. ::ScreenToClient(m_hwnd, &pt);
  1371. TOOLINFO tiHit;
  1372. ZeroMemory(&tiHit, sizeof(tiHit));
  1373. tiHit.cbSize = sizeof(TOOLINFO);
  1374. int nHit = OnToolHitTest(pt, &tiHit);
  1375. if (m_nLastHit != nHit)
  1376. {
  1377. if (nHit != -1)
  1378. {
  1379. // add new tool and activate the tip
  1380. if (!::SendMessage(m_hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&tiHit))
  1381. {
  1382. ERROR_OUT(("TTM_ADDTOOL failed"));
  1383. }
  1384. if (::GetActiveWindow() == m_hwnd)
  1385. {
  1386. // allow the tooltip to popup when it should
  1387. ::SendMessage(m_hwndToolTip, TTM_ACTIVATE, TRUE, 0);
  1388. // bring the tooltip window above other popup windows
  1389. ::SetWindowPos(m_hwndToolTip, HWND_TOP, 0, 0, 0, 0,
  1390. SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE);
  1391. }
  1392. }
  1393. // relay mouse event before deleting old tool
  1394. ::SendMessage(m_hwndToolTip, TTM_RELAYEVENT, 0, (LPARAM)pMsg);
  1395. // now safe to delete the old tool
  1396. if (m_tiLastHit.cbSize != 0)
  1397. ::SendMessage(m_hwndToolTip, TTM_DELTOOL, 0, (LPARAM)&m_tiLastHit);
  1398. m_nLastHit = nHit;
  1399. m_tiLastHit = tiHit;
  1400. }
  1401. else
  1402. {
  1403. // relay mouse events through the tooltip
  1404. if (nHit != -1)
  1405. ::SendMessage(m_hwndToolTip, TTM_RELAYEVENT, 0, (LPARAM)pMsg);
  1406. }
  1407. }
  1408. #if 0
  1409. DoneToolTipFiltering:
  1410. #endif
  1411. // Assume we will use the main accelerator table
  1412. HACCEL hAccelTable = m_hAccelTable;
  1413. // If this window has focus, just continue
  1414. HWND hwndFocus = ::GetFocus();
  1415. if (hwndFocus && (hwndFocus != m_hwnd))
  1416. {
  1417. // Check whether an edit field in the pages group has the focus
  1418. if (m_AG.IsChildEditField(hwndFocus))
  1419. {
  1420. hAccelTable = m_hAccelPagesGroup;
  1421. }
  1422. // Check whether text editor has the focus and is active
  1423. else if ( (hwndFocus == m_drawingArea.m_hwnd)
  1424. && (m_drawingArea.TextEditActive()))
  1425. {
  1426. // Let editbox do its own acceleration.
  1427. hAccelTable = NULL;
  1428. }
  1429. }
  1430. return ( (hAccelTable != NULL)
  1431. && ::TranslateAccelerator(m_hwnd, hAccelTable, pMsg));
  1432. }
  1433. //
  1434. //
  1435. // Function: OnDisplayError
  1436. //
  1437. // Purpose: Display an error message
  1438. //
  1439. //
  1440. void WbMainWindow::OnDisplayError(WPARAM uiFEReturnCode, LPARAM uiDCGReturnCode)
  1441. {
  1442. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnDisplayError");
  1443. // Only continue if we are not currently displaying an error
  1444. if (!m_bDisplayingError)
  1445. {
  1446. // Show that we are currently displaying an error message
  1447. m_bDisplayingError = TRUE;
  1448. // Display the error
  1449. ::ErrorMessage((UINT)uiFEReturnCode, (UINT)uiDCGReturnCode);
  1450. // Show that we are no longer displaying an error
  1451. m_bDisplayingError = FALSE;
  1452. }
  1453. }
  1454. //
  1455. //
  1456. // Function: OnTimer
  1457. //
  1458. // Purpose: Process a timer event. These are used to update the progress
  1459. // meter and the sync position.
  1460. //
  1461. //
  1462. void WbMainWindow::OnTimer(UINT_PTR idTimer)
  1463. {
  1464. TRACE_TIMER(("WbMainWindow::OnTimer"));
  1465. //
  1466. // Only do anything if the timer has not been switched off (this may be an
  1467. // old timer message left in the queue when we stopped the timer).
  1468. //
  1469. if (m_bTimerActive)
  1470. {
  1471. //
  1472. // Check for sync position update needed
  1473. //
  1474. // Check whether an update is flagged
  1475. if (m_bSyncUpdateNeeded)
  1476. {
  1477. TRACE_TIMER(("Updating sync position"));
  1478. // Check whether the local user is still synced
  1479. if ((m_uiState == IN_CALL) &&
  1480. (m_pLocalUser != NULL) &&
  1481. (m_pLocalUser->IsSynced()) &&
  1482. (!WB_ContentsLocked()))
  1483. {
  1484. RECT rcVis;
  1485. // Update the local user's position information
  1486. m_drawingArea.GetVisibleRect(&rcVis);
  1487. m_pLocalUser->SetVisibleRect(&rcVis);
  1488. // Write the sync position from the local user's current position
  1489. m_pLocalUser->PutSyncPosition();
  1490. }
  1491. // Show that the update has been done
  1492. m_bSyncUpdateNeeded = FALSE;
  1493. }
  1494. }
  1495. }
  1496. //
  1497. //
  1498. // Function: OnPaletteChanged
  1499. //
  1500. // Purpose: The palette has changed.
  1501. //
  1502. //
  1503. void WbMainWindow::OnPaletteChanged(HWND hwndPalette)
  1504. {
  1505. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnPaletteChanged");
  1506. if ((hwndPalette != m_hwnd) &&
  1507. (hwndPalette != m_drawingArea.m_hwnd))
  1508. {
  1509. // Tell the drawing area to realize its palette
  1510. m_drawingArea.RealizePalette( TRUE );
  1511. }
  1512. }
  1513. //
  1514. //
  1515. // Function: OnQueryNewPalette
  1516. //
  1517. // Purpose: We are getting focus and must realize our palette
  1518. //
  1519. //
  1520. LRESULT WbMainWindow::OnQueryNewPalette(void)
  1521. {
  1522. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnQueryNewPalette");
  1523. // Tell the drawing area to realize its palette
  1524. m_drawingArea.RealizePalette( FALSE );
  1525. return TRUE;
  1526. }
  1527. //
  1528. //
  1529. // Function: WbMainWindowEventHandler
  1530. //
  1531. // Purpose: Event handler for WbMainWindow objects. This is a class
  1532. // wide function. The client data passed to it is a pointer
  1533. // to the instance of WbMainWindow for which the event is
  1534. // intended.
  1535. //
  1536. //
  1537. BOOL CALLBACK WbMainWindowEventHandler
  1538. (
  1539. LPVOID utHandle,
  1540. UINT event,
  1541. UINT_PTR param1,
  1542. UINT_PTR param2
  1543. )
  1544. {
  1545. if (g_pMain->m_hwnd != NULL)
  1546. {
  1547. return(g_pMain->EventHandler(event, param1, param2));
  1548. }
  1549. else
  1550. {
  1551. return(FALSE);
  1552. }
  1553. }
  1554. //
  1555. //
  1556. // Function: EventHandler
  1557. //
  1558. // Purpose: Handler for DC-Groupware events for this object
  1559. //
  1560. //
  1561. BOOL WbMainWindow::EventHandler(UINT Event, UINT_PTR param1, UINT_PTR param2)
  1562. {
  1563. BOOL processed;
  1564. switch (Event)
  1565. {
  1566. case CMS_NEW_CALL:
  1567. case CMS_END_CALL:
  1568. case ALS_LOCAL_LOAD:
  1569. case ALS_REMOTE_LOAD_RESULT:
  1570. case WBP_EVENT_JOIN_CALL_OK:
  1571. case WBP_EVENT_JOIN_CALL_FAILED:
  1572. case WBP_EVENT_NETWORK_LOST:
  1573. case WBP_EVENT_ERROR:
  1574. case WBP_EVENT_PAGE_CLEAR_IND:
  1575. case WBP_EVENT_PAGE_ORDER_UPDATED:
  1576. case WBP_EVENT_PAGE_DELETE_IND:
  1577. case WBP_EVENT_CONTENTS_LOCKED:
  1578. case WBP_EVENT_PAGE_ORDER_LOCKED:
  1579. case WBP_EVENT_UNLOCKED:
  1580. case WBP_EVENT_LOCK_FAILED:
  1581. case WBP_EVENT_GRAPHIC_ADDED:
  1582. case WBP_EVENT_GRAPHIC_MOVED:
  1583. case WBP_EVENT_GRAPHIC_UPDATE_IND:
  1584. case WBP_EVENT_GRAPHIC_REPLACE_IND:
  1585. case WBP_EVENT_GRAPHIC_DELETE_IND:
  1586. case WBP_EVENT_PERSON_JOINED:
  1587. case WBP_EVENT_PERSON_LEFT:
  1588. case WBP_EVENT_PERSON_UPDATE:
  1589. case WBP_EVENT_PERSON_REPLACE:
  1590. case WBP_EVENT_SYNC_POSITION_UPDATED:
  1591. case WBP_EVENT_LOAD_COMPLETE:
  1592. case WBP_EVENT_LOAD_FAILED:
  1593. // Process the Event
  1594. ProcessEvents(Event, param1, param2);
  1595. processed = TRUE;
  1596. break;
  1597. default:
  1598. processed = FALSE;
  1599. break;
  1600. }
  1601. return(processed);
  1602. }
  1603. //
  1604. //
  1605. // Function: PopupContextMenu
  1606. //
  1607. // Purpose: Popup the context menu for the drawing area. This is called
  1608. // by the drawing area window on a right mouse click.
  1609. //
  1610. //
  1611. void WbMainWindow::PopupContextMenu(int x, int y)
  1612. {
  1613. POINT surfacePos;
  1614. RECT clientRect;
  1615. DCWbGraphic * pGraphic;
  1616. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::PopupContextMenu");
  1617. surfacePos.x = x;
  1618. surfacePos.y = y;
  1619. // figure out which popup menu to use (bug 426)
  1620. if (m_pCurrentTool->ToolType() == TOOLTYPE_SELECT)
  1621. {
  1622. m_drawingArea.ClientToSurface(&surfacePos);
  1623. if( (pGraphic = m_drawingArea.GetHitObject( surfacePos )) != NULL )
  1624. {
  1625. // we clicked over an object, see if its already selected
  1626. if( !m_drawingArea.IsSelected( pGraphic ) )
  1627. {
  1628. // object is not already selected, zap current selection and then select it
  1629. m_drawingArea.ClearSelection();
  1630. m_drawingArea.SelectGraphic( pGraphic );
  1631. }
  1632. else
  1633. {
  1634. // plug leak by deleteing pGraphic
  1635. delete pGraphic;
  1636. }
  1637. }
  1638. if( m_drawingArea.GraphicSelected() )
  1639. {
  1640. // selector tool is active, and one or more objects are selected
  1641. m_hInitMenu = m_hGrobjContextMenu;
  1642. }
  1643. else
  1644. {
  1645. // no current selection, show drawing menu
  1646. m_hInitMenu = m_hContextMenu;
  1647. }
  1648. }
  1649. else
  1650. {
  1651. // no objects selected, use drawing menu
  1652. m_hInitMenu = m_hContextMenu;
  1653. }
  1654. // set up current menu state
  1655. SetMenuStates(m_hInitMenu);
  1656. // pop it up
  1657. ::GetClientRect(m_drawingArea.m_hwnd, &clientRect);
  1658. ::MapWindowPoints(m_drawingArea.m_hwnd, NULL, (LPPOINT)&clientRect.left, 2);
  1659. ::TrackPopupMenu(m_hInitMenu, TPM_RIGHTALIGN | TPM_RIGHTBUTTON,
  1660. x + clientRect.left,
  1661. y + clientRect.top,
  1662. 0,
  1663. m_hwnd,
  1664. NULL);
  1665. // reset m_hInitMenu to indicate the popup menu isn't being shown anymore
  1666. m_hInitMenu = NULL;
  1667. }
  1668. //
  1669. //
  1670. // Function: ProcessEvents
  1671. //
  1672. // Purpose: Process events that have been queued internally
  1673. //
  1674. //
  1675. void WbMainWindow::ProcessEvents(UINT Event, UINT_PTR param1, UINT_PTR param2)
  1676. {
  1677. HWND hwndLastPopup;
  1678. TRACE_EVENT(("WbMainWindow::ProcessEvents"));
  1679. //
  1680. // If we are closing, ignore it.
  1681. //
  1682. if (m_uiState == CLOSING)
  1683. {
  1684. TRACE_EVENT(("ProcessEvents: ignored because WB is closing"));
  1685. return;
  1686. }
  1687. //
  1688. // If we are busy drawing, we postpone it until later when we can
  1689. // handle it.
  1690. //
  1691. // If the page sorter dialog is up, it gets notified by the appropriate
  1692. // event handler after the fact.
  1693. //
  1694. if (m_drawingArea.IsBusy())
  1695. {
  1696. TRACE_EVENT(("Reposting event %x, param1 %d param2 %d", Event, param1, param2));
  1697. g_pwbCore->WBP_PostEvent(200, Event, param1, param2);
  1698. return;
  1699. }
  1700. TRACE_EVENT(("Event %x, m_uiState %d", Event, m_uiState));
  1701. //
  1702. // Process according to the event type.
  1703. //
  1704. switch (Event)
  1705. {
  1706. case CMS_NEW_CALL:
  1707. OnCMSNewCall((BOOL)param1, (DWORD)param2);
  1708. break;
  1709. case CMS_END_CALL:
  1710. OnCMSEndCall();
  1711. break;
  1712. case ALS_LOCAL_LOAD:
  1713. switch (m_uiState)
  1714. {
  1715. case IN_CALL:
  1716. case ERROR_STATE:
  1717. // show the main window normal/minimized as necessary
  1718. hwndLastPopup = ::GetLastActivePopup(m_hwnd);
  1719. if (::IsIconic(m_hwnd))
  1720. ::ShowWindow(m_hwnd, SW_RESTORE);
  1721. else
  1722. ::ShowWindow(m_hwnd, SW_SHOW);
  1723. ::SetForegroundWindow(hwndLastPopup);
  1724. if (param2)
  1725. {
  1726. if (m_uiState == IN_CALL)
  1727. LoadCmdLine((LPCSTR)param2);
  1728. ::GlobalFree((HGLOBAL)param2);
  1729. }
  1730. break;
  1731. default:
  1732. TRACE_MSG(("Joining a call so try load later",
  1733. (LPCTSTR)param2));
  1734. g_pwbCore->WBP_PostEvent(400, Event, param1, param2);
  1735. break;
  1736. }
  1737. break;
  1738. case ALS_REMOTE_LOAD_RESULT:
  1739. OnALSLoadResult((UINT)param1);
  1740. break;
  1741. case WBP_EVENT_JOIN_CALL_OK:
  1742. OnWBPJoinCallOK();
  1743. break;
  1744. case WBP_EVENT_JOIN_CALL_FAILED:
  1745. OnWBPJoinCallFailed();
  1746. break;
  1747. case WBP_EVENT_NETWORK_LOST:
  1748. OnWBPNetworkLost();
  1749. break;
  1750. case WBP_EVENT_ERROR:
  1751. OnWBPError();
  1752. break;
  1753. case WBP_EVENT_PAGE_CLEAR_IND:
  1754. OnWBPPageClearInd((WB_PAGE_HANDLE) param1);
  1755. break;
  1756. case WBP_EVENT_PAGE_ORDER_UPDATED:
  1757. OnWBPPageOrderUpdated();
  1758. break;
  1759. case WBP_EVENT_PAGE_DELETE_IND:
  1760. OnWBPPageDeleteInd((WB_PAGE_HANDLE) param1);
  1761. break;
  1762. case WBP_EVENT_CONTENTS_LOCKED:
  1763. OnWBPContentsLocked((POM_OBJECT) param2);
  1764. break;
  1765. case WBP_EVENT_PAGE_ORDER_LOCKED:
  1766. OnWBPPageOrderLocked((POM_OBJECT) param2);
  1767. break;
  1768. case WBP_EVENT_UNLOCKED:
  1769. OnWBPUnlocked((POM_OBJECT) param2);
  1770. break;
  1771. case WBP_EVENT_LOCK_FAILED:
  1772. OnWBPLockFailed();
  1773. break;
  1774. case WBP_EVENT_GRAPHIC_ADDED:
  1775. OnWBPGraphicAdded((WB_PAGE_HANDLE) param1, (WB_GRAPHIC_HANDLE) param2);
  1776. break;
  1777. case WBP_EVENT_GRAPHIC_MOVED:
  1778. OnWBPGraphicMoved((WB_PAGE_HANDLE) param1, (WB_GRAPHIC_HANDLE) param2);
  1779. break;
  1780. case WBP_EVENT_GRAPHIC_UPDATE_IND:
  1781. OnWBPGraphicUpdateInd((WB_PAGE_HANDLE) param1, (WB_GRAPHIC_HANDLE) param2);
  1782. break;
  1783. case WBP_EVENT_GRAPHIC_REPLACE_IND:
  1784. OnWBPGraphicReplaceInd((WB_PAGE_HANDLE) param1, (WB_GRAPHIC_HANDLE) param2);
  1785. break;
  1786. case WBP_EVENT_GRAPHIC_DELETE_IND:
  1787. OnWBPGraphicDeleteInd((WB_PAGE_HANDLE) param1, (WB_GRAPHIC_HANDLE) param2);
  1788. break;
  1789. case WBP_EVENT_PERSON_JOINED:
  1790. OnWBPUserJoined((POM_OBJECT) param2);
  1791. break;
  1792. case WBP_EVENT_PERSON_LEFT:
  1793. OnWBPUserLeftInd((POM_OBJECT) param2);
  1794. break;
  1795. case WBP_EVENT_PERSON_UPDATE:
  1796. OnWBPUserUpdateInd((POM_OBJECT) param2, FALSE);
  1797. break;
  1798. case WBP_EVENT_PERSON_REPLACE:
  1799. OnWBPUserUpdateInd((POM_OBJECT) param2, TRUE);
  1800. break;
  1801. case WBP_EVENT_SYNC_POSITION_UPDATED:
  1802. OnWBPSyncPositionUpdated();
  1803. break;
  1804. case WBP_EVENT_LOAD_COMPLETE:
  1805. OnWBPLoadComplete();
  1806. break;
  1807. case WBP_EVENT_LOAD_FAILED:
  1808. OnWBPLoadFailed();
  1809. break;
  1810. default:
  1811. WARNING_OUT(("Unrecognized event %x", Event));
  1812. break;
  1813. }
  1814. }
  1815. //
  1816. //
  1817. // Function: OnCMSNewCall
  1818. //
  1819. // Purpose: Handler for CMS_NEW_CALL
  1820. //
  1821. //
  1822. void WbMainWindow::OnCMSNewCall(BOOL fTopProvider, DWORD _m_dwDomain)
  1823. {
  1824. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnCMSNewCall");
  1825. //
  1826. // If we created the call
  1827. //
  1828. if (fTopProvider)
  1829. {
  1830. // Join the call, keep existing contents
  1831. if (m_uiState == IN_CALL)
  1832. {
  1833. //
  1834. // Join the call but keep any existing messages.
  1835. //
  1836. ::PostMessage(m_hwnd, WM_USER_JOIN_CALL, 1, (LONG) _m_dwDomain);
  1837. }
  1838. else
  1839. {
  1840. m_bJoinCallPending = TRUE;
  1841. m_dwPendingDomain = _m_dwDomain;
  1842. m_bPendingCallKeepContents = TRUE;
  1843. }
  1844. }
  1845. else
  1846. {
  1847. CM_STATUS status;
  1848. CMS_GetStatus(&status);
  1849. if (!(status.attendeePermissions & NM_PERMIT_USEOLDWBATALL))
  1850. {
  1851. WARNING_OUT(("OLD WB: not joining call, not permitted"));
  1852. return;
  1853. }
  1854. if (m_uiState == IN_CALL)
  1855. {
  1856. //
  1857. // Join the call, throwing away our current contents (after
  1858. // prompting the user to save them first).
  1859. //
  1860. ::PostMessage(m_hwnd, WM_USER_JOIN_CALL, 0, (LONG) _m_dwDomain);
  1861. }
  1862. else
  1863. {
  1864. m_bJoinCallPending = TRUE;
  1865. m_dwPendingDomain = _m_dwDomain;
  1866. m_bPendingCallKeepContents = FALSE;
  1867. }
  1868. }
  1869. //
  1870. // Get the call status correct.
  1871. //
  1872. m_bCallActive = TRUE;
  1873. UpdateWindowTitle();
  1874. }
  1875. //
  1876. //
  1877. // Function: OnJoinPendingCall
  1878. //
  1879. // Purpose: Handler for WM_USER_JOIN_PENDING_CALL
  1880. //
  1881. //
  1882. void WbMainWindow::OnJoinPendingCall(void)
  1883. {
  1884. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnJoinPendingCall");
  1885. //
  1886. // If there's still a pending call (haven't received an end-call message
  1887. // between posting the WM_USER_JOIN_PENDING_CALL and getting here).
  1888. //
  1889. if (m_bJoinCallPending)
  1890. {
  1891. //
  1892. // Post a message to join the call
  1893. //
  1894. ::PostMessage(m_hwnd, WM_USER_JOIN_CALL,
  1895. m_bPendingCallKeepContents,
  1896. (LONG) m_dwPendingDomain);
  1897. // cancel call-pending status
  1898. m_bJoinCallPending = FALSE;
  1899. }
  1900. }
  1901. //
  1902. //
  1903. // Function: OnCMSEndCall
  1904. //
  1905. // Purpose: Handler for CMS_END_CALL
  1906. //
  1907. //
  1908. void WbMainWindow::OnCMSEndCall(void)
  1909. {
  1910. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnCMSEndCall");
  1911. //
  1912. // Flag to cancel any current join-call processing, and destroy any
  1913. // associated dialogs.
  1914. //
  1915. if (m_bPromptingJoinCall)
  1916. {
  1917. m_bPromptingJoinCall = FALSE;
  1918. if (m_hwndQuerySaveDlg != NULL)
  1919. {
  1920. ::SendMessage(m_hwndQuerySaveDlg, WM_COMMAND,
  1921. MAKELONG(IDCANCEL, BN_CLICKED), 0);
  1922. ASSERT(m_hwndQuerySaveDlg == NULL);
  1923. }
  1924. }
  1925. //
  1926. // Show that we are no longer in a call
  1927. //
  1928. m_dwDomain = OM_NO_CALL;
  1929. //
  1930. // If currently in the process of joining a call, then set the domain
  1931. // we're joining to NO_CALL and join the local (singleton) domain.
  1932. // Get the call status correct.
  1933. //
  1934. m_bCallActive = FALSE;
  1935. TRACE_MSG(("m_uiState %d", m_uiState));
  1936. m_dwDomain = OM_NO_CALL;
  1937. //
  1938. // Show there is no call pending
  1939. //
  1940. m_bJoinCallPending = FALSE;
  1941. //
  1942. // Update the window title with "not in call"
  1943. //
  1944. UpdateWindowTitle();
  1945. }
  1946. //
  1947. //
  1948. // Function: OnWBPJoinCallOK
  1949. //
  1950. // Purpose: Handler for WBP_EVENT_JOIN_CALL_OK
  1951. //
  1952. //
  1953. void WbMainWindow::OnWBPJoinCallOK(void)
  1954. {
  1955. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnWBPJoinCallOK");
  1956. //
  1957. // Record that we have joined the call, but the drawing area is not yet
  1958. // ready for input (because we have not yet attached to a page).
  1959. //
  1960. m_uiState = JOINED;
  1961. //
  1962. // Get the local user
  1963. //
  1964. m_pLocalUser = WB_LocalUser();
  1965. if (!m_pLocalUser)
  1966. {
  1967. ERROR_OUT(("Can't join call; can't create local user object, m_pLocalUser!"));
  1968. m_uiState = ERROR_STATE;
  1969. }
  1970. else
  1971. {
  1972. //
  1973. // Get the first user in the call
  1974. //
  1975. WbUser* pUser = WB_GetFirstUser();
  1976. //
  1977. // Loop through all available users
  1978. //
  1979. while (pUser != NULL)
  1980. {
  1981. //
  1982. // Make updates necessary for a user joining
  1983. //
  1984. UserJoined(pUser);
  1985. //
  1986. // Get the next user
  1987. //
  1988. pUser = WB_GetNextUser(pUser);
  1989. }
  1990. //
  1991. // If the registration dialog is up - cancel it
  1992. //
  1993. m_uiState = IN_CALL; // have to set m_uiState before zapping
  1994. // m_hwndWaitForEventDlg or it will
  1995. // think the call failed now (the
  1996. // delay has been removed from
  1997. // EndDialogDelayed() (bug 3881)
  1998. }
  1999. if (m_hwndWaitForEventDlg != NULL)
  2000. {
  2001. TRACE_MSG(("Joined call OK - end dialog"));
  2002. ::SendMessage(m_hwndWaitForEventDlg, WM_COMMAND, MAKELONG(IDOK, BN_CLICKED), 0);
  2003. ASSERT(m_hwndWaitForEventDlg == NULL);
  2004. }
  2005. if (!m_pLocalUser)
  2006. {
  2007. //
  2008. // BAIL out, we can't join the call
  2009. return;
  2010. }
  2011. //
  2012. // Now complete the join call processing
  2013. //
  2014. TRACE_MSG(("Successfully joined the call"));
  2015. m_dwDomain = m_dwJoinDomain;
  2016. //
  2017. // If we have never attached to a page before (ie at start up), attach
  2018. // to the first available page in the drawing area. If we are joining
  2019. // a call then we reattach to the current page
  2020. //
  2021. if (m_hCurrentPage == WB_PAGE_HANDLE_NULL)
  2022. {
  2023. TRACE_MSG(("Attach to first page"));
  2024. g_pwbCore->WBP_PageHandle(WB_PAGE_HANDLE_NULL, PAGE_FIRST, &m_hCurrentPage);
  2025. }
  2026. else
  2027. {
  2028. TRACE_DEBUG(("Just joined new call, reattach to the current page."));
  2029. }
  2030. m_drawingArea.Attach(m_hCurrentPage);
  2031. // Display the initial status
  2032. UpdateStatus();
  2033. ::SetTimer(m_hwnd, TIMERID_PROGRESS_METER, MAIN_PROGRESS_TIMER, NULL);
  2034. m_bTimerActive = TRUE;
  2035. //
  2036. // Unlock the drawing area, allowing user updates (unless its already
  2037. // locked by someone else)
  2038. //
  2039. if (!WB_ContentsLocked())
  2040. {
  2041. UnlockDrawingArea();
  2042. }
  2043. // Set the substate (also updates page buttons)
  2044. SetSubstate(SUBSTATE_IDLE);
  2045. //
  2046. // If we aren't synced, then sync now.
  2047. // Set the window title to show we're no longer registering/joining a
  2048. // call
  2049. //
  2050. Sync();
  2051. UpdateWindowTitle();
  2052. //
  2053. // If we were joining the local domain, and a join call message arrived
  2054. // in the meantime, then join that call now.
  2055. //
  2056. if ((m_bJoinCallPending) && (m_dwJoinDomain == OM_NO_CALL))
  2057. {
  2058. ::PostMessage(m_hwnd, WM_USER_JOIN_PENDING_CALL, 0, 0L);
  2059. }
  2060. }
  2061. //
  2062. //
  2063. // Function: OnWBPJoinCallFailed
  2064. //
  2065. // Purpose: Handler for WBP_EVENT_JOIN_CALL_FAILED
  2066. //
  2067. //
  2068. void WbMainWindow::OnWBPJoinCallFailed(void)
  2069. {
  2070. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnWBPJoinCallFailed");
  2071. //
  2072. // If we have just failed to join a new call (not a single domain) it
  2073. // may be because the call ended before we had time to join it
  2074. // completely - try joining the single domain.
  2075. //
  2076. if ((m_uiState == STARTING) && (m_dwJoinDomain != OM_NO_CALL))
  2077. {
  2078. WARNING_OUT(("Failed to join call on startup, try local domain"));
  2079. m_dwJoinDomain = OM_NO_CALL;
  2080. m_bCallActive = FALSE;
  2081. JoinCall(FALSE);
  2082. }
  2083. else
  2084. {
  2085. //
  2086. // Tell the registration dialog to finish
  2087. //
  2088. if (m_hwndWaitForEventDlg != NULL)
  2089. {
  2090. WARNING_OUT(("Failed to join call - end dialog"));
  2091. ::SendMessage(m_hwndWaitForEventDlg, WM_COMMAND, MAKELONG(IDOK, BN_CLICKED), 0);
  2092. ASSERT(m_hwndWaitForEventDlg == NULL);
  2093. }
  2094. m_uiState = ERROR_STATE;
  2095. }
  2096. }
  2097. //
  2098. //
  2099. // Function: OnWBPNetworkLost
  2100. //
  2101. // Purpose: Handler for WBP_EVENT_NETWORK_LOST
  2102. //
  2103. //
  2104. void WbMainWindow::OnWBPNetworkLost(void)
  2105. {
  2106. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnWBPNetworkLost");
  2107. //
  2108. // We have lost contact with the other people in the call.
  2109. // Treat as if we got an end call (we should get an end call too, but
  2110. // other intervening events might occur (such as trying to join a
  2111. // call).
  2112. //
  2113. OnCMSEndCall();
  2114. }
  2115. //
  2116. //
  2117. // Function: OnWBPError
  2118. //
  2119. // Purpose: Handler for WBP_EVENT_ERROR
  2120. //
  2121. //
  2122. void WbMainWindow::OnWBPError(void)
  2123. {
  2124. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnWBPError");
  2125. // Inform the user of the error.
  2126. ::PostMessage(m_hwnd, WM_USER_DISPLAY_ERROR, WBFE_RC_WB, 0);
  2127. }
  2128. //
  2129. //
  2130. // Function: OnWBPPageClearInd
  2131. //
  2132. // Purpose: Handler for WBP_EVENT_PAGE_CLEAR_IND
  2133. //
  2134. //
  2135. void WbMainWindow::OnWBPPageClearInd(WB_PAGE_HANDLE hPage)
  2136. {
  2137. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnWBPPageClearInd");
  2138. // Confirm the clearing of the page. This is OK even if the page being
  2139. // cleared is the current page because we already know that the drawing
  2140. // area is not busy (otherwise we would not be here).
  2141. // If there's an object on the page which has been copied to the
  2142. // clipboard with delayed rendering, then save it
  2143. if (CLP_LastCopiedPage() == hPage)
  2144. {
  2145. CLP_SaveDelayedGraphic();
  2146. }
  2147. // If it is the current page being cleared
  2148. if (m_hCurrentPage == hPage)
  2149. {
  2150. m_drawingArea.PageCleared();
  2151. }
  2152. // If there is a last deleted graphic
  2153. // and it belongs to the page being cleared.
  2154. if ((m_LastDeletedGraphic.GotTrash()) &&
  2155. (m_LastDeletedGraphic.Page() == hPage))
  2156. {
  2157. // Free the last deleted graphic
  2158. m_LastDeletedGraphic.BurnTrash();
  2159. }
  2160. g_pwbCore->WBP_PageClearConfirm(hPage);
  2161. //
  2162. // Notify the page sorter AFTER the page has been cleared
  2163. //
  2164. if (m_hwndPageSortDlg != NULL)
  2165. {
  2166. ::SendMessage(m_hwndPageSortDlg, WM_PS_PAGECLEARIND, (WPARAM)hPage, 0);
  2167. }
  2168. }
  2169. //
  2170. //
  2171. // Function: OnWBPPageOrderUpdated
  2172. //
  2173. // Purpose: Handler for WBP_EVENT_PAGE_ORDER_UPDATED
  2174. //
  2175. //
  2176. void WbMainWindow::OnWBPPageOrderUpdated(void)
  2177. {
  2178. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnWBPPageOrderUpdated");
  2179. m_drawingArea.CancelDrawingMode();
  2180. // The page order has changed, we just need to update the number of the
  2181. // current page in the pages group.
  2182. UpdateStatus();
  2183. //
  2184. // Notify the page sorter AFTER the page order has been updated
  2185. //
  2186. if (m_hwndPageSortDlg != NULL)
  2187. {
  2188. ::SendMessage(m_hwndPageSortDlg, WM_PS_PAGEORDERUPD, 0, 0);
  2189. }
  2190. }
  2191. //
  2192. //
  2193. // Function: OnWBPPageDeleteInd
  2194. //
  2195. // Purpose: Handler for WBP_EVENT_PAGE_DELETE_IND
  2196. //
  2197. //
  2198. void WbMainWindow::OnWBPPageDeleteInd(WB_PAGE_HANDLE hPage)
  2199. {
  2200. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnWBPPageDeleteInd");
  2201. //
  2202. // Notify the page sorter BEFORE the page is deleted
  2203. //
  2204. if (m_hwndPageSortDlg != NULL)
  2205. {
  2206. ::SendMessage(m_hwndPageSortDlg, WM_PS_PAGEDELIND, (WPARAM)hPage, 0);
  2207. }
  2208. m_drawingArea.CancelDrawingMode();
  2209. // Remove it from the page-position map
  2210. PAGE_POSITION *mapob;
  2211. POSITION savedPos;
  2212. POSITION position = m_pageToPosition.GetHeadPosition();
  2213. BOOL bFound = FALSE;
  2214. while (position && !bFound)
  2215. {
  2216. savedPos = position;
  2217. mapob = (PAGE_POSITION *)m_pageToPosition.GetNext(position);
  2218. if ( mapob->hPage == hPage)
  2219. {
  2220. bFound = TRUE;
  2221. }
  2222. }
  2223. if(bFound)
  2224. {
  2225. m_pageToPosition.RemoveAt(savedPos);
  2226. delete mapob;
  2227. }
  2228. // A page has been deleted. If it is the current page we must attach
  2229. // a different page to the drawing area. In any case we should confirm
  2230. // the delete.
  2231. // If there's an object on the page which has been copied to the
  2232. // clipboard with delayed rendering, then save it
  2233. if (CLP_LastCopiedPage() == hPage)
  2234. {
  2235. CLP_SaveDelayedGraphic();
  2236. }
  2237. if (hPage == m_hCurrentPage)
  2238. {
  2239. // Check whether we are deleting the last page
  2240. WB_PAGE_HANDLE hNewPage;
  2241. g_pwbCore->WBP_PageHandle(WB_PAGE_HANDLE_NULL, PAGE_LAST, &hNewPage);
  2242. if (hNewPage == hPage)
  2243. {
  2244. // We are deleting the last page, so go back one
  2245. hNewPage = PG_GetPreviousPage(hPage);
  2246. }
  2247. else
  2248. {
  2249. // We are not deleting the last page, so go forward one
  2250. hNewPage = PG_GetNextPage(hPage);
  2251. }
  2252. // Check that we got a different page to the one being deleted
  2253. ASSERT(hNewPage != hPage);
  2254. // Lock the drawing area - this ensures we are no longer editing
  2255. // any text etc.
  2256. LockDrawingArea();
  2257. // Move to the new page
  2258. GotoPage(hNewPage);
  2259. // Unlock the drawing area (unless we're doing a new, in which case we
  2260. // leave it locked - it will become unlocked when the new completes)
  2261. if ( (!WB_ContentsLocked())
  2262. && (m_uiState == IN_CALL)
  2263. && (m_uiSubState != SUBSTATE_NEW_IN_PROGRESS))
  2264. {
  2265. UnlockDrawingArea();
  2266. }
  2267. }
  2268. // If there is a last deleted graphic
  2269. if ((m_LastDeletedGraphic.GotTrash()) &&
  2270. (m_LastDeletedGraphic.Page() == hPage))
  2271. {
  2272. // Free the last deleted graphic
  2273. m_LastDeletedGraphic.BurnTrash();
  2274. }
  2275. // if the remote pointer is on the deleted page then turn it off
  2276. ASSERT(m_pLocalUser);
  2277. DCWbGraphicPointer* pPointer = m_pLocalUser->GetPointer();
  2278. if ( (pPointer->IsActive())
  2279. && (pPointer->Page() == hPage))
  2280. {
  2281. OnRemotePointer();
  2282. }
  2283. // Let the core delete the page
  2284. g_pwbCore->WBP_PageDeleteConfirm(hPage);
  2285. // if this is last page to be deleted, then the file/new is complete
  2286. if ((m_uiSubState == SUBSTATE_NEW_IN_PROGRESS)
  2287. && (g_pwbCore->WBP_ContentsCountPages() == 1))
  2288. {
  2289. SetSubstate(SUBSTATE_IDLE);
  2290. ReleasePageOrderLock();
  2291. if (!WB_ContentsLocked())
  2292. {
  2293. UnlockDrawingArea();
  2294. }
  2295. }
  2296. // Update the status (there is a new number of pages)
  2297. UpdateStatus();
  2298. }
  2299. //
  2300. //
  2301. // Function: OnWBPContentsLocked
  2302. //
  2303. // Purpose: Handler for WBP_EVENT_CONTENTS_LOCKED
  2304. //
  2305. //
  2306. void WbMainWindow::OnWBPContentsLocked(POM_OBJECT hUser)
  2307. {
  2308. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnWBPContentsLocked");
  2309. //
  2310. // Notify page sorter dialog that the lock status has changed
  2311. //
  2312. if (m_hwndPageSortDlg != NULL)
  2313. {
  2314. ::SendMessage(m_hwndPageSortDlg, WM_PS_LOCKCHANGE, 0, 0);
  2315. }
  2316. if (m_uiState != IN_CALL)
  2317. {
  2318. TRACE_MSG(("Lock indication received out of call - ignored"));
  2319. }
  2320. else
  2321. {
  2322. ASSERT(m_pLocalUser);
  2323. if (m_pLocalUser->Handle() == hUser)
  2324. {
  2325. // We have acquired the lock
  2326. // Set the locked check mark
  2327. CheckMenuItem(IDM_LOCK);
  2328. // Tell the tool bar of the new selection
  2329. m_TB.PushDown(IDM_LOCK);
  2330. }
  2331. else
  2332. {
  2333. //
  2334. // A remote user has acquired the lock:
  2335. // If we're not synced, then sync now.
  2336. //
  2337. Sync();
  2338. // Tell the drawing area it is now locked
  2339. LockDrawingArea();
  2340. // ensure the page button enable/disable state is correct
  2341. UpdatePageButtons();
  2342. }
  2343. }
  2344. //
  2345. // If the lock dialog is up - cancel it.
  2346. //
  2347. if (m_hwndWaitForLockDlg != NULL)
  2348. {
  2349. ::SendMessage(m_hwndWaitForLockDlg, WM_COMMAND, MAKELONG(IDOK, BN_CLICKED), 0);
  2350. ASSERT(m_hwndWaitForLockDlg == NULL);
  2351. }
  2352. }
  2353. //
  2354. //
  2355. // Function: OnWBPPageOrderLocked
  2356. //
  2357. // Purpose: Handler for WBP_EVENT_PAGE_ORDER_LOCKED
  2358. //
  2359. //
  2360. void WbMainWindow::OnWBPPageOrderLocked(POM_OBJECT)
  2361. {
  2362. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnWBPPageOrderLocked");
  2363. // If the lock dialog is up - cancel it
  2364. if (m_hwndWaitForLockDlg != NULL)
  2365. {
  2366. ::SendMessage(m_hwndWaitForLockDlg, WM_COMMAND, MAKELONG(IDOK, BN_CLICKED), 0);
  2367. ASSERT(m_hwndWaitForLockDlg == NULL);
  2368. }
  2369. // Update the page sorter
  2370. if (m_hwndPageSortDlg != NULL)
  2371. {
  2372. ::SendMessage(m_hwndPageSortDlg, WM_PS_LOCKCHANGE, 0, 0);
  2373. }
  2374. if (!WB_GotLock())
  2375. {
  2376. EnableToolbar( FALSE );
  2377. UpdatePageButtons();
  2378. }
  2379. }
  2380. //
  2381. //
  2382. // Function: OnWBPUnlocked
  2383. //
  2384. // Purpose: Handler for WBP_EVENT_UNLOCKED
  2385. //
  2386. //
  2387. void WbMainWindow::OnWBPUnlocked(POM_OBJECT hUser)
  2388. {
  2389. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnWBPUnlocked");
  2390. // Update the page sorter if it's around
  2391. if (m_hwndPageSortDlg != NULL)
  2392. {
  2393. ::SendMessage(m_hwndPageSortDlg, WM_PS_LOCKCHANGE, 0, 0);
  2394. }
  2395. // Uncheck the lock menu item
  2396. UncheckMenuItem(IDM_LOCK);
  2397. // Tell the tool bar of the change
  2398. m_TB.PopUp(IDM_LOCK);
  2399. // If a remote user is releasing the lock, and we're in a state where
  2400. // it's safe to unlock the drawing area...
  2401. if ((m_pLocalUser != NULL) &&
  2402. (m_pLocalUser->Handle() != hUser) &&
  2403. (m_uiState == IN_CALL))
  2404. {
  2405. // Tell the drawing area it is no longer locked
  2406. UnlockDrawingArea();
  2407. }
  2408. // ensure the page button enable/disable state is correct
  2409. UpdatePageButtons();
  2410. m_bUnlockStateSettled = TRUE; //Allow page operations now
  2411. }
  2412. //
  2413. //
  2414. // Function: OnWBPLockFailed
  2415. //
  2416. // Purpose: Handler for WBP_EVENT_LOCK_FAILED
  2417. //
  2418. //
  2419. void WbMainWindow::OnWBPLockFailed(void)
  2420. {
  2421. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnWBPLockFailed");
  2422. // If the lock dialog is up - kill it
  2423. if (m_hwndWaitForLockDlg != NULL)
  2424. {
  2425. ::SendMessage(m_hwndWaitForLockDlg, WM_COMMAND, MAKELONG(IDOK, BN_CLICKED), 0);
  2426. ASSERT(m_hwndWaitForLockDlg == NULL);
  2427. }
  2428. }
  2429. //
  2430. //
  2431. // Function: OnWBPGraphicAdded
  2432. //
  2433. // Purpose: Handler for WBP_EVENT_GRAPHIC_ADDED
  2434. //
  2435. //
  2436. void WbMainWindow::OnWBPGraphicAdded
  2437. (
  2438. WB_PAGE_HANDLE hPage,
  2439. WB_GRAPHIC_HANDLE hGraphic
  2440. )
  2441. {
  2442. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnWBPGraphicAdded");
  2443. // We only need to take action if the page to which the graphic has
  2444. // been added is the current page.
  2445. if (hPage == m_hCurrentPage && (!(hGraphic->flags & DELETED)))
  2446. {
  2447. // Retrieve the graphic that has been added
  2448. DCWbGraphic* pGraphic = DCWbGraphic::ConstructGraphic(hPage, hGraphic);
  2449. // Tell the drawing area of the new graphic
  2450. m_drawingArea.GraphicAdded(pGraphic);
  2451. // Free the graphic
  2452. delete pGraphic;
  2453. }
  2454. }
  2455. //
  2456. //
  2457. // Function: OnWBPGraphicMoved
  2458. //
  2459. // Purpose: Handler for WBP_EVENT_GRAPHIC_MOVED
  2460. //
  2461. //
  2462. void WbMainWindow::OnWBPGraphicMoved
  2463. (
  2464. WB_PAGE_HANDLE hPage,
  2465. WB_GRAPHIC_HANDLE hGraphic
  2466. )
  2467. {
  2468. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnWBPGraphicMoved");
  2469. // We only need to take action if the graphic belongs to the current page
  2470. if (hPage == m_hCurrentPage && (!(hGraphic->flags & DELETED)))
  2471. {
  2472. // Retrieve the graphic that has been moved
  2473. DCWbGraphic* pGraphic = DCWbGraphic::ConstructGraphic(hPage, hGraphic);
  2474. // Tell the drawing area of the new graphic
  2475. m_drawingArea.GraphicUpdated(pGraphic, TRUE, FALSE);
  2476. // set paint to draw only objects above this object inclusive
  2477. if (pGraphic->IsGraphicTool() == enumGraphicText)
  2478. {
  2479. m_drawingArea.SetStartPaintGraphic( NULL );
  2480. // this optimization screws up text
  2481. // so short it out if this is text
  2482. // (text draws transparently and background
  2483. // isn't repainted properly if this is active)
  2484. }
  2485. else
  2486. {
  2487. m_drawingArea.SetStartPaintGraphic( hGraphic );
  2488. // not text so optimize by drawing only this
  2489. // object and everthing above it
  2490. }
  2491. // Free the graphic
  2492. delete pGraphic;
  2493. }
  2494. }
  2495. //
  2496. //
  2497. // Function: OnWBPGraphicUpdateInd
  2498. //
  2499. // Purpose: Handler for WBP_EVENT_GRAPHIC_UPDATE_IND
  2500. //
  2501. //
  2502. void WbMainWindow::OnWBPGraphicUpdateInd
  2503. (
  2504. WB_PAGE_HANDLE hPage,
  2505. WB_GRAPHIC_HANDLE hGraphic
  2506. )
  2507. {
  2508. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnWBPGraphicUpdateInd");
  2509. if(hGraphic->flags & DELETED)
  2510. {
  2511. return;
  2512. }
  2513. PWB_GRAPHIC pOldHeader;
  2514. PWB_GRAPHIC pOldHeaderCopy;
  2515. DCWbGraphic* pOldGraphic;
  2516. PWB_GRAPHIC pNewHeader;
  2517. DCWbGraphic* pNewGraphic;
  2518. if (hPage != m_hCurrentPage)
  2519. {
  2520. // nothing visual has changed, confirm and we're done
  2521. g_pwbCore->WBP_GraphicUpdateConfirm(hPage, hGraphic);
  2522. return;
  2523. }
  2524. // Retrieve the original graphic and make a copy
  2525. // Get the page of the update
  2526. pOldHeader = PG_GetData(hPage, hGraphic);
  2527. pOldHeaderCopy = (PWB_GRAPHIC) new BYTE[ pOldHeader->length ];
  2528. if( pOldHeaderCopy == NULL )
  2529. {
  2530. ERROR_OUT( ("Can't copy pOldHeader, can't update drawing") );
  2531. g_pwbCore->WBP_GraphicRelease(hPage, hGraphic, pOldHeader );
  2532. g_pwbCore->WBP_GraphicUpdateConfirm(hPage, hGraphic);
  2533. return;
  2534. }
  2535. CopyMemory( (PVOID)pOldHeaderCopy, (CONST VOID *)pOldHeader, pOldHeader->length );
  2536. // confirm and get the new one
  2537. g_pwbCore->WBP_GraphicRelease(hPage, hGraphic, pOldHeader );
  2538. g_pwbCore->WBP_GraphicUpdateConfirm(hPage, hGraphic);
  2539. pNewHeader = PG_GetData(hPage, hGraphic);
  2540. // This update might affect painting. See if old and new are visually different
  2541. if( HasGraphicChanged( pOldHeaderCopy, (const PWB_GRAPHIC)pNewHeader ) )
  2542. {
  2543. // they're different, invalidate/erase old graphic's bounding rect
  2544. pOldGraphic = DCWbGraphic::ConstructGraphic(hPage, hGraphic, pOldHeaderCopy );
  2545. m_drawingArea.GraphicUpdated( pOldGraphic, FALSE, TRUE );
  2546. // draw new graphic (don't need to erase)
  2547. pNewGraphic = DCWbGraphic::ConstructGraphic(hPage, hGraphic, pNewHeader );
  2548. g_pwbCore->WBP_GraphicRelease(hPage, hGraphic, pNewHeader );
  2549. m_drawingArea.GraphicUpdated( pNewGraphic, TRUE, FALSE );
  2550. // If the graphic is selected, ensure the attributes bar is up to date
  2551. if (m_drawingArea.GraphicSelected())
  2552. {
  2553. DCWbGraphic* pSelectedGraphic = m_drawingArea.GetSelection();
  2554. if ((pSelectedGraphic != NULL) &&
  2555. (pSelectedGraphic->Handle() == hGraphic))
  2556. {
  2557. m_pCurrentTool->SelectGraphic(pNewGraphic);
  2558. OnUpdateAttributes();
  2559. }
  2560. }
  2561. delete pOldGraphic;
  2562. delete pNewGraphic;
  2563. }
  2564. else
  2565. {
  2566. g_pwbCore->WBP_GraphicRelease(hPage, hGraphic, pNewHeader);
  2567. }
  2568. delete pOldHeaderCopy;
  2569. }
  2570. //
  2571. //
  2572. // Function: OnWBPGraphicReplaceInd
  2573. //
  2574. // Purpose: Handler for WBP_EVENT_GRAPHIC_REPLACE_IND
  2575. //
  2576. //
  2577. void WbMainWindow::OnWBPGraphicReplaceInd
  2578. (
  2579. WB_PAGE_HANDLE hPage,
  2580. WB_GRAPHIC_HANDLE hGraphic
  2581. )
  2582. {
  2583. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnWBPGraphicReplaceInd");
  2584. if(hGraphic->flags & DELETED)
  2585. {
  2586. return;
  2587. }
  2588. // Retrieve the graphic that has been replaced
  2589. DCWbGraphic* pGraphic = DCWbGraphic::ConstructGraphic(hPage, hGraphic);
  2590. if (pGraphic->IsGraphicTool() == enumGraphicFreeHand)
  2591. {
  2592. // Confirm the replace - the graphic reads its new details
  2593. pGraphic->ReplaceConfirm();
  2594. // Only redraw the graphic if it is on the current page
  2595. if (hPage == m_hCurrentPage)
  2596. {
  2597. // Redraw the graphic
  2598. m_drawingArea.GraphicFreehandUpdated(pGraphic);
  2599. }
  2600. }
  2601. else
  2602. {
  2603. // We make two updates to the drawing area - one with the graphic in its
  2604. // current state and one after the update is confirmed. The first one
  2605. // invalidates the rectangle that the graphic now occupies. The second one
  2606. // invalidates the new rectangle. This ensures that the graphic is
  2607. // correctly redrawn.
  2608. // If the graphic is on the current page...
  2609. if (hPage == m_hCurrentPage)
  2610. {
  2611. // Update the drawing area for the old version of the graphic
  2612. m_drawingArea.GraphicUpdated(pGraphic, FALSE);
  2613. }
  2614. // Confirm the replace - the graphic reads its new details
  2615. pGraphic->ReplaceConfirm();
  2616. // If the graphic is on the current page...
  2617. if (hPage == m_hCurrentPage)
  2618. {
  2619. // Update the drawing area for the new version of the graphic
  2620. m_drawingArea.GraphicUpdated(pGraphic, TRUE);
  2621. }
  2622. }
  2623. // If the graphic is selected, ensure the attributes bar is up to date
  2624. if (m_drawingArea.GraphicSelected())
  2625. {
  2626. DCWbGraphic* pSelectedGraphic = m_drawingArea.GetSelection();
  2627. if ((pSelectedGraphic != NULL) &&
  2628. (pSelectedGraphic->Handle() == hGraphic))
  2629. {
  2630. m_pCurrentTool->SelectGraphic(pGraphic);
  2631. OnUpdateAttributes();
  2632. }
  2633. }
  2634. // Free the graphic
  2635. delete pGraphic;
  2636. }
  2637. //
  2638. //
  2639. // Function: OnWBPGraphicDeleteInd
  2640. //
  2641. // Purpose: Handler for WBP_EVENT_GRAPHIC_DELETE_IND
  2642. //
  2643. //
  2644. void WbMainWindow::OnWBPGraphicDeleteInd
  2645. (
  2646. WB_PAGE_HANDLE hPage,
  2647. WB_GRAPHIC_HANDLE hGraphic
  2648. )
  2649. {
  2650. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnWBPGraphicDeleteInd");
  2651. // if the graphic was copied into the clipboard and was delayed,
  2652. // then save it in case we are asked to render it later
  2653. if ( (CLP_LastCopiedPage() == hPage)
  2654. && (CLP_LastCopiedGraphic() == hGraphic))
  2655. {
  2656. CLP_SaveDelayedGraphic();
  2657. }
  2658. // Retrieve the graphic that is to be deleted
  2659. DCWbGraphic* pGraphic = DCWbGraphic::ConstructGraphic(hPage, hGraphic);
  2660. // If the graphic is on the current page...
  2661. if (hPage == m_hCurrentPage)
  2662. {
  2663. // Update the drawing area
  2664. m_drawingArea.GraphicDeleted(pGraphic);
  2665. }
  2666. // Confirm the delete
  2667. g_pwbCore->WBP_GraphicDeleteConfirm(hPage, hGraphic);
  2668. // Free the graphic
  2669. delete pGraphic;
  2670. }
  2671. //
  2672. //
  2673. // Function: UserJoined
  2674. //
  2675. // Purpose: Make updates necessary for a new user joining the call
  2676. //
  2677. //
  2678. void WbMainWindow::UserJoined(WbUser* pUser)
  2679. {
  2680. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::UserJoined");
  2681. // Get the user's remote pointer
  2682. ASSERT(pUser);
  2683. DCWbGraphicPointer* pPointer = pUser->GetPointer();
  2684. // If the pointer is active and on the current page...
  2685. ASSERT(pPointer);
  2686. if ( (pPointer->IsActive())
  2687. && (pPointer->Page() == m_hCurrentPage))
  2688. {
  2689. // Update the drawing area
  2690. m_drawingArea.PointerUpdated(pPointer);
  2691. }
  2692. }
  2693. //
  2694. //
  2695. // Function: OnWBPUserJoined
  2696. //
  2697. // Purpose: Handler for WBP_EVENT_PERSON_JOINED
  2698. //
  2699. //
  2700. void WbMainWindow::OnWBPUserJoined(POM_OBJECT hUser)
  2701. {
  2702. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnWBPUserJoined");
  2703. // Create a user object from the handle
  2704. WbUser* pUser = WB_GetUser(hUser);
  2705. if (!pUser)
  2706. {
  2707. WARNING_OUT(("Can't handle OnWBPUserJoined; can't create user object for 0x%08x", hUser));
  2708. }
  2709. else
  2710. {
  2711. // Make the necessary updates
  2712. UserJoined(pUser);
  2713. }
  2714. // Update the title bar to reflect the number of users. Do this here,
  2715. // rather than in UserJoined because we go through this function for
  2716. // remote users only, but through UserJoined for the local user too.
  2717. UpdateWindowTitle();
  2718. }
  2719. //
  2720. //
  2721. // Function: OnWBPUserLeftInd
  2722. //
  2723. // Purpose: Handler for WBP_EVENT_PERSON_LEFT
  2724. //
  2725. //
  2726. void WbMainWindow::OnWBPUserLeftInd(POM_OBJECT hUser)
  2727. {
  2728. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnWBPUserLeft");
  2729. // Create a user object from the handle
  2730. WbUser* pUser = WB_GetUser(hUser);
  2731. if (!pUser)
  2732. {
  2733. WARNING_OUT(("Can't handle OnWBPUserLeftInd; can't get user object for 0x%08x", hUser));
  2734. }
  2735. else
  2736. {
  2737. // Get the user's remote pointer
  2738. DCWbGraphicPointer* pPointer = pUser->GetPointer();
  2739. ASSERT(pPointer);
  2740. // If the pointer is on the current page...
  2741. if (pPointer->Page() == m_hCurrentPage)
  2742. {
  2743. // Update the drawing area
  2744. m_drawingArea.PointerRemoved(pPointer);
  2745. }
  2746. }
  2747. // Confirm the update.
  2748. g_pwbCore->WBP_PersonLeftConfirm(hUser);
  2749. //
  2750. // Get this dude out of our list
  2751. //
  2752. if (pUser != NULL)
  2753. {
  2754. ASSERT(g_pUsers);
  2755. POSITION position = g_pUsers->GetHeadPosition();
  2756. WbUser * pRemovedUser;
  2757. while (position)
  2758. {
  2759. POSITION savedPosition = position;
  2760. pRemovedUser = (WbUser*)g_pUsers->GetNext(position);
  2761. if (pRemovedUser == pUser)
  2762. {
  2763. g_pUsers->RemoveAt(savedPosition);
  2764. position = NULL;
  2765. }
  2766. }
  2767. delete pUser;
  2768. }
  2769. // Update the title bar to reflect the number of users
  2770. UpdateWindowTitle();
  2771. }
  2772. //
  2773. //
  2774. // Function: OnWBPUserUpdateInd
  2775. //
  2776. // Purpose: Handler for WBP_EVENT_PERSON_UPDATE
  2777. //
  2778. //
  2779. void WbMainWindow::OnWBPUserUpdateInd(POM_OBJECT hUser, BOOL bReplace)
  2780. {
  2781. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnWBPUserUpdateInd");
  2782. BOOL bActiveOld, bActiveNew;
  2783. WB_PAGE_HANDLE hPointerPageOld, hPointerPageNew;
  2784. POINT pointOld, pointNew;
  2785. WB_PAGE_HANDLE hUserPageOld, hUserPageNew;
  2786. BOOL syncOld, syncNew;
  2787. DCWbGraphicPointer * pPointer = NULL;
  2788. // Get the user object associated with the handle, and the remote pointer
  2789. WbUser* pUser = WB_GetUser(hUser);
  2790. if (!pUser)
  2791. {
  2792. WARNING_OUT(("Can't handle OnWBPUserUpdatedInd; can't get user object for 0x%08x", hUser));
  2793. }
  2794. else
  2795. {
  2796. pPointer = pUser->GetPointer();
  2797. ASSERT(pPointer);
  2798. //
  2799. // Save the interesting bits of the user's state before the change.
  2800. //
  2801. bActiveOld = pPointer->IsActive();
  2802. hPointerPageOld = pPointer->Page();
  2803. pPointer->GetPosition(&pointOld);
  2804. hUserPageOld = pUser->Page();
  2805. syncOld = pUser->IsSynced();
  2806. }
  2807. //
  2808. // Confirm the change
  2809. //
  2810. if (bReplace)
  2811. {
  2812. g_pwbCore->WBP_PersonReplaceConfirm(hUser);
  2813. }
  2814. else
  2815. {
  2816. g_pwbCore->WBP_PersonUpdateConfirm(hUser);
  2817. }
  2818. if (pUser != NULL)
  2819. {
  2820. pUser->Refresh();
  2821. //
  2822. // We do nothing for the local user; since we made the updates locally,
  2823. // we should have already accounted for them.
  2824. //
  2825. if (pUser == m_pLocalUser)
  2826. {
  2827. return;
  2828. }
  2829. //
  2830. // Get the state after the change.
  2831. //
  2832. pPointer = pUser->GetPointer();
  2833. ASSERT(pPointer);
  2834. bActiveNew = pPointer->IsActive();
  2835. hPointerPageNew = pPointer->Page();
  2836. pPointer->GetPosition(&pointNew);
  2837. hUserPageNew = pUser->Page();
  2838. syncNew = pUser->IsSynced();
  2839. // Check whether anything in the pointer has changed
  2840. if ( (bActiveNew != bActiveOld)
  2841. || (hPointerPageNew != hPointerPageOld)
  2842. || (!EqualPoint(pointNew, pointOld)))
  2843. {
  2844. // Check that at least one of the pages is the current page
  2845. if ( (hPointerPageNew == m_hCurrentPage)
  2846. || (hPointerPageOld == m_hCurrentPage))
  2847. {
  2848. m_drawingArea.PointerUpdated(pPointer);
  2849. }
  2850. }
  2851. if (syncOld != syncNew)
  2852. {
  2853. // ensure the page button enable/disable state is correct
  2854. UpdatePageButtons();
  2855. }
  2856. }
  2857. }
  2858. //
  2859. //
  2860. // Function: OnWBPSyncPositionUpdated
  2861. //
  2862. // Purpose: Handler for WBP_EVENT_SYNC_POSITION_UPDATED
  2863. //
  2864. //
  2865. void WbMainWindow::OnWBPSyncPositionUpdated(void)
  2866. {
  2867. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnWBPSyncPositionUpdated");
  2868. //
  2869. // Dont do anythig if we don't have a local user.
  2870. //
  2871. if (m_pLocalUser == NULL)
  2872. {
  2873. ERROR_OUT(("Got a WBP_EVENT_SYNC_POSITION_UPDATED event and pLocaUser is NULL "));
  2874. return;
  2875. }
  2876. // If the local user is synced, change the current page/position
  2877. if (m_pLocalUser->IsSynced())
  2878. {
  2879. GotoSyncPosition();
  2880. }
  2881. }
  2882. //
  2883. //
  2884. // Function: OnSize
  2885. //
  2886. // Purpose: The window has been resized.
  2887. //
  2888. //
  2889. void WbMainWindow::OnSize(UINT nType, int cx, int cy )
  2890. {
  2891. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnSize");
  2892. // Only process this message if the window is not minimized
  2893. if (nType != SIZE_MINIMIZED)
  2894. {
  2895. // Hide the statusbar to avoid drawing problems
  2896. if (m_bStatusBarOn)
  2897. {
  2898. ::ShowWindow(m_hwndSB, SW_HIDE);
  2899. }
  2900. // Resize the subpanes of the window
  2901. ResizePanes();
  2902. // Show it again
  2903. if (m_bStatusBarOn)
  2904. {
  2905. ::ShowWindow(m_hwndSB, SW_SHOW);
  2906. }
  2907. }
  2908. // The user's view has changed
  2909. PositionUpdated();
  2910. // If the status has changed, set the option
  2911. if (m_uiWindowSize != nType)
  2912. {
  2913. m_uiWindowSize = nType;
  2914. // Write the new option values to file
  2915. OPT_SetBooleanOption(OPT_MAIN_MAXIMIZED,
  2916. (m_uiWindowSize == SIZE_MAXIMIZED));
  2917. OPT_SetBooleanOption(OPT_MAIN_MINIMIZED,
  2918. (m_uiWindowSize == SIZE_MINIMIZED));
  2919. }
  2920. // If this is setting the window to a new normal size,
  2921. // save the new position.
  2922. if (nType == SIZE_RESTORED)
  2923. {
  2924. SaveWindowPosition();
  2925. }
  2926. }
  2927. //
  2928. //
  2929. // Function: SaveWindowPosition
  2930. //
  2931. // Purpose: Save the current window position to the options file.
  2932. //
  2933. //
  2934. void WbMainWindow::SaveWindowPosition(void)
  2935. {
  2936. RECT rectWindow;
  2937. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::SaveWindowPosition");
  2938. // Get the new window rectangle
  2939. ::GetWindowRect(m_hwnd, &rectWindow);
  2940. // Write the new option values to file
  2941. OPT_SetWindowRectOption(OPT_MAIN_MAINWINDOWRECT, &rectWindow);
  2942. }
  2943. //
  2944. //
  2945. // Function: OnMove
  2946. //
  2947. // Purpose: The window has been moved.
  2948. //
  2949. //
  2950. void WbMainWindow::OnMove(void)
  2951. {
  2952. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnMove");
  2953. // If we are not maximized
  2954. if (!::IsZoomed(m_hwnd) && !::IsIconic(m_hwnd))
  2955. {
  2956. // Save the new position of the window
  2957. SaveWindowPosition();
  2958. }
  2959. }
  2960. //
  2961. //
  2962. // Function: ResizePanes
  2963. //
  2964. // Purpose: Resize the subpanes of the main window.
  2965. //
  2966. //
  2967. void WbMainWindow::ResizePanes(void)
  2968. {
  2969. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::ResizePanes");
  2970. //
  2971. //
  2972. // The client area is organized as follows:
  2973. //
  2974. // -------------------------------------
  2975. // | | |
  2976. // | T | |
  2977. // | o | Drawing Area |
  2978. // | o | |
  2979. // | l | |
  2980. // | s | |
  2981. // |---| |
  2982. // | W | |
  2983. // | i | |
  2984. // | d | |
  2985. // | t | |
  2986. // | h | |
  2987. // | s | |
  2988. // |-----------------------------------|
  2989. // | Attributes (colors) | Pages |
  2990. // |-----------------------------------|
  2991. // | Status |
  2992. // -------------------------------------
  2993. //
  2994. //
  2995. RECT clientRect;
  2996. RECT rectStatusBar;
  2997. RECT rectToolBar;
  2998. RECT rectWG;
  2999. RECT rectAG;
  3000. RECT rectDraw;
  3001. SIZE size;
  3002. SIZE sizeAG;
  3003. // Get the client rectangle
  3004. ::GetClientRect(m_hwnd, &clientRect);
  3005. rectStatusBar = clientRect;
  3006. // Resize the help bar and progress meter
  3007. if (m_bStatusBarOn)
  3008. {
  3009. rectStatusBar.top = rectStatusBar.bottom - STATUSBAR_HEIGHT;
  3010. ::MoveWindow(m_hwndSB, rectStatusBar.left, rectStatusBar.top,
  3011. rectStatusBar.right - rectStatusBar.left,
  3012. rectStatusBar.bottom - rectStatusBar.top, TRUE);
  3013. }
  3014. else
  3015. {
  3016. // Status bar is off - set it's height to zero
  3017. rectStatusBar.top = rectStatusBar.bottom;
  3018. }
  3019. // Resize the tool and width windows
  3020. m_TB.GetNaturalSize(&size);
  3021. rectToolBar.left = 0;
  3022. rectToolBar.right = rectToolBar.left + size.cx;
  3023. rectToolBar.top = 0;
  3024. rectToolBar.bottom = rectToolBar.top + size.cy;
  3025. m_WG.GetNaturalSize(&size);
  3026. rectWG.left = rectToolBar.left;
  3027. rectWG.top = rectToolBar.bottom;
  3028. rectWG.bottom = rectWG.top + size.cy;
  3029. if (!m_bToolBarOn)
  3030. {
  3031. // Toolbar is either off or floating - set its width to zero
  3032. rectToolBar.right = rectToolBar.left;
  3033. }
  3034. rectWG.right = rectToolBar.right;
  3035. // Position attribute group
  3036. m_AG.GetNaturalSize(&sizeAG);
  3037. ::MoveWindow(m_AG.m_hwnd, rectToolBar.left, rectStatusBar.top - sizeAG.cy,
  3038. clientRect.right - rectToolBar.left, sizeAG.cy, TRUE);
  3039. // finish fiddling with tools and widths bars
  3040. if (m_bToolBarOn)
  3041. {
  3042. //
  3043. // We make the toolbar, which includes the width bar, extend all
  3044. // down the left side.
  3045. //
  3046. rectToolBar.bottom = rectStatusBar.top - sizeAG.cy;
  3047. rectWG.left += TOOLBAR_MARGINX;
  3048. rectWG.right -= 2*TOOLBAR_MARGINX;
  3049. ::MoveWindow(m_TB.m_hwnd, rectToolBar.left,
  3050. rectToolBar.top, rectToolBar.right - rectToolBar.left,
  3051. rectToolBar.bottom - rectToolBar.top, TRUE);
  3052. ::MoveWindow(m_WG.m_hwnd, rectWG.left, rectWG.top,
  3053. rectWG.right - rectWG.left, rectWG.bottom - rectWG.top, TRUE);
  3054. ::BringWindowToTop(m_WG.m_hwnd);
  3055. }
  3056. // Resize the drawing pane
  3057. rectDraw = clientRect;
  3058. rectDraw.bottom = rectStatusBar.top - sizeAG.cy;
  3059. rectDraw.left = rectToolBar.right;
  3060. ::MoveWindow(m_drawingArea.m_hwnd, rectDraw.left, rectDraw.top,
  3061. rectDraw.right - rectDraw.left, rectDraw.bottom - rectDraw.top, TRUE);
  3062. // Check to see if Width group is overlapping Attributes group. This can happen if
  3063. // the menu bar has wrapped because the window isn't wide enough (bug 424)
  3064. RECT crWidthWnd;
  3065. RECT crAttrWnd;
  3066. ::GetWindowRect(m_WG.m_hwnd, &crWidthWnd);
  3067. ::GetWindowRect(m_AG.m_hwnd, &crAttrWnd);
  3068. if (crAttrWnd.top < crWidthWnd.bottom)
  3069. {
  3070. // the menu bar has wrapped and our height placements are wrong. Adjust window
  3071. // by difference and try again
  3072. RECT crMainWnd;
  3073. ::GetWindowRect(m_hwnd, &crMainWnd);
  3074. crMainWnd.bottom += (crWidthWnd.bottom - crAttrWnd.top + ::GetSystemMetrics(SM_CYFIXEDFRAME));
  3075. ::MoveWindow(m_hwnd, crMainWnd.left, crMainWnd.top,
  3076. crMainWnd.right - crMainWnd.left, crMainWnd.bottom - crMainWnd.top,
  3077. FALSE);
  3078. // this is going to recurse but the adjustment will happen only once.....
  3079. }
  3080. }
  3081. //
  3082. //
  3083. // Function: WbMainWindow::OnGetMinMaxInfo
  3084. //
  3085. // Purpose: Set the minimum and maximum tracking sizes of the window
  3086. //
  3087. //
  3088. void WbMainWindow::OnGetMinMaxInfo(LPMINMAXINFO lpmmi)
  3089. {
  3090. if (m_TB.m_hwnd == NULL)
  3091. return; // not ready to do this yet
  3092. SIZE csFrame;
  3093. SIZE csSeparator;
  3094. SIZE csAG;
  3095. SIZE csToolBar;
  3096. SIZE csWidthBar;
  3097. SIZE csStatusBar;
  3098. RECT rectStatusBar;
  3099. SIZE csMaxSize;
  3100. SIZE csScrollBars;
  3101. csFrame.cx = ::GetSystemMetrics(SM_CXSIZEFRAME);
  3102. csFrame.cy = ::GetSystemMetrics(SM_CYSIZEFRAME);
  3103. csSeparator.cx = ::GetSystemMetrics(SM_CXEDGE);
  3104. csSeparator.cy = ::GetSystemMetrics(SM_CYEDGE);
  3105. csScrollBars.cx = ::GetSystemMetrics(SM_CXVSCROLL);
  3106. csScrollBars.cy = ::GetSystemMetrics(SM_CYHSCROLL);
  3107. m_AG.GetNaturalSize(&csAG);
  3108. m_TB.GetNaturalSize(&csToolBar);
  3109. m_WG.GetNaturalSize(&csWidthBar);
  3110. csStatusBar.cx = 0;
  3111. if (m_bStatusBarOn)
  3112. {
  3113. csStatusBar.cy = STATUSBAR_HEIGHT;
  3114. }
  3115. else
  3116. {
  3117. csStatusBar.cy = 0;
  3118. }
  3119. // Set the minimum width and height of the window
  3120. lpmmi->ptMinTrackSize.x =
  3121. csFrame.cx + csAG.cx + csFrame.cx;
  3122. lpmmi->ptMinTrackSize.y =
  3123. csFrame.cy +
  3124. GetSystemMetrics( SM_CYCAPTION ) +
  3125. GetSystemMetrics( SM_CYMENU ) +
  3126. csToolBar.cy +
  3127. csWidthBar.cy +
  3128. csSeparator.cy +
  3129. csAG.cy +
  3130. csSeparator.cy +
  3131. csStatusBar.cy +
  3132. csFrame.cy ;
  3133. //
  3134. // Retrieves the size of the work area on the primary display monitor. The work
  3135. // area is the portion of the screen not obscured by the system taskbar or by
  3136. // application desktop toolbars
  3137. //
  3138. RECT rcWorkArea;
  3139. ::SystemParametersInfo( SPI_GETWORKAREA, 0, (&rcWorkArea), NULL );
  3140. csMaxSize.cx = rcWorkArea.right - rcWorkArea.left;
  3141. csMaxSize.cy = rcWorkArea.bottom - rcWorkArea.top;
  3142. lpmmi->ptMaxPosition.x = 0;
  3143. lpmmi->ptMaxPosition.y = 0;
  3144. lpmmi->ptMaxSize.x = csMaxSize.cx;
  3145. lpmmi->ptMaxSize.y = csMaxSize.cy;
  3146. lpmmi->ptMaxTrackSize.x = csMaxSize.cx;
  3147. lpmmi->ptMaxTrackSize.y = csMaxSize.cy;
  3148. }
  3149. //
  3150. //
  3151. // Function: WbMainWindow::CreateContextMenus
  3152. //
  3153. // Purpose: Create the pop-up context menus: used within the application
  3154. // drawing area.
  3155. //
  3156. //
  3157. BOOL WbMainWindow::CreateContextMenus(void)
  3158. {
  3159. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::CreateContextMenus");
  3160. m_hContextMenuBar = ::LoadMenu(g_hInstance, MAKEINTRESOURCE(CONTEXTMENU));
  3161. if (!m_hContextMenuBar)
  3162. {
  3163. ERROR_OUT(("Failed to create context menu"));
  3164. DefaultExceptionHandler(WBFE_RC_WINDOWS, 0);
  3165. return FALSE;
  3166. }
  3167. m_hContextMenu = ::GetSubMenu(m_hContextMenuBar, 0);
  3168. m_hGrobjContextMenuBar = ::LoadMenu(g_hInstance, MAKEINTRESOURCE(GROBJMENU));
  3169. if (!m_hGrobjContextMenuBar)
  3170. {
  3171. ERROR_OUT(("Failed to create grobj context menu"));
  3172. DefaultExceptionHandler(WBFE_RC_WINDOWS, 0);
  3173. return FALSE;
  3174. }
  3175. m_hGrobjContextMenu = ::GetSubMenu(m_hGrobjContextMenuBar, 0);
  3176. // make parts of m_hGrobjContextMenu be owner draw
  3177. ::ModifyMenu(m_hGrobjContextMenu, IDM_WIDTH_1, MF_ENABLED | MF_OWNERDRAW,
  3178. IDM_WIDTH_1, NULL);
  3179. ::ModifyMenu(m_hGrobjContextMenu, IDM_WIDTH_2, MF_ENABLED | MF_OWNERDRAW,
  3180. IDM_WIDTH_2, NULL);
  3181. ::ModifyMenu(m_hGrobjContextMenu, IDM_WIDTH_3, MF_ENABLED | MF_OWNERDRAW,
  3182. IDM_WIDTH_3, NULL);
  3183. ::ModifyMenu(m_hGrobjContextMenu, IDM_WIDTH_4, MF_ENABLED | MF_OWNERDRAW,
  3184. IDM_WIDTH_4, NULL);
  3185. return TRUE;
  3186. }
  3187. //
  3188. //
  3189. // Function: WbMainWindow::InitializeMenus
  3190. //
  3191. // Purpose: Initialise the menus: set up owner-drawn menu items and
  3192. // those read from options file.
  3193. //
  3194. //
  3195. void WbMainWindow::InitializeMenus(void)
  3196. {
  3197. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::InitializeMenus");
  3198. // Make the width menu ownerdraw
  3199. HMENU hMenu = GetMenuWithItem(::GetMenu(m_hwnd), IDM_WIDTH_1);
  3200. if (hMenu != NULL)
  3201. {
  3202. // Change each entry to be ownerdraw (loop until failure)
  3203. int iIndex;
  3204. UINT uiId;
  3205. int iCount = ::GetMenuItemCount(hMenu);
  3206. for (iIndex = 0; iIndex < iCount; iIndex++)
  3207. {
  3208. uiId = ::GetMenuItemID(hMenu, iIndex);
  3209. ::ModifyMenu(hMenu, iIndex,
  3210. MF_BYPOSITION
  3211. | MF_ENABLED
  3212. | MF_OWNERDRAW,
  3213. uiId,
  3214. NULL);
  3215. }
  3216. }
  3217. }
  3218. //
  3219. //
  3220. // Function: WbMainWindow::OnMeasureItem
  3221. //
  3222. // Purpose: Return the size of an item in the widths menu
  3223. //
  3224. //
  3225. void WbMainWindow::OnMeasureItem
  3226. (
  3227. int nIDCtl,
  3228. LPMEASUREITEMSTRUCT measureStruct
  3229. )
  3230. {
  3231. // Check that this is for a color menu item
  3232. if ( (measureStruct->itemID >= IDM_WIDTHS_START)
  3233. && (measureStruct->itemID < IDM_WIDTHS_END))
  3234. {
  3235. measureStruct->itemWidth = ::GetSystemMetrics(SM_CXMENUCHECK) +
  3236. (2 * CHECKMARK_BORDER_X) + COLOR_MENU_WIDTH;
  3237. measureStruct->itemHeight = ::GetSystemMetrics(SM_CYMENUCHECK) +
  3238. (2 * CHECKMARK_BORDER_Y);
  3239. }
  3240. }
  3241. //
  3242. //
  3243. // Function: WbMainWindow::OnDrawItem
  3244. //
  3245. // Purpose: Draw an item in the color menu
  3246. //
  3247. //
  3248. void WbMainWindow::OnDrawItem
  3249. (
  3250. int nIDCtl,
  3251. LPDRAWITEMSTRUCT drawStruct
  3252. )
  3253. {
  3254. COLORREF crMenuBackground;
  3255. COLORREF crMenuText;
  3256. HPEN hOldPen;
  3257. HBRUSH hOldBrush;
  3258. COLORREF crOldBkgnd;
  3259. COLORREF crOldText;
  3260. int nOldBkMode;
  3261. HBITMAP hbmp = NULL;
  3262. BITMAP bitmap;
  3263. UINT uiCheckWidth;
  3264. UINT uiCheckHeight;
  3265. RECT rect;
  3266. RECT rectCheck;
  3267. RECT rectLine;
  3268. HDC hMemDC;
  3269. UINT uiWidthIndex;
  3270. UINT uiWidth;
  3271. HPEN hPenMenu;
  3272. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnDrawItem");
  3273. // Check that this is a width menu item
  3274. if( (drawStruct->itemID < IDM_WIDTHS_START) ||
  3275. (drawStruct->itemID >= IDM_WIDTHS_END) )
  3276. {
  3277. return;
  3278. }
  3279. // get menu item colors
  3280. if( (drawStruct->itemState & ODS_SELECTED) ||
  3281. ((drawStruct->itemState & (ODS_SELECTED |ODS_CHECKED)) ==
  3282. (ODS_SELECTED |ODS_CHECKED))
  3283. )
  3284. {
  3285. crMenuBackground = COLOR_HIGHLIGHT;
  3286. crMenuText = COLOR_HIGHLIGHTTEXT;
  3287. }
  3288. else if( drawStruct->itemState & ODS_GRAYED)
  3289. {
  3290. crMenuBackground = COLOR_MENU;
  3291. crMenuText = COLOR_GRAYTEXT;
  3292. }
  3293. else
  3294. {
  3295. crMenuBackground = COLOR_MENU;
  3296. crMenuText = COLOR_MENUTEXT;
  3297. }
  3298. hPenMenu = ::CreatePen(PS_SOLID, 0, ::GetSysColor(crMenuBackground));
  3299. if (!hPenMenu)
  3300. {
  3301. TRACE_MSG(("Failed to create penMenu"));
  3302. ::PostMessage(m_hwnd, WM_USER_DISPLAY_ERROR, WBFE_RC_WINDOWS, 0);
  3303. goto bail_out;
  3304. }
  3305. rect = drawStruct->rcItem;
  3306. // Fill the whole box with current menu background color
  3307. hOldPen = SelectPen(drawStruct->hDC, hPenMenu);
  3308. hOldBrush = SelectBrush(drawStruct->hDC, GetSysColorBrush(crMenuBackground));
  3309. ::Rectangle(drawStruct->hDC, rect.left, rect.top, rect.right, rect.bottom);
  3310. SelectBrush(drawStruct->hDC, hOldBrush);
  3311. SelectPen(drawStruct->hDC, hOldPen);
  3312. if( (hbmp = (HBITMAP)LoadImage( NULL, MAKEINTRESOURCE( OBM_CHECK ), IMAGE_BITMAP,
  3313. 0,0, 0 ))
  3314. == NULL )
  3315. {
  3316. TRACE_MSG(("Failed to create check image"));
  3317. ::PostMessage(m_hwnd, WM_USER_DISPLAY_ERROR, WBFE_RC_WINDOWS, 0);
  3318. goto bail_out;
  3319. }
  3320. // Get the width and height of the bitmap (allowing some border)
  3321. ::GetObject(hbmp, sizeof(BITMAP), &bitmap);
  3322. uiCheckWidth = bitmap.bmWidth + (2 * CHECKMARK_BORDER_X);
  3323. uiCheckHeight = bitmap.bmHeight;
  3324. // Draw in a checkmark (if needed)
  3325. if (drawStruct->itemState & ODS_CHECKED)
  3326. {
  3327. hMemDC = ::CreateCompatibleDC(drawStruct->hDC);
  3328. if (!hMemDC)
  3329. {
  3330. ERROR_OUT(("Failed to create memDC"));
  3331. ::PostMessage(m_hwnd, WM_USER_DISPLAY_ERROR, WBFE_RC_WINDOWS, 0);
  3332. goto bail_out;
  3333. }
  3334. crOldBkgnd = ::SetBkColor(drawStruct->hDC, GetSysColor( crMenuBackground ) );
  3335. crOldText = ::SetTextColor(drawStruct->hDC, GetSysColor( crMenuText ) );
  3336. nOldBkMode = ::SetBkMode(drawStruct->hDC, OPAQUE );
  3337. HBITMAP hOld = SelectBitmap(hMemDC, hbmp);
  3338. if (hOld != NULL)
  3339. {
  3340. rectCheck = rect;
  3341. rectCheck.top += ((rectCheck.bottom - rectCheck.top)/2 - uiCheckHeight/2);
  3342. rectCheck.right = rectCheck.left + uiCheckWidth;
  3343. rectCheck.bottom = rectCheck.top + uiCheckHeight;
  3344. ::BitBlt(drawStruct->hDC, rectCheck.left,
  3345. rectCheck.top,
  3346. rectCheck.right - rectCheck.left,
  3347. rectCheck.bottom - rectCheck.top,
  3348. hMemDC,
  3349. 0,
  3350. 0,
  3351. SRCCOPY);
  3352. SelectBitmap(hMemDC, hOld);
  3353. }
  3354. ::SetBkMode(drawStruct->hDC, nOldBkMode);
  3355. ::SetTextColor(drawStruct->hDC, crOldText);
  3356. ::SetBkColor(drawStruct->hDC, crOldBkgnd);
  3357. ::DeleteDC(hMemDC);
  3358. }
  3359. DeleteBitmap(hbmp);
  3360. // Allow room for the checkmark to the left of the color
  3361. rect.left += uiCheckWidth;
  3362. uiWidthIndex = drawStruct->itemID - IDM_WIDTHS_START;
  3363. uiWidth = g_PenWidths[uiWidthIndex];
  3364. // If pens are very wide they can be larger than the allowed rectangle.
  3365. // So we reduce the clipping rectangle here. We save the DC so that we
  3366. // can restore it - getting the clip region back.
  3367. if (::SaveDC(drawStruct->hDC) == 0)
  3368. {
  3369. ERROR_OUT(("Failed to save DC"));
  3370. ::PostMessage(m_hwnd, WM_USER_DISPLAY_ERROR, WBFE_RC_WINDOWS, 0);
  3371. goto bail_out;
  3372. }
  3373. if (::IntersectClipRect(drawStruct->hDC, rect.left, rect.top,
  3374. rect.right, rect.bottom) == ERROR)
  3375. {
  3376. ERROR_OUT(("Failed to set clip rect"));
  3377. ::RestoreDC(drawStruct->hDC, -1);
  3378. ::PostMessage(m_hwnd, WM_USER_DISPLAY_ERROR, WBFE_RC_WINDOWS, 0);
  3379. goto bail_out;
  3380. }
  3381. hOldPen = SelectPen(drawStruct->hDC, hPenMenu);
  3382. hOldBrush = SelectBrush(drawStruct->hDC, GetSysColorBrush(crMenuText));
  3383. rectLine.left = rect.left;
  3384. rectLine.top = rect.top + ((rect.bottom - rect.top) / 2) - uiWidth/2;
  3385. rectLine.right= rect.right - ((rect.right - rect.left) / 6);
  3386. rectLine.bottom = rectLine.top + uiWidth + 2;
  3387. ::Rectangle(drawStruct->hDC, rectLine.left, rectLine.top,
  3388. rectLine.right, rectLine.bottom);
  3389. SelectBrush(drawStruct->hDC, hOldBrush);
  3390. SelectPen(drawStruct->hDC, hOldPen);
  3391. ::RestoreDC(drawStruct->hDC, -1);
  3392. bail_out:
  3393. if (hPenMenu != NULL)
  3394. {
  3395. ::DeletePen(hPenMenu);
  3396. }
  3397. }
  3398. //
  3399. //
  3400. // Function: OnSetFocus
  3401. //
  3402. // Purpose: The window is getting the focus
  3403. //
  3404. //
  3405. void WbMainWindow::OnSetFocus(void)
  3406. {
  3407. // We pass the focus on to the main drawing area
  3408. ::SetFocus(m_drawingArea.m_hwnd);
  3409. }
  3410. //
  3411. //
  3412. // Function: UpdateStatus
  3413. //
  3414. // Purpose: Set the text in the status bar
  3415. //
  3416. //
  3417. void WbMainWindow::UpdateStatus()
  3418. {
  3419. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::UpdateStatus");
  3420. //
  3421. // Update the current and last page numbers
  3422. //
  3423. m_AG.SetCurrentPageNumber(g_pwbCore->WBP_PageNumberFromHandle(m_hCurrentPage));
  3424. m_AG.SetLastPageNumber(g_pwbCore->WBP_ContentsCountPages());
  3425. //
  3426. // Update the user information with the page.
  3427. //
  3428. if (m_pLocalUser != NULL)
  3429. {
  3430. m_pLocalUser->SetPage(m_hCurrentPage);
  3431. }
  3432. }
  3433. //
  3434. //
  3435. // Function: SetMenuState
  3436. //
  3437. // Purpose: Sets menu contents to their correct enabled/disabled state
  3438. //
  3439. //
  3440. void WbMainWindow::SetMenuStates(HMENU hInitMenu)
  3441. {
  3442. BOOL bLocked;
  3443. BOOL bPageOrderLocked;
  3444. BOOL bPresentationMode;
  3445. UINT uiEnable;
  3446. UINT uiCountPages;
  3447. BOOL bIdle;
  3448. BOOL bSelected;
  3449. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::SetMenuStates");
  3450. //
  3451. // Check menu exists
  3452. //
  3453. if (hInitMenu == NULL)
  3454. {
  3455. WARNING_OUT(("Menu doesn't exist"));
  3456. return;
  3457. }
  3458. HMENU hMainMenu = ::GetMenu(m_hwnd);
  3459. // Get the window's main menu and check that the menu
  3460. // now being popped up is one on the top-level. (We do not
  3461. // seem to be able to associate the index number passed with
  3462. // sub-menus easily.)
  3463. if ((hInitMenu != m_hContextMenu) && (hInitMenu != m_hGrobjContextMenu))
  3464. {
  3465. BOOL bTopLevel = FALSE;
  3466. int nCount = ::GetMenuItemCount(hMainMenu);
  3467. for (int nNext = 0; nNext < nCount; nNext++)
  3468. {
  3469. HMENU hNextMenu = ::GetSubMenu(hMainMenu, nNext);
  3470. if (hNextMenu != NULL)
  3471. {
  3472. if (hNextMenu == hInitMenu)
  3473. {
  3474. bTopLevel = TRUE;
  3475. break;
  3476. }
  3477. }
  3478. }
  3479. // not a top level, so leave the function now
  3480. if (!bTopLevel)
  3481. {
  3482. TRACE_DEBUG(("Not top-level menu"));
  3483. return;
  3484. }
  3485. }
  3486. // Get the lock and selection states:
  3487. // If we are joining a call, we cannot assume that the contents
  3488. // and user/client details have been created yet, so just set the
  3489. // locked state to true.
  3490. bIdle = IsIdle();
  3491. bSelected = m_drawingArea.GraphicSelected();
  3492. TRACE_DEBUG(("m_uiState %d", m_uiState));
  3493. if ((m_uiState == STARTING) || (m_uiState == JOINING))
  3494. {
  3495. TRACE_DEBUG(("Not initilalised yet"));
  3496. bLocked = TRUE;
  3497. bPageOrderLocked = TRUE;
  3498. bPresentationMode = TRUE;
  3499. uiCountPages = 1;
  3500. }
  3501. else
  3502. {
  3503. //
  3504. // Note that bLocked and bPageOrderLocked are always true when
  3505. // we're not in idle state.
  3506. //
  3507. uiCountPages = g_pwbCore->WBP_ContentsCountPages();
  3508. bLocked = (WB_Locked() || !bIdle);
  3509. bPageOrderLocked = (WB_Locked() || !bIdle);
  3510. bPresentationMode = (((m_uiState == IN_CALL) &&
  3511. (WB_PresentationMode()))
  3512. || (!bIdle));
  3513. }
  3514. //
  3515. // Functions which are disabled when contents is locked
  3516. //
  3517. uiEnable = MF_BYCOMMAND | (bLocked ? MF_GRAYED : MF_ENABLED);
  3518. ::EnableMenuItem(hInitMenu, IDM_OPEN, uiEnable);
  3519. ::EnableMenuItem(hInitMenu, IDM_SAVE, uiEnable);
  3520. ::EnableMenuItem(hInitMenu, IDM_SAVE_AS, uiEnable);
  3521. ::EnableMenuItem(hInitMenu, IDM_PRINT, uiEnable);
  3522. ::EnableMenuItem(hInitMenu, IDM_GRAB_AREA, uiEnable);
  3523. ::EnableMenuItem(hInitMenu, IDM_GRAB_WINDOW, uiEnable);
  3524. ::EnableMenuItem(hInitMenu, IDM_SELECTALL, uiEnable);
  3525. ::EnableMenuItem(hInitMenu, IDM_SELECT, uiEnable);
  3526. ::EnableMenuItem(hInitMenu, IDM_PEN, uiEnable);
  3527. ::EnableMenuItem(hInitMenu, IDM_HIGHLIGHT, uiEnable);
  3528. // Don't allow editing in zoom mode
  3529. if( m_drawingArea.Zoomed() )
  3530. ::EnableMenuItem(hInitMenu, IDM_TEXT, MF_GRAYED);
  3531. else
  3532. ::EnableMenuItem(hInitMenu, IDM_TEXT, uiEnable);
  3533. ::EnableMenuItem(hInitMenu, IDM_CLEAR_PAGE, uiEnable);
  3534. ::EnableMenuItem(hInitMenu, IDM_ERASER, uiEnable);
  3535. ::EnableMenuItem(hInitMenu, IDM_LINE, uiEnable);
  3536. ::EnableMenuItem(hInitMenu, IDM_BOX, uiEnable);
  3537. ::EnableMenuItem(hInitMenu, IDM_FILLED_BOX, uiEnable);
  3538. ::EnableMenuItem(hInitMenu, IDM_ELLIPSE, uiEnable);
  3539. ::EnableMenuItem(hInitMenu, IDM_FILLED_ELLIPSE, uiEnable);
  3540. ::EnableMenuItem(hInitMenu, IDM_ZOOM, uiEnable);
  3541. // So toolbar will follow menu (MFC-auto-update is broken for this)
  3542. EnableToolbar( !bLocked );
  3543. //
  3544. // File/New is disabled if page order is locked, or not in a call,
  3545. // or a new is already in progress.
  3546. //
  3547. ::EnableMenuItem(hInitMenu, IDM_NEW, MF_BYCOMMAND |
  3548. (bPageOrderLocked ? MF_GRAYED : MF_ENABLED));
  3549. //
  3550. // Paste enabled only if not locked, and there's something in the
  3551. // clipboard
  3552. //
  3553. uiEnable = MF_BYCOMMAND | MF_ENABLED;
  3554. if ( (CLP_AcceptableClipboardFormat() == NULL)
  3555. || (bLocked))
  3556. {
  3557. // No acceptable format available, or the contents
  3558. // are locked by another user - gray the Paste command.
  3559. uiEnable = MF_BYCOMMAND | MF_GRAYED;
  3560. }
  3561. ::EnableMenuItem(hInitMenu, IDM_PASTE, uiEnable);
  3562. //
  3563. // Functions which require a graphic to be selected
  3564. //
  3565. uiEnable = MF_BYCOMMAND | MF_ENABLED;
  3566. if( !m_drawingArea.TextEditActive() )
  3567. {
  3568. if (!bSelected || bLocked)
  3569. {
  3570. // No acceptable format available - gray the menu item
  3571. uiEnable = MF_BYCOMMAND | MF_GRAYED;
  3572. }
  3573. }
  3574. ::EnableMenuItem(hInitMenu, IDM_CUT, uiEnable);
  3575. // don't do textedit delete for now
  3576. if( m_drawingArea.TextEditActive() )
  3577. ::EnableMenuItem(hInitMenu, IDM_DELETE, MF_BYCOMMAND | MF_GRAYED);
  3578. else
  3579. ::EnableMenuItem(hInitMenu, IDM_DELETE, uiEnable);
  3580. ::EnableMenuItem(hInitMenu, IDM_BRING_TO_TOP, uiEnable);
  3581. ::EnableMenuItem(hInitMenu, IDM_SEND_TO_BACK, uiEnable);
  3582. //
  3583. // Can copy even if contents are locked
  3584. //
  3585. //COMMENT BY RAND - To fix 556 I changed !bIdle to bIdle like the current
  3586. // 16bit code does.
  3587. ::EnableMenuItem(hInitMenu, IDM_COPY, MF_BYCOMMAND |
  3588. (m_drawingArea.TextEditActive()||(bSelected && bIdle)
  3589. ? MF_ENABLED : MF_GRAYED)); //CHANGED BY RAND for 556
  3590. //
  3591. // Object to undelete?
  3592. //
  3593. ::EnableMenuItem(hInitMenu, IDM_UNDELETE, MF_BYCOMMAND |
  3594. ((m_LastDeletedGraphic.GotTrash() &&
  3595. (m_LastDeletedGraphic.Page() == m_hCurrentPage) &&
  3596. (!bLocked)) ? MF_ENABLED : MF_GRAYED));
  3597. //
  3598. // Page functions depend on number of pages
  3599. //
  3600. ::EnableMenuItem(hInitMenu, IDM_DELETE_PAGE, MF_BYCOMMAND |
  3601. ((bPageOrderLocked ||
  3602. (uiCountPages == 1)||
  3603. (!m_bUnlockStateSettled))
  3604. ? MF_GRAYED : MF_ENABLED));
  3605. uiEnable = MF_BYCOMMAND | MF_ENABLED;
  3606. if ((bPageOrderLocked) ||
  3607. (uiCountPages == WB_MAX_PAGES)||
  3608. (!m_bUnlockStateSettled))
  3609. {
  3610. uiEnable = MF_BYCOMMAND | MF_GRAYED;
  3611. }
  3612. ::EnableMenuItem(hInitMenu, IDM_PAGE_INSERT_BEFORE, uiEnable);
  3613. ::EnableMenuItem(hInitMenu, IDM_PAGE_INSERT_AFTER, uiEnable);
  3614. //
  3615. // Can't bring up page sorter if locked
  3616. //
  3617. ::EnableMenuItem(hInitMenu, IDM_PAGE_SORTER, MF_BYCOMMAND |
  3618. (bPresentationMode ? MF_GRAYED : MF_ENABLED));
  3619. // Enable page controls
  3620. m_AG.EnablePageCtrls(!bPresentationMode);
  3621. //
  3622. // Lock enabled only if not already locked
  3623. //
  3624. ::EnableMenuItem(hInitMenu, IDM_LOCK, MF_BYCOMMAND |
  3625. (bPageOrderLocked ? MF_GRAYED : MF_ENABLED));
  3626. //
  3627. // Enable sync if not in "presentation" mode
  3628. //
  3629. ::EnableMenuItem(hInitMenu, IDM_SYNC, MF_BYCOMMAND |
  3630. (((!bPresentationMode) && bIdle) ? MF_ENABLED : MF_GRAYED));
  3631. //
  3632. // Gray font/color/widths if inappropriate for current tool.
  3633. //
  3634. ::EnableMenuItem(hInitMenu, IDM_FONT, MF_BYCOMMAND |
  3635. (!bLocked && m_pCurrentTool->HasFont() ? MF_ENABLED : MF_GRAYED));
  3636. ::EnableMenuItem(hInitMenu, IDM_EDITCOLOR, MF_BYCOMMAND |
  3637. (!bLocked && m_pCurrentTool->HasColor() ? MF_ENABLED : MF_GRAYED));
  3638. // enable width menu (bug 433)
  3639. HMENU hOptionsMenu = ::GetSubMenu(hMainMenu, MENUPOS_OPTIONS);
  3640. uiEnable = (!bLocked && m_pCurrentTool->HasWidth())?MF_ENABLED:MF_GRAYED;
  3641. if (hOptionsMenu == hInitMenu )
  3642. ::EnableMenuItem(hOptionsMenu, OPTIONSPOS_WIDTH, MF_BYPOSITION | uiEnable );
  3643. UINT i;
  3644. UINT uIdmCurWidth = 0;
  3645. if( uiEnable == MF_ENABLED )
  3646. uIdmCurWidth = m_pCurrentTool->GetWidthIndex() + IDM_WIDTH_1;
  3647. // set width state(bug 426)
  3648. for( i=IDM_WIDTH_1; i<=IDM_WIDTH_4; i++ )
  3649. {
  3650. ::EnableMenuItem(hInitMenu, i, uiEnable );
  3651. if( uiEnable == MF_ENABLED )
  3652. {
  3653. if( uIdmCurWidth == i )
  3654. ::CheckMenuItem(hInitMenu, i, MF_CHECKED );
  3655. else
  3656. ::CheckMenuItem(hInitMenu, i, MF_UNCHECKED );
  3657. }
  3658. }
  3659. }
  3660. //
  3661. //
  3662. // Function: OnInitMenuPopup
  3663. //
  3664. // Purpose: Process a WM_INITMENUPOPUP event
  3665. //
  3666. //
  3667. void WbMainWindow::OnInitMenuPopup
  3668. (
  3669. HMENU hMenu,
  3670. UINT uiIndex,
  3671. BOOL bSystemMenu
  3672. )
  3673. {
  3674. // 1/2 of fix for strange MFC4.2 build bug that clogs up DCL's message pipe.
  3675. // The other 1/2 and a better comment are in LoadFile().
  3676. if( m_bIsWin95 )
  3677. {
  3678. if( GetSubState() == SUBSTATE_LOADING )
  3679. {
  3680. ::SetFocus(m_drawingArea.m_hwnd);
  3681. return;
  3682. }
  3683. }
  3684. // Ignore the event if it relates to the system menu
  3685. if (!bSystemMenu)
  3686. {
  3687. if (hMenu)
  3688. {
  3689. SetMenuStates(hMenu);
  3690. m_hInitMenu = hMenu;
  3691. }
  3692. else
  3693. {
  3694. m_hInitMenu = NULL;
  3695. }
  3696. // Save the last menu we handled, so that we can alter its state
  3697. // if necessary whilst it is still visible
  3698. }
  3699. }
  3700. //
  3701. //
  3702. // Function : OnMenuSelect
  3703. //
  3704. // Purpose : Update the text in the help bar
  3705. //
  3706. //
  3707. void WbMainWindow::OnMenuSelect(UINT uiItemID, UINT uiFlags, HMENU hSysMenu)
  3708. {
  3709. UINT firstMenuId;
  3710. UINT statusId;
  3711. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnMenuSelect");
  3712. //
  3713. // Work out the help ID for the menu item. We have to store this now
  3714. // because when the user presses F1 from a menu item, we can't tell
  3715. // which item it was.
  3716. //
  3717. if (uiFlags == (UINT)-1)
  3718. {
  3719. //
  3720. // The menu has been dismissed
  3721. //
  3722. m_hInitMenu = NULL;
  3723. statusId = IDS_DEFAULT;
  3724. if( hSysMenu == 0 )
  3725. {
  3726. // Menu was dismissed, check cursor loc.
  3727. DCWbGraphic *pGraphic;
  3728. POINT surfacePos;
  3729. ::GetCursorPos( &surfacePos );
  3730. ::ScreenToClient(m_drawingArea.m_hwnd, &surfacePos);
  3731. m_drawingArea.ClientToSurface(&surfacePos );
  3732. if( (pGraphic = m_drawingArea.GetHitObject( surfacePos )) == NULL )
  3733. {
  3734. // we clicked dead air, don't lose current selection (bug 426)
  3735. m_drawingArea.SetLClickIgnore( TRUE );
  3736. }
  3737. else
  3738. delete pGraphic; // plug leak
  3739. }
  3740. }
  3741. else if ((uiFlags & MF_POPUP) && (uiFlags & MF_SYSMENU))
  3742. {
  3743. //
  3744. // System menu selected
  3745. //
  3746. statusId = IDS_MENU_SYSTEM;
  3747. }
  3748. else if (uiFlags & MF_POPUP)
  3749. {
  3750. // get popup menu handle and first item (bug NM4db:463)
  3751. HMENU hPopup = ::GetSubMenu( hSysMenu, uiItemID );
  3752. firstMenuId = ::GetMenuItemID( hPopup, 0 );
  3753. // figure out which popup it is so we can display the right help text
  3754. switch (firstMenuId)
  3755. {
  3756. case IDM_NEW:
  3757. statusId = IDS_MENU_FILE;
  3758. break;
  3759. case IDM_DELETE:
  3760. statusId = IDS_MENU_EDIT;
  3761. break;
  3762. case IDM_TOOL_BAR_TOGGLE:
  3763. statusId = IDS_MENU_VIEW;
  3764. break;
  3765. case IDM_EDITCOLOR:
  3766. // The first item in the options menu is the color popup
  3767. // menu - popup menus have Id -1
  3768. statusId = IDS_MENU_OPTIONS;
  3769. break;
  3770. case IDM_TOOLS_START:
  3771. statusId = IDS_MENU_TOOLS;
  3772. break;
  3773. case IDM_HELP:
  3774. statusId = IDS_MENU_HELP;
  3775. break;
  3776. case IDM_WIDTH_1: // (added for bug NM4db:463)
  3777. statusId = IDS_MENU_WIDTH;
  3778. break;
  3779. default:
  3780. statusId = IDS_DEFAULT;
  3781. break;
  3782. }
  3783. }
  3784. else
  3785. {
  3786. //
  3787. // A normal menu item has been selected
  3788. //
  3789. statusId = uiItemID;
  3790. }
  3791. // Set the new help text
  3792. TCHAR szStatus[256];
  3793. if (::LoadString(g_hInstance, statusId, szStatus, 256))
  3794. {
  3795. ::SetWindowText(m_hwndSB, szStatus);
  3796. }
  3797. }
  3798. //
  3799. //
  3800. // Function: OnParentNotfiy
  3801. //
  3802. // Purpose: Process a message coming from a child window
  3803. //
  3804. //
  3805. void WbMainWindow::OnParentNotify(UINT uiMessage)
  3806. {
  3807. switch (uiMessage)
  3808. {
  3809. // Scroll message from the drawing area. These are sent when the user
  3810. // scrolls the area using the scroll bars. We queue an update of the
  3811. // current sync position.
  3812. case WM_HSCROLL:
  3813. case WM_VSCROLL:
  3814. // The user's view has changed
  3815. PositionUpdated();
  3816. break;
  3817. }
  3818. }
  3819. //
  3820. //
  3821. // Function: QuerySaveRequired
  3822. //
  3823. // Purpose: Check whether the drawing pane contents are to be saved
  3824. // before a destructive function is performed.
  3825. //
  3826. //
  3827. int WbMainWindow::QuerySaveRequired(BOOL bCancelBtn)
  3828. {
  3829. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::QuerySaveRequired");
  3830. // Default the response to "no save required"
  3831. int iResult = IDNO;
  3832. //
  3833. // If we are already displaying a "Save As" dialog, dismiss it.
  3834. //
  3835. if (m_hwndQuerySaveDlg != NULL)
  3836. {
  3837. ::SendMessage(m_hwndQuerySaveDlg, WM_COMMAND,
  3838. MAKELONG(IDCANCEL, BN_CLICKED), 0);
  3839. ASSERT(m_hwndQuerySaveDlg == NULL);
  3840. }
  3841. // If any of the pages has changed - ask the user if they want to
  3842. // save the contents of the Whiteboard.
  3843. if (g_pwbCore->WBP_ContentsChanged())
  3844. {
  3845. ::SetForegroundWindow(m_hwnd); //bring us to the top first
  3846. // SetForegroundWindow() does not work properly in Memphis when its called during a
  3847. // SendMessage handler, specifically, when conf calls me to shutdown. The window activation
  3848. // state is messed up or something and my window does not pop to the top. So I have to
  3849. // force my window to the top using SetWindowPos. But even after that the titlebar is not
  3850. // highlighted properly. I tried combinations of SetActiveWindow, SetFocus, etc but to no
  3851. // avail. But, at least the dialog is visible so you can clear it thus fixing the
  3852. // bug (NM4db:2103). SetForegroundWindow() works ok for Win95 and NT here without
  3853. // having to use SetWindowPos (it doesn't hurt anyting to do it anyway so I didn't
  3854. // do a platform check).
  3855. ::SetWindowPos(m_hwnd, HWND_TOPMOST, 0,0, 0,0, SWP_NOMOVE | SWP_NOSIZE ); // force to top
  3856. ::SetWindowPos(m_hwnd, HWND_NOTOPMOST, 0,0, 0,0, SWP_NOMOVE | SWP_NOSIZE ); // let go of topmost
  3857. //
  3858. // Display a dialog box with the relevant question
  3859. // LOWORD of user data is "cancel command is allowed"
  3860. // HIWORD of user data is "disable cancel button"
  3861. //
  3862. iResult = (int)DialogBoxParam(g_hInstance,
  3863. bCancelBtn ? MAKEINTRESOURCE(QUERYSAVEDIALOGCANCEL)
  3864. : MAKEINTRESOURCE(QUERYSAVEDIALOG),
  3865. m_hwnd,
  3866. QuerySaveDlgProc,
  3867. MAKELONG(bCancelBtn, FALSE));
  3868. }
  3869. return iResult;
  3870. }
  3871. //
  3872. // QuerySaveDlgProc()
  3873. // Handler for query save dialogs. We save some flags in GWL_USER
  3874. //
  3875. INT_PTR CALLBACK QuerySaveDlgProc(HWND hwnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
  3876. {
  3877. BOOL fHandled = FALSE;
  3878. switch (uMessage)
  3879. {
  3880. case WM_INITDIALOG:
  3881. //
  3882. // Save away our HWND so this dialog can be cancelled if necessary
  3883. //
  3884. g_pMain->m_hwndQuerySaveDlg = hwnd;
  3885. // Remember the flags we passed
  3886. ::SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
  3887. // Should the cancel button be disabled?
  3888. if (HIWORD(lParam))
  3889. ::EnableWindow(::GetDlgItem(hwnd, IDCANCEL), FALSE);
  3890. // Bring us to the front
  3891. ::SetForegroundWindow(hwnd);
  3892. fHandled = TRUE;
  3893. break;
  3894. case WM_CLOSE:
  3895. // Even if the cancel button is disabled, kill the dialog
  3896. ::PostMessage(hwnd, WM_COMMAND, IDCANCEL, 0);
  3897. fHandled = TRUE;
  3898. break;
  3899. case WM_COMMAND:
  3900. switch (GET_WM_COMMAND_ID(wParam, lParam))
  3901. {
  3902. case IDCANCEL:
  3903. //
  3904. // If a dialog doesn't have a cancel button or it's
  3905. // disabled and the user pressed the close btn, we can
  3906. // get here.
  3907. //
  3908. if (!LOWORD(::GetWindowLongPtr(hwnd, GWLP_USERDATA)))
  3909. wParam = MAKELONG(IDNO, HIWORD(wParam));
  3910. // FALL THRU
  3911. case IDYES:
  3912. case IDNO:
  3913. if (GET_WM_COMMAND_CMD(wParam, lParam) == BN_CLICKED)
  3914. {
  3915. g_pMain->m_hwndQuerySaveDlg = NULL;
  3916. ::EndDialog(hwnd, GET_WM_COMMAND_ID(wParam, lParam));
  3917. break;
  3918. }
  3919. break;
  3920. }
  3921. fHandled = TRUE;
  3922. break;
  3923. }
  3924. return(fHandled);
  3925. }
  3926. //
  3927. //
  3928. // Function: OnNew
  3929. //
  3930. // Purpose: Clear the workspace and associated filenames
  3931. //
  3932. //
  3933. void WbMainWindow::OnNew(void)
  3934. {
  3935. int iDoNew;
  3936. if( UsersMightLoseData( NULL, NULL ) ) // bug NM4db:418
  3937. return;
  3938. // check state before proceeding - if we're already doing a new, then abort
  3939. if ( (m_uiState != IN_CALL)
  3940. || (m_uiSubState == SUBSTATE_NEW_IN_PROGRESS))
  3941. {
  3942. // post an error message indicating the whiteboard is busy
  3943. ::PostMessage(m_hwnd, WM_USER_DISPLAY_ERROR, WBFE_RC_WB, WB_RC_BUSY);
  3944. goto OnNewCleanup;
  3945. }
  3946. // if we're currently loading, then cancel the load and proceed (don't
  3947. // prompt to save).
  3948. else if (m_uiSubState == SUBSTATE_LOADING)
  3949. {
  3950. // cancel load, not releasing the page order lock, because
  3951. // we need it immediately afterwards
  3952. CancelLoad(FALSE);
  3953. iDoNew = IDNO;
  3954. }
  3955. // otherwise prompt to save if necessary
  3956. else
  3957. {
  3958. // Get confirmation for the new
  3959. iDoNew = QuerySaveRequired(TRUE);
  3960. }
  3961. if (iDoNew == IDYES)
  3962. {
  3963. // Save the changes
  3964. iDoNew = OnSave(FALSE);
  3965. }
  3966. // If the user did not cancel the operation, clear the drawing area
  3967. if (iDoNew != IDCANCEL)
  3968. {
  3969. // Go to the first page, as this won't be deleted - stops flashing
  3970. // with locking contents for each page delete
  3971. OnFirstPage();
  3972. GotoPosition(0, 0);
  3973. // lock the drawing area
  3974. LockDrawingArea();
  3975. // Save the current lock status
  3976. SaveLock();
  3977. // Get the Page Order Lock (with an invisible dialog)
  3978. BOOL bGotLock = GetLock(WB_LOCK_TYPE_PAGE_ORDER, SW_HIDE);
  3979. if (!bGotLock)
  3980. {
  3981. RestoreLock();
  3982. }
  3983. else
  3984. {
  3985. UINT uiReturn;
  3986. // Remove all the pages
  3987. uiReturn = g_pwbCore->WBP_ContentsDelete();
  3988. if (uiReturn != 0)
  3989. {
  3990. DefaultExceptionHandler(WBFE_RC_WB, uiReturn);
  3991. return;
  3992. }
  3993. // if there is only one page, the new is implemented just as a page-
  3994. // clear, so we don't need to go into NEW_IN_PROGRESS substate.
  3995. if (g_pwbCore->WBP_ContentsCountPages() > 1)
  3996. {
  3997. // set substate to show we're doing a new
  3998. SetSubstate(SUBSTATE_NEW_IN_PROGRESS);
  3999. }
  4000. else
  4001. {
  4002. // Restore the lock status
  4003. RestoreLock();
  4004. }
  4005. // Clear the associated file name
  4006. ZeroMemory(m_strFileName, sizeof(m_strFileName));
  4007. // Update the window title with no file name
  4008. UpdateWindowTitle();
  4009. }
  4010. }
  4011. OnNewCleanup:
  4012. // unlock the drawing area if the new is not asynchronous
  4013. if ( (m_uiSubState != SUBSTATE_NEW_IN_PROGRESS)
  4014. && (!WB_ContentsLocked()))
  4015. {
  4016. UnlockDrawingArea();
  4017. }
  4018. return;
  4019. }
  4020. //
  4021. //
  4022. // Function: OnNextPage
  4023. //
  4024. // Purpose: Move to the next worksheet in the pages list
  4025. //
  4026. //
  4027. void WbMainWindow::OnNextPage(void)
  4028. {
  4029. // ignore this command if in presentation mode
  4030. if ( (m_uiState == IN_CALL)
  4031. && (!WB_PresentationMode()))
  4032. {
  4033. // Go to the next page
  4034. GotoPage(PG_GetNextPage(m_hCurrentPage));
  4035. }
  4036. }
  4037. //
  4038. //
  4039. // Function: OnPrevPage
  4040. //
  4041. // Purpose: Move to the previous worksheet in the pages list
  4042. //
  4043. //
  4044. void WbMainWindow::OnPrevPage(void)
  4045. {
  4046. // ignore this command if in presentation mode
  4047. if ( (m_uiState == IN_CALL)
  4048. && (!WB_PresentationMode()))
  4049. {
  4050. // Go to the previous page
  4051. GotoPage(PG_GetPreviousPage(m_hCurrentPage));
  4052. }
  4053. }
  4054. //
  4055. //
  4056. // Function: OnFirstPage
  4057. //
  4058. // Purpose: Move to the first worksheet in the pages list
  4059. //
  4060. //
  4061. void WbMainWindow::OnFirstPage(void)
  4062. {
  4063. // ignore this command if in presentation mode
  4064. if ( (m_uiState == IN_CALL)
  4065. && (!WB_PresentationMode()))
  4066. {
  4067. // Go to the first page
  4068. WB_PAGE_HANDLE hPage;
  4069. g_pwbCore->WBP_PageHandle(WB_PAGE_HANDLE_NULL, PAGE_FIRST, &hPage);
  4070. GotoPage(hPage);
  4071. }
  4072. }
  4073. //
  4074. //
  4075. // Function: OnLastPage
  4076. //
  4077. // Purpose: Move to the last worksheet in the pages list
  4078. //
  4079. //
  4080. void WbMainWindow::OnLastPage(void)
  4081. {
  4082. // ignore this command if in presentation mode
  4083. if ( (m_uiState == IN_CALL)
  4084. && (!WB_PresentationMode()))
  4085. {
  4086. // Go to the last page
  4087. WB_PAGE_HANDLE hPage;
  4088. g_pwbCore->WBP_PageHandle(WB_PAGE_HANDLE_NULL, PAGE_LAST, &hPage);
  4089. GotoPage(hPage);
  4090. }
  4091. }
  4092. //
  4093. //
  4094. // Function: OnGotoPage
  4095. //
  4096. // Purpose: Move to the specified page (if it exists)
  4097. //
  4098. //
  4099. void WbMainWindow::OnGotoPage(void)
  4100. {
  4101. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnGotoPage");
  4102. // ignore this command if in presentation mode
  4103. if ( (m_uiState == IN_CALL)
  4104. && (!WB_PresentationMode()))
  4105. {
  4106. // Get the requested page number from the pages group
  4107. UINT uiPageNumber = m_AG.GetCurrentPageNumber();
  4108. // Goto the page
  4109. GotoPageNumber(uiPageNumber);
  4110. }
  4111. }
  4112. //
  4113. //
  4114. // Function: GotoPage
  4115. //
  4116. // Purpose: Move to the specified page
  4117. //
  4118. //
  4119. void WbMainWindow::GotoPage(WB_PAGE_HANDLE hPageNew)
  4120. {
  4121. BOOL inEditField;
  4122. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::GotoPage");
  4123. inEditField = m_AG.IsChildEditField(::GetFocus());
  4124. // If we are changing page
  4125. if (hPageNew != m_hCurrentPage)
  4126. {
  4127. m_drawingArea.CancelDrawingMode();
  4128. // Attach the new page to the drawing area
  4129. m_hCurrentPage = hPageNew;
  4130. m_drawingArea.Attach(m_hCurrentPage);
  4131. // Update the local user information with the new page
  4132. if (m_pLocalUser != NULL)
  4133. m_pLocalUser->SetPage(m_hCurrentPage);
  4134. // Show that we need to update the sync position
  4135. m_bSyncUpdateNeeded = TRUE;
  4136. PAGE_POSITION *mapob;
  4137. POSITION position = m_pageToPosition.GetHeadPosition();
  4138. BOOL bFound = FALSE;
  4139. while (position && !bFound)
  4140. {
  4141. mapob = (PAGE_POSITION *)m_pageToPosition.GetNext(position);
  4142. if ( mapob->hPage == hPageNew)
  4143. {
  4144. bFound = TRUE;
  4145. }
  4146. }
  4147. if (!bFound)
  4148. {
  4149. // page not in map, so go to the top-left
  4150. //CHANGED BY RAND - to fix memory leak
  4151. GotoPosition( 0, 0);
  4152. }
  4153. else
  4154. GotoPosition(mapob->position.x, mapob->position.y);
  4155. }
  4156. // Update the status display
  4157. UpdateStatus();
  4158. // set the focus back to the drawing area
  4159. if (!inEditField)
  4160. {
  4161. ::SetFocus(m_drawingArea.m_hwnd);
  4162. }
  4163. }
  4164. //
  4165. //
  4166. // Function: GotoPageNumber
  4167. //
  4168. // Purpose: Move to the specified page
  4169. //
  4170. //
  4171. void WbMainWindow::GotoPageNumber(UINT uiPageNumber)
  4172. {
  4173. GotoPage(PG_GetPageNumber(uiPageNumber));
  4174. }
  4175. //
  4176. //
  4177. // Function: GotoPosition
  4178. //
  4179. // Purpose: Move to the specified position within the page
  4180. //
  4181. //
  4182. void WbMainWindow::GotoPosition(int x, int y)
  4183. {
  4184. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::GotoPosition");
  4185. // Move the drawing area to the new position
  4186. m_drawingArea.GotoPosition(x, y);
  4187. // The user's view has changed
  4188. PositionUpdated();
  4189. }
  4190. //
  4191. //
  4192. // Function: GotoSyncPosition
  4193. //
  4194. // Purpose: Move to the the current sync position
  4195. //
  4196. //
  4197. void WbMainWindow::GotoSyncPosition(void)
  4198. {
  4199. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::GotoSyncPosition");
  4200. //
  4201. // Get the local user to determine the new position.
  4202. //
  4203. if (!m_pLocalUser)
  4204. {
  4205. ERROR_OUT(("Skipping GotoSyncPosition; no local user object"));
  4206. return;
  4207. }
  4208. m_pLocalUser->GetSyncPosition();
  4209. //
  4210. // If the page is different to where we are currently, get the number
  4211. // of the page and select the current page
  4212. //
  4213. if (m_pLocalUser->Page() != m_hCurrentPage)
  4214. {
  4215. GotoPageNumber(g_pwbCore->WBP_PageNumberFromHandle(m_pLocalUser->Page()));
  4216. }
  4217. // Get the requested position from the user
  4218. RECT rectVisibleUser;
  4219. m_pLocalUser->GetVisibleRect(&rectVisibleUser);
  4220. // Scroll to the required position
  4221. GotoPosition(rectVisibleUser.left, rectVisibleUser.top);
  4222. // Make sure we are zoomed / not zoomed as appropriate
  4223. if ((m_pLocalUser->GetZoom()) != m_drawingArea.Zoomed())
  4224. {
  4225. OnZoom();
  4226. }
  4227. //
  4228. // Reset the sync position update flag that will have been turned on by
  4229. // the calls above. We do not want to change the current sync position
  4230. // when we are merely changing our position to match that set by
  4231. // another user in the call.
  4232. //
  4233. m_bSyncUpdateNeeded = FALSE;
  4234. // Inform the other users that we have changed position
  4235. m_pLocalUser->Update();
  4236. }
  4237. //
  4238. //
  4239. // Function: OnGotoUserPosition
  4240. //
  4241. // Purpose: Move to the the current position of the specified user
  4242. //
  4243. //
  4244. void WbMainWindow::OnGotoUserPosition(LPARAM lParam)
  4245. {
  4246. UINT uiPageNumber = 1;
  4247. WB_PAGE_HANDLE hPage;
  4248. WbUser * pUser;
  4249. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnGotoUserPosition");
  4250. //
  4251. // If the drawing area is busy, ignore this command. This is unlikely
  4252. // since this command is generated by selecting a menu entry on a user
  4253. // icon. The user should not therefore be drawing on the page by the
  4254. // time we get the message.
  4255. //
  4256. if (m_drawingArea.IsBusy())
  4257. {
  4258. TRACE_DEBUG(("drawing area is busy just now.."));
  4259. return;
  4260. }
  4261. //
  4262. // Get a user object (throws an exception if the handle specified is no
  4263. // longer valid).
  4264. //
  4265. pUser = WB_GetUser((POM_OBJECT) lParam);
  4266. if (!pUser)
  4267. {
  4268. WARNING_OUT(("Can't handle OnGotoUserPosition; can't get user object for 0x%08x", lParam));
  4269. return;
  4270. }
  4271. //
  4272. // Get the requested page from the user.
  4273. //
  4274. hPage = pUser->Page();
  4275. //
  4276. // Quit if the requested page is not valid locally.
  4277. //
  4278. if (hPage == WB_PAGE_HANDLE_NULL)
  4279. {
  4280. TRACE_DEBUG(("Page is not valid locally"));
  4281. return;
  4282. }
  4283. //
  4284. // Don't go to user's position if it's on another page and we're in
  4285. // presentation mode (this shouldn't normally happen, since we should
  4286. // all be on the same page, but there is a window at the start-up of
  4287. // presentation mode.
  4288. //
  4289. if ( (hPage == m_hCurrentPage) ||
  4290. (!WB_PresentationMode()) )
  4291. {
  4292. //
  4293. // If the page is different to where we are currently, get the
  4294. // number of the page and select the current page.
  4295. //
  4296. if (hPage != m_hCurrentPage)
  4297. {
  4298. uiPageNumber = g_pwbCore->WBP_PageNumberFromHandle(hPage);
  4299. GotoPageNumber(uiPageNumber);
  4300. }
  4301. //
  4302. // Get the requested position from the user and scroll to it.
  4303. //
  4304. RECT rectVisibleUser;
  4305. pUser->GetVisibleRect(&rectVisibleUser);
  4306. GotoPosition(rectVisibleUser.left, rectVisibleUser.top);
  4307. //
  4308. // Zoom/unzoom if the sync zoom state is different to our current
  4309. // zoom state.
  4310. //
  4311. if ( (m_pLocalUser->GetZoom()) != (m_drawingArea.Zoomed()) )
  4312. {
  4313. TRACE_DEBUG(("Change zoom state"));
  4314. OnZoom();
  4315. }
  4316. }
  4317. }
  4318. //
  4319. //
  4320. // Function: OnGotoUserPointer
  4321. //
  4322. // Purpose: Move to the pointer position of the specified user
  4323. //
  4324. //
  4325. void WbMainWindow::OnGotoUserPointer(LPARAM lParam)
  4326. {
  4327. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnGotoUserPointer");
  4328. // If the drawing area is busy, ignore this command.
  4329. // This is unlikely since this command is generated by selecting
  4330. // a menu entry on a user icon. The user should not therefore be
  4331. // drawing on the page by the time we get the message.
  4332. if (!m_drawingArea.IsBusy())
  4333. {
  4334. // Get a user object (throws an exception if the
  4335. // handle specified is no longer valid).
  4336. WbUser* pUser = WB_GetUser((POM_OBJECT) lParam);
  4337. if (!pUser)
  4338. {
  4339. WARNING_OUT(("Can't handle OnGotoUserPointer; can't get user object for 0x%08x", lParam));
  4340. return;
  4341. }
  4342. DCWbGraphicPointer* pPointer = pUser->GetPointer();
  4343. ASSERT(pPointer != NULL);
  4344. // Continue only if the user is using the pointer
  4345. if (pPointer->IsActive())
  4346. {
  4347. // Get the requested page from the user
  4348. WB_PAGE_HANDLE hPage = pPointer->Page();
  4349. // Check that the requested page is valid locally
  4350. if (hPage != WB_PAGE_HANDLE_NULL)
  4351. {
  4352. // If the pointer is on a different page, change to the
  4353. // correct page.
  4354. if (hPage != m_hCurrentPage)
  4355. {
  4356. GotoPageNumber(g_pwbCore->WBP_PageNumberFromHandle(hPage));
  4357. }
  4358. // Move within the page if the pointer is not wholly visible
  4359. // in the drawing area window.
  4360. RECT rectPointer;
  4361. RECT rcVis;
  4362. RECT rcT;
  4363. pPointer->GetBoundsRect(&rectPointer);
  4364. m_drawingArea.GetVisibleRect(&rcVis);
  4365. ::IntersectRect(&rcT, &rcVis, &rectPointer);
  4366. if (!::EqualRect(&rcT, &rectPointer))
  4367. {
  4368. // Adjust the position so that the pointer is shown
  4369. // in the centre of the window.
  4370. POINT position;
  4371. SIZE size;
  4372. position.x = rectPointer.left;
  4373. position.y = rectPointer.top;
  4374. size.cx = (rcVis.right - rcVis.left) - (rectPointer.right - rectPointer.left);
  4375. size.cy = (rcVis.bottom - rcVis.top) - (rectPointer.bottom - rectPointer.top);
  4376. position.x += -size.cx / 2;
  4377. position.y += -size.cy / 2;
  4378. // Scroll to the required position
  4379. GotoPosition(position.x, position.y);
  4380. }
  4381. }
  4382. }
  4383. }
  4384. }
  4385. //
  4386. //
  4387. // Function: LoadFile
  4388. //
  4389. // Purpose: Load a metafile into the application. Errors are reported
  4390. // to the caller by the return code.
  4391. //
  4392. //
  4393. void WbMainWindow::LoadFile
  4394. (
  4395. LPCSTR szLoadFileName
  4396. )
  4397. {
  4398. UINT uRes;
  4399. // Check we're in idle state
  4400. if (!IsIdle())
  4401. {
  4402. // post an error message indicating the whiteboard is busy
  4403. ::PostMessage(m_hwnd, WM_USER_DISPLAY_ERROR, WBFE_RC_WB, WB_RC_BUSY);
  4404. goto UserPointerCleanup;
  4405. }
  4406. if (*szLoadFileName)
  4407. {
  4408. // Change the cursor to "wait"
  4409. ::SetCursor(::LoadCursor(NULL, IDC_WAIT));
  4410. // Save the current lock
  4411. SaveLock();
  4412. // Get the Page Order Lock (with an invisible dialog)
  4413. BOOL bGotLock = GetLock(WB_LOCK_TYPE_PAGE_ORDER, SW_HIDE);
  4414. if (!bGotLock)
  4415. {
  4416. RestoreLock();
  4417. goto UserPointerCleanup;
  4418. }
  4419. // Load the file
  4420. uRes = g_pwbCore->WBP_ContentsLoad(szLoadFileName);
  4421. if (uRes != 0)
  4422. {
  4423. DefaultExceptionHandler(WBFE_RC_WB, uRes);
  4424. return;
  4425. }
  4426. // Set the window title to the new file name
  4427. lstrcpy(m_strFileName, szLoadFileName);
  4428. // Update the window title with the new file name
  4429. UpdateWindowTitle();
  4430. // Set the state to say that we are loading a file
  4431. SetSubstate(SUBSTATE_LOADING);
  4432. }
  4433. UserPointerCleanup:
  4434. // Restore the cursor
  4435. ::SetCursor(::LoadCursor(NULL, IDC_ARROW));
  4436. }
  4437. //
  4438. //
  4439. // Function: OnDropFiles
  4440. //
  4441. // Purpose: Files have been dropped onto the Whiteboard window
  4442. //
  4443. //
  4444. void WbMainWindow::OnDropFiles(HDROP hDropInfo)
  4445. {
  4446. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnDropFiles");
  4447. UINT uiFilesDropped = 0;
  4448. UINT eachfile;
  4449. // Get the total number of files dropped
  4450. uiFilesDropped = ::DragQueryFile(hDropInfo, (UINT) -1, NULL, (UINT) 0);
  4451. // release mouse capture in case we report any errors (message boxes
  4452. // won't repsond to mouse clicks if we don't)
  4453. ReleaseCapture();
  4454. if( UsersMightLoseData( NULL, NULL ) ) // bug NM4db:418
  4455. goto bail_out;
  4456. // Don't prompt to save file if we're already loading
  4457. int iOnSave;
  4458. if( m_uiSubState != SUBSTATE_LOADING )
  4459. {
  4460. // Check whether there are changes to be saved
  4461. iOnSave = QuerySaveRequired(TRUE);
  4462. }
  4463. else
  4464. {
  4465. goto bail_out;
  4466. }
  4467. if( iOnSave == IDYES )
  4468. {
  4469. // User wants to save the drawing area contents
  4470. int iResult = OnSave(TRUE);
  4471. if( iResult == IDOK )
  4472. {
  4473. // Update the window title with the new file name
  4474. UpdateWindowTitle();
  4475. }
  4476. else
  4477. {
  4478. // cancelled out of save, so cancel the open operation
  4479. goto bail_out;
  4480. }
  4481. }
  4482. // see if user canceled the whole drop
  4483. if( iOnSave == IDCANCEL )
  4484. goto bail_out;
  4485. for (eachfile = 0; eachfile < uiFilesDropped; eachfile++)
  4486. {
  4487. // Retrieve each file name
  4488. char szDropFileName[256];
  4489. ::DragQueryFile(hDropInfo, eachfile,
  4490. szDropFileName, 256);
  4491. TRACE_MSG(("Loading file: %s", szDropFileName));
  4492. // Load the file
  4493. // If this is a valid whiteboard file, the action is simply to load it
  4494. if (g_pwbCore->WBP_ValidateFile(szDropFileName, NULL) == 0)
  4495. {
  4496. LoadFile(szDropFileName);
  4497. }
  4498. else
  4499. {
  4500. ::Message(NULL, IDS_MSG_CAPTION,IDS_MSG_BAD_FILE_FORMAT);
  4501. }
  4502. }
  4503. bail_out:
  4504. ::DragFinish(hDropInfo);
  4505. }
  4506. //
  4507. //
  4508. // Function: OnOpen
  4509. //
  4510. // Purpose: Load a metafile into the application.
  4511. //
  4512. //
  4513. void WbMainWindow::OnOpen(void)
  4514. {
  4515. int iOnSave;
  4516. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnOpen");
  4517. if( UsersMightLoseData( NULL, NULL ) ) // bug NM4db:418
  4518. return;
  4519. // Check we're in idle state
  4520. if ( (m_uiState != IN_CALL) || (m_uiSubState == SUBSTATE_NEW_IN_PROGRESS))
  4521. {
  4522. // post an error message indicating the whiteboard is busy
  4523. ::PostMessage(m_hwnd, WM_USER_DISPLAY_ERROR, WBFE_RC_WB, WB_RC_BUSY);
  4524. return;
  4525. }
  4526. // Don't prompt to save file if we're already loading
  4527. if (m_uiSubState != SUBSTATE_LOADING)
  4528. {
  4529. // Check whether there are changes to be saved
  4530. iOnSave = QuerySaveRequired(TRUE);
  4531. }
  4532. else
  4533. {
  4534. iOnSave = IDNO;
  4535. }
  4536. if (iOnSave == IDYES)
  4537. {
  4538. // User wants to save the drawing area contents
  4539. int iResult = OnSave(TRUE);
  4540. if (iResult == IDOK)
  4541. {
  4542. UpdateWindowTitle();
  4543. }
  4544. else
  4545. {
  4546. // cancelled out of Save As, so cancel the open operation
  4547. iOnSave = IDCANCEL;
  4548. }
  4549. }
  4550. // Only continue if the user has not cancelled the operation
  4551. if (iOnSave != IDCANCEL)
  4552. {
  4553. OPENFILENAME ofn;
  4554. TCHAR szFileName[_MAX_PATH];
  4555. TCHAR szFileTitle[64];
  4556. TCHAR strLoadFilter[2*_MAX_PATH];
  4557. TCHAR strDefaultExt[_MAX_PATH];
  4558. TCHAR strDefaultPath[2*_MAX_PATH];
  4559. TCHAR * pStr;
  4560. UINT strSize = 0;
  4561. UINT totalSize;
  4562. // Build the filter for loadable files
  4563. pStr = strLoadFilter;
  4564. totalSize = 2*_MAX_PATH;
  4565. // These must be NULL separated, with a double NULL at the end
  4566. strSize = ::LoadString(g_hInstance, IDS_FILTER_WHT, pStr, totalSize) + 1;
  4567. pStr += strSize;
  4568. ASSERT(totalSize > strSize);
  4569. totalSize -= strSize;
  4570. strSize = ::LoadString(g_hInstance, IDS_FILTER_WHT_SPEC, pStr, totalSize) + 1;
  4571. pStr += strSize;
  4572. ASSERT(totalSize > strSize);
  4573. totalSize -= strSize;
  4574. strSize = ::LoadString(g_hInstance, IDS_FILTER_ALL, pStr, totalSize) + 1;
  4575. pStr += strSize;
  4576. ASSERT(totalSize > strSize);
  4577. totalSize -= strSize;
  4578. strSize = ::LoadString(g_hInstance, IDS_FILTER_ALL_SPEC, pStr, totalSize) + 1;
  4579. pStr += strSize;
  4580. ASSERT(totalSize > strSize);
  4581. totalSize -= strSize;
  4582. *pStr = 0;
  4583. //
  4584. // Setup the OPENFILENAME struct
  4585. //
  4586. ZeroMemory(&ofn, sizeof(ofn));
  4587. ofn.lStructSize = sizeof(ofn);
  4588. ofn.hwndOwner = m_hwnd;
  4589. // No file name supplied to begin with
  4590. szFileName[0] = 0;
  4591. ofn.lpstrFile = szFileName;
  4592. ofn.nMaxFile = _MAX_PATH;
  4593. // Default Extension: .WHT
  4594. ::LoadString(g_hInstance, IDS_EXT_WHT, strDefaultExt, sizeof(strDefaultExt));
  4595. ofn.lpstrDefExt = strDefaultExt;
  4596. // Default file title is empty
  4597. szFileTitle[0] = 0;
  4598. ofn.lpstrFileTitle = szFileTitle;
  4599. ofn.nMaxFileTitle = 64;
  4600. // Open flags
  4601. ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_EXPLORER;
  4602. ofn.hInstance = g_hInstance;
  4603. // Filter
  4604. ofn.lpstrFilter = strLoadFilter;
  4605. // Default path
  4606. if (GetDefaultPath(strDefaultPath, sizeof(strDefaultPath)))
  4607. ofn.lpstrInitialDir = strDefaultPath;
  4608. // Get user input, continue only if the user selects the OK button
  4609. if (::GetOpenFileName(&ofn))
  4610. {
  4611. // Change the cursor to "wait"
  4612. ::SetCursor(::LoadCursor(NULL, IDC_WAIT));
  4613. // if we're currently loading a file, cancel it, not releasing
  4614. // the page order lock, because we need it immediately afterwards
  4615. if (m_uiSubState == SUBSTATE_LOADING)
  4616. {
  4617. CancelLoad(FALSE);
  4618. }
  4619. // Load the file
  4620. LoadFile(ofn.lpstrFile);
  4621. }
  4622. }
  4623. }
  4624. //
  4625. //
  4626. // Function: GetFileName
  4627. //
  4628. // Purpose: Get a file name for saving the contents
  4629. //
  4630. //
  4631. int WbMainWindow::GetFileName(void)
  4632. {
  4633. OPENFILENAME ofn;
  4634. int iResult;
  4635. TCHAR szFileTitle[64];
  4636. TCHAR strSaveFilter[2*_MAX_PATH];
  4637. TCHAR strDefaultExt[_MAX_PATH];
  4638. TCHAR strDefaultPath[2 * _MAX_PATH];
  4639. TCHAR szFileName[2*_MAX_PATH];
  4640. TCHAR * pStr;
  4641. UINT strSize = 0;
  4642. UINT totalSize;
  4643. //
  4644. // If we are already displaying a "Save As" dialog, dismiss it and create
  4645. // a new one. This can happen if Win95 shuts down whilst WB is
  4646. // displaying the "Save As" dialog and the use selects "Yes" when asked
  4647. // whether they want to save the contents - a second "Save As dialog
  4648. // appears on top of the first.
  4649. //
  4650. if (m_bInSaveDialog)
  4651. {
  4652. CancelSaveDialog();
  4653. }
  4654. // Build the filter for save files
  4655. pStr = strSaveFilter;
  4656. totalSize = 2*_MAX_PATH;
  4657. // These must be NULL separated, with a double NULL at the end
  4658. strSize = ::LoadString(g_hInstance, IDS_FILTER_WHT, pStr, totalSize) + 1;
  4659. pStr += strSize;
  4660. ASSERT(totalSize > strSize);
  4661. totalSize -= strSize;
  4662. strSize = ::LoadString(g_hInstance, IDS_FILTER_WHT_SPEC, pStr, totalSize) + 1;
  4663. pStr += strSize;
  4664. ASSERT(totalSize > strSize);
  4665. totalSize -= strSize;
  4666. strSize = ::LoadString(g_hInstance, IDS_FILTER_ALL, pStr, totalSize) + 1;
  4667. pStr += strSize;
  4668. ASSERT(totalSize > strSize);
  4669. totalSize -= strSize;
  4670. strSize = ::LoadString(g_hInstance, IDS_FILTER_ALL_SPEC, pStr, totalSize) + 1;
  4671. pStr += strSize;
  4672. ASSERT(totalSize > strSize);
  4673. totalSize -= strSize;
  4674. *pStr = 0;
  4675. //
  4676. // Setup the OPENFILENAME struct
  4677. //
  4678. ZeroMemory(&ofn, sizeof(ofn));
  4679. ofn.lStructSize = sizeof(ofn);
  4680. ofn.hwndOwner = m_hwnd;
  4681. lstrcpy(szFileName, m_strFileName);
  4682. ofn.lpstrFile = szFileName;
  4683. ofn.nMaxFile = _MAX_PATH;
  4684. // Build the default extension string
  4685. ::LoadString(g_hInstance, IDS_EXT_WHT, strDefaultExt, sizeof(strDefaultExt));
  4686. ofn.lpstrDefExt = strDefaultExt;
  4687. szFileTitle[0] = 0;
  4688. ofn.lpstrFileTitle = szFileTitle;
  4689. ofn.nMaxFileTitle = 64;
  4690. // Save flags
  4691. ofn.Flags = OFN_HIDEREADONLY | OFN_NOREADONLYRETURN |
  4692. OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST;
  4693. ofn.hInstance = g_hInstance;
  4694. // Filter
  4695. ofn.lpstrFilter = strSaveFilter;
  4696. // Default path
  4697. if (GetDefaultPath(strDefaultPath, sizeof(strDefaultPath)))
  4698. ofn.lpstrInitialDir = strDefaultPath;
  4699. m_bInSaveDialog = TRUE;
  4700. if (::GetSaveFileName(&ofn))
  4701. {
  4702. // The user selected OK
  4703. iResult = IDOK;
  4704. lstrcpy(m_strFileName, szFileName);
  4705. }
  4706. else
  4707. {
  4708. iResult = IDCANCEL;
  4709. }
  4710. m_bInSaveDialog = FALSE;
  4711. return iResult;
  4712. }
  4713. //
  4714. //
  4715. // Function: OnSave
  4716. //
  4717. // Purpose: Save the contents of the Whiteboard using the current file
  4718. // name (or prompting for a new name if there is no current).
  4719. //
  4720. //
  4721. int WbMainWindow::OnSave(BOOL bPrompt)
  4722. {
  4723. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnSave");
  4724. int iResult = IDOK;
  4725. // save the old file name in case there's an error
  4726. TCHAR *strOldName;
  4727. UINT fileNameSize = lstrlen(m_strFileName);
  4728. strOldName = new TCHAR[fileNameSize+1];
  4729. if (!strOldName)
  4730. {
  4731. ERROR_OUT(("OnSave: failed to allocate strOldName TCHAR array, fail"));
  4732. ::PostMessage(m_hwnd, WM_USER_DISPLAY_ERROR, WBFE_RC_WB, WB_RC_BUSY);
  4733. return(iResult);
  4734. }
  4735. else
  4736. {
  4737. lstrcpy(strOldName, m_strFileName);
  4738. }
  4739. BOOL bNewName = FALSE;
  4740. if (!IsIdle())
  4741. {
  4742. // post an error message indicating the whiteboard is busy
  4743. ::PostMessage(m_hwnd, WM_USER_DISPLAY_ERROR, WBFE_RC_WB, WB_RC_BUSY);
  4744. return(iResult);
  4745. }
  4746. // Check whether there is a filename available for use
  4747. if (!fileNameSize || bPrompt)
  4748. {
  4749. // Get user input, continue only if the user selects the OK button
  4750. iResult = GetFileName();
  4751. if (iResult == IDOK)
  4752. {
  4753. // entering a blank file name is treated as cancelling the save
  4754. if (!lstrlen(m_strFileName))
  4755. {
  4756. lstrcpy(m_strFileName, strOldName);
  4757. iResult = IDCANCEL;
  4758. }
  4759. else
  4760. {
  4761. // flag that we've changed the contents file name
  4762. bNewName = TRUE;
  4763. }
  4764. }
  4765. }
  4766. // Now save the file
  4767. if ((iResult == IDOK) && lstrlen(m_strFileName))
  4768. {
  4769. WIN32_FIND_DATA findFileData;
  4770. HANDLE hFind;
  4771. // Get attributes
  4772. hFind = ::FindFirstFile(m_strFileName, &findFileData);
  4773. if (hFind != INVALID_HANDLE_VALUE)
  4774. {
  4775. ::FindClose(hFind);
  4776. // This is a read-only file; we can't change its contents
  4777. if (findFileData.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
  4778. {
  4779. WARNING_OUT(("Dest file %s is read only", m_strFileName));
  4780. ::Message(NULL, IDS_SAVE, IDS_SAVE_READ_ONLY);
  4781. // If the file name was changed for this save then undo
  4782. // the change
  4783. if (bNewName)
  4784. {
  4785. lstrcpy(m_strFileName, strOldName);
  4786. bNewName = FALSE;
  4787. }
  4788. // Change the return code to indicate no save was made
  4789. iResult = IDCANCEL;
  4790. return(iResult);
  4791. }
  4792. }
  4793. // Change the cursor to "wait"
  4794. ::SetCursor(::LoadCursor(NULL,IDC_WAIT));
  4795. // Write the file
  4796. if (g_pwbCore->WBP_ContentsSave(m_strFileName) != 0)
  4797. {
  4798. // Show that an error occurred saving the file.
  4799. WARNING_OUT(("Error saving file"));
  4800. ::Message(NULL, IDS_SAVE, IDS_SAVE_ERROR);
  4801. // If the file name was changed for this save then undo
  4802. // the change
  4803. if (bNewName)
  4804. {
  4805. lstrcpy(m_strFileName, strOldName);
  4806. bNewName = FALSE;
  4807. }
  4808. // Change the return code to indicate no save was made
  4809. iResult = IDCANCEL;
  4810. }
  4811. // Restore the cursor
  4812. ::SetCursor(::LoadCursor(NULL,IDC_ARROW));
  4813. }
  4814. // if the contents file name has changed as a result of the save then
  4815. // update the window title
  4816. if (bNewName)
  4817. {
  4818. UpdateWindowTitle();
  4819. }
  4820. delete strOldName;
  4821. return(iResult);
  4822. }
  4823. //
  4824. // CancelSaveDialog()
  4825. // This cancels the save as dialog if up and we need to kill it to continue.
  4826. // We walk back up the owner chain in case the save dialog puts up help or
  4827. // other owned windows.
  4828. //
  4829. void WbMainWindow::CancelSaveDialog(void)
  4830. {
  4831. WBFINDDIALOG wbf;
  4832. ASSERT(m_bInSaveDialog);
  4833. wbf.hwndOwner = m_hwnd;
  4834. wbf.hwndDialog = NULL;
  4835. EnumThreadWindows(::GetCurrentThreadId(), WbFindCurrentDialog, (LPARAM)&wbf);
  4836. if (wbf.hwndDialog)
  4837. {
  4838. // Found it!
  4839. ::SendMessage(wbf.hwndDialog, WM_COMMAND, IDCANCEL, 0);
  4840. }
  4841. m_bInSaveDialog = FALSE;
  4842. }
  4843. BOOL CALLBACK WbFindCurrentDialog(HWND hwndNext, LPARAM lParam)
  4844. {
  4845. WBFINDDIALOG * pwbf = (WBFINDDIALOG *)lParam;
  4846. // Is this a dialog, owned by the main window?
  4847. if ((::GetClassLong(hwndNext, GCW_ATOM) == 0x8002) &&
  4848. (::GetWindow(hwndNext, GW_OWNER) == pwbf->hwndOwner))
  4849. {
  4850. pwbf->hwndDialog = hwndNext;
  4851. return(FALSE);
  4852. }
  4853. return(TRUE);
  4854. }
  4855. //
  4856. //
  4857. // Function: OnClose
  4858. //
  4859. // Purpose: Close the Whiteboard
  4860. //
  4861. //
  4862. void WbMainWindow::OnClose()
  4863. {
  4864. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnClose");
  4865. int iOnSave = IDOK;
  4866. KillInitDlg();
  4867. m_drawingArea.CancelDrawingMode();
  4868. m_drawingArea.RemoveMarker(NULL);
  4869. m_drawingArea.GetMarker()->DeleteAllMarkers( NULL );
  4870. m_AG.SaveSettings();
  4871. // If we got here, by way of OnDestroy from the DCL cores or
  4872. // by system shutdown, then assume that user responded already to the
  4873. // save-changes dialog that would have poped up during conf's global shutdown
  4874. // message. We don't need to ask 'em again. What tangled webs......
  4875. if ((!m_bQuerySysShutdown) && (IsIdle()))
  4876. {
  4877. // Check whether there are changes to be saved
  4878. iOnSave = QuerySaveRequired(TRUE);
  4879. if (iOnSave == IDYES)
  4880. {
  4881. // User wants to save the drawing area contents
  4882. iOnSave = OnSave(TRUE);
  4883. }
  4884. }
  4885. // If the exit was not cancelled, close the application
  4886. if (iOnSave != IDCANCEL)
  4887. {
  4888. // Mark state as closing - stops any queued events being processed
  4889. m_uiState = CLOSING;
  4890. //PUTBACK BY RAND - the progress timer meter is kinda the heart beat
  4891. // of this thing which I ripped out when I removed the
  4892. // progress meter. I put it back to fix 1476.
  4893. if (m_bTimerActive)
  4894. {
  4895. ::KillTimer(m_hwnd, TIMERID_PROGRESS_METER);
  4896. m_bTimerActive = FALSE;
  4897. }
  4898. m_drawingArea.ShutDownDC();
  4899. // Close the application
  4900. ::PostQuitMessage(0);
  4901. }
  4902. }
  4903. //
  4904. //
  4905. // Function: OnClearPage
  4906. //
  4907. // Purpose: Clear the Whiteboard drawing area. The user is prompted to
  4908. // choose clearing of foreground, background or both.
  4909. //
  4910. //
  4911. void WbMainWindow::OnClearPage(void)
  4912. {
  4913. int iResult;
  4914. BOOL bWasPosted;
  4915. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnClearPage");
  4916. if( UsersMightLoseData( &bWasPosted, NULL ) ) // bug NM4db:418
  4917. return;
  4918. if( bWasPosted )
  4919. iResult = IDYES;
  4920. else
  4921. iResult = ::Message(NULL, IDS_CLEAR_CAPTION, IDS_CLEAR_MESSAGE, MB_YESNO | MB_ICONQUESTION);
  4922. if (iResult == IDYES)
  4923. {
  4924. TRACE_MSG(("User requested clear of page"));
  4925. // lock the drawing area
  4926. LockDrawingArea();
  4927. // Save the current lock status
  4928. SaveLock();
  4929. // Get the Page Order Lock (with an invisible dialog)
  4930. BOOL bGotLock = GetLock(WB_LOCK_TYPE_PAGE_ORDER, SW_HIDE);
  4931. if( bGotLock )
  4932. {
  4933. // clear only if we got the page lock (NM4db:470)
  4934. m_drawingArea.Clear();
  4935. GotoPosition(0, 0);
  4936. }
  4937. RestoreLock();
  4938. UnlockDrawingArea();
  4939. }
  4940. }
  4941. //
  4942. //
  4943. // Function: OnDelete
  4944. //
  4945. // Purpose: Delete the current selection
  4946. //
  4947. //
  4948. void WbMainWindow::OnDelete()
  4949. {
  4950. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnDelete");
  4951. DCWbGraphic* pGraphicCopy = NULL;
  4952. // cleanup select logic in case object context menu called us (bug 426)
  4953. m_drawingArea.SetLClickIgnore( FALSE );
  4954. // If the user currently has a graphic selected
  4955. if (m_drawingArea.GraphicSelected())
  4956. {
  4957. m_LastDeletedGraphic.BurnTrash();
  4958. // Delete the currently selected graphic and add to m_LastDeletedGraphic
  4959. m_drawingArea.DeleteSelection();
  4960. }
  4961. }
  4962. //
  4963. //
  4964. // Function: OnUndelete
  4965. //
  4966. // Purpose: Undo the last delete operation
  4967. //
  4968. //
  4969. void WbMainWindow::OnUndelete()
  4970. {
  4971. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnUndelete");
  4972. // If there is a deleted graphic to restore
  4973. if ( m_LastDeletedGraphic.GotTrash() )
  4974. {
  4975. // If the deleted graphic belongs to the current page
  4976. if (m_LastDeletedGraphic.Page() == m_hCurrentPage)
  4977. {
  4978. // Add the graphic back into the current page
  4979. m_LastDeletedGraphic.AddToPageLast(m_hCurrentPage);
  4980. // if the current tool is a select tool then select the new
  4981. // graphic, otherwise forget it.
  4982. if (m_pCurrentTool->ToolType() == TOOLTYPE_SELECT)
  4983. {
  4984. m_LastDeletedGraphic.SelectTrash();
  4985. m_LastDeletedGraphic.EmptyTrash();
  4986. }
  4987. else
  4988. {
  4989. // Free the local copy
  4990. m_LastDeletedGraphic.BurnTrash();
  4991. }
  4992. }
  4993. }
  4994. }
  4995. void WbMainWindow::OnSelectAll( void )
  4996. {
  4997. // turn off any selections
  4998. // cleanup select logic in case object context menu called us (bug 426)
  4999. m_drawingArea.SetLClickIgnore( FALSE );
  5000. // inhibit normal select-tool action
  5001. m_bSelectAllInProgress = TRUE;
  5002. //put us in select-tool mode first
  5003. OnSelectTool(IDM_SELECT);
  5004. // back to normal
  5005. m_bSelectAllInProgress = FALSE;
  5006. // now, select everything
  5007. m_drawingArea.SelectMarkerFromRect( NULL );
  5008. }
  5009. //
  5010. //
  5011. // Function: DoCopy
  5012. //
  5013. // Purpose: Copy the current selection to the clipboard
  5014. //
  5015. //
  5016. BOOL WbMainWindow::DoCopy(BOOL bRenderNow)
  5017. {
  5018. BOOL bResult = FALSE;
  5019. DCWbGraphicMarker *pMarker;
  5020. DCWbGraphic* pGraphic = m_drawingArea.GetSelection();
  5021. if (pGraphic != NULL)
  5022. {
  5023. pMarker = m_drawingArea.GetMarker();
  5024. if( pMarker->GetNumMarkers() > 1 )
  5025. {
  5026. // more objs than just pGraphic, do a multi-object-to-clipboard
  5027. // operation.
  5028. pGraphic = pMarker;
  5029. }
  5030. //else if == 1 then pMarker contains just pGraphic already
  5031. // so we do a single-object-to-clipboard operation.
  5032. // Copy the graphic (or multiple marker objects) to the clipboard
  5033. bResult = CLP_Copy(pGraphic, bRenderNow);
  5034. // If an error occurred during the copy, report it now
  5035. if (!bResult)
  5036. {
  5037. ::Message(NULL, IDS_COPY, IDS_COPY_ERROR);
  5038. }
  5039. }
  5040. return bResult;
  5041. }
  5042. //
  5043. //
  5044. // Function: OnCut
  5045. //
  5046. // Purpose: Cut the current selection
  5047. //
  5048. //
  5049. void WbMainWindow::OnCut()
  5050. {
  5051. // cleanup select logic in case object context menu called us (bug 426)
  5052. m_drawingArea.SetLClickIgnore( FALSE );
  5053. if (m_drawingArea.TextEditActive())
  5054. {
  5055. m_drawingArea.TextEditCut();
  5056. return;
  5057. }
  5058. if (DoCopy(TRUE))
  5059. {
  5060. // Graphic copied to the clipboard OK - delete it
  5061. m_drawingArea.DeleteSelection();
  5062. }
  5063. }
  5064. //
  5065. // OnCopy()
  5066. // Purpose: Copy the current selection to the clipboard
  5067. //
  5068. //
  5069. void WbMainWindow::OnCopy(void)
  5070. {
  5071. // cleanup select logic in case object context menu called us (bug 426)
  5072. m_drawingArea.SetLClickIgnore( FALSE );
  5073. if( m_drawingArea.TextEditActive() )
  5074. {
  5075. m_drawingArea.TextEditCopy();
  5076. return;
  5077. }
  5078. DoCopy(TRUE);
  5079. }
  5080. //
  5081. //
  5082. // Function: OnPaste
  5083. //
  5084. // Purpose: Paste the contents of the clipboard into the drawing pane
  5085. //
  5086. //
  5087. void WbMainWindow::OnPaste()
  5088. {
  5089. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnPaste");
  5090. // cleanup select logic in case object context menu called us (bug 426)
  5091. m_drawingArea.SetLClickIgnore( FALSE );
  5092. if (m_drawingArea.TextEditActive())
  5093. {
  5094. m_drawingArea.TextEditPaste();
  5095. return;
  5096. }
  5097. // Get the data from the clipboard
  5098. DCWbGraphic* pGraphic = CLP_Paste();
  5099. if (pGraphic != NULL)
  5100. {
  5101. TRACE_MSG(("Got graphic object from clipboard OK"));
  5102. //CHANGED BY RAND - have to handle marker sperately,
  5103. // marker objects are already added to
  5104. // m_hCurrentPage and positioned
  5105. if( pGraphic->IsGraphicTool() == enumGraphicMarker)
  5106. {
  5107. ((DCWbGraphicMarker *)pGraphic)->Update();
  5108. if( m_pCurrentTool->ToolType() == TOOLTYPE_SELECT )
  5109. {
  5110. // marker is already setup, just draw it
  5111. m_drawingArea.PutMarker(NULL);
  5112. }
  5113. else
  5114. {
  5115. // don't select anything, dump marker
  5116. m_drawingArea.RemoveMarker(NULL);
  5117. }
  5118. }
  5119. else // not a marker, deal with single object
  5120. {
  5121. RECT rcVis;
  5122. // Position the graphic at the top left of the visible area of the
  5123. // drawing area
  5124. m_drawingArea.GetVisibleRect(&rcVis);
  5125. pGraphic->MoveTo(rcVis.left, rcVis.top);
  5126. // Add the graphic to the page
  5127. pGraphic->AddToPageLast(m_hCurrentPage);
  5128. // if the current tool is a select tool then select the new
  5129. // object, otherwise forget it.
  5130. if( m_pCurrentTool->ToolType() == TOOLTYPE_SELECT )
  5131. m_drawingArea.SelectGraphic(pGraphic);
  5132. else
  5133. {
  5134. // Free the graphic
  5135. delete pGraphic;
  5136. }
  5137. }
  5138. }
  5139. else
  5140. {
  5141. TRACE_MSG(("Could not get graphic from clipboard"));
  5142. // display error message instead of throwing exception
  5143. ::Message(NULL, IDS_PASTE, IDS_PASTE_ERROR);
  5144. }
  5145. }
  5146. //
  5147. //
  5148. // Function: OnRenderAllFormats
  5149. //
  5150. // Purpose: Render all formats of the graphic last copied to the
  5151. // CLP_
  5152. //
  5153. //
  5154. void WbMainWindow::OnRenderAllFormats(void)
  5155. {
  5156. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnRenderAllFormats");
  5157. //
  5158. // only render something if we have not done it already
  5159. //
  5160. if (CLP_LastCopiedPage() != WB_PAGE_HANDLE_NULL)
  5161. {
  5162. if (!CLP_RenderAllFormats())
  5163. {
  5164. // An error occurred rendering the formats
  5165. ERROR_OUT(("Error rendering all formats"));
  5166. }
  5167. }
  5168. }
  5169. //
  5170. //
  5171. // Function: CheckMenuItem
  5172. //
  5173. // Purpose: Check an item on the application menus (main and context
  5174. // menu.)
  5175. //
  5176. //
  5177. void WbMainWindow::CheckMenuItem(UINT uiId)
  5178. {
  5179. CheckMenuItemRecursive(::GetMenu(m_hwnd), uiId, MF_BYCOMMAND | MF_CHECKED);
  5180. CheckMenuItemRecursive(m_hContextMenu, uiId, MF_BYCOMMAND | MF_CHECKED);
  5181. CheckMenuItemRecursive(m_hGrobjContextMenu, uiId, MF_BYCOMMAND | MF_CHECKED); // bug 426
  5182. }
  5183. //
  5184. //
  5185. // Function: UncheckMenuItem
  5186. //
  5187. // Purpose: Uncheck an item on the application menus (main and context
  5188. // menus.)
  5189. //
  5190. //
  5191. void WbMainWindow::UncheckMenuItem(UINT uiId)
  5192. {
  5193. CheckMenuItemRecursive(::GetMenu(m_hwnd), uiId, MF_BYCOMMAND | MF_UNCHECKED);
  5194. CheckMenuItemRecursive(m_hContextMenu, uiId, MF_BYCOMMAND | MF_UNCHECKED);
  5195. CheckMenuItemRecursive(m_hGrobjContextMenu, uiId, MF_BYCOMMAND | MF_UNCHECKED); // bug 426
  5196. }
  5197. //
  5198. //
  5199. // Function: CheckMenuItemRecursive
  5200. //
  5201. // Purpose: Check or uncheck an item on the any of the Whiteboard menus.
  5202. // This function recursively searches through the menus until
  5203. // it finds the specified item. The menu item Ids must be
  5204. // unique for this function to work.
  5205. //
  5206. //
  5207. BOOL WbMainWindow::CheckMenuItemRecursive(HMENU hMenu,
  5208. UINT uiId,
  5209. BOOL bCheck)
  5210. {
  5211. UINT uiNumItems = ::GetMenuItemCount(hMenu);
  5212. // Attempt to check the menu item
  5213. UINT uiCheck = MF_BYCOMMAND | (bCheck ? MF_CHECKED : MF_UNCHECKED);
  5214. // A return code of -1 from CheckMenuItem implies that
  5215. // the menu item was not found
  5216. BOOL bChecked = ((::CheckMenuItem(hMenu, uiId, uiCheck) == -1) ? FALSE : TRUE);
  5217. if (bChecked)
  5218. {
  5219. //
  5220. // If this item is on the active menu, ensure it's redrawn now
  5221. //
  5222. if (hMenu == m_hInitMenu)
  5223. {
  5224. InvalidateActiveMenu();
  5225. }
  5226. }
  5227. else
  5228. {
  5229. UINT uiPos;
  5230. HMENU hSubMenu;
  5231. // Recurse through the submenus of the specified menu
  5232. for (uiPos = 0; uiPos < uiNumItems; uiPos++)
  5233. {
  5234. // Assume that the next item is a submenu
  5235. // and try to get a pointer to it
  5236. hSubMenu = ::GetSubMenu(hMenu, (int)uiPos);
  5237. // NULL return implies the item is a not submenu
  5238. if (hSubMenu != NULL)
  5239. {
  5240. // Item is a submenu, make recursive call to search it
  5241. bChecked = CheckMenuItemRecursive(hSubMenu, uiId, bCheck);
  5242. if (bChecked)
  5243. {
  5244. // We have found the item
  5245. break;
  5246. }
  5247. }
  5248. }
  5249. }
  5250. return bChecked;
  5251. }
  5252. //
  5253. //
  5254. // Function: GetMenuWithItem
  5255. //
  5256. // Purpose: Return the menu which contains the specified item.
  5257. //
  5258. //
  5259. HMENU WbMainWindow::GetMenuWithItem(HMENU hMenu, UINT uiID)
  5260. {
  5261. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::GetMenuWithItem");
  5262. ASSERT(hMenu != NULL);
  5263. HMENU hMenuResult = NULL;
  5264. // Get the number ofitems in the menu
  5265. UINT uiNumItems = ::GetMenuItemCount(hMenu);
  5266. UINT uiPos;
  5267. UINT uiNextID;
  5268. // Look for the item through the menu
  5269. for (uiPos = 0; uiPos < uiNumItems; uiPos++)
  5270. {
  5271. // Get the ID of the item at this position
  5272. uiNextID = ::GetMenuItemID(hMenu, uiPos);
  5273. if (uiNextID == uiID)
  5274. {
  5275. // We have found the item
  5276. hMenuResult = hMenu;
  5277. break;
  5278. }
  5279. }
  5280. // If we have not yet found the item
  5281. if (hMenuResult == NULL)
  5282. {
  5283. // Look through each of the submenus of the current menu
  5284. HMENU hSubMenu;
  5285. for (uiPos = 0; uiPos < uiNumItems; uiPos++)
  5286. {
  5287. // Get the ID of the item at this position
  5288. uiNextID = ::GetMenuItemID(hMenu, uiPos);
  5289. // If the item is a submenu
  5290. if (uiNextID == -1)
  5291. {
  5292. // Get the submenu
  5293. hSubMenu = ::GetSubMenu(hMenu, (int) uiPos);
  5294. // Search the submenu
  5295. hMenuResult = GetMenuWithItem(hSubMenu, uiID);
  5296. if (hMenuResult != NULL)
  5297. {
  5298. // We have found the menu with the requested item
  5299. break;
  5300. }
  5301. }
  5302. }
  5303. }
  5304. return hMenuResult;
  5305. }
  5306. //
  5307. //
  5308. // Function: OnScrollAccelerator
  5309. //
  5310. // Purpose: Called when a scroll accelerator is used
  5311. //
  5312. //
  5313. void WbMainWindow::OnScrollAccelerator(UINT uiMenuId)
  5314. {
  5315. int iScroll;
  5316. // Locate the scroll messages to be sent in the conversion table
  5317. for (iScroll = 0; iScroll < ARRAYSIZE(s_MenuToScroll); iScroll++)
  5318. {
  5319. if (s_MenuToScroll[iScroll].uiMenuId == uiMenuId)
  5320. {
  5321. // Found it;
  5322. break;
  5323. }
  5324. }
  5325. // Send the messages
  5326. if (iScroll < ARRAYSIZE(s_MenuToScroll))
  5327. {
  5328. while ((s_MenuToScroll[iScroll].uiMenuId == uiMenuId) && (iScroll < ARRAYSIZE(s_MenuToScroll)))
  5329. {
  5330. // Tell the drawing pane to scroll
  5331. ::PostMessage(m_drawingArea.m_hwnd, s_MenuToScroll[iScroll].uiMessage,
  5332. s_MenuToScroll[iScroll].uiScrollCode, 0);
  5333. iScroll++;
  5334. }
  5335. // Indicate that scrolling has completed (in both directions)
  5336. ::PostMessage(m_drawingArea.m_hwnd, WM_HSCROLL, SB_ENDSCROLL, 0L);
  5337. ::PostMessage(m_drawingArea.m_hwnd, WM_VSCROLL, SB_ENDSCROLL, 0L);
  5338. }
  5339. }
  5340. //
  5341. //
  5342. // Function: OnZoom
  5343. //
  5344. // Purpose: Zoom or unzoom the drawing area
  5345. //
  5346. //
  5347. void WbMainWindow::OnZoom()
  5348. {
  5349. // If the drawing area is currently zoomed
  5350. if (m_drawingArea.Zoomed())
  5351. {
  5352. // Remove the zoomed check mark
  5353. UncheckMenuItem(IDM_ZOOM);
  5354. // Tell the tool bar of the new selection
  5355. m_TB.PopUp(IDM_ZOOM);
  5356. // Inform the local user of the zoom state
  5357. if (m_pLocalUser != NULL)
  5358. m_pLocalUser->Unzoom();
  5359. }
  5360. else
  5361. {
  5362. // Set the zoomed check mark
  5363. CheckMenuItem(IDM_ZOOM);
  5364. // Tell the tool bar of the new selection
  5365. m_TB.PushDown(IDM_ZOOM);
  5366. // Inform the local user of the zoom state
  5367. if (m_pLocalUser != NULL)
  5368. m_pLocalUser->Zoom();
  5369. }
  5370. // Zoom/unzoom the drawing area
  5371. m_drawingArea.Zoom();
  5372. // Restore the focus to the drawing area
  5373. ::SetFocus(m_drawingArea.m_hwnd);
  5374. }
  5375. //
  5376. //
  5377. // Function: OnSelectTool
  5378. //
  5379. // Purpose: Select the current tool
  5380. //
  5381. //
  5382. void WbMainWindow::OnSelectTool(UINT uiMenuId)
  5383. {
  5384. UINT uiIndex;
  5385. UncheckMenuItem(m_currentMenuTool);
  5386. CheckMenuItem( uiMenuId);
  5387. // Save the new menu Id
  5388. m_currentMenuTool = uiMenuId;
  5389. // Tell the tool bar of the new selection
  5390. m_TB.PushDown(m_currentMenuTool);
  5391. // Get the new tool
  5392. m_pCurrentTool = m_ToolArray[TOOL_INDEX(m_currentMenuTool)];
  5393. // Set the current attributes
  5394. if( !m_bSelectAllInProgress )
  5395. {
  5396. m_AG.SetChoiceColor(m_pCurrentTool->GetColor() );
  5397. ::SendMessage(m_hwnd, WM_COMMAND, IDM_COLOR, 0L);
  5398. ::SendMessage(m_hwnd, WM_COMMAND, IDM_WIDTHS_START + m_pCurrentTool->GetWidthIndex(), 0L);//CHANGED BY RAND
  5399. }
  5400. // Report the change of tool to the attributes group
  5401. m_AG.DisplayTool(m_pCurrentTool);
  5402. // Select the new tool into the drawing area
  5403. m_drawingArea.SelectTool(m_pCurrentTool);
  5404. // Restore the focus to the drawing area
  5405. ::SetFocus(m_drawingArea.m_hwnd);
  5406. }
  5407. //
  5408. //
  5409. // Function: OnSelectColor
  5410. //
  5411. // Purpose: Set the current color
  5412. //
  5413. //
  5414. void WbMainWindow::OnSelectColor(void)
  5415. {
  5416. // Tell the attributes group of the new selection and get the
  5417. // new color value selected ino the current tool.
  5418. m_AG.SelectColor(m_pCurrentTool);
  5419. // Select the changed tool into the drawing area
  5420. m_drawingArea.SelectTool(m_pCurrentTool);
  5421. // If we are using a select tool, change the color of the selected object
  5422. if (m_pCurrentTool->ToolType() == TOOLTYPE_SELECT)
  5423. {
  5424. // If there is an object marked for changing
  5425. if (m_drawingArea.GraphicSelected())
  5426. {
  5427. // Update the object
  5428. m_drawingArea.SetSelectionColor(m_pCurrentTool->GetColor());
  5429. }
  5430. }
  5431. // if currently editing a text object then change its color
  5432. if ( (m_pCurrentTool->ToolType() == TOOLTYPE_TEXT)
  5433. && (m_drawingArea.TextEditActive()))
  5434. {
  5435. m_drawingArea.SetSelectionColor(m_pCurrentTool->GetColor());
  5436. }
  5437. // Restore the focus to the drawing area
  5438. ::SetFocus(m_drawingArea.m_hwnd);
  5439. }
  5440. //
  5441. //
  5442. // Function: OnSelectWidth
  5443. //
  5444. // Purpose: Set the current nib width
  5445. //
  5446. //
  5447. void WbMainWindow::OnSelectWidth(UINT uiMenuId)
  5448. {
  5449. // cleanup select logic in case object context menu called us (bug 426)
  5450. m_drawingArea.SetLClickIgnore( FALSE );
  5451. // Move the check mark on the menu
  5452. UncheckMenuItem(m_currentMenuWidth);
  5453. CheckMenuItem(uiMenuId);
  5454. // Save the new pen width
  5455. m_currentMenuWidth = uiMenuId;
  5456. // Tell the attributes display of the new selection
  5457. m_WG.PushDown(uiMenuId - IDM_WIDTHS_START);
  5458. if (m_pCurrentTool != NULL)
  5459. {
  5460. m_pCurrentTool->SetWidthIndex(uiMenuId - IDM_WIDTHS_START);
  5461. }
  5462. // Tell the drawing pane of the new selection
  5463. m_drawingArea.SelectTool(m_pCurrentTool);
  5464. // If we are using a select tool, change the color of the selected object
  5465. if (m_pCurrentTool->ToolType() == TOOLTYPE_SELECT)
  5466. {
  5467. // If there is an object marked for changing
  5468. if (m_drawingArea.GraphicSelected())
  5469. {
  5470. // Update the object
  5471. m_drawingArea.SetSelectionWidth(m_pCurrentTool->GetWidth());
  5472. }
  5473. }
  5474. // Restore the focus to the drawing area
  5475. ::SetFocus(m_drawingArea.m_hwnd);
  5476. }
  5477. //
  5478. //
  5479. // Function: OnChooseFont
  5480. //
  5481. // Purpose: Let the user select a font
  5482. //
  5483. //
  5484. void WbMainWindow::OnChooseFont(void)
  5485. {
  5486. HDC hdc;
  5487. LOGFONT lfont;
  5488. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnChooseFont");
  5489. // cleanup select logic in case object context menu called us (bug 426)
  5490. m_drawingArea.SetLClickIgnore( FALSE );
  5491. // It is only really sensible to be here when a text tool is selected.
  5492. // This is achieved by graying the Font selection menu entry when
  5493. // anything other than a text tool is in use.
  5494. // Get the font details from the current tool
  5495. ::GetObject(m_pCurrentTool->GetFont(), sizeof(LOGFONT), &lfont);
  5496. lfont.lfClipPrecision |= CLIP_DFA_OVERRIDE;
  5497. //
  5498. // The Font dialog is passed a LOGFONT structure which it uses to
  5499. // initialize all of its fields (face name, weight etc).
  5500. //
  5501. // The face name passed in the LOGFONT structure is checked by the dialog
  5502. // against the facenames of all available fonts. If the name does not
  5503. // match one of the available fonts, no name is displayed.
  5504. //
  5505. // WB stores the LOGFONT structure specifying the font used for a text
  5506. // object in the object. This LOGFONT is selected into a DC where the
  5507. // GDIs font mapper decides which physical font most closely matches the
  5508. // required logical font. On boxes where the original font is not
  5509. // supported the font is substituted for the closest matching font
  5510. // available.
  5511. //
  5512. // So, if we pass the LOGFONT structure for a font which is not supported
  5513. // into the Font dialog, no facename is displayed. To bypass this we
  5514. //
  5515. // - select the logical font into a DC
  5516. //
  5517. // - determine the textmetrics and get the face name of the physical font
  5518. // chosen by the Font Mapper
  5519. //
  5520. // - use these textmetrics to create a LOGFONT structure which matches
  5521. // the substituted font!
  5522. //
  5523. // The resulting LOGFONT will have the correct weight, dimensions and
  5524. // facename for the substituted font.
  5525. //
  5526. hdc = ::CreateCompatibleDC(NULL);
  5527. if (hdc != NULL)
  5528. {
  5529. TEXTMETRIC tm;
  5530. HFONT hFont;
  5531. HFONT hOldFont;
  5532. hFont = ::CreateFontIndirect(&lfont);
  5533. //
  5534. // Get the face name and text metrics of the selected font.
  5535. //
  5536. hOldFont = SelectFont(hdc, hFont);
  5537. if (hOldFont == NULL)
  5538. {
  5539. WARNING_OUT(("Failed to select font into DC"));
  5540. }
  5541. else
  5542. {
  5543. ::GetTextMetrics(hdc, &tm);
  5544. ::GetTextFace(hdc, LF_FACESIZE, lfont.lfFaceName);
  5545. //
  5546. // Restore the old font back into the DC.
  5547. //
  5548. SelectFont(hdc, hOldFont);
  5549. //
  5550. // Create a LOGFONT structure which matches the Text metrics
  5551. // of the font used by the DC so that the font dialog manages
  5552. // to initialise all of its fields properly, even for
  5553. // substituted fonts...
  5554. //
  5555. lfont.lfHeight = tm.tmHeight;
  5556. lfont.lfWidth = tm.tmAveCharWidth;
  5557. lfont.lfWeight = tm.tmWeight;
  5558. lfont.lfItalic = tm.tmItalic;
  5559. lfont.lfUnderline = tm.tmUnderlined;
  5560. lfont.lfStrikeOut = tm.tmStruckOut;
  5561. lfont.lfCharSet = tm.tmCharSet;
  5562. //ADDED BY RAND - to make lfHeight be a char height. This makes
  5563. // the font dlg show the same pt size that is
  5564. // displayed in the sample font toolbar
  5565. if( lfont.lfHeight > 0 )
  5566. {
  5567. lfont.lfHeight = -(lfont.lfHeight - tm.tmInternalLeading);
  5568. }
  5569. }
  5570. ::DeleteDC(hdc);
  5571. if (hFont != NULL)
  5572. {
  5573. ::DeleteFont(hFont);
  5574. }
  5575. }
  5576. else
  5577. {
  5578. WARNING_OUT(("Failed to get DC to select font into"));
  5579. }
  5580. CHOOSEFONT cf;
  5581. TCHAR szStyleName[64];
  5582. ZeroMemory(&cf, sizeof(cf));
  5583. ZeroMemory(szStyleName, sizeof(szStyleName));
  5584. cf.lStructSize = sizeof(cf);
  5585. cf.lpszStyle = szStyleName;
  5586. cf.rgbColors = m_pCurrentTool->GetColor() & 0x00ffffff; // blow off palette bits (NM4db:2304)
  5587. cf.Flags = CF_EFFECTS | CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS |
  5588. CF_NOVERTFONTS;
  5589. cf.lpLogFont = &lfont;
  5590. cf.hwndOwner = m_hwnd;
  5591. // Call up the ChooseFont dialog from COM DLG
  5592. if (::ChooseFont(&cf))
  5593. {
  5594. lfont.lfClipPrecision |= CLIP_DFA_OVERRIDE;
  5595. //ADDED BY RAND - set color selected in dialog.
  5596. m_pCurrentTool->SetColor(cf.rgbColors);
  5597. m_AG.DisplayTool( m_pCurrentTool );
  5598. ::SendMessage(m_hwnd, WM_COMMAND,
  5599. (WPARAM)MAKELONG( IDM_COLOR, BN_CLICKED ),
  5600. (LPARAM)0 );
  5601. // Inform the drawing pane of the new selection
  5602. HFONT hNewFont;
  5603. hNewFont = ::CreateFontIndirect(&lfont);
  5604. if (!hNewFont)
  5605. {
  5606. ERROR_OUT(("Failed to create font"));
  5607. DefaultExceptionHandler(WBFE_RC_WINDOWS, 0);
  5608. return;
  5609. }
  5610. //
  5611. // We need to set the text editor font after inserting it in the DC
  5612. // and querying the metrics, otherwise we may get a font with different
  5613. // metrics in zoomed mode
  5614. //
  5615. HFONT hNewFont2;
  5616. HDC hDC = m_drawingArea.GetCachedDC();
  5617. TEXTMETRIC textMetrics;
  5618. m_drawingArea.PrimeFont(hDC, hNewFont, &textMetrics);
  5619. lfont.lfHeight = textMetrics.tmHeight;
  5620. lfont.lfWidth = textMetrics.tmAveCharWidth;
  5621. lfont.lfPitchAndFamily = textMetrics.tmPitchAndFamily;
  5622. ::GetTextFace(hDC, sizeof(lfont.lfFaceName),
  5623. lfont.lfFaceName);
  5624. TRACE_MSG(("Font face name %s", lfont.lfFaceName));
  5625. // Inform the drawing pane of the new selection
  5626. hNewFont2 = ::CreateFontIndirect(&lfont);
  5627. if (!hNewFont2)
  5628. {
  5629. ERROR_OUT(("Failed to create font"));
  5630. DefaultExceptionHandler(WBFE_RC_WINDOWS, 0);
  5631. return;
  5632. }
  5633. m_drawingArea.SetSelectionColor(cf.rgbColors);
  5634. m_drawingArea.SetSelectionFont(hNewFont2);
  5635. if (m_pCurrentTool != NULL)
  5636. {
  5637. m_pCurrentTool->SetFont(hNewFont2);
  5638. }
  5639. m_drawingArea.SelectTool(m_pCurrentTool);
  5640. //
  5641. // discard the new font
  5642. //
  5643. m_drawingArea.UnPrimeFont( hDC );
  5644. // Delete the fonts we created--everybody above makes copies
  5645. ::DeleteFont(hNewFont2);
  5646. ::DeleteFont(hNewFont);
  5647. }
  5648. // Restore the focus to the drawing area
  5649. ::SetFocus(m_drawingArea.m_hwnd);
  5650. }
  5651. //
  5652. //
  5653. // Function: OnToolBarToggle
  5654. //
  5655. // Purpose: Let the user toggle the tool bar on/off
  5656. //
  5657. //
  5658. void WbMainWindow::OnToolBarToggle(void)
  5659. {
  5660. RECT rectWnd;
  5661. // Toggle the flag
  5662. m_bToolBarOn = !m_bToolBarOn;
  5663. // Make the necessary updates
  5664. if (m_bToolBarOn)
  5665. {
  5666. // The tool bar was hidden, so show it
  5667. ::ShowWindow(m_TB.m_hwnd, SW_SHOW);
  5668. // The tool window is fixed so we must resize the other panes in
  5669. // the window to make room for it
  5670. ResizePanes();
  5671. // Check the associated menu item
  5672. CheckMenuItem(IDM_TOOL_BAR_TOGGLE);
  5673. }
  5674. else
  5675. {
  5676. // The tool bar was visible, so hide it
  5677. ::ShowWindow(m_TB.m_hwnd, SW_HIDE);
  5678. // Uncheck the associated menu item
  5679. UncheckMenuItem(IDM_TOOL_BAR_TOGGLE);
  5680. ResizePanes();
  5681. }
  5682. // Make sure things reflect current tool
  5683. m_AG.DisplayTool(m_pCurrentTool);
  5684. // Write the new option value to the options file
  5685. OPT_SetBooleanOption(OPT_MAIN_TOOLBARVISIBLE,
  5686. m_bToolBarOn);
  5687. ::GetWindowRect(m_hwnd, &rectWnd);
  5688. ::MoveWindow(m_hwnd, rectWnd.left, rectWnd.top,
  5689. rectWnd.right - rectWnd.left, rectWnd.bottom - rectWnd.top, TRUE);
  5690. }
  5691. //
  5692. //
  5693. // Function: OnStatusBarToggle
  5694. //
  5695. // Purpose: Let the user toggle the help bar on/off
  5696. //
  5697. //
  5698. void WbMainWindow::OnStatusBarToggle(void)
  5699. {
  5700. RECT rectWnd;
  5701. // Toggle the flag
  5702. m_bStatusBarOn = !m_bStatusBarOn;
  5703. // Make the necessary updates
  5704. if (m_bStatusBarOn)
  5705. {
  5706. // Resize the panes to give room for the help bar
  5707. ResizePanes();
  5708. // The help bar was hidden, so show it
  5709. ::ShowWindow(m_hwndSB, SW_SHOW);
  5710. // Check the associated menu item
  5711. CheckMenuItem(IDM_STATUS_BAR_TOGGLE);
  5712. }
  5713. else
  5714. {
  5715. // The help bar was visible, so hide it
  5716. ::ShowWindow(m_hwndSB, SW_HIDE);
  5717. // Uncheck the associated menu item
  5718. UncheckMenuItem(IDM_STATUS_BAR_TOGGLE);
  5719. // Resize the panes to take up the help bar space
  5720. ResizePanes();
  5721. }
  5722. // Write the new option value to the options file
  5723. OPT_SetBooleanOption(OPT_MAIN_STATUSBARVISIBLE, m_bStatusBarOn);
  5724. ::GetWindowRect(m_hwnd, &rectWnd);
  5725. ::MoveWindow(m_hwnd, rectWnd.left, rectWnd.top,
  5726. rectWnd.right - rectWnd.left, rectWnd.bottom - rectWnd.top, TRUE);
  5727. }
  5728. //
  5729. //
  5730. // Function: OnAbout
  5731. //
  5732. // Purpose: Show the about box for the Whiteboard application. This
  5733. // method is called whenever a WM_COMMAND with IDM_ABOUT
  5734. // is issued by Windows.
  5735. //
  5736. //
  5737. void WbMainWindow::OnAbout()
  5738. {
  5739. ::DialogBoxParam(g_hInstance, MAKEINTRESOURCE(ABOUTBOX), m_hwnd,
  5740. AboutDlgProc, 0);
  5741. }
  5742. INT_PTR AboutDlgProc(HWND hwnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
  5743. {
  5744. BOOL fHandled = FALSE;
  5745. switch (uMessage)
  5746. {
  5747. case WM_INITDIALOG:
  5748. {
  5749. TCHAR szFormat[256];
  5750. TCHAR szVersion[512];
  5751. ::GetDlgItemText(hwnd, IDC_ABOUTVERSION, szFormat, 256);
  5752. wsprintf(szVersion, szFormat, VER_PRODUCTRELEASE_STR,
  5753. VER_PRODUCTVERSION_STR);
  5754. ::SetDlgItemText(hwnd, IDC_ABOUTVERSION, szVersion);
  5755. fHandled = TRUE;
  5756. break;
  5757. }
  5758. case WM_COMMAND:
  5759. switch (GET_WM_COMMAND_ID(wParam, lParam))
  5760. {
  5761. case IDOK:
  5762. case IDCANCEL:
  5763. switch (GET_WM_COMMAND_CMD(wParam, lParam))
  5764. {
  5765. case BN_CLICKED:
  5766. ::EndDialog(hwnd, IDCANCEL);
  5767. break;
  5768. }
  5769. break;
  5770. }
  5771. fHandled = TRUE;
  5772. break;
  5773. }
  5774. return(fHandled);
  5775. }
  5776. //
  5777. //
  5778. // Function: SelectWindow
  5779. //
  5780. // Purpose: Let the user select a window for grabbing
  5781. //
  5782. //
  5783. HWND WbMainWindow::SelectWindow(void)
  5784. {
  5785. POINT mousePos; // Mouse position
  5786. HWND hwndSelected = NULL; // Window clicked on
  5787. MSG msg; // Current message
  5788. // Load the grabbing cursors
  5789. HCURSOR hGrabCursor = ::LoadCursor(g_hInstance, MAKEINTRESOURCE( GRABCURSOR ) );
  5790. // Capture the mouse
  5791. UT_CaptureMouse(m_hwnd);
  5792. // Ensure we receive all keyboard messages.
  5793. ::SetFocus(m_hwnd);
  5794. // Reset the CancelMode state
  5795. ResetCancelMode();
  5796. // Change to the grab cursor
  5797. HCURSOR hOldCursor = ::SetCursor(hGrabCursor);
  5798. // Trap all mouse messages until a WM_LBUTTONUP is received
  5799. for ( ; ; )
  5800. {
  5801. // Wait for the next message
  5802. ::WaitMessage();
  5803. // Cancel if we have been sent a WM_CANCELMODE message
  5804. if (CancelModeSent())
  5805. {
  5806. break;
  5807. }
  5808. // If it is a mouse message, process it
  5809. if (::PeekMessage(&msg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE))
  5810. {
  5811. if (msg.message == WM_LBUTTONUP)
  5812. {
  5813. // Get mouse position
  5814. mousePos.x = (short)LOWORD(msg.lParam);
  5815. mousePos.y = (short)HIWORD(msg.lParam);
  5816. // Convert to screen coordinates
  5817. ::ClientToScreen(m_hwnd, &mousePos);
  5818. // Get the window under the mouse
  5819. hwndSelected = ::WindowFromPoint(mousePos);
  5820. // Leave the loop
  5821. break;
  5822. }
  5823. }
  5824. // Cancel if ESCAPE is pressed.
  5825. // or if another window receives the focus
  5826. else if (::PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
  5827. {
  5828. if (msg.wParam == VK_ESCAPE)
  5829. {
  5830. break;
  5831. }
  5832. }
  5833. }
  5834. // Release the mouse
  5835. UT_ReleaseMouse(m_hwnd);
  5836. // Restore the cursor
  5837. ::SetCursor(hOldCursor);
  5838. return(hwndSelected);
  5839. }
  5840. //
  5841. //
  5842. // Function: OnGrabWindow
  5843. //
  5844. // Purpose: Allows the user to grab a bitmap of a window
  5845. //
  5846. //
  5847. void WbMainWindow::OnGrabWindow(void)
  5848. {
  5849. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnGrabWindow");
  5850. if (::DialogBoxParam(g_hInstance, MAKEINTRESOURCE(WARNSELECTWINDOW),
  5851. m_hwnd, WarnSelectWindowDlgProc, 0) != IDOK)
  5852. {
  5853. // User cancelled; bail out
  5854. return;
  5855. }
  5856. // Hide the application windows
  5857. ::ShowWindow(m_hwnd, SW_HIDE);
  5858. // Get window selection from the user
  5859. HWND hwndSelected = SelectWindow();
  5860. if (hwndSelected != NULL)
  5861. {
  5862. // Walk back to the find the 'real' window ancestor
  5863. HWND hwndParent;
  5864. // The following piece of code attempts to find the frame window
  5865. // enclosing the selected window. This allows us to bring the
  5866. // enclosing window to the top, bringing the child window with it.
  5867. DWORD dwStyle;
  5868. while ((hwndParent = ::GetParent(hwndSelected)) != NULL)
  5869. {
  5870. // If we have reached a stand-alone window, stop the search
  5871. dwStyle = ::GetWindowLong(hwndSelected, GWL_STYLE);
  5872. if ( ((dwStyle & WS_POPUP) == WS_POPUP)
  5873. || ((dwStyle & WS_THICKFRAME) == WS_THICKFRAME)
  5874. || ((dwStyle & WS_DLGFRAME) == WS_DLGFRAME))
  5875. {
  5876. break;
  5877. }
  5878. // Move up to the parent window
  5879. hwndSelected = hwndParent;
  5880. }
  5881. // Bring the selected window to the top
  5882. ::BringWindowToTop(hwndSelected);
  5883. ::UpdateWindow(hwndSelected);
  5884. // Get an image copy of the window
  5885. RECT areaRect;
  5886. ::GetWindowRect(hwndSelected, &areaRect);
  5887. DCWbGraphicDIB dib;
  5888. dib.FromScreenArea(&areaRect);
  5889. // Add the new grabbed bitmap
  5890. AddCapturedImage(dib);
  5891. // Force the selection tool to be selected
  5892. ::PostMessage(m_hwnd, WM_COMMAND, IDM_TOOLS_START, 0L);
  5893. }
  5894. // Show the windows again
  5895. ::ShowWindow(m_hwnd, SW_SHOW);
  5896. // Restore the focus to the drawing area
  5897. ::SetFocus(m_drawingArea.m_hwnd);
  5898. }
  5899. //
  5900. // WarnSelectWindowDlgProc()
  5901. // This puts up the warning/explanation dialog. We use the default settings
  5902. // or whatever the user chose last time this dialog was up.
  5903. //
  5904. INT_PTR CALLBACK WarnSelectWindowDlgProc(HWND hwnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
  5905. {
  5906. BOOL fHandled = FALSE;
  5907. switch (uMessage)
  5908. {
  5909. case WM_INITDIALOG:
  5910. {
  5911. if (OPT_GetBooleanOption( OPT_MAIN_SELECTWINDOW_NOTAGAIN,
  5912. DFLT_MAIN_SELECTWINDOW_NOTAGAIN))
  5913. {
  5914. // End this right away, the user doesn't want a warning
  5915. ::EndDialog(hwnd, IDOK);
  5916. }
  5917. fHandled = TRUE;
  5918. break;
  5919. }
  5920. case WM_COMMAND:
  5921. switch (GET_WM_COMMAND_ID(wParam, lParam))
  5922. {
  5923. case IDOK:
  5924. switch (GET_WM_COMMAND_CMD(wParam, lParam))
  5925. {
  5926. case BN_CLICKED:
  5927. //
  5928. // Update settings -- note that we don't have to write out
  5929. // FALSE--we wouldn't be in the dialog in the first place
  5930. // if the current setting weren't already FALSE.
  5931. //
  5932. if (::IsDlgButtonChecked(hwnd, IDC_SWWARN_NOTAGAIN))
  5933. {
  5934. OPT_SetBooleanOption(OPT_MAIN_SELECTWINDOW_NOTAGAIN, TRUE);
  5935. }
  5936. ::EndDialog(hwnd, IDOK);
  5937. break;
  5938. }
  5939. break;
  5940. case IDCANCEL:
  5941. switch (GET_WM_COMMAND_CMD(wParam, lParam))
  5942. {
  5943. case BN_CLICKED:
  5944. ::EndDialog(hwnd, IDCANCEL);
  5945. break;
  5946. }
  5947. break;
  5948. }
  5949. fHandled = TRUE;
  5950. break;
  5951. }
  5952. return(fHandled);
  5953. }
  5954. //
  5955. //
  5956. // Function: ShowAllWindows
  5957. //
  5958. // Purpose: Show or hide the main window and associated windows
  5959. //
  5960. //
  5961. void WbMainWindow::ShowAllWindows(int iShow)
  5962. {
  5963. // Show/hide the main window
  5964. ::ShowWindow(m_hwnd, iShow);
  5965. // Show/hide the tool window
  5966. if (m_bToolBarOn)
  5967. {
  5968. ::ShowWindow(m_TB.m_hwnd, iShow);
  5969. }
  5970. }
  5971. //
  5972. //
  5973. // Function: OnGrabArea
  5974. //
  5975. // Purpose: Allows the user to grab a bitmap of an area of the screen
  5976. //
  5977. //
  5978. void WbMainWindow::OnGrabArea(void)
  5979. {
  5980. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnGrabArea");
  5981. if (::DialogBoxParam(g_hInstance, MAKEINTRESOURCE(WARNSELECTAREA),
  5982. m_hwnd, WarnSelectAreaDlgProc, 0) != IDOK)
  5983. {
  5984. // User cancelled, so bail out
  5985. return;
  5986. }
  5987. // Hide the application windows
  5988. ::ShowWindow(m_hwnd, SW_HIDE);
  5989. // Load the grabbing cursors
  5990. HCURSOR hGrabCursor = ::LoadCursor(g_hInstance, MAKEINTRESOURCE( PENCURSOR ) );
  5991. // Capture the mouse
  5992. UT_CaptureMouse(m_hwnd);
  5993. // Ensure we receive all keyboard messages.
  5994. ::SetFocus(m_hwnd);
  5995. // Reset the CancelMode status
  5996. ResetCancelMode();
  5997. // Change to the grab cursor
  5998. HCURSOR hOldCursor = ::SetCursor(hGrabCursor);
  5999. // Let the user select the area to be grabbed
  6000. RECT rect;
  6001. int tmp;
  6002. GetGrabArea(&rect);
  6003. // Normalize coords
  6004. if (rect.right < rect.left)
  6005. {
  6006. tmp = rect.left;
  6007. rect.left = rect.right;
  6008. rect.right = tmp;
  6009. }
  6010. if (rect.bottom < rect.top)
  6011. {
  6012. tmp = rect.top;
  6013. rect.top = rect.bottom;
  6014. rect.bottom = tmp;
  6015. }
  6016. DCWbGraphicDIB dib;
  6017. if (!::IsRectEmpty(&rect))
  6018. {
  6019. // Get a bitmap copy of the screen area
  6020. dib.FromScreenArea(&rect);
  6021. }
  6022. // Show the windows again now - if we do it later we get the bitmap to
  6023. // be added re-drawn twice (once on the window show and once when the
  6024. // graphic added indication arrives).
  6025. ::ShowWindow(m_hwnd, SW_SHOW);
  6026. ::UpdateWindow(m_hwnd);
  6027. if (!::IsRectEmpty(&rect))
  6028. {
  6029. // Add the bitmap
  6030. AddCapturedImage(dib);
  6031. // Force the selection tool to be selected
  6032. ::PostMessage(m_hwnd, WM_COMMAND, IDM_TOOLS_START, 0L);
  6033. }
  6034. // Release the mouse
  6035. UT_ReleaseMouse(m_hwnd);
  6036. // Restore the cursor
  6037. ::SetCursor(hOldCursor);
  6038. // Restore the focus to the drawing area
  6039. ::SetFocus(m_drawingArea.m_hwnd);
  6040. }
  6041. //
  6042. // WarnSelectArea dialog handler
  6043. //
  6044. INT_PTR CALLBACK WarnSelectAreaDlgProc(HWND hwnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
  6045. {
  6046. BOOL fHandled = FALSE;
  6047. switch (uMessage)
  6048. {
  6049. case WM_INITDIALOG:
  6050. if (OPT_GetBooleanOption(OPT_MAIN_SELECTAREA_NOTAGAIN,
  6051. DFLT_MAIN_SELECTAREA_NOTAGAIN))
  6052. {
  6053. // End this right away, the user doesn't want a warning
  6054. ::EndDialog(hwnd, IDOK);
  6055. }
  6056. fHandled = TRUE;
  6057. break;
  6058. case WM_COMMAND:
  6059. switch (GET_WM_COMMAND_ID(wParam, lParam))
  6060. {
  6061. case IDOK:
  6062. switch (GET_WM_COMMAND_CMD(wParam, lParam))
  6063. {
  6064. case BN_CLICKED:
  6065. //
  6066. // Update settings -- note that we don't have to write out
  6067. // FALSE--we wouldn't be in the dialog in the first place
  6068. // if the current setting weren't already FALSE.
  6069. //
  6070. if (::IsDlgButtonChecked(hwnd, IDC_SAWARN_NOTAGAIN))
  6071. {
  6072. OPT_SetBooleanOption(OPT_MAIN_SELECTAREA_NOTAGAIN, TRUE);
  6073. }
  6074. ::EndDialog(hwnd, IDOK);
  6075. break;
  6076. }
  6077. break;
  6078. case IDCANCEL:
  6079. switch (GET_WM_COMMAND_CMD(wParam, lParam))
  6080. {
  6081. case BN_CLICKED:
  6082. ::EndDialog(hwnd, IDCANCEL);
  6083. break;
  6084. }
  6085. }
  6086. fHandled = TRUE;
  6087. break;
  6088. }
  6089. return(fHandled);
  6090. }
  6091. //
  6092. //
  6093. // Function: GetGrabArea
  6094. //
  6095. // Purpose: Allows the user to grab a bitmap of an area of the screen
  6096. //
  6097. //
  6098. void WbMainWindow::GetGrabArea(LPRECT lprect)
  6099. {
  6100. POINT mousePos; // Mouse position
  6101. MSG msg; // Current message
  6102. BOOL tracking = FALSE; // Flag indicating mouse button is down
  6103. HDC hDC = NULL;
  6104. POINT grabStartPoint; // Start point (when mouse button is pressed)
  6105. POINT grabEndPoint; // End point (when mouse button is released)
  6106. POINT grabCurrPoint; // Current mouse position
  6107. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::GetGrabArea");
  6108. // Set the result to an empty rectangle
  6109. ::SetRectEmpty(lprect);
  6110. // Create the rectangle to be used for tracking
  6111. DCWbGraphicTrackingRectangle rectangle;
  6112. rectangle.SetColor(RGB(0, 0, 0));
  6113. rectangle.SetPenWidth(1);
  6114. rectangle.SetPenStyle(PS_DOT);
  6115. // Get the DC for tracking
  6116. HWND hDesktopWnd = ::GetDesktopWindow();
  6117. hDC = ::GetWindowDC(hDesktopWnd);
  6118. if (hDC == NULL)
  6119. {
  6120. WARNING_OUT(("NULL desktop DC"));
  6121. goto GrabAreaCleanup;
  6122. }
  6123. // Trap all mouse messages until a WM_LBUTTONUP is received
  6124. for ( ; ; )
  6125. {
  6126. // Wait for the next message
  6127. ::WaitMessage();
  6128. // Cancel if we have been sent a WM_CANCELMODE message
  6129. if (CancelModeSent())
  6130. {
  6131. TRACE_MSG(("canceling grab"));
  6132. // Erase the last tracking rectangle
  6133. if (!EqualPoint(grabStartPoint, grabEndPoint))
  6134. {
  6135. rectangle.SetRectPts(grabStartPoint, grabEndPoint);
  6136. rectangle.Draw(hDC);
  6137. }
  6138. break;
  6139. }
  6140. // If it is a mouse message, process it
  6141. if (::PeekMessage(&msg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE))
  6142. {
  6143. // Get mouse position
  6144. TRACE_MSG( ("msg = %x, lParam = %0x", msg.message, msg.lParam) );
  6145. mousePos.x = (short)LOWORD(msg.lParam);
  6146. mousePos.y = (short)HIWORD(msg.lParam);
  6147. TRACE_MSG( ("mousePos = %d,%d", mousePos.x, mousePos.y) );
  6148. // Convert to screen coordinates
  6149. ::ClientToScreen(m_hwnd, &mousePos);
  6150. grabCurrPoint = mousePos;
  6151. switch (msg.message)
  6152. {
  6153. // Starting the grab
  6154. case WM_LBUTTONDOWN:
  6155. // Save the starting position
  6156. TRACE_MSG(("grabbing start position"));
  6157. grabStartPoint = mousePos;
  6158. grabEndPoint = mousePos;
  6159. tracking = TRUE;
  6160. break;
  6161. // Completing the rectangle
  6162. case WM_LBUTTONUP:
  6163. {
  6164. tracking = FALSE;
  6165. // Check that there is an area to capture
  6166. TRACE_MSG(("grabbing end position"));
  6167. if (EqualPoint(grabStartPoint, grabCurrPoint))
  6168. {
  6169. TRACE_MSG(("start == end, skipping grab"));
  6170. goto GrabAreaCleanup;
  6171. }
  6172. // Erase the last tracking rectangle
  6173. if (!EqualPoint(grabStartPoint, grabEndPoint))
  6174. {
  6175. rectangle.SetRectPts(grabStartPoint, grabEndPoint);
  6176. rectangle.Draw(hDC);
  6177. }
  6178. // Update the rectangle object
  6179. rectangle.SetRectPts(grabStartPoint, grabCurrPoint);
  6180. *lprect = *rectangle.GetRect();
  6181. // We are done
  6182. goto GrabAreaCleanup;
  6183. }
  6184. break;
  6185. // Continuing the rectangle
  6186. case WM_MOUSEMOVE:
  6187. if (tracking)
  6188. {
  6189. TRACE_MSG(("tracking grab"));
  6190. // Erase the last tracking rectangle
  6191. if (!EqualPoint(grabStartPoint, grabEndPoint))
  6192. {
  6193. rectangle.SetRectPts(grabStartPoint, grabEndPoint);
  6194. rectangle.Draw(hDC);
  6195. }
  6196. // Draw the new rectangle
  6197. if (!EqualPoint(grabStartPoint, grabCurrPoint))
  6198. {
  6199. // Save the new box end point
  6200. grabEndPoint = grabCurrPoint;
  6201. // Draw the rectangle
  6202. TRACE_MSG( ("grabStartPoint = %d,%d",
  6203. grabStartPoint.x, grabStartPoint.y) );
  6204. TRACE_MSG( ("grabEndPoint = %d,%d",
  6205. grabEndPoint.x, grabEndPoint.y) );
  6206. rectangle.SetRectPts(grabStartPoint, grabEndPoint);
  6207. rectangle.Draw(hDC);
  6208. }
  6209. }
  6210. break;
  6211. }
  6212. }
  6213. // Cancel if ESCAPE is pressed.
  6214. else if (::PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
  6215. {
  6216. if( ((msg.message == WM_KEYUP)||(msg.message == WM_SYSKEYUP))&&
  6217. (msg.wParam == VK_ESCAPE) )
  6218. {
  6219. TRACE_MSG(("grab cancelled by ESC"));
  6220. // Erase the last tracking rectangle
  6221. if (!EqualPoint(grabStartPoint, grabEndPoint))
  6222. {
  6223. rectangle.SetRectPts(grabStartPoint, grabEndPoint);
  6224. rectangle.Draw(hDC);
  6225. }
  6226. break;
  6227. }
  6228. }
  6229. }
  6230. GrabAreaCleanup:
  6231. // Release the device context (if we have it)
  6232. if (hDC != NULL)
  6233. {
  6234. ::ReleaseDC(hDesktopWnd, hDC);
  6235. }
  6236. }
  6237. //
  6238. //
  6239. // Function: AddCapturedImage
  6240. //
  6241. // Purpose: Add a bitmap to the contents (adding a new page for it
  6242. // if necessary).
  6243. //
  6244. //
  6245. void WbMainWindow::AddCapturedImage(DCWbGraphicDIB& dib)
  6246. {
  6247. // Position the grabbed object at the top left of the currently visible
  6248. // area.
  6249. RECT rcVis;
  6250. m_drawingArea.GetVisibleRect(&rcVis);
  6251. dib.MoveTo(rcVis.left, rcVis.top);
  6252. // Add the new grabbed bitmap
  6253. dib.AddToPageLast(m_hCurrentPage);
  6254. }
  6255. //
  6256. //
  6257. // Function: OnPrint
  6258. //
  6259. // Purpose: Print the contents of the drawing pane
  6260. //
  6261. //
  6262. void WbMainWindow::OnPrint()
  6263. {
  6264. BOOL bPrintError = FALSE;
  6265. PRINTDLG pd;
  6266. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnPrint");
  6267. if (!IsIdle())
  6268. {
  6269. // post an error message indicating the whiteboard is busy
  6270. ::PostMessage(m_hwnd, WM_USER_DISPLAY_ERROR, WBFE_RC_WB, WB_RC_BUSY);
  6271. return;
  6272. }
  6273. //
  6274. // Initialize the PRINTDLG structure
  6275. //
  6276. ZeroMemory(&pd, sizeof(pd));
  6277. pd.lStructSize = sizeof(pd);
  6278. pd.hInstance = g_hInstance;
  6279. pd.hwndOwner = m_hwnd;
  6280. pd.Flags = PD_ALLPAGES | PD_RETURNDC | PD_PAGENUMS |
  6281. PD_HIDEPRINTTOFILE | PD_NOSELECTION;
  6282. pd.nMinPage = 1;
  6283. pd.nMaxPage = (WORD)g_pwbCore->WBP_ContentsCountPages();
  6284. pd.nFromPage = pd.nMinPage;
  6285. pd.nToPage = pd.nMaxPage;
  6286. // Put up the COMMDLG print dialog
  6287. if (::PrintDlg(&pd))
  6288. {
  6289. int nStartPage, nEndPage;
  6290. // Get the start and end page numbers to be printed
  6291. if (pd.Flags & PD_PAGENUMS)
  6292. {
  6293. nStartPage = pd.nFromPage;
  6294. nEndPage = pd.nToPage;
  6295. }
  6296. else
  6297. {
  6298. nStartPage = pd.nMinPage;
  6299. nEndPage = pd.nMaxPage;
  6300. }
  6301. // Check whether any pages are to be printed
  6302. if (nStartPage <= pd.nMaxPage)
  6303. {
  6304. // Ensure that the start and end pages lie within range.
  6305. nStartPage = max(nStartPage, pd.nMinPage);
  6306. nEndPage = min(nEndPage, pd.nMaxPage);
  6307. // Get the printer and output port names.
  6308. // These are written to the dialog for the user to see
  6309. // in the OnInitDialog member.
  6310. TCHAR szDeviceName[2*_MAX_PATH];
  6311. LPDEVNAMES lpDev;
  6312. // Device name
  6313. if (pd.hDevNames == NULL)
  6314. {
  6315. szDeviceName[0] = 0;
  6316. }
  6317. else
  6318. {
  6319. lpDev = (LPDEVNAMES)::GlobalLock(pd.hDevNames);
  6320. wsprintf(szDeviceName, "%s %s",
  6321. (LPCTSTR)lpDev + lpDev->wDeviceOffset,
  6322. (LPCTSTR)lpDev + lpDev->wOutputOffset);
  6323. ::GlobalUnlock(pd.hDevNames);
  6324. }
  6325. //
  6326. // Tell the printer we are starting the print.
  6327. // Note that the printer object handles the cancellation dialog.
  6328. WbPrinter printer(szDeviceName);
  6329. TCHAR szJobName[_MAX_PATH];
  6330. ::LoadString(g_hInstance, IDS_PRINT_NAME, szJobName, _MAX_PATH);
  6331. int nPrintResult = printer.StartDoc(pd.hDC, szJobName, nStartPage);
  6332. if (nPrintResult < 0)
  6333. {
  6334. WARNING_OUT(("Print result %d", nPrintResult));
  6335. bPrintError = TRUE;
  6336. }
  6337. else
  6338. {
  6339. // Find out how many copies to print
  6340. int copyNum;
  6341. copyNum = 0;
  6342. while ((copyNum < pd.nCopies) && !bPrintError)
  6343. {
  6344. // Loop through all pages
  6345. int nPrintPage;
  6346. WB_PAGE_HANDLE hPage;
  6347. for (nPrintPage = nStartPage; nPrintPage <= nEndPage; nPrintPage++)
  6348. {
  6349. // Get the first page
  6350. hPage = PG_GetPageNumber((WORD) nPrintPage);
  6351. // Only print the page if there are some objects on it
  6352. if (g_pwbCore->WBP_PageCountGraphics(hPage) > 0)
  6353. {
  6354. // Tell the printer we are starting a new page
  6355. printer.StartPage(pd.hDC, nPrintPage);
  6356. if (!printer.Error())
  6357. {
  6358. RECT rectArea;
  6359. rectArea.left = 0;
  6360. rectArea.top = 0;
  6361. rectArea.right = DRAW_WIDTH;
  6362. rectArea.bottom = DRAW_HEIGHT;
  6363. // Print the page
  6364. PG_Print(hPage, pd.hDC, &rectArea);
  6365. // Inform the printer that the page is complete
  6366. printer.EndPage(pd.hDC);
  6367. }
  6368. else
  6369. {
  6370. bPrintError = TRUE;
  6371. break;
  6372. }
  6373. }
  6374. }
  6375. copyNum++;
  6376. }
  6377. // The print has completed
  6378. nPrintResult = printer.EndDoc(pd.hDC);
  6379. if (nPrintResult < 0)
  6380. {
  6381. WARNING_OUT(("Print result %d", nPrintResult));
  6382. bPrintError = TRUE;
  6383. }
  6384. // reset the error if the user cancelled the print
  6385. if (printer.Aborted())
  6386. {
  6387. WARNING_OUT(("User cancelled print"));
  6388. bPrintError = FALSE;
  6389. }
  6390. }
  6391. }
  6392. }
  6393. // Inform the user if an error occurred
  6394. if (bPrintError)
  6395. {
  6396. // display a message informing the user the job terminated
  6397. ::PostMessage(m_hwnd, WM_USER_DISPLAY_ERROR, WBFE_RC_PRINTER, 0);
  6398. }
  6399. //
  6400. // Cleanup the hDevMode, hDevNames, and hdc blocks if allocated
  6401. //
  6402. if (pd.hDevMode != NULL)
  6403. {
  6404. ::GlobalFree(pd.hDevMode);
  6405. pd.hDevMode = NULL;
  6406. }
  6407. if (pd.hDevNames != NULL)
  6408. {
  6409. ::GlobalFree(pd.hDevNames);
  6410. pd.hDevNames = NULL;
  6411. }
  6412. if (pd.hDC != NULL)
  6413. {
  6414. ::DeleteDC(pd.hDC);
  6415. pd.hDC = NULL;
  6416. }
  6417. }
  6418. //
  6419. //
  6420. // Function: OnPageSorter
  6421. //
  6422. // Purpose: Re-order the pages
  6423. //
  6424. //
  6425. void WbMainWindow::OnPageSorter()
  6426. {
  6427. // don't call up page sorter if another user is presenting (has the contents
  6428. // locked and sync on)
  6429. if ( (m_uiState == IN_CALL)
  6430. && (!WB_PresentationMode()))
  6431. {
  6432. PAGESORT ps;
  6433. m_drawingArea.CancelDrawingMode();
  6434. // Save the lock state (in case the Page Sorter gets it)
  6435. SaveLock();
  6436. //
  6437. // Fill in the initial values
  6438. //
  6439. ZeroMemory(&ps, sizeof(ps));
  6440. ps.hCurPage = m_hCurrentPage;
  6441. ps.fPageOpsAllowed = (m_uiSubState == SUBSTATE_IDLE);
  6442. //
  6443. // Put up the dialog
  6444. //
  6445. ASSERT(m_hwndPageSortDlg == NULL);
  6446. ::DialogBoxParam(g_hInstance, MAKEINTRESOURCE(PAGESORTERDIALOG),
  6447. m_hwnd, PageSortDlgProc, (LPARAM)&ps);
  6448. ASSERT(m_hwndPageSortDlg == NULL);
  6449. // Restore the lock state
  6450. RestoreLock();
  6451. // Set up the new current page pointer
  6452. if ((ps.hCurPage != m_hCurrentPage) || ps.fChanged)
  6453. {
  6454. GotoPage((WB_PAGE_HANDLE)ps.hCurPage);
  6455. }
  6456. // Update the page number display,
  6457. // the number of the current page may have changed.
  6458. UpdateStatus();
  6459. }
  6460. }
  6461. //
  6462. //
  6463. // Function: OnInsertPageBefore
  6464. //
  6465. // Purpose: Insert a new page before the current page
  6466. //
  6467. //
  6468. void WbMainWindow::OnInsertPageBefore()
  6469. {
  6470. if (!m_bUnlockStateSettled)
  6471. {
  6472. // Disable insert button code so crazed users can't insert again before
  6473. // the conference wide page-lock status has settled. If we ask for the
  6474. // page-lock again before the last unlock has finished then something
  6475. // happens to the lock-event from the cores and we hang waiting for it
  6476. // (until our wait-timeout runs out). This arguably could be called a
  6477. // DCL core bug but I couldn't generate any convincing proof of that
  6478. // so I just fixed it on Whiteboard's end by preventing asking for the
  6479. // lock too soon.
  6480. //
  6481. // RestoreLock() will eventually set m_bUnlockStateSettled to TRUE (in
  6482. // OnWBPUnlocked() by way of the WBP_EVENT_UNLOCKED event)
  6483. MessageBeep( 0xffffffff );
  6484. return;
  6485. }
  6486. // check state before allowing action
  6487. if (!IsIdle())
  6488. {
  6489. // post an error message indicating the whiteboard is busy
  6490. ::PostMessage(m_hwnd, WM_USER_DISPLAY_ERROR, WBFE_RC_WB, WB_RC_BUSY);
  6491. return;
  6492. }
  6493. // Save the current lock status
  6494. SaveLock();
  6495. // Catch exceptions so that we can restore the lock state
  6496. // Get the Page Order Lock (with an invisible dialog)
  6497. BOOL bGotLock = GetLock(WB_LOCK_TYPE_PAGE_ORDER, SW_HIDE);
  6498. if (bGotLock)
  6499. {
  6500. UINT uiRet;
  6501. WB_PAGE_HANDLE hPage;
  6502. // Set flag to prevent any more inserts until
  6503. // we have completely released the page-lock
  6504. m_bUnlockStateSettled = FALSE;
  6505. // Add the new page to the list (throws an exception on failure)
  6506. uiRet = g_pwbCore->WBP_PageAddBefore(m_hCurrentPage, &hPage);
  6507. if (uiRet != 0)
  6508. {
  6509. DefaultExceptionHandler(WBFE_RC_WB, uiRet);
  6510. return;
  6511. }
  6512. // Go to the inserted page
  6513. GotoPage(hPage);
  6514. }
  6515. //CHANGED BY RAND
  6516. // Restore the lock status. This will eventually set m_bUnlockStateSettled
  6517. // to TRUE (in OnWBPUnlocked() by way of the WBP_EVENT_UNLOCKED event)
  6518. // and enable this function after the conference wide lock-status
  6519. // has settled.
  6520. RestoreLock();
  6521. }
  6522. //
  6523. //
  6524. // Function: InsertPageAfter
  6525. //
  6526. // Purpose: Insert a new page after the specified page.
  6527. //
  6528. //
  6529. void WbMainWindow::InsertPageAfter(WB_PAGE_HANDLE hPageAfter)
  6530. {
  6531. if (!m_bUnlockStateSettled)
  6532. {
  6533. // Disable insert button code so crazed users can't insert again before
  6534. // the conference wide page-lock status has settled. If we ask for the
  6535. // page-lock again before the last unlock has finished then something
  6536. // happens to the lock-event from the cores and we hang waiting for it
  6537. // (until our wait-timeout runs out). This arguably could be called a
  6538. // DCL core bug but I couldn't generate any convincing proof of that
  6539. // so I just fixed it on Whiteboard's end by preventing asking for the
  6540. // lock too soon.
  6541. //
  6542. // RestoreLock() will eventually set m_bUnlockStateSettled to TRUE (in
  6543. // OnWBPUnlocked() by way of the WBP_EVENT_UNLOCKED event)
  6544. MessageBeep( 0xffffffff );
  6545. return;
  6546. }
  6547. // check state before allowing action
  6548. if (!IsIdle())
  6549. {
  6550. // post an error message indicating the whiteboard is busy
  6551. ::PostMessage(m_hwnd, WM_USER_DISPLAY_ERROR, WBFE_RC_WB, WB_RC_BUSY);
  6552. return;
  6553. }
  6554. // Save the current lock status
  6555. SaveLock();
  6556. // Catch exceptions so that we can restore the lock state
  6557. BOOL bGotLock = GetLock(WB_LOCK_TYPE_PAGE_ORDER, SW_HIDE);
  6558. if (bGotLock)
  6559. {
  6560. UINT uiRet;
  6561. WB_PAGE_HANDLE hPage;
  6562. // Set flag to prevent any more inserts until
  6563. // we have completely released the page-lock
  6564. m_bUnlockStateSettled = FALSE;
  6565. uiRet = g_pwbCore->WBP_PageAddAfter(hPageAfter, &hPage);
  6566. if (uiRet != 0)
  6567. {
  6568. DefaultExceptionHandler(WBFE_RC_WB, uiRet);
  6569. return;
  6570. }
  6571. // Move to the added page
  6572. GotoPage(hPage);
  6573. }
  6574. //CHANGED BY RAND
  6575. // Restore the lock status. This will eventually set m_bUnlockStateSettled
  6576. // to TRUE (in OnWBPUnlocked() by way of the WBP_EVENT_UNLOCKED event)
  6577. // and enable this function after the conference wide lock-status
  6578. // has settled.
  6579. RestoreLock();
  6580. }
  6581. //
  6582. //
  6583. // Function: OnInsertPageAfter
  6584. //
  6585. // Purpose: Insert a new page after the current page
  6586. //
  6587. //
  6588. void WbMainWindow::OnInsertPageAfter()
  6589. {
  6590. // Insert the new page
  6591. InsertPageAfter(m_hCurrentPage);
  6592. }
  6593. //
  6594. //
  6595. // Function: OnDeletePage
  6596. //
  6597. // Purpose: Delete the current page
  6598. //
  6599. //
  6600. void WbMainWindow::OnDeletePage()
  6601. {
  6602. int iResult;
  6603. BOOL bWasPosted;
  6604. if (!m_bUnlockStateSettled)
  6605. {
  6606. // Disable delete button code so crazed users can't delete again before
  6607. // the conference wide page-lock status has settled. If we ask for the
  6608. // page-lock again before the last unlock has finished then something
  6609. // happens to the lock-event from the cores and we hang waiting for it
  6610. // (until our wait-timeout runs out). This arguably could be called a
  6611. // DCL core bug but I couldn't generate any convincing proof of that
  6612. // so I just fixed it on Whiteboard's end by preventing asking for the
  6613. // lock too soon.
  6614. //
  6615. // RestoreLock() will eventually set m_bUnlockStateSettled to TRUE (in
  6616. // OnWBPUnlocked() by way of the WBP_EVENT_UNLOCKED event)
  6617. MessageBeep( 0xffffffff );
  6618. return;
  6619. }
  6620. // check state
  6621. if (!IsIdle())
  6622. {
  6623. // post an error message indicating the whiteboard is busy
  6624. ::PostMessage(m_hwnd, WM_USER_DISPLAY_ERROR, WBFE_RC_WB, WB_RC_BUSY);
  6625. return;
  6626. }
  6627. // Display a message box with the relevant question
  6628. if( UsersMightLoseData( &bWasPosted, NULL ) ) // bug NM4db:418
  6629. return;
  6630. if( bWasPosted )
  6631. iResult = IDYES;
  6632. else
  6633. iResult = ::Message(NULL, IDS_DELETE_PAGE, IDS_DELETE_PAGE_MESSAGE, MB_YESNO | MB_ICONQUESTION);
  6634. // If the user wants to continue with the delete
  6635. if (iResult == IDYES)
  6636. {
  6637. // If this is the only page
  6638. if (g_pwbCore->WBP_ContentsCountPages() == 1)
  6639. {
  6640. // Just clear it. The core does handle this
  6641. // case but it is better not to get the lock unnecessarily, the
  6642. // lock is required to call the core delete page function.
  6643. m_drawingArea.Clear();
  6644. }
  6645. else
  6646. {
  6647. // Lock the drawing area - this ensures we cannot draw to a bad page
  6648. // It will normally be unlocked when we get the corresponding page
  6649. // delete indication
  6650. // - moved until after we have got the page order lock
  6651. //LockDrawingArea();
  6652. // Save the current lock status
  6653. SaveLock();
  6654. // Catch exceptions so that we can restore the lock state
  6655. // Get the Page Order Lock (with an invisible dialog)
  6656. BOOL bGotLock = GetLock(WB_LOCK_TYPE_PAGE_ORDER, SW_HIDE);
  6657. if (bGotLock)
  6658. {
  6659. UINT uiRet;
  6660. // Set flag to prevent any more inserts until
  6661. // we have completely released the page-lock
  6662. m_bUnlockStateSettled = FALSE;
  6663. // Lock the drawing area - this ensures we cannot draw to a bad page
  6664. // It will normally be unlocked when we get the corresponding page
  6665. // delete indication
  6666. LockDrawingArea();
  6667. // Delete the page. The page is not deleted immediately but a
  6668. // WBP_EVENT_PAGE_DELETED event is generated.
  6669. uiRet = g_pwbCore->WBP_PageDelete(m_hCurrentPage);
  6670. if (uiRet != 0)
  6671. {
  6672. DefaultExceptionHandler(WBFE_RC_WB, uiRet);
  6673. return;
  6674. }
  6675. }
  6676. //CHANGED BY RAND
  6677. // Restore the lock status. This will eventually set m_bUnlockStateSettled
  6678. // to TRUE (in OnWBPUnlocked() by way of the WBP_EVENT_UNLOCKED event)
  6679. // and enable this function after the conference wide lock-status
  6680. // has settled.
  6681. RestoreLock();
  6682. }
  6683. }
  6684. }
  6685. //
  6686. //
  6687. // Function: OnRemotePointer
  6688. //
  6689. // Purpose: Create a remote pointer
  6690. //
  6691. //
  6692. void WbMainWindow::OnRemotePointer(void)
  6693. {
  6694. if (!m_pLocalUser)
  6695. return;
  6696. DCWbGraphicPointer* pPointer = m_pLocalUser->GetPointer();
  6697. // This function toggles the presence of the user's remote pointer
  6698. ASSERT(pPointer != NULL);
  6699. if (pPointer->IsActive())
  6700. {
  6701. // Turn off the pointer in the user information
  6702. pPointer->SetInactive();
  6703. // Tell the drawing area of the change
  6704. m_drawingArea.PointerUpdated(pPointer);
  6705. // Set the check mark on the menu item
  6706. UncheckMenuItem(IDM_REMOTE);
  6707. // Pop up the sync button
  6708. m_TB.PopUp(IDM_REMOTE);
  6709. }
  6710. else
  6711. {
  6712. // Calculate a position at which to drop the pointer. The centre of the
  6713. // remote pointer is placed in the centre of the currently visible
  6714. // area of the surface (the centre of the drawing area window).
  6715. RECT rectVisible;
  6716. RECT rectPointer;
  6717. POINT ptCenter;
  6718. m_drawingArea.GetVisibleRect(&rectVisible);
  6719. pPointer->GetBoundsRect(&rectPointer);
  6720. ptCenter.x = (rectVisible.left + rectVisible.right) / 2;
  6721. ptCenter.x -= ((rectPointer.right - rectPointer.left) / 2);
  6722. ptCenter.y = (rectVisible.top + rectVisible.bottom) / 2;
  6723. ptCenter.y -= ((rectPointer.bottom - rectPointer.top) / 2);
  6724. // Turn on the pointer in the user information
  6725. pPointer->SetActive(m_hCurrentPage, ptCenter);
  6726. // Tell the drawing area of the change
  6727. m_drawingArea.PointerUpdated(pPointer);
  6728. // Set the synced check mark
  6729. CheckMenuItem(IDM_REMOTE);
  6730. // Pop up the sync button
  6731. m_TB.PushDown(IDM_REMOTE);
  6732. // Force the selection tool to be selected
  6733. ::PostMessage(m_hwnd, WM_COMMAND, IDM_TOOLS_START, 0L);
  6734. }
  6735. // Restore the focus to the drawing area
  6736. ::SetFocus(m_drawingArea.m_hwnd);
  6737. }
  6738. //
  6739. //
  6740. // Function: OnSync
  6741. //
  6742. // Purpose: Sync or unsync the Whiteboard with other users
  6743. //
  6744. //
  6745. void WbMainWindow::OnSync(void)
  6746. {
  6747. // disabled if in presentation mode (another user has lock & sync on)
  6748. if (!WB_PresentationMode())
  6749. {
  6750. if (m_pLocalUser != NULL)
  6751. {
  6752. // Determine whether we are currently synced
  6753. if (m_pLocalUser->IsSynced())
  6754. {
  6755. // currently synced, so unsync
  6756. Unsync();
  6757. }
  6758. else
  6759. {
  6760. // currently unsynced, so sync
  6761. Sync();
  6762. }
  6763. }
  6764. }
  6765. // Restore the focus to the drawing area
  6766. ::SetFocus(m_drawingArea.m_hwnd);
  6767. }
  6768. //
  6769. //
  6770. // Function: Sync
  6771. //
  6772. // Purpose: Sync the Whiteboard with other users
  6773. //
  6774. //
  6775. void WbMainWindow::Sync(void)
  6776. {
  6777. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::Sync");
  6778. //
  6779. // Dont do anything if the local user is already synced.
  6780. //
  6781. if (!m_pLocalUser || m_pLocalUser->IsSynced())
  6782. {
  6783. TRACE_DEBUG(("User already synced"));
  6784. return;
  6785. }
  6786. //
  6787. // Update the local user's position information, to make sure it's up
  6788. // to date.
  6789. //
  6790. RECT rcVisDraw;
  6791. RECT rcVisUser;
  6792. m_drawingArea.GetVisibleRect(&rcVisDraw);
  6793. m_pLocalUser->SetVisibleRect(&rcVisDraw);
  6794. //
  6795. // We are not currently synced - sync now (if we have the contents
  6796. // lock, or are the first to sync, it will put our sync position).
  6797. //
  6798. m_pLocalUser->Sync();
  6799. //
  6800. // Set the synced check mark and pop up the sync button.
  6801. //
  6802. CheckMenuItem(IDM_SYNC);
  6803. m_TB.PushDown(IDM_SYNC);
  6804. //
  6805. // If the sync position (or zoom state) chosen was not where we are
  6806. // now, move to the current sync position (we are joining a set of
  6807. // synced users).
  6808. //
  6809. m_drawingArea.GetVisibleRect(&rcVisDraw);
  6810. m_pLocalUser->GetVisibleRect(&rcVisUser);
  6811. if ( (m_pLocalUser->Page() != m_hCurrentPage) ||
  6812. (!::EqualRect(&rcVisUser, &rcVisDraw)) ||
  6813. (m_pLocalUser->GetZoom() != m_drawingArea.Zoomed()) ) //CHANGED BY RAND
  6814. {
  6815. TRACE_DEBUG(("Move to new sync pos/state"));
  6816. ::PostMessage(m_hwnd, WM_USER_GOTO_USER_POSITION, 0, (LPARAM)m_pLocalUser->Handle());
  6817. }
  6818. } // Sync
  6819. //
  6820. //
  6821. // Function: Unsync
  6822. //
  6823. // Purpose: Unsync the Whiteboard with other users
  6824. //
  6825. //
  6826. void WbMainWindow::Unsync(void)
  6827. {
  6828. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::Unsync");
  6829. //
  6830. // Dont do anythig if we are already unsynced.
  6831. //
  6832. if (!m_pLocalUser || !m_pLocalUser->IsSynced())
  6833. {
  6834. TRACE_DEBUG(("Already unsynced"));
  6835. return;
  6836. }
  6837. //
  6838. // Unsync.
  6839. // Set the synced check mark and pop up the sync button.
  6840. //
  6841. m_pLocalUser->Unsync();
  6842. UncheckMenuItem(IDM_SYNC);
  6843. m_TB.PopUp(IDM_SYNC);
  6844. } // Unsync
  6845. //
  6846. //
  6847. // Function: SaveLock
  6848. //
  6849. // Purpose: Save the current lock type
  6850. //
  6851. //
  6852. void WbMainWindow::SaveLock(void)
  6853. {
  6854. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::SaveLock");
  6855. m_uiSavedLockType = WB_LOCK_TYPE_NONE;
  6856. // If we have the contents lock
  6857. if (WB_GotContentsLock())
  6858. {
  6859. TRACE_MSG(("Saved contents lock"));
  6860. m_uiSavedLockType = WB_LOCK_TYPE_CONTENTS;
  6861. }
  6862. else
  6863. {
  6864. // If we have the page order lock
  6865. if (WB_GotLock())
  6866. {
  6867. TRACE_MSG(("Saved page order lock"));
  6868. m_uiSavedLockType = WB_LOCK_TYPE_PAGE_ORDER;
  6869. }
  6870. }
  6871. }
  6872. //
  6873. //
  6874. // Function: RestoreLock
  6875. //
  6876. // Purpose: Restore the current lock type (SaveLock must have been
  6877. // called previously.
  6878. //
  6879. //
  6880. void WbMainWindow::RestoreLock(void)
  6881. {
  6882. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::RestoreLock");
  6883. switch(m_uiSavedLockType)
  6884. {
  6885. case WB_LOCK_TYPE_CONTENTS:
  6886. // If we do not have the contents lock
  6887. if (!WB_GotContentsLock())
  6888. {
  6889. // Get the contents lock (with invisible dialog)
  6890. TRACE_MSG(("Restoring contents lock"));
  6891. GetLock(WB_LOCK_TYPE_CONTENTS, SW_HIDE);
  6892. }
  6893. // we really own the lock, clear settled flag so page buttons don't hang
  6894. m_bUnlockStateSettled = TRUE;
  6895. break;
  6896. case WB_LOCK_TYPE_PAGE_ORDER:
  6897. if (!WB_GotLock() || WB_GotContentsLock())
  6898. {
  6899. // Get the page order lock (with invisible dialog)
  6900. TRACE_MSG(("Restoring page order lock"));
  6901. GetLock(WB_LOCK_TYPE_PAGE_ORDER, SW_HIDE);
  6902. }
  6903. //ADDED BY RAND- we really own the lock, clear settled flag
  6904. // so page buttons don't hang
  6905. m_bUnlockStateSettled = TRUE;
  6906. break;
  6907. case WB_LOCK_TYPE_NONE:
  6908. // If we have the lock
  6909. if (WB_GotLock())
  6910. {
  6911. // Release the lock
  6912. TRACE_MSG(("Restoring no lock"));
  6913. // Let WBP_EVENT_LOCKED handle m_bUnlockStateSettled flag
  6914. g_pwbCore->WBP_Unlock();
  6915. }
  6916. break;
  6917. default:
  6918. // We have saved an invalid lock type
  6919. ERROR_OUT(("Bad saved lock type"));
  6920. //ADDED BY RAND- somethings broken, clear settled flag
  6921. // so page buttons don't hang
  6922. m_bUnlockStateSettled = TRUE;
  6923. break;
  6924. }
  6925. }
  6926. //
  6927. //
  6928. // Function: GetLock
  6929. //
  6930. // Purpose: Get the Page Order Lock (synchronously)
  6931. //
  6932. //
  6933. BOOL WbMainWindow::GetLock(UINT uiLockType, UINT uiHide)
  6934. {
  6935. BOOL bGotRequiredLock = FALSE;
  6936. BOOL bCancelled = FALSE;
  6937. UINT uiDialogReturn = 0;
  6938. UINT lDialogDelay = 1;
  6939. UINT lTimeout = 0;
  6940. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::GetLock");
  6941. switch(uiLockType)
  6942. {
  6943. case WB_LOCK_TYPE_PAGE_ORDER:
  6944. TRACE_DEBUG(("WB_LOCK_TYPE_PAGE_ORDER"));
  6945. if (WB_GotLock())
  6946. {
  6947. TRACE_DEBUG(("Already got it"));
  6948. bGotRequiredLock = TRUE;
  6949. goto RestoreLockCleanup;
  6950. }
  6951. break;
  6952. case WB_LOCK_TYPE_CONTENTS:
  6953. TRACE_DEBUG(("WB_LOCK_TYPE_CONTENTS"));
  6954. if (WB_GotContentsLock())
  6955. {
  6956. TRACE_DEBUG(("Already got it"));
  6957. bGotRequiredLock = TRUE;
  6958. goto RestoreLockCleanup;
  6959. }
  6960. break;
  6961. default:
  6962. ERROR_OUT(("Invalid lock type requested"));
  6963. break;
  6964. }
  6965. if (WB_Locked())
  6966. {
  6967. TRACE_DEBUG(("Contents already locked"));
  6968. goto RestoreLockCleanup;
  6969. }
  6970. // check for any object locks
  6971. BOOL bAnObjectIsLocked;
  6972. WB_PAGE_HANDLE hPage;
  6973. DCWbGraphic* pGraphic;
  6974. bAnObjectIsLocked = FALSE;
  6975. hPage = m_drawingArea.Page();
  6976. if (hPage != WB_PAGE_HANDLE_NULL)
  6977. {
  6978. WB_GRAPHIC_HANDLE hStart;
  6979. pGraphic = PG_First(hPage, &hStart);
  6980. while (pGraphic != NULL)
  6981. {
  6982. // get object lock
  6983. bAnObjectIsLocked = pGraphic->Locked();
  6984. // Release the current graphic
  6985. delete pGraphic;
  6986. // check object lock
  6987. if( bAnObjectIsLocked )
  6988. break;
  6989. // Get the next one
  6990. pGraphic = PG_Next(hPage, &hStart, NULL);
  6991. }
  6992. }
  6993. if( bAnObjectIsLocked )
  6994. {
  6995. Message(NULL, IDS_LOCK, IDS_OBJECTSARELOCKED);
  6996. return( FALSE );
  6997. }
  6998. //
  6999. // If we get this far then we need to get the lock.
  7000. //
  7001. if (uiLockType == WB_LOCK_TYPE_PAGE_ORDER)
  7002. {
  7003. g_pwbCore->WBP_PageOrderLock();
  7004. }
  7005. else
  7006. {
  7007. g_pwbCore->WBP_ContentsLock();
  7008. }
  7009. //
  7010. // Bring up a dialog to wait for the response. This dialog is
  7011. // cancelled by the event handler code when the lock response event is
  7012. // received.
  7013. //
  7014. ASSERT(m_hwndWaitForLockDlg == NULL);
  7015. TMDLG tmdlg;
  7016. ZeroMemory(&tmdlg, sizeof(tmdlg));
  7017. tmdlg.bLockNotEvent = TRUE;
  7018. tmdlg.uiMaxDisplay = MAIN_LOCK_TIMEOUT;
  7019. if (uiHide == SW_SHOW)
  7020. {
  7021. tmdlg.bVisible = TRUE;
  7022. uiDialogReturn = (UINT)::DialogBoxParam(g_hInstance, MAKEINTRESOURCE(LOCKDIALOG),
  7023. m_hwnd, TimedDlgProc, (LPARAM)&tmdlg);
  7024. }
  7025. else
  7026. {
  7027. tmdlg.bVisible = FALSE;
  7028. uiDialogReturn = (UINT)::DialogBoxParam(g_hInstance, MAKEINTRESOURCE(INVISIBLEDIALOG),
  7029. m_hwnd, TimedDlgProc, (LPARAM)&tmdlg);
  7030. }
  7031. ASSERT(m_hwndWaitForLockDlg == NULL);
  7032. if (uiDialogReturn == IDCANCEL)
  7033. {
  7034. // The user cancelled the lock request or it timed out
  7035. TRACE_MSG(("User cancelled lock request"));
  7036. bCancelled = TRUE;
  7037. //
  7038. // If we havent already got the lock then unlock here.
  7039. //
  7040. if (!WB_GotLock())
  7041. {
  7042. TRACE_DEBUG(("Havent got lock confirmation yet - cancel it"));
  7043. g_pwbCore->WBP_Unlock();
  7044. }
  7045. goto RestoreLockCleanup;
  7046. }
  7047. switch(uiLockType)
  7048. {
  7049. case WB_LOCK_TYPE_PAGE_ORDER:
  7050. if (WB_GotLock())
  7051. {
  7052. bGotRequiredLock = TRUE;
  7053. }
  7054. break;
  7055. case WB_LOCK_TYPE_CONTENTS:
  7056. if (WB_GotContentsLock())
  7057. {
  7058. bGotRequiredLock = TRUE;
  7059. }
  7060. break;
  7061. default:
  7062. // can't get here - trapped at top.
  7063. ERROR_OUT(("Invalid lock type - internal error"));
  7064. break;
  7065. }
  7066. RestoreLockCleanup:
  7067. if (!bGotRequiredLock)
  7068. {
  7069. if( !bCancelled )
  7070. {
  7071. // post error only if user didn't cancel (bug NM4db:429)
  7072. TRACE_MSG(("Failed to get the lock"));
  7073. // post an error message indicating the failure to get the lock
  7074. ::PostMessage(m_hwnd, WM_USER_DISPLAY_ERROR, WBFE_RC_WB, WB_RC_LOCKED);
  7075. }
  7076. }
  7077. return(bGotRequiredLock);
  7078. }
  7079. //
  7080. //
  7081. // Function: OnLock
  7082. //
  7083. // Purpose: Lock or unlock the Whiteboard
  7084. //
  7085. //
  7086. void WbMainWindow::OnLock(void)
  7087. {
  7088. // If we have the lock, this is an unlock request
  7089. if (WB_GotContentsLock())
  7090. {
  7091. // if currently loading or doing a new, then restore page order lock
  7092. if (!IsIdle())
  7093. {
  7094. GetLock(WB_LOCK_TYPE_PAGE_ORDER, SW_HIDE);
  7095. }
  7096. else
  7097. {
  7098. // Release the lock
  7099. g_pwbCore->WBP_Unlock();
  7100. }
  7101. // Set the locked check mark
  7102. UncheckMenuItem(IDM_LOCK);
  7103. // Pop up the lock button
  7104. m_TB.PopUp(IDM_LOCK);
  7105. }
  7106. else
  7107. {
  7108. // If another user has the lock.
  7109. // We should not usually get here if another user has the lock because
  7110. // the Lock menu entry (and button) will be grayed.
  7111. if (WB_ContentsLocked())
  7112. {
  7113. // Display a message
  7114. Message(NULL, IDS_LOCK, IDS_LOCK_ERROR);
  7115. }
  7116. else
  7117. {
  7118. // Save the current lock state (in case the user cancels the request)
  7119. SaveLock();
  7120. // Catch exceptions raised during the lock request
  7121. // Request the lock
  7122. BOOL bGotLock = GetLock(WB_LOCK_TYPE_CONTENTS, SW_SHOW);
  7123. if (!bGotLock)
  7124. {
  7125. RestoreLock();
  7126. }
  7127. else
  7128. {
  7129. // Turn sync on and write our sync position
  7130. Sync();
  7131. m_pLocalUser->PutSyncPosition();
  7132. }
  7133. }
  7134. }
  7135. // Restore the focus to the drawing area
  7136. ::SetFocus(m_drawingArea.m_hwnd);
  7137. }
  7138. //
  7139. //
  7140. // Function : OnWBPLoadComplete
  7141. //
  7142. // Purpose : Finished loading a file
  7143. //
  7144. //
  7145. void WbMainWindow::OnWBPLoadComplete(void)
  7146. {
  7147. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnWBPLoadComplete");
  7148. if (m_uiSubState == SUBSTATE_LOADING)
  7149. {
  7150. TRACE_MSG(("Load has completed OK"));
  7151. SetSubstate(SUBSTATE_IDLE);
  7152. if (WB_GotLock())
  7153. {
  7154. }
  7155. ReleasePageOrderLock();
  7156. }
  7157. else
  7158. {
  7159. TRACE_MSG(("Unexpected WBP_EVENT_LOAD_COMPLETE event ignored"));
  7160. }
  7161. }
  7162. //
  7163. //
  7164. // Function : OnWBPLoadFailed
  7165. //
  7166. // Purpose : Finished loading a file
  7167. //
  7168. //
  7169. void WbMainWindow::OnWBPLoadFailed(void)
  7170. {
  7171. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnWBPLoadFailed");
  7172. if (m_uiSubState == SUBSTATE_LOADING)
  7173. {
  7174. ::PostMessage(m_hwnd, WM_USER_DISPLAY_ERROR, WBFE_RC_WB, WB_RC_BAD_FILE_FORMAT);
  7175. TRACE_MSG(("Load has failed - tell the user about it..."));
  7176. SetSubstate(SUBSTATE_IDLE);
  7177. ReleasePageOrderLock();
  7178. }
  7179. else
  7180. {
  7181. TRACE_MSG(("Unexpected WBP_EVENT_LOAD_FAILED event ignored"));
  7182. }
  7183. }
  7184. //
  7185. //
  7186. // Function: GetWindowTitle
  7187. //
  7188. // Purpose: Return a string for the window title
  7189. //
  7190. //
  7191. TCHAR * WbMainWindow::GetWindowTitle()
  7192. {
  7193. // Calculate the size we will need
  7194. int strSize=0;
  7195. if( m_pLockOwner != NULL )
  7196. {
  7197. strSize = lstrlen(m_pLockOwner->Name());
  7198. }
  7199. // This is the worst scenario, the total size would be less than 2*_MAX_FNAME
  7200. // but we give a lot of space for localization.
  7201. int totalSize = 2*(_MAX_FNAME)
  7202. + strSize + 1
  7203. +3*(_MAX_FNAME); // account for the following strings, the total is probably < 200
  7204. // IDS_UNTITLED
  7205. // IDS_TITLE_SEPARATOR
  7206. // IDS_DEFAULT
  7207. // IDS_IN_CALL
  7208. // IDS_IN_CALL_OTHERS
  7209. // IDS_JOINING
  7210. // IDS_INITIALIZING
  7211. // IDS_NOT_IN_CALL
  7212. // IDS_LOCKEDTITLE
  7213. TCHAR *pTitle = new TCHAR[totalSize];
  7214. if (!pTitle)
  7215. {
  7216. ERROR_OUT(("GetWindowTitle: failed to allocate TCHAR array"));
  7217. return(NULL);
  7218. }
  7219. TCHAR inUseBy[_MAX_PATH];
  7220. TCHAR *pStartTitle = pTitle;
  7221. // Set title to either the "Untitled" string, or the loaded file name
  7222. if( (!lstrlen(m_strFileName))||
  7223. (GetFileTitle( m_strFileName, pTitle, 2*_MAX_FNAME ) != 0) )
  7224. {
  7225. strSize = ::LoadString(g_hInstance, IDS_UNTITLED, pTitle, totalSize );
  7226. pTitle+=strSize;
  7227. ASSERT(totalSize>strSize);
  7228. totalSize -=strSize;
  7229. }
  7230. else
  7231. {
  7232. strSize = lstrlen(pTitle);
  7233. pTitle +=strSize;;
  7234. ASSERT(totalSize>strSize);
  7235. totalSize -=strSize;
  7236. }
  7237. // Get the separator from resources
  7238. strSize = ::LoadString(g_hInstance, IDS_TITLE_SEPARATOR, pTitle, totalSize);
  7239. pTitle+=strSize;;
  7240. ASSERT(totalSize>strSize);
  7241. totalSize -=strSize;
  7242. // Get the application title from options
  7243. strSize = ::LoadString(g_hInstance, IDS_DEFAULT, pTitle, totalSize );
  7244. pTitle+=strSize;
  7245. ASSERT(totalSize>strSize);
  7246. totalSize -=strSize;
  7247. // Add either "In Call" or "Not in Call", or "Initialising" or
  7248. // "Joining a call"
  7249. strSize = ::LoadString(g_hInstance, IDS_TITLE_SEPARATOR, pTitle, totalSize);
  7250. pTitle+=strSize;
  7251. ASSERT(totalSize>strSize);
  7252. totalSize -=strSize;
  7253. if ((m_uiState == IN_CALL) && m_bCallActive)
  7254. {
  7255. UINT count;
  7256. count = g_pwbCore->WBP_PersonCountInCall();
  7257. strSize = ::LoadString(g_hInstance, IDS_IN_CALL, inUseBy, totalSize);
  7258. strSize=wsprintf(pTitle, inUseBy, (count-1));
  7259. pTitle+=strSize;
  7260. ASSERT(totalSize>strSize);
  7261. totalSize -=strSize;
  7262. }
  7263. else if ((m_uiState == JOINING) ||
  7264. ((m_uiState == JOINED) && !m_bCallActive) ||
  7265. ((m_uiState == IN_CALL) && (m_dwDomain != OM_NO_CALL) && !m_bCallActive))
  7266. {
  7267. strSize = ::LoadString(g_hInstance, IDS_JOINING, pTitle, totalSize );
  7268. pTitle+=strSize;
  7269. ASSERT(totalSize>strSize);
  7270. totalSize -=strSize;
  7271. }
  7272. else if (m_uiState == STARTING)
  7273. {
  7274. strSize = ::LoadString(g_hInstance, IDS_INITIALIZING, pTitle, totalSize);
  7275. pTitle+=strSize;
  7276. ASSERT(totalSize>strSize);
  7277. totalSize -=strSize;
  7278. }
  7279. else
  7280. {
  7281. strSize = ::LoadString(g_hInstance, IDS_NOT_IN_CALL, pTitle, totalSize);
  7282. pTitle+=strSize;
  7283. ASSERT(totalSize>strSize);
  7284. totalSize -=strSize;
  7285. }
  7286. // add lock info
  7287. if( m_pLockOwner != NULL )
  7288. {
  7289. strSize = ::LoadString(g_hInstance, IDS_LOCKEDTITLE, pTitle, totalSize);
  7290. ASSERT(totalSize>strSize);
  7291. pTitle+=strSize;
  7292. lstrcpy(pTitle, m_pLockOwner->Name());
  7293. }
  7294. // Return the complete title string
  7295. return pStartTitle;
  7296. }
  7297. LRESULT WbMainWindow::OnConfShutdown( WPARAM, LPARAM )
  7298. {
  7299. if (OnQueryEndSession())
  7300. {
  7301. ::SendMessage(m_hwnd, WM_CLOSE, 0, 0); // do close immediately
  7302. // :
  7303. // DON'T DO ANYTHING else at this point except for exit.
  7304. return( 0 );// tell conf ok to shutdown
  7305. }
  7306. else
  7307. return( (LRESULT)g_cuEndSessionAbort ); // don't shutdown
  7308. }
  7309. //
  7310. //
  7311. // Function: OnQueryEndSession
  7312. //
  7313. // Purpose: Ensure user is prompted to save changes when windows is
  7314. // ended.
  7315. //
  7316. //
  7317. LRESULT WbMainWindow::OnQueryEndSession(void)
  7318. {
  7319. HWND hwndPopup;
  7320. if ((hwndPopup = ::GetLastActivePopup(m_hwnd)) != m_hwnd)
  7321. {
  7322. Message(NULL, IDS_DEFAULT, IDS_CANTCLOSE );
  7323. ::BringWindowToTop(hwndPopup);
  7324. return( FALSE );
  7325. }
  7326. // If changes are required then prompt the user to save
  7327. int iDoNew = IDOK;
  7328. if (IsIdle())
  7329. {
  7330. iDoNew = QuerySaveRequired(TRUE);
  7331. if (iDoNew == IDYES)
  7332. {
  7333. // Save the changes
  7334. iDoNew = OnSave(FALSE);
  7335. }
  7336. }
  7337. // remember what we did so OnClose can act appropriately
  7338. m_bQuerySysShutdown = (iDoNew != IDCANCEL);
  7339. // If the user did not cancel, let windows exit
  7340. return( m_bQuerySysShutdown );
  7341. }
  7342. //
  7343. //
  7344. // Function: Recover
  7345. //
  7346. // Purpose: Ensure the whiteboard is not left partly registered.
  7347. //
  7348. //
  7349. //
  7350. void WbMainWindow::Recover()
  7351. {
  7352. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::Recover");
  7353. // If the error occurred during start-up, then quit immediately
  7354. if (m_uiState == STARTING)
  7355. {
  7356. TRACE_MSG(("error during startup - exiting"));
  7357. ::PostMessage(m_hwnd, WM_CLOSE, FALSE, 0L);
  7358. }
  7359. else
  7360. {
  7361. // ensure the drawing area is locked while we are in a bad state
  7362. LockDrawingArea();
  7363. // disable remote pointer while we are handling this join failure (bug 4767)
  7364. m_TB.Disable(IDM_REMOTE);
  7365. // set state to starting - ensures we don't get in an infinite loop,
  7366. // because if an error occurs then we will quit if we try to recover
  7367. m_uiState = STARTING;
  7368. TRACE_MSG(("Attempting to recover after join call failure - state set to STARTING"));
  7369. // state changed: update page buttons
  7370. UpdatePageButtons();
  7371. // see if there is a call active
  7372. CM_STATUS cmStatus;
  7373. // if there's a call available, try to join it
  7374. if (!CMS_GetStatus(&cmStatus))
  7375. cmStatus.callID = OM_NO_CALL;
  7376. ::PostMessage(m_hwnd, WM_USER_JOIN_CALL, FALSE, (LONG)cmStatus.callID);
  7377. }
  7378. }
  7379. //
  7380. //
  7381. // Function: UnlockDrawingArea
  7382. //
  7383. // Purpose: Unlock the drawing area and enable the appropriate buttons
  7384. //
  7385. //
  7386. //
  7387. void WbMainWindow::UnlockDrawingArea()
  7388. {
  7389. m_drawingArea.Unlock();
  7390. // Enable tool-bar buttons that can now be used
  7391. if (WB_Locked() || !IsIdle())
  7392. {
  7393. EnableToolbar( FALSE );
  7394. }
  7395. else
  7396. {
  7397. EnableToolbar( TRUE );
  7398. }
  7399. //
  7400. // Show the tool attributes group.
  7401. //
  7402. m_AG.DisplayTool(m_pCurrentTool);
  7403. }
  7404. //
  7405. //
  7406. // Function: LockDrawingArea
  7407. //
  7408. // Purpose: Lock the drawing area and enable the appropriate buttons
  7409. //
  7410. //
  7411. //
  7412. void WbMainWindow::LockDrawingArea()
  7413. {
  7414. m_drawingArea.Lock();
  7415. // Disable tool-bar buttons that cannot be used while locked
  7416. if (WB_Locked() || !IsIdle())
  7417. {
  7418. EnableToolbar( FALSE );
  7419. }
  7420. else
  7421. {
  7422. EnableToolbar( TRUE );
  7423. }
  7424. //
  7425. // Hide the tool attributes
  7426. //
  7427. if (m_WG.m_hwnd != NULL)
  7428. {
  7429. ::ShowWindow(m_WG.m_hwnd, SW_HIDE);
  7430. }
  7431. m_AG.Hide();
  7432. }
  7433. void WbMainWindow::EnableToolbar( BOOL bEnable )
  7434. {
  7435. if (bEnable)
  7436. {
  7437. m_TB.Enable(IDM_SELECT);
  7438. // don't allow text editing in zoom mode
  7439. if( m_drawingArea.Zoomed() )
  7440. m_TB.Disable(IDM_TEXT);
  7441. else
  7442. m_TB.Enable(IDM_TEXT);
  7443. m_TB.Enable(IDM_PEN);
  7444. m_TB.Enable(IDM_HIGHLIGHT);
  7445. m_TB.Enable(IDM_LINE);
  7446. m_TB.Enable(IDM_ZOOM);
  7447. m_TB.Enable(IDM_BOX);
  7448. m_TB.Enable(IDM_FILLED_BOX);
  7449. m_TB.Enable(IDM_ELLIPSE);
  7450. m_TB.Enable(IDM_FILLED_ELLIPSE);
  7451. m_TB.Enable(IDM_ERASER);
  7452. m_TB.Enable(IDM_GRAB_AREA);
  7453. m_TB.Enable(IDM_GRAB_WINDOW);
  7454. m_TB.Enable(IDM_LOCK);
  7455. m_TB.Enable(IDM_SYNC);
  7456. // enable remote pointer incase it was disabled handling
  7457. // join failures (bug 4767)
  7458. m_TB.Enable(IDM_REMOTE);
  7459. }
  7460. else
  7461. {
  7462. m_TB.Disable(IDM_SELECT);
  7463. m_TB.Disable(IDM_PEN);
  7464. m_TB.Disable(IDM_HIGHLIGHT);
  7465. m_TB.Disable(IDM_TEXT);
  7466. m_TB.Disable(IDM_LINE);
  7467. m_TB.Disable(IDM_ZOOM);
  7468. m_TB.Disable(IDM_BOX);
  7469. m_TB.Disable(IDM_FILLED_BOX);
  7470. m_TB.Disable(IDM_ELLIPSE);
  7471. m_TB.Disable(IDM_FILLED_ELLIPSE);
  7472. m_TB.Disable(IDM_ERASER);
  7473. m_TB.Disable(IDM_GRAB_AREA);
  7474. m_TB.Disable(IDM_GRAB_WINDOW);
  7475. m_TB.Disable(IDM_LOCK);
  7476. m_TB.Disable(IDM_SYNC);
  7477. }
  7478. }
  7479. //
  7480. //
  7481. // Function: UpdatePageButtons
  7482. //
  7483. // Purpose: Enable or disable the page buttons, according to the current
  7484. // state.
  7485. //
  7486. //
  7487. //
  7488. void WbMainWindow::UpdatePageButtons()
  7489. {
  7490. // Disable page buttons if not in a call, or doing a new, or another user
  7491. // has the lock and is synced.
  7492. if ( (m_uiState != IN_CALL) ||
  7493. (m_uiSubState == SUBSTATE_NEW_IN_PROGRESS) ||
  7494. (WB_PresentationMode()))
  7495. {
  7496. m_AG.EnablePageCtrls(FALSE);
  7497. // when the page buttons are disabled, we do not allow the page sorter
  7498. // dialog to be displayed
  7499. if (m_hwndPageSortDlg != NULL)
  7500. {
  7501. ::SendMessage(m_hwndPageSortDlg, WM_COMMAND, MAKELONG(IDOK, BN_CLICKED),
  7502. 0);
  7503. ASSERT(m_hwndPageSortDlg == NULL);
  7504. }
  7505. }
  7506. else
  7507. {
  7508. m_AG.EnablePageCtrls(TRUE);
  7509. }
  7510. if (WB_Locked() || !IsIdle() )
  7511. {
  7512. EnableToolbar( FALSE );
  7513. }
  7514. else
  7515. {
  7516. EnableToolbar( TRUE );
  7517. }
  7518. //
  7519. // If the page sorter is up, inform it of the state change
  7520. //
  7521. if (m_hwndPageSortDlg != NULL)
  7522. {
  7523. ::SendMessage(m_hwndPageSortDlg, WM_PS_ENABLEPAGEOPS,
  7524. (m_uiSubState == SUBSTATE_IDLE), 0);
  7525. }
  7526. //
  7527. // Enable the insert-page button if the page order's not locked
  7528. //
  7529. m_AG.EnableInsert( ((m_uiState == IN_CALL) &&
  7530. (m_uiSubState == SUBSTATE_IDLE) &&
  7531. (g_pwbCore->WBP_ContentsCountPages() < WB_MAX_PAGES) &&
  7532. (!WB_Locked())));
  7533. //
  7534. // Ensure the currently active menu (if any) is correctly enabled
  7535. //
  7536. InvalidateActiveMenu();
  7537. }
  7538. //
  7539. //
  7540. // Function: InvalidateActiveMenu
  7541. //
  7542. // Purpose: If a menu is currently active, gray items according to
  7543. // the current state, and force it to redraw.
  7544. //
  7545. //
  7546. void WbMainWindow::InvalidateActiveMenu()
  7547. {
  7548. if (m_hInitMenu != NULL)
  7549. {
  7550. // A menu is displayed, so set the state appropriately and force a
  7551. // repaint to show the new state
  7552. SetMenuStates(m_hInitMenu);
  7553. ::RedrawWindow(::GetTopWindow(::GetDesktopWindow()),
  7554. NULL, NULL,
  7555. RDW_FRAME | RDW_INVALIDATE | RDW_ERASE |
  7556. RDW_ERASENOW | RDW_ALLCHILDREN);
  7557. }
  7558. }
  7559. //
  7560. //
  7561. // Function: CancelLoad
  7562. //
  7563. // Purpose: Cancel any load in progress
  7564. //
  7565. //
  7566. void WbMainWindow::CancelLoad(BOOL bReleaseLock)
  7567. {
  7568. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::CancelLoad");
  7569. // Cancel the load
  7570. g_pwbCore->WBP_CancelLoad();
  7571. // reset file name to untitled
  7572. ZeroMemory(m_strFileName, sizeof(m_strFileName));
  7573. UpdateWindowTitle();
  7574. // reset the whiteboard substate
  7575. SetSubstate(SUBSTATE_IDLE);
  7576. if (bReleaseLock)
  7577. {
  7578. ReleasePageOrderLock();
  7579. }
  7580. }
  7581. //
  7582. //
  7583. // Function: ReleasePageOrderLock
  7584. //
  7585. // Purpose: Releases the page order lock, unless the user has got the
  7586. // contents locked, in which case it has no effect. Called
  7587. // after asynchronous functions requiring the page order lock
  7588. // (file/new, file/open) have completed.
  7589. //
  7590. //
  7591. void WbMainWindow::ReleasePageOrderLock()
  7592. {
  7593. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::ReleasePageOrderLock");
  7594. //
  7595. // Only release the page order lock if:
  7596. // - the contents are not also locked (if they are then releasing
  7597. // the page order lock has no effect).
  7598. // - we actually have the page order locked in the first place.
  7599. //
  7600. if ( (!WB_GotContentsLock()) &&
  7601. (WB_GotLock()) )
  7602. {
  7603. g_pwbCore->WBP_Unlock();
  7604. }
  7605. }
  7606. //
  7607. //
  7608. // Function: IsIdle
  7609. //
  7610. // Purpose: Returns true if the main window is idle (in a call and not
  7611. // loading a file/performing a new)
  7612. //
  7613. //
  7614. BOOL WbMainWindow::IsIdle()
  7615. {
  7616. return((m_uiState == IN_CALL) && (m_uiSubState == SUBSTATE_IDLE));
  7617. }
  7618. //
  7619. //
  7620. // Function: SetSubstate
  7621. //
  7622. // Purpose: Sets the substate, informing the page sorter dialog of the
  7623. // change, if necessary.
  7624. //
  7625. //
  7626. void WbMainWindow::SetSubstate(UINT newSubState)
  7627. {
  7628. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::SetSubstate");
  7629. // substate only valid if in a call
  7630. if ( (m_uiState != IN_CALL)
  7631. || (newSubState != m_uiSubState))
  7632. {
  7633. m_uiSubState = newSubState;
  7634. // Trace the substate change
  7635. switch (m_uiSubState)
  7636. {
  7637. case SUBSTATE_IDLE:
  7638. TRACE_DEBUG(("set substate to IDLE"));
  7639. break;
  7640. case SUBSTATE_LOADING:
  7641. TRACE_DEBUG(("set substate to LOADING"));
  7642. break;
  7643. case SUBSTATE_NEW_IN_PROGRESS:
  7644. TRACE_DEBUG(("set substate to NEW_IN_PROGRESS"));
  7645. break;
  7646. default:
  7647. ERROR_OUT(("Unknown substate %hd",m_uiSubState));
  7648. break;
  7649. }
  7650. // update the page buttons (may have become enabled/disabled)
  7651. UpdatePageButtons();
  7652. }
  7653. }
  7654. //
  7655. //
  7656. // Function: PositionUpdated
  7657. //
  7658. // Purpose: Called when the drawing area position has changed.
  7659. // change, if necessary.
  7660. //
  7661. //
  7662. void WbMainWindow::PositionUpdated()
  7663. {
  7664. RECT rectDraw;
  7665. m_drawingArea.GetVisibleRect(&rectDraw);
  7666. if (m_pLocalUser != NULL)
  7667. {
  7668. // Set the new position from the drawing area
  7669. m_pLocalUser->SetVisibleRect(&rectDraw);
  7670. // Show that an update of the sync position is pending
  7671. m_bSyncUpdateNeeded = TRUE;
  7672. }
  7673. // If the current page is a valid one then store the user's position on
  7674. // that page.
  7675. if (m_hCurrentPage != WB_PAGE_HANDLE_NULL)
  7676. {
  7677. // Store position of this page
  7678. WORD pageIndex = (WORD)m_hCurrentPage;
  7679. PAGE_POSITION *mapob;
  7680. POSITION position = m_pageToPosition.GetHeadPosition();
  7681. BOOL bFound = FALSE;
  7682. while (position && !bFound)
  7683. {
  7684. mapob = (PAGE_POSITION *)m_pageToPosition.GetNext(position);
  7685. if ( mapob->hPage == pageIndex)
  7686. {
  7687. bFound = TRUE;
  7688. }
  7689. }
  7690. // If we're replacing an existing entry, then free the old entry.
  7691. if (bFound)
  7692. {
  7693. mapob->position.x = rectDraw.left;
  7694. mapob->position.y = rectDraw.top;
  7695. }
  7696. else
  7697. {
  7698. mapob = new PAGE_POSITION;
  7699. if (!mapob)
  7700. {
  7701. ERROR_OUT(("PositionUpdated failing; couldn't allocate PAGE_POSITION object"));
  7702. }
  7703. else
  7704. {
  7705. mapob->hPage = pageIndex;
  7706. mapob->position.x = rectDraw.left;
  7707. mapob->position.y = rectDraw.top;
  7708. m_pageToPosition.AddTail(mapob);
  7709. }
  7710. }
  7711. }
  7712. }
  7713. //
  7714. //
  7715. // Function : OnALSLoadResult
  7716. //
  7717. // Purpose : Deal with an ALS_LOAD_RESULT event
  7718. //
  7719. //
  7720. void WbMainWindow::OnALSLoadResult(UINT reason)
  7721. {
  7722. int errorMsg = 0;
  7723. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnALSLoadResult");
  7724. switch (reason)
  7725. {
  7726. case AL_LOAD_FAIL_NO_FP:
  7727. WARNING_OUT(("Remote WB load failed - no FP"));
  7728. errorMsg = IDS_MSG_LOAD_FAIL_NO_FP;
  7729. break;
  7730. case AL_LOAD_FAIL_NO_EXE:
  7731. WARNING_OUT(("Remote WB load failed - no exe"));
  7732. errorMsg = IDS_MSG_LOAD_FAIL_NO_EXE;
  7733. break;
  7734. case AL_LOAD_FAIL_BAD_EXE:
  7735. WARNING_OUT(("Remote WB load failed - bad exe"));
  7736. errorMsg = IDS_MSG_LOAD_FAIL_BAD_EXE;
  7737. break;
  7738. case AL_LOAD_FAIL_LOW_MEM:
  7739. WARNING_OUT(("Remote WB load failed - low mem"));
  7740. errorMsg = IDS_MSG_LOAD_FAIL_LOW_MEM;
  7741. break;
  7742. default:
  7743. WARNING_OUT(("Bad ALSLoadResult reason %d", reason));
  7744. break;
  7745. }
  7746. if (errorMsg)
  7747. {
  7748. //
  7749. // Put up an error message
  7750. //
  7751. Message(NULL, IDS_MSG_CAPTION, errorMsg);
  7752. }
  7753. }
  7754. //
  7755. //
  7756. // Function : OnEndSession
  7757. //
  7758. // Purpose : Called when Windows is exiting
  7759. //
  7760. //
  7761. void WbMainWindow::OnEndSession(BOOL bEnding)
  7762. {
  7763. if (bEnding)
  7764. {
  7765. ::PostQuitMessage(0);
  7766. }
  7767. else
  7768. {
  7769. m_bQuerySysShutdown = FALSE; // never mind, cancel OnClose special handling
  7770. }
  7771. }
  7772. //
  7773. // Function: OnCancelMode()
  7774. //
  7775. // Purpose: Called whenever a WM_CANCELMODE message is sent to the frame
  7776. // window.
  7777. // WM_CANCELMODE is sent when another app or dialog receives the
  7778. // input focus. The frame simply records that a WM_CANCELMODE
  7779. // message has been sent. This fact is used by the SelectWindow
  7780. // code to determine if it should cancel the selecting of a
  7781. // window
  7782. //
  7783. //
  7784. void WbMainWindow::OnCancelMode()
  7785. {
  7786. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::OnCancelMode");
  7787. m_cancelModeSent = TRUE;
  7788. //
  7789. // Note: Not passed to the default handler as the default action on
  7790. // WM_CANCELMODE is to release mouse capture - we shall do this
  7791. // explicitly.
  7792. //
  7793. // blow off any dragging that might be in progress (bug 573)
  7794. POINT pt;
  7795. ::GetCursorPos( &pt );
  7796. ::ScreenToClient(m_drawingArea.m_hwnd, &pt);
  7797. ::SendMessage(m_drawingArea.m_hwnd, WM_LBUTTONUP, 0, MAKELONG( pt.x, pt.y ) );
  7798. }
  7799. void WbMainWindow::LoadCmdLine(LPCSTR szFilename)
  7800. {
  7801. int iOnSave;
  7802. if (szFilename && *szFilename)
  7803. {
  7804. if( UsersMightLoseData( NULL, NULL ) ) // bug NM4db:418
  7805. return;
  7806. // Don't prompt to save file if we're already loading
  7807. if (m_uiSubState != SUBSTATE_LOADING )
  7808. {
  7809. // Check whether there are changes to be saved
  7810. iOnSave = QuerySaveRequired(TRUE);
  7811. }
  7812. else
  7813. {
  7814. return;
  7815. }
  7816. if (iOnSave == IDYES)
  7817. {
  7818. // User wants to save the drawing area contents
  7819. int iResult = OnSave(TRUE);
  7820. if( iResult == IDOK )
  7821. {
  7822. UpdateWindowTitle();
  7823. }
  7824. else
  7825. {
  7826. // cancelled out of save, so cancel the open operation
  7827. return;
  7828. }
  7829. }
  7830. // load filename
  7831. if( iOnSave != IDCANCEL )
  7832. LoadFile(szFilename);
  7833. }
  7834. }
  7835. //
  7836. // OnNotify()
  7837. // Handles TTN_NEEDTEXTA and TTN_NEEDTEXTW
  7838. //
  7839. void WbMainWindow::OnNotify(UINT id, NMHDR * pNM)
  7840. {
  7841. UINT nID;
  7842. HWND hwnd = NULL;
  7843. POINT ptCurPos;
  7844. UINT nTipStringID;
  7845. if (!pNM)
  7846. return;
  7847. if (pNM->code == TTN_NEEDTEXTA)
  7848. {
  7849. TOOLTIPTEXTA *pTA = (TOOLTIPTEXTA *)pNM;
  7850. // get id and hwnd
  7851. if( pTA->uFlags & TTF_IDISHWND )
  7852. {
  7853. // idFrom is actually the HWND of the tool
  7854. hwnd = (HWND)pNM->idFrom;
  7855. nID = ::GetDlgCtrlID(hwnd);
  7856. }
  7857. else
  7858. {
  7859. nID = (UINT)pNM->idFrom;
  7860. }
  7861. // get tip string id
  7862. nTipStringID = GetTipId(hwnd, nID);
  7863. if (nTipStringID == 0)
  7864. return;
  7865. // give it to em
  7866. pTA->lpszText = MAKEINTRESOURCE( nTipStringID );
  7867. pTA->hinst = g_hInstance;
  7868. }
  7869. else if (pNM->code == TTN_NEEDTEXTW)
  7870. {
  7871. TOOLTIPTEXTW *pTW = (TOOLTIPTEXTW *)pNM;
  7872. // get id and hwnd
  7873. if( pTW->uFlags & TTF_IDISHWND )
  7874. {
  7875. // idFrom is actually the HWND of the tool
  7876. hwnd = (HWND)pNM->idFrom;
  7877. nID = ::GetDlgCtrlID(hwnd);
  7878. }
  7879. else
  7880. {
  7881. nID = (UINT)pNM->idFrom;
  7882. }
  7883. // get tip string id
  7884. nTipStringID = GetTipId(hwnd, nID );
  7885. if (nTipStringID == 0)
  7886. return;
  7887. // give it to em
  7888. pTW->lpszText = (LPWSTR) MAKEINTRESOURCE( nTipStringID );
  7889. pTW->hinst = g_hInstance;
  7890. }
  7891. }
  7892. //
  7893. // GetTipId()
  7894. // Finds the tooltip for a control in Whiteboard
  7895. //
  7896. UINT WbMainWindow::GetTipId(HWND hwndTip, UINT nID)
  7897. {
  7898. WbTool * pTool;
  7899. BOOL bCheckedState;
  7900. int nTipID;
  7901. int nTipStringID;
  7902. int i;
  7903. // find tip stuff relevant for nID
  7904. nTipID = -1;
  7905. for( i=0; i<((sizeof g_tipIDsArray)/(sizeof (TIPIDS) )); i++ )
  7906. {
  7907. if( g_tipIDsArray[i].nID == nID )
  7908. {
  7909. nTipID = i;
  7910. break;
  7911. }
  7912. }
  7913. // valid?
  7914. if( nTipID < 0 )
  7915. return( 0 );
  7916. // get checked state
  7917. switch( g_tipIDsArray[ nTipID ].nCheck )
  7918. {
  7919. case TB:
  7920. bCheckedState =
  7921. (::SendMessage(m_TB.m_hwnd, TB_ISBUTTONCHECKED, nID, 0) != 0);
  7922. break;
  7923. case BT:
  7924. if (hwndTip != NULL)
  7925. {
  7926. bCheckedState =
  7927. (::SendMessage(hwndTip, BM_GETSTATE, 0, 0) & 0x0003) == 1;
  7928. }
  7929. else
  7930. bCheckedState = FALSE;
  7931. break;
  7932. case NA:
  7933. default:
  7934. bCheckedState = FALSE;
  7935. break;
  7936. }
  7937. // get tip string id
  7938. if( bCheckedState )
  7939. nTipStringID = g_tipIDsArray[ nTipID ].nDownTipID;
  7940. else
  7941. nTipStringID = g_tipIDsArray[ nTipID ].nUpTipID;
  7942. // done
  7943. return( nTipStringID );
  7944. }
  7945. // gets default path if no saves or opens have been done yet
  7946. // Returns FALSE if last default should be reused
  7947. BOOL WbMainWindow::GetDefaultPath(LPTSTR csDefaultPath , UINT size)
  7948. {
  7949. DWORD dwType;
  7950. DWORD dwBufLen = size;
  7951. HKEY hDefaultKey = NULL;
  7952. if( !lstrlen(m_strFileName) )
  7953. {
  7954. // a name has not been picked yet in this session, use path
  7955. // to "My Documents"
  7956. if( (RegOpenKeyEx( HKEY_CURRENT_USER,
  7957. "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
  7958. 0,
  7959. KEY_READ,
  7960. &hDefaultKey )
  7961. != ERROR_SUCCESS) ||
  7962. (RegQueryValueEx( hDefaultKey,
  7963. "Personal",
  7964. NULL,
  7965. &dwType,
  7966. (BYTE *)csDefaultPath,
  7967. &dwBufLen )
  7968. != ERROR_SUCCESS))
  7969. {
  7970. // reg failed, use desktop
  7971. GetWindowsDirectory( csDefaultPath, 2*_MAX_PATH );
  7972. lstrcpy(csDefaultPath,"\\Desktop");
  7973. }
  7974. if( hDefaultKey != NULL )
  7975. RegCloseKey( hDefaultKey );
  7976. return( TRUE );
  7977. }
  7978. else
  7979. {
  7980. return( FALSE );
  7981. }
  7982. }
  7983. void WbMainWindow::OnSysColorChange( void )
  7984. {
  7985. if (m_drawingArea.Page() != WB_PAGE_HANDLE_NULL)
  7986. {
  7987. PG_ReinitPalettes();
  7988. ::InvalidateRect(m_hwnd, NULL, TRUE );
  7989. ::UpdateWindow(m_hwnd);
  7990. }
  7991. m_TB.RecolorButtonImages();
  7992. m_AG.RecolorButtonImages();
  7993. }
  7994. //
  7995. // posts a do-you-wana-do-that message if other users are in the conference
  7996. //
  7997. BOOL WbMainWindow::UsersMightLoseData( BOOL *pbWasPosted, HWND hwnd )
  7998. {
  7999. if ( (m_uiState == IN_CALL) && m_bCallActive )
  8000. {
  8001. UINT count;
  8002. count = g_pwbCore->WBP_PersonCountInCall();
  8003. if (count > 1)
  8004. {
  8005. if( pbWasPosted != NULL )
  8006. *pbWasPosted = TRUE;
  8007. return( ::Message(hwnd, IDS_DEFAULT, IDS_MSG_USERSMIGHTLOSE, MB_YESNO | MB_ICONEXCLAMATION ) != IDYES );
  8008. }
  8009. }
  8010. if( pbWasPosted != NULL )
  8011. *pbWasPosted = FALSE;
  8012. return( FALSE );
  8013. }
  8014. BOOL WbMainWindow::HasGraphicChanged( PWB_GRAPHIC pOldHeaderCopy, const PWB_GRAPHIC pNewHeader )
  8015. {
  8016. MLZ_EntryOut(ZONE_FUNCTION, "WbMainWindow::HasGraphicChanged");
  8017. // If nothing is different but the lock state and some misc in a WBP_EVENT_GRAPHIC_UPDATE_IND then
  8018. // the graphics are visually the same.
  8019. //
  8020. // NOTE: This does not check ZORDER. ZORDER changes are handled by WBP_EVENT_GRAPHIC_MOVED
  8021. // if objects aren't the same length, they are different
  8022. if( pOldHeaderCopy->length != pNewHeader->length )
  8023. return( TRUE );
  8024. // temporarialy set pOldHeaderCopy's locked state + misc to same as pNewHeader so we can do an
  8025. // object compare.
  8026. UINT uOldLocked = pOldHeaderCopy->locked;
  8027. pOldHeaderCopy->locked = pNewHeader->locked;
  8028. OM_OBJECT_ID oldlockPersonID = pOldHeaderCopy->lockPersonID;
  8029. pOldHeaderCopy->lockPersonID = pNewHeader->lockPersonID;
  8030. UINT oldloadedFromFile = pOldHeaderCopy->loadedFromFile;
  8031. pOldHeaderCopy->loadedFromFile = pNewHeader->loadedFromFile;
  8032. NET_UID oldloadingClientID = pOldHeaderCopy->loadingClientID;
  8033. pOldHeaderCopy->loadingClientID = pNewHeader->loadingClientID;
  8034. // compare objects
  8035. BOOL bChanged = FALSE;
  8036. if( memcmp( pOldHeaderCopy, pNewHeader, pOldHeaderCopy->length ) != 0 )
  8037. bChanged = TRUE;
  8038. // restore lock state + misc
  8039. pOldHeaderCopy->locked = (TSHR_UINT8)uOldLocked;
  8040. pOldHeaderCopy->lockPersonID = oldlockPersonID;
  8041. pOldHeaderCopy->loadedFromFile = (TSHR_UINT16)oldloadedFromFile;
  8042. pOldHeaderCopy->loadingClientID = oldloadingClientID;
  8043. return( bChanged );
  8044. }
  8045. void WbMainWindow::UpdateWindowTitle(void)
  8046. {
  8047. TCHAR *pTitle = GetWindowTitle();
  8048. if (pTitle != NULL)
  8049. {
  8050. ::SetWindowText(m_hwnd, pTitle);
  8051. delete pTitle;
  8052. }
  8053. }