]> git.saurik.com Git - wxWidgets.git/blob - src/msw/statbr95.cpp
VTK wrapper of vtkRenderWindow for wxPython. Tested on MSW so far.
[wxWidgets.git] / src / msw / statbr95.cpp
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 #ifdef __WIN95__
31
32 #include "wx/log.h"
33 #include "wx/generic/statusbr.h"
34 #include "wx/msw/statbr95.h"
35
36 #include "wx/msw/private.h"
37 #include <windowsx.h>
38
39 #if !defined(__GNUWIN32__) || defined(__TWIN32__) || defined(wxUSE_NORLANDER_HEADERS)
40 #include <commctrl.h>
41 #endif
42
43 #if wxUSE_NATIVE_STATUSBAR
44
45 #if !USE_SHARED_LIBRARY
46 IMPLEMENT_DYNAMIC_CLASS(wxStatusBar95, wxStatusBar);
47
48 BEGIN_EVENT_TABLE(wxStatusBar95, wxStatusBar)
49 EVT_SIZE(wxStatusBar95::OnSize)
50 END_EVENT_TABLE()
51 #endif //USE_SHARED_LIBRARY
52
53
54 // ----------------------------------------------------------------------------
55 // macros
56 // ----------------------------------------------------------------------------
57
58 // windowsx.h and commctrl.h don't define those, so we do it here
59 #define StatusBar_SetParts(h, n, w) SendMessage(h, SB_SETPARTS, (WPARAM)n, (LPARAM)w)
60 #define StatusBar_SetText(h, n, t) SendMessage(h, SB_SETTEXT, (WPARAM)n, (LPARAM)(LPCTSTR)t)
61 #define StatusBar_GetTextLen(h, n) LOWORD(SendMessage(h, SB_GETTEXTLENGTH, (WPARAM)n, 0))
62 #define StatusBar_GetText(h, n, s) LOWORD(SendMessage(h, SB_GETTEXT, (WPARAM)n, (LPARAM)(LPTSTR)s))
63
64 #define hwnd ((HWND)m_hWnd)
65
66 // ============================================================================
67 // implementation
68 // ============================================================================
69
70 // ----------------------------------------------------------------------------
71 // wxStatusBar95 class
72 // ----------------------------------------------------------------------------
73
74 wxStatusBar95::wxStatusBar95()
75 {
76 SetParent(NULL);
77 m_hWnd = 0;
78 m_windowId = 0;
79 }
80
81 wxStatusBar95::wxStatusBar95(wxWindow *parent, wxWindowID id, long style)
82 {
83 Create(parent, id, style);
84 }
85
86 bool wxStatusBar95::Create(wxWindow *parent, wxWindowID id, long style)
87 {
88 SetParent(parent);
89
90 if (id == -1)
91 m_windowId = NewControlId();
92 else
93 m_windowId = id;
94
95 DWORD wstyle = WS_CHILD | WS_VISIBLE;
96 if ( style & wxST_SIZEGRIP )
97 wstyle |= SBARS_SIZEGRIP;
98
99 m_hWnd = (WXHWND)CreateStatusWindow(wstyle,
100 wxT(""),
101 (HWND)parent->GetHWND(),
102 m_windowId);
103 if ( m_hWnd == 0 ) {
104 wxLogSysError(wxT("can't create status bar window"));
105 return FALSE;
106 }
107
108 // this doesn't work: display problems (white 1-2 pixel borders...)
109 // SubclassWin(m_hWnd);
110
111 return TRUE;
112 }
113
114 void wxStatusBar95::CopyFieldsWidth(const int widths[])
115 {
116 if (widths && !m_statusWidths)
117 m_statusWidths = new int[m_nFields];
118
119 if ( widths != NULL ) {
120 for ( int i = 0; i < m_nFields; i++ )
121 m_statusWidths[i] = widths[i];
122 }
123 else {
124 delete [] m_statusWidths;
125 m_statusWidths = NULL;
126 }
127 }
128
129 void wxStatusBar95::SetFieldsCount(int nFields, const int widths[])
130 {
131 wxASSERT( (nFields > 0) && (nFields < 255) );
132
133 m_nFields = nFields;
134
135 CopyFieldsWidth(widths);
136 SetFieldsWidth();
137 }
138
139 void wxStatusBar95::SetStatusWidths(int n, const int widths[])
140 {
141 // @@ I don't understand what this function is for...
142 wxASSERT( n == m_nFields );
143
144 CopyFieldsWidth(widths);
145 SetFieldsWidth();
146 }
147
148 void wxStatusBar95::SetFieldsWidth()
149 {
150 if ( !m_nFields )
151 return;
152
153 int *pWidths = new int[m_nFields];
154
155 int nWindowWidth, y;
156 GetClientSize(&nWindowWidth, &y);
157
158 if ( m_statusWidths == NULL ) {
159 // default: all fields have the same width
160 int nWidth = nWindowWidth / m_nFields;
161 for ( int i = 0; i < m_nFields; i++ )
162 pWidths[i] = (i + 1) * nWidth;
163 }
164 else {
165 // -1 doesn't mean the same thing for wxWindows and Win32, recalc
166 int nTotalWidth = 0,
167 nVarCount = 0,
168 i;
169 for ( i = 0; i < m_nFields; i++ ) {
170 if ( m_statusWidths[i] == -1 )
171 nVarCount++;
172 else
173 nTotalWidth += m_statusWidths[i];
174 }
175
176 if ( nVarCount == 0 ) {
177 // wrong! at least one field must be of variable width
178 wxFAIL;
179
180 nVarCount++;
181 }
182
183 int nVarWidth = (nWindowWidth - nTotalWidth) / nVarCount;
184
185 // do fill the array
186 int nCurPos = 0;
187 for ( i = 0; i < m_nFields; i++ ) {
188 if ( m_statusWidths[i] == -1 )
189 nCurPos += nVarWidth;
190 else
191 nCurPos += m_statusWidths[i];
192 pWidths[i] = nCurPos;
193 }
194 }
195
196 if ( !StatusBar_SetParts(hwnd, m_nFields, pWidths) ) {
197 wxLogLastError(wxT("StatusBar_SetParts"));
198 }
199
200 delete [] pWidths;
201 }
202
203 void wxStatusBar95::SetStatusText(const wxString& strText, int nField)
204 {
205 if ( !StatusBar_SetText(hwnd, nField, strText) ) {
206 wxLogLastError(wxT("StatusBar_SetText"));
207 }
208 }
209
210 wxString wxStatusBar95::GetStatusText(int nField) const
211 {
212 wxASSERT( (nField > -1) && (nField < m_nFields) );
213
214 wxString str(wxT(""));
215 int len = StatusBar_GetTextLen(hwnd, nField);
216 if (len > 0)
217 {
218 StatusBar_GetText(hwnd, nField, str.GetWriteBuf(len));
219 str.UngetWriteBuf();
220 }
221 return str;
222 }
223
224 void wxStatusBar95::OnSize(wxSizeEvent& event)
225 {
226 FORWARD_WM_SIZE(hwnd, SIZE_RESTORED, event.GetSize().x, event.GetSize().y,
227 SendMessage);
228
229 // adjust fields widths to the new size
230 SetFieldsWidth();
231 }
232
233 #endif // wxUSE_NATIVE_STATUSBAR
234
235 #else
236 #error "wxStatusBar95 is only available under Windows 95 and later."
237 #endif // __WIN95__
238