]>
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"
25 #include "wx/settings.h"
26 #include "wx/dcclient.h"
31 #include "wx/msw/private.h"
34 // include <commctrl.h> "properly"
35 #include "wx/msw/wrapcctl.h"
38 #include "wx/msw/uxtheme.h"
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
45 // windowsx.h and commctrl.h don't define those, so we do it here
46 #define StatusBar_SetParts(h, n, w) SendMessage(h, SB_SETPARTS, (WPARAM)n, (LPARAM)w)
47 #define StatusBar_SetText(h, n, t) SendMessage(h, SB_SETTEXT, (WPARAM)n, (LPARAM)(LPCTSTR)t)
48 #define StatusBar_GetTextLen(h, n) LOWORD(SendMessage(h, SB_GETTEXTLENGTH, (WPARAM)n, 0))
49 #define StatusBar_GetText(h, n, s) LOWORD(SendMessage(h, SB_GETTEXT, (WPARAM)n, (LPARAM)(LPTSTR)s))
51 // ============================================================================
53 // ============================================================================
55 // ----------------------------------------------------------------------------
56 // wxStatusBar95 class
57 // ----------------------------------------------------------------------------
59 wxStatusBar95::wxStatusBar95()
66 bool wxStatusBar95::Create(wxWindow
*parent
,
71 wxCHECK_MSG( parent
, false, wxT("status bar must have a parent") );
74 SetWindowStyleFlag(style
);
77 parent
->AddChild(this);
79 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
81 DWORD wstyle
= WS_CHILD
| WS_VISIBLE
;
83 if ( style
& wxCLIP_SIBLINGS
)
84 wstyle
|= WS_CLIPSIBLINGS
;
86 // setting SBARS_SIZEGRIP is perfectly useless: it's always on by default
87 // (at least in the version of comctl32.dll I'm using), and the only way to
88 // turn it off is to use CCS_TOP style - as we position the status bar
89 // manually anyhow (see DoMoveWindow), use CCS_TOP style if wxST_SIZEGRIP
91 if ( !(style
& wxST_SIZEGRIP
) )
98 // may be some versions of comctl32.dll do need it - anyhow, it won't
100 wstyle
|= SBARS_SIZEGRIP
;
104 m_hWnd
= (WXHWND
)CreateStatusWindow(wstyle
,
110 wxLogSysError(_("Failed to create a status bar."));
119 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR
));
121 // we must refresh the frame size when the statusbar is created, because
122 // its client area might change
123 wxFrame
*frame
= wxDynamicCast(GetParent(), wxFrame
);
126 frame
->SendSizeEvent();
132 wxStatusBar95::~wxStatusBar95()
134 // we must refresh the frame size when the statusbar is deleted but the
135 // frame is not - otherwise statusbar leaves a hole in the place it used to
137 wxFrame
*frame
= wxDynamicCast(GetParent(), wxFrame
);
138 if ( frame
&& !frame
->IsBeingDeleted() )
140 frame
->SendSizeEvent();
144 void wxStatusBar95::SetFieldsCount(int nFields
, const int *widths
)
146 // this is a Windows limitation
147 wxASSERT_MSG( (nFields
> 0) && (nFields
< 255), _T("too many fields") );
149 wxStatusBarBase::SetFieldsCount(nFields
, widths
);
154 void wxStatusBar95::SetStatusWidths(int n
, const int widths
[])
156 wxStatusBarBase::SetStatusWidths(n
, widths
);
161 void wxStatusBar95::SetFieldsWidth()
167 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
169 int extraWidth
= aBorders
[2]; // space between fields
171 wxArrayInt widthsAbs
=
172 CalculateAbsWidths(GetClientSize().x
- extraWidth
*(m_nFields
- 1));
174 int *pWidths
= new int[m_nFields
];
177 for ( int i
= 0; i
< m_nFields
; i
++ ) {
178 nCurPos
+= widthsAbs
[i
] + extraWidth
;
179 pWidths
[i
] = nCurPos
;
182 if ( !StatusBar_SetParts(GetHwnd(), m_nFields
, pWidths
) ) {
183 wxLogLastError(wxT("StatusBar_SetParts"));
189 void wxStatusBar95::SetStatusText(const wxString
& strText
, int nField
)
191 wxCHECK_RET( (nField
>= 0) && (nField
< m_nFields
),
192 _T("invalid statusbar field index") );
194 // Get field style, if any
198 switch(m_statusStyles
[nField
])
204 style
= SBT_NOBORDERS
;
215 // Pass both field number and style. MSDN library doesn't mention
216 // that nField and style have to be 'ORed'
217 if ( !StatusBar_SetText(GetHwnd(), nField
| style
, strText
) )
219 wxLogLastError(wxT("StatusBar_SetText"));
223 wxString
wxStatusBar95::GetStatusText(int nField
) const
225 wxCHECK_MSG( (nField
>= 0) && (nField
< m_nFields
), wxEmptyString
,
226 _T("invalid statusbar field index") );
229 int len
= StatusBar_GetTextLen(GetHwnd(), nField
);
232 StatusBar_GetText(GetHwnd(), nField
, wxStringBuffer(str
, len
));
238 int wxStatusBar95::GetBorderX() const
241 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
246 int wxStatusBar95::GetBorderY() const
249 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
254 void wxStatusBar95::SetMinHeight(int height
)
256 SendMessage(GetHwnd(), SB_SETMINHEIGHT
, height
+ 2*GetBorderY(), 0);
258 // have to send a (dummy) WM_SIZE to redraw it now
259 SendMessage(GetHwnd(), WM_SIZE
, 0, 0);
262 bool wxStatusBar95::GetFieldRect(int i
, wxRect
& rect
) const
264 wxCHECK_MSG( (i
>= 0) && (i
< m_nFields
), false,
265 _T("invalid statusbar field index") );
268 if ( !::SendMessage(GetHwnd(), SB_GETRECT
, i
, (LPARAM
)&r
) )
270 wxLogLastError(wxT("SendMessage(SB_GETRECT)"));
274 wxUxThemeHandle
theme((wxStatusBar95
*)this, L
"Status"); // const_cast
277 // by default Windows has a 2 pixel border to the right of the left
278 // divider (or it could be a bug) but it looks wrong so remove it
284 wxUxThemeEngine::Get()->GetThemeBackgroundContentRect(theme
, NULL
,
290 wxCopyRECTToRect(r
, rect
);
295 void wxStatusBar95::DoMoveWindow(int x
, int y
, int width
, int height
)
297 if ( GetParent()->IsSizeDeferred() )
299 wxWindowMSW::DoMoveWindow(x
, y
, width
, height
);
303 // parent pos/size isn't deferred so do it now but don't send
304 // WM_WINDOWPOSCHANGING since we don't want to change pos/size later
305 // we must use SWP_NOCOPYBITS here otherwise it paints incorrectly
306 // if other windows are size deferred
307 ::SetWindowPos(GetHwnd(), NULL
, x
, y
, width
, height
,
308 SWP_NOZORDER
| SWP_NOOWNERZORDER
| SWP_NOACTIVATE
310 | SWP_NOCOPYBITS
| SWP_NOSENDCHANGING
315 // adjust fields widths to the new size
318 // we have to trigger wxSizeEvent if there are children window in status
319 // bar because GetFieldRect returned incorrect (not updated) values up to
320 // here, which almost certainly resulted in incorrectly redrawn statusbar
321 if ( m_children
.GetCount() > 0 )
323 wxSizeEvent
event(GetClientSize(), m_windowId
);
324 event
.SetEventObject(this);
325 GetEventHandler()->ProcessEvent(event
);
329 void wxStatusBar95::SetStatusStyles(int n
, const int styles
[])
331 wxStatusBarBase::SetStatusStyles(n
, styles
);
336 for (int i
= 0; i
< n
; i
++)
345 style
= SBT_NOBORDERS
;
352 // The SB_SETTEXT message is both used to set the field's text as well as
353 // the fields' styles. MSDN library doesn't mention
354 // that nField and style have to be 'ORed'
355 wxString text
= GetStatusText(i
);
356 if (!StatusBar_SetText(GetHwnd(), style
| i
, text
))
358 wxLogLastError(wxT("StatusBar_SetText"));
364 wxStatusBar95::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
367 if ( nMsg
== WM_WINDOWPOSCHANGING
)
369 WINDOWPOS
*lpPos
= (WINDOWPOS
*)lParam
;
374 // we need real window coords and not wx client coords
375 AdjustForParentClientOrigin(x
, y
);
385 if ( nMsg
== WM_NCLBUTTONDOWN
)
387 // if hit-test is on gripper then send message to TLW to begin
388 // resizing. It is possible to send this message to any window.
389 if ( wParam
== HTBOTTOMRIGHT
)
393 for ( win
= GetParent(); win
; win
= win
->GetParent() )
395 if ( win
->IsTopLevel() )
397 SendMessage(GetHwndOf(win
), WM_NCLBUTTONDOWN
,
407 return wxStatusBarBase::MSWWindowProc(nMsg
, wParam
, lParam
);
410 #endif // wxUSE_STATUSBAR && wxUSE_NATIVE_STATUSBAR