]>
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
== -1 ? 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."));
120 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR
));
125 wxStatusBar95::~wxStatusBar95()
129 void wxStatusBar95::SetFieldsCount(int nFields
, const int *widths
)
131 // this is a Windows limitation
132 wxASSERT_MSG( (nFields
> 0) && (nFields
< 255), _T("too many fields") );
134 wxStatusBarBase::SetFieldsCount(nFields
, widths
);
139 void wxStatusBar95::SetStatusWidths(int n
, const int widths
[])
141 wxStatusBarBase::SetStatusWidths(n
, widths
);
146 void wxStatusBar95::SetFieldsWidth()
152 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
154 int extraWidth
= aBorders
[2]; // space between fields
156 wxArrayInt widthsAbs
=
157 CalculateAbsWidths(GetClientSize().x
- extraWidth
*(m_nFields
- 1));
159 int *pWidths
= new int[m_nFields
];
162 for ( int i
= 0; i
< m_nFields
; i
++ ) {
163 nCurPos
+= widthsAbs
[i
] + extraWidth
;
164 pWidths
[i
] = nCurPos
;
167 if ( !StatusBar_SetParts(GetHwnd(), m_nFields
, pWidths
) ) {
168 wxLogLastError(wxT("StatusBar_SetParts"));
174 void wxStatusBar95::SetStatusText(const wxString
& strText
, int nField
)
176 wxCHECK_RET( (nField
>= 0) && (nField
< m_nFields
),
177 _T("invalid statusbar field index") );
179 if ( !StatusBar_SetText(GetHwnd(), nField
, strText
) )
181 wxLogLastError(wxT("StatusBar_SetText"));
185 wxString
wxStatusBar95::GetStatusText(int nField
) const
187 wxCHECK_MSG( (nField
>= 0) && (nField
< m_nFields
), wxEmptyString
,
188 _T("invalid statusbar field index") );
191 int len
= StatusBar_GetTextLen(GetHwnd(), nField
);
194 StatusBar_GetText(GetHwnd(), nField
, wxStringBuffer(str
, len
));
200 int wxStatusBar95::GetBorderX() const
203 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
208 int wxStatusBar95::GetBorderY() const
211 SendMessage(GetHwnd(), SB_GETBORDERS
, 0, (LPARAM
)aBorders
);
216 void wxStatusBar95::SetMinHeight(int height
)
218 SendMessage(GetHwnd(), SB_SETMINHEIGHT
, height
+ 2*GetBorderY(), 0);
220 // have to send a (dummy) WM_SIZE to redraw it now
221 SendMessage(GetHwnd(), WM_SIZE
, 0, 0);
224 bool wxStatusBar95::GetFieldRect(int i
, wxRect
& rect
) const
226 wxCHECK_MSG( (i
>= 0) && (i
< m_nFields
), FALSE
,
227 _T("invalid statusbar field index") );
230 if ( !::SendMessage(GetHwnd(), SB_GETRECT
, i
, (LPARAM
)&r
) )
232 wxLogLastError(wxT("SendMessage(SB_GETRECT)"));
235 wxCopyRECTToRect(r
, rect
);
240 void wxStatusBar95::DoMoveWindow(int x
, int y
, int width
, int height
)
242 // the status bar wnd proc must be forwarded the WM_SIZE message whenever
243 // the stat bar position/size is changed because it normally positions the
244 // control itself along bottom or top side of the parent window - failing
245 // to do so will result in nasty visual effects
246 FORWARD_WM_SIZE(GetHwnd(), SIZE_RESTORED
, x
, y
, SendMessage
);
248 // but now, when the standard status bar wnd proc did all it wanted to do,
249 // move the status bar to its correct location - usually this call may be
250 // omitted because for normal status bars (positioned along the bottom
251 // edge) the position is already set correctly, but if the user wants to
252 // position them in some exotic location, this is really needed
253 wxWindow::DoMoveWindow(x
, y
, width
, height
);
255 // adjust fields widths to the new size
258 // we have to trigger wxSizeEvent if there are children window in status
259 // bar because GetFieldRect returned incorrect (not updated) values up to
260 // here, which almost certainly resulted in incorrectly redrawn statusbar
261 if ( m_children
.GetCount() > 0 )
263 wxSizeEvent
event(GetClientSize(), m_windowId
);
264 event
.SetEventObject(this);
265 GetEventHandler()->ProcessEvent(event
);
269 #endif // __WIN95__ && wxUSE_NATIVE_STATUSBAR