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.

3777 lines
110 KiB

  1. #include "ctlspriv.h"
  2. #include "image.h"
  3. #define CCHLABELMAX MAX_PATH // borrowed from listview.h
  4. #define HDDF_NOIMAGE 0x0001
  5. #define HDDF_NOEDGE 0x0002
  6. #define HDI_ALL95 0x001f
  7. #define TF_HEADER TF_LISTVIEW
  8. #define HD_EDITCHANGETIMER 0x100
  9. #define c_cxFilterBarEdge (1)
  10. #define c_cyFilterBarEdge (1)
  11. #define c_cxFilterImage (13)
  12. #define c_cyFilterImage (12)
  13. typedef struct
  14. {
  15. int x; // this is the x position of the RIGHT side (divider) of this item
  16. int cxy;
  17. int fmt;
  18. LPTSTR pszText;
  19. HBITMAP hbm;
  20. int iImage; // index of bitmap in imagelist
  21. LPARAM lParam;
  22. int xBm; // cached values
  23. int xText; // for implementing text and bitmap in header
  24. int cxTextAndBm;
  25. // information used for the filter contol
  26. UINT idOperator;
  27. UINT type;
  28. HD_TEXTFILTER textFilter;
  29. int intFilter;
  30. } HDI;
  31. typedef struct
  32. {
  33. CCONTROLINFO ci;
  34. UINT flags;
  35. int cxEllipses;
  36. int cxDividerSlop;
  37. int cyChar;
  38. HFONT hfont;
  39. HFONT hfontSortArrow;
  40. HIMAGELIST hFilterImage;
  41. HDSA hdsaHDI; // list of HDI's
  42. // tracking state info
  43. int iTrack;
  44. BITBOOL bTrackPress :1; // is the button pressed?
  45. BITBOOL fTrackSet:1;
  46. BITBOOL fOwnerDraw:1;
  47. BITBOOL fFocus:1;
  48. BITBOOL fFilterChangePending:1;
  49. UINT flagsTrack;
  50. int dxTrack; // the distance from the divider that the user started tracking
  51. int xTrack; // the current track position (or starting track position on a button drag)
  52. int xMinTrack; // the x of the end of the previous item (left limit)
  53. int xTrackOldWidth;
  54. HIMAGELIST himl; // handle to our image list
  55. HDSA hdsaOrder; // this is an index array of the hdsaHDI items.
  56. // this is the physical order of items
  57. int iHot ;
  58. HIMAGELIST himlDrag;
  59. int iNewOrder; // what's the new insertion point for a d/d?
  60. int iTextMargin; // The margin to place on either side of text or bitmaps
  61. int iBmMargin; // Normally, 3 * g_cxLabelMargin
  62. int iFocus; // focus object
  63. int iEdit; // editing object
  64. int iButtonDown;
  65. int iFilterChangeTimeout;
  66. HWND hwndEdit;
  67. WNDPROC pfnEditWndProc;
  68. int typeOld;
  69. LPTSTR pszFilterOld;
  70. int intFilterOld;
  71. HTHEME hTheme;
  72. } HD;
  73. LRESULT CALLBACK Header_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  74. // Message handler functions
  75. BOOL Header_OnCreate(HD* phd, CREATESTRUCT* lpCreateStruct);
  76. void Header_OnNCDestroy(HD* phd);
  77. HIMAGELIST Header_OnSetImageList(HD* phd, HIMAGELIST himl);
  78. HIMAGELIST Header_OnGetImageList(HD* phd);
  79. void Header_OnPaint(HD* phd, HDC hdcIn);
  80. void Header_OnCommand(HD* phd, int id, HWND hwndCtl, UINT codeNotify);
  81. void Header_OnEnable(HD* phd, BOOL fEnable);
  82. UINT Header_OnGetDlgCode(HD* phd, MSG* lpmsg);
  83. void Header_OnLButtonDown(HD* phd, BOOL fDoubleClick, int x, int y, UINT keyFlags);
  84. BOOL Header_IsTracking(HD* phd);
  85. void Header_OnMouseMove(HD* phd, int x, int y, UINT keyFlags);
  86. void Header_OnLButtonUp(HD* phd, int x, int y, UINT keyFlags);
  87. void Header_OnSetFont(HD* plv, HFONT hfont, BOOL fRedraw);
  88. int Header_OnHitTest(HD* phd, HD_HITTESTINFO *phdht);
  89. HFONT Header_OnGetFont(HD* plv);
  90. HIMAGELIST Header_OnCreateDragImage(HD* phd, int i);
  91. BOOL Header_OnGetItemRect(HD* phd, int i, RECT* prc);
  92. void Header_Draw(HD* phd, HDC hdc, RECT* prcClip);
  93. void Header_InvalidateItem(HD* phd, int i, UINT uFlags );
  94. void Header_GetDividerRect(HD* phd, int i, LPRECT prc);
  95. LPARAM Header_OnSetHotDivider(HD* phd, BOOL fPos, LPARAM lParam);
  96. void Header_GetFilterRects(LPRECT prcItem, LPRECT prcHeader, LPRECT prcEdit, LPRECT prcButton);
  97. BOOL Header_BeginFilterEdit(HD* phd, int i);
  98. VOID Header_StopFilterEdit(HD* phd, BOOL fDiscardChanges);
  99. VOID Header_FilterChanged(HD* phd, BOOL fWait);
  100. VOID Header_OnFilterButton(HD* phd, INT i);
  101. LRESULT Header_OnClearFilter(HD* phd, INT i);
  102. // HDM_* Message handler functions
  103. int Header_OnInsertItem(HD* phd, int i, const HD_ITEM* pitem);
  104. BOOL Header_OnDeleteItem(HD* phd, int i);
  105. BOOL Header_OnGetItem(HD* phd, int i, HD_ITEM* pitem);
  106. BOOL Header_OnSetItem(HD* phd, int i, const HD_ITEM* pitem);
  107. BOOL Header_OnLayout(HD* phd, HD_LAYOUT* playout);
  108. BOOL Header_OnSetCursor(HD* phd, HWND hwndCursor, UINT codeHitTest, UINT msg);
  109. void Header_DrawDivider(HD* phd, int x);
  110. int Header_OnInsertItemA(HD* phd, int i, HD_ITEMA* pitem);
  111. BOOL Header_OnGetItemA(HD* phd, int i, HD_ITEMA* pitem);
  112. BOOL Header_OnSetItemA(HD* phd, int i, HD_ITEMA* pitem);
  113. void Header_EndDrag(HD* phd);
  114. BOOL Header_SendChange(HD* phd, int i, int code, const HD_ITEM* pitem);
  115. BOOL Header_Notify(HD* phd, int i, int iButton, int code);
  116. #define Header_GetItemPtr(phd, i) (HDI*)DSA_GetItemPtr((phd)->hdsaHDI, (i))
  117. #define Header_GetCount(phd) (DSA_GetItemCount((phd)->hdsaHDI))
  118. #define Header_IsFilter(phd) ((phd)->ci.style & HDS_FILTERBAR)
  119. #pragma code_seg(CODESEG_INIT)
  120. BOOL Header_Init(HINSTANCE hinst)
  121. {
  122. WNDCLASS wc;
  123. wc.lpfnWndProc = Header_WndProc;
  124. wc.hCursor = NULL; // we do WM_SETCURSOR handling
  125. wc.hIcon = NULL;
  126. wc.lpszMenuName = NULL;
  127. wc.hInstance = hinst;
  128. wc.lpszClassName = c_szHeaderClass;
  129. wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
  130. wc.style = CS_DBLCLKS | CS_GLOBALCLASS;
  131. wc.cbWndExtra = sizeof(HD*);
  132. wc.cbClsExtra = 0;
  133. return (RegisterClass(&wc) || (GetLastError() == ERROR_CLASS_ALREADY_EXISTS));
  134. }
  135. #pragma code_seg()
  136. // returns -1 if failed to find the item
  137. int Header_OnGetItemOrder(HD* phd, int i)
  138. {
  139. int iIndex;
  140. // if there's no hdsaOrder, then it's in index order
  141. if (phd->hdsaOrder) {
  142. int j;
  143. int iData;
  144. iIndex = -1;
  145. for (j = 0; j < DSA_GetItemCount(phd->hdsaOrder); j++) {
  146. DSA_GetItem(phd->hdsaOrder, j, &iData);
  147. if (iData == i) {
  148. iIndex = j;
  149. break;
  150. }
  151. }
  152. } else {
  153. iIndex = i;
  154. }
  155. return iIndex;
  156. }
  157. int Header_ItemOrderToIndex(HD* phd, int iOrder)
  158. {
  159. RIPMSG(iOrder < DSA_GetItemCount(phd->hdsaHDI), "HDM_ORDERTOINDEX: Invalid order %d", iOrder);
  160. if (phd->hdsaOrder) {
  161. ASSERT(DSA_GetItemCount(phd->hdsaHDI) == DSA_GetItemCount(phd->hdsaOrder));
  162. #ifdef DEBUG
  163. // DSA_GetItem will assert on an invalid index, so filter it out
  164. // so all we get is the RIP above.
  165. if (iOrder < DSA_GetItemCount(phd->hdsaOrder))
  166. #endif
  167. DSA_GetItem(phd->hdsaOrder, iOrder, &iOrder);
  168. }
  169. return iOrder;
  170. }
  171. HDI* Header_GetItemPtrByOrder(HD* phd, int iOrder)
  172. {
  173. int iIndex = Header_ItemOrderToIndex(phd, iOrder);
  174. return Header_GetItemPtr(phd, iIndex);
  175. }
  176. HDSA Header_InitOrderArray(HD* phd)
  177. {
  178. int i;
  179. if (!phd->hdsaOrder && !(phd->ci.style & HDS_OWNERDATA)) {
  180. // not initialized yet..
  181. // create an array with i to i mapping
  182. phd->hdsaOrder = DSA_Create(sizeof(int), 4);
  183. if (phd->hdsaOrder) {
  184. for (i = 0; i < Header_GetCount(phd); i++) {
  185. if (DSA_InsertItem(phd->hdsaOrder, i, &i) == -1) {
  186. // faild to add... bail
  187. DSA_Destroy(phd->hdsaOrder);
  188. phd->hdsaOrder = NULL;
  189. }
  190. }
  191. }
  192. }
  193. return phd->hdsaOrder;
  194. }
  195. // this moves all items starting from iIndex over by dx
  196. void Header_ShiftItems(HD* phd, int iOrder, int dx)
  197. {
  198. for(; iOrder < Header_GetCount(phd); iOrder++) {
  199. HDI* phdi = Header_GetItemPtrByOrder(phd, iOrder);
  200. phdi->x += dx;
  201. }
  202. }
  203. void Header_OnSetItemOrder(HD* phd, int iIndex, int iOrder)
  204. {
  205. if (iIndex < Header_GetCount(phd) &&
  206. iOrder < Header_GetCount(phd) &&
  207. Header_InitOrderArray(phd)) {
  208. int iCurOrder = Header_OnGetItemOrder(phd, iIndex);
  209. // only do work if the order is changing
  210. if (iOrder != iCurOrder) {
  211. // delete the current order location
  212. HDI* phdi = Header_GetItemPtr(phd, iIndex);
  213. HDI* phdiOld = Header_GetItemPtrByOrder(phd, iOrder);
  214. // stop editing the filter
  215. Header_StopFilterEdit(phd, FALSE);
  216. // remove iIndex from the current order
  217. // (slide stuff to the right down by our width)
  218. Header_ShiftItems(phd, iCurOrder + 1, -phdi->cxy);
  219. DSA_DeleteItem(phd->hdsaOrder, iCurOrder);
  220. // insert it into the order and slide everything else over
  221. // (slide stuff to the right of the new position up by our width)
  222. DSA_InsertItem(phd->hdsaOrder, iOrder, &iIndex);
  223. // set our right edge to where their left edge was
  224. Header_ShiftItems(phd, iOrder + 1, phdi->cxy);
  225. if (iOrder == 0) {
  226. phdi->x = phdi->cxy;
  227. } else {
  228. phdiOld = Header_GetItemPtrByOrder(phd, iOrder - 1);
  229. phdi->x = phdiOld->x + phdi->cxy;
  230. }
  231. RedrawWindow(phd->ci.hwnd, NULL, NULL, RDW_INVALIDATE | RDW_ERASE);
  232. }
  233. }
  234. }
  235. void Header_SetHotItem(HD* phd, int i)
  236. {
  237. if (i != phd->iHot) {
  238. Header_InvalidateItem(phd, i, RDW_INVALIDATE);
  239. Header_InvalidateItem(phd, phd->iHot, RDW_INVALIDATE);
  240. phd->iHot = i;
  241. }
  242. }
  243. LRESULT Header_OnGetOrderArray(HD* phd, int iCount, LPINT lpi)
  244. {
  245. int i;
  246. if (Header_GetCount(phd) != iCount)
  247. return FALSE;
  248. for (i = 0; i < Header_GetCount(phd) ; i++) {
  249. lpi[i] = Header_ItemOrderToIndex(phd, i);
  250. }
  251. return TRUE;
  252. }
  253. LRESULT Header_OnSetOrderArray(HD* phd, int iCount, LPINT lpi)
  254. {
  255. int i;
  256. if (Header_GetCount(phd) != iCount)
  257. return FALSE;
  258. for (i = 0; i < Header_GetCount(phd); i++) {
  259. Header_OnSetItemOrder(phd, lpi[i], i);
  260. }
  261. NotifyWinEvent(EVENT_OBJECT_REORDER, phd->ci.hwnd, OBJID_CLIENT, 0);
  262. return TRUE;
  263. }
  264. BOOL HDDragFullWindows(HD* phd)
  265. {
  266. return (g_fDragFullWindows && (phd->ci.style & HDS_FULLDRAG));
  267. }
  268. LRESULT CALLBACK Header_WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  269. {
  270. HD* phd = (HD*)GetWindowPtr(hwnd, 0);
  271. if (phd == NULL)
  272. {
  273. if (uMsg == WM_NCCREATE)
  274. {
  275. phd = (HD*)NearAlloc(sizeof(HD));
  276. if (phd == NULL)
  277. return 0L;
  278. phd->ci.hwnd = hwnd;
  279. phd->ci.hwndParent = ((LPCREATESTRUCT)lParam)->hwndParent;
  280. SetWindowPtr(hwnd, 0, phd);
  281. // fall through to call DefWindowProc
  282. }
  283. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  284. }
  285. else
  286. {
  287. if (uMsg == WM_THEMECHANGED)
  288. {
  289. if (phd->hTheme)
  290. CloseThemeData(phd->hTheme);
  291. phd->hTheme = OpenThemeData(phd->ci.hwnd, L"Header");
  292. InvalidateRect(phd->ci.hwnd, NULL, TRUE);
  293. return 0;
  294. }
  295. if (uMsg == WM_NCDESTROY)
  296. {
  297. Header_OnNCDestroy(phd);
  298. NearFree(phd);
  299. SetWindowInt(hwnd, 0, 0);
  300. return 0;
  301. }
  302. // if we loose capture, or the r-button goes down, or the user hits esc, then we abort the drag/resize
  303. if (uMsg == WM_CAPTURECHANGED ||
  304. uMsg == WM_RBUTTONDOWN || (GetKeyState(VK_ESCAPE) & 0x8000)) {
  305. if (phd->himlDrag) {
  306. // if this is the end of a drag,
  307. // notify the user.
  308. HDITEM item;
  309. item.mask = HDI_ORDER;
  310. item.iOrder = -1; // abort order changing
  311. Header_EndDrag(phd);
  312. Header_SendChange(phd, phd->iTrack, HDN_ENDDRAG, &item);
  313. } else if (phd->flagsTrack & (HHT_ONDIVIDER | HHT_ONDIVOPEN)) {
  314. HD_ITEM item;
  315. item.mask = HDI_WIDTH;
  316. item.cxy = phd->xTrackOldWidth;
  317. phd->flagsTrack = 0;
  318. KillTimer(phd->ci.hwnd, 1);
  319. CCReleaseCapture(&phd->ci);
  320. Header_SendChange(phd, phd->iTrack, HDN_ENDTRACK, &item);
  321. if (HDDragFullWindows(phd)) {
  322. // incase they changed something
  323. item.mask = HDI_WIDTH;
  324. item.cxy = phd->xTrackOldWidth;
  325. Header_OnSetItem(phd, phd->iTrack, &item);
  326. RedrawWindow(phd->ci.hwnd, NULL, NULL, RDW_INVALIDATE | RDW_ERASE);
  327. } else {
  328. // Undraw the last divider we displayed
  329. Header_DrawDivider(phd, phd->xTrack);
  330. }
  331. }
  332. }
  333. if ((uMsg >= WM_MOUSEFIRST) && (uMsg <= WM_MOUSELAST) &&
  334. (phd->hTheme || phd->ci.style & HDS_HOTTRACK) && !phd->fTrackSet) {
  335. TRACKMOUSEEVENT tme;
  336. phd->fTrackSet = TRUE;
  337. tme.cbSize = sizeof(tme);
  338. tme.hwndTrack = phd->ci.hwnd;
  339. tme.dwFlags = TME_LEAVE;
  340. TrackMouseEvent(&tme);
  341. }
  342. // ROBUSTNESS: keep this switch within the if (phd) block
  343. //
  344. switch (uMsg)
  345. {
  346. HANDLE_MSG(phd, WM_CREATE, Header_OnCreate);
  347. HANDLE_MSG(phd, WM_SETCURSOR, Header_OnSetCursor);
  348. HANDLE_MSG(phd, WM_MOUSEMOVE, Header_OnMouseMove);
  349. HANDLE_MSG(phd, WM_LBUTTONDOWN, Header_OnLButtonDown);
  350. HANDLE_MSG(phd, WM_LBUTTONDBLCLK, Header_OnLButtonDown);
  351. HANDLE_MSG(phd, WM_LBUTTONUP, Header_OnLButtonUp);
  352. HANDLE_MSG(phd, WM_GETDLGCODE, Header_OnGetDlgCode);
  353. HANDLE_MSG(phd, WM_SETFONT, Header_OnSetFont);
  354. HANDLE_MSG(phd, WM_GETFONT, Header_OnGetFont);
  355. case WM_COMMAND:
  356. if ( (phd->iEdit>=0) && ((HWND)lParam == phd->hwndEdit) )
  357. {
  358. // when filtering we will receive notifications that the filter
  359. // has been edited, therefore lets send those down to the
  360. // parent.
  361. if ( HIWORD(wParam)==EN_CHANGE )
  362. {
  363. Header_FilterChanged(phd, TRUE);
  364. return(0);
  365. }
  366. }
  367. break;
  368. case WM_TIMER:
  369. if (wParam == HD_EDITCHANGETIMER)
  370. {
  371. Header_FilterChanged(phd, FALSE);
  372. return(0);
  373. }
  374. break;
  375. case WM_SETFOCUS:
  376. case WM_KILLFOCUS:
  377. // filter bar and not editing then take caret into edit first column
  378. if (Header_IsFilter(phd))
  379. {
  380. phd->fFocus = (uMsg==WM_SETFOCUS);
  381. Header_InvalidateItem(phd, Header_ItemOrderToIndex(phd, phd->iFocus), RDW_INVALIDATE);
  382. UpdateWindow(phd->ci.hwnd);
  383. return(0);
  384. }
  385. break;
  386. case WM_KEYDOWN:
  387. if ( phd->fFocus )
  388. {
  389. // handle the key events that the header control receives, when the filter
  390. // bar is displayed we then allow the user to enter filter mode and drop the
  391. // filter menu.
  392. //
  393. // F2 = enter filter mode
  394. // F4 = drop filter menu
  395. // -> = next column
  396. // <- = previous column
  397. if ( wParam == VK_F2 )
  398. {
  399. // start editing the currently focused column
  400. Header_BeginFilterEdit(phd, Header_ItemOrderToIndex(phd, phd->iFocus));
  401. //notify of navigation key usage
  402. CCNotifyNavigationKeyUsage(&(phd->ci), UISF_HIDEFOCUS);
  403. return 0L;
  404. }
  405. else if ( wParam == VK_F4 )
  406. {
  407. // drop the filter menu (this exits edit mode)
  408. Header_OnFilterButton(phd, Header_ItemOrderToIndex(phd, phd->iFocus));
  409. //notify of navigation key usage
  410. CCNotifyNavigationKeyUsage(&(phd->ci), UISF_HIDEFOCUS);
  411. return 0L;
  412. }
  413. else if ( (wParam == VK_LEFT)||(wParam == VK_RIGHT) )
  414. {
  415. INT iFocus = phd->iFocus;
  416. // move to previous or next column
  417. if ( wParam == VK_RIGHT )
  418. {
  419. phd->iFocus = (iFocus+1) % Header_GetCount(phd);
  420. }
  421. else
  422. {
  423. phd->iFocus = iFocus-1;
  424. if ( phd->iFocus < 0 )
  425. phd->iFocus = max(Header_GetCount(phd)-1, 0);
  426. }
  427. // did the focused column change? if so then update the control
  428. // as required.
  429. if ( iFocus != phd->iFocus )
  430. {
  431. Header_InvalidateItem(phd, Header_ItemOrderToIndex(phd, iFocus), RDW_INVALIDATE);
  432. Header_InvalidateItem(phd, Header_ItemOrderToIndex(phd, phd->iFocus), RDW_INVALIDATE);
  433. UpdateWindow(phd->ci.hwnd);
  434. }
  435. //notify of navigation key usage
  436. CCNotifyNavigationKeyUsage(&(phd->ci), UISF_HIDEFOCUS);
  437. return 0L;
  438. }
  439. }
  440. break;
  441. case WM_MOUSELEAVE:
  442. Header_SetHotItem(phd, -1);
  443. phd->fTrackSet = FALSE;
  444. break;
  445. case WM_ERASEBKGND:
  446. return 1;
  447. case WM_PRINTCLIENT:
  448. case WM_PAINT:
  449. Header_OnPaint(phd, (HDC)wParam);
  450. return(0);
  451. case WM_RBUTTONUP:
  452. if (CCSendNotify(&phd->ci, NM_RCLICK, NULL))
  453. return(0);
  454. break;
  455. case WM_STYLECHANGED:
  456. if (wParam == GWL_STYLE) {
  457. LPSTYLESTRUCT pss = (LPSTYLESTRUCT)lParam;
  458. phd->ci.style = pss->styleNew;
  459. // if the filter is changing then discard it if its active
  460. if ((pss->styleOld & HDS_FILTERBAR) != (pss->styleNew & HDS_FILTERBAR))
  461. Header_StopFilterEdit(phd, TRUE);
  462. // we don't cache our style so relay out and invaidate
  463. InvalidateRect(phd->ci.hwnd, NULL, TRUE);
  464. }
  465. return(0);
  466. case WM_UPDATEUISTATE:
  467. {
  468. DWORD dwUIStateMask = MAKEWPARAM(0xFFFF, UISF_HIDEFOCUS);
  469. if (CCOnUIState(&(phd->ci), WM_UPDATEUISTATE, wParam & dwUIStateMask, lParam) &&
  470. phd->iFocus < DSA_GetItemCount(phd->hdsaHDI))
  471. {
  472. Header_InvalidateItem(phd, Header_ItemOrderToIndex(phd, phd->iFocus), RDW_INVALIDATE);
  473. }
  474. break;
  475. }
  476. case WM_NOTIFYFORMAT:
  477. return CIHandleNotifyFormat(&phd->ci, lParam);
  478. case HDM_GETITEMCOUNT:
  479. return (LPARAM)(UINT)DSA_GetItemCount(phd->hdsaHDI);
  480. case HDM_INSERTITEM:
  481. return (LPARAM)Header_OnInsertItem(phd, (int)wParam, (const HD_ITEM*)lParam);
  482. case HDM_DELETEITEM:
  483. return (LPARAM)Header_OnDeleteItem(phd, (int)wParam);
  484. case HDM_GETITEM:
  485. return (LPARAM)Header_OnGetItem(phd, (int)wParam, (HD_ITEM*)lParam);
  486. case HDM_SETITEM:
  487. return (LPARAM)Header_OnSetItem(phd, (int)wParam, (const HD_ITEM*)lParam);
  488. case HDM_LAYOUT:
  489. return (LPARAM)Header_OnLayout(phd, (HD_LAYOUT*)lParam);
  490. case HDM_HITTEST:
  491. return (LPARAM)Header_OnHitTest(phd, (HD_HITTESTINFO *)lParam);
  492. case HDM_GETITEMRECT:
  493. return (LPARAM)Header_OnGetItemRect(phd, (int)wParam, (LPRECT)lParam);
  494. case HDM_SETIMAGELIST:
  495. return (LRESULT)(ULONG_PTR)Header_OnSetImageList(phd, (HIMAGELIST)lParam);
  496. case HDM_GETIMAGELIST:
  497. return (LRESULT)(ULONG_PTR)phd->himl;
  498. case HDM_INSERTITEMA:
  499. return (LPARAM)Header_OnInsertItemA(phd, (int)wParam, (HD_ITEMA*)lParam);
  500. case HDM_GETITEMA:
  501. return (LPARAM)Header_OnGetItemA(phd, (int)wParam, (HD_ITEMA*)lParam);
  502. case HDM_SETITEMA:
  503. return (LPARAM)Header_OnSetItemA(phd, (int)wParam, (HD_ITEMA*)lParam);
  504. case HDM_ORDERTOINDEX:
  505. return Header_ItemOrderToIndex(phd, (int)wParam);
  506. case HDM_CREATEDRAGIMAGE:
  507. return (LRESULT)Header_OnCreateDragImage(phd, Header_OnGetItemOrder(phd, (int)wParam));
  508. case HDM_SETORDERARRAY:
  509. return Header_OnSetOrderArray(phd, (int)wParam, (LPINT)lParam);
  510. case HDM_GETORDERARRAY:
  511. return Header_OnGetOrderArray(phd, (int)wParam, (LPINT)lParam);
  512. case HDM_SETHOTDIVIDER:
  513. return Header_OnSetHotDivider(phd, (int)wParam, lParam);
  514. case HDM_SETBITMAPMARGIN:
  515. phd->iBmMargin = (int)wParam;
  516. TraceMsg(TF_HEADER, "Setting bmMargin = %d",wParam);
  517. return TRUE;
  518. case HDM_GETBITMAPMARGIN:
  519. return phd->iBmMargin;
  520. case HDM_EDITFILTER:
  521. Header_StopFilterEdit(phd, (BOOL)LOWORD(lParam));
  522. return Header_BeginFilterEdit(phd, (int)wParam);
  523. case HDM_SETFILTERCHANGETIMEOUT:
  524. if ( lParam ) {
  525. int iOldTimeout = phd->iFilterChangeTimeout;
  526. phd->iFilterChangeTimeout = (int)lParam;
  527. return(iOldTimeout);
  528. }
  529. return(phd->iFilterChangeTimeout);
  530. case HDM_CLEARFILTER:
  531. return Header_OnClearFilter(phd, (int)wParam);
  532. case WM_GETOBJECT:
  533. if( lParam == OBJID_QUERYCLASSNAMEIDX )
  534. return MSAA_CLASSNAMEIDX_HEADER;
  535. break;
  536. default:
  537. {
  538. LRESULT lres;
  539. if (CCWndProc(&phd->ci, uMsg, wParam, lParam, &lres))
  540. return lres;
  541. }
  542. }
  543. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  544. }
  545. }
  546. BOOL Header_SendChange(HD* phd, int i, int code, const HD_ITEM* pitem)
  547. {
  548. NMHEADER nm;
  549. nm.iItem = i;
  550. nm.pitem = (HD_ITEM*)pitem;
  551. nm.iButton = 0;
  552. return !(BOOL)CCSendNotify(&phd->ci, code, &nm.hdr);
  553. }
  554. BOOL Header_Notify(HD* phd, int i, int iButton, int code)
  555. {
  556. NMHEADER nm;
  557. nm.iItem = i;
  558. nm.iButton = iButton;
  559. nm.pitem = NULL;
  560. return !(BOOL)CCSendNotify(&phd->ci, code, &nm.hdr);
  561. }
  562. void Header_NewFont(HD* phd, HFONT hfont)
  563. {
  564. HDC hdc;
  565. SIZE siz = {0};
  566. HRESULT hr = E_FAIL;
  567. HFONT hFontOld = NULL;
  568. int cy;
  569. TEXTMETRIC tm;
  570. HFONT hfontSortArrow = NULL;
  571. hdc = GetDC(HWND_DESKTOP);
  572. if (phd->hTheme)
  573. {
  574. RECT rc = {0};
  575. RECT rcBound = {0};
  576. hr = GetThemeTextExtent(phd->hTheme, hdc, HP_HEADERITEM, 0, TEXT("M"), -1, 0, &rcBound, &rc);
  577. siz.cx = RECTWIDTH(rc);
  578. siz.cy = RECTHEIGHT(rc);
  579. }
  580. if (FAILED(hr))
  581. {
  582. if (hfont)
  583. SelectFont(hdc, hfont);
  584. GetTextExtentPoint(hdc, c_szEllipses, CCHELLIPSES, &siz);
  585. }
  586. if (phd->hfont)
  587. hFontOld = (HFONT)SelectObject(hdc, phd->hfont);
  588. GetTextMetrics(hdc, &tm);
  589. if (hFontOld)
  590. SelectObject(hdc, hFontOld);
  591. // Set the font height (based on original USER code)
  592. cy = ((tm.tmHeight + tm.tmExternalLeading + GetSystemMetrics(SM_CYBORDER)) & 0xFFFE) - 1;
  593. // Create the marlett font, so we can paint the arrows.
  594. hfontSortArrow = CreateFont(cy, 0, 0, 0, 0, FALSE, FALSE, FALSE, DEFAULT_CHARSET, 0, 0, 0, 0,
  595. TEXT("Marlett"));
  596. phd->cxEllipses = siz.cx;
  597. phd->cyChar = siz.cy;
  598. phd->hfont = hfont;
  599. if (hfontSortArrow)
  600. {
  601. if (phd->hfontSortArrow) // Do we have one to free?
  602. {
  603. DeleteObject(phd->hfontSortArrow);
  604. }
  605. phd->hfontSortArrow = hfontSortArrow;
  606. }
  607. phd->ci.uiCodePage = GetCodePageForFont(hfont);
  608. ReleaseDC(HWND_DESKTOP, hdc);
  609. }
  610. BOOL Header_OnCreate(HD* phd, CREATESTRUCT* lpCreateStruct)
  611. {
  612. ASSERT(phd); // we are only called if phd is valid
  613. CIInitialize(&phd->ci, phd->ci.hwnd, (LPCREATESTRUCT)lpCreateStruct);
  614. phd->flags = 0;
  615. phd->hfont = NULL;
  616. phd->hFilterImage = NULL;
  617. phd->iNewOrder = -1;
  618. phd->iHot = -1;
  619. phd->iFocus = 0;
  620. phd->iEdit = -1;
  621. phd->iButtonDown = -1;
  622. phd->iFilterChangeTimeout = GetDoubleClickTime()*2;
  623. phd->hwndEdit = NULL;
  624. phd->hdsaHDI = DSA_Create(sizeof(HDI), 4);
  625. if (!phd->hdsaHDI)
  626. return FALSE;
  627. phd->cxDividerSlop = 8 * g_cxBorder;
  628. phd->hTheme = OpenThemeData(phd->ci.hwnd, L"Header");
  629. // Warning! ListView_RSetColumnWidth knows these values.
  630. phd->iTextMargin = 3 * g_cxLabelMargin;
  631. phd->iBmMargin = 3 * g_cxLabelMargin;
  632. // phd->himl = NULL;
  633. Header_NewFont(phd, NULL);
  634. return TRUE;
  635. }
  636. int Header_DestroyItemCallback(LPVOID p, LPVOID d)
  637. {
  638. HDI * phdi = (HDI*)p;
  639. if (phdi)
  640. {
  641. Str_Set(&phdi->pszText, NULL);
  642. if ( (phdi->type & HDFT_ISMASK)==HDFT_ISSTRING )
  643. Str_Set(&phdi->textFilter.pszText, NULL);
  644. }
  645. return 1;
  646. }
  647. void Header_OnNCDestroy(HD* phd)
  648. {
  649. // stop editing the filter
  650. if ( phd->hFilterImage )
  651. ImageList_Destroy(phd->hFilterImage);
  652. Header_StopFilterEdit(phd, TRUE);
  653. // We must walk through and destroy all of the string pointers that
  654. // are contained in the structures before we pass it off to the
  655. // DSA_Destroy function...
  656. DSA_DestroyCallback(phd->hdsaHDI, Header_DestroyItemCallback, 0);
  657. phd->hdsaHDI = NULL;
  658. if (phd->hdsaOrder)
  659. {
  660. DSA_Destroy(phd->hdsaOrder);
  661. phd->hdsaOrder = NULL;
  662. }
  663. if (phd->hTheme)
  664. CloseThemeData(phd->hTheme);
  665. if (phd->hfontSortArrow)
  666. DeleteObject(phd->hfontSortArrow);
  667. }
  668. HIMAGELIST Header_OnSetImageList(HD* phd, HIMAGELIST himl)
  669. {
  670. HIMAGELIST hImageOld = phd->himl;
  671. phd->himl = himl;
  672. return hImageOld;
  673. }
  674. void Header_OnPaint(HD* phd, HDC hdc)
  675. {
  676. PAINTSTRUCT ps;
  677. HDC hdcUse;
  678. CCDBUFFER cdd;
  679. if (!phd)
  680. return;
  681. if (hdc)
  682. {
  683. hdcUse = hdc;
  684. GetClientRect(phd->ci.hwnd, &ps.rcPaint);
  685. }
  686. else
  687. {
  688. hdcUse = BeginPaint(phd->ci.hwnd, &ps);
  689. }
  690. hdcUse = CCBeginDoubleBuffer(hdcUse, &ps.rcPaint, &cdd);
  691. Header_Draw(phd, hdcUse, &ps.rcPaint);
  692. CCEndDoubleBuffer(&cdd);
  693. if (!hdc)
  694. {
  695. EndPaint(phd->ci.hwnd, &ps);
  696. }
  697. }
  698. UINT Header_OnGetDlgCode(HD* phd, MSG* lpmsg)
  699. {
  700. return DLGC_WANTTAB | DLGC_WANTARROWS;
  701. }
  702. int Header_HitTest(HD* phd, int x, int y, UINT* pflags)
  703. {
  704. UINT flags = 0;
  705. POINT pt;
  706. RECT rc;
  707. HDI* phdi;
  708. int i;
  709. pt.x = x; pt.y = y;
  710. GetClientRect(phd->ci.hwnd, &rc);
  711. flags = 0;
  712. i = -1;
  713. if (x < rc.left)
  714. flags |= HHT_TOLEFT;
  715. else if (x >= rc.right)
  716. flags |= HHT_TORIGHT;
  717. if (y < rc.top)
  718. flags |= HHT_ABOVE;
  719. else if (y >= rc.bottom)
  720. flags |= HHT_BELOW;
  721. if (flags == 0)
  722. {
  723. int cItems = DSA_GetItemCount(phd->hdsaHDI);
  724. int xPrev = 0;
  725. BOOL fPrevZero = FALSE;
  726. int xItem;
  727. int cxSlop;
  728. //DebugMsg(DM_TRACE, "Hit Test begin");
  729. for (i = 0; i <= cItems; i++, phdi++, xPrev = xItem)
  730. {
  731. if (i == cItems)
  732. xItem = rc.right;
  733. else {
  734. phdi = Header_GetItemPtrByOrder(phd, i);
  735. xItem = phdi->x;
  736. }
  737. // DebugMsg(DM_TRACE, "x = %d xItem = %d xPrev = %d fPrevZero = %d", x, xItem, xPrev, xPrev == xItem);
  738. if (xItem == xPrev)
  739. {
  740. // Skip zero width items...
  741. //
  742. fPrevZero = TRUE;
  743. continue;
  744. }
  745. cxSlop = min((xItem - xPrev) / 4, phd->cxDividerSlop);
  746. if (x >= xPrev && x < xItem)
  747. {
  748. if ( Header_IsFilter(phd) )
  749. {
  750. RECT rcItem;
  751. RECT rcHeader, rcFilter, rcButton;
  752. rcItem.left = xPrev;
  753. rcItem.top = rc.top;
  754. rcItem.right = xItem;
  755. rcItem.bottom = rc.bottom ;
  756. Header_GetFilterRects(&rcItem, &rcHeader, &rcFilter, &rcButton);
  757. if ( y >= rcFilter.top )
  758. {
  759. if ( x >= rcFilter.right )
  760. {
  761. // hit check the entire button, forget about the divider
  762. // when over the filter glyph
  763. flags = HHT_ONFILTERBUTTON;
  764. break;
  765. }
  766. else
  767. {
  768. flags = HHT_ONFILTER;
  769. }
  770. }
  771. else if ( y < rcHeader.bottom )
  772. flags = HHT_ONHEADER;
  773. }
  774. else
  775. {
  776. flags = HHT_ONHEADER;
  777. }
  778. if (i > 0 && x < xPrev + cxSlop)
  779. {
  780. i--;
  781. flags = HHT_ONDIVIDER;
  782. if (fPrevZero && x > xPrev)
  783. {
  784. flags = HHT_ONDIVOPEN;
  785. }
  786. }
  787. else if (x >= xItem - cxSlop)
  788. {
  789. flags = HHT_ONDIVIDER;
  790. }
  791. break;
  792. }
  793. fPrevZero = FALSE;
  794. }
  795. if (i == cItems)
  796. {
  797. i = -1;
  798. flags = HHT_NOWHERE;
  799. } else {
  800. // now convert order index to real index
  801. i = Header_ItemOrderToIndex(phd, i);
  802. }
  803. }
  804. *pflags = flags;
  805. return i;
  806. }
  807. int Header_OnHitTest(HD* phd, HD_HITTESTINFO *phdht)
  808. {
  809. if (phdht && phd) {
  810. phdht->iItem = Header_HitTest(phd, phdht->pt.x, phdht->pt.y, &phdht->flags);
  811. return phdht->iItem;
  812. } else
  813. return -1;
  814. }
  815. BOOL Header_OnSetCursor(HD* phd, HWND hwndCursor, UINT codeHitTest, UINT msg)
  816. {
  817. POINT pt;
  818. UINT flags;
  819. LPCTSTR lpCur = MAKEINTRESOURCE(IDC_SIZEWE);
  820. HINSTANCE hinst = NULL;
  821. int iItem;
  822. int iDPI = CCGetScreenDPI();
  823. if (!phd)
  824. return FALSE;
  825. if (phd->ci.hwnd != hwndCursor || codeHitTest >= 0x8000)
  826. return FALSE;
  827. GetMessagePosClient(hwndCursor, &pt);
  828. iItem = Header_HitTest(phd, pt.x, pt.y, &flags);
  829. switch (flags)
  830. {
  831. case HHT_ONDIVIDER:
  832. if (iDPI <= 96)
  833. {
  834. lpCur = MAKEINTRESOURCE(IDC_DIVIDER);
  835. hinst = HINST_THISDLL;
  836. }
  837. break;
  838. case HHT_ONDIVOPEN:
  839. if (iDPI <= 96)
  840. {
  841. lpCur = MAKEINTRESOURCE(IDC_DIVOPEN);
  842. hinst = HINST_THISDLL;
  843. }
  844. break;
  845. case HHT_ONFILTER:
  846. {
  847. HDI* phdi = Header_GetItemPtrByOrder(phd, iItem);
  848. ASSERT(phdi);
  849. lpCur = IDC_ARROW; // default to the arrow
  850. switch ( phdi->type & HDFT_ISMASK )
  851. {
  852. case HDFT_ISSTRING:
  853. case HDFT_ISNUMBER:
  854. lpCur = IDC_IBEAM;
  855. break;
  856. default:
  857. // FEATURE: handle custom filters
  858. break;
  859. }
  860. break;
  861. }
  862. default:
  863. lpCur = IDC_ARROW;
  864. break;
  865. }
  866. SetCursor(LoadCursor(hinst, lpCur));
  867. return TRUE;
  868. }
  869. void Header_DrawDivider(HD* phd, int x)
  870. {
  871. RECT rc;
  872. HDC hdc = GetDC(phd->ci.hwnd);
  873. GetClientRect(phd->ci.hwnd, &rc);
  874. rc.left = x;
  875. rc.right = x + g_cxBorder;
  876. InvertRect(hdc, &rc);
  877. ReleaseDC(phd->ci.hwnd, hdc);
  878. }
  879. int Header_PinDividerPos(HD* phd, int x)
  880. {
  881. x += phd->dxTrack;
  882. if (x < phd->xMinTrack)
  883. x = phd->xMinTrack;
  884. return x;
  885. }
  886. void Header_OnLButtonDown(HD* phd, BOOL fDoubleClick, int x, int y, UINT keyFlags)
  887. {
  888. HD_ITEM hd;
  889. int i;
  890. UINT flags;
  891. if (!phd)
  892. return;
  893. Header_StopFilterEdit(phd, FALSE);
  894. i = Header_HitTest(phd, x, y, &flags);
  895. if (flags & (HHT_ONDIVIDER))
  896. {
  897. if (fDoubleClick) {
  898. Header_SendChange(phd, i, HDN_DIVIDERDBLCLICK, NULL);
  899. }
  900. }
  901. if ((flags & (HHT_ONDIVIDER | HHT_ONHEADER | HHT_ONDIVOPEN))
  902. && !fDoubleClick)
  903. {
  904. phd->iTrack = i;
  905. phd->flagsTrack = flags;
  906. phd->xTrack = x;
  907. SetCapture(phd->ci.hwnd);
  908. // this is just to get messages so we can
  909. // check for the escape key being hit
  910. SetTimer(phd->ci.hwnd, 1, 100, NULL);
  911. GetAsyncKeyState(VK_ESCAPE);
  912. }
  913. if (flags & (HHT_ONDIVIDER | HHT_ONDIVOPEN) &&
  914. !fDoubleClick)
  915. {
  916. //
  917. // We should first send out the HDN_BEGINTRACK notification
  918. //
  919. HDI * phdi;
  920. int iOrder = Header_OnGetItemOrder(phd, i);
  921. phdi = Header_GetItemPtr(phd, i);
  922. phd->xMinTrack = phdi->x - phdi->cxy;
  923. phd->xTrack = phdi->x;
  924. phd->dxTrack = phd->xTrack - x;
  925. phd->xTrackOldWidth = phdi->cxy;
  926. hd.mask = HDI_WIDTH;
  927. hd.cxy = phd->xTrackOldWidth;
  928. if (!Header_SendChange(phd, i, HDN_BEGINTRACK, &hd))
  929. {
  930. // They said no!
  931. phd->flagsTrack = 0;
  932. CCReleaseCapture(&phd->ci);
  933. KillTimer(phd->ci.hwnd, 1);
  934. return;
  935. }
  936. if (!HDDragFullWindows(phd)) {
  937. x = Header_PinDividerPos(phd, x);
  938. Header_DrawDivider(phd, x);
  939. }
  940. }
  941. else if ((flags & HHT_ONHEADER) && (phd->ci.style & HDS_BUTTONS))
  942. {
  943. if (fDoubleClick) {
  944. Header_SendChange(phd, i, HDN_ITEMDBLCLICK, NULL);
  945. } else {
  946. phd->bTrackPress = TRUE;
  947. Header_InvalidateItem(phd, phd->iTrack, RDW_INVALIDATE| RDW_ERASE);
  948. }
  949. }
  950. if ( flags & HHT_ONFILTER )
  951. {
  952. Header_BeginFilterEdit(phd, i);
  953. }
  954. if ( flags & HHT_ONFILTERBUTTON )
  955. {
  956. Header_OnFilterButton(phd, i);
  957. }
  958. }
  959. void Header_StartDrag(HD* phd, int i, int x, int y)
  960. {
  961. RECT rc;
  962. if ((phd->ci.style & HDS_DRAGDROP) &&
  963. Header_Notify(phd, i, MK_LBUTTON, HDN_BEGINDRAG)) {
  964. // clear the hot bit and
  965. // update before we do the BeginDrag so that the save bitmap won't
  966. // have the hot drawing on it.
  967. Header_SetHotItem(phd, -1);
  968. UpdateWindow(phd->ci.hwnd);
  969. phd->himlDrag = Header_OnCreateDragImage(phd, Header_OnGetItemOrder(phd,i));
  970. if (!phd->himlDrag)
  971. return;
  972. // find the delta between the start of the item and the cursor
  973. Header_OnGetItemRect(phd, i, &rc);
  974. phd->dxTrack = rc.left - x;
  975. ImageList_BeginDrag(phd->himlDrag, 0, 0, 0);
  976. ImageList_DragEnter(phd->ci.hwnd, x, 0);
  977. }
  978. }
  979. void Header_InvalidateDivider(HD* phd, int iItem)
  980. {
  981. RECT rc;
  982. Header_GetDividerRect(phd, iItem, &rc);
  983. InvalidateRect(phd->ci.hwnd, &rc, FALSE);
  984. }
  985. void _Header_SetHotDivider(HD* phd, int iNewOrder)
  986. {
  987. if (iNewOrder != phd->iNewOrder) {
  988. if (phd->himlDrag)
  989. ImageList_DragShowNolock(FALSE);
  990. Header_InvalidateDivider(phd, phd->iNewOrder);
  991. Header_InvalidateDivider(phd, iNewOrder);
  992. phd->iNewOrder = iNewOrder;
  993. UpdateWindow(phd->ci.hwnd);
  994. if (phd->himlDrag)
  995. ImageList_DragShowNolock(TRUE);
  996. }
  997. }
  998. LPARAM Header_OnSetHotDivider(HD* phd, BOOL fPos, LPARAM lParam)
  999. {
  1000. int iNewOrder = -1;
  1001. if (fPos) {
  1002. RECT rc;
  1003. int y = GET_Y_LPARAM(lParam);
  1004. int x = GET_X_LPARAM(lParam);
  1005. // this means that lParam is the cursor position (in client coordinates)
  1006. GetClientRect(phd->ci.hwnd, &rc);
  1007. InflateRect(&rc, 0, g_cyHScroll * 2);
  1008. // show only if the y point is reasonably close to the header
  1009. // (a la scrollbar)
  1010. if (y >= rc.top &&
  1011. y <= rc.bottom) {
  1012. //
  1013. // find out the new insertion point
  1014. //
  1015. if (x <= 0) {
  1016. iNewOrder = 0;
  1017. } else {
  1018. UINT flags;
  1019. int iIndex;
  1020. iIndex = Header_HitTest(phd, x, (rc.top + rc.bottom)/2, &flags);
  1021. // if we didn't find an item, see if it's on the far right
  1022. if (iIndex == -1) {
  1023. int iLast = Header_ItemOrderToIndex(phd, Header_GetCount(phd) -1);
  1024. if (Header_OnGetItemRect(phd, iLast, &rc)) {
  1025. if (x >= rc.right) {
  1026. iNewOrder = Header_GetCount(phd);
  1027. }
  1028. }
  1029. } else {
  1030. Header_OnGetItemRect(phd, iIndex, &rc);
  1031. iNewOrder= Header_OnGetItemOrder(phd, iIndex);
  1032. // if it was past the midpoint, the insertion point is the next one
  1033. if (x > ((rc.left + rc.right)/2)) {
  1034. // get the next item... translate to item order then back to index.
  1035. iNewOrder++;
  1036. }
  1037. }
  1038. }
  1039. }
  1040. } else {
  1041. iNewOrder = (int)lParam;
  1042. }
  1043. _Header_SetHotDivider(phd, iNewOrder);
  1044. return iNewOrder;
  1045. }
  1046. void Header_MoveDrag(HD* phd, int x, int y)
  1047. {
  1048. LPARAM iNewOrder = -1;
  1049. iNewOrder = Header_OnSetHotDivider(phd, TRUE, MAKELONG(x, y));
  1050. if (iNewOrder == -1) {
  1051. ImageList_DragShowNolock(FALSE);
  1052. } else {
  1053. ImageList_DragShowNolock(TRUE);
  1054. ImageList_DragMove(x + phd->dxTrack, 0);
  1055. }
  1056. }
  1057. void Header_EndDrag(HD* phd)
  1058. {
  1059. ImageList_EndDrag();
  1060. ImageList_Destroy(phd->himlDrag);
  1061. phd->himlDrag = NULL;
  1062. _Header_SetHotDivider(phd, -1);
  1063. }
  1064. // iOrder
  1065. void Header_GetDividerRect(HD* phd, int iOrder, LPRECT prc)
  1066. {
  1067. int iIndex;
  1068. BOOL fLeft;
  1069. if (iOrder == -1)
  1070. {
  1071. SetRectEmpty(prc);
  1072. return;
  1073. }
  1074. // if we're getting the divider slot of < N then
  1075. // it's the left of the rect of item i.
  1076. // otherwise it's the right of the last item.
  1077. if (iOrder < Header_GetCount(phd)) {
  1078. fLeft = TRUE;
  1079. } else {
  1080. fLeft = FALSE;
  1081. iOrder--;
  1082. }
  1083. iIndex = Header_ItemOrderToIndex(phd, iOrder);
  1084. Header_OnGetItemRect(phd, iIndex, prc);
  1085. if (fLeft) {
  1086. prc->right = prc->left;
  1087. } else {
  1088. prc->left = prc->right;
  1089. }
  1090. InflateRect(prc, g_cxBorder, 0);
  1091. }
  1092. void Header_OnMouseMove(HD* phd, int x, int y, UINT keyFlags)
  1093. {
  1094. UINT flags;
  1095. int i;
  1096. HD_ITEM hd;
  1097. if (!phd)
  1098. return;
  1099. // do the hot tracking
  1100. // but not if anything is ownerdraw or if we're in d/d mode
  1101. if ((phd->hTheme || phd->ci.style & HDS_HOTTRACK) && !phd->fOwnerDraw && !phd->himlDrag) {
  1102. // only do this if we're in button mode meaning you can actually click
  1103. if (phd->ci.style & HDS_BUTTONS) {
  1104. i = Header_HitTest(phd, x, y, &flags);
  1105. Header_SetHotItem(phd, i);
  1106. }
  1107. }
  1108. if (Header_IsTracking(phd))
  1109. {
  1110. if (phd->flagsTrack & (HHT_ONDIVIDER | HHT_ONDIVOPEN))
  1111. {
  1112. x = Header_PinDividerPos(phd, x);
  1113. //
  1114. // Let the Owner have a chance to update this.
  1115. //
  1116. hd.mask = HDI_WIDTH;
  1117. hd.cxy = x - phd->xMinTrack;
  1118. if (!HDDragFullWindows(phd) && !Header_SendChange(phd, phd->iTrack, HDN_TRACK, &hd))
  1119. {
  1120. // We need to cancel tracking
  1121. phd->flagsTrack = 0;
  1122. CCReleaseCapture(&phd->ci);
  1123. KillTimer(phd->ci.hwnd, 1);
  1124. // Undraw the last divider we displayed
  1125. Header_DrawDivider(phd, phd->xTrack);
  1126. return;
  1127. }
  1128. // We should update our x depending on what caller did
  1129. x = hd.cxy + phd->xMinTrack;
  1130. // if full window track is turned on, go ahead and set the width
  1131. if (HDDragFullWindows(phd)) {
  1132. HD_ITEM item;
  1133. item.mask = HDI_WIDTH;
  1134. item.cxy = hd.cxy;
  1135. DebugMsg(DM_TRACE, TEXT("Tracking header. item %d gets width %d... %d %d"), phd->iTrack, item.cxy, phd->xMinTrack, x);
  1136. // Let the owner have a chance to say yes.
  1137. Header_OnSetItem(phd, phd->iTrack, &item);
  1138. UpdateWindow(phd->ci.hwnd);
  1139. } else {
  1140. // do the cheezy old stuff
  1141. Header_DrawDivider(phd, phd->xTrack);
  1142. Header_DrawDivider(phd, x);
  1143. }
  1144. phd->xTrack = x;
  1145. }
  1146. else if (phd->flagsTrack & HHT_ONHEADER)
  1147. {
  1148. i = Header_HitTest(phd, x, y, &flags);
  1149. if (ABS(x - phd->xTrack) >
  1150. GetSystemMetrics(SM_CXDRAG)) {
  1151. if (!phd->himlDrag) {
  1152. Header_StartDrag(phd, i, phd->xTrack, y);
  1153. }
  1154. }
  1155. if (phd->himlDrag) {
  1156. Header_MoveDrag(phd, x, y);
  1157. } else {
  1158. // if pressing on button and it's not pressed, press it
  1159. if (flags & HHT_ONHEADER && i == phd->iTrack)
  1160. {
  1161. if ((!phd->bTrackPress) && (phd->ci.style & HDS_BUTTONS))
  1162. {
  1163. phd->bTrackPress = TRUE;
  1164. Header_InvalidateItem(phd, phd->iTrack, RDW_INVALIDATE| RDW_ERASE);
  1165. }
  1166. }
  1167. // tracked off of button. if pressed, pop it
  1168. else if ((phd->bTrackPress) && (phd->ci.style & HDS_BUTTONS))
  1169. {
  1170. phd->bTrackPress = FALSE;
  1171. Header_InvalidateItem(phd, phd->iTrack, RDW_INVALIDATE| RDW_ERASE);
  1172. }
  1173. }
  1174. }
  1175. }
  1176. }
  1177. void Header_OnLButtonUp(HD* phd, int x, int y, UINT keyFlags)
  1178. {
  1179. if (!phd)
  1180. return;
  1181. if (Header_IsTracking(phd))
  1182. {
  1183. if (phd->flagsTrack & (HHT_ONDIVIDER | HHT_ONDIVOPEN))
  1184. {
  1185. HD_ITEM item;
  1186. if (!HDDragFullWindows(phd)) {
  1187. Header_DrawDivider(phd, phd->xTrack);
  1188. }
  1189. item.mask = HDI_WIDTH;
  1190. item.cxy = phd->xTrack - phd->xMinTrack;
  1191. // Let the owner have a chance to say yes.
  1192. if (Header_SendChange(phd, phd->iTrack, HDN_ENDTRACK, &item))
  1193. Header_OnSetItem(phd, phd->iTrack, &item);
  1194. RedrawWindow(phd->ci.hwnd, NULL, NULL, RDW_INVALIDATE | RDW_ERASE);
  1195. }
  1196. else if ((phd->flagsTrack & HHT_ONHEADER)
  1197. && (phd->bTrackPress || phd->himlDrag))
  1198. {
  1199. if (phd->himlDrag) {
  1200. // if this is the end of a drag,
  1201. // notify the user.
  1202. HDITEM item;
  1203. item.mask = HDI_ORDER;
  1204. item.iOrder = phd->iNewOrder;
  1205. if (item.iOrder > Header_OnGetItemOrder(phd, phd->iTrack)) {
  1206. // if the new order is greater than the old one,
  1207. // we subtract one because it's leaving the old place
  1208. // which decs the count by one.
  1209. item.iOrder--;
  1210. }
  1211. Header_EndDrag(phd);
  1212. if (Header_SendChange(phd, phd->iTrack, HDN_ENDDRAG, &item)) {
  1213. if (item.iOrder != -1) {
  1214. // all's well... change the item order
  1215. Header_OnSetItemOrder(phd, phd->iTrack, item.iOrder);
  1216. NotifyWinEvent(EVENT_OBJECT_REORDER, phd->ci.hwnd, OBJID_CLIENT, 0);
  1217. }
  1218. }
  1219. } else {
  1220. // Notify the owner that the item has been clicked
  1221. Header_Notify(phd, phd->iTrack, 0, HDN_ITEMCLICK);
  1222. }
  1223. phd->bTrackPress = FALSE;
  1224. Header_InvalidateItem(phd, phd->iTrack, RDW_INVALIDATE| RDW_ERASE);
  1225. }
  1226. phd->flagsTrack = 0;
  1227. CCReleaseCapture(&phd->ci);
  1228. KillTimer(phd->ci.hwnd, 1);
  1229. }
  1230. }
  1231. BOOL Header_IsTracking(HD* phd)
  1232. {
  1233. if (!phd->flagsTrack)
  1234. {
  1235. return FALSE;
  1236. } else if (GetCapture() != phd->ci.hwnd) {
  1237. phd->flagsTrack = 0;
  1238. return FALSE;
  1239. }
  1240. return TRUE;
  1241. }
  1242. void Header_OnSetFont(HD* phd, HFONT hfont, BOOL fRedraw)
  1243. {
  1244. if (!phd)
  1245. return;
  1246. if (hfont != phd->hfont)
  1247. {
  1248. Header_NewFont(phd, hfont);
  1249. if (fRedraw)
  1250. RedrawWindow(phd->ci.hwnd, NULL, NULL, RDW_INVALIDATE | RDW_ERASE);
  1251. }
  1252. }
  1253. HFONT Header_OnGetFont(HD* phd)
  1254. {
  1255. if (!phd)
  1256. return NULL;
  1257. return phd->hfont;
  1258. }
  1259. //**********************************************************************
  1260. int Header_OnInsertItemA(HD* phd, int i, HD_ITEMA* pitem) {
  1261. LPWSTR pszW = NULL;
  1262. LPSTR pszC = NULL;
  1263. HD_TEXTFILTERW textFilterW;
  1264. LPHD_TEXTFILTERA ptextFilterA = NULL;
  1265. int iRet;
  1266. //HACK ALERT -- this code assumes that HD_ITEMA is exactly the same
  1267. // as HD_ITEMW except for the pointer to the string.
  1268. ASSERT(sizeof(HD_ITEMA) == sizeof(HD_ITEMW))
  1269. if (!pitem || !phd)
  1270. return -1;
  1271. if ((pitem->mask & HDI_TEXT) && (pitem->pszText != LPSTR_TEXTCALLBACKA) &&
  1272. (pitem->pszText != NULL)) {
  1273. pszC = pitem->pszText;
  1274. if ((pszW = ProduceWFromA(phd->ci.uiCodePage, pszC)) == NULL)
  1275. return -1;
  1276. pitem->pszText = (LPSTR)pszW;
  1277. }
  1278. if ( (pitem->mask & HDI_FILTER) &&
  1279. ((pitem->type & HDFT_ISMASK) == HDFT_ISSTRING) ) {
  1280. // pick up the filter if there is one for us to thunk
  1281. if ( pitem->pvFilter ) {
  1282. ptextFilterA = pitem->pvFilter;
  1283. ASSERT(ptextFilterA);
  1284. textFilterW.pszText = NULL;
  1285. textFilterW.cchTextMax = ptextFilterA->cchTextMax;
  1286. if ( !(pitem->type & HDFT_HASNOVALUE) ) {
  1287. textFilterW.pszText = ProduceWFromA(phd->ci.uiCodePage, ptextFilterA->pszText);
  1288. if ( !textFilterW.pszText ) {
  1289. if ( pszW )
  1290. FreeProducedString(pszW)
  1291. return -1;
  1292. }
  1293. }
  1294. pitem->pvFilter = &textFilterW;
  1295. }
  1296. }
  1297. iRet = Header_OnInsertItem(phd, i, (const HD_ITEM*) pitem);
  1298. if (pszW != NULL) {
  1299. pitem->pszText = pszC;
  1300. FreeProducedString(pszW);
  1301. }
  1302. if (ptextFilterA)
  1303. {
  1304. pitem->pvFilter = ptextFilterA;
  1305. FreeProducedString(textFilterW.pszText);
  1306. }
  1307. return iRet;
  1308. }
  1309. int Header_OnInsertItem(HD* phd, int i, const HD_ITEM* pitem)
  1310. {
  1311. HDI hdi = {0};
  1312. int x;
  1313. HDI* phdi;
  1314. int iOrder;
  1315. int cxy;
  1316. if (!pitem || !phd || i < 0)
  1317. return -1;
  1318. if (pitem->mask == 0)
  1319. return -1;
  1320. if (!DSA_ForceGrow(phd->hdsaHDI, 1))
  1321. {
  1322. return -1;
  1323. }
  1324. if (phd->hdsaOrder && !DSA_ForceGrow(phd->hdsaOrder, 1))
  1325. {
  1326. return -1;
  1327. }
  1328. cxy = pitem->cxy;
  1329. if (cxy < 0)
  1330. cxy = 0;
  1331. x = cxy;
  1332. if (i > DSA_GetItemCount(phd->hdsaHDI))
  1333. i = DSA_GetItemCount(phd->hdsaHDI);
  1334. // stop editing the filter
  1335. Header_StopFilterEdit(phd, FALSE);
  1336. iOrder = i;
  1337. // can't have order info if it's owner data
  1338. if (!(phd->ci.style & HDS_OWNERDATA))
  1339. {
  1340. // the iOrder field wasn't there in win95...
  1341. // so access it only if the bit is there.
  1342. if (pitem->mask & HDI_ORDER)
  1343. {
  1344. if ((pitem->iOrder != i) && (pitem->iOrder <= Header_GetCount(phd)))
  1345. {
  1346. if (Header_InitOrderArray(phd))
  1347. iOrder = pitem->iOrder;
  1348. }
  1349. }
  1350. }
  1351. if (iOrder > 0)
  1352. {
  1353. phdi = Header_GetItemPtrByOrder(phd, iOrder - 1);
  1354. if (phdi)
  1355. x += phdi->x;
  1356. }
  1357. // move everything else over
  1358. Header_ShiftItems(phd, iOrder, cxy);
  1359. if (phd->hdsaOrder)
  1360. {
  1361. int j;
  1362. int iIndex = -1;
  1363. // an index is added, all the current indices
  1364. // need to be incr by one
  1365. for (j = 0; j < DSA_GetItemCount(phd->hdsaOrder); j++)
  1366. {
  1367. DSA_GetItem(phd->hdsaOrder, j, &iIndex);
  1368. if (iIndex >= i)
  1369. {
  1370. iIndex++;
  1371. DSA_SetItem(phd->hdsaOrder, j, &iIndex);
  1372. }
  1373. }
  1374. DSA_InsertItem(phd->hdsaOrder, iOrder, &i);
  1375. }
  1376. hdi.x = x;
  1377. hdi.lParam = pitem->lParam;
  1378. hdi.fmt = pitem->fmt;
  1379. //hdi.pszText = NULL;
  1380. //hdi.iImage = 0;
  1381. hdi.cxy = cxy;
  1382. hdi.xText = hdi.xBm = RECOMPUTE;
  1383. hdi.type = HDFT_ISSTRING|HDFT_HASNOVALUE;
  1384. //hdi.textFilter.pszText = NULL;
  1385. hdi.textFilter.cchTextMax = MAX_PATH;
  1386. if ((pitem->mask & HDI_TEXT) && (pitem->pszText != NULL))
  1387. {
  1388. if (!Str_Set(&hdi.pszText, pitem->pszText))
  1389. return -1;
  1390. // Unless ownerdraw make sure the text bit is on!
  1391. if ((pitem->mask & HDF_OWNERDRAW) == 0)
  1392. hdi.fmt |= HDF_STRING;
  1393. }
  1394. else
  1395. {
  1396. hdi.fmt &= ~(HDF_STRING);
  1397. }
  1398. if ((pitem->mask & HDI_BITMAP) && (pitem->hbm != NULL))
  1399. {
  1400. hdi.hbm = pitem->hbm;
  1401. // Unless ownerdraw make sure the text bit is on!
  1402. if ((pitem->mask & HDF_OWNERDRAW) == 0)
  1403. hdi.fmt |= HDF_BITMAP;
  1404. }
  1405. else
  1406. {
  1407. hdi.hbm = NULL;
  1408. hdi.fmt &= ~(HDF_BITMAP);
  1409. }
  1410. if (pitem->mask & HDI_IMAGE)
  1411. {
  1412. hdi.iImage = pitem->iImage;
  1413. // Unless ownerdraw make sure the image bit is on!
  1414. if ((pitem->mask & HDF_OWNERDRAW) == 0)
  1415. hdi.fmt |= HDF_IMAGE;
  1416. }
  1417. if ( pitem->mask & HDI_FILTER )
  1418. {
  1419. // pick up the new filter, handling the case where the filter value is
  1420. // being discarded, and/or there is none
  1421. hdi.type = pitem->type;
  1422. switch ( hdi.type & HDFT_ISMASK )
  1423. {
  1424. case HDFT_ISSTRING:
  1425. {
  1426. if ( pitem->pvFilter )
  1427. {
  1428. LPHDTEXTFILTER ptextFilter = (LPHDTEXTFILTER)pitem->pvFilter;
  1429. ASSERT(ptextFilter);
  1430. if ( !(pitem->type & HDFT_HASNOVALUE) )
  1431. Str_Set(&hdi.textFilter.pszText, ptextFilter->pszText);
  1432. hdi.textFilter.cchTextMax = ptextFilter->cchTextMax;
  1433. }
  1434. break;
  1435. }
  1436. case HDFT_ISNUMBER:
  1437. {
  1438. if ( !(pitem->type & HDFT_HASNOVALUE) && pitem->pvFilter )
  1439. hdi.intFilter = *((int*)pitem->pvFilter);
  1440. break;
  1441. }
  1442. }
  1443. }
  1444. i = DSA_InsertItem(phd->hdsaHDI, i, &hdi);
  1445. if (i == -1)
  1446. {
  1447. // failed to add
  1448. Str_Set(&hdi.pszText, NULL);
  1449. if ( (hdi.type & HDFT_ISMASK) == HDFT_ISSTRING )
  1450. Str_Set(&hdi.textFilter.pszText, NULL);
  1451. }
  1452. else
  1453. {
  1454. RECT rc;
  1455. // succeeded! redraw
  1456. GetClientRect(phd->ci.hwnd, &rc);
  1457. rc.left = x - cxy;
  1458. RedrawWindow(phd->ci.hwnd, &rc, NULL, RDW_INVALIDATE | RDW_ERASE);
  1459. NotifyWinEvent(EVENT_OBJECT_CREATE, phd->ci.hwnd, OBJID_CLIENT, i+1);
  1460. }
  1461. return i;
  1462. }
  1463. BOOL Header_OnDeleteItem(HD* phd, int i)
  1464. {
  1465. HDI hdi;
  1466. RECT rc;
  1467. int iWidth;
  1468. int iOrder;
  1469. if (!phd)
  1470. return FALSE;
  1471. if (!DSA_GetItem(phd->hdsaHDI, i, &hdi))
  1472. return FALSE;
  1473. NotifyWinEvent(EVENT_OBJECT_DESTROY, phd->ci.hwnd, OBJID_CLIENT, i+1);
  1474. Header_StopFilterEdit(phd, FALSE);
  1475. phd->iFocus = 0;
  1476. GetClientRect(phd->ci.hwnd, &rc);
  1477. iWidth = rc.right;
  1478. Header_OnGetItemRect(phd, i, &rc);
  1479. InflateRect(&rc, g_cxBorder, g_cyBorder);
  1480. // move everything else over
  1481. iOrder = Header_OnGetItemOrder(phd, i);
  1482. Header_ShiftItems(phd, iOrder, -hdi.cxy);
  1483. if (!DSA_DeleteItem(phd->hdsaHDI, i))
  1484. return FALSE;
  1485. if (phd->hdsaOrder) {
  1486. int j;
  1487. int iIndex;
  1488. DSA_DeleteItem(phd->hdsaOrder, iOrder);
  1489. // an index is going away, all the current indices
  1490. // need to be decremented by one
  1491. for (j = 0; j < DSA_GetItemCount(phd->hdsaOrder); j++) {
  1492. DSA_GetItem(phd->hdsaOrder, j, &iIndex);
  1493. ASSERT(iIndex != i);
  1494. if (iIndex > i) {
  1495. iIndex--;
  1496. DSA_SetItem(phd->hdsaOrder, j, &iIndex);
  1497. }
  1498. }
  1499. }
  1500. Header_DestroyItemCallback(&hdi, NULL);
  1501. rc.right = iWidth;
  1502. InvalidateRect(phd->ci.hwnd, &rc, TRUE);
  1503. return TRUE;
  1504. }
  1505. BOOL Header_OnGetItemA(HD* phd, int i, HD_ITEMA* pitem) {
  1506. LPWSTR pszW = NULL;
  1507. LPSTR pszC = NULL;
  1508. HD_TEXTFILTERW textFilterW;
  1509. LPHD_TEXTFILTERA ptextFilterA = NULL;
  1510. BOOL fRet;
  1511. //HACK ALERT -- this code assumes that HD_ITEMA is exactly the same
  1512. // as HD_ITEMW except for the pointer to the string.
  1513. ASSERT(sizeof(HD_ITEMA) == sizeof(HD_ITEMW))
  1514. if (!pitem || !phd)
  1515. return FALSE;
  1516. if ((pitem->mask & HDI_TEXT) && (pitem->pszText != LPSTR_TEXTCALLBACKA) &&
  1517. (pitem->pszText != NULL)) {
  1518. pszC = pitem->pszText;
  1519. pszW = LocalAlloc(LMEM_FIXED, pitem->cchTextMax * sizeof(WCHAR));
  1520. if (pszW == NULL)
  1521. return FALSE;
  1522. pitem->pszText = (LPSTR)pszW;
  1523. }
  1524. if ( (pitem->mask & HDI_FILTER) &&
  1525. ((pitem->type & HDFT_ISMASK)==HDFT_ISSTRING) ) {
  1526. if ( pitem->pvFilter ) {
  1527. ptextFilterA = pitem->pvFilter;
  1528. ASSERT(ptextFilterA);
  1529. textFilterW.pszText = LocalAlloc(LMEM_FIXED, ptextFilterA->cchTextMax * sizeof(WCHAR));
  1530. textFilterW.cchTextMax = ptextFilterA->cchTextMax;
  1531. if ( !textFilterW.pszText ) {
  1532. if ( pszW )
  1533. LocalFree(pszW);
  1534. return FALSE;
  1535. }
  1536. pitem->pvFilter = &textFilterW;
  1537. }
  1538. }
  1539. fRet = Header_OnGetItem(phd, i, (HD_ITEM *) pitem);
  1540. if (pszW != NULL) {
  1541. ConvertWToAN(phd->ci.uiCodePage, pszC, pitem->cchTextMax, pszW, -1);
  1542. pitem->pszText = pszC;
  1543. LocalFree(pszW);
  1544. }
  1545. if (ptextFilterA)
  1546. {
  1547. ConvertWToAN(phd->ci.uiCodePage, ptextFilterA->pszText, ptextFilterA->cchTextMax,
  1548. textFilterW.pszText, -1);
  1549. pitem->pvFilter = ptextFilterA;
  1550. }
  1551. return fRet;
  1552. }
  1553. BOOL Header_OnGetItem(HD* phd, int i, HD_ITEM* pitem)
  1554. {
  1555. HDI* phdi;
  1556. UINT mask;
  1557. NMHDDISPINFO nm;
  1558. ASSERT(pitem);
  1559. if (!pitem || !phd)
  1560. return FALSE;
  1561. // Crappy hack to fix norton commander. MFC has a bug where it
  1562. // passes in stack trash (in addition to the desired bits) to HDM_GETITEM.
  1563. // Fix it here by stripping down to Win95 bits if more bits than the
  1564. // current valid bits are defined.
  1565. if (pitem->mask & ~HDI_ALL)
  1566. pitem->mask &= HDI_ALL95;
  1567. nm.mask = 0;
  1568. mask = pitem->mask;
  1569. #ifdef DEBUG
  1570. if (i < 0 || i >= Header_GetCount(phd))
  1571. {
  1572. RIPMSG(0, "HDM_GETITEM: Invalid item number %d", i);
  1573. return FALSE; // Return immediately so Header_GetItemPtr doesn't assert
  1574. }
  1575. #endif
  1576. phdi = Header_GetItemPtr(phd, i);
  1577. if (!phdi)
  1578. return FALSE;
  1579. if (mask & HDI_WIDTH)
  1580. {
  1581. pitem->cxy = phdi->cxy;
  1582. }
  1583. if (mask & HDI_FORMAT)
  1584. {
  1585. pitem->fmt = phdi->fmt;
  1586. }
  1587. if (mask & HDI_ORDER)
  1588. {
  1589. pitem->iOrder = Header_OnGetItemOrder(phd, i);
  1590. }
  1591. if (mask & HDI_LPARAM)
  1592. {
  1593. pitem->lParam = phdi->lParam;
  1594. }
  1595. if (mask & HDI_TEXT)
  1596. {
  1597. if (phdi->pszText != LPSTR_TEXTCALLBACK) {
  1598. // if pszText was NULL and you tried to retrieve it, we would bail
  1599. // and return FALSE, now we may return TRUE.
  1600. Str_GetPtr0(phdi->pszText, pitem->pszText, pitem->cchTextMax);
  1601. }
  1602. else {
  1603. // need to recalc the xText because they could keep changing it on us
  1604. phdi->xText = RECOMPUTE;
  1605. nm.mask |= HDI_TEXT;
  1606. }
  1607. }
  1608. if (mask & HDI_BITMAP)
  1609. pitem->hbm = phdi->hbm;
  1610. if (mask & HDI_IMAGE)
  1611. {
  1612. if (phdi->iImage == I_IMAGECALLBACK)
  1613. nm.mask |= HDI_IMAGE;
  1614. else
  1615. pitem->iImage = phdi->iImage;
  1616. }
  1617. if (mask & HDI_FILTER)
  1618. {
  1619. if (pitem->pvFilter)
  1620. {
  1621. if ((phdi->type & HDFT_ISMASK) != (pitem->type & HDFT_ISMASK))
  1622. return FALSE;
  1623. switch (phdi->type & HDFT_ISMASK)
  1624. {
  1625. case HDFT_ISSTRING:
  1626. {
  1627. LPHDTEXTFILTER ptextFilter = (LPHDTEXTFILTER)pitem->pvFilter;
  1628. ASSERT(ptextFilter);
  1629. if ( !Str_GetPtr(phdi->textFilter.pszText, ptextFilter->pszText, ptextFilter->cchTextMax) )
  1630. return FALSE;
  1631. ptextFilter->cchTextMax = phdi->textFilter.cchTextMax;
  1632. break;
  1633. }
  1634. case HDFT_ISNUMBER:
  1635. {
  1636. *((int*)pitem->pvFilter) = phdi->intFilter;
  1637. break;
  1638. }
  1639. default:
  1640. return FALSE;
  1641. }
  1642. }
  1643. pitem->type = phdi->type;
  1644. }
  1645. if (nm.mask) {
  1646. // just in case HDI_IMAGE is set and callback doesn't fill it in
  1647. // ... we'd rather have a -1 than watever garbage is on the stack
  1648. nm.iImage = -1;
  1649. nm.lParam = phdi->lParam;
  1650. if (nm.mask & HDI_TEXT) {
  1651. ASSERT(pitem->pszText);
  1652. nm.pszText = pitem->pszText;
  1653. nm.cchTextMax = pitem->cchTextMax;
  1654. // Make sure the buffer is zero terminated...
  1655. if (nm.cchTextMax)
  1656. *nm.pszText = 0;
  1657. }
  1658. CCSendNotify(&phd->ci, HDN_GETDISPINFO, &nm.hdr);
  1659. if (nm.mask & HDI_IMAGE)
  1660. pitem->iImage = nm.iImage;
  1661. if (nm.mask & HDI_TEXT)
  1662. pitem->pszText = CCReturnDispInfoText(nm.pszText, pitem->pszText, pitem->cchTextMax);
  1663. }
  1664. if (phdi && (nm.mask & HDI_DI_SETITEM)) {
  1665. if (nm.mask & HDI_IMAGE)
  1666. phdi->iImage = nm.iImage;
  1667. if (nm.mask & HDI_TEXT)
  1668. if (nm.pszText) {
  1669. ASSERT(phdi->pszText == LPSTR_TEXTCALLBACK);
  1670. Str_Set(&phdi->pszText, nm.pszText);
  1671. }
  1672. }
  1673. pitem->mask = mask;
  1674. return TRUE;
  1675. }
  1676. BOOL Header_OnSetItemA(HD* phd, int i, HD_ITEMA* pitem) {
  1677. LPWSTR pszW = NULL;
  1678. LPSTR pszC = NULL;
  1679. HD_TEXTFILTERW textFilterW;
  1680. LPHD_TEXTFILTERA ptextFilterA = NULL;
  1681. BOOL fRet;
  1682. //HACK ALERT -- this code assumes that HD_ITEMA is exactly the same
  1683. // as HD_ITEMW except for the pointer to the string.
  1684. ASSERT(sizeof(HD_ITEMA) == sizeof(HD_ITEMW));
  1685. if (!pitem || !phd)
  1686. return FALSE;
  1687. if ((pitem->mask & HDI_TEXT) && (pitem->pszText != LPSTR_TEXTCALLBACKA) &&
  1688. (pitem->pszText != NULL)) {
  1689. pszC = pitem->pszText;
  1690. if ((pszW = ProduceWFromA(phd->ci.uiCodePage, pszC)) == NULL)
  1691. return FALSE;
  1692. pitem->pszText = (LPSTR)pszW;
  1693. }
  1694. if ( (pitem->mask & HDI_FILTER) &&
  1695. ((pitem->type & HDFT_ISMASK) == HDFT_ISSTRING) )
  1696. {
  1697. if ( pitem->pvFilter )
  1698. {
  1699. ptextFilterA = pitem->pvFilter;
  1700. ASSERT(ptextFilterA);
  1701. textFilterW.pszText = NULL;
  1702. textFilterW.cchTextMax = ptextFilterA->cchTextMax;
  1703. if ( !(pitem->type & HDFT_HASNOVALUE) )
  1704. {
  1705. textFilterW.pszText = ProduceWFromA(phd->ci.uiCodePage, ptextFilterA->pszText);
  1706. if ( !textFilterW.pszText ) {
  1707. if ( pszW )
  1708. FreeProducedString(pszW)
  1709. return FALSE;
  1710. }
  1711. }
  1712. pitem->pvFilter = &textFilterW;
  1713. }
  1714. }
  1715. fRet = Header_OnSetItem(phd, i, (const HD_ITEM*) pitem);
  1716. if (pszW != NULL) {
  1717. pitem->pszText = pszC;
  1718. FreeProducedString(pszW);
  1719. }
  1720. if (ptextFilterA)
  1721. {
  1722. pitem->pvFilter = ptextFilterA;
  1723. FreeProducedString(textFilterW.pszText);
  1724. }
  1725. return fRet;
  1726. }
  1727. BOOL Header_OnSetItem(HD* phd, int i, const HD_ITEM* pitem)
  1728. {
  1729. HDI* phdi;
  1730. UINT mask;
  1731. int xOld;
  1732. BOOL fInvalidate = FALSE;
  1733. ASSERT(pitem);
  1734. if (!pitem || !phd)
  1735. return FALSE;
  1736. #ifdef DEBUG
  1737. if (i < 0 || i >= Header_GetCount(phd))
  1738. {
  1739. RIPMSG(0, "HDM_SETITEM: Invalid item number %d", i);
  1740. return FALSE; // Return immediately so Header_GetItemPtr doesn't assert
  1741. }
  1742. #endif
  1743. phdi = Header_GetItemPtr(phd, i);
  1744. if (!phdi)
  1745. return FALSE;
  1746. mask = pitem->mask;
  1747. if (mask == 0)
  1748. return TRUE;
  1749. // stop editing the filter
  1750. //Header_StopFilterEdit(phd, FALSE);
  1751. if (!Header_SendChange(phd, i, HDN_ITEMCHANGING, pitem))
  1752. return FALSE;
  1753. xOld = phdi->x;
  1754. if (mask & HDI_WIDTH)
  1755. {
  1756. RECT rcClip;
  1757. int iOrder;
  1758. int dx;
  1759. int cxy = pitem->cxy;
  1760. if (cxy < 0)
  1761. cxy = 0;
  1762. DebugMsg(DM_TRACE, TEXT("Header--SetWidth x=%d, cxyOld=%d, cxyNew=%d, dx=%d"),
  1763. phdi->x, phdi->cxy, cxy, (cxy-phdi->cxy));
  1764. dx = cxy - phdi->cxy;
  1765. phdi->cxy = cxy;
  1766. // scroll everything over
  1767. GetClientRect(phd->ci.hwnd, &rcClip);
  1768. rcClip.left = phdi->x; // we want to scroll the divider as well
  1769. // the scrolling rect needs to be the largest rect of the before
  1770. // and after. so if dx is negative, we want to enlarge the rect
  1771. if (dx < 0)
  1772. rcClip.left += dx;
  1773. iOrder = Header_OnGetItemOrder(phd, i);
  1774. Header_ShiftItems(phd, iOrder, dx);
  1775. phdi->xText = phdi->xBm = RECOMPUTE;
  1776. {
  1777. SMOOTHSCROLLINFO si = {
  1778. sizeof(si),
  1779. 0,
  1780. phd->ci.hwnd,
  1781. dx,
  1782. 0,
  1783. NULL,
  1784. &rcClip,
  1785. NULL,
  1786. NULL,
  1787. SW_ERASE | SW_INVALIDATE,
  1788. };
  1789. SmoothScrollWindow(&si);
  1790. }
  1791. UpdateWindow(phd->ci.hwnd);
  1792. // now invalidate this item itself
  1793. Header_OnGetItemRect(phd, i, &rcClip);
  1794. InvalidateRect(phd->ci.hwnd, &rcClip, TRUE);
  1795. }
  1796. if (mask & HDI_FORMAT) {
  1797. phdi->fmt = pitem->fmt;
  1798. phdi->xText = phdi->xBm = RECOMPUTE;
  1799. fInvalidate = TRUE;
  1800. }
  1801. if (mask & HDI_LPARAM)
  1802. phdi->lParam = pitem->lParam;
  1803. if (mask & HDI_TEXT)
  1804. {
  1805. if (!Str_Set(&phdi->pszText, pitem->pszText))
  1806. return FALSE;
  1807. phdi->xText = RECOMPUTE;
  1808. fInvalidate = TRUE;
  1809. }
  1810. if (mask & HDI_BITMAP)
  1811. {
  1812. phdi->hbm = pitem->hbm;
  1813. phdi->xBm = RECOMPUTE;
  1814. fInvalidate = TRUE;
  1815. }
  1816. if (mask & HDI_IMAGE)
  1817. {
  1818. phdi->iImage = pitem->iImage;
  1819. phdi->xBm = RECOMPUTE;
  1820. fInvalidate = TRUE;
  1821. }
  1822. if (mask & HDI_ORDER)
  1823. {
  1824. if (pitem->iOrder >= 0 && pitem->iOrder < Header_GetCount(phd))
  1825. {
  1826. Header_OnSetItemOrder(phd, i, pitem->iOrder);
  1827. NotifyWinEvent(EVENT_OBJECT_REORDER, phd->ci.hwnd, OBJID_CLIENT, 0);
  1828. }
  1829. }
  1830. if ( mask & HDI_FILTER )
  1831. {
  1832. if ( (phdi->type & HDFT_ISMASK) == HDFT_ISSTRING )
  1833. Str_Set(&phdi->textFilter.pszText, NULL);
  1834. // pick up the new filter, handling the case where the filter value is
  1835. // being discarded, and/or there is none
  1836. phdi->type = pitem->type;
  1837. switch ( phdi->type & HDFT_ISMASK )
  1838. {
  1839. case HDFT_ISSTRING:
  1840. {
  1841. if ( pitem->pvFilter )
  1842. {
  1843. LPHDTEXTFILTER ptextFilter = (LPHDTEXTFILTER)pitem->pvFilter;
  1844. ASSERT(ptextFilter);
  1845. if ( !(pitem->type & HDFT_HASNOVALUE) )
  1846. Str_Set(&phdi->textFilter.pszText, ptextFilter->pszText);
  1847. phdi->textFilter.cchTextMax = ptextFilter->cchTextMax;
  1848. }
  1849. break;
  1850. }
  1851. case HDFT_ISNUMBER:
  1852. {
  1853. if ( !(pitem->type & HDFT_HASNOVALUE) && pitem->pvFilter )
  1854. phdi->intFilter = *((int*)pitem->pvFilter);
  1855. break;
  1856. }
  1857. }
  1858. fInvalidate = TRUE;
  1859. }
  1860. Header_SendChange(phd, i, HDN_ITEMCHANGED, pitem);
  1861. if ( mask & HDI_FILTER )
  1862. Header_Notify(phd, i, 0, HDN_FILTERCHANGE); // send out a notify of change
  1863. if (fInvalidate) {
  1864. if (xOld == phdi->x) {
  1865. // no change in x
  1866. Header_InvalidateItem(phd, i, RDW_INVALIDATE| RDW_ERASE);
  1867. } else {
  1868. RECT rc;
  1869. GetClientRect(phd->ci.hwnd, &rc);
  1870. if (i > 0) {
  1871. HDI * phdiTemp;
  1872. phdiTemp = Header_GetItemPtrByOrder(phd, i - 1);
  1873. if (phdiTemp) {
  1874. rc.left = phdi->x;
  1875. }
  1876. }
  1877. RedrawWindow(phd->ci.hwnd, &rc, NULL, RDW_INVALIDATE | RDW_ERASE);
  1878. }
  1879. }
  1880. return TRUE;
  1881. }
  1882. // Compute layout for header bar, and leftover rectangle.
  1883. //
  1884. BOOL Header_OnLayout(HD* phd, HD_LAYOUT* playout)
  1885. {
  1886. int cyHeader;
  1887. WINDOWPOS* pwpos;
  1888. RECT* prc;
  1889. RIPMSG(playout != NULL, "HDM_LAYOUT: Invalid NULL pointer");
  1890. if (!playout || !phd)
  1891. return FALSE;
  1892. if (!(playout->pwpos && playout->prc))
  1893. return FALSE;
  1894. pwpos = playout->pwpos;
  1895. prc = playout->prc;
  1896. cyHeader = phd->cyChar + 2 * g_cyEdgeScaled;
  1897. // when filter bar is enabled then lets show that region
  1898. if ( Header_IsFilter(phd) )
  1899. cyHeader += phd->cyChar + (2*g_cyEdgeScaled) + c_cyFilterBarEdge;
  1900. // internal hack style for use with LVS_REPORT|LVS_NOCOLUMNHEADER! edh
  1901. if (phd->ci.style & HDS_HIDDEN)
  1902. cyHeader = 0;
  1903. pwpos->hwndInsertAfter = NULL;
  1904. pwpos->flags = SWP_NOZORDER | SWP_NOACTIVATE;
  1905. pwpos->x = prc->left;
  1906. pwpos->cx = prc->right - prc->left;
  1907. pwpos->y = prc->top;
  1908. pwpos->cy = cyHeader;
  1909. prc->top += cyHeader;
  1910. return TRUE;
  1911. }
  1912. BOOL Header_OnGetItemRect(HD* phd, int i, RECT* prc)
  1913. {
  1914. HDI* phdi;
  1915. phdi = Header_GetItemPtr(phd, i);
  1916. if (!phdi)
  1917. return FALSE;
  1918. GetClientRect(phd->ci.hwnd, prc);
  1919. prc->right = phdi->x;
  1920. prc->left = prc->right - phdi->cxy;
  1921. return TRUE;
  1922. }
  1923. void Header_InvalidateItem(HD* phd, int i, UINT uFlags)
  1924. {
  1925. RECT rc;
  1926. if (i != -1) {
  1927. Header_OnGetItemRect(phd, i, &rc);
  1928. InflateRect(&rc, g_cxBorder, g_cyBorder);
  1929. RedrawWindow(phd->ci.hwnd, &rc, NULL, uFlags);
  1930. }
  1931. }
  1932. int _Header_DrawBitmap(HDC hdc, HIMAGELIST himl, HD_ITEM* pitem,
  1933. RECT *prc, int fmt, UINT flags, LPRECT prcDrawn, int iMargin)
  1934. {
  1935. // This routine returns either the left of the image
  1936. // or the right of the image depending on the justification.
  1937. // This return value is used in order to properly tack on the
  1938. // bitmap when both the HDF_IMAGE and HDF_BITMAP flags are set.
  1939. RECT rc;
  1940. int xBitmap = 0;
  1941. int yBitmap = 0;
  1942. int cxBitmap;
  1943. int cyBitmap;
  1944. IMAGELISTDRAWPARAMS imldp;
  1945. HBITMAP hbmOld;
  1946. BITMAP bm;
  1947. HDC hdcMem;
  1948. int cxRc;
  1949. SetRectEmpty(prcDrawn);
  1950. if (IsRectEmpty(prc))
  1951. return prc->left;
  1952. rc = *prc;
  1953. rc.left += iMargin;
  1954. rc.right -= iMargin;
  1955. // rc.right -= g_cxEdge; // handle edge
  1956. if (rc.left >= rc.right)
  1957. return rc.left;
  1958. if (pitem->fmt & HDF_IMAGE)
  1959. ImageList_GetIconSize(himl, &cxBitmap, &cyBitmap);
  1960. else { // pitem->fmt & BITMAP
  1961. if (GetObject(pitem->hbm, sizeof(bm), &bm) != sizeof(bm))
  1962. return rc.left; // could not get the info about bitmap.
  1963. hdcMem = CreateCompatibleDC(hdc);
  1964. if (!hdcMem || ((hbmOld = SelectObject(hdcMem, pitem->hbm)) == ERROR))
  1965. return rc.left; // an error happened.
  1966. cxBitmap = bm.bmWidth;
  1967. cyBitmap = bm.bmHeight;
  1968. }
  1969. if (flags & SHDT_DEPRESSED)
  1970. OffsetRect(&rc, g_cxBorder, g_cyBorder);
  1971. // figure out all the formatting...
  1972. cxRc = rc.right - rc.left; // cache this value
  1973. if (fmt == HDF_LEFT)
  1974. {
  1975. if (cxBitmap > cxRc)
  1976. cxBitmap = cxRc;
  1977. }
  1978. else if (fmt == HDF_CENTER)
  1979. {
  1980. if (cxBitmap > cxRc)
  1981. {
  1982. xBitmap = (cxBitmap - cxRc) / 2;
  1983. cxBitmap = cxRc;
  1984. }
  1985. else
  1986. rc.left = (rc.left + rc.right - cxBitmap) / 2;
  1987. }
  1988. else // fmt == HDF_RIGHT
  1989. {
  1990. if (cxBitmap > cxRc)
  1991. {
  1992. xBitmap = cxBitmap - cxRc;
  1993. cxBitmap = cxRc;
  1994. }
  1995. else
  1996. rc.left = rc.right - cxBitmap;
  1997. }
  1998. // Now setup vertically
  1999. if (cyBitmap > (rc.bottom - rc.top))
  2000. {
  2001. yBitmap = (cyBitmap - (rc.bottom - rc.top)) / 2;
  2002. cyBitmap = rc.bottom - rc.top;
  2003. }
  2004. else
  2005. rc.top = (rc.bottom - rc.top - cyBitmap) / 2;
  2006. if (pitem->fmt & HDF_IMAGE) {
  2007. imldp.cbSize = sizeof(imldp);
  2008. imldp.himl = himl;
  2009. imldp.hdcDst = hdc;
  2010. imldp.i = pitem->iImage;
  2011. imldp.x = rc.left;
  2012. imldp.y = rc.top;
  2013. imldp.cx = cxBitmap;
  2014. imldp.cy = cyBitmap;
  2015. imldp.xBitmap= xBitmap;
  2016. imldp.yBitmap= yBitmap;
  2017. imldp.rgbBk = CLR_DEFAULT;
  2018. imldp.rgbFg = CLR_DEFAULT;
  2019. imldp.fStyle = ILD_NORMAL;
  2020. imldp.fState = 0;
  2021. ImageList_DrawIndirect(&imldp);
  2022. }
  2023. else { // pitem->fmt & HDF_BITMAP
  2024. TraceMsg(TF_HEADER, "h_db: BitBlt to (%d,%d) from (%d, %d)", rc.left, rc.top, xBitmap, yBitmap);
  2025. // Last but not least we will do the bitblt.
  2026. BitBlt(hdc, rc.left, rc.top, cxBitmap, cyBitmap,
  2027. hdcMem, xBitmap, yBitmap, SRCCOPY);
  2028. // Unselect our object from the DC
  2029. SelectObject(hdcMem, hbmOld);
  2030. // Also free any memory dcs we may have created
  2031. DeleteDC(hdcMem);
  2032. }
  2033. *prcDrawn = rc;
  2034. prcDrawn->bottom = rc.top + cyBitmap;
  2035. prcDrawn->right = rc.left + cxBitmap;
  2036. return ((pitem->fmt & HDF_RIGHT) ? rc.left : rc.left+cxBitmap);
  2037. }
  2038. void Header_DrawButtonEdges(HD* phd, HDC hdc, LPRECT prc, BOOL fItemSunken)
  2039. {
  2040. UINT uEdge;
  2041. UINT uBF;
  2042. if (phd->ci.style & HDS_BUTTONS)
  2043. {
  2044. if (fItemSunken) {
  2045. uEdge = EDGE_SUNKEN;
  2046. uBF = BF_RECT | BF_SOFT | BF_FLAT;
  2047. } else {
  2048. uEdge = EDGE_RAISED;
  2049. uBF = BF_RECT | BF_SOFT;
  2050. }
  2051. }
  2052. else
  2053. {
  2054. uEdge = EDGE_ETCHED;
  2055. if (phd->ci.style & WS_BORDER)
  2056. uBF = BF_RIGHT;
  2057. else
  2058. uBF = BF_BOTTOMRIGHT;
  2059. }
  2060. DrawEdge(hdc, prc, uEdge, uBF);
  2061. }
  2062. void Header_DrawFilterGlyph(HD* phd, HDC hdc, RECT* prc, BOOL fPressed)
  2063. {
  2064. UINT uEdge = BDR_RAISEDOUTER|BDR_RAISEDINNER;
  2065. UINT uBF = BF_RECT;
  2066. RECT rc = *prc;
  2067. if ( fPressed )
  2068. {
  2069. uEdge = EDGE_SUNKEN;
  2070. uBF = BF_RECT | BF_SOFT | BF_FLAT;
  2071. }
  2072. if ( !phd->hFilterImage )
  2073. {
  2074. phd->hFilterImage = ImageList_LoadBitmap(HINST_THISDLL, MAKEINTRESOURCE(IDB_FILTERIMAGE), c_cxFilterImage, 0, RGB(128, 0, 0));
  2075. if ( !phd->hFilterImage )
  2076. return;
  2077. }
  2078. DrawEdge(hdc, &rc, uEdge, uBF|BF_MIDDLE);
  2079. if (fPressed)
  2080. OffsetRect(&rc, g_cxBorder, g_cyBorder);
  2081. ImageList_Draw(phd->hFilterImage, 0, hdc,
  2082. rc.left+(((rc.right-rc.left)-c_cxFilterImage)/2),
  2083. rc.top+(((rc.bottom-rc.top)-c_cyFilterImage)/2),
  2084. ILD_NORMAL);
  2085. }
  2086. //
  2087. // Oh boy, here come the pictures.
  2088. //
  2089. // For a left-justified header item, the items are arranged like this.
  2090. //
  2091. // rcHeader.left rcHeader.right
  2092. // | iTextMargin iTextMargin |
  2093. // | ->| |<- ->| |<- |
  2094. // | | | | | |
  2095. // v |<--textSize-->| | v
  2096. // +----------------------------------------+
  2097. // | |BMPBMP| | |TEXTTEXTTEXT| | |
  2098. // +----------------------------------------+
  2099. // |<-bmSize->| | |
  2100. // | | | | | |
  2101. // ->| |<- ->| |<- | |
  2102. // iBmMargin iBmMargin | |
  2103. // | | |
  2104. // |<-------cxTextAndBm------->|
  2105. //
  2106. //
  2107. // For a right-justified header item, the items are arranged like this.
  2108. //
  2109. // rcHeader.left rcHeader.right
  2110. // | iBmMargin iBmMargin |
  2111. // | ->| |<- ->| |<- |
  2112. // | | | | | |
  2113. // v |<-bmSize->| v
  2114. // +----------------------------------------+
  2115. // | | |BMPBMP| | |TEXTTEXTTEXT| |
  2116. // +----------------------------------------+
  2117. // | |<---textSize--->|
  2118. // | | | | |
  2119. // | ->| |<- ->| |<-
  2120. // | iTextMargin iTextMargin
  2121. // | |
  2122. // |<-------cxTextAndBm------->|
  2123. //
  2124. // Obvious variations apply to center-justified, bitmap-on-right, etc.
  2125. // The point is that all the sizes are accounted for in the manner above.
  2126. // There are no gratuitous +1's or g_cxEdge's.
  2127. //
  2128. void Header_DrawItem(HD* phd, HDC hdc, int i, int iIndex, LPRECT prc, UINT uFlags)
  2129. {
  2130. RECT rcHeader;
  2131. RECT rcFilter, rcButton;
  2132. RECT rcText; // item text clipping rect
  2133. RECT rcBm; // item bitmap clipping rect
  2134. COLORREF clrText;
  2135. COLORREF clrBk;
  2136. DWORD dwRet = CDRF_DODEFAULT;
  2137. HDI* phdi; // pointer to current header item
  2138. BOOL fItemSunken;
  2139. HD_ITEM item; // used for text callback
  2140. BOOL fTracking = Header_IsTracking(phd);
  2141. UINT uDrawTextFlags;
  2142. NMCUSTOMDRAW nmcd;
  2143. TCHAR ach[CCHLABELMAX]; // used for text callback
  2144. HRGN hrgnClip = NULL;
  2145. HRESULT hr = E_FAIL;
  2146. int iStateId = HIS_NORMAL;
  2147. rcHeader = rcFilter = *prc; // private copies for us to dork
  2148. phdi = Header_GetItemPtrByOrder(phd,i);
  2149. fItemSunken = (fTracking && (phd->flagsTrack & HHT_ONHEADER) &&
  2150. (phd->iTrack == iIndex) && phd->bTrackPress);
  2151. if (fItemSunken)
  2152. {
  2153. iStateId = HIS_PRESSED;
  2154. }
  2155. else if (iIndex == phd->iHot)
  2156. {
  2157. iStateId = HIS_HOT;
  2158. }
  2159. // Note that SHDT_EXTRAMARGIN requires phd->iTextMargin >= 3*g_cxLabelMargin
  2160. uDrawTextFlags = SHDT_ELLIPSES | SHDT_EXTRAMARGIN | SHDT_CLIPPED;
  2161. if(fItemSunken)
  2162. uDrawTextFlags |= SHDT_DEPRESSED;
  2163. if (phdi->fmt & HDF_OWNERDRAW)
  2164. {
  2165. DRAWITEMSTRUCT dis;
  2166. phd->fOwnerDraw = TRUE;
  2167. dis.CtlType = ODT_HEADER;
  2168. dis.CtlID = GetWindowID(phd->ci.hwnd);
  2169. dis.itemID = iIndex;
  2170. dis.itemAction = ODA_DRAWENTIRE;
  2171. dis.itemState = (fItemSunken) ? ODS_SELECTED : 0;
  2172. dis.hwndItem = phd->ci.hwnd;
  2173. dis.hDC = hdc;
  2174. dis.rcItem = *prc;
  2175. dis.itemData = phdi->lParam;
  2176. // Now send it off to my parent...
  2177. if (SendMessage(phd->ci.hwndParent, WM_DRAWITEM, dis.CtlID,
  2178. (LPARAM)(DRAWITEMSTRUCT *)&dis))
  2179. goto DrawEdges; //Ick, but it works
  2180. }
  2181. else
  2182. {
  2183. nmcd.dwItemSpec = iIndex;
  2184. nmcd.hdc = hdc;
  2185. nmcd.rc = *prc;
  2186. nmcd.uItemState = (fItemSunken) ? CDIS_SELECTED : 0;
  2187. nmcd.lItemlParam = phdi->lParam;
  2188. if (!(CCGetUIState(&(phd->ci)) & UISF_HIDEFOCUS))
  2189. nmcd.uItemState |= CDIS_SHOWKEYBOARDCUES;
  2190. dwRet = CICustomDrawNotify(&phd->ci, CDDS_ITEMPREPAINT, &nmcd);
  2191. if (dwRet & CDRF_SKIPDEFAULT)
  2192. {
  2193. return;
  2194. }
  2195. }
  2196. // this is to fetch out any changes the caller might have changed
  2197. clrText = GetTextColor(hdc);
  2198. clrBk = GetBkColor(hdc);
  2199. //
  2200. // Now neet to handle the different combinatations of
  2201. // text, bitmaps, and images...
  2202. //
  2203. if ( Header_IsFilter(phd) )
  2204. Header_GetFilterRects(prc, &rcHeader, &rcFilter, &rcButton);
  2205. rcText = rcBm = rcHeader;
  2206. if (phdi->fmt & (HDF_STRING | HDF_IMAGE | HDF_BITMAP))
  2207. {
  2208. item.mask = HDI_TEXT | HDI_IMAGE | HDI_FORMAT | HDI_BITMAP;
  2209. item.pszText = ach;
  2210. item.cchTextMax = ARRAYSIZE(ach);
  2211. Header_OnGetItem(phd,iIndex,&item);
  2212. }
  2213. if (phd->hTheme)
  2214. {
  2215. GetThemeBackgroundContentRect(phd->hTheme, hdc, HP_HEADERITEM, iStateId, &rcHeader, &rcText);
  2216. rcBm = rcText;
  2217. }
  2218. //
  2219. // If we have a string and either an image or a bitmap...
  2220. //
  2221. if (phdi->fmt & HDF_STRING &&
  2222. (phdi->fmt & (HDF_BITMAP | HDF_IMAGE) ||
  2223. phdi->fmt & (HDF_SORTUP | HDF_SORTDOWN)))
  2224. {
  2225. // Begin Recompute
  2226. if (phdi->xText == RECOMPUTE ||
  2227. phdi->xBm == RECOMPUTE)
  2228. {
  2229. BITMAP bm; // used to calculate bitmap width
  2230. // calculate the placement of bitmap rect and text rect
  2231. SIZE textSize,bmSize; int dx;
  2232. // get total textwidth
  2233. if (phd->hTheme)
  2234. {
  2235. RECT rc = {0};
  2236. RECT rcBound = {0};
  2237. hr = GetThemeTextExtent(phd->hTheme, hdc, HP_HEADERITEM, iStateId, item.pszText, -1, 0, &rcBound, &rc);
  2238. textSize.cx = RECTWIDTH(rc);
  2239. textSize.cy = RECTHEIGHT(rc);
  2240. }
  2241. if (FAILED(hr))
  2242. {
  2243. GetTextExtentPoint(hdc,item.pszText,lstrlen(item.pszText),
  2244. &textSize);
  2245. }
  2246. TraceMsg(TF_HEADER, "h_di: GetTextExtentPoint returns %d", textSize.cx);
  2247. textSize.cx += 2 * phd->iTextMargin;
  2248. // get total bitmap width
  2249. if (phdi->fmt & HDF_IMAGE)
  2250. {
  2251. ImageList_GetIconSize(phd->himl,(LPINT)&bmSize.cx,(LPINT)&bmSize.cy);
  2252. }
  2253. else if (phdi->fmt & (HDF_SORTUP | HDF_SORTDOWN))
  2254. {
  2255. // Make the size of the arrow a square based on height.
  2256. bmSize.cx = textSize.cy + 2 * g_cxEdge;
  2257. bmSize.cy = textSize.cy;
  2258. }
  2259. else
  2260. {
  2261. // phdi->fmt & HDF_BITMAP
  2262. GetObject(phdi->hbm,sizeof(bm), &bm);
  2263. bmSize.cx = bm.bmWidth;
  2264. TraceMsg(TF_HEADER, "h_di: Bitmap size is %d", bmSize.cx);
  2265. }
  2266. bmSize.cx += 2 * phd->iBmMargin;
  2267. phdi->cxTextAndBm = bmSize.cx + textSize.cx;
  2268. // calculate how much extra space we have, if any.
  2269. dx = rcHeader.right-rcHeader.left - phdi->cxTextAndBm;
  2270. if (dx < 0)
  2271. {
  2272. dx = 0;
  2273. phdi->cxTextAndBm = rcHeader.right-rcHeader.left;
  2274. }
  2275. if (phdi->fmt & HDF_BITMAP_ON_RIGHT ||
  2276. phdi->fmt & (HDF_SORTUP | HDF_SORTDOWN)) // Sort arrows behave as if on right
  2277. {
  2278. switch (phdi->fmt & HDF_JUSTIFYMASK)
  2279. {
  2280. case HDF_LEFT:
  2281. phdi->xText = rcText.left;
  2282. break;
  2283. case HDF_RIGHT:
  2284. phdi->xText = rcText.right - phdi->cxTextAndBm;
  2285. break;
  2286. case HDF_CENTER:
  2287. phdi->xText = rcText.left + dx/2;
  2288. break;
  2289. }
  2290. // show as much of the bitmap as possible..
  2291. // if we start running out of room, scoot the bitmap
  2292. // back on.
  2293. if (dx == 0)
  2294. phdi->xBm = rcText.right - bmSize.cx;
  2295. else
  2296. phdi->xBm = phdi->xText + textSize.cx;
  2297. // clip the values
  2298. if (phdi->xBm < rcHeader.left)
  2299. phdi->xBm = rcHeader.left;
  2300. }
  2301. else
  2302. {
  2303. // BITMAP_ON_LEFT
  2304. switch (phdi->fmt & HDF_JUSTIFYMASK)
  2305. {
  2306. case HDF_LEFT:
  2307. phdi->xBm = rcBm.left;
  2308. break;
  2309. case HDF_RIGHT:
  2310. phdi->xBm = rcBm.right - phdi->cxTextAndBm;
  2311. break;
  2312. case HDF_CENTER:
  2313. phdi->xBm = rcBm.left + dx/2;
  2314. break;
  2315. }
  2316. phdi->xText = phdi->xBm + bmSize.cx;
  2317. // clip the values
  2318. if (phdi->xText > rcHeader.right)
  2319. phdi->xText = rcHeader.right;
  2320. }
  2321. // xBm and xText are now absolute coordinates..
  2322. // change them to item relative coordinates
  2323. phdi->xBm -= rcHeader.left;
  2324. phdi->xText -= rcHeader.left;
  2325. TraceMsg(TF_HEADER, "h_di: phdi->xBm = %d, phdi->xText=%d",phdi->xBm, phdi->xText );
  2326. }
  2327. // End Recompute
  2328. // calculate text and bitmap rectangles
  2329. rcBm.left = phdi->xBm + rcText.left;
  2330. rcText.left = phdi->xText + rcText.left;
  2331. if (phdi->fmt & HDF_BITMAP_ON_RIGHT ||
  2332. phdi->fmt & (HDF_SORTUP | HDF_SORTDOWN))
  2333. {
  2334. rcBm.right = rcText.left + phdi->cxTextAndBm;
  2335. rcText.right = rcBm.left;
  2336. }
  2337. else
  2338. {
  2339. // BITMAP_ON_LEFT
  2340. rcBm.right = rcText.left;
  2341. rcText.right = rcBm.left + phdi->cxTextAndBm;
  2342. }
  2343. }
  2344. if (phd->hTheme)
  2345. {
  2346. DrawThemeBackground(phd->hTheme, hdc, HP_HEADERITEM, iStateId, &rcHeader, 0);
  2347. }
  2348. if (phdi->fmt & (HDF_SORTUP | HDF_SORTDOWN))
  2349. {
  2350. BOOL fUpArrow = phdi->fmt & HDF_SORTUP;
  2351. if (phd->hfontSortArrow)
  2352. {
  2353. int cy;
  2354. TEXTMETRIC tm;
  2355. int bkMode = SetBkMode(hdc, TRANSPARENT);
  2356. COLORREF cr = SetTextColor(hdc, g_clrGrayText);
  2357. HFONT hFontOld = SelectObject(hdc, phd->hfontSortArrow);
  2358. GetTextMetrics(hdc, &tm);
  2359. // Set the font height (based on original USER code)
  2360. cy = ((tm.tmHeight + tm.tmExternalLeading + GetSystemMetrics(SM_CYBORDER)) & 0xFFFE) - 1;
  2361. ExtTextOut(hdc, rcBm.left, rcBm.top + (RECTHEIGHT(rcBm) - cy)/ 2, 0, &rcBm, fUpArrow? TEXT("5") : TEXT("6"), 1, NULL);
  2362. SetTextColor(hdc, cr);
  2363. SetBkMode(hdc, bkMode);
  2364. SelectObject(hdc, hFontOld);
  2365. }
  2366. }
  2367. else if (phdi->fmt & HDF_IMAGE ||
  2368. phdi->fmt & HDF_BITMAP) // If we have a bitmap and/or an image...
  2369. {
  2370. BOOL fDrawBoth = FALSE;
  2371. RECT rcDrawn;
  2372. HRGN hrgn1 = NULL, hrgn2 = NULL;
  2373. int temp; // used to determine placement of bitmap.
  2374. if (phdi->fmt & HDF_IMAGE &&
  2375. phdi->fmt & HDF_BITMAP)
  2376. {
  2377. // we have to do both
  2378. fDrawBoth = TRUE;
  2379. // first do just the image... turn off the bitmap bit
  2380. // HACK ALERT! -- Don't call _Header_DrawBitmap with
  2381. // both the bitmap and image flags on
  2382. // Draw the image...
  2383. item.fmt ^= HDF_BITMAP; // turn off bitmap bit
  2384. }
  2385. if (!(uFlags & HDDF_NOIMAGE))
  2386. {
  2387. TraceMsg(TF_HEADER, "h_di: about to draw bitmap at rcBm= (%d,%d,%d,%d)",
  2388. rcBm.left, rcBm.top, rcBm.right, rcBm.bottom );
  2389. temp = _Header_DrawBitmap(hdc, phd->himl, &item, &rcBm,
  2390. item.fmt & HDF_JUSTIFYMASK, uDrawTextFlags,
  2391. &rcDrawn, phd->iBmMargin);
  2392. hrgn1 = CreateRectRgnIndirect(&rcDrawn);
  2393. }
  2394. if (fDrawBoth)
  2395. {
  2396. // Tack on the bitmap...
  2397. // Always tack the bitmap on the right of the image and
  2398. // text unless we are right justified. then, tack it on
  2399. // left.
  2400. item.fmt ^= HDF_BITMAP; // turn on bitmap bit
  2401. item.fmt ^= HDF_IMAGE; // and turn off image bit
  2402. if (item.fmt & HDF_RIGHT)
  2403. {
  2404. rcBm.right = temp;
  2405. if (item.fmt & HDF_STRING)
  2406. {
  2407. rcBm.right = ((rcBm.left < rcText.left) ?
  2408. rcBm.left : rcText.left);
  2409. }
  2410. rcBm.left = rcHeader.left;
  2411. }
  2412. else
  2413. {
  2414. rcBm.left = temp;
  2415. if (item.fmt & HDF_STRING)
  2416. {
  2417. rcBm.left = ((rcBm.right > rcText.right) ? rcBm.right:rcText.right);
  2418. }
  2419. rcBm.right = rcHeader.right;
  2420. }
  2421. if (!(uFlags & HDDF_NOIMAGE))
  2422. {
  2423. _Header_DrawBitmap(hdc, phd->himl, &item, &rcBm,
  2424. item.fmt & HDF_RIGHT, uDrawTextFlags,
  2425. &rcDrawn, phd->iBmMargin);
  2426. hrgn2 = CreateRectRgnIndirect(&rcDrawn);
  2427. }
  2428. item.fmt ^= HDF_IMAGE; // turn on the image bit
  2429. }
  2430. // if there were any regions created, union them together
  2431. if(hrgn1 && hrgn2)
  2432. {
  2433. hrgnClip = CreateRectRgn(0,0,0,0);
  2434. CombineRgn(hrgnClip, hrgn1, hrgn2, RGN_OR);
  2435. DeleteObject(hrgn1);
  2436. DeleteObject(hrgn2);
  2437. }
  2438. else if (hrgn1)
  2439. {
  2440. hrgnClip = hrgn1;
  2441. hrgn1 = NULL;
  2442. }
  2443. else if (hrgn2)
  2444. {
  2445. hrgnClip = hrgn2;
  2446. hrgn2 = NULL;
  2447. }
  2448. // this only happens in the drag/drop case
  2449. if ((uFlags & HDDF_NOIMAGE) && !hrgnClip )
  2450. {
  2451. // this means we didn't draw the images, which means we
  2452. // don't have the rects for them,
  2453. // which means we need to create a dummy empty hrgnClip;
  2454. hrgnClip = CreateRectRgn(0,0,0,0);
  2455. }
  2456. SaveDC(hdc);
  2457. }
  2458. if (phdi->fmt & HDF_STRING)
  2459. {
  2460. if (item.fmt & HDF_RTLREADING)
  2461. {
  2462. uDrawTextFlags |= SHDT_RTLREADING;
  2463. }
  2464. if (phd->hTheme)
  2465. {
  2466. clrBk = CLR_NONE;
  2467. }
  2468. TraceMsg(TF_HEADER, "h_di: about to draw text rcText=(%d,%d,%d,%d)",
  2469. rcText.left, rcText.top, rcText.right, rcText.bottom );
  2470. SHThemeDrawText(phd->hTheme, hdc, HP_HEADERITEM, iStateId, item.pszText, &rcText,
  2471. item.fmt & HDF_JUSTIFYMASK,
  2472. uDrawTextFlags, phd->cyChar, phd->cxEllipses,
  2473. clrText, clrBk);
  2474. if (hrgnClip)
  2475. {
  2476. // if we're building a clipping region, add the text to it.
  2477. HRGN hrgnText;
  2478. hrgnText = CreateRectRgnIndirect(&rcText);
  2479. CombineRgn(hrgnClip, hrgnText, hrgnClip, RGN_OR);
  2480. DeleteObject(hrgnText);
  2481. }
  2482. }
  2483. if (Header_IsFilter(phd))
  2484. {
  2485. TCHAR szBuffer[32] = {'\0'};
  2486. LPTSTR pBuffer = szBuffer;
  2487. DWORD dwButtonState = DFCS_BUTTONPUSH;
  2488. uDrawTextFlags = SHDT_ELLIPSES | SHDT_EXTRAMARGIN | SHDT_CLIPPED;
  2489. if (item.fmt & HDF_RTLREADING)
  2490. uDrawTextFlags |= SHDT_RTLREADING;
  2491. if (phdi->type & HDFT_HASNOVALUE)
  2492. {
  2493. LocalizedLoadString(IDS_ENTERTEXTHERE, szBuffer, ARRAYSIZE(szBuffer));
  2494. clrText = g_clrGrayText;
  2495. }
  2496. else
  2497. {
  2498. clrText = g_clrWindowText;
  2499. switch (phdi->type & HDFT_ISMASK)
  2500. {
  2501. case HDFT_ISSTRING:
  2502. pBuffer = phdi->textFilter.pszText;
  2503. break;
  2504. case HDFT_ISNUMBER:
  2505. StringCchPrintf(szBuffer, ARRAYSIZE(szBuffer), TEXT("%d"), phdi->intFilter);
  2506. break;
  2507. default:
  2508. ASSERT(FALSE);
  2509. break;
  2510. }
  2511. }
  2512. SHDrawText(hdc, pBuffer, &rcFilter,
  2513. 0, uDrawTextFlags,
  2514. phd->cyChar, phd->cxEllipses,
  2515. clrText, g_clrWindow);
  2516. PatBlt(hdc, rcFilter.left, rcFilter.bottom, rcFilter.right-rcFilter.left, c_cyFilterBarEdge, BLACKNESS);
  2517. Header_DrawFilterGlyph(phd, hdc, &rcButton, (i==phd->iButtonDown));
  2518. if (hrgnClip) {
  2519. // if we're building a clipping region, add the text to it.
  2520. HRGN hrgnFilter;
  2521. hrgnFilter = CreateRectRgn( rcFilter.left, rcButton.top, rcButton.right, rcButton.bottom );
  2522. CombineRgn(hrgnClip, hrgnFilter, hrgnClip, RGN_OR);
  2523. DeleteObject(hrgnFilter);
  2524. }
  2525. if ( phd->fFocus && (phd->iFocus == i) &&
  2526. !(CCGetUIState(&(phd->ci)) & UISF_HIDEFOCUS))
  2527. {
  2528. InflateRect(&rcFilter, -g_cxEdge/2, -g_cyEdge/2);
  2529. SetTextColor(hdc, g_clrWindowText);
  2530. DrawFocusRect(hdc, &rcFilter);
  2531. }
  2532. }
  2533. if (hrgnClip)
  2534. {
  2535. if (!phd->hTheme)
  2536. {
  2537. // hrgnClip is the union of everyplace we've drawn..
  2538. // we want just the opposite.. so xor it
  2539. HRGN hrgnAll = CreateRectRgnIndirect(&rcHeader);
  2540. if (hrgnAll)
  2541. {
  2542. HRGN hrgn = CreateRectRgn(0, 0,0,0);
  2543. if (hrgn)
  2544. {
  2545. CombineRgn(hrgn, hrgnAll, hrgnClip, RGN_XOR);
  2546. SelectClipRgn(hdc, hrgn);
  2547. ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rcHeader, NULL, 0, NULL);
  2548. RestoreDC(hdc, -1);
  2549. DeleteObject(hrgn);
  2550. }
  2551. DeleteObject(hrgnAll);
  2552. }
  2553. }
  2554. DeleteObject(hrgnClip);
  2555. }
  2556. DrawEdges:
  2557. if (!phd->hTheme && (!(uFlags & HDDF_NOEDGE) &&
  2558. !(phd->ci.style & HDS_FLAT) ||
  2559. iIndex == phd->iHot))
  2560. {
  2561. Header_DrawButtonEdges(phd, hdc, &rcHeader, fItemSunken);
  2562. }
  2563. if (dwRet & CDRF_NOTIFYPOSTPAINT)
  2564. {
  2565. CICustomDrawNotify(&phd->ci, CDDS_ITEMPOSTPAINT, &nmcd);
  2566. }
  2567. }
  2568. void Header_Draw(HD* phd, HDC hdc, RECT* prcClip)
  2569. {
  2570. int i; // index of current header item
  2571. int cItems; // number of items in header
  2572. RECT rc = { 0 }; // item clipping rect
  2573. BOOL fTracking;
  2574. HFONT hfontOld = NULL;
  2575. HDC hdcMem = NULL;
  2576. int iIndex;
  2577. NMCUSTOMDRAW nmcd;
  2578. COLORREF clrText;
  2579. fTracking = Header_IsTracking(phd);
  2580. if (phd->hfont)
  2581. hfontOld = SelectFont(hdc, phd->hfont);
  2582. cItems = DSA_GetItemCount(phd->hdsaHDI);
  2583. FillRectClr(hdc, prcClip, GetSysColor(COLOR_BTNFACE));
  2584. nmcd.hdc = hdc;
  2585. nmcd.uItemState = 0;
  2586. nmcd.lItemlParam = 0;
  2587. nmcd.rc = *prcClip;
  2588. phd->ci.dwCustom = CICustomDrawNotify(&phd->ci, CDDS_PREPAINT, &nmcd);
  2589. for (i = 0 ; i < cItems; i++)
  2590. {
  2591. iIndex = Header_ItemOrderToIndex(phd, i);
  2592. Header_OnGetItemRect(phd, iIndex, &rc);
  2593. if (prcClip)
  2594. {
  2595. if (rc.right < prcClip->left)
  2596. continue;
  2597. if (rc.left >= prcClip->right)
  2598. break;
  2599. }
  2600. if (iIndex == phd->iHot) {
  2601. clrText = GetSysColor(COLOR_HOTLIGHT);
  2602. } else {
  2603. clrText = g_clrBtnText;
  2604. }
  2605. SetTextColor(hdc, clrText);
  2606. SetBkColor(hdc, g_clrBtnFace);
  2607. Header_DrawItem(phd, hdc, i, iIndex, &rc, 0);
  2608. }
  2609. if (i == cItems)
  2610. {
  2611. // we got through the loop... now we need to do the blank area on the right
  2612. rc.left = rc.right;
  2613. rc.right = 32000;
  2614. if (phd->hTheme)
  2615. {
  2616. DrawThemeBackground(phd->hTheme, hdc, 0, 0, &rc, 0);
  2617. }
  2618. else if (phd->ci.style & HDS_FLAT)
  2619. {
  2620. FillRectClr(hdc, &rc, g_clrBtnFace);
  2621. }
  2622. else
  2623. {
  2624. Header_DrawButtonEdges(phd, hdc, &rc, FALSE);
  2625. }
  2626. }
  2627. if (!HDDragFullWindows(phd) && fTracking && (phd->flagsTrack & (HHT_ONDIVIDER | HHT_ONDIVOPEN)))
  2628. Header_DrawDivider(phd, phd->xTrack);
  2629. // draw the hot divider
  2630. if (phd->iNewOrder != -1) {
  2631. RECT rc;
  2632. COLORREF clrHot = GetSysColor(COLOR_HOTLIGHT);
  2633. Header_GetDividerRect(phd, phd->iNewOrder, &rc);
  2634. FillRectClr(hdc, &rc, clrHot);
  2635. }
  2636. if (phd->ci.dwCustom & CDRF_NOTIFYPOSTPAINT) {
  2637. CICustomDrawNotify(&phd->ci, CDDS_POSTPAINT, &nmcd);
  2638. }
  2639. if (hfontOld)
  2640. SelectFont(hdc, hfontOld);
  2641. }
  2642. HIMAGELIST Header_OnCreateDragImage(HD* phd, int i)
  2643. {
  2644. HDC hdcMem;
  2645. RECT rc;
  2646. HBITMAP hbmImage = NULL;
  2647. HBITMAP hbmMask = NULL;
  2648. HFONT hfontOld = NULL;
  2649. HIMAGELIST himl = NULL;
  2650. HIMAGELIST himlDither = NULL;
  2651. HBITMAP hbmOld = NULL;
  2652. BOOL bMirroredWnd = (phd->ci.dwExStyle&RTL_MIRRORED_WINDOW);
  2653. int iIndex = Header_ItemOrderToIndex(phd, i);
  2654. // Fixing crash in OE while dragging the message
  2655. // header.
  2656. if( !Header_OnGetItemRect(phd, iIndex, &rc) )
  2657. goto Bail;
  2658. // draw the header into this bitmap
  2659. OffsetRect(&rc, -rc.left, -rc.top);
  2660. if (!(hdcMem = CreateCompatibleDC(NULL)))
  2661. goto Bail;
  2662. if (!(hbmImage = CreateColorBitmap(rc.right, rc.bottom)))
  2663. goto Bail;
  2664. if (!(hbmMask = CreateMonoBitmap(rc.right, rc.bottom)))
  2665. goto Bail;
  2666. //
  2667. // Mirror the memory DC so that the transition from
  2668. // mirrored(memDC)->non-mirrored(imagelist DCs)->mirrored(screenDC)
  2669. // is consistent. [samera]
  2670. //
  2671. if (bMirroredWnd) {
  2672. SET_DC_RTL_MIRRORED(hdcMem);
  2673. }
  2674. if (phd->hfont)
  2675. hfontOld = SelectFont(hdcMem, phd->hfont);
  2676. if (!(himl = ImageList_Create(rc.right, rc.bottom, ILC_MASK, 1, 0)))
  2677. goto Bail;
  2678. if (!(himlDither = ImageList_Create(rc.right, rc.bottom, ILC_MASK, 1, 0)))
  2679. goto Bail;
  2680. // have the darker background
  2681. SetTextColor(hdcMem, g_clrBtnText);
  2682. SetBkColor(hdcMem, g_clrBtnShadow);
  2683. hbmOld = SelectObject(hdcMem, hbmImage);
  2684. Header_DrawItem(phd, hdcMem, i, iIndex, &rc, HDDF_NOEDGE);
  2685. //
  2686. // If the header is RTL mirrored, then
  2687. // mirror the Memory DC, so that when copying back
  2688. // we don't get any image-flipping. [samera]
  2689. //
  2690. if (bMirroredWnd)
  2691. MirrorBitmapInDC(hdcMem, hbmImage);
  2692. // fill the mask with all black
  2693. SelectObject(hdcMem, hbmMask);
  2694. PatBlt(hdcMem, 0, 0, rc.right, rc.bottom, BLACKNESS);
  2695. // put the image into an imagelist
  2696. SelectObject(hdcMem, hbmOld);
  2697. ImageList_SetBkColor(himl, CLR_NONE);
  2698. ImageList_Add(himl, hbmImage, hbmMask);
  2699. // have the darker background
  2700. // now put the text in undithered.
  2701. SetTextColor(hdcMem, g_clrBtnText);
  2702. SetBkColor(hdcMem, g_clrBtnShadow);
  2703. hbmOld = SelectObject(hdcMem, hbmImage);
  2704. Header_DrawItem(phd, hdcMem, i, iIndex, &rc, HDDF_NOIMAGE | HDDF_NOEDGE);
  2705. DrawEdge(hdcMem, &rc, EDGE_BUMP, BF_RECT | BF_FLAT);
  2706. //
  2707. // If the header is RTL mirrored, then
  2708. // mirror the Memory DC, so that when copying back
  2709. // we don't get any image-flipping. [samera]
  2710. //
  2711. if (bMirroredWnd)
  2712. MirrorBitmapInDC(hdcMem, hbmImage);
  2713. /*
  2714. // initialize this to transparent
  2715. SelectObject(hdcMem, hbmImage);
  2716. PatBlt(hdcMem, 0, 0, rc.right, rc.bottom, BLACKNESS);
  2717. SelectObject(hdcMem, hbmMask);
  2718. PatBlt(hdcMem, 0, 0, rc.right, rc.bottom, WHITENESS);
  2719. */
  2720. SelectObject(hdcMem, hbmOld);
  2721. ImageList_AddMasked(himlDither, hbmImage, g_clrBtnShadow);
  2722. // dither image into himlDithered
  2723. ImageList_CopyDitherImage(himlDither, 0, 0, 0,
  2724. himl, 0, 0);
  2725. Bail:
  2726. if (himl)
  2727. {
  2728. ImageList_Destroy(himl);
  2729. }
  2730. if (hdcMem)
  2731. {
  2732. if (hbmOld)
  2733. SelectObject(hdcMem, hbmOld);
  2734. if (hfontOld)
  2735. SelectFont(hdcMem, hfontOld);
  2736. DeleteObject(hdcMem);
  2737. }
  2738. if (hbmImage)
  2739. DeleteObject(hbmImage);
  2740. if (hbmMask)
  2741. DeleteObject(hbmMask);
  2742. return himlDither;
  2743. }
  2744. void Header_GetFilterRects(LPRECT prcItem, LPRECT prcHeader, LPRECT prcFilter, LPRECT prcButton)
  2745. {
  2746. INT cyFilter = ((prcItem->bottom-prcItem->top)-c_cyFilterBarEdge)/2;
  2747. *prcButton = *prcFilter = *prcHeader = *prcItem;
  2748. prcHeader->bottom = prcHeader->top + cyFilter;
  2749. prcButton->left = prcFilter->right = prcFilter->right -= (g_cxBorder*4)+c_cxFilterImage;
  2750. prcButton->top = prcFilter->top = prcHeader->bottom;
  2751. prcFilter->bottom = prcFilter->top + cyFilter;
  2752. }
  2753. //
  2754. // Subclass the edit control to ensure we get the keys we are interested in
  2755. //
  2756. LRESULT CALLBACK Header_EditWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  2757. {
  2758. HD* phd = (HD*)GetWindowPtr(GetParent(hwnd), 0);
  2759. ASSERT(phd);
  2760. switch (msg)
  2761. {
  2762. case WM_KILLFOCUS:
  2763. Header_StopFilterEdit(phd, FALSE);
  2764. return 0L;
  2765. case WM_KEYDOWN:
  2766. {
  2767. if (wParam == VK_RETURN)
  2768. {
  2769. Header_StopFilterEdit(phd, FALSE);
  2770. return 0L;
  2771. }
  2772. else if (wParam == VK_ESCAPE)
  2773. {
  2774. Header_StopFilterEdit(phd, TRUE);
  2775. return 0L;
  2776. }
  2777. else if (wParam == VK_F4 )
  2778. {
  2779. Header_OnFilterButton(phd, phd->iEdit);
  2780. return 0L;
  2781. }
  2782. break;
  2783. }
  2784. case WM_CHAR:
  2785. {
  2786. switch (wParam)
  2787. {
  2788. case VK_RETURN:
  2789. case VK_ESCAPE:
  2790. case VK_TAB:
  2791. return 0L; // eat these so we don't beep
  2792. }
  2793. //notify of navigation key usage
  2794. CCNotifyNavigationKeyUsage(&(phd->ci), UISF_HIDEFOCUS);
  2795. break;
  2796. }
  2797. case WM_GETDLGCODE:
  2798. return DLGC_WANTALLKEYS | DLGC_HASSETSEL; /* editing name, no dialog handling right now */
  2799. }
  2800. return CallWindowProc(phd->pfnEditWndProc, hwnd, msg, wParam, lParam);
  2801. }
  2802. //
  2803. // Begin to edit the given column, displaying the editor as required
  2804. //
  2805. BOOL Header_BeginFilterEdit(HD* phd, int i)
  2806. {
  2807. RECT rc, rcHeader, rcFilter, rcButton;
  2808. int iIndex = i;
  2809. int cxEdit, cyEdit;
  2810. TCHAR szBuffer[MAX_PATH];
  2811. LPTSTR pBuffer = szBuffer;
  2812. int cchBuffer = MAX_PATH;
  2813. UINT uFlags = WS_CLIPSIBLINGS|WS_VISIBLE|WS_CHILD|ES_AUTOHSCROLL;
  2814. HDI* phdi = Header_GetItemPtr(phd, i);
  2815. if ( !phdi || (i < 0) )
  2816. return FALSE; // yikes
  2817. // lets create an edit control that allows the user to
  2818. // modify the current filter, note that we first must
  2819. // format the data to be displayed in the control
  2820. Header_OnGetItemRect(phd, iIndex, &rc);
  2821. Header_GetFilterRects(&rc, &rcHeader, &rcFilter, &rcButton);
  2822. phd->typeOld = phdi->type; // keep the type field safe
  2823. switch (phdi->type & HDFT_ISMASK)
  2824. {
  2825. case HDFT_ISSTRING:
  2826. Str_Set(&phd->pszFilterOld, phdi->textFilter.pszText);
  2827. pBuffer = phdi->textFilter.pszText;
  2828. // This count does not include the terminating null
  2829. cchBuffer = phdi->textFilter.cchTextMax;
  2830. break;
  2831. case HDFT_ISNUMBER:
  2832. phd->intFilterOld = phdi->intFilter;
  2833. StringCchPrintf(szBuffer, ARRAYSIZE(szBuffer), TEXT("%d"), phdi->intFilter);
  2834. cchBuffer = 11; // 10 digits, plus sign
  2835. uFlags |= ES_NUMBER;
  2836. break;
  2837. default:
  2838. return FALSE;
  2839. }
  2840. cxEdit = (rcFilter.right-rcFilter.left)-(g_cxLabelMargin*6);
  2841. cyEdit = (rcFilter.bottom-rcFilter.top)-(g_cyEdge*2);
  2842. phd->hwndEdit = CreateWindow(TEXT("EDIT"),
  2843. !(phdi->type & HDFT_HASNOVALUE) ? pBuffer:TEXT(""),
  2844. uFlags,
  2845. rcFilter.left+(g_cxLabelMargin*3),
  2846. rcFilter.top+g_cyEdge,
  2847. cxEdit, cyEdit,
  2848. phd->ci.hwnd,
  2849. NULL, HINST_THISDLL, NULL);
  2850. if ( phd->hwndEdit )
  2851. {
  2852. INT iOldFocus = phd->iFocus;
  2853. //
  2854. // Setup the edit mode for this object?
  2855. //
  2856. phd->iEdit = i; // now editing this column
  2857. phd->iFocus = Header_OnGetItemOrder(phd, i);
  2858. Header_OnGetItemRect(phd, Header_ItemOrderToIndex(phd, iOldFocus), &rc); // nb: iOldFocus
  2859. Header_GetFilterRects(&rc, &rcHeader, &rcFilter, &rcButton);
  2860. RedrawWindow(phd->ci.hwnd, &rcFilter, NULL, RDW_INVALIDATE | RDW_ERASE);
  2861. //
  2862. // Now subclass the edit control so we can trap the keystrokes we are interested in
  2863. //
  2864. phd->pfnEditWndProc = SubclassWindow(phd->hwndEdit, Header_EditWndProc);
  2865. ASSERT(phd->pfnEditWndProc);
  2866. Edit_LimitText(phd->hwndEdit, cchBuffer);
  2867. Edit_SetSel(phd->hwndEdit, 0, -1);
  2868. FORWARD_WM_SETFONT(phd->hwndEdit, phd->hfont, FALSE, SendMessage);
  2869. SetFocus(phd->hwndEdit);
  2870. }
  2871. return(phd->hwndEdit != NULL);
  2872. }
  2873. //
  2874. // Stop editing the fitler, discarding the change if we need to, otherwise
  2875. // the item has the correct information stored within it.
  2876. //
  2877. VOID Header_StopFilterEdit(HD* phd, BOOL fDiscardChanges)
  2878. {
  2879. if ( phd->iEdit >= 0 )
  2880. {
  2881. HDI* phdi = Header_GetItemPtr(phd, phd->iEdit);
  2882. HD_ITEM hdi;
  2883. HD_TEXTFILTER textFilter;
  2884. int intFilter;
  2885. ASSERT(phdi);
  2886. if ( fDiscardChanges )
  2887. {
  2888. hdi.mask = HDI_FILTER;
  2889. hdi.type = phd->typeOld;
  2890. switch (phdi->type & HDFT_ISMASK)
  2891. {
  2892. case HDFT_ISSTRING:
  2893. textFilter.pszText = phd->pszFilterOld;
  2894. textFilter.cchTextMax = phdi->textFilter.cchTextMax;
  2895. hdi.pvFilter = &textFilter;
  2896. break;
  2897. case HDFT_ISNUMBER:
  2898. intFilter = phd->intFilterOld;
  2899. hdi.pvFilter = &intFilter;
  2900. break;
  2901. }
  2902. Header_OnSetItem(phd, phd->iEdit, &hdi);
  2903. }
  2904. else
  2905. {
  2906. Header_FilterChanged(phd, FALSE); // ensure we flush the changes
  2907. }
  2908. if ( phd->hwndEdit )
  2909. {
  2910. SubclassWindow(phd->hwndEdit, phd->pfnEditWndProc);
  2911. DestroyWindow(phd->hwndEdit);
  2912. phd->hwndEdit = NULL;
  2913. }
  2914. phd->iEdit = -1;
  2915. phd->pszFilterOld = NULL;
  2916. }
  2917. }
  2918. //
  2919. // Send a filter change to the parent, either now or wait until the timeout
  2920. // expires.
  2921. //
  2922. VOID Header_FilterChanged(HD* phd, BOOL fWait)
  2923. {
  2924. if ( phd->iEdit < 0 )
  2925. return;
  2926. if ( fWait )
  2927. {
  2928. // defering the notify, therefore lets set the timer (killing any
  2929. // previous ones) and marking that we are waiting on it.
  2930. KillTimer(phd->ci.hwnd, HD_EDITCHANGETIMER);
  2931. SetTimer(phd->ci.hwnd, HD_EDITCHANGETIMER, phd->iFilterChangeTimeout, NULL);
  2932. phd->fFilterChangePending = TRUE;
  2933. }
  2934. else
  2935. {
  2936. HDI* phdi = Header_GetItemPtrByOrder(phd, phd->iEdit);
  2937. ASSERT(phdi);
  2938. // if we have a change notify pending then lets send it to
  2939. // the parent window, otherwise we just swallow it.
  2940. if ( phd->fFilterChangePending )
  2941. {
  2942. TCHAR szBuffer[MAX_PATH];
  2943. HD_ITEM hdi;
  2944. HD_TEXTFILTER textFilter;
  2945. int intFilter;
  2946. KillTimer(phd->ci.hwnd, HD_EDITCHANGETIMER);
  2947. phd->fFilterChangePending = FALSE;
  2948. hdi.mask = HDI_FILTER;
  2949. hdi.type = phdi->type & ~HDFT_HASNOVALUE;
  2950. if ( !GetWindowText(phd->hwndEdit, szBuffer, ARRAYSIZE(szBuffer)) )
  2951. hdi.type |= HDFT_HASNOVALUE;
  2952. switch (phdi->type & HDFT_ISMASK)
  2953. {
  2954. case HDFT_ISSTRING:
  2955. textFilter.pszText = szBuffer;
  2956. textFilter.cchTextMax = phdi->textFilter.cchTextMax;
  2957. hdi.pvFilter = &textFilter;
  2958. break;
  2959. case HDFT_ISNUMBER:
  2960. intFilter = StrToInt(szBuffer);
  2961. hdi.pvFilter = &intFilter;
  2962. break;
  2963. }
  2964. Header_OnSetItem(phd, phd->iEdit, &hdi);
  2965. }
  2966. }
  2967. }
  2968. //
  2969. // Handle the user displaying the filter menu
  2970. //
  2971. VOID Header_OnFilterButton(HD* phd, INT i)
  2972. {
  2973. NMHDFILTERBTNCLICK fbc;
  2974. RECT rc, rcHeader, rcFilter;
  2975. // filter button being depressed so depress it, then tell the user
  2976. // that it went down so they can display the UI they want, before
  2977. // we pop the button. if the notify returns TRUE then send
  2978. // a change notify around.
  2979. Header_StopFilterEdit(phd, FALSE);
  2980. ASSERT(phd->iButtonDown == -1);
  2981. phd->iButtonDown = i;
  2982. Header_InvalidateItem(phd, i, RDW_INVALIDATE);
  2983. UpdateWindow(phd->ci.hwnd);
  2984. ZeroMemory(&fbc, SIZEOF(fbc));
  2985. fbc.iItem = i;
  2986. // fbc.rc = { 0, 0, 0, 0 };
  2987. Header_OnGetItemRect(phd, i, &rc);
  2988. Header_GetFilterRects(&rc, &rcHeader, &rcFilter, &fbc.rc);
  2989. if ( CCSendNotify(&phd->ci, HDN_FILTERBTNCLICK, &fbc.hdr) )
  2990. Header_Notify(phd, i, 0, HDN_FILTERCHANGE);
  2991. phd->iButtonDown = -1;
  2992. Header_InvalidateItem(phd, i, RDW_INVALIDATE);
  2993. UpdateWindow(phd->ci.hwnd);
  2994. }
  2995. //
  2996. // Handle clearing the filter for the given item
  2997. //
  2998. LRESULT Header_OnClearFilter(HD* phd, INT i)
  2999. {
  3000. HDI* phdi;
  3001. HD_ITEM hdi;
  3002. INT iChanged = 0;
  3003. Header_StopFilterEdit(phd, FALSE);
  3004. if ( i == -1 )
  3005. {
  3006. //
  3007. // clear all filters by setting setting the HDFT_HASNOVALUEFLAG on all items
  3008. // remember to release the filter data. For each item we also send an item
  3009. // changing indicating that the filter is changing and then a item changed
  3010. // to indicat that we really did fix the value.
  3011. //
  3012. for ( i = 0 ; i < DSA_GetItemCount(phd->hdsaHDI); i++ )
  3013. {
  3014. phdi = Header_GetItemPtrByOrder(phd, i);
  3015. ASSERT(phdi);
  3016. if ( !(phdi->type & HDFT_HASNOVALUE) )
  3017. {
  3018. hdi.mask = HDI_FILTER;
  3019. hdi.type = phdi->type|HDFT_HASNOVALUE;
  3020. hdi.pvFilter = NULL;
  3021. if ( Header_SendChange(phd, i, HDN_ITEMCHANGING, &hdi) )
  3022. {
  3023. if ( (phdi->type & HDFT_ISMASK) == HDFT_ISSTRING )
  3024. Str_Set(&phdi->textFilter.pszText, NULL);
  3025. phdi->type |= HDFT_HASNOVALUE; // item is now empty
  3026. Header_SendChange(phd, i, HDN_ITEMCHANGED, &hdi);
  3027. iChanged++;
  3028. }
  3029. }
  3030. }
  3031. if ( iChanged )
  3032. {
  3033. //
  3034. // item == -1 indicating that we are cleared all filters, then invalidate
  3035. // the window so that the filter values are no longer visible
  3036. //
  3037. Header_Notify(phd, -1, 0, HDN_FILTERCHANGE); // send out a notify of change
  3038. RedrawWindow(phd->ci.hwnd, NULL, NULL, RDW_INVALIDATE | RDW_ERASE);
  3039. }
  3040. }
  3041. else
  3042. {
  3043. if ( (i < 0) || (i > DSA_GetItemCount(phd->hdsaHDI)) )
  3044. return 0L;
  3045. phdi = Header_GetItemPtrByOrder(phd, i);
  3046. ASSERT(phdi);
  3047. if ( !(phdi->type & HDFT_HASNOVALUE) )
  3048. {
  3049. //
  3050. // clear a single filter by setting the HDFT_HASNOVALUE flag
  3051. //
  3052. hdi.mask = HDI_FILTER;
  3053. hdi.type = phdi->type|HDFT_HASNOVALUE;
  3054. hdi.pvFilter = NULL;
  3055. Header_OnSetItem(phd, i, &hdi);
  3056. }
  3057. }
  3058. return 1L;
  3059. }