comctl32: Remove some more useless asserts.
[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_NODIVIDER
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 %s\n", wine_dbgstr_rect(lpRect));
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 (const STATUS_INFO *infoPtr, HDC hdc, const 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 %s\n", wine_dbgstr_rect(&r));
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 (const STATUS_INFO *infoPtr, HDC hdc, const 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 int
314 STATUSBAR_InternalHitTest(const STATUS_INFO *infoPtr, const LPPOINT pt)
315 {
316     int i;
317     if (infoPtr->simple)
318         return 255;
319
320     for (i = 0; i < infoPtr->numParts; i++)
321         if (pt->x >= infoPtr->parts[i].bound.left && pt->x <= infoPtr->parts[i].bound.right)
322             return i;
323     return -2;
324 }
325
326
327 static void
328 STATUSBAR_SetPartBounds (STATUS_INFO *infoPtr)
329 {
330     STATUSWINDOWPART *part;
331     RECT rect, *r;
332     int i;
333
334     /* get our window size */
335     GetClientRect (infoPtr->Self, &rect);
336     TRACE("client wnd size is %s\n", wine_dbgstr_rect(&rect));
337
338     rect.left += infoPtr->horizontalBorder;
339     rect.top += infoPtr->verticalBorder;
340
341     /* set bounds for simple rectangle */
342     infoPtr->part0.bound = rect;
343
344     /* set bounds for non-simple rectangles */
345     for (i = 0; i < infoPtr->numParts; i++) {
346         part = &infoPtr->parts[i];
347         r = &infoPtr->parts[i].bound;
348         r->top = rect.top;
349         r->bottom = rect.bottom;
350         if (i == 0)
351             r->left = 0;
352         else
353             r->left = infoPtr->parts[i-1].bound.right + infoPtr->horizontalGap;
354         if (part->x == -1)
355             r->right = rect.right;
356         else
357             r->right = part->x;
358
359         if (infoPtr->hwndToolTip) {
360             TTTOOLINFOW ti;
361
362             ti.cbSize = sizeof(TTTOOLINFOW);
363             ti.hwnd = infoPtr->Self;
364             ti.uId = i;
365             ti.rect = *r;
366             SendMessageW (infoPtr->hwndToolTip, TTM_NEWTOOLRECTW,
367                             0, (LPARAM)&ti);
368         }
369     }
370 }
371
372
373 static LRESULT
374 STATUSBAR_Relay2Tip (const STATUS_INFO *infoPtr, UINT uMsg,
375                      WPARAM wParam, LPARAM lParam)
376 {
377     MSG msg;
378
379     msg.hwnd = infoPtr->Self;
380     msg.message = uMsg;
381     msg.wParam = wParam;
382     msg.lParam = lParam;
383     msg.time = GetMessageTime ();
384     msg.pt.x = (short)LOWORD(GetMessagePos ());
385     msg.pt.y = (short)HIWORD(GetMessagePos ());
386
387     return SendMessageW (infoPtr->hwndToolTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
388 }
389
390
391 static BOOL
392 STATUSBAR_GetBorders (const STATUS_INFO *infoPtr, INT out[])
393 {
394     TRACE("\n");
395     out[0] = infoPtr->horizontalBorder;
396     out[1] = infoPtr->verticalBorder;
397     out[2] = infoPtr->horizontalGap;
398
399     return TRUE;
400 }
401
402
403 static BOOL
404 STATUSBAR_SetBorders (STATUS_INFO *infoPtr, const INT in[])
405 {
406     TRACE("\n");
407     infoPtr->horizontalBorder = in[0];
408     infoPtr->verticalBorder = in[1];
409     infoPtr->horizontalGap = in[2];
410     InvalidateRect(infoPtr->Self, NULL, FALSE);
411
412     return TRUE;
413 }
414
415
416 static HICON
417 STATUSBAR_GetIcon (const STATUS_INFO *infoPtr, INT nPart)
418 {
419     TRACE("%d\n", nPart);
420     /* MSDN says: "simple parts are indexed with -1" */
421     if ((nPart < -1) || (nPart >= infoPtr->numParts))
422         return 0;
423
424     if (nPart == -1)
425         return (infoPtr->part0.hIcon);
426     else
427         return (infoPtr->parts[nPart].hIcon);
428 }
429
430
431 static INT
432 STATUSBAR_GetParts (const STATUS_INFO *infoPtr, INT num_parts, INT parts[])
433 {
434     INT   i;
435
436     TRACE("(%d)\n", num_parts);
437     if (parts) {
438         for (i = 0; i < num_parts; i++) {
439             parts[i] = infoPtr->parts[i].x;
440         }
441     }
442     return infoPtr->numParts;
443 }
444
445
446 static BOOL
447 STATUSBAR_GetRect (const STATUS_INFO *infoPtr, INT nPart, LPRECT rect)
448 {
449     TRACE("part %d\n", nPart);
450     if(nPart >= infoPtr->numParts || nPart < 0)
451       return FALSE;
452     if (infoPtr->simple)
453         *rect = infoPtr->part0.bound;
454     else
455         *rect = infoPtr->parts[nPart].bound;
456     return TRUE;
457 }
458
459
460 static LRESULT
461 STATUSBAR_GetTextA (STATUS_INFO *infoPtr, INT nPart, LPSTR buf)
462 {
463     STATUSWINDOWPART *part;
464     LRESULT result;
465
466     TRACE("part %d\n", nPart);
467
468     /* MSDN says: "simple parts use index of 0", so this check is ok. */
469     if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
470
471     if (infoPtr->simple)
472         part = &infoPtr->part0;
473     else
474         part = &infoPtr->parts[nPart];
475
476     if (part->style & SBT_OWNERDRAW)
477         result = (LRESULT)part->text;
478     else {
479         DWORD len = part->text ? WideCharToMultiByte( CP_ACP, 0, part->text, -1,
480                                                       NULL, 0, NULL, NULL ) - 1 : 0;
481         result = MAKELONG( len, part->style );
482         if (part->text && buf)
483             WideCharToMultiByte( CP_ACP, 0, part->text, -1, buf, len+1, NULL, NULL );
484     }
485     return result;
486 }
487
488
489 static LRESULT
490 STATUSBAR_GetTextW (STATUS_INFO *infoPtr, INT nPart, LPWSTR buf)
491 {
492     STATUSWINDOWPART *part;
493     LRESULT result;
494
495     TRACE("part %d\n", nPart);
496     if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
497
498     if (infoPtr->simple)
499         part = &infoPtr->part0;
500     else
501         part = &infoPtr->parts[nPart];
502
503     if (part->style & SBT_OWNERDRAW)
504         result = (LRESULT)part->text;
505     else {
506         result = part->text ? strlenW (part->text) : 0;
507         result |= (part->style << 16);
508         if (part->text && buf)
509             strcpyW (buf, part->text);
510     }
511     return result;
512 }
513
514
515 static LRESULT
516 STATUSBAR_GetTextLength (STATUS_INFO *infoPtr, INT nPart)
517 {
518     STATUSWINDOWPART *part;
519     DWORD result;
520
521     TRACE("part %d\n", nPart);
522
523     /* MSDN says: "simple parts use index of 0", so this check is ok. */
524     if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
525
526     if (infoPtr->simple)
527         part = &infoPtr->part0;
528     else
529         part = &infoPtr->parts[nPart];
530
531     if ((~part->style & SBT_OWNERDRAW) && part->text)
532         result = strlenW(part->text);
533     else
534         result = 0;
535
536     result |= (part->style << 16);
537     return result;
538 }
539
540 static LRESULT
541 STATUSBAR_GetTipTextA (const STATUS_INFO *infoPtr, INT id, LPSTR tip, INT size)
542 {
543     TRACE("\n");
544     if (tip) {
545         CHAR buf[INFOTIPSIZE];
546         buf[0]='\0';
547
548         if (infoPtr->hwndToolTip) {
549             TTTOOLINFOA ti;
550             ti.cbSize = sizeof(TTTOOLINFOA);
551             ti.hwnd = infoPtr->Self;
552             ti.uId = id;
553             ti.lpszText = buf;
554             SendMessageA (infoPtr->hwndToolTip, TTM_GETTEXTA, 0, (LPARAM)&ti);
555         }
556         lstrcpynA (tip, buf, size);
557     }
558     return 0;
559 }
560
561
562 static LRESULT
563 STATUSBAR_GetTipTextW (const STATUS_INFO *infoPtr, INT id, LPWSTR tip, INT size)
564 {
565     TRACE("\n");
566     if (tip) {
567         WCHAR buf[INFOTIPSIZE];
568         buf[0]=0;
569
570         if (infoPtr->hwndToolTip) {
571             TTTOOLINFOW ti;
572             ti.cbSize = sizeof(TTTOOLINFOW);
573             ti.hwnd = infoPtr->Self;
574             ti.uId = id;
575             ti.lpszText = buf;
576             SendMessageW(infoPtr->hwndToolTip, TTM_GETTEXTW, 0, (LPARAM)&ti);
577         }
578         lstrcpynW(tip, buf, size);
579     }
580
581     return 0;
582 }
583
584
585 static COLORREF
586 STATUSBAR_SetBkColor (STATUS_INFO *infoPtr, COLORREF color)
587 {
588     COLORREF oldBkColor;
589
590     oldBkColor = infoPtr->clrBk;
591     infoPtr->clrBk = color;
592     InvalidateRect(infoPtr->Self, NULL, FALSE);
593
594     TRACE("CREF: %08x -> %08x\n", oldBkColor, infoPtr->clrBk);
595     return oldBkColor;
596 }
597
598
599 static BOOL
600 STATUSBAR_SetIcon (STATUS_INFO *infoPtr, INT nPart, HICON hIcon)
601 {
602     if ((nPart < -1) || (nPart >= infoPtr->numParts))
603         return FALSE;
604
605     TRACE("setting part %d\n", nPart);
606
607     /* FIXME: MSDN says "if nPart is -1, the status bar is assumed simple" */
608     if (nPart == -1) {
609         if (infoPtr->part0.hIcon == hIcon) /* same as - no redraw */
610             return TRUE;
611         infoPtr->part0.hIcon = hIcon;
612         if (infoPtr->simple)
613             InvalidateRect(infoPtr->Self, &infoPtr->part0.bound, FALSE);
614     } else {
615         if (infoPtr->parts[nPart].hIcon == hIcon) /* same as - no redraw */
616             return TRUE;
617
618         infoPtr->parts[nPart].hIcon = hIcon;
619         if (!(infoPtr->simple))
620             InvalidateRect(infoPtr->Self, &infoPtr->parts[nPart].bound, FALSE);
621     }
622     return TRUE;
623 }
624
625
626 static BOOL
627 STATUSBAR_SetMinHeight (STATUS_INFO *infoPtr, INT height)
628 {
629
630     TRACE("(height=%d)\n", height);
631     if (IsWindowVisible (infoPtr->Self)) {
632         INT  width, x, y;
633         RECT parent_rect;
634         HTHEME theme;
635
636         infoPtr->height = height + infoPtr->verticalBorder;
637         
638         if ((theme = GetWindowTheme (infoPtr->Self)))
639         {
640             /* Determine bar height from theme such that the content area is
641              * 'height' pixels large */
642             HDC hdc = GetDC (infoPtr->Self);
643             RECT r;
644             memset (&r, 0, sizeof (r));
645             r.bottom = height;
646             if (SUCCEEDED(GetThemeBackgroundExtent (theme, hdc, SP_PANE, 0, &r, &r)))
647             {
648                 infoPtr->height = r.bottom - r.top;
649             }
650             ReleaseDC (infoPtr->Self, hdc);
651         }
652         
653         if (GetClientRect (infoPtr->Notify, &parent_rect))
654         {
655             width = parent_rect.right - parent_rect.left;
656             x = parent_rect.left;
657             y = parent_rect.bottom - infoPtr->height;
658             MoveWindow (infoPtr->Self, x, y, width, infoPtr->height, TRUE);
659             STATUSBAR_SetPartBounds (infoPtr);
660         }
661     }
662
663     return TRUE;
664 }
665
666
667 static BOOL
668 STATUSBAR_SetParts (STATUS_INFO *infoPtr, INT count, LPINT parts)
669 {
670     STATUSWINDOWPART *tmp;
671     int i, oldNumParts;
672
673     TRACE("(%d,%p)\n", count, parts);
674
675     oldNumParts = infoPtr->numParts;
676     infoPtr->numParts = count;
677     if (oldNumParts > infoPtr->numParts) {
678         for (i = infoPtr->numParts ; i < oldNumParts; i++) {
679             if (!(infoPtr->parts[i].style & SBT_OWNERDRAW))
680                 Free (infoPtr->parts[i].text);
681         }
682     } else if (oldNumParts < infoPtr->numParts) {
683         tmp = Alloc (sizeof(STATUSWINDOWPART) * infoPtr->numParts);
684         if (!tmp) return FALSE;
685         for (i = 0; i < oldNumParts; i++) {
686             tmp[i] = infoPtr->parts[i];
687         }
688         Free (infoPtr->parts);
689         infoPtr->parts = tmp;
690     }
691     if (oldNumParts == infoPtr->numParts) {
692         for (i=0; i < oldNumParts; i++)
693             if (infoPtr->parts[i].x != parts[i])
694                 break;
695         if (i==oldNumParts) /* Unchanged? no need to redraw! */
696             return TRUE;
697     }
698
699     for (i = 0; i < infoPtr->numParts; i++)
700         infoPtr->parts[i].x = parts[i];
701
702     if (infoPtr->hwndToolTip) {
703         INT nTipCount, i;
704         TTTOOLINFOW ti;
705
706         ZeroMemory (&ti, sizeof(TTTOOLINFOW));
707         ti.cbSize = sizeof(TTTOOLINFOW);
708         ti.hwnd = infoPtr->Self;
709
710         nTipCount = SendMessageW (infoPtr->hwndToolTip, TTM_GETTOOLCOUNT, 0, 0);
711         if (nTipCount < infoPtr->numParts) {
712             /* add tools */
713             for (i = nTipCount; i < infoPtr->numParts; i++) {
714                 TRACE("add tool %d\n", i);
715                 ti.uId = i;
716                 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
717                                 0, (LPARAM)&ti);
718             }
719         }
720         else if (nTipCount > infoPtr->numParts) {
721             /* delete tools */
722             for (i = nTipCount - 1; i >= infoPtr->numParts; i--) {
723                 TRACE("delete tool %d\n", i);
724                 ti.uId = i;
725                 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW,
726                                 0, (LPARAM)&ti);
727             }
728         }
729     }
730     STATUSBAR_SetPartBounds (infoPtr);
731     InvalidateRect(infoPtr->Self, NULL, FALSE);
732     return TRUE;
733 }
734
735
736 static BOOL
737 STATUSBAR_SetTextT (STATUS_INFO *infoPtr, INT nPart, WORD style,
738                     LPCWSTR text, BOOL isW)
739 {
740     STATUSWINDOWPART *part=NULL;
741     BOOL changed = FALSE;
742     INT  oldStyle;
743
744     if (style & SBT_OWNERDRAW) {
745          TRACE("part %d, text %p\n",nPart,text);
746     }
747     else TRACE("part %d, text %s\n", nPart, debugstr_t(text, isW));
748
749     /* MSDN says: "If the parameter is set to SB_SIMPLEID (255), the status
750      * window is assumed to be a simple window */
751
752     if (nPart == 0x00ff) {
753         part = &infoPtr->part0;
754     } else {
755         if (infoPtr->parts && nPart >= 0 && nPart < infoPtr->numParts) {
756             part = &infoPtr->parts[nPart];
757         }
758     }
759     if (!part) return FALSE;
760
761     if (part->style != style)
762         changed = TRUE;
763
764     oldStyle = part->style;
765     part->style = style;
766     if (style & SBT_OWNERDRAW) {
767         if (!(oldStyle & SBT_OWNERDRAW))
768             Free (part->text);
769         else if (part->text == text)
770             return TRUE;
771         part->text = (LPWSTR)text;
772     } else {
773         LPWSTR ntext;
774
775         if (text && !isW) {
776             LPCSTR atxt = (LPCSTR)text;
777             DWORD len = MultiByteToWideChar( CP_ACP, 0, atxt, -1, NULL, 0 );
778             ntext = Alloc( (len + 1)*sizeof(WCHAR) );
779             if (!ntext) return FALSE;
780             MultiByteToWideChar( CP_ACP, 0, atxt, -1, ntext, len );
781         } else if (text) {
782             ntext = Alloc( (strlenW(text) + 1)*sizeof(WCHAR) );
783             if (!ntext) return FALSE;
784             strcpyW (ntext, text);
785         } else ntext = 0;
786
787         /* check if text is unchanged -> no need to redraw */
788         if (text) {
789             if (!changed && part->text && !lstrcmpW(ntext, part->text)) {
790                 Free(ntext);
791                 return TRUE;
792             }
793         } else {
794             if (!changed && !part->text)
795                 return TRUE;
796         }
797
798         if (!(oldStyle & SBT_OWNERDRAW))
799             Free (part->text);
800         part->text = ntext;
801     }
802     InvalidateRect(infoPtr->Self, &part->bound, FALSE);
803     UpdateWindow(infoPtr->Self);
804
805     return TRUE;
806 }
807
808
809 static LRESULT
810 STATUSBAR_SetTipTextA (const STATUS_INFO *infoPtr, INT id, LPSTR text)
811 {
812     TRACE("part %d: \"%s\"\n", id, text);
813     if (infoPtr->hwndToolTip) {
814         TTTOOLINFOA ti;
815         ti.cbSize = sizeof(TTTOOLINFOA);
816         ti.hwnd = infoPtr->Self;
817         ti.uId = id;
818         ti.hinst = 0;
819         ti.lpszText = text;
820         SendMessageA (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTA, 0, (LPARAM)&ti);
821     }
822
823     return 0;
824 }
825
826
827 static LRESULT
828 STATUSBAR_SetTipTextW (const STATUS_INFO *infoPtr, INT id, LPWSTR text)
829 {
830     TRACE("part %d: \"%s\"\n", id, debugstr_w(text));
831     if (infoPtr->hwndToolTip) {
832         TTTOOLINFOW ti;
833         ti.cbSize = sizeof(TTTOOLINFOW);
834         ti.hwnd = infoPtr->Self;
835         ti.uId = id;
836         ti.hinst = 0;
837         ti.lpszText = text;
838         SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
839     }
840
841     return 0;
842 }
843
844
845 static inline LRESULT
846 STATUSBAR_SetUnicodeFormat (STATUS_INFO *infoPtr, BOOL bUnicode)
847 {
848     BOOL bOld = infoPtr->bUnicode;
849
850     TRACE("(0x%x)\n", bUnicode);
851     infoPtr->bUnicode = bUnicode;
852
853     return bOld;
854 }
855
856
857 static BOOL
858 STATUSBAR_Simple (STATUS_INFO *infoPtr, BOOL simple)
859 {
860     NMHDR  nmhdr;
861
862     TRACE("(simple=%d)\n", simple);
863     if (infoPtr->simple == simple) /* no need to change */
864         return TRUE;
865
866     infoPtr->simple = simple;
867
868     /* send notification */
869     nmhdr.hwndFrom = infoPtr->Self;
870     nmhdr.idFrom = GetWindowLongPtrW (infoPtr->Self, GWLP_ID);
871     nmhdr.code = SBN_SIMPLEMODECHANGE;
872     SendMessageW (infoPtr->Notify, WM_NOTIFY, 0, (LPARAM)&nmhdr);
873     InvalidateRect(infoPtr->Self, NULL, FALSE);
874     return TRUE;
875 }
876
877
878 static LRESULT
879 STATUSBAR_WMDestroy (STATUS_INFO *infoPtr)
880 {
881     int i;
882
883     TRACE("\n");
884     for (i = 0; i < infoPtr->numParts; i++) {
885         if (!(infoPtr->parts[i].style & SBT_OWNERDRAW))
886             Free (infoPtr->parts[i].text);
887     }
888     if (!(infoPtr->part0.style & SBT_OWNERDRAW))
889         Free (infoPtr->part0.text);
890     Free (infoPtr->parts);
891
892     /* delete default font */
893     if (infoPtr->hDefaultFont)
894         DeleteObject (infoPtr->hDefaultFont);
895
896     /* delete tool tip control */
897     if (infoPtr->hwndToolTip)
898         DestroyWindow (infoPtr->hwndToolTip);
899
900     CloseThemeData (GetWindowTheme (infoPtr->Self));
901
902     SetWindowLongPtrW(infoPtr->Self, 0, 0);
903     Free (infoPtr);
904     return 0;
905 }
906
907
908 static LRESULT
909 STATUSBAR_WMCreate (HWND hwnd, const CREATESTRUCTA *lpCreate)
910 {
911     STATUS_INFO *infoPtr;
912     NONCLIENTMETRICSW nclm;
913     DWORD dwStyle;
914     RECT rect;
915     int i, width, len, textHeight = 0;
916     HDC hdc;
917
918     TRACE("\n");
919     infoPtr = (STATUS_INFO*)Alloc (sizeof(STATUS_INFO));
920     if (!infoPtr) goto create_fail;
921     SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
922
923     infoPtr->Self = hwnd;
924     infoPtr->Notify = lpCreate->hwndParent;
925     infoPtr->numParts = 1;
926     infoPtr->parts = 0;
927     infoPtr->simple = FALSE;
928     infoPtr->clrBk = CLR_DEFAULT;
929     infoPtr->hFont = 0;
930     infoPtr->horizontalBorder = HORZ_BORDER;
931     infoPtr->verticalBorder = VERT_BORDER;
932     infoPtr->horizontalGap = HORZ_GAP;
933
934     i = SendMessageW(infoPtr->Notify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
935     infoPtr->NtfUnicode = (i == NFR_UNICODE);
936
937     GetClientRect (hwnd, &rect);
938     InvalidateRect (hwnd, &rect, 0);
939     UpdateWindow(hwnd);
940
941     ZeroMemory (&nclm, sizeof(nclm));
942     nclm.cbSize = sizeof(nclm);
943     SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, nclm.cbSize, &nclm, 0);
944     infoPtr->hDefaultFont = CreateFontIndirectW (&nclm.lfStatusFont);
945
946     /* initialize simple case */
947     infoPtr->part0.bound = rect;
948     infoPtr->part0.text = 0;
949     infoPtr->part0.x = 0;
950     infoPtr->part0.style = 0;
951     infoPtr->part0.hIcon = 0;
952
953     /* initialize first part */
954     infoPtr->parts = Alloc (sizeof(STATUSWINDOWPART));
955     if (!infoPtr->parts) goto create_fail;
956     infoPtr->parts[0].bound = rect;
957     infoPtr->parts[0].text = 0;
958     infoPtr->parts[0].x = -1;
959     infoPtr->parts[0].style = 0;
960     infoPtr->parts[0].hIcon = 0;
961     
962     OpenThemeData (hwnd, themeClass);
963
964     if (IsWindowUnicode (hwnd)) {
965         infoPtr->bUnicode = TRUE;
966         if (lpCreate->lpszName &&
967             (len = strlenW ((LPCWSTR)lpCreate->lpszName))) {
968             infoPtr->parts[0].text = Alloc ((len + 1)*sizeof(WCHAR));
969             if (!infoPtr->parts[0].text) goto create_fail;
970             strcpyW (infoPtr->parts[0].text, (LPCWSTR)lpCreate->lpszName);
971         }
972     }
973     else {
974         if (lpCreate->lpszName &&
975             (len = strlen((LPCSTR)lpCreate->lpszName))) {
976             DWORD lenW = MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1, NULL, 0 );
977             infoPtr->parts[0].text = Alloc (lenW*sizeof(WCHAR));
978             if (!infoPtr->parts[0].text) goto create_fail;
979             MultiByteToWideChar( CP_ACP, 0, (LPCSTR)lpCreate->lpszName, -1,
980                                  infoPtr->parts[0].text, lenW );
981         }
982     }
983
984     dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
985     /* native seems to clear WS_BORDER, too */
986     dwStyle &= ~WS_BORDER;
987
988     /* statusbars on managed windows should not have SIZEGRIP style */
989     if ((dwStyle & SBARS_SIZEGRIP) && lpCreate->hwndParent &&
990         GetPropA( lpCreate->hwndParent, "__wine_x11_managed" ))
991         dwStyle &= ~SBARS_SIZEGRIP;
992
993     SetWindowLongW (hwnd, GWL_STYLE, dwStyle);
994
995     if ((hdc = GetDC (hwnd))) {
996         TEXTMETRICW tm;
997         HFONT hOldFont;
998
999         hOldFont = SelectObject (hdc, infoPtr->hDefaultFont);
1000         GetTextMetricsW (hdc, &tm);
1001         textHeight = tm.tmHeight;
1002         SelectObject (hdc, hOldFont);
1003         ReleaseDC (hwnd, hdc);
1004     }
1005     TRACE("    textHeight=%d\n", textHeight);
1006
1007     if (dwStyle & SBT_TOOLTIPS) {
1008         infoPtr->hwndToolTip =
1009             CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, WS_POPUP | TTS_ALWAYSTIP,
1010                              CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
1011                              CW_USEDEFAULT, hwnd, 0,
1012                              (HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE), NULL);
1013
1014         if (infoPtr->hwndToolTip) {
1015             NMTOOLTIPSCREATED nmttc;
1016
1017             nmttc.hdr.hwndFrom = hwnd;
1018             nmttc.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
1019             nmttc.hdr.code = NM_TOOLTIPSCREATED;
1020             nmttc.hwndToolTips = infoPtr->hwndToolTip;
1021
1022             SendMessageW (lpCreate->hwndParent, WM_NOTIFY, nmttc.hdr.idFrom, (LPARAM)&nmttc);
1023         }
1024     }
1025
1026     if (!(dwStyle & CCS_NORESIZE)) { /* don't resize wnd if it doesn't want it ! */
1027         HTHEME theme;
1028         GetClientRect (infoPtr->Notify, &rect);
1029         width = rect.right - rect.left;
1030         infoPtr->height = textHeight + 4 + infoPtr->verticalBorder;
1031         
1032         if ((theme = GetWindowTheme (hwnd)))
1033         {
1034             /* Determine bar height from theme such that the content area is
1035              * textHeight pixels large */
1036             HDC hdc = GetDC (hwnd);
1037             RECT r;
1038             memset (&r, 0, sizeof (r));
1039             r.bottom = textHeight;
1040             if (SUCCEEDED(GetThemeBackgroundExtent (theme, hdc, SP_PANE, 0, &r, &r)))
1041             {
1042                 infoPtr->height = r.bottom - r.top;
1043             }
1044             ReleaseDC (hwnd, hdc);
1045         }
1046     
1047         SetWindowPos(hwnd, 0, lpCreate->x, lpCreate->y - 1,
1048                         width, infoPtr->height, SWP_NOZORDER);
1049         STATUSBAR_SetPartBounds (infoPtr);
1050     }
1051
1052     return 0;
1053
1054 create_fail:
1055     TRACE("    failed!\n");
1056     if (infoPtr) STATUSBAR_WMDestroy(infoPtr);
1057     return -1;
1058 }
1059
1060
1061 /* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
1062  * of the first part only (usual behaviour) */
1063 static INT
1064 STATUSBAR_WMGetText (const STATUS_INFO *infoPtr, INT size, LPWSTR buf)
1065 {
1066     INT len;
1067
1068     TRACE("\n");
1069     if (!(infoPtr->parts[0].text))
1070         return 0;
1071     if (infoPtr->bUnicode)
1072         len = strlenW (infoPtr->parts[0].text);
1073     else
1074         len = WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1, NULL, 0, NULL, NULL )-1;
1075
1076     if (size > len) {
1077         if (infoPtr->bUnicode)
1078             strcpyW (buf, infoPtr->parts[0].text);
1079         else
1080             WideCharToMultiByte( CP_ACP, 0, infoPtr->parts[0].text, -1,
1081                                  (LPSTR)buf, len+1, NULL, NULL );
1082         return len;
1083     }
1084
1085     return -1;
1086 }
1087
1088
1089 static BOOL
1090 STATUSBAR_WMNCHitTest (const STATUS_INFO *infoPtr, INT x, INT y)
1091 {
1092     if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP) {
1093         RECT  rect;
1094         POINT pt;
1095
1096         GetClientRect (infoPtr->Self, &rect);
1097
1098         pt.x = x;
1099         pt.y = y;
1100         ScreenToClient (infoPtr->Self, &pt);
1101
1102         rect.left = rect.right - 13;
1103         rect.top += 2;
1104
1105         if (PtInRect (&rect, pt))
1106             return HTBOTTOMRIGHT;
1107     }
1108
1109     return HTERROR;
1110 }
1111
1112
1113 static LRESULT
1114 STATUSBAR_WMPaint (STATUS_INFO *infoPtr, HDC hdc)
1115 {
1116     PAINTSTRUCT ps;
1117
1118     TRACE("\n");
1119     if (hdc) return STATUSBAR_Refresh (infoPtr, hdc);
1120     hdc = BeginPaint (infoPtr->Self, &ps);
1121     STATUSBAR_Refresh (infoPtr, hdc);
1122     EndPaint (infoPtr->Self, &ps);
1123
1124     return 0;
1125 }
1126
1127
1128 static LRESULT
1129 STATUSBAR_WMSetFont (STATUS_INFO *infoPtr, HFONT font, BOOL redraw)
1130 {
1131     infoPtr->hFont = font;
1132     TRACE("%p\n", infoPtr->hFont);
1133     if (redraw)
1134         InvalidateRect(infoPtr->Self, NULL, FALSE);
1135
1136     return 0;
1137 }
1138
1139
1140 static BOOL
1141 STATUSBAR_WMSetText (const STATUS_INFO *infoPtr, LPCSTR text)
1142 {
1143     STATUSWINDOWPART *part;
1144     int len;
1145
1146     TRACE("\n");
1147     if (infoPtr->numParts == 0)
1148         return FALSE;
1149
1150     part = &infoPtr->parts[0];
1151     /* duplicate string */
1152     Free (part->text);
1153     part->text = 0;
1154     if (infoPtr->bUnicode) {
1155         if (text && (len = strlenW((LPCWSTR)text))) {
1156             part->text = Alloc ((len+1)*sizeof(WCHAR));
1157             if (!part->text) return FALSE;
1158             strcpyW (part->text, (LPCWSTR)text);
1159         }
1160     }
1161     else {
1162         if (text && (len = lstrlenA(text))) {
1163             DWORD lenW = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
1164             part->text = Alloc (lenW*sizeof(WCHAR));
1165             if (!part->text) return FALSE;
1166             MultiByteToWideChar( CP_ACP, 0, text, -1, part->text, lenW );
1167         }
1168     }
1169
1170     InvalidateRect(infoPtr->Self, &part->bound, FALSE);
1171
1172     return TRUE;
1173 }
1174
1175
1176 static BOOL
1177 STATUSBAR_WMSize (STATUS_INFO *infoPtr, WORD flags)
1178 {
1179     INT  width, x, y;
1180     RECT parent_rect;
1181
1182     /* Need to resize width to match parent */
1183     TRACE("flags %04x\n", flags);
1184
1185     if (flags != SIZE_RESTORED && flags != SIZE_MAXIMIZED) {
1186         WARN("flags MUST be SIZE_RESTORED or SIZE_MAXIMIZED\n");
1187         return FALSE;
1188     }
1189
1190     if (GetWindowLongW(infoPtr->Self, GWL_STYLE) & CCS_NORESIZE) return FALSE;
1191
1192     /* width and height don't apply */
1193     if (!GetClientRect (infoPtr->Notify, &parent_rect))
1194         return FALSE;
1195
1196     width = parent_rect.right - parent_rect.left;
1197     x = parent_rect.left;
1198     y = parent_rect.bottom - infoPtr->height;
1199     MoveWindow (infoPtr->Self, x, y, width, infoPtr->height, TRUE);
1200     STATUSBAR_SetPartBounds (infoPtr);
1201     return TRUE;
1202 }
1203
1204
1205 /* update theme after a WM_THEMECHANGED message */
1206 static LRESULT theme_changed (const STATUS_INFO* infoPtr)
1207 {
1208     HTHEME theme = GetWindowTheme (infoPtr->Self);
1209     CloseThemeData (theme);
1210     OpenThemeData (infoPtr->Self, themeClass);
1211     return 0;
1212 }
1213
1214
1215 static LRESULT
1216 STATUSBAR_NotifyFormat (STATUS_INFO *infoPtr, HWND from, INT cmd)
1217 {
1218     if (cmd == NF_REQUERY) {
1219         INT i = SendMessageW(from, WM_NOTIFYFORMAT, (WPARAM)infoPtr->Self, NF_QUERY);
1220         infoPtr->NtfUnicode = (i == NFR_UNICODE);
1221     }
1222     return infoPtr->NtfUnicode ? NFR_UNICODE : NFR_ANSI;
1223 }
1224
1225
1226 static LRESULT
1227 STATUSBAR_SendMouseNotify(const STATUS_INFO *infoPtr, UINT code, LPARAM lParam)
1228 {
1229     NMMOUSE  nm;
1230
1231     TRACE("code %04x, lParam=%lx\n", code, lParam);
1232     nm.hdr.hwndFrom = infoPtr->Self;
1233     nm.hdr.idFrom = GetWindowLongPtrW(infoPtr->Self, GWLP_ID);
1234     nm.hdr.code = code;
1235     nm.pt.x = (short)LOWORD(lParam);
1236     nm.pt.y = (short)HIWORD(lParam);
1237     nm.dwItemSpec = STATUSBAR_InternalHitTest(infoPtr, &nm.pt);
1238     nm.dwItemData = 0;
1239     nm.dwHitInfo = 0x30000;     /* seems constant */
1240     SendMessageW(infoPtr->Notify, WM_NOTIFY, 0, (LPARAM)&nm);
1241     return 0;
1242 }
1243
1244
1245
1246 static LRESULT WINAPI
1247 StatusWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1248 {
1249     STATUS_INFO *infoPtr = (STATUS_INFO *)GetWindowLongPtrW (hwnd, 0);
1250     INT nPart = ((INT) wParam) & 0x00ff;
1251     LRESULT res;
1252
1253     TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd, msg, wParam, lParam);
1254     if (!infoPtr && msg != WM_CREATE)
1255         return DefWindowProcW (hwnd, msg, wParam, lParam);
1256
1257     switch (msg) {
1258         case SB_GETBORDERS:
1259             return STATUSBAR_GetBorders (infoPtr, (INT *)lParam);
1260
1261         case SB_GETICON:
1262             return (LRESULT)STATUSBAR_GetIcon (infoPtr, nPart);
1263
1264         case SB_GETPARTS:
1265             return STATUSBAR_GetParts (infoPtr, (INT)wParam, (INT *)lParam);
1266
1267         case SB_GETRECT:
1268             return STATUSBAR_GetRect (infoPtr, nPart, (LPRECT)lParam);
1269
1270         case SB_GETTEXTA:
1271             return STATUSBAR_GetTextA (infoPtr, nPart, (LPSTR)lParam);
1272
1273         case SB_GETTEXTW:
1274             return STATUSBAR_GetTextW (infoPtr, nPart, (LPWSTR)lParam);
1275
1276         case SB_GETTEXTLENGTHA:
1277         case SB_GETTEXTLENGTHW:
1278             return STATUSBAR_GetTextLength (infoPtr, nPart);
1279
1280         case SB_GETTIPTEXTA:
1281             return STATUSBAR_GetTipTextA (infoPtr,  LOWORD(wParam), (LPSTR)lParam,  HIWORD(wParam));
1282
1283         case SB_GETTIPTEXTW:
1284             return STATUSBAR_GetTipTextW (infoPtr,  LOWORD(wParam), (LPWSTR)lParam,  HIWORD(wParam));
1285
1286         case SB_GETUNICODEFORMAT:
1287             return infoPtr->bUnicode;
1288
1289         case SB_ISSIMPLE:
1290             return infoPtr->simple;
1291
1292         case SB_SETBORDERS:
1293             return STATUSBAR_SetBorders (infoPtr, (INT *)lParam);
1294
1295         case SB_SETBKCOLOR:
1296             return STATUSBAR_SetBkColor (infoPtr, (COLORREF)lParam);
1297
1298         case SB_SETICON:
1299             return STATUSBAR_SetIcon (infoPtr, nPart, (HICON)lParam);
1300
1301         case SB_SETMINHEIGHT:
1302             return STATUSBAR_SetMinHeight (infoPtr, (INT)wParam);
1303
1304         case SB_SETPARTS:
1305             return STATUSBAR_SetParts (infoPtr, (INT)wParam, (LPINT)lParam);
1306
1307         case SB_SETTEXTA:
1308             return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, FALSE);
1309
1310         case SB_SETTEXTW:
1311             return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, TRUE);
1312
1313         case SB_SETTIPTEXTA:
1314             return STATUSBAR_SetTipTextA (infoPtr, (INT)wParam, (LPSTR)lParam);
1315
1316         case SB_SETTIPTEXTW:
1317             return STATUSBAR_SetTipTextW (infoPtr, (INT)wParam, (LPWSTR)lParam);
1318
1319         case SB_SETUNICODEFORMAT:
1320             return STATUSBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1321
1322         case SB_SIMPLE:
1323             return STATUSBAR_Simple (infoPtr, (BOOL)wParam);
1324
1325         case WM_CREATE:
1326             return STATUSBAR_WMCreate (hwnd, (LPCREATESTRUCTA)lParam);
1327
1328         case WM_DESTROY:
1329             return STATUSBAR_WMDestroy (infoPtr);
1330
1331         case WM_GETFONT:
1332             return (LRESULT)(infoPtr->hFont? infoPtr->hFont : infoPtr->hDefaultFont);
1333
1334         case WM_GETTEXT:
1335             return STATUSBAR_WMGetText (infoPtr, (INT)wParam, (LPWSTR)lParam);
1336
1337         case WM_GETTEXTLENGTH:
1338             return STATUSBAR_GetTextLength (infoPtr, 0);
1339
1340         case WM_LBUTTONDBLCLK:
1341             return STATUSBAR_SendMouseNotify(infoPtr, NM_DBLCLK, lParam);
1342
1343         case WM_LBUTTONUP:
1344             return STATUSBAR_SendMouseNotify(infoPtr, NM_CLICK, lParam);
1345
1346         case WM_MOUSEMOVE:
1347             return STATUSBAR_Relay2Tip (infoPtr, msg, wParam, lParam);
1348
1349         case WM_NCHITTEST:
1350             res = STATUSBAR_WMNCHitTest(infoPtr, (short)LOWORD(lParam),
1351                                         (short)HIWORD(lParam));
1352             if (res != HTERROR) return res;
1353             return DefWindowProcW (hwnd, msg, wParam, lParam);
1354
1355         case WM_NCLBUTTONUP:
1356         case WM_NCLBUTTONDOWN:
1357             PostMessageW (infoPtr->Notify, msg, wParam, lParam);
1358             return 0;
1359
1360         case WM_NOTIFYFORMAT:
1361             return STATUSBAR_NotifyFormat(infoPtr, (HWND)wParam, (INT)lParam);
1362
1363         case WM_PRINTCLIENT:
1364         case WM_PAINT:
1365             return STATUSBAR_WMPaint (infoPtr, (HDC)wParam);
1366
1367         case WM_RBUTTONDBLCLK:
1368             return STATUSBAR_SendMouseNotify(infoPtr, NM_RDBLCLK, lParam);
1369
1370         case WM_RBUTTONUP:
1371             return STATUSBAR_SendMouseNotify(infoPtr, NM_RCLICK, lParam);
1372
1373         case WM_SETFONT:
1374             return STATUSBAR_WMSetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
1375
1376         case WM_SETTEXT:
1377             return STATUSBAR_WMSetText (infoPtr, (LPCSTR)lParam);
1378
1379         case WM_SIZE:
1380             if (STATUSBAR_WMSize (infoPtr, (WORD)wParam)) return 0;
1381             return DefWindowProcW (hwnd, msg, wParam, lParam);
1382
1383         case WM_THEMECHANGED:
1384             return theme_changed (infoPtr);
1385
1386         default:
1387             if ((msg >= WM_USER) && (msg < WM_APP))
1388                 ERR("unknown msg %04x wp=%04lx lp=%08lx\n",
1389                      msg, wParam, lParam);
1390             return DefWindowProcW (hwnd, msg, wParam, lParam);
1391     }
1392 }
1393
1394
1395 /***********************************************************************
1396  * STATUS_Register [Internal]
1397  *
1398  * Registers the status window class.
1399  */
1400
1401 void
1402 STATUS_Register (void)
1403 {
1404     WNDCLASSW wndClass;
1405
1406     ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1407     wndClass.style         = CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW;
1408     wndClass.lpfnWndProc   = StatusWindowProc;
1409     wndClass.cbClsExtra    = 0;
1410     wndClass.cbWndExtra    = sizeof(STATUS_INFO *);
1411     wndClass.hCursor       = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1412     wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
1413     wndClass.lpszClassName = STATUSCLASSNAMEW;
1414
1415     RegisterClassW (&wndClass);
1416 }
1417
1418
1419 /***********************************************************************
1420  * STATUS_Unregister [Internal]
1421  *
1422  * Unregisters the status window class.
1423  */
1424
1425 void
1426 STATUS_Unregister (void)
1427 {
1428     UnregisterClassW (STATUSCLASSNAMEW, NULL);
1429 }