comctl32: header: Test and improve the custom draw and owner draw code.
[wine] / dlls / comctl32 / status.c
1 /*
2  * Interface code to StatusWindow widget/control
3  *
4  * Copyright 1996 Bruce Milner
5  * Copyright 1998, 1999 Eric Kohl
6  * Copyright 2002 Dimitrie O. Paun
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21  *
22  * NOTE
23  * 
24  * This code was audited for completeness against the documented features
25  * of Comctl32.dll version 6.0 on Sep. 24, 2002, by Dimitrie O. Paun.
26  * 
27  * Unless otherwise noted, we believe this code to be complete, as per
28  * the specification mentioned above.
29  * If you discover missing features, or bugs, please note them below.
30  * 
31  * TODO:
32  *      -- CCS_BOTTOM (default)
33  *      -- CCS_LEFT
34  *      -- CCS_NODEVIDER
35  *      -- CCS_NOMOVEX
36  *      -- CCS_NOMOVEY
37  *      -- CCS_NOPARENTALIGN
38  *      -- CCS_RIGHT
39  *      -- CCS_TOP
40  *      -- CCS_VERT (defaults to RIGHT)
41  */
42
43 #include <stdarg.h>
44 #include <string.h>
45
46 #include "windef.h"
47 #include "winbase.h"
48 #include "wine/unicode.h"
49 #include "wingdi.h"
50 #include "winuser.h"
51 #include "winnls.h"
52 #include "commctrl.h"
53 #include "comctl32.h"
54 #include "uxtheme.h"
55 #include "tmschema.h"
56 #include "wine/debug.h"
57
58 WINE_DEFAULT_DEBUG_CHANNEL(statusbar);
59
60 typedef struct
61 {
62     INT         x;
63     INT         style;
64     RECT        bound;
65     LPWSTR      text;
66     HICON       hIcon;
67 } STATUSWINDOWPART;
68
69 typedef struct
70 {
71     HWND              Self;
72     HWND              Notify;
73     WORD              numParts;
74     UINT              height;
75     BOOL              simple;
76     HWND              hwndToolTip;
77     HFONT             hFont;
78     HFONT             hDefaultFont;
79     COLORREF          clrBk;            /* background color */
80     BOOL              bUnicode;         /* unicode flag */
81     BOOL              NtfUnicode;       /* notify format */
82     STATUSWINDOWPART  part0;            /* simple window */
83     STATUSWINDOWPART* parts;
84     INT               horizontalBorder;
85     INT               verticalBorder;
86     INT               horizontalGap;
87 } STATUS_INFO;
88
89 /*
90  * Run tests using Waite Group Windows95 API Bible Vol. 1&2
91  * The second cdrom contains executables drawstat.exe, gettext.exe,
92  * simple.exe, getparts.exe, setparts.exe, statwnd.exe
93  */
94
95 #define HORZ_BORDER 0
96 #define VERT_BORDER 2
97 #define HORZ_GAP    2
98
99 static const WCHAR themeClass[] = { 'S','t','a','t','u','s',0 };
100
101 /* prototype */
102 static void
103 STATUSBAR_SetPartBounds (STATUS_INFO *infoPtr);
104
105 static inline LPCSTR debugstr_t(LPCWSTR text, BOOL isW)
106 {
107   return isW ? debugstr_w(text) : debugstr_a((LPCSTR)text);
108 }
109
110 static void
111 STATUSBAR_DrawSizeGrip (HTHEME theme, HDC hdc, LPRECT lpRect)
112 {
113     HPEN hPenFace, hPenShadow, hPenHighlight, hOldPen;
114     POINT pt;
115     INT i;
116
117     TRACE("draw size grip %d,%d - %d,%d\n", lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
118     
119     if (theme)
120     {
121         RECT gripperRect;
122         SIZE gripperSize;
123         gripperRect = *lpRect;
124         if (SUCCEEDED (GetThemePartSize (theme, hdc, SP_GRIPPER, 0, lpRect, 
125             TS_DRAW, &gripperSize)))
126         {
127             gripperRect.left = gripperRect.right - gripperSize.cx;
128             gripperRect.top = gripperRect.bottom - gripperSize.cy;
129             if (SUCCEEDED (DrawThemeBackground(theme, hdc, SP_GRIPPER, 0, &gripperRect, NULL)))
130                 return;
131         }
132     }
133
134     pt.x = lpRect->right - 1;
135     pt.y = lpRect->bottom - 1;
136
137     hPenFace = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DFACE ));
138     hOldPen = SelectObject( hdc, hPenFace );
139     MoveToEx (hdc, pt.x - 12, pt.y, NULL);
140     LineTo (hdc, pt.x, pt.y);
141     LineTo (hdc, pt.x, pt.y - 13);
142
143     pt.x--;
144     pt.y--;
145
146     hPenShadow = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DSHADOW ));
147     SelectObject( hdc, hPenShadow );
148     for (i = 1; i < 11; i += 4) {
149         MoveToEx (hdc, pt.x - i, pt.y, NULL);
150         LineTo (hdc, pt.x + 1, pt.y - i - 1);
151
152         MoveToEx (hdc, pt.x - i - 1, pt.y, NULL);
153         LineTo (hdc, pt.x + 1, pt.y - i - 2);
154     }
155
156     hPenHighlight = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DHIGHLIGHT ));
157     SelectObject( hdc, hPenHighlight );
158     for (i = 3; i < 13; i += 4) {
159         MoveToEx (hdc, pt.x - i, pt.y, NULL);
160         LineTo (hdc, pt.x + 1, pt.y - i - 1);
161     }
162
163     SelectObject (hdc, hOldPen);
164     DeleteObject( hPenFace );
165     DeleteObject( hPenShadow );
166     DeleteObject( hPenHighlight );
167 }
168
169
170 static void
171 STATUSBAR_DrawPart (STATUS_INFO *infoPtr, HDC hdc, STATUSWINDOWPART *part, int itemID)
172 {
173     RECT r = part->bound;
174     UINT border = BDR_SUNKENOUTER;
175     HTHEME theme = GetWindowTheme (infoPtr->Self);
176     int themePart = SP_PANE;
177
178     TRACE("part bound %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom);
179     if (part->style & SBT_POPOUT)
180         border = BDR_RAISEDOUTER;
181     else if (part->style & SBT_NOBORDERS)
182         border = 0;
183
184     if (theme)
185     {
186         if ((GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
187             && (infoPtr->simple || (itemID == (infoPtr->numParts-1))))
188             themePart = SP_GRIPPERPANE;
189         DrawThemeBackground(theme, hdc, themePart, 0, &r, NULL);
190     }
191     else
192         DrawEdge(hdc, &r, border, BF_RECT|BF_ADJUST);
193
194     if (part->style & SBT_OWNERDRAW) {
195         DRAWITEMSTRUCT dis;
196
197         dis.CtlID = GetWindowLongPtrW (infoPtr->Self, GWLP_ID);
198         dis.itemID = itemID;
199         dis.hwndItem = infoPtr->Self;
200         dis.hDC = hdc;
201         dis.rcItem = r;
202         dis.itemData = (ULONG_PTR)part->text;
203         SendMessageW (infoPtr->Notify, WM_DRAWITEM, (WPARAM)dis.CtlID, (LPARAM)&dis);
204     } else {
205         if (part->hIcon) {
206            INT cy = r.bottom - r.top;
207
208             r.left += 2;
209             DrawIconEx (hdc, r.left, r.top, part->hIcon, cy, cy, 0, 0, DI_NORMAL);
210             r.left += cy;
211         }
212         DrawStatusTextW (hdc, &r, part->text, SBT_NOBORDERS);
213     }
214 }
215
216
217 static void
218 STATUSBAR_RefreshPart (STATUS_INFO *infoPtr, HDC hdc, STATUSWINDOWPART *part, int itemID)
219 {
220     HBRUSH hbrBk;
221     HFONT  hOldFont;
222     HTHEME theme;
223
224     TRACE("item %d\n", itemID);
225     if (!IsWindowVisible (infoPtr->Self))
226         return;
227
228     if (part->bound.right < part->bound.left) return;
229
230     if ((theme = GetWindowTheme (infoPtr->Self)))
231     {
232         RECT cr;
233         GetClientRect (infoPtr->Self, &cr);
234         DrawThemeBackground(theme, hdc, 0, 0, &cr, &part->bound);
235     }
236     else
237     {
238         if (infoPtr->clrBk != CLR_DEFAULT)
239                 hbrBk = CreateSolidBrush (infoPtr->clrBk);
240         else
241                 hbrBk = GetSysColorBrush (COLOR_3DFACE);
242         FillRect(hdc, &part->bound, hbrBk);
243         if (infoPtr->clrBk != CLR_DEFAULT)
244                 DeleteObject (hbrBk);
245     }
246
247     hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
248
249         STATUSBAR_DrawPart (infoPtr, hdc, part, itemID);
250
251     SelectObject (hdc, hOldFont);
252
253     if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP) {
254         RECT rect;
255
256         GetClientRect (infoPtr->Self, &rect);
257         STATUSBAR_DrawSizeGrip (theme, hdc, &rect);
258     }
259 }
260
261
262 static LRESULT
263 STATUSBAR_Refresh (STATUS_INFO *infoPtr, HDC hdc)
264 {
265     int      i;
266     RECT   rect;
267     HBRUSH hbrBk;
268     HFONT  hOldFont;
269     HTHEME theme;
270
271     TRACE("\n");
272     if (!IsWindowVisible(infoPtr->Self))
273         return 0;
274
275     STATUSBAR_SetPartBounds(infoPtr);
276
277     GetClientRect (infoPtr->Self, &rect);
278
279     if ((theme = GetWindowTheme (infoPtr->Self)))
280     {
281         DrawThemeBackground(theme, hdc, 0, 0, &rect, NULL);
282     }
283     else
284     {
285         if (infoPtr->clrBk != CLR_DEFAULT)
286             hbrBk = CreateSolidBrush (infoPtr->clrBk);
287         else
288             hbrBk = GetSysColorBrush (COLOR_3DFACE);
289         FillRect(hdc, &rect, hbrBk);
290         if (infoPtr->clrBk != CLR_DEFAULT)
291             DeleteObject (hbrBk);
292     }
293
294     hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
295
296     if (infoPtr->simple) {
297         STATUSBAR_RefreshPart (infoPtr, hdc, &infoPtr->part0, 0);
298     } else {
299         for (i = 0; i < infoPtr->numParts; i++) {
300             STATUSBAR_RefreshPart (infoPtr, hdc, &infoPtr->parts[i], i);
301         }
302     }
303
304     SelectObject (hdc, hOldFont);
305
306     if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
307             STATUSBAR_DrawSizeGrip (theme, hdc, &rect);
308
309     return 0;
310 }
311
312
313 static void
314 STATUSBAR_SetPartBounds (STATUS_INFO *infoPtr)
315 {
316     STATUSWINDOWPART *part;
317     RECT rect, *r;
318     int i;
319
320     /* get our window size */
321     GetClientRect (infoPtr->Self, &rect);
322     TRACE("client wnd size is %d,%d - %d,%d\n", rect.left, rect.top, rect.right, rect.bottom);
323
324     rect.left += infoPtr->horizontalBorder;
325     rect.top += infoPtr->verticalBorder;
326
327     /* set bounds for simple rectangle */
328     infoPtr->part0.bound = rect;
329
330     /* set bounds for non-simple rectangles */
331     for (i = 0; i < infoPtr->numParts; i++) {
332         part = &infoPtr->parts[i];
333         r = &infoPtr->parts[i].bound;
334         r->top = rect.top;
335         r->bottom = rect.bottom;
336         if (i == 0)
337             r->left = 0;
338         else
339             r->left = infoPtr->parts[i-1].bound.right + infoPtr->horizontalGap;
340         if (part->x == -1)
341             r->right = rect.right;
342         else
343             r->right = part->x;
344
345         if (infoPtr->hwndToolTip) {
346             TTTOOLINFOW ti;
347
348             ti.cbSize = sizeof(TTTOOLINFOW);
349             ti.hwnd = infoPtr->Self;
350             ti.uId = i;
351             ti.rect = *r;
352             SendMessageW (infoPtr->hwndToolTip, TTM_NEWTOOLRECTW,
353                             0, (LPARAM)&ti);
354         }
355     }
356 }
357
358
359 static LRESULT
360 STATUSBAR_Relay2Tip (STATUS_INFO *infoPtr, UINT uMsg,
361                      WPARAM wParam, LPARAM lParam)
362 {
363     MSG msg;
364
365     msg.hwnd = infoPtr->Self;
366     msg.message = uMsg;
367     msg.wParam = wParam;
368     msg.lParam = lParam;
369     msg.time = GetMessageTime ();
370     msg.pt.x = LOWORD(GetMessagePos ());
371     msg.pt.y = HIWORD(GetMessagePos ());
372
373     return SendMessageW (infoPtr->hwndToolTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
374 }
375
376
377 static BOOL
378 STATUSBAR_GetBorders (STATUS_INFO *infoPtr, INT out[])
379 {
380     TRACE("\n");
381     out[0] = infoPtr->horizontalBorder;
382     out[1] = infoPtr->verticalBorder;
383     out[2] = infoPtr->horizontalGap;
384
385     return TRUE;
386 }
387
388
389 static BOOL
390 STATUSBAR_SetBorders (STATUS_INFO *infoPtr, INT in[])
391 {
392     TRACE("\n");
393     infoPtr->horizontalBorder = in[0];
394     infoPtr->verticalBorder = in[1];
395     infoPtr->horizontalGap = in[2];
396     InvalidateRect(infoPtr->Self, NULL, FALSE);
397
398     return TRUE;
399 }
400
401
402 static HICON
403 STATUSBAR_GetIcon (STATUS_INFO *infoPtr, INT nPart)
404 {
405     TRACE("%d\n", nPart);
406     /* MSDN says: "simple parts are indexed with -1" */
407     if ((nPart < -1) || (nPart >= infoPtr->numParts))
408         return 0;
409
410     if (nPart == -1)
411         return (infoPtr->part0.hIcon);
412     else
413         return (infoPtr->parts[nPart].hIcon);
414 }
415
416
417 static INT
418 STATUSBAR_GetParts (STATUS_INFO *infoPtr, INT num_parts, INT parts[])
419 {
420     INT   i;
421
422     TRACE("(%d)\n", num_parts);
423     if (parts) {
424         for (i = 0; i < num_parts; i++) {
425             parts[i] = infoPtr->parts[i].x;
426         }
427     }
428     return infoPtr->numParts;
429 }
430
431
432 static BOOL
433 STATUSBAR_GetRect (STATUS_INFO *infoPtr, INT nPart, LPRECT rect)
434 {
435     TRACE("part %d\n", nPart);
436     if (infoPtr->simple)
437         *rect = infoPtr->part0.bound;
438     else
439         *rect = infoPtr->parts[nPart].bound;
440     return TRUE;
441 }
442
443
444 static LRESULT
445 STATUSBAR_GetTextA (STATUS_INFO *infoPtr, INT nPart, LPSTR buf)
446 {
447     STATUSWINDOWPART *part;
448     LRESULT result;
449
450     TRACE("part %d\n", nPart);
451
452     /* MSDN says: "simple parts use index of 0", so this check is ok. */
453     if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
454
455     if (infoPtr->simple)
456         part = &infoPtr->part0;
457     else
458         part = &infoPtr->parts[nPart];
459
460     if (part->style & SBT_OWNERDRAW)
461         result = (LRESULT)part->text;
462     else {
463         DWORD len = part->text ? WideCharToMultiByte( CP_ACP, 0, part->text, -1,
464                                                       NULL, 0, NULL, NULL ) - 1 : 0;
465         result = MAKELONG( len, part->style );
466         if (part->text && buf)
467             WideCharToMultiByte( CP_ACP, 0, part->text, -1, buf, len+1, NULL, NULL );
468     }
469     return result;
470 }
471
472
473 static LRESULT
474 STATUSBAR_GetTextW (STATUS_INFO *infoPtr, INT nPart, LPWSTR buf)
475 {
476     STATUSWINDOWPART *part;
477     LRESULT result;
478
479     TRACE("part %d\n", nPart);
480     if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
481
482     if (infoPtr->simple)
483         part = &infoPtr->part0;
484     else
485         part = &infoPtr->parts[nPart];
486
487     if (part->style & SBT_OWNERDRAW)
488         result = (LRESULT)part->text;
489     else {
490         result = part->text ? strlenW (part->text) : 0;
491         result |= (part->style << 16);
492         if (part->text && buf)
493             strcpyW (buf, part->text);
494     }
495     return result;
496 }
497
498
499 static LRESULT
500 STATUSBAR_GetTextLength (STATUS_INFO *infoPtr, INT nPart)
501 {
502     STATUSWINDOWPART *part;
503     DWORD result;
504
505     TRACE("part %d\n", nPart);
506
507     /* MSDN says: "simple parts use index of 0", so this check is ok. */
508     if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
509
510     if (infoPtr->simple)
511         part = &infoPtr->part0;
512     else
513         part = &infoPtr->parts[nPart];
514
515     if ((~part->style & SBT_OWNERDRAW) && part->text)
516         result = strlenW(part->text);
517     else
518         result = 0;
519
520     result |= (part->style << 16);
521     return result;
522 }
523
524 static LRESULT
525 STATUSBAR_GetTipTextA (STATUS_INFO *infoPtr, INT id, LPSTR tip, INT size)
526 {
527     TRACE("\n");
528     if (tip) {
529         CHAR buf[INFOTIPSIZE];
530         buf[0]='\0';
531
532         if (infoPtr->hwndToolTip) {
533             TTTOOLINFOA ti;
534             ti.cbSize = sizeof(TTTOOLINFOA);
535             ti.hwnd = infoPtr->Self;
536             ti.uId = id;
537             ti.lpszText = buf;
538             SendMessageA (infoPtr->hwndToolTip, TTM_GETTEXTA, 0, (LPARAM)&ti);
539         }
540         lstrcpynA (tip, buf, size);
541     }
542     return 0;
543 }
544
545
546 static LRESULT
547 STATUSBAR_GetTipTextW (STATUS_INFO *infoPtr, INT id, LPWSTR tip, INT size)
548 {
549     TRACE("\n");
550     if (tip) {
551         WCHAR buf[INFOTIPSIZE];
552         buf[0]=0;
553
554         if (infoPtr->hwndToolTip) {
555             TTTOOLINFOW ti;
556             ti.cbSize = sizeof(TTTOOLINFOW);
557             ti.hwnd = infoPtr->Self;
558             ti.uId = id;
559             ti.lpszText = buf;
560             SendMessageW(infoPtr->hwndToolTip, TTM_GETTEXTW, 0, (LPARAM)&ti);
561         }
562         lstrcpynW(tip, buf, size);
563     }
564
565     return 0;
566 }
567
568
569 static COLORREF
570 STATUSBAR_SetBkColor (STATUS_INFO *infoPtr, COLORREF color)
571 {
572     COLORREF oldBkColor;
573
574     oldBkColor = infoPtr->clrBk;
575     infoPtr->clrBk = color;
576     InvalidateRect(infoPtr->Self, NULL, FALSE);
577
578     TRACE("CREF: %08x -> %08x\n", oldBkColor, infoPtr->clrBk);
579     return oldBkColor;
580 }
581
582
583 static BOOL
584 STATUSBAR_SetIcon (STATUS_INFO *infoPtr, INT nPart, HICON hIcon)
585 {
586     if ((nPart < -1) || (nPart >= infoPtr->numParts))
587         return FALSE;
588
589     TRACE("setting part %d\n", nPart);
590
591     /* FIXME: MSDN says "if nPart is -1, the status bar is assumed simple" */
592     if (nPart == -1) {
593         if (infoPtr->part0.hIcon == hIcon) /* same as - no redraw */
594             return TRUE;
595         infoPtr->part0.hIcon = hIcon;
596         if (infoPtr->simple)
597             InvalidateRect(infoPtr->Self, &infoPtr->part0.bound, FALSE);
598     } else {
599         if (infoPtr->parts[nPart].hIcon == hIcon) /* same as - no redraw */
600             return TRUE;
601
602         infoPtr->parts[nPart].hIcon = hIcon;
603         if (!(infoPtr->simple))
604             InvalidateRect(infoPtr->Self, &infoPtr->parts[nPart].bound, FALSE);
605     }
606     return TRUE;
607 }
608
609
610 static BOOL
611 STATUSBAR_SetMinHeight (STATUS_INFO *infoPtr, INT height)
612 {
613
614     TRACE("(height=%d)\n", height);
615     if (IsWindowVisible (infoPtr->Self)) {
616         INT  width, x, y;
617         RECT parent_rect;
618         HTHEME theme;
619
620         GetClientRect (infoPtr->Notify, &parent_rect);
621         infoPtr->height = height + infoPtr->verticalBorder;
622         
623         if ((theme = GetWindowTheme (infoPtr->Self)))
624         {
625             /* Determine bar height from theme such that the content area is
626              * 'height' pixels large */
627             HDC hdc = GetDC (infoPtr->Self);
628             RECT r;
629             memset (&r, 0, sizeof (r));
630             r.bottom = height;
631             if (SUCCEEDED(GetThemeBackgroundExtent (theme, hdc, SP_PANE, 0, &r, &r)))
632             {
633                 infoPtr->height = r.bottom - r.top;
634             }
635             ReleaseDC (infoPtr->Self, hdc);
636         }
637         
638         width = parent_rect.right - parent_rect.left;
639         x = parent_rect.left;
640         y = parent_rect.bottom - infoPtr->height;
641         MoveWindow (infoPtr->Self, parent_rect.left,
642                     parent_rect.bottom - infoPtr->height,
643                     width, infoPtr->height, TRUE);
644         STATUSBAR_SetPartBounds (infoPtr);
645     }
646
647     return TRUE;
648 }
649
650
651 static BOOL
652 STATUSBAR_SetParts (STATUS_INFO *infoPtr, INT count, LPINT parts)
653 {
654     STATUSWINDOWPART *tmp;
655     int i, oldNumParts;
656
657     TRACE("(%d,%p)\n", count, parts);
658
659     oldNumParts = infoPtr->numParts;
660     infoPtr->numParts = count;
661     if (oldNumParts > infoPtr->numParts) {
662         for (i = infoPtr->numParts ; i < oldNumParts; i++) {
663             if (infoPtr->parts[i].text && !(infoPtr->parts[i].style & SBT_OWNERDRAW))
664                 Free (infoPtr->parts[i].text);
665         }
666     } else if (oldNumParts < infoPtr->numParts) {
667         tmp = Alloc (sizeof(STATUSWINDOWPART) * infoPtr->numParts);
668         if (!tmp) return FALSE;
669         for (i = 0; i < oldNumParts; i++) {
670             tmp[i] = infoPtr->parts[i];
671         }
672         if (infoPtr->parts)
673             Free (infoPtr->parts);
674         infoPtr->parts = tmp;
675     }
676     if (oldNumParts == infoPtr->numParts) {
677         for (i=0; i < oldNumParts; i++)
678             if (infoPtr->parts[i].x != parts[i])
679                 break;
680         if (i==oldNumParts) /* Unchanged? no need to redraw! */
681             return TRUE;
682     }
683
684     for (i = 0; i < infoPtr->numParts; i++)
685         infoPtr->parts[i].x = parts[i];
686
687     if (infoPtr->hwndToolTip) {
688         INT nTipCount, i;
689         TTTOOLINFOW ti;
690
691         ZeroMemory (&ti, sizeof(TTTOOLINFOW));
692         ti.cbSize = sizeof(TTTOOLINFOW);
693         ti.hwnd = infoPtr->Self;
694
695         nTipCount = SendMessageW (infoPtr->hwndToolTip, TTM_GETTOOLCOUNT, 0, 0);
696         if (nTipCount < infoPtr->numParts) {
697             /* add tools */
698             for (i = nTipCount; i < infoPtr->numParts; i++) {
699                 TRACE("add tool %d\n", i);
700                 ti.uId = i;
701                 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
702                                 0, (LPARAM)&ti);
703             }
704         }
705         else if (nTipCount > infoPtr->numParts) {
706             /* delete tools */
707             for (i = nTipCount - 1; i >= infoPtr->numParts; i--) {
708                 TRACE("delete tool %d\n", i);
709                 ti.uId = i;
710                 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW,
711                                 0, (LPARAM)&ti);
712             }
713         }
714     }
715     STATUSBAR_SetPartBounds (infoPtr);
716     InvalidateRect(infoPtr->Self, NULL, FALSE);
717     return TRUE;
718 }
719
720
721 static BOOL
722 STATUSBAR_SetTextT (STATUS_INFO *infoPtr, INT nPart, WORD style,
723                     LPCWSTR text, BOOL isW)
724 {
725     STATUSWINDOWPART *part=NULL;
726     BOOL changed = FALSE;
727     INT  oldStyle;
728
729     if (style & SBT_OWNERDRAW) {
730          TRACE("part %d, text %p\n",nPart,text);
731     }
732     else TRACE("part %d, text %s\n", nPart, debugstr_t(text, isW));
733
734     /* MSDN says: "If the parameter is set to SB_SIMPLEID (255), the status
735      * window is assumed to be a simple window */
736
737     if (nPart == 0x00ff) {
738         part = &infoPtr->part0;
739     } else {
740         if (infoPtr->parts && nPart >= 0 && nPart < infoPtr->numParts) {
741             part = &infoPtr->parts[nPart];
742         }
743     }
744     if (!part) return FALSE;
745
746     if (part->style != style)
747         changed = TRUE;
748
749     oldStyle = part->style;
750     part->style = style;
751     if (style & SBT_OWNERDRAW) {
752         if (!(oldStyle & SBT_OWNERDRAW)) {
753             if (part->text)
754                 Free (part->text);
755         } else if (part->text == text)
756             return TRUE;
757         part->text = (LPWSTR)text;
758     } else {
759         LPWSTR ntext;
760
761         if (text && !isW) {
762             LPCSTR atxt = (LPCSTR)text;
763             DWORD len = MultiByteToWideChar( CP_ACP, 0, atxt, -1, NULL, 0 );
764             ntext = Alloc( (len + 1)*sizeof(WCHAR) );
765             if (!ntext) return FALSE;
766             MultiByteToWideChar( CP_ACP, 0, atxt, -1, ntext, len );
767         } else if (text) {
768             ntext = Alloc( (strlenW(text) + 1)*sizeof(WCHAR) );
769             if (!ntext) return FALSE;
770             strcpyW (ntext, text);
771         } else ntext = 0;
772
773         /* check if text is unchanged -> no need to redraw */
774         if (text) {
775             if (!changed && part->text && !lstrcmpW(ntext, part->text)) {
776                 Free(ntext);
777                 return TRUE;
778             }
779         } else {
780             if (!changed && !part->text)
781                 return TRUE;
782         }
783
784         if (part->text && !(oldStyle & SBT_OWNERDRAW))
785             Free (part->text);
786         part->text = ntext;
787     }
788     InvalidateRect(infoPtr->Self, &part->bound, FALSE);
789     UpdateWindow(infoPtr->Self);
790
791     return TRUE;
792 }
793
794
795 static LRESULT
796 STATUSBAR_SetTipTextA (STATUS_INFO *infoPtr, INT id, LPSTR text)
797 {
798     TRACE("part %d: \"%s\"\n", id, text);
799     if (infoPtr->hwndToolTip) {
800         TTTOOLINFOA ti;
801         ti.cbSize = sizeof(TTTOOLINFOA);
802         ti.hwnd = infoPtr->Self;
803         ti.uId = id;
804         ti.hinst = 0;
805         ti.lpszText = text;
806         SendMessageA (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTA, 0, (LPARAM)&ti);
807     }
808
809     return 0;
810 }
811
812
813 static LRESULT
814 STATUSBAR_SetTipTextW (STATUS_INFO *infoPtr, INT id, LPWSTR text)
815 {
816     TRACE("part %d: \"%s\"\n", id, debugstr_w(text));
817     if (infoPtr->hwndToolTip) {
818         TTTOOLINFOW ti;
819         ti.cbSize = sizeof(TTTOOLINFOW);
820         ti.hwnd = infoPtr->Self;
821         ti.uId = id;
822         ti.hinst = 0;
823         ti.lpszText = text;
824         SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
825     }
826
827     return 0;
828 }
829
830
831 inline static LRESULT
832 STATUSBAR_SetUnicodeFormat (STATUS_INFO *infoPtr, BOOL bUnicode)
833 {
834     BOOL bOld = infoPtr->bUnicode;
835
836     TRACE("(0x%x)\n", bUnicode);
837     infoPtr->bUnicode = bUnicode;
838
839     return bOld;
840 }
841
842
843 static BOOL
844 STATUSBAR_Simple (STATUS_INFO *infoPtr, BOOL simple)
845 {
846     NMHDR  nmhdr;
847
848     TRACE("(simple=%d)\n", simple);
849     if (infoPtr->simple == simple) /* no need to change */
850         return TRUE;
851
852     infoPtr->simple = simple;
853
854     /* send notification */
855     nmhdr.hwndFrom = infoPtr->Self;
856     nmhdr.idFrom = GetWindowLongPtrW (infoPtr->Self, GWLP_ID);
857     nmhdr.code = SBN_SIMPLEMODECHANGE;
858     SendMessageW (infoPtr->Notify, WM_NOTIFY, 0, (LPARAM)&nmhdr);
859     InvalidateRect(infoPtr->Self, NULL, FALSE);
860     return TRUE;
861 }
862
863
864 static LRESULT
865 STATUSBAR_WMDestroy (STATUS_INFO *infoPtr)
866 {
867     int i;
868
869     TRACE("\n");
870     for (i = 0; i < infoPtr->numParts; i++) {
871         if (infoPtr->parts[i].text && !(infoPtr->parts[i].style & SBT_OWNERDRAW))
872             Free (infoPtr->parts[i].text);
873     }
874     if (infoPtr->part0.text && !(infoPtr->part0.style & SBT_OWNERDRAW))
875         Free (infoPtr->part0.text);
876     Free (infoPtr->parts);
877
878     /* delete default font */
879     if (infoPtr->hDefaultFont)
880         DeleteObject (infoPtr->hDefaultFont);
881
882     /* delete tool tip control */
883     if (infoPtr->hwndToolTip)
884         DestroyWindow (infoPtr->hwndToolTip);
885
886     CloseThemeData (GetWindowTheme (infoPtr->Self));
887
888     SetWindowLongPtrW(infoPtr->Self, 0, 0);
889     Free (infoPtr);
890     return 0;
891 }
892
893
894 static LRESULT
895 STATUSBAR_WMCreate (HWND hwnd, LPCREATESTRUCTA lpCreate)
896 {
897     STATUS_INFO *infoPtr;
898     NONCLIENTMETRICSW nclm;
899     DWORD dwStyle;
900     RECT rect;
901     int i, width, len, textHeight = 0;
902     HDC hdc;
903
904     TRACE("\n");
905     infoPtr = (STATUS_INFO*)Alloc (sizeof(STATUS_INFO));
906     if (!infoPtr) goto create_fail;
907     SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
908
909     infoPtr->Self = hwnd;
910     infoPtr->Notify = lpCreate->hwndParent;
911     infoPtr->numParts = 1;
912     infoPtr->parts = 0;
913     infoPtr->simple = FALSE;
914     infoPtr->clrBk = CLR_DEFAULT;
915     infoPtr->hFont = 0;
916     infoPtr->horizontalBorder = HORZ_BORDER;
917     infoPtr->verticalBorder = VERT_BORDER;
918     infoPtr->horizontalGap = HORZ_GAP;
919
920     i = SendMessageW(infoPtr->Notify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
921     infoPtr->NtfUnicode = (i == NFR_UNICODE);
922
923     GetClientRect (hwnd, &rect);
924     InvalidateRect (hwnd, &rect, 0);
925     UpdateWindow(hwnd);
926
927     ZeroMemory (&nclm, sizeof(nclm));
928     nclm.cbSize = sizeof(nclm);
929     SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, nclm.cbSize, &nclm, 0);
930     infoPtr->hDefaultFont = CreateFontIndirectW (&nclm.lfStatusFont);
931
932     /* initialize simple case */
933     infoPtr->part0.bound = rect;
934     infoPtr->part0.text = 0;
935     infoPtr->part0.x = 0;
936     infoPtr->part0.style = 0;
937     infoPtr->part0.hIcon = 0;
938
939     /* initialize first part */
940     infoPtr->parts = Alloc (sizeof(STATUSWINDOWPART));
941     if (!infoPtr->parts) goto create_fail;
942     infoPtr->parts[0].bound = rect;
943     infoPtr->parts[0].text = 0;
944     infoPtr->parts[0].x = -1;
945     infoPtr->parts[0].style = 0;
946     infoPtr->parts[0].hIcon = 0;
947     
948     OpenThemeData (hwnd, themeClass);
949
950     if (IsWindowUnicode (hwnd)) {
951         infoPtr->bUnicode = TRUE;
952         if (lpCreate->lpszName &&
953             (len = strlenW ((LPCWSTR)lpCreate->lpszName))) {
954             infoPtr->parts[0].text = Alloc ((len + 1)*sizeof(WCHAR));
955             if (!infoPtr->parts[0].text) goto create_fail;
956             strcpyW (infoPtr->parts[0].text, (LPCWSTR)lpCreate->lpszName);
957         }
958     }
959     else {
960         if (lpCreate->lpszName &&
961             (len = strlen((LPCSTR)lpCreate->lpszName))) {
962             DWORD lenW = MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1, NULL, 0 );
963             infoPtr->parts[0].text = Alloc (lenW*sizeof(WCHAR));
964             if (!infoPtr->parts[0].text) goto create_fail;
965             MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1,
966                                  infoPtr->parts[0].text, lenW );
967         }
968     }
969
970     dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
971     /* native seems to clear WS_BORDER, too */
972     dwStyle &= ~WS_BORDER;
973
974     /* statusbars on managed windows should not have SIZEGRIP style */
975     if ((dwStyle & SBARS_SIZEGRIP) && lpCreate->hwndParent &&
976         GetPropA( lpCreate->hwndParent, "__wine_x11_managed" ))
977         dwStyle &= ~SBARS_SIZEGRIP;
978
979     SetWindowLongW (hwnd, GWL_STYLE, dwStyle);
980
981     if ((hdc = GetDC (hwnd))) {
982         TEXTMETRICW tm;
983         HFONT hOldFont;
984
985         hOldFont = SelectObject (hdc, infoPtr->hDefaultFont);
986         GetTextMetricsW (hdc, &tm);
987         textHeight = tm.tmHeight;
988         SelectObject (hdc, hOldFont);
989         ReleaseDC (hwnd, hdc);
990     }
991     TRACE("    textHeight=%d\n", textHeight);
992
993     if (dwStyle & SBT_TOOLTIPS) {
994         infoPtr->hwndToolTip =
995             CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, 0,
996                              CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
997                              CW_USEDEFAULT, hwnd, 0,
998                              (HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE), NULL);
999
1000         if (infoPtr->hwndToolTip) {
1001             NMTOOLTIPSCREATED nmttc;
1002
1003             nmttc.hdr.hwndFrom = hwnd;
1004             nmttc.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
1005             nmttc.hdr.code = NM_TOOLTIPSCREATED;
1006             nmttc.hwndToolTips = infoPtr->hwndToolTip;
1007
1008             SendMessageW (lpCreate->hwndParent, WM_NOTIFY,
1009                             (WPARAM)nmttc.hdr.idFrom, (LPARAM)&nmttc);
1010         }
1011     }
1012
1013     if (!(dwStyle & CCS_NORESIZE)) { /* don't resize wnd if it doesn't want it ! */
1014         HTHEME theme;
1015         GetClientRect (infoPtr->Notify, &rect);
1016         width = rect.right - rect.left;
1017         infoPtr->height = textHeight + 4 + infoPtr->verticalBorder;
1018         
1019         if ((theme = GetWindowTheme (hwnd)))
1020         {
1021             /* Determine bar height from theme such that the content area is
1022              * textHeight pixels large */
1023             HDC hdc = GetDC (hwnd);
1024             RECT r;
1025             memset (&r, 0, sizeof (r));
1026             r.bottom = textHeight;
1027             if (SUCCEEDED(GetThemeBackgroundExtent (theme, hdc, SP_PANE, 0, &r, &r)))
1028             {
1029                 infoPtr->height = r.bottom - r.top;
1030             }
1031             ReleaseDC (hwnd, hdc);
1032         }
1033     
1034         SetWindowPos(hwnd, 0, lpCreate->x, lpCreate->y - 1,
1035                         width, infoPtr->height, SWP_NOZORDER);
1036         STATUSBAR_SetPartBounds (infoPtr);
1037     }
1038
1039     return 0;
1040
1041 create_fail:
1042     TRACE("    failed!\n");
1043     if (infoPtr) STATUSBAR_WMDestroy(infoPtr);
1044     return -1;
1045 }
1046
1047
1048 /* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
1049  * of the first part only (usual behaviour) */
1050 static INT
1051 STATUSBAR_WMGetText (STATUS_INFO *infoPtr, INT size, LPWSTR buf)
1052 {
1053     INT len;
1054
1055     TRACE("\n");
1056     if (!(infoPtr->parts[0].text))
1057         return 0;
1058     if (infoPtr->bUnicode)
1059         len = strlenW (infoPtr->parts[0].text);
1060     else
1061         len = WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1, NULL, 0, NULL, NULL )-1;
1062
1063     if (size > len) {
1064         if (infoPtr->bUnicode)
1065             strcpyW (buf, infoPtr->parts[0].text);
1066         else
1067             WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1,
1068                                  (LPSTR)buf, len+1, NULL, NULL );
1069         return len;
1070     }
1071
1072     return -1;
1073 }
1074
1075
1076 static BOOL
1077 STATUSBAR_WMNCHitTest (STATUS_INFO *infoPtr, INT x, INT y)
1078 {
1079     if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP) {
1080         RECT  rect;
1081         POINT pt;
1082
1083         GetClientRect (infoPtr->Self, &rect);
1084
1085         pt.x = x;
1086         pt.y = y;
1087         ScreenToClient (infoPtr->Self, &pt);
1088
1089         rect.left = rect.right - 13;
1090         rect.top += 2;
1091
1092         if (PtInRect (&rect, pt))
1093             return HTBOTTOMRIGHT;
1094     }
1095
1096     return HTERROR;
1097 }
1098
1099
1100 static LRESULT
1101 STATUSBAR_WMPaint (STATUS_INFO *infoPtr, HDC hdc)
1102 {
1103     PAINTSTRUCT ps;
1104
1105     TRACE("\n");
1106     if (hdc) return STATUSBAR_Refresh (infoPtr, hdc);
1107     hdc = BeginPaint (infoPtr->Self, &ps);
1108     STATUSBAR_Refresh (infoPtr, hdc);
1109     EndPaint (infoPtr->Self, &ps);
1110
1111     return 0;
1112 }
1113
1114
1115 static LRESULT
1116 STATUSBAR_WMSetFont (STATUS_INFO *infoPtr, HFONT font, BOOL redraw)
1117 {
1118     infoPtr->hFont = font;
1119     TRACE("%p\n", infoPtr->hFont);
1120     if (redraw)
1121         InvalidateRect(infoPtr->Self, NULL, FALSE);
1122
1123     return 0;
1124 }
1125
1126
1127 static BOOL
1128 STATUSBAR_WMSetText (STATUS_INFO *infoPtr, LPCSTR text)
1129 {
1130     STATUSWINDOWPART *part;
1131     int len;
1132
1133     TRACE("\n");
1134     if (infoPtr->numParts == 0)
1135         return FALSE;
1136
1137     part = &infoPtr->parts[0];
1138     /* duplicate string */
1139     if (part->text)
1140         Free (part->text);
1141     part->text = 0;
1142     if (infoPtr->bUnicode) {
1143         if (text && (len = strlenW((LPCWSTR)text))) {
1144             part->text = Alloc ((len+1)*sizeof(WCHAR));
1145             if (!part->text) return FALSE;
1146             strcpyW (part->text, (LPCWSTR)text);
1147         }
1148     }
1149     else {
1150         if (text && (len = lstrlenA(text))) {
1151             DWORD lenW = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
1152             part->text = Alloc (lenW*sizeof(WCHAR));
1153             if (!part->text) return FALSE;
1154             MultiByteToWideChar( CP_ACP, 0, text, -1, part->text, lenW );
1155         }
1156     }
1157
1158     InvalidateRect(infoPtr->Self, &part->bound, FALSE);
1159
1160     return TRUE;
1161 }
1162
1163
1164 static BOOL
1165 STATUSBAR_WMSize (STATUS_INFO *infoPtr, WORD flags)
1166 {
1167     INT  width, x, y;
1168     RECT parent_rect;
1169
1170     /* Need to resize width to match parent */
1171     TRACE("flags %04x\n", flags);
1172
1173     if (flags != SIZE_RESTORED && flags != SIZE_MAXIMIZED) {
1174         WARN("flags MUST be SIZE_RESTORED or SIZE_MAXIMIZED\n");
1175         return FALSE;
1176     }
1177
1178     if (GetWindowLongW(infoPtr->Self, GWL_STYLE) & CCS_NORESIZE) return FALSE;
1179
1180     /* width and height don't apply */
1181     GetClientRect (infoPtr->Notify, &parent_rect);
1182     width = parent_rect.right - parent_rect.left;
1183     x = parent_rect.left;
1184     y = parent_rect.bottom - infoPtr->height;
1185     MoveWindow (infoPtr->Self, parent_rect.left,
1186                 parent_rect.bottom - infoPtr->height,
1187                 width, infoPtr->height, TRUE);
1188     STATUSBAR_SetPartBounds (infoPtr);
1189     return TRUE;
1190 }
1191
1192
1193 /* update theme after a WM_THEMECHANGED message */
1194 static LRESULT theme_changed (STATUS_INFO* infoPtr)
1195 {
1196     HTHEME theme = GetWindowTheme (infoPtr->Self);
1197     CloseThemeData (theme);
1198     OpenThemeData (infoPtr->Self, themeClass);
1199     return 0;
1200 }
1201
1202
1203 static LRESULT
1204 STATUSBAR_NotifyFormat (STATUS_INFO *infoPtr, HWND from, INT cmd)
1205 {
1206     if (cmd == NF_REQUERY) {
1207         INT i = SendMessageW(from, WM_NOTIFYFORMAT, (WPARAM)infoPtr->Self, NF_QUERY);
1208         infoPtr->NtfUnicode = (i == NFR_UNICODE);
1209     }
1210     return infoPtr->NtfUnicode ? NFR_UNICODE : NFR_ANSI;
1211 }
1212
1213
1214 static LRESULT
1215 STATUSBAR_SendNotify (STATUS_INFO *infoPtr, UINT code)
1216 {
1217     NMHDR  nmhdr;
1218
1219     TRACE("code %04x\n", code);
1220     nmhdr.hwndFrom = infoPtr->Self;
1221     nmhdr.idFrom = GetWindowLongPtrW (infoPtr->Self, GWLP_ID);
1222     nmhdr.code = code;
1223     SendMessageW (infoPtr->Notify, WM_NOTIFY, 0, (LPARAM)&nmhdr);
1224     return 0;
1225 }
1226
1227
1228
1229 static LRESULT WINAPI
1230 StatusWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1231 {
1232     STATUS_INFO *infoPtr = (STATUS_INFO *)GetWindowLongPtrW (hwnd, 0);
1233     INT nPart = ((INT) wParam) & 0x00ff;
1234     LRESULT res;
1235
1236     TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hwnd, msg, wParam, lParam);
1237     if (!infoPtr && msg != WM_CREATE)
1238         return DefWindowProcW (hwnd, msg, wParam, lParam);
1239
1240     switch (msg) {
1241         case SB_GETBORDERS:
1242             return STATUSBAR_GetBorders (infoPtr, (INT *)lParam);
1243
1244         case SB_GETICON:
1245             return (LRESULT)STATUSBAR_GetIcon (infoPtr, nPart);
1246
1247         case SB_GETPARTS:
1248             return STATUSBAR_GetParts (infoPtr, (INT)wParam, (INT *)lParam);
1249
1250         case SB_GETRECT:
1251             return STATUSBAR_GetRect (infoPtr, nPart, (LPRECT)lParam);
1252
1253         case SB_GETTEXTA:
1254             return STATUSBAR_GetTextA (infoPtr, nPart, (LPSTR)lParam);
1255
1256         case SB_GETTEXTW:
1257             return STATUSBAR_GetTextW (infoPtr, nPart, (LPWSTR)lParam);
1258
1259         case SB_GETTEXTLENGTHA:
1260         case SB_GETTEXTLENGTHW:
1261             return STATUSBAR_GetTextLength (infoPtr, nPart);
1262
1263         case SB_GETTIPTEXTA:
1264             return STATUSBAR_GetTipTextA (infoPtr,  LOWORD(wParam), (LPSTR)lParam,  HIWORD(wParam));
1265
1266         case SB_GETTIPTEXTW:
1267             return STATUSBAR_GetTipTextW (infoPtr,  LOWORD(wParam), (LPWSTR)lParam,  HIWORD(wParam));
1268
1269         case SB_GETUNICODEFORMAT:
1270             return infoPtr->bUnicode;
1271
1272         case SB_ISSIMPLE:
1273             return infoPtr->simple;
1274
1275         case SB_SETBORDERS:
1276             return STATUSBAR_SetBorders (infoPtr, (INT *)lParam);
1277
1278         case SB_SETBKCOLOR:
1279             return STATUSBAR_SetBkColor (infoPtr, (COLORREF)lParam);
1280
1281         case SB_SETICON:
1282             return STATUSBAR_SetIcon (infoPtr, nPart, (HICON)lParam);
1283
1284         case SB_SETMINHEIGHT:
1285             return STATUSBAR_SetMinHeight (infoPtr, (INT)wParam);
1286
1287         case SB_SETPARTS:
1288             return STATUSBAR_SetParts (infoPtr, (INT)wParam, (LPINT)lParam);
1289
1290         case SB_SETTEXTA:
1291             return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, FALSE);
1292
1293         case SB_SETTEXTW:
1294             return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, TRUE);
1295
1296         case SB_SETTIPTEXTA:
1297             return STATUSBAR_SetTipTextA (infoPtr, (INT)wParam, (LPSTR)lParam);
1298
1299         case SB_SETTIPTEXTW:
1300             return STATUSBAR_SetTipTextW (infoPtr, (INT)wParam, (LPWSTR)lParam);
1301
1302         case SB_SETUNICODEFORMAT:
1303             return STATUSBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1304
1305         case SB_SIMPLE:
1306             return STATUSBAR_Simple (infoPtr, (BOOL)wParam);
1307
1308         case WM_CREATE:
1309             return STATUSBAR_WMCreate (hwnd, (LPCREATESTRUCTA)lParam);
1310
1311         case WM_DESTROY:
1312             return STATUSBAR_WMDestroy (infoPtr);
1313
1314         case WM_GETFONT:
1315             return (LRESULT)(infoPtr->hFont? infoPtr->hFont : infoPtr->hDefaultFont);
1316
1317         case WM_GETTEXT:
1318             return STATUSBAR_WMGetText (infoPtr, (INT)wParam, (LPWSTR)lParam);
1319
1320         case WM_GETTEXTLENGTH:
1321             return STATUSBAR_GetTextLength (infoPtr, 0);
1322
1323         case WM_LBUTTONDBLCLK:
1324             return STATUSBAR_SendNotify (infoPtr, NM_DBLCLK);
1325
1326         case WM_LBUTTONUP:
1327             return STATUSBAR_SendNotify (infoPtr, NM_CLICK);
1328
1329         case WM_MOUSEMOVE:
1330             return STATUSBAR_Relay2Tip (infoPtr, msg, wParam, lParam);
1331
1332         case WM_NCHITTEST:
1333             res = STATUSBAR_WMNCHitTest(infoPtr, (INT)LOWORD(lParam),
1334                                         (INT)HIWORD(lParam));
1335             if (res != HTERROR) return res;
1336             return DefWindowProcW (hwnd, msg, wParam, lParam);
1337
1338         case WM_NCLBUTTONUP:
1339         case WM_NCLBUTTONDOWN:
1340             PostMessageW (infoPtr->Notify, msg, wParam, lParam);
1341             return 0;
1342
1343         case WM_NOTIFYFORMAT:
1344             return STATUSBAR_NotifyFormat(infoPtr, (HWND)wParam, (INT)lParam);
1345
1346         case WM_PRINTCLIENT:
1347         case WM_PAINT:
1348             return STATUSBAR_WMPaint (infoPtr, (HDC)wParam);
1349
1350         case WM_RBUTTONDBLCLK:
1351             return STATUSBAR_SendNotify (infoPtr, NM_RDBLCLK);
1352
1353         case WM_RBUTTONUP:
1354             return STATUSBAR_SendNotify (infoPtr, NM_RCLICK);
1355
1356         case WM_SETFONT:
1357             return STATUSBAR_WMSetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
1358
1359         case WM_SETTEXT:
1360             return STATUSBAR_WMSetText (infoPtr, (LPCSTR)lParam);
1361
1362         case WM_SIZE:
1363             if (STATUSBAR_WMSize (infoPtr, (WORD)wParam)) return 0;
1364             return DefWindowProcW (hwnd, msg, wParam, lParam);
1365
1366         case WM_THEMECHANGED:
1367             return theme_changed (infoPtr);
1368
1369         default:
1370             if ((msg >= WM_USER) && (msg < WM_APP))
1371                 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1372                      msg, wParam, lParam);
1373             return DefWindowProcW (hwnd, msg, wParam, lParam);
1374     }
1375 }
1376
1377
1378 /***********************************************************************
1379  * STATUS_Register [Internal]
1380  *
1381  * Registers the status window class.
1382  */
1383
1384 void
1385 STATUS_Register (void)
1386 {
1387     WNDCLASSW wndClass;
1388
1389     ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1390     wndClass.style         = CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW;
1391     wndClass.lpfnWndProc   = StatusWindowProc;
1392     wndClass.cbClsExtra    = 0;
1393     wndClass.cbWndExtra    = sizeof(STATUS_INFO *);
1394     wndClass.hCursor       = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1395     wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
1396     wndClass.lpszClassName = STATUSCLASSNAMEW;
1397
1398     RegisterClassW (&wndClass);
1399 }
1400
1401
1402 /***********************************************************************
1403  * STATUS_Unregister [Internal]
1404  *
1405  * Unregisters the status window class.
1406  */
1407
1408 void
1409 STATUS_Unregister (void)
1410 {
1411     UnregisterClassW (STATUSCLASSNAMEW, NULL);
1412 }