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