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.

304 lines
7.4 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 1993-1994
  4. *
  5. * TITLE: REGDRAG.C
  6. *
  7. * VERSION: 4.01
  8. *
  9. * AUTHOR: Tracy Sharpe
  10. *
  11. * DATE: 05 Mar 1994
  12. *
  13. * Drag and drop routines for the Registry Editor.
  14. *
  15. ********************************************************************************
  16. *
  17. * CHANGE LOG:
  18. *
  19. * DATE REV DESCRIPTION
  20. * ----------- --- -------------------------------------------------------------
  21. * 05 Mar 1994 TCS Original implementation.
  22. *
  23. *******************************************************************************/
  24. #include "pch.h"
  25. #include "regedit.h"
  26. typedef struct _REGDRAGDRATA {
  27. POINT DragRectPoint;
  28. POINT HotSpotPoint;
  29. HWND hLockWnd;
  30. PRECT pDragRectArray;
  31. int DragRectCount;
  32. } REGDRAGDATA;
  33. REGDRAGDATA s_RegDragData;
  34. VOID
  35. PASCAL
  36. DrawDragRects(
  37. VOID
  38. );
  39. /*******************************************************************************
  40. *
  41. * RegEdit_DragObjects
  42. *
  43. * DESCRIPTION:
  44. *
  45. * PARAMETERS:
  46. * hWnd, handle of RegEdit window.
  47. * hSourceWnd, handle of window initiating the drag.
  48. * hDragImageList, image used during drag operation, assumed to be at image
  49. * index 0. May be NULL if pDragRectArray is valid.
  50. * pDragRectArray, array of rectangles to draw during drag operation. May
  51. * be NULL if hDragImageList is valid.
  52. * DragRectCount, number of rectangles pointed to be pDragRectArray.
  53. * HotSpotPoint, offset of the cursor hotpoint relative to the image.
  54. *
  55. *******************************************************************************/
  56. VOID
  57. PASCAL
  58. RegEdit_DragObjects(
  59. HWND hWnd,
  60. HIMAGELIST hDragImageList,
  61. PRECT pDragRectArray,
  62. int DragRectCount,
  63. POINT HotSpotPoint
  64. )
  65. {
  66. RECT CurrentDropRect;
  67. HCURSOR hDropCursor;
  68. HCURSOR hNoDropCursor;
  69. HCURSOR hDragCursor;
  70. HCURSOR hNewDragCursor;
  71. POINT Point;
  72. BOOL fContinueDrag;
  73. MSG Msg;
  74. MSG PeekMsg;
  75. HTREEITEM hCurrentDropTreeItem = NULL;
  76. GetWindowRect(g_RegEditData.hKeyTreeWnd, &CurrentDropRect);
  77. GetCursorPos(&Point);
  78. Point.x -= CurrentDropRect.left;
  79. Point.y -= CurrentDropRect.top;
  80. if (hDragImageList != NULL) {
  81. if ( ImageList_BeginDrag(hDragImageList, 0, HotSpotPoint.x, HotSpotPoint.y) ) {
  82. ImageList_DragEnter(g_RegEditData.hKeyTreeWnd, Point.x, Point.y );
  83. }
  84. }
  85. s_RegDragData.hLockWnd = g_RegEditData.hKeyTreeWnd;
  86. LockWindowUpdate(s_RegDragData.hLockWnd);
  87. if (hDragImageList != NULL) {
  88. ShowCursor(FALSE);
  89. ImageList_DragShowNolock(TRUE);
  90. }
  91. else {
  92. s_RegDragData.HotSpotPoint = HotSpotPoint;
  93. s_RegDragData.pDragRectArray = pDragRectArray;
  94. s_RegDragData.DragRectCount = DragRectCount;
  95. s_RegDragData.DragRectPoint = Point;
  96. DrawDragRects();
  97. }
  98. hDropCursor = LoadCursor(NULL, IDC_ARROW);
  99. hDragCursor = hDropCursor;
  100. hNoDropCursor = LoadCursor(NULL, IDC_NO);
  101. SetCapture(hWnd);
  102. fContinueDrag = TRUE;
  103. while (fContinueDrag && GetMessage(&Msg, NULL, 0, 0)) {
  104. switch (Msg.message) {
  105. case WM_MOUSEMOVE:
  106. //
  107. // If we have another WM_MOUSEMOVE message in the queue
  108. // (before any other mouse message), don't process this
  109. // mouse message.
  110. //
  111. if (PeekMessage(&PeekMsg, NULL, WM_MOUSEFIRST, WM_MOUSELAST,
  112. PM_NOREMOVE) && PeekMsg.message == WM_MOUSEMOVE)
  113. break;
  114. if (!PtInRect(&CurrentDropRect, Msg.pt)) {
  115. hNewDragCursor = hNoDropCursor;
  116. }
  117. else {
  118. hNewDragCursor = hDropCursor;
  119. }
  120. if (hNewDragCursor != hDragCursor) {
  121. if (hDragImageList != NULL) {
  122. if (hNewDragCursor == hDropCursor) {
  123. ImageList_DragShowNolock(TRUE);
  124. ShowCursor(FALSE);
  125. }
  126. else {
  127. ImageList_DragShowNolock(FALSE);
  128. ShowCursor(TRUE);
  129. SetCursor(hNewDragCursor);
  130. }
  131. }
  132. else
  133. SetCursor(hNewDragCursor);
  134. hDragCursor = hNewDragCursor;
  135. }
  136. Msg.pt.x -= CurrentDropRect.left;
  137. Msg.pt.y -= CurrentDropRect.top;
  138. {
  139. TV_HITTESTINFO TVHitTestInfo;
  140. HTREEITEM hTreeItem;
  141. TVHitTestInfo.pt = Msg.pt;
  142. hTreeItem = TreeView_HitTest(g_RegEditData.hKeyTreeWnd, &TVHitTestInfo);
  143. if (hTreeItem != hCurrentDropTreeItem) {
  144. ImageList_DragShowNolock(FALSE);
  145. // DbgPrintf(("Got a drop target!!!\n"));
  146. // SetWindowRedraw(g_RegEditData.hKeyTreeWnd, FALSE);
  147. TreeView_SelectDropTarget(g_RegEditData.hKeyTreeWnd, hTreeItem);
  148. // SetWindowRedraw(g_RegEditData.hKeyTreeWnd, TRUE);
  149. hCurrentDropTreeItem = hTreeItem;
  150. ImageList_DragShowNolock(TRUE);
  151. }
  152. }
  153. if (hDragImageList != NULL)
  154. ImageList_DragMove(Msg.pt.x, Msg.pt.y);
  155. else {
  156. DrawDragRects();
  157. s_RegDragData.DragRectPoint = Msg.pt;
  158. DrawDragRects();
  159. }
  160. break;
  161. case WM_KEYDOWN:
  162. if (Msg.wParam != VK_ESCAPE)
  163. break;
  164. // FALL THROUGH
  165. case WM_LBUTTONDOWN:
  166. case WM_RBUTTONDOWN:
  167. fContinueDrag = FALSE;
  168. break;
  169. case WM_LBUTTONUP:
  170. case WM_RBUTTONUP:
  171. fContinueDrag = FALSE;
  172. break;
  173. default:
  174. TranslateMessage(&Msg);
  175. DispatchMessage(&Msg);
  176. break;
  177. }
  178. }
  179. ReleaseCapture();
  180. if (hDragImageList != NULL) {
  181. ImageList_DragShowNolock(FALSE);
  182. ImageList_EndDrag();
  183. if (hDragCursor == hDropCursor)
  184. ShowCursor(TRUE);
  185. }
  186. else
  187. DrawDragRects();
  188. LockWindowUpdate(NULL);
  189. }
  190. /*******************************************************************************
  191. *
  192. * DragDragRects
  193. *
  194. * DESCRIPTION:
  195. *
  196. * PARAMETERS:
  197. * (none).
  198. *
  199. *******************************************************************************/
  200. VOID
  201. PASCAL
  202. DrawDragRects(
  203. VOID
  204. )
  205. {
  206. HDC hDC;
  207. int Index;
  208. RECT Rect;
  209. hDC = GetDCEx(s_RegDragData.hLockWnd, NULL, DCX_WINDOW | DCX_CACHE |
  210. DCX_LOCKWINDOWUPDATE);
  211. for (Index = s_RegDragData.DragRectCount; Index >= 0; Index--) {
  212. Rect = s_RegDragData.pDragRectArray[Index];
  213. OffsetRect(&Rect, s_RegDragData.DragRectPoint.x -
  214. s_RegDragData.HotSpotPoint.x, s_RegDragData.DragRectPoint.y -
  215. s_RegDragData.HotSpotPoint.y);
  216. DrawFocusRect(hDC, &Rect);
  217. }
  218. ReleaseDC(s_RegDragData.hLockWnd, hDC);
  219. }