]>
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"
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
42 // windowsx.h and commctrl.h don't define those, so we do it here
43 #define StatusBar_SetParts(h, n, w) SendMessage(h, SB_SETPARTS, (WPARAM)n, (LPARAM)w)
44 #define StatusBar_SetText(h, n, t) SendMessage(h, SB_SETTEXT, (WPARAM)n, (LPARAM)(LPCTSTR)t)
45 #define StatusBar_GetTextLen(h, n) LOWORD(SendMessage(h, SB_GETTEXTLENGTH, (WPARAM)n, 0))
46 #define StatusBar_GetText(h, n, s) LOWORD(SendMessage(h, SB_GETTEXT, (WPARAM)n, (LPARAM)(LPTSTR)s))
48 // ============================================================================
50 // ============================================================================
52 // ----------------------------------------------------------------------------
53 // wxStatusBar95 class
54 // ----------------------------------------------------------------------------
56 wxStatusBar95::wxStatusBar95()
63 bool wxStatusBar95::Create(wxWindow
*parent
,
68 wxCHECK_MSG( parent
, false, wxT("status bar must have a parent") );
71 SetWindowStyleFlag(style
);
74 parent
->AddChild(this);
76 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
78 DWORD wstyle
= WS_CHILD
| WS_VISIBLE
;
80 if ( style
& wxCLIP_SIBLINGS
)
81 wstyle
|= WS_CLIPSIBLINGS
;
83 // setting SBARS_SIZEGRIP is perfectly useless: it's always on by default
84 // (at least in the version of comctl32.dll I'm using), and the only way to
85 // turn it off is to use CCS_TOP style - as we position the status bar
86 // manually anyhow (see DoMoveWindow), use CCS_TOP style if wxST_SIZEGRIP
88 if ( !(style
& wxST_SIZEGRIP
) )
95 // may be some versions of comctl32.dll do need it - anyhow, it won't
97 wstyle
|= SBARS_SIZEGRIP
;
101 m_hWnd
= (WXHWND
)CreateStatusWindow(wstyle
,
107 wxLogSysError(_("Failed to create a status bar."));
116 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR
));
118 // we must refresh the frame size when the statusbar is created, because
119 // its client area might change
120 wxFrame
*frame
= wxDynamicCast(GetParent(), wxFrame
);
123 frame
->SendSizeEvent();
129 wxStatusBar95::~wxStatusBar95()
131 // we must refresh the frame size when the statusbar is deleted but the
132 // frame is not - otherwise statusbar leaves a hole in the place it used to
134 wxFrame
*frame
= wxDynamicCast(GetParent(), wxFrame
);
135 if ( frame
&& !frame
->IsBeingDeleted() )
137 frame
->SendSizeEvent();
141 void wxStatusBar95::SetFieldsCount(int nFields
, const int *widths
)
143 // this is a Windows limitation
144 wxASSERT_MSG( (nFields
> 0) && (nFields
< 255), _T("too many fields") );
146 wxStatusBarBase::SetFieldsCount(nFields
, widths
);
151 void wxStatusBar95::SetStatusWidths(int n
, const int widths
[])
153 wxStatusBarBase::SetStatusWidths(n
, widths
);
158 void wxStatusBar95::SetFieldsWidth()
164 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
166 int extraWidth
= aBorders
[2]; // space between fields
168 wxArrayInt widthsAbs
=
169 CalculateAbsWidths(GetClientSize().x
- extraWidth
*(m_nFields
- 1));
171 int *pWidths
= new int[m_nFields
];
174 for ( int i
= 0; i
< m_nFields
; i
++ ) {
175 nCurPos
+= widthsAbs
[i
] + extraWidth
;
176 pWidths
[i
] = nCurPos
;
179 if ( !StatusBar_SetParts(GetHwnd(), m_nFields
, pWidths
) ) {
180 wxLogLastError(wxT("StatusBar_SetParts"));
186 void wxStatusBar95::SetStatusText(const wxString
& strText
, int nField
)
188 wxCHECK_RET( (nField
>= 0) && (nField
< m_nFields
),
189 _T("invalid statusbar field index") );
191 // Get field style, if any
195 switch(m_statusStyles
[nField
])
201 style
= SBT_NOBORDERS
;
212 // Pass both field number and style. MSDN library doesn't mention
213 // that nField and style have to be 'ORed'
214 if ( !StatusBar_SetText(GetHwnd(), nField
| style
, strText
) )
216 wxLogLastError(wxT("StatusBar_SetText"));
220 wxString
wxStatusBar95::GetStatusText(int nField
) const
222 wxCHECK_MSG( (nField
>= 0) && (nField
< m_nFields
), wxEmptyString
,
223 _T("invalid statusbar field index") );
226 int len
= StatusBar_GetTextLen(GetHwnd(), nField
);
229 StatusBar_GetText(GetHwnd(), nField
, wxStringBuffer(str
, len
));
235 int wxStatusBar95::GetBorderX() const
238 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
243 int wxStatusBar95::GetBorderY() const
246 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
251 void wxStatusBar95::SetMinHeight(int height
)
253 SendMessage(GetHwnd(), SB_SETMINHEIGHT
, height
+ 2*GetBorderY(), 0);
255 // have to send a (dummy) WM_SIZE to redraw it now
256 SendMessage(GetHwnd(), WM_SIZE
, 0, 0);
259 bool wxStatusBar95::GetFieldRect(int i
, wxRect
& rect
) const
261 wxCHECK_MSG( (i
>= 0) && (i
< m_nFields
), false,
262 _T("invalid statusbar field index") );
265 if ( !::SendMessage(GetHwnd(), SB_GETRECT
, i
, (LPARAM
)&r
) )
267 wxLogLastError(wxT("SendMessage(SB_GETRECT)"));
270 wxCopyRECTToRect(r
, rect
);
275 #ifndef SWP_NOSENDCHANGING
276 #define SWP_NOSENDCHANGING 0
279 void wxStatusBar95::DoMoveWindow(int x
, int y
, int width
, int height
)
281 if ( GetParent()->IsSizeDeferred() )
283 wxWindowMSW::DoMoveWindow(x
, y
, width
, height
);
287 // parent pos/size isn't deferred so do it now but don't send
288 // WM_WINDOWPOSCHANGING since we don't want to change pos/size later
289 ::SetWindowPos(GetHwnd(), NULL
, x
, y
, width
, height
,
290 SWP_NOZORDER
| SWP_NOSENDCHANGING
);
293 // adjust fields widths to the new size
296 // we have to trigger wxSizeEvent if there are children window in status
297 // bar because GetFieldRect returned incorrect (not updated) values up to
298 // here, which almost certainly resulted in incorrectly redrawn statusbar
299 if ( m_children
.GetCount() > 0 )
301 wxSizeEvent
event(GetClientSize(), m_windowId
);
302 event
.SetEventObject(this);
303 GetEventHandler()->ProcessEvent(event
);
307 void wxStatusBar95::SetStatusStyles(int n
, const int styles
[])
309 wxStatusBarBase::SetStatusStyles(n
, styles
);
314 for (int i
= 0; i
< n
; i
++)
323 style
= SBT_NOBORDERS
;
330 // The SB_SETTEXT message is both used to set the field's text as well as
331 // the fields' styles. MSDN library doesn't mention
332 // that nField and style have to be 'ORed'
333 wxString text
= GetStatusText(i
);
334 if (!StatusBar_SetText(GetHwnd(), style
| i
, text
))
336 wxLogLastError(wxT("StatusBar_SetText"));
342 wxStatusBar95::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
345 if ( nMsg
== WM_WINDOWPOSCHANGING
)
347 WINDOWPOS
*lpPos
= (WINDOWPOS
*)lParam
;
352 // we need real window coords and not wx client coords
353 AdjustForParentClientOrigin(x
, y
);
363 if ( nMsg
== WM_NCLBUTTONDOWN
)
365 // if hit-test is on gripper then send message to TLW to begin
366 // resizing. It is possible to send this message to any window.
367 if ( wParam
== HTBOTTOMRIGHT
)
371 for ( win
= GetParent(); win
; win
= win
->GetParent() )
373 if ( win
->IsTopLevel() )
375 SendMessage(GetHwndOf(win
), WM_NCLBUTTONDOWN
,
385 return wxStatusBarBase::MSWWindowProc(nMsg
, wParam
, lParam
);
388 #endif // wxUSE_STATUSBAR && wxUSE_NATIVE_STATUSBAR