]>
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, | |
111 | _T(""), | |
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 FM |
128 | |
129 | // cache the DC instance used by UpdateFieldText: | |
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 FM |
155 | |
156 | wxDELETE(m_pDC); | |
2bda0e17 KB |
157 | } |
158 | ||
0cd15959 FM |
159 | bool wxStatusBar::SetFont(const wxFont& font) |
160 | { | |
161 | if (!wxWindow::SetFont(font)) | |
162 | return false; | |
163 | ||
80255b7e | 164 | if (m_pDC) m_pDC->SetFont(font); |
0cd15959 FM |
165 | return true; |
166 | } | |
167 | ||
936f6353 | 168 | void wxStatusBar::SetFieldsCount(int nFields, const int *widths) |
2bda0e17 | 169 | { |
f6bcfd97 | 170 | // this is a Windows limitation |
6418ad5e | 171 | wxASSERT_MSG( (nFields > 0) && (nFields < 255), "too many fields" ); |
2bda0e17 | 172 | |
498fd97d | 173 | wxStatusBarBase::SetFieldsCount(nFields, widths); |
27d2cd5c VZ |
174 | |
175 | SetFieldsWidth(); | |
6418ad5e FM |
176 | |
177 | // keep in synch also our m_tooltips array | |
178 | ||
179 | // reset all current tooltips | |
180 | for (size_t i=0; i<m_tooltips.size(); i++) | |
181 | { | |
182 | delete m_tooltips[i]; | |
183 | m_tooltips[i] = NULL; | |
184 | } | |
185 | ||
186 | // shrink/expand the array: | |
187 | m_tooltips.resize(m_panes.GetCount(), NULL); | |
2bda0e17 KB |
188 | } |
189 | ||
936f6353 | 190 | void wxStatusBar::SetStatusWidths(int n, const int widths[]) |
2bda0e17 | 191 | { |
498fd97d | 192 | wxStatusBarBase::SetStatusWidths(n, widths); |
2bda0e17 | 193 | |
f6bcfd97 | 194 | SetFieldsWidth(); |
2bda0e17 KB |
195 | } |
196 | ||
936f6353 | 197 | void wxStatusBar::SetFieldsWidth() |
2bda0e17 | 198 | { |
7b6fefbe | 199 | if ( m_panes.IsEmpty() ) |
3175c712 VZ |
200 | return; |
201 | ||
ed791986 VZ |
202 | int aBorders[3]; |
203 | SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders); | |
2bda0e17 | 204 | |
ed791986 | 205 | int extraWidth = aBorders[2]; // space between fields |
2bda0e17 | 206 | |
6418ad5e FM |
207 | |
208 | // distribute the available space (client width) among the various fields: | |
209 | ||
498fd97d | 210 | wxArrayInt widthsAbs = |
7b6fefbe | 211 | CalculateAbsWidths(GetClientSize().x - extraWidth*(m_panes.GetCount() - 1)); |
2bda0e17 | 212 | |
6418ad5e FM |
213 | |
214 | // update the field widths in the native control: | |
215 | ||
7b6fefbe | 216 | int *pWidths = new int[m_panes.GetCount()]; |
2bda0e17 | 217 | |
498fd97d | 218 | int nCurPos = 0; |
6418ad5e FM |
219 | for ( size_t i = 0; i < m_panes.GetCount(); i++ ) |
220 | { | |
498fd97d VZ |
221 | nCurPos += widthsAbs[i] + extraWidth; |
222 | pWidths[i] = nCurPos; | |
2bda0e17 | 223 | } |
2bda0e17 | 224 | |
6418ad5e FM |
225 | if ( !StatusBar_SetParts(GetHwnd(), m_panes.GetCount(), pWidths) ) |
226 | wxLogLastError("StatusBar_SetParts"); | |
2bda0e17 | 227 | |
ed791986 | 228 | delete [] pWidths; |
6418ad5e FM |
229 | |
230 | ||
231 | // FIXME: we may want to call UpdateFieldText() here since we may need to (de)ellipsize status texts | |
2bda0e17 KB |
232 | } |
233 | ||
936f6353 | 234 | void wxStatusBar::SetStatusText(const wxString& strText, int nField) |
2bda0e17 | 235 | { |
a37d94d3 | 236 | wxCHECK_RET( (nField >= 0) && ((size_t)nField < m_panes.GetCount()), |
6418ad5e | 237 | "invalid statusbar field index" ); |
ed791986 | 238 | |
823b6635 VZ |
239 | if ( strText == GetStatusText(nField) ) |
240 | { | |
6418ad5e FM |
241 | // don't call StatusBar_SetText() to avoid flicker |
242 | return; | |
823b6635 VZ |
243 | } |
244 | ||
0cd15959 FM |
245 | wxStatusBarBase::SetStatusText(strText, nField); |
246 | ||
247 | UpdateFieldText(nField); | |
248 | } | |
249 | ||
250 | void wxStatusBar::UpdateFieldText(int nField) | |
251 | { | |
252 | if (!m_pDC) | |
253 | return; | |
254 | ||
c2919ab3 VZ |
255 | // Get field style, if any |
256 | int style; | |
b31eaa5c | 257 | switch(m_panes[nField].GetStyle()) |
c2919ab3 | 258 | { |
7b6fefbe FM |
259 | case wxSB_RAISED: |
260 | style = SBT_POPOUT; | |
261 | break; | |
262 | case wxSB_FLAT: | |
263 | style = SBT_NOBORDERS; | |
264 | break; | |
265 | ||
266 | case wxSB_NORMAL: | |
267 | default: | |
c2919ab3 | 268 | style = 0; |
7b6fefbe FM |
269 | break; |
270 | } | |
c2919ab3 | 271 | |
0cd15959 FM |
272 | wxRect rc; |
273 | GetFieldRect(nField, rc); | |
274 | ||
275 | int margin; | |
276 | if (nField == GetFieldsCount()-1) | |
277 | margin = -6; // windows reports a smaller rect for the last field; enlarge it | |
278 | else | |
279 | margin = 4; | |
280 | ||
6418ad5e FM |
281 | int maxWidth = rc.GetWidth() - margin; // leave a small margin |
282 | wxString text = GetStatusText(nField); | |
283 | ||
0cd15959 | 284 | // do we need to ellipsize this string? |
6418ad5e FM |
285 | wxEllipsizeMode ellmode = (wxEllipsizeMode)-1; |
286 | if (HasFlag(wxSTB_ELLIPSIZE_START)) ellmode = wxELLIPSIZE_START; | |
287 | else if (HasFlag(wxSTB_ELLIPSIZE_MIDDLE)) ellmode = wxELLIPSIZE_MIDDLE; | |
288 | else if (HasFlag(wxSTB_ELLIPSIZE_END)) ellmode = wxELLIPSIZE_END; | |
289 | ||
290 | if (ellmode == (wxEllipsizeMode)-1) | |
291 | { | |
292 | // if we have the wxSTB_SHOW_TIPS we must set the ellipsized flag even if | |
293 | // we don't ellipsize the text but just truncate it | |
294 | if (HasFlag(wxSTB_SHOW_TIPS)) | |
295 | SetEllipsizedFlag(nField, m_pDC->GetTextExtent(text).GetWidth() > maxWidth); | |
296 | } | |
297 | else | |
b3d008db | 298 | { |
6418ad5e FM |
299 | text = wxControl::Ellipsize(text, |
300 | *m_pDC, | |
301 | ellmode, | |
302 | maxWidth, | |
303 | wxELLIPSIZE_EXPAND_TAB); | |
304 | ||
305 | // update the ellipsization status for this pane; this is used later to | |
306 | // decide whether a tooltip should be shown or not for this pane | |
307 | // (if we have wxSTB_SHOW_TIPS) | |
308 | SetEllipsizedFlag(nField, text != GetStatusText(nField)); | |
309 | } | |
310 | ||
311 | // Set the status text in the native control passing both field number and style. | |
312 | // NOTE: MSDN library doesn't mention that nField and style have to be 'ORed' | |
313 | if ( !StatusBar_SetText(GetHwnd(), nField | style, text.wx_str()) ) | |
314 | wxLogLastError("StatusBar_SetText"); | |
315 | ||
316 | if (HasFlag(wxSTB_SHOW_TIPS)) | |
317 | { | |
318 | wxASSERT(m_tooltips.size() == m_panes.GetCount()); | |
319 | ||
320 | if (m_tooltips[nField]) | |
321 | { | |
322 | if (GetField(nField).IsEllipsized()) | |
323 | { | |
324 | // update the rect of this tooltip: | |
325 | m_tooltips[nField]->SetRect(rc); | |
326 | ||
327 | // update also the text: | |
328 | m_tooltips[nField]->SetTip(GetStatusText(nField)); | |
329 | } | |
330 | else | |
331 | { | |
332 | // delete the tooltip associated with this pane; it's not needed anymore | |
333 | delete m_tooltips[nField]; | |
334 | m_tooltips[nField] = NULL; | |
335 | } | |
336 | } | |
337 | else | |
338 | { | |
339 | // create a new tooltip for this pane if needed | |
340 | if (GetField(nField).IsEllipsized()) | |
341 | m_tooltips[nField] = new wxToolTip(this, nField, GetStatusText(nField), rc); | |
342 | //else: leave m_tooltips[nField]==NULL | |
343 | } | |
b3d008db | 344 | } |
2bda0e17 KB |
345 | } |
346 | ||
936f6353 | 347 | int wxStatusBar::GetBorderX() const |
ed791986 VZ |
348 | { |
349 | int aBorders[3]; | |
350 | SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders); | |
351 | ||
352 | return aBorders[0]; | |
353 | } | |
354 | ||
936f6353 | 355 | int wxStatusBar::GetBorderY() const |
ed791986 VZ |
356 | { |
357 | int aBorders[3]; | |
358 | SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders); | |
359 | ||
360 | return aBorders[1]; | |
361 | } | |
362 | ||
936f6353 | 363 | void wxStatusBar::SetMinHeight(int height) |
ed791986 VZ |
364 | { |
365 | SendMessage(GetHwnd(), SB_SETMINHEIGHT, height + 2*GetBorderY(), 0); | |
366 | ||
6418ad5e | 367 | // we have to send a (dummy) WM_SIZE to redraw it now |
ed791986 VZ |
368 | SendMessage(GetHwnd(), WM_SIZE, 0, 0); |
369 | } | |
370 | ||
936f6353 | 371 | bool wxStatusBar::GetFieldRect(int i, wxRect& rect) const |
ed791986 | 372 | { |
a37d94d3 | 373 | wxCHECK_MSG( (i >= 0) && ((size_t)i < m_panes.GetCount()), false, |
6418ad5e | 374 | "invalid statusbar field index" ); |
ed791986 VZ |
375 | |
376 | RECT r; | |
377 | if ( !::SendMessage(GetHwnd(), SB_GETRECT, i, (LPARAM)&r) ) | |
6418ad5e | 378 | wxLogLastError("SendMessage(SB_GETRECT)"); |
ed791986 | 379 | |
1feb5443 | 380 | #if wxUSE_UXTHEME |
6418ad5e | 381 | wxUxThemeHandle theme(const_cast<wxStatusBar*>(this), L"Status"); |
1feb5443 JG |
382 | if ( theme ) |
383 | { | |
384 | // by default Windows has a 2 pixel border to the right of the left | |
385 | // divider (or it could be a bug) but it looks wrong so remove it | |
386 | if ( i != 0 ) | |
387 | { | |
388 | r.left -= 2; | |
389 | } | |
390 | ||
391 | wxUxThemeEngine::Get()->GetThemeBackgroundContentRect(theme, NULL, | |
392 | 1 /* SP_PANE */, 0, | |
393 | &r, &r); | |
394 | } | |
395 | #endif | |
396 | ||
ed791986 VZ |
397 | wxCopyRECTToRect(r, rect); |
398 | ||
57f4f925 | 399 | return true; |
ed791986 VZ |
400 | } |
401 | ||
936f6353 | 402 | wxSize wxStatusBar::DoGetBestSize() const |
c0ac3149 VZ |
403 | { |
404 | int borders[3]; | |
405 | SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)borders); | |
406 | ||
407 | // calculate width | |
408 | int width = 0; | |
a37d94d3 | 409 | for ( size_t i = 0; i < m_panes.GetCount(); ++i ) |
c0ac3149 | 410 | { |
7b6fefbe | 411 | int widthField = |
b31eaa5c | 412 | m_bSameWidthForAllPanes ? DEFAULT_FIELD_WIDTH : m_panes[i].GetWidth(); |
c0ac3149 VZ |
413 | if ( widthField >= 0 ) |
414 | { | |
e408d9ca | 415 | width += widthField; |
c0ac3149 VZ |
416 | } |
417 | else | |
418 | { | |
419 | // variable width field, its width is really a proportion | |
420 | // related to the other fields | |
421 | width += -widthField*DEFAULT_FIELD_WIDTH; | |
422 | } | |
423 | ||
424 | // add the space between fields | |
425 | width += borders[2]; | |
426 | } | |
427 | ||
428 | if ( !width ) | |
429 | { | |
430 | // still need something even for an empty status bar | |
431 | width = 2*DEFAULT_FIELD_WIDTH; | |
432 | } | |
433 | ||
c0ac3149 VZ |
434 | // calculate height |
435 | int height; | |
436 | wxGetCharSize(GetHWND(), NULL, &height, GetFont()); | |
437 | height = EDIT_HEIGHT_FROM_CHAR_HEIGHT(height); | |
438 | height += borders[1]; | |
439 | ||
440 | wxSize best(width, height); | |
441 | CacheBestSize(best); | |
442 | return best; | |
443 | } | |
444 | ||
936f6353 | 445 | void wxStatusBar::DoMoveWindow(int x, int y, int width, int height) |
2bda0e17 | 446 | { |
c07103f2 VZ |
447 | if ( GetParent()->IsSizeDeferred() ) |
448 | { | |
449 | wxWindowMSW::DoMoveWindow(x, y, width, height); | |
450 | } | |
451 | else | |
452 | { | |
453 | // parent pos/size isn't deferred so do it now but don't send | |
454 | // WM_WINDOWPOSCHANGING since we don't want to change pos/size later | |
dd28827a JG |
455 | // we must use SWP_NOCOPYBITS here otherwise it paints incorrectly |
456 | // if other windows are size deferred | |
c07103f2 | 457 | ::SetWindowPos(GetHwnd(), NULL, x, y, width, height, |
99cc862c | 458 | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE |
521bf4ff | 459 | #ifndef __WXWINCE__ |
99cc862c JS |
460 | | SWP_NOCOPYBITS | SWP_NOSENDCHANGING |
461 | #endif | |
462 | ); | |
c07103f2 | 463 | } |
43b5058d VZ |
464 | |
465 | // adjust fields widths to the new size | |
466 | SetFieldsWidth(); | |
dafa4925 | 467 | |
57f4f925 | 468 | // we have to trigger wxSizeEvent if there are children window in status |
dafa4925 VS |
469 | // bar because GetFieldRect returned incorrect (not updated) values up to |
470 | // here, which almost certainly resulted in incorrectly redrawn statusbar | |
471 | if ( m_children.GetCount() > 0 ) | |
472 | { | |
473 | wxSizeEvent event(GetClientSize(), m_windowId); | |
474 | event.SetEventObject(this); | |
937013e0 | 475 | HandleWindowEvent(event); |
dafa4925 | 476 | } |
2bda0e17 KB |
477 | } |
478 | ||
936f6353 | 479 | void wxStatusBar::SetStatusStyles(int n, const int styles[]) |
c2919ab3 VZ |
480 | { |
481 | wxStatusBarBase::SetStatusStyles(n, styles); | |
482 | ||
a37d94d3 | 483 | if (n != (int)m_panes.GetCount()) |
c2919ab3 VZ |
484 | return; |
485 | ||
486 | for (int i = 0; i < n; i++) | |
487 | { | |
488 | int style; | |
489 | switch(styles[i]) | |
490 | { | |
491 | case wxSB_RAISED: | |
492 | style = SBT_POPOUT; | |
493 | break; | |
494 | case wxSB_FLAT: | |
495 | style = SBT_NOBORDERS; | |
496 | break; | |
497 | case wxSB_NORMAL: | |
498 | default: | |
499 | style = 0; | |
500 | break; | |
501 | } | |
6418ad5e | 502 | |
c2919ab3 | 503 | // The SB_SETTEXT message is both used to set the field's text as well as |
6418ad5e FM |
504 | // the fields' styles. |
505 | // NOTE: MSDN library doesn't mention that nField and style have to be 'ORed' | |
c2919ab3 | 506 | wxString text = GetStatusText(i); |
e0a050e3 | 507 | if (!StatusBar_SetText(GetHwnd(), style | i, text.wx_str())) |
6418ad5e | 508 | wxLogLastError("StatusBar_SetText"); |
c2919ab3 VZ |
509 | } |
510 | } | |
511 | ||
c07103f2 | 512 | WXLRESULT |
936f6353 | 513 | wxStatusBar::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) |
c07103f2 | 514 | { |
e78e8583 | 515 | #ifndef __WXWINCE__ |
c07103f2 VZ |
516 | if ( nMsg == WM_WINDOWPOSCHANGING ) |
517 | { | |
518 | WINDOWPOS *lpPos = (WINDOWPOS *)lParam; | |
519 | int x, y, w, h; | |
520 | GetPosition(&x, &y); | |
521 | GetSize(&w, &h); | |
522 | ||
4ce18ecb VZ |
523 | // we need real window coords and not wx client coords |
524 | AdjustForParentClientOrigin(x, y); | |
525 | ||
c07103f2 VZ |
526 | lpPos->x = x; |
527 | lpPos->y = y; | |
528 | lpPos->cx = w; | |
529 | lpPos->cy = h; | |
530 | ||
531 | return 0; | |
532 | } | |
e78e8583 | 533 | |
c07103f2 VZ |
534 | if ( nMsg == WM_NCLBUTTONDOWN ) |
535 | { | |
536 | // if hit-test is on gripper then send message to TLW to begin | |
537 | // resizing. It is possible to send this message to any window. | |
538 | if ( wParam == HTBOTTOMRIGHT ) | |
539 | { | |
540 | wxWindow *win; | |
541 | ||
542 | for ( win = GetParent(); win; win = win->GetParent() ) | |
543 | { | |
544 | if ( win->IsTopLevel() ) | |
545 | { | |
546 | SendMessage(GetHwndOf(win), WM_NCLBUTTONDOWN, | |
547 | wParam, lParam); | |
548 | ||
549 | return 0; | |
550 | } | |
551 | } | |
552 | } | |
553 | } | |
e78e8583 | 554 | #endif |
c07103f2 | 555 | |
6418ad5e FM |
556 | bool needsEllipsization = HasFlag(wxSTB_ELLIPSIZE_START) || |
557 | HasFlag(wxSTB_ELLIPSIZE_MIDDLE) || | |
558 | HasFlag(wxSTB_ELLIPSIZE_END); | |
559 | if ( nMsg == WM_SIZE && needsEllipsization ) | |
0cd15959 FM |
560 | { |
561 | for (int i=0; i<GetFieldsCount(); i++) | |
562 | UpdateFieldText(i); | |
563 | // re-set the field text, in case we need to ellipsize | |
564 | // (or de-ellipsize) some parts of it | |
565 | } | |
566 | ||
c07103f2 VZ |
567 | return wxStatusBarBase::MSWWindowProc(nMsg, wParam, lParam); |
568 | } | |
569 | ||
6418ad5e FM |
570 | #if wxUSE_TOOLTIPS |
571 | bool wxStatusBar::MSWProcessMessage(WXMSG* pMsg) | |
572 | { | |
573 | if ( HasFlag(wxSTB_SHOW_TIPS) ) | |
574 | { | |
575 | // for a tooltip to be shown, we need to relay mouse events to it; | |
576 | // this is typically done by wxWindowMSW::MSWProcessMessage but only | |
577 | // if wxWindow::m_tooltip pointer is non-NULL. | |
578 | // Since wxStatusBar has multiple tooltips for a single HWND, it keeps | |
579 | // wxWindow::m_tooltip == NULL and then relays mouse events here: | |
580 | MSG *msg = (MSG *)pMsg; | |
581 | if ( msg->message == WM_MOUSEMOVE ) | |
582 | wxToolTip::RelayEvent(pMsg); | |
583 | } | |
584 | ||
585 | return wxWindow::MSWProcessMessage(pMsg); | |
586 | } | |
587 | ||
778adf4c | 588 | bool wxStatusBar::MSWOnNotify(int WXUNUSED(idCtrl), WXLPARAM lParam, WXLPARAM* WXUNUSED(result)) |
6418ad5e FM |
589 | { |
590 | if ( HasFlag(wxSTB_SHOW_TIPS) ) | |
591 | { | |
592 | // see comment in wxStatusBar::MSWProcessMessage for more info; | |
593 | // basically we need to override wxWindow::MSWOnNotify because | |
594 | // we have wxWindow::m_tooltip always NULL but we still use tooltips... | |
595 | ||
596 | NMHDR* hdr = (NMHDR *)lParam; | |
597 | ||
598 | wxString str; | |
599 | if (hdr->idFrom < m_tooltips.size() && m_tooltips[hdr->idFrom]) | |
600 | str = m_tooltips[hdr->idFrom]->GetTip(); | |
601 | ||
602 | if ( HandleTooltipNotify(hdr->code, lParam, str)) | |
603 | { | |
604 | // processed | |
605 | return true; | |
606 | } | |
607 | } | |
608 | ||
609 | return false; | |
610 | } | |
611 | #endif // wxUSE_TOOLTIPS | |
612 | ||
a71d815b | 613 | #endif // wxUSE_STATUSBAR && wxUSE_NATIVE_STATUSBAR |