]> git.saurik.com Git - wxWidgets.git/blame - src/msw/statbr95.cpp
wxWindow::FindFocus() doesn't exist in wxGTK - #ifdef'd out
[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
50#if USE_NATIVE_STATUSBAR
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
98 m_windowId = id == -1 ? NewControlId() : id;
99
100 DWORD wstyle = WS_CHILD | WS_VISIBLE;
1c089c47 101 if ( style & wxST_SIZEGRIP )
2bda0e17
KB
102 wstyle |= SBARS_SIZEGRIP;
103
104 m_hWnd = (WXHWND)CreateStatusWindow(wstyle,
105 "",
106 (HWND)parent->GetHWND(),
107 m_windowId);
108 if ( m_hWnd == 0 ) {
109 wxLogSysError("can't create status bar window");
110 return FALSE;
111 }
112
113 // this doesn't work: display problems (white 1-2 pixel borders...)
114 // SubclassWin(m_hWnd);
115
116 return TRUE;
117}
118
debe6624 119void wxStatusBar95::CopyFieldsWidth(int *widths)
2bda0e17
KB
120{
121 if (widths && !m_statusWidths)
122 m_statusWidths = new int[m_nFields];
123
124 if ( widths != NULL ) {
125 for ( int i = 0; i < m_nFields; i++ )
126 m_statusWidths[i] = widths[i];
127 }
128 else {
129 delete [] m_statusWidths;
130 m_statusWidths = NULL;
131 }
132}
133
debe6624 134void wxStatusBar95::SetFieldsCount(int nFields, int *widths)
2bda0e17
KB
135{
136 wxASSERT( (nFields > 0) && (nFields < 255) );
137
138 m_nFields = nFields;
139
140 CopyFieldsWidth(widths);
141 SetFieldsWidth();
142}
143
debe6624 144void wxStatusBar95::SetStatusWidths(int n, int *widths)
2bda0e17
KB
145{
146 // @@ I don't understand what this function is for...
147 wxASSERT( n == m_nFields );
148
149 CopyFieldsWidth(widths);
150 SetFieldsWidth();
151}
152
153void wxStatusBar95::SetFieldsWidth()
154{
155 int *pWidths = new int[m_nFields];
156
157 int nWindowWidth, y;
158 GetClientSize(&nWindowWidth, &y);
159
160 if ( m_statusWidths == NULL ) {
161 // default: all fields have the same width
162 int nWidth = nWindowWidth / m_nFields;
163 for ( int i = 0; i < m_nFields; i++ )
c1e34828 164 pWidths[i] = (i + 1) * nWidth;
2bda0e17
KB
165 }
166 else {
167 // -1 doesn't mean the same thing for wxWindows and Win32, recalc
168 int nTotalWidth = 0,
169 nVarCount = 0,
170 i;
171 for ( i = 0; i < m_nFields; i++ ) {
172 if ( m_statusWidths[i] == -1 )
173 nVarCount++;
174 else
175 nTotalWidth += m_statusWidths[i];
176 }
177
178 if ( nVarCount == 0 ) {
179 // wrong! at least one field must be of variable width
180 wxFAIL;
181
182 nVarCount++;
183 }
184
185 int nVarWidth = (nWindowWidth - nTotalWidth) / nVarCount;
186
187 // do fill the array
188 int nCurPos = 0;
189 for ( i = 0; i < m_nFields; i++ ) {
190 if ( m_statusWidths[i] == -1 )
191 nCurPos += nVarWidth;
192 else
193 nCurPos += m_statusWidths[i];
194 pWidths[i] = nCurPos;
195 }
196 }
197
198 if ( !StatusBar_SetParts(hwnd, m_nFields, pWidths) ) {
199 wxLogDebug("StatusBar_SetParts failed.");
200 }
201
202 delete [] pWidths;
203}
204
debe6624 205void wxStatusBar95::SetStatusText(const wxString& strText, int nField)
2bda0e17
KB
206{
207 if ( !StatusBar_SetText(hwnd, nField, strText) ) {
208 wxLogDebug("StatusBar_SetText failed");
209 }
210}
211
212wxString wxStatusBar95::GetStatusText(int nField) const
213{
b7346a70 214 wxASSERT( (nField > -1) && (nField < m_nFields) );
2bda0e17 215
b7346a70
JS
216 wxString str("");
217 int len = StatusBar_GetTextLen(hwnd, nField);
218 if (len > 0)
219 {
220 StatusBar_GetText(hwnd, nField, str.GetWriteBuf(len));
221 }
2bda0e17
KB
222 return str;
223}
224
225void wxStatusBar95::OnSize(wxSizeEvent& event)
226{
227 FORWARD_WM_SIZE(hwnd, SIZE_RESTORED, event.GetSize().x, event.GetSize().y,
228 SendMessage);
229
230 // adjust fields widths to the new size
231 SetFieldsWidth();
232}
233
234#endif //USE_NATIVE_STATUSBAR