X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/808e3bce622d9ec7ae8c43581472ae699ed47221..b9efe021b554fa3967d1442cf758435c5cd5ae8f:/src/palmos/control.cpp diff --git a/src/palmos/control.cpp b/src/palmos/control.cpp index b5a89e8932..3b9b881995 100644 --- a/src/palmos/control.cpp +++ b/src/palmos/control.cpp @@ -44,6 +44,7 @@ #include "wx/checkbox.h" #include "wx/tglbtn.h" #include "wx/radiobut.h" +#include "wx/slider.h" // ---------------------------------------------------------------------------- // wxWin macros @@ -63,9 +64,25 @@ END_EVENT_TABLE() // wxControl ctor/dtor // ---------------------------------------------------------------------------- +void wxControl::Init() +{ + m_palmControl = false; + m_palmField = false; +} + wxControl::~wxControl() { + SetLabel(wxEmptyString); m_isBeingDeleted = true; + + DestroyChildren(); + + uint16_t index; + FormType* form = GetObjectFormIndex(index); + if(form!=NULL && index!=frmInvalidObjectId) + { + FrmRemoveObject((FormType **)&form,index); + } } // ---------------------------------------------------------------------------- @@ -91,37 +108,101 @@ bool wxControl::Create(wxWindow *parent, } bool wxControl::PalmCreateControl(ControlStyleType style, - wxWindow *parent, - wxWindowID id, const wxString& label, const wxPoint& pos, - const wxSize& size) + const wxSize& size, + uint8_t groupID) +{ + FormType* form = GetParentForm(); + if(form==NULL) + return false; + + + wxCoord x = pos.x == wxDefaultCoord ? 0 : pos.x, + y = pos.y == wxDefaultCoord ? 0 : pos.y, + w = size.x == wxDefaultCoord ? 1 : size.x, + h = size.y == wxDefaultCoord ? 1 : size.y; + + wxWindow *win = this; + while(win->GetParent()) + { + win = win->GetParent(); + wxPoint pt(win->GetClientAreaOrigin()); + x += pt.x; + y += pt.y; + } + + ControlType *control = CtlNewControl( + (void **)&form, + GetId(), + style, + wxEmptyString, + x, + y, + w, + h, + stdFont, + groupID, + true + ); + + if(control==NULL) + return false; + + m_palmControl = true; + + SetInitialBestSize(size); + SetLabel(label); + Show(); + return true; +} + +bool wxControl::PalmCreateField(const wxString& label, + const wxPoint& pos, + const wxSize& size, + bool editable, + bool underlined, + JustificationType justification) { - SetParent(parent); - SetId( id == wxID_ANY ? NewControlId() : id ); FormType* form = GetParentForm(); if(form==NULL) return false; m_label = label; - m_control = CtlNewControl( - (void **)&form, - GetId(), - style, - m_label.c_str(), - ( pos.x == wxDefaultCoord ) ? winUndefConstraint : pos.x, - ( pos.y == wxDefaultCoord ) ? winUndefConstraint : pos.y, - ( size.x == wxDefaultCoord ) ? winUndefConstraint : size.x, - ( size.y == wxDefaultCoord ) ? winUndefConstraint : size.y, - stdFont, - 0, - false - ); - - if(m_control==NULL) + wxCoord x = pos.x == wxDefaultCoord ? 0 : pos.x, + y = pos.y == wxDefaultCoord ? 0 : pos.y, + w = size.x == wxDefaultCoord ? 1 : size.x, + h = size.y == wxDefaultCoord ? 1 : size.y; + + AdjustForParentClientOrigin(x, y); + + FieldType *field = FldNewField( + (void **)&form, + GetId(), + x, + y, + w, + h, + stdFont, + 10, + editable, + underlined, + false, + false, + justification, + false, + false, + false + ); + + if(field==NULL) return false; + m_palmField = true; + + SetInitialBestSize(size); + SetLabel(label); Show(); return true; } @@ -143,6 +224,24 @@ FormType* wxControl::GetParentForm() const return tlw->GetForm(); } +FormType* wxControl::GetObjectFormIndex(uint16_t& index) const +{ + FormType* form = GetParentForm(); + if(form!=NULL) + index = FrmGetObjectIndex(form, GetId()); + else + index = frmInvalidObjectId; + return form; +} + +void* wxControl::GetObjectPtr() const +{ + uint16_t index; + FormType* form = GetObjectFormIndex(index); + if(form==NULL || index==frmInvalidObjectId)return NULL; + return FrmGetObjectPtr(form,index); +} + wxBorder wxControl::GetDefaultBorder() const { // we want to automatically give controls a sunken style (confusingly, @@ -194,41 +293,71 @@ void wxControl::DoGetBounds( RectangleType &rect ) const FrmGetObjectBounds(form,index,&rect); } +void wxControl::DoSetBounds( RectangleType &rect ) +{ + FormType* form = GetParentForm(); + if(form==NULL) + return; + uint16_t index = FrmGetObjectIndex(form,GetId()); + if(index==frmInvalidObjectId) + return; + FrmSetObjectBounds(form,index,&rect); +} + void wxControl::DoGetPosition( int *x, int *y ) const { + int ox = 0, oy = 0; + AdjustForParentClientOrigin(ox, oy); + RectangleType rect; DoGetBounds(rect); + if(x) - *x = rect.topLeft.x; + *x = rect.topLeft.x - ox; if(y) - *y = rect.topLeft.y; + *y = rect.topLeft.y - oy; } void wxControl::DoGetSize( int *width, int *height ) const { RectangleType rect; DoGetBounds(rect); + if(width) *width = rect.extent.x; if(height) *height = rect.extent.y; } +void wxControl::DoMoveWindow(int x, int y, int width, int height) +{ + wxRect area = GetRect(); + RectangleType rect; + rect.topLeft.x = x; + rect.topLeft.y = y; + rect.extent.x = width; + rect.extent.y = height; + DoSetBounds(rect); + GetParent()->Refresh(true, &area); +} + bool wxControl::Enable(bool enable) { - if( m_control == NULL ) + ControlType *control = (ControlType *)GetObjectPtr(); + if( !IsPalmControl() || (control == NULL)) return false; - if( IsEnabled() == enable) + if( CtlEnabled(control) == enable) return false; - CtlSetEnabled( m_control, enable); + CtlSetEnabled( control, enable); return true; } bool wxControl::IsEnabled() const { - if( m_control == NULL ) + ControlType *control = (ControlType *)GetObjectPtr(); + if( !IsPalmControl() || (control == NULL)) return false; - return CtlEnabled(m_control); + return CtlEnabled(control); } bool wxControl::IsShown() const @@ -251,31 +380,82 @@ bool wxControl::Show( bool show ) return true; } -void wxControl::SetLabel(const wxString& label) +void wxControl::SetFieldLabel(const wxString& label) { - // setting in wrong control causes crash - if ( ( wxDynamicCast(this,wxButton) != NULL ) || - ( wxDynamicCast(this,wxCheckBox) != NULL ) || - ( wxDynamicCast(this,wxRadioButton) != NULL ) || - ( wxDynamicCast(this,wxToggleButton) != NULL ) ) + FieldType* field = (FieldType*)GetObjectPtr(); + if(field==NULL) + return; + + uint16_t newSize = label.Length() + 1; + MemHandle strHandle = FldGetTextHandle(field); + FldSetTextHandle(field, NULL ); + if (strHandle) { - m_label = label; - // TODO: as manual states, it crashes here - // needs own manipulation on used string pointers - // CtlSetLabel(m_control,m_label); + if(MemHandleResize(strHandle, newSize)!=errNone) + strHandle = 0; } + else + { + strHandle = MemHandleNew( newSize ); + } + if(!strHandle) + return; + + char* str = (char*) MemHandleLock( strHandle ); + if(str==NULL) + return; + + strcpy(str, label.c_str()); + MemHandleUnlock(strHandle); + FldSetTextHandle(field, strHandle); + FldRecalculateField(field, true); +} + +void wxControl::SetControlLabel(const wxString& label) +{ + ControlType* control = (ControlType*)GetObjectPtr(); + if(control==NULL) + return; + CtlSetLabel(control,wxEmptyString); + m_label = label; + if(!m_label.empty()) + CtlSetLabel(control,m_label.c_str()); +} + +void wxControl::SetLabel(const wxString& label) +{ + if(IsPalmField()) + SetFieldLabel(label); + + // unlike other native controls, slider has no label + if(IsPalmControl() && !wxDynamicCast(this,wxSlider)) + SetControlLabel(label); +} + +wxString wxControl::GetFieldLabel() +{ + FieldType* field = (FieldType*)GetObjectPtr(); + if(field==NULL) + return wxEmptyString; + return FldGetTextPtr(field); +} + +wxString wxControl::GetControlLabel() +{ + ControlType* control = (ControlType*)GetObjectPtr(); + if(control==NULL) + return wxEmptyString; + return CtlGetLabel(control); } wxString wxControl::GetLabel() { - // setting in wrong control causes crash - if ( wxDynamicCast(this,wxButton) || - wxDynamicCast(this,wxCheckBox) || - wxDynamicCast(this,wxRadioButton) || - wxDynamicCast(this,wxToggleButton) ) - { - return m_label; - } + if(IsPalmField()) + return GetFieldLabel(); + + // unlike other native controls, slider has no label + if(IsPalmControl() && !wxDynamicCast(this,wxSlider)) + return GetControlLabel(); return wxEmptyString; } @@ -323,17 +503,4 @@ void wxControl::OnEraseBackground(wxEraseEvent& event) { } -WXHBRUSH wxControl::OnCtlColor(WXHDC pDC, WXHWND WXUNUSED(pWnd), WXUINT WXUNUSED(nCtlColor), - WXUINT WXUNUSED(message), - WXWPARAM WXUNUSED(wParam), - WXLPARAM WXUNUSED(lParam) - ) -{ - return (WXHBRUSH)0; -} - -// --------------------------------------------------------------------------- -// global functions -// --------------------------------------------------------------------------- - #endif // wxUSE_CONTROLS