]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/msw/statbr95.cpp
fix for BSD compilation
[wxWidgets.git] / src / msw / statbr95.cpp
... / ...
CommitLineData
1///////////////////////////////////////////////////////////////////////////////
2// Name: msw/statbr95.cpp
3// Purpose: native implementation of wxStatusBar
4// Author: Vadim Zeitlin
5// Modified by:
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
12#ifdef __GNUG__
13#pragma implementation "statbr95.h"
14#endif
15
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
30#if defined(__WIN95__) && wxUSE_NATIVE_STATUSBAR
31
32#include "wx/intl.h"
33#include "wx/log.h"
34#include "wx/statusbr.h"
35
36#include "wx/msw/private.h"
37#include <windowsx.h>
38
39#if defined(__WIN95__) && !((defined(__GNUWIN32_OLD__) || defined(__TWIN32__)) && !defined(__CYGWIN10__))
40 #include <commctrl.h>
41#endif
42
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)
49#define StatusBar_SetText(h, n, t) SendMessage(h, SB_SETTEXT, (WPARAM)n, (LPARAM)(LPCTSTR)t)
50#define StatusBar_GetTextLen(h, n) LOWORD(SendMessage(h, SB_GETTEXTLENGTH, (WPARAM)n, 0))
51#define StatusBar_GetText(h, n, s) LOWORD(SendMessage(h, SB_GETTEXT, (WPARAM)n, (LPARAM)(LPTSTR)s))
52
53// ============================================================================
54// implementation
55// ============================================================================
56
57// ----------------------------------------------------------------------------
58// wxStatusBar95 class
59// ----------------------------------------------------------------------------
60
61wxStatusBar95::wxStatusBar95()
62{
63 SetParent(NULL);
64 m_hWnd = 0;
65 m_windowId = 0;
66}
67
68bool wxStatusBar95::Create(wxWindow *parent,
69 wxWindowID id,
70 long style,
71 const wxString& name)
72{
73 wxCHECK_MSG( parent, FALSE, wxT("status bar must have a parent") );
74
75 SetName(name);
76 SetWindowStyleFlag(style);
77 SetParent(parent);
78
79 parent->AddChild(this);
80
81 m_windowId = id == -1 ? NewControlId() : id;
82
83 DWORD wstyle = WS_CHILD | WS_VISIBLE;
84
85 if ( style & wxCLIP_SIBLINGS )
86 wstyle |= WS_CLIPSIBLINGS;
87
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
101 wstyle |= SBARS_SIZEGRIP;
102 }
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 }
114
115 SetFieldsCount(1);
116 SubclassWin(m_hWnd);
117
118 return TRUE;
119}
120
121wxStatusBar95::~wxStatusBar95()
122{
123}
124
125void wxStatusBar95::SetFieldsCount(int nFields, const int *widths)
126{
127 // this is a Windows limitation
128 wxASSERT_MSG( (nFields > 0) && (nFields < 255), _T("too many fields") );
129
130 wxStatusBarBase::SetFieldsCount(nFields, widths);
131}
132
133void wxStatusBar95::SetStatusWidths(int n, const int widths[])
134{
135 wxStatusBarBase::SetStatusWidths(n, widths);
136
137 SetFieldsWidth();
138}
139
140void wxStatusBar95::SetFieldsWidth()
141{
142 if ( !m_nFields )
143 return;
144
145 int aBorders[3];
146 SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders);
147
148 int extraWidth = aBorders[2]; // space between fields
149
150 wxArrayInt widthsAbs =
151 CalculateAbsWidths(GetClientSize().x - extraWidth*(m_nFields - 1));
152
153 int *pWidths = new int[m_nFields];
154
155 int nCurPos = 0;
156 for ( int i = 0; i < m_nFields; i++ ) {
157 nCurPos += widthsAbs[i] + extraWidth;
158 pWidths[i] = nCurPos;
159 }
160
161 if ( !StatusBar_SetParts(GetHwnd(), m_nFields, pWidths) ) {
162 wxLogLastError(wxT("StatusBar_SetParts"));
163 }
164
165 delete [] pWidths;
166}
167
168void wxStatusBar95::SetStatusText(const wxString& strText, int nField)
169{
170 wxCHECK_RET( (nField >= 0) && (nField < m_nFields),
171 _T("invalid statusbar field index") );
172
173 if ( !StatusBar_SetText(GetHwnd(), nField, strText) )
174 {
175 wxLogLastError(wxT("StatusBar_SetText"));
176 }
177}
178
179wxString wxStatusBar95::GetStatusText(int nField) const
180{
181 wxCHECK_MSG( (nField >= 0) && (nField < m_nFields), wxEmptyString,
182 _T("invalid statusbar field index") );
183
184 wxString str;
185 int len = StatusBar_GetTextLen(GetHwnd(), nField);
186 if ( len > 0 )
187 {
188 StatusBar_GetText(GetHwnd(), nField, str.GetWriteBuf(len));
189 str.UngetWriteBuf();
190 }
191
192 return str;
193}
194
195int wxStatusBar95::GetBorderX() const
196{
197 int aBorders[3];
198 SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders);
199
200 return aBorders[0];
201}
202
203int wxStatusBar95::GetBorderY() const
204{
205 int aBorders[3];
206 SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders);
207
208 return aBorders[1];
209}
210
211void wxStatusBar95::SetMinHeight(int height)
212{
213 SendMessage(GetHwnd(), SB_SETMINHEIGHT, height + 2*GetBorderY(), 0);
214
215 // have to send a (dummy) WM_SIZE to redraw it now
216 SendMessage(GetHwnd(), WM_SIZE, 0, 0);
217}
218
219bool wxStatusBar95::GetFieldRect(int i, wxRect& rect) const
220{
221 wxCHECK_MSG( (i >= 0) && (i < m_nFields), FALSE,
222 _T("invalid statusbar field index") );
223
224 RECT r;
225 if ( !::SendMessage(GetHwnd(), SB_GETRECT, i, (LPARAM)&r) )
226 {
227 wxLogLastError(wxT("SendMessage(SB_GETRECT)"));
228 }
229
230 wxCopyRECTToRect(r, rect);
231
232 return TRUE;
233}
234
235void wxStatusBar95::DoMoveWindow(int x, int y, int width, int height)
236{
237 // the status bar wnd proc must be forwarded the WM_SIZE message whenever
238 // the stat bar position/size is changed because it normally positions the
239 // control itself along bottom or top side of the parent window - failing
240 // to do so will result in nasty visual effects
241 FORWARD_WM_SIZE(GetHwnd(), SIZE_RESTORED, x, y, SendMessage);
242
243 // but now, when the standard status bar wnd proc did all it wanted to do,
244 // move the status bar to its correct location - usually this call may be
245 // omitted because for normal status bars (positioned along the bottom
246 // edge) the position is already set correctly, but if the user wants to
247 // position them in some exotic location, this is really needed
248 wxWindow::DoMoveWindow(x, y, width, height);
249
250 // adjust fields widths to the new size
251 SetFieldsWidth();
252
253 // we have to trigger wxSizeEvent if there are children window in status
254 // bar because GetFieldRect returned incorrect (not updated) values up to
255 // here, which almost certainly resulted in incorrectly redrawn statusbar
256 if ( m_children.GetCount() > 0 )
257 {
258 wxSizeEvent event(GetClientSize(), m_windowId);
259 event.SetEventObject(this);
260 GetEventHandler()->ProcessEvent(event);
261 }
262}
263
264#endif // __WIN95__ && wxUSE_NATIVE_STATUSBAR
265