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

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

Unicode and other extensions

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