]> git.saurik.com Git - wxWidgets.git/blame - src/msw/statbr95.cpp
Smooth Aqua buttons in wxTreeCtrl.
[wxWidgets.git] / src / msw / statbr95.cpp
CommitLineData
2bda0e17
KB
1///////////////////////////////////////////////////////////////////////////////
2// Name: msw/statbr95.cpp
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>
9// Licence: wxWindows license
10///////////////////////////////////////////////////////////////////////////////
11
cfe780fb
JS
12#ifdef __GNUG__
13#pragma implementation "statbr95.h"
14#endif
15
2bda0e17
KB
16// for compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20 #pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
24 #include "wx/setup.h"
25 #include "wx/frame.h"
26 #include "wx/settings.h"
27 #include "wx/dcclient.h"
28#endif
29
ed791986 30#if defined(__WIN95__) && wxUSE_NATIVE_STATUSBAR
2432b92d 31
608eeb0f 32#include "wx/intl.h"
2bda0e17 33#include "wx/log.h"
ed791986 34#include "wx/statusbr.h"
2bda0e17 35
42e69d6b
VZ
36#include "wx/msw/private.h"
37#include <windowsx.h>
2bda0e17 38
ae090fdb 39#if defined(__WIN95__) && !((defined(__GNUWIN32_OLD__) || defined(__TWIN32__)) && !defined(__CYGWIN10__))
c42404a5 40 #include <commctrl.h>
ce3ed50d
JS
41#endif
42
2bda0e17
KB
43// ----------------------------------------------------------------------------
44// macros
45// ----------------------------------------------------------------------------
46
47// windowsx.h and commctrl.h don't define those, so we do it here
48#define StatusBar_SetParts(h, n, w) SendMessage(h, SB_SETPARTS, (WPARAM)n, (LPARAM)w)
837e5743 49#define StatusBar_SetText(h, n, t) SendMessage(h, SB_SETTEXT, (WPARAM)n, (LPARAM)(LPCTSTR)t)
2bda0e17 50#define StatusBar_GetTextLen(h, n) LOWORD(SendMessage(h, SB_GETTEXTLENGTH, (WPARAM)n, 0))
837e5743 51#define StatusBar_GetText(h, n, s) LOWORD(SendMessage(h, SB_GETTEXT, (WPARAM)n, (LPARAM)(LPTSTR)s))
2bda0e17 52
2bda0e17
KB
53// ============================================================================
54// implementation
55// ============================================================================
56
57// ----------------------------------------------------------------------------
58// wxStatusBar95 class
59// ----------------------------------------------------------------------------
60
61wxStatusBar95::wxStatusBar95()
62{
b3d008db
VZ
63 SetParent(NULL);
64 m_hWnd = 0;
65 m_windowId = 0;
2bda0e17
KB
66}
67
ed791986
VZ
68bool wxStatusBar95::Create(wxWindow *parent,
69 wxWindowID id,
70 long style,
71 const wxString& name)
2bda0e17 72{
cbc66a27
VZ
73 wxCHECK_MSG( parent, FALSE, wxT("status bar must have a parent") );
74
ed791986 75 SetName(name);
cbc66a27 76 SetWindowStyleFlag(style);
ed791986
VZ
77 SetParent(parent);
78
cbc66a27
VZ
79 parent->AddChild(this);
80
81 m_windowId = id == -1 ? NewControlId() : id;
ed791986 82
b0766406
JS
83 DWORD wstyle = WS_CHILD | WS_VISIBLE;
84
85 if ( style & wxCLIP_SIBLINGS )
86 wstyle |= WS_CLIPSIBLINGS;
87
43b5058d
VZ
88 // setting SBARS_SIZEGRIP is perfectly useless: it's always on by default
89 // (at least in the version of comctl32.dll I'm using), and the only way to
90 // turn it off is to use CCS_TOP style - as we position the status bar
91 // manually anyhow (see DoMoveWindow), use CCS_TOP style if wxST_SIZEGRIP
92 // is not given
93 if ( !(style & wxST_SIZEGRIP) )
94 {
95 wstyle |= CCS_TOP;
96 }
97 else
98 {
99 // may be some versions of comctl32.dll do need it - anyhow, it won't
100 // do any harm
ed791986 101 wstyle |= SBARS_SIZEGRIP;
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
112 return FALSE;
113 }
2bda0e17 114
c6e7d14f 115 SetFieldsCount(1);
b3d008db 116 SubclassWin(m_hWnd);
2bda0e17 117
ed791986
VZ
118 return TRUE;
119}
2bda0e17 120
ed791986
VZ
121wxStatusBar95::~wxStatusBar95()
122{
2bda0e17
KB
123}
124
790ad94f 125void wxStatusBar95::SetFieldsCount(int nFields, const int *widths)
2bda0e17 126{
f6bcfd97
BP
127 // this is a Windows limitation
128 wxASSERT_MSG( (nFields > 0) && (nFields < 255), _T("too many fields") );
2bda0e17 129
498fd97d 130 wxStatusBarBase::SetFieldsCount(nFields, widths);
27d2cd5c
VZ
131
132 SetFieldsWidth();
2bda0e17
KB
133}
134
498fd97d 135void wxStatusBar95::SetStatusWidths(int n, const int widths[])
2bda0e17 136{
498fd97d 137 wxStatusBarBase::SetStatusWidths(n, widths);
2bda0e17 138
f6bcfd97 139 SetFieldsWidth();
2bda0e17
KB
140}
141
142void wxStatusBar95::SetFieldsWidth()
143{
3175c712
VZ
144 if ( !m_nFields )
145 return;
146
ed791986
VZ
147 int aBorders[3];
148 SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders);
2bda0e17 149
ed791986 150 int extraWidth = aBorders[2]; // space between fields
2bda0e17 151
498fd97d
VZ
152 wxArrayInt widthsAbs =
153 CalculateAbsWidths(GetClientSize().x - extraWidth*(m_nFields - 1));
2bda0e17 154
498fd97d 155 int *pWidths = new int[m_nFields];
2bda0e17 156
498fd97d
VZ
157 int nCurPos = 0;
158 for ( int i = 0; i < m_nFields; i++ ) {
159 nCurPos += widthsAbs[i] + extraWidth;
160 pWidths[i] = nCurPos;
2bda0e17 161 }
2bda0e17 162
ed791986
VZ
163 if ( !StatusBar_SetParts(GetHwnd(), m_nFields, pWidths) ) {
164 wxLogLastError(wxT("StatusBar_SetParts"));
165 }
2bda0e17 166
ed791986 167 delete [] pWidths;
2bda0e17
KB
168}
169
debe6624 170void wxStatusBar95::SetStatusText(const wxString& strText, int nField)
2bda0e17 171{
ed791986
VZ
172 wxCHECK_RET( (nField >= 0) && (nField < m_nFields),
173 _T("invalid statusbar field index") );
174
b3d008db
VZ
175 if ( !StatusBar_SetText(GetHwnd(), nField, strText) )
176 {
177 wxLogLastError(wxT("StatusBar_SetText"));
178 }
2bda0e17
KB
179}
180
181wxString wxStatusBar95::GetStatusText(int nField) const
182{
ed791986
VZ
183 wxCHECK_MSG( (nField >= 0) && (nField < m_nFields), wxEmptyString,
184 _T("invalid statusbar field index") );
2bda0e17 185
b3d008db
VZ
186 wxString str;
187 int len = StatusBar_GetTextLen(GetHwnd(), nField);
188 if ( len > 0 )
189 {
190 StatusBar_GetText(GetHwnd(), nField, str.GetWriteBuf(len));
191 str.UngetWriteBuf();
192 }
193
194 return str;
2bda0e17
KB
195}
196
ed791986
VZ
197int wxStatusBar95::GetBorderX() const
198{
199 int aBorders[3];
200 SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders);
201
202 return aBorders[0];
203}
204
205int wxStatusBar95::GetBorderY() const
206{
207 int aBorders[3];
208 SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders);
209
210 return aBorders[1];
211}
212
213void wxStatusBar95::SetMinHeight(int height)
214{
215 SendMessage(GetHwnd(), SB_SETMINHEIGHT, height + 2*GetBorderY(), 0);
216
217 // have to send a (dummy) WM_SIZE to redraw it now
218 SendMessage(GetHwnd(), WM_SIZE, 0, 0);
219}
220
221bool wxStatusBar95::GetFieldRect(int i, wxRect& rect) const
222{
223 wxCHECK_MSG( (i >= 0) && (i < m_nFields), FALSE,
224 _T("invalid statusbar field index") );
225
226 RECT r;
227 if ( !::SendMessage(GetHwnd(), SB_GETRECT, i, (LPARAM)&r) )
228 {
f6bcfd97 229 wxLogLastError(wxT("SendMessage(SB_GETRECT)"));
ed791986
VZ
230 }
231
232 wxCopyRECTToRect(r, rect);
233
234 return TRUE;
235}
236
cbc66a27 237void wxStatusBar95::DoMoveWindow(int x, int y, int width, int height)
2bda0e17 238{
43b5058d
VZ
239 // the status bar wnd proc must be forwarded the WM_SIZE message whenever
240 // the stat bar position/size is changed because it normally positions the
241 // control itself along bottom or top side of the parent window - failing
242 // to do so will result in nasty visual effects
243 FORWARD_WM_SIZE(GetHwnd(), SIZE_RESTORED, x, y, SendMessage);
244
245 // but now, when the standard status bar wnd proc did all it wanted to do,
246 // move the status bar to its correct location - usually this call may be
247 // omitted because for normal status bars (positioned along the bottom
248 // edge) the position is already set correctly, but if the user wants to
249 // position them in some exotic location, this is really needed
250 wxWindow::DoMoveWindow(x, y, width, height);
251
252 // adjust fields widths to the new size
253 SetFieldsWidth();
dafa4925
VS
254
255 // we have to trigger wxSizeEvent if there are children window in status
256 // bar because GetFieldRect returned incorrect (not updated) values up to
257 // here, which almost certainly resulted in incorrectly redrawn statusbar
258 if ( m_children.GetCount() > 0 )
259 {
260 wxSizeEvent event(GetClientSize(), m_windowId);
261 event.SetEventObject(this);
262 GetEventHandler()->ProcessEvent(event);
263 }
2bda0e17
KB
264}
265
ed791986 266#endif // __WIN95__ && wxUSE_NATIVE_STATUSBAR
ba681060 267