]> git.saurik.com Git - wxWidgets.git/blob - src/palmos/statbrpalm.cpp
Close tree edit even if the change is vetoed to be consistent with MSW [patch 1110252]
[wxWidgets.git] / src / palmos / statbrpalm.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/palmos/statbrpalm.cpp
3 // Purpose: Implementation of wxStatusBar for PalmOS
4 // Author: William Osborne - minimal working wxPalmOS port
5 // Modified by: Wlodzimierz ABX Skiba - transition from faked drawing to native statusbar
6 // Created: 10/13/04
7 // RCS-ID: $Id$
8 // Copyright: (c) William Osborne, Wlodzimierz Skiba
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "statusbr.h"
14 #endif
15
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
30 #if wxUSE_NATIVE_STATUSBAR
31
32 #include "wx/intl.h"
33 #include "wx/log.h"
34 #include "wx/statusbr.h"
35
36 // ----------------------------------------------------------------------------
37 // macros
38 // ----------------------------------------------------------------------------
39
40 // ============================================================================
41 // implementation
42 // ============================================================================
43
44 // ----------------------------------------------------------------------------
45 // wxStatusBarPalm class
46 // ----------------------------------------------------------------------------
47
48 wxStatusBarPalm::wxStatusBarPalm()
49 {
50 SetParent(NULL);
51 m_hWnd = 0;
52 m_windowId = 0;
53 }
54
55 bool wxStatusBarPalm::Create(wxWindow *parent,
56 wxWindowID id,
57 long style,
58 const wxString& name)
59 {
60 wxCHECK_MSG( parent, false, wxT("status bar must have a parent") );
61
62 StatusTextBuffer = NULL;
63
64 SetName(name);
65 SetParent(parent);
66 SetId( id == wxID_ANY ? NewControlId() : id );
67
68 parent->AddChild(this);
69
70 SetFieldsCount(1);
71 SubclassWin(m_hWnd);
72
73 return true;
74 }
75
76 wxStatusBarPalm::~wxStatusBarPalm()
77 {
78 Show();
79
80 DeleteStatusBuffer();
81 }
82
83 bool wxStatusBarPalm::IsShown() const
84 {
85 return StatGetAttribute ( statAttrBarVisible , NULL );
86 }
87
88 bool wxStatusBarPalm::Show( bool show )
89 {
90 if(show)
91 {
92 // show it if hidden
93 if(IsShown())
94 return false;
95 status_t rc = StatShow();
96 wxCHECK_MSG( rc == errNone, false, wxT("cannot hide status bar") );
97 }
98 else
99 {
100 // hide it if shown
101 if(!IsShown())
102 return false;
103 status_t rc = StatHide();
104 wxCHECK_MSG( rc == errNone, false, wxT("cannot hide status bar") );
105 }
106 return true;
107 }
108
109 void wxStatusBarPalm::SetFieldsCount(int nFields, const int *widths)
110 {
111 // this is a Windows limitation
112 wxASSERT_MSG( (nFields > 0) && (nFields < 255), _T("too many fields") );
113
114 wxStatusBarBase::SetFieldsCount(nFields, widths);
115
116 SetFieldsWidth();
117 }
118
119 void wxStatusBarPalm::SetStatusWidths(int n, const int widths[])
120 {
121 wxStatusBarBase::SetStatusWidths(n, widths);
122
123 SetFieldsWidth();
124 }
125
126 void wxStatusBarPalm::SetFieldsWidth()
127 {
128 // clear the status bar
129 DeleteStatusBuffer();
130 }
131
132 void wxStatusBarPalm::SetStatusText(const wxString& strText, int nField)
133 {
134 wxCHECK_RET( (nField >= 0) && (nField < m_nFields),
135 _T("invalid statusbar field index") );
136
137 SetStatusBufferText(strText,nField);
138 DrawStatusBar();
139 }
140
141 wxString wxStatusBarPalm::GetStatusText(int nField) const
142 {
143 wxCHECK_MSG( (nField >= 0) && (nField < m_nFields), wxEmptyString,
144 _T("invalid statusbar field index") );
145
146 wxString text;
147 return text;
148 }
149
150 void wxStatusBarPalm::DrawStatusBar()
151 {
152 #if 0
153 int i=0;
154 int leftPos=0;
155 wxArrayInt widthsAbs;
156 wxString text;
157
158 RectangleType EraseRect;
159 EraseRect.topLeft.x=0;
160 EraseRect.topLeft.y=160-FntCharHeight()-1;
161 EraseRect.extent.x=159;
162 EraseRect.extent.y=159;
163 WinEraseRectangle(&EraseRect,0);
164
165 if(m_nFields>0)
166 widthsAbs=CalculateAbsWidths(160 - 2*(m_nFields - 1));
167
168 for(i=0;i<m_nFields;i++)
169 {
170 text=GetStatusBufferText(i);
171 WinDrawTruncChars(text,StrLen(text),leftPos,160-FntCharHeight(),widthsAbs[i]);
172 leftPos+=widthsAbs[i]+2;
173 }
174 WinDrawLine(0,160-FntCharHeight()-1,159,160-FntCharHeight()-1);
175 #endif
176 }
177
178 void wxStatusBarPalm::SetStatusBufferText(const wxString& text, int number)
179 {
180 wxListString* st = GetOrCreateStatusBuffer(number);
181
182 wxString tmp1(text);
183 wxString* tmp = new wxString(tmp1);
184 st->Insert(tmp);
185 }
186
187 wxString wxStatusBarPalm::GetStatusBufferText(int number)
188 {
189 wxListString *st = GetStatusBufferStack(number);
190 if(st==0)
191 return wxEmptyString;
192
193 wxListString::compatibility_iterator top = st->GetFirst();
194 return(*top->GetData());
195 }
196
197 wxListString *wxStatusBarPalm::GetOrCreateStatusBuffer(int i)
198 {
199 if(!StatusTextBuffer)
200 {
201 StatusTextBuffer = new wxListString*[m_nFields];
202
203 size_t j;
204 for(j = 0; j < (size_t)m_nFields; ++j) StatusTextBuffer[j] = 0;
205 }
206
207 if(!StatusTextBuffer[i])
208 {
209 StatusTextBuffer[i] = new wxListString();
210 }
211 else
212 {
213 wxListString *st=StatusTextBuffer[i];
214 wxListString::compatibility_iterator top = st->GetFirst();
215 delete top->GetData();
216 st->Erase(top);
217 delete st;
218
219 StatusTextBuffer[i] = new wxListString();
220 }
221
222 return StatusTextBuffer[i];
223 }
224
225 wxListString *wxStatusBarPalm::GetStatusBufferStack(int i) const
226 {
227 if(!StatusTextBuffer)
228 return 0;
229 return StatusTextBuffer[i];
230 }
231
232 void wxStatusBarPalm::DeleteStatusBuffer()
233 {
234 if(!StatusTextBuffer)
235 {
236 return;
237 }
238
239 for(int i=0;i<m_nFields;i++)
240 {
241 if(StatusTextBuffer[i])
242 {
243 wxListString *st=StatusTextBuffer[i];
244 wxListString::compatibility_iterator top = st->GetFirst();
245 delete top->GetData();
246 st->Erase(top);
247 delete st;
248 StatusTextBuffer[i]=0;
249 }
250 }
251 delete[] m_statusTextStacks;
252 }
253
254 int wxStatusBarPalm::GetBorderX() const
255 {
256 return 0;
257 }
258
259 int wxStatusBarPalm::GetBorderY() const
260 {
261 return 0;
262 }
263
264 void wxStatusBarPalm::SetMinHeight(int height)
265 {
266 }
267
268 bool wxStatusBarPalm::GetFieldRect(int i, wxRect& rect) const
269 {
270 }
271
272 void wxStatusBarPalm::DoMoveWindow(int x, int y, int width, int height)
273 {
274 }
275
276 #endif // wxUSE_NATIVE_STATUSBAR
277