]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | /////////////////////////////////////////////////////////////////////////////// |
936f6353 | 2 | // Name: src/msw/statusbar.cpp |
2bda0e17 KB |
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 | ||
2bda0e17 KB |
12 | // for compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifdef __BORLANDC__ | |
16 | #pragma hdrstop | |
17 | #endif | |
18 | ||
88a7a4e1 WS |
19 | #if wxUSE_STATUSBAR && wxUSE_NATIVE_STATUSBAR |
20 | ||
21 | #include "wx/statusbr.h" | |
22 | ||
2bda0e17 | 23 | #ifndef WX_PRECOMP |
57bd4c60 | 24 | #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly" |
88a7a4e1 WS |
25 | #include "wx/frame.h" |
26 | #include "wx/settings.h" | |
27 | #include "wx/dcclient.h" | |
28 | #include "wx/intl.h" | |
e4db172a | 29 | #include "wx/log.h" |
2bda0e17 KB |
30 | #endif |
31 | ||
42e69d6b VZ |
32 | #include "wx/msw/private.h" |
33 | #include <windowsx.h> | |
2bda0e17 | 34 | |
1feb5443 JG |
35 | #if wxUSE_UXTHEME |
36 | #include "wx/msw/uxtheme.h" | |
37 | #endif | |
38 | ||
2bda0e17 KB |
39 | // ---------------------------------------------------------------------------- |
40 | // macros | |
41 | // ---------------------------------------------------------------------------- | |
42 | ||
43 | // windowsx.h and commctrl.h don't define those, so we do it here | |
44 | #define StatusBar_SetParts(h, n, w) SendMessage(h, SB_SETPARTS, (WPARAM)n, (LPARAM)w) | |
837e5743 | 45 | #define StatusBar_SetText(h, n, t) SendMessage(h, SB_SETTEXT, (WPARAM)n, (LPARAM)(LPCTSTR)t) |
2bda0e17 | 46 | #define StatusBar_GetTextLen(h, n) LOWORD(SendMessage(h, SB_GETTEXTLENGTH, (WPARAM)n, 0)) |
837e5743 | 47 | #define StatusBar_GetText(h, n, s) LOWORD(SendMessage(h, SB_GETTEXT, (WPARAM)n, (LPARAM)(LPTSTR)s)) |
2bda0e17 | 48 | |
2bda0e17 KB |
49 | // ============================================================================ |
50 | // implementation | |
51 | // ============================================================================ | |
52 | ||
53 | // ---------------------------------------------------------------------------- | |
936f6353 | 54 | // wxStatusBar class |
2bda0e17 KB |
55 | // ---------------------------------------------------------------------------- |
56 | ||
936f6353 | 57 | wxStatusBar::wxStatusBar() |
2bda0e17 | 58 | { |
b3d008db VZ |
59 | SetParent(NULL); |
60 | m_hWnd = 0; | |
61 | m_windowId = 0; | |
2bda0e17 KB |
62 | } |
63 | ||
936f6353 VZ |
64 | bool wxStatusBar::Create(wxWindow *parent, |
65 | wxWindowID id, | |
66 | long style, | |
67 | const wxString& name) | |
2bda0e17 | 68 | { |
57f4f925 | 69 | wxCHECK_MSG( parent, false, wxT("status bar must have a parent") ); |
cbc66a27 | 70 | |
ed791986 | 71 | SetName(name); |
cbc66a27 | 72 | SetWindowStyleFlag(style); |
ed791986 VZ |
73 | SetParent(parent); |
74 | ||
cbc66a27 VZ |
75 | parent->AddChild(this); |
76 | ||
57f4f925 | 77 | m_windowId = id == wxID_ANY ? NewControlId() : id; |
ed791986 | 78 | |
b0766406 JS |
79 | DWORD wstyle = WS_CHILD | WS_VISIBLE; |
80 | ||
81 | if ( style & wxCLIP_SIBLINGS ) | |
82 | wstyle |= WS_CLIPSIBLINGS; | |
83 | ||
43b5058d VZ |
84 | // setting SBARS_SIZEGRIP is perfectly useless: it's always on by default |
85 | // (at least in the version of comctl32.dll I'm using), and the only way to | |
86 | // turn it off is to use CCS_TOP style - as we position the status bar | |
87 | // manually anyhow (see DoMoveWindow), use CCS_TOP style if wxST_SIZEGRIP | |
88 | // is not given | |
89 | if ( !(style & wxST_SIZEGRIP) ) | |
90 | { | |
91 | wstyle |= CCS_TOP; | |
92 | } | |
93 | else | |
94 | { | |
4676948b | 95 | #ifndef __WXWINCE__ |
43b5058d VZ |
96 | // may be some versions of comctl32.dll do need it - anyhow, it won't |
97 | // do any harm | |
ed791986 | 98 | wstyle |= SBARS_SIZEGRIP; |
4676948b | 99 | #endif |
43b5058d | 100 | } |
ed791986 | 101 | |
2a11c826 VZ |
102 | m_hWnd = CreateWindow |
103 | ( | |
104 | STATUSCLASSNAME, | |
105 | _T(""), | |
106 | wstyle, | |
107 | 0, 0, 0, 0, | |
108 | GetHwndOf(parent), | |
dca0f651 | 109 | (HMENU)wxUIntToPtr(m_windowId.GetValue()), |
2a11c826 VZ |
110 | wxGetInstance(), |
111 | NULL | |
112 | ); | |
ed791986 VZ |
113 | if ( m_hWnd == 0 ) |
114 | { | |
115 | wxLogSysError(_("Failed to create a status bar.")); | |
116 | ||
57f4f925 | 117 | return false; |
ed791986 | 118 | } |
2bda0e17 | 119 | |
c6e7d14f | 120 | SetFieldsCount(1); |
b3d008db | 121 | SubclassWin(m_hWnd); |
e0176dd9 | 122 | InheritAttributes(); |
2bda0e17 | 123 | |
7d6d3bf3 | 124 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR)); |
c07103f2 | 125 | |
c10d3a54 VS |
126 | // we must refresh the frame size when the statusbar is created, because |
127 | // its client area might change | |
ecdc1183 VZ |
128 | // |
129 | // notice that we must post the event, not send it, as the frame doesn't | |
130 | // know that we're its status bar yet so laying it out right now wouldn't | |
131 | // work correctly, we need to wait until we return to the main loop | |
132 | PostSizeEventToParent(); | |
7d6d3bf3 | 133 | |
57f4f925 | 134 | return true; |
ed791986 | 135 | } |
2bda0e17 | 136 | |
936f6353 | 137 | wxStatusBar::~wxStatusBar() |
ed791986 | 138 | { |
6b5c56bd VS |
139 | // we must refresh the frame size when the statusbar is deleted but the |
140 | // frame is not - otherwise statusbar leaves a hole in the place it used to | |
141 | // occupy | |
ecdc1183 | 142 | PostSizeEventToParent(); |
2bda0e17 KB |
143 | } |
144 | ||
936f6353 | 145 | void wxStatusBar::SetFieldsCount(int nFields, const int *widths) |
2bda0e17 | 146 | { |
f6bcfd97 BP |
147 | // this is a Windows limitation |
148 | wxASSERT_MSG( (nFields > 0) && (nFields < 255), _T("too many fields") ); | |
2bda0e17 | 149 | |
498fd97d | 150 | wxStatusBarBase::SetFieldsCount(nFields, widths); |
27d2cd5c VZ |
151 | |
152 | SetFieldsWidth(); | |
2bda0e17 KB |
153 | } |
154 | ||
936f6353 | 155 | void wxStatusBar::SetStatusWidths(int n, const int widths[]) |
2bda0e17 | 156 | { |
498fd97d | 157 | wxStatusBarBase::SetStatusWidths(n, widths); |
2bda0e17 | 158 | |
f6bcfd97 | 159 | SetFieldsWidth(); |
2bda0e17 KB |
160 | } |
161 | ||
936f6353 | 162 | void wxStatusBar::SetFieldsWidth() |
2bda0e17 | 163 | { |
7b6fefbe | 164 | if ( m_panes.IsEmpty() ) |
3175c712 VZ |
165 | return; |
166 | ||
ed791986 VZ |
167 | int aBorders[3]; |
168 | SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders); | |
2bda0e17 | 169 | |
ed791986 | 170 | int extraWidth = aBorders[2]; // space between fields |
2bda0e17 | 171 | |
498fd97d | 172 | wxArrayInt widthsAbs = |
7b6fefbe | 173 | CalculateAbsWidths(GetClientSize().x - extraWidth*(m_panes.GetCount() - 1)); |
2bda0e17 | 174 | |
7b6fefbe | 175 | int *pWidths = new int[m_panes.GetCount()]; |
2bda0e17 | 176 | |
498fd97d | 177 | int nCurPos = 0; |
a37d94d3 | 178 | for ( size_t i = 0; i < m_panes.GetCount(); i++ ) { |
498fd97d VZ |
179 | nCurPos += widthsAbs[i] + extraWidth; |
180 | pWidths[i] = nCurPos; | |
2bda0e17 | 181 | } |
2bda0e17 | 182 | |
7b6fefbe | 183 | if ( !StatusBar_SetParts(GetHwnd(), m_panes.GetCount(), pWidths) ) { |
ed791986 VZ |
184 | wxLogLastError(wxT("StatusBar_SetParts")); |
185 | } | |
2bda0e17 | 186 | |
ed791986 | 187 | delete [] pWidths; |
2bda0e17 KB |
188 | } |
189 | ||
936f6353 | 190 | void wxStatusBar::SetStatusText(const wxString& strText, int nField) |
2bda0e17 | 191 | { |
a37d94d3 | 192 | wxCHECK_RET( (nField >= 0) && ((size_t)nField < m_panes.GetCount()), |
ed791986 VZ |
193 | _T("invalid statusbar field index") ); |
194 | ||
823b6635 VZ |
195 | if ( strText == GetStatusText(nField) ) |
196 | { | |
197 | // don't call StatusBar_SetText() to avoid flicker | |
198 | return; | |
199 | } | |
200 | ||
c2919ab3 VZ |
201 | // Get field style, if any |
202 | int style; | |
7b6fefbe | 203 | switch(m_panes[nField].nStyle) |
c2919ab3 | 204 | { |
7b6fefbe FM |
205 | case wxSB_RAISED: |
206 | style = SBT_POPOUT; | |
207 | break; | |
208 | case wxSB_FLAT: | |
209 | style = SBT_NOBORDERS; | |
210 | break; | |
211 | ||
212 | case wxSB_NORMAL: | |
213 | default: | |
c2919ab3 | 214 | style = 0; |
7b6fefbe FM |
215 | break; |
216 | } | |
c2919ab3 VZ |
217 | |
218 | // Pass both field number and style. MSDN library doesn't mention | |
219 | // that nField and style have to be 'ORed' | |
e0a050e3 | 220 | if ( !StatusBar_SetText(GetHwnd(), nField | style, strText.wx_str()) ) |
b3d008db VZ |
221 | { |
222 | wxLogLastError(wxT("StatusBar_SetText")); | |
223 | } | |
2bda0e17 KB |
224 | } |
225 | ||
936f6353 | 226 | wxString wxStatusBar::GetStatusText(int nField) const |
2bda0e17 | 227 | { |
a37d94d3 | 228 | wxCHECK_MSG( (nField >= 0) && ((size_t)nField < m_panes.GetCount()), wxEmptyString, |
ed791986 | 229 | _T("invalid statusbar field index") ); |
2bda0e17 | 230 | |
b3d008db VZ |
231 | wxString str; |
232 | int len = StatusBar_GetTextLen(GetHwnd(), nField); | |
233 | if ( len > 0 ) | |
234 | { | |
de564874 | 235 | StatusBar_GetText(GetHwnd(), nField, wxStringBuffer(str, len)); |
b3d008db VZ |
236 | } |
237 | ||
238 | return str; | |
2bda0e17 KB |
239 | } |
240 | ||
936f6353 | 241 | int wxStatusBar::GetBorderX() const |
ed791986 VZ |
242 | { |
243 | int aBorders[3]; | |
244 | SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders); | |
245 | ||
246 | return aBorders[0]; | |
247 | } | |
248 | ||
936f6353 | 249 | int wxStatusBar::GetBorderY() const |
ed791986 VZ |
250 | { |
251 | int aBorders[3]; | |
252 | SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders); | |
253 | ||
254 | return aBorders[1]; | |
255 | } | |
256 | ||
936f6353 | 257 | void wxStatusBar::SetMinHeight(int height) |
ed791986 VZ |
258 | { |
259 | SendMessage(GetHwnd(), SB_SETMINHEIGHT, height + 2*GetBorderY(), 0); | |
260 | ||
261 | // have to send a (dummy) WM_SIZE to redraw it now | |
262 | SendMessage(GetHwnd(), WM_SIZE, 0, 0); | |
263 | } | |
264 | ||
936f6353 | 265 | bool wxStatusBar::GetFieldRect(int i, wxRect& rect) const |
ed791986 | 266 | { |
a37d94d3 | 267 | wxCHECK_MSG( (i >= 0) && ((size_t)i < m_panes.GetCount()), false, |
ed791986 VZ |
268 | _T("invalid statusbar field index") ); |
269 | ||
270 | RECT r; | |
271 | if ( !::SendMessage(GetHwnd(), SB_GETRECT, i, (LPARAM)&r) ) | |
272 | { | |
f6bcfd97 | 273 | wxLogLastError(wxT("SendMessage(SB_GETRECT)")); |
ed791986 VZ |
274 | } |
275 | ||
1feb5443 | 276 | #if wxUSE_UXTHEME |
936f6353 | 277 | wxUxThemeHandle theme((wxStatusBar *)this, L"Status"); // const_cast |
1feb5443 JG |
278 | if ( theme ) |
279 | { | |
280 | // by default Windows has a 2 pixel border to the right of the left | |
281 | // divider (or it could be a bug) but it looks wrong so remove it | |
282 | if ( i != 0 ) | |
283 | { | |
284 | r.left -= 2; | |
285 | } | |
286 | ||
287 | wxUxThemeEngine::Get()->GetThemeBackgroundContentRect(theme, NULL, | |
288 | 1 /* SP_PANE */, 0, | |
289 | &r, &r); | |
290 | } | |
291 | #endif | |
292 | ||
ed791986 VZ |
293 | wxCopyRECTToRect(r, rect); |
294 | ||
57f4f925 | 295 | return true; |
ed791986 VZ |
296 | } |
297 | ||
c0ac3149 VZ |
298 | // no idea for a default width, just choose something |
299 | #define DEFAULT_FIELD_WIDTH 25 | |
300 | ||
936f6353 | 301 | wxSize wxStatusBar::DoGetBestSize() const |
c0ac3149 VZ |
302 | { |
303 | int borders[3]; | |
304 | SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)borders); | |
305 | ||
306 | // calculate width | |
307 | int width = 0; | |
a37d94d3 | 308 | for ( size_t i = 0; i < m_panes.GetCount(); ++i ) |
c0ac3149 | 309 | { |
7b6fefbe FM |
310 | int widthField = |
311 | m_bSameWidthForAllPanes ? DEFAULT_FIELD_WIDTH : m_panes[i].nWidth; | |
c0ac3149 VZ |
312 | if ( widthField >= 0 ) |
313 | { | |
e408d9ca | 314 | width += widthField; |
c0ac3149 VZ |
315 | } |
316 | else | |
317 | { | |
318 | // variable width field, its width is really a proportion | |
319 | // related to the other fields | |
320 | width += -widthField*DEFAULT_FIELD_WIDTH; | |
321 | } | |
322 | ||
323 | // add the space between fields | |
324 | width += borders[2]; | |
325 | } | |
326 | ||
327 | if ( !width ) | |
328 | { | |
329 | // still need something even for an empty status bar | |
330 | width = 2*DEFAULT_FIELD_WIDTH; | |
331 | } | |
332 | ||
333 | ||
334 | // calculate height | |
335 | int height; | |
336 | wxGetCharSize(GetHWND(), NULL, &height, GetFont()); | |
337 | height = EDIT_HEIGHT_FROM_CHAR_HEIGHT(height); | |
338 | height += borders[1]; | |
339 | ||
340 | wxSize best(width, height); | |
341 | CacheBestSize(best); | |
342 | return best; | |
343 | } | |
344 | ||
936f6353 | 345 | void wxStatusBar::DoMoveWindow(int x, int y, int width, int height) |
2bda0e17 | 346 | { |
c07103f2 VZ |
347 | if ( GetParent()->IsSizeDeferred() ) |
348 | { | |
349 | wxWindowMSW::DoMoveWindow(x, y, width, height); | |
350 | } | |
351 | else | |
352 | { | |
353 | // parent pos/size isn't deferred so do it now but don't send | |
354 | // WM_WINDOWPOSCHANGING since we don't want to change pos/size later | |
dd28827a JG |
355 | // we must use SWP_NOCOPYBITS here otherwise it paints incorrectly |
356 | // if other windows are size deferred | |
c07103f2 | 357 | ::SetWindowPos(GetHwnd(), NULL, x, y, width, height, |
99cc862c | 358 | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE |
521bf4ff | 359 | #ifndef __WXWINCE__ |
99cc862c JS |
360 | | SWP_NOCOPYBITS | SWP_NOSENDCHANGING |
361 | #endif | |
362 | ); | |
c07103f2 | 363 | } |
43b5058d VZ |
364 | |
365 | // adjust fields widths to the new size | |
366 | SetFieldsWidth(); | |
dafa4925 | 367 | |
57f4f925 | 368 | // we have to trigger wxSizeEvent if there are children window in status |
dafa4925 VS |
369 | // bar because GetFieldRect returned incorrect (not updated) values up to |
370 | // here, which almost certainly resulted in incorrectly redrawn statusbar | |
371 | if ( m_children.GetCount() > 0 ) | |
372 | { | |
373 | wxSizeEvent event(GetClientSize(), m_windowId); | |
374 | event.SetEventObject(this); | |
937013e0 | 375 | HandleWindowEvent(event); |
dafa4925 | 376 | } |
2bda0e17 KB |
377 | } |
378 | ||
936f6353 | 379 | void wxStatusBar::SetStatusStyles(int n, const int styles[]) |
c2919ab3 VZ |
380 | { |
381 | wxStatusBarBase::SetStatusStyles(n, styles); | |
382 | ||
a37d94d3 | 383 | if (n != (int)m_panes.GetCount()) |
c2919ab3 VZ |
384 | return; |
385 | ||
386 | for (int i = 0; i < n; i++) | |
387 | { | |
388 | int style; | |
389 | switch(styles[i]) | |
390 | { | |
391 | case wxSB_RAISED: | |
392 | style = SBT_POPOUT; | |
393 | break; | |
394 | case wxSB_FLAT: | |
395 | style = SBT_NOBORDERS; | |
396 | break; | |
397 | case wxSB_NORMAL: | |
398 | default: | |
399 | style = 0; | |
400 | break; | |
401 | } | |
402 | // The SB_SETTEXT message is both used to set the field's text as well as | |
403 | // the fields' styles. MSDN library doesn't mention | |
404 | // that nField and style have to be 'ORed' | |
405 | wxString text = GetStatusText(i); | |
e0a050e3 | 406 | if (!StatusBar_SetText(GetHwnd(), style | i, text.wx_str())) |
c2919ab3 VZ |
407 | { |
408 | wxLogLastError(wxT("StatusBar_SetText")); | |
409 | } | |
410 | } | |
411 | } | |
412 | ||
c07103f2 | 413 | WXLRESULT |
936f6353 | 414 | wxStatusBar::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) |
c07103f2 | 415 | { |
e78e8583 | 416 | #ifndef __WXWINCE__ |
c07103f2 VZ |
417 | if ( nMsg == WM_WINDOWPOSCHANGING ) |
418 | { | |
419 | WINDOWPOS *lpPos = (WINDOWPOS *)lParam; | |
420 | int x, y, w, h; | |
421 | GetPosition(&x, &y); | |
422 | GetSize(&w, &h); | |
423 | ||
4ce18ecb VZ |
424 | // we need real window coords and not wx client coords |
425 | AdjustForParentClientOrigin(x, y); | |
426 | ||
c07103f2 VZ |
427 | lpPos->x = x; |
428 | lpPos->y = y; | |
429 | lpPos->cx = w; | |
430 | lpPos->cy = h; | |
431 | ||
432 | return 0; | |
433 | } | |
e78e8583 | 434 | |
c07103f2 VZ |
435 | if ( nMsg == WM_NCLBUTTONDOWN ) |
436 | { | |
437 | // if hit-test is on gripper then send message to TLW to begin | |
438 | // resizing. It is possible to send this message to any window. | |
439 | if ( wParam == HTBOTTOMRIGHT ) | |
440 | { | |
441 | wxWindow *win; | |
442 | ||
443 | for ( win = GetParent(); win; win = win->GetParent() ) | |
444 | { | |
445 | if ( win->IsTopLevel() ) | |
446 | { | |
447 | SendMessage(GetHwndOf(win), WM_NCLBUTTONDOWN, | |
448 | wParam, lParam); | |
449 | ||
450 | return 0; | |
451 | } | |
452 | } | |
453 | } | |
454 | } | |
e78e8583 | 455 | #endif |
c07103f2 VZ |
456 | |
457 | return wxStatusBarBase::MSWWindowProc(nMsg, wParam, lParam); | |
458 | } | |
459 | ||
a71d815b | 460 | #endif // wxUSE_STATUSBAR && wxUSE_NATIVE_STATUSBAR |