]>
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"
22 #include "wx/settings.h"
23 #include "wx/dcclient.h"
26 #if wxUSE_STATUSBAR && wxUSE_NATIVE_STATUSBAR
30 #include "wx/statusbr.h"
32 #include "wx/msw/private.h"
35 // include <commctrl.h> "properly"
36 #include "wx/msw/wrapcctl.h"
39 #include "wx/msw/uxtheme.h"
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
46 // windowsx.h and commctrl.h don't define those, so we do it here
47 #define StatusBar_SetParts(h, n, w) SendMessage(h, SB_SETPARTS, (WPARAM)n, (LPARAM)w)
48 #define StatusBar_SetText(h, n, t) SendMessage(h, SB_SETTEXT, (WPARAM)n, (LPARAM)(LPCTSTR)t)
49 #define StatusBar_GetTextLen(h, n) LOWORD(SendMessage(h, SB_GETTEXTLENGTH, (WPARAM)n, 0))
50 #define StatusBar_GetText(h, n, s) LOWORD(SendMessage(h, SB_GETTEXT, (WPARAM)n, (LPARAM)(LPTSTR)s))
52 // ============================================================================
54 // ============================================================================
56 // ----------------------------------------------------------------------------
57 // wxStatusBar95 class
58 // ----------------------------------------------------------------------------
60 wxStatusBar95::wxStatusBar95()
67 bool wxStatusBar95::Create(wxWindow
*parent
,
72 wxCHECK_MSG( parent
, false, wxT("status bar must have a parent") );
75 SetWindowStyleFlag(style
);
78 parent
->AddChild(this);
80 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
82 DWORD wstyle
= WS_CHILD
| WS_VISIBLE
;
84 if ( style
& wxCLIP_SIBLINGS
)
85 wstyle
|= WS_CLIPSIBLINGS
;
87 // setting SBARS_SIZEGRIP is perfectly useless: it's always on by default
88 // (at least in the version of comctl32.dll I'm using), and the only way to
89 // turn it off is to use CCS_TOP style - as we position the status bar
90 // manually anyhow (see DoMoveWindow), use CCS_TOP style if wxST_SIZEGRIP
92 if ( !(style
& wxST_SIZEGRIP
) )
99 // may be some versions of comctl32.dll do need it - anyhow, it won't
101 wstyle
|= SBARS_SIZEGRIP
;
105 m_hWnd
= (WXHWND
)CreateStatusWindow(wstyle
,
111 wxLogSysError(_("Failed to create a status bar."));
120 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR
));
122 // we must refresh the frame size when the statusbar is created, because
123 // its client area might change
124 wxFrame
*frame
= wxDynamicCast(GetParent(), wxFrame
);
127 frame
->SendSizeEvent();
133 wxStatusBar95::~wxStatusBar95()
135 // we must refresh the frame size when the statusbar is deleted but the
136 // frame is not - otherwise statusbar leaves a hole in the place it used to
138 wxFrame
*frame
= wxDynamicCast(GetParent(), wxFrame
);
139 if ( frame
&& !frame
->IsBeingDeleted() )
141 frame
->SendSizeEvent();
145 void wxStatusBar95::SetFieldsCount(int nFields
, const int *widths
)
147 // this is a Windows limitation
148 wxASSERT_MSG( (nFields
> 0) && (nFields
< 255), _T("too many fields") );
150 wxStatusBarBase::SetFieldsCount(nFields
, widths
);
155 void wxStatusBar95::SetStatusWidths(int n
, const int widths
[])
157 wxStatusBarBase::SetStatusWidths(n
, widths
);
162 void wxStatusBar95::SetFieldsWidth()
168 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
170 int extraWidth
= aBorders
[2]; // space between fields
172 wxArrayInt widthsAbs
=
173 CalculateAbsWidths(GetClientSize().x
- extraWidth
*(m_nFields
- 1));
175 int *pWidths
= new int[m_nFields
];
178 for ( int i
= 0; i
< m_nFields
; i
++ ) {
179 nCurPos
+= widthsAbs
[i
] + extraWidth
;
180 pWidths
[i
] = nCurPos
;
183 if ( !StatusBar_SetParts(GetHwnd(), m_nFields
, pWidths
) ) {
184 wxLogLastError(wxT("StatusBar_SetParts"));
190 void wxStatusBar95::SetStatusText(const wxString
& strText
, int nField
)
192 wxCHECK_RET( (nField
>= 0) && (nField
< m_nFields
),
193 _T("invalid statusbar field index") );
195 // Get field style, if any
199 switch(m_statusStyles
[nField
])
205 style
= SBT_NOBORDERS
;
216 // Pass both field number and style. MSDN library doesn't mention
217 // that nField and style have to be 'ORed'
218 if ( !StatusBar_SetText(GetHwnd(), nField
| style
, strText
) )
220 wxLogLastError(wxT("StatusBar_SetText"));
224 wxString
wxStatusBar95::GetStatusText(int nField
) const
226 wxCHECK_MSG( (nField
>= 0) && (nField
< m_nFields
), wxEmptyString
,
227 _T("invalid statusbar field index") );
230 int len
= StatusBar_GetTextLen(GetHwnd(), nField
);
233 StatusBar_GetText(GetHwnd(), nField
, wxStringBuffer(str
, len
));
239 int wxStatusBar95::GetBorderX() const
242 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
247 int wxStatusBar95::GetBorderY() const
250 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
255 void wxStatusBar95::SetMinHeight(int height
)
257 SendMessage(GetHwnd(), SB_SETMINHEIGHT
, height
+ 2*GetBorderY(), 0);
259 // have to send a (dummy) WM_SIZE to redraw it now
260 SendMessage(GetHwnd(), WM_SIZE
, 0, 0);
263 bool wxStatusBar95::GetFieldRect(int i
, wxRect
& rect
) const
265 wxCHECK_MSG( (i
>= 0) && (i
< m_nFields
), false,
266 _T("invalid statusbar field index") );
269 if ( !::SendMessage(GetHwnd(), SB_GETRECT
, i
, (LPARAM
)&r
) )
271 wxLogLastError(wxT("SendMessage(SB_GETRECT)"));
275 wxUxThemeHandle
theme((wxStatusBar95
*)this, L
"Status"); // const_cast
278 // by default Windows has a 2 pixel border to the right of the left
279 // divider (or it could be a bug) but it looks wrong so remove it
285 wxUxThemeEngine::Get()->GetThemeBackgroundContentRect(theme
, NULL
,
291 wxCopyRECTToRect(r
, rect
);
296 #ifndef SWP_NOSENDCHANGING
297 #define SWP_NOSENDCHANGING 0
300 void wxStatusBar95::DoMoveWindow(int x
, int y
, int width
, int height
)
302 if ( GetParent()->IsSizeDeferred() )
304 wxWindowMSW::DoMoveWindow(x
, y
, width
, height
);
308 // parent pos/size isn't deferred so do it now but don't send
309 // WM_WINDOWPOSCHANGING since we don't want to change pos/size later
310 ::SetWindowPos(GetHwnd(), NULL
, x
, y
, width
, height
,
311 SWP_NOZORDER
| SWP_NOSENDCHANGING
);
314 // adjust fields widths to the new size
317 // we have to trigger wxSizeEvent if there are children window in status
318 // bar because GetFieldRect returned incorrect (not updated) values up to
319 // here, which almost certainly resulted in incorrectly redrawn statusbar
320 if ( m_children
.GetCount() > 0 )
322 wxSizeEvent
event(GetClientSize(), m_windowId
);
323 event
.SetEventObject(this);
324 GetEventHandler()->ProcessEvent(event
);
328 void wxStatusBar95::SetStatusStyles(int n
, const int styles
[])
330 wxStatusBarBase::SetStatusStyles(n
, styles
);
335 for (int i
= 0; i
< n
; i
++)
344 style
= SBT_NOBORDERS
;
351 // The SB_SETTEXT message is both used to set the field's text as well as
352 // the fields' styles. MSDN library doesn't mention
353 // that nField and style have to be 'ORed'
354 wxString text
= GetStatusText(i
);
355 if (!StatusBar_SetText(GetHwnd(), style
| i
, text
))
357 wxLogLastError(wxT("StatusBar_SetText"));
363 wxStatusBar95::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
366 if ( nMsg
== WM_WINDOWPOSCHANGING
)
368 WINDOWPOS
*lpPos
= (WINDOWPOS
*)lParam
;
373 // we need real window coords and not wx client coords
374 AdjustForParentClientOrigin(x
, y
);
384 if ( nMsg
== WM_NCLBUTTONDOWN
)
386 // if hit-test is on gripper then send message to TLW to begin
387 // resizing. It is possible to send this message to any window.
388 if ( wParam
== HTBOTTOMRIGHT
)
392 for ( win
= GetParent(); win
; win
= win
->GetParent() )
394 if ( win
->IsTopLevel() )
396 SendMessage(GetHwndOf(win
), WM_NCLBUTTONDOWN
,
406 return wxStatusBarBase::MSWWindowProc(nMsg
, wParam
, lParam
);
409 #endif // wxUSE_STATUSBAR && wxUSE_NATIVE_STATUSBAR