2 * Interface code to StatusWindow widget/control
4 * Copyright 1996 Bruce Milner
5 * Copyright 1998, 1999 Eric Kohl
9 * 1) Don't hard code bar to bottom of window, allow CCS_TOP also.
10 * 2) Tooltip support (almost done).
14 #include "wine/unicode.h"
15 #include "wine/winestring.h"
17 #include "debugtools.h"
19 DEFAULT_DEBUG_CHANNEL(statusbar);
39 COLORREF clrBk; /* background color */
40 BOOL bUnicode; /* unicode flag */
41 STATUSWINDOWPART part0; /* simple window */
42 STATUSWINDOWPART *parts;
46 * Run tests using Waite Group Windows95 API Bible Vol. 1&2
47 * The second cdrom contains executables drawstat.exe,gettext.exe,
48 * simple.exe, getparts.exe, setparts.exe, statwnd.exe
52 #define _MAX(a,b) (((a)>(b))?(a):(b))
53 #define _MIN(a,b) (((a)>(b))?(b):(a))
59 #define STATUSBAR_GetInfoPtr(hwnd) ((STATUSWINDOWINFO *)GetWindowLongA (hwnd, 0))
63 STATUSBAR_SetPartBounds (HWND hwnd);
66 STATUSBAR_DrawSizeGrip (HDC hdc, LPRECT lpRect)
72 pt.x = lpRect->right - 1;
73 pt.y = lpRect->bottom - 1;
75 hOldPen = SelectObject (hdc, GetSysColorPen (COLOR_3DFACE));
76 MoveToEx (hdc, pt.x - 12, pt.y, NULL);
77 LineTo (hdc, pt.x, pt.y);
78 LineTo (hdc, pt.x, pt.y - 12);
83 SelectObject (hdc, GetSysColorPen (COLOR_3DSHADOW));
84 for (i = 1; i < 11; i += 4) {
85 MoveToEx (hdc, pt.x - i, pt.y, NULL);
86 LineTo (hdc, pt.x, pt.y - i);
88 MoveToEx (hdc, pt.x - i-1, pt.y, NULL);
89 LineTo (hdc, pt.x, pt.y - i-1);
92 SelectObject (hdc, GetSysColorPen (COLOR_3DHIGHLIGHT));
93 for (i = 3; i < 13; i += 4) {
94 MoveToEx (hdc, pt.x - i, pt.y, NULL);
95 LineTo (hdc, pt.x, pt.y - i);
98 SelectObject (hdc, hOldPen);
103 STATUSBAR_DrawPart (HDC hdc, STATUSWINDOWPART *part)
105 RECT r = part->bound;
106 UINT border = BDR_SUNKENOUTER;
108 if (part->style & SBT_POPOUT)
109 border = BDR_RAISEDOUTER;
110 else if (part->style & SBT_NOBORDERS)
113 DrawEdge(hdc, &r, border, BF_RECT|BF_ADJUST);
117 INT cy = r.bottom - r.top;
120 DrawIconEx (hdc, r.left, r.top, part->hIcon, cy, cy, 0, 0, DI_NORMAL);
126 int oldbkmode = SetBkMode(hdc, TRANSPARENT);
127 LPWSTR p = (LPWSTR)part->text;
128 UINT align = DT_LEFT;
139 DrawTextW (hdc, p, lstrlenW (p), &r, align|DT_VCENTER|DT_SINGLELINE);
140 if (oldbkmode != TRANSPARENT)
141 SetBkMode(hdc, oldbkmode);
147 STATUSBAR_RefreshPart (HWND hwnd, STATUSWINDOWPART *part, HDC hdc, int itemID)
149 STATUSWINDOWINFO *self = STATUSBAR_GetInfoPtr (hwnd);
153 if (!IsWindowVisible (hwnd))
156 if (part->bound.right < part->bound.left) return;
158 if (self->clrBk != CLR_DEFAULT)
159 hbrBk = CreateSolidBrush (self->clrBk);
161 hbrBk = GetSysColorBrush (COLOR_3DFACE);
162 FillRect(hdc, &part->bound, hbrBk);
164 hOldFont = SelectObject (hdc, self->hFont ? self->hFont : self->hDefaultFont);
166 if (part->style & SBT_OWNERDRAW) {
169 dis.CtlID = GetWindowLongA (hwnd, GWL_ID);
173 dis.rcItem = part->bound;
174 dis.itemData = (INT)part->text;
175 SendMessageA (GetParent (hwnd), WM_DRAWITEM,
176 (WPARAM)dis.CtlID, (LPARAM)&dis);
178 STATUSBAR_DrawPart (hdc, part);
180 SelectObject (hdc, hOldFont);
182 if (self->clrBk != CLR_DEFAULT)
183 DeleteObject (hbrBk);
185 if (GetWindowLongA (hwnd, GWL_STYLE) & SBARS_SIZEGRIP) {
188 GetClientRect (hwnd, &rect);
189 STATUSBAR_DrawSizeGrip (hdc, &rect);
195 STATUSBAR_Refresh (HWND hwnd, HDC hdc)
197 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
203 if (!IsWindowVisible(hwnd))
206 STATUSBAR_SetPartBounds(hwnd);
208 GetClientRect (hwnd, &rect);
210 if (infoPtr->clrBk != CLR_DEFAULT)
211 hbrBk = CreateSolidBrush (infoPtr->clrBk);
213 hbrBk = GetSysColorBrush (COLOR_3DFACE);
214 FillRect(hdc, &rect, hbrBk);
216 hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont);
218 if (infoPtr->simple) {
219 STATUSBAR_RefreshPart (hwnd, &infoPtr->part0, hdc, 0);
221 for (i = 0; i < infoPtr->numParts; i++) {
222 if (infoPtr->parts[i].style & SBT_OWNERDRAW) {
225 dis.CtlID = GetWindowLongA (hwnd, GWL_ID);
229 dis.rcItem = infoPtr->parts[i].bound;
230 dis.itemData = (INT)infoPtr->parts[i].text;
231 SendMessageA (GetParent (hwnd), WM_DRAWITEM,
232 (WPARAM)dis.CtlID, (LPARAM)&dis);
234 STATUSBAR_RefreshPart (hwnd, &infoPtr->parts[i], hdc, i);
238 SelectObject (hdc, hOldFont);
240 if (infoPtr->clrBk != CLR_DEFAULT)
241 DeleteObject (hbrBk);
243 if (GetWindowLongA(hwnd, GWL_STYLE) & SBARS_SIZEGRIP)
244 STATUSBAR_DrawSizeGrip (hdc, &rect);
251 STATUSBAR_SetPartBounds (HWND hwnd)
253 STATUSWINDOWINFO *self = STATUSBAR_GetInfoPtr (hwnd);
254 STATUSWINDOWPART *part;
258 /* get our window size */
259 GetClientRect (hwnd, &rect);
261 rect.top += VERT_BORDER;
263 /* set bounds for simple rectangle */
264 self->part0.bound = rect;
266 /* set bounds for non-simple rectangles */
267 for (i = 0; i < self->numParts; i++) {
268 part = &self->parts[i];
269 r = &self->parts[i].bound;
271 r->bottom = rect.bottom;
275 r->left = self->parts[i-1].bound.right + HORZ_GAP;
277 r->right = rect.right;
281 if (self->hwndToolTip) {
284 ti.cbSize = sizeof(TTTOOLINFOA);
288 SendMessageA (self->hwndToolTip, TTM_NEWTOOLRECTA,
296 STATUSBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
297 WPARAM wParam, LPARAM lParam)
305 msg.time = GetMessageTime ();
306 msg.pt.x = LOWORD(GetMessagePos ());
307 msg.pt.y = HIWORD(GetMessagePos ());
309 SendMessageA (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
313 inline static LRESULT
314 STATUSBAR_GetBorders (LPARAM lParam)
316 LPINT out = (LPINT) lParam;
318 out[0] = HORZ_BORDER; /* horizontal border width */
319 out[1] = VERT_BORDER; /* vertical border width */
320 out[2] = HORZ_GAP; /* width of border between rectangles */
327 STATUSBAR_GetIcon (HWND hwnd, WPARAM wParam)
329 STATUSWINDOWINFO *self = STATUSBAR_GetInfoPtr (hwnd);
332 nPart = (INT)wParam & 0x00ff;
333 if ((nPart < -1) || (nPart >= self->numParts))
337 return (self->part0.hIcon);
339 return (self->parts[nPart].hIcon);
344 STATUSBAR_GetParts (HWND hwnd, WPARAM wParam, LPARAM lParam)
346 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
351 num_parts = (INT) wParam;
352 parts = (LPINT) lParam;
354 for (i = 0; i < num_parts; i++) {
355 parts[i] = infoPtr->parts[i].x;
358 return (infoPtr->numParts);
363 STATUSBAR_GetRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
365 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
369 part_num = ((INT) wParam) & 0x00ff;
370 rect = (LPRECT) lParam;
372 *rect = infoPtr->part0.bound;
374 *rect = infoPtr->parts[part_num].bound;
380 STATUSBAR_GetTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
382 STATUSWINDOWINFO *self = STATUSBAR_GetInfoPtr (hwnd);
383 STATUSWINDOWPART *part;
387 nPart = ((INT) wParam) & 0x00ff;
391 part = &self->parts[nPart];
393 if (part->style & SBT_OWNERDRAW)
394 result = (LRESULT)part->text;
396 result = part->text ? lstrlenW (part->text) : 0;
397 result |= (part->style << 16);
398 if (lParam && LOWORD(result))
399 lstrcpyWtoA ((LPSTR)lParam, part->text);
406 STATUSBAR_GetTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
408 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
409 STATUSWINDOWPART *part;
413 nPart = ((INT)wParam) & 0x00ff;
415 part = &infoPtr->part0;
417 part = &infoPtr->parts[nPart];
419 if (part->style & SBT_OWNERDRAW)
420 result = (LRESULT)part->text;
422 result = part->text ? lstrlenW (part->text) : 0;
423 result |= (part->style << 16);
424 if (part->text && lParam)
425 strcpyW ((LPWSTR)lParam, part->text);
432 STATUSBAR_GetTextLength (HWND hwnd, WPARAM wParam)
434 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
435 STATUSWINDOWPART *part;
439 part_num = ((INT) wParam) & 0x00ff;
442 part = &infoPtr->part0;
444 part = &infoPtr->parts[part_num];
447 result = lstrlenW(part->text);
451 result |= (part->style << 16);
457 STATUSBAR_GetTipTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
459 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
461 if (infoPtr->hwndToolTip) {
463 ti.cbSize = sizeof(TTTOOLINFOA);
465 ti.uId = LOWORD(wParam);
466 SendMessageA (infoPtr->hwndToolTip, TTM_GETTEXTA, 0, (LPARAM)&ti);
469 lstrcpynA ((LPSTR)lParam, ti.lpszText, HIWORD(wParam));
477 STATUSBAR_GetTipTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
479 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
481 if (infoPtr->hwndToolTip) {
483 ti.cbSize = sizeof(TTTOOLINFOW);
485 ti.uId = LOWORD(wParam);
486 SendMessageW (infoPtr->hwndToolTip, TTM_GETTEXTW, 0, (LPARAM)&ti);
489 lstrcpynW ((LPWSTR)lParam, ti.lpszText, HIWORD(wParam));
496 inline static LRESULT
497 STATUSBAR_GetUnicodeFormat (HWND hwnd)
499 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
500 return infoPtr->bUnicode;
504 inline static LRESULT
505 STATUSBAR_IsSimple (HWND hwnd)
507 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
508 return infoPtr->simple;
513 STATUSBAR_SetBkColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
515 STATUSWINDOWINFO *self = STATUSBAR_GetInfoPtr (hwnd);
518 oldBkColor = self->clrBk;
519 self->clrBk = (COLORREF)lParam;
520 InvalidateRect(hwnd, NULL, FALSE);
527 STATUSBAR_SetIcon (HWND hwnd, WPARAM wParam, LPARAM lParam)
529 STATUSWINDOWINFO *self = STATUSBAR_GetInfoPtr (hwnd);
530 INT nPart = (INT)wParam & 0x00ff;
532 if ((nPart < -1) || (nPart >= self->numParts))
535 TRACE("setting part %d, icon %lx\n",nPart,lParam);
538 if (self->part0.hIcon == (HICON)lParam) /* same as - no redraw */
540 self->part0.hIcon = (HICON)lParam;
542 InvalidateRect(hwnd, &self->part0.bound, FALSE);
544 if (self->parts[nPart].hIcon == (HICON)lParam) /* same as - no redraw */
547 self->parts[nPart].hIcon = (HICON)lParam;
549 InvalidateRect(hwnd, &self->parts[nPart].bound, FALSE);
556 STATUSBAR_SetMinHeight (HWND hwnd, WPARAM wParam, LPARAM lParam)
558 STATUSWINDOWINFO *self = STATUSBAR_GetInfoPtr (hwnd);
560 if (IsWindowVisible (hwnd)) {
561 HWND parent = GetParent (hwnd);
565 GetClientRect (parent, &parent_rect);
566 self->height = (INT)wParam + VERT_BORDER;
567 width = parent_rect.right - parent_rect.left;
568 x = parent_rect.left;
569 y = parent_rect.bottom - self->height;
570 MoveWindow (hwnd, parent_rect.left,
571 parent_rect.bottom - self->height,
572 width, self->height, TRUE);
573 STATUSBAR_SetPartBounds (hwnd);
581 STATUSBAR_SetParts (HWND hwnd, WPARAM wParam, LPARAM lParam)
583 STATUSWINDOWINFO *self = STATUSBAR_GetInfoPtr (hwnd);
584 STATUSWINDOWPART *tmp;
589 TRACE("(%d,%p)\n",wParam,(LPVOID)lParam);
592 self->simple = FALSE;
594 oldNumParts = self->numParts;
595 self->numParts = (INT) wParam;
596 parts = (LPINT) lParam;
597 if (oldNumParts > self->numParts) {
598 for (i = self->numParts ; i < oldNumParts; i++) {
599 if (self->parts[i].text && !(self->parts[i].style & SBT_OWNERDRAW))
600 COMCTL32_Free (self->parts[i].text);
603 if (oldNumParts < self->numParts) {
604 tmp = COMCTL32_Alloc (sizeof(STATUSWINDOWPART) * self->numParts);
605 for (i = 0; i < oldNumParts; i++) {
606 tmp[i] = self->parts[i];
609 COMCTL32_Free (self->parts);
612 if (oldNumParts == self->numParts) {
613 for (i=0;i<oldNumParts;i++)
614 if (self->parts[i].x != parts[i])
616 if (i==oldNumParts) /* Unchanged? no need to redraw! */
620 for (i = 0; i < self->numParts; i++)
621 self->parts[i].x = parts[i];
623 if (self->hwndToolTip) {
625 SendMessageA (self->hwndToolTip, TTM_GETTOOLCOUNT, 0, 0);
627 if (nTipCount < self->numParts) {
632 ZeroMemory (&ti, sizeof(TTTOOLINFOA));
633 ti.cbSize = sizeof(TTTOOLINFOA);
635 for (i = nTipCount; i < self->numParts; i++) {
636 TRACE("add tool %d\n", i);
638 SendMessageA (self->hwndToolTip, TTM_ADDTOOLA,
642 else if (nTipCount > self->numParts) {
646 for (i = nTipCount - 1; i >= self->numParts; i--) {
647 FIXME("delete tool %d\n", i);
651 STATUSBAR_SetPartBounds (hwnd);
652 InvalidateRect(hwnd, NULL, FALSE);
658 STATUSBAR_SetTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
660 STATUSWINDOWINFO *self = STATUSBAR_GetInfoPtr (hwnd);
661 STATUSWINDOWPART *part=NULL;
665 BOOL changed = FALSE;
667 text = (LPSTR) lParam;
668 part_num = ((INT) wParam) & 0x00ff;
669 style = ((INT) wParam) & 0xff00;
671 TRACE("setting part %d, text %s\n",part_num,debugstr_a(text));
675 else if (!self->simple && self->parts!=NULL)
676 part = &self->parts[part_num];
677 if (!part) return FALSE;
679 if (part->style != style)
683 if (style & SBT_OWNERDRAW) {
684 if (part->text == (LPWSTR)text)
686 part->text = (LPWSTR)text;
690 /* check if text is unchanged -> no need to redraw */
692 LPWSTR tmptext = COMCTL32_Alloc((lstrlenA(text)+1)*sizeof(WCHAR));
693 lstrcpyAtoW (tmptext, text);
695 if (!changed && part->text && !lstrcmpW(tmptext,part->text)) {
696 COMCTL32_Free(tmptext);
701 if (!changed && !part->text)
707 COMCTL32_Free (part->text);
710 InvalidateRect(hwnd, &part->bound, FALSE);
717 STATUSBAR_SetTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
719 STATUSWINDOWINFO *self = STATUSBAR_GetInfoPtr (hwnd);
720 STATUSWINDOWPART *part;
721 INT part_num, style, len;
723 BOOL bRedraw = FALSE;
725 text = (LPWSTR) lParam;
726 part_num = ((INT) wParam) & 0x00ff;
727 style = ((INT) wParam) & 0xff00;
729 if ((self->simple) || (self->parts==NULL) || (part_num==255))
732 part = &self->parts[part_num];
733 if (!part) return FALSE;
735 if(part->style != style)
740 /* FIXME: not sure how/if we can check for change in string with ownerdraw(remove this if we can't)... */
741 if (style & SBT_OWNERDRAW)
749 COMCTL32_Free(part->text);
753 } else if(!part->text || strcmpW(part->text, text)) /* see if the new string differs from the existing string */
755 if(part->text) COMCTL32_Free(part->text);
757 len = lstrlenW(text);
758 part->text = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
759 strcpyW(part->text, text);
764 InvalidateRect(hwnd, &part->bound, FALSE);
771 STATUSBAR_SetTipTextA (HWND hwnd, WPARAM wParam, LPARAM lParam)
773 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
775 TRACE("part %d: \"%s\"\n", (INT)wParam, (LPSTR)lParam);
776 if (infoPtr->hwndToolTip) {
778 ti.cbSize = sizeof(TTTOOLINFOA);
780 ti.uId = (INT)wParam;
782 ti.lpszText = (LPSTR)lParam;
783 SendMessageA (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTA,
792 STATUSBAR_SetTipTextW (HWND hwnd, WPARAM wParam, LPARAM lParam)
794 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
796 TRACE("part %d: \"%s\"\n", (INT)wParam, (LPSTR)lParam);
797 if (infoPtr->hwndToolTip) {
799 ti.cbSize = sizeof(TTTOOLINFOW);
801 ti.uId = (INT)wParam;
803 ti.lpszText = (LPWSTR)lParam;
804 SendMessageW (infoPtr->hwndToolTip, TTM_UPDATETIPTEXTW,
812 inline static LRESULT
813 STATUSBAR_SetUnicodeFormat (HWND hwnd, WPARAM wParam)
815 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
816 BOOL bTemp = infoPtr->bUnicode;
818 TRACE("(0x%x)\n", (BOOL)wParam);
819 infoPtr->bUnicode = (BOOL)wParam;
826 STATUSBAR_Simple (HWND hwnd, WPARAM wParam, LPARAM lParam)
828 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
831 if (infoPtr->simple == wParam) /* no need to change */
834 infoPtr->simple = (BOOL)wParam;
836 /* send notification */
837 nmhdr.hwndFrom = hwnd;
838 nmhdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
839 nmhdr.code = SBN_SIMPLEMODECHANGE;
840 SendMessageA (GetParent (hwnd), WM_NOTIFY, 0, (LPARAM)&nmhdr);
841 InvalidateRect(hwnd, NULL, FALSE);
847 STATUSBAR_WMCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
849 LPCREATESTRUCTA lpCreate = (LPCREATESTRUCTA)lParam;
850 NONCLIENTMETRICSA nclm;
855 STATUSWINDOWINFO *self;
857 self = (STATUSWINDOWINFO*)COMCTL32_Alloc (sizeof(STATUSWINDOWINFO));
858 SetWindowLongA (hwnd, 0, (DWORD)self);
862 self->simple = FALSE;
863 self->clrBk = CLR_DEFAULT;
865 GetClientRect (hwnd, &rect);
867 nclm.cbSize = sizeof(NONCLIENTMETRICSA);
868 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS, 0, &nclm, 0);
869 self->hDefaultFont = CreateFontIndirectA (&nclm.lfStatusFont);
871 /* initialize simple case */
872 self->part0.bound = rect;
873 self->part0.text = 0;
875 self->part0.style = 0;
876 self->part0.hIcon = 0;
878 /* initialize first part */
879 self->parts = COMCTL32_Alloc (sizeof(STATUSWINDOWPART));
880 self->parts[0].bound = rect;
881 self->parts[0].text = 0;
882 self->parts[0].x = -1;
883 self->parts[0].style = 0;
884 self->parts[0].hIcon = 0;
886 if (IsWindowUnicode (hwnd)) {
887 self->bUnicode = TRUE;
888 if (lpCreate->lpszName &&
889 (len = lstrlenW ((LPCWSTR)lpCreate->lpszName))) {
890 self->parts[0].text = COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
891 strcpyW (self->parts[0].text, (LPCWSTR)lpCreate->lpszName);
895 if (lpCreate->lpszName &&
896 (len = lstrlenA ((LPCSTR)lpCreate->lpszName))) {
897 self->parts[0].text = COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
898 lstrcpyAtoW (self->parts[0].text, (LPCSTR)lpCreate->lpszName);
902 dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
904 /* statusbars on managed windows should not have SIZEGRIP style */
905 if ((dwStyle & SBARS_SIZEGRIP) && lpCreate->hwndParent)
906 if (GetWindowLongA(lpCreate->hwndParent, GWL_EXSTYLE) & WS_EX_MANAGED)
907 SetWindowLongA (hwnd, GWL_STYLE, dwStyle & ~SBARS_SIZEGRIP);
909 if ((hdc = GetDC (0))) {
913 hOldFont = SelectObject (hdc,self->hDefaultFont);
914 GetTextMetricsA(hdc, &tm);
915 self->textHeight = tm.tmHeight;
916 SelectObject (hdc, hOldFont);
920 if (dwStyle & SBT_TOOLTIPS) {
922 CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
923 CW_USEDEFAULT, CW_USEDEFAULT,
924 CW_USEDEFAULT, CW_USEDEFAULT,
926 GetWindowLongA (hwnd, GWL_HINSTANCE), NULL);
928 if (self->hwndToolTip) {
929 NMTOOLTIPSCREATED nmttc;
931 nmttc.hdr.hwndFrom = hwnd;
932 nmttc.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
933 nmttc.hdr.code = NM_TOOLTIPSCREATED;
934 nmttc.hwndToolTips = self->hwndToolTip;
936 SendMessageA (GetParent (hwnd), WM_NOTIFY,
937 (WPARAM)nmttc.hdr.idFrom, (LPARAM)&nmttc);
941 GetClientRect (GetParent (hwnd), &rect);
942 width = rect.right - rect.left;
943 self->height = self->textHeight + 4 + VERT_BORDER;
944 MoveWindow (hwnd, lpCreate->x, lpCreate->y - 1,
945 width, self->height, FALSE);
946 STATUSBAR_SetPartBounds (hwnd);
953 STATUSBAR_WMDestroy (HWND hwnd)
955 STATUSWINDOWINFO *self = STATUSBAR_GetInfoPtr (hwnd);
958 for (i = 0; i < self->numParts; i++) {
959 if (self->parts[i].text && !(self->parts[i].style & SBT_OWNERDRAW))
960 COMCTL32_Free (self->parts[i].text);
962 if (self->part0.text && !(self->part0.style & SBT_OWNERDRAW))
963 COMCTL32_Free (self->part0.text);
964 COMCTL32_Free (self->parts);
966 /* delete default font */
967 if (self->hDefaultFont)
968 DeleteObject (self->hDefaultFont);
970 /* delete tool tip control */
971 if (self->hwndToolTip)
972 DestroyWindow (self->hwndToolTip);
974 COMCTL32_Free (self);
975 SetWindowLongA(hwnd, 0, 0);
980 static inline LRESULT
981 STATUSBAR_WMGetFont (HWND hwnd)
983 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
984 return infoPtr->hFont? infoPtr->hFont : infoPtr->hDefaultFont;
989 STATUSBAR_WMGetText (HWND hwnd, WPARAM wParam, LPARAM lParam)
991 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
994 if (!(infoPtr->parts[0].text))
996 len = lstrlenW (infoPtr->parts[0].text);
998 if (infoPtr->bUnicode)
999 strcpyW ((LPWSTR)lParam, infoPtr->parts[0].text);
1001 lstrcpyWtoA ((LPSTR)lParam, infoPtr->parts[0].text);
1009 inline static LRESULT
1010 STATUSBAR_WMMouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
1012 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
1014 if (infoPtr->hwndToolTip)
1015 STATUSBAR_RelayEvent (infoPtr->hwndToolTip, hwnd,
1016 WM_MOUSEMOVE, wParam, lParam);
1022 STATUSBAR_WMNCHitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
1024 if (GetWindowLongA (hwnd, GWL_STYLE) & SBARS_SIZEGRIP) {
1028 GetClientRect (hwnd, &rect);
1030 pt.x = (INT)LOWORD(lParam);
1031 pt.y = (INT)HIWORD(lParam);
1032 ScreenToClient (hwnd, &pt);
1034 rect.left = rect.right - 13;
1037 if (PtInRect (&rect, pt))
1038 return HTBOTTOMRIGHT;
1041 return DefWindowProcA (hwnd, WM_NCHITTEST, wParam, lParam);
1045 static inline LRESULT
1046 STATUSBAR_WMNCLButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
1048 PostMessageA (GetParent (hwnd), WM_NCLBUTTONDOWN, wParam, lParam);
1053 static inline LRESULT
1054 STATUSBAR_WMNCLButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1056 PostMessageA (GetParent (hwnd), WM_NCLBUTTONUP, wParam, lParam);
1062 STATUSBAR_WMPaint (HWND hwnd, WPARAM wParam)
1067 hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
1068 STATUSBAR_Refresh (hwnd, hdc);
1070 EndPaint (hwnd, &ps);
1077 STATUSBAR_WMSetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
1079 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
1081 infoPtr->hFont = (HFONT)wParam;
1082 if (LOWORD(lParam) == TRUE)
1083 InvalidateRect(hwnd, NULL, FALSE);
1090 STATUSBAR_WMSetText (HWND hwnd, WPARAM wParam, LPARAM lParam)
1092 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
1093 STATUSWINDOWPART *part;
1096 if (infoPtr->numParts == 0)
1099 part = &infoPtr->parts[0];
1100 /* duplicate string */
1102 COMCTL32_Free (part->text);
1104 if (infoPtr->bUnicode) {
1105 if (lParam && (len = lstrlenW((LPCWSTR)lParam))) {
1106 part->text = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
1107 strcpyW (part->text, (LPCWSTR)lParam);
1111 if (lParam && (len = lstrlenA((LPCSTR)lParam))) {
1112 part->text = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
1113 lstrcpyAtoW (part->text, (LPCSTR)lParam);
1117 InvalidateRect(hwnd, &part->bound, FALSE);
1124 STATUSBAR_WMSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
1126 STATUSWINDOWINFO *infoPtr = STATUSBAR_GetInfoPtr (hwnd);
1127 INT width, x, y, flags;
1131 /* Need to resize width to match parent */
1132 flags = (INT) wParam;
1134 /* FIXME for flags =
1135 * SIZE_MAXIMIZED, SIZE_MAXSHOW, SIZE_MINIMIZED, SIZE_RESTORED
1138 if (flags == SIZE_RESTORED) {
1139 /* width and height don't apply */
1140 parent = GetParent (hwnd);
1141 GetClientRect (parent, &parent_rect);
1142 width = parent_rect.right - parent_rect.left;
1143 x = parent_rect.left;
1144 y = parent_rect.bottom - infoPtr->height;
1145 MoveWindow (hwnd, parent_rect.left,
1146 parent_rect.bottom - infoPtr->height,
1147 width, infoPtr->height, TRUE);
1148 STATUSBAR_SetPartBounds (hwnd);
1155 STATUSBAR_SendNotify (HWND hwnd, UINT code)
1159 nmhdr.hwndFrom = hwnd;
1160 nmhdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
1162 SendMessageA (GetParent (hwnd), WM_NOTIFY, 0, (LPARAM)&nmhdr);
1168 static LRESULT WINAPI
1169 StatusWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1171 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n", hwnd, msg, wParam, lParam);
1172 if (!(STATUSBAR_GetInfoPtr(hwnd)) && (msg != WM_CREATE))
1173 return DefWindowProcA (hwnd, msg, wParam, lParam);
1177 return STATUSBAR_GetBorders (lParam);
1180 return STATUSBAR_GetIcon (hwnd, wParam);
1183 return STATUSBAR_GetParts (hwnd, wParam, lParam);
1186 return STATUSBAR_GetRect (hwnd, wParam, lParam);
1189 return STATUSBAR_GetTextA (hwnd, wParam, lParam);
1192 return STATUSBAR_GetTextW (hwnd, wParam, lParam);
1194 case SB_GETTEXTLENGTHA:
1195 case SB_GETTEXTLENGTHW:
1196 return STATUSBAR_GetTextLength (hwnd, wParam);
1198 case SB_GETTIPTEXTA:
1199 return STATUSBAR_GetTipTextA (hwnd, wParam, lParam);
1201 case SB_GETTIPTEXTW:
1202 return STATUSBAR_GetTipTextW (hwnd, wParam, lParam);
1204 case SB_GETUNICODEFORMAT:
1205 return STATUSBAR_GetUnicodeFormat (hwnd);
1208 return STATUSBAR_IsSimple (hwnd);
1211 return STATUSBAR_SetBkColor (hwnd, wParam, lParam);
1214 return STATUSBAR_SetIcon (hwnd, wParam, lParam);
1216 case SB_SETMINHEIGHT:
1217 return STATUSBAR_SetMinHeight (hwnd, wParam, lParam);
1220 return STATUSBAR_SetParts (hwnd, wParam, lParam);
1223 return STATUSBAR_SetTextA (hwnd, wParam, lParam);
1226 return STATUSBAR_SetTextW (hwnd, wParam, lParam);
1228 case SB_SETTIPTEXTA:
1229 return STATUSBAR_SetTipTextA (hwnd, wParam, lParam);
1231 case SB_SETTIPTEXTW:
1232 return STATUSBAR_SetTipTextW (hwnd, wParam, lParam);
1234 case SB_SETUNICODEFORMAT:
1235 return STATUSBAR_SetUnicodeFormat (hwnd, wParam);
1238 return STATUSBAR_Simple (hwnd, wParam, lParam);
1242 return STATUSBAR_WMCreate (hwnd, wParam, lParam);
1245 return STATUSBAR_WMDestroy (hwnd);
1248 return STATUSBAR_WMGetFont (hwnd);
1251 return STATUSBAR_WMGetText (hwnd, wParam, lParam);
1253 case WM_GETTEXTLENGTH:
1254 return STATUSBAR_GetTextLength (hwnd, 0);
1256 case WM_LBUTTONDBLCLK:
1257 return STATUSBAR_SendNotify (hwnd, NM_DBLCLK);
1260 return STATUSBAR_SendNotify (hwnd, NM_CLICK);
1263 return STATUSBAR_WMMouseMove (hwnd, wParam, lParam);
1266 return STATUSBAR_WMNCHitTest (hwnd, wParam, lParam);
1268 case WM_NCLBUTTONDOWN:
1269 return STATUSBAR_WMNCLButtonDown (hwnd, wParam, lParam);
1271 case WM_NCLBUTTONUP:
1272 return STATUSBAR_WMNCLButtonUp (hwnd, wParam, lParam);
1275 return STATUSBAR_WMPaint (hwnd, wParam);
1277 case WM_RBUTTONDBLCLK:
1278 return STATUSBAR_SendNotify (hwnd, NM_RDBLCLK);
1281 return STATUSBAR_SendNotify (hwnd, NM_RCLICK);
1284 return STATUSBAR_WMSetFont (hwnd, wParam, lParam);
1287 return STATUSBAR_WMSetText (hwnd, wParam, lParam);
1290 return STATUSBAR_WMSize (hwnd, wParam, lParam);
1294 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1295 msg, wParam, lParam);
1296 return DefWindowProcA (hwnd, msg, wParam, lParam);
1302 /***********************************************************************
1303 * STATUS_Register [Internal]
1305 * Registers the status window class.
1309 STATUS_Register (void)
1313 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
1314 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW;
1315 wndClass.lpfnWndProc = (WNDPROC)StatusWindowProc;
1316 wndClass.cbClsExtra = 0;
1317 wndClass.cbWndExtra = sizeof(STATUSWINDOWINFO *);
1318 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
1319 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
1320 wndClass.lpszClassName = STATUSCLASSNAMEA;
1322 RegisterClassA (&wndClass);
1326 /***********************************************************************
1327 * STATUS_Unregister [Internal]
1329 * Unregisters the status window class.
1333 STATUS_Unregister (void)
1335 UnregisterClassA (STATUSCLASSNAMEA, (HINSTANCE)NULL);