1 | /*
|
---|
2 | * Trackbar control
|
---|
3 | *
|
---|
4 | * Copyright 1998, 1999 Eric Kohl <ekohl@abo.rhein-zeitung.de>
|
---|
5 | * Copyright 1998, 1999 Alex Priem <alexp@sci.kun.nl>
|
---|
6 | * Copyright 2002 Dimitrie O. Paun <dimi@bigfoot.com>
|
---|
7 | *
|
---|
8 | * This library is free software; you can redistribute it and/or
|
---|
9 | * modify it under the terms of the GNU Lesser General Public
|
---|
10 | * License as published by the Free Software Foundation; either
|
---|
11 | * version 2.1 of the License, or (at your option) any later version.
|
---|
12 | *
|
---|
13 | * This library is distributed in the hope that it will be useful,
|
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
16 | * Lesser General Public License for more details.
|
---|
17 | *
|
---|
18 | * You should have received a copy of the GNU Lesser General Public
|
---|
19 | * License along with this library; if not, write to the Free Software
|
---|
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
21 | *
|
---|
22 | * NOTE
|
---|
23 | *
|
---|
24 | * This code was audited for completeness against the documented features
|
---|
25 | * of Comctl32.dll version 6.0 on Sep. 12, 2002, by Dimitrie O. Paun.
|
---|
26 | *
|
---|
27 | * Unless otherwise noted, we believe this code to be complete, as per
|
---|
28 | * the specification mentioned above.
|
---|
29 | * If you discover missing features, or bugs, please note them below.
|
---|
30 | *
|
---|
31 | */
|
---|
32 |
|
---|
33 | #include <stdio.h>
|
---|
34 | #include <stdlib.h>
|
---|
35 | #include <string.h>
|
---|
36 |
|
---|
37 | #include "winbase.h"
|
---|
38 | #include "commctrl.h"
|
---|
39 | #include "wine/debug.h"
|
---|
40 |
|
---|
41 | #include "comctl32.h"
|
---|
42 |
|
---|
43 | WINE_DEFAULT_DEBUG_CHANNEL(trackbar);
|
---|
44 |
|
---|
45 | typedef struct
|
---|
46 | {
|
---|
47 | HWND hwndSelf;
|
---|
48 | LONG lRangeMin;
|
---|
49 | LONG lRangeMax;
|
---|
50 | LONG lLineSize;
|
---|
51 | LONG lPageSize;
|
---|
52 | LONG lSelMin;
|
---|
53 | LONG lSelMax;
|
---|
54 | LONG lPos;
|
---|
55 | UINT uThumbLen;
|
---|
56 | UINT uNumTics;
|
---|
57 | UINT uTicFreq;
|
---|
58 | HWND hwndNotify;
|
---|
59 | HWND hwndToolTip;
|
---|
60 | HWND hwndBuddyLA;
|
---|
61 | HWND hwndBuddyRB;
|
---|
62 | INT fLocation;
|
---|
63 | INT flags;
|
---|
64 | BOOL bUnicode;
|
---|
65 | RECT rcChannel;
|
---|
66 | RECT rcSelection;
|
---|
67 | RECT rcThumb;
|
---|
68 | LPLONG tics;
|
---|
69 | } TRACKBAR_INFO;
|
---|
70 |
|
---|
71 | DEFINE_COMMON_NOTIFICATIONS(TRACKBAR_INFO, hwndSelf);
|
---|
72 |
|
---|
73 | #define TB_REFRESH_TIMER 1
|
---|
74 | #define TB_REFRESH_DELAY 500
|
---|
75 |
|
---|
76 | #define TOOLTIP_OFFSET 2 /* distance from ctrl edge to tooltip */
|
---|
77 |
|
---|
78 | /* Used by TRACKBAR_Refresh to find out which parts of the control
|
---|
79 | need to be recalculated */
|
---|
80 |
|
---|
81 | #define TB_THUMBPOSCHANGED 1
|
---|
82 | #define TB_THUMBSIZECHANGED 2
|
---|
83 | #define TB_THUMBCHANGED (TB_THUMBPOSCHANGED | TB_THUMBSIZECHANGED)
|
---|
84 | #define TB_SELECTIONCHANGED 4
|
---|
85 | #define TB_DRAG_MODE 8 /* we're dragging the slider */
|
---|
86 | #define TB_AUTO_PAGE_LEFT 16
|
---|
87 | #define TB_AUTO_PAGE_RIGHT 32
|
---|
88 | #define TB_AUTO_PAGE (TB_AUTO_PAGE_LEFT | TB_AUTO_PAGE_RIGHT)
|
---|
89 |
|
---|
90 | /* helper defines for TRACKBAR_DrawTic */
|
---|
91 | #define TIC_EDGE 0x20
|
---|
92 | #define TIC_SELECTIONMARKMAX 0x80
|
---|
93 | #define TIC_SELECTIONMARKMIN 0x100
|
---|
94 | #define TIC_SELECTIONMARK (TIC_SELECTIONMARKMAX | TIC_SELECTIONMARKMIN)
|
---|
95 |
|
---|
96 | static BOOL TRACKBAR_SendNotify (TRACKBAR_INFO *infoPtr, UINT code);
|
---|
97 |
|
---|
98 | static inline int
|
---|
99 | notify_customdraw(NMCUSTOMDRAW *pnmcd, int stage)
|
---|
100 | {
|
---|
101 | pnmcd->dwDrawStage = stage;
|
---|
102 | return SendMessageW (GetParent(pnmcd->hdr.hwndFrom), WM_NOTIFY,
|
---|
103 | pnmcd->hdr.idFrom, (LPARAM)pnmcd);
|
---|
104 | }
|
---|
105 |
|
---|
106 | static void TRACKBAR_RecalculateTics (TRACKBAR_INFO *infoPtr)
|
---|
107 | {
|
---|
108 | int i, tic, nrTics;
|
---|
109 |
|
---|
110 | if (infoPtr->uTicFreq && infoPtr->lRangeMax >= infoPtr->lRangeMin)
|
---|
111 | nrTics=(infoPtr->lRangeMax - infoPtr->lRangeMin)/infoPtr->uTicFreq;
|
---|
112 | else {
|
---|
113 | nrTics = 0;
|
---|
114 | COMCTL32_Free (infoPtr->tics);
|
---|
115 | infoPtr->tics = NULL;
|
---|
116 | infoPtr->uNumTics = 0;
|
---|
117 | return;
|
---|
118 | }
|
---|
119 |
|
---|
120 | if (nrTics != infoPtr->uNumTics) {
|
---|
121 | infoPtr->tics=COMCTL32_ReAlloc (infoPtr->tics,
|
---|
122 | (nrTics+1)*sizeof (DWORD));
|
---|
123 | if (!infoPtr->tics) {
|
---|
124 | infoPtr->uNumTics = 0;
|
---|
125 | notify_outofmemory(infoPtr);
|
---|
126 | return;
|
---|
127 | }
|
---|
128 | infoPtr->uNumTics = nrTics;
|
---|
129 | }
|
---|
130 |
|
---|
131 | tic = infoPtr->lRangeMin + infoPtr->uTicFreq;
|
---|
132 | for (i = 0; i < nrTics; i++, tic += infoPtr->uTicFreq)
|
---|
133 | infoPtr->tics[i] = tic;
|
---|
134 | }
|
---|
135 |
|
---|
136 | /* converts from physical (mouse) position to logical position
|
---|
137 | (in range of trackbar) */
|
---|
138 |
|
---|
139 | static inline LONG
|
---|
140 | TRACKBAR_ConvertPlaceToPosition (TRACKBAR_INFO *infoPtr, int place,
|
---|
141 | int vertical)
|
---|
142 | {
|
---|
143 | double range, width, pos;
|
---|
144 |
|
---|
145 | range = infoPtr->lRangeMax - infoPtr->lRangeMin;
|
---|
146 | if (vertical) {
|
---|
147 | width = infoPtr->rcChannel.bottom - infoPtr->rcChannel.top;
|
---|
148 | pos = (range*(place - infoPtr->rcChannel.top)) / width;
|
---|
149 | } else {
|
---|
150 | width = infoPtr->rcChannel.right - infoPtr->rcChannel.left;
|
---|
151 | pos = (range*(place - infoPtr->rcChannel.left)) / width;
|
---|
152 | }
|
---|
153 | pos += infoPtr->lRangeMin;
|
---|
154 | if (pos > infoPtr->lRangeMax)
|
---|
155 | pos = infoPtr->lRangeMax;
|
---|
156 | else if (pos < infoPtr->lRangeMin)
|
---|
157 | pos = infoPtr->lRangeMin;
|
---|
158 |
|
---|
159 | TRACE("%.2f\n", pos);
|
---|
160 | return (LONG)(pos + 0.5);
|
---|
161 | }
|
---|
162 |
|
---|
163 |
|
---|
164 | /* return: 0> prev, 0 none, >0 next */
|
---|
165 | static LONG
|
---|
166 | TRACKBAR_GetAutoPageDirection (TRACKBAR_INFO *infoPtr, POINT clickPoint)
|
---|
167 | {
|
---|
168 | DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
|
---|
169 | RECT pageRect;
|
---|
170 |
|
---|
171 | if (dwStyle & TBS_VERT) {
|
---|
172 | pageRect.top = infoPtr->rcChannel.top;
|
---|
173 | pageRect.bottom = infoPtr->rcChannel.bottom;
|
---|
174 | pageRect.left = infoPtr->rcThumb.left;
|
---|
175 | pageRect.right = infoPtr->rcThumb.right;
|
---|
176 | } else {
|
---|
177 | pageRect.top = infoPtr->rcThumb.top;
|
---|
178 | pageRect.bottom = infoPtr->rcThumb.bottom;
|
---|
179 | pageRect.left = infoPtr->rcChannel.left;
|
---|
180 | pageRect.right = infoPtr->rcChannel.right;
|
---|
181 | }
|
---|
182 |
|
---|
183 |
|
---|
184 | if (PtInRect(&pageRect, clickPoint))
|
---|
185 | {
|
---|
186 | int clickPlace = (dwStyle & TBS_VERT) ? clickPoint.y : clickPoint.x;
|
---|
187 |
|
---|
188 | LONG clickPos = TRACKBAR_ConvertPlaceToPosition(infoPtr, clickPlace,
|
---|
189 | dwStyle & TBS_VERT);
|
---|
190 | return clickPos - infoPtr->lPos;
|
---|
191 | }
|
---|
192 |
|
---|
193 | return 0;
|
---|
194 | }
|
---|
195 |
|
---|
196 | static void inline
|
---|
197 | TRACKBAR_PageUp (TRACKBAR_INFO *infoPtr)
|
---|
198 | {
|
---|
199 | if (infoPtr->lPos == infoPtr->lRangeMax) return;
|
---|
200 |
|
---|
201 | infoPtr->lPos += infoPtr->lPageSize;
|
---|
202 | if (infoPtr->lPos > infoPtr->lRangeMax)
|
---|
203 | infoPtr->lPos = infoPtr->lRangeMax;
|
---|
204 | TRACKBAR_SendNotify (infoPtr, TB_PAGEUP);
|
---|
205 | }
|
---|
206 |
|
---|
207 |
|
---|
208 | static void inline
|
---|
209 | TRACKBAR_PageDown (TRACKBAR_INFO *infoPtr)
|
---|
210 | {
|
---|
211 | if (infoPtr->lPos == infoPtr->lRangeMin) return;
|
---|
212 |
|
---|
213 | infoPtr->lPos -= infoPtr->lPageSize;
|
---|
214 | if (infoPtr->lPos < infoPtr->lRangeMin)
|
---|
215 | infoPtr->lPos = infoPtr->lRangeMin;
|
---|
216 | TRACKBAR_SendNotify (infoPtr, TB_PAGEDOWN);
|
---|
217 | }
|
---|
218 |
|
---|
219 | static void
|
---|
220 | TRACKBAR_CalcChannel (TRACKBAR_INFO *infoPtr)
|
---|
221 | {
|
---|
222 | DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
|
---|
223 | INT cyChannel, offsetthumb, offsetedge;
|
---|
224 | RECT lpRect, *channel = & infoPtr->rcChannel;
|
---|
225 |
|
---|
226 | GetClientRect (infoPtr->hwndSelf, &lpRect);
|
---|
227 |
|
---|
228 | offsetthumb = (int)(infoPtr->uThumbLen/4.5);
|
---|
229 | offsetedge = offsetthumb + 3;
|
---|
230 | cyChannel = (dwStyle & TBS_ENABLESELRANGE) ? (offsetthumb+1)*3 : 4;
|
---|
231 |
|
---|
232 | if (dwStyle & TBS_VERT) {
|
---|
233 | channel->top = lpRect.top + offsetedge;
|
---|
234 | channel->bottom = lpRect.bottom - offsetedge;
|
---|
235 | channel->left = lpRect.left + offsetthumb;
|
---|
236 | if (dwStyle & (TBS_BOTH | TBS_LEFT)) channel->left += 8;
|
---|
237 | channel->right = channel->left + cyChannel;
|
---|
238 | } else {
|
---|
239 | channel->left = lpRect.left + offsetedge;
|
---|
240 | channel->right = lpRect.right - offsetedge;
|
---|
241 | channel->top = lpRect.top + offsetthumb;
|
---|
242 | if (dwStyle & (TBS_BOTH | TBS_TOP)) channel->top += 8;
|
---|
243 | channel->bottom = channel->top + cyChannel;
|
---|
244 | }
|
---|
245 | }
|
---|
246 |
|
---|
247 | static void
|
---|
248 | TRACKBAR_CalcThumb (TRACKBAR_INFO *infoPtr, LONG lPos, RECT *thumb)
|
---|
249 | {
|
---|
250 | int range, width, thumbdepth;
|
---|
251 | DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
|
---|
252 |
|
---|
253 | range=infoPtr->lRangeMax - infoPtr->lRangeMin;
|
---|
254 | thumbdepth = ((int)(infoPtr->uThumbLen / 4.5) * 2) + 2;
|
---|
255 |
|
---|
256 | if (!range) range = 1;
|
---|
257 |
|
---|
258 | if (dwStyle & TBS_VERT)
|
---|
259 | {
|
---|
260 | width=infoPtr->rcChannel.bottom - infoPtr->rcChannel.top;
|
---|
261 |
|
---|
262 | if (dwStyle & (TBS_BOTH | TBS_LEFT))
|
---|
263 | thumb->left = 10;
|
---|
264 | else
|
---|
265 | thumb->left = 2;
|
---|
266 | thumb->right = thumb -> left + infoPtr->uThumbLen;
|
---|
267 | thumb->top = infoPtr->rcChannel.top +
|
---|
268 | (width*(lPos - infoPtr->lRangeMin))/range -
|
---|
269 | thumbdepth/2;
|
---|
270 | thumb->bottom = thumb->top + thumbdepth;
|
---|
271 | }
|
---|
272 | else
|
---|
273 | {
|
---|
274 | width=infoPtr->rcChannel.right - infoPtr->rcChannel.left;
|
---|
275 |
|
---|
276 | thumb->left = infoPtr->rcChannel.left +
|
---|
277 | (width*(lPos - infoPtr->lRangeMin))/range -
|
---|
278 | thumbdepth/2;
|
---|
279 | thumb->right = thumb->left + thumbdepth;
|
---|
280 | if (dwStyle & (TBS_BOTH | TBS_TOP))
|
---|
281 | thumb->top = 10;
|
---|
282 | else
|
---|
283 | thumb->top = 2;
|
---|
284 | thumb->bottom = thumb->top + infoPtr->uThumbLen;
|
---|
285 | }
|
---|
286 | }
|
---|
287 |
|
---|
288 | inline static void
|
---|
289 | TRACKBAR_UpdateThumb (TRACKBAR_INFO *infoPtr)
|
---|
290 | {
|
---|
291 | TRACKBAR_CalcThumb(infoPtr, infoPtr->lPos, &infoPtr->rcThumb);
|
---|
292 | }
|
---|
293 |
|
---|
294 | static inline void
|
---|
295 | TRACKBAR_InvalidateAll(TRACKBAR_INFO * infoPtr)
|
---|
296 | {
|
---|
297 | InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
|
---|
298 | }
|
---|
299 |
|
---|
300 | static void
|
---|
301 | TRACKBAR_InvalidateThumb (TRACKBAR_INFO *infoPtr, LONG thumbPos)
|
---|
302 | {
|
---|
303 | RECT rcThumb;
|
---|
304 |
|
---|
305 | TRACKBAR_CalcThumb(infoPtr, thumbPos, &rcThumb);
|
---|
306 | InflateRect(&rcThumb, 1, 1);
|
---|
307 | InvalidateRect(infoPtr->hwndSelf, &rcThumb, FALSE);
|
---|
308 | }
|
---|
309 |
|
---|
310 | static inline void
|
---|
311 | TRACKBAR_InvalidateThumbMove (TRACKBAR_INFO *infoPtr, LONG oldPos, LONG newPos)
|
---|
312 | {
|
---|
313 | TRACKBAR_InvalidateThumb (infoPtr, oldPos);
|
---|
314 | if (newPos != oldPos)
|
---|
315 | TRACKBAR_InvalidateThumb (infoPtr, newPos);
|
---|
316 | }
|
---|
317 |
|
---|
318 | static BOOL inline
|
---|
319 | TRACKBAR_HasSelection (TRACKBAR_INFO *infoPtr)
|
---|
320 | {
|
---|
321 | return infoPtr->lSelMin != infoPtr->lSelMax;
|
---|
322 | }
|
---|
323 |
|
---|
324 | static void
|
---|
325 | TRACKBAR_CalcSelection (TRACKBAR_INFO *infoPtr)
|
---|
326 | {
|
---|
327 | RECT *selection = &infoPtr->rcSelection;
|
---|
328 | int range = infoPtr->lRangeMax - infoPtr->lRangeMin;
|
---|
329 |
|
---|
330 | if (range <= 0) {
|
---|
331 | SetRectEmpty (selection);
|
---|
332 | } else {
|
---|
333 | if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_VERT) {
|
---|
334 | int height = infoPtr->rcChannel.right - infoPtr->rcChannel.left;
|
---|
335 | selection->top = infoPtr->rcChannel.top +
|
---|
336 | (height*infoPtr->lSelMin)/range;
|
---|
337 | selection->bottom = infoPtr->rcChannel.top +
|
---|
338 | (height*infoPtr->lSelMax)/range;
|
---|
339 | selection->left = infoPtr->rcChannel.left + 3;
|
---|
340 | selection->right = infoPtr->rcChannel.right - 3;
|
---|
341 | } else {
|
---|
342 | int width = infoPtr->rcChannel.right - infoPtr->rcChannel.left;
|
---|
343 | selection->left = infoPtr->rcChannel.left +
|
---|
344 | (width*infoPtr->lSelMin)/range;
|
---|
345 | selection->right = infoPtr->rcChannel.left +
|
---|
346 | (width*infoPtr->lSelMax)/range;
|
---|
347 | selection->top = infoPtr->rcChannel.top + 3;
|
---|
348 | selection->bottom = infoPtr->rcChannel.bottom - 3;
|
---|
349 | }
|
---|
350 | }
|
---|
351 |
|
---|
352 | TRACE("selection[left=%d, top=%d, right=%d, bottom=%d]\n",
|
---|
353 | selection->left, selection->top, selection->right, selection->bottom);
|
---|
354 | }
|
---|
355 |
|
---|
356 | static BOOL
|
---|
357 | TRACKBAR_AutoPage (TRACKBAR_INFO *infoPtr, POINT clickPoint)
|
---|
358 | {
|
---|
359 | LONG dir = TRACKBAR_GetAutoPageDirection(infoPtr, clickPoint);
|
---|
360 | LONG prevPos = infoPtr->lPos;
|
---|
361 |
|
---|
362 | TRACE("x=%ld, y=%ld, dir=%ld\n", clickPoint.x, clickPoint.y, dir);
|
---|
363 |
|
---|
364 | if (dir > 0 && (infoPtr->flags & TB_AUTO_PAGE_RIGHT))
|
---|
365 | TRACKBAR_PageUp(infoPtr);
|
---|
366 | else if (dir < 0 && (infoPtr->flags & TB_AUTO_PAGE_LEFT))
|
---|
367 | TRACKBAR_PageDown(infoPtr);
|
---|
368 | else return FALSE;
|
---|
369 |
|
---|
370 | infoPtr->flags |= TB_THUMBPOSCHANGED;
|
---|
371 | TRACKBAR_InvalidateThumbMove (infoPtr, prevPos, infoPtr->lPos);
|
---|
372 |
|
---|
373 | return TRUE;
|
---|
374 | }
|
---|
375 |
|
---|
376 | /* Trackbar drawing code. I like my spaghetti done milanese. */
|
---|
377 |
|
---|
378 | static void
|
---|
379 | TRACKBAR_DrawChannel (TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
|
---|
380 | {
|
---|
381 | RECT rcChannel = infoPtr->rcChannel;
|
---|
382 |
|
---|
383 | DrawEdge (hdc, &rcChannel, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
|
---|
384 | if (dwStyle & TBS_ENABLESELRANGE) { /* fill the channel */
|
---|
385 | FillRect (hdc, &rcChannel, GetStockObject(WHITE_BRUSH));
|
---|
386 | if (TRACKBAR_HasSelection(infoPtr))
|
---|
387 | FillRect (hdc, &infoPtr->rcSelection, GetSysColorBrush(COLOR_HIGHLIGHT));
|
---|
388 | }
|
---|
389 | }
|
---|
390 |
|
---|
391 | static void
|
---|
392 | TRACKBAR_DrawOneTic (TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos, int flags)
|
---|
393 | {
|
---|
394 | int x, y, ox, oy, range, side, offset = 5, indent = 0, len = 3;
|
---|
395 | RECT rcTics;
|
---|
396 |
|
---|
397 | TRACE("\n");
|
---|
398 |
|
---|
399 | GetClientRect(infoPtr->hwndSelf, &rcTics);
|
---|
400 | if (flags & TBS_VERT) {
|
---|
401 | rcTics.top = infoPtr->rcChannel.top;
|
---|
402 | rcTics.bottom = infoPtr->rcChannel.bottom;
|
---|
403 | } else {
|
---|
404 | rcTics.left = infoPtr->rcChannel.left;
|
---|
405 | rcTics.right = infoPtr->rcChannel.right;
|
---|
406 | }
|
---|
407 |
|
---|
408 | if (flags & (TBS_TOP | TBS_LEFT)) {
|
---|
409 | x = rcTics.left;
|
---|
410 | y = rcTics.top;
|
---|
411 | side = -1;
|
---|
412 | } else {
|
---|
413 | x = rcTics.right;
|
---|
414 | y = rcTics.bottom;
|
---|
415 | side = 1;
|
---|
416 | }
|
---|
417 |
|
---|
418 | range = infoPtr->lRangeMax - infoPtr->lRangeMin;
|
---|
419 | if (range == 0)
|
---|
420 | range = 1; /* to avoid division by zero */
|
---|
421 |
|
---|
422 | if (flags & TIC_SELECTIONMARK) {
|
---|
423 | indent = (flags & TIC_SELECTIONMARKMIN) ? -1 : 1;
|
---|
424 | } else if (flags & TIC_EDGE) {
|
---|
425 | len++;
|
---|
426 | }
|
---|
427 |
|
---|
428 | if (flags & TBS_VERT) {
|
---|
429 | int height = rcTics.bottom = rcTics.top;
|
---|
430 | y = rcTics.top + (height*(ticPos - infoPtr->lRangeMin))/range;
|
---|
431 | x -= (offset + 2) * side;
|
---|
432 | y += indent;
|
---|
433 | } else {
|
---|
434 | int width = rcTics.right - rcTics.left;
|
---|
435 | x = rcTics.left + (width*(ticPos - infoPtr->lRangeMin))/range;
|
---|
436 | x += indent;
|
---|
437 | y -= (offset + 2) * side;
|
---|
438 | }
|
---|
439 |
|
---|
440 | ox = x;
|
---|
441 | oy = y;
|
---|
442 | MoveToEx(hdc, x, y, 0);
|
---|
443 | if (flags & TBS_VERT) x += len * side;
|
---|
444 | else y += len * side;
|
---|
445 | LineTo(hdc, x, y);
|
---|
446 |
|
---|
447 | if (flags & TIC_SELECTIONMARK) {
|
---|
448 | if (flags & TBS_VERT) {
|
---|
449 | x -= side;
|
---|
450 | } else {
|
---|
451 | y -= side;
|
---|
452 | }
|
---|
453 | MoveToEx(hdc, x, y, 0);
|
---|
454 | if (flags & TBS_VERT) {
|
---|
455 | y += 2 * indent;
|
---|
456 | } else {
|
---|
457 | x += 2 * indent;
|
---|
458 | }
|
---|
459 |
|
---|
460 | LineTo(hdc, x, y);
|
---|
461 | LineTo(hdc, ox, oy);
|
---|
462 | }
|
---|
463 | }
|
---|
464 |
|
---|
465 |
|
---|
466 | static inline void
|
---|
467 | TRACKBAR_DrawTic (TRACKBAR_INFO *infoPtr, HDC hdc, LONG ticPos, int flags)
|
---|
468 | {
|
---|
469 | if ((flags & (TBS_LEFT | TBS_TOP)) || (flags & TBS_BOTH))
|
---|
470 | TRACKBAR_DrawOneTic (infoPtr, hdc, ticPos, flags | TBS_LEFT);
|
---|
471 |
|
---|
472 | if (!(flags & (TBS_LEFT | TBS_TOP)) || (flags & TBS_BOTH))
|
---|
473 | TRACKBAR_DrawOneTic (infoPtr, hdc, ticPos, flags);
|
---|
474 | }
|
---|
475 |
|
---|
476 | static void
|
---|
477 | TRACKBAR_DrawTics (TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
|
---|
478 | {
|
---|
479 | int i, ticFlags = dwStyle & 0x0f;
|
---|
480 | LOGPEN ticPen = { PS_SOLID, {1, 0}, GetSysColor (COLOR_3DDKSHADOW) };
|
---|
481 | HPEN hOldPen, hTicPen;
|
---|
482 |
|
---|
483 | /* create the pen to draw the tics with */
|
---|
484 | hTicPen = CreatePenIndirect(&ticPen);
|
---|
485 | hOldPen = hTicPen ? SelectObject(hdc, hTicPen) : 0;
|
---|
486 |
|
---|
487 | /* actually draw the tics */
|
---|
488 | for (i=0; i<infoPtr->uNumTics; i++)
|
---|
489 | TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->tics[i], ticFlags);
|
---|
490 |
|
---|
491 | TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lRangeMin, ticFlags | TIC_EDGE);
|
---|
492 | TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lRangeMax, ticFlags | TIC_EDGE);
|
---|
493 |
|
---|
494 | if ((dwStyle & TBS_ENABLESELRANGE) && TRACKBAR_HasSelection(infoPtr)) {
|
---|
495 | TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lSelMin,
|
---|
496 | ticFlags | TIC_SELECTIONMARKMIN);
|
---|
497 | TRACKBAR_DrawTic (infoPtr, hdc, infoPtr->lSelMax,
|
---|
498 | ticFlags | TIC_SELECTIONMARKMAX);
|
---|
499 | }
|
---|
500 |
|
---|
501 | /* clean up the pen, if we created one */
|
---|
502 | if (hTicPen) {
|
---|
503 | SelectObject(hdc, hOldPen);
|
---|
504 | DeleteObject(hTicPen);
|
---|
505 | }
|
---|
506 | }
|
---|
507 |
|
---|
508 | static void
|
---|
509 | TRACKBAR_DrawThumb(TRACKBAR_INFO *infoPtr, HDC hdc, DWORD dwStyle)
|
---|
510 | {
|
---|
511 | HBRUSH oldbr;
|
---|
512 | HPEN oldpen;
|
---|
513 | RECT thumb = infoPtr->rcThumb;
|
---|
514 | int BlackUntil = 3;
|
---|
515 | int PointCount = 6;
|
---|
516 | POINT points[6];
|
---|
517 | int fillClr;
|
---|
518 |
|
---|
519 | static INT PointDepth = 4;
|
---|
520 |
|
---|
521 | fillClr = infoPtr->flags & TB_DRAG_MODE ? COLOR_BTNHILIGHT : COLOR_BTNFACE;
|
---|
522 | oldbr = SelectObject (hdc, GetSysColorBrush(fillClr));
|
---|
523 | SetPolyFillMode (hdc, WINDING);
|
---|
524 |
|
---|
525 | if (dwStyle & TBS_BOTH)
|
---|
526 | {
|
---|
527 | points[0].x=thumb.right;
|
---|
528 | points[0].y=thumb.top;
|
---|
529 | points[1].x=thumb.right;
|
---|
530 | points[1].y=thumb.bottom;
|
---|
531 | points[2].x=thumb.left;
|
---|
532 | points[2].y=thumb.bottom;
|
---|
533 | points[3].x=thumb.left;
|
---|
534 | points[3].y=thumb.top;
|
---|
535 | points[4].x=points[0].x;
|
---|
536 | points[4].y=points[0].y;
|
---|
537 | PointCount = 5;
|
---|
538 | BlackUntil = 3;
|
---|
539 | }
|
---|
540 | else
|
---|
541 | {
|
---|
542 | if (dwStyle & TBS_VERT)
|
---|
543 | {
|
---|
544 | if (dwStyle & TBS_LEFT)
|
---|
545 | {
|
---|
546 | points[0].x=thumb.right;
|
---|
547 | points[0].y=thumb.top;
|
---|
548 | points[1].x=thumb.right;
|
---|
549 | points[1].y=thumb.bottom;
|
---|
550 | points[2].x=thumb.left + PointDepth;
|
---|
551 | points[2].y=thumb.bottom;
|
---|
552 | points[3].x=thumb.left;
|
---|
553 | points[3].y=(thumb.bottom - thumb.top) / 2 + thumb.top;
|
---|
554 | points[4].x=thumb.left + PointDepth;
|
---|
555 | points[4].y=thumb.top;
|
---|
556 | points[5].x=points[0].x;
|
---|
557 | points[5].y=points[0].y;
|
---|
558 | BlackUntil = 4;
|
---|
559 | }
|
---|
560 | else
|
---|
561 | {
|
---|
562 | points[0].x=thumb.right;
|
---|
563 | points[0].y=(thumb.bottom - thumb.top) / 2 + thumb.top;
|
---|
564 | points[1].x=thumb.right - PointDepth;
|
---|
565 | points[1].y=thumb.bottom;
|
---|
566 | points[2].x=thumb.left;
|
---|
567 | points[2].y=thumb.bottom;
|
---|
568 | points[3].x=thumb.left;
|
---|
569 | points[3].y=thumb.top;
|
---|
570 | points[4].x=thumb.right - PointDepth;
|
---|
571 | points[4].y=thumb.top;
|
---|
572 | points[5].x=points[0].x;
|
---|
573 | points[5].y=points[0].y;
|
---|
574 | }
|
---|
575 | }
|
---|
576 | else
|
---|
577 | {
|
---|
578 | if (dwStyle & TBS_TOP)
|
---|
579 | {
|
---|
580 | points[0].x=(thumb.right - thumb.left) / 2 + thumb.left ;
|
---|
581 | points[0].y=thumb.top;
|
---|
582 | points[1].x=thumb.right;
|
---|
583 | points[1].y=thumb.top + PointDepth;
|
---|
584 | points[2].x=thumb.right;
|
---|
585 | points[2].y=thumb.bottom;
|
---|
586 | points[3].x=thumb.left;
|
---|
587 | points[3].y=thumb.bottom;
|
---|
588 | points[4].x=thumb.left;
|
---|
589 | points[4].y=thumb.top + PointDepth;
|
---|
590 | points[5].x=points[0].x;
|
---|
591 | points[5].y=points[0].y;
|
---|
592 | BlackUntil = 4;
|
---|
593 | }
|
---|
594 | else
|
---|
595 | {
|
---|
596 | points[0].x=thumb.right;
|
---|
597 | points[0].y=thumb.top;
|
---|
598 | points[1].x=thumb.right;
|
---|
599 | points[1].y=thumb.bottom - PointDepth;
|
---|
600 | points[2].x=(thumb.right - thumb.left) / 2 + thumb.left ;
|
---|
601 | points[2].y=thumb.bottom;
|
---|
602 | points[3].x=thumb.left;
|
---|
603 | points[3].y=thumb.bottom - PointDepth;
|
---|
604 | points[4].x=thumb.left;
|
---|
605 | points[4].y=thumb.top;
|
---|
606 | points[5].x=points[0].x;
|
---|
607 | points[5].y=points[0].y;
|
---|
608 | }
|
---|
609 | }
|
---|
610 |
|
---|
611 | }
|
---|
612 |
|
---|
613 | /* Draw the thumb now */
|
---|
614 | Polygon (hdc, points, PointCount);
|
---|
615 | oldpen = SelectObject(hdc, GetStockObject(BLACK_PEN));
|
---|
616 | Polyline(hdc,points, BlackUntil);
|
---|
617 | SelectObject(hdc, GetStockObject(WHITE_PEN));
|
---|
618 | Polyline(hdc, &points[BlackUntil-1], PointCount+1-BlackUntil);
|
---|
619 | SelectObject(hdc, oldpen);
|
---|
620 | SelectObject(hdc, oldbr);
|
---|
621 | }
|
---|
622 |
|
---|
623 |
|
---|
624 | static void inline
|
---|
625 | TRACKBAR_ActivateToolTip (TRACKBAR_INFO *infoPtr, BOOL fShow)
|
---|
626 | {
|
---|
627 | TTTOOLINFOW ti;
|
---|
628 |
|
---|
629 | if (!infoPtr->hwndToolTip) return;
|
---|
630 |
|
---|
631 | ZeroMemory(&ti, sizeof(ti));
|
---|
632 | ti.cbSize = sizeof(ti);
|
---|
633 | ti.hwnd = infoPtr->hwndSelf;
|
---|
634 |
|
---|
635 | SendMessageW (infoPtr->hwndToolTip, TTM_TRACKACTIVATE, fShow, (LPARAM)&ti);
|
---|
636 | }
|
---|
637 |
|
---|
638 |
|
---|
639 | static void
|
---|
640 | TRACKBAR_UpdateToolTip (TRACKBAR_INFO *infoPtr)
|
---|
641 | {
|
---|
642 | DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
|
---|
643 | WCHAR buf[80], fmt[] = { '%', 'l', 'd', 0 };
|
---|
644 | TTTOOLINFOW ti;
|
---|
645 | POINT pt;
|
---|
646 | RECT rcClient;
|
---|
647 | LRESULT size;
|
---|
648 |
|
---|
649 | if (!infoPtr->hwndToolTip) return;
|
---|
650 |
|
---|
651 | ZeroMemory(&ti, sizeof(ti));
|
---|
652 | ti.cbSize = sizeof(ti);
|
---|
653 | ti.hwnd = infoPtr->hwndSelf;
|
---|
654 | ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
|
---|
655 |
|
---|
656 | wsprintfW (buf, fmt, infoPtr->lPos);
|
---|
657 | ti.lpszText = buf;
|
---|
658 | SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
|
---|
659 |
|
---|
660 | GetClientRect (infoPtr->hwndSelf, &rcClient);
|
---|
661 | size = SendMessageW (infoPtr->hwndToolTip, TTM_GETBUBBLESIZE, 0, (LPARAM)&ti);
|
---|
662 | if (dwStyle & TBS_VERT) {
|
---|
663 | if (infoPtr->fLocation == TBTS_LEFT)
|
---|
664 | pt.x = 0 - LOWORD(size) - TOOLTIP_OFFSET;
|
---|
665 | else
|
---|
666 | pt.x = rcClient.right + TOOLTIP_OFFSET;
|
---|
667 | pt.y = (infoPtr->rcThumb.top + infoPtr->rcThumb.bottom - HIWORD(size))/2;
|
---|
668 | } else {
|
---|
669 | if (infoPtr->fLocation == TBTS_TOP)
|
---|
670 | pt.y = 0 - HIWORD(size) - TOOLTIP_OFFSET;
|
---|
671 | else
|
---|
672 | pt.y = rcClient.bottom + TOOLTIP_OFFSET;
|
---|
673 | pt.x = (infoPtr->rcThumb.left + infoPtr->rcThumb.right - LOWORD(size))/2;
|
---|
674 | }
|
---|
675 | ClientToScreen(infoPtr->hwndSelf, &pt);
|
---|
676 |
|
---|
677 | SendMessageW (infoPtr->hwndToolTip, TTM_TRACKPOSITION,
|
---|
678 | 0, (LPARAM)MAKELPARAM(pt.x, pt.y));
|
---|
679 | }
|
---|
680 |
|
---|
681 |
|
---|
682 | static void
|
---|
683 | TRACKBAR_Refresh (TRACKBAR_INFO *infoPtr, HDC hdcDst)
|
---|
684 | {
|
---|
685 | DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
|
---|
686 | RECT rcClient;
|
---|
687 | HDC hdc;
|
---|
688 | HBITMAP hOldBmp = 0, hOffScreenBmp = 0;
|
---|
689 | NMCUSTOMDRAW nmcd;
|
---|
690 | int gcdrf, icdrf;
|
---|
691 |
|
---|
692 | if (infoPtr->flags & TB_THUMBCHANGED) {
|
---|
693 | TRACKBAR_UpdateThumb (infoPtr);
|
---|
694 | if (infoPtr->flags & TB_THUMBSIZECHANGED)
|
---|
695 | TRACKBAR_CalcChannel (infoPtr);
|
---|
696 | }
|
---|
697 | if (infoPtr->flags & TB_SELECTIONCHANGED)
|
---|
698 | TRACKBAR_CalcSelection (infoPtr);
|
---|
699 |
|
---|
700 | if (infoPtr->flags & TB_DRAG_MODE)
|
---|
701 | TRACKBAR_UpdateToolTip (infoPtr);
|
---|
702 |
|
---|
703 | infoPtr->flags &= ~ (TB_THUMBCHANGED | TB_SELECTIONCHANGED);
|
---|
704 |
|
---|
705 | GetClientRect (infoPtr->hwndSelf, &rcClient);
|
---|
706 |
|
---|
707 | /* try to render offscreen, if we fail, carrry onscreen */
|
---|
708 | hdc = CreateCompatibleDC(hdcDst);
|
---|
709 | if (hdc) {
|
---|
710 | hOffScreenBmp = CreateCompatibleBitmap(hdcDst, rcClient.right, rcClient.bottom);
|
---|
711 | if (hOffScreenBmp) {
|
---|
712 | hOldBmp = SelectObject(hdc, hOffScreenBmp);
|
---|
713 | } else {
|
---|
714 | DeleteObject(hdc);
|
---|
715 | hdc = hdcDst;
|
---|
716 | }
|
---|
717 | } else {
|
---|
718 | hdc = hdcDst;
|
---|
719 | }
|
---|
720 |
|
---|
721 | ZeroMemory(&nmcd, sizeof(nmcd));
|
---|
722 | nmcd.hdr.hwndFrom = infoPtr->hwndSelf;
|
---|
723 | nmcd.hdr.idFrom = GetWindowLongW (infoPtr->hwndSelf, GWL_ID);
|
---|
724 | nmcd.hdr.code = NM_CUSTOMDRAW;
|
---|
725 | nmcd.hdc = hdc;
|
---|
726 |
|
---|
727 | /* start the paint cycle */
|
---|
728 | nmcd.rc = rcClient;
|
---|
729 | gcdrf = notify_customdraw(&nmcd, CDDS_PREPAINT);
|
---|
730 | if (gcdrf & CDRF_SKIPDEFAULT) goto cleanup;
|
---|
731 |
|
---|
732 | /* Erase backbround */
|
---|
733 | if (gcdrf == CDRF_DODEFAULT ||
|
---|
734 | notify_customdraw(&nmcd, CDDS_PREERASE) != CDRF_SKIPDEFAULT) {
|
---|
735 | FillRect (hdc, &rcClient, GetSysColorBrush(COLOR_BTNFACE));
|
---|
736 | if (gcdrf != CDRF_DODEFAULT)
|
---|
737 | notify_customdraw(&nmcd, CDDS_POSTERASE);
|
---|
738 | }
|
---|
739 |
|
---|
740 | /* draw channel */
|
---|
741 | if (gcdrf & CDRF_NOTIFYITEMDRAW) {
|
---|
742 | nmcd.dwItemSpec = TBCD_CHANNEL;
|
---|
743 | nmcd.uItemState = CDIS_DEFAULT;
|
---|
744 | nmcd.rc = infoPtr->rcChannel;
|
---|
745 | icdrf = notify_customdraw(&nmcd, CDDS_ITEMPREPAINT);
|
---|
746 | } else icdrf = CDRF_DODEFAULT;
|
---|
747 | if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
|
---|
748 | TRACKBAR_DrawChannel (infoPtr, hdc, dwStyle);
|
---|
749 | if (icdrf & CDRF_NOTIFYPOSTPAINT)
|
---|
750 | notify_customdraw(&nmcd, CDDS_ITEMPOSTPAINT);
|
---|
751 | }
|
---|
752 |
|
---|
753 |
|
---|
754 | /* draw tics */
|
---|
755 | if (!(dwStyle & TBS_NOTICKS)) {
|
---|
756 | if (gcdrf & CDRF_NOTIFYITEMDRAW) {
|
---|
757 | nmcd.dwItemSpec = TBCD_TICS;
|
---|
758 | nmcd.uItemState = CDIS_DEFAULT;
|
---|
759 | nmcd.rc = rcClient;
|
---|
760 | icdrf = notify_customdraw(&nmcd, CDDS_ITEMPREPAINT);
|
---|
761 | } else icdrf = CDRF_DODEFAULT;
|
---|
762 | if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
|
---|
763 | TRACKBAR_DrawTics (infoPtr, hdc, dwStyle);
|
---|
764 | if (icdrf & CDRF_NOTIFYPOSTPAINT)
|
---|
765 | notify_customdraw(&nmcd, CDDS_ITEMPOSTPAINT);
|
---|
766 | }
|
---|
767 | }
|
---|
768 |
|
---|
769 | /* draw thumb */
|
---|
770 | if (!(dwStyle & TBS_NOTHUMB)) {
|
---|
771 | if (gcdrf & CDRF_NOTIFYITEMDRAW) {
|
---|
772 | nmcd.dwItemSpec = TBCD_THUMB;
|
---|
773 | nmcd.uItemState = infoPtr->flags & TB_DRAG_MODE ? CDIS_HOT : CDIS_DEFAULT;
|
---|
774 | nmcd.rc = infoPtr->rcThumb;
|
---|
775 | icdrf = notify_customdraw(&nmcd, CDDS_ITEMPREPAINT);
|
---|
776 | } else icdrf = CDRF_DODEFAULT;
|
---|
777 | if ( !(icdrf & CDRF_SKIPDEFAULT) ) {
|
---|
778 | TRACKBAR_DrawThumb(infoPtr, hdc, dwStyle);
|
---|
779 | if (icdrf & CDRF_NOTIFYPOSTPAINT)
|
---|
780 | notify_customdraw(&nmcd, CDDS_ITEMPOSTPAINT);
|
---|
781 | }
|
---|
782 | }
|
---|
783 |
|
---|
784 | /* finish up the painting */
|
---|
785 | if (gcdrf & CDRF_NOTIFYPOSTPAINT)
|
---|
786 | notify_customdraw(&nmcd, CDDS_POSTPAINT);
|
---|
787 |
|
---|
788 | cleanup:
|
---|
789 | /* cleanup, if we rendered offscreen */
|
---|
790 | if (hdc != hdcDst) {
|
---|
791 | BitBlt(hdcDst, 0, 0, rcClient.right, rcClient.bottom, hdc, 0, 0, SRCCOPY);
|
---|
792 | SelectObject(hdc, hOldBmp);
|
---|
793 | DeleteObject(hOffScreenBmp);
|
---|
794 | DeleteObject(hdc);
|
---|
795 | }
|
---|
796 | }
|
---|
797 |
|
---|
798 |
|
---|
799 | static void
|
---|
800 | TRACKBAR_AlignBuddies (TRACKBAR_INFO *infoPtr)
|
---|
801 | {
|
---|
802 | DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
|
---|
803 | HWND hwndParent = GetParent (infoPtr->hwndSelf);
|
---|
804 | RECT rcSelf, rcBuddy;
|
---|
805 | INT x, y;
|
---|
806 |
|
---|
807 | GetWindowRect (infoPtr->hwndSelf, &rcSelf);
|
---|
808 | MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcSelf, 2);
|
---|
809 |
|
---|
810 | /* align buddy left or above */
|
---|
811 | if (infoPtr->hwndBuddyLA) {
|
---|
812 | GetWindowRect (infoPtr->hwndBuddyLA, &rcBuddy);
|
---|
813 | MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
|
---|
814 |
|
---|
815 | if (dwStyle & TBS_VERT) {
|
---|
816 | x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
|
---|
817 | (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
|
---|
818 | y = rcSelf.top - (rcBuddy.bottom - rcBuddy.top);
|
---|
819 | }
|
---|
820 | else {
|
---|
821 | x = rcSelf.left - (rcBuddy.right - rcBuddy.left);
|
---|
822 | y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
|
---|
823 | (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
|
---|
824 | }
|
---|
825 |
|
---|
826 | SetWindowPos (infoPtr->hwndBuddyLA, 0, x, y, 0, 0,
|
---|
827 | SWP_NOZORDER | SWP_NOSIZE);
|
---|
828 | }
|
---|
829 |
|
---|
830 |
|
---|
831 | /* align buddy right or below */
|
---|
832 | if (infoPtr->hwndBuddyRB) {
|
---|
833 | GetWindowRect (infoPtr->hwndBuddyRB, &rcBuddy);
|
---|
834 | MapWindowPoints (HWND_DESKTOP, hwndParent, (LPPOINT)&rcBuddy, 2);
|
---|
835 |
|
---|
836 | if (dwStyle & TBS_VERT) {
|
---|
837 | x = (infoPtr->rcChannel.right + infoPtr->rcChannel.left) / 2 -
|
---|
838 | (rcBuddy.right - rcBuddy.left) / 2 + rcSelf.left;
|
---|
839 | y = rcSelf.bottom;
|
---|
840 | }
|
---|
841 | else {
|
---|
842 | x = rcSelf.right;
|
---|
843 | y = (infoPtr->rcChannel.bottom + infoPtr->rcChannel.top) / 2 -
|
---|
844 | (rcBuddy.bottom - rcBuddy.top) / 2 + rcSelf.top;
|
---|
845 | }
|
---|
846 | SetWindowPos (infoPtr->hwndBuddyRB, 0, x, y, 0, 0,
|
---|
847 | SWP_NOZORDER | SWP_NOSIZE);
|
---|
848 | }
|
---|
849 | }
|
---|
850 |
|
---|
851 |
|
---|
852 | static LRESULT
|
---|
853 | TRACKBAR_ClearSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
|
---|
854 | {
|
---|
855 | infoPtr->lSelMin = 0;
|
---|
856 | infoPtr->lSelMax = 0;
|
---|
857 | infoPtr->flags |= TB_SELECTIONCHANGED;
|
---|
858 |
|
---|
859 | if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
|
---|
860 |
|
---|
861 | return 0;
|
---|
862 | }
|
---|
863 |
|
---|
864 |
|
---|
865 | static LRESULT
|
---|
866 | TRACKBAR_ClearTics (TRACKBAR_INFO *infoPtr, BOOL fRedraw)
|
---|
867 | {
|
---|
868 | if (infoPtr->tics) {
|
---|
869 | COMCTL32_Free (infoPtr->tics);
|
---|
870 | infoPtr->tics = NULL;
|
---|
871 | infoPtr->uNumTics = 0;
|
---|
872 | }
|
---|
873 |
|
---|
874 | if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
|
---|
875 |
|
---|
876 | return 0;
|
---|
877 | }
|
---|
878 |
|
---|
879 |
|
---|
880 | static LRESULT inline
|
---|
881 | TRACKBAR_GetChannelRect (TRACKBAR_INFO *infoPtr, LPRECT lprc)
|
---|
882 | {
|
---|
883 | if (lprc == NULL) return 0;
|
---|
884 |
|
---|
885 | lprc->left = infoPtr->rcChannel.left;
|
---|
886 | lprc->right = infoPtr->rcChannel.right;
|
---|
887 | lprc->bottom = infoPtr->rcChannel.bottom;
|
---|
888 | lprc->top = infoPtr->rcChannel.top;
|
---|
889 |
|
---|
890 | return 0;
|
---|
891 | }
|
---|
892 |
|
---|
893 |
|
---|
894 | static LONG inline
|
---|
895 | TRACKBAR_GetNumTics (TRACKBAR_INFO *infoPtr)
|
---|
896 | {
|
---|
897 | if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_NOTICKS)
|
---|
898 | return 0;
|
---|
899 |
|
---|
900 | return infoPtr->uNumTics + 2;
|
---|
901 | }
|
---|
902 |
|
---|
903 |
|
---|
904 | static int comp_tics(const void *ap, const void *bp)
|
---|
905 | {
|
---|
906 | DWORD a = *((DWORD *)ap);
|
---|
907 | DWORD b = *((DWORD *)bp);
|
---|
908 |
|
---|
909 | TRACE("(a=%ld, b=%ld)\n", a, b);
|
---|
910 | if (a < b) return -1;
|
---|
911 | if (a > b) return 1;
|
---|
912 | return 0;
|
---|
913 | }
|
---|
914 |
|
---|
915 |
|
---|
916 | static LONG inline
|
---|
917 | TRACKBAR_GetTic (TRACKBAR_INFO *infoPtr, INT iTic)
|
---|
918 | {
|
---|
919 | if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
|
---|
920 | return -1;
|
---|
921 |
|
---|
922 | qsort(infoPtr->tics, infoPtr->uNumTics, sizeof(DWORD), comp_tics);
|
---|
923 | return infoPtr->tics[iTic];
|
---|
924 | }
|
---|
925 |
|
---|
926 |
|
---|
927 | static LONG inline
|
---|
928 | TRACKBAR_GetTicPos (TRACKBAR_INFO *infoPtr, INT iTic)
|
---|
929 | {
|
---|
930 | LONG range, width, pos, tic;
|
---|
931 |
|
---|
932 | if ((iTic < 0) || (iTic >= infoPtr->uNumTics) || !infoPtr->tics)
|
---|
933 | return -1;
|
---|
934 |
|
---|
935 | tic = TRACKBAR_GetTic (infoPtr, iTic);
|
---|
936 | range = infoPtr->lRangeMax - infoPtr->lRangeMin;
|
---|
937 | width = infoPtr->rcChannel.right - infoPtr->rcChannel.left;
|
---|
938 | pos = infoPtr->rcChannel.left + (width * tic) / range;
|
---|
939 |
|
---|
940 | return pos;
|
---|
941 | }
|
---|
942 |
|
---|
943 |
|
---|
944 | static HWND
|
---|
945 | TRACKBAR_SetBuddy (TRACKBAR_INFO *infoPtr, BOOL fLocation, HWND hwndBuddy)
|
---|
946 | {
|
---|
947 | HWND hwndTemp;
|
---|
948 |
|
---|
949 | if (fLocation) {
|
---|
950 | /* buddy is left or above */
|
---|
951 | hwndTemp = infoPtr->hwndBuddyLA;
|
---|
952 | infoPtr->hwndBuddyLA = hwndBuddy;
|
---|
953 | }
|
---|
954 | else {
|
---|
955 | /* buddy is right or below */
|
---|
956 | hwndTemp = infoPtr->hwndBuddyRB;
|
---|
957 | infoPtr->hwndBuddyRB = hwndBuddy;
|
---|
958 | }
|
---|
959 |
|
---|
960 | TRACKBAR_AlignBuddies (infoPtr);
|
---|
961 |
|
---|
962 | return hwndTemp;
|
---|
963 | }
|
---|
964 |
|
---|
965 |
|
---|
966 | static LONG inline
|
---|
967 | TRACKBAR_SetLineSize (TRACKBAR_INFO *infoPtr, LONG lLineSize)
|
---|
968 | {
|
---|
969 | LONG lTemp = infoPtr->lLineSize;
|
---|
970 |
|
---|
971 | infoPtr->lLineSize = lLineSize;
|
---|
972 |
|
---|
973 | return lTemp;
|
---|
974 | }
|
---|
975 |
|
---|
976 |
|
---|
977 | static LONG inline
|
---|
978 | TRACKBAR_SetPageSize (TRACKBAR_INFO *infoPtr, LONG lPageSize)
|
---|
979 | {
|
---|
980 | LONG lTemp = infoPtr->lPageSize;
|
---|
981 |
|
---|
982 | infoPtr->lPageSize = lPageSize;
|
---|
983 |
|
---|
984 | return lTemp;
|
---|
985 | }
|
---|
986 |
|
---|
987 |
|
---|
988 | static LRESULT inline
|
---|
989 | TRACKBAR_SetPos (TRACKBAR_INFO *infoPtr, BOOL fPosition, LONG lPosition)
|
---|
990 | {
|
---|
991 | LONG oldPos = infoPtr->lPos;
|
---|
992 | infoPtr->lPos = lPosition;
|
---|
993 |
|
---|
994 | if (infoPtr->lPos < infoPtr->lRangeMin)
|
---|
995 | infoPtr->lPos = infoPtr->lRangeMin;
|
---|
996 |
|
---|
997 | if (infoPtr->lPos > infoPtr->lRangeMax)
|
---|
998 | infoPtr->lPos = infoPtr->lRangeMax;
|
---|
999 | infoPtr->flags |= TB_THUMBPOSCHANGED;
|
---|
1000 |
|
---|
1001 | if (fPosition) TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, lPosition);
|
---|
1002 |
|
---|
1003 | return 0;
|
---|
1004 | }
|
---|
1005 |
|
---|
1006 |
|
---|
1007 | static LRESULT inline
|
---|
1008 | TRACKBAR_SetRange (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lRange)
|
---|
1009 | {
|
---|
1010 | infoPtr->lRangeMin = (SHORT)LOWORD(lRange);
|
---|
1011 | infoPtr->lRangeMax = (SHORT)HIWORD(lRange);
|
---|
1012 |
|
---|
1013 | if (infoPtr->lPos < infoPtr->lRangeMin) {
|
---|
1014 | infoPtr->lPos = infoPtr->lRangeMin;
|
---|
1015 | infoPtr->flags |= TB_THUMBPOSCHANGED;
|
---|
1016 | }
|
---|
1017 |
|
---|
1018 | if (infoPtr->lPos > infoPtr->lRangeMax) {
|
---|
1019 | infoPtr->lPos = infoPtr->lRangeMax;
|
---|
1020 | infoPtr->flags |= TB_THUMBPOSCHANGED;
|
---|
1021 | }
|
---|
1022 |
|
---|
1023 | infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
|
---|
1024 | if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
|
---|
1025 |
|
---|
1026 | if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
|
---|
1027 |
|
---|
1028 | return 0;
|
---|
1029 | }
|
---|
1030 |
|
---|
1031 |
|
---|
1032 | static LRESULT inline
|
---|
1033 | TRACKBAR_SetRangeMax (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lMax)
|
---|
1034 | {
|
---|
1035 | infoPtr->lRangeMax = lMax;
|
---|
1036 | if (infoPtr->lPos > infoPtr->lRangeMax) {
|
---|
1037 | infoPtr->lPos = infoPtr->lRangeMax;
|
---|
1038 | infoPtr->flags |= TB_THUMBPOSCHANGED;
|
---|
1039 | }
|
---|
1040 |
|
---|
1041 | infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
|
---|
1042 | if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
|
---|
1043 |
|
---|
1044 | if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
|
---|
1045 |
|
---|
1046 | return 0;
|
---|
1047 | }
|
---|
1048 |
|
---|
1049 |
|
---|
1050 | static LRESULT inline
|
---|
1051 | TRACKBAR_SetRangeMin (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lMin)
|
---|
1052 | {
|
---|
1053 | infoPtr->lRangeMin = lMin;
|
---|
1054 | if (infoPtr->lPos < infoPtr->lRangeMin) {
|
---|
1055 | infoPtr->lPos = infoPtr->lRangeMin;
|
---|
1056 | infoPtr->flags |= TB_THUMBPOSCHANGED;
|
---|
1057 | }
|
---|
1058 |
|
---|
1059 | infoPtr->lPageSize = (infoPtr->lRangeMax - infoPtr->lRangeMin) / 5;
|
---|
1060 | if (infoPtr->lPageSize == 0) infoPtr->lPageSize = 1;
|
---|
1061 |
|
---|
1062 | if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
|
---|
1063 |
|
---|
1064 | return 0;
|
---|
1065 | }
|
---|
1066 |
|
---|
1067 |
|
---|
1068 | static LRESULT inline
|
---|
1069 | TRACKBAR_SetSel (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lSel)
|
---|
1070 | {
|
---|
1071 | if (!GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_ENABLESELRANGE)
|
---|
1072 | return 0;
|
---|
1073 |
|
---|
1074 | infoPtr->lSelMin = (SHORT)LOWORD(lSel);
|
---|
1075 | infoPtr->lSelMax = (SHORT)HIWORD(lSel);
|
---|
1076 | infoPtr->flags |= TB_SELECTIONCHANGED;
|
---|
1077 |
|
---|
1078 | if (infoPtr->lSelMin < infoPtr->lRangeMin)
|
---|
1079 | infoPtr->lSelMin = infoPtr->lRangeMin;
|
---|
1080 | if (infoPtr->lSelMax > infoPtr->lRangeMax)
|
---|
1081 | infoPtr->lSelMax = infoPtr->lRangeMax;
|
---|
1082 |
|
---|
1083 | if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
|
---|
1084 |
|
---|
1085 | return 0;
|
---|
1086 | }
|
---|
1087 |
|
---|
1088 |
|
---|
1089 | static LRESULT inline
|
---|
1090 | TRACKBAR_SetSelEnd (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lEnd)
|
---|
1091 | {
|
---|
1092 | if (!GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_ENABLESELRANGE)
|
---|
1093 | return 0;
|
---|
1094 |
|
---|
1095 | infoPtr->lSelMax = lEnd;
|
---|
1096 | infoPtr->flags |= TB_SELECTIONCHANGED;
|
---|
1097 |
|
---|
1098 | if (infoPtr->lSelMax > infoPtr->lRangeMax)
|
---|
1099 | infoPtr->lSelMax = infoPtr->lRangeMax;
|
---|
1100 |
|
---|
1101 | if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
|
---|
1102 |
|
---|
1103 | return 0;
|
---|
1104 | }
|
---|
1105 |
|
---|
1106 |
|
---|
1107 | static LRESULT inline
|
---|
1108 | TRACKBAR_SetSelStart (TRACKBAR_INFO *infoPtr, BOOL fRedraw, LONG lStart)
|
---|
1109 | {
|
---|
1110 | if (!GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_ENABLESELRANGE)
|
---|
1111 | return 0;
|
---|
1112 |
|
---|
1113 | infoPtr->lSelMin = lStart;
|
---|
1114 | infoPtr->flags |=TB_SELECTIONCHANGED;
|
---|
1115 |
|
---|
1116 | if (infoPtr->lSelMin < infoPtr->lRangeMin)
|
---|
1117 | infoPtr->lSelMin = infoPtr->lRangeMin;
|
---|
1118 |
|
---|
1119 | if (fRedraw) TRACKBAR_InvalidateAll(infoPtr);
|
---|
1120 |
|
---|
1121 | return 0;
|
---|
1122 | }
|
---|
1123 |
|
---|
1124 |
|
---|
1125 | static LRESULT inline
|
---|
1126 | TRACKBAR_SetThumbLength (TRACKBAR_INFO *infoPtr, UINT iLength)
|
---|
1127 | {
|
---|
1128 | if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_FIXEDLENGTH)
|
---|
1129 | infoPtr->uThumbLen = iLength;
|
---|
1130 |
|
---|
1131 | infoPtr->flags |= TB_THUMBSIZECHANGED;
|
---|
1132 |
|
---|
1133 | InvalidateRect (infoPtr->hwndSelf, &infoPtr->rcThumb, FALSE);
|
---|
1134 |
|
---|
1135 | return 0;
|
---|
1136 | }
|
---|
1137 |
|
---|
1138 |
|
---|
1139 | static LRESULT inline
|
---|
1140 | TRACKBAR_SetTic (TRACKBAR_INFO *infoPtr, LONG lPos)
|
---|
1141 | {
|
---|
1142 | if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_AUTOTICKS)
|
---|
1143 | return FALSE;
|
---|
1144 |
|
---|
1145 | if ((lPos < infoPtr->lRangeMin) || (lPos> infoPtr->lRangeMax))
|
---|
1146 | return FALSE;
|
---|
1147 |
|
---|
1148 | TRACE("lPos=%ld\n", lPos);
|
---|
1149 |
|
---|
1150 | infoPtr->uNumTics++;
|
---|
1151 | infoPtr->tics=COMCTL32_ReAlloc( infoPtr->tics,
|
---|
1152 | (infoPtr->uNumTics)*sizeof (DWORD));
|
---|
1153 | if (!infoPtr->tics) {
|
---|
1154 | infoPtr->uNumTics = 0;
|
---|
1155 | notify_outofmemory(infoPtr);
|
---|
1156 | return FALSE;
|
---|
1157 | }
|
---|
1158 | infoPtr->tics[infoPtr->uNumTics-1] = lPos;
|
---|
1159 |
|
---|
1160 | TRACKBAR_InvalidateAll(infoPtr);
|
---|
1161 |
|
---|
1162 | return TRUE;
|
---|
1163 | }
|
---|
1164 |
|
---|
1165 |
|
---|
1166 | static LRESULT inline
|
---|
1167 | TRACKBAR_SetTicFreq (TRACKBAR_INFO *infoPtr, WORD wFreq)
|
---|
1168 | {
|
---|
1169 | if (GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_AUTOTICKS) {
|
---|
1170 | infoPtr->uTicFreq = wFreq;
|
---|
1171 | TRACKBAR_RecalculateTics (infoPtr);
|
---|
1172 | TRACKBAR_InvalidateAll(infoPtr);
|
---|
1173 | }
|
---|
1174 |
|
---|
1175 | return 0;
|
---|
1176 | }
|
---|
1177 |
|
---|
1178 |
|
---|
1179 | static INT inline
|
---|
1180 | TRACKBAR_SetTipSide (TRACKBAR_INFO *infoPtr, INT fLocation)
|
---|
1181 | {
|
---|
1182 | INT fTemp = infoPtr->fLocation;
|
---|
1183 |
|
---|
1184 | infoPtr->fLocation = fLocation;
|
---|
1185 |
|
---|
1186 | return fTemp;
|
---|
1187 | }
|
---|
1188 |
|
---|
1189 |
|
---|
1190 | static LRESULT inline
|
---|
1191 | TRACKBAR_SetToolTips (TRACKBAR_INFO *infoPtr, HWND hwndTT)
|
---|
1192 | {
|
---|
1193 | infoPtr->hwndToolTip = hwndTT;
|
---|
1194 |
|
---|
1195 | return 0;
|
---|
1196 | }
|
---|
1197 |
|
---|
1198 |
|
---|
1199 | static BOOL inline
|
---|
1200 | TRACKBAR_SetUnicodeFormat (TRACKBAR_INFO *infoPtr, BOOL fUnicode)
|
---|
1201 | {
|
---|
1202 | BOOL bTemp = infoPtr->bUnicode;
|
---|
1203 |
|
---|
1204 | infoPtr->bUnicode = fUnicode;
|
---|
1205 |
|
---|
1206 | return bTemp;
|
---|
1207 | }
|
---|
1208 |
|
---|
1209 |
|
---|
1210 | static LRESULT
|
---|
1211 | TRACKBAR_InitializeThumb (TRACKBAR_INFO *infoPtr)
|
---|
1212 | {
|
---|
1213 | infoPtr->uThumbLen = 23; /* initial thumb length */
|
---|
1214 |
|
---|
1215 | TRACKBAR_CalcChannel (infoPtr);
|
---|
1216 | TRACKBAR_UpdateThumb (infoPtr);
|
---|
1217 | infoPtr->flags &= ~TB_SELECTIONCHANGED;
|
---|
1218 |
|
---|
1219 | return 0;
|
---|
1220 | }
|
---|
1221 |
|
---|
1222 |
|
---|
1223 | static LRESULT
|
---|
1224 | TRACKBAR_Create (HWND hwnd, LPCREATESTRUCTW lpcs)
|
---|
1225 | {
|
---|
1226 | TRACKBAR_INFO *infoPtr;
|
---|
1227 | DWORD oldStyle, newStyle;
|
---|
1228 |
|
---|
1229 | infoPtr = (TRACKBAR_INFO *)COMCTL32_Alloc (sizeof(TRACKBAR_INFO));
|
---|
1230 | if (!infoPtr) return -1;
|
---|
1231 | SetWindowLongW (hwnd, 0, (DWORD)infoPtr);
|
---|
1232 |
|
---|
1233 | /* set default values */
|
---|
1234 | infoPtr->hwndSelf = hwnd;
|
---|
1235 | infoPtr->lRangeMin = 0;
|
---|
1236 | infoPtr->lRangeMax = 100;
|
---|
1237 | infoPtr->lLineSize = 1;
|
---|
1238 | infoPtr->lPageSize = 20;
|
---|
1239 | infoPtr->lSelMin = 0;
|
---|
1240 | infoPtr->lSelMax = 0;
|
---|
1241 | infoPtr->lPos = 0;
|
---|
1242 | infoPtr->fLocation = -1;
|
---|
1243 | infoPtr->uNumTics = 0; /* start and end tic are not included in count*/
|
---|
1244 | infoPtr->uTicFreq = 1;
|
---|
1245 | infoPtr->tics = NULL;
|
---|
1246 | infoPtr->hwndNotify= GetParent (hwnd);
|
---|
1247 |
|
---|
1248 | TRACKBAR_InitializeThumb (infoPtr);
|
---|
1249 |
|
---|
1250 | oldStyle = newStyle = GetWindowLongW (hwnd, GWL_STYLE);
|
---|
1251 | if (oldStyle & TBS_VERT) {
|
---|
1252 | if (! (oldStyle & (TBS_LEFT | TBS_RIGHT | TBS_BOTH)) )
|
---|
1253 | newStyle |= TBS_RIGHT;
|
---|
1254 | } else {
|
---|
1255 | if (! (oldStyle & (TBS_TOP | TBS_BOTTOM | TBS_BOTH)) )
|
---|
1256 | newStyle |= TBS_BOTTOM;
|
---|
1257 | }
|
---|
1258 | if (newStyle != oldStyle)
|
---|
1259 | SetWindowLongW (hwnd, GWL_STYLE, newStyle);
|
---|
1260 |
|
---|
1261 | /* Create tooltip control */
|
---|
1262 | if (newStyle & TBS_TOOLTIPS) {
|
---|
1263 |
|
---|
1264 | infoPtr->hwndToolTip =
|
---|
1265 | CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, 0,
|
---|
1266 | CW_USEDEFAULT, CW_USEDEFAULT,
|
---|
1267 | CW_USEDEFAULT, CW_USEDEFAULT,
|
---|
1268 | hwnd, 0, 0, 0);
|
---|
1269 |
|
---|
1270 | if (infoPtr->hwndToolTip) {
|
---|
1271 | TTTOOLINFOW ti;
|
---|
1272 | notify_tooltipscreated(infoPtr);
|
---|
1273 |
|
---|
1274 | ZeroMemory (&ti, sizeof(ti));
|
---|
1275 | ti.cbSize = sizeof(ti);
|
---|
1276 | ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
|
---|
1277 | ti.hwnd = hwnd;
|
---|
1278 |
|
---|
1279 | SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW, 0, (LPARAM)&ti);
|
---|
1280 | }
|
---|
1281 | }
|
---|
1282 |
|
---|
1283 | return 0;
|
---|
1284 | }
|
---|
1285 |
|
---|
1286 |
|
---|
1287 | static LRESULT
|
---|
1288 | TRACKBAR_Destroy (TRACKBAR_INFO *infoPtr)
|
---|
1289 | {
|
---|
1290 | /* delete tooltip control */
|
---|
1291 | if (infoPtr->hwndToolTip)
|
---|
1292 | DestroyWindow (infoPtr->hwndToolTip);
|
---|
1293 |
|
---|
1294 | COMCTL32_Free (infoPtr);
|
---|
1295 | SetWindowLongW (infoPtr->hwndSelf, 0, 0);
|
---|
1296 | return 0;
|
---|
1297 | }
|
---|
1298 |
|
---|
1299 |
|
---|
1300 | static LRESULT
|
---|
1301 | TRACKBAR_KillFocus (TRACKBAR_INFO *infoPtr, HWND hwndGetFocus)
|
---|
1302 | {
|
---|
1303 | TRACE("\n");
|
---|
1304 |
|
---|
1305 | TRACKBAR_InvalidateAll(infoPtr);
|
---|
1306 |
|
---|
1307 | return 0;
|
---|
1308 | }
|
---|
1309 |
|
---|
1310 | static LRESULT
|
---|
1311 | TRACKBAR_LButtonDown (TRACKBAR_INFO *infoPtr, DWORD fwKeys, POINTS pts)
|
---|
1312 | {
|
---|
1313 | POINT clickPoint = { pts.x, pts.y };
|
---|
1314 |
|
---|
1315 | SetFocus(infoPtr->hwndSelf);
|
---|
1316 |
|
---|
1317 | if (PtInRect(&infoPtr->rcThumb, clickPoint)) {
|
---|
1318 | infoPtr->flags |= TB_DRAG_MODE;
|
---|
1319 | SetCapture (infoPtr->hwndSelf);
|
---|
1320 | TRACKBAR_UpdateToolTip (infoPtr);
|
---|
1321 | TRACKBAR_ActivateToolTip (infoPtr, TRUE);
|
---|
1322 | TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
|
---|
1323 | } else {
|
---|
1324 | LONG dir = TRACKBAR_GetAutoPageDirection(infoPtr, clickPoint);
|
---|
1325 | if (dir == 0) return 0;
|
---|
1326 | infoPtr->flags |= (dir < 0) ? TB_AUTO_PAGE_LEFT : TB_AUTO_PAGE_RIGHT;
|
---|
1327 | TRACKBAR_AutoPage (infoPtr, clickPoint);
|
---|
1328 | SetCapture (infoPtr->hwndSelf);
|
---|
1329 | SetTimer(infoPtr->hwndSelf, TB_REFRESH_TIMER, TB_REFRESH_DELAY, 0);
|
---|
1330 | }
|
---|
1331 |
|
---|
1332 | return 0;
|
---|
1333 | }
|
---|
1334 |
|
---|
1335 |
|
---|
1336 | static LRESULT
|
---|
1337 | TRACKBAR_LButtonUp (TRACKBAR_INFO *infoPtr, DWORD fwKeys, POINTS pts)
|
---|
1338 | {
|
---|
1339 | if (infoPtr->flags & TB_DRAG_MODE) {
|
---|
1340 | TRACKBAR_SendNotify (infoPtr, TB_ENDTRACK);
|
---|
1341 | infoPtr->flags &= ~TB_DRAG_MODE;
|
---|
1342 | ReleaseCapture ();
|
---|
1343 | notify_releasedcapture(infoPtr);
|
---|
1344 | TRACKBAR_ActivateToolTip(infoPtr, FALSE);
|
---|
1345 | TRACKBAR_InvalidateThumb(infoPtr, infoPtr->lPos);
|
---|
1346 | }
|
---|
1347 | if (infoPtr->flags & TB_AUTO_PAGE) {
|
---|
1348 | KillTimer (infoPtr->hwndSelf, TB_REFRESH_TIMER);
|
---|
1349 | infoPtr->flags &= ~TB_AUTO_PAGE;
|
---|
1350 | ReleaseCapture ();
|
---|
1351 | notify_releasedcapture(infoPtr);
|
---|
1352 | }
|
---|
1353 |
|
---|
1354 | return 0;
|
---|
1355 | }
|
---|
1356 |
|
---|
1357 |
|
---|
1358 | static LRESULT
|
---|
1359 | TRACKBAR_CaptureChanged (TRACKBAR_INFO *infoPtr)
|
---|
1360 | {
|
---|
1361 | TRACKBAR_SendNotify (infoPtr, TB_ENDTRACK);
|
---|
1362 | return 0;
|
---|
1363 | }
|
---|
1364 |
|
---|
1365 |
|
---|
1366 | static LRESULT
|
---|
1367 | TRACKBAR_Paint (TRACKBAR_INFO *infoPtr, HDC hdc)
|
---|
1368 | {
|
---|
1369 | if (hdc) {
|
---|
1370 | TRACKBAR_Refresh(infoPtr, hdc);
|
---|
1371 | } else {
|
---|
1372 | PAINTSTRUCT ps;
|
---|
1373 | hdc = BeginPaint (infoPtr->hwndSelf, &ps);
|
---|
1374 | TRACKBAR_Refresh (infoPtr, hdc);
|
---|
1375 | EndPaint (infoPtr->hwndSelf, &ps);
|
---|
1376 | }
|
---|
1377 |
|
---|
1378 | return 0;
|
---|
1379 | }
|
---|
1380 |
|
---|
1381 |
|
---|
1382 | static LRESULT
|
---|
1383 | TRACKBAR_SetFocus (TRACKBAR_INFO *infoPtr, HWND hwndLoseFocus)
|
---|
1384 | {
|
---|
1385 | TRACE("\n");
|
---|
1386 |
|
---|
1387 | TRACKBAR_InvalidateAll(infoPtr);
|
---|
1388 |
|
---|
1389 | return 0;
|
---|
1390 | }
|
---|
1391 |
|
---|
1392 |
|
---|
1393 | static LRESULT
|
---|
1394 | TRACKBAR_Size (TRACKBAR_INFO *infoPtr, DWORD fwSizeType, INT nWidth, INT nHeight)
|
---|
1395 | {
|
---|
1396 | TRACKBAR_CalcChannel (infoPtr);
|
---|
1397 | TRACKBAR_AlignBuddies (infoPtr);
|
---|
1398 |
|
---|
1399 | return 0;
|
---|
1400 | }
|
---|
1401 |
|
---|
1402 |
|
---|
1403 | static LRESULT
|
---|
1404 | TRACKBAR_Timer (TRACKBAR_INFO *infoPtr, INT wTimerID, TIMERPROC *tmrpc)
|
---|
1405 | {
|
---|
1406 | if (infoPtr->flags & TB_AUTO_PAGE) {
|
---|
1407 | POINT pt;
|
---|
1408 | if (GetCursorPos(&pt))
|
---|
1409 | if (ScreenToClient(infoPtr->hwndSelf, &pt))
|
---|
1410 | TRACKBAR_AutoPage(infoPtr, pt);
|
---|
1411 | }
|
---|
1412 | return 0;
|
---|
1413 | }
|
---|
1414 |
|
---|
1415 |
|
---|
1416 | static BOOL
|
---|
1417 | TRACKBAR_SendNotify (TRACKBAR_INFO *infoPtr, UINT code)
|
---|
1418 | {
|
---|
1419 | BOOL bVert = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_VERT;
|
---|
1420 |
|
---|
1421 | TRACE("%x\n", code);
|
---|
1422 |
|
---|
1423 | return (BOOL) SendMessageW (GetParent (infoPtr->hwndSelf),
|
---|
1424 | bVert ? WM_VSCROLL : WM_HSCROLL,
|
---|
1425 | (WPARAM)code, (LPARAM)infoPtr->hwndSelf);
|
---|
1426 | }
|
---|
1427 |
|
---|
1428 |
|
---|
1429 | static LRESULT
|
---|
1430 | TRACKBAR_MouseMove (TRACKBAR_INFO *infoPtr, DWORD fwKeys, POINTS pts)
|
---|
1431 | {
|
---|
1432 | DWORD dwStyle = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE);
|
---|
1433 | INT clickPlace = (dwStyle & TBS_VERT) ? pts.y : pts.x;
|
---|
1434 | DOUBLE dragPos, oldPos = infoPtr->lPos;
|
---|
1435 |
|
---|
1436 | TRACE("(x=%d. y=%d)\n", pts.x, pts.y);
|
---|
1437 |
|
---|
1438 | if (infoPtr->flags & TB_AUTO_PAGE) {
|
---|
1439 | POINT pt;
|
---|
1440 | POINTSTOPOINT(pt, pts);
|
---|
1441 | TRACKBAR_AutoPage (infoPtr, pt);
|
---|
1442 | return TRUE;
|
---|
1443 | }
|
---|
1444 |
|
---|
1445 | if (!(infoPtr->flags & TB_DRAG_MODE)) return TRUE;
|
---|
1446 |
|
---|
1447 | dragPos = TRACKBAR_ConvertPlaceToPosition (infoPtr, clickPlace,
|
---|
1448 | dwStyle & TBS_VERT);
|
---|
1449 | if (dragPos > ((INT)dragPos) + 0.5) dragPos++;
|
---|
1450 |
|
---|
1451 | if (dragPos == oldPos) return TRUE;
|
---|
1452 |
|
---|
1453 | infoPtr->lPos = dragPos;
|
---|
1454 |
|
---|
1455 | infoPtr->flags |= TB_THUMBPOSCHANGED;
|
---|
1456 | TRACKBAR_SendNotify (infoPtr, TB_THUMBTRACK | (infoPtr->lPos<<16));
|
---|
1457 |
|
---|
1458 |
|
---|
1459 | TRACKBAR_InvalidateThumbMove(infoPtr, oldPos, dragPos);
|
---|
1460 | UpdateWindow (infoPtr->hwndSelf);
|
---|
1461 |
|
---|
1462 | return TRUE;
|
---|
1463 | }
|
---|
1464 |
|
---|
1465 |
|
---|
1466 | static BOOL
|
---|
1467 | TRACKBAR_KeyDown (TRACKBAR_INFO *infoPtr, INT nVirtKey, DWORD lKeyData)
|
---|
1468 | {
|
---|
1469 | BOOL downIsLeft = GetWindowLongW (infoPtr->hwndSelf, GWL_STYLE) & TBS_DOWNISLEFT;
|
---|
1470 | LONG pos = infoPtr->lPos;
|
---|
1471 |
|
---|
1472 | TRACE("%x\n", nVirtKey);
|
---|
1473 |
|
---|
1474 | switch (nVirtKey) {
|
---|
1475 | case VK_UP:
|
---|
1476 | if (downIsLeft) goto step_right;
|
---|
1477 | case VK_LEFT:
|
---|
1478 | step_left:
|
---|
1479 | if (infoPtr->lPos == infoPtr->lRangeMin) return FALSE;
|
---|
1480 | infoPtr->lPos -= infoPtr->lLineSize;
|
---|
1481 | if (infoPtr->lPos < infoPtr->lRangeMin)
|
---|
1482 | infoPtr->lPos = infoPtr->lRangeMin;
|
---|
1483 | TRACKBAR_SendNotify (infoPtr, TB_LINEUP);
|
---|
1484 | break;
|
---|
1485 | case VK_DOWN:
|
---|
1486 | if (downIsLeft) goto step_left;
|
---|
1487 | case VK_RIGHT:
|
---|
1488 | step_right:
|
---|
1489 | if (infoPtr->lPos == infoPtr->lRangeMax) return FALSE;
|
---|
1490 | infoPtr->lPos += infoPtr->lLineSize;
|
---|
1491 | if (infoPtr->lPos > infoPtr->lRangeMax)
|
---|
1492 | infoPtr->lPos = infoPtr->lRangeMax;
|
---|
1493 | TRACKBAR_SendNotify (infoPtr, TB_LINEDOWN);
|
---|
1494 | break;
|
---|
1495 | case VK_NEXT:
|
---|
1496 | if (downIsLeft) goto page_left;
|
---|
1497 | page_right:
|
---|
1498 | TRACKBAR_PageUp(infoPtr);
|
---|
1499 | break;
|
---|
1500 | case VK_PRIOR:
|
---|
1501 | if (downIsLeft) goto page_right;
|
---|
1502 | page_left:
|
---|
1503 | TRACKBAR_PageDown(infoPtr);
|
---|
1504 | break;
|
---|
1505 | case VK_HOME:
|
---|
1506 | if (infoPtr->lPos == infoPtr->lRangeMin) return FALSE;
|
---|
1507 | infoPtr->lPos = infoPtr->lRangeMin;
|
---|
1508 | TRACKBAR_SendNotify (infoPtr, TB_TOP);
|
---|
1509 | break;
|
---|
1510 | case VK_END:
|
---|
1511 | if (infoPtr->lPos == infoPtr->lRangeMax) return FALSE;
|
---|
1512 | infoPtr->lPos = infoPtr->lRangeMax;
|
---|
1513 | TRACKBAR_SendNotify (infoPtr, TB_BOTTOM);
|
---|
1514 | break;
|
---|
1515 | }
|
---|
1516 |
|
---|
1517 | if (pos != infoPtr->lPos) {
|
---|
1518 | infoPtr->flags |=TB_THUMBPOSCHANGED;
|
---|
1519 | TRACKBAR_InvalidateThumbMove (infoPtr, pos, infoPtr->lPos);
|
---|
1520 | }
|
---|
1521 |
|
---|
1522 | return TRUE;
|
---|
1523 | }
|
---|
1524 |
|
---|
1525 |
|
---|
1526 | static BOOL inline
|
---|
1527 | TRACKBAR_KeyUp (TRACKBAR_INFO *infoPtr, INT nVirtKey, DWORD lKeyData)
|
---|
1528 | {
|
---|
1529 | switch (nVirtKey) {
|
---|
1530 | case VK_LEFT:
|
---|
1531 | case VK_UP:
|
---|
1532 | case VK_RIGHT:
|
---|
1533 | case VK_DOWN:
|
---|
1534 | case VK_NEXT:
|
---|
1535 | case VK_PRIOR:
|
---|
1536 | case VK_HOME:
|
---|
1537 | case VK_END:
|
---|
1538 | TRACKBAR_SendNotify (infoPtr, TB_ENDTRACK);
|
---|
1539 | }
|
---|
1540 | return TRUE;
|
---|
1541 | }
|
---|
1542 |
|
---|
1543 |
|
---|
1544 | static LRESULT WINAPI
|
---|
1545 | TRACKBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
---|
1546 | {
|
---|
1547 | TRACKBAR_INFO *infoPtr = (TRACKBAR_INFO *)GetWindowLongW (hwnd, 0);
|
---|
1548 |
|
---|
1549 | TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hwnd, uMsg, wParam, lParam);
|
---|
1550 |
|
---|
1551 | if (!infoPtr && (uMsg != WM_CREATE))
|
---|
1552 | return DefWindowProcW (hwnd, uMsg, wParam, lParam);
|
---|
1553 |
|
---|
1554 | switch (uMsg)
|
---|
1555 | {
|
---|
1556 | case TBM_CLEARSEL:
|
---|
1557 | return TRACKBAR_ClearSel (infoPtr, (BOOL)wParam);
|
---|
1558 |
|
---|
1559 | case TBM_CLEARTICS:
|
---|
1560 | return TRACKBAR_ClearTics (infoPtr, (BOOL)wParam);
|
---|
1561 |
|
---|
1562 | case TBM_GETBUDDY:
|
---|
1563 | return (LRESULT)(wParam ? infoPtr->hwndBuddyLA : infoPtr->hwndBuddyRB);
|
---|
1564 |
|
---|
1565 | case TBM_GETCHANNELRECT:
|
---|
1566 | return TRACKBAR_GetChannelRect (infoPtr, (LPRECT)lParam);
|
---|
1567 |
|
---|
1568 | case TBM_GETLINESIZE:
|
---|
1569 | return infoPtr->lLineSize;
|
---|
1570 |
|
---|
1571 | case TBM_GETNUMTICS:
|
---|
1572 | return TRACKBAR_GetNumTics (infoPtr);
|
---|
1573 |
|
---|
1574 | case TBM_GETPAGESIZE:
|
---|
1575 | return infoPtr->lPageSize;
|
---|
1576 |
|
---|
1577 | case TBM_GETPOS:
|
---|
1578 | return infoPtr->lPos;
|
---|
1579 |
|
---|
1580 | case TBM_GETPTICS:
|
---|
1581 | return (LRESULT)infoPtr->tics;
|
---|
1582 |
|
---|
1583 | case TBM_GETRANGEMAX:
|
---|
1584 | return infoPtr->lRangeMax;
|
---|
1585 |
|
---|
1586 | case TBM_GETRANGEMIN:
|
---|
1587 | return infoPtr->lRangeMin;
|
---|
1588 |
|
---|
1589 | case TBM_GETSELEND:
|
---|
1590 | return infoPtr->lSelMax;
|
---|
1591 |
|
---|
1592 | case TBM_GETSELSTART:
|
---|
1593 | return infoPtr->lSelMin;
|
---|
1594 |
|
---|
1595 | case TBM_GETTHUMBLENGTH:
|
---|
1596 | return infoPtr->uThumbLen;
|
---|
1597 |
|
---|
1598 | case TBM_GETTHUMBRECT:
|
---|
1599 | return CopyRect((LPRECT)lParam, &infoPtr->rcThumb);
|
---|
1600 |
|
---|
1601 | case TBM_GETTIC:
|
---|
1602 | return TRACKBAR_GetTic (infoPtr, (INT)wParam);
|
---|
1603 |
|
---|
1604 | case TBM_GETTICPOS:
|
---|
1605 | return TRACKBAR_GetTicPos (infoPtr, (INT)wParam);
|
---|
1606 |
|
---|
1607 | case TBM_GETTOOLTIPS:
|
---|
1608 | return (LRESULT)infoPtr->hwndToolTip;
|
---|
1609 |
|
---|
1610 | case TBM_GETUNICODEFORMAT:
|
---|
1611 | return infoPtr->bUnicode;
|
---|
1612 |
|
---|
1613 | case TBM_SETBUDDY:
|
---|
1614 | return (LRESULT) TRACKBAR_SetBuddy(infoPtr, (BOOL)wParam, (HWND)lParam);
|
---|
1615 |
|
---|
1616 | case TBM_SETLINESIZE:
|
---|
1617 | return TRACKBAR_SetLineSize (infoPtr, (LONG)lParam);
|
---|
1618 |
|
---|
1619 | case TBM_SETPAGESIZE:
|
---|
1620 | return TRACKBAR_SetPageSize (infoPtr, (LONG)lParam);
|
---|
1621 |
|
---|
1622 | case TBM_SETPOS:
|
---|
1623 | return TRACKBAR_SetPos (infoPtr, (BOOL)wParam, (LONG)lParam);
|
---|
1624 |
|
---|
1625 | case TBM_SETRANGE:
|
---|
1626 | return TRACKBAR_SetRange (infoPtr, (BOOL)wParam, (LONG)lParam);
|
---|
1627 |
|
---|
1628 | case TBM_SETRANGEMAX:
|
---|
1629 | return TRACKBAR_SetRangeMax (infoPtr, (BOOL)wParam, (LONG)lParam);
|
---|
1630 |
|
---|
1631 | case TBM_SETRANGEMIN:
|
---|
1632 | return TRACKBAR_SetRangeMin (infoPtr, (BOOL)wParam, (LONG)lParam);
|
---|
1633 |
|
---|
1634 | case TBM_SETSEL:
|
---|
1635 | return TRACKBAR_SetSel (infoPtr, (BOOL)wParam, (LONG)lParam);
|
---|
1636 |
|
---|
1637 | case TBM_SETSELEND:
|
---|
1638 | return TRACKBAR_SetSelEnd (infoPtr, (BOOL)wParam, (LONG)lParam);
|
---|
1639 |
|
---|
1640 | case TBM_SETSELSTART:
|
---|
1641 | return TRACKBAR_SetSelStart (infoPtr, (BOOL)wParam, (LONG)lParam);
|
---|
1642 |
|
---|
1643 | case TBM_SETTHUMBLENGTH:
|
---|
1644 | return TRACKBAR_SetThumbLength (infoPtr, (UINT)wParam);
|
---|
1645 |
|
---|
1646 | case TBM_SETTIC:
|
---|
1647 | return TRACKBAR_SetTic (infoPtr, (LONG)lParam);
|
---|
1648 |
|
---|
1649 | case TBM_SETTICFREQ:
|
---|
1650 | return TRACKBAR_SetTicFreq (infoPtr, (WORD)wParam);
|
---|
1651 |
|
---|
1652 | case TBM_SETTIPSIDE:
|
---|
1653 | return TRACKBAR_SetTipSide (infoPtr, (INT)wParam);
|
---|
1654 |
|
---|
1655 | case TBM_SETTOOLTIPS:
|
---|
1656 | return TRACKBAR_SetToolTips (infoPtr, (HWND)wParam);
|
---|
1657 |
|
---|
1658 | case TBM_SETUNICODEFORMAT:
|
---|
1659 | return TRACKBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
|
---|
1660 |
|
---|
1661 |
|
---|
1662 | case WM_CAPTURECHANGED:
|
---|
1663 | return TRACKBAR_CaptureChanged (infoPtr);
|
---|
1664 |
|
---|
1665 | case WM_CREATE:
|
---|
1666 | return TRACKBAR_Create (hwnd, (LPCREATESTRUCTW)lParam);
|
---|
1667 |
|
---|
1668 | case WM_DESTROY:
|
---|
1669 | return TRACKBAR_Destroy (infoPtr);
|
---|
1670 |
|
---|
1671 | /* case WM_ENABLE: */
|
---|
1672 |
|
---|
1673 | case WM_ERASEBKGND:
|
---|
1674 | return 0;
|
---|
1675 |
|
---|
1676 | case WM_GETDLGCODE:
|
---|
1677 | return DLGC_WANTARROWS;
|
---|
1678 |
|
---|
1679 | case WM_KEYDOWN:
|
---|
1680 | return TRACKBAR_KeyDown (infoPtr, (INT)wParam, (DWORD)lParam);
|
---|
1681 |
|
---|
1682 | case WM_KEYUP:
|
---|
1683 | return TRACKBAR_KeyUp (infoPtr, (INT)wParam, (DWORD)lParam);
|
---|
1684 |
|
---|
1685 | case WM_KILLFOCUS:
|
---|
1686 | return TRACKBAR_KillFocus (infoPtr, (HWND)wParam);
|
---|
1687 |
|
---|
1688 | case WM_LBUTTONDOWN:
|
---|
1689 | return TRACKBAR_LButtonDown (infoPtr, wParam, MAKEPOINTS(lParam));
|
---|
1690 |
|
---|
1691 | case WM_LBUTTONUP:
|
---|
1692 | return TRACKBAR_LButtonUp (infoPtr, wParam, MAKEPOINTS(lParam));
|
---|
1693 |
|
---|
1694 | case WM_MOUSEMOVE:
|
---|
1695 | return TRACKBAR_MouseMove (infoPtr, wParam, MAKEPOINTS(lParam));
|
---|
1696 |
|
---|
1697 | case WM_PAINT:
|
---|
1698 | return TRACKBAR_Paint (infoPtr, (HDC)wParam);
|
---|
1699 |
|
---|
1700 | case WM_SETFOCUS:
|
---|
1701 | return TRACKBAR_SetFocus (infoPtr, (HWND)wParam);
|
---|
1702 |
|
---|
1703 | case WM_SIZE:
|
---|
1704 | return TRACKBAR_Size (infoPtr, wParam, LOWORD(lParam), HIWORD(lParam));
|
---|
1705 |
|
---|
1706 | case WM_TIMER:
|
---|
1707 | return TRACKBAR_Timer (infoPtr, (INT)wParam, (TIMERPROC *)lParam);
|
---|
1708 |
|
---|
1709 | case WM_WININICHANGE:
|
---|
1710 | return TRACKBAR_InitializeThumb (infoPtr);
|
---|
1711 |
|
---|
1712 | default:
|
---|
1713 | if ((uMsg >= WM_USER) && (uMsg < WM_APP))
|
---|
1714 | ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
|
---|
1715 | return DefWindowProcW (hwnd, uMsg, wParam, lParam);
|
---|
1716 | }
|
---|
1717 | return 0;
|
---|
1718 | }
|
---|
1719 |
|
---|
1720 |
|
---|
1721 | void TRACKBAR_Register (void)
|
---|
1722 | {
|
---|
1723 | WNDCLASSW wndClass;
|
---|
1724 |
|
---|
1725 | ZeroMemory (&wndClass, sizeof(WNDCLASSW));
|
---|
1726 | wndClass.style = CS_GLOBALCLASS;
|
---|
1727 | wndClass.lpfnWndProc = (WNDPROC)TRACKBAR_WindowProc;
|
---|
1728 | wndClass.cbClsExtra = 0;
|
---|
1729 | wndClass.cbWndExtra = sizeof(TRACKBAR_INFO *);
|
---|
1730 | wndClass.hCursor = LoadCursorW (0, IDC_ARROWW);
|
---|
1731 | wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
|
---|
1732 | wndClass.lpszClassName = TRACKBAR_CLASSW;
|
---|
1733 |
|
---|
1734 | RegisterClassW (&wndClass);
|
---|
1735 | }
|
---|
1736 |
|
---|
1737 |
|
---|
1738 | void TRACKBAR_Unregister (void)
|
---|
1739 | {
|
---|
1740 | UnregisterClassW (TRACKBAR_CLASSW, (HINSTANCE)NULL);
|
---|
1741 | }
|
---|