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

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

buddy fix, improved mouse down on thumb

File size: 68.7 KB
Line 
1/* $Id: trackbar.c,v 1.16 1999-08-22 13:20:26 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 * Status: ready to use
12 * Version: 5.00
13 */
14
15#include "winbase.h"
16#include "commctrl.h"
17#include "trackbar.h"
18#include <stdio.h>
19
20
21#define TRACKBAR_GetInfoPtr(hwnd) ((TRACKBAR_INFO*)GetWindowLongA(hwnd,0))
22
23
24/* Used by TRACKBAR_Draw to find out which parts of the control
25 need to be recalculated */
26
27#define TB_THUMBPOSCHANGED 1
28#define TB_THUMBSIZECHANGED 2
29#define TB_THUMBCHANGED (TB_THUMBPOSCHANGED | TB_THUMBPOSCHANGED)
30#define TB_SELECTIONCHANGED 4
31#define TB_DRAG_MODE 16 /* we're dragging the slider */
32#define TB_DRAGPOSVALID 32 /* current Position is in dragPos */
33#define TB_SCROLL_MODE 64 /* WM_TIMER scroll mode */
34#define TB_SHOW_TOOLTIP 128 /* tooltip-style enabled and tooltip on */
35
36/* helper defines for TRACKBAR_DrawTic */
37#define TIC_LEFTEDGE 0x20
38#define TIC_RIGHTEDGE 0x40
39#define TIC_EDGE (TIC_LEFTEDGE | TIC_RIGHTEDGE)
40#define TIC_SELECTIONMARKMAX 0x80
41#define TIC_SELECTIONMARKMIN 0x100
42#define TIC_SELECTIONMARK (TIC_SELECTIONMARKMAX | TIC_SELECTIONMARKMIN)
43
44/* size calculation */
45
46#define BORDER_SIZE 2
47
48#define SCALE_SIZE 4
49#define SCALE_SPACE 1
50
51#define THUMB_LEN 23
52#define THUMB_MINLEN 4
53
54#define CHANNEL_NOSEL_HEIGHT 4 //min no sel height
55#define CHANNEL_MIN_HEIGHT 6 //min sel height
56#define CHANNEL_THUMB_DIFF 8 //sel thumb, channel difference
57#define CHANNEL_SPACE 8
58#define CHANNEL_SCALE_SPACE SCALE_SIZE+SCALE_SPACE+BORDER_SIZE
59#define CHANNEL_THUMB_SPACE BORDER_SIZE
60
61/* scroll mode */
62
63#define SCROLL_TIME 500 //ms
64#define SCROLL_TIMER_ID 1
65
66/* Tooltips */
67
68#define TOOLTIP_XSPACE 5
69#define TOOLTIP_YSPACE 5
70
71static BOOL TRACKBAR_SendNotify (HWND hwnd, UINT code);
72
73static void TRACKBAR_RecalculateTics (HWND hwnd,TRACKBAR_INFO *infoPtr,BOOL restoreOld)
74{
75 INT i,tic,nrTics;
76 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
77
78 if (dwStyle & TBS_NOTICKS) //no ticks
79 {
80 COMCTL32_Free(infoPtr->tics);
81 infoPtr->tics = NULL;
82
83 infoPtr->uNumTics = 0;
84 return;
85 }
86
87 if (restoreOld && !(dwStyle & TBS_AUTOTICKS) && infoPtr->tics != NULL)
88 { //check old ticks
89 LPLONG oldTics = COMCTL32_Alloc(infoPtr->uNumTics*sizeof(DWORD));
90 INT count = 0;
91
92 for (i = 0;i < infoPtr->uNumTics;i++)
93 {
94 if (infoPtr->tics[i] >= infoPtr->nRangeMin && infoPtr->tics[i] <= infoPtr->nRangeMax)
95 {
96 oldTics[count] = infoPtr->tics[i];
97 count++;
98 }
99 }
100
101 COMCTL32_Free(infoPtr->tics);
102 infoPtr->tics = COMCTL32_ReAlloc(oldTics,count*sizeof(DWORD));
103 infoPtr->uNumTics = count;
104
105 return;
106 }
107
108 if (infoPtr->uTicFreq && infoPtr->nRangeMax > infoPtr->nRangeMin && (dwStyle & TBS_AUTOTICKS))
109 {
110 //Tics without start and end tic
111 nrTics = (infoPtr->nRangeMax-infoPtr->nRangeMin)/infoPtr->uTicFreq-1;
112 if (nrTics <= 0)
113 {
114 COMCTL32_Free(infoPtr->tics);
115 infoPtr->tics = NULL;
116 infoPtr->uNumTics = 0;
117 return;
118 }
119 } else
120 {
121 COMCTL32_Free(infoPtr->tics);
122 infoPtr->tics = NULL;
123 infoPtr->uNumTics = 0;
124 return;
125 }
126
127 if (nrTics != infoPtr->uNumTics)
128 {
129 COMCTL32_Free(infoPtr->tics);
130 infoPtr->tics = COMCTL32_Alloc(nrTics*sizeof(DWORD));
131 infoPtr->uNumTics = nrTics;
132 }
133
134 tic = infoPtr->nRangeMin+infoPtr->uTicFreq; //start not included
135 for (i = 0;i < nrTics;i++)
136 {
137 infoPtr->tics[i] = tic;
138 tic += infoPtr->uTicFreq;
139 }
140}
141
142
143/* converts from physical (mouse) position to logical position
144 (in range of trackbar) */
145
146static DOUBLE
147TRACKBAR_ConvertPlaceToPosition(TRACKBAR_INFO *infoPtr,int place,int vertical)
148{
149 double range,width,pos;
150
151 range = infoPtr->nRangeMax-infoPtr->nRangeMin;
152 if (vertical)
153 {
154 width = infoPtr->rcChannel.bottom-infoPtr->rcChannel.top;
155 pos = infoPtr->nRangeMin+(range*(place-infoPtr->rcChannel.top))/width;
156 } else
157 {
158 width = infoPtr->rcChannel.right-infoPtr->rcChannel.left;
159 pos = infoPtr->nRangeMin+(range*(place-infoPtr->rcChannel.left))/width;
160 }
161
162 if (pos > infoPtr->nRangeMax) pos = infoPtr->nRangeMax;
163 else if (pos < infoPtr->nRangeMin) pos = infoPtr->nRangeMin;
164
165// TRACE (trackbar,"%.2f\n",pos);
166 return pos;
167}
168
169
170static VOID
171TRACKBAR_CalcChannel (HWND hwnd,TRACKBAR_INFO *infoPtr)
172{
173 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
174 INT channelSize;
175 RECT lpRect,*channel = &infoPtr->rcChannel;
176 INT thumbDiff;
177
178 GetClientRect(hwnd,&lpRect);
179
180 if (dwStyle & TBS_ENABLESELRANGE) channelSize = MAX(infoPtr->uThumbLen-CHANNEL_THUMB_DIFF,CHANNEL_MIN_HEIGHT);
181 else channelSize = CHANNEL_NOSEL_HEIGHT;
182
183 thumbDiff = (infoPtr->uThumbLen-channelSize)/2;
184
185 if (dwStyle & TBS_VERT)
186 {
187 channel->top = lpRect.top+CHANNEL_SPACE;
188 channel->bottom = lpRect.bottom-CHANNEL_SPACE;
189
190 if (dwStyle & TBS_BOTH || dwStyle & TBS_NOTICKS)
191 { //center
192 channel->left = (lpRect.right-channelSize)/2;
193 channel->right = (lpRect.right+channelSize)/2;
194 } else if (dwStyle & TBS_LEFT)
195 {
196 channel->left = lpRect.left+thumbDiff+CHANNEL_SCALE_SPACE;
197 channel->right = channel->left+channelSize;
198 } else
199 { //Right, align left
200 channel->left = lpRect.left+thumbDiff+CHANNEL_THUMB_SPACE;
201 channel->right = channel->left+channelSize;
202 }
203 } else
204 {
205 channel->left = lpRect.left+CHANNEL_SPACE;
206 channel->right = lpRect.right-CHANNEL_SPACE;
207 if (dwStyle & TBS_BOTH || dwStyle & TBS_NOTICKS)
208 { //center
209 channel->top = (lpRect.bottom-channelSize)/2;
210 channel->bottom = (lpRect.bottom+channelSize)/2;
211 } else if (dwStyle & TBS_TOP)
212 {
213 channel->top = lpRect.top+thumbDiff+CHANNEL_SCALE_SPACE;
214 channel->bottom = channel->top+channelSize;
215 } else
216 { //Bottom, align top
217 channel->top = lpRect.top+thumbDiff+CHANNEL_THUMB_SPACE;
218 channel->bottom = channel->top+channelSize;
219 }
220 }
221}
222
223//Calculate thumb size
224
225static VOID
226TRACKBAR_CalcThumb(HWND hwnd,TRACKBAR_INFO *infoPtr)
227{
228 RECT *thumb;
229 RECT *fullThumb;
230 int range, width;
231 int x,y;
232 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
233 int thumbFactor = 2;
234
235 thumb = &infoPtr->rcThumb;
236 fullThumb = &infoPtr->rcFullThumb;
237 range = infoPtr->nRangeMax-infoPtr->nRangeMin;
238 if (dwStyle & TBS_VERT)
239 {
240 width = infoPtr->rcChannel.bottom-infoPtr->rcChannel.top;
241 y = infoPtr->uThumbLen/thumbFactor; //thumb height
242 if (y%2 == 1) y++; //for real arrow
243 thumb->top = infoPtr->rcChannel.top+(width*(infoPtr->nPos-infoPtr->nRangeMin))/range-y/2; //centered
244 thumb->bottom = thumb->top+y;
245 //centered, no arrows
246 thumb->left = infoPtr->rcChannel.left-(infoPtr->uThumbLen-(infoPtr->rcChannel.right-infoPtr->rcChannel.left))/2;
247 thumb->right = thumb->left+infoPtr->uThumbLen;
248 CopyRect(fullThumb,thumb);
249 if (dwStyle & TBS_BOTH) return;
250 x = y/2; //arrow width
251 if (dwStyle & TBS_LEFT) thumb->left += x; else thumb->right -= x;
252 } else
253 {
254 width = infoPtr->rcChannel.right-infoPtr->rcChannel.left;
255 x = infoPtr->uThumbLen/thumbFactor; //thumb width
256 if (x%2 == 1) x++; //for real arrow
257 thumb->left = infoPtr->rcChannel.left+(width*(infoPtr->nPos-infoPtr->nRangeMin))/range-x/2; //centered
258 thumb->right = thumb->left+x;
259 //centered, no arrows
260 thumb->top = infoPtr->rcChannel.top-(infoPtr->uThumbLen-(infoPtr->rcChannel.bottom-infoPtr->rcChannel.top))/2;
261 thumb->bottom = thumb->top+infoPtr->uThumbLen;
262 CopyRect(fullThumb,thumb);
263 if (dwStyle & TBS_BOTH) return;
264 y = x/2; //arrow height
265 if (dwStyle & TBS_TOP) thumb->top += y; else thumb->bottom -= y;
266 }
267}
268
269static VOID
270TRACKBAR_CalcSelection (HWND hwnd, TRACKBAR_INFO *infoPtr)
271{
272 RECT *selection;
273 int range,width,height;
274 int selMin = infoPtr->nSelMin-infoPtr->nRangeMin; //relative to nRangeMin
275 int selMax = infoPtr->nSelMax-infoPtr->nRangeMin; //dito
276
277 selection = &infoPtr->rcSelection;
278 range = infoPtr->nRangeMax-infoPtr->nRangeMin;
279
280 if (range <= 0 || selMin == selMax) SetRectEmpty(selection);
281 else
282 if (!(GetWindowLongA(hwnd, GWL_STYLE) & TBS_VERT))
283 { //Horizontal
284 width = infoPtr->rcChannel.right-infoPtr->rcChannel.left;
285 selection->left = infoPtr->rcChannel.left+(width*selMin)/range;
286 selection->right = infoPtr->rcChannel.left+(width*selMax)/range;
287 selection->top = infoPtr->rcChannel.top+2;
288 selection->bottom = infoPtr->rcChannel.bottom-2;
289 } else
290 { //Vertical
291 height = infoPtr->rcChannel.bottom-infoPtr->rcChannel.top;
292 selection->top = infoPtr->rcChannel.top+(height*selMin)/range;
293 selection->bottom = infoPtr->rcChannel.top+(height*selMax)/range;
294 selection->left = infoPtr->rcChannel.left+2;
295 selection->right = infoPtr->rcChannel.right-2;
296 }
297}
298
299/* Trackbar drawing code */
300
301/* ticPos is in tic-units, not in pixels */
302
303static VOID
304TRACKBAR_DrawHorizTic (TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos,
305 int flags, COLORREF clrTic)
306{
307 RECT rcChannel = infoPtr->rcChannel;
308 int x,y,width,range,side;
309
310 range = infoPtr->nRangeMax-infoPtr->nRangeMin;
311 width = rcChannel.right-rcChannel.left;
312
313 if (flags & TBS_TOP)
314 {
315 y = infoPtr->rcFullThumb.top-SCALE_SPACE-1;
316 side = -1;
317 } else
318 {
319 y = infoPtr->rcFullThumb.bottom+SCALE_SPACE+1;
320 side = 1;
321 }
322 if (flags & TIC_SELECTIONMARK)
323 {
324 ticPos -= infoPtr->nRangeMin; //relative to nRangeMin
325 if (flags & TIC_SELECTIONMARKMIN) x = rcChannel.left+(width*ticPos)/range - 1;
326 else x = rcChannel.left+(width*ticPos)/range+1;
327
328 //first line
329 SetPixel(hdc,x,y+1*side,clrTic);
330 SetPixel(hdc,x,y+2*side,clrTic);
331 //point
332 if (flags & TIC_SELECTIONMARKMIN) x--; else x++;
333 SetPixel(hdc,x,y+2*side,clrTic);
334
335 return;
336 }
337
338 if ((ticPos > infoPtr->nRangeMin) && (ticPos < infoPtr->nRangeMax))
339 {
340 ticPos -= infoPtr->nRangeMin; //relative to nRangeMin
341 x = rcChannel.left+(width*ticPos)/range;
342 SetPixel(hdc,x,y,clrTic); //base
343 SetPixel(hdc,x,y+1*side,clrTic);
344 SetPixel(hdc,x,y+2*side,clrTic);
345 }
346
347 if (flags & TIC_EDGE)
348 {
349 if (flags & TIC_LEFTEDGE) x = rcChannel.left;
350 else x = rcChannel.right;
351
352 SetPixel(hdc,x,y,clrTic); //base
353 SetPixel(hdc,x,y+1*side,clrTic);
354 SetPixel(hdc,x,y+2*side,clrTic);
355 SetPixel(hdc,x,y+3*side,clrTic);
356 }
357}
358
359static VOID TRACKBAR_FillHorzTics(TRACKBAR_INFO *infoPtr,HDC hdc,int flags,COLORREF clrTic)
360{
361 RECT rect;
362 INT range = infoPtr->nRangeMax-infoPtr->nRangeMin;
363 INT width = infoPtr->rcChannel.right-infoPtr->rcChannel.left;
364 HBRUSH hbr = CreateSolidBrush(clrTic);
365
366 if (flags & TBS_TOP)
367 {
368 rect.bottom = infoPtr->rcFullThumb.top-SCALE_SPACE-1+1;
369 rect.top = rect.bottom-3;
370 } else
371 {
372 rect.top = infoPtr->rcFullThumb.bottom+SCALE_SPACE+1;
373 rect.bottom = rect.top+3;
374 }
375 rect.left = infoPtr->rcChannel.left+(width*(infoPtr->tics[0]-infoPtr->nRangeMin))/range;
376 rect.right = infoPtr->rcChannel.left+(width*(infoPtr->tics[infoPtr->uNumTics-1]-infoPtr->nRangeMin))/range+1;
377
378 FillRect(hdc,&rect,hbr);
379 DeleteObject(hbr);
380}
381
382static VOID
383TRACKBAR_DrawVertTic (TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos,
384 int flags, COLORREF clrTic)
385{
386 RECT rcChannel = infoPtr->rcChannel;
387 int x,y,width,range,side;
388
389 range = infoPtr->nRangeMax-infoPtr->nRangeMin;
390 width = rcChannel.bottom-rcChannel.top;
391
392 if (flags & TBS_LEFT)
393 {
394 x = infoPtr->rcFullThumb.left-SCALE_SPACE-1;
395 side = -1;
396 } else
397 {
398 x = infoPtr->rcFullThumb.right+SCALE_SPACE+1;
399 side = 1;
400 }
401
402
403 if (flags & TIC_SELECTIONMARK)
404 {
405 ticPos -= infoPtr->nRangeMin;
406 if (flags & TIC_SELECTIONMARKMIN) y = rcChannel.top+(width*ticPos)/range-1;
407 else y = rcChannel.top+(width*ticPos)/range+1;
408
409 //first line
410 SetPixel(hdc,x+1*side,y,clrTic);
411 SetPixel(hdc,x+2*side,y,clrTic);
412 //point
413 if (flags & TIC_SELECTIONMARKMIN) y--; else y++;
414 SetPixel(hdc,x+2*side,y,clrTic);
415
416 return;
417 }
418
419 if ((ticPos>infoPtr->nRangeMin) && (ticPos<infoPtr->nRangeMax))
420 {
421 ticPos -= infoPtr->nRangeMin;
422 y = rcChannel.top+(width*ticPos)/range;
423 SetPixel (hdc,x, y,clrTic); //base
424 SetPixel (hdc,x+1*side,y,clrTic);
425 SetPixel (hdc,x+2*side,y,clrTic);
426 }
427
428 if (flags & TIC_EDGE)
429 {
430 if (flags & TIC_LEFTEDGE) y = rcChannel.top;
431 else y = rcChannel.bottom;
432
433 SetPixel (hdc,x,y,clrTic); //base
434 SetPixel (hdc,x+1*side,y,clrTic);
435 SetPixel (hdc,x+2*side,y,clrTic);
436 SetPixel (hdc,x+3*side,y,clrTic);
437 }
438}
439
440static VOID TRACKBAR_FillVertTics(TRACKBAR_INFO *infoPtr,HDC hdc,int flags,COLORREF clrTic)
441{
442 RECT rect;
443 INT range = infoPtr->nRangeMax-infoPtr->nRangeMin;
444 INT width = infoPtr->rcChannel.bottom-infoPtr->rcChannel.top;
445 HBRUSH hbr = CreateSolidBrush(clrTic);
446
447 if (flags & TBS_TOP)
448 {
449 rect.right = infoPtr->rcFullThumb.left-SCALE_SPACE-1+1;
450 rect.left = rect.right-3;
451 } else
452 {
453 rect.left = infoPtr->rcFullThumb.right+SCALE_SPACE+1;
454 rect.right = rect.left+3;
455 }
456 rect.top = infoPtr->rcChannel.top+(width*(infoPtr->tics[0]-infoPtr->nRangeMin))/range;
457 rect.bottom = infoPtr->rcChannel.top+(width*(infoPtr->tics[infoPtr->uNumTics-1]-infoPtr->nRangeMin))/range+1;
458
459 FillRect(hdc,&rect,hbr);
460 DeleteObject(hbr);
461}
462
463static VOID
464TRACKBAR_DrawTics (TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos,
465 int flags, COLORREF clrTic)
466{
467 if (flags & TBS_VERT)
468 {
469 if ((flags & TBS_LEFT) || (flags & TBS_BOTH))
470 TRACKBAR_DrawVertTic (infoPtr,hdc,ticPos,flags | TBS_LEFT ,clrTic);
471 //TBS_RIGHT == default
472 if (!(flags & TBS_LEFT) || (flags & TBS_BOTH))
473 TRACKBAR_DrawVertTic(infoPtr,hdc,ticPos,flags & ~TBS_LEFT,clrTic);
474 } else
475 {
476 if ((flags & TBS_TOP) || (flags & TBS_BOTH))
477 TRACKBAR_DrawHorizTic(infoPtr,hdc,ticPos,flags | TBS_TOP,clrTic);
478 //TBS_BOTTOM == default
479 if (!(flags & TBS_TOP) || (flags & TBS_BOTH))
480 TRACKBAR_DrawHorizTic(infoPtr,hdc,ticPos,flags & ~TBS_TOP,clrTic);
481 }
482}
483
484//draw thumb, call only from draw!
485
486static VOID TRACKBAR_DrawThumb(TRACKBAR_INFO *infoPtr,HDC hdc,DWORD dwStyle)
487{
488 if (!(dwStyle & TBS_NOTHUMB))
489 {
490
491 HBRUSH hbr,hbrOld;
492 RECT thumb = infoPtr->rcThumb;
493
494 if (infoPtr->flags & TB_DRAG_MODE) hbr = CreateSolidBrush(GetSysColor(COLOR_3DHILIGHT));
495 else hbr = CreateSolidBrush(GetSysColor(COLOR_3DFACE));
496 hbrOld = SelectObject(hdc,hbr);
497
498 if (dwStyle & TBS_BOTH)
499 {
500 DrawEdge(hdc,&thumb,EDGE_RAISED,BF_RECT | BF_ADJUST);
501 FillRect(hdc,&thumb,hbr);
502 } else
503 {
504
505 POINT points[6];
506 RECT triangle; /* for correct shadows of thumb */
507
508 if (dwStyle & TBS_VERT)
509 { //Vertical
510
511 if (dwStyle & TBS_LEFT)
512 {
513 HPEN oldPen,pen;
514
515 //Outline
516
517 SetPolyFillMode(hdc,WINDING);
518 points[0].x = thumb.left;
519 points[0].y = thumb.top;
520 points[1].x = thumb.left-(thumb.bottom-thumb.top)/2;
521 points[1].y = thumb.top+(thumb.bottom-thumb.top)/2;
522 points[2].x = thumb.left;
523 points[2].y = thumb.bottom;
524 points[3].x = thumb.right;
525 points[3].y = thumb.bottom;
526 points[4].x = thumb.right;
527 points[4].y = thumb.top;
528 points[5].x = points[0].x;
529 points[5].y = points[0].y;
530 Polygon(hdc,points,6);
531
532 //Edge
533
534 thumb.bottom++;
535 thumb.right++;
536 DrawEdge(hdc,&thumb,EDGE_RAISED,BF_BOTTOM | BF_TOP | BF_RIGHT);
537
538 //Draw notch
539
540 triangle.right = points[0].x;
541 triangle.top = points[0].y;
542 triangle.left = points[1].x;
543 triangle.bottom = points[1].y;
544 DrawEdge(hdc,&triangle,EDGE_RAISED,BF_DIAGONAL | BF_DIAGONAL_ENDTOPRIGHT);
545
546 //draw this line direct, DrawEdge not useful
547 pen = GetSysColorPen(COLOR_3DDKSHADOW);
548 oldPen = SelectObject(hdc,pen);
549 MoveToEx(hdc,points[1].x,points[1].y,NULL);
550 LineTo(hdc,points[2].x-1,points[2].y-1);
551 pen = GetSysColorPen(COLOR_BTNSHADOW);
552 SelectObject(hdc,pen);
553 MoveToEx(hdc,points[1].x+1,points[1].y,NULL);
554 LineTo(hdc,points[2].x,points[2].y-1);
555 SelectObject(hdc,oldPen);
556
557 } else //Right
558 {
559 HPEN oldPen,pen;
560
561 //Outline
562
563 SetPolyFillMode(hdc,WINDING);
564 points[0].x = thumb.left;
565 points[0].y = thumb.top;
566 points[1].x = thumb.left;
567 points[1].y = thumb.bottom;
568 points[2].x = thumb.right;
569 points[2].y = thumb.bottom;
570 points[3].x = thumb.right+(thumb.bottom-thumb.top)/2;
571 points[3].y = thumb.bottom-(thumb.bottom-thumb.top)/2;
572 points[4].x = thumb.right;
573 points[4].y = thumb.top;
574 points[5].x = points[0].x;
575 points[5].y = points[0].y;
576 Polygon(hdc,points,6);
577
578 //Edge
579
580 thumb.bottom++;
581 DrawEdge(hdc,&thumb,EDGE_RAISED,BF_BOTTOM | BF_TOP | BF_LEFT);
582
583 //Draw notch
584
585 //draw this line direct, DrawEdge not useful
586 pen = GetSysColorPen(COLOR_3DLIGHT);
587 oldPen = SelectObject(hdc,pen);
588 MoveToEx(hdc,points[4].x,points[4].y,NULL);
589 LineTo(hdc,points[3].x-1,points[3].y-1);
590 pen = GetSysColorPen(COLOR_BTNHIGHLIGHT);
591 SelectObject(hdc,pen);
592 MoveToEx(hdc,points[4].x,points[4].y+1,NULL);
593 LineTo(hdc,points[3].x-2,points[3].y-1);
594 SelectObject(hdc,oldPen);
595
596 triangle.right = points[3].x;
597 triangle.top = points[3].y;
598 triangle.left = points[2].x;
599 triangle.bottom = points[2].y;
600 DrawEdge(hdc,&triangle,EDGE_RAISED,BF_DIAGONAL | BF_DIAGONAL_ENDBOTTOMLEFT);
601 }
602 } else
603 { //Horizontal
604
605 if (dwStyle & TBS_TOP)
606 {
607 //Outline
608
609 SetPolyFillMode(hdc,WINDING);
610 points[0].x = thumb.left;
611 points[0].y = thumb.top;
612 points[1].x = thumb.left+(thumb.right-thumb.left)/2;
613 points[1].y = thumb.top-(thumb.right-thumb.left)/2;
614 points[2].x = thumb.right;
615 points[2].y = thumb.top;
616 points[3].x = thumb.right;
617 points[3].y = thumb.bottom;
618 points[4].x = thumb.left;
619 points[4].y = thumb.bottom;
620 points[5].x = points[0].x;
621 points[5].y = points[0].y;
622 Polygon(hdc,points,6);
623
624 //Edge
625
626 thumb.right++;
627 thumb.bottom++;
628 DrawEdge(hdc,&thumb,EDGE_RAISED,BF_BOTTOM | BF_LEFT | BF_RIGHT);
629
630 //Draw notch
631
632 triangle.left = points[0].x;
633 triangle.bottom = points[0].y;
634 triangle.right = points[1].x;
635 triangle.top = points[1].y;
636 DrawEdge(hdc,&triangle,EDGE_RAISED,BF_DIAGONAL | BF_DIAGONAL_ENDTOPRIGHT);
637
638
639 triangle.left = points[1].x;
640 triangle.top = points[1].y;
641 triangle.right = points[2].x;
642 triangle.bottom = points[2].y;
643 DrawEdge(hdc,&triangle,EDGE_RAISED,BF_DIAGONAL | BF_DIAGONAL_ENDBOTTOMRIGHT);
644
645 } else //Bottom
646 {
647
648 //Outline
649
650 SetPolyFillMode(hdc,WINDING);
651 points[0].x = thumb.left;
652 points[0].y = thumb.top;
653 points[1].x = thumb.right;
654 points[1].y = thumb.top;
655 points[2].x = thumb.right;
656 points[2].y = thumb.bottom;
657 points[3].x = thumb.right-(thumb.right-thumb.left)/2;
658 points[3].y = thumb.bottom+(thumb.right-thumb.left)/2;
659 points[4].x = thumb.left;
660 points[4].y = thumb.bottom;
661 points[5].x = points[0].x;
662 points[5].y = points[0].y;
663 Polygon(hdc,points,6);
664
665 //Edge
666
667 thumb.right++;
668 thumb.bottom++;
669 DrawEdge(hdc,&thumb,EDGE_RAISED,BF_TOP | BF_LEFT | BF_RIGHT);
670
671 //Draw notch
672
673 triangle.right = points[2].x;
674 triangle.top = points[2].y;
675 triangle.left = points[3].x;
676 triangle.bottom = points[3].y;
677 DrawEdge(hdc,&triangle,EDGE_RAISED,BF_DIAGONAL | BF_DIAGONAL_ENDBOTTOMLEFT);
678 triangle.right = points[3].x;
679 triangle.bottom = points[3].y;
680 triangle.left = points[4].x;
681 triangle.top = points[4].y;
682 DrawEdge(hdc,&triangle,EDGE_RAISED,BF_DIAGONAL | BF_DIAGONAL_ENDTOPLEFT);
683
684 }
685 }
686 }
687 SelectObject(hdc,hbrOld);
688 DeleteObject(hbr);
689 }
690}
691
692//draw the trackbar
693
694static VOID TRACKBAR_Draw(HWND hwnd,HDC hdc)
695{
696 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
697 DWORD dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
698 RECT rcClient,rcChannel,rcSelection;
699 HBRUSH hBrush = CreateSolidBrush(infoPtr->clrBk);
700 int i;
701 NMCUSTOMDRAW cdraw;
702 LRESULT cdctlres,cdres;
703
704 GetClientRect(hwnd,&rcClient);
705
706 //Custom draw
707 cdraw.hdr.hwndFrom = hwnd;
708 cdraw.hdr.idFrom = GetWindowLongA(hwnd,GWL_ID);
709 cdraw.hdr.code = NM_CUSTOMDRAW;
710 cdraw.dwDrawStage = CDDS_PREPAINT;
711 cdraw.hdc = hdc;
712 cdraw.dwItemSpec = 0;
713 cdraw.uItemState = CDIS_DEFAULT;
714 cdraw.rc = rcClient;
715 cdraw.lItemlParam = 0;
716
717 cdctlres = SendMessageA(GetParent(hwnd),WM_NOTIFY,(WPARAM)cdraw.hdr.idFrom,(LPARAM)&cdraw);
718
719 if (cdctlres & CDRF_SKIPDEFAULT) return;
720
721 //Background
722 hBrush = CreateSolidBrush(infoPtr->clrBk);
723 FillRect(hdc,&rcClient,hBrush);
724 DeleteObject(hBrush);
725
726 if (infoPtr->flags & TB_DRAGPOSVALID)
727 {
728 infoPtr->nPos = infoPtr->dragPos;
729 infoPtr->flags |= TB_THUMBPOSCHANGED;
730 }
731
732 if (infoPtr->flags & TB_THUMBCHANGED)
733 {
734 TRACKBAR_CalcThumb(hwnd,infoPtr);
735 if (infoPtr->flags & TB_THUMBSIZECHANGED) TRACKBAR_CalcChannel(hwnd,infoPtr);
736 }
737 if (infoPtr->flags & TB_SELECTIONCHANGED) TRACKBAR_CalcSelection(hwnd,infoPtr);
738 infoPtr->flags &= ~ (TB_THUMBCHANGED | TB_SELECTIONCHANGED | TB_DRAGPOSVALID);
739
740 /* draw channel */
741
742 if (cdctlres & CDRF_NOTIFYITEMDRAW)
743 {
744 cdraw.dwDrawStage = CDDS_ITEMPREPAINT;
745 cdraw.dwItemSpec = TBCD_CHANNEL;
746 cdraw.rc = infoPtr->rcChannel;
747
748 cdres = SendMessageA(GetParent(hwnd),WM_NOTIFY,(WPARAM)cdraw.hdr.idFrom,(LPARAM)&cdraw);
749 } else cdres = 0;
750
751 if (!(cdres & CDRF_SKIPDEFAULT))
752 {
753 rcChannel = infoPtr->rcChannel;
754 rcSelection = infoPtr->rcSelection;
755 DrawEdge(hdc,&rcChannel,EDGE_SUNKEN,BF_RECT | BF_ADJUST);
756
757 if (dwStyle & TBS_ENABLESELRANGE) /* fill the channel */
758 {
759 HBRUSH hbr = CreateSolidBrush(RGB(255,255,255));
760 FillRect(hdc,&rcChannel,hbr);
761 DeleteObject(hbr);
762 if (((dwStyle & TBS_VERT) && (rcSelection.top != rcSelection.bottom)) ||
763 ((!(dwStyle & TBS_VERT)) && (rcSelection.left != rcSelection.right)))
764 {
765 hbr = CreateSolidBrush (COLOR_HIGHLIGHT);
766 FillRect (hdc,&rcSelection,hbr);
767 DeleteObject(hbr);
768 }
769 }
770
771 if (cdctlres & CDRF_NOTIFYITEMDRAW)
772 {
773 cdraw.dwDrawStage = CDDS_ITEMPOSTPAINT;
774
775 SendMessageA(GetParent(hwnd),WM_NOTIFY,(WPARAM)cdraw.hdr.idFrom,(LPARAM)&cdraw);
776 }
777 }
778
779 /* draw tics */
780
781 if (cdctlres & CDRF_NOTIFYITEMDRAW)
782 {
783 cdraw.dwDrawStage = CDDS_ITEMPREPAINT;
784 cdraw.dwItemSpec = TBCD_TICS;
785 SetRectEmpty(&cdraw.rc);
786
787 cdres = SendMessageA(GetParent(hwnd),WM_NOTIFY,(WPARAM)cdraw.hdr.idFrom,(LPARAM)&cdraw);
788 } else cdres = 0;
789
790 if (!(cdres & CDRF_SKIPDEFAULT))
791 {
792 if (!(dwStyle & TBS_NOTICKS))
793 {
794 int ticFlags = dwStyle & 0x0f;
795 COLORREF clrTic = GetSysColor(COLOR_3DDKSHADOW);
796 INT range = infoPtr->nRangeMax-infoPtr->nRangeMin;
797 INT width = (dwStyle & TBS_VERT) ? rcChannel.bottom-rcChannel.top:rcChannel.right-rcChannel.left;
798
799 //check if maximum of visible marks is reached
800 if (dwStyle & TBS_AUTOTICKS && infoPtr->uNumTics > 1 && (INT)(width*infoPtr->tics[0]/range) == (INT)(width*infoPtr->tics[1]/range))
801 {
802 //draw all pixels at once -> much faster
803 if (dwStyle & TBS_VERT)
804 {
805 if ((ticFlags & TBS_LEFT) || (ticFlags & TBS_BOTH))
806 TRACKBAR_FillVertTics(infoPtr,hdc,ticFlags | TBS_LEFT,clrTic);
807 if (!(ticFlags & TBS_LEFT) || (ticFlags & TBS_BOTH))
808 TRACKBAR_FillVertTics(infoPtr,hdc,ticFlags & ~TBS_LEFT,clrTic);
809 } else
810 {
811 if ((ticFlags & TBS_TOP) || (ticFlags & TBS_BOTH))
812 TRACKBAR_FillHorzTics(infoPtr,hdc,ticFlags | TBS_TOP,clrTic);
813 if (!(ticFlags & TBS_TOP) || (ticFlags & TBS_BOTH))
814 TRACKBAR_FillHorzTics(infoPtr,hdc,ticFlags & ~TBS_TOP,clrTic);
815 }
816 } else
817 {
818 for (i = 0;i < infoPtr->uNumTics;i++)
819 TRACKBAR_DrawTics(infoPtr,hdc,infoPtr->tics[i],ticFlags,clrTic);
820 }
821
822 TRACKBAR_DrawTics(infoPtr,hdc,0,ticFlags | TIC_LEFTEDGE,clrTic);
823 TRACKBAR_DrawTics(infoPtr,hdc,0,ticFlags | TIC_RIGHTEDGE,clrTic);
824
825 if ((dwStyle & TBS_ENABLESELRANGE) &&
826 ((dwStyle & TBS_VERT && rcSelection.bottom != rcSelection.top) ||
827 (!(dwStyle & TBS_VERT) && rcSelection.left != rcSelection.right)))
828 {
829 TRACKBAR_DrawTics(infoPtr,hdc,infoPtr->nSelMin,ticFlags | TIC_SELECTIONMARKMIN,clrTic);
830 TRACKBAR_DrawTics(infoPtr,hdc,infoPtr->nSelMax,ticFlags | TIC_SELECTIONMARKMAX,clrTic);
831 }
832 }
833
834 if (cdctlres & CDRF_NOTIFYITEMDRAW)
835 {
836 cdraw.dwDrawStage = CDDS_ITEMPOSTPAINT;
837
838 SendMessageA(GetParent(hwnd),WM_NOTIFY,(WPARAM)cdraw.hdr.idFrom,(LPARAM)&cdraw);
839 }
840 }
841
842 /* draw thumb */
843
844 if (cdctlres & CDRF_NOTIFYITEMDRAW)
845 {
846 cdraw.dwDrawStage = CDDS_ITEMPREPAINT;
847 cdraw.dwItemSpec = TBCD_THUMB;
848 cdraw.rc = infoPtr->rcFullThumb;
849
850 cdres = SendMessageA(GetParent(hwnd),WM_NOTIFY,(WPARAM)cdraw.hdr.idFrom,(LPARAM)&cdraw);
851 } else cdres = 0;
852
853 if (!(cdres & CDRF_SKIPDEFAULT))
854 {
855 TRACKBAR_DrawThumb(infoPtr,hdc,dwStyle);
856
857 if (cdctlres & CDRF_NOTIFYITEMDRAW)
858 {
859 cdraw.dwDrawStage = CDDS_ITEMPOSTPAINT;
860
861 SendMessageA(GetParent(hwnd),WM_NOTIFY,(WPARAM)cdraw.hdr.idFrom,(LPARAM)&cdraw);
862 }
863
864 }
865
866 if (infoPtr->bFocus) DrawFocusRect(hdc,&rcClient);
867
868 if (cdctlres & CDRF_NOTIFYPOSTPAINT)
869 {
870 cdraw.dwDrawStage = CDDS_POSTPAINT;
871 cdraw.dwItemSpec = 0;
872 GetClientRect(hwnd,&cdraw.rc);
873
874 SendMessageA(GetParent(hwnd),WM_NOTIFY,(WPARAM)cdraw.hdr.idFrom,(LPARAM)&cdraw);
875 }
876
877}
878
879//update thumb position
880
881static VOID TRACKBAR_UpdateThumbPosition(HWND hwnd,INT lastPos,BOOL mustRedraw)
882{
883 HDC hdc;
884 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr(hwnd);
885 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
886 RECT lastRect,newRect,updateRect;
887 HDC hdcCompatible;
888 HBITMAP bitmap,oldbmp;
889
890 //last
891 lastRect = infoPtr->rcFullThumb;
892
893 //new
894 if (infoPtr->flags & TB_DRAGPOSVALID)
895 {
896 infoPtr->nPos = infoPtr->dragPos;
897 infoPtr->flags &= ~TB_DRAGPOSVALID;
898 }
899 if (!mustRedraw && infoPtr->nPos == lastPos) return;
900
901 if (dwStyle & TBS_NOTHUMB) return;
902
903 TRACKBAR_CalcThumb(hwnd,infoPtr);
904 infoPtr->flags &= ~TB_THUMBCHANGED;
905 newRect = infoPtr->rcFullThumb;
906
907 //same rect?
908 if (!mustRedraw && EqualRect(&lastRect,&newRect)) return;
909
910 //3D frame adjustation
911 lastRect.right++;
912 lastRect.bottom++;
913 newRect.right++;
914 newRect.bottom++;
915
916 //BitBlt from memory -> no flickering
917 updateRect.left = MIN(lastRect.left,newRect.left);
918 updateRect.right = MAX(lastRect.right,newRect.right);
919 updateRect.top = MIN(lastRect.top,newRect.top);
920 updateRect.bottom = MAX(lastRect.bottom,newRect.bottom);
921 hdc = GetDC(hwnd);
922 hdcCompatible = CreateCompatibleDC(hdc);
923 bitmap = CreateCompatibleBitmap(hdc,updateRect.right,updateRect.bottom);
924 oldbmp = SelectObject(hdcCompatible,bitmap);
925 TRACKBAR_Draw(hwnd,hdcCompatible);
926 if (dwStyle & TBS_VERT)
927 {
928 if (lastRect.top > newRect.top && lastRect.top < newRect.bottom)
929 BitBlt(hdc,newRect.left,newRect.top,newRect.right-newRect.left,lastRect.bottom-newRect.top,hdcCompatible,newRect.left,newRect.top,SRCCOPY);
930 else if (lastRect.bottom < newRect.bottom && lastRect.bottom > newRect.top)
931 BitBlt(hdc,lastRect.left,lastRect.top,lastRect.right-lastRect.left,newRect.bottom-lastRect.top,hdcCompatible,lastRect.left,lastRect.top,SRCCOPY);
932 else
933 {
934 BitBlt(hdc,lastRect.left,lastRect.top,lastRect.right-lastRect.left,lastRect.bottom-lastRect.top,hdcCompatible,lastRect.left,lastRect.top,SRCCOPY);
935 BitBlt(hdc,newRect.left,newRect.top,newRect.right-newRect.left,newRect.bottom-newRect.top,hdcCompatible,newRect.left,newRect.top,SRCCOPY);
936 }
937 } else
938 {
939 if (lastRect.right > newRect.left && lastRect.right < newRect.right)
940 BitBlt(hdc,lastRect.left,lastRect.top,newRect.right-lastRect.left,lastRect.bottom-lastRect.top,hdcCompatible,lastRect.left,lastRect.top,SRCCOPY);
941 else if (lastRect.left < newRect.right && lastRect.left > newRect.left)
942 BitBlt(hdc,newRect.left,newRect.top,lastRect.right-newRect.left,newRect.bottom-newRect.top,hdcCompatible,newRect.left,newRect.top,SRCCOPY);
943 else
944 {
945 BitBlt(hdc,lastRect.left,lastRect.top,lastRect.right-lastRect.left,lastRect.bottom-lastRect.top,hdcCompatible,lastRect.left,lastRect.top,SRCCOPY);
946 BitBlt(hdc,newRect.left,newRect.top,newRect.right-newRect.left,newRect.bottom-newRect.top,hdcCompatible,newRect.left,newRect.top,SRCCOPY);
947 }
948 }
949 SelectObject(hdcCompatible,oldbmp);
950 DeleteObject(bitmap);
951 DeleteDC(hdcCompatible);
952 ReleaseDC(hwnd,hdc);
953}
954
955//redraw everything
956
957static VOID TRACKBAR_Refresh (HWND hwnd)
958{
959 HDC hdc;
960
961 hdc = GetDC (hwnd);
962 TRACKBAR_Draw(hwnd,hdc);
963 ReleaseDC(hwnd,hdc);
964}
965
966static VOID
967TRACKBAR_AlignBuddies (HWND hwnd, TRACKBAR_INFO *infoPtr)
968{
969 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
970 HWND hwndParent = GetParent(hwnd);
971 RECT rcSelf,rcBuddy;
972 INT x, y;
973
974 GetWindowRect(hwnd,&rcSelf);
975
976 /* align buddy left or above */
977 if (infoPtr->hwndBuddyLA)
978 {
979 GetWindowRect(infoPtr->hwndBuddyLA,&rcBuddy);
980
981 if (dwStyle & TBS_VERT)
982 { //above
983 x = rcSelf.left-(rcBuddy.right-rcBuddy.left)/2+infoPtr->rcChannel.left+(infoPtr->rcChannel.right-infoPtr->rcChannel.left)/2;
984 y = rcSelf.top-(rcBuddy.bottom-rcBuddy.top);
985 } else
986 { //left
987 x = rcSelf.left+infoPtr->rcChannel.left-(rcBuddy.right-rcBuddy.left)/2;
988 y = rcSelf.top-(rcBuddy.bottom-rcBuddy.top);
989 }
990
991 SetWindowPos(infoPtr->hwndBuddyLA,0,x,y,0,0,SWP_NOZORDER | SWP_NOSIZE);
992 }
993
994
995 /* align buddy right or below */
996 if (infoPtr->hwndBuddyRB)
997 {
998 GetWindowRect(infoPtr->hwndBuddyRB,&rcBuddy);
999
1000 if (dwStyle & TBS_VERT)
1001 { //below
1002 x = rcSelf.left-(rcBuddy.right-rcBuddy.left)/2+infoPtr->rcChannel.left+(infoPtr->rcChannel.right-infoPtr->rcChannel.left)/2;
1003 y = rcSelf.bottom;
1004 } else
1005 {
1006 x = rcSelf.right-infoPtr->rcChannel.left-(rcBuddy.right-rcBuddy.left)/2;
1007 y = rcSelf.top-(rcBuddy.bottom-rcBuddy.top);
1008 }
1009
1010 SetWindowPos(infoPtr->hwndBuddyRB,0,x,y,0,0,SWP_NOZORDER | SWP_NOSIZE);
1011 }
1012}
1013
1014
1015static LRESULT
1016TRACKBAR_ClearSel (HWND hwnd, WPARAM wParam, LPARAM lParam)
1017{
1018 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1019
1020 if (infoPtr->nSelMin != infoPtr->nSelMax)
1021 {
1022 infoPtr->nSelMin = 0;
1023 infoPtr->nSelMax = 0;
1024 infoPtr->flags |= TB_SELECTIONCHANGED;
1025
1026 if ((BOOL)wParam) TRACKBAR_Refresh(hwnd);
1027 }
1028
1029 return 0;
1030}
1031
1032
1033static LRESULT
1034TRACKBAR_ClearTics (HWND hwnd, WPARAM wParam, LPARAM lParam)
1035{
1036 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1037
1038 if (!(GetWindowLongA(hwnd, GWL_STYLE) & (TBS_AUTOTICKS | TBS_NOTICKS))) return 0;
1039
1040 if (infoPtr->tics)
1041 {
1042 COMCTL32_Free(infoPtr->tics);
1043 infoPtr->tics = NULL;
1044 infoPtr->uNumTics = 0;
1045
1046 if (wParam) TRACKBAR_Refresh(hwnd);
1047 }
1048
1049 return 0;
1050}
1051
1052
1053static LRESULT
1054TRACKBAR_GetBuddy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1055{
1056 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr(hwnd);
1057
1058 if (wParam)
1059 return (LRESULT)infoPtr->hwndBuddyLA; //left or above
1060 else
1061 return (LRESULT)infoPtr->hwndBuddyRB; //right or below
1062}
1063
1064
1065static LRESULT
1066TRACKBAR_GetChannelRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
1067{
1068 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1069 LPRECT lprc = (LPRECT)lParam;
1070
1071 if (lprc == NULL) return 0;
1072
1073 CopyRect(lprc,&infoPtr->rcChannel);
1074
1075 return 0;
1076}
1077
1078
1079static LRESULT
1080TRACKBAR_GetLineSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
1081{
1082 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1083
1084 return infoPtr->nLineSize;
1085}
1086
1087
1088static LRESULT
1089TRACKBAR_GetNumTics (HWND hwnd, WPARAM wParam, LPARAM lParam)
1090{
1091 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1092
1093 if (GetWindowLongA(hwnd, GWL_STYLE) & TBS_NOTICKS) return 0;
1094
1095 return infoPtr->uNumTics+2; //includes last and first tick
1096}
1097
1098
1099static LRESULT
1100TRACKBAR_GetPageSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
1101{
1102 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1103
1104 return infoPtr->nPageSize;
1105}
1106
1107
1108static LRESULT
1109TRACKBAR_GetPos (HWND hwnd, WPARAM wParam, LPARAM lParam)
1110{
1111 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1112
1113 return infoPtr->nPos;
1114}
1115
1116
1117static LRESULT
1118TRACKBAR_GetRangeMax (HWND hwnd, WPARAM wParam, LPARAM lParam)
1119{
1120 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1121
1122 return infoPtr->nRangeMax;
1123}
1124
1125
1126static LRESULT
1127TRACKBAR_GetRangeMin (HWND hwnd, WPARAM wParam, LPARAM lParam)
1128{
1129 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1130
1131 return infoPtr->nRangeMin;
1132}
1133
1134
1135static LRESULT
1136TRACKBAR_GetSelEnd (HWND hwnd, WPARAM wParam, LPARAM lParam)
1137{
1138 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1139
1140 return infoPtr->nSelMax;
1141}
1142
1143
1144static LRESULT
1145TRACKBAR_GetSelStart (HWND hwnd, WPARAM wParam, LPARAM lParam)
1146{
1147 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1148
1149 return infoPtr->nSelMin;
1150}
1151
1152
1153static LRESULT
1154TRACKBAR_GetThumbLength (HWND hwnd, WPARAM wParam, LPARAM lParam)
1155{
1156 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1157
1158 return infoPtr->uThumbLen;
1159}
1160
1161static LRESULT
1162TRACKBAR_GetPTics (HWND hwnd)
1163{
1164 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1165
1166 return (LRESULT)infoPtr->tics;
1167}
1168
1169static LRESULT
1170TRACKBAR_GetThumbRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
1171{
1172 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1173 LPRECT lprc = (LPRECT)lParam;
1174
1175 if (lprc == NULL) return 0;
1176
1177 CopyRect(lprc,&infoPtr->rcFullThumb);
1178
1179 return 0;
1180}
1181
1182
1183static LRESULT
1184TRACKBAR_GetTic (HWND hwnd, WPARAM wParam, LPARAM lParam)
1185{
1186 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1187 INT iTic;
1188
1189 iTic = (INT)wParam;
1190 if ((iTic < 0) || (iTic > infoPtr->uNumTics)) return -1;
1191
1192 return (LRESULT)infoPtr->tics[iTic];
1193
1194}
1195
1196
1197static LRESULT
1198TRACKBAR_GetTicPos (HWND hwnd, WPARAM wParam, LPARAM lParam)
1199{
1200 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1201 INT iTic, range, width, pos;
1202
1203
1204 iTic = (INT)wParam;
1205 if ((iTic < 0) || (iTic > infoPtr->uNumTics)) return -1;
1206
1207 range = infoPtr->nRangeMax-infoPtr->nRangeMin;
1208 width = infoPtr->rcChannel.right-infoPtr->rcChannel.left;
1209 pos = infoPtr->rcChannel.left+(width*(infoPtr->tics[iTic]-infoPtr->nRangeMin))/range;
1210
1211 return (LRESULT) pos;
1212}
1213
1214
1215static LRESULT
1216TRACKBAR_GetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
1217{
1218 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1219
1220 if (GetWindowLongA (hwnd, GWL_STYLE) & TBS_TOOLTIPS)
1221 return (LRESULT)infoPtr->hwndToolTip;
1222 return 0;
1223}
1224
1225
1226/* case TBM_GETUNICODEFORMAT: */
1227
1228
1229static LRESULT
1230TRACKBAR_SetBuddy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1231{
1232 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr(hwnd);
1233 HWND hwndTemp;
1234
1235 if (!(GetParent(lParam) == GetParent(hwnd))) return wParam ? infoPtr->hwndBuddyLA:infoPtr->hwndBuddyRB;
1236
1237 if (wParam)
1238 {
1239 /* buddy is left or above */
1240 hwndTemp = infoPtr->hwndBuddyLA;
1241 infoPtr->hwndBuddyLA = (HWND)lParam;
1242 } else
1243 {
1244 /* buddy is right or below */
1245 hwndTemp = infoPtr->hwndBuddyRB;
1246 infoPtr->hwndBuddyRB = (HWND)lParam;
1247 }
1248
1249 TRACKBAR_AlignBuddies(hwnd,infoPtr);
1250
1251 return (LRESULT)hwndTemp;
1252}
1253
1254
1255static LRESULT
1256TRACKBAR_SetLineSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
1257{
1258 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1259 INT nTemp = infoPtr->nLineSize;
1260
1261 infoPtr->nLineSize = (INT)lParam;
1262
1263 return nTemp;
1264}
1265
1266
1267static LRESULT
1268TRACKBAR_SetPageSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
1269{
1270 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1271 INT nTemp = infoPtr->nPageSize;
1272
1273 infoPtr->nPageSize = (INT)lParam;
1274
1275 return nTemp;
1276}
1277
1278
1279static LRESULT
1280TRACKBAR_SetPos (HWND hwnd, WPARAM wParam, LPARAM lParam)
1281{
1282 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1283 INT lastPos = infoPtr->nPos;
1284
1285 infoPtr->nPos = (INT)LOWORD(lParam);
1286
1287 if (lastPos == infoPtr->nPos) return 0; //nothing changed
1288
1289 if (infoPtr->nPos < infoPtr->nRangeMin)
1290 infoPtr->nPos = infoPtr->nRangeMin;
1291
1292 if (infoPtr->nPos > infoPtr->nRangeMax)
1293 infoPtr->nPos = infoPtr->nRangeMax;
1294 infoPtr->flags |= TB_THUMBPOSCHANGED;
1295
1296 if (wParam) TRACKBAR_UpdateThumbPosition(hwnd,lastPos,FALSE);
1297
1298 return 0;
1299}
1300
1301
1302static LRESULT
1303TRACKBAR_SetRange (HWND hwnd, WPARAM wParam, LPARAM lParam)
1304{
1305 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1306 int newMin,newMax;
1307 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
1308
1309 newMin = (INT)LOWORD(lParam);
1310 newMax = (INT)HIWORD(lParam);
1311
1312 if (newMin == newMax) return 0;
1313 if (newMin > newMax)
1314 { //exchange
1315 int x;
1316
1317 x = newMin;
1318 newMin = newMax;
1319 newMax = x;
1320 }
1321 if (newMin == infoPtr->nRangeMin && newMax == infoPtr->nRangeMax) return 0;
1322
1323 infoPtr->nRangeMin = newMin;
1324 infoPtr->nRangeMax = newMax;
1325
1326 if (infoPtr->nPos < infoPtr->nRangeMin)
1327 {
1328 infoPtr->nPos = infoPtr->nRangeMin;
1329 infoPtr->flags |= TB_THUMBPOSCHANGED;
1330 }
1331 if (infoPtr->nPos > infoPtr->nRangeMax)
1332 {
1333 infoPtr->nPos = infoPtr->nRangeMax;
1334 infoPtr->flags |= TB_THUMBPOSCHANGED;
1335 }
1336
1337 if (infoPtr->nSelMin < infoPtr->nRangeMin)
1338 {
1339 infoPtr->nSelMin = infoPtr->nRangeMin;
1340 infoPtr->flags |= TB_SELECTIONCHANGED;
1341 }
1342 if (infoPtr->nSelMin > infoPtr->nRangeMax)
1343 {
1344 infoPtr->nSelMin = infoPtr->nRangeMax;
1345 infoPtr->flags |= TB_SELECTIONCHANGED;
1346 }
1347 if (infoPtr->nSelMax < infoPtr->nRangeMin)
1348 {
1349 infoPtr->nSelMax = infoPtr->nRangeMin;
1350 infoPtr->flags |= TB_SELECTIONCHANGED;
1351 }
1352 if (infoPtr->nSelMax > infoPtr->nRangeMax)
1353 {
1354 infoPtr->nSelMax = infoPtr->nRangeMax;
1355 infoPtr->flags |= TB_SELECTIONCHANGED;
1356 }
1357
1358 infoPtr->nPageSize = (infoPtr->nRangeMax-infoPtr->nRangeMin)/5;
1359 if (infoPtr->nPageSize == 0) infoPtr->nPageSize = 1;
1360 TRACKBAR_RecalculateTics(hwnd,infoPtr,TRUE);
1361
1362 if (wParam) TRACKBAR_Refresh(hwnd);
1363
1364 return 0;
1365}
1366
1367
1368static LRESULT
1369TRACKBAR_SetRangeMax (HWND hwnd, WPARAM wParam, LPARAM lParam)
1370{
1371 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1372
1373 if ((INT)lParam <= infoPtr->nRangeMin) return 0;
1374 if (infoPtr->nRangeMax == (INT)lParam) return 0;
1375
1376 infoPtr->nRangeMax = (INT)lParam;
1377 if (infoPtr->nPos > infoPtr->nRangeMax)
1378 {
1379 infoPtr->nPos = infoPtr->nRangeMax;
1380 infoPtr->flags |=TB_THUMBPOSCHANGED;
1381 }
1382
1383 infoPtr->nPageSize = (infoPtr->nRangeMax-infoPtr->nRangeMin)/5;
1384 if (infoPtr->nPageSize == 0) infoPtr->nPageSize = 1;
1385 TRACKBAR_RecalculateTics(hwnd,infoPtr,TRUE);
1386
1387 if (wParam) TRACKBAR_Refresh(hwnd);
1388
1389 return 0;
1390}
1391
1392
1393static LRESULT
1394TRACKBAR_SetRangeMin (HWND hwnd, WPARAM wParam, LPARAM lParam)
1395{
1396 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1397
1398 if ((INT)lParam >= infoPtr->nRangeMax) return 0;
1399 if (infoPtr->nRangeMin == (INT)lParam) return 0;
1400
1401 infoPtr->nRangeMin = (INT)lParam;
1402 if (infoPtr->nPos < infoPtr->nRangeMin)
1403 {
1404 infoPtr->nPos = infoPtr->nRangeMin;
1405 infoPtr->flags |=TB_THUMBPOSCHANGED;
1406 }
1407
1408 infoPtr->nPageSize = (infoPtr->nRangeMax-infoPtr->nRangeMin)/5;
1409 if (infoPtr->nPageSize == 0) infoPtr->nPageSize = 1;
1410 TRACKBAR_RecalculateTics(hwnd,infoPtr,TRUE);
1411
1412 if (wParam) TRACKBAR_Refresh(hwnd);
1413
1414 return 0;
1415}
1416
1417
1418static LRESULT
1419TRACKBAR_SetTicFreq (HWND hwnd, WPARAM wParam)
1420{
1421 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1422
1423 if (infoPtr->uTicFreq == (UINT)wParam) return 0;
1424
1425 if (!(GetWindowLongA(hwnd,GWL_STYLE) & TBS_AUTOTICKS)) return 0;
1426
1427 infoPtr->uTicFreq = (UINT)wParam;
1428
1429 TRACKBAR_RecalculateTics(hwnd,infoPtr,FALSE);
1430
1431 TRACKBAR_Refresh(hwnd);
1432
1433 return 0;
1434}
1435
1436
1437static LRESULT
1438TRACKBAR_SetSel(HWND hwnd,WPARAM wParam,LPARAM lParam)
1439{
1440 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1441 INT newMin,newMax,oldMin,oldMax;
1442
1443 oldMin = infoPtr->nSelMin;
1444 oldMax = infoPtr->nSelMax;
1445 newMin = (INT)LOWORD(lParam);
1446 newMax = (INT)HIWORD(lParam);
1447
1448 if (infoPtr->nSelMin == newMin && infoPtr->nSelMax == newMax) return 0;
1449 infoPtr->nSelMin = newMin;
1450 infoPtr->nSelMax = newMax;
1451
1452 if (infoPtr->nSelMin < infoPtr->nRangeMin) infoPtr->nSelMin = infoPtr->nRangeMin;
1453 if (infoPtr->nSelMin > infoPtr->nRangeMax) infoPtr->nSelMin = infoPtr->nRangeMax;
1454 if (infoPtr->nSelMax > infoPtr->nRangeMax) infoPtr->nSelMax = infoPtr->nRangeMax;
1455 if (infoPtr->nSelMax < infoPtr->nRangeMin) infoPtr->nSelMax = infoPtr->nRangeMin;
1456
1457 if (infoPtr->nSelMin > infoPtr->nSelMax) infoPtr->nSelMin = infoPtr->nSelMax;
1458
1459 if (!GetWindowLongA(hwnd, GWL_STYLE) & TBS_ENABLESELRANGE) return 0;
1460
1461 if (oldMin != newMin || oldMax != newMax)
1462 {
1463 infoPtr->flags |= TB_SELECTIONCHANGED;
1464 if (wParam) TRACKBAR_Refresh(hwnd);
1465 }
1466
1467 return 0;
1468}
1469
1470
1471static LRESULT
1472TRACKBAR_SetSelEnd (HWND hwnd, WPARAM wParam, LPARAM lParam)
1473{
1474 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1475 INT oldMax;
1476
1477 if (infoPtr->nSelMax == (INT)lParam) return 0;
1478
1479 oldMax = infoPtr->nSelMax;
1480 infoPtr->nSelMax = (INT)lParam;
1481
1482 if (infoPtr->nSelMax > infoPtr->nRangeMax) infoPtr->nSelMax = infoPtr->nRangeMax;
1483 if (infoPtr->nSelMax < infoPtr->nRangeMin) infoPtr->nSelMax = infoPtr->nRangeMin;
1484
1485 if (infoPtr->nSelMin > infoPtr->nSelMax) infoPtr->nSelMin = infoPtr->nSelMax;
1486
1487 if (!GetWindowLongA(hwnd,GWL_STYLE) & TBS_ENABLESELRANGE) return 0;
1488
1489 if (oldMax != infoPtr->nSelMax)
1490 {
1491 infoPtr->flags |= TB_SELECTIONCHANGED;
1492 if (wParam) TRACKBAR_Refresh(hwnd);
1493 }
1494
1495 return 0;
1496}
1497
1498
1499static LRESULT
1500TRACKBAR_SetSelStart (HWND hwnd, WPARAM wParam, LPARAM lParam)
1501{
1502 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1503 INT oldMin;
1504
1505 if (infoPtr->nSelMin == (INT)lParam) return 0;
1506
1507 oldMin = infoPtr->nSelMin;
1508 infoPtr->nSelMin = (INT)lParam;
1509
1510 if (infoPtr->nSelMin < infoPtr->nRangeMin) infoPtr->nSelMin = infoPtr->nRangeMin;
1511 if (infoPtr->nSelMin > infoPtr->nRangeMax) infoPtr->nSelMin = infoPtr->nRangeMax;
1512
1513 if (infoPtr->nSelMin > infoPtr->nSelMax) infoPtr->nSelMin = infoPtr->nSelMax;
1514
1515 if (!GetWindowLongA(hwnd,GWL_STYLE) & TBS_ENABLESELRANGE) return 0;
1516
1517 if (oldMin != infoPtr->nSelMin)
1518 {
1519 infoPtr->flags |= TB_SELECTIONCHANGED;
1520 if (wParam) TRACKBAR_Refresh(hwnd);
1521 }
1522
1523 return 0;
1524}
1525
1526
1527static LRESULT
1528TRACKBAR_SetThumbLength (HWND hwnd, WPARAM wParam, LPARAM lParam)
1529{
1530 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1531
1532 if (infoPtr->uThumbLen == (UINT)wParam) return 0;
1533
1534 if (!(GetWindowLongA (hwnd, GWL_STYLE) & TBS_FIXEDLENGTH)) return 0;
1535
1536 infoPtr->uThumbLen = (UINT)wParam;
1537 infoPtr->flags |= TB_THUMBSIZECHANGED;
1538
1539 TRACKBAR_Refresh(hwnd);
1540
1541 return 0;
1542}
1543
1544static void TRACKBAR_QuickSort(LPLONG list,INT lo,INT hi)
1545{
1546 INT i,j,x,y;
1547
1548 i = lo;
1549 j = hi;
1550 x = list[(lo+hi)/2];
1551 do
1552 {
1553 while (list[i] < x) i++;
1554 while (x < list[j]) j--;
1555 if (i <= j)
1556 {
1557 y = list[i];
1558 list[i] = list[j];
1559 list[j] = y;
1560 i++;
1561 j--;
1562 }
1563 } while (i <= j);
1564 if (lo < j) TRACKBAR_QuickSort(list,lo,j);
1565 if (i < hi) TRACKBAR_QuickSort(list,i,hi);
1566}
1567
1568static LRESULT
1569TRACKBAR_SetTic (HWND hwnd, WPARAM wParam, LPARAM lParam)
1570{
1571 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1572 INT nPos = (INT)lParam;
1573 INT x;
1574
1575 if (!(GetWindowLongA(hwnd, GWL_STYLE) & (TBS_AUTOTICKS | TBS_NOTICKS))) return 0;
1576
1577 if ((nPos < infoPtr->nRangeMin) || (nPos > infoPtr->nRangeMax)) return FALSE;
1578
1579 //Check if tick exists
1580 for (x = 0;x < infoPtr->uNumTics;x++)
1581 {
1582 if (infoPtr->tics[x] == nPos) return TRUE; //value is ok
1583 }
1584
1585 infoPtr->uNumTics++;
1586 infoPtr->tics = COMCTL32_ReAlloc(infoPtr->tics,infoPtr->uNumTics*sizeof(DWORD));
1587 infoPtr->tics[infoPtr->uNumTics-1] = nPos;
1588
1589 //Quicksort the list
1590 TRACKBAR_QuickSort(infoPtr->tics,0,infoPtr->uNumTics-1);
1591
1592 TRACKBAR_Refresh(hwnd);
1593
1594 return TRUE;
1595}
1596
1597
1598static LRESULT
1599TRACKBAR_SetTipSide (HWND hwnd, WPARAM wParam, LPARAM lParam)
1600{
1601 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr(hwnd);
1602 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
1603 INT fTemp = infoPtr->fLocation;
1604
1605 if (dwStyle & TBS_VERT)
1606 {
1607 if (wParam == TBTS_LEFT || wParam == TBTS_RIGHT) infoPtr->fLocation = (INT)wParam;
1608 } else
1609 {
1610 if (wParam == TBTS_TOP || wParam == TBTS_BOTTOM) infoPtr->fLocation = (INT)wParam;
1611 }
1612
1613 return fTemp;
1614}
1615
1616
1617static LRESULT
1618TRACKBAR_SetToolTips (HWND hwnd, WPARAM wParam, LPARAM lParam)
1619{
1620 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1621
1622 infoPtr->hwndToolTip = (HWND)wParam;
1623
1624 return 0;
1625}
1626
1627
1628/* case TBM_SETUNICODEFORMAT: */
1629
1630
1631static LRESULT
1632TRACKBAR_InitializeThumb (HWND hwnd)
1633{
1634 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1635 RECT clientRect;
1636 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
1637 INT scaleSize;
1638
1639 GetClientRect(hwnd,&clientRect);
1640 infoPtr->uThumbLen = THUMB_LEN; /* initial thumb length */
1641
1642 scaleSize = 2*BORDER_SIZE;
1643 if (dwStyle & TBS_NOTICKS) scaleSize += 0;
1644 else if (dwStyle & TBS_BOTH) scaleSize += 2*(SCALE_SIZE+SCALE_SPACE);
1645 else scaleSize += SCALE_SIZE+SCALE_SPACE;
1646
1647 if (dwStyle & TBS_VERT)
1648 {
1649 INT width = clientRect.right-clientRect.left;
1650
1651 if (infoPtr->uThumbLen+scaleSize > width) infoPtr->uThumbLen = MAX(width-scaleSize,THUMB_MINLEN);
1652 } else
1653 {
1654 INT height = clientRect.bottom-clientRect.top;
1655
1656 if (infoPtr->uThumbLen+scaleSize > height) infoPtr->uThumbLen = MAX(height-scaleSize,THUMB_MINLEN);
1657 }
1658
1659 TRACKBAR_CalcChannel(hwnd,infoPtr);
1660 TRACKBAR_CalcThumb(hwnd,infoPtr);
1661
1662 infoPtr->flags &= ~TB_SELECTIONCHANGED;
1663
1664 return 0;
1665}
1666
1667
1668static LRESULT
1669TRACKBAR_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
1670{
1671 TRACKBAR_INFO *infoPtr;
1672 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
1673
1674 infoPtr = (TRACKBAR_INFO *)COMCTL32_Alloc(sizeof(TRACKBAR_INFO));
1675 SetWindowLongA(hwnd,0,(DWORD)infoPtr);
1676
1677 /* set default values */
1678 infoPtr->nRangeMin = 0;
1679 infoPtr->nRangeMax = 100;
1680 infoPtr->nLineSize = 1;
1681 infoPtr->nPageSize = 20;
1682 infoPtr->nSelMin = 0;
1683 infoPtr->nSelMax = 0;
1684 infoPtr->nPos = 0;
1685
1686 infoPtr->uNumTics = 0; /* start and end tic are not included in count*/
1687 infoPtr->uTicFreq = 1;
1688 infoPtr->tics = NULL;
1689 infoPtr->clrBk = GetSysColor(COLOR_3DFACE);
1690 infoPtr->hwndNotify = GetParent(hwnd);
1691
1692 infoPtr->hwndBuddyLA = 0;
1693 infoPtr->hwndBuddyRB = 0;
1694 infoPtr->flags = 0;
1695 infoPtr->bFocus = FALSE;
1696
1697 if (dwStyle & TBS_VERT)
1698 {
1699 infoPtr->fLocation = (dwStyle & TBS_LEFT) ? TBTS_RIGHT : TBTS_LEFT;
1700 } else
1701 {
1702 infoPtr->fLocation = (dwStyle & TBS_TOP) ? TBTS_BOTTOM : TBTS_TOP;
1703 }
1704
1705 TRACKBAR_InitializeThumb (hwnd);
1706
1707 /* Create tooltip control */
1708 if (dwStyle & TBS_TOOLTIPS)
1709 {
1710 TTTOOLINFOA ti;
1711
1712 infoPtr->hwndToolTip =
1713 CreateWindowExA (WS_EX_TOOLWINDOW,TOOLTIPS_CLASSA,NULL,WS_POPUP,
1714 CW_USEDEFAULT,CW_USEDEFAULT,
1715 CW_USEDEFAULT,CW_USEDEFAULT,
1716 hwnd,0,0,0);
1717
1718 /* Send NM_TOOLTIPSCREATED notification */
1719 if (infoPtr->hwndToolTip)
1720 {
1721 NMTOOLTIPSCREATED nmttc;
1722
1723 nmttc.hdr.hwndFrom = hwnd;
1724 nmttc.hdr.idFrom = GetWindowLongA(hwnd,GWL_ID);
1725 nmttc.hdr.code = NM_TOOLTIPSCREATED;
1726 nmttc.hwndToolTips = infoPtr->hwndToolTip;
1727
1728 SendMessageA(GetParent(hwnd),WM_NOTIFY,(WPARAM)nmttc.hdr.idFrom,(LPARAM)&nmttc);
1729 }
1730
1731 ZeroMemory(&ti,sizeof(TTTOOLINFOA));
1732 ti.cbSize = sizeof(TTTOOLINFOA);
1733 ti.uFlags = TTF_TRACK | TTF_CENTERTIP | TTF_ABSOLUTE;
1734 ti.hwnd = hwnd;
1735 ti.uId = 0;
1736 ti.lpszText = ""; /* LPSTR_TEXTCALLBACK */
1737 SetRectEmpty(&ti.rect);
1738
1739 SendMessageA(infoPtr->hwndToolTip,TTM_ADDTOOLA,0,(LPARAM)&ti);
1740 } else infoPtr->hwndToolTip = 0;
1741
1742 return 0;
1743}
1744
1745
1746static LRESULT
1747TRACKBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1748{
1749 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1750
1751 /* delete tooltip control */
1752 if (infoPtr->hwndToolTip) DestroyWindow(infoPtr->hwndToolTip);
1753
1754 COMCTL32_Free(infoPtr->tics);
1755 COMCTL32_Free(infoPtr);
1756
1757 return 0;
1758}
1759
1760static VOID TRACKBAR_CalcToolTipPos(HWND hwnd,DWORD dwStyle,TRACKBAR_INFO *infoPtr,POINT *pt)
1761{
1762 if (dwStyle & TBS_VERT)
1763 {
1764 if (infoPtr->fLocation == TBTS_RIGHT)
1765 {
1766 pt->x = infoPtr->rcFullThumb.right;
1767 pt->y = infoPtr->rcFullThumb.top+(infoPtr->rcFullThumb.bottom-infoPtr->rcFullThumb.top)/2;
1768 } else
1769 {
1770 pt->x = infoPtr->rcFullThumb.left-15; //CB: optimize!
1771 pt->y = infoPtr->rcFullThumb.top+(infoPtr->rcFullThumb.bottom-infoPtr->rcFullThumb.top)/2;
1772 }
1773
1774 } else
1775 {
1776 if (infoPtr->fLocation == TBTS_TOP)
1777 {
1778 pt->x = infoPtr->rcFullThumb.left+(infoPtr->rcFullThumb.right-infoPtr->rcFullThumb.left)/2;
1779 pt->y = infoPtr->rcFullThumb.top-15; //CB: optimize!
1780 } else
1781 {
1782 pt->x = infoPtr->rcFullThumb.left+(infoPtr->rcFullThumb.right-infoPtr->rcFullThumb.left)/2;
1783 pt->y = infoPtr->rcFullThumb.bottom;
1784 }
1785 }
1786 ClientToScreen(hwnd,pt);
1787}
1788
1789static LRESULT
1790TRACKBAR_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
1791{
1792 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1793 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1794 int clickPlace,prevPos,vertical;
1795 DOUBLE clickPos;
1796 RECT thumb,fullThumb;
1797 POINT clickPoint;
1798
1799 SetFocus (hwnd);
1800
1801 vertical = dwStyle & TBS_VERT;
1802 clickPoint.x = (INT)LOWORD(lParam);
1803 clickPoint.y = (INT)HIWORD(lParam);
1804
1805
1806 if (vertical) clickPlace = clickPoint.y;
1807 else clickPlace = clickPoint.x;
1808
1809 //Button down on thumb?
1810 thumb = infoPtr->rcThumb;
1811 fullThumb = infoPtr->rcFullThumb;
1812 if ((vertical &&
1813 clickPoint.y >= thumb.top &&
1814 clickPoint.y <= thumb.bottom &&
1815 ((dwStyle & TBS_BOTH &&
1816 clickPoint.x >= thumb.left &&
1817 clickPoint.x <= thumb.right
1818 ) ||
1819 (dwStyle & TBS_LEFT &&
1820 clickPoint.x <= thumb.right &&
1821 (clickPoint.x >= thumb.left ||
1822 (clickPoint.x >= fullThumb.left &&
1823 (thumb.left-clickPoint.x <= clickPoint.y-thumb.top &&
1824 thumb.left-clickPoint.x <= thumb.bottom-clickPoint.y
1825 )
1826 )
1827 )
1828 ) ||
1829 (!(dwStyle & (TBS_BOTH | TBS_LEFT)) &&
1830 clickPoint.x >= thumb.left &&
1831 (clickPoint.x <= thumb.right ||
1832 (clickPoint.x <= fullThumb.right &&
1833 (clickPoint.x-thumb.right <= clickPoint.y-thumb.top &&
1834 clickPoint.x-thumb.right <= thumb.bottom-clickPoint.y
1835 )
1836 )
1837 )
1838 ))
1839 ) ||
1840 (!vertical &&
1841 clickPoint.x >= thumb.left &&
1842 clickPoint.x <= thumb.right &&
1843 ((dwStyle & TBS_BOTH &&
1844 clickPoint.y >= thumb.top &&
1845 clickPoint.y <= thumb.bottom
1846 ) ||
1847 (dwStyle & TBS_TOP &&
1848 clickPoint.y <= thumb.bottom &&
1849 (clickPoint.y >= thumb.top ||
1850 (clickPoint.y >= fullThumb.top &&
1851 (thumb.top-clickPoint.y <= clickPoint.x-thumb.left &&
1852 thumb.top-clickPoint.y <= thumb.right-clickPoint.x
1853 )
1854 )
1855 )
1856 ) ||
1857 (!(dwStyle & (TBS_BOTH | TBS_TOP)) &&
1858 clickPoint.y >= thumb.top &&
1859 (clickPoint.y <= thumb.bottom ||
1860 (clickPoint.y <= fullThumb.bottom &&
1861 (clickPoint.y-thumb.bottom <= clickPoint.x-thumb.left &&
1862 clickPoint.y-thumb.bottom <= thumb.right-clickPoint.x
1863 )
1864 )
1865 )
1866 ))
1867 ))
1868 {
1869 infoPtr->flags |= TB_DRAG_MODE;
1870 if (dwStyle & TBS_TOOLTIPS)
1871 { /* enable tooltip */
1872 TTTOOLINFOA ti;
1873 POINT pt;
1874 char buf[80];
1875
1876 TRACKBAR_CalcToolTipPos(hwnd,dwStyle,infoPtr,&pt);
1877 SendMessageA(infoPtr->hwndToolTip,TTM_TRACKPOSITION,0,(LPARAM)MAKELPARAM(pt.x,pt.y));
1878
1879 ti.cbSize = sizeof(TTTOOLINFOA);
1880 ti.uId = 0;
1881 ti.hwnd = (UINT)hwnd;
1882 ti.hinst = 0;
1883 sprintf (buf,"%d",infoPtr->nPos);
1884 ti.lpszText = (LPSTR)buf;
1885
1886 infoPtr->flags |= TB_SHOW_TOOLTIP;
1887 SetCapture(hwnd);
1888
1889 SendMessageA(infoPtr->hwndToolTip,TTM_UPDATETIPTEXTA,0,(LPARAM)&ti);
1890 SendMessageA(infoPtr->hwndToolTip,TTM_TRACKACTIVATE,(WPARAM)TRUE,(LPARAM)&ti);
1891 }
1892 SetCapture(hwnd);
1893 TRACKBAR_UpdateThumbPosition(hwnd,infoPtr->nPos,TRUE); //change arrow color
1894 return 0;
1895 }
1896 else if ((vertical &&
1897 (clickPoint.y >= thumb.top) &&
1898 (clickPoint.y <= thumb.bottom)) ||
1899 (!vertical &&
1900 (clickPoint.x >= thumb.left) &&
1901 (clickPoint.x <= thumb.right)))
1902 {
1903 //ScrollMode
1904 infoPtr->flags |= TB_SCROLL_MODE;
1905 SetCapture(hwnd);
1906 SetTimer(hwnd,SCROLL_TIMER_ID,SCROLL_TIME,NULL);
1907
1908 return 0;
1909 }
1910
1911 clickPos = TRACKBAR_ConvertPlaceToPosition(infoPtr,clickPlace,vertical);
1912 prevPos = infoPtr->nPos;
1913
1914 if (clickPos > prevPos)
1915 { /* similar to VK_NEXT */
1916 infoPtr->nPos += infoPtr->nPageSize;
1917 if (infoPtr->nPos > infoPtr->nRangeMax) infoPtr->nPos = infoPtr->nRangeMax;
1918 if (prevPos != infoPtr->nPos) TRACKBAR_SendNotify(hwnd,TB_PAGEUP);
1919 } else
1920 { /* similar to VK_PRIOR */
1921 infoPtr->nPos -= infoPtr->nPageSize;
1922 if (infoPtr->nPos < infoPtr->nRangeMin) infoPtr->nPos = infoPtr->nRangeMin;
1923 if (prevPos != infoPtr->nPos) TRACKBAR_SendNotify(hwnd,TB_PAGEDOWN);
1924 }
1925
1926 if (prevPos != infoPtr->nPos)
1927 {
1928 infoPtr->flags |= TB_THUMBPOSCHANGED;
1929 TRACKBAR_UpdateThumbPosition(hwnd,prevPos,TRUE);
1930 }
1931
1932 //ScrollMode
1933 infoPtr->flags |= TB_SCROLL_MODE;
1934 SetCapture(hwnd);
1935 SetTimer(hwnd,SCROLL_TIMER_ID,SCROLL_TIME,NULL);
1936
1937 return 0;
1938}
1939
1940
1941static LRESULT
1942TRACKBAR_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1943{
1944 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
1945
1946 if (infoPtr->flags & TB_DRAG_MODE)
1947 {
1948 TRACKBAR_SendNotify(hwnd,TB_ENDTRACK);
1949
1950 infoPtr->flags &= ~TB_DRAG_MODE;
1951
1952 if (GetCapture() == hwnd)
1953 {
1954 NMHDR nmhdr;
1955
1956 nmhdr.hwndFrom = hwnd;
1957 nmhdr.idFrom = GetWindowLongA(hwnd,GWL_ID);
1958 nmhdr.code = NM_RELEASEDCAPTURE;
1959
1960 SendMessageA(GetParent(hwnd),WM_NOTIFY,(WPARAM)nmhdr.idFrom,(LPARAM)&nmhdr);
1961
1962 ReleaseCapture();
1963 }
1964
1965 TRACKBAR_UpdateThumbPosition(hwnd,infoPtr->nPos,TRUE); //change arrow color
1966 }
1967
1968 if (infoPtr->flags & TB_SCROLL_MODE)
1969 {
1970 infoPtr->flags &= ~TB_SCROLL_MODE;
1971
1972 if (GetCapture() == hwnd)
1973 {
1974 NMHDR nmhdr;
1975
1976 nmhdr.hwndFrom = hwnd;
1977 nmhdr.idFrom = GetWindowLongA(hwnd,GWL_ID);
1978 nmhdr.code = NM_RELEASEDCAPTURE;
1979
1980 SendMessageA(GetParent(hwnd),WM_NOTIFY,(WPARAM)nmhdr.idFrom,(LPARAM)&nmhdr);
1981
1982 ReleaseCapture();
1983 }
1984
1985 KillTimer(hwnd,SCROLL_TIMER_ID);
1986 }
1987
1988 if (GetWindowLongA (hwnd, GWL_STYLE) & TBS_TOOLTIPS)
1989 { /* disable tooltip */
1990 TTTOOLINFOA ti;
1991
1992 ti.cbSize = sizeof(TTTOOLINFOA);
1993 ti.uId = 0;
1994 ti.hwnd = (UINT)hwnd;
1995
1996 infoPtr->flags &= ~TB_SHOW_TOOLTIP;
1997 SendMessageA (infoPtr->hwndToolTip,TTM_TRACKACTIVATE,(WPARAM)FALSE,(LPARAM)&ti);
1998 }
1999
2000 return 0;
2001}
2002
2003
2004static LRESULT TRACKBAR_Timer(HWND hwnd,WPARAM wParam,LPARAM lParam)
2005{
2006 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr(hwnd);
2007 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
2008 POINT mousePoint;
2009 INT mousePlace,prevPos,newPos,vertical;
2010 DOUBLE mousePos;
2011
2012 GetCursorPos(&mousePoint);
2013 ScreenToClient(hwnd,&mousePoint);
2014
2015 vertical = dwStyle & TBS_VERT;
2016 if (vertical) mousePlace = mousePoint.y;
2017 else mousePlace = mousePoint.x;
2018
2019 mousePos = TRACKBAR_ConvertPlaceToPosition(infoPtr,mousePlace,vertical);
2020 prevPos = infoPtr->nPos;
2021
2022 if (mousePos > (INT)mousePos+0.5) newPos = mousePos+1;
2023 else newPos = mousePos;
2024 if (newPos == prevPos) return 0;
2025
2026 if (newPos > prevPos)
2027 { /* similar to VK_NEXT */
2028 infoPtr->nPos += infoPtr->nPageSize;
2029 if (infoPtr->nPos > infoPtr->nRangeMax) infoPtr->nPos = infoPtr->nRangeMax;
2030 if (prevPos != infoPtr->nPos) TRACKBAR_SendNotify(hwnd,TB_PAGEUP);
2031 } else
2032 { /* similar to VK_PRIOR */
2033 infoPtr->nPos -= infoPtr->nPageSize;
2034 if (infoPtr->nPos < infoPtr->nRangeMin) infoPtr->nPos = infoPtr->nRangeMin;
2035 if (prevPos != infoPtr->nPos) TRACKBAR_SendNotify(hwnd,TB_PAGEDOWN);
2036 }
2037
2038 if (prevPos != infoPtr->nPos)
2039 {
2040 infoPtr->flags |= TB_THUMBPOSCHANGED;
2041 TRACKBAR_UpdateThumbPosition(hwnd,prevPos,FALSE);
2042 }
2043
2044 return 0;
2045}
2046
2047static LRESULT
2048TRACKBAR_CaptureChanged (HWND hwnd, WPARAM wParam, LPARAM lParam)
2049{
2050 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
2051
2052 if (infoPtr->flags & TB_DRAGPOSVALID)
2053 {
2054 int lastPos = infoPtr->nPos;
2055 infoPtr->nPos = infoPtr->dragPos;
2056 if (lastPos != infoPtr->nPos) TRACKBAR_UpdateThumbPosition(hwnd,lastPos,TRUE);
2057 }
2058
2059 infoPtr->flags &= ~ TB_DRAGPOSVALID;
2060
2061 if (infoPtr->flags & TB_SCROLL_MODE)
2062 {
2063 infoPtr->flags &= ~TB_SCROLL_MODE;
2064 KillTimer(hwnd,SCROLL_TIMER_ID);
2065 }
2066
2067 TRACKBAR_SendNotify(hwnd,TB_ENDTRACK);
2068 return 0;
2069}
2070
2071
2072static LRESULT
2073TRACKBAR_Paint (HWND hwnd, WPARAM wParam)
2074{
2075 HDC hdc;
2076 PAINTSTRUCT ps;
2077
2078 hdc = wParam == 0 ? BeginPaint(hwnd,&ps) : (HDC)wParam;
2079 TRACKBAR_Draw(hwnd,hdc);
2080 if (!wParam) EndPaint(hwnd,&ps);
2081 return 0;
2082}
2083
2084
2085static LRESULT
2086TRACKBAR_SetFocus (HWND hwnd, WPARAM wParam, LPARAM lParam)
2087{
2088 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
2089 HDC hdc;
2090 RECT rcClient;
2091
2092// TRACE (trackbar,"\n");
2093 if (!infoPtr->bFocus)
2094 {
2095 infoPtr->bFocus = TRUE;
2096
2097 GetClientRect (hwnd,&rcClient);
2098 hdc = GetDC (hwnd);
2099 DrawFocusRect (hdc,&rcClient);
2100 ReleaseDC(hwnd,hdc);
2101
2102 }
2103 return 0;
2104}
2105
2106static LRESULT
2107TRACKBAR_KillFocus (HWND hwnd, WPARAM wParam, LPARAM lParam)
2108{
2109 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
2110 HDC hdc;
2111 RECT rcClient;
2112
2113// TRACE (trackbar,"\n");
2114
2115 infoPtr->flags &= ~TB_DRAG_MODE;
2116 if (infoPtr->bFocus)
2117 {
2118 infoPtr->bFocus = FALSE;
2119
2120 GetClientRect(hwnd,&rcClient);
2121 hdc = GetDC (hwnd);
2122 DrawFocusRect(hdc,&rcClient); //XOR removes
2123 ReleaseDC(hwnd,hdc);
2124 }
2125
2126 return 0;
2127}
2128
2129static LRESULT
2130TRACKBAR_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
2131{
2132 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
2133
2134 TRACKBAR_CalcChannel (hwnd, infoPtr);
2135 TRACKBAR_AlignBuddies (hwnd, infoPtr);
2136
2137 return 0;
2138}
2139
2140
2141static BOOL
2142TRACKBAR_SendNotify (HWND hwnd, UINT code)
2143{
2144// TRACE (trackbar, "%x\n",code);
2145
2146 if (GetWindowLongA(hwnd, GWL_STYLE) & TBS_VERT)
2147 {
2148 return (BOOL)SendMessageA(GetParent(hwnd),WM_VSCROLL,(WPARAM)code,(LPARAM)hwnd);
2149 } else
2150 {
2151 return (BOOL)SendMessageA(GetParent(hwnd),WM_HSCROLL,(WPARAM)code,(LPARAM)hwnd);
2152 }
2153}
2154
2155
2156static LRESULT
2157TRACKBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
2158{
2159 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr (hwnd);
2160 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
2161 SHORT clickPlace;
2162 DOUBLE dragPos;
2163
2164// TRACE (trackbar, "%x\n",wParam);
2165
2166 if (!(infoPtr->flags & TB_DRAG_MODE)) return TRUE;
2167
2168 if (dwStyle & TBS_VERT) clickPlace = (SHORT)HIWORD(lParam);
2169 else clickPlace = (SHORT)LOWORD(lParam);
2170
2171 dragPos = TRACKBAR_ConvertPlaceToPosition(infoPtr,clickPlace,dwStyle & TBS_VERT);
2172 if (dragPos > ((INT)dragPos)+0.5) infoPtr->dragPos = dragPos + 1;
2173 else infoPtr->dragPos = dragPos;
2174
2175 if (infoPtr->nPos == infoPtr->dragPos) return TRUE; //nothing changed
2176
2177 infoPtr->flags |= TB_DRAGPOSVALID;
2178
2179 TRACKBAR_UpdateThumbPosition(hwnd,infoPtr->nPos,FALSE); //infoPtr->nPos now set
2180
2181 TRACKBAR_SendNotify(hwnd,TB_THUMBTRACK | (infoPtr->nPos >> 16));
2182
2183 if (infoPtr->flags & TB_SHOW_TOOLTIP)
2184 {
2185 POINT pt;
2186 TTTOOLINFOA ti;
2187 char buf[80];
2188
2189 ti.cbSize = sizeof(TTTOOLINFOA);
2190 ti.hwnd = hwnd;
2191 ti.uId = 0;
2192 ti.hinst = 0;
2193 sprintf (buf,"%d",infoPtr->nPos);
2194 ti.lpszText = (LPSTR)buf;
2195
2196 SendMessageA(infoPtr->hwndToolTip,TTM_UPDATETIPTEXTA,0,(LPARAM)&ti);
2197 TRACKBAR_CalcToolTipPos(hwnd,dwStyle,infoPtr,&pt);
2198 SendMessageA(infoPtr->hwndToolTip,TTM_TRACKPOSITION,0,(LPARAM)MAKELPARAM(pt.x,pt.y));
2199 }
2200
2201 return TRUE;
2202}
2203
2204
2205static LRESULT
2206TRACKBAR_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
2207{
2208 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr(hwnd);
2209 INT pos;
2210
2211// TRACE (trackbar, "%x\n",wParam);
2212
2213 if (infoPtr->flags & TB_DRAG_MODE) return TRUE;
2214
2215 pos = infoPtr->nPos;
2216 switch (wParam) {
2217 case VK_LEFT:
2218 case VK_UP:
2219 if (infoPtr->nPos == infoPtr->nRangeMin) return FALSE;
2220 infoPtr->nPos -= infoPtr->nLineSize;
2221 if (infoPtr->nPos < infoPtr->nRangeMin)
2222 infoPtr->nPos = infoPtr->nRangeMin;
2223 TRACKBAR_SendNotify(hwnd,TB_LINEUP);
2224 break;
2225 case VK_RIGHT:
2226 case VK_DOWN:
2227 if (infoPtr->nPos == infoPtr->nRangeMax) return FALSE;
2228 infoPtr->nPos += infoPtr->nLineSize;
2229 if (infoPtr->nPos > infoPtr->nRangeMax)
2230 infoPtr->nPos = infoPtr->nRangeMax;
2231 TRACKBAR_SendNotify (hwnd, TB_LINEDOWN);
2232 break;
2233 case VK_NEXT:
2234 if (infoPtr->nPos == infoPtr->nRangeMax) return FALSE;
2235 infoPtr->nPos += infoPtr->nPageSize;
2236 if (infoPtr->nPos > infoPtr->nRangeMax)
2237 infoPtr->nPos = infoPtr->nRangeMax;
2238 TRACKBAR_SendNotify (hwnd, TB_PAGEUP);
2239 break;
2240 case VK_PRIOR:
2241 if (infoPtr->nPos == infoPtr->nRangeMin) return FALSE;
2242 infoPtr->nPos -= infoPtr->nPageSize;
2243 if (infoPtr->nPos < infoPtr->nRangeMin)
2244 infoPtr->nPos = infoPtr->nRangeMin;
2245 TRACKBAR_SendNotify (hwnd, TB_PAGEDOWN);
2246 break;
2247 case VK_HOME:
2248 if (infoPtr->nPos == infoPtr->nRangeMin) return FALSE;
2249 infoPtr->nPos = infoPtr->nRangeMin;
2250 TRACKBAR_SendNotify (hwnd, TB_TOP);
2251 break;
2252 case VK_END:
2253 if (infoPtr->nPos == infoPtr->nRangeMax) return FALSE;
2254 infoPtr->nPos = infoPtr->nRangeMax;
2255 TRACKBAR_SendNotify (hwnd, TB_BOTTOM);
2256 break;
2257 }
2258
2259 if (pos != infoPtr->nPos)
2260 {
2261 infoPtr->flags |= TB_THUMBPOSCHANGED;
2262 TRACKBAR_UpdateThumbPosition(hwnd,pos,FALSE);
2263 }
2264
2265 return TRUE;
2266}
2267
2268
2269static LRESULT
2270TRACKBAR_KeyUp (HWND hwnd, WPARAM wParam)
2271{
2272 TRACKBAR_INFO *infoPtr = TRACKBAR_GetInfoPtr(hwnd);
2273
2274 if (infoPtr->flags & TB_DRAG_MODE) return TRUE;
2275
2276 switch (wParam) {
2277 case VK_LEFT:
2278 case VK_UP:
2279 case VK_RIGHT:
2280 case VK_DOWN:
2281 case VK_NEXT:
2282 case VK_PRIOR:
2283 case VK_HOME:
2284 case VK_END:
2285 TRACKBAR_SendNotify (hwnd, TB_ENDTRACK);
2286 }
2287 return TRUE;
2288}
2289
2290
2291static LRESULT WINAPI
2292TRACKBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2293{
2294 switch (uMsg)
2295 {
2296 case TBM_CLEARSEL:
2297 return TRACKBAR_ClearSel (hwnd, wParam, lParam);
2298
2299 case TBM_CLEARTICS:
2300 return TRACKBAR_ClearTics (hwnd, wParam, lParam);
2301
2302 case TBM_GETBUDDY:
2303 return TRACKBAR_GetBuddy (hwnd, wParam, lParam);
2304
2305 case TBM_GETCHANNELRECT:
2306 return TRACKBAR_GetChannelRect (hwnd, wParam, lParam);
2307
2308 case TBM_GETLINESIZE:
2309 return TRACKBAR_GetLineSize (hwnd, wParam, lParam);
2310
2311 case TBM_GETNUMTICS:
2312 return TRACKBAR_GetNumTics (hwnd, wParam, lParam);
2313
2314 case TBM_GETPAGESIZE:
2315 return TRACKBAR_GetPageSize (hwnd, wParam, lParam);
2316
2317 case TBM_GETPOS:
2318 return TRACKBAR_GetPos (hwnd, wParam, lParam);
2319
2320 case TBM_GETPTICS:
2321 return TRACKBAR_GetPTics (hwnd);
2322
2323 case TBM_GETRANGEMAX:
2324 return TRACKBAR_GetRangeMax (hwnd, wParam, lParam);
2325
2326 case TBM_GETRANGEMIN:
2327 return TRACKBAR_GetRangeMin (hwnd, wParam, lParam);
2328
2329 case TBM_GETSELEND:
2330 return TRACKBAR_GetSelEnd (hwnd, wParam, lParam);
2331
2332 case TBM_GETSELSTART:
2333 return TRACKBAR_GetSelStart (hwnd, wParam, lParam);
2334
2335 case TBM_GETTHUMBLENGTH:
2336 return TRACKBAR_GetThumbLength (hwnd, wParam, lParam);
2337
2338 case TBM_GETTHUMBRECT:
2339 return TRACKBAR_GetThumbRect (hwnd, wParam, lParam);
2340
2341 case TBM_GETTIC:
2342 return TRACKBAR_GetTic (hwnd, wParam, lParam);
2343
2344 case TBM_GETTICPOS:
2345 return TRACKBAR_GetTicPos (hwnd, wParam, lParam);
2346
2347 case TBM_GETTOOLTIPS:
2348 return TRACKBAR_GetToolTips (hwnd, wParam, lParam);
2349
2350/* case TBM_GETUNICODEFORMAT: */
2351
2352 case TBM_SETBUDDY:
2353 return TRACKBAR_SetBuddy (hwnd, wParam, lParam);
2354
2355 case TBM_SETLINESIZE:
2356 return TRACKBAR_SetLineSize (hwnd, wParam, lParam);
2357
2358 case TBM_SETPAGESIZE:
2359 return TRACKBAR_SetPageSize (hwnd, wParam, lParam);
2360
2361 case TBM_SETPOS:
2362 return TRACKBAR_SetPos (hwnd, wParam, lParam);
2363
2364 case TBM_SETRANGE:
2365 return TRACKBAR_SetRange (hwnd, wParam, lParam);
2366
2367 case TBM_SETRANGEMAX:
2368 return TRACKBAR_SetRangeMax (hwnd, wParam, lParam);
2369
2370 case TBM_SETRANGEMIN:
2371 return TRACKBAR_SetRangeMin (hwnd, wParam, lParam);
2372
2373 case TBM_SETSEL:
2374 return TRACKBAR_SetSel (hwnd, wParam, lParam);
2375
2376 case TBM_SETSELEND:
2377 return TRACKBAR_SetSelEnd (hwnd, wParam, lParam);
2378
2379 case TBM_SETSELSTART:
2380 return TRACKBAR_SetSelStart (hwnd, wParam, lParam);
2381
2382 case TBM_SETTHUMBLENGTH:
2383 return TRACKBAR_SetThumbLength (hwnd, wParam, lParam);
2384
2385 case TBM_SETTIC:
2386 return TRACKBAR_SetTic (hwnd, wParam, lParam);
2387
2388 case TBM_SETTICFREQ:
2389 return TRACKBAR_SetTicFreq (hwnd, wParam);
2390
2391 case TBM_SETTIPSIDE:
2392 return TRACKBAR_SetTipSide (hwnd, wParam, lParam);
2393
2394 case TBM_SETTOOLTIPS:
2395 return TRACKBAR_SetToolTips (hwnd, wParam, lParam);
2396
2397/* case TBM_SETUNICODEFORMAT: */
2398
2399
2400 case WM_CAPTURECHANGED:
2401 return TRACKBAR_CaptureChanged (hwnd, wParam, lParam);
2402
2403 case WM_CREATE:
2404 return TRACKBAR_Create (hwnd, wParam, lParam);
2405
2406 case WM_DESTROY:
2407 return TRACKBAR_Destroy (hwnd, wParam, lParam);
2408
2409/* case WM_ENABLE: */
2410
2411/* case WM_ERASEBKGND: */
2412/* return 0; */
2413
2414 case WM_GETDLGCODE:
2415 return DLGC_WANTARROWS;
2416
2417 case WM_KEYDOWN:
2418 return TRACKBAR_KeyDown (hwnd, wParam, lParam);
2419
2420 case WM_KEYUP:
2421 return TRACKBAR_KeyUp (hwnd, wParam);
2422
2423 case WM_LBUTTONDOWN:
2424 return TRACKBAR_LButtonDown (hwnd, wParam, lParam);
2425
2426 case WM_LBUTTONUP:
2427 return TRACKBAR_LButtonUp (hwnd, wParam, lParam);
2428
2429 case WM_TIMER:
2430 return TRACKBAR_Timer(hwnd,wParam,lParam);
2431
2432 case WM_MOUSEMOVE:
2433 return TRACKBAR_MouseMove (hwnd, wParam, lParam);
2434
2435 case WM_PAINT:
2436 return TRACKBAR_Paint (hwnd, wParam);
2437
2438 case WM_SETFOCUS:
2439 return TRACKBAR_SetFocus (hwnd, wParam, lParam);
2440
2441 case WM_KILLFOCUS:
2442 return TRACKBAR_KillFocus (hwnd, wParam, lParam);
2443
2444 case WM_SIZE:
2445 return TRACKBAR_Size (hwnd, wParam, lParam);
2446
2447 case WM_WININICHANGE:
2448 return TRACKBAR_InitializeThumb (hwnd);
2449
2450 default:
2451// if (uMsg >= WM_USER)
2452// ERR (trackbar, "unknown msg %04x wp=%08x lp=%08lx\n",
2453// uMsg, wParam, lParam);
2454 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
2455 }
2456 return 0;
2457}
2458
2459
2460VOID
2461TRACKBAR_Register (VOID)
2462{
2463 WNDCLASSA wndClass;
2464
2465 if (GlobalFindAtomA (TRACKBAR_CLASSA)) return;
2466
2467 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
2468 wndClass.style = CS_GLOBALCLASS;
2469 wndClass.lpfnWndProc = (WNDPROC)TRACKBAR_WindowProc;
2470 wndClass.cbClsExtra = 0;
2471 wndClass.cbWndExtra = sizeof(TRACKBAR_INFO *);
2472 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
2473 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
2474 wndClass.lpszClassName = TRACKBAR_CLASSA;
2475
2476 RegisterClassA (&wndClass);
2477}
2478
2479
2480VOID
2481TRACKBAR_Unregister (VOID)
2482{
2483 if (GlobalFindAtomA (TRACKBAR_CLASSA))
2484 UnregisterClassA (TRACKBAR_CLASSA, (HINSTANCE)NULL);
2485}
2486
Note: See TracBrowser for help on using the repository browser.