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