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