]>
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 | |
c42404a5 VZ |
39 | #if !(defined(__GNUWIN32_OLD__) || defined(__TWIN32__)) |
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 | |
ed791986 VZ |
60 | // ---------------------------------------------------------------------------- |
61 | // | |
62 | // ---------------------------------------------------------------------------- | |
63 | ||
457e6c54 JS |
64 | // static WNDPROC gs_wndprocStatBar = NULL; |
65 | static WXFARPROC gs_wndprocStatBar = (WXFARPROC) NULL; | |
ed791986 VZ |
66 | |
67 | LRESULT APIENTRY wxStatusBarProc(HWND hwnd, | |
68 | UINT message, | |
69 | WPARAM wParam, | |
70 | LPARAM lParam) | |
71 | { | |
bae41109 RD |
72 | switch (message) { |
73 | case WM_COMMAND: | |
74 | case WM_SIZE: | |
75 | case WM_MOVE: | |
76 | case WM_MOUSEMOVE: | |
bae41109 RD |
77 | case WM_LBUTTONUP: |
78 | case WM_LBUTTONDBLCLK: | |
79 | case WM_RBUTTONDOWN: | |
80 | case WM_RBUTTONUP: | |
81 | case WM_RBUTTONDBLCLK: | |
82 | case WM_MBUTTONDOWN: | |
83 | case WM_MBUTTONUP: | |
84 | case WM_MBUTTONDBLCLK: | |
85 | wxStatusBar95 *sb = (wxStatusBar95 *)GetWindowLong(hwnd, GWL_USERDATA); | |
86 | sb->MSWWindowProc(message, wParam, lParam); | |
87 | break; | |
ed791986 VZ |
88 | } |
89 | ||
66e33344 | 90 | return ::CallWindowProc(CASTWNDPROC gs_wndprocStatBar, hwnd, message, wParam, lParam); |
ed791986 | 91 | } |
2bda0e17 KB |
92 | |
93 | // ============================================================================ | |
94 | // implementation | |
95 | // ============================================================================ | |
96 | ||
97 | // ---------------------------------------------------------------------------- | |
98 | // wxStatusBar95 class | |
99 | // ---------------------------------------------------------------------------- | |
100 | ||
101 | wxStatusBar95::wxStatusBar95() | |
102 | { | |
103 | SetParent(NULL); | |
104 | m_hWnd = 0; | |
105 | m_windowId = 0; | |
106 | } | |
107 | ||
ed791986 VZ |
108 | bool wxStatusBar95::Create(wxWindow *parent, |
109 | wxWindowID id, | |
110 | long style, | |
111 | const wxString& name) | |
2bda0e17 | 112 | { |
cbc66a27 VZ |
113 | wxCHECK_MSG( parent, FALSE, wxT("status bar must have a parent") ); |
114 | ||
ed791986 | 115 | SetName(name); |
cbc66a27 | 116 | SetWindowStyleFlag(style); |
ed791986 VZ |
117 | SetParent(parent); |
118 | ||
cbc66a27 VZ |
119 | parent->AddChild(this); |
120 | ||
121 | m_windowId = id == -1 ? NewControlId() : id; | |
ed791986 VZ |
122 | |
123 | DWORD wstyle = WS_CHILD | WS_VISIBLE; | |
43b5058d VZ |
124 | |
125 | // setting SBARS_SIZEGRIP is perfectly useless: it's always on by default | |
126 | // (at least in the version of comctl32.dll I'm using), and the only way to | |
127 | // turn it off is to use CCS_TOP style - as we position the status bar | |
128 | // manually anyhow (see DoMoveWindow), use CCS_TOP style if wxST_SIZEGRIP | |
129 | // is not given | |
130 | if ( !(style & wxST_SIZEGRIP) ) | |
131 | { | |
132 | wstyle |= CCS_TOP; | |
133 | } | |
134 | else | |
135 | { | |
136 | // may be some versions of comctl32.dll do need it - anyhow, it won't | |
137 | // do any harm | |
ed791986 | 138 | wstyle |= SBARS_SIZEGRIP; |
43b5058d | 139 | } |
ed791986 VZ |
140 | |
141 | m_hWnd = (WXHWND)CreateStatusWindow(wstyle, | |
142 | wxEmptyString, | |
143 | GetHwndOf(parent), | |
144 | m_windowId); | |
145 | if ( m_hWnd == 0 ) | |
146 | { | |
147 | wxLogSysError(_("Failed to create a status bar.")); | |
148 | ||
149 | return FALSE; | |
150 | } | |
2bda0e17 | 151 | |
c6e7d14f RD |
152 | SetFieldsCount(1); |
153 | ||
cbc66a27 VZ |
154 | // we can't subclass this window as usual because the status bar window |
155 | // proc processes WM_SIZE and WM_PAINT specially | |
ed791986 VZ |
156 | // SubclassWin(m_hWnd); |
157 | ||
cbc66a27 VZ |
158 | // but we want to process the messages from it still, so do custom |
159 | // subclassing here | |
457e6c54 | 160 | gs_wndprocStatBar = (WXFARPROC)GetWindowLong(GetHwnd(), GWL_WNDPROC); |
ed791986 VZ |
161 | SetWindowLong(GetHwnd(), GWL_WNDPROC, (LONG)wxStatusBarProc); |
162 | SetWindowLong(GetHwnd(), GWL_USERDATA, (LONG)this); | |
2bda0e17 | 163 | |
ed791986 VZ |
164 | return TRUE; |
165 | } | |
2bda0e17 | 166 | |
ed791986 VZ |
167 | wxStatusBar95::~wxStatusBar95() |
168 | { | |
169 | delete [] m_statusWidths; | |
2bda0e17 KB |
170 | } |
171 | ||
8b9518ee | 172 | void wxStatusBar95::CopyFieldsWidth(const int widths[]) |
2bda0e17 KB |
173 | { |
174 | if (widths && !m_statusWidths) | |
175 | m_statusWidths = new int[m_nFields]; | |
176 | ||
177 | if ( widths != NULL ) { | |
178 | for ( int i = 0; i < m_nFields; i++ ) | |
179 | m_statusWidths[i] = widths[i]; | |
180 | } | |
181 | else { | |
182 | delete [] m_statusWidths; | |
183 | m_statusWidths = NULL; | |
184 | } | |
185 | } | |
186 | ||
790ad94f | 187 | void wxStatusBar95::SetFieldsCount(int nFields, const int *widths) |
2bda0e17 | 188 | { |
ed791986 VZ |
189 | // this is Windows limitation |
190 | wxASSERT_MSG( (nFields > 0) && (nFields < 255), _T("too many fields") ); | |
2bda0e17 KB |
191 | |
192 | m_nFields = nFields; | |
193 | ||
194 | CopyFieldsWidth(widths); | |
195 | SetFieldsWidth(); | |
196 | } | |
197 | ||
8b9518ee | 198 | void wxStatusBar95::SetStatusWidths(int n, const int widths[]) |
2bda0e17 | 199 | { |
ed791986 | 200 | wxASSERT_MSG( n == m_nFields, _T("field number mismatch") ); |
2bda0e17 KB |
201 | |
202 | CopyFieldsWidth(widths); | |
203 | SetFieldsWidth(); | |
204 | } | |
205 | ||
206 | void wxStatusBar95::SetFieldsWidth() | |
207 | { | |
3175c712 VZ |
208 | if ( !m_nFields ) |
209 | return; | |
210 | ||
ed791986 VZ |
211 | int aBorders[3]; |
212 | SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders); | |
2bda0e17 | 213 | |
ed791986 | 214 | int extraWidth = aBorders[2]; // space between fields |
2bda0e17 | 215 | |
ed791986 | 216 | int *pWidths = new int[m_nFields]; |
2bda0e17 | 217 | |
ed791986 VZ |
218 | int nWindowWidth, y; |
219 | GetClientSize(&nWindowWidth, &y); | |
2bda0e17 | 220 | |
ed791986 VZ |
221 | if ( m_statusWidths == NULL ) { |
222 | // default: all fields have the same width | |
223 | int nWidth = nWindowWidth / m_nFields; | |
224 | for ( int i = 0; i < m_nFields; i++ ) | |
225 | pWidths[i] = (i + 1) * nWidth; | |
2bda0e17 | 226 | } |
ed791986 VZ |
227 | else { |
228 | // -1 doesn't mean the same thing for wxWindows and Win32, recalc | |
229 | int nTotalWidth = 0, | |
230 | nVarCount = 0, | |
231 | i; | |
232 | for ( i = 0; i < m_nFields; i++ ) { | |
233 | if ( m_statusWidths[i] == -1 ) | |
234 | nVarCount++; | |
235 | else | |
236 | nTotalWidth += m_statusWidths[i] + extraWidth; | |
237 | } | |
238 | ||
239 | if ( nVarCount == 0 ) { | |
240 | wxFAIL_MSG( _T("at least one field must be of variable width") ); | |
241 | ||
242 | nVarCount++; | |
243 | } | |
244 | ||
245 | int nVarWidth = (nWindowWidth - nTotalWidth) / nVarCount; | |
246 | ||
247 | // do fill the array | |
248 | int nCurPos = 0; | |
249 | for ( i = 0; i < m_nFields; i++ ) { | |
250 | if ( m_statusWidths[i] == -1 ) | |
251 | nCurPos += nVarWidth; | |
252 | else | |
253 | nCurPos += m_statusWidths[i] + extraWidth; | |
254 | pWidths[i] = nCurPos; | |
255 | } | |
2bda0e17 | 256 | } |
2bda0e17 | 257 | |
ed791986 VZ |
258 | if ( !StatusBar_SetParts(GetHwnd(), m_nFields, pWidths) ) { |
259 | wxLogLastError(wxT("StatusBar_SetParts")); | |
260 | } | |
2bda0e17 | 261 | |
ed791986 | 262 | delete [] pWidths; |
2bda0e17 KB |
263 | } |
264 | ||
debe6624 | 265 | void wxStatusBar95::SetStatusText(const wxString& strText, int nField) |
2bda0e17 | 266 | { |
ed791986 VZ |
267 | wxCHECK_RET( (nField >= 0) && (nField < m_nFields), |
268 | _T("invalid statusbar field index") ); | |
269 | ||
270 | if ( !StatusBar_SetText(GetHwnd(), nField, strText) ) { | |
223d09f6 | 271 | wxLogLastError(wxT("StatusBar_SetText")); |
2bda0e17 KB |
272 | } |
273 | } | |
274 | ||
275 | wxString wxStatusBar95::GetStatusText(int nField) const | |
276 | { | |
ed791986 VZ |
277 | wxCHECK_MSG( (nField >= 0) && (nField < m_nFields), wxEmptyString, |
278 | _T("invalid statusbar field index") ); | |
2bda0e17 | 279 | |
ed791986 VZ |
280 | wxString str; |
281 | int len = StatusBar_GetTextLen(GetHwnd(), nField); | |
b7346a70 JS |
282 | if (len > 0) |
283 | { | |
ed791986 VZ |
284 | StatusBar_GetText(GetHwnd(), nField, str.GetWriteBuf(len)); |
285 | str.UngetWriteBuf(); | |
b7346a70 | 286 | } |
2bda0e17 KB |
287 | return str; |
288 | } | |
289 | ||
ed791986 VZ |
290 | int wxStatusBar95::GetBorderX() const |
291 | { | |
292 | int aBorders[3]; | |
293 | SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders); | |
294 | ||
295 | return aBorders[0]; | |
296 | } | |
297 | ||
298 | int wxStatusBar95::GetBorderY() const | |
299 | { | |
300 | int aBorders[3]; | |
301 | SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders); | |
302 | ||
303 | return aBorders[1]; | |
304 | } | |
305 | ||
306 | void wxStatusBar95::SetMinHeight(int height) | |
307 | { | |
308 | SendMessage(GetHwnd(), SB_SETMINHEIGHT, height + 2*GetBorderY(), 0); | |
309 | ||
310 | // have to send a (dummy) WM_SIZE to redraw it now | |
311 | SendMessage(GetHwnd(), WM_SIZE, 0, 0); | |
312 | } | |
313 | ||
314 | bool wxStatusBar95::GetFieldRect(int i, wxRect& rect) const | |
315 | { | |
316 | wxCHECK_MSG( (i >= 0) && (i < m_nFields), FALSE, | |
317 | _T("invalid statusbar field index") ); | |
318 | ||
319 | RECT r; | |
320 | if ( !::SendMessage(GetHwnd(), SB_GETRECT, i, (LPARAM)&r) ) | |
321 | { | |
322 | wxLogLastError("SendMessage(SB_GETRECT)"); | |
323 | } | |
324 | ||
325 | wxCopyRECTToRect(r, rect); | |
326 | ||
327 | return TRUE; | |
328 | } | |
329 | ||
cbc66a27 | 330 | void wxStatusBar95::DoMoveWindow(int x, int y, int width, int height) |
2bda0e17 | 331 | { |
43b5058d VZ |
332 | // the status bar wnd proc must be forwarded the WM_SIZE message whenever |
333 | // the stat bar position/size is changed because it normally positions the | |
334 | // control itself along bottom or top side of the parent window - failing | |
335 | // to do so will result in nasty visual effects | |
336 | FORWARD_WM_SIZE(GetHwnd(), SIZE_RESTORED, x, y, SendMessage); | |
337 | ||
338 | // but now, when the standard status bar wnd proc did all it wanted to do, | |
339 | // move the status bar to its correct location - usually this call may be | |
340 | // omitted because for normal status bars (positioned along the bottom | |
341 | // edge) the position is already set correctly, but if the user wants to | |
342 | // position them in some exotic location, this is really needed | |
343 | wxWindow::DoMoveWindow(x, y, width, height); | |
344 | ||
345 | // adjust fields widths to the new size | |
346 | SetFieldsWidth(); | |
2bda0e17 KB |
347 | } |
348 | ||
ed791986 | 349 | #endif // __WIN95__ && wxUSE_NATIVE_STATUSBAR |
ba681060 | 350 |