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