]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: msw/statbr95.cpp | |
3 | // Purpose: native implementation of wxStatusBar | |
4 | // Author: Vadim Zeitlin | |
ed791986 | 5 | // Modified by: |
2bda0e17 KB |
6 | // Created: 04.04.98 |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
65571936 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
14f355c2 | 12 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
cfe780fb JS |
13 | #pragma implementation "statbr95.h" |
14 | #endif | |
15 | ||
2bda0e17 KB |
16 | // for compilers that support precompilation, includes "wx.h". |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #ifndef WX_PRECOMP | |
24 | #include "wx/setup.h" | |
25 | #include "wx/frame.h" | |
26 | #include "wx/settings.h" | |
27 | #include "wx/dcclient.h" | |
28 | #endif | |
29 | ||
3080bf59 | 30 | #if wxUSE_STATUSBAR && defined(__WIN95__) && wxUSE_NATIVE_STATUSBAR |
2432b92d | 31 | |
608eeb0f | 32 | #include "wx/intl.h" |
2bda0e17 | 33 | #include "wx/log.h" |
ed791986 | 34 | #include "wx/statusbr.h" |
2bda0e17 | 35 | |
42e69d6b VZ |
36 | #include "wx/msw/private.h" |
37 | #include <windowsx.h> | |
2bda0e17 | 38 | |
b39dbf34 | 39 | #if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__)) |
c42404a5 | 40 | #include <commctrl.h> |
ce3ed50d JS |
41 | #endif |
42 | ||
2bda0e17 KB |
43 | // ---------------------------------------------------------------------------- |
44 | // macros | |
45 | // ---------------------------------------------------------------------------- | |
46 | ||
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) | |
837e5743 | 49 | #define StatusBar_SetText(h, n, t) SendMessage(h, SB_SETTEXT, (WPARAM)n, (LPARAM)(LPCTSTR)t) |
2bda0e17 | 50 | #define StatusBar_GetTextLen(h, n) LOWORD(SendMessage(h, SB_GETTEXTLENGTH, (WPARAM)n, 0)) |
837e5743 | 51 | #define StatusBar_GetText(h, n, s) LOWORD(SendMessage(h, SB_GETTEXT, (WPARAM)n, (LPARAM)(LPTSTR)s)) |
2bda0e17 | 52 | |
2bda0e17 KB |
53 | // ============================================================================ |
54 | // implementation | |
55 | // ============================================================================ | |
56 | ||
57 | // ---------------------------------------------------------------------------- | |
58 | // wxStatusBar95 class | |
59 | // ---------------------------------------------------------------------------- | |
60 | ||
61 | wxStatusBar95::wxStatusBar95() | |
62 | { | |
b3d008db VZ |
63 | SetParent(NULL); |
64 | m_hWnd = 0; | |
65 | m_windowId = 0; | |
2bda0e17 KB |
66 | } |
67 | ||
ed791986 VZ |
68 | bool wxStatusBar95::Create(wxWindow *parent, |
69 | wxWindowID id, | |
70 | long style, | |
71 | const wxString& name) | |
2bda0e17 | 72 | { |
cbc66a27 VZ |
73 | wxCHECK_MSG( parent, FALSE, wxT("status bar must have a parent") ); |
74 | ||
ed791986 | 75 | SetName(name); |
cbc66a27 | 76 | SetWindowStyleFlag(style); |
ed791986 VZ |
77 | SetParent(parent); |
78 | ||
cbc66a27 VZ |
79 | parent->AddChild(this); |
80 | ||
81 | m_windowId = id == -1 ? NewControlId() : id; | |
ed791986 | 82 | |
b0766406 JS |
83 | DWORD wstyle = WS_CHILD | WS_VISIBLE; |
84 | ||
85 | if ( style & wxCLIP_SIBLINGS ) | |
86 | wstyle |= WS_CLIPSIBLINGS; | |
87 | ||
43b5058d VZ |
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 | |
92 | // is not given | |
93 | if ( !(style & wxST_SIZEGRIP) ) | |
94 | { | |
95 | wstyle |= CCS_TOP; | |
96 | } | |
97 | else | |
98 | { | |
4676948b | 99 | #ifndef __WXWINCE__ |
43b5058d VZ |
100 | // may be some versions of comctl32.dll do need it - anyhow, it won't |
101 | // do any harm | |
ed791986 | 102 | wstyle |= SBARS_SIZEGRIP; |
4676948b | 103 | #endif |
43b5058d | 104 | } |
ed791986 VZ |
105 | |
106 | m_hWnd = (WXHWND)CreateStatusWindow(wstyle, | |
107 | wxEmptyString, | |
108 | GetHwndOf(parent), | |
109 | m_windowId); | |
110 | if ( m_hWnd == 0 ) | |
111 | { | |
112 | wxLogSysError(_("Failed to create a status bar.")); | |
113 | ||
114 | return FALSE; | |
115 | } | |
2bda0e17 | 116 | |
c6e7d14f | 117 | SetFieldsCount(1); |
b3d008db | 118 | SubclassWin(m_hWnd); |
e0176dd9 | 119 | InheritAttributes(); |
2bda0e17 | 120 | |
7d6d3bf3 VZ |
121 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR)); |
122 | ||
ed791986 VZ |
123 | return TRUE; |
124 | } | |
2bda0e17 | 125 | |
ed791986 VZ |
126 | wxStatusBar95::~wxStatusBar95() |
127 | { | |
2bda0e17 KB |
128 | } |
129 | ||
790ad94f | 130 | void wxStatusBar95::SetFieldsCount(int nFields, const int *widths) |
2bda0e17 | 131 | { |
f6bcfd97 BP |
132 | // this is a Windows limitation |
133 | wxASSERT_MSG( (nFields > 0) && (nFields < 255), _T("too many fields") ); | |
2bda0e17 | 134 | |
498fd97d | 135 | wxStatusBarBase::SetFieldsCount(nFields, widths); |
27d2cd5c VZ |
136 | |
137 | SetFieldsWidth(); | |
2bda0e17 KB |
138 | } |
139 | ||
498fd97d | 140 | void wxStatusBar95::SetStatusWidths(int n, const int widths[]) |
2bda0e17 | 141 | { |
498fd97d | 142 | wxStatusBarBase::SetStatusWidths(n, widths); |
2bda0e17 | 143 | |
f6bcfd97 | 144 | SetFieldsWidth(); |
2bda0e17 KB |
145 | } |
146 | ||
147 | void wxStatusBar95::SetFieldsWidth() | |
148 | { | |
3175c712 VZ |
149 | if ( !m_nFields ) |
150 | return; | |
151 | ||
ed791986 VZ |
152 | int aBorders[3]; |
153 | SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders); | |
2bda0e17 | 154 | |
ed791986 | 155 | int extraWidth = aBorders[2]; // space between fields |
2bda0e17 | 156 | |
498fd97d VZ |
157 | wxArrayInt widthsAbs = |
158 | CalculateAbsWidths(GetClientSize().x - extraWidth*(m_nFields - 1)); | |
2bda0e17 | 159 | |
498fd97d | 160 | int *pWidths = new int[m_nFields]; |
2bda0e17 | 161 | |
498fd97d VZ |
162 | int nCurPos = 0; |
163 | for ( int i = 0; i < m_nFields; i++ ) { | |
164 | nCurPos += widthsAbs[i] + extraWidth; | |
165 | pWidths[i] = nCurPos; | |
2bda0e17 | 166 | } |
2bda0e17 | 167 | |
ed791986 VZ |
168 | if ( !StatusBar_SetParts(GetHwnd(), m_nFields, pWidths) ) { |
169 | wxLogLastError(wxT("StatusBar_SetParts")); | |
170 | } | |
2bda0e17 | 171 | |
ed791986 | 172 | delete [] pWidths; |
2bda0e17 KB |
173 | } |
174 | ||
debe6624 | 175 | void wxStatusBar95::SetStatusText(const wxString& strText, int nField) |
2bda0e17 | 176 | { |
ed791986 VZ |
177 | wxCHECK_RET( (nField >= 0) && (nField < m_nFields), |
178 | _T("invalid statusbar field index") ); | |
179 | ||
c2919ab3 VZ |
180 | // Get field style, if any |
181 | int style; | |
182 | if (m_statusStyles) | |
183 | { | |
184 | switch(m_statusStyles[nField]) | |
185 | { | |
186 | case wxSB_RAISED: | |
187 | style = SBT_POPOUT; | |
188 | break; | |
189 | case wxSB_FLAT: | |
190 | style = SBT_NOBORDERS; | |
191 | break; | |
192 | case wxSB_NORMAL: | |
193 | default: | |
194 | style = 0; | |
195 | break; | |
196 | } | |
197 | } | |
198 | else | |
199 | style = 0; | |
200 | ||
201 | // Pass both field number and style. MSDN library doesn't mention | |
202 | // that nField and style have to be 'ORed' | |
203 | if ( !StatusBar_SetText(GetHwnd(), nField | style, strText) ) | |
b3d008db VZ |
204 | { |
205 | wxLogLastError(wxT("StatusBar_SetText")); | |
206 | } | |
2bda0e17 KB |
207 | } |
208 | ||
209 | wxString wxStatusBar95::GetStatusText(int nField) const | |
210 | { | |
ed791986 VZ |
211 | wxCHECK_MSG( (nField >= 0) && (nField < m_nFields), wxEmptyString, |
212 | _T("invalid statusbar field index") ); | |
2bda0e17 | 213 | |
b3d008db VZ |
214 | wxString str; |
215 | int len = StatusBar_GetTextLen(GetHwnd(), nField); | |
216 | if ( len > 0 ) | |
217 | { | |
de564874 | 218 | StatusBar_GetText(GetHwnd(), nField, wxStringBuffer(str, len)); |
b3d008db VZ |
219 | } |
220 | ||
221 | return str; | |
2bda0e17 KB |
222 | } |
223 | ||
ed791986 VZ |
224 | int wxStatusBar95::GetBorderX() const |
225 | { | |
226 | int aBorders[3]; | |
227 | SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders); | |
228 | ||
229 | return aBorders[0]; | |
230 | } | |
231 | ||
232 | int wxStatusBar95::GetBorderY() const | |
233 | { | |
234 | int aBorders[3]; | |
235 | SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders); | |
236 | ||
237 | return aBorders[1]; | |
238 | } | |
239 | ||
240 | void wxStatusBar95::SetMinHeight(int height) | |
241 | { | |
242 | SendMessage(GetHwnd(), SB_SETMINHEIGHT, height + 2*GetBorderY(), 0); | |
243 | ||
244 | // have to send a (dummy) WM_SIZE to redraw it now | |
245 | SendMessage(GetHwnd(), WM_SIZE, 0, 0); | |
246 | } | |
247 | ||
248 | bool wxStatusBar95::GetFieldRect(int i, wxRect& rect) const | |
249 | { | |
250 | wxCHECK_MSG( (i >= 0) && (i < m_nFields), FALSE, | |
251 | _T("invalid statusbar field index") ); | |
252 | ||
253 | RECT r; | |
254 | if ( !::SendMessage(GetHwnd(), SB_GETRECT, i, (LPARAM)&r) ) | |
255 | { | |
f6bcfd97 | 256 | wxLogLastError(wxT("SendMessage(SB_GETRECT)")); |
ed791986 VZ |
257 | } |
258 | ||
259 | wxCopyRECTToRect(r, rect); | |
260 | ||
261 | return TRUE; | |
262 | } | |
263 | ||
cbc66a27 | 264 | void wxStatusBar95::DoMoveWindow(int x, int y, int width, int height) |
2bda0e17 | 265 | { |
43b5058d VZ |
266 | // the status bar wnd proc must be forwarded the WM_SIZE message whenever |
267 | // the stat bar position/size is changed because it normally positions the | |
268 | // control itself along bottom or top side of the parent window - failing | |
269 | // to do so will result in nasty visual effects | |
270 | FORWARD_WM_SIZE(GetHwnd(), SIZE_RESTORED, x, y, SendMessage); | |
271 | ||
272 | // but now, when the standard status bar wnd proc did all it wanted to do, | |
273 | // move the status bar to its correct location - usually this call may be | |
274 | // omitted because for normal status bars (positioned along the bottom | |
275 | // edge) the position is already set correctly, but if the user wants to | |
276 | // position them in some exotic location, this is really needed | |
7d2d5d81 | 277 | wxWindowMSW::DoMoveWindow(x, y, width, height); |
43b5058d VZ |
278 | |
279 | // adjust fields widths to the new size | |
280 | SetFieldsWidth(); | |
dafa4925 VS |
281 | |
282 | // we have to trigger wxSizeEvent if there are children window in status | |
283 | // bar because GetFieldRect returned incorrect (not updated) values up to | |
284 | // here, which almost certainly resulted in incorrectly redrawn statusbar | |
285 | if ( m_children.GetCount() > 0 ) | |
286 | { | |
287 | wxSizeEvent event(GetClientSize(), m_windowId); | |
288 | event.SetEventObject(this); | |
289 | GetEventHandler()->ProcessEvent(event); | |
290 | } | |
2bda0e17 KB |
291 | } |
292 | ||
c2919ab3 VZ |
293 | void wxStatusBar95::SetStatusStyles(int n, const int styles[]) |
294 | { | |
295 | wxStatusBarBase::SetStatusStyles(n, styles); | |
296 | ||
297 | if (n != m_nFields) | |
298 | return; | |
299 | ||
300 | for (int i = 0; i < n; i++) | |
301 | { | |
302 | int style; | |
303 | switch(styles[i]) | |
304 | { | |
305 | case wxSB_RAISED: | |
306 | style = SBT_POPOUT; | |
307 | break; | |
308 | case wxSB_FLAT: | |
309 | style = SBT_NOBORDERS; | |
310 | break; | |
311 | case wxSB_NORMAL: | |
312 | default: | |
313 | style = 0; | |
314 | break; | |
315 | } | |
316 | // The SB_SETTEXT message is both used to set the field's text as well as | |
317 | // the fields' styles. MSDN library doesn't mention | |
318 | // that nField and style have to be 'ORed' | |
319 | wxString text = GetStatusText(i); | |
320 | if (!StatusBar_SetText(GetHwnd(), style | i, text)) | |
321 | { | |
322 | wxLogLastError(wxT("StatusBar_SetText")); | |
323 | } | |
324 | } | |
325 | } | |
326 | ||
ed791986 | 327 | #endif // __WIN95__ && wxUSE_NATIVE_STATUSBAR |
ba681060 | 328 |