X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/bdb5436554c910fe850db1470514ee83ded76db3..d2e66707deb10dea6f92e3e4092f8a43ef942a5d:/src/palmos/control.cpp?ds=sidebyside diff --git a/src/palmos/control.cpp b/src/palmos/control.cpp index df1399f819..66dd535de7 100644 --- a/src/palmos/control.cpp +++ b/src/palmos/control.cpp @@ -17,10 +17,6 @@ // headers // ---------------------------------------------------------------------------- -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma implementation "control.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -30,20 +26,31 @@ #if wxUSE_CONTROLS +#include "wx/control.h" + #ifndef WX_PRECOMP #include "wx/event.h" #include "wx/app.h" #include "wx/dcclient.h" #include "wx/log.h" #include "wx/settings.h" + #include "wx/button.h" + #include "wx/checkbox.h" + #include "wx/radiobut.h" + #include "wx/slider.h" + #include "wx/toplevel.h" #endif -#include "wx/control.h" -#include "wx/toplevel.h" -#include "wx/button.h" -#include "wx/checkbox.h" #include "wx/tglbtn.h" +#include +#include +#ifdef __WXPALMOS6__ + #include +#else + #include +#endif // __WXPALMOS6__ + // ---------------------------------------------------------------------------- // wxWin macros // ---------------------------------------------------------------------------- @@ -62,9 +69,26 @@ END_EVENT_TABLE() // wxControl ctor/dtor // ---------------------------------------------------------------------------- +void wxControl::Init() +{ + m_palmControl = false; + m_palmField = false; +} + wxControl::~wxControl() { - m_isBeingDeleted = true; + SendDestroyEvent(); + + SetLabel(wxEmptyString); + + DestroyChildren(); + + uint16_t index; + FormType* form = (FormType*)GetObjectFormIndex(index); + if(form!=NULL && index!=frmInvalidObjectId) + { + FrmRemoveObject((FormType **)&form,index); + } } // ---------------------------------------------------------------------------- @@ -89,42 +113,102 @@ bool wxControl::Create(wxWindow *parent, return true; } -bool wxControl::PalmCreateControl(ControlStyleType style, - wxWindow *parent, - wxWindowID id, +bool wxControl::PalmCreateControl(int style, const wxString& label, const wxPoint& pos, - const wxSize& size) + const wxSize& size, + uint8_t groupID) { - wxWindow* parentTLW = parent; - while ( parentTLW && !parentTLW->IsTopLevel() ) + FormType* form = (FormType*)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()) { - parentTLW = parentTLW->GetParent(); + win = win->GetParent(); + wxPoint pt(win->GetClientAreaOrigin()); + x += pt.x; + y += pt.y; } - wxTopLevelWindowPalm* tlw = wxDynamicCast(parentTLW, wxTopLevelWindowPalm); - if(!tlw) + + ControlType *control = CtlNewControl( + (void **)&form, + GetId(), + (ControlStyleType)style, + NULL, + x, + y, + w, + h, + stdFont, + groupID, + true + ); + + if(control==NULL) + return false; + + m_palmControl = true; + + SetInitialSize(size); + SetLabel(label); + Show(); + return true; +} + +bool wxControl::PalmCreateField(const wxString& label, + const wxPoint& pos, + const wxSize& size, + bool editable, + bool underlined, + int justification) +{ + FormType* form = (FormType*)GetParentForm(); + if(form==NULL) return false; - FormType* form = tlw->GetForm(); - - SetParent(parent); - - m_control = CtlNewControl( - (void **)&form, - id, - style, - label.c_str(), - pos.x, - pos.y, - size.x, - size.y, - boldFont, - 0, - false - ); - - if(m_control==NULL) + + m_label = label; + + 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, + (JustificationType)justification, + false, + false, + false + ); + + if(field==NULL) return false; + m_palmField = true; + + SetInitialSize(size); + SetLabel(label); Show(); return true; } @@ -133,6 +217,37 @@ bool wxControl::PalmCreateControl(ControlStyleType style, // various accessors // ---------------------------------------------------------------------------- +WXFORMPTR wxControl::GetParentForm() const +{ + wxWindow* parentTLW = GetParent(); + while ( parentTLW && !parentTLW->IsTopLevel() ) + { + parentTLW = parentTLW->GetParent(); + } + wxTopLevelWindowPalm* tlw = wxDynamicCast(parentTLW, wxTopLevelWindowPalm); + if(!tlw) + return NULL; + return tlw->GetForm(); +} + +WXFORMPTR wxControl::GetObjectFormIndex(uint16_t& index) const +{ + FormType* form = (FormType* )GetParentForm(); + if(form!=NULL) + index = FrmGetObjectIndex(form, GetId()); + else + index = frmInvalidObjectId; + return form; +} + +void* wxControl::GetObjectPtr() const +{ + uint16_t index; + FormType* form = (FormType*)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, @@ -141,26 +256,118 @@ wxBorder wxControl::GetDefaultBorder() const return wxBORDER_SUNKEN; } +void wxControl::SetIntValue(int val) +{ + FormType* form = (FormType*)GetParentForm(); + if(form==NULL) + return; + uint16_t index = FrmGetObjectIndex(form, GetId()); + if(index==frmInvalidObjectId) + return; + FrmSetControlValue(form, index, val); +} + +void wxControl::SetBoolValue(bool val) +{ + SetIntValue(val?1:0); +} + +bool wxControl::GetBoolValue() const +{ + FormType* form = (FormType*)GetParentForm(); + if(form==NULL) + return false; + uint16_t index = FrmGetObjectIndex(form, GetId()); + if(index==frmInvalidObjectId) + return false; + return ( FrmGetControlValue(form, index) == 1 ); +} + wxSize wxControl::DoGetBestSize() const { return wxSize(16, 16); } +void wxControl::DoGetBounds( WXRECTANGLEPTR rect ) const +{ + if(rect==NULL) + return; + FormType* form = (FormType*)GetParentForm(); + if(form==NULL) + return; + uint16_t index = FrmGetObjectIndex(form,GetId()); + if(index==frmInvalidObjectId) + return; + FrmGetObjectBounds(form,index,(RectangleType*)rect); +} + +void wxControl::DoSetBounds( WXRECTANGLEPTR rect ) +{ + if(rect==NULL) + return; + FormType* form = (FormType*)GetParentForm(); + if(form==NULL) + return; + uint16_t index = FrmGetObjectIndex(form,GetId()); + if(index==frmInvalidObjectId) + return; + FrmSetObjectBounds(form,index,(RectangleType*)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 - ox; + if(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 @@ -170,37 +377,99 @@ bool wxControl::IsShown() const bool wxControl::Show( bool show ) { + FormType* form = (FormType*)GetParentForm(); + if(form==NULL) + return false; + uint16_t index = FrmGetObjectIndex(form,GetId()); + if(index==frmInvalidObjectId) + return false; if(show) - CtlShowControl(m_control); + FrmShowObject(form,index); else - CtlHideControl(m_control); + FrmHideObject(form,index); 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,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) { - CtlSetLabel(m_control,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, ""); + 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); +} +#if 0 wxString wxControl::GetLabel() { - // setting in wrong control causes crash - if ( wxDynamicCast(this,wxButton) || - wxDynamicCast(this,wxCheckBox) || - wxDynamicCast(this,wxToggleButton) ) - { - return CtlGetLabel(m_control); - } + if(IsPalmField()) + return GetFieldLabel(); + + // unlike other native controls, slider has no label + if(IsPalmControl() && !wxDynamicCast(this,wxSlider)) + return GetControlLabel(); return wxEmptyString; } - +#endif /* static */ wxVisualAttributes wxControl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) { @@ -237,30 +506,11 @@ wxControl::GetCompositeControlsDefaultAttributes(wxWindowVariant WXUNUSED(varian bool wxControl::ProcessCommand(wxCommandEvent& event) { - return GetEventHandler()->ProcessEvent(event); + return HandleWindowEvent(event); } void wxControl::OnEraseBackground(wxEraseEvent& event) { } -WXHBRUSH wxControl::OnCtlColor(WXHDC pDC, WXHWND WXUNUSED(pWnd), WXUINT WXUNUSED(nCtlColor), -#if wxUSE_CTL3D - WXUINT message, - WXWPARAM wParam, - WXLPARAM lParam -#else - WXUINT WXUNUSED(message), - WXWPARAM WXUNUSED(wParam), - WXLPARAM WXUNUSED(lParam) -#endif - ) -{ - return (WXHBRUSH)0; -} - -// --------------------------------------------------------------------------- -// global functions -// --------------------------------------------------------------------------- - #endif // wxUSE_CONTROLS