]>
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 | { |
57f4f925 | 73 | wxCHECK_MSG( parent, false, wxT("status bar must have a parent") ); |
cbc66a27 | 74 | |
ed791986 | 75 | SetName(name); |
cbc66a27 | 76 | SetWindowStyleFlag(style); |
ed791986 VZ |
77 | SetParent(parent); |
78 | ||
cbc66a27 VZ |
79 | parent->AddChild(this); |
80 | ||
57f4f925 | 81 | m_windowId = id == wxID_ANY ? 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 | ||
57f4f925 | 114 | return false; |
ed791986 | 115 | } |
2bda0e17 | 116 | |
c6e7d14f | 117 | SetFieldsCount(1); |
b3d008db | 118 | SubclassWin(m_hWnd); |
e0176dd9 | 119 | InheritAttributes(); |
2bda0e17 | 120 | |
7d6d3bf3 | 121 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR)); |
c07103f2 | 122 | |
c10d3a54 VS |
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); | |
126 | if ( frame ) | |
127 | { | |
128 | frame->SendSizeEvent(); | |
129 | } | |
7d6d3bf3 | 130 | |
57f4f925 | 131 | return true; |
ed791986 | 132 | } |
2bda0e17 | 133 | |
ed791986 VZ |
134 | wxStatusBar95::~wxStatusBar95() |
135 | { | |
6b5c56bd VS |
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 | |
138 | // occupy | |
139 | wxFrame *frame = wxDynamicCast(GetParent(), wxFrame); | |
140 | if ( frame && !frame->IsBeingDeleted() ) | |
141 | { | |
142 | frame->SendSizeEvent(); | |
143 | } | |
2bda0e17 KB |
144 | } |
145 | ||
790ad94f | 146 | void wxStatusBar95::SetFieldsCount(int nFields, const int *widths) |
2bda0e17 | 147 | { |
f6bcfd97 BP |
148 | // this is a Windows limitation |
149 | wxASSERT_MSG( (nFields > 0) && (nFields < 255), _T("too many fields") ); | |
2bda0e17 | 150 | |
498fd97d | 151 | wxStatusBarBase::SetFieldsCount(nFields, widths); |
27d2cd5c VZ |
152 | |
153 | SetFieldsWidth(); | |
2bda0e17 KB |
154 | } |
155 | ||
498fd97d | 156 | void wxStatusBar95::SetStatusWidths(int n, const int widths[]) |
2bda0e17 | 157 | { |
498fd97d | 158 | wxStatusBarBase::SetStatusWidths(n, widths); |
2bda0e17 | 159 | |
f6bcfd97 | 160 | SetFieldsWidth(); |
2bda0e17 KB |
161 | } |
162 | ||
163 | void wxStatusBar95::SetFieldsWidth() | |
164 | { | |
3175c712 VZ |
165 | if ( !m_nFields ) |
166 | return; | |
167 | ||
ed791986 VZ |
168 | int aBorders[3]; |
169 | SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders); | |
2bda0e17 | 170 | |
ed791986 | 171 | int extraWidth = aBorders[2]; // space between fields |
2bda0e17 | 172 | |
498fd97d VZ |
173 | wxArrayInt widthsAbs = |
174 | CalculateAbsWidths(GetClientSize().x - extraWidth*(m_nFields - 1)); | |
2bda0e17 | 175 | |
498fd97d | 176 | int *pWidths = new int[m_nFields]; |
2bda0e17 | 177 | |
498fd97d VZ |
178 | int nCurPos = 0; |
179 | for ( int i = 0; i < m_nFields; i++ ) { | |
180 | nCurPos += widthsAbs[i] + extraWidth; | |
181 | pWidths[i] = nCurPos; | |
2bda0e17 | 182 | } |
2bda0e17 | 183 | |
ed791986 VZ |
184 | if ( !StatusBar_SetParts(GetHwnd(), m_nFields, pWidths) ) { |
185 | wxLogLastError(wxT("StatusBar_SetParts")); | |
186 | } | |
2bda0e17 | 187 | |
ed791986 | 188 | delete [] pWidths; |
2bda0e17 KB |
189 | } |
190 | ||
debe6624 | 191 | void wxStatusBar95::SetStatusText(const wxString& strText, int nField) |
2bda0e17 | 192 | { |
ed791986 VZ |
193 | wxCHECK_RET( (nField >= 0) && (nField < m_nFields), |
194 | _T("invalid statusbar field index") ); | |
195 | ||
c2919ab3 VZ |
196 | // Get field style, if any |
197 | int style; | |
198 | if (m_statusStyles) | |
199 | { | |
200 | switch(m_statusStyles[nField]) | |
201 | { | |
202 | case wxSB_RAISED: | |
203 | style = SBT_POPOUT; | |
204 | break; | |
205 | case wxSB_FLAT: | |
206 | style = SBT_NOBORDERS; | |
207 | break; | |
208 | case wxSB_NORMAL: | |
209 | default: | |
210 | style = 0; | |
211 | break; | |
212 | } | |
213 | } | |
214 | else | |
215 | style = 0; | |
216 | ||
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) ) | |
b3d008db VZ |
220 | { |
221 | wxLogLastError(wxT("StatusBar_SetText")); | |
222 | } | |
2bda0e17 KB |
223 | } |
224 | ||
225 | wxString wxStatusBar95::GetStatusText(int nField) const | |
226 | { | |
ed791986 VZ |
227 | wxCHECK_MSG( (nField >= 0) && (nField < m_nFields), wxEmptyString, |
228 | _T("invalid statusbar field index") ); | |
2bda0e17 | 229 | |
b3d008db VZ |
230 | wxString str; |
231 | int len = StatusBar_GetTextLen(GetHwnd(), nField); | |
232 | if ( len > 0 ) | |
233 | { | |
de564874 | 234 | StatusBar_GetText(GetHwnd(), nField, wxStringBuffer(str, len)); |
b3d008db VZ |
235 | } |
236 | ||
237 | return str; | |
2bda0e17 KB |
238 | } |
239 | ||
ed791986 VZ |
240 | int wxStatusBar95::GetBorderX() const |
241 | { | |
242 | int aBorders[3]; | |
243 | SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders); | |
244 | ||
245 | return aBorders[0]; | |
246 | } | |
247 | ||
248 | int wxStatusBar95::GetBorderY() const | |
249 | { | |
250 | int aBorders[3]; | |
251 | SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders); | |
252 | ||
253 | return aBorders[1]; | |
254 | } | |
255 | ||
256 | void wxStatusBar95::SetMinHeight(int height) | |
257 | { | |
258 | SendMessage(GetHwnd(), SB_SETMINHEIGHT, height + 2*GetBorderY(), 0); | |
259 | ||
260 | // have to send a (dummy) WM_SIZE to redraw it now | |
261 | SendMessage(GetHwnd(), WM_SIZE, 0, 0); | |
262 | } | |
263 | ||
264 | bool wxStatusBar95::GetFieldRect(int i, wxRect& rect) const | |
265 | { | |
57f4f925 | 266 | wxCHECK_MSG( (i >= 0) && (i < m_nFields), false, |
ed791986 VZ |
267 | _T("invalid statusbar field index") ); |
268 | ||
269 | RECT r; | |
270 | if ( !::SendMessage(GetHwnd(), SB_GETRECT, i, (LPARAM)&r) ) | |
271 | { | |
f6bcfd97 | 272 | wxLogLastError(wxT("SendMessage(SB_GETRECT)")); |
ed791986 VZ |
273 | } |
274 | ||
275 | wxCopyRECTToRect(r, rect); | |
276 | ||
57f4f925 | 277 | return true; |
ed791986 VZ |
278 | } |
279 | ||
e78e8583 JS |
280 | #ifndef SWP_NOSENDCHANGING |
281 | #define SWP_NOSENDCHANGING 0 | |
282 | #endif | |
283 | ||
cbc66a27 | 284 | void wxStatusBar95::DoMoveWindow(int x, int y, int width, int height) |
2bda0e17 | 285 | { |
c07103f2 VZ |
286 | if ( GetParent()->IsSizeDeferred() ) |
287 | { | |
288 | wxWindowMSW::DoMoveWindow(x, y, width, height); | |
289 | } | |
290 | else | |
291 | { | |
292 | // parent pos/size isn't deferred so do it now but don't send | |
293 | // WM_WINDOWPOSCHANGING since we don't want to change pos/size later | |
294 | ::SetWindowPos(GetHwnd(), NULL, x, y, width, height, | |
295 | SWP_NOZORDER | SWP_NOSENDCHANGING); | |
296 | } | |
43b5058d VZ |
297 | |
298 | // adjust fields widths to the new size | |
299 | SetFieldsWidth(); | |
dafa4925 | 300 | |
57f4f925 | 301 | // we have to trigger wxSizeEvent if there are children window in status |
dafa4925 VS |
302 | // bar because GetFieldRect returned incorrect (not updated) values up to |
303 | // here, which almost certainly resulted in incorrectly redrawn statusbar | |
304 | if ( m_children.GetCount() > 0 ) | |
305 | { | |
306 | wxSizeEvent event(GetClientSize(), m_windowId); | |
307 | event.SetEventObject(this); | |
308 | GetEventHandler()->ProcessEvent(event); | |
309 | } | |
2bda0e17 KB |
310 | } |
311 | ||
c2919ab3 VZ |
312 | void wxStatusBar95::SetStatusStyles(int n, const int styles[]) |
313 | { | |
314 | wxStatusBarBase::SetStatusStyles(n, styles); | |
315 | ||
316 | if (n != m_nFields) | |
317 | return; | |
318 | ||
319 | for (int i = 0; i < n; i++) | |
320 | { | |
321 | int style; | |
322 | switch(styles[i]) | |
323 | { | |
324 | case wxSB_RAISED: | |
325 | style = SBT_POPOUT; | |
326 | break; | |
327 | case wxSB_FLAT: | |
328 | style = SBT_NOBORDERS; | |
329 | break; | |
330 | case wxSB_NORMAL: | |
331 | default: | |
332 | style = 0; | |
333 | break; | |
334 | } | |
335 | // The SB_SETTEXT message is both used to set the field's text as well as | |
336 | // the fields' styles. MSDN library doesn't mention | |
337 | // that nField and style have to be 'ORed' | |
338 | wxString text = GetStatusText(i); | |
339 | if (!StatusBar_SetText(GetHwnd(), style | i, text)) | |
340 | { | |
341 | wxLogLastError(wxT("StatusBar_SetText")); | |
342 | } | |
343 | } | |
344 | } | |
345 | ||
c07103f2 VZ |
346 | WXLRESULT |
347 | wxStatusBar95::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) | |
348 | { | |
e78e8583 | 349 | #ifndef __WXWINCE__ |
c07103f2 VZ |
350 | if ( nMsg == WM_WINDOWPOSCHANGING ) |
351 | { | |
352 | WINDOWPOS *lpPos = (WINDOWPOS *)lParam; | |
353 | int x, y, w, h; | |
354 | GetPosition(&x, &y); | |
355 | GetSize(&w, &h); | |
356 | ||
4ce18ecb VZ |
357 | // we need real window coords and not wx client coords |
358 | AdjustForParentClientOrigin(x, y); | |
359 | ||
c07103f2 VZ |
360 | lpPos->x = x; |
361 | lpPos->y = y; | |
362 | lpPos->cx = w; | |
363 | lpPos->cy = h; | |
364 | ||
365 | return 0; | |
366 | } | |
e78e8583 | 367 | |
c07103f2 VZ |
368 | if ( nMsg == WM_NCLBUTTONDOWN ) |
369 | { | |
370 | // if hit-test is on gripper then send message to TLW to begin | |
371 | // resizing. It is possible to send this message to any window. | |
372 | if ( wParam == HTBOTTOMRIGHT ) | |
373 | { | |
374 | wxWindow *win; | |
375 | ||
376 | for ( win = GetParent(); win; win = win->GetParent() ) | |
377 | { | |
378 | if ( win->IsTopLevel() ) | |
379 | { | |
380 | SendMessage(GetHwndOf(win), WM_NCLBUTTONDOWN, | |
381 | wParam, lParam); | |
382 | ||
383 | return 0; | |
384 | } | |
385 | } | |
386 | } | |
387 | } | |
e78e8583 | 388 | #endif |
c07103f2 VZ |
389 | |
390 | return wxStatusBarBase::MSWWindowProc(nMsg, wParam, lParam); | |
391 | } | |
392 | ||
ed791986 | 393 | #endif // __WIN95__ && wxUSE_NATIVE_STATUSBAR |
ba681060 | 394 |