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