source: trunk/src/comctl32/status.cpp@ 2875

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

C -> C++, WINE animate, treeview WM_VSCROLL fixed

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