maintainers: Move WineHQ URLs to https.
[wine.git] / dlls / comctl32 / status.c
blob08ca158055cd039d50a70ee2bd9f1664e6d919b0
1 /*
2 * Interface code to StatusWindow widget/control
4 * Copyright 1996 Bruce Milner
5 * Copyright 1998, 1999 Eric Kohl
6 * Copyright 2002 Dimitrie O. Paun
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.
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.
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
22 * NOTE
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.
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.
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)
43 #include <stdarg.h>
44 #include <string.h>
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 "vssym32.h"
56 #include "wine/debug.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(statusbar);
60 typedef struct
62 INT x;
63 INT style;
64 RECT bound;
65 LPWSTR text;
66 HICON hIcon;
67 } STATUSWINDOWPART;
69 typedef struct
71 HWND Self;
72 HWND Notify;
73 WORD numParts;
74 UINT height;
75 UINT minHeight; /* at least MIN_PANE_HEIGHT, can be increased by SB_SETMINHEIGHT */
76 BOOL simple;
77 HWND hwndToolTip;
78 HFONT hFont;
79 HFONT hDefaultFont;
80 COLORREF clrBk; /* background color */
81 BOOL bUnicode; /* notify format. TRUE if notifies in Unicode */
82 STATUSWINDOWPART part0; /* simple window */
83 STATUSWINDOWPART* parts;
84 INT horizontalBorder;
85 INT verticalBorder;
86 INT horizontalGap;
87 } STATUS_INFO;
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
95 #define HORZ_BORDER 0
96 #define VERT_BORDER 2
97 #define HORZ_GAP 2
99 static const WCHAR themeClass[] = { 'S','t','a','t','u','s',0 };
101 /* prototype */
102 static void
103 STATUSBAR_SetPartBounds (STATUS_INFO *infoPtr);
104 static LRESULT
105 STATUSBAR_NotifyFormat (STATUS_INFO *infoPtr, HWND from, INT cmd);
107 static inline LPCSTR debugstr_t(LPCWSTR text, BOOL isW)
109 return isW ? debugstr_w(text) : debugstr_a((LPCSTR)text);
112 static UINT
113 STATUSBAR_ComputeHeight(STATUS_INFO *infoPtr)
115 HTHEME theme;
116 UINT height;
117 TEXTMETRICW tm;
118 int margin;
120 COMCTL32_GetFontMetrics(infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont, &tm);
121 margin = (tm.tmInternalLeading ? tm.tmInternalLeading : 2);
122 height = max(tm.tmHeight + margin + 2*GetSystemMetrics(SM_CYBORDER), infoPtr->minHeight) + infoPtr->verticalBorder;
124 if ((theme = GetWindowTheme(infoPtr->Self)))
126 /* Determine bar height from theme such that the content area is
127 * textHeight pixels large */
128 HDC hdc = GetDC(infoPtr->Self);
129 RECT r;
131 SetRect(&r, 0, 0, 0, max(infoPtr->minHeight, tm.tmHeight));
132 if (SUCCEEDED(GetThemeBackgroundExtent(theme, hdc, SP_PANE, 0, &r, &r)))
134 height = r.bottom - r.top;
136 ReleaseDC(infoPtr->Self, hdc);
139 TRACE(" textHeight=%d+%d, final height=%d\n", tm.tmHeight, tm.tmInternalLeading, height);
140 return height;
143 static void
144 STATUSBAR_DrawSizeGrip (HTHEME theme, HDC hdc, LPRECT lpRect)
146 RECT rc = *lpRect;
148 TRACE("draw size grip %s\n", wine_dbgstr_rect(lpRect));
150 if (theme)
152 SIZE gripperSize;
153 if (SUCCEEDED (GetThemePartSize (theme, hdc, SP_GRIPPER, 0, lpRect,
154 TS_DRAW, &gripperSize)))
156 rc.left = rc.right - gripperSize.cx;
157 rc.top = rc.bottom - gripperSize.cy;
158 if (SUCCEEDED (DrawThemeBackground(theme, hdc, SP_GRIPPER, 0, &rc, NULL)))
159 return;
163 rc.left = max( rc.left, rc.right - GetSystemMetrics(SM_CXVSCROLL) - 1 );
164 rc.top = max( rc.top, rc.bottom - GetSystemMetrics(SM_CYHSCROLL) - 1 );
165 DrawFrameControl( hdc, &rc, DFC_SCROLL, DFCS_SCROLLSIZEGRIP );
169 static void
170 STATUSBAR_DrawPart (const STATUS_INFO *infoPtr, HDC hdc, const STATUSWINDOWPART *part, int itemID)
172 RECT r = part->bound;
173 UINT border = BDR_SUNKENOUTER;
174 HTHEME theme = GetWindowTheme (infoPtr->Self);
175 int themePart = SP_PANE;
176 int x = 0;
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;
184 if (theme)
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);
191 else
192 DrawEdge(hdc, &r, border, BF_RECT|BF_ADJUST);
194 if (part->hIcon) {
195 INT cy = r.bottom - r.top;
196 DrawIconEx (hdc, r.left + 2, r.top, part->hIcon, cy, cy, 0, 0, DI_NORMAL);
197 x = 2 + cy;
200 if (part->style & SBT_OWNERDRAW) {
201 DRAWITEMSTRUCT dis;
203 dis.CtlID = GetWindowLongPtrW (infoPtr->Self, GWLP_ID);
204 dis.itemID = itemID;
205 dis.hwndItem = infoPtr->Self;
206 dis.hDC = hdc;
207 dis.rcItem = r;
208 dis.itemData = (ULONG_PTR)part->text;
209 SendMessageW (infoPtr->Notify, WM_DRAWITEM, dis.CtlID, (LPARAM)&dis);
210 } else {
211 r.left += x;
212 DrawStatusTextW (hdc, &r, part->text, SBT_NOBORDERS);
217 static void
218 STATUSBAR_RefreshPart (const STATUS_INFO *infoPtr, HDC hdc, const STATUSWINDOWPART *part, int itemID)
220 HBRUSH hbrBk;
221 HTHEME theme;
223 TRACE("item %d\n", itemID);
225 if (part->bound.right < part->bound.left) return;
227 if (!RectVisible(hdc, &part->bound))
228 return;
230 if ((theme = GetWindowTheme (infoPtr->Self)))
232 RECT cr;
233 GetClientRect (infoPtr->Self, &cr);
234 DrawThemeBackground(theme, hdc, 0, 0, &cr, &part->bound);
236 else
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);
247 STATUSBAR_DrawPart (infoPtr, hdc, part, itemID);
251 static LRESULT
252 STATUSBAR_Refresh (STATUS_INFO *infoPtr, HDC hdc)
254 RECT rect;
255 HBRUSH hbrBk;
256 HFONT hOldFont;
257 HTHEME theme;
259 TRACE("\n");
260 if (!IsWindowVisible(infoPtr->Self))
261 return 0;
263 STATUSBAR_SetPartBounds(infoPtr);
265 GetClientRect (infoPtr->Self, &rect);
267 if ((theme = GetWindowTheme (infoPtr->Self)))
269 DrawThemeBackground(theme, hdc, 0, 0, &rect, NULL);
271 else
273 if (infoPtr->clrBk != CLR_DEFAULT)
274 hbrBk = CreateSolidBrush (infoPtr->clrBk);
275 else
276 hbrBk = GetSysColorBrush (COLOR_3DFACE);
277 FillRect(hdc, &rect, hbrBk);
278 if (infoPtr->clrBk != CLR_DEFAULT)
279 DeleteObject (hbrBk);
282 hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
284 if (infoPtr->simple) {
285 STATUSBAR_RefreshPart (infoPtr, hdc, &infoPtr->part0, 0);
286 } else {
287 unsigned int i;
289 for (i = 0; i < infoPtr->numParts; i++) {
290 STATUSBAR_RefreshPart (infoPtr, hdc, &infoPtr->parts[i], i);
294 SelectObject (hdc, hOldFont);
296 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
297 STATUSBAR_DrawSizeGrip (theme, hdc, &rect);
299 return 0;
303 static int
304 STATUSBAR_InternalHitTest(const STATUS_INFO *infoPtr, const POINT *pt)
306 unsigned int i;
308 if (infoPtr->simple)
309 return 255;
311 for (i = 0; i < infoPtr->numParts; i++)
312 if (pt->x >= infoPtr->parts[i].bound.left && pt->x <= infoPtr->parts[i].bound.right)
313 return i;
314 return -2;
318 static void
319 STATUSBAR_SetPartBounds (STATUS_INFO *infoPtr)
321 STATUSWINDOWPART *part;
322 RECT rect, *r;
323 UINT i;
325 /* get our window size */
326 GetClientRect (infoPtr->Self, &rect);
327 TRACE("client wnd size is %s\n", wine_dbgstr_rect(&rect));
329 rect.left += infoPtr->horizontalBorder;
330 rect.top += infoPtr->verticalBorder;
332 /* set bounds for simple rectangle */
333 infoPtr->part0.bound = rect;
335 /* set bounds for non-simple rectangles */
336 for (i = 0; i < infoPtr->numParts; i++) {
337 part = &infoPtr->parts[i];
338 r = &infoPtr->parts[i].bound;
339 r->top = rect.top;
340 r->bottom = rect.bottom;
341 if (i == 0)
342 r->left = 0;
343 else
344 r->left = infoPtr->parts[i-1].bound.right + infoPtr->horizontalGap;
345 if (part->x == -1)
346 r->right = rect.right;
347 else
348 r->right = part->x;
350 if (infoPtr->hwndToolTip) {
351 TTTOOLINFOW ti;
353 ti.cbSize = sizeof(TTTOOLINFOW);
354 ti.hwnd = infoPtr->Self;
355 ti.uId = i;
356 ti.rect = *r;
357 SendMessageW (infoPtr->hwndToolTip, TTM_NEWTOOLRECTW,
358 0, (LPARAM)&ti);
364 static LRESULT
365 STATUSBAR_Relay2Tip (const STATUS_INFO *infoPtr, UINT uMsg,
366 WPARAM wParam, LPARAM lParam)
368 MSG msg;
370 msg.hwnd = infoPtr->Self;
371 msg.message = uMsg;
372 msg.wParam = wParam;
373 msg.lParam = lParam;
374 msg.time = GetMessageTime ();
375 msg.pt.x = (short)LOWORD(GetMessagePos ());
376 msg.pt.y = (short)HIWORD(GetMessagePos ());
378 return SendMessageW (infoPtr->hwndToolTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
382 static BOOL
383 STATUSBAR_GetBorders (const STATUS_INFO *infoPtr, INT out[])
385 TRACE("\n");
386 out[0] = infoPtr->horizontalBorder;
387 out[1] = infoPtr->verticalBorder;
388 out[2] = infoPtr->horizontalGap;
390 return TRUE;
394 static BOOL
395 STATUSBAR_SetBorders (STATUS_INFO *infoPtr, const INT in[])
397 TRACE("\n");
398 infoPtr->horizontalBorder = in[0];
399 infoPtr->verticalBorder = in[1];
400 infoPtr->horizontalGap = in[2];
401 InvalidateRect(infoPtr->Self, NULL, FALSE);
403 return TRUE;
407 static HICON
408 STATUSBAR_GetIcon (const STATUS_INFO *infoPtr, INT nPart)
410 TRACE("%d\n", nPart);
411 /* MSDN says: "simple parts are indexed with -1" */
412 if ((nPart < -1) || (nPart >= infoPtr->numParts))
413 return 0;
415 if (nPart == -1)
416 return (infoPtr->part0.hIcon);
417 else
418 return (infoPtr->parts[nPart].hIcon);
422 static INT
423 STATUSBAR_GetParts (const STATUS_INFO *infoPtr, INT num_parts, INT parts[])
425 INT i;
427 TRACE("(%d)\n", num_parts);
428 if (parts) {
429 for (i = 0; i < num_parts; i++) {
430 parts[i] = infoPtr->parts[i].x;
433 return infoPtr->numParts;
437 static BOOL
438 STATUSBAR_GetRect (const STATUS_INFO *infoPtr, INT nPart, LPRECT rect)
440 TRACE("part %d\n", nPart);
441 if(nPart >= infoPtr->numParts || nPart < 0)
442 return FALSE;
443 if (infoPtr->simple)
444 *rect = infoPtr->part0.bound;
445 else
446 *rect = infoPtr->parts[nPart].bound;
447 return TRUE;
451 static LRESULT
452 STATUSBAR_GetTextA (STATUS_INFO *infoPtr, INT nPart, LPSTR buf)
454 STATUSWINDOWPART *part;
455 LRESULT result;
457 TRACE("part %d\n", nPart);
459 /* MSDN says: "simple parts use index of 0", so this check is ok. */
460 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
462 if (infoPtr->simple)
463 part = &infoPtr->part0;
464 else
465 part = &infoPtr->parts[nPart];
467 if (part->style & SBT_OWNERDRAW)
468 result = (LRESULT)part->text;
469 else {
470 DWORD len = part->text ? WideCharToMultiByte( CP_ACP, 0, part->text, -1,
471 NULL, 0, NULL, NULL ) - 1 : 0;
472 result = MAKELONG( len, part->style );
473 if (part->text && buf)
474 WideCharToMultiByte( CP_ACP, 0, part->text, -1, buf, len+1, NULL, NULL );
476 return result;
480 static LRESULT
481 STATUSBAR_GetTextW (STATUS_INFO *infoPtr, INT nPart, LPWSTR buf)
483 STATUSWINDOWPART *part;
484 LRESULT result;
486 TRACE("part %d\n", nPart);
487 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
489 if (infoPtr->simple)
490 part = &infoPtr->part0;
491 else
492 part = &infoPtr->parts[nPart];
494 if (part->style & SBT_OWNERDRAW)
495 result = (LRESULT)part->text;
496 else {
497 result = part->text ? strlenW (part->text) : 0;
498 result |= (part->style << 16);
499 if (part->text && buf)
500 strcpyW (buf, part->text);
502 return result;
506 static LRESULT
507 STATUSBAR_GetTextLength (STATUS_INFO *infoPtr, INT nPart)
509 STATUSWINDOWPART *part;
510 DWORD result;
512 TRACE("part %d\n", nPart);
514 /* MSDN says: "simple parts use index of 0", so this check is ok. */
515 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
517 if (infoPtr->simple)
518 part = &infoPtr->part0;
519 else
520 part = &infoPtr->parts[nPart];
522 if ((~part->style & SBT_OWNERDRAW) && part->text)
523 result = strlenW(part->text);
524 else
525 result = 0;
527 result |= (part->style << 16);
528 return result;
531 static LRESULT
532 STATUSBAR_GetTipTextA (const STATUS_INFO *infoPtr, INT id, LPSTR tip, INT size)
534 TRACE("\n");
535 if (tip) {
536 CHAR buf[INFOTIPSIZE];
537 buf[0]='\0';
539 if (infoPtr->hwndToolTip) {
540 TTTOOLINFOA ti;
541 ti.cbSize = sizeof(TTTOOLINFOA);
542 ti.hwnd = infoPtr->Self;
543 ti.uId = id;
544 ti.lpszText = buf;
545 SendMessageA (infoPtr->hwndToolTip, TTM_GETTEXTA, 0, (LPARAM)&ti);
547 lstrcpynA (tip, buf, size);
549 return 0;
553 static LRESULT
554 STATUSBAR_GetTipTextW (const STATUS_INFO *infoPtr, INT id, LPWSTR tip, INT size)
556 TRACE("\n");
557 if (tip) {
558 WCHAR buf[INFOTIPSIZE];
559 buf[0]=0;
561 if (infoPtr->hwndToolTip) {
562 TTTOOLINFOW ti;
563 ti.cbSize = sizeof(TTTOOLINFOW);
564 ti.hwnd = infoPtr->Self;
565 ti.uId = id;
566 ti.lpszText = buf;
567 SendMessageW(infoPtr->hwndToolTip, TTM_GETTEXTW, 0, (LPARAM)&ti);
569 lstrcpynW(tip, buf, size);
572 return 0;
576 static COLORREF
577 STATUSBAR_SetBkColor (STATUS_INFO *infoPtr, COLORREF color)
579 COLORREF oldBkColor;
581 oldBkColor = infoPtr->clrBk;
582 infoPtr->clrBk = color;
583 InvalidateRect(infoPtr->Self, NULL, FALSE);
585 TRACE("CREF: %08x -> %08x\n", oldBkColor, infoPtr->clrBk);
586 return oldBkColor;
590 static BOOL
591 STATUSBAR_SetIcon (STATUS_INFO *infoPtr, INT nPart, HICON hIcon)
593 if ((nPart < -1) || (nPart >= infoPtr->numParts))
594 return FALSE;
596 TRACE("setting part %d\n", nPart);
598 /* FIXME: MSDN says "if nPart is -1, the status bar is assumed simple" */
599 if (nPart == -1) {
600 if (infoPtr->part0.hIcon == hIcon) /* same as - no redraw */
601 return TRUE;
602 infoPtr->part0.hIcon = hIcon;
603 if (infoPtr->simple)
604 InvalidateRect(infoPtr->Self, &infoPtr->part0.bound, FALSE);
605 } else {
606 if (infoPtr->parts[nPart].hIcon == hIcon) /* same as - no redraw */
607 return TRUE;
609 infoPtr->parts[nPart].hIcon = hIcon;
610 if (!(infoPtr->simple))
611 InvalidateRect(infoPtr->Self, &infoPtr->parts[nPart].bound, FALSE);
613 return TRUE;
617 static BOOL
618 STATUSBAR_SetMinHeight (STATUS_INFO *infoPtr, INT height)
620 DWORD ysize = GetSystemMetrics(SM_CYSIZE);
621 if (ysize & 1) ysize--;
622 infoPtr->minHeight = max(height, ysize);
623 infoPtr->height = STATUSBAR_ComputeHeight(infoPtr);
624 /* like native, don't resize the control */
625 return TRUE;
629 static BOOL
630 STATUSBAR_SetParts (STATUS_INFO *infoPtr, INT count, LPINT parts)
632 STATUSWINDOWPART *tmp;
633 INT i, oldNumParts;
635 TRACE("(%d,%p)\n", count, parts);
637 if(!count) return FALSE;
639 oldNumParts = infoPtr->numParts;
640 infoPtr->numParts = count;
641 if (oldNumParts > infoPtr->numParts) {
642 for (i = infoPtr->numParts ; i < oldNumParts; i++) {
643 if (!(infoPtr->parts[i].style & SBT_OWNERDRAW))
644 Free (infoPtr->parts[i].text);
646 } else if (oldNumParts < infoPtr->numParts) {
647 tmp = Alloc (sizeof(STATUSWINDOWPART) * infoPtr->numParts);
648 if (!tmp) return FALSE;
649 for (i = 0; i < oldNumParts; i++) {
650 tmp[i] = infoPtr->parts[i];
652 Free (infoPtr->parts);
653 infoPtr->parts = tmp;
655 if (oldNumParts == infoPtr->numParts) {
656 for (i=0; i < oldNumParts; i++)
657 if (infoPtr->parts[i].x != parts[i])
658 break;
659 if (i==oldNumParts) /* Unchanged? no need to redraw! */
660 return TRUE;
663 for (i = 0; i < infoPtr->numParts; i++)
664 infoPtr->parts[i].x = parts[i];
666 if (infoPtr->hwndToolTip) {
667 INT nTipCount;
668 TTTOOLINFOW ti;
669 WCHAR wEmpty = 0;
671 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
672 ti.cbSize = sizeof(TTTOOLINFOW);
673 ti.hwnd = infoPtr->Self;
674 ti.lpszText = &wEmpty;
676 nTipCount = SendMessageW (infoPtr->hwndToolTip, TTM_GETTOOLCOUNT, 0, 0);
677 if (nTipCount < infoPtr->numParts) {
678 /* add tools */
679 for (i = nTipCount; i < infoPtr->numParts; i++) {
680 TRACE("add tool %d\n", i);
681 ti.uId = i;
682 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
683 0, (LPARAM)&ti);
686 else if (nTipCount > infoPtr->numParts) {
687 /* delete tools */
688 for (i = nTipCount - 1; i >= infoPtr->numParts; i--) {
689 TRACE("delete tool %d\n", i);
690 ti.uId = i;
691 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW,
692 0, (LPARAM)&ti);
696 STATUSBAR_SetPartBounds (infoPtr);
697 InvalidateRect(infoPtr->Self, NULL, FALSE);
698 return TRUE;
702 static BOOL
703 STATUSBAR_SetTextT (STATUS_INFO *infoPtr, INT nPart, WORD style,
704 LPWSTR text, BOOL isW)
706 STATUSWINDOWPART *part=NULL;
707 BOOL changed = FALSE;
708 INT oldStyle;
710 if (style & SBT_OWNERDRAW) {
711 TRACE("part %d, text %p\n",nPart,text);
713 else TRACE("part %d, text %s\n", nPart, debugstr_t(text, isW));
715 /* MSDN says: "If the parameter is set to SB_SIMPLEID (255), the status
716 * window is assumed to be a simple window */
718 if (nPart == 0x00ff) {
719 part = &infoPtr->part0;
720 } else {
721 if (infoPtr->parts && nPart >= 0 && nPart < infoPtr->numParts) {
722 part = &infoPtr->parts[nPart];
725 if (!part) return FALSE;
727 if (part->style != style)
728 changed = TRUE;
730 oldStyle = part->style;
731 part->style = style;
732 if (style & SBT_OWNERDRAW) {
733 if (!(oldStyle & SBT_OWNERDRAW))
734 Free (part->text);
735 part->text = text;
736 } else {
737 LPWSTR ntext;
738 WCHAR *idx;
740 if (text && !isW) {
741 LPCSTR atxt = (LPCSTR)text;
742 DWORD len = MultiByteToWideChar( CP_ACP, 0, atxt, -1, NULL, 0 );
743 ntext = Alloc( (len + 1)*sizeof(WCHAR) );
744 if (!ntext) return FALSE;
745 MultiByteToWideChar( CP_ACP, 0, atxt, -1, ntext, len );
746 } else if (text) {
747 ntext = Alloc( (strlenW(text) + 1)*sizeof(WCHAR) );
748 if (!ntext) return FALSE;
749 strcpyW (ntext, text);
750 } else ntext = 0;
752 /* replace nonprintable characters with spaces */
753 if (ntext) {
754 idx = ntext;
755 while (*idx) {
756 if(!isprintW(*idx))
757 *idx = ' ';
758 idx++;
762 /* check if text is unchanged -> no need to redraw */
763 if (text) {
764 if (!changed && part->text && !lstrcmpW(ntext, part->text)) {
765 Free(ntext);
766 return TRUE;
768 } else {
769 if (!changed && !part->text)
770 return TRUE;
773 if (!(oldStyle & SBT_OWNERDRAW))
774 Free (part->text);
775 part->text = ntext;
777 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
778 UpdateWindow(infoPtr->Self);
780 return TRUE;
784 static LRESULT
785 STATUSBAR_SetTipTextA (const STATUS_INFO *infoPtr, INT id, LPSTR text)
787 TRACE("part %d: \"%s\"\n", id, text);
788 if (infoPtr->hwndToolTip) {
789 TTTOOLINFOA ti;
790 ti.cbSize = sizeof(TTTOOLINFOA);
791 ti.hwnd = infoPtr->Self;
792 ti.uId = id;
793 ti.hinst = 0;
794 ti.lpszText = text;
795 SendMessageA (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTA, 0, (LPARAM)&ti);
798 return 0;
802 static LRESULT
803 STATUSBAR_SetTipTextW (const STATUS_INFO *infoPtr, INT id, LPWSTR text)
805 TRACE("part %d: \"%s\"\n", id, debugstr_w(text));
806 if (infoPtr->hwndToolTip) {
807 TTTOOLINFOW ti;
808 ti.cbSize = sizeof(TTTOOLINFOW);
809 ti.hwnd = infoPtr->Self;
810 ti.uId = id;
811 ti.hinst = 0;
812 ti.lpszText = text;
813 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
816 return 0;
820 static inline LRESULT
821 STATUSBAR_SetUnicodeFormat (STATUS_INFO *infoPtr, BOOL bUnicode)
823 BOOL bOld = infoPtr->bUnicode;
825 TRACE("(0x%x)\n", bUnicode);
826 infoPtr->bUnicode = bUnicode;
828 return bOld;
832 static BOOL
833 STATUSBAR_Simple (STATUS_INFO *infoPtr, BOOL simple)
835 NMHDR nmhdr;
837 TRACE("(simple=%d)\n", simple);
838 if (infoPtr->simple == simple) /* no need to change */
839 return TRUE;
841 infoPtr->simple = simple;
843 /* send notification */
844 nmhdr.hwndFrom = infoPtr->Self;
845 nmhdr.idFrom = GetWindowLongPtrW (infoPtr->Self, GWLP_ID);
846 nmhdr.code = SBN_SIMPLEMODECHANGE;
847 SendMessageW (infoPtr->Notify, WM_NOTIFY, 0, (LPARAM)&nmhdr);
848 InvalidateRect(infoPtr->Self, NULL, FALSE);
849 return TRUE;
853 static LRESULT
854 STATUSBAR_WMDestroy (STATUS_INFO *infoPtr)
856 unsigned int i;
858 TRACE("\n");
859 for (i = 0; i < infoPtr->numParts; i++) {
860 if (!(infoPtr->parts[i].style & SBT_OWNERDRAW))
861 Free (infoPtr->parts[i].text);
863 if (!(infoPtr->part0.style & SBT_OWNERDRAW))
864 Free (infoPtr->part0.text);
865 Free (infoPtr->parts);
867 /* delete default font */
868 if (infoPtr->hDefaultFont)
869 DeleteObject (infoPtr->hDefaultFont);
871 /* delete tool tip control */
872 if (infoPtr->hwndToolTip)
873 DestroyWindow (infoPtr->hwndToolTip);
875 CloseThemeData (GetWindowTheme (infoPtr->Self));
877 SetWindowLongPtrW(infoPtr->Self, 0, 0);
878 Free (infoPtr);
879 return 0;
883 static LRESULT
884 STATUSBAR_WMCreate (HWND hwnd, const CREATESTRUCTA *lpCreate)
886 STATUS_INFO *infoPtr;
887 NONCLIENTMETRICSW nclm;
888 DWORD dwStyle;
889 RECT rect;
890 int len;
892 TRACE("\n");
893 infoPtr = Alloc (sizeof(STATUS_INFO));
894 if (!infoPtr) goto create_fail;
895 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
897 infoPtr->Self = hwnd;
898 infoPtr->Notify = lpCreate->hwndParent;
899 infoPtr->numParts = 1;
900 infoPtr->parts = 0;
901 infoPtr->simple = FALSE;
902 infoPtr->clrBk = CLR_DEFAULT;
903 infoPtr->hFont = 0;
904 infoPtr->horizontalBorder = HORZ_BORDER;
905 infoPtr->verticalBorder = VERT_BORDER;
906 infoPtr->horizontalGap = HORZ_GAP;
907 infoPtr->minHeight = GetSystemMetrics(SM_CYSIZE);
908 if (infoPtr->minHeight & 1) infoPtr->minHeight--;
910 STATUSBAR_NotifyFormat(infoPtr, infoPtr->Notify, NF_REQUERY);
912 ZeroMemory (&nclm, sizeof(nclm));
913 nclm.cbSize = sizeof(nclm);
914 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, nclm.cbSize, &nclm, 0);
915 infoPtr->hDefaultFont = CreateFontIndirectW (&nclm.lfStatusFont);
917 GetClientRect (hwnd, &rect);
919 /* initialize simple case */
920 infoPtr->part0.bound = rect;
921 infoPtr->part0.text = 0;
922 infoPtr->part0.x = 0;
923 infoPtr->part0.style = 0;
924 infoPtr->part0.hIcon = 0;
926 /* initialize first part */
927 infoPtr->parts = Alloc (sizeof(STATUSWINDOWPART));
928 if (!infoPtr->parts) goto create_fail;
929 infoPtr->parts[0].bound = rect;
930 infoPtr->parts[0].text = 0;
931 infoPtr->parts[0].x = -1;
932 infoPtr->parts[0].style = 0;
933 infoPtr->parts[0].hIcon = 0;
935 OpenThemeData (hwnd, themeClass);
937 if (lpCreate->lpszName && (len = strlenW ((LPCWSTR)lpCreate->lpszName)))
939 infoPtr->parts[0].text = Alloc ((len + 1)*sizeof(WCHAR));
940 if (!infoPtr->parts[0].text) goto create_fail;
941 strcpyW (infoPtr->parts[0].text, (LPCWSTR)lpCreate->lpszName);
944 dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
945 /* native seems to clear WS_BORDER, too */
946 dwStyle &= ~WS_BORDER;
947 SetWindowLongW (hwnd, GWL_STYLE, dwStyle);
949 infoPtr->height = STATUSBAR_ComputeHeight(infoPtr);
951 if (dwStyle & SBT_TOOLTIPS) {
952 infoPtr->hwndToolTip =
953 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, WS_POPUP | TTS_ALWAYSTIP,
954 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
955 CW_USEDEFAULT, hwnd, 0,
956 (HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE), NULL);
958 if (infoPtr->hwndToolTip) {
959 NMTOOLTIPSCREATED nmttc;
961 nmttc.hdr.hwndFrom = hwnd;
962 nmttc.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
963 nmttc.hdr.code = NM_TOOLTIPSCREATED;
964 nmttc.hwndToolTips = infoPtr->hwndToolTip;
966 SendMessageW (lpCreate->hwndParent, WM_NOTIFY, nmttc.hdr.idFrom, (LPARAM)&nmttc);
970 return 0;
972 create_fail:
973 TRACE(" failed!\n");
974 if (infoPtr) STATUSBAR_WMDestroy(infoPtr);
975 return -1;
979 /* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
980 * of the first part only (usual behaviour) */
981 static INT
982 STATUSBAR_WMGetText (const STATUS_INFO *infoPtr, INT size, LPWSTR buf)
984 INT len;
986 TRACE("\n");
987 if (!(infoPtr->parts[0].text))
988 return 0;
990 len = strlenW (infoPtr->parts[0].text);
992 if (!size)
993 return len;
994 else if (size > len) {
995 strcpyW (buf, infoPtr->parts[0].text);
996 return len;
998 else {
999 memcpy (buf, infoPtr->parts[0].text, (size - 1) * sizeof(WCHAR));
1000 buf[size - 1] = 0;
1001 return size - 1;
1006 static BOOL
1007 STATUSBAR_WMNCHitTest (const STATUS_INFO *infoPtr, INT x, INT y)
1009 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP) {
1010 RECT rect;
1011 POINT pt;
1013 GetClientRect (infoPtr->Self, &rect);
1015 pt.x = x;
1016 pt.y = y;
1017 ScreenToClient (infoPtr->Self, &pt);
1019 rect.left = rect.right - 13;
1020 rect.top += 2;
1022 if (PtInRect (&rect, pt))
1024 if (GetWindowLongW( infoPtr->Self, GWL_EXSTYLE ) & WS_EX_LAYOUTRTL) return HTBOTTOMLEFT;
1025 else return HTBOTTOMRIGHT;
1029 return HTERROR;
1033 static LRESULT
1034 STATUSBAR_WMPaint (STATUS_INFO *infoPtr, HDC hdc)
1036 PAINTSTRUCT ps;
1038 TRACE("\n");
1039 if (hdc) return STATUSBAR_Refresh (infoPtr, hdc);
1040 hdc = BeginPaint (infoPtr->Self, &ps);
1041 STATUSBAR_Refresh (infoPtr, hdc);
1042 EndPaint (infoPtr->Self, &ps);
1044 return 0;
1048 static LRESULT
1049 STATUSBAR_WMSetFont (STATUS_INFO *infoPtr, HFONT font, BOOL redraw)
1051 infoPtr->hFont = font;
1052 TRACE("%p\n", infoPtr->hFont);
1054 infoPtr->height = STATUSBAR_ComputeHeight(infoPtr);
1055 SendMessageW(infoPtr->Self, WM_SIZE, 0, 0); /* update size */
1056 if (redraw)
1057 InvalidateRect(infoPtr->Self, NULL, FALSE);
1059 return 0;
1063 static BOOL
1064 STATUSBAR_WMSetText (const STATUS_INFO *infoPtr, LPCSTR text)
1066 STATUSWINDOWPART *part;
1067 int len;
1069 TRACE("\n");
1070 if (infoPtr->numParts == 0)
1071 return FALSE;
1073 part = &infoPtr->parts[0];
1074 /* duplicate string */
1075 Free (part->text);
1076 part->text = 0;
1078 if (text && (len = strlenW((LPCWSTR)text))) {
1079 part->text = Alloc ((len+1)*sizeof(WCHAR));
1080 if (!part->text) return FALSE;
1081 strcpyW (part->text, (LPCWSTR)text);
1084 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
1086 return TRUE;
1090 static BOOL
1091 STATUSBAR_WMSize (STATUS_INFO *infoPtr, WORD flags)
1093 INT width, x, y;
1094 RECT parent_rect;
1096 /* Need to resize width to match parent */
1097 TRACE("flags %04x\n", flags);
1099 if (flags != SIZE_RESTORED && flags != SIZE_MAXIMIZED) {
1100 WARN("flags MUST be SIZE_RESTORED or SIZE_MAXIMIZED\n");
1101 return FALSE;
1104 if (GetWindowLongW(infoPtr->Self, GWL_STYLE) & CCS_NORESIZE) return FALSE;
1106 /* width and height don't apply */
1107 if (!GetClientRect (infoPtr->Notify, &parent_rect))
1108 return FALSE;
1110 width = parent_rect.right - parent_rect.left;
1111 x = parent_rect.left;
1112 y = parent_rect.bottom - infoPtr->height;
1113 MoveWindow (infoPtr->Self, x, y, width, infoPtr->height, TRUE);
1114 STATUSBAR_SetPartBounds (infoPtr);
1115 return TRUE;
1119 /* update theme after a WM_THEMECHANGED message */
1120 static LRESULT theme_changed (const STATUS_INFO* infoPtr)
1122 HTHEME theme = GetWindowTheme (infoPtr->Self);
1123 CloseThemeData (theme);
1124 OpenThemeData (infoPtr->Self, themeClass);
1125 return 0;
1129 static LRESULT
1130 STATUSBAR_NotifyFormat (STATUS_INFO *infoPtr, HWND from, INT cmd)
1132 if (cmd == NF_REQUERY) {
1133 INT i = SendMessageW(from, WM_NOTIFYFORMAT, (WPARAM)infoPtr->Self, NF_QUERY);
1134 infoPtr->bUnicode = (i == NFR_UNICODE);
1136 return infoPtr->bUnicode ? NFR_UNICODE : NFR_ANSI;
1140 static LRESULT
1141 STATUSBAR_SendMouseNotify(const STATUS_INFO *infoPtr, UINT code, UINT msg, WPARAM wParam, LPARAM lParam)
1143 NMMOUSE nm;
1145 TRACE("code %04x, lParam=%lx\n", code, lParam);
1146 nm.hdr.hwndFrom = infoPtr->Self;
1147 nm.hdr.idFrom = GetWindowLongPtrW(infoPtr->Self, GWLP_ID);
1148 nm.hdr.code = code;
1149 nm.pt.x = (short)LOWORD(lParam);
1150 nm.pt.y = (short)HIWORD(lParam);
1151 nm.dwItemSpec = STATUSBAR_InternalHitTest(infoPtr, &nm.pt);
1152 nm.dwItemData = 0;
1153 nm.dwHitInfo = 0x30000; /* seems constant */
1155 /* Do default processing if WM_NOTIFY returns zero */
1156 if(!SendMessageW(infoPtr->Notify, WM_NOTIFY, nm.hdr.idFrom, (LPARAM)&nm))
1158 return DefWindowProcW(infoPtr->Self, msg, wParam, lParam);
1160 return 0;
1165 static LRESULT WINAPI
1166 StatusWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1168 STATUS_INFO *infoPtr = (STATUS_INFO *)GetWindowLongPtrW (hwnd, 0);
1169 INT nPart = ((INT) wParam) & 0x00ff;
1170 LRESULT res;
1172 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd, msg, wParam, lParam);
1173 if (!infoPtr && msg != WM_CREATE)
1174 return DefWindowProcW (hwnd, msg, wParam, lParam);
1176 switch (msg) {
1177 case SB_GETBORDERS:
1178 return STATUSBAR_GetBorders (infoPtr, (INT *)lParam);
1180 case SB_GETICON:
1181 return (LRESULT)STATUSBAR_GetIcon (infoPtr, nPart);
1183 case SB_GETPARTS:
1184 return STATUSBAR_GetParts (infoPtr, (INT)wParam, (INT *)lParam);
1186 case SB_GETRECT:
1187 return STATUSBAR_GetRect (infoPtr, nPart, (LPRECT)lParam);
1189 case SB_GETTEXTA:
1190 return STATUSBAR_GetTextA (infoPtr, nPart, (LPSTR)lParam);
1192 case SB_GETTEXTW:
1193 return STATUSBAR_GetTextW (infoPtr, nPart, (LPWSTR)lParam);
1195 case SB_GETTEXTLENGTHA:
1196 case SB_GETTEXTLENGTHW:
1197 return STATUSBAR_GetTextLength (infoPtr, nPart);
1199 case SB_GETTIPTEXTA:
1200 return STATUSBAR_GetTipTextA (infoPtr, LOWORD(wParam), (LPSTR)lParam, HIWORD(wParam));
1202 case SB_GETTIPTEXTW:
1203 return STATUSBAR_GetTipTextW (infoPtr, LOWORD(wParam), (LPWSTR)lParam, HIWORD(wParam));
1205 case SB_GETUNICODEFORMAT:
1206 return infoPtr->bUnicode;
1208 case SB_ISSIMPLE:
1209 return infoPtr->simple;
1211 case SB_SETBORDERS:
1212 return STATUSBAR_SetBorders (infoPtr, (INT *)lParam);
1214 case SB_SETBKCOLOR:
1215 return STATUSBAR_SetBkColor (infoPtr, (COLORREF)lParam);
1217 case SB_SETICON:
1218 return STATUSBAR_SetIcon (infoPtr, nPart, (HICON)lParam);
1220 case SB_SETMINHEIGHT:
1221 return STATUSBAR_SetMinHeight (infoPtr, (INT)wParam);
1223 case SB_SETPARTS:
1224 return STATUSBAR_SetParts (infoPtr, (INT)wParam, (LPINT)lParam);
1226 case SB_SETTEXTA:
1227 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPWSTR)lParam, FALSE);
1229 case SB_SETTEXTW:
1230 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPWSTR)lParam, TRUE);
1232 case SB_SETTIPTEXTA:
1233 return STATUSBAR_SetTipTextA (infoPtr, (INT)wParam, (LPSTR)lParam);
1235 case SB_SETTIPTEXTW:
1236 return STATUSBAR_SetTipTextW (infoPtr, (INT)wParam, (LPWSTR)lParam);
1238 case SB_SETUNICODEFORMAT:
1239 return STATUSBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1241 case SB_SIMPLE:
1242 return STATUSBAR_Simple (infoPtr, (BOOL)wParam);
1244 case WM_CREATE:
1245 return STATUSBAR_WMCreate (hwnd, (LPCREATESTRUCTA)lParam);
1247 case WM_DESTROY:
1248 return STATUSBAR_WMDestroy (infoPtr);
1250 case WM_GETFONT:
1251 return (LRESULT)(infoPtr->hFont? infoPtr->hFont : infoPtr->hDefaultFont);
1253 case WM_GETTEXT:
1254 return STATUSBAR_WMGetText (infoPtr, (INT)wParam, (LPWSTR)lParam);
1256 case WM_GETTEXTLENGTH:
1257 return LOWORD(STATUSBAR_GetTextLength (infoPtr, 0));
1259 case WM_LBUTTONDBLCLK:
1260 return STATUSBAR_SendMouseNotify(infoPtr, NM_DBLCLK, msg, wParam, lParam);
1262 case WM_LBUTTONUP:
1263 return STATUSBAR_SendMouseNotify(infoPtr, NM_CLICK, msg, wParam, lParam);
1265 case WM_MOUSEMOVE:
1266 return STATUSBAR_Relay2Tip (infoPtr, msg, wParam, lParam);
1268 case WM_NCHITTEST:
1269 res = STATUSBAR_WMNCHitTest(infoPtr, (short)LOWORD(lParam),
1270 (short)HIWORD(lParam));
1271 if (res != HTERROR) return res;
1272 return DefWindowProcW (hwnd, msg, wParam, lParam);
1274 case WM_NCLBUTTONUP:
1275 case WM_NCLBUTTONDOWN:
1276 PostMessageW (infoPtr->Notify, msg, wParam, lParam);
1277 return 0;
1279 case WM_NOTIFYFORMAT:
1280 return STATUSBAR_NotifyFormat(infoPtr, (HWND)wParam, (INT)lParam);
1282 case WM_PRINTCLIENT:
1283 case WM_PAINT:
1284 return STATUSBAR_WMPaint (infoPtr, (HDC)wParam);
1286 case WM_RBUTTONDBLCLK:
1287 return STATUSBAR_SendMouseNotify(infoPtr, NM_RDBLCLK, msg, wParam, lParam);
1289 case WM_RBUTTONUP:
1290 return STATUSBAR_SendMouseNotify(infoPtr, NM_RCLICK, msg, wParam, lParam);
1292 case WM_SETFONT:
1293 return STATUSBAR_WMSetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
1295 case WM_SETTEXT:
1296 return STATUSBAR_WMSetText (infoPtr, (LPCSTR)lParam);
1298 case WM_SIZE:
1299 if (STATUSBAR_WMSize (infoPtr, (WORD)wParam)) return 0;
1300 return DefWindowProcW (hwnd, msg, wParam, lParam);
1302 case WM_SYSCOLORCHANGE:
1303 COMCTL32_RefreshSysColors();
1304 return 0;
1306 case WM_THEMECHANGED:
1307 return theme_changed (infoPtr);
1309 default:
1310 if ((msg >= WM_USER) && (msg < WM_APP) && !COMCTL32_IsReflectedMessage(msg))
1311 ERR("unknown msg %04x wp=%04lx lp=%08lx\n",
1312 msg, wParam, lParam);
1313 return DefWindowProcW (hwnd, msg, wParam, lParam);
1318 /***********************************************************************
1319 * STATUS_Register [Internal]
1321 * Registers the status window class.
1324 void
1325 STATUS_Register (void)
1327 WNDCLASSW wndClass;
1329 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1330 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW;
1331 wndClass.lpfnWndProc = StatusWindowProc;
1332 wndClass.cbClsExtra = 0;
1333 wndClass.cbWndExtra = sizeof(STATUS_INFO *);
1334 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1335 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
1336 wndClass.lpszClassName = STATUSCLASSNAMEW;
1338 RegisterClassW (&wndClass);
1342 /***********************************************************************
1343 * STATUS_Unregister [Internal]
1345 * Unregisters the status window class.
1348 void
1349 STATUS_Unregister (void)
1351 UnregisterClassW (STATUSCLASSNAMEW, NULL);