wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / comctl32 / status.c
blob0c3a90887c85cc9d6fcb0a9c8af7f6ec70075d2a
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 HTHEME theme;
106 UINT height;
107 TEXTMETRICW tm;
108 int margin;
110 COMCTL32_GetFontMetrics(infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont, &tm);
111 margin = (tm.tmInternalLeading ? tm.tmInternalLeading : 2);
112 height = max(tm.tmHeight + margin + 2*GetSystemMetrics(SM_CYBORDER), infoPtr->minHeight) + infoPtr->verticalBorder;
114 if ((theme = GetWindowTheme(infoPtr->Self)))
116 /* Determine bar height from theme such that the content area is
117 * textHeight pixels large */
118 HDC hdc = GetDC(infoPtr->Self);
119 RECT r;
121 SetRect(&r, 0, 0, 0, max(infoPtr->minHeight, tm.tmHeight));
122 if (SUCCEEDED(GetThemeBackgroundExtent(theme, hdc, SP_PANE, 0, &r, &r)))
124 height = r.bottom - r.top;
126 ReleaseDC(infoPtr->Self, hdc);
129 TRACE(" textHeight=%d+%d, final height=%d\n", tm.tmHeight, tm.tmInternalLeading, height);
130 return height;
133 static void
134 STATUSBAR_DrawSizeGrip (HTHEME theme, HDC hdc, LPRECT lpRect)
136 RECT rc = *lpRect;
138 TRACE("draw size grip %s\n", wine_dbgstr_rect(lpRect));
140 if (theme)
142 SIZE gripperSize;
143 if (SUCCEEDED (GetThemePartSize (theme, hdc, SP_GRIPPER, 0, lpRect,
144 TS_DRAW, &gripperSize)))
146 rc.left = rc.right - gripperSize.cx;
147 rc.top = rc.bottom - gripperSize.cy;
148 if (SUCCEEDED (DrawThemeBackground(theme, hdc, SP_GRIPPER, 0, &rc, NULL)))
149 return;
153 rc.left = max( rc.left, rc.right - GetSystemMetrics(SM_CXVSCROLL) - 1 );
154 rc.top = max( rc.top, rc.bottom - GetSystemMetrics(SM_CYHSCROLL) - 1 );
155 DrawFrameControl( hdc, &rc, DFC_SCROLL, DFCS_SCROLLSIZEGRIP );
159 static void
160 STATUSBAR_DrawPart (const STATUS_INFO *infoPtr, HDC hdc, const STATUSWINDOWPART *part, int itemID)
162 RECT r = part->bound;
163 UINT border = BDR_SUNKENOUTER;
164 HTHEME theme = GetWindowTheme (infoPtr->Self);
165 int themePart = SP_PANE;
166 int x = 0;
168 TRACE("part bound %s\n", wine_dbgstr_rect(&r));
169 if (part->style & SBT_POPOUT)
170 border = BDR_RAISEDOUTER;
171 else if (part->style & SBT_NOBORDERS)
172 border = 0;
174 if (theme)
176 if ((GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
177 && (infoPtr->simple || (itemID == (infoPtr->numParts-1))))
178 themePart = SP_GRIPPERPANE;
179 DrawThemeBackground(theme, hdc, themePart, 0, &r, NULL);
181 else
182 DrawEdge(hdc, &r, border, BF_RECT|BF_ADJUST);
184 if (part->hIcon) {
185 INT cy = r.bottom - r.top;
186 DrawIconEx (hdc, r.left + 2, r.top, part->hIcon, cy, cy, 0, 0, DI_NORMAL);
187 x = 2 + cy;
190 if (part->style & SBT_OWNERDRAW) {
191 DRAWITEMSTRUCT dis;
193 dis.CtlID = GetWindowLongPtrW (infoPtr->Self, GWLP_ID);
194 dis.itemID = itemID;
195 dis.hwndItem = infoPtr->Self;
196 dis.hDC = hdc;
197 dis.rcItem = r;
198 dis.itemData = (ULONG_PTR)part->text;
199 SendMessageW (infoPtr->Notify, WM_DRAWITEM, dis.CtlID, (LPARAM)&dis);
200 } else {
201 r.left += x;
202 DrawStatusTextW (hdc, &r, part->text, SBT_NOBORDERS);
207 static void
208 STATUSBAR_RefreshPart (const STATUS_INFO *infoPtr, HDC hdc, const STATUSWINDOWPART *part, int itemID)
210 HBRUSH hbrBk;
211 HTHEME theme;
213 TRACE("item %d\n", itemID);
215 if (part->bound.right < part->bound.left) return;
217 if (!RectVisible(hdc, &part->bound))
218 return;
220 if ((theme = GetWindowTheme (infoPtr->Self)))
222 RECT cr;
223 GetClientRect (infoPtr->Self, &cr);
224 DrawThemeBackground(theme, hdc, 0, 0, &cr, &part->bound);
226 else
228 if (infoPtr->clrBk != CLR_DEFAULT)
229 hbrBk = CreateSolidBrush (infoPtr->clrBk);
230 else
231 hbrBk = GetSysColorBrush (COLOR_3DFACE);
232 FillRect(hdc, &part->bound, hbrBk);
233 if (infoPtr->clrBk != CLR_DEFAULT)
234 DeleteObject (hbrBk);
237 STATUSBAR_DrawPart (infoPtr, hdc, part, itemID);
241 static LRESULT
242 STATUSBAR_Refresh (STATUS_INFO *infoPtr, HDC hdc)
244 RECT rect;
245 HBRUSH hbrBk;
246 HFONT hOldFont;
247 HTHEME theme;
249 TRACE("\n");
250 if (!IsWindowVisible(infoPtr->Self))
251 return 0;
253 STATUSBAR_SetPartBounds(infoPtr);
255 GetClientRect (infoPtr->Self, &rect);
257 if ((theme = GetWindowTheme (infoPtr->Self)))
259 DrawThemeBackground(theme, hdc, 0, 0, &rect, NULL);
261 else
263 if (infoPtr->clrBk != CLR_DEFAULT)
264 hbrBk = CreateSolidBrush (infoPtr->clrBk);
265 else
266 hbrBk = GetSysColorBrush (COLOR_3DFACE);
267 FillRect(hdc, &rect, hbrBk);
268 if (infoPtr->clrBk != CLR_DEFAULT)
269 DeleteObject (hbrBk);
272 hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
274 if (infoPtr->simple) {
275 STATUSBAR_RefreshPart (infoPtr, hdc, &infoPtr->part0, 0);
276 } else {
277 unsigned int i;
279 for (i = 0; i < infoPtr->numParts; i++) {
280 STATUSBAR_RefreshPart (infoPtr, hdc, &infoPtr->parts[i], i);
284 SelectObject (hdc, hOldFont);
286 if ((GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
287 && !(GetWindowLongW (infoPtr->Notify, GWL_STYLE) & WS_MAXIMIZE))
288 STATUSBAR_DrawSizeGrip (theme, hdc, &rect);
290 return 0;
294 static int
295 STATUSBAR_InternalHitTest(const STATUS_INFO *infoPtr, const POINT *pt)
297 unsigned int i;
299 if (infoPtr->simple)
300 return 255;
302 for (i = 0; i < infoPtr->numParts; i++)
303 if (pt->x >= infoPtr->parts[i].bound.left && pt->x <= infoPtr->parts[i].bound.right)
304 return i;
305 return -2;
309 static void
310 STATUSBAR_SetPartBounds (STATUS_INFO *infoPtr)
312 STATUSWINDOWPART *part;
313 RECT rect, *r;
314 UINT i;
316 /* get our window size */
317 GetClientRect (infoPtr->Self, &rect);
318 TRACE("client wnd size is %s\n", wine_dbgstr_rect(&rect));
320 rect.left += infoPtr->horizontalBorder;
321 rect.top += infoPtr->verticalBorder;
323 /* set bounds for simple rectangle */
324 infoPtr->part0.bound = rect;
326 /* set bounds for non-simple rectangles */
327 for (i = 0; i < infoPtr->numParts; i++) {
328 part = &infoPtr->parts[i];
329 r = &infoPtr->parts[i].bound;
330 r->top = rect.top;
331 r->bottom = rect.bottom;
332 if (i == 0)
333 r->left = 0;
334 else
335 r->left = infoPtr->parts[i-1].bound.right + infoPtr->horizontalGap;
336 if (part->x == -1)
337 r->right = rect.right;
338 else
339 r->right = part->x;
341 if (infoPtr->hwndToolTip) {
342 TTTOOLINFOW ti;
344 ti.cbSize = sizeof(TTTOOLINFOW);
345 ti.hwnd = infoPtr->Self;
346 ti.uId = i;
347 ti.rect = *r;
348 SendMessageW (infoPtr->hwndToolTip, TTM_NEWTOOLRECTW,
349 0, (LPARAM)&ti);
355 static LRESULT
356 STATUSBAR_Relay2Tip (const STATUS_INFO *infoPtr, UINT uMsg,
357 WPARAM wParam, LPARAM lParam)
359 MSG msg;
361 msg.hwnd = infoPtr->Self;
362 msg.message = uMsg;
363 msg.wParam = wParam;
364 msg.lParam = lParam;
365 msg.time = GetMessageTime ();
366 msg.pt.x = (short)LOWORD(GetMessagePos ());
367 msg.pt.y = (short)HIWORD(GetMessagePos ());
369 return SendMessageW (infoPtr->hwndToolTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
373 static BOOL
374 STATUSBAR_GetBorders (const STATUS_INFO *infoPtr, INT out[])
376 TRACE("\n");
377 out[0] = infoPtr->horizontalBorder;
378 out[1] = infoPtr->verticalBorder;
379 out[2] = infoPtr->horizontalGap;
381 return TRUE;
385 static BOOL
386 STATUSBAR_SetBorders (STATUS_INFO *infoPtr, const INT in[])
388 TRACE("\n");
389 infoPtr->horizontalBorder = in[0];
390 infoPtr->verticalBorder = in[1];
391 infoPtr->horizontalGap = in[2];
392 InvalidateRect(infoPtr->Self, NULL, FALSE);
394 return TRUE;
398 static HICON
399 STATUSBAR_GetIcon (const STATUS_INFO *infoPtr, INT nPart)
401 TRACE("%d\n", nPart);
402 /* MSDN says: "simple parts are indexed with -1" */
403 if ((nPart < -1) || (nPart >= infoPtr->numParts))
404 return 0;
406 if (nPart == -1)
407 return (infoPtr->part0.hIcon);
408 else
409 return (infoPtr->parts[nPart].hIcon);
413 static INT
414 STATUSBAR_GetParts (const STATUS_INFO *infoPtr, INT num_parts, INT parts[])
416 INT i;
418 TRACE("(%d)\n", num_parts);
419 if (parts) {
420 for (i = 0; i < num_parts; i++) {
421 parts[i] = infoPtr->parts[i].x;
424 return infoPtr->numParts;
428 static BOOL
429 STATUSBAR_GetRect (const STATUS_INFO *infoPtr, INT nPart, LPRECT rect)
431 TRACE("part %d\n", nPart);
432 if(nPart >= infoPtr->numParts || nPart < 0)
433 return FALSE;
434 if (infoPtr->simple)
435 *rect = infoPtr->part0.bound;
436 else
437 *rect = infoPtr->parts[nPart].bound;
438 return TRUE;
442 static LRESULT
443 STATUSBAR_GetTextA (STATUS_INFO *infoPtr, INT nPart, LPSTR buf)
445 STATUSWINDOWPART *part;
446 LRESULT result;
448 TRACE("part %d\n", nPart);
450 /* MSDN says: "simple parts use index of 0", so this check is ok. */
451 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
453 if (infoPtr->simple)
454 part = &infoPtr->part0;
455 else
456 part = &infoPtr->parts[nPart];
458 if (part->style & SBT_OWNERDRAW)
459 result = (LRESULT)part->text;
460 else {
461 DWORD len = part->text ? WideCharToMultiByte( CP_ACP, 0, part->text, -1,
462 NULL, 0, NULL, NULL ) - 1 : 0;
463 result = MAKELONG( len, part->style );
464 if (part->text && buf)
465 WideCharToMultiByte( CP_ACP, 0, part->text, -1, buf, len+1, NULL, NULL );
467 return result;
471 static LRESULT
472 STATUSBAR_GetTextW (STATUS_INFO *infoPtr, INT nPart, LPWSTR buf)
474 STATUSWINDOWPART *part;
475 LRESULT result;
477 TRACE("part %d\n", nPart);
478 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
480 if (infoPtr->simple)
481 part = &infoPtr->part0;
482 else
483 part = &infoPtr->parts[nPart];
485 if (part->style & SBT_OWNERDRAW)
486 result = (LRESULT)part->text;
487 else {
488 result = part->text ? lstrlenW (part->text) : 0;
489 result |= (part->style << 16);
490 if (part->text && buf)
491 lstrcpyW (buf, part->text);
493 return result;
497 static LRESULT
498 STATUSBAR_GetTextLength (STATUS_INFO *infoPtr, INT nPart)
500 STATUSWINDOWPART *part;
501 DWORD result;
503 TRACE("part %d\n", nPart);
505 /* MSDN says: "simple parts use index of 0", so this check is ok. */
506 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
508 if (infoPtr->simple)
509 part = &infoPtr->part0;
510 else
511 part = &infoPtr->parts[nPart];
513 if ((~part->style & SBT_OWNERDRAW) && part->text)
514 result = lstrlenW(part->text);
515 else
516 result = 0;
518 result |= (part->style << 16);
519 return result;
522 static LRESULT
523 STATUSBAR_GetTipTextA (const STATUS_INFO *infoPtr, INT id, LPSTR tip, INT size)
525 TRACE("\n");
526 if (tip) {
527 CHAR buf[INFOTIPSIZE];
528 buf[0]='\0';
530 if (infoPtr->hwndToolTip) {
531 TTTOOLINFOA ti;
532 ti.cbSize = sizeof(TTTOOLINFOA);
533 ti.hwnd = infoPtr->Self;
534 ti.uId = id;
535 ti.lpszText = buf;
536 SendMessageA (infoPtr->hwndToolTip, TTM_GETTEXTA, 0, (LPARAM)&ti);
538 lstrcpynA (tip, buf, size);
540 return 0;
544 static LRESULT
545 STATUSBAR_GetTipTextW (const STATUS_INFO *infoPtr, INT id, LPWSTR tip, INT size)
547 TRACE("\n");
548 if (tip) {
549 WCHAR buf[INFOTIPSIZE];
550 buf[0]=0;
552 if (infoPtr->hwndToolTip) {
553 TTTOOLINFOW ti;
554 ti.cbSize = sizeof(TTTOOLINFOW);
555 ti.hwnd = infoPtr->Self;
556 ti.uId = id;
557 ti.lpszText = buf;
558 SendMessageW(infoPtr->hwndToolTip, TTM_GETTEXTW, 0, (LPARAM)&ti);
560 lstrcpynW(tip, buf, size);
563 return 0;
567 static COLORREF
568 STATUSBAR_SetBkColor (STATUS_INFO *infoPtr, COLORREF color)
570 COLORREF oldBkColor;
572 oldBkColor = infoPtr->clrBk;
573 infoPtr->clrBk = color;
574 InvalidateRect(infoPtr->Self, NULL, FALSE);
576 TRACE("CREF: %08x -> %08x\n", oldBkColor, infoPtr->clrBk);
577 return oldBkColor;
581 static BOOL
582 STATUSBAR_SetIcon (STATUS_INFO *infoPtr, INT nPart, HICON hIcon)
584 if ((nPart < -1) || (nPart >= infoPtr->numParts))
585 return FALSE;
587 TRACE("setting part %d\n", nPart);
589 /* FIXME: MSDN says "if nPart is -1, the status bar is assumed simple" */
590 if (nPart == -1) {
591 if (infoPtr->part0.hIcon == hIcon) /* same as - no redraw */
592 return TRUE;
593 infoPtr->part0.hIcon = hIcon;
594 if (infoPtr->simple)
595 InvalidateRect(infoPtr->Self, &infoPtr->part0.bound, FALSE);
596 } else {
597 if (infoPtr->parts[nPart].hIcon == hIcon) /* same as - no redraw */
598 return TRUE;
600 infoPtr->parts[nPart].hIcon = hIcon;
601 if (!(infoPtr->simple))
602 InvalidateRect(infoPtr->Self, &infoPtr->parts[nPart].bound, FALSE);
604 return TRUE;
608 static BOOL
609 STATUSBAR_SetMinHeight (STATUS_INFO *infoPtr, INT height)
611 DWORD ysize = GetSystemMetrics(SM_CYSIZE);
612 if (ysize & 1) ysize--;
613 infoPtr->minHeight = max(height, ysize);
614 infoPtr->height = STATUSBAR_ComputeHeight(infoPtr);
615 /* like native, don't resize the control */
616 return TRUE;
620 static BOOL
621 STATUSBAR_SetParts (STATUS_INFO *infoPtr, INT count, LPINT parts)
623 STATUSWINDOWPART *tmp;
624 INT i, oldNumParts;
626 TRACE("(%d,%p)\n", count, parts);
628 if(!count) return FALSE;
630 oldNumParts = infoPtr->numParts;
631 infoPtr->numParts = count;
632 if (oldNumParts > infoPtr->numParts) {
633 for (i = infoPtr->numParts ; i < oldNumParts; i++) {
634 if (!(infoPtr->parts[i].style & SBT_OWNERDRAW))
635 Free (infoPtr->parts[i].text);
637 } else if (oldNumParts < infoPtr->numParts) {
638 tmp = Alloc (sizeof(STATUSWINDOWPART) * infoPtr->numParts);
639 if (!tmp) return FALSE;
640 for (i = 0; i < oldNumParts; i++) {
641 tmp[i] = infoPtr->parts[i];
643 Free (infoPtr->parts);
644 infoPtr->parts = tmp;
646 if (oldNumParts == infoPtr->numParts) {
647 for (i=0; i < oldNumParts; i++)
648 if (infoPtr->parts[i].x != parts[i])
649 break;
650 if (i==oldNumParts) /* Unchanged? no need to redraw! */
651 return TRUE;
654 for (i = 0; i < infoPtr->numParts; i++)
655 infoPtr->parts[i].x = parts[i];
657 if (infoPtr->hwndToolTip) {
658 INT nTipCount;
659 TTTOOLINFOW ti;
660 WCHAR wEmpty[] = L"";
662 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
663 ti.cbSize = sizeof(TTTOOLINFOW);
664 ti.hwnd = infoPtr->Self;
665 ti.lpszText = wEmpty;
667 nTipCount = SendMessageW (infoPtr->hwndToolTip, TTM_GETTOOLCOUNT, 0, 0);
668 if (nTipCount < infoPtr->numParts) {
669 /* add tools */
670 for (i = nTipCount; i < infoPtr->numParts; i++) {
671 TRACE("add tool %d\n", i);
672 ti.uId = i;
673 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
674 0, (LPARAM)&ti);
677 else if (nTipCount > infoPtr->numParts) {
678 /* delete tools */
679 for (i = nTipCount - 1; i >= infoPtr->numParts; i--) {
680 TRACE("delete tool %d\n", i);
681 ti.uId = i;
682 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW,
683 0, (LPARAM)&ti);
687 STATUSBAR_SetPartBounds (infoPtr);
688 InvalidateRect(infoPtr->Self, NULL, FALSE);
689 return TRUE;
693 static BOOL
694 STATUSBAR_SetTextT (STATUS_INFO *infoPtr, INT nPart, WORD style,
695 LPWSTR text, BOOL isW)
697 STATUSWINDOWPART *part=NULL;
698 BOOL changed = FALSE;
699 INT oldStyle;
701 if (style & SBT_OWNERDRAW) {
702 TRACE("part %d, text %p\n",nPart,text);
704 else TRACE("part %d, text %s\n", nPart, debugstr_t(text, isW));
706 /* MSDN says: "If the parameter is set to SB_SIMPLEID (255), the status
707 * window is assumed to be a simple window */
709 if (nPart == 0x00ff) {
710 part = &infoPtr->part0;
711 } else {
712 if (infoPtr->parts && nPart >= 0 && nPart < infoPtr->numParts) {
713 part = &infoPtr->parts[nPart];
716 if (!part) return FALSE;
718 if (part->style != style)
719 changed = TRUE;
721 oldStyle = part->style;
722 part->style = style;
723 if (style & SBT_OWNERDRAW) {
724 if (!(oldStyle & SBT_OWNERDRAW))
725 Free (part->text);
726 part->text = text;
727 } else {
728 LPWSTR ntext;
729 WCHAR *idx;
731 if (text && !isW) {
732 LPCSTR atxt = (LPCSTR)text;
733 DWORD len = MultiByteToWideChar( CP_ACP, 0, atxt, -1, NULL, 0 );
734 ntext = Alloc( (len + 1)*sizeof(WCHAR) );
735 if (!ntext) return FALSE;
736 MultiByteToWideChar( CP_ACP, 0, atxt, -1, ntext, len );
737 } else if (text) {
738 ntext = Alloc( (lstrlenW(text) + 1)*sizeof(WCHAR) );
739 if (!ntext) return FALSE;
740 lstrcpyW (ntext, text);
741 } else ntext = 0;
743 /* replace nonprintable characters with spaces */
744 if (ntext) {
745 idx = ntext;
746 while (*idx) {
747 if(*idx < ' ' && *idx != '\t')
748 *idx = ' ';
749 idx++;
753 /* check if text is unchanged -> no need to redraw */
754 if (text) {
755 if (!changed && part->text && !lstrcmpW(ntext, part->text)) {
756 Free(ntext);
757 return TRUE;
759 } else {
760 if (!changed && !part->text)
761 return TRUE;
764 if (!(oldStyle & SBT_OWNERDRAW))
765 Free (part->text);
766 part->text = ntext;
768 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
769 UpdateWindow(infoPtr->Self);
771 return TRUE;
775 static LRESULT
776 STATUSBAR_SetTipTextA (const STATUS_INFO *infoPtr, INT id, LPSTR text)
778 TRACE("part %d: \"%s\"\n", id, text);
779 if (infoPtr->hwndToolTip) {
780 TTTOOLINFOA ti;
781 ti.cbSize = sizeof(TTTOOLINFOA);
782 ti.hwnd = infoPtr->Self;
783 ti.uId = id;
784 ti.hinst = 0;
785 ti.lpszText = text;
786 SendMessageA (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTA, 0, (LPARAM)&ti);
789 return 0;
793 static LRESULT
794 STATUSBAR_SetTipTextW (const STATUS_INFO *infoPtr, INT id, LPWSTR text)
796 TRACE("part %d: \"%s\"\n", id, debugstr_w(text));
797 if (infoPtr->hwndToolTip) {
798 TTTOOLINFOW ti;
799 ti.cbSize = sizeof(TTTOOLINFOW);
800 ti.hwnd = infoPtr->Self;
801 ti.uId = id;
802 ti.hinst = 0;
803 ti.lpszText = text;
804 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
807 return 0;
811 static inline LRESULT
812 STATUSBAR_SetUnicodeFormat (STATUS_INFO *infoPtr, BOOL bUnicode)
814 BOOL bOld = infoPtr->bUnicode;
816 TRACE("(0x%x)\n", bUnicode);
817 infoPtr->bUnicode = bUnicode;
819 return bOld;
823 static BOOL
824 STATUSBAR_Simple (STATUS_INFO *infoPtr, BOOL simple)
826 NMHDR nmhdr;
828 TRACE("(simple=%d)\n", simple);
829 if (infoPtr->simple == simple) /* no need to change */
830 return TRUE;
832 infoPtr->simple = simple;
834 /* send notification */
835 nmhdr.hwndFrom = infoPtr->Self;
836 nmhdr.idFrom = GetWindowLongPtrW (infoPtr->Self, GWLP_ID);
837 nmhdr.code = SBN_SIMPLEMODECHANGE;
838 SendMessageW (infoPtr->Notify, WM_NOTIFY, 0, (LPARAM)&nmhdr);
839 InvalidateRect(infoPtr->Self, NULL, FALSE);
840 return TRUE;
844 static LRESULT
845 STATUSBAR_WMDestroy (STATUS_INFO *infoPtr)
847 unsigned int i;
849 TRACE("\n");
850 for (i = 0; i < infoPtr->numParts; i++) {
851 if (!(infoPtr->parts[i].style & SBT_OWNERDRAW))
852 Free (infoPtr->parts[i].text);
854 if (!(infoPtr->part0.style & SBT_OWNERDRAW))
855 Free (infoPtr->part0.text);
856 Free (infoPtr->parts);
858 /* delete default font */
859 if (infoPtr->hDefaultFont)
860 DeleteObject (infoPtr->hDefaultFont);
862 /* delete tool tip control */
863 if (infoPtr->hwndToolTip)
864 DestroyWindow (infoPtr->hwndToolTip);
866 CloseThemeData (GetWindowTheme (infoPtr->Self));
868 SetWindowLongPtrW(infoPtr->Self, 0, 0);
869 Free (infoPtr);
870 return 0;
874 static LRESULT
875 STATUSBAR_WMCreate (HWND hwnd, const CREATESTRUCTA *lpCreate)
877 STATUS_INFO *infoPtr;
878 NONCLIENTMETRICSW nclm;
879 DWORD dwStyle;
880 RECT rect;
881 int len;
883 TRACE("\n");
884 infoPtr = Alloc (sizeof(STATUS_INFO));
885 if (!infoPtr) goto create_fail;
886 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
888 infoPtr->Self = hwnd;
889 infoPtr->Notify = lpCreate->hwndParent;
890 infoPtr->numParts = 1;
891 infoPtr->parts = 0;
892 infoPtr->simple = FALSE;
893 infoPtr->clrBk = CLR_DEFAULT;
894 infoPtr->hFont = 0;
895 infoPtr->horizontalBorder = HORZ_BORDER;
896 infoPtr->verticalBorder = VERT_BORDER;
897 infoPtr->horizontalGap = HORZ_GAP;
898 infoPtr->minHeight = GetSystemMetrics(SM_CYSIZE);
899 if (infoPtr->minHeight & 1) infoPtr->minHeight--;
901 STATUSBAR_NotifyFormat(infoPtr, infoPtr->Notify, NF_REQUERY);
903 ZeroMemory (&nclm, sizeof(nclm));
904 nclm.cbSize = sizeof(nclm);
905 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, nclm.cbSize, &nclm, 0);
906 infoPtr->hDefaultFont = CreateFontIndirectW (&nclm.lfStatusFont);
908 GetClientRect (hwnd, &rect);
910 /* initialize simple case */
911 infoPtr->part0.bound = rect;
912 infoPtr->part0.text = 0;
913 infoPtr->part0.x = 0;
914 infoPtr->part0.style = 0;
915 infoPtr->part0.hIcon = 0;
917 /* initialize first part */
918 infoPtr->parts = Alloc (sizeof(STATUSWINDOWPART));
919 if (!infoPtr->parts) goto create_fail;
920 infoPtr->parts[0].bound = rect;
921 infoPtr->parts[0].text = 0;
922 infoPtr->parts[0].x = -1;
923 infoPtr->parts[0].style = 0;
924 infoPtr->parts[0].hIcon = 0;
926 OpenThemeData (hwnd, themeClass);
928 if (lpCreate->lpszName && (len = lstrlenW ((LPCWSTR)lpCreate->lpszName)))
930 infoPtr->parts[0].text = Alloc ((len + 1)*sizeof(WCHAR));
931 if (!infoPtr->parts[0].text) goto create_fail;
932 lstrcpyW (infoPtr->parts[0].text, (LPCWSTR)lpCreate->lpszName);
935 dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
936 /* native seems to clear WS_BORDER, too */
937 dwStyle &= ~WS_BORDER;
938 SetWindowLongW (hwnd, GWL_STYLE, dwStyle);
940 infoPtr->height = STATUSBAR_ComputeHeight(infoPtr);
942 if (dwStyle & SBT_TOOLTIPS) {
943 infoPtr->hwndToolTip =
944 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, WS_POPUP | TTS_ALWAYSTIP,
945 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
946 CW_USEDEFAULT, hwnd, 0,
947 (HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE), NULL);
949 if (infoPtr->hwndToolTip) {
950 NMTOOLTIPSCREATED nmttc;
952 nmttc.hdr.hwndFrom = hwnd;
953 nmttc.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
954 nmttc.hdr.code = NM_TOOLTIPSCREATED;
955 nmttc.hwndToolTips = infoPtr->hwndToolTip;
957 SendMessageW (lpCreate->hwndParent, WM_NOTIFY, nmttc.hdr.idFrom, (LPARAM)&nmttc);
961 return 0;
963 create_fail:
964 TRACE(" failed!\n");
965 if (infoPtr) STATUSBAR_WMDestroy(infoPtr);
966 return -1;
970 /* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
971 * of the first part only (usual behaviour) */
972 static INT
973 STATUSBAR_WMGetText (const STATUS_INFO *infoPtr, INT size, LPWSTR buf)
975 INT len;
977 TRACE("\n");
978 if (!(infoPtr->parts[0].text))
979 return 0;
981 len = lstrlenW (infoPtr->parts[0].text);
983 if (!size)
984 return len;
985 else if (size > len) {
986 lstrcpyW (buf, infoPtr->parts[0].text);
987 return len;
989 else {
990 memcpy (buf, infoPtr->parts[0].text, (size - 1) * sizeof(WCHAR));
991 buf[size - 1] = 0;
992 return size - 1;
997 static BOOL
998 STATUSBAR_WMNCHitTest (const STATUS_INFO *infoPtr, INT x, INT y)
1000 if ((GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
1001 && !(GetWindowLongW (infoPtr->Notify, GWL_STYLE) & WS_MAXIMIZE)) {
1002 RECT rect;
1003 POINT pt;
1005 GetClientRect (infoPtr->Self, &rect);
1007 pt.x = x;
1008 pt.y = y;
1009 ScreenToClient (infoPtr->Self, &pt);
1011 if (pt.x >= rect.right - GetSystemMetrics(SM_CXVSCROLL))
1013 if (GetWindowLongW( infoPtr->Self, GWL_EXSTYLE ) & WS_EX_LAYOUTRTL) return HTBOTTOMLEFT;
1014 else return HTBOTTOMRIGHT;
1018 return HTERROR;
1022 static LRESULT
1023 STATUSBAR_WMPaint (STATUS_INFO *infoPtr, HDC hdc)
1025 PAINTSTRUCT ps;
1027 TRACE("\n");
1028 if (hdc) return STATUSBAR_Refresh (infoPtr, hdc);
1029 hdc = BeginPaint (infoPtr->Self, &ps);
1030 STATUSBAR_Refresh (infoPtr, hdc);
1031 EndPaint (infoPtr->Self, &ps);
1033 return 0;
1037 static LRESULT
1038 STATUSBAR_WMSetFont (STATUS_INFO *infoPtr, HFONT font, BOOL redraw)
1040 infoPtr->hFont = font;
1041 TRACE("%p\n", infoPtr->hFont);
1043 infoPtr->height = STATUSBAR_ComputeHeight(infoPtr);
1044 SendMessageW(infoPtr->Self, WM_SIZE, 0, 0); /* update size */
1045 if (redraw)
1046 InvalidateRect(infoPtr->Self, NULL, FALSE);
1048 return 0;
1052 static BOOL
1053 STATUSBAR_WMSetText (const STATUS_INFO *infoPtr, LPCSTR text)
1055 STATUSWINDOWPART *part;
1056 int len;
1058 TRACE("\n");
1059 if (infoPtr->numParts == 0)
1060 return FALSE;
1062 part = &infoPtr->parts[0];
1063 /* duplicate string */
1064 Free (part->text);
1065 part->text = 0;
1067 if (text && (len = lstrlenW((LPCWSTR)text))) {
1068 part->text = Alloc ((len+1)*sizeof(WCHAR));
1069 if (!part->text) return FALSE;
1070 lstrcpyW (part->text, (LPCWSTR)text);
1073 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
1075 return TRUE;
1079 static BOOL
1080 STATUSBAR_WMSize (STATUS_INFO *infoPtr, WORD flags)
1082 INT width, x, y;
1083 RECT parent_rect;
1085 /* Need to resize width to match parent */
1086 TRACE("flags %04x\n", flags);
1088 if (flags != SIZE_RESTORED && flags != SIZE_MAXIMIZED) {
1089 WARN("flags MUST be SIZE_RESTORED or SIZE_MAXIMIZED\n");
1090 return FALSE;
1093 if (GetWindowLongW(infoPtr->Self, GWL_STYLE) & CCS_NORESIZE) return FALSE;
1095 /* width and height don't apply */
1096 if (!GetClientRect (infoPtr->Notify, &parent_rect))
1097 return FALSE;
1099 width = parent_rect.right - parent_rect.left;
1100 x = parent_rect.left;
1101 y = parent_rect.bottom - infoPtr->height;
1102 MoveWindow (infoPtr->Self, x, y, width, infoPtr->height, TRUE);
1103 STATUSBAR_SetPartBounds (infoPtr);
1104 return TRUE;
1108 /* update theme after a WM_THEMECHANGED message */
1109 static LRESULT theme_changed (const STATUS_INFO* infoPtr)
1111 HTHEME theme = GetWindowTheme (infoPtr->Self);
1112 CloseThemeData (theme);
1113 OpenThemeData (infoPtr->Self, themeClass);
1114 return 0;
1118 static LRESULT
1119 STATUSBAR_NotifyFormat (STATUS_INFO *infoPtr, HWND from, INT cmd)
1121 if (cmd == NF_REQUERY) {
1122 INT i = SendMessageW(from, WM_NOTIFYFORMAT, (WPARAM)infoPtr->Self, NF_QUERY);
1123 infoPtr->bUnicode = (i == NFR_UNICODE);
1125 return infoPtr->bUnicode ? NFR_UNICODE : NFR_ANSI;
1129 static LRESULT
1130 STATUSBAR_SendMouseNotify(const STATUS_INFO *infoPtr, UINT code, UINT msg, WPARAM wParam, LPARAM lParam)
1132 NMMOUSE nm;
1134 TRACE("code %04x, lParam=%lx\n", code, lParam);
1135 nm.hdr.hwndFrom = infoPtr->Self;
1136 nm.hdr.idFrom = GetWindowLongPtrW(infoPtr->Self, GWLP_ID);
1137 nm.hdr.code = code;
1138 nm.pt.x = (short)LOWORD(lParam);
1139 nm.pt.y = (short)HIWORD(lParam);
1140 nm.dwItemSpec = STATUSBAR_InternalHitTest(infoPtr, &nm.pt);
1141 nm.dwItemData = 0;
1142 nm.dwHitInfo = 0x30000; /* seems constant */
1144 /* Do default processing if WM_NOTIFY returns zero */
1145 if(!SendMessageW(infoPtr->Notify, WM_NOTIFY, nm.hdr.idFrom, (LPARAM)&nm))
1147 return DefWindowProcW(infoPtr->Self, msg, wParam, lParam);
1149 return 0;
1154 static LRESULT WINAPI
1155 StatusWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1157 STATUS_INFO *infoPtr = (STATUS_INFO *)GetWindowLongPtrW (hwnd, 0);
1158 INT nPart = ((INT) wParam) & 0x00ff;
1159 LRESULT res;
1161 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd, msg, wParam, lParam);
1162 if (!infoPtr && msg != WM_CREATE)
1163 return DefWindowProcW (hwnd, msg, wParam, lParam);
1165 switch (msg) {
1166 case SB_GETBORDERS:
1167 return STATUSBAR_GetBorders (infoPtr, (INT *)lParam);
1169 case SB_GETICON:
1170 return (LRESULT)STATUSBAR_GetIcon (infoPtr, nPart);
1172 case SB_GETPARTS:
1173 return STATUSBAR_GetParts (infoPtr, (INT)wParam, (INT *)lParam);
1175 case SB_GETRECT:
1176 return STATUSBAR_GetRect (infoPtr, nPart, (LPRECT)lParam);
1178 case SB_GETTEXTA:
1179 return STATUSBAR_GetTextA (infoPtr, nPart, (LPSTR)lParam);
1181 case SB_GETTEXTW:
1182 return STATUSBAR_GetTextW (infoPtr, nPart, (LPWSTR)lParam);
1184 case SB_GETTEXTLENGTHA:
1185 case SB_GETTEXTLENGTHW:
1186 return STATUSBAR_GetTextLength (infoPtr, nPart);
1188 case SB_GETTIPTEXTA:
1189 return STATUSBAR_GetTipTextA (infoPtr, LOWORD(wParam), (LPSTR)lParam, HIWORD(wParam));
1191 case SB_GETTIPTEXTW:
1192 return STATUSBAR_GetTipTextW (infoPtr, LOWORD(wParam), (LPWSTR)lParam, HIWORD(wParam));
1194 case SB_GETUNICODEFORMAT:
1195 return infoPtr->bUnicode;
1197 case SB_ISSIMPLE:
1198 return infoPtr->simple;
1200 case SB_SETBORDERS:
1201 return STATUSBAR_SetBorders (infoPtr, (INT *)lParam);
1203 case SB_SETBKCOLOR:
1204 return STATUSBAR_SetBkColor (infoPtr, (COLORREF)lParam);
1206 case SB_SETICON:
1207 return STATUSBAR_SetIcon (infoPtr, nPart, (HICON)lParam);
1209 case SB_SETMINHEIGHT:
1210 return STATUSBAR_SetMinHeight (infoPtr, (INT)wParam);
1212 case SB_SETPARTS:
1213 return STATUSBAR_SetParts (infoPtr, (INT)wParam, (LPINT)lParam);
1215 case SB_SETTEXTA:
1216 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPWSTR)lParam, FALSE);
1218 case SB_SETTEXTW:
1219 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPWSTR)lParam, TRUE);
1221 case SB_SETTIPTEXTA:
1222 return STATUSBAR_SetTipTextA (infoPtr, (INT)wParam, (LPSTR)lParam);
1224 case SB_SETTIPTEXTW:
1225 return STATUSBAR_SetTipTextW (infoPtr, (INT)wParam, (LPWSTR)lParam);
1227 case SB_SETUNICODEFORMAT:
1228 return STATUSBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1230 case SB_SIMPLE:
1231 return STATUSBAR_Simple (infoPtr, (BOOL)wParam);
1233 case WM_CREATE:
1234 return STATUSBAR_WMCreate (hwnd, (LPCREATESTRUCTA)lParam);
1236 case WM_DESTROY:
1237 return STATUSBAR_WMDestroy (infoPtr);
1239 case WM_GETFONT:
1240 return (LRESULT)(infoPtr->hFont? infoPtr->hFont : infoPtr->hDefaultFont);
1242 case WM_GETTEXT:
1243 return STATUSBAR_WMGetText (infoPtr, (INT)wParam, (LPWSTR)lParam);
1245 case WM_GETTEXTLENGTH:
1246 return LOWORD(STATUSBAR_GetTextLength (infoPtr, 0));
1248 case WM_LBUTTONDBLCLK:
1249 return STATUSBAR_SendMouseNotify(infoPtr, NM_DBLCLK, msg, wParam, lParam);
1251 case WM_LBUTTONUP:
1252 return STATUSBAR_SendMouseNotify(infoPtr, NM_CLICK, msg, wParam, lParam);
1254 case WM_MOUSEMOVE:
1255 return STATUSBAR_Relay2Tip (infoPtr, msg, wParam, lParam);
1257 case WM_NCHITTEST:
1258 res = STATUSBAR_WMNCHitTest(infoPtr, (short)LOWORD(lParam),
1259 (short)HIWORD(lParam));
1260 if (res != HTERROR) return res;
1261 return DefWindowProcW (hwnd, msg, wParam, lParam);
1263 case WM_NCLBUTTONUP:
1264 case WM_NCLBUTTONDOWN:
1265 PostMessageW (infoPtr->Notify, msg, wParam, lParam);
1266 return 0;
1268 case WM_NOTIFYFORMAT:
1269 return STATUSBAR_NotifyFormat(infoPtr, (HWND)wParam, (INT)lParam);
1271 case WM_PRINTCLIENT:
1272 case WM_PAINT:
1273 return STATUSBAR_WMPaint (infoPtr, (HDC)wParam);
1275 case WM_RBUTTONDBLCLK:
1276 return STATUSBAR_SendMouseNotify(infoPtr, NM_RDBLCLK, msg, wParam, lParam);
1278 case WM_RBUTTONUP:
1279 return STATUSBAR_SendMouseNotify(infoPtr, NM_RCLICK, msg, wParam, lParam);
1281 case WM_SETFONT:
1282 return STATUSBAR_WMSetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
1284 case WM_SETTEXT:
1285 return STATUSBAR_WMSetText (infoPtr, (LPCSTR)lParam);
1287 case WM_SIZE:
1288 if (STATUSBAR_WMSize (infoPtr, (WORD)wParam)) return 0;
1289 return DefWindowProcW (hwnd, msg, wParam, lParam);
1291 case WM_SYSCOLORCHANGE:
1292 COMCTL32_RefreshSysColors();
1293 return 0;
1295 case WM_THEMECHANGED:
1296 return theme_changed (infoPtr);
1298 default:
1299 if ((msg >= WM_USER) && (msg < WM_APP) && !COMCTL32_IsReflectedMessage(msg))
1300 ERR("unknown msg %04x wp=%04lx lp=%08lx\n",
1301 msg, wParam, lParam);
1302 return DefWindowProcW (hwnd, msg, wParam, lParam);
1307 /***********************************************************************
1308 * STATUS_Register [Internal]
1310 * Registers the status window class.
1313 void
1314 STATUS_Register (void)
1316 WNDCLASSW wndClass;
1318 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1319 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW;
1320 wndClass.lpfnWndProc = StatusWindowProc;
1321 wndClass.cbClsExtra = 0;
1322 wndClass.cbWndExtra = sizeof(STATUS_INFO *);
1323 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1324 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
1325 wndClass.lpszClassName = STATUSCLASSNAMEW;
1327 RegisterClassW (&wndClass);
1331 /***********************************************************************
1332 * STATUS_Unregister [Internal]
1334 * Unregisters the status window class.
1337 void
1338 STATUS_Unregister (void)
1340 UnregisterClassW (STATUSCLASSNAMEW, NULL);