]>
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 | ||
edd608b1 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
2bda0e17 KB |
20 | // for compilers that support precompilation, includes "wx.h". |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
88a7a4e1 WS |
27 | #if wxUSE_STATUSBAR && wxUSE_NATIVE_STATUSBAR |
28 | ||
29 | #include "wx/statusbr.h" | |
30 | ||
2bda0e17 | 31 | #ifndef WX_PRECOMP |
57bd4c60 | 32 | #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly" |
88a7a4e1 WS |
33 | #include "wx/frame.h" |
34 | #include "wx/settings.h" | |
35 | #include "wx/dcclient.h" | |
36 | #include "wx/intl.h" | |
e4db172a | 37 | #include "wx/log.h" |
cbbf47f3 | 38 | #include "wx/control.h" |
2bda0e17 KB |
39 | #endif |
40 | ||
42e69d6b | 41 | #include "wx/msw/private.h" |
6418ad5e | 42 | #include "wx/tooltip.h" |
42e69d6b | 43 | #include <windowsx.h> |
2bda0e17 | 44 | |
1feb5443 JG |
45 | #if wxUSE_UXTHEME |
46 | #include "wx/msw/uxtheme.h" | |
47 | #endif | |
48 | ||
edd608b1 VZ |
49 | // ---------------------------------------------------------------------------- |
50 | // constants | |
51 | // ---------------------------------------------------------------------------- | |
52 | ||
53 | namespace | |
54 | { | |
55 | ||
0cd15959 | 56 | // no idea for a default width, just choose something |
edd608b1 VZ |
57 | static const int DEFAULT_FIELD_WIDTH = 25; |
58 | ||
59 | } // anonymous namespace | |
0cd15959 | 60 | |
2bda0e17 KB |
61 | // ---------------------------------------------------------------------------- |
62 | // macros | |
63 | // ---------------------------------------------------------------------------- | |
64 | ||
65 | // windowsx.h and commctrl.h don't define those, so we do it here | |
66 | #define StatusBar_SetParts(h, n, w) SendMessage(h, SB_SETPARTS, (WPARAM)n, (LPARAM)w) | |
837e5743 | 67 | #define StatusBar_SetText(h, n, t) SendMessage(h, SB_SETTEXT, (WPARAM)n, (LPARAM)(LPCTSTR)t) |
2bda0e17 | 68 | #define StatusBar_GetTextLen(h, n) LOWORD(SendMessage(h, SB_GETTEXTLENGTH, (WPARAM)n, 0)) |
837e5743 | 69 | #define StatusBar_GetText(h, n, s) LOWORD(SendMessage(h, SB_GETTEXT, (WPARAM)n, (LPARAM)(LPTSTR)s)) |
2bda0e17 | 70 | |
2bda0e17 KB |
71 | // ============================================================================ |
72 | // implementation | |
73 | // ============================================================================ | |
74 | ||
75 | // ---------------------------------------------------------------------------- | |
936f6353 | 76 | // wxStatusBar class |
2bda0e17 KB |
77 | // ---------------------------------------------------------------------------- |
78 | ||
936f6353 | 79 | wxStatusBar::wxStatusBar() |
2bda0e17 | 80 | { |
b3d008db VZ |
81 | SetParent(NULL); |
82 | m_hWnd = 0; | |
83 | m_windowId = 0; | |
0cd15959 | 84 | m_pDC = NULL; |
2bda0e17 KB |
85 | } |
86 | ||
936f6353 VZ |
87 | bool wxStatusBar::Create(wxWindow *parent, |
88 | wxWindowID id, | |
89 | long style, | |
90 | const wxString& name) | |
2bda0e17 | 91 | { |
6418ad5e | 92 | wxCHECK_MSG( parent, false, "status bar must have a parent" ); |
cbc66a27 | 93 | |
ed791986 | 94 | SetName(name); |
cbc66a27 | 95 | SetWindowStyleFlag(style); |
ed791986 VZ |
96 | SetParent(parent); |
97 | ||
cbc66a27 VZ |
98 | parent->AddChild(this); |
99 | ||
57f4f925 | 100 | m_windowId = id == wxID_ANY ? NewControlId() : id; |
ed791986 | 101 | |
b0766406 JS |
102 | DWORD wstyle = WS_CHILD | WS_VISIBLE; |
103 | ||
104 | if ( style & wxCLIP_SIBLINGS ) | |
105 | wstyle |= WS_CLIPSIBLINGS; | |
106 | ||
9584818a VZ |
107 | // wxSTB_SIZEGRIP is part of our default style but it doesn't make sense to |
108 | // show size grip if this is the status bar of a non-resizeable TLW so turn | |
109 | // it off in such case | |
110 | if ( parent->IsTopLevel() && !parent->HasFlag(wxRESIZE_BORDER) ) | |
111 | style &= ~wxSTB_SIZEGRIP; | |
112 | ||
43b5058d VZ |
113 | // setting SBARS_SIZEGRIP is perfectly useless: it's always on by default |
114 | // (at least in the version of comctl32.dll I'm using), and the only way to | |
115 | // turn it off is to use CCS_TOP style - as we position the status bar | |
c4c178c1 | 116 | // manually anyhow (see DoMoveWindow), use CCS_TOP style if wxSTB_SIZEGRIP |
43b5058d | 117 | // is not given |
c4c178c1 | 118 | if ( !(style & wxSTB_SIZEGRIP) ) |
43b5058d VZ |
119 | { |
120 | wstyle |= CCS_TOP; | |
121 | } | |
122 | else | |
123 | { | |
4676948b | 124 | #ifndef __WXWINCE__ |
43b5058d VZ |
125 | // may be some versions of comctl32.dll do need it - anyhow, it won't |
126 | // do any harm | |
ed791986 | 127 | wstyle |= SBARS_SIZEGRIP; |
4676948b | 128 | #endif |
43b5058d | 129 | } |
ed791986 | 130 | |
2a11c826 VZ |
131 | m_hWnd = CreateWindow |
132 | ( | |
133 | STATUSCLASSNAME, | |
9a83f860 | 134 | wxT(""), |
2a11c826 VZ |
135 | wstyle, |
136 | 0, 0, 0, 0, | |
137 | GetHwndOf(parent), | |
dca0f651 | 138 | (HMENU)wxUIntToPtr(m_windowId.GetValue()), |
2a11c826 VZ |
139 | wxGetInstance(), |
140 | NULL | |
141 | ); | |
ed791986 VZ |
142 | if ( m_hWnd == 0 ) |
143 | { | |
144 | wxLogSysError(_("Failed to create a status bar.")); | |
145 | ||
57f4f925 | 146 | return false; |
ed791986 | 147 | } |
2bda0e17 | 148 | |
c6e7d14f | 149 | SetFieldsCount(1); |
b3d008db | 150 | SubclassWin(m_hWnd); |
80255b7e | 151 | |
6cf68971 | 152 | // cache the DC instance used by DoUpdateStatusText: |
80255b7e FM |
153 | // NOTE: create the DC before calling InheritAttributes() since |
154 | // it may result in a call to our SetFont() | |
155 | m_pDC = new wxClientDC(this); | |
156 | ||
e0176dd9 | 157 | InheritAttributes(); |
2bda0e17 | 158 | |
7d6d3bf3 | 159 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR)); |
c07103f2 | 160 | |
c10d3a54 VS |
161 | // we must refresh the frame size when the statusbar is created, because |
162 | // its client area might change | |
ecdc1183 VZ |
163 | // |
164 | // notice that we must post the event, not send it, as the frame doesn't | |
165 | // know that we're its status bar yet so laying it out right now wouldn't | |
166 | // work correctly, we need to wait until we return to the main loop | |
167 | PostSizeEventToParent(); | |
7d6d3bf3 | 168 | |
57f4f925 | 169 | return true; |
ed791986 | 170 | } |
2bda0e17 | 171 | |
936f6353 | 172 | wxStatusBar::~wxStatusBar() |
ed791986 | 173 | { |
6b5c56bd VS |
174 | // we must refresh the frame size when the statusbar is deleted but the |
175 | // frame is not - otherwise statusbar leaves a hole in the place it used to | |
176 | // occupy | |
ecdc1183 | 177 | PostSizeEventToParent(); |
80255b7e | 178 | |
421962be FM |
179 | // delete existing tooltips |
180 | for (size_t i=0; i<m_tooltips.size(); i++) | |
181 | { | |
182 | if (m_tooltips[i]) | |
183 | { | |
184 | delete m_tooltips[i]; | |
185 | m_tooltips[i] = NULL; | |
186 | } | |
187 | } | |
188 | ||
80255b7e | 189 | wxDELETE(m_pDC); |
2bda0e17 KB |
190 | } |
191 | ||
0cd15959 FM |
192 | bool wxStatusBar::SetFont(const wxFont& font) |
193 | { | |
194 | if (!wxWindow::SetFont(font)) | |
195 | return false; | |
196 | ||
80255b7e | 197 | if (m_pDC) m_pDC->SetFont(font); |
0cd15959 FM |
198 | return true; |
199 | } | |
200 | ||
936f6353 | 201 | void wxStatusBar::SetFieldsCount(int nFields, const int *widths) |
2bda0e17 | 202 | { |
f6bcfd97 | 203 | // this is a Windows limitation |
6418ad5e | 204 | wxASSERT_MSG( (nFields > 0) && (nFields < 255), "too many fields" ); |
2bda0e17 | 205 | |
498fd97d | 206 | wxStatusBarBase::SetFieldsCount(nFields, widths); |
27d2cd5c | 207 | |
6cf68971 | 208 | MSWUpdateFieldsWidths(); |
43b2d5e7 | 209 | |
6418ad5e FM |
210 | // keep in synch also our m_tooltips array |
211 | ||
212 | // reset all current tooltips | |
213 | for (size_t i=0; i<m_tooltips.size(); i++) | |
214 | { | |
421962be FM |
215 | if (m_tooltips[i]) |
216 | { | |
217 | delete m_tooltips[i]; | |
218 | m_tooltips[i] = NULL; | |
219 | } | |
6418ad5e FM |
220 | } |
221 | ||
222 | // shrink/expand the array: | |
223 | m_tooltips.resize(m_panes.GetCount(), NULL); | |
2bda0e17 KB |
224 | } |
225 | ||
936f6353 | 226 | void wxStatusBar::SetStatusWidths(int n, const int widths[]) |
2bda0e17 | 227 | { |
498fd97d | 228 | wxStatusBarBase::SetStatusWidths(n, widths); |
2bda0e17 | 229 | |
6cf68971 | 230 | MSWUpdateFieldsWidths(); |
2bda0e17 KB |
231 | } |
232 | ||
6cf68971 | 233 | void wxStatusBar::MSWUpdateFieldsWidths() |
2bda0e17 | 234 | { |
7b6fefbe | 235 | if ( m_panes.IsEmpty() ) |
3175c712 VZ |
236 | return; |
237 | ||
edd608b1 VZ |
238 | const int count = m_panes.GetCount(); |
239 | ||
240 | const int extraWidth = MSWGetBorderWidth() + MSWGetMetrics().textMargin; | |
2bda0e17 | 241 | |
edd608b1 VZ |
242 | // compute the effectively available amount of space: |
243 | int widthAvailable = GetClientSize().x; // start with the entire width | |
244 | widthAvailable -= extraWidth*(count - 1); // extra space between fields | |
245 | widthAvailable -= MSWGetMetrics().textMargin; // and for the last field | |
2bda0e17 | 246 | |
edd608b1 VZ |
247 | if ( HasFlag(wxSTB_SIZEGRIP) ) |
248 | widthAvailable -= MSWGetMetrics().gripWidth; | |
6418ad5e FM |
249 | |
250 | // distribute the available space (client width) among the various fields: | |
251 | ||
edd608b1 | 252 | wxArrayInt widthsAbs = CalculateAbsWidths(widthAvailable); |
2bda0e17 | 253 | |
6418ad5e FM |
254 | |
255 | // update the field widths in the native control: | |
256 | ||
edd608b1 | 257 | int *pWidths = new int[count]; |
2bda0e17 | 258 | |
498fd97d | 259 | int nCurPos = 0; |
edd608b1 | 260 | for ( int i = 0; i < count; i++ ) |
6418ad5e | 261 | { |
498fd97d VZ |
262 | nCurPos += widthsAbs[i] + extraWidth; |
263 | pWidths[i] = nCurPos; | |
2bda0e17 | 264 | } |
2bda0e17 | 265 | |
edd608b1 | 266 | if ( !StatusBar_SetParts(GetHwnd(), count, pWidths) ) |
43b2d5e7 | 267 | { |
6418ad5e | 268 | wxLogLastError("StatusBar_SetParts"); |
43b2d5e7 | 269 | } |
2bda0e17 | 270 | |
ed791986 | 271 | delete [] pWidths; |
6418ad5e FM |
272 | |
273 | ||
6cf68971 | 274 | // FIXME: we may want to call DoUpdateStatusText() here since we may need to (de)ellipsize status texts |
2bda0e17 KB |
275 | } |
276 | ||
6cf68971 | 277 | void wxStatusBar::DoUpdateStatusText(int nField) |
0cd15959 FM |
278 | { |
279 | if (!m_pDC) | |
280 | return; | |
281 | ||
c2919ab3 VZ |
282 | // Get field style, if any |
283 | int style; | |
b31eaa5c | 284 | switch(m_panes[nField].GetStyle()) |
c2919ab3 | 285 | { |
7b6fefbe FM |
286 | case wxSB_RAISED: |
287 | style = SBT_POPOUT; | |
288 | break; | |
289 | case wxSB_FLAT: | |
290 | style = SBT_NOBORDERS; | |
291 | break; | |
292 | ||
293 | case wxSB_NORMAL: | |
294 | default: | |
c2919ab3 | 295 | style = 0; |
7b6fefbe FM |
296 | break; |
297 | } | |
c2919ab3 | 298 | |
0cd15959 FM |
299 | wxRect rc; |
300 | GetFieldRect(nField, rc); | |
301 | ||
edd608b1 | 302 | const int maxWidth = rc.GetWidth() - MSWGetMetrics().textMargin; |
0cd15959 | 303 | |
6418ad5e FM |
304 | wxString text = GetStatusText(nField); |
305 | ||
0cd15959 | 306 | // do we need to ellipsize this string? |
6418ad5e FM |
307 | wxEllipsizeMode ellmode = (wxEllipsizeMode)-1; |
308 | if (HasFlag(wxSTB_ELLIPSIZE_START)) ellmode = wxELLIPSIZE_START; | |
309 | else if (HasFlag(wxSTB_ELLIPSIZE_MIDDLE)) ellmode = wxELLIPSIZE_MIDDLE; | |
310 | else if (HasFlag(wxSTB_ELLIPSIZE_END)) ellmode = wxELLIPSIZE_END; | |
311 | ||
312 | if (ellmode == (wxEllipsizeMode)-1) | |
313 | { | |
314 | // if we have the wxSTB_SHOW_TIPS we must set the ellipsized flag even if | |
315 | // we don't ellipsize the text but just truncate it | |
316 | if (HasFlag(wxSTB_SHOW_TIPS)) | |
317 | SetEllipsizedFlag(nField, m_pDC->GetTextExtent(text).GetWidth() > maxWidth); | |
318 | } | |
319 | else | |
b3d008db | 320 | { |
43b2d5e7 | 321 | text = wxControl::Ellipsize(text, |
6418ad5e FM |
322 | *m_pDC, |
323 | ellmode, | |
324 | maxWidth, | |
355ce7ad | 325 | wxELLIPSIZE_FLAGS_EXPAND_TABS); |
43b2d5e7 VZ |
326 | |
327 | // update the ellipsization status for this pane; this is used later to | |
328 | // decide whether a tooltip should be shown or not for this pane | |
6418ad5e FM |
329 | // (if we have wxSTB_SHOW_TIPS) |
330 | SetEllipsizedFlag(nField, text != GetStatusText(nField)); | |
331 | } | |
332 | ||
43b2d5e7 | 333 | // Set the status text in the native control passing both field number and style. |
6418ad5e FM |
334 | // NOTE: MSDN library doesn't mention that nField and style have to be 'ORed' |
335 | if ( !StatusBar_SetText(GetHwnd(), nField | style, text.wx_str()) ) | |
43b2d5e7 | 336 | { |
6418ad5e | 337 | wxLogLastError("StatusBar_SetText"); |
43b2d5e7 | 338 | } |
6418ad5e FM |
339 | |
340 | if (HasFlag(wxSTB_SHOW_TIPS)) | |
341 | { | |
342 | wxASSERT(m_tooltips.size() == m_panes.GetCount()); | |
343 | ||
344 | if (m_tooltips[nField]) | |
345 | { | |
346 | if (GetField(nField).IsEllipsized()) | |
347 | { | |
348 | // update the rect of this tooltip: | |
349 | m_tooltips[nField]->SetRect(rc); | |
350 | ||
351 | // update also the text: | |
352 | m_tooltips[nField]->SetTip(GetStatusText(nField)); | |
353 | } | |
354 | else | |
355 | { | |
356 | // delete the tooltip associated with this pane; it's not needed anymore | |
357 | delete m_tooltips[nField]; | |
358 | m_tooltips[nField] = NULL; | |
359 | } | |
360 | } | |
361 | else | |
362 | { | |
363 | // create a new tooltip for this pane if needed | |
364 | if (GetField(nField).IsEllipsized()) | |
365 | m_tooltips[nField] = new wxToolTip(this, nField, GetStatusText(nField), rc); | |
366 | //else: leave m_tooltips[nField]==NULL | |
367 | } | |
b3d008db | 368 | } |
2bda0e17 KB |
369 | } |
370 | ||
edd608b1 | 371 | wxStatusBar::MSWBorders wxStatusBar::MSWGetBorders() const |
ed791986 VZ |
372 | { |
373 | int aBorders[3]; | |
374 | SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders); | |
375 | ||
edd608b1 VZ |
376 | MSWBorders borders; |
377 | borders.horz = aBorders[0]; | |
378 | borders.vert = aBorders[1]; | |
379 | borders.between = aBorders[2]; | |
380 | return borders; | |
381 | } | |
382 | ||
383 | int wxStatusBar::GetBorderX() const | |
384 | { | |
385 | return MSWGetBorders().horz; | |
ed791986 VZ |
386 | } |
387 | ||
936f6353 | 388 | int wxStatusBar::GetBorderY() const |
ed791986 | 389 | { |
edd608b1 VZ |
390 | return MSWGetBorders().vert; |
391 | } | |
ed791986 | 392 | |
edd608b1 VZ |
393 | int wxStatusBar::MSWGetBorderWidth() const |
394 | { | |
395 | return MSWGetBorders().between; | |
396 | } | |
397 | ||
398 | /* static */ | |
399 | const wxStatusBar::MSWMetrics& wxStatusBar::MSWGetMetrics() | |
400 | { | |
401 | static MSWMetrics s_metrics = { 0 }; | |
402 | if ( !s_metrics.textMargin ) | |
403 | { | |
404 | // Grip size should be self explanatory (the only problem with it is | |
405 | // that it's hard coded as we don't know how to find its size using | |
406 | // API) but the margin might merit an explanation: Windows offsets the | |
407 | // text drawn in status bar panes so we need to take this extra margin | |
408 | // into account to make sure the text drawn by user fits inside the | |
409 | // pane. Notice that it's not the value returned by SB_GETBORDERS | |
410 | // which, at least on this Windows 2003 system, returns {0, 2, 2} | |
411 | if ( wxUxThemeEngine::GetIfActive() ) | |
412 | { | |
413 | s_metrics.gripWidth = 20; | |
414 | s_metrics.textMargin = 8; | |
415 | } | |
416 | else // classic/unthemed look | |
417 | { | |
418 | s_metrics.gripWidth = 18; | |
419 | s_metrics.textMargin = 4; | |
420 | } | |
421 | } | |
422 | ||
423 | return s_metrics; | |
ed791986 VZ |
424 | } |
425 | ||
936f6353 | 426 | void wxStatusBar::SetMinHeight(int height) |
ed791986 VZ |
427 | { |
428 | SendMessage(GetHwnd(), SB_SETMINHEIGHT, height + 2*GetBorderY(), 0); | |
429 | ||
6418ad5e | 430 | // we have to send a (dummy) WM_SIZE to redraw it now |
ed791986 VZ |
431 | SendMessage(GetHwnd(), WM_SIZE, 0, 0); |
432 | } | |
433 | ||
936f6353 | 434 | bool wxStatusBar::GetFieldRect(int i, wxRect& rect) const |
ed791986 | 435 | { |
a37d94d3 | 436 | wxCHECK_MSG( (i >= 0) && ((size_t)i < m_panes.GetCount()), false, |
6418ad5e | 437 | "invalid statusbar field index" ); |
ed791986 VZ |
438 | |
439 | RECT r; | |
440 | if ( !::SendMessage(GetHwnd(), SB_GETRECT, i, (LPARAM)&r) ) | |
43b2d5e7 | 441 | { |
6418ad5e | 442 | wxLogLastError("SendMessage(SB_GETRECT)"); |
43b2d5e7 | 443 | } |
ed791986 | 444 | |
1feb5443 | 445 | #if wxUSE_UXTHEME |
6418ad5e | 446 | wxUxThemeHandle theme(const_cast<wxStatusBar*>(this), L"Status"); |
1feb5443 JG |
447 | if ( theme ) |
448 | { | |
449 | // by default Windows has a 2 pixel border to the right of the left | |
450 | // divider (or it could be a bug) but it looks wrong so remove it | |
451 | if ( i != 0 ) | |
452 | { | |
453 | r.left -= 2; | |
454 | } | |
455 | ||
456 | wxUxThemeEngine::Get()->GetThemeBackgroundContentRect(theme, NULL, | |
457 | 1 /* SP_PANE */, 0, | |
458 | &r, &r); | |
459 | } | |
460 | #endif | |
461 | ||
ed791986 VZ |
462 | wxCopyRECTToRect(r, rect); |
463 | ||
edd608b1 VZ |
464 | // Windows seems to under-report the size of the last field rectangle, |
465 | // presumably in order to prevent the buggy applications from overflowing | |
466 | // onto the size grip but we want to return the real size to wx users | |
467 | if ( HasFlag(wxSTB_SIZEGRIP) && i == (int)m_panes.GetCount() - 1 ) | |
468 | { | |
469 | rect.width += MSWGetMetrics().gripWidth - MSWGetBorderWidth(); | |
470 | } | |
471 | ||
57f4f925 | 472 | return true; |
ed791986 VZ |
473 | } |
474 | ||
936f6353 | 475 | wxSize wxStatusBar::DoGetBestSize() const |
c0ac3149 | 476 | { |
edd608b1 | 477 | const MSWBorders borders = MSWGetBorders(); |
c0ac3149 VZ |
478 | |
479 | // calculate width | |
480 | int width = 0; | |
a37d94d3 | 481 | for ( size_t i = 0; i < m_panes.GetCount(); ++i ) |
c0ac3149 | 482 | { |
7b6fefbe | 483 | int widthField = |
b31eaa5c | 484 | m_bSameWidthForAllPanes ? DEFAULT_FIELD_WIDTH : m_panes[i].GetWidth(); |
c0ac3149 VZ |
485 | if ( widthField >= 0 ) |
486 | { | |
e408d9ca | 487 | width += widthField; |
c0ac3149 VZ |
488 | } |
489 | else | |
490 | { | |
491 | // variable width field, its width is really a proportion | |
492 | // related to the other fields | |
493 | width += -widthField*DEFAULT_FIELD_WIDTH; | |
494 | } | |
495 | ||
496 | // add the space between fields | |
edd608b1 | 497 | width += borders.between; |
c0ac3149 VZ |
498 | } |
499 | ||
500 | if ( !width ) | |
501 | { | |
502 | // still need something even for an empty status bar | |
503 | width = 2*DEFAULT_FIELD_WIDTH; | |
504 | } | |
505 | ||
c0ac3149 VZ |
506 | // calculate height |
507 | int height; | |
508 | wxGetCharSize(GetHWND(), NULL, &height, GetFont()); | |
509 | height = EDIT_HEIGHT_FROM_CHAR_HEIGHT(height); | |
edd608b1 | 510 | height += borders.vert; |
c0ac3149 VZ |
511 | |
512 | wxSize best(width, height); | |
513 | CacheBestSize(best); | |
514 | return best; | |
515 | } | |
516 | ||
936f6353 | 517 | void wxStatusBar::DoMoveWindow(int x, int y, int width, int height) |
2bda0e17 | 518 | { |
c07103f2 VZ |
519 | if ( GetParent()->IsSizeDeferred() ) |
520 | { | |
521 | wxWindowMSW::DoMoveWindow(x, y, width, height); | |
522 | } | |
523 | else | |
524 | { | |
525 | // parent pos/size isn't deferred so do it now but don't send | |
526 | // WM_WINDOWPOSCHANGING since we don't want to change pos/size later | |
dd28827a JG |
527 | // we must use SWP_NOCOPYBITS here otherwise it paints incorrectly |
528 | // if other windows are size deferred | |
c07103f2 | 529 | ::SetWindowPos(GetHwnd(), NULL, x, y, width, height, |
99cc862c | 530 | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE |
521bf4ff | 531 | #ifndef __WXWINCE__ |
99cc862c JS |
532 | | SWP_NOCOPYBITS | SWP_NOSENDCHANGING |
533 | #endif | |
534 | ); | |
c07103f2 | 535 | } |
43b5058d VZ |
536 | |
537 | // adjust fields widths to the new size | |
6cf68971 | 538 | MSWUpdateFieldsWidths(); |
dafa4925 | 539 | |
57f4f925 | 540 | // we have to trigger wxSizeEvent if there are children window in status |
dafa4925 VS |
541 | // bar because GetFieldRect returned incorrect (not updated) values up to |
542 | // here, which almost certainly resulted in incorrectly redrawn statusbar | |
543 | if ( m_children.GetCount() > 0 ) | |
544 | { | |
545 | wxSizeEvent event(GetClientSize(), m_windowId); | |
546 | event.SetEventObject(this); | |
937013e0 | 547 | HandleWindowEvent(event); |
dafa4925 | 548 | } |
2bda0e17 KB |
549 | } |
550 | ||
936f6353 | 551 | void wxStatusBar::SetStatusStyles(int n, const int styles[]) |
c2919ab3 VZ |
552 | { |
553 | wxStatusBarBase::SetStatusStyles(n, styles); | |
554 | ||
a37d94d3 | 555 | if (n != (int)m_panes.GetCount()) |
c2919ab3 VZ |
556 | return; |
557 | ||
558 | for (int i = 0; i < n; i++) | |
559 | { | |
560 | int style; | |
561 | switch(styles[i]) | |
562 | { | |
563 | case wxSB_RAISED: | |
564 | style = SBT_POPOUT; | |
565 | break; | |
566 | case wxSB_FLAT: | |
567 | style = SBT_NOBORDERS; | |
568 | break; | |
569 | case wxSB_NORMAL: | |
570 | default: | |
571 | style = 0; | |
572 | break; | |
573 | } | |
6418ad5e | 574 | |
c2919ab3 | 575 | // The SB_SETTEXT message is both used to set the field's text as well as |
43b2d5e7 | 576 | // the fields' styles. |
6418ad5e | 577 | // NOTE: MSDN library doesn't mention that nField and style have to be 'ORed' |
c2919ab3 | 578 | wxString text = GetStatusText(i); |
e0a050e3 | 579 | if (!StatusBar_SetText(GetHwnd(), style | i, text.wx_str())) |
43b2d5e7 | 580 | { |
6418ad5e | 581 | wxLogLastError("StatusBar_SetText"); |
43b2d5e7 | 582 | } |
c2919ab3 VZ |
583 | } |
584 | } | |
585 | ||
c07103f2 | 586 | WXLRESULT |
936f6353 | 587 | wxStatusBar::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) |
c07103f2 | 588 | { |
e78e8583 | 589 | #ifndef __WXWINCE__ |
c07103f2 VZ |
590 | if ( nMsg == WM_WINDOWPOSCHANGING ) |
591 | { | |
592 | WINDOWPOS *lpPos = (WINDOWPOS *)lParam; | |
593 | int x, y, w, h; | |
594 | GetPosition(&x, &y); | |
595 | GetSize(&w, &h); | |
596 | ||
4ce18ecb VZ |
597 | // we need real window coords and not wx client coords |
598 | AdjustForParentClientOrigin(x, y); | |
599 | ||
c07103f2 VZ |
600 | lpPos->x = x; |
601 | lpPos->y = y; | |
602 | lpPos->cx = w; | |
603 | lpPos->cy = h; | |
604 | ||
605 | return 0; | |
606 | } | |
e78e8583 | 607 | |
c07103f2 VZ |
608 | if ( nMsg == WM_NCLBUTTONDOWN ) |
609 | { | |
610 | // if hit-test is on gripper then send message to TLW to begin | |
611 | // resizing. It is possible to send this message to any window. | |
612 | if ( wParam == HTBOTTOMRIGHT ) | |
613 | { | |
614 | wxWindow *win; | |
615 | ||
616 | for ( win = GetParent(); win; win = win->GetParent() ) | |
617 | { | |
618 | if ( win->IsTopLevel() ) | |
619 | { | |
620 | SendMessage(GetHwndOf(win), WM_NCLBUTTONDOWN, | |
621 | wParam, lParam); | |
622 | ||
623 | return 0; | |
624 | } | |
625 | } | |
626 | } | |
627 | } | |
e78e8583 | 628 | #endif |
c07103f2 | 629 | |
6418ad5e FM |
630 | bool needsEllipsization = HasFlag(wxSTB_ELLIPSIZE_START) || |
631 | HasFlag(wxSTB_ELLIPSIZE_MIDDLE) || | |
632 | HasFlag(wxSTB_ELLIPSIZE_END); | |
633 | if ( nMsg == WM_SIZE && needsEllipsization ) | |
0cd15959 FM |
634 | { |
635 | for (int i=0; i<GetFieldsCount(); i++) | |
6cf68971 | 636 | DoUpdateStatusText(i); |
0cd15959 FM |
637 | // re-set the field text, in case we need to ellipsize |
638 | // (or de-ellipsize) some parts of it | |
639 | } | |
640 | ||
c07103f2 VZ |
641 | return wxStatusBarBase::MSWWindowProc(nMsg, wParam, lParam); |
642 | } | |
643 | ||
6418ad5e FM |
644 | #if wxUSE_TOOLTIPS |
645 | bool wxStatusBar::MSWProcessMessage(WXMSG* pMsg) | |
646 | { | |
647 | if ( HasFlag(wxSTB_SHOW_TIPS) ) | |
648 | { | |
649 | // for a tooltip to be shown, we need to relay mouse events to it; | |
650 | // this is typically done by wxWindowMSW::MSWProcessMessage but only | |
651 | // if wxWindow::m_tooltip pointer is non-NULL. | |
652 | // Since wxStatusBar has multiple tooltips for a single HWND, it keeps | |
653 | // wxWindow::m_tooltip == NULL and then relays mouse events here: | |
654 | MSG *msg = (MSG *)pMsg; | |
655 | if ( msg->message == WM_MOUSEMOVE ) | |
656 | wxToolTip::RelayEvent(pMsg); | |
657 | } | |
658 | ||
659 | return wxWindow::MSWProcessMessage(pMsg); | |
660 | } | |
661 | ||
778adf4c | 662 | bool wxStatusBar::MSWOnNotify(int WXUNUSED(idCtrl), WXLPARAM lParam, WXLPARAM* WXUNUSED(result)) |
6418ad5e FM |
663 | { |
664 | if ( HasFlag(wxSTB_SHOW_TIPS) ) | |
665 | { | |
666 | // see comment in wxStatusBar::MSWProcessMessage for more info; | |
667 | // basically we need to override wxWindow::MSWOnNotify because | |
668 | // we have wxWindow::m_tooltip always NULL but we still use tooltips... | |
669 | ||
670 | NMHDR* hdr = (NMHDR *)lParam; | |
671 | ||
672 | wxString str; | |
673 | if (hdr->idFrom < m_tooltips.size() && m_tooltips[hdr->idFrom]) | |
674 | str = m_tooltips[hdr->idFrom]->GetTip(); | |
675 | ||
676 | if ( HandleTooltipNotify(hdr->code, lParam, str)) | |
677 | { | |
678 | // processed | |
679 | return true; | |
680 | } | |
681 | } | |
682 | ||
683 | return false; | |
684 | } | |
685 | #endif // wxUSE_TOOLTIPS | |
686 | ||
a71d815b | 687 | #endif // wxUSE_STATUSBAR && wxUSE_NATIVE_STATUSBAR |