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