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