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