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