]>
Commit | Line | Data |
---|---|---|
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 | ||
ed791986 VZ |
43 | // ---------------------------------------------------------------------------- |
44 | // wxWindows macros | |
45 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 46 | |
ed791986 VZ |
47 | IMPLEMENT_DYNAMIC_CLASS(wxStatusBar95, wxWindow); |
48 | IMPLEMENT_DYNAMIC_CLASS(wxStatusBar, wxStatusBar95) | |
2bda0e17 | 49 | |
2bda0e17 KB |
50 | // ---------------------------------------------------------------------------- |
51 | // macros | |
52 | // ---------------------------------------------------------------------------- | |
53 | ||
54 | // windowsx.h and commctrl.h don't define those, so we do it here | |
55 | #define StatusBar_SetParts(h, n, w) SendMessage(h, SB_SETPARTS, (WPARAM)n, (LPARAM)w) | |
837e5743 | 56 | #define StatusBar_SetText(h, n, t) SendMessage(h, SB_SETTEXT, (WPARAM)n, (LPARAM)(LPCTSTR)t) |
2bda0e17 | 57 | #define StatusBar_GetTextLen(h, n) LOWORD(SendMessage(h, SB_GETTEXTLENGTH, (WPARAM)n, 0)) |
837e5743 | 58 | #define StatusBar_GetText(h, n, s) LOWORD(SendMessage(h, SB_GETTEXT, (WPARAM)n, (LPARAM)(LPTSTR)s)) |
2bda0e17 | 59 | |
2bda0e17 KB |
60 | // ============================================================================ |
61 | // implementation | |
62 | // ============================================================================ | |
63 | ||
64 | // ---------------------------------------------------------------------------- | |
65 | // wxStatusBar95 class | |
66 | // ---------------------------------------------------------------------------- | |
67 | ||
68 | wxStatusBar95::wxStatusBar95() | |
69 | { | |
b3d008db VZ |
70 | SetParent(NULL); |
71 | m_hWnd = 0; | |
72 | m_windowId = 0; | |
2bda0e17 KB |
73 | } |
74 | ||
ed791986 VZ |
75 | bool wxStatusBar95::Create(wxWindow *parent, |
76 | wxWindowID id, | |
77 | long style, | |
78 | const wxString& name) | |
2bda0e17 | 79 | { |
cbc66a27 VZ |
80 | wxCHECK_MSG( parent, FALSE, wxT("status bar must have a parent") ); |
81 | ||
ed791986 | 82 | SetName(name); |
cbc66a27 | 83 | SetWindowStyleFlag(style); |
ed791986 VZ |
84 | SetParent(parent); |
85 | ||
cbc66a27 VZ |
86 | parent->AddChild(this); |
87 | ||
88 | m_windowId = id == -1 ? NewControlId() : id; | |
ed791986 | 89 | |
b0766406 JS |
90 | DWORD wstyle = WS_CHILD | WS_VISIBLE; |
91 | ||
92 | if ( style & wxCLIP_SIBLINGS ) | |
93 | wstyle |= WS_CLIPSIBLINGS; | |
94 | ||
43b5058d VZ |
95 | // setting SBARS_SIZEGRIP is perfectly useless: it's always on by default |
96 | // (at least in the version of comctl32.dll I'm using), and the only way to | |
97 | // turn it off is to use CCS_TOP style - as we position the status bar | |
98 | // manually anyhow (see DoMoveWindow), use CCS_TOP style if wxST_SIZEGRIP | |
99 | // is not given | |
100 | if ( !(style & wxST_SIZEGRIP) ) | |
101 | { | |
102 | wstyle |= CCS_TOP; | |
103 | } | |
104 | else | |
105 | { | |
106 | // may be some versions of comctl32.dll do need it - anyhow, it won't | |
107 | // do any harm | |
ed791986 | 108 | wstyle |= SBARS_SIZEGRIP; |
43b5058d | 109 | } |
ed791986 VZ |
110 | |
111 | m_hWnd = (WXHWND)CreateStatusWindow(wstyle, | |
112 | wxEmptyString, | |
113 | GetHwndOf(parent), | |
114 | m_windowId); | |
115 | if ( m_hWnd == 0 ) | |
116 | { | |
117 | wxLogSysError(_("Failed to create a status bar.")); | |
118 | ||
119 | return FALSE; | |
120 | } | |
2bda0e17 | 121 | |
c6e7d14f | 122 | SetFieldsCount(1); |
b3d008db | 123 | SubclassWin(m_hWnd); |
2bda0e17 | 124 | |
ed791986 VZ |
125 | return TRUE; |
126 | } | |
2bda0e17 | 127 | |
ed791986 VZ |
128 | wxStatusBar95::~wxStatusBar95() |
129 | { | |
130 | delete [] m_statusWidths; | |
2bda0e17 KB |
131 | } |
132 | ||
8b9518ee | 133 | void wxStatusBar95::CopyFieldsWidth(const int widths[]) |
2bda0e17 | 134 | { |
b3d008db VZ |
135 | if (widths && !m_statusWidths) |
136 | m_statusWidths = new int[m_nFields]; | |
137 | ||
138 | if ( widths != NULL ) | |
139 | { | |
140 | for ( int i = 0; i < m_nFields; i++ ) | |
141 | m_statusWidths[i] = widths[i]; | |
142 | } | |
143 | else // no widths | |
144 | { | |
145 | delete [] m_statusWidths; | |
146 | m_statusWidths = NULL; | |
147 | } | |
2bda0e17 KB |
148 | } |
149 | ||
790ad94f | 150 | void wxStatusBar95::SetFieldsCount(int nFields, const int *widths) |
2bda0e17 | 151 | { |
f6bcfd97 BP |
152 | // this is a Windows limitation |
153 | wxASSERT_MSG( (nFields > 0) && (nFields < 255), _T("too many fields") ); | |
2bda0e17 | 154 | |
f6bcfd97 | 155 | m_nFields = nFields; |
2bda0e17 | 156 | |
f6bcfd97 BP |
157 | CopyFieldsWidth(widths); |
158 | SetFieldsWidth(); | |
2bda0e17 KB |
159 | } |
160 | ||
3ba55e66 | 161 | void wxStatusBar95::SetStatusWidths(int WXUNUSED_UNLESS_DEBUG(n), const int widths[]) |
2bda0e17 | 162 | { |
f6bcfd97 | 163 | wxASSERT_MSG( n == m_nFields, _T("field number mismatch") ); |
2bda0e17 | 164 | |
f6bcfd97 BP |
165 | CopyFieldsWidth(widths); |
166 | SetFieldsWidth(); | |
2bda0e17 KB |
167 | } |
168 | ||
169 | void wxStatusBar95::SetFieldsWidth() | |
170 | { | |
3175c712 VZ |
171 | if ( !m_nFields ) |
172 | return; | |
173 | ||
ed791986 VZ |
174 | int aBorders[3]; |
175 | SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders); | |
2bda0e17 | 176 | |
ed791986 | 177 | int extraWidth = aBorders[2]; // space between fields |
2bda0e17 | 178 | |
ed791986 | 179 | int *pWidths = new int[m_nFields]; |
2bda0e17 | 180 | |
ed791986 VZ |
181 | int nWindowWidth, y; |
182 | GetClientSize(&nWindowWidth, &y); | |
2bda0e17 | 183 | |
ed791986 VZ |
184 | if ( m_statusWidths == NULL ) { |
185 | // default: all fields have the same width | |
186 | int nWidth = nWindowWidth / m_nFields; | |
187 | for ( int i = 0; i < m_nFields; i++ ) | |
188 | pWidths[i] = (i + 1) * nWidth; | |
2bda0e17 | 189 | } |
ed791986 VZ |
190 | else { |
191 | // -1 doesn't mean the same thing for wxWindows and Win32, recalc | |
192 | int nTotalWidth = 0, | |
193 | nVarCount = 0, | |
194 | i; | |
195 | for ( i = 0; i < m_nFields; i++ ) { | |
196 | if ( m_statusWidths[i] == -1 ) | |
197 | nVarCount++; | |
198 | else | |
199 | nTotalWidth += m_statusWidths[i] + extraWidth; | |
200 | } | |
201 | ||
202 | if ( nVarCount == 0 ) { | |
203 | wxFAIL_MSG( _T("at least one field must be of variable width") ); | |
204 | ||
205 | nVarCount++; | |
206 | } | |
207 | ||
208 | int nVarWidth = (nWindowWidth - nTotalWidth) / nVarCount; | |
209 | ||
210 | // do fill the array | |
211 | int nCurPos = 0; | |
212 | for ( i = 0; i < m_nFields; i++ ) { | |
213 | if ( m_statusWidths[i] == -1 ) | |
214 | nCurPos += nVarWidth; | |
215 | else | |
216 | nCurPos += m_statusWidths[i] + extraWidth; | |
217 | pWidths[i] = nCurPos; | |
218 | } | |
2bda0e17 | 219 | } |
2bda0e17 | 220 | |
ed791986 VZ |
221 | if ( !StatusBar_SetParts(GetHwnd(), m_nFields, pWidths) ) { |
222 | wxLogLastError(wxT("StatusBar_SetParts")); | |
223 | } | |
2bda0e17 | 224 | |
ed791986 | 225 | delete [] pWidths; |
2bda0e17 KB |
226 | } |
227 | ||
debe6624 | 228 | void wxStatusBar95::SetStatusText(const wxString& strText, int nField) |
2bda0e17 | 229 | { |
ed791986 VZ |
230 | wxCHECK_RET( (nField >= 0) && (nField < m_nFields), |
231 | _T("invalid statusbar field index") ); | |
232 | ||
b3d008db VZ |
233 | if ( !StatusBar_SetText(GetHwnd(), nField, strText) ) |
234 | { | |
235 | wxLogLastError(wxT("StatusBar_SetText")); | |
236 | } | |
2bda0e17 KB |
237 | } |
238 | ||
239 | wxString wxStatusBar95::GetStatusText(int nField) const | |
240 | { | |
ed791986 VZ |
241 | wxCHECK_MSG( (nField >= 0) && (nField < m_nFields), wxEmptyString, |
242 | _T("invalid statusbar field index") ); | |
2bda0e17 | 243 | |
b3d008db VZ |
244 | wxString str; |
245 | int len = StatusBar_GetTextLen(GetHwnd(), nField); | |
246 | if ( len > 0 ) | |
247 | { | |
248 | StatusBar_GetText(GetHwnd(), nField, str.GetWriteBuf(len)); | |
249 | str.UngetWriteBuf(); | |
250 | } | |
251 | ||
252 | return str; | |
2bda0e17 KB |
253 | } |
254 | ||
ed791986 VZ |
255 | int wxStatusBar95::GetBorderX() const |
256 | { | |
257 | int aBorders[3]; | |
258 | SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders); | |
259 | ||
260 | return aBorders[0]; | |
261 | } | |
262 | ||
263 | int wxStatusBar95::GetBorderY() const | |
264 | { | |
265 | int aBorders[3]; | |
266 | SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders); | |
267 | ||
268 | return aBorders[1]; | |
269 | } | |
270 | ||
271 | void wxStatusBar95::SetMinHeight(int height) | |
272 | { | |
273 | SendMessage(GetHwnd(), SB_SETMINHEIGHT, height + 2*GetBorderY(), 0); | |
274 | ||
275 | // have to send a (dummy) WM_SIZE to redraw it now | |
276 | SendMessage(GetHwnd(), WM_SIZE, 0, 0); | |
277 | } | |
278 | ||
279 | bool wxStatusBar95::GetFieldRect(int i, wxRect& rect) const | |
280 | { | |
281 | wxCHECK_MSG( (i >= 0) && (i < m_nFields), FALSE, | |
282 | _T("invalid statusbar field index") ); | |
283 | ||
284 | RECT r; | |
285 | if ( !::SendMessage(GetHwnd(), SB_GETRECT, i, (LPARAM)&r) ) | |
286 | { | |
f6bcfd97 | 287 | wxLogLastError(wxT("SendMessage(SB_GETRECT)")); |
ed791986 VZ |
288 | } |
289 | ||
290 | wxCopyRECTToRect(r, rect); | |
291 | ||
292 | return TRUE; | |
293 | } | |
294 | ||
cbc66a27 | 295 | void wxStatusBar95::DoMoveWindow(int x, int y, int width, int height) |
2bda0e17 | 296 | { |
43b5058d VZ |
297 | // the status bar wnd proc must be forwarded the WM_SIZE message whenever |
298 | // the stat bar position/size is changed because it normally positions the | |
299 | // control itself along bottom or top side of the parent window - failing | |
300 | // to do so will result in nasty visual effects | |
301 | FORWARD_WM_SIZE(GetHwnd(), SIZE_RESTORED, x, y, SendMessage); | |
302 | ||
303 | // but now, when the standard status bar wnd proc did all it wanted to do, | |
304 | // move the status bar to its correct location - usually this call may be | |
305 | // omitted because for normal status bars (positioned along the bottom | |
306 | // edge) the position is already set correctly, but if the user wants to | |
307 | // position them in some exotic location, this is really needed | |
308 | wxWindow::DoMoveWindow(x, y, width, height); | |
309 | ||
310 | // adjust fields widths to the new size | |
311 | SetFieldsWidth(); | |
dafa4925 VS |
312 | |
313 | // we have to trigger wxSizeEvent if there are children window in status | |
314 | // bar because GetFieldRect returned incorrect (not updated) values up to | |
315 | // here, which almost certainly resulted in incorrectly redrawn statusbar | |
316 | if ( m_children.GetCount() > 0 ) | |
317 | { | |
318 | wxSizeEvent event(GetClientSize(), m_windowId); | |
319 | event.SetEventObject(this); | |
320 | GetEventHandler()->ProcessEvent(event); | |
321 | } | |
2bda0e17 KB |
322 | } |
323 | ||
ed791986 | 324 | #endif // __WIN95__ && wxUSE_NATIVE_STATUSBAR |
ba681060 | 325 |