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