]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/msw/statbr95.cpp
Improved selection mode handling in wxGrid::SelectBlock
[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(__GNUWIN32_OLD__) || defined(__TWIN32__))
40 #include <commctrl.h>
41#endif
42
43// ----------------------------------------------------------------------------
44// wxWindows macros
45// ----------------------------------------------------------------------------
46
47IMPLEMENT_DYNAMIC_CLASS(wxStatusBar95, wxWindow);
48IMPLEMENT_DYNAMIC_CLASS(wxStatusBar, wxStatusBar95)
49
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)
56#define StatusBar_SetText(h, n, t) SendMessage(h, SB_SETTEXT, (WPARAM)n, (LPARAM)(LPCTSTR)t)
57#define StatusBar_GetTextLen(h, n) LOWORD(SendMessage(h, SB_GETTEXTLENGTH, (WPARAM)n, 0))
58#define StatusBar_GetText(h, n, s) LOWORD(SendMessage(h, SB_GETTEXT, (WPARAM)n, (LPARAM)(LPTSTR)s))
59
60// ----------------------------------------------------------------------------
61//
62// ----------------------------------------------------------------------------
63
64// static WNDPROC gs_wndprocStatBar = NULL;
65static WXFARPROC gs_wndprocStatBar = (WXFARPROC) NULL;
66
67LRESULT APIENTRY wxStatusBarProc(HWND hwnd,
68 UINT message,
69 WPARAM wParam,
70 LPARAM lParam)
71{
72 if ( message == WM_COMMAND )
73 {
74 wxStatusBar95 *sb = (wxStatusBar95 *)GetWindowLong(hwnd, GWL_USERDATA);
75 sb->MSWWindowProc(message, wParam, lParam);
76 }
77
78 return ::CallWindowProc(CASTWNDPROC gs_wndprocStatBar, hwnd, message, wParam, lParam);
79}
80
81// ============================================================================
82// implementation
83// ============================================================================
84
85// ----------------------------------------------------------------------------
86// wxStatusBar95 class
87// ----------------------------------------------------------------------------
88
89wxStatusBar95::wxStatusBar95()
90{
91 SetParent(NULL);
92 m_hWnd = 0;
93 m_windowId = 0;
94}
95
96bool wxStatusBar95::Create(wxWindow *parent,
97 wxWindowID id,
98 long style,
99 const wxString& name)
100{
101 wxCHECK_MSG( parent, FALSE, wxT("status bar must have a parent") );
102
103 SetName(name);
104 SetWindowStyleFlag(style);
105 SetParent(parent);
106
107 parent->AddChild(this);
108
109 m_windowId = id == -1 ? NewControlId() : id;
110
111 DWORD wstyle = WS_CHILD | WS_VISIBLE;
112 if ( style & wxST_SIZEGRIP )
113 wstyle |= SBARS_SIZEGRIP;
114
115 m_hWnd = (WXHWND)CreateStatusWindow(wstyle,
116 wxEmptyString,
117 GetHwndOf(parent),
118 m_windowId);
119 if ( m_hWnd == 0 )
120 {
121 wxLogSysError(_("Failed to create a status bar."));
122
123 return FALSE;
124 }
125
126 SetFieldsCount(1);
127
128 // we can't subclass this window as usual because the status bar window
129 // proc processes WM_SIZE and WM_PAINT specially
130 // SubclassWin(m_hWnd);
131
132 // but we want to process the messages from it still, so do custom
133 // subclassing here
134 gs_wndprocStatBar = (WXFARPROC)GetWindowLong(GetHwnd(), GWL_WNDPROC);
135 SetWindowLong(GetHwnd(), GWL_WNDPROC, (LONG)wxStatusBarProc);
136 SetWindowLong(GetHwnd(), GWL_USERDATA, (LONG)this);
137
138 return TRUE;
139}
140
141wxStatusBar95::~wxStatusBar95()
142{
143 delete [] m_statusWidths;
144}
145
146void wxStatusBar95::CopyFieldsWidth(const int widths[])
147{
148 if (widths && !m_statusWidths)
149 m_statusWidths = new int[m_nFields];
150
151 if ( widths != NULL ) {
152 for ( int i = 0; i < m_nFields; i++ )
153 m_statusWidths[i] = widths[i];
154 }
155 else {
156 delete [] m_statusWidths;
157 m_statusWidths = NULL;
158 }
159}
160
161void wxStatusBar95::SetFieldsCount(int nFields, const int *widths)
162{
163 // this is Windows limitation
164 wxASSERT_MSG( (nFields > 0) && (nFields < 255), _T("too many fields") );
165
166 m_nFields = nFields;
167
168 CopyFieldsWidth(widths);
169 SetFieldsWidth();
170}
171
172void wxStatusBar95::SetStatusWidths(int n, const int widths[])
173{
174 wxASSERT_MSG( n == m_nFields, _T("field number mismatch") );
175
176 CopyFieldsWidth(widths);
177 SetFieldsWidth();
178}
179
180void wxStatusBar95::SetFieldsWidth()
181{
182 if ( !m_nFields )
183 return;
184
185 int aBorders[3];
186 SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders);
187
188 int extraWidth = aBorders[2]; // space between fields
189
190 int *pWidths = new int[m_nFields];
191
192 int nWindowWidth, y;
193 GetClientSize(&nWindowWidth, &y);
194
195 if ( m_statusWidths == NULL ) {
196 // default: all fields have the same width
197 int nWidth = nWindowWidth / m_nFields;
198 for ( int i = 0; i < m_nFields; i++ )
199 pWidths[i] = (i + 1) * nWidth;
200 }
201 else {
202 // -1 doesn't mean the same thing for wxWindows and Win32, recalc
203 int nTotalWidth = 0,
204 nVarCount = 0,
205 i;
206 for ( i = 0; i < m_nFields; i++ ) {
207 if ( m_statusWidths[i] == -1 )
208 nVarCount++;
209 else
210 nTotalWidth += m_statusWidths[i] + extraWidth;
211 }
212
213 if ( nVarCount == 0 ) {
214 wxFAIL_MSG( _T("at least one field must be of variable width") );
215
216 nVarCount++;
217 }
218
219 int nVarWidth = (nWindowWidth - nTotalWidth) / nVarCount;
220
221 // do fill the array
222 int nCurPos = 0;
223 for ( i = 0; i < m_nFields; i++ ) {
224 if ( m_statusWidths[i] == -1 )
225 nCurPos += nVarWidth;
226 else
227 nCurPos += m_statusWidths[i] + extraWidth;
228 pWidths[i] = nCurPos;
229 }
230 }
231
232 if ( !StatusBar_SetParts(GetHwnd(), m_nFields, pWidths) ) {
233 wxLogLastError(wxT("StatusBar_SetParts"));
234 }
235
236 delete [] pWidths;
237}
238
239void wxStatusBar95::SetStatusText(const wxString& strText, int nField)
240{
241 wxCHECK_RET( (nField >= 0) && (nField < m_nFields),
242 _T("invalid statusbar field index") );
243
244 if ( !StatusBar_SetText(GetHwnd(), nField, strText) ) {
245 wxLogLastError(wxT("StatusBar_SetText"));
246 }
247}
248
249wxString wxStatusBar95::GetStatusText(int nField) const
250{
251 wxCHECK_MSG( (nField >= 0) && (nField < m_nFields), wxEmptyString,
252 _T("invalid statusbar field index") );
253
254 wxString str;
255 int len = StatusBar_GetTextLen(GetHwnd(), nField);
256 if (len > 0)
257 {
258 StatusBar_GetText(GetHwnd(), nField, str.GetWriteBuf(len));
259 str.UngetWriteBuf();
260 }
261 return str;
262}
263
264int wxStatusBar95::GetBorderX() const
265{
266 int aBorders[3];
267 SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders);
268
269 return aBorders[0];
270}
271
272int wxStatusBar95::GetBorderY() const
273{
274 int aBorders[3];
275 SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)aBorders);
276
277 return aBorders[1];
278}
279
280void wxStatusBar95::SetMinHeight(int height)
281{
282 SendMessage(GetHwnd(), SB_SETMINHEIGHT, height + 2*GetBorderY(), 0);
283
284 // have to send a (dummy) WM_SIZE to redraw it now
285 SendMessage(GetHwnd(), WM_SIZE, 0, 0);
286}
287
288bool wxStatusBar95::GetFieldRect(int i, wxRect& rect) const
289{
290 wxCHECK_MSG( (i >= 0) && (i < m_nFields), FALSE,
291 _T("invalid statusbar field index") );
292
293 RECT r;
294 if ( !::SendMessage(GetHwnd(), SB_GETRECT, i, (LPARAM)&r) )
295 {
296 wxLogLastError("SendMessage(SB_GETRECT)");
297 }
298
299 wxCopyRECTToRect(r, rect);
300
301 return TRUE;
302}
303
304void wxStatusBar95::DoMoveWindow(int x, int y, int width, int height)
305{
306 FORWARD_WM_SIZE(GetHwnd(), SIZE_RESTORED, x, y, SendMessage);
307
308 // adjust fields widths to the new size
309 SetFieldsWidth();
310}
311
312#endif // __WIN95__ && wxUSE_NATIVE_STATUSBAR
313