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