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