]> git.saurik.com Git - wxWidgets.git/blame - src/msw/statbr95.cpp
help search is much faster now (7 times! that's what I call optimization ;-)
[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
65fd5cb0 39#if !defined(__GNUWIN32__) || defined(__TWIN32__) || defined(wxUSE_NORLANDER_HEADERS)
42e69d6b 40#include <commctrl.h>
ce3ed50d
JS
41#endif
42
ba681060 43#if wxUSE_NATIVE_STATUSBAR
2bda0e17 44
2bda0e17
KB
45 IMPLEMENT_DYNAMIC_CLASS(wxStatusBar95, wxStatusBar);
46
47 BEGIN_EVENT_TABLE(wxStatusBar95, wxStatusBar)
2bda0e17
KB
48 EVT_SIZE(wxStatusBar95::OnSize)
49 END_EVENT_TABLE()
2bda0e17
KB
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)
837e5743 58#define StatusBar_SetText(h, n, t) SendMessage(h, SB_SETTEXT, (WPARAM)n, (LPARAM)(LPCTSTR)t)
2bda0e17 59#define StatusBar_GetTextLen(h, n) LOWORD(SendMessage(h, SB_GETTEXTLENGTH, (WPARAM)n, 0))
837e5743 60#define StatusBar_GetText(h, n, s) LOWORD(SendMessage(h, SB_GETTEXT, (WPARAM)n, (LPARAM)(LPTSTR)s))
2bda0e17
KB
61
62#define hwnd ((HWND)m_hWnd)
63
64// ============================================================================
65// implementation
66// ============================================================================
67
68// ----------------------------------------------------------------------------
69// wxStatusBar95 class
70// ----------------------------------------------------------------------------
71
72wxStatusBar95::wxStatusBar95()
73{
74 SetParent(NULL);
75 m_hWnd = 0;
76 m_windowId = 0;
77}
78
79wxStatusBar95::wxStatusBar95(wxWindow *parent, wxWindowID id, long style)
80{
81 Create(parent, id, style);
82}
83
84bool wxStatusBar95::Create(wxWindow *parent, wxWindowID id, long style)
85{
86 SetParent(parent);
87
8b9518ee
JS
88 if (id == -1)
89 m_windowId = NewControlId();
90 else
91 m_windowId = id;
2bda0e17
KB
92
93 DWORD wstyle = WS_CHILD | WS_VISIBLE;
1c089c47 94 if ( style & wxST_SIZEGRIP )
2bda0e17
KB
95 wstyle |= SBARS_SIZEGRIP;
96
97 m_hWnd = (WXHWND)CreateStatusWindow(wstyle,
223d09f6 98 wxT(""),
2bda0e17
KB
99 (HWND)parent->GetHWND(),
100 m_windowId);
101 if ( m_hWnd == 0 ) {
223d09f6 102 wxLogSysError(wxT("can't create status bar window"));
2bda0e17
KB
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
8b9518ee 112void wxStatusBar95::CopyFieldsWidth(const int widths[])
2bda0e17
KB
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
8b9518ee 127void wxStatusBar95::SetFieldsCount(int nFields, const int widths[])
2bda0e17
KB
128{
129 wxASSERT( (nFields > 0) && (nFields < 255) );
130
131 m_nFields = nFields;
132
133 CopyFieldsWidth(widths);
134 SetFieldsWidth();
135}
136
8b9518ee 137void wxStatusBar95::SetStatusWidths(int n, const int widths[])
2bda0e17
KB
138{
139 // @@ I don't understand what this function is for...
140 wxASSERT( n == m_nFields );
141
142 CopyFieldsWidth(widths);
143 SetFieldsWidth();
144}
145
146void wxStatusBar95::SetFieldsWidth()
147{
3175c712
VZ
148 if ( !m_nFields )
149 return;
150
2bda0e17
KB
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++ )
c1e34828 160 pWidths[i] = (i + 1) * nWidth;
2bda0e17
KB
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) ) {
223d09f6 195 wxLogLastError(wxT("StatusBar_SetParts"));
2bda0e17
KB
196 }
197
198 delete [] pWidths;
199}
200
debe6624 201void wxStatusBar95::SetStatusText(const wxString& strText, int nField)
2bda0e17
KB
202{
203 if ( !StatusBar_SetText(hwnd, nField, strText) ) {
223d09f6 204 wxLogLastError(wxT("StatusBar_SetText"));
2bda0e17
KB
205 }
206}
207
208wxString wxStatusBar95::GetStatusText(int nField) const
209{
b7346a70 210 wxASSERT( (nField > -1) && (nField < m_nFields) );
2bda0e17 211
223d09f6 212 wxString str(wxT(""));
b7346a70
JS
213 int len = StatusBar_GetTextLen(hwnd, nField);
214 if (len > 0)
215 {
216 StatusBar_GetText(hwnd, nField, str.GetWriteBuf(len));
8b9518ee 217 str.UngetWriteBuf();
b7346a70 218 }
2bda0e17
KB
219 return str;
220}
221
222void 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
ba681060
VZ
231#endif // wxUSE_NATIVE_STATUSBAR
232
233#else
234 #error "wxStatusBar95 is only available under Windows 95 and later."
235#endif // __WIN95__
236