Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2067 lines
58 KiB

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