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