source: trunk/src/comctl32/trackbar.c@ 110

Last change on this file since 110 was 110, checked in by cbratschi, 26 years ago

comctl32 wine conversion bugs fixed
trackbar: TRACKBAR_Draw prototype

File size: 43.7 KB
Line 
1/* $Id: trackbar.c,v 1.5 1999-06-16 20:25:44 cbratschi Exp $ */
2/*
3 * Trackbar control
4 *
5 * Copyright 1998, 1999 Eric Kohl <ekohl@abo.rhein-zeitung.de>
6 * Copyright 1998,1999 Alex Priem <alexp@sci.kun.nl>
7 * Copyright 1999 Achim Hasenmueller
8 * Copyright 1999 Christoph Bratschi <cbratschi@datacomm.ch>
9 *
10 *
11 * TODO:
12 * - Some messages.
13 * - more display code.
14 * - handle dragging slider better
15 * - better tic handling.
16 * - more notifications.
17 * - implement TRACKBAR_Draw with inUpdate
18 *
19 */
20
21/* known bugs:
22
23 -TBM_SETRANGEMAX & TBM_SETRANGEMIN should only change the view of the
24 trackbar, not the actual amount of tics in the list.
25 -TBM_GETTIC & TBM_GETTICPOS shouldn't rely on infoPtr->tics being sorted.
26 - Make drawing code exact match of w95 drawing.
27*/
28
29
30
31#include "winbase.h"
32#include "commctrl.h"
33#include "trackbar.h"
34#include <stdio.h>
35
36
37#define TRACKBAR_GetInfoPtr(wndPtr) ((TRACKBAR_INFO *)GetWindowLongA (hwnd,0))
38
39
40/* Used by TRACKBAR_Refresh to find out which parts of the control
41 need to be recalculated */
42
43#define TB_THUMBPOSCHANGED 1
44#define TB_THUMBSIZECHANGED 2
45#define TB_THUMBCHANGED (TB_THUMBPOSCHANGED | TB_THUMBPOSCHANGED)
46#define TB_SELECTIONCHANGED 4
47#define TB_DRAG_MODE 16 /* we're dragging the slider */
48#define TB_DRAGPOSVALID 32 /* current Position is in dragPos */
49#define TB_SHOW_TOOLTIP 64 /* tooltip-style enabled and tooltip on */
50
51/* helper defines for TRACKBAR_DrawTic */
52#define TIC_LEFTEDGE 0x20
53#define TIC_RIGHTEDGE 0x40
54#define TIC_EDGE (TIC_LEFTEDGE | TIC_RIGHTEDGE)
55#define TIC_SELECTIONMARKMAX 0x80
56#define TIC_SELECTIONMARKMIN 0x100
57#define TIC_SELECTIONMARK (TIC_SELECTIONMARKMAX | TIC_SELECTIONMARKMIN)
58
59static BOOL TRACKBAR_SendNotify (HWND hwnd, UINT code);
60
61void TRACKBAR_RecalculateTics (TRACKBAR_INFO *infoPtr)
62{
63 int i,tic,nrTics;
64
65 if (infoPtr->uTicFreq && infoPtr->nRangeMax >= infoPtr->nRangeMin)
66 nrTics=(infoPtr->nRangeMax - infoPtr->nRangeMin)/infoPtr->uTicFreq;
67 else {
68 nrTics=0;
69 COMCTL32_Free (infoPtr->tics);
70 infoPtr->tics=NULL;
71 infoPtr->uNumTics=0;
72 return;
73 }
74
75 if (nrTics!=infoPtr->uNumTics) {
76 infoPtr->tics=COMCTL32_ReAlloc (infoPtr->tics,
77 (nrTics+1)*sizeof (DWORD));
78 infoPtr->uNumTics=nrTics;
79 }
80 infoPtr->uNumTics=nrTics;
81 tic=infoPtr->nRangeMin+infoPtr->uTicFreq;
82 for (i=0; i<nrTics; i++,tic+=infoPtr->uTicFreq)
83 infoPtr->tics[i]=tic;
84}
85
86
87/* converts from physical (mouse) position to logical position
88 (in range of trackbar) */
89
90static DOUBLE
91TRACKBAR_ConvertPlaceToPosition (TRACKBAR_INFO *infoPtr, int place,
92 int vertical)
93{
94 double range,width,pos;
95
96 range=infoPtr->nRangeMax - infoPtr->nRangeMin;
97 if (vertical) {
98 width=infoPtr->rcChannel.bottom - infoPtr->rcChannel.top;
99 pos=(range*(place - infoPtr->rcChannel.top)) / width;
100 } else {
101 width=infoPtr->rcChannel.right - infoPtr->rcChannel.left;
102 pos=(range*(place - infoPtr->rcChannel.left)) / width;
103 }
104
105 if (pos > infoPtr->nRangeMax)
106 pos = infoPtr->nRangeMax;
107 else if (pos < infoPtr->nRangeMin)
108 pos = infoPtr->nRangeMin;
109
110// TRACE (trackbar,"%.2f\n",pos);
111 return pos;
112}
113
114
115static VOID
116TRACKBAR_CalcChannel (HWND hwnd, TRACKBAR_INFO *infoPtr)
117{
118 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
119 INT cyChannel;
120 RECT lpRect,*channel = & infoPtr->rcChannel;
121
122 GetClientRect (hwnd, &lpRect);
123
124 if (dwStyle & TBS_ENABLESELRANGE)
125 cyChannel = MAX(infoPtr->uThumbLen - 8, 4);
126 else
127 cyChannel = 4;
128
129 if (dwStyle & TBS_VERT) {
130 channel->top = lpRect.top + 8;
131 channel->bottom = lpRect.bottom - 8;
132
133 if (dwStyle & TBS_BOTH) {
134 channel->left = (lpRect.right - cyChannel) / 2;
135 channel->right = (lpRect.right + cyChannel) / 2;
136 }
137 else if (dwStyle & TBS_LEFT) {
138 channel->left = lpRect.left + 10;
139 channel->right = channel->left + cyChannel;
140 }
141 else { /* TBS_RIGHT */
142 channel->right = lpRect.right - 10;
143 channel->left = channel->right - cyChannel;
144 }
145 }
146 else {
147 channel->left = lpRect.left + 8;
148 channel->right = lpRect.right - 8;
149 if (dwStyle & TBS_BOTH) {
150 channel->top = (lpRect.bottom - cyChannel) / 2;
151 channel->bottom = (lpRect.bottom + cyChannel) / 2;
152 }
153 else if (dwStyle & TBS_TOP) {
154 channel->top = lpRect.top + 10;
155 channel->bottom = channel->top + cyChannel;
156 }
157 else { /* TBS_BOTTOM */
158 channel->bottom = lpRect.bottom - 10;
159 channel->top = channel->bottom - cyChannel;
160 }
161 }
162}
163
164static VOID
165TRACKBAR_CalcThumb (HWND hwnd, TRACKBAR_INFO *infoPtr)
166{
167 RECT *thumb;
168 int range, width;
169
170 thumb=&infoPtr->rcThumb;
171 range=infoPtr->nRangeMax - infoPtr->nRangeMin;
172 if (GetWindowLongA (hwnd, GWL_STYLE) & TBS_VERT) {
173 width=infoPtr->rcChannel.bottom - infoPtr->rcChannel.top;
174 thumb->left = infoPtr->rcChannel.left - 1;
175 thumb->right = infoPtr->rcChannel.left + infoPtr->uThumbLen - 8;
176 thumb->top = infoPtr->rcChannel.top +
177 (width*infoPtr->nPos)/range - 5;
178 thumb->bottom = thumb->top + infoPtr->uThumbLen/3;
179
180 } else {
181 width=infoPtr->rcChannel.right - infoPtr->rcChannel.left;
182 thumb->left = infoPtr->rcChannel.left +
183 (width*infoPtr->nPos)/range - 5;
184 thumb->right = thumb->left + infoPtr->uThumbLen/3;
185 thumb->top = infoPtr->rcChannel.top - 1;
186 thumb->bottom = infoPtr->rcChannel.top + infoPtr->uThumbLen - 8;
187 }
188}
189
190static VOID
191TRACKBAR_CalcSelection (HWND hwnd, TRACKBAR_INFO *infoPtr)
192{
193 RECT *selection;
194 int range, width;
195
196 selection= & infoPtr->rcSelection;
197 range=infoPtr->nRangeMax - infoPtr->nRangeMin;
198 width=infoPtr->rcChannel.right - infoPtr->rcChannel.left;
199
200 if (range <= 0)
201 SetRectEmpty (selection);
202 else
203 if (GetWindowLongA (hwnd, GWL_STYLE) & TBS_VERT) {
204 selection->left = infoPtr->rcChannel.left +
205 (width*infoPtr->nSelMin)/range;
206 selection->right = infoPtr->rcChannel.left +
207 (width*infoPtr->nSelMax)/range;
208 selection->top = infoPtr->rcChannel.top + 2;
209 selection->bottom = infoPtr->rcChannel.bottom - 2;
210 } else {
211 selection->top = infoPtr->rcChannel.top +
212 (width*infoPtr->nSelMin)/range;
213 selection->bottom = infoPtr->rcChannel.top +
214 (width*infoPtr->nSelMax)/range;
215 selection->left = infoPtr->rcChannel.left + 2;
216 selection->right = infoPtr->rcChannel.right - 2;
217 }
218}
219
220/* Trackbar drawing code. I like my spaghetti done milanese. */
221
222/* ticPos is in tic-units, not in pixels */
223
224static VOID
225TRACKBAR_DrawHorizTic (TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos,
226 int flags, COLORREF clrTic)
227{
228 RECT rcChannel=infoPtr->rcChannel;
229 int x,y,width,range,side;
230
231 range=infoPtr->nRangeMax - infoPtr->nRangeMin;
232 width=rcChannel.right - rcChannel.left;
233
234 if (flags & TBS_TOP) {
235 y=rcChannel.top-2;
236 side=-1;
237 } else {
238 y=rcChannel.bottom+2;
239 side=1;
240 }
241
242 if (flags & TIC_SELECTIONMARK) {
243 if (flags & TIC_SELECTIONMARKMIN)
244 x=rcChannel.left + (width*ticPos)/range - 1;
245 else
246 x=rcChannel.left + (width*ticPos)/range + 1;
247
248 SetPixel (hdc, x,y+6*side, clrTic);
249 SetPixel (hdc, x,y+7*side, clrTic);
250 return;
251 }
252
253 if ((ticPos>infoPtr->nRangeMin) && (ticPos<infoPtr->nRangeMax)) {
254 x=rcChannel.left + (width*ticPos)/range;
255 SetPixel (hdc, x,y+5*side, clrTic);
256 SetPixel (hdc, x,y+6*side, clrTic);
257 SetPixel (hdc, x,y+7*side, clrTic);
258 }
259
260 if (flags & TIC_EDGE) {
261 if (flags & TIC_LEFTEDGE)
262 x=rcChannel.left;
263 else
264 x=rcChannel.right;
265
266 SetPixel (hdc, x,y+5*side, clrTic);
267 SetPixel (hdc, x,y+6*side, clrTic);
268 SetPixel (hdc, x,y+7*side, clrTic);
269 SetPixel (hdc, x,y+8*side, clrTic);
270 }
271
272}
273
274static VOID
275TRACKBAR_DrawVertTic (TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos,
276 int flags, COLORREF clrTic)
277{
278 RECT rcChannel=infoPtr->rcChannel;
279 int x,y,width,range,side;
280
281 range=infoPtr->nRangeMax - infoPtr->nRangeMin;
282 width=rcChannel.bottom - rcChannel.top;
283
284 if (flags & TBS_TOP) {
285 x=rcChannel.right-2;
286 side=-1;
287 } else {
288 x=rcChannel.left+2;
289 side=1;
290 }
291
292
293 if (flags & TIC_SELECTIONMARK) {
294 if (flags & TIC_SELECTIONMARKMIN)
295 y=rcChannel.top + (width*ticPos)/range - 1;
296 else
297 y=rcChannel.top + (width*ticPos)/range + 1;
298
299 SetPixel (hdc, x+6*side, y, clrTic);
300 SetPixel (hdc, x+7*side, y, clrTic);
301 return;
302 }
303
304 if ((ticPos>infoPtr->nRangeMin) && (ticPos<infoPtr->nRangeMax)) {
305 y=rcChannel.top + (width*ticPos)/range;
306 SetPixel (hdc, x+5*side, y, clrTic);
307 SetPixel (hdc, x+6*side, y, clrTic);
308 SetPixel (hdc, x+7*side, y, clrTic);
309 }
310
311 if (flags & TIC_EDGE) {
312 if (flags & TIC_LEFTEDGE)
313 y=rcChannel.top;
314 else
315 y=rcChannel.bottom;
316
317 SetPixel (hdc, x+5*side, y, clrTic);
318 SetPixel (hdc, x+6*side, y, clrTic);
319 SetPixel (hdc, x+7*side, y, clrTic);
320 SetPixel (hdc, x+8*side, y, clrTic);
321 }
322
323}
324
325
326static VOID
327TRACKBAR_DrawTics (TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos,
328 int flags, COLORREF clrTic)
329{
330
331 if (flags & TBS_VERT) {
332 if ((flags & TBS_TOP) || (flags & TBS_BOTH))
333 TRACKBAR_DrawVertTic (infoPtr, hdc, ticPos,
334 flags | TBS_TOP , clrTic);
335 if (!(flags & TBS_TOP) || (flags & TBS_BOTH))
336 TRACKBAR_DrawVertTic (infoPtr, hdc, ticPos, flags, clrTic);
337 return;
338 }
339
340 if ((flags & TBS_TOP) || (flags & TBS_BOTH))
341 TRACKBAR_DrawHorizTic (infoPtr, hdc, ticPos, flags | TBS_TOP , clrTic);
342
343 if (!(flags & TBS_TOP) || (flags & TBS_BOTH))
344 TRACKBAR_DrawHorizTic (infoPtr, hdc, ticPos, flags, clrTic);
345
346}
347
348//draw the trackbar
349
350static VOID TRACKBAR_Draw(HWND hwnd,HDC hdc,INT lastPos,BOOL inUpdate)
351{
352 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
353 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
354 RECT rcClient, rcChannel, rcSelection;
355 HBRUSH hBrush = CreateSolidBrush (infoPtr->clrBk);
356 int i;
357
358 GetClientRect (hwnd, &rcClient);
359 if (!inUpdate)
360 {
361 hBrush = CreateSolidBrush (infoPtr->clrBk);
362 FillRect (hdc, &rcClient, hBrush);
363 DeleteObject (hBrush);
364 }
365
366 if (infoPtr->flags & TB_DRAGPOSVALID) {
367 infoPtr->nPos=infoPtr->dragPos;
368 infoPtr->flags |= TB_THUMBPOSCHANGED;
369 }
370
371 if (infoPtr->flags & TB_THUMBCHANGED) {
372 TRACKBAR_CalcThumb (hwnd, infoPtr);
373 if (infoPtr->flags & TB_THUMBSIZECHANGED)
374 TRACKBAR_CalcChannel (hwnd, infoPtr);
375 }
376 if (infoPtr->flags & TB_SELECTIONCHANGED)
377 TRACKBAR_CalcSelection (hwnd, infoPtr);
378 infoPtr->flags &= ~ (TB_THUMBCHANGED | TB_SELECTIONCHANGED |
379 TB_DRAGPOSVALID);
380
381 /* draw channel */
382
383 rcChannel = infoPtr->rcChannel;
384 rcSelection= infoPtr->rcSelection;
385 DrawEdge (hdc, &rcChannel, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
386
387 if (dwStyle & TBS_ENABLESELRANGE) { /* fill the channel */
388 HBRUSH hbr = CreateSolidBrush (RGB(255,255,255));
389 FillRect (hdc, &rcChannel, hbr);
390 if (((dwStyle & TBS_VERT) &&
391 (rcSelection.left!=rcSelection.right)) ||
392 ((!(dwStyle & TBS_VERT)) &&
393 (rcSelection.left!=rcSelection.right))) {
394 hbr=CreateSolidBrush (COLOR_HIGHLIGHT);
395 FillRect (hdc, &rcSelection, hbr);
396 }
397 DeleteObject (hbr);
398 }
399
400
401 /* draw tics */
402
403 if (!(dwStyle & TBS_NOTICKS)) {
404 int ticFlags = dwStyle & 0x0f;
405 COLORREF clrTic=GetSysColor (COLOR_3DDKSHADOW);
406
407 for (i=0; i<infoPtr->uNumTics; i++)
408 TRACKBAR_DrawTics (infoPtr, hdc, infoPtr->tics[i],
409 ticFlags, clrTic);
410
411 TRACKBAR_DrawTics (infoPtr, hdc, 0, ticFlags | TIC_LEFTEDGE, clrTic);
412 TRACKBAR_DrawTics (infoPtr, hdc, 0, ticFlags | TIC_RIGHTEDGE, clrTic);
413
414 if ((dwStyle & TBS_ENABLESELRANGE) &&
415 (rcSelection.left!=rcSelection.right)) {
416 TRACKBAR_DrawTics (infoPtr, hdc, infoPtr->nSelMin,
417 ticFlags | TIC_SELECTIONMARKMIN, clrTic);
418 TRACKBAR_DrawTics (infoPtr, hdc, infoPtr->nSelMax,
419 ticFlags | TIC_SELECTIONMARKMAX, clrTic);
420 }
421 }
422
423 /* draw thumb */
424
425 if (!(dwStyle & TBS_NOTHUMB)) {
426
427 HBRUSH hbr = CreateSolidBrush (COLOR_BACKGROUND);
428 RECT thumb = infoPtr->rcThumb;
429
430 SelectObject (hdc, hbr);
431
432 if (dwStyle & TBS_BOTH) {
433 FillRect (hdc, &thumb, hbr);
434 DrawEdge (hdc, &thumb, EDGE_RAISED, BF_TOPLEFT);
435 } else {
436
437 POINT points[6];
438
439 /* first, fill the thumb */
440 /* FIXME: revamp. check for TBS_VERT */
441
442 SetPolyFillMode (hdc,WINDING);
443 points[0].x=thumb.left;
444 points[0].y=thumb.top;
445 points[1].x=thumb.right - 1;
446 points[1].y=thumb.top;
447 points[2].x=thumb.right - 1;
448 points[2].y=thumb.bottom -2;
449 points[3].x=(thumb.right + thumb.left-1)/2;
450 points[3].y=thumb.bottom+4;
451 points[4].x=thumb.left;
452 points[4].y=thumb.bottom -2;
453 points[5].x=points[0].x;
454 points[5].y=points[0].y;
455 Polygon (hdc, points, 6);
456
457 if (dwStyle & TBS_VERT) {
458 /* draw edge */
459 } else {
460 RECT triangle; /* for correct shadows of thumb */
461 DrawEdge (hdc, &thumb, EDGE_RAISED, BF_TOPLEFT);
462
463 /* draw notch */
464
465 triangle.right = thumb.right+5;
466 triangle.left = points[3].x+5;
467 triangle.top = thumb.bottom +5;
468 triangle.bottom= thumb.bottom +1;
469 DrawEdge (hdc, &triangle, EDGE_SUNKEN,
470 BF_DIAGONAL | BF_TOP | BF_RIGHT);
471 triangle.left = thumb.left+6;
472 triangle.right = points[3].x+6;
473 DrawEdge (hdc, &triangle, EDGE_RAISED,
474 BF_DIAGONAL | BF_TOP | BF_LEFT);
475 }
476 }
477 DeleteObject (hbr);
478 }
479
480 if (infoPtr->bFocus)
481 DrawFocusRect (hdc, &rcClient);
482}
483
484//update display
485
486static VOID TRACKBAR_Update(HWND hwnd,INT lastPos)
487{
488 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
489 HDC hdc;
490
491 if (infoPtr->flags & TB_DRAGPOSVALID && lastPos == infoPtr->dragPos) return;
492 if (!infoPtr->flags & TB_DRAGPOSVALID && lastPos == infoPtr->nPos) return;
493 hdc = GetDC(hwnd);
494 TRACKBAR_Draw(hwnd,hdc,lastPos,TRUE);
495 ReleaseDC(hwnd,hdc);
496}
497
498//redraw everything
499
500static VOID TRACKBAR_Refresh (HWND hwnd)
501{
502 HDC hdc;
503
504 hdc = GetDC (hwnd);
505 TRACKBAR_Draw(hwnd,hdc,0,FALSE);
506 ReleaseDC(hwnd,hdc);
507}
508
509static VOID
510TRACKBAR_AlignBuddies (HWND hwnd, TRACKBAR_INFO *infoPtr)
511{
512 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
513 HWND hwndParent = GetParent (hwnd);
514 RECT rcSelf, rcBuddy;
515 INT x, y;
516
517 GetWindowRect (hwnd, &rcSelf);
518 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcSelf, 2);
519
520 /* align buddy left or above */
521 if (infoPtr->hwndBuddyLA) {
522 GetWindowRect (infoPtr->hwndBuddyLA, &rcBuddy);
523 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
524
525 if (dwStyle & TBS_VERT) {
526 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
527 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
528 y = rcSelf.top - (rcBuddy.bottom - rcBuddy.top);
529 }
530 else {
531 x = rcSelf.left - (rcBuddy.right - rcBuddy.left);
532 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
533 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
534 }
535
536 SetWindowPos (infoPtr->hwndBuddyLA, 0, x, y, 0, 0,
537 SWP_NOZORDER | SWP_NOSIZE);
538 }
539
540
541 /* align buddy right or below */
542 if (infoPtr->hwndBuddyRB) {
543 GetWindowRect (infoPtr->hwndBuddyRB, &rcBuddy);
544 MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
545
546 if (dwStyle & TBS_VERT) {
547 x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
548 (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
549 y = rcSelf.bottom;
550 }
551 else {
552 x = rcSelf.right;
553 y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
554 (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
555 }
556 SetWindowPos (infoPtr->hwndBuddyRB, 0, x, y, 0, 0,
557 SWP_NOZORDER | SWP_NOSIZE);
558 }
559}
560
561
562static LRESULT
563TRACKBAR_ClearSel (HWND hwnd, WPARAM wParam, LPARAM lParam)
564{
565 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
566
567 infoPtr->nSelMin = 0;
568 infoPtr->nSelMax = 0;
569 infoPtr->flags |= TB_SELECTIONCHANGED;
570
571 if ((BOOL)wParam) TRACKBAR_Refresh(hwnd);
572
573 return 0;
574}
575
576
577static LRESULT
578TRACKBAR_ClearTics (HWND hwnd, WPARAM wParam, LPARAM lParam)
579{
580 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
581
582 if (infoPtr->tics) {
583 COMCTL32_Free (infoPtr->tics);
584 infoPtr->tics = NULL;
585 infoPtr->uNumTics = 0;
586 }
587
588 if (wParam) TRACKBAR_Refresh(hwnd);
589
590 return 0;
591}
592
593
594static LRESULT
595TRACKBAR_GetBuddy (HWND hwnd, WPARAM wParam, LPARAM lParam)
596{
597 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
598
599 if (wParam) /* buddy is left or above */
600 return (LRESULT)infoPtr->hwndBuddyLA;
601
602 /* buddy is right or below */
603 return (LRESULT) infoPtr->hwndBuddyRB;
604}
605
606
607static LRESULT
608TRACKBAR_GetChannelRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
609{
610 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
611 LPRECT lprc = (LPRECT)lParam;
612
613 if (lprc == NULL)
614 return 0;
615
616 lprc->left = infoPtr->rcChannel.left;
617 lprc->right = infoPtr->rcChannel.right;
618 lprc->bottom = infoPtr->rcChannel.bottom;
619 lprc->top = infoPtr->rcChannel.top;
620
621 return 0;
622}
623
624
625static LRESULT
626TRACKBAR_GetLineSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
627{
628 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
629
630 return infoPtr->nLineSize;
631}
632
633
634static LRESULT
635TRACKBAR_GetNumTics (HWND hwnd, WPARAM wParam, LPARAM lParam)
636{
637 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
638
639 if (GetWindowLongA (hwnd, GWL_STYLE) & TBS_NOTICKS)
640 return 0;
641
642 return infoPtr->uNumTics+2;
643}
644
645
646static LRESULT
647TRACKBAR_GetPageSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
648{
649 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
650
651 return infoPtr->nPageSize;
652}
653
654
655static LRESULT
656TRACKBAR_GetPos (HWND hwnd, WPARAM wParam, LPARAM lParam)
657{
658 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
659
660 return infoPtr->nPos;
661}
662
663
664static LRESULT
665TRACKBAR_GetRangeMax (HWND hwnd, WPARAM wParam, LPARAM lParam)
666{
667 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
668
669 return infoPtr->nRangeMax;
670}
671
672
673static LRESULT
674TRACKBAR_GetRangeMin (HWND hwnd, WPARAM wParam, LPARAM lParam)
675{
676 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
677
678 return infoPtr->nRangeMin;
679}
680
681
682static LRESULT
683TRACKBAR_GetSelEnd (HWND hwnd, WPARAM wParam, LPARAM lParam)
684{
685 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
686
687 return infoPtr->nSelMax;
688}
689
690
691static LRESULT
692TRACKBAR_GetSelStart (HWND hwnd, WPARAM wParam, LPARAM lParam)
693{
694 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
695
696 return infoPtr->nSelMin;
697}
698
699
700static LRESULT
701TRACKBAR_GetThumbLength (HWND hwnd, WPARAM wParam, LPARAM lParam)
702{
703 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
704
705 return infoPtr->uThumbLen;
706}
707
708static LRESULT
709TRACKBAR_GetPTics (HWND hwnd)
710{
711 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
712
713 return (LRESULT) infoPtr->tics;
714}
715
716static LRESULT
717TRACKBAR_GetThumbRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
718{
719 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
720 LPRECT lprc = (LPRECT)lParam;
721
722 if (lprc == NULL)
723 return 0;
724
725 lprc->left = infoPtr->rcThumb.left;
726 lprc->right = infoPtr->rcThumb.right;
727 lprc->bottom = infoPtr->rcThumb.bottom;
728 lprc->top = infoPtr->rcThumb.top;
729
730 return 0;
731}
732
733
734static LRESULT
735TRACKBAR_GetTic (HWND hwnd, WPARAM wParam, LPARAM lParam)
736{
737 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
738 INT iTic;
739
740 iTic=(INT) wParam;
741 if ((iTic<0) || (iTic>infoPtr->uNumTics))
742 return -1;
743
744 return (LRESULT) infoPtr->tics[iTic];
745
746}
747
748
749static LRESULT
750TRACKBAR_GetTicPos (HWND hwnd, WPARAM wParam, LPARAM lParam)
751{
752 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
753 INT iTic, range, width, pos;
754
755
756 iTic=(INT ) wParam;
757 if ((iTic<0) || (iTic>infoPtr->uNumTics))
758 return -1;
759
760 range=infoPtr->nRangeMax - infoPtr->nRangeMin;
761 width=infoPtr->rcChannel.right - infoPtr->rcChannel.left;
762 pos=infoPtr->rcChannel.left + (width * infoPtr->tics[iTic]) / range;
763
764
765 return (LRESULT) pos;
766}
767
768
769static LRESULT
770TRACKBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
771{
772 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
773
774 if (GetWindowLongA (hwnd, GWL_STYLE) & TBS_TOOLTIPS)
775 return (LRESULT)infoPtr->hwndToolTip;
776 return 0;
777}
778
779
780/* case TBM_GETUNICODEFORMAT: */
781
782
783static LRESULT
784TRACKBAR_SetBuddy (HWND hwnd, WPARAM wParam, LPARAM lParam)
785{
786 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
787 HWND hwndTemp;
788
789 if (wParam) {
790 /* buddy is left or above */
791 hwndTemp = infoPtr->hwndBuddyLA;
792 infoPtr->hwndBuddyLA = (HWND)lParam;
793
794// FIXME (trackbar, "move buddy!\n");
795 }
796 else {
797 /* buddy is right or below */
798 hwndTemp = infoPtr->hwndBuddyRB;
799 infoPtr->hwndBuddyRB = (HWND)lParam;
800
801// FIXME (trackbar, "move buddy!\n");
802 }
803
804 TRACKBAR_AlignBuddies (hwnd, infoPtr);
805
806 return (LRESULT)hwndTemp;
807}
808
809
810static LRESULT
811TRACKBAR_SetLineSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
812{
813 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
814 INT nTemp = infoPtr->nLineSize;
815
816 infoPtr->nLineSize = (INT)lParam;
817
818 return nTemp;
819}
820
821
822static LRESULT
823TRACKBAR_SetPageSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
824{
825 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
826 INT nTemp = infoPtr->nPageSize;
827
828 infoPtr->nPageSize = (INT)lParam;
829
830 return nTemp;
831}
832
833
834static LRESULT
835TRACKBAR_SetPos (HWND hwnd, WPARAM wParam, LPARAM lParam)
836{
837 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
838
839 INT lastPos = infoPtr->nPos;
840 infoPtr->nPos = (INT)LOWORD(lParam);
841
842 if (infoPtr->nPos < infoPtr->nRangeMin)
843 infoPtr->nPos = infoPtr->nRangeMin;
844
845 if (infoPtr->nPos > infoPtr->nRangeMax)
846 infoPtr->nPos = infoPtr->nRangeMax;
847 infoPtr->flags |= TB_THUMBPOSCHANGED;
848
849 if (wParam) TRACKBAR_Update(hwnd,lastPos);
850
851 return 0;
852}
853
854
855static LRESULT
856TRACKBAR_SetRange (HWND hwnd, WPARAM wParam, LPARAM lParam)
857{
858 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
859 infoPtr->nRangeMin = (INT)LOWORD(lParam);
860 infoPtr->nRangeMax = (INT)HIWORD(lParam);
861
862 if (infoPtr->nPos < infoPtr->nRangeMin) {
863 infoPtr->nPos = infoPtr->nRangeMin;
864 infoPtr->flags |=TB_THUMBPOSCHANGED;
865 }
866
867 if (infoPtr->nPos > infoPtr->nRangeMax) {
868 infoPtr->nPos = infoPtr->nRangeMax;
869 infoPtr->flags |=TB_THUMBPOSCHANGED;
870 }
871
872 infoPtr->nPageSize=(infoPtr->nRangeMax - infoPtr->nRangeMin)/5;
873 if (infoPtr->nPageSize == 0)
874 infoPtr->nPageSize = 1;
875 TRACKBAR_RecalculateTics (infoPtr);
876
877 if (wParam) TRACKBAR_Refresh(hwnd);
878
879 return 0;
880}
881
882
883static LRESULT
884TRACKBAR_SetRangeMax (HWND hwnd, WPARAM wParam, LPARAM lParam)
885{
886 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
887
888 infoPtr->nRangeMax = (INT)lParam;
889 if (infoPtr->nPos > infoPtr->nRangeMax) {
890 infoPtr->nPos = infoPtr->nRangeMax;
891 infoPtr->flags |=TB_THUMBPOSCHANGED;
892 }
893
894 infoPtr->nPageSize=(infoPtr->nRangeMax - infoPtr->nRangeMin)/5;
895 if (infoPtr->nPageSize == 0)
896 infoPtr->nPageSize = 1;
897 TRACKBAR_RecalculateTics (infoPtr);
898
899 if (wParam) TRACKBAR_Refresh(hwnd);
900
901 return 0;
902}
903
904
905static LRESULT
906TRACKBAR_SetRangeMin (HWND hwnd, WPARAM wParam, LPARAM lParam)
907{
908 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
909
910 infoPtr->nRangeMin = (INT)lParam;
911 if (infoPtr->nPos < infoPtr->nRangeMin) {
912 infoPtr->nPos = infoPtr->nRangeMin;
913 infoPtr->flags |=TB_THUMBPOSCHANGED;
914 }
915
916 infoPtr->nPageSize=(infoPtr->nRangeMax - infoPtr->nRangeMin)/5;
917 if (infoPtr->nPageSize == 0)
918 infoPtr->nPageSize = 1;
919 TRACKBAR_RecalculateTics (infoPtr);
920
921 if (wParam) TRACKBAR_Refresh(hwnd);
922
923 return 0;
924}
925
926
927static LRESULT
928TRACKBAR_SetTicFreq (HWND hwnd, WPARAM wParam)
929{
930 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
931
932 if (GetWindowLongA (hwnd, GWL_STYLE) & TBS_AUTOTICKS)
933 infoPtr->uTicFreq=(UINT) wParam;
934
935 TRACKBAR_RecalculateTics (infoPtr);
936
937 TRACKBAR_Refresh(hwnd); //CB: necessary?
938
939 return 0;
940}
941
942
943static LRESULT
944TRACKBAR_SetSel (HWND hwnd, WPARAM wParam, LPARAM lParam)
945{
946 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
947
948 infoPtr->nSelMin = (INT)LOWORD(lParam);
949 infoPtr->nSelMax = (INT)HIWORD(lParam);
950 infoPtr->flags |=TB_SELECTIONCHANGED;
951
952 if (!GetWindowLongA (hwnd, GWL_STYLE) & TBS_ENABLESELRANGE)
953 return 0;
954
955 if (infoPtr->nSelMin < infoPtr->nRangeMin)
956 infoPtr->nSelMin = infoPtr->nRangeMin;
957 if (infoPtr->nSelMax > infoPtr->nRangeMax)
958 infoPtr->nSelMax = infoPtr->nRangeMax;
959
960 if (wParam) TRACKBAR_Refresh(hwnd);
961
962
963 return 0;
964}
965
966
967static LRESULT
968TRACKBAR_SetSelEnd (HWND hwnd, WPARAM wParam, LPARAM lParam)
969{
970 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
971
972 if (!GetWindowLongA (hwnd, GWL_STYLE) & TBS_ENABLESELRANGE)
973 return 0;
974
975 infoPtr->nSelMax = (INT)lParam;
976 infoPtr->flags |= TB_SELECTIONCHANGED;
977
978 if (infoPtr->nSelMax > infoPtr->nRangeMax)
979 infoPtr->nSelMax = infoPtr->nRangeMax;
980
981 if (wParam) TRACKBAR_Refresh(hwnd);
982
983 return 0;
984}
985
986
987static LRESULT
988TRACKBAR_SetSelStart (HWND hwnd, WPARAM wParam, LPARAM lParam)
989{
990 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
991
992 if (!GetWindowLongA (hwnd, GWL_STYLE) & TBS_ENABLESELRANGE)
993 return 0;
994
995 infoPtr->nSelMin = (INT)lParam;
996 infoPtr->flags |=TB_SELECTIONCHANGED;
997
998 if (infoPtr->nSelMin < infoPtr->nRangeMin)
999 infoPtr->nSelMin = infoPtr->nRangeMin;
1000
1001 if (wParam) TRACKBAR_Refresh(hwnd);
1002
1003 return 0;
1004}
1005
1006
1007static LRESULT
1008TRACKBAR_SetThumbLength (HWND hwnd, WPARAM wParam, LPARAM lParam)
1009{
1010 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1011
1012 if (GetWindowLongA (hwnd, GWL_STYLE) & TBS_FIXEDLENGTH)
1013 infoPtr->uThumbLen = (UINT)wParam;
1014
1015 infoPtr->flags |= TB_THUMBSIZECHANGED;
1016
1017 TRACKBAR_Refresh(hwnd);
1018
1019 return 0;
1020}
1021
1022
1023static LRESULT
1024TRACKBAR_SetTic (HWND hwnd, WPARAM wParam, LPARAM lParam)
1025{
1026 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1027 INT nPos = (INT)lParam;
1028
1029 if ((nPos < infoPtr->nRangeMin) || (nPos> infoPtr->nRangeMax))
1030 return FALSE;
1031
1032 infoPtr->uNumTics++;
1033 infoPtr->tics=COMCTL32_ReAlloc( infoPtr->tics,
1034 (infoPtr->uNumTics)*sizeof (DWORD));
1035 infoPtr->tics[infoPtr->uNumTics-1]=nPos;
1036
1037 TRACKBAR_Refresh(hwnd);
1038
1039 return TRUE;
1040}
1041
1042
1043static LRESULT
1044TRACKBAR_SetTipSide (HWND hwnd, WPARAM wParam, LPARAM lParam)
1045{
1046 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1047 INT fTemp = infoPtr->fLocation;
1048
1049 infoPtr->fLocation = (INT)wParam;
1050
1051 return fTemp;
1052}
1053
1054
1055static LRESULT
1056TRACKBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
1057{
1058 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1059
1060 infoPtr->hwndToolTip = (HWND)wParam;
1061
1062 return 0;
1063}
1064
1065
1066/* case TBM_SETUNICODEFORMAT: */
1067
1068
1069static LRESULT
1070TRACKBAR_InitializeThumb (HWND hwnd)
1071{
1072 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1073
1074 infoPtr->uThumbLen = 23; /* initial thumb length */
1075
1076 TRACKBAR_CalcChannel (hwnd,infoPtr);
1077 TRACKBAR_CalcThumb (hwnd, infoPtr);
1078 infoPtr->flags &= ~TB_SELECTIONCHANGED;
1079
1080 return 0;
1081}
1082
1083
1084static LRESULT
1085TRACKBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
1086{
1087 TRACKBAR_INFO *infoPtr;
1088
1089 infoPtr = (TRACKBAR_INFO *)COMCTL32_Alloc (sizeof(TRACKBAR_INFO));
1090 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
1091
1092 /* set default values */
1093 infoPtr->nRangeMin = 0;
1094 infoPtr->nRangeMax = 100;
1095 infoPtr->nLineSize = 1;
1096 infoPtr->nPageSize = 20;
1097 infoPtr->nSelMin = 0;
1098 infoPtr->nSelMax = 0;
1099 infoPtr->nPos = 0;
1100
1101 infoPtr->uNumTics = 0; /* start and end tic are not included in count*/
1102 infoPtr->uTicFreq = 1;
1103 infoPtr->tics = NULL;
1104 infoPtr->clrBk = GetSysColor (COLOR_BACKGROUND);
1105 infoPtr->hwndNotify = GetParent (hwnd);
1106
1107 TRACKBAR_InitializeThumb (hwnd);
1108
1109 /* Create tooltip control */
1110 if (GetWindowLongA (hwnd, GWL_STYLE) & TBS_TOOLTIPS) {
1111 TTTOOLINFOA ti;
1112
1113 infoPtr->hwndToolTip =
1114 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
1115 CW_USEDEFAULT, CW_USEDEFAULT,
1116 CW_USEDEFAULT, CW_USEDEFAULT,
1117 hwnd, 0, 0, 0);
1118
1119 /* Send NM_TOOLTIPSCREATED notification */
1120 if (infoPtr->hwndToolTip) {
1121 NMTOOLTIPSCREATED nmttc;
1122
1123 nmttc.hdr.hwndFrom = hwnd;
1124 nmttc.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
1125 nmttc.hdr.code = NM_TOOLTIPSCREATED;
1126 nmttc.hwndToolTips = infoPtr->hwndToolTip;
1127
1128 SendMessageA (GetParent (hwnd), WM_NOTIFY,
1129 (WPARAM)nmttc.hdr.idFrom, (LPARAM)&nmttc);
1130 }
1131
1132 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
1133 ti.cbSize = sizeof(TTTOOLINFOA);
1134 ti.uFlags = TTF_IDISHWND | TTF_TRACK;
1135 ti.hwnd = hwnd;
1136 ti.uId = 0;
1137 ti.lpszText = "Test"; /* LPSTR_TEXTCALLBACK */
1138 SetRectEmpty (&ti.rect);
1139
1140 SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA, 0, (LPARAM)&ti);
1141 }
1142
1143 return 0;
1144}
1145
1146
1147static LRESULT
1148TRACKBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1149{
1150 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1151
1152 /* delete tooltip control */
1153 if (infoPtr->hwndToolTip)
1154 DestroyWindow (infoPtr->hwndToolTip);
1155
1156 COMCTL32_Free (infoPtr);
1157 return 0;
1158}
1159
1160
1161static LRESULT
1162TRACKBAR_KillFocus (HWND hwnd, WPARAM wParam, LPARAM lParam)
1163{
1164 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1165
1166// TRACE (trackbar,"\n");
1167
1168 infoPtr->bFocus = FALSE;
1169 infoPtr->flags &= ~TB_DRAG_MODE;
1170
1171 TRACKBAR_Refresh(hwnd); //CB: make changes here
1172
1173 return 0;
1174}
1175
1176
1177static LRESULT
1178TRACKBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
1179{
1180 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1181 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1182 int clickPlace,prevPos,vertical;
1183 DOUBLE clickPos;
1184
1185 SetFocus (hwnd);
1186
1187 vertical = dwStyle & TBS_VERT;
1188 if (vertical)
1189 clickPlace=(INT)HIWORD(lParam);
1190 else
1191 clickPlace=(INT)LOWORD(lParam);
1192
1193 if ((vertical &&
1194 (clickPlace>infoPtr->rcThumb.top) &&
1195 (clickPlace<infoPtr->rcThumb.bottom)) ||
1196 (!vertical &&
1197 (clickPlace>infoPtr->rcThumb.left) &&
1198 (clickPlace<infoPtr->rcThumb.right))) {
1199 infoPtr->flags |= TB_DRAG_MODE;
1200 if (dwStyle & TBS_TOOLTIPS) { /* enable tooltip */
1201 TTTOOLINFOA ti;
1202 POINT pt;
1203
1204 GetCursorPos (&pt);
1205 SendMessageA (infoPtr->hwndToolTip, TTM_TRACKPOSITION, 0,
1206 (LPARAM)MAKELPARAM(pt.x, pt.y));
1207
1208 ti.cbSize = sizeof(TTTOOLINFOA);
1209 ti.uId = 0;
1210 ti.hwnd = (UINT)hwnd;
1211
1212 infoPtr->flags |= TB_SHOW_TOOLTIP;
1213 SetCapture (hwnd);
1214 SendMessageA (infoPtr->hwndToolTip, TTM_TRACKACTIVATE,
1215 (WPARAM)TRUE, (LPARAM)&ti);
1216 }
1217 return 0;
1218 }
1219
1220 clickPos = TRACKBAR_ConvertPlaceToPosition (infoPtr, clickPlace, vertical);
1221 prevPos = infoPtr->nPos;
1222
1223 if (clickPos > prevPos) { /* similar to VK_NEXT */
1224 infoPtr->nPos += infoPtr->nPageSize;
1225 if (infoPtr->nPos > infoPtr->nRangeMax)
1226 infoPtr->nPos = infoPtr->nRangeMax;
1227 TRACKBAR_SendNotify (hwnd, TB_PAGEUP);
1228 } else {
1229 infoPtr->nPos -= infoPtr->nPageSize; /* similar to VK_PRIOR */
1230 if (infoPtr->nPos < infoPtr->nRangeMin)
1231 infoPtr->nPos = infoPtr->nRangeMin;
1232 TRACKBAR_SendNotify (hwnd, TB_PAGEDOWN);
1233 }
1234
1235 if (prevPos!=infoPtr->nPos) {
1236 infoPtr->flags |= TB_THUMBPOSCHANGED;
1237 TRACKBAR_Update(hwnd,prevPos);
1238 }
1239
1240 return 0;
1241}
1242
1243
1244static LRESULT
1245TRACKBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1246{
1247 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1248
1249 TRACKBAR_SendNotify (hwnd, TB_ENDTRACK);
1250
1251 if (infoPtr->flags & TB_DRAG_MODE)
1252 {
1253 infoPtr->flags &= ~TB_DRAG_MODE;
1254 ReleaseCapture ();
1255 }
1256
1257 if (GetWindowLongA (hwnd, GWL_STYLE) & TBS_TOOLTIPS) { /* disable tooltip */
1258 TTTOOLINFOA ti;
1259
1260 ti.cbSize = sizeof(TTTOOLINFOA);
1261 ti.uId = 0;
1262 ti.hwnd = (UINT)hwnd;
1263
1264 infoPtr->flags &= ~TB_SHOW_TOOLTIP;
1265 SendMessageA (infoPtr->hwndToolTip, TTM_TRACKACTIVATE,
1266 (WPARAM)FALSE, (LPARAM)&ti);
1267 }
1268
1269 //TRACKBAR_Refresh(hwnd); //CB: nothing changed
1270
1271 return 0;
1272}
1273
1274
1275static LRESULT
1276TRACKBAR_CaptureChanged (HWND hwnd, WPARAM wParam, LPARAM lParam)
1277{
1278 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1279
1280 if (infoPtr->flags & TB_DRAGPOSVALID) {
1281 int lastPos = infoPtr->nPos;
1282 infoPtr->nPos=infoPtr->dragPos;
1283 TRACKBAR_Update(hwnd,lastPos);
1284 }
1285
1286 infoPtr->flags &= ~ TB_DRAGPOSVALID;
1287
1288 TRACKBAR_SendNotify (hwnd, TB_ENDTRACK);
1289 return 0;
1290}
1291
1292
1293static LRESULT
1294TRACKBAR_Paint (HWND hwnd, WPARAM wParam)
1295{
1296 HDC hdc;
1297 PAINTSTRUCT ps;
1298
1299 hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
1300 TRACKBAR_Draw(hwnd,hdc,0,FALSE);
1301 if(!wParam)
1302 EndPaint (hwnd, &ps);
1303 return 0;
1304}
1305
1306
1307static LRESULT
1308TRACKBAR_SetFocus (HWND hwnd, WPARAM wParam, LPARAM lParam)
1309{
1310 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1311
1312// TRACE (trackbar,"\n");
1313 infoPtr->bFocus = TRUE;
1314
1315 TRACKBAR_Refresh(hwnd); //CB: make changes here
1316
1317 return 0;
1318}
1319
1320
1321static LRESULT
1322TRACKBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
1323{
1324 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1325
1326 TRACKBAR_CalcChannel (hwnd, infoPtr);
1327 TRACKBAR_AlignBuddies (hwnd, infoPtr);
1328
1329 return 0;
1330}
1331
1332
1333static BOOL
1334TRACKBAR_SendNotify (HWND hwnd, UINT code)
1335{
1336// TRACE (trackbar, "%x\n",code);
1337
1338 if (GetWindowLongA (hwnd, GWL_STYLE) & TBS_VERT)
1339 return (BOOL) SendMessageA (GetParent (hwnd),
1340 WM_VSCROLL, (WPARAM)code, (LPARAM)hwnd);
1341
1342 return (BOOL) SendMessageA (GetParent (hwnd),
1343 WM_HSCROLL, (WPARAM)code, (LPARAM)hwnd);
1344}
1345
1346
1347static LRESULT
1348TRACKBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
1349{
1350 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1351 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1352 SHORT clickPlace;
1353 DOUBLE dragPos;
1354 char buf[80];
1355 INT lastDragPos;
1356
1357// TRACE (trackbar, "%x\n",wParam);
1358
1359 if (dwStyle & TBS_VERT)
1360 clickPlace=(SHORT)HIWORD(lParam);
1361 else
1362 clickPlace=(SHORT)LOWORD(lParam);
1363
1364 if (!(infoPtr->flags & TB_DRAG_MODE))
1365 return TRUE;
1366
1367 SetCapture (hwnd);
1368 lastDragPos = infoPtr->dragPos;
1369 dragPos = TRACKBAR_ConvertPlaceToPosition (infoPtr, clickPlace,
1370 dwStyle & TBS_VERT);
1371 if (dragPos > ((INT)dragPos) + 0.5)
1372 infoPtr->dragPos = dragPos + 1;
1373 else
1374 infoPtr->dragPos = dragPos;
1375
1376 infoPtr->flags |= TB_DRAGPOSVALID;
1377 TRACKBAR_SendNotify (hwnd, TB_THUMBTRACK | (infoPtr->nPos>>16));
1378
1379 if (infoPtr->flags & TB_SHOW_TOOLTIP) {
1380 POINT pt;
1381 TTTOOLINFOA ti;
1382
1383 ti.cbSize = sizeof(TTTOOLINFOA);
1384 ti.hwnd = hwnd;
1385 ti.uId = 0;
1386 ti.hinst=0;
1387 sprintf (buf,"%d",infoPtr->nPos);
1388 ti.lpszText = (LPSTR) buf;
1389 GetCursorPos (&pt);
1390
1391 if (dwStyle & TBS_VERT) {
1392 SendMessageA (infoPtr->hwndToolTip, TTM_TRACKPOSITION,
1393 0, (LPARAM)MAKELPARAM(pt.x+5, pt.y+15));
1394 } else {
1395 SendMessageA (infoPtr->hwndToolTip, TTM_TRACKPOSITION,
1396 0, (LPARAM)MAKELPARAM(pt.x+15, pt.y+5));
1397 }
1398 SendMessageA (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTA,
1399 0, (LPARAM)&ti);
1400 }
1401
1402 TRACKBAR_Update(hwnd,lastDragPos);
1403 UpdateWindow (hwnd);
1404
1405 return TRUE;
1406}
1407
1408
1409static LRESULT
1410TRACKBAR_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
1411{
1412 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1413 INT pos;
1414
1415// TRACE (trackbar, "%x\n",wParam);
1416
1417 pos=infoPtr->nPos;
1418 switch (wParam) {
1419 case VK_LEFT:
1420 case VK_UP:
1421 if (infoPtr->nPos == infoPtr->nRangeMin) return FALSE;
1422 infoPtr->nPos -= infoPtr->nLineSize;
1423 if (infoPtr->nPos < infoPtr->nRangeMin)
1424 infoPtr->nPos = infoPtr->nRangeMin;
1425 TRACKBAR_SendNotify (hwnd, TB_LINEUP);
1426 break;
1427 case VK_RIGHT:
1428 case VK_DOWN:
1429 if (infoPtr->nPos == infoPtr->nRangeMax) return FALSE;
1430 infoPtr->nPos += infoPtr->nLineSize;
1431 if (infoPtr->nPos > infoPtr->nRangeMax)
1432 infoPtr->nPos = infoPtr->nRangeMax;
1433 TRACKBAR_SendNotify (hwnd, TB_LINEDOWN);
1434 break;
1435 case VK_NEXT:
1436 if (infoPtr->nPos == infoPtr->nRangeMax) return FALSE;
1437 infoPtr->nPos += infoPtr->nPageSize;
1438 if (infoPtr->nPos > infoPtr->nRangeMax)
1439 infoPtr->nPos = infoPtr->nRangeMax;
1440 TRACKBAR_SendNotify (hwnd, TB_PAGEUP);
1441 break;
1442 case VK_PRIOR:
1443 if (infoPtr->nPos == infoPtr->nRangeMin) return FALSE;
1444 infoPtr->nPos -= infoPtr->nPageSize;
1445 if (infoPtr->nPos < infoPtr->nRangeMin)
1446 infoPtr->nPos = infoPtr->nRangeMin;
1447 TRACKBAR_SendNotify (hwnd, TB_PAGEDOWN);
1448 break;
1449 case VK_HOME:
1450 if (infoPtr->nPos == infoPtr->nRangeMin) return FALSE;
1451 infoPtr->nPos = infoPtr->nRangeMin;
1452 TRACKBAR_SendNotify (hwnd, TB_TOP);
1453 break;
1454 case VK_END:
1455 if (infoPtr->nPos == infoPtr->nRangeMax) return FALSE;
1456 infoPtr->nPos = infoPtr->nRangeMax;
1457 TRACKBAR_SendNotify (hwnd, TB_BOTTOM);
1458 break;
1459 }
1460
1461 if (pos!=infoPtr->nPos) {
1462 infoPtr->flags |=TB_THUMBPOSCHANGED;
1463 TRACKBAR_Update(hwnd,pos);
1464 }
1465
1466 return TRUE;
1467}
1468
1469
1470static LRESULT
1471TRACKBAR_KeyUp (HWND hwnd, WPARAM wParam)
1472{
1473 switch (wParam) {
1474 case VK_LEFT:
1475 case VK_UP:
1476 case VK_RIGHT:
1477 case VK_DOWN:
1478 case VK_NEXT:
1479 case VK_PRIOR:
1480 case VK_HOME:
1481 case VK_END:
1482 TRACKBAR_SendNotify (hwnd, TB_ENDTRACK);
1483 }
1484 return TRUE;
1485}
1486
1487
1488LRESULT WINAPI
1489TRACKBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1490{
1491 switch (uMsg)
1492 {
1493 case TBM_CLEARSEL:
1494 return TRACKBAR_ClearSel (hwnd, wParam, lParam);
1495
1496 case TBM_CLEARTICS:
1497 return TRACKBAR_ClearTics (hwnd, wParam, lParam);
1498
1499 case TBM_GETBUDDY:
1500 return TRACKBAR_GetBuddy (hwnd, wParam, lParam);
1501
1502 case TBM_GETCHANNELRECT:
1503 return TRACKBAR_GetChannelRect (hwnd, wParam, lParam);
1504
1505 case TBM_GETLINESIZE:
1506 return TRACKBAR_GetLineSize (hwnd, wParam, lParam);
1507
1508 case TBM_GETNUMTICS:
1509 return TRACKBAR_GetNumTics (hwnd, wParam, lParam);
1510
1511 case TBM_GETPAGESIZE:
1512 return TRACKBAR_GetPageSize (hwnd, wParam, lParam);
1513
1514 case TBM_GETPOS:
1515 return TRACKBAR_GetPos (hwnd, wParam, lParam);
1516
1517 case TBM_GETPTICS:
1518 return TRACKBAR_GetPTics (hwnd);
1519
1520 case TBM_GETRANGEMAX:
1521 return TRACKBAR_GetRangeMax (hwnd, wParam, lParam);
1522
1523 case TBM_GETRANGEMIN:
1524 return TRACKBAR_GetRangeMin (hwnd, wParam, lParam);
1525
1526 case TBM_GETSELEND:
1527 return TRACKBAR_GetSelEnd (hwnd, wParam, lParam);
1528
1529 case TBM_GETSELSTART:
1530 return TRACKBAR_GetSelStart (hwnd, wParam, lParam);
1531
1532 case TBM_GETTHUMBLENGTH:
1533 return TRACKBAR_GetThumbLength (hwnd, wParam, lParam);
1534
1535 case TBM_GETTHUMBRECT:
1536 return TRACKBAR_GetThumbRect (hwnd, wParam, lParam);
1537
1538 case TBM_GETTIC:
1539 return TRACKBAR_GetTic (hwnd, wParam, lParam);
1540
1541 case TBM_GETTICPOS:
1542 return TRACKBAR_GetTicPos (hwnd, wParam, lParam);
1543
1544 case TBM_GETTOOLTIPS:
1545 return TRACKBAR_GetToolTips (hwnd, wParam, lParam);
1546
1547/* case TBM_GETUNICODEFORMAT: */
1548
1549 case TBM_SETBUDDY:
1550 return TRACKBAR_SetBuddy (hwnd, wParam, lParam);
1551
1552 case TBM_SETLINESIZE:
1553 return TRACKBAR_SetLineSize (hwnd, wParam, lParam);
1554
1555 case TBM_SETPAGESIZE:
1556 return TRACKBAR_SetPageSize (hwnd, wParam, lParam);
1557
1558 case TBM_SETPOS:
1559 return TRACKBAR_SetPos (hwnd, wParam, lParam);
1560
1561 case TBM_SETRANGE:
1562 return TRACKBAR_SetRange (hwnd, wParam, lParam);
1563
1564 case TBM_SETRANGEMAX:
1565 return TRACKBAR_SetRangeMax (hwnd, wParam, lParam);
1566
1567 case TBM_SETRANGEMIN:
1568 return TRACKBAR_SetRangeMin (hwnd, wParam, lParam);
1569
1570 case TBM_SETSEL:
1571 return TRACKBAR_SetSel (hwnd, wParam, lParam);
1572
1573 case TBM_SETSELEND:
1574 return TRACKBAR_SetSelEnd (hwnd, wParam, lParam);
1575
1576 case TBM_SETSELSTART:
1577 return TRACKBAR_SetSelStart (hwnd, wParam, lParam);
1578
1579 case TBM_SETTHUMBLENGTH:
1580 return TRACKBAR_SetThumbLength (hwnd, wParam, lParam);
1581
1582 case TBM_SETTIC:
1583 return TRACKBAR_SetTic (hwnd, wParam, lParam);
1584
1585 case TBM_SETTICFREQ:
1586 return TRACKBAR_SetTicFreq (hwnd, wParam);
1587
1588 case TBM_SETTIPSIDE:
1589 return TRACKBAR_SetTipSide (hwnd, wParam, lParam);
1590
1591 case TBM_SETTOOLTIPS:
1592 return TRACKBAR_SetToolTips (hwnd, wParam, lParam);
1593
1594/* case TBM_SETUNICODEFORMAT: */
1595
1596
1597 case WM_CAPTURECHANGED:
1598 return TRACKBAR_CaptureChanged (hwnd, wParam, lParam);
1599
1600 case WM_CREATE:
1601 return TRACKBAR_Create (hwnd, wParam, lParam);
1602
1603 case WM_DESTROY:
1604 return TRACKBAR_Destroy (hwnd, wParam, lParam);
1605
1606/* case WM_ENABLE: */
1607
1608/* case WM_ERASEBKGND: */
1609/* return 0; */
1610
1611 case WM_GETDLGCODE:
1612 return DLGC_WANTARROWS;
1613
1614 case WM_KEYDOWN:
1615 return TRACKBAR_KeyDown (hwnd, wParam, lParam);
1616
1617 case WM_KEYUP:
1618 return TRACKBAR_KeyUp (hwnd, wParam);
1619
1620 case WM_KILLFOCUS:
1621 return TRACKBAR_KillFocus (hwnd, wParam, lParam);
1622
1623 case WM_LBUTTONDOWN:
1624 return TRACKBAR_LButtonDown (hwnd, wParam, lParam);
1625
1626 case WM_LBUTTONUP:
1627 return TRACKBAR_LButtonUp (hwnd, wParam, lParam);
1628
1629 case WM_MOUSEMOVE:
1630 return TRACKBAR_MouseMove (hwnd, wParam, lParam);
1631
1632 case WM_PAINT:
1633 return TRACKBAR_Paint (hwnd, wParam);
1634
1635 case WM_SETFOCUS:
1636 return TRACKBAR_SetFocus (hwnd, wParam, lParam);
1637
1638 case WM_SIZE:
1639 return TRACKBAR_Size (hwnd, wParam, lParam);
1640
1641 case WM_WININICHANGE:
1642 return TRACKBAR_InitializeThumb (hwnd);
1643
1644 default:
1645// if (uMsg >= WM_USER)
1646// ERR (trackbar, "unknown msg %04x wp=%08x lp=%08lx\n",
1647// uMsg, wParam, lParam);
1648 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
1649 }
1650 return 0;
1651}
1652
1653
1654VOID
1655TRACKBAR_Register (VOID)
1656{
1657 WNDCLASSA wndClass;
1658
1659 if (GlobalFindAtomA (TRACKBAR_CLASSA)) return;
1660
1661 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
1662 wndClass.style = CS_GLOBALCLASS;
1663 wndClass.lpfnWndProc = (WNDPROC)TRACKBAR_WindowProc;
1664 wndClass.cbClsExtra = 0;
1665 wndClass.cbWndExtra = sizeof(TRACKBAR_INFO *);
1666 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
1667 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
1668 wndClass.lpszClassName = TRACKBAR_CLASSA;
1669
1670 RegisterClassA (&wndClass);
1671}
1672
1673
1674VOID
1675TRACKBAR_Unregister (VOID)
1676{
1677 if (GlobalFindAtomA (TRACKBAR_CLASSA))
1678 UnregisterClassA (TRACKBAR_CLASSA, (HINSTANCE)NULL);
1679}
1680
Note: See TracBrowser for help on using the repository browser.