cryptui: Implement specifying the destination store in CryptUIWizImport.
[wine/wine64.git] / dlls / comctl32 / status.c
blobd107329922fc250cc943f6b691a563d1a5190ea9
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 "tmschema.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
98 #define MIN_PANE_HEIGHT 18
100 static const WCHAR themeClass[] = { 'S','t','a','t','u','s',0 };
102 /* prototype */
103 static void
104 STATUSBAR_SetPartBounds (STATUS_INFO *infoPtr);
105 static LRESULT
106 STATUSBAR_NotifyFormat (STATUS_INFO *infoPtr, HWND from, INT cmd);
108 static inline LPCSTR debugstr_t(LPCWSTR text, BOOL isW)
110 return isW ? debugstr_w(text) : debugstr_a((LPCSTR)text);
113 static UINT
114 STATUSBAR_ComputeHeight(STATUS_INFO *infoPtr)
116 HTHEME theme;
117 UINT height;
118 TEXTMETRICW tm;
119 int margin;
121 COMCTL32_GetFontMetrics(infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont, &tm);
122 margin = (tm.tmInternalLeading ? tm.tmInternalLeading : 2);
123 height = max(tm.tmHeight + margin + 2*GetSystemMetrics(SM_CYBORDER), infoPtr->minHeight) + infoPtr->verticalBorder;
125 if ((theme = GetWindowTheme(infoPtr->Self)))
127 /* Determine bar height from theme such that the content area is
128 * textHeight pixels large */
129 HDC hdc = GetDC(infoPtr->Self);
130 RECT r;
131 memset (&r, 0, sizeof (r));
132 r.bottom = max(infoPtr->minHeight, tm.tmHeight);
133 if (SUCCEEDED(GetThemeBackgroundExtent(theme, hdc, SP_PANE, 0, &r, &r)))
135 height = r.bottom - r.top;
137 ReleaseDC(infoPtr->Self, hdc);
140 TRACE(" textHeight=%d+%d, final height=%d\n", tm.tmHeight, tm.tmInternalLeading, height);
141 return height;
144 static void
145 STATUSBAR_DrawSizeGrip (HTHEME theme, HDC hdc, LPRECT lpRect)
147 HPEN hPenFace, hPenShadow, hPenHighlight, hOldPen;
148 POINT pt;
149 INT i;
151 TRACE("draw size grip %s\n", wine_dbgstr_rect(lpRect));
153 if (theme)
155 RECT gripperRect;
156 SIZE gripperSize;
157 gripperRect = *lpRect;
158 if (SUCCEEDED (GetThemePartSize (theme, hdc, SP_GRIPPER, 0, lpRect,
159 TS_DRAW, &gripperSize)))
161 gripperRect.left = gripperRect.right - gripperSize.cx;
162 gripperRect.top = gripperRect.bottom - gripperSize.cy;
163 if (SUCCEEDED (DrawThemeBackground(theme, hdc, SP_GRIPPER, 0, &gripperRect, NULL)))
164 return;
168 pt.x = lpRect->right - 1;
169 pt.y = lpRect->bottom - 1;
171 hPenFace = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DFACE ));
172 hOldPen = SelectObject( hdc, hPenFace );
173 MoveToEx (hdc, pt.x - 12, pt.y, NULL);
174 LineTo (hdc, pt.x, pt.y);
175 LineTo (hdc, pt.x, pt.y - 13);
177 pt.x--;
178 pt.y--;
180 hPenShadow = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DSHADOW ));
181 SelectObject( hdc, hPenShadow );
182 for (i = 1; i < 11; i += 4) {
183 MoveToEx (hdc, pt.x - i, pt.y, NULL);
184 LineTo (hdc, pt.x + 1, pt.y - i - 1);
186 MoveToEx (hdc, pt.x - i - 1, pt.y, NULL);
187 LineTo (hdc, pt.x + 1, pt.y - i - 2);
190 hPenHighlight = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DHIGHLIGHT ));
191 SelectObject( hdc, hPenHighlight );
192 for (i = 3; i < 13; i += 4) {
193 MoveToEx (hdc, pt.x - i, pt.y, NULL);
194 LineTo (hdc, pt.x + 1, pt.y - i - 1);
197 SelectObject (hdc, hOldPen);
198 DeleteObject( hPenFace );
199 DeleteObject( hPenShadow );
200 DeleteObject( hPenHighlight );
204 static void
205 STATUSBAR_DrawPart (const STATUS_INFO *infoPtr, HDC hdc, const STATUSWINDOWPART *part, int itemID)
207 RECT r = part->bound;
208 UINT border = BDR_SUNKENOUTER;
209 HTHEME theme = GetWindowTheme (infoPtr->Self);
210 int themePart = SP_PANE;
212 TRACE("part bound %s\n", wine_dbgstr_rect(&r));
213 if (part->style & SBT_POPOUT)
214 border = BDR_RAISEDOUTER;
215 else if (part->style & SBT_NOBORDERS)
216 border = 0;
218 if (theme)
220 if ((GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
221 && (infoPtr->simple || (itemID == (infoPtr->numParts-1))))
222 themePart = SP_GRIPPERPANE;
223 DrawThemeBackground(theme, hdc, themePart, 0, &r, NULL);
225 else
226 DrawEdge(hdc, &r, border, BF_RECT|BF_ADJUST);
228 if (part->style & SBT_OWNERDRAW) {
229 DRAWITEMSTRUCT dis;
231 dis.CtlID = GetWindowLongPtrW (infoPtr->Self, GWLP_ID);
232 dis.itemID = itemID;
233 dis.hwndItem = infoPtr->Self;
234 dis.hDC = hdc;
235 dis.rcItem = r;
236 dis.itemData = (ULONG_PTR)part->text;
237 SendMessageW (infoPtr->Notify, WM_DRAWITEM, (WPARAM)dis.CtlID, (LPARAM)&dis);
238 } else {
239 if (part->hIcon) {
240 INT cy = r.bottom - r.top;
242 r.left += 2;
243 DrawIconEx (hdc, r.left, r.top, part->hIcon, cy, cy, 0, 0, DI_NORMAL);
244 r.left += cy;
246 DrawStatusTextW (hdc, &r, part->text, SBT_NOBORDERS);
251 static void
252 STATUSBAR_RefreshPart (const STATUS_INFO *infoPtr, HDC hdc, const STATUSWINDOWPART *part, int itemID)
254 HBRUSH hbrBk;
255 HTHEME theme;
257 TRACE("item %d\n", itemID);
259 if (part->bound.right < part->bound.left) return;
261 if (!RectVisible(hdc, &part->bound))
262 return;
264 if ((theme = GetWindowTheme (infoPtr->Self)))
266 RECT cr;
267 GetClientRect (infoPtr->Self, &cr);
268 DrawThemeBackground(theme, hdc, 0, 0, &cr, &part->bound);
270 else
272 if (infoPtr->clrBk != CLR_DEFAULT)
273 hbrBk = CreateSolidBrush (infoPtr->clrBk);
274 else
275 hbrBk = GetSysColorBrush (COLOR_3DFACE);
276 FillRect(hdc, &part->bound, hbrBk);
277 if (infoPtr->clrBk != CLR_DEFAULT)
278 DeleteObject (hbrBk);
281 STATUSBAR_DrawPart (infoPtr, hdc, part, itemID);
285 static LRESULT
286 STATUSBAR_Refresh (STATUS_INFO *infoPtr, HDC hdc)
288 int i;
289 RECT rect;
290 HBRUSH hbrBk;
291 HFONT hOldFont;
292 HTHEME theme;
294 TRACE("\n");
295 if (!IsWindowVisible(infoPtr->Self))
296 return 0;
298 STATUSBAR_SetPartBounds(infoPtr);
300 GetClientRect (infoPtr->Self, &rect);
302 if ((theme = GetWindowTheme (infoPtr->Self)))
304 DrawThemeBackground(theme, hdc, 0, 0, &rect, NULL);
306 else
308 if (infoPtr->clrBk != CLR_DEFAULT)
309 hbrBk = CreateSolidBrush (infoPtr->clrBk);
310 else
311 hbrBk = GetSysColorBrush (COLOR_3DFACE);
312 FillRect(hdc, &rect, hbrBk);
313 if (infoPtr->clrBk != CLR_DEFAULT)
314 DeleteObject (hbrBk);
317 hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
319 if (infoPtr->simple) {
320 STATUSBAR_RefreshPart (infoPtr, hdc, &infoPtr->part0, 0);
321 } else {
322 for (i = 0; i < infoPtr->numParts; i++) {
323 STATUSBAR_RefreshPart (infoPtr, hdc, &infoPtr->parts[i], i);
327 SelectObject (hdc, hOldFont);
329 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP)
330 STATUSBAR_DrawSizeGrip (theme, hdc, &rect);
332 return 0;
336 static int
337 STATUSBAR_InternalHitTest(const STATUS_INFO *infoPtr, const LPPOINT pt)
339 int i;
340 if (infoPtr->simple)
341 return 255;
343 for (i = 0; i < infoPtr->numParts; i++)
344 if (pt->x >= infoPtr->parts[i].bound.left && pt->x <= infoPtr->parts[i].bound.right)
345 return i;
346 return -2;
350 static void
351 STATUSBAR_SetPartBounds (STATUS_INFO *infoPtr)
353 STATUSWINDOWPART *part;
354 RECT rect, *r;
355 int i;
357 /* get our window size */
358 GetClientRect (infoPtr->Self, &rect);
359 TRACE("client wnd size is %s\n", wine_dbgstr_rect(&rect));
361 rect.left += infoPtr->horizontalBorder;
362 rect.top += infoPtr->verticalBorder;
364 /* set bounds for simple rectangle */
365 infoPtr->part0.bound = rect;
367 /* set bounds for non-simple rectangles */
368 for (i = 0; i < infoPtr->numParts; i++) {
369 part = &infoPtr->parts[i];
370 r = &infoPtr->parts[i].bound;
371 r->top = rect.top;
372 r->bottom = rect.bottom;
373 if (i == 0)
374 r->left = 0;
375 else
376 r->left = infoPtr->parts[i-1].bound.right + infoPtr->horizontalGap;
377 if (part->x == -1)
378 r->right = rect.right;
379 else
380 r->right = part->x;
382 if (infoPtr->hwndToolTip) {
383 TTTOOLINFOW ti;
385 ti.cbSize = sizeof(TTTOOLINFOW);
386 ti.hwnd = infoPtr->Self;
387 ti.uId = i;
388 ti.rect = *r;
389 SendMessageW (infoPtr->hwndToolTip, TTM_NEWTOOLRECTW,
390 0, (LPARAM)&ti);
396 static LRESULT
397 STATUSBAR_Relay2Tip (const STATUS_INFO *infoPtr, UINT uMsg,
398 WPARAM wParam, LPARAM lParam)
400 MSG msg;
402 msg.hwnd = infoPtr->Self;
403 msg.message = uMsg;
404 msg.wParam = wParam;
405 msg.lParam = lParam;
406 msg.time = GetMessageTime ();
407 msg.pt.x = (short)LOWORD(GetMessagePos ());
408 msg.pt.y = (short)HIWORD(GetMessagePos ());
410 return SendMessageW (infoPtr->hwndToolTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
414 static BOOL
415 STATUSBAR_GetBorders (const STATUS_INFO *infoPtr, INT out[])
417 TRACE("\n");
418 out[0] = infoPtr->horizontalBorder;
419 out[1] = infoPtr->verticalBorder;
420 out[2] = infoPtr->horizontalGap;
422 return TRUE;
426 static BOOL
427 STATUSBAR_SetBorders (STATUS_INFO *infoPtr, const INT in[])
429 TRACE("\n");
430 infoPtr->horizontalBorder = in[0];
431 infoPtr->verticalBorder = in[1];
432 infoPtr->horizontalGap = in[2];
433 InvalidateRect(infoPtr->Self, NULL, FALSE);
435 return TRUE;
439 static HICON
440 STATUSBAR_GetIcon (const STATUS_INFO *infoPtr, INT nPart)
442 TRACE("%d\n", nPart);
443 /* MSDN says: "simple parts are indexed with -1" */
444 if ((nPart < -1) || (nPart >= infoPtr->numParts))
445 return 0;
447 if (nPart == -1)
448 return (infoPtr->part0.hIcon);
449 else
450 return (infoPtr->parts[nPart].hIcon);
454 static INT
455 STATUSBAR_GetParts (const STATUS_INFO *infoPtr, INT num_parts, INT parts[])
457 INT i;
459 TRACE("(%d)\n", num_parts);
460 if (parts) {
461 for (i = 0; i < num_parts; i++) {
462 parts[i] = infoPtr->parts[i].x;
465 return infoPtr->numParts;
469 static BOOL
470 STATUSBAR_GetRect (const STATUS_INFO *infoPtr, INT nPart, LPRECT rect)
472 TRACE("part %d\n", nPart);
473 if(nPart >= infoPtr->numParts || nPart < 0)
474 return FALSE;
475 if (infoPtr->simple)
476 *rect = infoPtr->part0.bound;
477 else
478 *rect = infoPtr->parts[nPart].bound;
479 return TRUE;
483 static LRESULT
484 STATUSBAR_GetTextA (STATUS_INFO *infoPtr, INT nPart, LPSTR buf)
486 STATUSWINDOWPART *part;
487 LRESULT result;
489 TRACE("part %d\n", nPart);
491 /* MSDN says: "simple parts use index of 0", so this check is ok. */
492 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
494 if (infoPtr->simple)
495 part = &infoPtr->part0;
496 else
497 part = &infoPtr->parts[nPart];
499 if (part->style & SBT_OWNERDRAW)
500 result = (LRESULT)part->text;
501 else {
502 DWORD len = part->text ? WideCharToMultiByte( CP_ACP, 0, part->text, -1,
503 NULL, 0, NULL, NULL ) - 1 : 0;
504 result = MAKELONG( len, part->style );
505 if (part->text && buf)
506 WideCharToMultiByte( CP_ACP, 0, part->text, -1, buf, len+1, NULL, NULL );
508 return result;
512 static LRESULT
513 STATUSBAR_GetTextW (STATUS_INFO *infoPtr, INT nPart, LPWSTR buf)
515 STATUSWINDOWPART *part;
516 LRESULT result;
518 TRACE("part %d\n", nPart);
519 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
521 if (infoPtr->simple)
522 part = &infoPtr->part0;
523 else
524 part = &infoPtr->parts[nPart];
526 if (part->style & SBT_OWNERDRAW)
527 result = (LRESULT)part->text;
528 else {
529 result = part->text ? strlenW (part->text) : 0;
530 result |= (part->style << 16);
531 if (part->text && buf)
532 strcpyW (buf, part->text);
534 return result;
538 static LRESULT
539 STATUSBAR_GetTextLength (STATUS_INFO *infoPtr, INT nPart)
541 STATUSWINDOWPART *part;
542 DWORD result;
544 TRACE("part %d\n", nPart);
546 /* MSDN says: "simple parts use index of 0", so this check is ok. */
547 if (nPart < 0 || nPart >= infoPtr->numParts) return 0;
549 if (infoPtr->simple)
550 part = &infoPtr->part0;
551 else
552 part = &infoPtr->parts[nPart];
554 if ((~part->style & SBT_OWNERDRAW) && part->text)
555 result = strlenW(part->text);
556 else
557 result = 0;
559 result |= (part->style << 16);
560 return result;
563 static LRESULT
564 STATUSBAR_GetTipTextA (const STATUS_INFO *infoPtr, INT id, LPSTR tip, INT size)
566 TRACE("\n");
567 if (tip) {
568 CHAR buf[INFOTIPSIZE];
569 buf[0]='\0';
571 if (infoPtr->hwndToolTip) {
572 TTTOOLINFOA ti;
573 ti.cbSize = sizeof(TTTOOLINFOA);
574 ti.hwnd = infoPtr->Self;
575 ti.uId = id;
576 ti.lpszText = buf;
577 SendMessageA (infoPtr->hwndToolTip, TTM_GETTEXTA, 0, (LPARAM)&ti);
579 lstrcpynA (tip, buf, size);
581 return 0;
585 static LRESULT
586 STATUSBAR_GetTipTextW (const STATUS_INFO *infoPtr, INT id, LPWSTR tip, INT size)
588 TRACE("\n");
589 if (tip) {
590 WCHAR buf[INFOTIPSIZE];
591 buf[0]=0;
593 if (infoPtr->hwndToolTip) {
594 TTTOOLINFOW ti;
595 ti.cbSize = sizeof(TTTOOLINFOW);
596 ti.hwnd = infoPtr->Self;
597 ti.uId = id;
598 ti.lpszText = buf;
599 SendMessageW(infoPtr->hwndToolTip, TTM_GETTEXTW, 0, (LPARAM)&ti);
601 lstrcpynW(tip, buf, size);
604 return 0;
608 static COLORREF
609 STATUSBAR_SetBkColor (STATUS_INFO *infoPtr, COLORREF color)
611 COLORREF oldBkColor;
613 oldBkColor = infoPtr->clrBk;
614 infoPtr->clrBk = color;
615 InvalidateRect(infoPtr->Self, NULL, FALSE);
617 TRACE("CREF: %08x -> %08x\n", oldBkColor, infoPtr->clrBk);
618 return oldBkColor;
622 static BOOL
623 STATUSBAR_SetIcon (STATUS_INFO *infoPtr, INT nPart, HICON hIcon)
625 if ((nPart < -1) || (nPart >= infoPtr->numParts))
626 return FALSE;
628 TRACE("setting part %d\n", nPart);
630 /* FIXME: MSDN says "if nPart is -1, the status bar is assumed simple" */
631 if (nPart == -1) {
632 if (infoPtr->part0.hIcon == hIcon) /* same as - no redraw */
633 return TRUE;
634 infoPtr->part0.hIcon = hIcon;
635 if (infoPtr->simple)
636 InvalidateRect(infoPtr->Self, &infoPtr->part0.bound, FALSE);
637 } else {
638 if (infoPtr->parts[nPart].hIcon == hIcon) /* same as - no redraw */
639 return TRUE;
641 infoPtr->parts[nPart].hIcon = hIcon;
642 if (!(infoPtr->simple))
643 InvalidateRect(infoPtr->Self, &infoPtr->parts[nPart].bound, FALSE);
645 return TRUE;
649 static BOOL
650 STATUSBAR_SetMinHeight (STATUS_INFO *infoPtr, INT height)
652 infoPtr->minHeight = max(height, MIN_PANE_HEIGHT);
653 infoPtr->height = STATUSBAR_ComputeHeight(infoPtr);
654 /* like native, don't resize the control */
655 return TRUE;
659 static BOOL
660 STATUSBAR_SetParts (STATUS_INFO *infoPtr, INT count, LPINT parts)
662 STATUSWINDOWPART *tmp;
663 UINT i, oldNumParts;
665 TRACE("(%d,%p)\n", count, parts);
667 oldNumParts = infoPtr->numParts;
668 infoPtr->numParts = count;
669 if (oldNumParts > infoPtr->numParts) {
670 for (i = infoPtr->numParts ; i < oldNumParts; i++) {
671 if (!(infoPtr->parts[i].style & SBT_OWNERDRAW))
672 Free (infoPtr->parts[i].text);
674 } else if (oldNumParts < infoPtr->numParts) {
675 tmp = Alloc (sizeof(STATUSWINDOWPART) * infoPtr->numParts);
676 if (!tmp) return FALSE;
677 for (i = 0; i < oldNumParts; i++) {
678 tmp[i] = infoPtr->parts[i];
680 Free (infoPtr->parts);
681 infoPtr->parts = tmp;
683 if (oldNumParts == infoPtr->numParts) {
684 for (i=0; i < oldNumParts; i++)
685 if (infoPtr->parts[i].x != parts[i])
686 break;
687 if (i==oldNumParts) /* Unchanged? no need to redraw! */
688 return TRUE;
691 for (i = 0; i < infoPtr->numParts; i++)
692 infoPtr->parts[i].x = parts[i];
694 if (infoPtr->hwndToolTip) {
695 UINT nTipCount;
696 TTTOOLINFOW ti;
698 ZeroMemory (&ti, sizeof(TTTOOLINFOW));
699 ti.cbSize = sizeof(TTTOOLINFOW);
700 ti.hwnd = infoPtr->Self;
702 nTipCount = SendMessageW (infoPtr->hwndToolTip, TTM_GETTOOLCOUNT, 0, 0);
703 if (nTipCount < infoPtr->numParts) {
704 /* add tools */
705 for (i = nTipCount; i < infoPtr->numParts; i++) {
706 TRACE("add tool %d\n", i);
707 ti.uId = i;
708 SendMessageW (infoPtr->hwndToolTip, TTM_ADDTOOLW,
709 0, (LPARAM)&ti);
712 else if (nTipCount > infoPtr->numParts) {
713 /* delete tools */
714 for (i = nTipCount - 1; i >= infoPtr->numParts; i--) {
715 TRACE("delete tool %d\n", i);
716 ti.uId = i;
717 SendMessageW (infoPtr->hwndToolTip, TTM_DELTOOLW,
718 0, (LPARAM)&ti);
722 STATUSBAR_SetPartBounds (infoPtr);
723 InvalidateRect(infoPtr->Self, NULL, FALSE);
724 return TRUE;
728 static BOOL
729 STATUSBAR_SetTextT (STATUS_INFO *infoPtr, INT nPart, WORD style,
730 LPCWSTR text, BOOL isW)
732 STATUSWINDOWPART *part=NULL;
733 BOOL changed = FALSE;
734 INT oldStyle;
736 if (style & SBT_OWNERDRAW) {
737 TRACE("part %d, text %p\n",nPart,text);
739 else TRACE("part %d, text %s\n", nPart, debugstr_t(text, isW));
741 /* MSDN says: "If the parameter is set to SB_SIMPLEID (255), the status
742 * window is assumed to be a simple window */
744 if (nPart == 0x00ff) {
745 part = &infoPtr->part0;
746 } else {
747 if (infoPtr->parts && nPart >= 0 && nPart < infoPtr->numParts) {
748 part = &infoPtr->parts[nPart];
751 if (!part) return FALSE;
753 if (part->style != style)
754 changed = TRUE;
756 oldStyle = part->style;
757 part->style = style;
758 if (style & SBT_OWNERDRAW) {
759 if (!(oldStyle & SBT_OWNERDRAW))
760 Free (part->text);
761 else if (part->text == text)
762 return TRUE;
763 part->text = (LPWSTR)text;
764 } else {
765 LPWSTR ntext;
767 if (text && !isW) {
768 LPCSTR atxt = (LPCSTR)text;
769 DWORD len = MultiByteToWideChar( CP_ACP, 0, atxt, -1, NULL, 0 );
770 ntext = Alloc( (len + 1)*sizeof(WCHAR) );
771 if (!ntext) return FALSE;
772 MultiByteToWideChar( CP_ACP, 0, atxt, -1, ntext, len );
773 } else if (text) {
774 ntext = Alloc( (strlenW(text) + 1)*sizeof(WCHAR) );
775 if (!ntext) return FALSE;
776 strcpyW (ntext, text);
777 } else ntext = 0;
779 /* check if text is unchanged -> no need to redraw */
780 if (text) {
781 if (!changed && part->text && !lstrcmpW(ntext, part->text)) {
782 Free(ntext);
783 return TRUE;
785 } else {
786 if (!changed && !part->text)
787 return TRUE;
790 if (!(oldStyle & SBT_OWNERDRAW))
791 Free (part->text);
792 part->text = ntext;
794 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
795 UpdateWindow(infoPtr->Self);
797 return TRUE;
801 static LRESULT
802 STATUSBAR_SetTipTextA (const STATUS_INFO *infoPtr, INT id, LPSTR text)
804 TRACE("part %d: \"%s\"\n", id, text);
805 if (infoPtr->hwndToolTip) {
806 TTTOOLINFOA ti;
807 ti.cbSize = sizeof(TTTOOLINFOA);
808 ti.hwnd = infoPtr->Self;
809 ti.uId = id;
810 ti.hinst = 0;
811 ti.lpszText = text;
812 SendMessageA (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTA, 0, (LPARAM)&ti);
815 return 0;
819 static LRESULT
820 STATUSBAR_SetTipTextW (const STATUS_INFO *infoPtr, INT id, LPWSTR text)
822 TRACE("part %d: \"%s\"\n", id, debugstr_w(text));
823 if (infoPtr->hwndToolTip) {
824 TTTOOLINFOW ti;
825 ti.cbSize = sizeof(TTTOOLINFOW);
826 ti.hwnd = infoPtr->Self;
827 ti.uId = id;
828 ti.hinst = 0;
829 ti.lpszText = text;
830 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW, 0, (LPARAM)&ti);
833 return 0;
837 static inline LRESULT
838 STATUSBAR_SetUnicodeFormat (STATUS_INFO *infoPtr, BOOL bUnicode)
840 BOOL bOld = infoPtr->bUnicode;
842 TRACE("(0x%x)\n", bUnicode);
843 infoPtr->bUnicode = bUnicode;
845 return bOld;
849 static BOOL
850 STATUSBAR_Simple (STATUS_INFO *infoPtr, BOOL simple)
852 NMHDR nmhdr;
854 TRACE("(simple=%d)\n", simple);
855 if (infoPtr->simple == simple) /* no need to change */
856 return TRUE;
858 infoPtr->simple = simple;
860 /* send notification */
861 nmhdr.hwndFrom = infoPtr->Self;
862 nmhdr.idFrom = GetWindowLongPtrW (infoPtr->Self, GWLP_ID);
863 nmhdr.code = SBN_SIMPLEMODECHANGE;
864 SendMessageW (infoPtr->Notify, WM_NOTIFY, 0, (LPARAM)&nmhdr);
865 InvalidateRect(infoPtr->Self, NULL, FALSE);
866 return TRUE;
870 static LRESULT
871 STATUSBAR_WMDestroy (STATUS_INFO *infoPtr)
873 int i;
875 TRACE("\n");
876 for (i = 0; i < infoPtr->numParts; i++) {
877 if (!(infoPtr->parts[i].style & SBT_OWNERDRAW))
878 Free (infoPtr->parts[i].text);
880 if (!(infoPtr->part0.style & SBT_OWNERDRAW))
881 Free (infoPtr->part0.text);
882 Free (infoPtr->parts);
884 /* delete default font */
885 if (infoPtr->hDefaultFont)
886 DeleteObject (infoPtr->hDefaultFont);
888 /* delete tool tip control */
889 if (infoPtr->hwndToolTip)
890 DestroyWindow (infoPtr->hwndToolTip);
892 CloseThemeData (GetWindowTheme (infoPtr->Self));
894 SetWindowLongPtrW(infoPtr->Self, 0, 0);
895 Free (infoPtr);
896 return 0;
900 static LRESULT
901 STATUSBAR_WMCreate (HWND hwnd, const CREATESTRUCTA *lpCreate)
903 STATUS_INFO *infoPtr;
904 NONCLIENTMETRICSW nclm;
905 DWORD dwStyle;
906 RECT rect;
907 int len;
909 TRACE("\n");
910 infoPtr = Alloc (sizeof(STATUS_INFO));
911 if (!infoPtr) goto create_fail;
912 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
914 infoPtr->Self = hwnd;
915 infoPtr->Notify = lpCreate->hwndParent;
916 infoPtr->numParts = 1;
917 infoPtr->parts = 0;
918 infoPtr->simple = FALSE;
919 infoPtr->clrBk = CLR_DEFAULT;
920 infoPtr->hFont = 0;
921 infoPtr->horizontalBorder = HORZ_BORDER;
922 infoPtr->verticalBorder = VERT_BORDER;
923 infoPtr->horizontalGap = HORZ_GAP;
924 infoPtr->minHeight = MIN_PANE_HEIGHT;
926 STATUSBAR_NotifyFormat(infoPtr, infoPtr->Notify, NF_REQUERY);
928 ZeroMemory (&nclm, sizeof(nclm));
929 nclm.cbSize = sizeof(nclm);
930 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, nclm.cbSize, &nclm, 0);
931 infoPtr->hDefaultFont = CreateFontIndirectW (&nclm.lfStatusFont);
933 GetClientRect (hwnd, &rect);
935 /* initialize simple case */
936 infoPtr->part0.bound = rect;
937 infoPtr->part0.text = 0;
938 infoPtr->part0.x = 0;
939 infoPtr->part0.style = 0;
940 infoPtr->part0.hIcon = 0;
942 /* initialize first part */
943 infoPtr->parts = Alloc (sizeof(STATUSWINDOWPART));
944 if (!infoPtr->parts) goto create_fail;
945 infoPtr->parts[0].bound = rect;
946 infoPtr->parts[0].text = 0;
947 infoPtr->parts[0].x = -1;
948 infoPtr->parts[0].style = 0;
949 infoPtr->parts[0].hIcon = 0;
951 OpenThemeData (hwnd, themeClass);
953 if (lpCreate->lpszName && (len = strlenW ((LPCWSTR)lpCreate->lpszName)))
955 infoPtr->parts[0].text = Alloc ((len + 1)*sizeof(WCHAR));
956 if (!infoPtr->parts[0].text) goto create_fail;
957 strcpyW (infoPtr->parts[0].text, (LPCWSTR)lpCreate->lpszName);
960 dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
961 /* native seems to clear WS_BORDER, too */
962 dwStyle &= ~WS_BORDER;
963 SetWindowLongW (hwnd, GWL_STYLE, dwStyle);
965 infoPtr->height = STATUSBAR_ComputeHeight(infoPtr);
967 if (dwStyle & SBT_TOOLTIPS) {
968 infoPtr->hwndToolTip =
969 CreateWindowExW (0, TOOLTIPS_CLASSW, NULL, WS_POPUP | TTS_ALWAYSTIP,
970 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
971 CW_USEDEFAULT, hwnd, 0,
972 (HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE), NULL);
974 if (infoPtr->hwndToolTip) {
975 NMTOOLTIPSCREATED nmttc;
977 nmttc.hdr.hwndFrom = hwnd;
978 nmttc.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
979 nmttc.hdr.code = NM_TOOLTIPSCREATED;
980 nmttc.hwndToolTips = infoPtr->hwndToolTip;
982 SendMessageW (lpCreate->hwndParent, WM_NOTIFY, nmttc.hdr.idFrom, (LPARAM)&nmttc);
986 return 0;
988 create_fail:
989 TRACE(" failed!\n");
990 if (infoPtr) STATUSBAR_WMDestroy(infoPtr);
991 return -1;
995 /* in contrast to SB_GETTEXT*, WM_GETTEXT handles the text
996 * of the first part only (usual behaviour) */
997 static INT
998 STATUSBAR_WMGetText (const STATUS_INFO *infoPtr, INT size, LPWSTR buf)
1000 INT len;
1002 TRACE("\n");
1003 if (!(infoPtr->parts[0].text))
1004 return 0;
1006 len = strlenW (infoPtr->parts[0].text);
1008 if (size > len) {
1009 strcpyW (buf, infoPtr->parts[0].text);
1010 return len;
1013 return -1;
1017 static BOOL
1018 STATUSBAR_WMNCHitTest (const STATUS_INFO *infoPtr, INT x, INT y)
1020 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & SBARS_SIZEGRIP) {
1021 RECT rect;
1022 POINT pt;
1024 GetClientRect (infoPtr->Self, &rect);
1026 pt.x = x;
1027 pt.y = y;
1028 ScreenToClient (infoPtr->Self, &pt);
1030 rect.left = rect.right - 13;
1031 rect.top += 2;
1033 if (PtInRect (&rect, pt))
1034 return HTBOTTOMRIGHT;
1037 return HTERROR;
1041 static LRESULT
1042 STATUSBAR_WMPaint (STATUS_INFO *infoPtr, HDC hdc)
1044 PAINTSTRUCT ps;
1046 TRACE("\n");
1047 if (hdc) return STATUSBAR_Refresh (infoPtr, hdc);
1048 hdc = BeginPaint (infoPtr->Self, &ps);
1049 STATUSBAR_Refresh (infoPtr, hdc);
1050 EndPaint (infoPtr->Self, &ps);
1052 return 0;
1056 static LRESULT
1057 STATUSBAR_WMSetFont (STATUS_INFO *infoPtr, HFONT font, BOOL redraw)
1059 infoPtr->hFont = font;
1060 TRACE("%p\n", infoPtr->hFont);
1062 infoPtr->height = STATUSBAR_ComputeHeight(infoPtr);
1063 SendMessageW(infoPtr->Self, WM_SIZE, 0, 0); /* update size */
1064 if (redraw)
1065 InvalidateRect(infoPtr->Self, NULL, FALSE);
1067 return 0;
1071 static BOOL
1072 STATUSBAR_WMSetText (const STATUS_INFO *infoPtr, LPCSTR text)
1074 STATUSWINDOWPART *part;
1075 int len;
1077 TRACE("\n");
1078 if (infoPtr->numParts == 0)
1079 return FALSE;
1081 part = &infoPtr->parts[0];
1082 /* duplicate string */
1083 Free (part->text);
1084 part->text = 0;
1086 if (text && (len = strlenW((LPCWSTR)text))) {
1087 part->text = Alloc ((len+1)*sizeof(WCHAR));
1088 if (!part->text) return FALSE;
1089 strcpyW (part->text, (LPCWSTR)text);
1092 InvalidateRect(infoPtr->Self, &part->bound, FALSE);
1094 return TRUE;
1098 static BOOL
1099 STATUSBAR_WMSize (STATUS_INFO *infoPtr, WORD flags)
1101 INT width, x, y;
1102 RECT parent_rect;
1104 /* Need to resize width to match parent */
1105 TRACE("flags %04x\n", flags);
1107 if (flags != SIZE_RESTORED && flags != SIZE_MAXIMIZED) {
1108 WARN("flags MUST be SIZE_RESTORED or SIZE_MAXIMIZED\n");
1109 return FALSE;
1112 if (GetWindowLongW(infoPtr->Self, GWL_STYLE) & CCS_NORESIZE) return FALSE;
1114 /* width and height don't apply */
1115 if (!GetClientRect (infoPtr->Notify, &parent_rect))
1116 return FALSE;
1118 width = parent_rect.right - parent_rect.left;
1119 x = parent_rect.left;
1120 y = parent_rect.bottom - infoPtr->height;
1121 MoveWindow (infoPtr->Self, x, y, width, infoPtr->height, TRUE);
1122 STATUSBAR_SetPartBounds (infoPtr);
1123 return TRUE;
1127 /* update theme after a WM_THEMECHANGED message */
1128 static LRESULT theme_changed (const STATUS_INFO* infoPtr)
1130 HTHEME theme = GetWindowTheme (infoPtr->Self);
1131 CloseThemeData (theme);
1132 OpenThemeData (infoPtr->Self, themeClass);
1133 return 0;
1137 static LRESULT
1138 STATUSBAR_NotifyFormat (STATUS_INFO *infoPtr, HWND from, INT cmd)
1140 if (cmd == NF_REQUERY) {
1141 INT i = SendMessageW(from, WM_NOTIFYFORMAT, (WPARAM)infoPtr->Self, NF_QUERY);
1142 infoPtr->bUnicode = (i == NFR_UNICODE);
1144 return infoPtr->bUnicode ? NFR_UNICODE : NFR_ANSI;
1148 static LRESULT
1149 STATUSBAR_SendMouseNotify(const STATUS_INFO *infoPtr, UINT code, LPARAM lParam)
1151 NMMOUSE nm;
1153 TRACE("code %04x, lParam=%lx\n", code, lParam);
1154 nm.hdr.hwndFrom = infoPtr->Self;
1155 nm.hdr.idFrom = GetWindowLongPtrW(infoPtr->Self, GWLP_ID);
1156 nm.hdr.code = code;
1157 nm.pt.x = (short)LOWORD(lParam);
1158 nm.pt.y = (short)HIWORD(lParam);
1159 nm.dwItemSpec = STATUSBAR_InternalHitTest(infoPtr, &nm.pt);
1160 nm.dwItemData = 0;
1161 nm.dwHitInfo = 0x30000; /* seems constant */
1162 SendMessageW(infoPtr->Notify, WM_NOTIFY, 0, (LPARAM)&nm);
1163 return 0;
1168 static LRESULT WINAPI
1169 StatusWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1171 STATUS_INFO *infoPtr = (STATUS_INFO *)GetWindowLongPtrW (hwnd, 0);
1172 INT nPart = ((INT) wParam) & 0x00ff;
1173 LRESULT res;
1175 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n", hwnd, msg, wParam, lParam);
1176 if (!infoPtr && msg != WM_CREATE)
1177 return DefWindowProcW (hwnd, msg, wParam, lParam);
1179 switch (msg) {
1180 case SB_GETBORDERS:
1181 return STATUSBAR_GetBorders (infoPtr, (INT *)lParam);
1183 case SB_GETICON:
1184 return (LRESULT)STATUSBAR_GetIcon (infoPtr, nPart);
1186 case SB_GETPARTS:
1187 return STATUSBAR_GetParts (infoPtr, (INT)wParam, (INT *)lParam);
1189 case SB_GETRECT:
1190 return STATUSBAR_GetRect (infoPtr, nPart, (LPRECT)lParam);
1192 case SB_GETTEXTA:
1193 return STATUSBAR_GetTextA (infoPtr, nPart, (LPSTR)lParam);
1195 case SB_GETTEXTW:
1196 return STATUSBAR_GetTextW (infoPtr, nPart, (LPWSTR)lParam);
1198 case SB_GETTEXTLENGTHA:
1199 case SB_GETTEXTLENGTHW:
1200 return STATUSBAR_GetTextLength (infoPtr, nPart);
1202 case SB_GETTIPTEXTA:
1203 return STATUSBAR_GetTipTextA (infoPtr, LOWORD(wParam), (LPSTR)lParam, HIWORD(wParam));
1205 case SB_GETTIPTEXTW:
1206 return STATUSBAR_GetTipTextW (infoPtr, LOWORD(wParam), (LPWSTR)lParam, HIWORD(wParam));
1208 case SB_GETUNICODEFORMAT:
1209 return infoPtr->bUnicode;
1211 case SB_ISSIMPLE:
1212 return infoPtr->simple;
1214 case SB_SETBORDERS:
1215 return STATUSBAR_SetBorders (infoPtr, (INT *)lParam);
1217 case SB_SETBKCOLOR:
1218 return STATUSBAR_SetBkColor (infoPtr, (COLORREF)lParam);
1220 case SB_SETICON:
1221 return STATUSBAR_SetIcon (infoPtr, nPart, (HICON)lParam);
1223 case SB_SETMINHEIGHT:
1224 return STATUSBAR_SetMinHeight (infoPtr, (INT)wParam);
1226 case SB_SETPARTS:
1227 return STATUSBAR_SetParts (infoPtr, (INT)wParam, (LPINT)lParam);
1229 case SB_SETTEXTA:
1230 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, FALSE);
1232 case SB_SETTEXTW:
1233 return STATUSBAR_SetTextT (infoPtr, nPart, wParam & 0xff00, (LPCWSTR)lParam, TRUE);
1235 case SB_SETTIPTEXTA:
1236 return STATUSBAR_SetTipTextA (infoPtr, (INT)wParam, (LPSTR)lParam);
1238 case SB_SETTIPTEXTW:
1239 return STATUSBAR_SetTipTextW (infoPtr, (INT)wParam, (LPWSTR)lParam);
1241 case SB_SETUNICODEFORMAT:
1242 return STATUSBAR_SetUnicodeFormat (infoPtr, (BOOL)wParam);
1244 case SB_SIMPLE:
1245 return STATUSBAR_Simple (infoPtr, (BOOL)wParam);
1247 case WM_CREATE:
1248 return STATUSBAR_WMCreate (hwnd, (LPCREATESTRUCTA)lParam);
1250 case WM_DESTROY:
1251 return STATUSBAR_WMDestroy (infoPtr);
1253 case WM_GETFONT:
1254 return (LRESULT)(infoPtr->hFont? infoPtr->hFont : infoPtr->hDefaultFont);
1256 case WM_GETTEXT:
1257 return STATUSBAR_WMGetText (infoPtr, (INT)wParam, (LPWSTR)lParam);
1259 case WM_GETTEXTLENGTH:
1260 return STATUSBAR_GetTextLength (infoPtr, 0);
1262 case WM_LBUTTONDBLCLK:
1263 return STATUSBAR_SendMouseNotify(infoPtr, NM_DBLCLK, lParam);
1265 case WM_LBUTTONUP:
1266 return STATUSBAR_SendMouseNotify(infoPtr, NM_CLICK, lParam);
1268 case WM_MOUSEMOVE:
1269 return STATUSBAR_Relay2Tip (infoPtr, msg, wParam, lParam);
1271 case WM_NCHITTEST:
1272 res = STATUSBAR_WMNCHitTest(infoPtr, (short)LOWORD(lParam),
1273 (short)HIWORD(lParam));
1274 if (res != HTERROR) return res;
1275 return DefWindowProcW (hwnd, msg, wParam, lParam);
1277 case WM_NCLBUTTONUP:
1278 case WM_NCLBUTTONDOWN:
1279 PostMessageW (infoPtr->Notify, msg, wParam, lParam);
1280 return 0;
1282 case WM_NOTIFYFORMAT:
1283 return STATUSBAR_NotifyFormat(infoPtr, (HWND)wParam, (INT)lParam);
1285 case WM_PRINTCLIENT:
1286 case WM_PAINT:
1287 return STATUSBAR_WMPaint (infoPtr, (HDC)wParam);
1289 case WM_RBUTTONDBLCLK:
1290 return STATUSBAR_SendMouseNotify(infoPtr, NM_RDBLCLK, lParam);
1292 case WM_RBUTTONUP:
1293 return STATUSBAR_SendMouseNotify(infoPtr, NM_RCLICK, lParam);
1295 case WM_SETFONT:
1296 return STATUSBAR_WMSetFont (infoPtr, (HFONT)wParam, LOWORD(lParam));
1298 case WM_SETTEXT:
1299 return STATUSBAR_WMSetText (infoPtr, (LPCSTR)lParam);
1301 case WM_SIZE:
1302 if (STATUSBAR_WMSize (infoPtr, (WORD)wParam)) return 0;
1303 return DefWindowProcW (hwnd, msg, wParam, lParam);
1305 case WM_THEMECHANGED:
1306 return theme_changed (infoPtr);
1308 default:
1309 if ((msg >= WM_USER) && (msg < WM_APP) && !COMCTL32_IsReflectedMessage(msg))
1310 ERR("unknown msg %04x wp=%04lx lp=%08lx\n",
1311 msg, wParam, lParam);
1312 return DefWindowProcW (hwnd, msg, wParam, lParam);
1317 /***********************************************************************
1318 * STATUS_Register [Internal]
1320 * Registers the status window class.
1323 void
1324 STATUS_Register (void)
1326 WNDCLASSW wndClass;
1328 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1329 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW;
1330 wndClass.lpfnWndProc = StatusWindowProc;
1331 wndClass.cbClsExtra = 0;
1332 wndClass.cbWndExtra = sizeof(STATUS_INFO *);
1333 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1334 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
1335 wndClass.lpszClassName = STATUSCLASSNAMEW;
1337 RegisterClassW (&wndClass);
1341 /***********************************************************************
1342 * STATUS_Unregister [Internal]
1344 * Unregisters the status window class.
1347 void
1348 STATUS_Unregister (void)
1350 UnregisterClassW (STATUSCLASSNAMEW, NULL);