d2d1: Implement ID2D1DeviceContext::CreateImageBrush().
[wine.git] / dlls / comctl32 / status.c
blob5251f3677b04c48647a78f355bfbf3a45d1430ae
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 * TODO:
23 * -- CCS_BOTTOM (default)
24 * -- CCS_LEFT
25 * -- CCS_NODIVIDER
26 * -- CCS_NOMOVEX
27 * -- CCS_NOMOVEY
28 * -- CCS_NOPARENTALIGN
29 * -- CCS_RIGHT
30 * -- CCS_TOP
31 * -- CCS_VERT (defaults to RIGHT)
34 #include <stdarg.h>
35 #include <string.h>
37 #include "windef.h"
38 #include "winbase.h"
39 #include "wingdi.h"
40 #include "winuser.h"
41 #include "winnls.h"
42 #include "commctrl.h"
43 #include "comctl32.h"
44 #include "uxtheme.h"
45 #include "vssym32.h"
46 #include "wine/debug.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(statusbar);
50 typedef struct
52 INT x;
53 INT style;
54 RECT bound;
55 LPWSTR text;
56 HICON hIcon;
57 } STATUSWINDOWPART;
59 typedef struct
61 HWND Self;
62 HWND Notify;
63 WORD numParts;
64 UINT height;
65 UINT minHeight; /* at least MIN_PANE_HEIGHT, can be increased by SB_SETMINHEIGHT */
66 BOOL simple;
67 HWND hwndToolTip;
68 HFONT hFont;
69 HFONT hDefaultFont;
70 COLORREF clrBk; /* background color */
71 BOOL bUnicode; /* notify format. TRUE if notifies in Unicode */
72 STATUSWINDOWPART part0; /* simple window */
73 STATUSWINDOWPART* parts;
74 INT horizontalBorder;
75 INT verticalBorder;
76 INT horizontalGap;
77 } STATUS_INFO;
80 * Run tests using Waite Group Windows95 API Bible Vol. 1&2
81 * The second cdrom contains executables drawstat.exe, gettext.exe,
82 * simple.exe, getparts.exe, setparts.exe, statwnd.exe
85 #define HORZ_BORDER 0
86 #define VERT_BORDER 2
87 #define HORZ_GAP 2
89 static const WCHAR themeClass[] = L"Status";
91 /* prototype */
92 static void
93 STATUSBAR_SetPartBounds (STATUS_INFO *infoPtr);
94 static LRESULT
95 STATUSBAR_NotifyFormat (STATUS_INFO *infoPtr, HWND from, INT cmd);
97 static inline LPCSTR debugstr_t(LPCWSTR text, BOOL isW)
99 return isW ? debugstr_w(text) : debugstr_a((LPCSTR)text);
102 static UINT
103 STATUSBAR_ComputeHeight(STATUS_INFO *infoPtr)
105 UINT height;
106 TEXTMETRICW tm;
107 int margin;
109 COMCTL32_GetFontMetrics(infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont, &tm);
110 margin = (tm.tmInternalLeading ? tm.tmInternalLeading : 2);
111 height = max(tm.tmHeight + margin + 2*GetSystemMetrics(SM_CYBORDER), infoPtr->minHeight) + infoPtr->verticalBorder;
113 TRACE(" textHeight=%ld+%ld, final height=%d\n", tm.tmHeight, tm.tmInternalLeading, height);
114 return height;
117 static void
118 STATUSBAR_DrawSizeGrip (HTHEME theme, HDC hdc, LPRECT lpRect)
120 RECT rc = *lpRect;
122 TRACE("draw size grip %s\n", wine_dbgstr_rect(lpRect));
124 if (theme)
126 SIZE gripperSize;
127 if (SUCCEEDED (GetThemePartSize (theme, hdc, SP_GRIPPER, 0, lpRect,
128 TS_DRAW, &gripperSize)))
130 rc.left = rc.right - gripperSize.cx;
131 rc.top = rc.bottom - gripperSize.cy;
132 if (SUCCEEDED (DrawThemeBackground(theme, hdc, SP_GRIPPER, 0, &rc, NULL)))
133 return;
137 rc.left = max( rc.left, rc.right - GetSystemMetrics(SM_CXVSCROLL) - 1 );
138 rc.top = max( rc.top, rc.bottom - GetSystemMetrics(SM_CYHSCROLL) - 1 );
139 DrawFrameControl( hdc, &rc, DFC_SCROLL, DFCS_SCROLLSIZEGRIP );
142 static void
143 STATUSBAR_DrawPart (const STATUS_INFO *infoPtr, HDC hdc, const STATUSWINDOWPART *part, int itemID)
145 RECT r = part->bound;
146 UINT border;
147 HTHEME theme = GetWindowTheme (infoPtr->Self);
148 int themePart = SP_PANE;
149 int x = 0;
151 TRACE("part bound %s\n", wine_dbgstr_rect(&r));
153 if (theme)
155 if ((GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
156 && (infoPtr->simple || (itemID == (infoPtr->numParts-1))))
157 themePart = SP_GRIPPERPANE;
158 DrawThemeBackground(theme, hdc, themePart, 0, &r, NULL);
160 else
162 if (part->style & SBT_POPOUT)
163 border = BDR_RAISEDOUTER;
164 else if (part->style & SBT_NOBORDERS)
165 border = 0;
166 else
167 border = BDR_SUNKENOUTER;
168 DrawEdge(hdc, &r, border, BF_RECT|BF_ADJUST);
171 if (part->hIcon) {
172 INT cy = r.bottom - r.top;
173 DrawIconEx (hdc, r.left + 2, r.top, part->hIcon, cy, cy, 0, 0, DI_NORMAL);
174 x = 2 + cy;
177 if (part->style & SBT_OWNERDRAW) {
178 DRAWITEMSTRUCT dis;
180 dis.CtlID = GetWindowLongPtrW (infoPtr->Self, GWLP_ID);
181 dis.itemID = itemID;
182 dis.hwndItem = infoPtr->Self;
183 dis.hDC = hdc;
184 dis.rcItem = r;
185 dis.itemData = (ULONG_PTR)part->text;
186 SendMessageW (infoPtr->Notify, WM_DRAWITEM, dis.CtlID, (LPARAM)&dis);
187 } else {
188 r.left += x;
189 COMCTL32_DrawStatusText(hdc, &r, part->text, 0, FALSE);
194 static void
195 STATUSBAR_RefreshPart (const STATUS_INFO *infoPtr, HDC hdc, const STATUSWINDOWPART *part, int itemID)
197 TRACE("item %d\n", itemID);
199 if (part->bound.right < part->bound.left) return;
201 if (!RectVisible(hdc, &part->bound))
202 return;
204 STATUSBAR_DrawPart (infoPtr, hdc, part, itemID);
208 static LRESULT
209 STATUSBAR_Refresh (STATUS_INFO *infoPtr, HDC hdc)
211 RECT rect;
212 HBRUSH hbrBk;
213 HFONT hOldFont;
214 HTHEME theme;
216 TRACE("\n");
217 if (!IsWindowVisible(infoPtr->Self))
218 return 0;
220 STATUSBAR_SetPartBounds(infoPtr);
222 GetClientRect (infoPtr->Self, &rect);
224 if ((theme = GetWindowTheme (infoPtr->Self)))
226 DrawThemeBackground(theme, hdc, 0, 0, &rect, NULL);
228 else
230 if (infoPtr->clrBk != CLR_DEFAULT)
231 hbrBk = CreateSolidBrush (infoPtr->clrBk);
232 else
233 hbrBk = GetSysColorBrush (COLOR_3DFACE);
234 FillRect(hdc, &rect, hbrBk);
235 if (infoPtr->clrBk != CLR_DEFAULT)
236 DeleteObject (hbrBk);
239 hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
241 if (infoPtr->simple) {
242 STATUSBAR_RefreshPart (infoPtr, hdc, &infoPtr->part0, 0);
243 } else {
244 unsigned int i;
246 for (i = 0; i < infoPtr->numParts; i++) {
247 STATUSBAR_RefreshPart (infoPtr, hdc, &infoPtr->parts[i], i);
251 SelectObject (hdc, hOldFont);
253 if ((GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
254 && !(GetWindowLongW (infoPtr->Notify, GWL_STYLE) & WS_MAXIMIZE))
255 STATUSBAR_DrawSizeGrip (theme, hdc, &rect);
257 return 0;
261 static int
262 STATUSBAR_InternalHitTest(const STATUS_INFO *infoPtr, const POINT *pt)
264 unsigned int i;
266 if (infoPtr->simple)
267 return 255;
269 for (i = 0; i < infoPtr->numParts; i++)
270 if (pt->x >= infoPtr->parts[i].bound.left && pt->x <= infoPtr->parts[i].bound.right)
271 return i;
272 return -2;
276 static void
277 STATUSBAR_SetPartBounds (STATUS_INFO *infoPtr)
279 STATUSWINDOWPART *part;
280 RECT rect, *r;
281 UINT i;
283 /* get our window size */
284 GetClientRect (infoPtr->Self, &rect);
285 TRACE("client wnd size is %s\n", wine_dbgstr_rect(&rect));
287 rect.left += infoPtr->horizontalBorder;
288 rect.top += infoPtr->verticalBorder;
290 /* set bounds for simple rectangle */
291 infoPtr->part0.bound = rect;
293 /* set bounds for non-simple rectangles */
294 for (i = 0; i < infoPtr->numParts; i++) {
295 part = &infoPtr->parts[i];
296 r = &infoPtr->parts[i].bound;
297 r->top = rect.top;
298 r->bottom = rect.bottom;
299 if (i == 0)
300 r->left = 0;
301 else
302 r->left = infoPtr->parts[i-1].bound.right + infoPtr->horizontalGap;
303 if (part->x == -1)
304 r->right = rect.right;
305 else
306 r->right = part->x;
308 if (infoPtr->hwndToolTip) {
309 TTTOOLINFOW ti;
311 ti.cbSize = sizeof(TTTOOLINFOW);
312 ti.hwnd = infoPtr->Self;
313 ti.uId = i;
314 ti.rect = *r;
315 SendMessageW (infoPtr->hwndToolTip, TTM_NEWTOOLRECTW,
316 0, (LPARAM)&ti);
322 static LRESULT
323 STATUSBAR_Relay2Tip (const STATUS_INFO *infoPtr, UINT uMsg,
324 WPARAM wParam, LPARAM lParam)
326 MSG msg;
328 msg.hwnd = infoPtr->Self;
329 msg.message = uMsg;
330 msg.wParam = wParam;
331 msg.lParam = lParam;
332 msg.time = GetMessageTime ();
333 msg.pt.x = (short)LOWORD(GetMessagePos ());
334 msg.pt.y = (short)HIWORD(GetMessagePos ());
336 return SendMessageW (infoPtr->hwndToolTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
340 static BOOL
341 STATUSBAR_GetBorders (const STATUS_INFO *infoPtr, INT out[])
343 TRACE("\n");
344 out[0] = infoPtr->horizontalBorder;
345 out[1] = infoPtr->verticalBorder;
346 out[2] = infoPtr->horizontalGap;
348 return TRUE;
352 static BOOL
353 STATUSBAR_SetBorders (STATUS_INFO *infoPtr, const INT in[])
355 TRACE("\n");
356 infoPtr->horizontalBorder = in[0];
357 infoPtr->verticalBorder = in[1];
358 infoPtr->horizontalGap = in[2];
359 InvalidateRect(infoPtr->Self, NULL, FALSE);
361 return TRUE;
365 static HICON
366 STATUSBAR_GetIcon (const STATUS_INFO *infoPtr, INT nPart)
368 TRACE("%d\n", nPart);
369 /* MSDN says: "simple parts are indexed with -1" */
370 if ((nPart < -1) || (nPart >= infoPtr->numParts))
371 return 0;
373 if (nPart == -1)
374 return (infoPtr->part0.hIcon);
375 else
376 return (infoPtr->parts[nPart].hIcon);
380 static INT
381 STATUSBAR_GetParts (const STATUS_INFO *infoPtr, INT num_parts, INT parts[])
383 INT i;
385 TRACE("(%d)\n", num_parts);
386 if (parts) {
387 if (num_parts > infoPtr->numParts)
388 num_parts = infoPtr->numParts;
389 for (i = 0; i < num_parts; i++) {
390 parts[i] = infoPtr->parts[i].x;
393 return infoPtr->numParts;
397 static BOOL
398 STATUSBAR_GetRect (const STATUS_INFO *infoPtr, INT nPart, LPRECT rect)
400 TRACE("part %d\n", nPart);
401 if(nPart >= infoPtr->numParts || nPart < 0)
402 return FALSE;
403 if (infoPtr->simple)
404 *rect = infoPtr->part0.bound;
405 else
406 *rect = infoPtr->parts[nPart].bound;
407 return TRUE;
411 static LRESULT
412 STATUSBAR_GetTextA (STATUS_INFO *infoPtr, INT nPart, LPSTR buf)
414 STATUSWINDOWPART *part;
415 LRESULT result;
417 TRACE("part %d\n", nPart);
419 /* MSDN says: "simple parts use index of 0", so this check is ok. */
420 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
422 if (infoPtr->simple)
423 part = &infoPtr->part0;
424 else
425 part = &infoPtr->parts[nPart];
427 if (part->style & SBT_OWNERDRAW)
428 result = (LRESULT)part->text;
429 else {
430 DWORD len = part->text ? WideCharToMultiByte( CP_ACP, 0, part->text, -1,
431 NULL, 0, NULL, NULL ) - 1 : 0;
432 result = MAKELONG( len, part->style );
433 if (part->text && buf)
434 WideCharToMultiByte( CP_ACP, 0, part->text, -1, buf, len+1, NULL, NULL );
436 return result;
440 static LRESULT
441 STATUSBAR_GetTextW (STATUS_INFO *infoPtr, INT nPart, LPWSTR buf)
443 STATUSWINDOWPART *part;
444 LRESULT result;
446 TRACE("part %d\n", nPart);
447 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
449 if (infoPtr->simple)
450 part = &infoPtr->part0;
451 else
452 part = &infoPtr->parts[nPart];
454 if (part->style & SBT_OWNERDRAW)
455 result = (LRESULT)part->text;
456 else {
457 result = part->text ? lstrlenW (part->text) : 0;
458 result |= (part->style << 16);
459 if (part->text && buf)
460 lstrcpyW (buf, part->text);
462 return result;
466 static LRESULT
467 STATUSBAR_GetTextLength (STATUS_INFO *infoPtr, INT nPart)
469 STATUSWINDOWPART *part;
470 DWORD result;
472 TRACE("part %d\n", nPart);
474 /* MSDN says: "simple parts use index of 0", so this check is ok. */
475 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
477 if (infoPtr->simple)
478 part = &infoPtr->part0;
479 else
480 part = &infoPtr->parts[nPart];
482 if ((~part->style & SBT_OWNERDRAW) && part->text)
483 result = lstrlenW(part->text);
484 else
485 result = 0;
487 result |= (part->style << 16);
488 return result;
491 static LRESULT
492 STATUSBAR_GetTipTextA (const STATUS_INFO *infoPtr, INT id, LPSTR tip, INT size)
494 TRACE("\n");
495 if (tip) {
496 CHAR buf[INFOTIPSIZE];
497 buf[0]='\0';
499 if (infoPtr->hwndToolTip) {
500 TTTOOLINFOA ti;
501 ti.cbSize = sizeof(TTTOOLINFOA);
502 ti.hwnd = infoPtr->Self;
503 ti.uId = id;
504 ti.lpszText = buf;
505 SendMessageA (infoPtr->hwndToolTip, TTM_GETTEXTA, 0, (LPARAM)&ti);
507 lstrcpynA (tip, buf, size);
509 return 0;
513 static LRESULT
514 STATUSBAR_GetTipTextW (const STATUS_INFO *infoPtr, INT id, LPWSTR tip, INT size)
516 TRACE("\n");
517 if (tip) {
518 WCHAR buf[INFOTIPSIZE];
519 buf[0]=0;
521 if (infoPtr->hwndToolTip) {
522 TTTOOLINFOW ti;
523 ti.cbSize = sizeof(TTTOOLINFOW);
524 ti.hwnd = infoPtr->Self;
525 ti.uId = id;
526 ti.lpszText = buf;
527 SendMessageW(infoPtr->hwndToolTip, TTM_GETTEXTW, 0, (LPARAM)&ti);
529 lstrcpynW(tip, buf, size);
532 return 0;
536 static COLORREF
537 STATUSBAR_SetBkColor (STATUS_INFO *infoPtr, COLORREF color)
539 COLORREF oldBkColor;
541 oldBkColor = infoPtr->clrBk;
542 infoPtr->clrBk = color;
543 InvalidateRect(infoPtr->Self, NULL, FALSE);
545 TRACE("CREF: %#lx -> %#lx\n", oldBkColor, infoPtr->clrBk);
546 return oldBkColor;
550 static BOOL
551 STATUSBAR_SetIcon (STATUS_INFO *infoPtr, INT nPart, HICON hIcon)
553 if ((nPart < -1) || (nPart >= infoPtr->numParts))
554 return FALSE;
556 TRACE("setting part %d\n", nPart);
558 /* FIXME: MSDN says "if nPart is -1, the status bar is assumed simple" */
559 if (nPart == -1) {
560 if (infoPtr->part0.hIcon == hIcon) /* same as - no redraw */
561 return TRUE;
562 infoPtr->part0.hIcon = hIcon;
563 if (infoPtr->simple)
564 InvalidateRect(infoPtr->Self, &infoPtr->part0.bound, FALSE);
565 } else {
566 if (infoPtr->parts[nPart].hIcon == hIcon) /* same as - no redraw */
567 return TRUE;
569 infoPtr->parts[nPart].hIcon = hIcon;
570 if (!(infoPtr->simple))
571 InvalidateRect(infoPtr->Self, &infoPtr->parts[nPart].bound, FALSE);
573 return TRUE;
577 static BOOL
578 STATUSBAR_SetMinHeight (STATUS_INFO *infoPtr, INT height)
580 DWORD ysize = GetSystemMetrics(SM_CYSIZE);
581 if (ysize & 1) ysize--;
582 infoPtr->minHeight = max(height, ysize);
583 infoPtr->height = STATUSBAR_ComputeHeight(infoPtr);
584 /* like native, don't resize the control */
585 return TRUE;
589 static BOOL
590 STATUSBAR_SetParts (STATUS_INFO *infoPtr, INT count, LPINT parts)
592 STATUSWINDOWPART *tmp;
593 INT i, oldNumParts;
595 TRACE("(%d,%p)\n", count, parts);
597 if(!count) return FALSE;
599 oldNumParts = infoPtr->numParts;
600 infoPtr->numParts = count;
601 if (oldNumParts > infoPtr->numParts) {
602 for (i = infoPtr->numParts ; i < oldNumParts; i++) {
603 if (!(infoPtr->parts[i].style & SBT_OWNERDRAW))
604 Free (infoPtr->parts[i].text);
606 } else if (oldNumParts < infoPtr->numParts) {
607 tmp = Alloc (sizeof(STATUSWINDOWPART) * infoPtr->numParts);
608 if (!tmp) return FALSE;
609 for (i = 0; i < oldNumParts; i++) {
610 tmp[i] = infoPtr->parts[i];
612 Free (infoPtr->parts);
613 infoPtr->parts = tmp;
615 if (oldNumParts == infoPtr->numParts) {
616 for (i=0; i < oldNumParts; i++)
617 if (infoPtr->parts[i].x != parts[i])
618 break;
619 if (i==oldNumParts) /* Unchanged? no need to redraw! */
620 return TRUE;
623 for (i = 0; i < infoPtr->numParts; i++)
624 infoPtr->parts[i].x = parts[i];
626 if (infoPtr->hwndToolTip) {
627 INT nTipCount;
628 TTTOOLINFOW ti;
629 WCHAR wEmpty[] = L"";
631 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
632 ti.cbSize = sizeof(TTTOOLINFOW);
633 ti.hwnd = infoPtr->Self;
634 ti.lpszText = wEmpty;
636 nTipCount = SendMessageW (infoPtr->hwndToolTip, TTM_GETTOOLCOUNT, 0, 0);
637 if (nTipCount < infoPtr->numParts) {
638 /* add tools */
639 for (i = nTipCount; i < infoPtr->numParts; i++) {
640 TRACE("add tool %d\n", i);
641 ti.uId = i;
642 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
643 0, (LPARAM)&ti);
646 else if (nTipCount > infoPtr->numParts) {
647 /* delete tools */
648 for (i = nTipCount - 1; i >= infoPtr->numParts; i--) {
649 TRACE("delete tool %d\n", i);
650 ti.uId = i;
651 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW,
652 0, (LPARAM)&ti);
656 STATUSBAR_SetPartBounds (infoPtr);
657 InvalidateRect(infoPtr->Self, NULL, FALSE);
658 return TRUE;
662 static BOOL
663 STATUSBAR_SetTextT (STATUS_INFO *infoPtr, INT nPart, WORD style,
664 LPWSTR text, BOOL isW)
666 STATUSWINDOWPART *part=NULL;
667 BOOL changed = FALSE;
668 INT oldStyle;
670 if (style & SBT_OWNERDRAW) {
671 TRACE("part %d, text %p\n",nPart,text);
673 else TRACE("part %d, text %s\n", nPart, debugstr_t(text, isW));
675 /* MSDN says: "If the parameter is set to SB_SIMPLEID (255), the status
676 * window is assumed to be a simple window */
678 if (nPart == 0x00ff) {
679 part = &infoPtr->part0;
680 } else {
681 if (infoPtr->parts && nPart >= 0 && nPart < infoPtr->numParts) {
682 part = &infoPtr->parts[nPart];
685 if (!part) return FALSE;
687 if (part->style != style)
688 changed = TRUE;
690 oldStyle = part->style;
691 part->style = style;
692 if (style & SBT_OWNERDRAW) {
693 if (!(oldStyle & SBT_OWNERDRAW))
694 Free (part->text);
695 part->text = text;
696 } else {
697 LPWSTR ntext;
698 WCHAR *idx;
700 if (text && !isW) {
701 LPCSTR atxt = (LPCSTR)text;
702 DWORD len = MultiByteToWideChar( CP_ACP, 0, atxt, -1, NULL, 0 );
703 ntext = Alloc( (len + 1)*sizeof(WCHAR) );
704 if (!ntext) return FALSE;
705 MultiByteToWideChar( CP_ACP, 0, atxt, -1, ntext, len );
706 } else if (text) {
707 ntext = Alloc( (lstrlenW(text) + 1)*sizeof(WCHAR) );
708 if (!ntext) return FALSE;
709 lstrcpyW (ntext, text);
710 } else ntext = 0;
712 /* replace nonprintable characters with spaces */
713 if (ntext) {
714 idx = ntext;
715 while (*idx) {
716 if(*idx < ' ' && *idx != '\t')
717 *idx = ' ';
718 idx++;
722 /* check if text is unchanged -> no need to redraw */
723 if (text) {
724 if (!changed && part->text && !lstrcmpW(ntext, part->text)) {
725 Free(ntext);
726 return TRUE;
728 } else {
729 if (!changed && !part->text)
730 return TRUE;
733 if (!(oldStyle & SBT_OWNERDRAW))
734 Free (part->text);
735 part->text = ntext;
737 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
738 UpdateWindow(infoPtr->Self);
740 return TRUE;
744 static LRESULT
745 STATUSBAR_SetTipTextA (const STATUS_INFO *infoPtr, INT id, LPSTR text)
747 TRACE("part %d: \"%s\"\n", id, text);
748 if (infoPtr->hwndToolTip) {
749 TTTOOLINFOA ti;
750 ti.cbSize = sizeof(TTTOOLINFOA);
751 ti.hwnd = infoPtr->Self;
752 ti.uId = id;
753 ti.hinst = 0;
754 ti.lpszText = text;
755 SendMessageA (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTA, 0, (LPARAM)&ti);
758 return 0;
762 static LRESULT
763 STATUSBAR_SetTipTextW (const STATUS_INFO *infoPtr, INT id, LPWSTR text)
765 TRACE("part %d: \"%s\"\n", id, debugstr_w(text));
766 if (infoPtr->hwndToolTip) {
767 TTTOOLINFOW ti;
768 ti.cbSize = sizeof(TTTOOLINFOW);
769 ti.hwnd = infoPtr->Self;
770 ti.uId = id;
771 ti.hinst = 0;
772 ti.lpszText = text;
773 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
776 return 0;
780 static inline LRESULT
781 STATUSBAR_SetUnicodeFormat (STATUS_INFO *infoPtr, BOOL bUnicode)
783 BOOL bOld = infoPtr->bUnicode;
785 TRACE("(0x%x)\n", bUnicode);
786 infoPtr->bUnicode = bUnicode;
788 return bOld;
792 static BOOL
793 STATUSBAR_Simple (STATUS_INFO *infoPtr, BOOL simple)
795 NMHDR nmhdr;
797 TRACE("(simple=%d)\n", simple);
798 if (infoPtr->simple == simple) /* no need to change */
799 return TRUE;
801 infoPtr->simple = simple;
803 /* send notification */
804 nmhdr.hwndFrom = infoPtr->Self;
805 nmhdr.idFrom = GetWindowLongPtrW (infoPtr->Self, GWLP_ID);
806 nmhdr.code = SBN_SIMPLEMODECHANGE;
807 SendMessageW (infoPtr->Notify, WM_NOTIFY, 0, (LPARAM)&nmhdr);
808 InvalidateRect(infoPtr->Self, NULL, FALSE);
809 return TRUE;
813 static LRESULT
814 STATUSBAR_WMDestroy (STATUS_INFO *infoPtr)
816 unsigned int i;
818 TRACE("\n");
819 for (i = 0; i < infoPtr->numParts; i++) {
820 if (!(infoPtr->parts[i].style & SBT_OWNERDRAW))
821 Free (infoPtr->parts[i].text);
823 if (!(infoPtr->part0.style & SBT_OWNERDRAW))
824 Free (infoPtr->part0.text);
825 Free (infoPtr->parts);
827 /* delete default font */
828 if (infoPtr->hDefaultFont)
829 DeleteObject (infoPtr->hDefaultFont);
831 /* delete tool tip control */
832 if (infoPtr->hwndToolTip)
833 DestroyWindow (infoPtr->hwndToolTip);
835 CloseThemeData (GetWindowTheme (infoPtr->Self));
837 SetWindowLongPtrW(infoPtr->Self, 0, 0);
838 Free (infoPtr);
839 return 0;
843 static LRESULT
844 STATUSBAR_WMCreate (HWND hwnd, const CREATESTRUCTA *lpCreate)
846 STATUS_INFO *infoPtr;
847 NONCLIENTMETRICSW nclm;
848 DWORD dwStyle;
849 RECT rect;
850 int len;
852 TRACE("\n");
853 infoPtr = Alloc (sizeof(STATUS_INFO));
854 if (!infoPtr) goto create_fail;
855 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
857 infoPtr->Self = hwnd;
858 infoPtr->Notify = lpCreate->hwndParent;
859 infoPtr->numParts = 1;
860 infoPtr->parts = 0;
861 infoPtr->simple = FALSE;
862 infoPtr->clrBk = CLR_DEFAULT;
863 infoPtr->hFont = 0;
864 infoPtr->horizontalBorder = HORZ_BORDER;
865 infoPtr->verticalBorder = VERT_BORDER;
866 infoPtr->horizontalGap = HORZ_GAP;
867 infoPtr->minHeight = GetSystemMetrics(SM_CYSIZE);
868 if (infoPtr->minHeight & 1) infoPtr->minHeight--;
870 STATUSBAR_NotifyFormat(infoPtr, infoPtr->Notify, NF_REQUERY);
872 ZeroMemory (&nclm, sizeof(nclm));
873 nclm.cbSize = sizeof(nclm);
874 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, nclm.cbSize, &nclm, 0);
875 infoPtr->hDefaultFont = CreateFontIndirectW (&nclm.lfStatusFont);
877 GetClientRect (hwnd, &rect);
879 /* initialize simple case */
880 infoPtr->part0.bound = rect;
881 infoPtr->part0.text = 0;
882 infoPtr->part0.x = 0;
883 infoPtr->part0.style = 0;
884 infoPtr->part0.hIcon = 0;
886 /* initialize first part */
887 infoPtr->parts = Alloc (sizeof(STATUSWINDOWPART));
888 if (!infoPtr->parts) goto create_fail;
889 infoPtr->parts[0].bound = rect;
890 infoPtr->parts[0].text = 0;
891 infoPtr->parts[0].x = -1;
892 infoPtr->parts[0].style = 0;
893 infoPtr->parts[0].hIcon = 0;
895 OpenThemeData (hwnd, themeClass);
897 if (lpCreate->lpszName && (len = lstrlenW ((LPCWSTR)lpCreate->lpszName)))
899 infoPtr->parts[0].text = Alloc ((len + 1)*sizeof(WCHAR));
900 if (!infoPtr->parts[0].text) goto create_fail;
901 lstrcpyW (infoPtr->parts[0].text, (LPCWSTR)lpCreate->lpszName);
904 dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
905 /* native seems to clear WS_BORDER, too */
906 dwStyle &= ~WS_BORDER;
907 SetWindowLongW (hwnd, GWL_STYLE, dwStyle);
909 infoPtr->height = STATUSBAR_ComputeHeight(infoPtr);
911 if (dwStyle & SBT_TOOLTIPS) {
912 infoPtr->hwndToolTip =
913 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, WS_POPUP | TTS_ALWAYSTIP,
914 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
915 CW_USEDEFAULT, hwnd, 0,
916 (HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE), NULL);
918 if (infoPtr->hwndToolTip) {
919 NMTOOLTIPSCREATED nmttc;
921 nmttc.hdr.hwndFrom = hwnd;
922 nmttc.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
923 nmttc.hdr.code = NM_TOOLTIPSCREATED;
924 nmttc.hwndToolTips = infoPtr->hwndToolTip;
926 SendMessageW (lpCreate->hwndParent, WM_NOTIFY, nmttc.hdr.idFrom, (LPARAM)&nmttc);
930 return 0;
932 create_fail:
933 TRACE(" failed!\n");
934 if (infoPtr) STATUSBAR_WMDestroy(infoPtr);
935 return -1;
939 /* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
940 * of the first part only (usual behaviour) */
941 static INT
942 STATUSBAR_WMGetText (const STATUS_INFO *infoPtr, INT size, LPWSTR buf)
944 INT len;
946 TRACE("\n");
947 if (!(infoPtr->parts[0].text))
948 return 0;
950 len = lstrlenW (infoPtr->parts[0].text);
952 if (!size)
953 return len;
954 else if (size > len) {
955 lstrcpyW (buf, infoPtr->parts[0].text);
956 return len;
958 else {
959 memcpy (buf, infoPtr->parts[0].text, (size - 1) * sizeof(WCHAR));
960 buf[size - 1] = 0;
961 return size - 1;
966 static BOOL
967 STATUSBAR_WMNCHitTest (const STATUS_INFO *infoPtr, INT x, INT y)
969 if ((GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
970 && !(GetWindowLongW (infoPtr->Notify, GWL_STYLE) & WS_MAXIMIZE)) {
971 RECT rect;
972 POINT pt;
974 GetClientRect (infoPtr->Self, &rect);
976 pt.x = x;
977 pt.y = y;
978 ScreenToClient (infoPtr->Self, &pt);
980 if (pt.x >= rect.right - GetSystemMetrics(SM_CXVSCROLL))
982 if (GetWindowLongW( infoPtr->Self, GWL_EXSTYLE ) & WS_EX_LAYOUTRTL) return HTBOTTOMLEFT;
983 else return HTBOTTOMRIGHT;
987 return HTERROR;
991 static LRESULT
992 STATUSBAR_WMPaint (STATUS_INFO *infoPtr, HDC hdc)
994 PAINTSTRUCT ps;
996 TRACE("\n");
997 if (hdc) return STATUSBAR_Refresh (infoPtr, hdc);
998 hdc = BeginPaint (infoPtr->Self, &ps);
999 STATUSBAR_Refresh (infoPtr, hdc);
1000 EndPaint (infoPtr->Self, &ps);
1002 return 0;
1006 static LRESULT
1007 STATUSBAR_WMSetFont (STATUS_INFO *infoPtr, HFONT font, BOOL redraw)
1009 infoPtr->hFont = font;
1010 TRACE("%p\n", infoPtr->hFont);
1012 infoPtr->height = STATUSBAR_ComputeHeight(infoPtr);
1013 SendMessageW(infoPtr->Self, WM_SIZE, 0, 0); /* update size */
1014 if (redraw)
1015 InvalidateRect(infoPtr->Self, NULL, FALSE);
1017 return 0;
1021 static BOOL
1022 STATUSBAR_WMSetText (const STATUS_INFO *infoPtr, LPCSTR text)
1024 STATUSWINDOWPART *part;
1025 int len;
1027 TRACE("\n");
1028 if (infoPtr->numParts == 0)
1029 return FALSE;
1031 part = &infoPtr->parts[0];
1032 /* duplicate string */
1033 Free (part->text);
1034 part->text = 0;
1036 if (text && (len = lstrlenW((LPCWSTR)text))) {
1037 part->text = Alloc ((len+1)*sizeof(WCHAR));
1038 if (!part->text) return FALSE;
1039 lstrcpyW (part->text, (LPCWSTR)text);
1042 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
1044 return TRUE;
1048 static BOOL
1049 STATUSBAR_WMSize (STATUS_INFO *infoPtr, WORD flags)
1051 INT width, x, y;
1052 RECT parent_rect;
1054 /* Need to resize width to match parent */
1055 TRACE("flags %04x\n", flags);
1057 if (flags != SIZE_RESTORED && flags != SIZE_MAXIMIZED) {
1058 WARN("flags MUST be SIZE_RESTORED or SIZE_MAXIMIZED\n");
1059 return FALSE;
1062 if (GetWindowLongW(infoPtr->Self, GWL_STYLE) & CCS_NORESIZE) return FALSE;
1064 /* width and height don't apply */
1065 if (!GetClientRect (infoPtr->Notify, &parent_rect))
1066 return FALSE;
1068 width = parent_rect.right - parent_rect.left;
1069 x = parent_rect.left;
1070 y = parent_rect.bottom - infoPtr->height;
1071 MoveWindow (infoPtr->Self, x, y, width, infoPtr->height, TRUE);
1072 STATUSBAR_SetPartBounds (infoPtr);
1073 return TRUE;
1077 /* update theme after a WM_THEMECHANGED message */
1078 static LRESULT theme_changed (const STATUS_INFO* infoPtr)
1080 HTHEME theme = GetWindowTheme (infoPtr->Self);
1081 CloseThemeData (theme);
1082 OpenThemeData (infoPtr->Self, themeClass);
1083 InvalidateRect (infoPtr->Self, NULL, TRUE);
1084 return 0;
1088 static LRESULT
1089 STATUSBAR_NotifyFormat (STATUS_INFO *infoPtr, HWND from, INT cmd)
1091 if (cmd == NF_REQUERY) {
1092 INT i = SendMessageW(from, WM_NOTIFYFORMAT, (WPARAM)infoPtr->Self, NF_QUERY);
1093 infoPtr->bUnicode = (i == NFR_UNICODE);
1095 return infoPtr->bUnicode ? NFR_UNICODE : NFR_ANSI;
1099 static LRESULT
1100 STATUSBAR_SendMouseNotify(const STATUS_INFO *infoPtr, UINT code, UINT msg, WPARAM wParam, LPARAM lParam)
1102 NMMOUSE nm;
1104 TRACE("code %04x, lParam %Ix\n", code, lParam);
1105 nm.hdr.hwndFrom = infoPtr->Self;
1106 nm.hdr.idFrom = GetWindowLongPtrW(infoPtr->Self, GWLP_ID);
1107 nm.hdr.code = code;
1108 nm.pt.x = (short)LOWORD(lParam);
1109 nm.pt.y = (short)HIWORD(lParam);
1110 nm.dwItemSpec = STATUSBAR_InternalHitTest(infoPtr, &nm.pt);
1111 nm.dwItemData = 0;
1112 nm.dwHitInfo = 0x30000; /* seems constant */
1114 /* Do default processing if WM_NOTIFY returns zero */
1115 if(!SendMessageW(infoPtr->Notify, WM_NOTIFY, nm.hdr.idFrom, (LPARAM)&nm))
1117 return DefWindowProcW(infoPtr->Self, msg, wParam, lParam);
1119 return 0;
1124 static LRESULT WINAPI
1125 StatusWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1127 STATUS_INFO *infoPtr = (STATUS_INFO *)GetWindowLongPtrW (hwnd, 0);
1128 INT nPart = ((INT) wParam) & 0x00ff;
1129 LRESULT res;
1131 TRACE("hwnd %p, msg %x, wparam %Ix, lparam %Ix\n", hwnd, msg, wParam, lParam);
1133 if (!infoPtr && msg != WM_CREATE)
1134 return DefWindowProcW (hwnd, msg, wParam, lParam);
1136 switch (msg) {
1137 case SB_GETBORDERS:
1138 return STATUSBAR_GetBorders (infoPtr, (INT *)lParam);
1140 case SB_GETICON:
1141 return (LRESULT)STATUSBAR_GetIcon (infoPtr, nPart);
1143 case SB_GETPARTS:
1144 return STATUSBAR_GetParts (infoPtr, (INT)wParam, (INT *)lParam);
1146 case SB_GETRECT:
1147 return STATUSBAR_GetRect (infoPtr, nPart, (LPRECT)lParam);
1149 case SB_GETTEXTA:
1150 return STATUSBAR_GetTextA (infoPtr, nPart, (LPSTR)lParam);
1152 case SB_GETTEXTW:
1153 return STATUSBAR_GetTextW (infoPtr, nPart, (LPWSTR)lParam);
1155 case SB_GETTEXTLENGTHA:
1156 case SB_GETTEXTLENGTHW:
1157 return STATUSBAR_GetTextLength (infoPtr, nPart);
1159 case SB_GETTIPTEXTA:
1160 return STATUSBAR_GetTipTextA (infoPtr, LOWORD(wParam), (LPSTR)lParam, HIWORD(wParam));
1162 case SB_GETTIPTEXTW:
1163 return STATUSBAR_GetTipTextW (infoPtr, LOWORD(wParam), (LPWSTR)lParam, HIWORD(wParam));
1165 case SB_GETUNICODEFORMAT:
1166 return infoPtr->bUnicode;
1168 case SB_ISSIMPLE:
1169 return infoPtr->simple;
1171 case SB_SETBORDERS:
1172 return STATUSBAR_SetBorders (infoPtr, (INT *)lParam);
1174 case SB_SETBKCOLOR:
1175 return STATUSBAR_SetBkColor (infoPtr, (COLORREF)lParam);
1177 case SB_SETICON:
1178 return STATUSBAR_SetIcon (infoPtr, nPart, (HICON)lParam);
1180 case SB_SETMINHEIGHT:
1181 return STATUSBAR_SetMinHeight (infoPtr, (INT)wParam);
1183 case SB_SETPARTS:
1184 return STATUSBAR_SetParts (infoPtr, (INT)wParam, (LPINT)lParam);
1186 case SB_SETTEXTA:
1187 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPWSTR)lParam, FALSE);
1189 case SB_SETTEXTW:
1190 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPWSTR)lParam, TRUE);
1192 case SB_SETTIPTEXTA:
1193 return STATUSBAR_SetTipTextA (infoPtr, (INT)wParam, (LPSTR)lParam);
1195 case SB_SETTIPTEXTW:
1196 return STATUSBAR_SetTipTextW (infoPtr, (INT)wParam, (LPWSTR)lParam);
1198 case SB_SETUNICODEFORMAT:
1199 return STATUSBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1201 case SB_SIMPLE:
1202 return STATUSBAR_Simple (infoPtr, (BOOL)wParam);
1204 case WM_CREATE:
1205 return STATUSBAR_WMCreate (hwnd, (LPCREATESTRUCTA)lParam);
1207 case WM_DESTROY:
1208 return STATUSBAR_WMDestroy (infoPtr);
1210 case WM_GETFONT:
1211 return (LRESULT)(infoPtr->hFont? infoPtr->hFont : infoPtr->hDefaultFont);
1213 case WM_GETTEXT:
1214 return STATUSBAR_WMGetText (infoPtr, (INT)wParam, (LPWSTR)lParam);
1216 case WM_GETTEXTLENGTH:
1217 return LOWORD(STATUSBAR_GetTextLength (infoPtr, 0));
1219 case WM_LBUTTONDBLCLK:
1220 return STATUSBAR_SendMouseNotify(infoPtr, NM_DBLCLK, msg, wParam, lParam);
1222 case WM_LBUTTONUP:
1223 return STATUSBAR_SendMouseNotify(infoPtr, NM_CLICK, msg, wParam, lParam);
1225 case WM_MOUSEMOVE:
1226 return STATUSBAR_Relay2Tip (infoPtr, msg, wParam, lParam);
1228 case WM_NCHITTEST:
1229 res = STATUSBAR_WMNCHitTest(infoPtr, (short)LOWORD(lParam),
1230 (short)HIWORD(lParam));
1231 if (res != HTERROR) return res;
1232 return DefWindowProcW (hwnd, msg, wParam, lParam);
1234 case WM_NCLBUTTONUP:
1235 case WM_NCLBUTTONDOWN:
1236 PostMessageW (infoPtr->Notify, msg, wParam, lParam);
1237 return 0;
1239 case WM_NOTIFYFORMAT:
1240 return STATUSBAR_NotifyFormat(infoPtr, (HWND)wParam, (INT)lParam);
1242 case WM_PRINTCLIENT:
1243 case WM_PAINT:
1244 return STATUSBAR_WMPaint (infoPtr, (HDC)wParam);
1246 case WM_RBUTTONDBLCLK:
1247 return STATUSBAR_SendMouseNotify(infoPtr, NM_RDBLCLK, msg, wParam, lParam);
1249 case WM_RBUTTONUP:
1250 return STATUSBAR_SendMouseNotify(infoPtr, NM_RCLICK, msg, wParam, lParam);
1252 case WM_SETFONT:
1253 return STATUSBAR_WMSetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
1255 case WM_SETTEXT:
1256 return STATUSBAR_WMSetText (infoPtr, (LPCSTR)lParam);
1258 case WM_SIZE:
1259 if (STATUSBAR_WMSize (infoPtr, (WORD)wParam)) return 0;
1260 return DefWindowProcW (hwnd, msg, wParam, lParam);
1262 case WM_SYSCOLORCHANGE:
1263 COMCTL32_RefreshSysColors();
1264 return 0;
1266 case WM_THEMECHANGED:
1267 return theme_changed (infoPtr);
1269 default:
1270 if ((msg >= WM_USER) && (msg < WM_APP) && !COMCTL32_IsReflectedMessage(msg))
1271 ERR("unknown msg %04x wp=%Ix lp=%Ix\n", msg, wParam, lParam);
1272 return DefWindowProcW (hwnd, msg, wParam, lParam);
1277 /***********************************************************************
1278 * STATUS_Register [Internal]
1280 * Registers the status window class.
1283 void
1284 STATUS_Register (void)
1286 WNDCLASSW wndClass;
1288 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1289 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW;
1290 wndClass.lpfnWndProc = StatusWindowProc;
1291 wndClass.cbClsExtra = 0;
1292 wndClass.cbWndExtra = sizeof(STATUS_INFO *);
1293 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1294 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
1295 wndClass.lpszClassName = STATUSCLASSNAMEW;
1297 RegisterClassW (&wndClass);
1301 /***********************************************************************
1302 * STATUS_Unregister [Internal]
1304 * Unregisters the status window class.
1307 void
1308 STATUS_Unregister (void)
1310 UnregisterClassW (STATUSCLASSNAMEW, NULL);