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