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