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.

2012 lines
58 KiB

  1. #include "ctlspriv.h"
  2. #include "limits.h"
  3. #include "image.h" // for CreateColorBitmap
  4. //#define TB_DEBUG
  5. //#define FEATURE_DEBUG // Ctrl+Shift force-enables rare features for debugging
  6. typedef struct {
  7. // standard header information for each control
  8. CCONTROLINFO ci;
  9. HDC hdc; // current DC
  10. HBITMAP hbmBuffer; // double buffer
  11. LONG lLogMin; // Logical minimum
  12. LONG lLogMax; // Logical maximum
  13. LONG lLogPos; // Logical position
  14. LONG lSelStart; // Logical selection start
  15. LONG lSelEnd; // Logical selection end
  16. int iThumbWidth; // Width of the thumb
  17. int iThumbHeight; // Height of the thumb
  18. int iSizePhys; // Size of where thumb lives
  19. RECT rc; // track bar rect.
  20. RECT rcThumb; // Rectangle we current thumb
  21. DWORD dwDragPos; // Logical position of mouse while dragging.
  22. int dwDragOffset; // how many pixels off the center did they click
  23. int nTics; // number of ticks.
  24. PDWORD pTics; // the tick marks.
  25. int ticFreq; // the frequency of ticks
  26. LONG lPageSize; // how much to thumb up and down.
  27. LONG lLineSize; // how muhc to scroll up and down on line up/down
  28. HWND hwndToolTips;
  29. // these should probably be word or bytes
  30. UINT wDirtyFlags;
  31. UINT uTipSide; // which side should the tip be on?
  32. UINT Flags; // Flags for our window
  33. UINT Cmd; // The command we're repeating.
  34. HTHEME hTheme;
  35. BOOL bThumbHot;
  36. HIMC hPrevImc; // previous input context handle
  37. HWND hwndBuddyLeft;
  38. HWND hwndBuddyRight;
  39. } TRACKBAR, *PTRACKBAR;
  40. // Trackbar flags
  41. #define TBF_NOTHUMB 0x0001 // No thumb because not wide enough.
  42. #define TBF_SELECTION 0x0002 // a selection has been established (draw the range)
  43. #define MIN_THUMB_HEIGHT (2 * g_cxEdge)
  44. /*
  45. useful constants.
  46. */
  47. #define REPEATTIME 500 // mouse auto repeat 1/2 of a second
  48. #define TIMER_ID 1
  49. /*
  50. Function Prototypes
  51. */
  52. void DoTrack(PTRACKBAR, int, DWORD);
  53. WORD WTrackType(PTRACKBAR, LONG);
  54. void TBTrackInit(PTRACKBAR, LPARAM);
  55. void TBTrackEnd(PTRACKBAR);
  56. void TBTrack(PTRACKBAR, LPARAM);
  57. void DrawThumb(PTRACKBAR, LPRECT, BOOL);
  58. HBRUSH SelectColorObjects(PTRACKBAR, BOOL);
  59. void SetTBCaretPos(PTRACKBAR);
  60. #define TICKHEIGHT 3
  61. #define BORDERSIZE 2
  62. #define ISVERT(tb) (tb->ci.style & TBS_VERT)
  63. #define TBC_TICS 0x1
  64. #define TBC_THUMB 0x2
  65. #define TBC_ALL 0xF
  66. // this is called internally when the trackbar has
  67. // changed and we need to update the double buffer bitmap
  68. // we only set a flag. we do the actual draw
  69. // during WM_PAINT. This prevents wasted efforts drawing.
  70. #define TBChanged(ptb, wFlags) ((ptb)->wDirtyFlags |= (wFlags))
  71. //
  72. // Function Prototypes
  73. //
  74. LPARAM CALLBACK TrackBarWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  75. void FlushChanges(PTRACKBAR tb);
  76. //--------------------------------------------------------------------------;
  77. //
  78. // LONG MulDiv32(a,b,c) = (a * b + c/2) / c
  79. //
  80. //--------------------------------------------------------------------------;
  81. #define MulDiv32 MulDiv // use KERNEL32 version (it rounds)
  82. //--------------------------------------------------------------------------;
  83. //--------------------------------------------------------------------------;
  84. //
  85. // convert a logical scroll-bar position to a physical pixel position
  86. //
  87. int TBLogToPhys(PTRACKBAR tb, DWORD dwPos)
  88. {
  89. int x;
  90. x = tb->rc.left;
  91. if (tb->lLogMax == tb->lLogMin)
  92. return x;
  93. return (int)MulDiv32(dwPos - tb->lLogMin, tb->iSizePhys - 1,
  94. tb->lLogMax - tb->lLogMin) + x;
  95. }
  96. LONG TBPhysToLog(PTRACKBAR ptb, int iPos)
  97. {
  98. int min, max, x;
  99. min = ptb->rc.left;
  100. max = ptb->rc.right;
  101. x = ptb->rc.left;
  102. if (ptb->iSizePhys <= 1)
  103. return ptb->lLogMin;
  104. if (iPos <= min)
  105. return ptb->lLogMin;
  106. if (iPos >= max)
  107. return ptb->lLogMax;
  108. return MulDiv32(iPos - x, ptb->lLogMax - ptb->lLogMin,
  109. ptb->iSizePhys - 1) + ptb->lLogMin;
  110. }
  111. #pragma code_seg(CODESEG_INIT)
  112. /*
  113. * Initialize the trackbar code
  114. */
  115. BOOL InitTrackBar(HINSTANCE hInstance)
  116. {
  117. WNDCLASS wc;
  118. // See if we must register a window class
  119. wc.lpfnWndProc = TrackBarWndProc;
  120. wc.lpszClassName = s_szSTrackBarClass;
  121. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  122. wc.hIcon = NULL;
  123. wc.lpszMenuName = NULL;
  124. wc.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
  125. wc.hInstance = hInstance;
  126. wc.style = CS_GLOBALCLASS;
  127. wc.cbClsExtra = 0;
  128. wc.cbWndExtra = sizeof(PTRACKBAR);
  129. return (RegisterClass(&wc) || (GetLastError() == ERROR_CLASS_ALREADY_EXISTS));
  130. }
  131. #pragma code_seg()
  132. /*
  133. * To add vertical capabilities, I'm using a virtual coordinate
  134. * system. the ptb->rcThumb and ptb->rc are in the virtual space (which
  135. * is just a horizontal trackbar). Draw routines use PatRect
  136. * which switch to the real coordinate system as needed.
  137. *
  138. * The one gotcha is that the Thumb Bitmap has the pressed bitmap
  139. * to the real right, and the masks to the real right again for both
  140. * the vertical and horizontal Thumbs. So those cases are hardcoded.
  141. * Do a search for ISVERT to find these dependancies.
  142. * -Chee
  143. */
  144. /*
  145. FlipRect Function is moved to cutils.c as other controls were also using it.
  146. -Arul
  147. */
  148. void TBFlipPoint(PTRACKBAR ptb, LPPOINT lppt)
  149. {
  150. if (ISVERT(ptb)) {
  151. FlipPoint(lppt);
  152. }
  153. }
  154. /* added trackbar variable to do auto verticalization */
  155. void PatRect(HDC hdc,int x,int y,int dx,int dy, PTRACKBAR ptb)
  156. {
  157. RECT rc;
  158. rc.left = x;
  159. rc.top = y;
  160. rc.right = x + dx;
  161. rc.bottom = y + dy;
  162. if (ISVERT(ptb))
  163. FlipRect(&rc);
  164. ExtTextOut(hdc,0,0,ETO_OPAQUE,&rc,NULL,0,NULL);
  165. }
  166. #define TBInvalidateRect(hwnd, prc, bErase, ptb) VertInvalidateRect(hwnd, prc, bErase, ISVERT(ptb))
  167. void VertInvalidateRect(HWND hwnd, LPRECT qrc, BOOL b, BOOL fVert)
  168. {
  169. RECT rc;
  170. rc = *qrc;
  171. if (fVert) FlipRect(&rc);
  172. InvalidateRect(hwnd, &rc, b);
  173. }
  174. #define TBDrawEdge(hdc, prc, uType, grfFlags, ptb, hTheme, iPartId, iStateId) VertDrawEdge(hdc, prc, uType, grfFlags, ISVERT(ptb), hTheme, iPartId, iStateId)
  175. // VertDrawEdge is theme aware (RENDERS)
  176. void VertDrawEdge(HDC hdc, LPRECT qrc, UINT edgeType, UINT grfFlags,
  177. BOOL fVert, HTHEME hTheme, int iPartId, int iStateId)
  178. {
  179. RECT temprc;
  180. UINT uFlags = grfFlags;
  181. temprc = *qrc;
  182. if (fVert) {
  183. FlipRect(&temprc);
  184. if (!(uFlags & BF_DIAGONAL)) {
  185. if (grfFlags & BF_TOP) uFlags |= BF_LEFT;
  186. else uFlags &= ~BF_LEFT;
  187. if (grfFlags & BF_LEFT) uFlags |= BF_TOP;
  188. else uFlags &= ~BF_TOP;
  189. if (grfFlags & BF_BOTTOM) uFlags |= BF_RIGHT;
  190. else uFlags &= ~BF_RIGHT;
  191. if (grfFlags & BF_RIGHT) uFlags |= BF_BOTTOM;
  192. else uFlags &= ~BF_BOTTOM;
  193. } else {
  194. if ((grfFlags & (BF_BOTTOM | BF_RIGHT)) == (BF_BOTTOM | BF_RIGHT)) {
  195. uFlags = BF_TOP | BF_LEFT;
  196. if (edgeType == EDGE_RAISED) {
  197. edgeType = EDGE_SUNKEN;
  198. } else {
  199. edgeType = EDGE_RAISED;
  200. }
  201. uFlags |= grfFlags & (~BF_RECT);
  202. uFlags ^= BF_SOFT;
  203. }
  204. }
  205. }
  206. if (hTheme)
  207. {
  208. DrawThemeBackground(hTheme, hdc, iPartId, iStateId, &temprc, 0);
  209. }
  210. else
  211. {
  212. DrawEdge(hdc, &temprc, edgeType, uFlags);
  213. }
  214. }
  215. #define TBPatBlt(hdc1, x1, y1, w, h, rop, ptb) VertPatBlt(hdc1, x1, y1, w, h, rop, ISVERT(ptb), NULL, 0, 0)
  216. // VertPatBlt is theme aware (RENDERS)
  217. void VertPatBlt(HDC hdc1, int x1, int y1, int w, int h,
  218. DWORD rop, BOOL fVert, HTHEME hTheme, int iPartId, int iStateId)
  219. {
  220. if (hTheme)
  221. {
  222. RECT rc;
  223. if (fVert)
  224. SetRect(&rc, y1, x1, h, w);
  225. else
  226. SetRect(&rc, x1, y1, w, h);
  227. DrawThemeBackground(hTheme, hdc1, iPartId, iStateId, &rc, 0);
  228. }
  229. else
  230. {
  231. if (fVert)
  232. PatBlt(hdc1, y1, x1, h, w, rop);
  233. else
  234. PatBlt(hdc1, x1, y1, w, h, rop);
  235. }
  236. }
  237. // DrawTic is theme aware (RENDERS)
  238. void DrawTic(PTRACKBAR ptb, int x, int y, int dir)
  239. {
  240. if (dir == -1) y -= TICKHEIGHT;
  241. if (ptb->hTheme)
  242. {
  243. COLORREF cr = 0;
  244. GetThemeColor(ptb->hTheme, ISVERT(ptb) ? TKP_TICSVERT : TKP_TICS, TSS_NORMAL, TMT_COLOR, &cr);
  245. SetBkColor(ptb->hdc, cr);
  246. }
  247. else
  248. {
  249. SetBkColor(ptb->hdc, g_clrBtnText);
  250. }
  251. PatRect(ptb->hdc,x,y,1,TICKHEIGHT, ptb);
  252. }
  253. // dir = direction multiplier (drawing up or down)
  254. // yTic = where (vertically) to draw the line of tics
  255. void DrawTicsOneLine(PTRACKBAR ptb, int dir, int yTic)
  256. {
  257. PDWORD pTics;
  258. int iPos;
  259. int i;
  260. DrawTic(ptb, ptb->rc.left, yTic, dir); // first
  261. DrawTic(ptb, ptb->rc.left, yTic+ (dir * 1), dir);
  262. DrawTic(ptb, ptb->rc.right-1, yTic, dir); // last
  263. DrawTic(ptb, ptb->rc.right-1, yTic+ (dir * 1), dir);
  264. // those inbetween
  265. pTics = ptb->pTics;
  266. if (ptb->ticFreq && pTics) {
  267. for (i = 0; i < ptb->nTics; ++i) {
  268. if (((i+1) % ptb->ticFreq) == 0) {
  269. iPos = TBLogToPhys(ptb,pTics[i]);
  270. DrawTic(ptb, iPos, yTic, dir);
  271. }
  272. }
  273. }
  274. // draw the selection range (triangles)
  275. if ((ptb->Flags & TBF_SELECTION) &&
  276. (ptb->lSelStart <= ptb->lSelEnd) && (ptb->lSelEnd >= ptb->lLogMin)) {
  277. SetBkColor(ptb->hdc, g_clrBtnText);
  278. iPos = TBLogToPhys(ptb,ptb->lSelStart);
  279. for (i = 0; i < TICKHEIGHT; i++)
  280. PatRect(ptb->hdc,iPos-i,yTic+(dir==1 ? i : -TICKHEIGHT),
  281. 1,TICKHEIGHT-i, ptb);
  282. iPos = TBLogToPhys(ptb,ptb->lSelEnd);
  283. for (i = 0; i < TICKHEIGHT; i++)
  284. PatRect(ptb->hdc,iPos+i,yTic+(dir==1 ? i : -TICKHEIGHT),
  285. 1,TICKHEIGHT-i, ptb);
  286. }
  287. }
  288. /* DrawTics() */
  289. /* There is always a tick at the beginning and end of the bar, but you can */
  290. /* add some more of your own with a TBM_SETTIC message. This draws them. */
  291. /* They are kept in an array whose handle is a window word. The first */
  292. /* element is the number of extra ticks, and then the positions. */
  293. void DrawTics(PTRACKBAR ptb)
  294. {
  295. // do they even want this?
  296. if (ptb->ci.style & TBS_NOTICKS) return;
  297. if ((ptb->ci.style & TBS_BOTH) || !(ptb->ci.style & TBS_TOP)) {
  298. DrawTicsOneLine(ptb, 1, ptb->rc.bottom + 1);
  299. }
  300. if ((ptb->ci.style & (TBS_BOTH | TBS_TOP))) {
  301. DrawTicsOneLine(ptb, -1, ptb->rc.top - 1);
  302. }
  303. }
  304. void GetChannelRect(PTRACKBAR ptb, LPRECT lprc)
  305. {
  306. int iwidth, iheight;
  307. if (!lprc)
  308. return;
  309. lprc->left = ptb->rc.left - ptb->iThumbWidth / 2;
  310. iwidth = ptb->iSizePhys + ptb->iThumbWidth - 1;
  311. lprc->right = lprc->left + iwidth;
  312. if (ptb->ci.style & TBS_ENABLESELRANGE) {
  313. iheight = ptb->iThumbHeight / 4 * 3; // this is Scrollheight
  314. } else {
  315. iheight = 4;
  316. }
  317. lprc->top = (ptb->rc.top + ptb->rc.bottom - iheight) /2;
  318. if (!(ptb->ci.style & TBS_BOTH))
  319. if (ptb->ci.style & TBS_TOP) lprc->top++;
  320. else lprc->top--;
  321. lprc->bottom = lprc->top + iheight;
  322. }
  323. /* This draws the track bar itself */
  324. // DrawChannel is theme aware (RENDERS)
  325. void DrawChannel(PTRACKBAR ptb, LPRECT lprc)
  326. {
  327. TBDrawEdge(ptb->hdc, lprc, EDGE_SUNKEN, BF_RECT,ptb, ptb->hTheme, ISVERT(ptb) ? TKP_TRACKVERT : TKP_TRACK, TRS_NORMAL);
  328. if (!ptb->hTheme)
  329. {
  330. SetBkColor(ptb->hdc, g_clrBtnHighlight);
  331. // Fill the center
  332. PatRect(ptb->hdc, lprc->left+2, lprc->top+2, (lprc->right-lprc->left)-4,
  333. (lprc->bottom-lprc->top)-4, ptb);
  334. // now highlight the selection range
  335. if ((ptb->Flags & TBF_SELECTION) &&
  336. (ptb->lSelStart <= ptb->lSelEnd) && (ptb->lSelEnd > ptb->lLogMin)) {
  337. int iStart, iEnd;
  338. iStart = TBLogToPhys(ptb,ptb->lSelStart);
  339. iEnd = TBLogToPhys(ptb,ptb->lSelEnd);
  340. if (iStart + 2 <= iEnd) {
  341. SetBkColor(ptb->hdc, g_clrHighlight);
  342. PatRect(ptb->hdc, iStart+1, lprc->top+3,
  343. iEnd-iStart-1, (lprc->bottom-lprc->top)-6, ptb);
  344. }
  345. }
  346. }
  347. }
  348. // DrawThumb is theme aware (RENDERS)
  349. void DrawThumb(PTRACKBAR ptb, LPRECT lprc, BOOL fSelected)
  350. {
  351. // iDpt direction from middle to point of thumb
  352. // a negative value inverts things.
  353. // this allows one code path..
  354. int iDpt = 0;
  355. int i = 0; // size of point triangle
  356. int iYpt = 0; // vertical location of tip;
  357. int iXmiddle = 0;
  358. int icount; // just a loop counter
  359. UINT uEdgeFlags = 0;
  360. RECT rcThumb = *lprc;
  361. if (ptb->Flags & TBF_NOTHUMB ||
  362. ptb->ci.style & TBS_NOTHUMB) // If no thumb, just leave.
  363. return;
  364. ASSERT(ptb->iThumbHeight >= MIN_THUMB_HEIGHT);
  365. ASSERT(ptb->iThumbWidth > 1);
  366. if (!ptb->hTheme)
  367. {
  368. // draw the rectangle part
  369. if (!(ptb->ci.style & TBS_BOTH)) {
  370. int iMiddle;
  371. // do -3 because wThumb is odd (triangles ya know)
  372. // and because draw rects draw inside the rects passed.
  373. // actually should be (width-1)/2-1, but this is the same...
  374. i = (ptb->iThumbWidth - 3) / 2;
  375. iMiddle = ptb->iThumbHeight / 2 + rcThumb.top;
  376. //draw the rectangle part
  377. if (ptb->ci.style & TBS_TOP) {
  378. iMiddle++; //correction because drawing routines
  379. iDpt = -1;
  380. rcThumb.top += (i+1);
  381. uEdgeFlags = BF_SOFT | BF_LEFT | BF_RIGHT | BF_BOTTOM;
  382. } else {
  383. iDpt = 1;
  384. rcThumb.bottom -= (i+1);
  385. // draw on the inside, not on the bottom and rt edge
  386. uEdgeFlags = BF_SOFT | BF_LEFT | BF_RIGHT | BF_TOP;
  387. }
  388. iYpt = iMiddle + (iDpt * (ptb->iThumbHeight / 2));
  389. iXmiddle = rcThumb.left + i;
  390. } else {
  391. uEdgeFlags = BF_SOFT | BF_RECT;
  392. }
  393. // fill in the center
  394. if (fSelected || !IsWindowEnabled(ptb->ci.hwnd)) {
  395. HBRUSH hbrTemp;
  396. // draw the dithered insides;
  397. hbrTemp = SelectObject(ptb->hdc, g_hbrMonoDither);
  398. if (hbrTemp) {
  399. SetTextColor(ptb->hdc, g_clrBtnHighlight);
  400. SetBkColor(ptb->hdc, g_clrBtnFace);
  401. TBPatBlt(ptb->hdc, rcThumb.left +2 , rcThumb.top,
  402. rcThumb.right-rcThumb.left -4, rcThumb.bottom-rcThumb.top,
  403. PATCOPY,ptb);
  404. if (!(ptb->ci.style & TBS_BOTH)) {
  405. for (icount = 1; icount <= i; icount++) {
  406. TBPatBlt(ptb->hdc, iXmiddle-icount+1,
  407. iYpt - (iDpt*icount),
  408. icount*2, 1, PATCOPY, ptb);
  409. }
  410. }
  411. SelectObject(ptb->hdc, hbrTemp);
  412. }
  413. } else {
  414. SetBkColor(ptb->hdc, g_clrBtnFace);
  415. PatRect(ptb->hdc, rcThumb.left+2, rcThumb.top,
  416. rcThumb.right-rcThumb.left-4, rcThumb.bottom-rcThumb.top, ptb);
  417. if (!(ptb->ci.style & TBS_BOTH)) {
  418. for (icount = 1; icount <= i; icount++) {
  419. PatRect(ptb->hdc, iXmiddle-icount+1,
  420. iYpt - (iDpt*icount),
  421. icount*2, 1, ptb);
  422. }
  423. }
  424. }
  425. }
  426. if (ptb->hTheme)
  427. {
  428. int iPartId;
  429. // States in overriding order
  430. int iStateId = TUS_NORMAL;
  431. if (ISVERT(ptb))
  432. {
  433. if (ptb->ci.style & TBS_BOTH)
  434. {
  435. iPartId = TKP_THUMBVERT;
  436. }
  437. else if (ptb->ci.style & TBS_LEFT)
  438. {
  439. iPartId = TKP_THUMBLEFT;
  440. }
  441. else
  442. {
  443. iPartId = TKP_THUMBRIGHT;
  444. }
  445. }
  446. else
  447. {
  448. if (ptb->ci.style & TBS_BOTH)
  449. {
  450. iPartId = TKP_THUMB;
  451. }
  452. else if (ptb->ci.style & TBS_TOP)
  453. {
  454. iPartId = TKP_THUMBTOP;
  455. }
  456. else
  457. {
  458. iPartId = TKP_THUMBBOTTOM;
  459. }
  460. }
  461. #ifdef DEBUG
  462. if (!IsThemePartDefined(ptb->hTheme, iPartId, 0))
  463. DebugMsg(DM_WARNING, TEXT("WARNING: Trackbar_Drawthumb: Theme Part not defined: %d\n"), iPartId);
  464. #endif
  465. if (ptb->ci.hwnd == GetFocus() && !(CCGetUIState(&(ptb->ci)) & UISF_HIDEFOCUS))
  466. iStateId = TUS_FOCUSED;
  467. if (ptb->bThumbHot)
  468. iStateId = TUS_HOT;
  469. if (fSelected)
  470. iStateId = TUS_PRESSED;
  471. if (ptb->ci.style & WS_DISABLED)
  472. iStateId = TUS_DISABLED;
  473. // Thumb and ThumbVert parts share the same enum values
  474. TBDrawEdge(ptb->hdc, &rcThumb, EDGE_RAISED, uEdgeFlags, ptb, ptb->hTheme, iPartId, iStateId);
  475. }
  476. else
  477. {
  478. TBDrawEdge(ptb->hdc, &rcThumb, EDGE_RAISED, uEdgeFlags, ptb, NULL, 0, 0);
  479. }
  480. if (!ptb->hTheme)
  481. {
  482. //now draw the point
  483. if (!(ptb->ci.style & TBS_BOTH)) {
  484. UINT uEdgeFlags2;
  485. // uEdgeFlags is now used to switch between top and bottom.
  486. // we'll or it in with the diagonal and left/right flags below
  487. if (ptb->ci.style & TBS_TOP) {
  488. rcThumb.bottom = rcThumb.top + 1;
  489. rcThumb.top = rcThumb.bottom - (i + 2);
  490. uEdgeFlags = BF_TOP | BF_RIGHT | BF_DIAGONAL | BF_SOFT;
  491. uEdgeFlags2 = BF_BOTTOM | BF_RIGHT | BF_DIAGONAL;
  492. } else {
  493. rcThumb.top = rcThumb.bottom - 1;
  494. rcThumb.bottom = rcThumb.top + (i + 2);
  495. uEdgeFlags = BF_TOP | BF_LEFT | BF_DIAGONAL | BF_SOFT;
  496. uEdgeFlags2 = BF_BOTTOM | BF_LEFT | BF_DIAGONAL;
  497. }
  498. rcThumb.right = rcThumb.left + (i + 2);
  499. // do the left side first
  500. TBDrawEdge(ptb->hdc, &rcThumb, EDGE_RAISED, uEdgeFlags , ptb, NULL, 0, 0);
  501. // then do th right side
  502. OffsetRect(&rcThumb, i + 1, 0);
  503. TBDrawEdge(ptb->hdc, &rcThumb, EDGE_RAISED, uEdgeFlags2 , ptb, NULL, 0, 0);
  504. }
  505. }
  506. }
  507. void TBInvalidateAll(PTRACKBAR ptb)
  508. {
  509. if (ptb) {
  510. TBChanged(ptb, TBC_ALL);
  511. InvalidateRect(ptb->ci.hwnd, NULL, FALSE);
  512. }
  513. }
  514. void MoveThumb(PTRACKBAR ptb, LONG lPos)
  515. {
  516. long lOld = ptb->lLogPos;
  517. TBInvalidateRect(ptb->ci.hwnd, &ptb->rcThumb, FALSE,ptb);
  518. ptb->lLogPos = BOUND(lPos,ptb->lLogMin,ptb->lLogMax);
  519. ptb->rcThumb.left = TBLogToPhys(ptb, ptb->lLogPos) - ptb->iThumbWidth / 2;
  520. ptb->rcThumb.right = ptb->rcThumb.left + ptb->iThumbWidth;
  521. TBInvalidateRect(ptb->ci.hwnd, &ptb->rcThumb, FALSE,ptb);
  522. TBChanged(ptb, TBC_THUMB);
  523. UpdateWindow(ptb->ci.hwnd);
  524. if (lOld != ptb->lLogPos)
  525. NotifyWinEvent(EVENT_OBJECT_VALUECHANGE, ptb->ci.hwnd, OBJID_CLIENT, 0);
  526. }
  527. void DrawFocus(PTRACKBAR ptb, HBRUSH hbrBackground)
  528. {
  529. RECT rc;
  530. if (ptb->ci.hwnd == GetFocus() &&
  531. !(CCGetUIState(&(ptb->ci)) & UISF_HIDEFOCUS))
  532. {
  533. SetBkColor(ptb->hdc, g_clrBtnHighlight);
  534. GetClientRect(ptb->ci.hwnd, &rc);
  535. // Successive calls to DrawFocusRect will invert it thereby erasing it.
  536. // To avoid this, whenever we process WM_PAINT, we erase the focus rect ourselves
  537. // before we draw it below.
  538. if (hbrBackground)
  539. FrameRect(ptb->hdc, &rc, hbrBackground);
  540. DrawFocusRect(ptb->hdc, &rc);
  541. }
  542. }
  543. void DoAutoTics(PTRACKBAR ptb)
  544. {
  545. LONG *pl;
  546. LONG l;
  547. if (!(ptb->ci.style & TBS_AUTOTICKS))
  548. return;
  549. if (ptb->pTics)
  550. LocalFree((HLOCAL)ptb->pTics);
  551. ptb->nTics = (int)(ptb->lLogMax - ptb->lLogMin - 1);
  552. if (ptb->nTics > 0)
  553. ptb->pTics = (DWORD *)LocalAlloc(LPTR, sizeof(DWORD) * ptb->nTics);
  554. else
  555. ptb->pTics = NULL;
  556. if (!ptb->pTics) {
  557. ptb->nTics = 0;
  558. return;
  559. }
  560. for (pl = (LONG *)ptb->pTics, l = ptb->lLogMin + 1; l < ptb->lLogMax; l++)
  561. *pl++ = l;
  562. }
  563. void ValidateThumbHeight(PTRACKBAR ptb)
  564. {
  565. if (ptb->iThumbHeight < MIN_THUMB_HEIGHT)
  566. ptb->iThumbHeight = MIN_THUMB_HEIGHT;
  567. ptb->iThumbWidth = ptb->iThumbHeight / 2;
  568. ptb->iThumbWidth |= 0x01; // make sure it's odd at at least 3
  569. if (ptb->ci.style & TBS_ENABLESELRANGE) {
  570. if (ptb->ci.style & TBS_FIXEDLENGTH) {
  571. // half of 9/10
  572. ptb->iThumbWidth = (ptb->iThumbHeight * 9) / 20;
  573. ptb->iThumbWidth |= 0x01;
  574. } else {
  575. ptb->iThumbHeight += (ptb->iThumbWidth * 2) / 9;
  576. }
  577. }
  578. }
  579. void TBPositionBuddies(PTRACKBAR ptb)
  580. {
  581. POINT pt;
  582. HWND hwndParent;
  583. RECT rcBuddy;
  584. RECT rcClient;
  585. RECT rcChannel;
  586. int yMid;
  587. GetChannelRect(ptb, &rcChannel);
  588. yMid = (rcChannel.top + rcChannel.bottom) / 2;
  589. GetClientRect(ptb->ci.hwnd, &rcClient);
  590. if (ISVERT(ptb))
  591. FlipRect(&rcClient);
  592. if (ptb->hwndBuddyLeft) {
  593. GetClientRect(ptb->hwndBuddyLeft, &rcBuddy);
  594. if (ISVERT(ptb))
  595. FlipRect(&rcBuddy);
  596. pt.y = yMid - ((RECTHEIGHT(rcBuddy))/2);
  597. pt.x = rcClient.left - RECTWIDTH(rcBuddy) - g_cxEdge;
  598. // x and y are now in trackbar's coordinates.
  599. // convert them to the parent of the buddy's coordinates
  600. hwndParent = GetParent(ptb->hwndBuddyLeft);
  601. TBFlipPoint(ptb, &pt);
  602. MapWindowPoints(ptb->ci.hwnd, hwndParent, &pt, 1);
  603. SetWindowPos(ptb->hwndBuddyLeft, NULL, pt.x, pt.y, 0, 0, SWP_NOSIZE |SWP_NOZORDER | SWP_NOACTIVATE);
  604. }
  605. if (ptb->hwndBuddyRight) {
  606. GetClientRect(ptb->hwndBuddyRight, &rcBuddy);
  607. if (ISVERT(ptb))
  608. FlipRect(&rcBuddy);
  609. pt.y = yMid - ((RECTHEIGHT(rcBuddy))/2);
  610. pt.x = rcClient.right + g_cxEdge;
  611. // x and y are now in trackbar's coordinates.
  612. // convert them to the parent of the buddy's coordinates
  613. hwndParent = GetParent(ptb->hwndBuddyRight);
  614. TBFlipPoint(ptb, &pt);
  615. MapWindowPoints(ptb->ci.hwnd, hwndParent, &pt, 1);
  616. SetWindowPos(ptb->hwndBuddyRight, NULL, pt.x, pt.y, 0, 0, SWP_NOSIZE |SWP_NOZORDER | SWP_NOACTIVATE);
  617. }
  618. }
  619. void TBNukeBuffer(PTRACKBAR ptb)
  620. {
  621. if (ptb->hbmBuffer) {
  622. DeleteObject(ptb->hbmBuffer);
  623. ptb->hbmBuffer = NULL;
  624. TBChanged(ptb, TBC_ALL); // Must do a full repaint
  625. }
  626. }
  627. void TBResize(PTRACKBAR ptb)
  628. {
  629. GetClientRect(ptb->ci.hwnd, &ptb->rc);
  630. if (ISVERT(ptb))
  631. FlipRect(&ptb->rc);
  632. if (!(ptb->ci.style & TBS_FIXEDLENGTH)) {
  633. ptb->iThumbHeight = (g_cyHScroll * 4) / 3;
  634. ValidateThumbHeight(ptb);
  635. if ((ptb->iThumbHeight > MIN_THUMB_HEIGHT) && (ptb->rc.bottom < (int)ptb->iThumbHeight)) {
  636. ptb->iThumbHeight = ptb->rc.bottom - 3*g_cyEdge; // top, bottom, and tic
  637. if (ptb->ci.style & TBS_ENABLESELRANGE)
  638. ptb->iThumbHeight = (ptb->iThumbHeight * 3 / 4);
  639. ValidateThumbHeight(ptb);
  640. }
  641. } else {
  642. ValidateThumbHeight(ptb);
  643. }
  644. if (ptb->ci.style & (TBS_BOTH | TBS_TOP) && !(ptb->ci.style & TBS_NOTICKS))
  645. ptb->rc.top += TICKHEIGHT + BORDERSIZE + 3;
  646. ptb->rc.top += BORDERSIZE;
  647. ptb->rc.bottom = ptb->rc.top + ptb->iThumbHeight;
  648. ptb->rc.left += (ptb->iThumbWidth + BORDERSIZE);
  649. ptb->rc.right -= (ptb->iThumbWidth + BORDERSIZE);
  650. ptb->rcThumb.top = ptb->rc.top;
  651. ptb->rcThumb.bottom = ptb->rc.bottom;
  652. // Figure out how much room we have to move the thumb in
  653. ptb->iSizePhys = ptb->rc.right - ptb->rc.left;
  654. // Elevator isn't there if there's no room.
  655. if (ptb->iSizePhys == 0) {
  656. // Lost our thumb.
  657. ptb->Flags |= TBF_NOTHUMB;
  658. ptb->iSizePhys = 1;
  659. } else {
  660. // Ah. We have a thumb.
  661. ptb->Flags &= ~TBF_NOTHUMB;
  662. }
  663. TBNukeBuffer(ptb);
  664. MoveThumb(ptb, ptb->lLogPos);
  665. TBInvalidateAll(ptb);
  666. TBPositionBuddies(ptb);
  667. }
  668. LRESULT TrackOnCreate(HWND hwnd, LPCREATESTRUCT lpCreate)
  669. {
  670. PTRACKBAR ptb;
  671. DWORD exStyle = 0;
  672. InitDitherBrush();
  673. InitGlobalColors();
  674. // Get us our window structure.
  675. ptb = (PTRACKBAR)LocalAlloc(LPTR, sizeof(TRACKBAR));
  676. if (!ptb)
  677. return -1;
  678. SetWindowPtr(hwnd, 0, ptb);
  679. CIInitialize(&ptb->ci, hwnd, lpCreate);
  680. ptb->Cmd = (UINT)-1;
  681. ptb->lLogMax = 100;
  682. ptb->ticFreq = 1;
  683. // ptb->hbmBuffer = 0;
  684. ptb->lPageSize = -1;
  685. ptb->lLineSize = 1;
  686. // initial size;
  687. ptb->iThumbHeight = (g_cyHScroll * 4) / 3;
  688. if (g_fDBCSInputEnabled)
  689. ptb->hPrevImc = ImmAssociateContext(hwnd, 0L);
  690. if (ISVERT(ptb))
  691. {
  692. if (ptb->ci.style & TBS_TOP)
  693. {
  694. ptb->uTipSide = TBTS_RIGHT;
  695. }
  696. else
  697. {
  698. ptb->uTipSide = TBTS_LEFT;
  699. }
  700. }
  701. else
  702. {
  703. if (ptb->ci.style & TBS_TOP)
  704. {
  705. ptb->uTipSide = TBTS_BOTTOM;
  706. }
  707. else
  708. {
  709. ptb->uTipSide = TBTS_TOP;
  710. }
  711. }
  712. if (ptb->ci.style & TBS_TOOLTIPS)
  713. {
  714. ptb->hwndToolTips = CreateWindowEx(exStyle,
  715. c_szSToolTipsClass, TEXT(""),
  716. WS_POPUP,
  717. CW_USEDEFAULT, CW_USEDEFAULT,
  718. CW_USEDEFAULT, CW_USEDEFAULT,
  719. ptb->ci.hwnd, NULL, HINST_THISDLL,
  720. NULL);
  721. if (ptb->hwndToolTips)
  722. {
  723. TOOLINFO ti;
  724. // don't bother setting the rect because we'll do it below
  725. // in FlushToolTipsMgr;
  726. ti.cbSize = sizeof(ti);
  727. ti.uFlags = TTF_TRACK | TTF_IDISHWND | TTF_CENTERTIP;
  728. ti.hwnd = ptb->ci.hwnd;
  729. ti.uId = (UINT_PTR)ptb->ci.hwnd;
  730. ti.lpszText = LPSTR_TEXTCALLBACK;
  731. ti.rect.left = ti.rect.top = ti.rect.bottom = ti.rect.right = 0; // update this on size
  732. SendMessage(ptb->hwndToolTips, TTM_ADDTOOL, 0,
  733. (LPARAM)(LPTOOLINFO)&ti);
  734. }
  735. else
  736. ptb->ci.style &= ~(TBS_TOOLTIPS);
  737. }
  738. // Initialize themes. No themese for owner drawn tab controls
  739. ptb->hTheme = OpenThemeData(ptb->ci.hwnd, L"TrackBar");
  740. ptb->bThumbHot = FALSE;
  741. TBResize(ptb);
  742. return 0;
  743. }
  744. void TrackOnNotify(PTRACKBAR ptb, LPNMHDR lpnm)
  745. {
  746. if (lpnm->hwndFrom == ptb->hwndToolTips)
  747. {
  748. switch (lpnm->code)
  749. {
  750. case TTN_NEEDTEXT:
  751. #define lpttt ((LPTOOLTIPTEXT)lpnm)
  752. StringCchPrintf(lpttt->szText, ARRAYSIZE(lpttt->szText), TEXT("%d"), ptb->lLogPos);
  753. default:
  754. SendNotifyEx(ptb->ci.hwndParent, (HWND)-1,
  755. lpnm->code, lpnm, ptb->ci.bUnicode);
  756. break;
  757. }
  758. }
  759. }
  760. HWND TBSetBuddy(PTRACKBAR ptb, BOOL fLeft, HWND hwndBuddy)
  761. {
  762. HWND hwndOldBuddy;
  763. if (fLeft)
  764. {
  765. hwndOldBuddy = ptb->hwndBuddyLeft;
  766. ptb->hwndBuddyLeft = hwndBuddy;
  767. }
  768. else
  769. {
  770. hwndOldBuddy = ptb->hwndBuddyRight;
  771. ptb->hwndBuddyRight = hwndBuddy;
  772. }
  773. TBResize(ptb);
  774. return hwndOldBuddy;
  775. }
  776. // Theme helper
  777. void TBRedrawThumb(PTRACKBAR ptb)
  778. {
  779. // Update display
  780. TBInvalidateRect(ptb->ci.hwnd, &ptb->rcThumb, FALSE, ptb);
  781. TBChanged(ptb, TBC_THUMB);
  782. UpdateWindow(ptb->ci.hwnd);
  783. }
  784. // TrackBarWndProc is theme aware
  785. LPARAM CALLBACK TrackBarWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  786. {
  787. PTRACKBAR ptb;
  788. PAINTSTRUCT ps;
  789. HLOCAL h;
  790. ptb = GetWindowPtr(hwnd, 0);
  791. if (!ptb) {
  792. if (uMsg == WM_CREATE)
  793. return TrackOnCreate(hwnd, (LPCREATESTRUCT)lParam);
  794. goto DoDefault;
  795. }
  796. // Track hot state for themes
  797. if ((uMsg >= WM_MOUSEFIRST) && (uMsg <= WM_MOUSELAST))
  798. {
  799. TRACKMOUSEEVENT tme;
  800. tme.cbSize = sizeof(tme);
  801. tme.hwndTrack = hwnd;
  802. tme.dwFlags = TME_LEAVE;
  803. TrackMouseEvent(&tme);
  804. }
  805. switch (uMsg) {
  806. case WM_MOUSELEAVE:
  807. if (ptb->hTheme)
  808. {
  809. // Make sure thumb hot is turned off
  810. if (ptb->bThumbHot)
  811. {
  812. ptb->bThumbHot = FALSE;
  813. TBRedrawThumb(ptb);
  814. }
  815. }
  816. break;
  817. // If color depth changes, the old buffer is no longer any good
  818. case WM_DISPLAYCHANGE:
  819. TBNukeBuffer(ptb);
  820. break;
  821. case WM_WININICHANGE:
  822. InitGlobalMetrics(wParam);
  823. // fall through to WM_SIZE
  824. case WM_SIZE:
  825. TBResize(ptb);
  826. break;
  827. case WM_SYSCOLORCHANGE:
  828. InitGlobalColors();
  829. TBInvalidateAll(ptb);
  830. break;
  831. case WM_NOTIFYFORMAT:
  832. return CIHandleNotifyFormat(&ptb->ci,lParam);
  833. case WM_NOTIFY:
  834. TrackOnNotify(ptb, (LPNMHDR)lParam);
  835. break;
  836. case WM_DESTROY:
  837. TerminateDitherBrush();
  838. if (ptb)
  839. {
  840. if (g_fDBCSInputEnabled)
  841. ImmAssociateContext(hwnd, ptb->hPrevImc);
  842. if ((ptb->ci.style & TBS_TOOLTIPS) && IsWindow(ptb->hwndToolTips))
  843. {
  844. DestroyWindow (ptb->hwndToolTips);
  845. }
  846. TBNukeBuffer(ptb);
  847. if (ptb->pTics)
  848. LocalFree((HLOCAL)ptb->pTics);
  849. // Close theme
  850. if (ptb->hTheme)
  851. CloseThemeData(ptb->hTheme);
  852. LocalFree((HLOCAL)ptb);
  853. SetWindowPtr(hwnd, 0, 0);
  854. }
  855. break;
  856. case WM_KILLFOCUS:
  857. // Reset wheel scroll amount
  858. gcWheelDelta = 0;
  859. // fall-through
  860. case WM_SETFOCUS:
  861. ASSERT(gcWheelDelta == 0);
  862. if (ptb)
  863. TBInvalidateAll(ptb);
  864. break;
  865. case WM_ENABLE:
  866. if (wParam) {
  867. ptb->ci.style &= ~WS_DISABLED;
  868. } else {
  869. ptb->ci.style |= WS_DISABLED;
  870. }
  871. // Redraw all if themes are enabled since more is configurable
  872. TBChanged(ptb, (ptb->hTheme) ? TBC_ALL : TBC_THUMB);
  873. InvalidateRect(hwnd, NULL, FALSE);
  874. break;
  875. case WM_PRINTCLIENT:
  876. case WM_PAINT: {
  877. RECT rc;
  878. HBITMAP hbmOld;
  879. HDC hdc;
  880. hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
  881. //DebugMsg(DM_TRACE, "NumTics = %d", SendMessage(ptb->ci.hwnd, TBM_GETNUMTICS, 0, 0));
  882. //ptb->hdc = GetDC(NULL);
  883. ptb->hdc = CreateCompatibleDC(hdc);
  884. if (!ptb->hbmBuffer) {
  885. GetClientRect(hwnd, &rc);
  886. ptb->hbmBuffer = CreateColorBitmap(rc.right, rc.bottom);
  887. }
  888. hbmOld = SelectObject(ptb->hdc, ptb->hbmBuffer);
  889. FlushChanges(ptb);
  890. //only copy the area that's changable.. ie the clip box
  891. switch(GetClipBox(hdc, &rc)) {
  892. case NULLREGION:
  893. case ERROR:
  894. GetClientRect(ptb->ci.hwnd, &rc);
  895. }
  896. BitBlt(hdc, rc.left, rc.top,
  897. rc.right - rc.left, rc.bottom - rc.top,
  898. ptb->hdc, rc.left, rc.top, SRCCOPY);
  899. #ifdef TB_DEBUG
  900. {
  901. HDC hdcScreen;
  902. RECT rcClient;
  903. hdcScreen = GetDC(NULL);
  904. GetClientRect(ptb->ci.hwnd, &rcClient);
  905. BitBlt(hdcScreen, 0, 0, rcClient.right, rcClient.bottom, ptb->hdc, 0,0, SRCCOPY);
  906. ReleaseDC(NULL, hdcScreen);
  907. }
  908. #endif
  909. SelectObject(ptb->hdc, hbmOld);
  910. DeleteDC(ptb->hdc);
  911. //ReleaseDC(NULL, ptb->hdc);
  912. if (wParam == 0)
  913. EndPaint(hwnd, &ps);
  914. ptb->hdc = NULL;
  915. break;
  916. }
  917. case WM_GETDLGCODE:
  918. return DLGC_WANTARROWS;
  919. case WM_LBUTTONDOWN:
  920. /* Give ourselves focus */
  921. if (!(ptb->ci.style & WS_DISABLED)) {
  922. SetFocus(hwnd); // REVIEW: we may not want to do this
  923. TBTrackInit(ptb, lParam);
  924. }
  925. break;
  926. case WM_LBUTTONUP:
  927. // We're through doing whatever we were doing with the
  928. // button down.
  929. if (!(ptb->ci.style & WS_DISABLED)) {
  930. TBTrackEnd(ptb);
  931. if (GetCapture() == hwnd)
  932. CCReleaseCapture(&ptb->ci);
  933. }
  934. break;
  935. case WM_TIMER:
  936. // The only way we get a timer message is if we're
  937. // autotracking.
  938. lParam = GetMessagePosClient(ptb->ci.hwnd, NULL);
  939. // fall through to WM_MOUSEMOVE
  940. case WM_MOUSEMOVE:
  941. // We only care that the mouse is moving if we're
  942. // tracking the bloody thing.
  943. if (!(ptb->ci.style & WS_DISABLED))
  944. {
  945. if ((ptb->Cmd != (UINT)-1))
  946. TBTrack(ptb, lParam);
  947. else
  948. {
  949. // No user actions, track hot state if theme
  950. if (ptb->hTheme)
  951. {
  952. // Check if mouse is currently over thumb
  953. if (WTrackType(ptb, (LONG)lParam) == TB_THUMBTRACK)
  954. {
  955. if (!ptb->bThumbHot)
  956. {
  957. // Hot bit not set, set now and invalidate
  958. ptb->bThumbHot = TRUE;
  959. // Update display
  960. TBRedrawThumb(ptb);
  961. }
  962. }
  963. else
  964. {
  965. // Mouse not over thumb
  966. if (ptb->bThumbHot)
  967. {
  968. ptb->bThumbHot = FALSE;
  969. // Update display
  970. TBRedrawThumb(ptb);
  971. }
  972. }
  973. }
  974. }
  975. }
  976. break;
  977. case WM_CAPTURECHANGED:
  978. // someone is stealing the capture from us
  979. TBTrackEnd(ptb);
  980. break;
  981. case WM_KEYUP:
  982. if (!(ptb->ci.style & WS_DISABLED)) {
  983. // If key was any of the keyboard accelerators, send end
  984. // track message when user up clicks on keyboard
  985. switch (wParam) {
  986. case VK_HOME:
  987. case VK_END:
  988. case VK_PRIOR:
  989. case VK_NEXT:
  990. case VK_LEFT:
  991. case VK_UP:
  992. case VK_RIGHT:
  993. case VK_DOWN:
  994. DoTrack(ptb, TB_ENDTRACK, 0);
  995. break;
  996. default:
  997. break;
  998. }
  999. }
  1000. break;
  1001. case WM_KEYDOWN:
  1002. if (!(ptb->ci.style & WS_DISABLED)) {
  1003. // Swap the left and right arrow key if the control is mirrored.
  1004. wParam = RTLSwapLeftRightArrows(&ptb->ci, wParam);
  1005. // If TBS_DOWNISLEFT, then swap left/right or up/down
  1006. // depending on whether we are vertical or horizontal.
  1007. // Some horizontal trackbars (e.g.) prefer that
  1008. // UpArrow=TB_PAGEDOWN.
  1009. if (ptb->ci.style & TBS_DOWNISLEFT) {
  1010. if (ISVERT(ptb)) {
  1011. wParam = CCSwapKeys(wParam, VK_LEFT, VK_RIGHT);
  1012. } else {
  1013. wParam = CCSwapKeys(wParam, VK_UP, VK_DOWN);
  1014. wParam = CCSwapKeys(wParam, VK_PRIOR, VK_NEXT);
  1015. }
  1016. }
  1017. switch (wParam) {
  1018. case VK_HOME:
  1019. wParam = TB_TOP;
  1020. goto KeyTrack;
  1021. case VK_END:
  1022. wParam = TB_BOTTOM;
  1023. goto KeyTrack;
  1024. case VK_PRIOR:
  1025. wParam = TB_PAGEUP;
  1026. goto KeyTrack;
  1027. case VK_NEXT:
  1028. wParam = TB_PAGEDOWN;
  1029. goto KeyTrack;
  1030. case VK_LEFT:
  1031. case VK_UP:
  1032. wParam = TB_LINEUP;
  1033. goto KeyTrack;
  1034. case VK_RIGHT:
  1035. case VK_DOWN:
  1036. wParam = TB_LINEDOWN;
  1037. KeyTrack:
  1038. DoTrack(ptb, (int) wParam, 0);
  1039. //notify of navigation key usage
  1040. CCNotifyNavigationKeyUsage(&(ptb->ci), UISF_HIDEFOCUS);
  1041. break;
  1042. default:
  1043. break;
  1044. }
  1045. }
  1046. break;
  1047. case WM_MBUTTONDOWN:
  1048. SetFocus(hwnd);
  1049. break;
  1050. case WM_STYLECHANGED:
  1051. if (wParam == GWL_STYLE) {
  1052. ptb->ci.style = ((LPSTYLESTRUCT)lParam)->styleNew;
  1053. TBResize(ptb);
  1054. }
  1055. break;
  1056. case WM_UPDATEUISTATE:
  1057. {
  1058. DWORD dwUIStateMask = MAKEWPARAM(0xFFFF, UISF_HIDEFOCUS);
  1059. if (CCOnUIState(&(ptb->ci), WM_UPDATEUISTATE, wParam & dwUIStateMask, lParam))
  1060. InvalidateRect(hwnd, NULL, TRUE);
  1061. goto DoDefault;
  1062. }
  1063. case TBM_GETPOS:
  1064. return ptb->lLogPos;
  1065. case TBM_GETSELSTART:
  1066. return ptb->lSelStart;
  1067. case TBM_GETSELEND:
  1068. return ptb->lSelEnd;
  1069. case TBM_GETRANGEMIN:
  1070. return ptb->lLogMin;
  1071. case TBM_GETRANGEMAX:
  1072. return ptb->lLogMax;
  1073. case TBM_GETPTICS:
  1074. return (LRESULT)ptb->pTics;
  1075. case TBM_CLEARSEL:
  1076. ptb->Flags &= ~TBF_SELECTION;
  1077. ptb->lSelStart = -1;
  1078. ptb->lSelEnd = -1;
  1079. goto RedrawTB;
  1080. case TBM_CLEARTICS:
  1081. if (ptb->pTics)
  1082. LocalFree((HLOCAL)ptb->pTics);
  1083. ptb->pTics = NULL;
  1084. ptb->nTics = 0;
  1085. goto RedrawTB;
  1086. case TBM_GETTIC:
  1087. if (ptb->pTics == NULL || (int)wParam >= ptb->nTics)
  1088. return -1L;
  1089. return ptb->pTics[wParam];
  1090. case TBM_GETTICPOS:
  1091. if (ptb->pTics == NULL || (int)wParam >= ptb->nTics)
  1092. return -1L;
  1093. return TBLogToPhys(ptb,ptb->pTics[wParam]);
  1094. case TBM_GETNUMTICS:
  1095. if (ptb->ci.style & TBS_NOTICKS)
  1096. return 0;
  1097. if (ptb->ticFreq) {
  1098. // first and last +
  1099. return 2 + (ptb->nTics / ptb->ticFreq);
  1100. }
  1101. // if there's no ticFreq, then we fall down here.
  1102. // 2 for the first and last tics that we always draw
  1103. // when NOTICS isn't set.
  1104. return 2;
  1105. case TBM_SETTIC:
  1106. /* not a valid position */
  1107. if (((LONG)lParam) < ptb->lLogMin || ((LONG)lParam) > ptb->lLogMax)
  1108. break;
  1109. h = CCLocalReAlloc(ptb->pTics,
  1110. sizeof(DWORD) * (ptb->nTics + 1));
  1111. if (!h)
  1112. return (LONG)FALSE;
  1113. ptb->pTics = (PDWORD)h;
  1114. ptb->pTics[ptb->nTics++] = (DWORD)lParam;
  1115. TBInvalidateAll(ptb);
  1116. return (LONG)TRUE;
  1117. case TBM_SETTICFREQ:
  1118. ptb->ticFreq = (int) wParam;
  1119. DoAutoTics(ptb);
  1120. goto RedrawTB;
  1121. case TBM_SETPOS:
  1122. /* Only redraw if it will physically move */
  1123. if (wParam && TBLogToPhys(ptb, (DWORD) lParam) !=
  1124. TBLogToPhys(ptb, ptb->lLogPos))
  1125. MoveThumb(ptb, (DWORD) lParam);
  1126. else
  1127. ptb->lLogPos = BOUND((LONG)lParam,ptb->lLogMin,ptb->lLogMax);
  1128. break;
  1129. case TBM_SETSEL:
  1130. if (!(ptb->ci.style & TBS_ENABLESELRANGE)) break;
  1131. ptb->Flags |= TBF_SELECTION;
  1132. if (((LONG)(SHORT)LOWORD(lParam)) < ptb->lLogMin)
  1133. ptb->lSelStart = ptb->lLogMin;
  1134. else
  1135. ptb->lSelStart = (LONG)(SHORT)LOWORD(lParam);
  1136. if (((LONG)(SHORT)HIWORD(lParam)) > ptb->lLogMax)
  1137. ptb->lSelEnd = ptb->lLogMax;
  1138. else
  1139. ptb->lSelEnd = (LONG)(SHORT)HIWORD(lParam);
  1140. if (ptb->lSelEnd < ptb->lSelStart)
  1141. ptb->lSelEnd = ptb->lSelStart;
  1142. goto RedrawTB;
  1143. case TBM_SETSELSTART:
  1144. if (!(ptb->ci.style & TBS_ENABLESELRANGE)) break;
  1145. ptb->Flags |= TBF_SELECTION;
  1146. if (lParam < ptb->lLogMin)
  1147. ptb->lSelStart = ptb->lLogMin;
  1148. else
  1149. ptb->lSelStart = (LONG) lParam;
  1150. if (ptb->lSelEnd < ptb->lSelStart || ptb->lSelEnd == -1)
  1151. ptb->lSelEnd = ptb->lSelStart;
  1152. goto RedrawTB;
  1153. case TBM_SETSELEND:
  1154. if (!(ptb->ci.style & TBS_ENABLESELRANGE)) break;
  1155. ptb->Flags |= TBF_SELECTION;
  1156. if (lParam > ptb->lLogMax)
  1157. ptb->lSelEnd = ptb->lLogMax;
  1158. else
  1159. ptb->lSelEnd = (LONG) lParam;
  1160. if (ptb->lSelStart > ptb->lSelEnd || ptb->lSelStart == -1)
  1161. ptb->lSelStart = ptb->lSelEnd;
  1162. goto RedrawTB;
  1163. case TBM_SETRANGE:
  1164. ptb->lLogMin = (LONG)(SHORT)LOWORD(lParam);
  1165. ptb->lLogMax = (LONG)(SHORT)HIWORD(lParam);
  1166. if (ptb->lSelStart < ptb->lLogMin)
  1167. ptb->lSelStart = ptb->lLogMin;
  1168. if (ptb->lSelEnd > ptb->lLogMax)
  1169. ptb->lSelEnd = ptb->lLogMax;
  1170. DoAutoTics(ptb);
  1171. goto RedrawTB;
  1172. case TBM_SETRANGEMIN:
  1173. ptb->lLogMin = (LONG)lParam;
  1174. if (ptb->lSelStart < ptb->lLogMin)
  1175. ptb->lSelStart = ptb->lLogMin;
  1176. DoAutoTics(ptb);
  1177. goto RedrawTB;
  1178. case TBM_SETRANGEMAX:
  1179. ptb->lLogMax = (LONG)lParam;
  1180. if (ptb->lSelEnd > ptb->lLogMax)
  1181. ptb->lSelEnd = ptb->lLogMax;
  1182. DoAutoTics(ptb);
  1183. RedrawTB:
  1184. ptb->lLogPos = BOUND(ptb->lLogPos, ptb->lLogMin,ptb->lLogMax);
  1185. TBChanged(ptb, TBC_ALL);
  1186. /* Only redraw if flag says so */
  1187. if (wParam) {
  1188. InvalidateRect(hwnd, NULL, FALSE);
  1189. MoveThumb(ptb, ptb->lLogPos);
  1190. }
  1191. break;
  1192. case TBM_SETTHUMBLENGTH:
  1193. if (ptb->ci.style & TBS_FIXEDLENGTH) {
  1194. ptb->iThumbHeight = (UINT)wParam;
  1195. TBResize(ptb);
  1196. }
  1197. break;
  1198. case TBM_GETTHUMBLENGTH:
  1199. return ptb->iThumbHeight;
  1200. case TBM_SETPAGESIZE: {
  1201. LONG lOldPage = ptb->lPageSize == -1 ? (ptb->lLogMax - ptb->lLogMin)/5 : ptb->lPageSize;
  1202. ptb->lPageSize = (LONG)lParam;
  1203. return lOldPage;
  1204. }
  1205. case TBM_GETPAGESIZE:
  1206. return ptb->lPageSize == -1 ? (ptb->lLogMax - ptb->lLogMin)/5 : ptb->lPageSize;
  1207. case TBM_SETLINESIZE: {
  1208. LONG lOldLine = ptb->lLineSize;
  1209. ptb->lLineSize = (LONG)lParam;
  1210. return lOldLine;
  1211. }
  1212. case TBM_GETLINESIZE:
  1213. return ptb->lLineSize;
  1214. case TBM_GETTHUMBRECT:
  1215. if (lParam) {
  1216. *((LPRECT)lParam) = ptb->rcThumb;
  1217. if (ISVERT(ptb)) FlipRect((LPRECT)lParam);
  1218. }
  1219. break;
  1220. case TBM_GETTOOLTIPS:
  1221. return (LRESULT)ptb->hwndToolTips;
  1222. case TBM_SETTOOLTIPS:
  1223. ptb->hwndToolTips = (HWND)wParam;
  1224. break;
  1225. case TBM_SETTIPSIDE:
  1226. {
  1227. UINT uOldSide = ptb->uTipSide;
  1228. ptb->uTipSide = (UINT) wParam;
  1229. return uOldSide;
  1230. }
  1231. case TBM_GETCHANNELRECT:
  1232. GetChannelRect(ptb, (LPRECT)lParam);
  1233. break;
  1234. case TBM_SETBUDDY:
  1235. return (LRESULT)TBSetBuddy(ptb, (BOOL)wParam, (HWND)lParam);
  1236. case TBM_GETBUDDY:
  1237. return (LRESULT)(wParam ? ptb->hwndBuddyLeft : ptb->hwndBuddyRight);
  1238. case WM_GETOBJECT:
  1239. if( lParam == OBJID_QUERYCLASSNAMEIDX )
  1240. return MSAA_CLASSNAMEIDX_TRACKBAR;
  1241. goto DoDefault;
  1242. case WM_THEMECHANGED:
  1243. if (ptb->hTheme)
  1244. CloseThemeData(ptb->hTheme);
  1245. ptb->hTheme = OpenThemeData(ptb->ci.hwnd, L"TrackBar");
  1246. TBInvalidateAll(ptb);
  1247. break;
  1248. default:
  1249. if (uMsg == g_msgMSWheel)
  1250. {
  1251. int cDetants;
  1252. long lPos;
  1253. ULONG ulPos;
  1254. int iWheelDelta = (int)(short)HIWORD(wParam);
  1255. // Update count of scroll amount
  1256. gcWheelDelta -= iWheelDelta;
  1257. cDetants = gcWheelDelta / WHEEL_DELTA;
  1258. if (cDetants != 0)
  1259. {
  1260. gcWheelDelta %= WHEEL_DELTA;
  1261. }
  1262. if (wParam & (MK_SHIFT | MK_CONTROL))
  1263. goto DoDefault;
  1264. if (SHRT_MIN <= ptb->lLogPos && ptb->lLogPos <= SHRT_MAX)
  1265. {
  1266. // Update position based on the logical unit length of the trackbar
  1267. // The larger the spread, the more logical units traversed
  1268. int cMult = (ptb->lLogMax - ptb->lLogMin) / 50;
  1269. if (cMult == 0)
  1270. cMult = 1;
  1271. lPos = ptb->lLogPos + (cDetants * cMult);
  1272. lPos = BOUND(lPos, ptb->lLogMin, ptb->lLogMax);
  1273. ulPos = BOUND(lPos, SHRT_MIN, SHRT_MAX);
  1274. if ((long) ulPos != ptb->lLogPos)
  1275. {
  1276. MoveThumb(ptb, (long) ulPos);
  1277. DoTrack(ptb, TB_THUMBPOSITION, ulPos);
  1278. }
  1279. }
  1280. return TRUE;
  1281. }
  1282. else
  1283. {
  1284. LRESULT lres;
  1285. if (CCWndProc(&ptb->ci, uMsg, wParam, lParam, &lres))
  1286. return lres;
  1287. }
  1288. DoDefault:
  1289. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  1290. }
  1291. return 0L;
  1292. }
  1293. /* DoTrack() */
  1294. void DoTrack(PTRACKBAR ptb, int cmd, DWORD dwPos)
  1295. {
  1296. LONG dpos;
  1297. switch(cmd) {
  1298. case TB_LINEDOWN:
  1299. dpos = ptb->lLineSize;
  1300. goto DMoveThumb;
  1301. case TB_LINEUP:
  1302. dpos = -ptb->lLineSize;
  1303. goto DMoveThumb;
  1304. case TB_PAGEUP:
  1305. case TB_PAGEDOWN:
  1306. if (ptb->lPageSize == -1) {
  1307. dpos = (ptb->lLogMax - ptb->lLogMin) / 5;
  1308. if (!dpos)
  1309. dpos = 1;
  1310. } else {
  1311. dpos = ptb->lPageSize;
  1312. }
  1313. if (cmd == TB_PAGEUP)
  1314. dpos *= -1;
  1315. DMoveThumb: // move delta
  1316. MoveThumb(ptb, ptb->lLogPos + dpos);
  1317. break;
  1318. case TB_BOTTOM:
  1319. dpos = ptb->lLogMax; // the BOUND will take care of this;
  1320. goto ABSMoveThumb;
  1321. case TB_TOP:
  1322. dpos = ptb->lLogMin; // the BOUND will take care of this;
  1323. ABSMoveThumb: // move absolute
  1324. MoveThumb(ptb, dpos);
  1325. break;
  1326. default: // do nothing
  1327. break;
  1328. }
  1329. // note: we only send back a WORD worth of the position.
  1330. if (ISVERT(ptb)) {
  1331. FORWARD_WM_VSCROLL(ptb->ci.hwndParent, ptb->ci.hwnd, cmd, LOWORD(dwPos), SendMessage);
  1332. } else
  1333. FORWARD_WM_HSCROLL(ptb->ci.hwndParent, ptb->ci.hwnd, cmd, LOWORD(dwPos), SendMessage);
  1334. }
  1335. /* WTrackType() */
  1336. WORD WTrackType(PTRACKBAR ptb, LONG lParam)
  1337. {
  1338. POINT pt;
  1339. pt.x = GET_X_LPARAM(lParam);
  1340. pt.y = GET_Y_LPARAM(lParam);
  1341. if (ptb->Flags & TBF_NOTHUMB ||
  1342. ptb->ci.style & TBS_NOTHUMB) // If no thumb, just leave.
  1343. return 0;
  1344. if (ISVERT(ptb)) {
  1345. // put point in virtual coordinates
  1346. int temp;
  1347. temp = pt.x;
  1348. pt.x = pt.y;
  1349. pt.y = temp;
  1350. }
  1351. if (PtInRect(&ptb->rcThumb, pt))
  1352. return TB_THUMBTRACK;
  1353. if (!PtInRect(&ptb->rc, pt))
  1354. return 0;
  1355. if (pt.x >= ptb->rcThumb.left)
  1356. return TB_PAGEDOWN;
  1357. else
  1358. return TB_PAGEUP;
  1359. }
  1360. /* TBTrackInit() */
  1361. void TBTrackInit(PTRACKBAR ptb, LPARAM lParam)
  1362. {
  1363. WORD wCmd;
  1364. if (ptb->Flags & TBF_NOTHUMB ||
  1365. ptb->ci.style & TBS_NOTHUMB) // No thumb: just leave.
  1366. return;
  1367. wCmd = WTrackType(ptb, (LONG) lParam);
  1368. if (!wCmd)
  1369. return;
  1370. SetCapture(ptb->ci.hwnd);
  1371. ptb->Cmd = wCmd;
  1372. ptb->dwDragPos = (DWORD)-1;
  1373. // Set up for auto-track (if needed).
  1374. if (wCmd != TB_THUMBTRACK) {
  1375. // Set our timer up
  1376. SetTimer(ptb->ci.hwnd, TIMER_ID, REPEATTIME, NULL);
  1377. } else {
  1378. int xPos;
  1379. // thumb tracking...
  1380. // store the offset between the cursor's position and the center of the thumb
  1381. xPos = TBLogToPhys(ptb, ptb->lLogPos);
  1382. ptb->dwDragOffset = (ISVERT(ptb) ? HIWORD(lParam) : LOWORD(lParam)) - xPos;
  1383. if (ptb->hwndToolTips) {
  1384. TOOLINFO ti;
  1385. // don't bother setting the rect because we'll do it below
  1386. // in FlushToolTipsMgr;
  1387. ti.cbSize = sizeof(ti);
  1388. ti.uFlags = TTF_TRACK | TTF_CENTERTIP;
  1389. ti.hwnd = ptb->ci.hwnd;
  1390. ti.uId = (UINT_PTR)ptb->ci.hwnd;
  1391. SendMessage(ptb->hwndToolTips, TTM_TRACKACTIVATE, (WPARAM)TRUE, (LPARAM)&ti);
  1392. }
  1393. }
  1394. TBTrack(ptb, lParam);
  1395. }
  1396. /* EndTrack() */
  1397. void TBTrackEnd(PTRACKBAR ptb)
  1398. {
  1399. // Decide how we're ending this thing.
  1400. if (ptb->Cmd == TB_THUMBTRACK) {
  1401. if (ptb->hwndToolTips)
  1402. SendMessage(ptb->hwndToolTips, TTM_TRACKACTIVATE, (WPARAM)FALSE, 0);
  1403. DoTrack(ptb, TB_THUMBPOSITION, ptb->dwDragPos);
  1404. }
  1405. KillTimer(ptb->ci.hwnd, TIMER_ID);
  1406. // Always send TB_ENDTRACK message if there's some sort of command tracking.
  1407. if (ptb->Cmd != (UINT)-1) {
  1408. DoTrack(ptb, TB_ENDTRACK, 0);
  1409. // Nothing going on.
  1410. ptb->Cmd = (UINT)-1;
  1411. }
  1412. MoveThumb(ptb, ptb->lLogPos);
  1413. }
  1414. #define TBTS_RIGHTLEFT 1 // low bit means it's on the right or left
  1415. void TBTrack(PTRACKBAR ptb, LPARAM lParam)
  1416. {
  1417. DWORD dwPos;
  1418. WORD pos;
  1419. // See if we're tracking the thumb
  1420. if (ptb->Cmd == TB_THUMBTRACK) {
  1421. pos = (ISVERT(ptb)) ? HIWORD(lParam) : LOWORD(lParam);
  1422. pos -= (WORD) ptb->dwDragOffset;
  1423. dwPos = TBPhysToLog(ptb, (int)(SHORT)pos);
  1424. // Tentative position changed -- notify the guy.
  1425. if (dwPos != ptb->dwDragPos) {
  1426. ptb->dwDragPos = dwPos;
  1427. MoveThumb(ptb, dwPos);
  1428. DoTrack(ptb, TB_THUMBTRACK, dwPos);
  1429. }
  1430. if (ptb->hwndToolTips) {
  1431. RECT rc;
  1432. POINT pt;
  1433. int iPixel;
  1434. UINT uTipSide = ptb->uTipSide;
  1435. // find the center of the window
  1436. GetClientRect(ptb->ci.hwnd, &rc);
  1437. pt.x = rc.right / 2;
  1438. pt.y = rc.bottom / 2;
  1439. //find the position of the thumb
  1440. iPixel = TBLogToPhys(ptb, dwPos);
  1441. if (ISVERT(ptb)) {
  1442. pt.y = iPixel;
  1443. uTipSide |= TBTS_RIGHTLEFT;
  1444. } else {
  1445. pt.x = iPixel;
  1446. uTipSide &= ~TBTS_RIGHTLEFT;
  1447. }
  1448. // move it out to the requested side
  1449. switch (uTipSide) {
  1450. case TBTS_TOP:
  1451. pt.y = -1;
  1452. break;
  1453. case TBTS_LEFT:
  1454. pt.x = -1;
  1455. break;
  1456. case TBTS_BOTTOM:
  1457. pt.y = rc.bottom + 1;
  1458. break;
  1459. case TBTS_RIGHT:
  1460. pt.x = rc.right + 1;
  1461. break;
  1462. }
  1463. // map it to screen coordinates
  1464. MapWindowPoints(ptb->ci.hwnd, HWND_DESKTOP, &pt, 1);
  1465. SendMessage(ptb->hwndToolTips, TTM_TRACKPOSITION, 0, MAKELONG(pt.x, pt.y));
  1466. }
  1467. }
  1468. else {
  1469. if (ptb->Cmd != WTrackType(ptb, (LONG) lParam))
  1470. return;
  1471. DoTrack(ptb, ptb->Cmd, 0);
  1472. }
  1473. }
  1474. // FlushChanges is theme aware (RENDERS)
  1475. void FlushChanges(PTRACKBAR ptb)
  1476. {
  1477. HBRUSH hbr;
  1478. NMCUSTOMDRAW nmcd;
  1479. hbr = FORWARD_WM_CTLCOLORSTATIC(ptb->ci.hwndParent, ptb->hdc, ptb->ci.hwnd, SendMessage);
  1480. if (hbr)
  1481. {
  1482. RECT rc;
  1483. BOOL fClear = FALSE;
  1484. if ( ptb->wDirtyFlags == TBC_ALL )
  1485. {
  1486. GetClientRect(ptb->ci.hwnd, &rc);
  1487. fClear = TRUE;
  1488. }
  1489. else if (ptb->wDirtyFlags & TBC_THUMB)
  1490. {
  1491. rc = ptb->rc;
  1492. rc.left = 0;
  1493. rc.right += ptb->iThumbWidth;
  1494. if (ISVERT(ptb))
  1495. FlipRect(&rc);
  1496. fClear = TRUE;
  1497. }
  1498. // Background fill
  1499. if (fClear)
  1500. {
  1501. FillRect(ptb->hdc, &rc, hbr);
  1502. }
  1503. }
  1504. nmcd.hdc = ptb->hdc;
  1505. if (ptb->ci.hwnd == GetFocus())
  1506. nmcd.uItemState = CDIS_FOCUS;
  1507. else
  1508. nmcd.uItemState = 0;
  1509. nmcd.lItemlParam = 0;
  1510. ptb->ci.dwCustom = CICustomDrawNotify(&ptb->ci, CDDS_PREPAINT, &nmcd);
  1511. // for skip default, no other flags make sense.. only allow that one
  1512. if (!(ptb->ci.dwCustom == CDRF_SKIPDEFAULT))
  1513. {
  1514. DWORD dwRet = 0;
  1515. // do the actual drawing
  1516. if (nmcd.uItemState & CDIS_FOCUS)
  1517. {
  1518. DrawFocus(ptb, hbr);
  1519. }
  1520. nmcd.uItemState = 0;
  1521. if (ptb->wDirtyFlags & TBC_TICS)
  1522. {
  1523. nmcd.dwItemSpec = TBCD_TICS;
  1524. dwRet = CICustomDrawNotify(&ptb->ci, CDDS_ITEMPREPAINT, &nmcd);
  1525. if (!(dwRet == CDRF_SKIPDEFAULT))
  1526. {
  1527. DrawTics(ptb);
  1528. if (dwRet & CDRF_NOTIFYPOSTPAINT)
  1529. {
  1530. nmcd.dwItemSpec = TBCD_TICS;
  1531. CICustomDrawNotify(&ptb->ci, CDDS_ITEMPOSTPAINT, &nmcd);
  1532. }
  1533. }
  1534. }
  1535. if (ptb->wDirtyFlags & TBC_THUMB)
  1536. {
  1537. // the channel
  1538. GetChannelRect(ptb, &nmcd.rc);
  1539. if (ISVERT(ptb))
  1540. FlipRect(&nmcd.rc);
  1541. nmcd.dwItemSpec = TBCD_CHANNEL;
  1542. dwRet = CICustomDrawNotify(&ptb->ci, CDDS_ITEMPREPAINT, &nmcd);
  1543. if (!(dwRet == CDRF_SKIPDEFAULT))
  1544. {
  1545. // flip it back from the last notify
  1546. if (ISVERT(ptb))
  1547. FlipRect(&nmcd.rc);
  1548. // the actual drawing
  1549. DrawChannel(ptb, &nmcd.rc);
  1550. if (dwRet & CDRF_NOTIFYPOSTPAINT)
  1551. {
  1552. if (ISVERT(ptb))
  1553. FlipRect(&nmcd.rc);
  1554. nmcd.dwItemSpec = TBCD_CHANNEL;
  1555. CICustomDrawNotify(&ptb->ci, CDDS_ITEMPOSTPAINT, &nmcd);
  1556. }
  1557. }
  1558. // the thumb
  1559. nmcd.rc = ptb->rcThumb;
  1560. if (ptb->Cmd == TB_THUMBTRACK)
  1561. {
  1562. nmcd.uItemState = CDIS_SELECTED;
  1563. }
  1564. if (ISVERT(ptb))
  1565. FlipRect(&nmcd.rc);
  1566. nmcd.dwItemSpec = TBCD_THUMB;
  1567. dwRet = CICustomDrawNotify(&ptb->ci, CDDS_ITEMPREPAINT, &nmcd);
  1568. if (!(dwRet == CDRF_SKIPDEFAULT))
  1569. {
  1570. if (ISVERT(ptb))
  1571. FlipRect(&nmcd.rc);
  1572. // the actual drawing
  1573. DrawThumb(ptb, &nmcd.rc, nmcd.uItemState & CDIS_SELECTED);
  1574. if (dwRet & CDRF_NOTIFYPOSTPAINT)
  1575. {
  1576. if (ISVERT(ptb))
  1577. FlipRect(&nmcd.rc);
  1578. nmcd.dwItemSpec = TBCD_THUMB;
  1579. CICustomDrawNotify(&ptb->ci, CDDS_ITEMPOSTPAINT, &nmcd);
  1580. }
  1581. }
  1582. }
  1583. ptb->wDirtyFlags = 0;
  1584. // notify parent afterwards if they want us to
  1585. if (ptb->ci.dwCustom & CDRF_NOTIFYPOSTPAINT)
  1586. {
  1587. CICustomDrawNotify(&ptb->ci, CDDS_POSTPAINT, &nmcd);
  1588. }
  1589. }
  1590. #ifdef TB_DEBUG
  1591. DebugMsg(DM_TRACE, TEXT("DrawDone"));
  1592. {
  1593. HDC hdcScreen;
  1594. RECT rcClient;
  1595. hdcScreen = GetDC(NULL);
  1596. GetClientRect(ptb->ci.hwnd, &rcClient);
  1597. BitBlt(hdcScreen, 200, 0, 200 + rcClient.right, rcClient.bottom, ptb->hdc, 0,0, SRCCOPY);
  1598. ReleaseDC(NULL, hdcScreen);
  1599. }
  1600. #endif
  1601. }