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