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.

427 lines
11 KiB

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