]> git.saurik.com Git - wxWidgets.git/blame - src/msw/statbr95.cpp
removed compilation warning about "switch with default but no case" (no
[wxWidgets.git] / src / msw / statbr95.cpp
CommitLineData
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
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20// for compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
27#ifndef WX_PRECOMP
28 #include "wx/setup.h"
29 #include "wx/frame.h"
30 #include "wx/settings.h"
31 #include "wx/dcclient.h"
32#endif
33
34#include "wx/log.h"
35
36#include "wx/generic/statusbr.h"
37#include "wx/msw/statbr95.h"
38
39#include <windows.h>
40#include <windowsx.h>
41
42#ifndef __GNUWIN32__
43#include <commctrl.h>
44#endif
45
46#if USE_NATIVE_STATUSBAR
47
48#if !USE_SHARED_LIBRARY
49 IMPLEMENT_DYNAMIC_CLASS(wxStatusBar95, wxStatusBar);
50
51 BEGIN_EVENT_TABLE(wxStatusBar95, wxStatusBar)
52 EVT_PAINT(wxWindow::OnPaint)
53 EVT_SIZE(wxStatusBar95::OnSize)
54 END_EVENT_TABLE()
55#endif //USE_SHARED_LIBRARY
56
57
58// ----------------------------------------------------------------------------
59// macros
60// ----------------------------------------------------------------------------
61
62// windowsx.h and commctrl.h don't define those, so we do it here
63#define StatusBar_SetParts(h, n, w) SendMessage(h, SB_SETPARTS, (WPARAM)n, (LPARAM)w)
64#define StatusBar_SetText(h, n, t) SendMessage(h, SB_SETTEXT, (WPARAM)n, (LPARAM)(LPCSTR)t)
65#define StatusBar_GetTextLen(h, n) LOWORD(SendMessage(h, SB_GETTEXTLENGTH, (WPARAM)n, 0))
66#define StatusBar_GetText(h, n, s) LOWORD(SendMessage(h, SB_GETTEXT, (WPARAM)n, (LPARAM)(LPSTR)s))
67
68#define hwnd ((HWND)m_hWnd)
69
70// ============================================================================
71// implementation
72// ============================================================================
73
74// ----------------------------------------------------------------------------
75// wxStatusBar95 class
76// ----------------------------------------------------------------------------
77
78wxStatusBar95::wxStatusBar95()
79{
80 SetParent(NULL);
81 m_hWnd = 0;
82 m_windowId = 0;
83}
84
85wxStatusBar95::wxStatusBar95(wxWindow *parent, wxWindowID id, long style)
86{
87 Create(parent, id, style);
88}
89
90bool wxStatusBar95::Create(wxWindow *parent, wxWindowID id, long style)
91{
92 SetParent(parent);
93
94 m_windowId = id == -1 ? NewControlId() : id;
95
96 DWORD wstyle = WS_CHILD | WS_VISIBLE;
97 if ( style & wxSB_SIZEGRIP )
98 wstyle |= SBARS_SIZEGRIP;
99
100 m_hWnd = (WXHWND)CreateStatusWindow(wstyle,
101 "",
102 (HWND)parent->GetHWND(),
103 m_windowId);
104 if ( m_hWnd == 0 ) {
105 wxLogSysError("can't create status bar window");
106 return FALSE;
107 }
108
109 // this doesn't work: display problems (white 1-2 pixel borders...)
110 // SubclassWin(m_hWnd);
111
112 return TRUE;
113}
114
115void wxStatusBar95::CopyFieldsWidth(const int *widths)
116{
117 if (widths && !m_statusWidths)
118 m_statusWidths = new int[m_nFields];
119
120 if ( widths != NULL ) {
121 for ( int i = 0; i < m_nFields; i++ )
122 m_statusWidths[i] = widths[i];
123 }
124 else {
125 delete [] m_statusWidths;
126 m_statusWidths = NULL;
127 }
128}
129
130void wxStatusBar95::SetFieldsCount(int nFields, const int *widths)
131{
132 wxASSERT( (nFields > 0) && (nFields < 255) );
133
134 m_nFields = nFields;
135
136 CopyFieldsWidth(widths);
137 SetFieldsWidth();
138}
139
140void wxStatusBar95::SetStatusWidths(int n, const int *widths)
141{
142 // @@ I don't understand what this function is for...
143 wxASSERT( n == m_nFields );
144
145 CopyFieldsWidth(widths);
146 SetFieldsWidth();
147}
148
149void wxStatusBar95::SetFieldsWidth()
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) * nWindowWidth;
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 wxLogDebug("StatusBar_SetParts failed.");
196 }
197
198 delete [] pWidths;
199}
200
201void wxStatusBar95::SetStatusText(const wxString& strText, const int nField)
202{
203 if ( !StatusBar_SetText(hwnd, nField, strText) ) {
204 wxLogDebug("StatusBar_SetText failed");
205 }
206}
207
208wxString wxStatusBar95::GetStatusText(int nField) const
209{
210 wxASSERT( (nField > 0) && (nField < m_nFields) );
211
212 wxString str;
213 StatusBar_GetText(hwnd, nField,
214 str.GetWriteBuf(StatusBar_GetTextLen(hwnd, nField)));
215 return str;
216}
217
218void wxStatusBar95::OnSize(wxSizeEvent& event)
219{
220 FORWARD_WM_SIZE(hwnd, SIZE_RESTORED, event.GetSize().x, event.GetSize().y,
221 SendMessage);
222
223 // adjust fields widths to the new size
224 SetFieldsWidth();
225}
226
227#endif //USE_NATIVE_STATUSBAR