]> git.saurik.com Git - wxWidgets.git/blob - src/palmos/statbrpalm.cpp
added wxIsSameDouble() which wraps double comparison in a pragmas disabling icc warni...
[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 // for compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #ifndef WX_PRECOMP
20 #include "wx/setup.h"
21 #include "wx/frame.h"
22 #include "wx/settings.h"
23 #include "wx/dcclient.h"
24 #endif
25
26 #if wxUSE_NATIVE_STATUSBAR
27
28 #include "wx/intl.h"
29 #include "wx/log.h"
30 #include "wx/statusbr.h"
31
32 #include <StatusBar.h>
33
34 // ----------------------------------------------------------------------------
35 // macros
36 // ----------------------------------------------------------------------------
37
38 // ============================================================================
39 // implementation
40 // ============================================================================
41
42 // ----------------------------------------------------------------------------
43 // wxStatusBarPalm class
44 // ----------------------------------------------------------------------------
45
46 wxStatusBarPalm::wxStatusBarPalm()
47 {
48 SetParent(NULL);
49 }
50
51 bool wxStatusBarPalm::Create(wxWindow *parent,
52 wxWindowID id,
53 long style,
54 const wxString& name)
55 {
56 wxCHECK_MSG( parent, false, wxT("status bar must have a parent") );
57
58 StatusTextBuffer = NULL;
59
60 SetName(name);
61 SetParent(parent);
62 SetId( id == wxID_ANY ? NewControlId() : id );
63
64 parent->AddChild(this);
65
66 SetFieldsCount(1);
67
68 return true;
69 }
70
71 wxStatusBarPalm::~wxStatusBarPalm()
72 {
73 Show();
74
75 DeleteStatusBuffer();
76 }
77
78 bool wxStatusBarPalm::IsShown() const
79 {
80 return StatGetAttribute ( statAttrBarVisible , NULL );
81 }
82
83 bool wxStatusBarPalm::Show( bool show )
84 {
85 if(show)
86 {
87 // show it if hidden
88 if(IsShown())
89 return false;
90 status_t rc = StatShow();
91 wxCHECK_MSG( rc == errNone, false, wxT("cannot hide status bar") );
92 }
93 else
94 {
95 // hide it if shown
96 if(!IsShown())
97 return false;
98 status_t rc = StatHide();
99 wxCHECK_MSG( rc == errNone, false, wxT("cannot hide status bar") );
100 }
101 return true;
102 }
103
104 void wxStatusBarPalm::SetFieldsCount(int nFields, const int *widths)
105 {
106 // this is a Windows limitation
107 wxASSERT_MSG( (nFields > 0) && (nFields < 255), _T("too many fields") );
108
109 wxStatusBarBase::SetFieldsCount(nFields, widths);
110
111 SetFieldsWidth();
112 }
113
114 void wxStatusBarPalm::SetStatusWidths(int n, const int widths[])
115 {
116 wxStatusBarBase::SetStatusWidths(n, widths);
117
118 SetFieldsWidth();
119 }
120
121 void wxStatusBarPalm::SetFieldsWidth()
122 {
123 // clear the status bar
124 DeleteStatusBuffer();
125 }
126
127 void wxStatusBarPalm::SetStatusText(const wxString& strText, int nField)
128 {
129 wxCHECK_RET( (nField >= 0) && (nField < m_nFields),
130 _T("invalid statusbar field index") );
131
132 SetStatusBufferText(strText,nField);
133 DrawStatusBar();
134 }
135
136 wxString wxStatusBarPalm::GetStatusText(int nField) const
137 {
138 wxCHECK_MSG( (nField >= 0) && (nField < m_nFields), wxEmptyString,
139 _T("invalid statusbar field index") );
140
141 wxString text;
142 return text;
143 }
144
145 void wxStatusBarPalm::DrawStatusBar()
146 {
147 #if 0
148 int i=0;
149 int leftPos=0;
150 wxArrayInt widthsAbs;
151 wxString text;
152
153 RectangleType EraseRect;
154 EraseRect.topLeft.x=0;
155 EraseRect.topLeft.y=160-FntCharHeight()-1;
156 EraseRect.extent.x=159;
157 EraseRect.extent.y=159;
158 WinEraseRectangle(&EraseRect,0);
159
160 if(m_nFields>0)
161 widthsAbs=CalculateAbsWidths(160 - 2*(m_nFields - 1));
162
163 for(i=0;i<m_nFields;i++)
164 {
165 text=GetStatusBufferText(i);
166 WinDrawTruncChars(text,StrLen(text),leftPos,160-FntCharHeight(),widthsAbs[i]);
167 leftPos+=widthsAbs[i]+2;
168 }
169 WinDrawLine(0,160-FntCharHeight()-1,159,160-FntCharHeight()-1);
170 #endif
171 }
172
173 void wxStatusBarPalm::SetStatusBufferText(const wxString& text, int number)
174 {
175 wxListString* st = GetOrCreateStatusBuffer(number);
176
177 wxString tmp1(text);
178 wxString* tmp = new wxString(tmp1);
179 st->Insert(tmp);
180 }
181
182 wxString wxStatusBarPalm::GetStatusBufferText(int number)
183 {
184 wxListString *st = GetStatusBufferStack(number);
185 if(st==0)
186 return wxEmptyString;
187
188 wxListString::compatibility_iterator top = st->GetFirst();
189 return(*top->GetData());
190 }
191
192 wxListString *wxStatusBarPalm::GetOrCreateStatusBuffer(int i)
193 {
194 if(!StatusTextBuffer)
195 {
196 StatusTextBuffer = new wxListString*[m_nFields];
197
198 size_t j;
199 for(j = 0; j < (size_t)m_nFields; ++j) StatusTextBuffer[j] = 0;
200 }
201
202 if(!StatusTextBuffer[i])
203 {
204 StatusTextBuffer[i] = new wxListString();
205 }
206 else
207 {
208 wxListString *st=StatusTextBuffer[i];
209 wxListString::compatibility_iterator top = st->GetFirst();
210 delete top->GetData();
211 st->Erase(top);
212 delete st;
213
214 StatusTextBuffer[i] = new wxListString();
215 }
216
217 return StatusTextBuffer[i];
218 }
219
220 wxListString *wxStatusBarPalm::GetStatusBufferStack(int i) const
221 {
222 if(!StatusTextBuffer)
223 return 0;
224 return StatusTextBuffer[i];
225 }
226
227 void wxStatusBarPalm::DeleteStatusBuffer()
228 {
229 if(!StatusTextBuffer)
230 {
231 return;
232 }
233
234 for(int i=0;i<m_nFields;i++)
235 {
236 if(StatusTextBuffer[i])
237 {
238 wxListString *st=StatusTextBuffer[i];
239 wxListString::compatibility_iterator top = st->GetFirst();
240 delete top->GetData();
241 st->Erase(top);
242 delete st;
243 StatusTextBuffer[i]=0;
244 }
245 }
246 delete[] m_statusTextStacks;
247 }
248
249 int wxStatusBarPalm::GetBorderX() const
250 {
251 return 0;
252 }
253
254 int wxStatusBarPalm::GetBorderY() const
255 {
256 return 0;
257 }
258
259 void wxStatusBarPalm::SetMinHeight(int height)
260 {
261 }
262
263 bool wxStatusBarPalm::GetFieldRect(int i, wxRect& rect) const
264 {
265 }
266
267 void wxStatusBarPalm::DoMoveWindow(int x, int y, int width, int height)
268 {
269 }
270
271 #endif // wxUSE_NATIVE_STATUSBAR
272