]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/statbr95.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/statbr95.cpp
3 // Purpose: native implementation of wxStatusBar
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // for compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
19 #if wxUSE_STATUSBAR && wxUSE_NATIVE_STATUSBAR
21 #include "wx/statusbr.h"
24 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
26 #include "wx/settings.h"
27 #include "wx/dcclient.h"
32 #include "wx/msw/private.h"
36 #include "wx/msw/uxtheme.h"
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 // windowsx.h and commctrl.h don't define those, so we do it here
44 #define StatusBar_SetParts(h, n, w) SendMessage(h, SB_SETPARTS, (WPARAM)n, (LPARAM)w)
45 #define StatusBar_SetText(h, n, t) SendMessage(h, SB_SETTEXT, (WPARAM)n, (LPARAM)(LPCTSTR)t)
46 #define StatusBar_GetTextLen(h, n) LOWORD(SendMessage(h, SB_GETTEXTLENGTH, (WPARAM)n, 0))
47 #define StatusBar_GetText(h, n, s) LOWORD(SendMessage(h, SB_GETTEXT, (WPARAM)n, (LPARAM)(LPTSTR)s))
49 // ============================================================================
51 // ============================================================================
53 // ----------------------------------------------------------------------------
54 // wxStatusBar95 class
55 // ----------------------------------------------------------------------------
57 wxStatusBar95::wxStatusBar95()
64 bool wxStatusBar95::Create(wxWindow
*parent
,
69 wxCHECK_MSG( parent
, false, wxT("status bar must have a parent") );
72 SetWindowStyleFlag(style
);
75 parent
->AddChild(this);
77 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
79 DWORD wstyle
= WS_CHILD
| WS_VISIBLE
;
81 if ( style
& wxCLIP_SIBLINGS
)
82 wstyle
|= WS_CLIPSIBLINGS
;
84 // setting SBARS_SIZEGRIP is perfectly useless: it's always on by default
85 // (at least in the version of comctl32.dll I'm using), and the only way to
86 // turn it off is to use CCS_TOP style - as we position the status bar
87 // manually anyhow (see DoMoveWindow), use CCS_TOP style if wxST_SIZEGRIP
89 if ( !(style
& wxST_SIZEGRIP
) )
96 // may be some versions of comctl32.dll do need it - anyhow, it won't
98 wstyle
|= SBARS_SIZEGRIP
;
102 m_hWnd
= CreateWindow
109 (HMENU
)m_windowId
.GetValue(),
115 wxLogSysError(_("Failed to create a status bar."));
124 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR
));
126 // we must refresh the frame size when the statusbar is created, because
127 // its client area might change
128 wxFrame
*frame
= wxDynamicCast(GetParent(), wxFrame
);
131 frame
->SendSizeEvent();
137 wxStatusBar95::~wxStatusBar95()
139 // we must refresh the frame size when the statusbar is deleted but the
140 // frame is not - otherwise statusbar leaves a hole in the place it used to
142 wxFrame
*frame
= wxDynamicCast(GetParent(), wxFrame
);
143 if ( frame
&& !frame
->IsBeingDeleted() )
145 frame
->SendSizeEvent();
149 void wxStatusBar95::SetFieldsCount(int nFields
, const int *widths
)
151 // this is a Windows limitation
152 wxASSERT_MSG( (nFields
> 0) && (nFields
< 255), _T("too many fields") );
154 wxStatusBarBase::SetFieldsCount(nFields
, widths
);
159 void wxStatusBar95::SetStatusWidths(int n
, const int widths
[])
161 wxStatusBarBase::SetStatusWidths(n
, widths
);
166 void wxStatusBar95::SetFieldsWidth()
172 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
174 int extraWidth
= aBorders
[2]; // space between fields
176 wxArrayInt widthsAbs
=
177 CalculateAbsWidths(GetClientSize().x
- extraWidth
*(m_nFields
- 1));
179 int *pWidths
= new int[m_nFields
];
182 for ( int i
= 0; i
< m_nFields
; i
++ ) {
183 nCurPos
+= widthsAbs
[i
] + extraWidth
;
184 pWidths
[i
] = nCurPos
;
187 if ( !StatusBar_SetParts(GetHwnd(), m_nFields
, pWidths
) ) {
188 wxLogLastError(wxT("StatusBar_SetParts"));
194 void wxStatusBar95::SetStatusText(const wxString
& strText
, int nField
)
196 wxCHECK_RET( (nField
>= 0) && (nField
< m_nFields
),
197 _T("invalid statusbar field index") );
199 if ( strText
== GetStatusText(nField
) )
201 // don't call StatusBar_SetText() to avoid flicker
205 // Get field style, if any
209 switch(m_statusStyles
[nField
])
215 style
= SBT_NOBORDERS
;
226 // Pass both field number and style. MSDN library doesn't mention
227 // that nField and style have to be 'ORed'
228 if ( !StatusBar_SetText(GetHwnd(), nField
| style
, strText
.wx_str()) )
230 wxLogLastError(wxT("StatusBar_SetText"));
234 wxString
wxStatusBar95::GetStatusText(int nField
) const
236 wxCHECK_MSG( (nField
>= 0) && (nField
< m_nFields
), wxEmptyString
,
237 _T("invalid statusbar field index") );
240 int len
= StatusBar_GetTextLen(GetHwnd(), nField
);
243 StatusBar_GetText(GetHwnd(), nField
, wxStringBuffer(str
, len
));
249 int wxStatusBar95::GetBorderX() const
252 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
257 int wxStatusBar95::GetBorderY() const
260 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
265 void wxStatusBar95::SetMinHeight(int height
)
267 SendMessage(GetHwnd(), SB_SETMINHEIGHT
, height
+ 2*GetBorderY(), 0);
269 // have to send a (dummy) WM_SIZE to redraw it now
270 SendMessage(GetHwnd(), WM_SIZE
, 0, 0);
273 bool wxStatusBar95::GetFieldRect(int i
, wxRect
& rect
) const
275 wxCHECK_MSG( (i
>= 0) && (i
< m_nFields
), false,
276 _T("invalid statusbar field index") );
279 if ( !::SendMessage(GetHwnd(), SB_GETRECT
, i
, (LPARAM
)&r
) )
281 wxLogLastError(wxT("SendMessage(SB_GETRECT)"));
285 wxUxThemeHandle
theme((wxStatusBar95
*)this, L
"Status"); // const_cast
288 // by default Windows has a 2 pixel border to the right of the left
289 // divider (or it could be a bug) but it looks wrong so remove it
295 wxUxThemeEngine::Get()->GetThemeBackgroundContentRect(theme
, NULL
,
301 wxCopyRECTToRect(r
, rect
);
306 // no idea for a default width, just choose something
307 #define DEFAULT_FIELD_WIDTH 25
309 wxSize
wxStatusBar95::DoGetBestSize() const
312 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)borders
);
316 for ( int i
= 0; i
< m_nFields
; ++i
)
318 int widthField
= m_statusWidths
? m_statusWidths
[i
]
319 : DEFAULT_FIELD_WIDTH
;
320 if ( widthField
>= 0 )
322 width
+= m_statusWidths
[i
];
326 // variable width field, its width is really a proportion
327 // related to the other fields
328 width
+= -widthField
*DEFAULT_FIELD_WIDTH
;
331 // add the space between fields
337 // still need something even for an empty status bar
338 width
= 2*DEFAULT_FIELD_WIDTH
;
344 wxGetCharSize(GetHWND(), NULL
, &height
, GetFont());
345 height
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(height
);
346 height
+= borders
[1];
348 wxSize
best(width
, height
);
353 void wxStatusBar95::DoMoveWindow(int x
, int y
, int width
, int height
)
355 if ( GetParent()->IsSizeDeferred() )
357 wxWindowMSW::DoMoveWindow(x
, y
, width
, height
);
361 // parent pos/size isn't deferred so do it now but don't send
362 // WM_WINDOWPOSCHANGING since we don't want to change pos/size later
363 // we must use SWP_NOCOPYBITS here otherwise it paints incorrectly
364 // if other windows are size deferred
365 ::SetWindowPos(GetHwnd(), NULL
, x
, y
, width
, height
,
366 SWP_NOZORDER
| SWP_NOOWNERZORDER
| SWP_NOACTIVATE
368 | SWP_NOCOPYBITS
| SWP_NOSENDCHANGING
373 // adjust fields widths to the new size
376 // we have to trigger wxSizeEvent if there are children window in status
377 // bar because GetFieldRect returned incorrect (not updated) values up to
378 // here, which almost certainly resulted in incorrectly redrawn statusbar
379 if ( m_children
.GetCount() > 0 )
381 wxSizeEvent
event(GetClientSize(), m_windowId
);
382 event
.SetEventObject(this);
383 HandleWindowEvent(event
);
387 void wxStatusBar95::SetStatusStyles(int n
, const int styles
[])
389 wxStatusBarBase::SetStatusStyles(n
, styles
);
394 for (int i
= 0; i
< n
; i
++)
403 style
= SBT_NOBORDERS
;
410 // The SB_SETTEXT message is both used to set the field's text as well as
411 // the fields' styles. MSDN library doesn't mention
412 // that nField and style have to be 'ORed'
413 wxString text
= GetStatusText(i
);
414 if (!StatusBar_SetText(GetHwnd(), style
| i
, text
.wx_str()))
416 wxLogLastError(wxT("StatusBar_SetText"));
422 wxStatusBar95::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
425 if ( nMsg
== WM_WINDOWPOSCHANGING
)
427 WINDOWPOS
*lpPos
= (WINDOWPOS
*)lParam
;
432 // we need real window coords and not wx client coords
433 AdjustForParentClientOrigin(x
, y
);
443 if ( nMsg
== WM_NCLBUTTONDOWN
)
445 // if hit-test is on gripper then send message to TLW to begin
446 // resizing. It is possible to send this message to any window.
447 if ( wParam
== HTBOTTOMRIGHT
)
451 for ( win
= GetParent(); win
; win
= win
->GetParent() )
453 if ( win
->IsTopLevel() )
455 SendMessage(GetHwndOf(win
), WM_NCLBUTTONDOWN
,
465 return wxStatusBarBase::MSWWindowProc(nMsg
, wParam
, lParam
);
468 #endif // wxUSE_STATUSBAR && wxUSE_NATIVE_STATUSBAR