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

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

progress, trackbar: finished version 5.00 (IE5)

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