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

494 lines
13 KiB

  1. //
  2. // DRAW.HPP
  3. // Drawing Code
  4. //
  5. // Copyright Microsoft 1998-
  6. //
  7. #ifndef __DRAW_HPP_
  8. #define __DRAW_HPP_
  9. //
  10. // Timer for periodic update of some graphic objects
  11. //
  12. #define TIMER_GRAPHIC_UPDATE 2
  13. #define EqualPoint(pt1, pt2) (((pt1).x == (pt2).x) && ((pt1).y == (pt2).y))
  14. #define DRAW_WIDTH 1024
  15. #define DRAW_HEIGHT 768
  16. #define DRAW_LINEVSCROLL 8
  17. #define DRAW_LINEHSCROLL 8
  18. #define DRAW_HANDLESIZE 6
  19. #define DRAW_ZOOMFACTOR 2
  20. #define DRAW_REMOTEPOINTERDELAY 250
  21. #define DRAW_GRAPHICUPDATEDELAY 1000
  22. //
  23. //
  24. // Class: WbDrawingArea
  25. //
  26. // Purpose: drawing window
  27. //
  28. //
  29. class WbDrawingArea
  30. {
  31. friend class DCWbGraphic;
  32. friend class DCWbGraphicLine;
  33. friend class DCWbGraphicFreehand;
  34. friend class DCWbGraphicRectangle;
  35. friend class DCWbGraphicFilledRectangle;
  36. friend class DCWbGraphicEllipse;
  37. friend class DCWbGraphicFilledEllipse;
  38. friend class DCWbGraphicSelectTrackingRectangle;
  39. friend class DCWbGraphicMarker;
  40. friend class DCWbGraphicText;
  41. friend class DCWbGraphicDIB;
  42. friend class WbTextBox;
  43. public:
  44. //
  45. // Constructor
  46. //
  47. WbDrawingArea(void);
  48. ~WbDrawingArea(void);
  49. void ShutDownDC(void);
  50. //
  51. // Create the drawing area
  52. //
  53. BOOL Create(HWND hwndParent, LPCRECT lprect);
  54. //
  55. // Return TRUE if the drawing area is busy and may be actively using
  56. // graphic objects in the current page.
  57. //
  58. BOOL IsBusy(void) { return m_bBusy; }
  59. //
  60. // Lock and unlock the drawing area
  61. //
  62. BOOL IsLocked (void) { return m_bLocked; }
  63. void Unlock (void);
  64. void Lock (void);
  65. //
  66. // Realize the drawing area's palette
  67. //
  68. void RealizePalette( BOOL bBackground );//CHANGED BY RAND
  69. //
  70. // Selection functions
  71. //
  72. void SelectTool(WbTool* pToolNew); // Select drawing tool
  73. //
  74. // Update the selected object
  75. //
  76. void SetSelectionColor (COLORREF clr); // Change color
  77. void SetSelectionWidth (UINT uiNewWidth); // Select pen width
  78. void SetSelectionFont (HFONT hFont); // Select font
  79. //
  80. // External update functions
  81. //
  82. void PageCleared(void);
  83. void GraphicAdded (DCWbGraphic* pAddedGraphic);
  84. void GraphicDeleted (DCWbGraphic* pDeletedGraphic);
  85. //CHANGED BY RAND
  86. void GraphicUpdated (DCWbGraphic* pUpdatedGraphic, BOOL bUpdateMarker, BOOL bErase=TRUE );
  87. void PointerUpdated (DCWbGraphicPointer* pPointer,
  88. BOOL bForcedRemove = FALSE);
  89. void PointerRemoved (DCWbGraphicPointer* pPointer) { PointerUpdated(pPointer, TRUE); }
  90. void RemoveGraphicPointer(DCWbGraphicPointer *p)
  91. {
  92. POSITION pos = m_allPointers.Lookup(p);
  93. if (pos != NULL)
  94. {
  95. m_allPointers.RemoveAt(pos);
  96. }
  97. }
  98. //
  99. // Query functions
  100. //
  101. // Ask whether an object is currently selected
  102. BOOL GraphicSelected(void);
  103. // Return the currently selected graphic
  104. DCWbGraphic* GetSelection(void);
  105. // Clear current (multi object) selection
  106. void ClearSelection( void );
  107. // is pGraphic selected?
  108. BOOL IsSelected( DCWbGraphic *pGraphic )
  109. {return(m_pMarker->HasAMarker( pGraphic ) != NULL );}
  110. DCWbGraphic *GetHitObject( POINT surfacePos )
  111. {return( PG_SelectLast(m_hPage, surfacePos) );}
  112. // Ask whether the drawing area is zoomed
  113. BOOL Zoomed(void) { return (m_iZoomFactor != 1); }
  114. // Ask whether the drawing area is zoomed
  115. int ZoomOption(void) { return (m_iZoomOption); }
  116. int ZoomFactor(void) { return (m_iZoomFactor); }
  117. // Ask whether the text editor is active
  118. BOOL TextEditActive(void) { return m_bTextEditorActive; }
  119. // text editor clipboard
  120. void TextEditCopy( void ) {m_textEditor.Copy();}
  121. void TextEditCut( void ) {m_textEditor.Cut();}
  122. void TextEditPaste( void ) {m_textEditor.Paste();}
  123. // Resets text editor for window resizing
  124. void TextEditParentResize( void )
  125. {m_textEditor.ParentResize();}
  126. // Redraws editbox
  127. void RedrawTextEditbox(void)
  128. {m_textEditor.RedrawEditbox();}
  129. // Gets editbox bounding rect
  130. void GetTextEditBoundsRect(LPRECT lprc)
  131. { m_textEditor.GetBoundsRect(lprc); }
  132. // Return the rectangle currently being viewed i.e. that portion of
  133. // the page surface that is within the window client area.
  134. void GetVisibleRect(LPRECT lprc);
  135. // Ask for the current page
  136. WB_PAGE_HANDLE Page(void) { return(m_hPage);}
  137. // Select objects inside rectSelect or ALL if rect is NULL
  138. void SelectMarkerFromRect(LPCRECT lprcSelect);
  139. DCWbGraphicMarker *GetMarker( void )
  140. {return( m_pMarker );}
  141. DCWbGraphic* SelectPreviousGraphicAt(DCWbGraphic* pGraphic, POINT point);
  142. void SetLClickIgnore( BOOL bIgnore )
  143. {m_bIgnoreNextLClick = bIgnore;}
  144. //
  145. // Delete a graphic
  146. //
  147. void DeleteGraphic(DCWbGraphic* pGraphic);
  148. //
  149. // Action members
  150. //
  151. void Attach(WB_PAGE_HANDLE hPage); // Attach a new page to the window
  152. void Detach(void) { Attach(NULL); } // Attach the empty page
  153. void DeleteSelection(void); // Delete selected graphic
  154. void BringToTopSelection(void); // Bring selected graphic to top
  155. void SendToBackSelection(void); // Send selected graphic to back
  156. void Clear(void); // Clear the workspace
  157. void Zoom(void); // Zoom the drawing area
  158. void GotoPosition(int x, int y); // Set scroll position
  159. // select an object
  160. void SelectGraphic(DCWbGraphic* pGraphic,
  161. BOOL bEnableForceAdd=FALSE, //CHANGED BY RAND
  162. BOOL bForceAdd=FALSE ); //CHANGED BY RAND
  163. //
  164. // A freehand graphic has been updated - redraw it
  165. //
  166. void GraphicFreehandUpdated(DCWbGraphic* pGraphic);
  167. //
  168. // Convert between surface and client co-ordinates
  169. //
  170. void SurfaceToClient(LPPOINT lppt);
  171. void ClientToSurface(LPPOINT lppt);
  172. void SurfaceToClient(LPRECT lprc);
  173. void ClientToSurface(LPRECT lprc);
  174. void MoveOntoSurface(LPPOINT lppt);
  175. void GetOrigin(LPPOINT lppt);
  176. HDC GetCachedDC (void) const {return(m_hDCCached); }
  177. void PrimeFont (HDC hDC, HFONT hFont, TEXTMETRIC* pTextMetrics);
  178. void UnPrimeFont (HDC hDC);
  179. void DrawMarker (HDC hDC);
  180. void PutMarker (HDC hDC, BOOL bDraw = TRUE );
  181. void RemoveMarker (HDC hDC);
  182. //
  183. // Cancel a drawing operation.
  184. //
  185. void CancelDrawingMode(void);
  186. void SetStartPaintGraphic( WB_GRAPHIC_HANDLE hStartPaintGraphic )
  187. {m_hStartPaintGraphic = PG_ZGreaterGraphic(m_hPage, m_hStartPaintGraphic, hStartPaintGraphic );}
  188. friend LRESULT CALLBACK DrawWndProc(HWND, UINT, WPARAM, LPARAM);
  189. //
  190. // Windows message handling
  191. //
  192. void OnPaint(void);
  193. void OnMouseMove(UINT flags, int x, int y);
  194. void OnLButtonDown(UINT flags, int x, int y);
  195. void OnLButtonUp(UINT flags, int x, int y);
  196. void OnRButtonDown(UINT flags, int x, int y);
  197. void OnSize(UINT flags, int cx, int cy);
  198. void OnHScroll(UINT code, UINT pos);
  199. void OnVScroll(UINT code, UINT pos);
  200. LRESULT OnEditColor(HDC hdc);
  201. void OnSetFocus(void);
  202. void OnActivate(UINT flags);
  203. LRESULT OnCursor(HWND hwnd, UINT hitTest, UINT msg);
  204. void OnTimer(UINT idTimer);
  205. void OnCancelMode(void);
  206. void OnContextMenu(int xScreen, int yScreen);
  207. protected:
  208. //
  209. // Update the window after an object has changed
  210. //
  211. void UpdateRectangles(LPCRECT lprc1, LPCRECT lprc2, BOOL bRepaint);
  212. //
  213. // Set the cursor to be used in the drawing area for the current state
  214. //
  215. BOOL SetCursorForState(void);
  216. //
  217. // Add an object to the end of the recorded list and display it in the
  218. // window.
  219. //
  220. void AddObjectLast(DCWbGraphic* pObject);
  221. //
  222. // Invalidate the client area rectangle corresponding to the surface
  223. // rectangle specified.
  224. //
  225. void InvalidateSurfaceRect(LPCRECT lprc, BOOL bErase = TRUE);
  226. //
  227. // Setup functions for the various drawing operations
  228. //
  229. BOOL RemotePointerSelect (POINT mousePos);
  230. void BeginSelectMode (POINT mousePos,
  231. BOOL bDontDrag=FALSE );
  232. void BeginDeleteMode (POINT mousePos);
  233. void BeginTextMode (POINT mousePos);
  234. void BeginFreehandMode (POINT mousePos);
  235. void BeginHighlightMode (POINT mousePos);
  236. void BeginLineMode (POINT mousePos);
  237. void BeginRectangleMode (POINT mousePos);
  238. void BeginEllipseMode (POINT mousePos);
  239. //
  240. // Mouse tracking functions. These are called for each mouse move event
  241. // (depending on the current drawing mode).
  242. //
  243. void TrackSelectMode (POINT mousePos);
  244. void TrackDeleteMode (POINT mousePos);
  245. void TrackFreehandMode (POINT mousePos);
  246. void TrackHighlightMode (POINT mousePos);
  247. void TrackLineMode (POINT mousePos);
  248. void TrackRectangleMode (POINT mousePos);
  249. void TrackEllipseMode (POINT mousePos);
  250. //
  251. // Completion functions for the various mode drawing operations.
  252. //
  253. void CompleteSelectMode();
  254. void CompleteDeleteMode();
  255. void CompleteMarkAreaMode();
  256. void CompleteTextMode();
  257. void CompleteFreehandMode();
  258. void CompleteLineMode();
  259. void CompleteRectangleMode();
  260. void CompleteFilledRectangleMode();
  261. void CompleteEllipseMode();
  262. void CompleteFilledEllipseMode();
  263. //
  264. // Complete a text object
  265. //
  266. void EndTextEntry(BOOL bAccept);
  267. //
  268. // Scroll the workspace to scrollPosition
  269. //
  270. void ScrollWorkspace (void);
  271. void DoScrollWorkspace (void);
  272. BOOL AutoScroll(int xPos, int yPos, BOOL bMoveCursor, int xCaret, int yCaret);
  273. //
  274. // Graphic object selection and marker manipulation
  275. //
  276. void DeselectGraphic(void);
  277. //
  278. // Remote pointer manipulation
  279. //
  280. void RemovePointers(HDC hDC, DCWbGraphicPointer* pPointerStart = NULL);
  281. void RemovePointers(HDC hDC, LPCRECT prcUpdate);
  282. void RemovePointers(HDC hDC, DCWbGraphicPointer* pPointerStart,
  283. LPCRECT prcUpdate);
  284. //
  285. // Redraw the pointers in the list specified. The pointers are drawn
  286. // from the start of the list to the end. If a NULL pointer is
  287. // specified, the undrawnPointers list is used.
  288. //
  289. void PutPointers(HDC hDC, COBLIST* pDrawList = NULL);
  290. void PrimeDC (HDC hDC);
  291. void UnPrimeDC (HDC hDC);
  292. //
  293. // List of pointers on the page
  294. // List of pointers that have been (temporarily undrawn). This list is
  295. // built by RemovePointers for use by PutPointers.
  296. //
  297. COBLIST m_allPointers;
  298. COBLIST m_undrawnPointers;
  299. //
  300. // Flag indicating that the drawing area is busy or locked
  301. //
  302. BOOL m_bBusy;
  303. BOOL m_bLocked;
  304. BOOL m_HourGlass; // we're busy doing something local
  305. //
  306. // Saved drawing attributes
  307. //
  308. HPEN m_hOldPen;
  309. HBRUSH m_hOldBrush;
  310. HPALETTE m_hOldPalette;
  311. HFONT m_hOldFont;
  312. HFONT m_hCurFont;
  313. //
  314. // Current offset of the client region of the window onto the picture
  315. //
  316. RECT m_rcSurface;
  317. public:
  318. SIZE m_originOffset;
  319. HWND m_hwnd;
  320. //
  321. // Saved drawing attributes
  322. //
  323. HDC m_hDCCached;
  324. HDC m_hDCWindow;
  325. protected:
  326. //
  327. // Scrolling control
  328. //
  329. void SetScrollRange(int cx, int cy);
  330. void ValidateScrollPos(void);
  331. POINT m_posScroll;
  332. POINT m_posZoomScroll;
  333. BOOL m_zoomRestoreScroll;
  334. //
  335. // Start and end points of most recent drawing operation
  336. //
  337. POINT m_ptStart;
  338. POINT m_ptEnd;
  339. //
  340. // Current drawing tool
  341. //
  342. WbTool * m_pToolCur;
  343. //
  344. // Mouse button down flag
  345. //
  346. BOOL m_bLButtonDown;
  347. //
  348. // Current page being used
  349. //
  350. WB_PAGE_HANDLE m_hPage;
  351. //
  352. // Graphics object pointer used for tracking object
  353. //
  354. DCWbGraphic* m_pGraphicTracker;
  355. //
  356. // Tick count used to determine when it is time to update the external
  357. // copy of a graphic.
  358. //
  359. DWORD m_dwTickCount;
  360. //
  361. // Marker for selection mode
  362. //
  363. DCWbGraphicMarker *m_pMarker;
  364. DCWbGraphic* m_pSelectedGraphic;
  365. BOOL m_bMarkerPresent;
  366. BOOL m_bNewMarkedGraphic;
  367. BOOL m_bTrackingSelectRect;
  368. //
  369. // Text editor control
  370. //
  371. WbTextEditor m_textEditor;
  372. BOOL m_bTextEditorActive;
  373. DCWbGraphicText* m_pActiveText;
  374. void ActivateTextEditor( BOOL bPutUpCusor );
  375. void DeactivateTextEditor(void);
  376. //
  377. // Text cursor control
  378. //
  379. BOOL m_bGotCaret;
  380. //
  381. // Currently marked area
  382. //
  383. RECT m_rcMarkedArea;
  384. //
  385. // Zoom variables
  386. //
  387. int m_iZoomFactor; // Current zoom factor
  388. int m_iZoomOption; // Zoom factor to be used
  389. HCURSOR m_hCursor; // handle of last cursor we displayed
  390. // (or null if normal arrow cursor)
  391. BOOL m_bIgnoreNextLClick;
  392. WB_GRAPHIC_HANDLE m_hStartPaintGraphic;
  393. };
  394. #endif // __DRAW_HPP_