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

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

comctl32 wine conversion bugs fixed
trackbar: TRACKBAR_Draw prototype

File size: 31.5 KB
Line 
1/* $Id: status.c,v 1.4 1999-06-16 20:25:43 cbratschi Exp $ */
2/*
3 * Interface code to StatusWindow widget/control
4 *
5 * Copyright 1996 Bruce Milner
6 * Copyright 1998, 1999 Eric Kohl
7 * Copyright 1999 Achim Hasenmueller
8 * Copyright 1999 Christoph Bratschi
9 */
10
11#include "winbase.h"
12#include "commctrl.h"
13#include "comctl32.h"
14#include "status.h"
15#include <string.h>
16
17/*
18 * Run tests using Waite Group Windows95 API Bible Vol. 1&2
19 * The second cdrom contains executables drawstat.exe,gettext.exe,
20 * simple.exe, getparts.exe, setparts.exe, statwnd.exe
21 */
22
23/*
24 * Fixme/Todo
25 * 1) Don't hard code bar to bottom of window, allow CCS_TOP also.
26 * 2) Tooltip support (almost done).
27 */
28
29#define _MAX(a,b) (((a)>(b))?(a):(b))
30#define _MIN(a,b) (((a)>(b))?(b):(a))
31
32#define HORZ_BORDER 0
33#define VERT_BORDER 2
34#define HORZ_GAP 2
35
36#define STATUSBAR_GetInfoPtr(hwnd) ((STATUSWINDOWINFO *)GetWindowLongA (hwnd, 0))
37
38
39static void
40STATUSBAR_DrawSizeGrip (HDC hdc, LPRECT lpRect)
41{
42 HPEN hOldPen;
43 POINT pt;
44 INT i;
45
46 pt.x = lpRect->right - 1;
47 pt.y = lpRect->bottom - 1;
48
49 hOldPen = SelectObject (hdc, GetSysColorPen (COLOR_3DFACE));
50 MoveToEx (hdc, pt.x - 12, pt.y, NULL);
51 LineTo (hdc, pt.x, pt.y);
52 LineTo (hdc, pt.x, pt.y - 12);
53
54 pt.x--;
55 pt.y--;
56
57 SelectObject (hdc, GetSysColorPen (COLOR_3DSHADOW));
58 for (i = 1; i < 11; i += 4) {
59 MoveToEx (hdc, pt.x - i, pt.y, NULL);
60 LineTo (hdc, pt.x, pt.y - i);
61
62 MoveToEx (hdc, pt.x - i-1, pt.y, NULL);
63 LineTo (hdc, pt.x, pt.y - i-1);
64 }
65
66 SelectObject (hdc, GetSysColorPen (COLOR_3DHIGHLIGHT));
67 for (i = 3; i < 13; i += 4) {
68 MoveToEx (hdc, pt.x - i, pt.y, NULL);
69 LineTo (hdc, pt.x, pt.y - i);
70 }
71
72 SelectObject (hdc, hOldPen);
73}
74
75
76static void
77STATUSBAR_DrawPart (HDC hdc, STATUSWINDOWPART *part)
78{
79 RECT r = part->bound;
80 UINT border = BDR_SUNKENOUTER;
81
82 if (part->style==SBT_POPOUT)
83 border = BDR_RAISEDOUTER;
84 else if (part->style==SBT_NOBORDERS)
85 border = 0;
86
87 DrawEdge(hdc, &r, border, BF_RECT|BF_ADJUST);
88
89 /* draw the icon */
90 if (part->hIcon) {
91 INT cy = r.bottom - r.top;
92
93 r.left += 2;
94 DrawIconEx (hdc, r.left, r.top, part->hIcon, cy, cy, 0, 0, DI_NORMAL);
95 r.left += cy;
96 }
97
98 /* now draw text */
99 if (part->text) {
100 int oldbkmode = SetBkMode(hdc, TRANSPARENT);
101 LPWSTR p = (LPWSTR)part->text;
102 UINT align = DT_LEFT;
103 if (*p == L'\t') {
104 p++;
105 align = DT_CENTER;
106
107 if (*p == L'\t') {
108 p++;
109 align = DT_RIGHT;
110 }
111 }
112 r.left += 3;
113 DrawTextW (hdc, p, lstrlenW (p), &r, align|DT_VCENTER|DT_SINGLELINE);
114 if (oldbkmode != TRANSPARENT)
115 SetBkMode(hdc, oldbkmode);
116 }
117}
118
119
120static VOID
121STATUSBAR_RefreshPart (HWND hwnd, STATUSWINDOWPART *part, HDC hdc)
122{
123 STATUSWINDOWINFO *self = STATUSBAR_GetInfoPtr (hwnd);
124 HBRUSH hbrBk;
125 HFONT hOldFont;
126
127 if (!IsWindowVisible (hwnd))
128 return;
129
130 if (self->clrBk != CLR_DEFAULT)
131 hbrBk = CreateSolidBrush (self->clrBk);
132 else
133 hbrBk = GetSysColorBrush (COLOR_3DFACE);
134 FillRect(hdc, &part->bound, hbrBk);
135
136 hOldFont = SelectObject (hdc, self->hFont ? self->hFont : self->hDefaultFont);
137
138 if (part->style == SBT_OWNERDRAW) {
139 DRAWITEMSTRUCT dis;
140
141 dis.CtlID = GetWindowLongA (hwnd, GWL_ID);
142 dis.itemID = -1;
143 dis.hwndItem = hwnd;
144 dis.hDC = hdc;
145 dis.rcItem = part->bound;
146 dis.itemData = (INT)part->text;
147 SendMessageA (GetParent (hwnd), WM_DRAWITEM,
148 (WPARAM)dis.CtlID, (LPARAM)&dis);
149 }
150 else
151 STATUSBAR_DrawPart (hdc, part);
152
153 SelectObject (hdc, hOldFont);
154
155 if (self->clrBk != CLR_DEFAULT)
156 DeleteObject (hbrBk);
157
158 if (GetWindowLongA (hwnd, GWL_STYLE) & SBARS_SIZEGRIP) {
159 RECT rect;
160
161 GetClientRect (hwnd, &rect);
162 STATUSBAR_DrawSizeGrip (hdc, &rect);
163 }
164}
165
166
167static BOOL
168STATUSBAR_Refresh (HWND hwnd, HDC hdc)
169{
170 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
171 int i;
172 RECT rect;
173 HBRUSH hbrBk;
174 HFONT hOldFont;
175
176 if (!IsWindowVisible(hwnd))
177 return (TRUE);
178
179 GetClientRect (hwnd, &rect);
180
181 if (infoPtr->clrBk != CLR_DEFAULT)
182 hbrBk = CreateSolidBrush (infoPtr->clrBk);
183 else
184 hbrBk = GetSysColorBrush (COLOR_3DFACE);
185 FillRect(hdc, &rect, hbrBk);
186
187 hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
188
189 if (infoPtr->simple) {
190 STATUSBAR_DrawPart (hdc, &infoPtr->part0);
191 }
192 else {
193 for (i = 0; i < infoPtr->numParts; i++) {
194 if (infoPtr->parts[i].style == SBT_OWNERDRAW) {
195 DRAWITEMSTRUCT dis;
196
197 dis.CtlID = GetWindowLongA (hwnd, GWL_ID);
198 dis.itemID = -1;
199 dis.hwndItem = hwnd;
200 dis.hDC = hdc;
201 dis.rcItem = infoPtr->parts[i].bound;
202 dis.itemData = (INT)infoPtr->parts[i].text;
203 SendMessageA (GetParent (hwnd), WM_DRAWITEM,
204 (WPARAM)dis.CtlID, (LPARAM)&dis);
205 }
206 else
207 STATUSBAR_DrawPart (hdc, &infoPtr->parts[i]);
208 }
209 }
210
211 SelectObject (hdc, hOldFont);
212
213 if (infoPtr->clrBk != CLR_DEFAULT)
214 DeleteObject (hbrBk);
215
216 if (GetWindowLongA(hwnd, GWL_STYLE) & SBARS_SIZEGRIP)
217 STATUSBAR_DrawSizeGrip (hdc, &rect);
218
219 return TRUE;
220}
221
222
223static void
224STATUSBAR_SetPartBounds (HWND hwnd)
225{
226 STATUSWINDOWINFO *self = STATUSBAR_GetInfoPtr (hwnd);
227 STATUSWINDOWPART *part;
228 RECT rect, *r;
229 int i;
230
231 /* get our window size */
232 GetClientRect (hwnd, &rect);
233
234 rect.top += VERT_BORDER;
235
236 /* set bounds for simple rectangle */
237 self->part0.bound = rect;
238
239 /* set bounds for non-simple rectangles */
240 for (i = 0; i < self->numParts; i++) {
241 part = &self->parts[i];
242 r = &self->parts[i].bound;
243 r->top = rect.top;
244 r->bottom = rect.bottom;
245 if (i == 0)
246 r->left = 0;
247 else
248 r->left = self->parts[i-1].bound.right + HORZ_GAP;
249 if (part->x == -1)
250 r->right = rect.right;
251 else
252 r->right = part->x;
253
254 if (self->hwndToolTip) {
255 TTTOOLINFOA ti;
256
257 ti.cbSize = sizeof(TTTOOLINFOA);
258 ti.hwnd = hwnd;
259 ti.uId = i;
260 ti.rect = *r;
261 SendMessageA (self->hwndToolTip, TTM_NEWTOOLRECTA,
262 0, (LPARAM)&ti);
263 }
264 }
265}
266
267
268static VOID
269STATUSBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
270 WPARAM wParam, LPARAM lParam)
271{
272 MSG msg;
273
274 msg.hwnd = hwndMsg;
275 msg.message = uMsg;
276 msg.wParam = wParam;
277 msg.lParam = lParam;
278 msg.time = GetMessageTime ();
279 msg.pt.x = LOWORD(GetMessagePos ());
280 msg.pt.y = HIWORD(GetMessagePos ());
281
282 SendMessageA (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
283}
284
285
286static LRESULT
287STATUSBAR_GetBorders (LPARAM lParam)
288{
289 LPINT out = (LPINT) lParam;
290
291 out[0] = HORZ_BORDER; /* horizontal border width */
292 out[1] = VERT_BORDER; /* vertical border width */
293 out[2] = HORZ_GAP; /* width of border between rectangles */
294
295 return TRUE;
296}
297
298
299static LRESULT
300STATUSBAR_GetIcon (HWND hwnd, WPARAM wParam)
301{
302 STATUSWINDOWINFO *self = STATUSBAR_GetInfoPtr (hwnd);
303 INT nPart;
304
305 nPart = (INT)wParam & 0x00ff;
306 if ((nPart < -1) || (nPart >= self->numParts))
307 return 0;
308
309 if (nPart == -1)
310 return (self->part0.hIcon);
311 else
312 return (self->parts[nPart].hIcon);
313}
314
315
316static LRESULT
317STATUSBAR_GetParts (HWND hwnd, WPARAM wParam, LPARAM lParam)
318{
319 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
320 LPINT parts;
321 INT num_parts;
322 INT i;
323
324 num_parts = (INT) wParam;
325 parts = (LPINT) lParam;
326 if (parts) {
327 return (infoPtr->numParts);
328 for (i = 0; i < num_parts; i++) {
329 parts[i] = infoPtr->parts[i].x;
330 }
331 }
332 return (infoPtr->numParts);
333}
334
335
336static LRESULT
337STATUSBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
338{
339 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
340 int part_num;
341 LPRECT rect;
342
343 part_num = ((INT) wParam) & 0x00ff;
344 rect = (LPRECT) lParam;
345 if (infoPtr->simple)
346 *rect = infoPtr->part0.bound;
347 else
348 *rect = infoPtr->parts[part_num].bound;
349 return TRUE;
350}
351
352
353static LRESULT
354STATUSBAR_GetTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
355{
356 STATUSWINDOWINFO *self = STATUSBAR_GetInfoPtr (hwnd);
357 STATUSWINDOWPART *part;
358 INT nPart;
359 LRESULT result;
360
361 nPart = ((INT) wParam) & 0x00ff;
362 if (self->simple)
363 part = &self->part0;
364 else
365 part = &self->parts[nPart];
366
367 if (part->style == SBT_OWNERDRAW)
368 result = (LRESULT)part->text;
369 else {
370 result = part->text ? lstrlenW (part->text) : 0;
371 result |= (part->style << 16);
372 if (lParam && LOWORD(result))
373 lstrcpyWtoA((LPSTR)lParam, part->text);
374 }
375 return result;
376}
377
378
379static LRESULT
380STATUSBAR_GetTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
381{
382 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
383 STATUSWINDOWPART *part;
384 INT nPart;
385 LRESULT result;
386
387 nPart = ((INT)wParam) & 0x00ff;
388 if (infoPtr->simple)
389 part = &infoPtr->part0;
390 else
391 part = &infoPtr->parts[nPart];
392
393 if (part->style == SBT_OWNERDRAW)
394 result = (LRESULT)part->text;
395 else {
396 result = part->text ? lstrlenW (part->text) : 0;
397 result |= (part->style << 16);
398 if (lParam)
399 lstrcpyW ((LPWSTR)lParam, part->text);
400 }
401 return result;
402}
403
404
405static LRESULT
406STATUSBAR_GetTextLength (HWND hwnd, WPARAM wParam)
407{
408 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
409 STATUSWINDOWPART *part;
410 INT part_num;
411 DWORD result;
412
413 part_num = ((INT) wParam) & 0x00ff;
414
415 if (infoPtr->simple)
416 part = &infoPtr->part0;
417 else
418 part = &infoPtr->parts[part_num];
419
420 if (part->text)
421 result = lstrlenW(part->text);
422 else
423 result = 0;
424
425 result |= (part->style << 16);
426 return result;
427}
428
429
430static LRESULT
431STATUSBAR_GetTipTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
432{
433 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
434
435 if (infoPtr->hwndToolTip) {
436 TTTOOLINFOA ti;
437 ti.cbSize = sizeof(TTTOOLINFOA);
438 ti.hwnd = hwnd;
439 ti.uId = LOWORD(wParam);
440 SendMessageA (infoPtr->hwndToolTip, TTM_GETTEXTA, 0, (LPARAM)&ti);
441
442 if (ti.lpszText)
443 lstrcpynA ((LPSTR)lParam, ti.lpszText, HIWORD(wParam));
444 }
445
446 return 0;
447}
448
449
450static LRESULT
451STATUSBAR_GetTipTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
452{
453 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
454
455 if (infoPtr->hwndToolTip) {
456 TTTOOLINFOW ti;
457 ti.cbSize = sizeof(TTTOOLINFOW);
458 ti.hwnd = hwnd;
459 ti.uId = LOWORD(wParam);
460 SendMessageW (infoPtr->hwndToolTip, TTM_GETTEXTW, 0, (LPARAM)&ti);
461
462 if (ti.lpszText)
463 lstrcpynW ((LPWSTR)lParam, ti.lpszText, HIWORD(wParam));
464 }
465
466 return 0;
467}
468
469
470static LRESULT
471STATUSBAR_GetUnicodeFormat (HWND hwnd)
472{
473 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
474 return infoPtr->bUnicode;
475}
476
477
478static LRESULT
479STATUSBAR_IsSimple (HWND hwnd)
480{
481 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
482 return infoPtr->simple;
483}
484
485
486static LRESULT
487STATUSBAR_SetBkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
488{
489 STATUSWINDOWINFO *self = STATUSBAR_GetInfoPtr (hwnd);
490 COLORREF oldBkColor;
491 HDC hdc;
492
493 oldBkColor = self->clrBk;
494 self->clrBk = (COLORREF)lParam;
495 hdc = GetDC (hwnd);
496 STATUSBAR_Refresh (hwnd, hdc);
497 ReleaseDC (hwnd, hdc);
498
499 return oldBkColor;
500}
501
502
503static LRESULT
504STATUSBAR_SetIcon (HWND hwnd, WPARAM wParam, LPARAM lParam)
505{
506 STATUSWINDOWINFO *self = STATUSBAR_GetInfoPtr (hwnd);
507 INT nPart = (INT)wParam & 0x00ff;
508 HDC hdc;
509
510 if ((nPart < -1) || (nPart >= self->numParts))
511 return FALSE;
512
513 hdc = GetDC (hwnd);
514 if (nPart == -1) {
515 self->part0.hIcon = (HICON)lParam;
516 if (self->simple)
517 STATUSBAR_RefreshPart (hwnd, &self->part0, hdc);
518 }
519 else {
520 self->parts[nPart].hIcon = (HICON)lParam;
521 if (!(self->simple))
522 STATUSBAR_RefreshPart (hwnd, &self->parts[nPart], hdc);
523 }
524 ReleaseDC (hwnd, hdc);
525
526 return TRUE;
527}
528
529
530static LRESULT
531STATUSBAR_SetMinHeight (HWND hwnd, WPARAM wParam, LPARAM lParam)
532{
533 STATUSWINDOWINFO *self = STATUSBAR_GetInfoPtr (hwnd);
534
535 if (IsWindowVisible (hwnd)) {
536 HWND parent = GetParent (hwnd);
537 INT width, x, y;
538 RECT parent_rect;
539
540 GetClientRect (parent, &parent_rect);
541 self->height = (INT)wParam + VERT_BORDER;
542 width = parent_rect.right - parent_rect.left;
543 x = parent_rect.left;
544 y = parent_rect.bottom - self->height;
545 MoveWindow (hwnd, parent_rect.left,
546 parent_rect.bottom - self->height,
547 width, self->height, TRUE);
548 STATUSBAR_SetPartBounds (hwnd);
549 }
550
551 return TRUE;
552}
553
554
555static LRESULT
556STATUSBAR_SetParts (HWND hwnd, WPARAM wParam, LPARAM lParam)
557{
558 STATUSWINDOWINFO *self = STATUSBAR_GetInfoPtr (hwnd);
559 STATUSWINDOWPART *tmp;
560 HDC hdc;
561 LPINT parts;
562 int i;
563 int oldNumParts;
564
565 if (self->simple)
566 self->simple = FALSE;
567
568 oldNumParts = self->numParts;
569 self->numParts = (INT) wParam;
570 parts = (LPINT) lParam;
571 if (oldNumParts > self->numParts) {
572 for (i = self->numParts ; i < oldNumParts; i++) {
573 if (self->parts[i].text && (self->parts[i].style != SBT_OWNERDRAW))
574 COMCTL32_Free (self->parts[i].text);
575 }
576 }
577 else if (oldNumParts < self->numParts) {
578 tmp = COMCTL32_Alloc (sizeof(STATUSWINDOWPART) * self->numParts);
579 for (i = 0; i < oldNumParts; i++) {
580 tmp[i] = self->parts[i];
581 }
582 if (self->parts)
583 COMCTL32_Free (self->parts);
584 self->parts = tmp;
585 }
586
587 for (i = 0; i < self->numParts; i++) {
588 self->parts[i].x = parts[i];
589 }
590
591 if (self->hwndToolTip) {
592 INT nTipCount =
593 SendMessageA (self->hwndToolTip, TTM_GETTOOLCOUNT, 0, 0);
594
595 if (nTipCount < self->numParts) {
596 /* add tools */
597 TTTOOLINFOA ti;
598 INT i;
599
600 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
601 ti.cbSize = sizeof(TTTOOLINFOA);
602 ti.hwnd = hwnd;
603 for (i = nTipCount; i < self->numParts; i++) {
604// TRACE (statusbar, "add tool %d\n", i);
605 ti.uId = i;
606 SendMessageA (self->hwndToolTip, TTM_ADDTOOLA,
607 0, (LPARAM)&ti);
608 }
609 }
610 else if (nTipCount > self->numParts) {
611 /* delete tools */
612 INT i;
613
614 for (i = nTipCount - 1; i >= self->numParts; i--) {
615
616// FIXME (statusbar, "delete tool %d\n", i);
617
618 }
619 }
620 }
621
622 STATUSBAR_SetPartBounds (hwnd);
623
624 hdc = GetDC (hwnd);
625 STATUSBAR_Refresh (hwnd, hdc);
626 ReleaseDC (hwnd, hdc);
627
628 return TRUE;
629}
630
631
632static LRESULT
633STATUSBAR_SetTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
634{
635 STATUSWINDOWINFO *self = STATUSBAR_GetInfoPtr (hwnd);
636 STATUSWINDOWPART *part;
637 int part_num;
638 int style;
639 LPSTR text;
640 int len;
641 HDC hdc;
642
643 text = (LPSTR) lParam;
644 part_num = ((INT) wParam) & 0x00ff;
645 style = ((INT) wParam) & 0xff00;
646
647 if ((self->simple) || (self->parts==NULL) || (part_num==255))
648 part = &self->part0;
649 else
650 part = &self->parts[part_num];
651 if (!part) return FALSE;
652 part->style = style;
653 if (style == SBT_OWNERDRAW) {
654 part->text = (LPWSTR)text;
655 }
656 else {
657 /* duplicate string */
658 if (part->text)
659 COMCTL32_Free (part->text);
660 part->text = 0;
661 if (text && (len = lstrlenA(text))) {
662 part->text = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
663 lstrcpyAtoW (part->text, text);
664 }
665 }
666
667 hdc = GetDC (hwnd);
668 STATUSBAR_RefreshPart (hwnd, part, hdc);
669 ReleaseDC (hwnd, hdc);
670
671 return TRUE;
672}
673
674
675static LRESULT
676STATUSBAR_SetTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
677{
678 STATUSWINDOWINFO *self = STATUSBAR_GetInfoPtr (hwnd);
679 STATUSWINDOWPART *part;
680 INT part_num, style, len;
681 LPWSTR text;
682 HDC hdc;
683
684 text = (LPWSTR) lParam;
685 part_num = ((INT) wParam) & 0x00ff;
686 style = ((INT) wParam) & 0xff00;
687
688 if ((self->simple) || (self->parts==NULL) || (part_num==255))
689 part = &self->part0;
690 else
691 part = &self->parts[part_num];
692 if (!part) return FALSE;
693 part->style = style;
694 if (style == SBT_OWNERDRAW) {
695 part->text = text;
696 }
697 else {
698 /* duplicate string */
699 if (part->text)
700 COMCTL32_Free (part->text);
701 part->text = 0;
702 if (text && (len = lstrlenW(text))) {
703 part->text = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
704 lstrcpyW(part->text, text);
705 }
706 }
707
708 hdc = GetDC (hwnd);
709 STATUSBAR_RefreshPart (hwnd, part, hdc);
710 ReleaseDC (hwnd, hdc);
711
712 return TRUE;
713}
714
715
716static LRESULT
717STATUSBAR_SetTipTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
718{
719 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
720
721// TRACE (statusbar, "part %d: \"%s\"\n", (INT)wParam, (LPSTR)lParam);
722 if (infoPtr->hwndToolTip) {
723 TTTOOLINFOA ti;
724 ti.cbSize = sizeof(TTTOOLINFOA);
725 ti.hwnd = hwnd;
726 ti.uId = (INT)wParam;
727 ti.hinst = 0;
728 ti.lpszText = (LPSTR)lParam;
729 SendMessageA (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTA,
730 0, (LPARAM)&ti);
731 }
732
733 return 0;
734}
735
736
737static LRESULT
738STATUSBAR_SetTipTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
739{
740 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
741
742// TRACE (statusbar, "part %d: \"%s\"\n", (INT)wParam, (LPSTR)lParam);
743 if (infoPtr->hwndToolTip) {
744 TTTOOLINFOW ti;
745 ti.cbSize = sizeof(TTTOOLINFOW);
746 ti.hwnd = hwnd;
747 ti.uId = (INT)wParam;
748 ti.hinst = 0;
749 ti.lpszText = (LPWSTR)lParam;
750 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW,
751 0, (LPARAM)&ti);
752 }
753
754 return 0;
755}
756
757
758static LRESULT
759STATUSBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam)
760{
761 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
762 BOOL bTemp = infoPtr->bUnicode;
763
764// TRACE (statusbar, "(0x%x)\n", (BOOL)wParam);
765 infoPtr->bUnicode = (BOOL)wParam;
766
767 return bTemp;
768}
769
770
771static LRESULT
772STATUSBAR_Simple (HWND hwnd, WPARAM wParam, LPARAM lParam)
773{
774 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
775 HDC hdc;
776 NMHDR nmhdr;
777
778 infoPtr->simple = (BOOL)wParam;
779
780 /* send notification */
781 nmhdr.hwndFrom = hwnd;
782 nmhdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
783 nmhdr.code = SBN_SIMPLEMODECHANGE;
784 SendMessageA (GetParent (hwnd), WM_NOTIFY, 0, (LPARAM)&nmhdr);
785
786 hdc = GetDC (hwnd);
787 STATUSBAR_Refresh (hwnd, hdc);
788 ReleaseDC (hwnd, hdc);
789
790 return TRUE;
791}
792
793
794static LRESULT
795STATUSBAR_WMCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
796{
797 LPCREATESTRUCTA lpCreate = (LPCREATESTRUCTA)lParam;
798 NONCLIENTMETRICSA nclm;
799 RECT rect;
800 int width, len;
801 HDC hdc;
802 STATUSWINDOWINFO *self;
803
804 self = (STATUSWINDOWINFO*)COMCTL32_Alloc (sizeof(STATUSWINDOWINFO));
805 SetWindowLongA (hwnd, 0, (DWORD)self);
806
807 self->numParts = 1;
808 self->parts = 0;
809 self->simple = FALSE;
810 self->clrBk = CLR_DEFAULT;
811 self->hFont = 0;
812 GetClientRect (hwnd, &rect);
813
814 nclm.cbSize = sizeof(NONCLIENTMETRICSA);
815 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS, 0, &nclm, 0);
816 self->hDefaultFont = CreateFontIndirectA (&nclm.lfStatusFont);
817
818 /* initialize simple case */
819 self->part0.bound = rect;
820 self->part0.text = 0;
821 self->part0.x = 0;
822 self->part0.style = 0;
823 self->part0.hIcon = 0;
824
825 /* initialize first part */
826 self->parts = COMCTL32_Alloc (sizeof(STATUSWINDOWPART));
827 self->parts[0].bound = rect;
828 self->parts[0].text = 0;
829 self->parts[0].x = -1;
830 self->parts[0].style = 0;
831 self->parts[0].hIcon = 0;
832
833 if (IsWindowUnicode (hwnd)) {
834 self->bUnicode = TRUE;
835 if ((len = lstrlenW ((LPCWSTR)lpCreate->lpszName))) {
836 self->parts[0].text = COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
837 lstrcpyW (self->parts[0].text, (LPCWSTR)lpCreate->lpszName);
838 }
839 }
840 else {
841 if ((len = lstrlenA ((LPCSTR)lpCreate->lpszName))) {
842 self->parts[0].text = COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
843 lstrcpyAtoW (self->parts[0].text, (LPCSTR)lpCreate->lpszName);
844 }
845 }
846
847 if ((hdc = GetDC (0))) {
848 TEXTMETRICA tm;
849 HFONT hOldFont;
850
851 hOldFont = SelectObject (hdc,self->hDefaultFont);
852 GetTextMetricsA(hdc, &tm);
853 self->textHeight = tm.tmHeight;
854 SelectObject (hdc, hOldFont);
855 ReleaseDC(0, hdc);
856 }
857
858 if (GetWindowLongA (hwnd, GWL_STYLE) & SBT_TOOLTIPS) {
859 self->hwndToolTip =
860 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
861 CW_USEDEFAULT, CW_USEDEFAULT,
862 CW_USEDEFAULT, CW_USEDEFAULT,
863 hwnd, 0,
864 GetWindowLongA (hwnd, GWL_HINSTANCE), NULL);
865
866 if (self->hwndToolTip) {
867 NMTOOLTIPSCREATED nmttc;
868
869 nmttc.hdr.hwndFrom = hwnd;
870 nmttc.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
871 nmttc.hdr.code = NM_TOOLTIPSCREATED;
872 nmttc.hwndToolTips = self->hwndToolTip;
873
874 SendMessageA (GetParent (hwnd), WM_NOTIFY,
875 (WPARAM)nmttc.hdr.idFrom, (LPARAM)&nmttc);
876 }
877 }
878
879 GetClientRect (GetParent (hwnd), &rect);
880 width = rect.right - rect.left;
881 self->height = self->textHeight + 4 + VERT_BORDER;
882 MoveWindow (hwnd, lpCreate->x, lpCreate->y-1,
883 width, self->height, FALSE);
884 STATUSBAR_SetPartBounds (hwnd);
885
886 return 0;
887}
888
889
890static LRESULT
891STATUSBAR_WMDestroy (HWND hwnd)
892{
893 STATUSWINDOWINFO *self = STATUSBAR_GetInfoPtr (hwnd);
894 int i;
895
896 for (i = 0; i < self->numParts; i++) {
897 if (self->parts[i].text && (self->parts[i].style != SBT_OWNERDRAW))
898 COMCTL32_Free (self->parts[i].text);
899 }
900 if (self->part0.text && (self->part0.style != SBT_OWNERDRAW))
901 COMCTL32_Free (self->part0.text);
902 COMCTL32_Free (self->parts);
903
904 /* delete default font */
905 if (self->hDefaultFont)
906 DeleteObject (self->hDefaultFont);
907
908 /* delete tool tip control */
909 if (self->hwndToolTip)
910 DestroyWindow (self->hwndToolTip);
911
912 COMCTL32_Free (self);
913
914 return 0;
915}
916
917
918static LRESULT
919STATUSBAR_WMGetFont (HWND hwnd)
920{
921 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
922 return infoPtr->hFont;
923}
924
925
926static LRESULT
927STATUSBAR_WMGetText (HWND hwnd, WPARAM wParam, LPARAM lParam)
928{
929 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
930 INT len;
931
932 if (!(infoPtr->parts[0].text))
933 return 0;
934 len = lstrlenW (infoPtr->parts[0].text);
935 if (wParam > len) {
936 if (infoPtr->bUnicode)
937 lstrcpyW ((LPWSTR)lParam, infoPtr->parts[0].text);
938 else
939 lstrcpyWtoA ((LPSTR)lParam, infoPtr->parts[0].text);
940 return len;
941 }
942
943 return -1;
944}
945
946
947static LRESULT
948STATUSBAR_WMMouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
949{
950 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
951
952 if (infoPtr->hwndToolTip)
953 STATUSBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
954 WM_MOUSEMOVE, wParam, lParam);
955 return 0;
956}
957
958
959static LRESULT
960STATUSBAR_WMNCHitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
961{
962 if (GetWindowLongA (hwnd, GWL_STYLE) & SBARS_SIZEGRIP) {
963 RECT rect;
964 POINT pt;
965
966 GetClientRect (hwnd, &rect);
967
968 pt.x = (INT)LOWORD(lParam);
969 pt.y = (INT)HIWORD(lParam);
970 ScreenToClient (hwnd, &pt);
971
972 rect.left = rect.right - 13;
973 rect.top += 2;
974
975 if (PtInRect (&rect, pt))
976 return HTBOTTOMRIGHT;
977 }
978
979 return DefWindowProcA (hwnd, WM_NCHITTEST, wParam, lParam);
980}
981
982
983static LRESULT
984STATUSBAR_WMNCLButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
985{
986 PostMessageA (GetParent (hwnd), WM_NCLBUTTONDOWN, wParam, lParam);
987 return 0;
988}
989
990
991static LRESULT
992STATUSBAR_WMNCLButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
993{
994 PostMessageA (GetParent (hwnd), WM_NCLBUTTONUP, wParam, lParam);
995 return 0;
996}
997
998
999static LRESULT
1000STATUSBAR_WMPaint (HWND hwnd, WPARAM wParam)
1001{
1002 HDC hdc;
1003 PAINTSTRUCT ps;
1004
1005 hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
1006 STATUSBAR_Refresh (hwnd, hdc);
1007 if (!wParam)
1008 EndPaint (hwnd, &ps);
1009
1010 return 0;
1011}
1012
1013
1014static LRESULT
1015STATUSBAR_WMSetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
1016{
1017 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
1018
1019 infoPtr->hFont = (HFONT)wParam;
1020 if (LOWORD(lParam) == TRUE) {
1021 HDC hdc = GetDC (hwnd);
1022 STATUSBAR_Refresh (hwnd, hdc);
1023 ReleaseDC (hwnd, hdc);
1024 }
1025
1026 return 0;
1027}
1028
1029
1030static LRESULT
1031STATUSBAR_WMSetText (HWND hwnd, WPARAM wParam, LPARAM lParam)
1032{
1033 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
1034 STATUSWINDOWPART *part;
1035 int len;
1036 HDC hdc;
1037
1038 if (infoPtr->numParts == 0)
1039 return FALSE;
1040
1041 part = &infoPtr->parts[0];
1042 /* duplicate string */
1043 if (part->text)
1044 COMCTL32_Free (part->text);
1045 part->text = 0;
1046 if (infoPtr->bUnicode) {
1047 if (lParam && (len = lstrlenW((LPCWSTR)lParam))) {
1048 part->text = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
1049 lstrcpyW (part->text, (LPCWSTR)lParam);
1050 }
1051 }
1052 else {
1053 if (lParam && (len = lstrlenA((LPCSTR)lParam))) {
1054 part->text = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
1055 lstrcpyAtoW (part->text, (LPCSTR)lParam);
1056 }
1057 }
1058
1059 hdc = GetDC (hwnd);
1060 STATUSBAR_RefreshPart (hwnd, part, hdc);
1061 ReleaseDC (hwnd, hdc);
1062
1063 return TRUE;
1064}
1065
1066
1067static LRESULT
1068STATUSBAR_WMSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
1069{
1070 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
1071 INT width, x, y, flags;
1072 RECT parent_rect;
1073 HWND parent;
1074
1075 /* Need to resize width to match parent */
1076 flags = (INT) wParam;
1077
1078 /* FIXME for flags =
1079 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED, SIZE_RESTORED
1080 */
1081
1082 if (flags == SIZE_RESTORED) {
1083 /* width and height don't apply */
1084 parent = GetParent (hwnd);
1085 GetClientRect (parent, &parent_rect);
1086 width = parent_rect.right - parent_rect.left;
1087 x = parent_rect.left;
1088 y = parent_rect.bottom - infoPtr->height;
1089 MoveWindow (hwnd, parent_rect.left,
1090 parent_rect.bottom - infoPtr->height,
1091 width, infoPtr->height, TRUE);
1092 STATUSBAR_SetPartBounds (hwnd);
1093 }
1094 return 0;
1095}
1096
1097
1098static LRESULT
1099STATUSBAR_SendNotify (HWND hwnd, UINT code)
1100{
1101 NMHDR nmhdr;
1102
1103 nmhdr.hwndFrom = hwnd;
1104 nmhdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
1105 nmhdr.code = code;
1106 SendMessageA (GetParent (hwnd), WM_NOTIFY, 0, (LPARAM)&nmhdr);
1107 return 0;
1108}
1109
1110
1111
1112LRESULT WINAPI
1113StatusWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1114{
1115 switch (msg) {
1116 case SB_GETBORDERS:
1117 return STATUSBAR_GetBorders (lParam);
1118
1119 case SB_GETICON:
1120 return STATUSBAR_GetIcon (hwnd, wParam);
1121
1122 case SB_GETPARTS:
1123 return STATUSBAR_GetParts (hwnd, wParam, lParam);
1124
1125 case SB_GETRECT:
1126 return STATUSBAR_GetRect (hwnd, wParam, lParam);
1127
1128 case SB_GETTEXTA:
1129 return STATUSBAR_GetTextA (hwnd, wParam, lParam);
1130
1131 case SB_GETTEXTW:
1132 return STATUSBAR_GetTextW (hwnd, wParam, lParam);
1133
1134 case SB_GETTEXTLENGTHA:
1135 case SB_GETTEXTLENGTHW:
1136 return STATUSBAR_GetTextLength (hwnd, wParam);
1137
1138 case SB_GETTIPTEXTA:
1139 return STATUSBAR_GetTipTextA (hwnd, wParam, lParam);
1140
1141 case SB_GETTIPTEXTW:
1142 return STATUSBAR_GetTipTextW (hwnd, wParam, lParam);
1143
1144 case SB_GETUNICODEFORMAT:
1145 return STATUSBAR_GetUnicodeFormat (hwnd);
1146
1147 case SB_ISSIMPLE:
1148 return STATUSBAR_IsSimple (hwnd);
1149
1150 case SB_SETBKCOLOR:
1151 return STATUSBAR_SetBkColor (hwnd, wParam, lParam);
1152
1153 case SB_SETICON:
1154 return STATUSBAR_SetIcon (hwnd, wParam, lParam);
1155
1156 case SB_SETMINHEIGHT:
1157 return STATUSBAR_SetMinHeight (hwnd, wParam, lParam);
1158
1159 case SB_SETPARTS:
1160 return STATUSBAR_SetParts (hwnd, wParam, lParam);
1161
1162 case SB_SETTEXTA:
1163 return STATUSBAR_SetTextA (hwnd, wParam, lParam);
1164
1165 case SB_SETTEXTW:
1166 return STATUSBAR_SetTextW (hwnd, wParam, lParam);
1167
1168 case SB_SETTIPTEXTA:
1169 return STATUSBAR_SetTipTextA (hwnd, wParam, lParam);
1170
1171 case SB_SETTIPTEXTW:
1172 return STATUSBAR_SetTipTextW (hwnd, wParam, lParam);
1173
1174 case SB_SETUNICODEFORMAT:
1175 return STATUSBAR_SetUnicodeFormat (hwnd, wParam);
1176
1177 case SB_SIMPLE:
1178 return STATUSBAR_Simple (hwnd, wParam, lParam);
1179
1180
1181 case WM_CREATE:
1182 return STATUSBAR_WMCreate (hwnd, wParam, lParam);
1183
1184 case WM_DESTROY:
1185 return STATUSBAR_WMDestroy (hwnd);
1186
1187 case WM_GETFONT:
1188 return STATUSBAR_WMGetFont (hwnd);
1189
1190 case WM_GETTEXT:
1191 return STATUSBAR_WMGetText (hwnd, wParam, lParam);
1192
1193 case WM_GETTEXTLENGTH:
1194 return STATUSBAR_GetTextLength (hwnd, 0);
1195
1196 case WM_LBUTTONDBLCLK:
1197 return STATUSBAR_SendNotify (hwnd, NM_DBLCLK);
1198
1199 case WM_LBUTTONUP:
1200 return STATUSBAR_SendNotify (hwnd, NM_CLICK);
1201
1202 case WM_MOUSEMOVE:
1203 return STATUSBAR_WMMouseMove (hwnd, wParam, lParam);
1204
1205 case WM_NCHITTEST:
1206 return STATUSBAR_WMNCHitTest (hwnd, wParam, lParam);
1207
1208 case WM_NCLBUTTONDOWN:
1209 return STATUSBAR_WMNCLButtonDown (hwnd, wParam, lParam);
1210
1211 case WM_NCLBUTTONUP:
1212 return STATUSBAR_WMNCLButtonUp (hwnd, wParam, lParam);
1213
1214 case WM_PAINT:
1215 return STATUSBAR_WMPaint (hwnd, wParam);
1216
1217 case WM_RBUTTONDBLCLK:
1218 return STATUSBAR_SendNotify (hwnd, NM_RDBLCLK);
1219
1220 case WM_RBUTTONUP:
1221 return STATUSBAR_SendNotify (hwnd, NM_RCLICK);
1222
1223 case WM_SETFONT:
1224 return STATUSBAR_WMSetFont (hwnd, wParam, lParam);
1225
1226 case WM_SETTEXT:
1227 return STATUSBAR_WMSetText (hwnd, wParam, lParam);
1228
1229 case WM_SIZE:
1230 return STATUSBAR_WMSize (hwnd, wParam, lParam);
1231
1232 default:
1233// if (msg >= WM_USER)
1234// ERR (statusbar, "unknown msg %04x wp=%04x lp=%08lx\n",
1235// msg, wParam, lParam);
1236 return DefWindowProcA (hwnd, msg, wParam, lParam);
1237 }
1238 return 0;
1239}
1240
1241
1242/***********************************************************************
1243 * STATUS_Register [Internal]
1244 *
1245 * Registers the status window class.
1246 */
1247
1248VOID
1249STATUS_Register (VOID)
1250{
1251 WNDCLASSA wndClass;
1252
1253 if (GlobalFindAtomA (STATUSCLASSNAMEA)) return;
1254
1255 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
1256 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW;
1257 wndClass.lpfnWndProc = (WNDPROC)StatusWindowProc;
1258 wndClass.cbClsExtra = 0;
1259 wndClass.cbWndExtra = sizeof(STATUSWINDOWINFO *);
1260 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
1261 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
1262 wndClass.lpszClassName = STATUSCLASSNAMEA;
1263
1264 RegisterClassA (&wndClass);
1265}
1266
1267
1268/***********************************************************************
1269 * STATUS_Unregister [Internal]
1270 *
1271 * Unregisters the status window class.
1272 */
1273
1274VOID
1275STATUS_Unregister (VOID)
1276{
1277 if (GlobalFindAtomA (STATUSCLASSNAMEA))
1278 UnregisterClassA (STATUSCLASSNAMEA, (HINSTANCE)NULL);
1279}
1280
Note: See TracBrowser for help on using the repository browser.