]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/statbr95.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: 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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "statbr95.h"
16 // for compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/settings.h"
27 #include "wx/dcclient.h"
30 #if wxUSE_STATUSBAR && defined(__WIN95__) && wxUSE_NATIVE_STATUSBAR
34 #include "wx/statusbr.h"
36 #include "wx/msw/private.h"
39 #if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__))
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
47 // windowsx.h and commctrl.h don't define those, so we do it here
48 #define StatusBar_SetParts(h, n, w) SendMessage(h, SB_SETPARTS, (WPARAM)n, (LPARAM)w)
49 #define StatusBar_SetText(h, n, t) SendMessage(h, SB_SETTEXT, (WPARAM)n, (LPARAM)(LPCTSTR)t)
50 #define StatusBar_GetTextLen(h, n) LOWORD(SendMessage(h, SB_GETTEXTLENGTH, (WPARAM)n, 0))
51 #define StatusBar_GetText(h, n, s) LOWORD(SendMessage(h, SB_GETTEXT, (WPARAM)n, (LPARAM)(LPTSTR)s))
53 // ============================================================================
55 // ============================================================================
57 // ----------------------------------------------------------------------------
58 // wxStatusBar95 class
59 // ----------------------------------------------------------------------------
61 wxStatusBar95::wxStatusBar95()
68 bool wxStatusBar95::Create(wxWindow
*parent
,
73 wxCHECK_MSG( parent
, false, wxT("status bar must have a parent") );
76 SetWindowStyleFlag(style
);
79 parent
->AddChild(this);
81 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
83 DWORD wstyle
= WS_CHILD
| WS_VISIBLE
;
85 if ( style
& wxCLIP_SIBLINGS
)
86 wstyle
|= WS_CLIPSIBLINGS
;
88 // setting SBARS_SIZEGRIP is perfectly useless: it's always on by default
89 // (at least in the version of comctl32.dll I'm using), and the only way to
90 // turn it off is to use CCS_TOP style - as we position the status bar
91 // manually anyhow (see DoMoveWindow), use CCS_TOP style if wxST_SIZEGRIP
93 if ( !(style
& wxST_SIZEGRIP
) )
100 // may be some versions of comctl32.dll do need it - anyhow, it won't
102 wstyle
|= SBARS_SIZEGRIP
;
106 m_hWnd
= (WXHWND
)CreateStatusWindow(wstyle
,
112 wxLogSysError(_("Failed to create a status bar."));
121 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR
));
123 // we must refresh the frame size when the statusbar is created, because
124 // its client area might change
125 wxFrame
*frame
= wxDynamicCast(GetParent(), wxFrame
);
128 frame
->SendSizeEvent();
134 wxStatusBar95::~wxStatusBar95()
136 // we must refresh the frame size when the statusbar is deleted but the
137 // frame is not - otherwise statusbar leaves a hole in the place it used to
139 wxFrame
*frame
= wxDynamicCast(GetParent(), wxFrame
);
140 if ( frame
&& !frame
->IsBeingDeleted() )
142 frame
->SendSizeEvent();
146 void wxStatusBar95::SetFieldsCount(int nFields
, const int *widths
)
148 // this is a Windows limitation
149 wxASSERT_MSG( (nFields
> 0) && (nFields
< 255), _T("too many fields") );
151 wxStatusBarBase::SetFieldsCount(nFields
, widths
);
156 void wxStatusBar95::SetStatusWidths(int n
, const int widths
[])
158 wxStatusBarBase::SetStatusWidths(n
, widths
);
163 void wxStatusBar95::SetFieldsWidth()
169 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
171 int extraWidth
= aBorders
[2]; // space between fields
173 wxArrayInt widthsAbs
=
174 CalculateAbsWidths(GetClientSize().x
- extraWidth
*(m_nFields
- 1));
176 int *pWidths
= new int[m_nFields
];
179 for ( int i
= 0; i
< m_nFields
; i
++ ) {
180 nCurPos
+= widthsAbs
[i
] + extraWidth
;
181 pWidths
[i
] = nCurPos
;
184 if ( !StatusBar_SetParts(GetHwnd(), m_nFields
, pWidths
) ) {
185 wxLogLastError(wxT("StatusBar_SetParts"));
191 void wxStatusBar95::SetStatusText(const wxString
& strText
, int nField
)
193 wxCHECK_RET( (nField
>= 0) && (nField
< m_nFields
),
194 _T("invalid statusbar field index") );
196 // Get field style, if any
200 switch(m_statusStyles
[nField
])
206 style
= SBT_NOBORDERS
;
217 // Pass both field number and style. MSDN library doesn't mention
218 // that nField and style have to be 'ORed'
219 if ( !StatusBar_SetText(GetHwnd(), nField
| style
, strText
) )
221 wxLogLastError(wxT("StatusBar_SetText"));
225 wxString
wxStatusBar95::GetStatusText(int nField
) const
227 wxCHECK_MSG( (nField
>= 0) && (nField
< m_nFields
), wxEmptyString
,
228 _T("invalid statusbar field index") );
231 int len
= StatusBar_GetTextLen(GetHwnd(), nField
);
234 StatusBar_GetText(GetHwnd(), nField
, wxStringBuffer(str
, len
));
240 int wxStatusBar95::GetBorderX() const
243 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
248 int wxStatusBar95::GetBorderY() const
251 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
256 void wxStatusBar95::SetMinHeight(int height
)
258 SendMessage(GetHwnd(), SB_SETMINHEIGHT
, height
+ 2*GetBorderY(), 0);
260 // have to send a (dummy) WM_SIZE to redraw it now
261 SendMessage(GetHwnd(), WM_SIZE
, 0, 0);
264 bool wxStatusBar95::GetFieldRect(int i
, wxRect
& rect
) const
266 wxCHECK_MSG( (i
>= 0) && (i
< m_nFields
), false,
267 _T("invalid statusbar field index") );
270 if ( !::SendMessage(GetHwnd(), SB_GETRECT
, i
, (LPARAM
)&r
) )
272 wxLogLastError(wxT("SendMessage(SB_GETRECT)"));
275 wxCopyRECTToRect(r
, rect
);
280 void wxStatusBar95::DoMoveWindow(int x
, int y
, int width
, int height
)
282 if ( GetParent()->IsSizeDeferred() )
284 wxWindowMSW::DoMoveWindow(x
, y
, width
, height
);
288 // parent pos/size isn't deferred so do it now but don't send
289 // WM_WINDOWPOSCHANGING since we don't want to change pos/size later
290 ::SetWindowPos(GetHwnd(), NULL
, x
, y
, width
, height
,
291 SWP_NOZORDER
| SWP_NOSENDCHANGING
);
294 // adjust fields widths to the new size
297 // we have to trigger wxSizeEvent if there are children window in status
298 // bar because GetFieldRect returned incorrect (not updated) values up to
299 // here, which almost certainly resulted in incorrectly redrawn statusbar
300 if ( m_children
.GetCount() > 0 )
302 wxSizeEvent
event(GetClientSize(), m_windowId
);
303 event
.SetEventObject(this);
304 GetEventHandler()->ProcessEvent(event
);
308 void wxStatusBar95::SetStatusStyles(int n
, const int styles
[])
310 wxStatusBarBase::SetStatusStyles(n
, styles
);
315 for (int i
= 0; i
< n
; i
++)
324 style
= SBT_NOBORDERS
;
331 // The SB_SETTEXT message is both used to set the field's text as well as
332 // the fields' styles. MSDN library doesn't mention
333 // that nField and style have to be 'ORed'
334 wxString text
= GetStatusText(i
);
335 if (!StatusBar_SetText(GetHwnd(), style
| i
, text
))
337 wxLogLastError(wxT("StatusBar_SetText"));
343 wxStatusBar95::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
345 if ( nMsg
== WM_WINDOWPOSCHANGING
)
347 WINDOWPOS
*lpPos
= (WINDOWPOS
*)lParam
;
359 if ( nMsg
== WM_NCLBUTTONDOWN
)
361 // if hit-test is on gripper then send message to TLW to begin
362 // resizing. It is possible to send this message to any window.
363 if ( wParam
== HTBOTTOMRIGHT
)
367 for ( win
= GetParent(); win
; win
= win
->GetParent() )
369 if ( win
->IsTopLevel() )
371 SendMessage(GetHwndOf(win
), WM_NCLBUTTONDOWN
,
380 return wxStatusBarBase::MSWWindowProc(nMsg
, wParam
, lParam
);
383 #endif // __WIN95__ && wxUSE_NATIVE_STATUSBAR