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.

357 lines
13 KiB

  1. #include "stdafx.h"
  2. #include "global.h"
  3. #include "pbrush.h"
  4. #include "sprite.h"
  5. #include "tracker.h"
  6. #ifdef _DEBUG
  7. #undef THIS_FILE
  8. static char BASED_CODE THIS_FILE[] = __FILE__;
  9. #endif
  10. #include "memtrace.h"
  11. // FUTURE: Make these static to CTracker!
  12. CBitmap NEAR g_bmapDragHandle; // Handle for the drag handle bitmap.
  13. CBitmap NEAR g_bmapDragHandle2; // Handle for hollow drag handle bitmap.
  14. // These are the bitmaps arrays used for tracker borders and the dotted
  15. // drag rectangles.
  16. //
  17. static unsigned short bmapHorizBorder[] =
  18. { 0x0F, 0x0F, 0x0F, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0 };
  19. static unsigned short bmapVertBorder [] =
  20. { 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA };
  21. static CBrush NEAR brushHorizBorder;
  22. static CBrush NEAR brushVertBorder;
  23. static CBitmap NEAR bitmapHorizBorder;
  24. static CBitmap NEAR bitmapVertBorder;
  25. static HCURSOR hcurArrow = NULL; // System "Select Arrow" cursor.
  26. static HCURSOR hcurMove = NULL; // System "Move" cursor.
  27. static HCURSOR hcurSizeNESW = NULL; // System sizing "NESW" cursor.
  28. static HCURSOR hcurSizeNS = NULL; // System sizing "NS" cursor.
  29. static HCURSOR hcurSizeNWSE = NULL; // System sizing "NWSE" cursor.
  30. static HCURSOR hcurSizeWE = NULL; // System sizing "WE" cursor.
  31. static HCURSOR hcurDragTool;
  32. // This array of hCursors is used to map tracker states (see the definition
  33. // of CTracker in editor.hxx) to the appropriate mouse cursor bitmaps.
  34. //
  35. static HCURSOR* mapTrackerStateToPHCursor[] =
  36. {
  37. &hcurArrow, // nil
  38. &hcurArrow, // predrag
  39. &hcurMove, // moving
  40. &hcurSizeNS, // resizingTop
  41. &hcurSizeWE, // resizingLeft
  42. &hcurSizeWE, // resizingRight
  43. &hcurSizeNS, // resizingBottom
  44. &hcurSizeNWSE, // resizingTopLeft
  45. &hcurSizeNESW, // resizingTopRight
  46. &hcurSizeNESW, // resizingBottomLeft
  47. &hcurSizeNWSE, // resizingBottomRight
  48. };
  49. HCURSOR HCursorFromTrackerState( int m )
  50. {
  51. ASSERT(m >= 0 &&
  52. m < sizeof (mapTrackerStateToPHCursor) / sizeof (HCURSOR*));
  53. return (*(mapTrackerStateToPHCursor[m]));
  54. }
  55. /* RVUV2
  56. *
  57. * This code needs to be called, just once, before we begin to use
  58. * trackers. In lieu of a standard initialization function into which
  59. * I can put this code, I am using a moduleInit variable as a kludge.
  60. */
  61. BOOL moduleInit = FALSE; /** RVUV2 temporary! **/
  62. BOOL InitTrackers()
  63. {
  64. /*
  65. * Initialize the brushes and bitmaps needed to do repaints
  66. */
  67. if (! bitmapHorizBorder.CreateBitmap( 8, 8, 1, 1, (LPSTR)bmapHorizBorder )
  68. || ! bitmapVertBorder.CreateBitmap ( 8, 8, 1, 1, (LPSTR)bmapVertBorder )
  69. || ! brushHorizBorder.CreatePatternBrush( &bitmapHorizBorder )
  70. || ! brushVertBorder.CreatePatternBrush ( &bitmapVertBorder )
  71. || ! g_bmapDragHandle.LoadBitmap ( IDBM_DRAGHANDLE )
  72. || ! g_bmapDragHandle2.LoadBitmap( IDBM_DRAGHANDLE2 ))
  73. {
  74. // Future: Failure here should cause error in opening dialog resource!
  75. theApp.SetMemoryEmergency( FALSE );
  76. return FALSE;
  77. }
  78. hcurArrow = theApp.LoadStandardCursor( IDC_ARROW );
  79. hcurMove = theApp.LoadCursor( IDCUR_MOVE );
  80. hcurSizeNESW = theApp.LoadCursor( IDCUR_SIZENESW );
  81. hcurSizeNS = theApp.LoadCursor( IDCUR_SIZENS );
  82. hcurSizeNWSE = theApp.LoadCursor( IDCUR_SIZENWSE );
  83. hcurSizeWE = theApp.LoadCursor( IDCUR_SIZEWE );
  84. hcurDragTool = ::LoadCursor( AfxGetInstanceHandle(),
  85. MAKEINTRESOURCE( IDC_DRAGTOOL ));
  86. moduleInit = TRUE;
  87. return TRUE;
  88. }
  89. /***************************************************************************/
  90. void CTracker::CleanUpTracker()
  91. {
  92. brushHorizBorder.DeleteObject();
  93. brushVertBorder.DeleteObject();
  94. bitmapHorizBorder.DeleteObject();
  95. bitmapVertBorder.DeleteObject();
  96. g_bmapDragHandle.DeleteObject();
  97. g_bmapDragHandle2.DeleteObject();
  98. }
  99. /***************************************************************************/
  100. // NOTE: The rect passed in here is the inner-most rect of the tracker!
  101. CTracker::STATE CTracker::HitTest( const CRect& rc,
  102. CPoint pt,
  103. STATE defaultState )
  104. {
  105. /*
  106. * Compute position of edge (non-corner) handles
  107. */
  108. int xMid = ((rc.right + rc.left) / 2) - (HANDLE_SIZE / 2);
  109. int yMid = ((rc.top + rc.bottom) / 2) - (HANDLE_SIZE / 2);
  110. /*
  111. * Now we do the actual hit-testing for each resizing handle
  112. */
  113. if ((pt.x < rc.left) && (pt.x > rc.left - HANDLE_SIZE))
  114. {
  115. if ((pt.y < rc.top) && (pt.y > rc.top - HANDLE_SIZE))
  116. return(resizingTopLeft);
  117. else
  118. if ((pt.y >= rc.bottom) && (pt.y < rc.bottom + HANDLE_SIZE))
  119. return(resizingBottomLeft);
  120. else
  121. if ( (pt.y >= yMid) && (pt.y < yMid + HANDLE_SIZE) )
  122. return(resizingLeft);
  123. }
  124. else
  125. if ((pt.x >= rc.right) && (pt.x < rc.right + HANDLE_SIZE))
  126. {
  127. if ((pt.y < rc.top) && (pt.y > rc.top - HANDLE_SIZE))
  128. return(resizingTopRight);
  129. else
  130. if ((pt.y >= rc.bottom) && (pt.y < rc.bottom + HANDLE_SIZE))
  131. return(resizingBottomRight);
  132. else
  133. if ((pt.y >= yMid) && (pt.y < yMid + HANDLE_SIZE))
  134. return(resizingRight);
  135. }
  136. else
  137. if ( (pt.x >= xMid) && (pt.x < xMid + HANDLE_SIZE) )
  138. {
  139. if ((pt.y < rc.top) && (pt.y > rc.top - HANDLE_SIZE))
  140. return(resizingTop);
  141. else
  142. if ((pt.y >= rc.bottom) && (pt.y < rc.bottom + HANDLE_SIZE))
  143. return(resizingBottom);
  144. }
  145. return (defaultState);
  146. }
  147. /******************************************************************************/
  148. void CTracker::DrawBorder( CDC* dc, const CRect& trackerRect, EDGES edges )
  149. {
  150. if (! moduleInit)
  151. InitTrackers(); // RVUV2
  152. // Some precalculation for drawing the fuzzy borders
  153. int width = trackerRect.Width();
  154. int height = trackerRect.Height();
  155. int borderWidth = HANDLE_SIZE;
  156. int xLength = width - HANDLE_SIZE * 2;
  157. int xHeight = height - HANDLE_SIZE * 2;
  158. int xRight = trackerRect.left + width - HANDLE_SIZE;
  159. int yBottom = trackerRect.top + height - HANDLE_SIZE;
  160. int iOffset = 1;
  161. // Draw the fuzzy borders. Note that we have different bitmaps for
  162. // the vertical and horizontal borders.
  163. COLORREF windowColor = GetSysColor( COLOR_WINDOW );
  164. COLORREF highlightColor = GetSysColor( COLOR_HIGHLIGHT );
  165. dc->SetTextColor( windowColor ); // colors reversed to adjust for
  166. dc->SetBkColor ( highlightColor ); // patblt's reversed world view.
  167. CBrush* oldBrush = dc->SelectObject( &brushHorizBorder );
  168. if (! (edges & top))
  169. {
  170. dc->SelectObject( GetSysBrush( COLOR_APPWORKSPACE ) );
  171. iOffset = 0;
  172. }
  173. dc->PatBlt( trackerRect.left + HANDLE_SIZE, trackerRect.top + iOffset, xLength, borderWidth - 2 * iOffset, PATCOPY );
  174. dc->PatBlt( trackerRect.left + HANDLE_SIZE, yBottom + iOffset, xLength, borderWidth - 2 * iOffset, PATCOPY );
  175. iOffset = 1;
  176. // dc->SelectObject( &brushVertBorder );
  177. if (! (edges & left))
  178. {
  179. dc->SelectObject( GetSysBrush( COLOR_APPWORKSPACE ) );
  180. iOffset = 0;
  181. }
  182. dc->PatBlt( xRight + iOffset, trackerRect.top + HANDLE_SIZE, borderWidth - 2 * iOffset, xHeight, PATCOPY );
  183. dc->PatBlt( trackerRect.left + iOffset, trackerRect.top + HANDLE_SIZE, borderWidth - 2 * iOffset, xHeight, PATCOPY );
  184. dc->SelectObject( oldBrush ); // clean up
  185. }
  186. /******************************************************************************/
  187. void CTracker::DrawHandles( CDC* dc, const CRect& rect, EDGES edges )
  188. {
  189. /*
  190. * Some precalculation for tracker handles. The bitmaps are colored,
  191. * but the function that loads them adds the windowColor and
  192. * selectionColor.
  193. */
  194. int x = rect.left + rect.Width() - HANDLE_SIZE;
  195. int y = rect.top + rect.Height() - HANDLE_SIZE;
  196. int xMid = rect.left + (((rect.Width() + 1) / 2) - (HANDLE_SIZE / 2));
  197. int yMid = rect.top + (((rect.Height() + 1) / 2) - (HANDLE_SIZE / 2));
  198. BOOL bTopLeft = (edges & top ) && (edges & left );
  199. BOOL bTopRight = (edges & top ) && (edges & right);
  200. BOOL bBottomLeft = (edges & bottom) && (edges & left );
  201. BOOL bBottomRight = (edges & bottom) && (edges & right);
  202. /*
  203. * Choose a solid resizing handle if this is the currently selected
  204. * control, otherwise choose a hollow tracker handle.
  205. */
  206. CDC tempDC;
  207. if (!tempDC.CreateCompatibleDC(dc))
  208. {
  209. theApp.SetGdiEmergency();
  210. return;
  211. }
  212. /*
  213. * Draw the eight resizing handles.
  214. */
  215. dc->SetTextColor( GetSysColor( COLOR_HIGHLIGHT ) );
  216. dc->SetBkColor ( GetSysColor( COLOR_WINDOW ) );
  217. for (int i = 0; i < 2; i += 1)
  218. {
  219. CBitmap* pOldBitmap = tempDC.SelectObject( i? &g_bmapDragHandle2
  220. : &g_bmapDragHandle );
  221. if (bTopLeft)
  222. dc->BitBlt(rect.left, rect.top, HANDLE_SIZE, HANDLE_SIZE,
  223. &tempDC, 0, 0, SRCCOPY);
  224. if (edges & top)
  225. dc->BitBlt(xMid, rect.top, HANDLE_SIZE, HANDLE_SIZE,
  226. &tempDC, 0, 0, SRCCOPY);
  227. if (bTopRight)
  228. dc->BitBlt(x, rect.top, HANDLE_SIZE, HANDLE_SIZE,
  229. &tempDC, 0, 0, SRCCOPY);
  230. if (edges & right)
  231. dc->BitBlt(x, yMid, HANDLE_SIZE, HANDLE_SIZE,
  232. &tempDC, 0, 0, SRCCOPY);
  233. if (bBottomRight)
  234. dc->BitBlt(x, y, HANDLE_SIZE, HANDLE_SIZE,
  235. &tempDC, 0, 0, SRCCOPY);
  236. if (edges & bottom)
  237. dc->BitBlt(xMid, y, HANDLE_SIZE, HANDLE_SIZE,
  238. &tempDC, 0, 0, SRCCOPY);
  239. if (bBottomLeft)
  240. dc->BitBlt(rect.left, y, HANDLE_SIZE, HANDLE_SIZE,
  241. &tempDC, 0, 0, SRCCOPY);
  242. if (edges & left)
  243. dc->BitBlt(rect.left, yMid, HANDLE_SIZE, HANDLE_SIZE,
  244. &tempDC, 0, 0, SRCCOPY);
  245. edges = (EDGES)~(int)edges;
  246. bTopLeft = !bTopLeft;
  247. bTopRight = !bTopRight;
  248. bBottomLeft = !bBottomLeft;
  249. bBottomRight = !bBottomRight;
  250. tempDC.SelectObject(pOldBitmap);
  251. }
  252. }
  253. /******************************************************************************/
  254. void CTracker::DrawBorderRgn( CDC* pdc, const CRect& trackerRect, CRgn *pcRgnPoly)
  255. {
  256. int ixOffset, iyOffset;
  257. if (! moduleInit)
  258. {
  259. InitTrackers(); // RVUV2
  260. }
  261. COLORREF windowColor = GetSysColor( COLOR_WINDOW );
  262. COLORREF highlightColor = GetSysColor( COLOR_HIGHLIGHT );
  263. pdc->SetTextColor( windowColor ); // colors reversed to adjust for
  264. pdc->SetBkColor ( highlightColor ); // patblt's reversed world view.
  265. ixOffset = trackerRect.left + CTracker::HANDLE_SIZE + 1;
  266. iyOffset = trackerRect.top + CTracker::HANDLE_SIZE + 1;
  267. // offset bitmap in the imgwnd from selection boundary
  268. if (pcRgnPoly != NULL
  269. && pcRgnPoly->GetSafeHandle() != NULL)
  270. {
  271. pcRgnPoly->OffsetRgn( ixOffset, iyOffset );
  272. pdc->FrameRgn( pcRgnPoly, &brushVertBorder, 1, 1 );
  273. pcRgnPoly->OffsetRgn( -ixOffset, -iyOffset );
  274. }
  275. }
  276. /******************************************************************************/
  277. void CTracker::DrawHandlesRgn( CDC* dc, const CRect& rect, EDGES edges, CRgn *pcRgnPoly)
  278. {
  279. /*
  280. * Some precalculation for tracker handles. The bitmaps are colored,
  281. * but the function that loads them adds the windowColor and
  282. * selectionColor.
  283. */
  284. }
  285. /******************************************************************************/
  286. CTracker::STATE CTracker::HitTestRgn( const CRect& rc, CPoint pt,
  287. STATE defaultState, CRgn *pcRgnPoly)
  288. {
  289. // if (pcRgnPoly->PtInRegion(pt) != FALSE)
  290. return (defaultState);
  291. }
  292. /******************************************************************************/