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.

684 lines
15 KiB

  1. //
  2. // MWND.HPP
  3. // Main WB Window
  4. //
  5. // Copyright Microsoft 1998-
  6. //
  7. #ifndef __MWND_HPP_
  8. #define __MWND_HPP_
  9. #define ARRAYSIZE(a) (sizeof(a) / sizeof(a[0]))
  10. #define T126WB_FP_NAME "Microsoft NetMeeting Whiteboard"
  11. #define T126WB_VERSION 30 // for 3.0
  12. //
  13. // Workset type constants
  14. //
  15. #define TYPE_T126_ASN_OBJECT 0
  16. #define TYPE_T126_DIB_OBJECT 1
  17. #define TYPE_T126_TEXT_OBJECT 2
  18. #define TYPE_T126_END_OF_FILE 1000
  19. //
  20. // Generic object
  21. //
  22. typedef struct tagWB_OBJ
  23. {
  24. ULONG length; // Total length of object
  25. UINT type; // Type of file object
  26. } WB_OBJ;
  27. typedef WB_OBJ* PWB_OBJ;
  28. //
  29. // File header for Whiteboard format files
  30. //
  31. typedef struct tagT126WB_FILE_HEADER
  32. {
  33. BYTE functionProfile[sizeof(T126WB_FP_NAME)];
  34. UINT length;
  35. UINT version;
  36. UINT numberOfWorkspaces;
  37. } T126WB_FILE_HEADER;
  38. typedef T126WB_FILE_HEADER * PT126WB_FILE_HEADER;
  39. typedef struct tagT126WB_FILE_HEADER_AND_OBJECTS
  40. {
  41. T126WB_FILE_HEADER fileHeader;
  42. UINT numberOfObjects[1];
  43. }T126WB_FILE_HEADER_AND_OBJECTS;
  44. typedef T126WB_FILE_HEADER_AND_OBJECTS* PT126WB_FILE_HEADER_AND_OBJECTS;
  45. //
  46. // The progress timer meter is kinda the heart beat of this thing
  47. //
  48. #define MAIN_PROGRESS_TIMER 1000
  49. // Milliseconds
  50. #define MAIN_DIALOG_DELAY 1500
  51. #define MAIN_REGISTRATION_TIMEOUT 300000 // These are long, for modems
  52. #define MAIN_LOCK_TIMEOUT 120000
  53. //
  54. // Timer IDs
  55. //
  56. #define TIMERID_PROGRESS_METER 4
  57. #define TIMERID_MAXDISPLAY 10
  58. //
  59. // Timed dialog information
  60. //
  61. typedef struct tagTMDLG
  62. {
  63. BOOL bLockNotEvent;
  64. BOOL bVisible;
  65. UINT uiMaxDisplay;
  66. }
  67. TMDLG;
  68. // This constant must only be defined in FAR EAST sdk
  69. // since it is not in US version. In Sook Choi (Korea) says
  70. // it is 40h so thats what I will use. Bug 3258.
  71. #ifndef CLIP_DFA_OVERRIDE
  72. #define CLIP_DFA_OVERRIDE (0x40)
  73. #endif
  74. // Constants for width menu commands
  75. #define TOOLSPOS_WIDTH 16
  76. //
  77. // Main state
  78. // STARTING = Whiteboard just started, not ready for user input.
  79. // In this state until registration dialog is cleared.
  80. // IN_CALL = Whiteboard ready for input
  81. // ERROR_STATE = a serious error has occurred, Whiteboard must be closed
  82. // JOINING = joining a call (join call dialog is up)
  83. // JOINED = Received join call indication, waiting for 'join call'
  84. // dialog to be dismissed.
  85. // CLOSING = Whiteboard is shutting down. Ignore all messages.
  86. //
  87. //
  88. enum
  89. {
  90. STARTING = 0,
  91. IN_CALL,
  92. ERROR_STATE,
  93. JOINING,
  94. JOINED,
  95. CLOSING
  96. };
  97. //
  98. // Substate - valid only when in call
  99. // IDLE = Normal state - user can do anything permitted by
  100. // current lock status.
  101. // LOADING = Currently loading a file
  102. // NEW_IN_PROGRESS = Currently deleting contents
  103. //
  104. //
  105. #define SUBSTATE_IDLE 0
  106. #define SUBSTATE_LOADING 1
  107. #define SUBSTATE_NEW_IN_PROGRESS 2
  108. #define SUBSTATE_SAVING 3
  109. //
  110. // Capture options
  111. //
  112. #define CAPTURE_TO_SAME 0
  113. #define CAPTURE_TO_NEW 1
  114. //
  115. // Border to be left around the checkmark in the color and width menus and
  116. // width of items in these menus.
  117. //
  118. #define CHECKMARK_BORDER_X 3
  119. #define CHECKMARK_BORDER_Y 5
  120. #define COLOR_MENU_WIDTH 40
  121. typedef struct tagWBFINDDIALOG
  122. {
  123. HWND hwndDialog;
  124. HWND hwndOwner;
  125. } WBFINDDIALOG;
  126. #define MAX_FONT_SIZE 20
  127. #define STATUSBAR_HEIGHT (MAX_FONT_SIZE + 2*::GetSystemMetrics(SM_CYEDGE))
  128. //
  129. //
  130. // Class: WbMainWindow
  131. //
  132. // Purpose: Main Whiteboard window
  133. //
  134. //
  135. class WbMainWindow
  136. {
  137. friend LRESULT CALLBACK WbMainWindowProc(HWND, UINT, WPARAM, LPARAM);
  138. friend BOOL CALLBACK WbFindCurrentDialog(HWND hwnd, LPARAM);
  139. public:
  140. //
  141. // Construction and destruction
  142. //
  143. WbMainWindow(void);
  144. ~WbMainWindow(void);
  145. BOOL InitToolArray(void);
  146. void DestroyToolArray(void);
  147. //
  148. // Initialization - display the window and its children
  149. //
  150. BOOL Open(int iCommand);
  151. VOID ShowWindow(); // For T126 we want to open but hide the ui
  152. void OnMenuSelect(UINT uiItemID, UINT uiFlags, HMENU hSysMenu);
  153. void OnCommand(UINT id, UINT code, HWND hwndCtl);
  154. void OnInitMenuPopup(HMENU hMenu, UINT uiIndex, BOOL bSystem);
  155. void SetMenuStates(HMENU hInitMenu);
  156. void UpdateWindowTitle(void);
  157. //
  158. // Popup context menu for drawing area
  159. //
  160. void PopupContextMenu(int x, int y);
  161. void UncheckMenuItem(UINT uiId);
  162. //
  163. // Check whether the application is idle (not opening or doing a new)
  164. //
  165. BOOL IsIdle(void);
  166. // widthbar needs access to the current tool to get the current widths
  167. WbTool *GetCurrentTool( void )
  168. {return( m_pCurrentTool );}
  169. BOOL IsToolBarOn( void )
  170. {return( m_bToolBarOn );}
  171. BOOL UsersMightLoseData( BOOL *pbWasPosted, HWND hwnd );
  172. //
  173. // Bring the main ui to top
  174. //
  175. void WbMainWindow::BringToFront(void);
  176. //
  177. // Update the page buttons disable/enable status
  178. //
  179. void UpdatePageButtons(void);
  180. //
  181. // Go to a specific page
  182. //
  183. void GotoPage(WorkspaceObj * pNewWorkspace, BOOL bResend = TRUE);
  184. void GoPage(WorkspaceObj * pNewWorkspace, BOOL bSend = TRUE);
  185. //
  186. // Handles tool tips and accelerators
  187. //
  188. BOOL FilterMessage(MSG* pMsg);
  189. //
  190. // Global data
  191. //
  192. HWND m_hwnd;
  193. WbTool * m_ToolArray[TOOLTYPE_MAX];
  194. // Dropping files onto the window
  195. void OnDropFiles(HDROP hDropInfo);
  196. //
  197. // HELP
  198. //
  199. LRESULT ShowHelp();
  200. // Command handlers
  201. LRESULT OnAbout(void);
  202. LRESULT OnNew(void);
  203. LRESULT OnOpen(LPCSTR szLoadFileName = NULL);
  204. LRESULT OnClearPage(BOOL bClearAll = TRUE);
  205. LRESULT OnDelete(void);
  206. LRESULT OnUndelete(void);
  207. LRESULT OnCut(void);
  208. LRESULT OnCopy(void);
  209. LRESULT OnPaste(void);
  210. LRESULT OnSelectAll( void );
  211. LRESULT OnChooseFont(void);
  212. LRESULT OnToolBarToggle(void);
  213. LRESULT OnLock(void);
  214. LRESULT OnGrabWindow(void);
  215. LRESULT OnZoom(void);
  216. LRESULT OnSave(BOOL bPrompt);
  217. LRESULT OnPrint(void);
  218. LRESULT OnInsertPageAfter(void);
  219. LRESULT OnDeletePage(void);
  220. LRESULT OnGrabArea(void);
  221. LRESULT OnLButtonDown(void);
  222. LRESULT OnLButtonUp(void);
  223. LRESULT OnMouseMove(void);
  224. LRESULT OnRemotePointer(void);
  225. LRESULT OnSelectTool(UINT id); // Select the current tool
  226. LRESULT OnSelectColor(void); // Color changed in palette
  227. LRESULT OnSelectWidth(UINT id); // Select pen width
  228. // Scrolling control (accessed via accelerators)
  229. LRESULT OnScrollAccelerator(UINT id);
  230. // Moving through the pages
  231. LRESULT OnFirstPage(void);
  232. LRESULT OnPrevPage(void);
  233. LRESULT OnNextPage(void);
  234. LRESULT OnLastPage(void);
  235. LRESULT OnGotoPage(void);
  236. LRESULT OnSync(void);
  237. void OnStatusBarToggle(void);
  238. // WindowProc handlers
  239. int OnCreate(LPCREATESTRUCT lpcs);
  240. void OnDestroy();
  241. void OnClose(void);
  242. void OnSize(UINT, int, int);
  243. void OnSetFocus(void);
  244. void OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT measureStruct);
  245. void OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT drawStruct);
  246. void OnGetMinMaxInfo(MINMAXINFO FAR* lpmmi);
  247. void OnPaletteChanged(HWND hwndPalette);
  248. LRESULT OnQueryNewPalette(void);
  249. LRESULT OnQueryEndSession(void);
  250. LRESULT OnConfShutdown( WPARAM, LPARAM );
  251. void OnEndSession(BOOL bEnding);
  252. void OnParentNotify(UINT msg);
  253. LRESULT OnToolTipText(UINT, NMHDR*);
  254. void OnDisplayError(WPARAM wParam, LPARAM lParam);
  255. void LoadCmdLine(LPCSTR szFileName);
  256. // CancelMode processing
  257. void OnCancelMode();
  258. void OnNotify(UINT id, NMHDR* pNM);
  259. void OnSysColorChange( void );
  260. BOOL CLP_RenderFormat(int iFormat);
  261. BOOL m_bToolBarOn;
  262. BitmapObj * m_pLocalRemotePointer;
  263. POINT m_localRemotePointerPosition;
  264. //
  265. // Tool bar window
  266. //
  267. WbToolBar m_TB;
  268. int CLP_AcceptableClipboardFormat(void);
  269. protected:
  270. void InvalidateActiveMenu();
  271. HMENU m_hInitMenu;
  272. //
  273. // Tooltips
  274. //
  275. HWND m_hwndToolTip;
  276. TOOLINFO m_tiLastHit;
  277. int m_nLastHit;
  278. int OnToolHitTest(POINT pt, TOOLINFO* pTI) const;
  279. BOOL m_bInitOk;
  280. //
  281. // Flag indicating that we are currently displaying a serious error
  282. // message.
  283. //
  284. BOOL m_bDisplayingError;
  285. //
  286. // Domain ID of the call we are currently in
  287. //
  288. DWORD m_dwDomain;
  289. //
  290. // Move to a given position in the page
  291. //
  292. void GotoPosition(int x, int y);
  293. //
  294. // Sync/unsync with other users.
  295. //
  296. void Sync(void);
  297. void Unsync(void);
  298. //
  299. // Clipboard access
  300. //
  301. BOOL PasteDIB( LPBITMAPINFOHEADER lpbi);
  302. BOOL CLP_Paste(void);
  303. BOOL CLP_Copy(void);
  304. void CLP_SaveDelayedGraphic(void);
  305. BOOL CLP_RenderAllFormats(void);
  306. BOOL CLP_RenderAllFormats(DCWbGraphic * pGraphic);
  307. BOOL CLP_DelayAllFormats(DCWbGraphic * pGraphic);
  308. BOOL CLP_RenderPrivateFormat();
  309. BOOL CLP_RenderPrivateSingleFormat(DCWbGraphic* pGraphic);
  310. BOOL CLP_RenderAsImage();
  311. BOOL CLP_RenderAsText();
  312. BOOL CLP_RenderAsBitmap();
  313. #ifdef RENDER_AS_MF
  314. BOOL CLP_RenderMetafileFormat(DCWbGraphic* pGraphic);
  315. #endif
  316. //
  317. // Insert a new page after the specified page
  318. //
  319. void InsertPageAfter(WorkspaceObj * pCurrentWorkspace);
  320. public:
  321. //
  322. // Drawing pane window
  323. //
  324. WbDrawingArea m_drawingArea;
  325. //
  326. // Color palette, font, page controls
  327. //
  328. WbAttributesGroup m_AG;
  329. //
  330. // Resize function for subpanes - called when the window is resized by
  331. // the user.
  332. //
  333. void ResizePanes(void);
  334. UINT GetSubState( void )
  335. {return(m_uiSubState );}
  336. //
  337. // Get a lock on the Whiteboard contents. The first parameter
  338. // determines the type of lock, the second whether a visible or
  339. // invisible dialog is to be used (use SW_SHOW or SW_HIDE).
  340. //
  341. BOOL GetLock(UINT uiLockType, UINT uiHide = SW_SHOW);
  342. //
  343. // FRAME WINDOW VARS
  344. //
  345. HACCEL m_hAccelTable;
  346. //
  347. // Get the window title
  348. //
  349. TCHAR * GetWindowTitle(void);
  350. WbWidthsGroup m_WG; // Pen Widths
  351. void EnableToolbar( BOOL bEnable );
  352. //
  353. // Dialog that asks whether to save changes.
  354. //
  355. HWND m_hwndQuerySaveDlg;
  356. //
  357. // Get confirmation for destructive functions (new, clear)
  358. //
  359. int QuerySaveRequired(BOOL bCancelBtn);
  360. //
  361. // Timed dialogs that are running while the main window is waiting
  362. // for a specific event.
  363. //
  364. HWND m_hwndWaitForEventDlg;
  365. HWND m_hwndWaitForLockDlg;
  366. //
  367. // Lock/unlock the drawing area
  368. //
  369. void LockDrawingArea(void);
  370. void UnlockDrawingArea(void);
  371. HANDLE m_hFile;
  372. LPSTR GetFileNameStr(void);
  373. UINT ObjectSave(UINT type, LPBYTE pData,UINT length);
  374. PT126WB_FILE_HEADER_AND_OBJECTS ValidateFile(LPCSTR pFileName);
  375. UINT ContentsLoad(LPCSTR pFileName);
  376. UINT ObjectLoad(void);
  377. UINT m_currentMenuTool; // Current tool menu Id
  378. //
  379. // Load a file
  380. //
  381. HRESULT WB_LoadFile(LPCTSTR szFile);
  382. void LoadFile(LPCSTR strLoadFileName);
  383. //
  384. // Ensure the attributes window is up to date
  385. //
  386. void OnUpdateAttributes(void)
  387. { m_AG.DisplayTool(m_pCurrentTool); }
  388. protected:
  389. UINT GetTipId(HWND hTipWnd, UINT nID);
  390. //
  391. // Current window size - normal, maximized or minimized
  392. //
  393. UINT m_uiWindowSize;
  394. //
  395. // Save the current window position to the options file
  396. //
  397. void SaveWindowPosition(void);
  398. //
  399. // Menu selection functions
  400. //
  401. UINT m_currentMenuWidth; // Current width menu Id
  402. HWND m_hwndSB;
  403. BOOL m_bStatusBarOn;
  404. void UpdateStatus(void);
  405. //
  406. // Current drawing tool
  407. //
  408. WbTool* m_pCurrentTool;
  409. //
  410. // Menu update functions
  411. //
  412. void InitializeMenus(void);
  413. void CheckMenuItem(UINT uiId);
  414. BOOL CheckMenuItemRecursive(HMENU hMenu, UINT uiId, BOOL bCheck);
  415. HMENU GetMenuWithItem(HMENU hMenu, UINT uiID);
  416. //
  417. //
  418. // Select a window for grabbing
  419. //
  420. HWND SelectWindow(void);
  421. //
  422. // Add a captured bitmap to the contents
  423. //
  424. void AddCapturedImage(BitmapObj* dib);
  425. //
  426. // Get a file name for saving
  427. //
  428. int GetFileName();
  429. //
  430. // Registration state variables
  431. //
  432. UINT m_uiSubState;
  433. //
  434. // Display a message box for an error
  435. //
  436. void DisplayError(UINT uiCaption, UINT uiMessage);
  437. //
  438. // Current file name for saving image
  439. //
  440. TCHAR m_strFileName[2*_MAX_PATH];
  441. TCHAR * m_pTitleFileName; // File Name in the title
  442. //
  443. // Grab an area of the screen into a bitmap
  444. //
  445. void GetGrabArea(LPRECT lprect);
  446. //
  447. // Hide/show the main window and its associated popups
  448. //
  449. void ShowAllWindows(int iShow);
  450. void ShowAllWindows(void) { ShowAllWindows(SW_RESTORE); }
  451. void HideAllWindows(void) { ShowAllWindows(SW_MINIMIZE); }
  452. //
  453. // Handle of alternative accelerator table for page and text edit fields
  454. //
  455. HACCEL m_hAccelPagesGroup;
  456. HACCEL m_hAccelTextEdit;
  457. //
  458. // Context menu for drawing area
  459. //
  460. HMENU m_hContextMenuBar;
  461. HMENU m_hEditContextMenu;
  462. HMENU m_hContextMenu;
  463. HMENU m_hGrobjContextMenuBar;
  464. HMENU m_hGrobjContextMenu;
  465. //
  466. // Member function to create pop-up context menu for the drawing area
  467. //
  468. BOOL CreateContextMenus(void);
  469. // We remember if we're in a save dialog so we can canel it on certain events
  470. BOOL m_bInSaveDialog;
  471. void CancelSaveDialog(void);
  472. //
  473. // Cancel a load in progress
  474. //
  475. void CancelLoad(BOOL bReleaseLock = TRUE);
  476. UINT ContentsSave(LPCSTR pFileName);
  477. //
  478. // Set the application substate
  479. //
  480. void SetSubstate(UINT newSubState);
  481. //
  482. // Map of page handles to positions
  483. //
  484. typedef struct PAGEPOSITION
  485. {
  486. WORD hPage;
  487. POINT position;
  488. } PAGE_POSITION;
  489. COBLIST m_pageToPosition;
  490. void PositionUpdated(void);
  491. protected:
  492. //
  493. // Number of remote users
  494. //
  495. BOOL m_bSelectAllInProgress;
  496. BOOL GetDefaultPath( LPTSTR csDefaultPath, UINT size );
  497. BOOL m_bUnlockStateSettled;
  498. BOOL m_bQuerySysShutdown;
  499. BOOL m_bIsWin95;
  500. //
  501. // Interface for determining if a WM_CANCELMODE message has been sent
  502. //
  503. protected:
  504. BOOL m_cancelModeSent;
  505. public:
  506. void ResetCancelMode() { m_cancelModeSent = FALSE; };
  507. BOOL CancelModeSent() { return m_cancelModeSent; };
  508. };
  509. //
  510. // Timed dialog proc
  511. //
  512. INT_PTR CALLBACK TimedDlgProc(HWND, UINT, WPARAM, LPARAM);
  513. //
  514. // QuerySave dialog proc
  515. //
  516. INT_PTR CALLBACK QuerySaveDlgProc(HWND, UINT, WPARAM, LPARAM);
  517. //
  518. // WarnSelectWindow dialog proc
  519. //
  520. INT_PTR CALLBACK WarnSelectWindowDlgProc(HWND, UINT, WPARAM, LPARAM);
  521. //
  522. // WarnSelectArea dialog proc
  523. //
  524. INT_PTR CALLBACK WarnSelectAreaDlgProc(HWND, UINT, WPARAM, LPARAM);
  525. //
  526. // About Box dialog proc
  527. //
  528. INT_PTR CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM);
  529. #endif // __MWND_HPP_