From ba88951339bb5ae38d11394b25041b7e019b6883 Mon Sep 17 00:00:00 2001 From: =?utf8?q?W=C5=82odzimierz=20Skiba?= Date: Thu, 27 Jan 2005 11:01:06 +0000 Subject: [PATCH] Get/SetValue() and other improvements to the native PalmOS controls. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31604 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/palmos/control.h | 17 ++++++++ include/wx/palmos/window.h | 9 ---- src/common/wincmn.cpp | 12 +++--- src/palmos/button.cpp | 4 ++ src/palmos/checkbox.cpp | 3 +- src/palmos/control.cpp | 83 ++++++++++++++++++++++++++++--------- src/palmos/slider.cpp | 21 ++++------ src/palmos/statbrpalm.cpp | 3 +- src/palmos/tglbtn.cpp | 3 +- src/palmos/toplevel.cpp | 6 ++- src/palmos/window.cpp | 46 ++------------------ 11 files changed, 111 insertions(+), 96 deletions(-) diff --git a/include/wx/palmos/control.h b/include/wx/palmos/control.h index db397571b0..c3dc2f6ffb 100644 --- a/include/wx/palmos/control.h +++ b/include/wx/palmos/control.h @@ -75,9 +75,17 @@ public: WXUINT message, WXWPARAM wParam, WXLPARAM lParam); protected: + // regardless how deeply we are in wxWidgets hierarchy always get correct form + FormType* GetParentForm() const; + // choose the default border for this window virtual wxBorder GetDefaultBorder() const; + // on/off-like controls + void SetBoolValue(bool value); + bool GetBoolValue() const; + void SetIntValue(int val); + // return default best size (doesn't really make any sense, override this) virtual wxSize DoGetBestSize() const; @@ -108,6 +116,15 @@ protected: ControlType *m_control; private: + + // Label stores label in case of wxButton, wxCheckBox, wxToggleButton etc. + // We must ensure that it persists for as long as it is being displayed + // (that is, for as long as the control is displayed or until we call + // CtlSetLabel() with a new string), and we must free the string after + // it is no longer in use (typically after the form containing the + // control is freed). + wxString m_label; + DECLARE_DYNAMIC_CLASS_NO_COPY(wxControl) DECLARE_EVENT_TABLE() }; diff --git a/include/wx/palmos/window.h b/include/wx/palmos/window.h index b103474cdc..8c1f1dd31e 100644 --- a/include/wx/palmos/window.h +++ b/include/wx/palmos/window.h @@ -252,11 +252,6 @@ public: virtual bool PalmOnScroll(int orientation, WXWORD nSBCode, WXWORD pos, WXHWND control); - // child control notifications -#ifdef __WIN95__ - virtual bool PalmOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result); -#endif // __WIN95__ - // owner-drawn controls need to process these messages virtual bool PalmOnDrawItem(int id, WXDRAWITEMSTRUCT *item); virtual bool PalmOnMeasureItem(int id, WXMEASUREITEMSTRUCT *item); @@ -431,10 +426,6 @@ private: bool HandleMoving(wxRect& rect); bool HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags); -#ifdef __WIN95__ - bool HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result); -#endif // __WIN95__ - // list of disabled children before last call to our Disable() wxWindowList *m_childrenDisabled; diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 4fb4d5b26f..d109b28adf 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -85,7 +85,9 @@ // static data // ---------------------------------------------------------------------------- -#if defined(__WXPM__) +#if defined(__WXPALMOS__) +int wxWindowBase::ms_lastControlId = 65535; +#elif defined(__WXPM__) int wxWindowBase::ms_lastControlId = 2000; #else int wxWindowBase::ms_lastControlId = -200; @@ -537,7 +539,7 @@ static bool wxHasRealChildren(const wxWindowBase* win) return (realChildCount > 0); } #endif - + void wxWindowBase::InvalidateBestSize() { m_bestSizeCache = wxDefaultSize; @@ -2693,7 +2695,7 @@ wxAccStatus wxWindowAccessible::GetName(int childId, wxString* name) #endif title = GetWindow()->GetName(); - if (!title.IsEmpty()) + if (!title.empty()) { *name = title; return wxACC_OK; @@ -2799,7 +2801,7 @@ wxAccStatus wxWindowAccessible::GetDescription(int WXUNUSED(childId), wxString* return wxACC_FAIL; wxString ht(GetWindow()->GetHelpText()); - if (!ht.IsEmpty()) + if (!ht.empty()) { *description = ht; return wxACC_OK; @@ -2815,7 +2817,7 @@ wxAccStatus wxWindowAccessible::GetHelpText(int WXUNUSED(childId), wxString* hel return wxACC_FAIL; wxString ht(GetWindow()->GetHelpText()); - if (!ht.IsEmpty()) + if (!ht.empty()) { *helpText = ht; return wxACC_OK; diff --git a/src/palmos/button.cpp b/src/palmos/button.cpp index c72fc9402f..a53ae3f19a 100644 --- a/src/palmos/button.cpp +++ b/src/palmos/button.cpp @@ -151,6 +151,10 @@ wxSize wxButtonBase::GetDefaultSize() void wxButton::SetDefault() { + FormType* form = GetParentForm(); + if(form==NULL) + return; + FrmSetDefaultButtonID(form,GetId()); } void wxButton::SetTmpDefault() diff --git a/src/palmos/checkbox.cpp b/src/palmos/checkbox.cpp index 77f06f5409..5b55dd7c00 100644 --- a/src/palmos/checkbox.cpp +++ b/src/palmos/checkbox.cpp @@ -117,11 +117,12 @@ wxSize wxCheckBox::DoGetBestSize() const void wxCheckBox::SetValue(bool val) { + SetBoolValue(val); } bool wxCheckBox::GetValue() const { - return false; + return GetBoolValue(); } void wxCheckBox::Command(wxCommandEvent& event) diff --git a/src/palmos/control.cpp b/src/palmos/control.cpp index df1399f819..25fcb3225e 100644 --- a/src/palmos/control.cpp +++ b/src/palmos/control.cpp @@ -96,27 +96,23 @@ bool wxControl::PalmCreateControl(ControlStyleType style, const wxPoint& pos, const wxSize& size) { - wxWindow* parentTLW = parent; - while ( parentTLW && !parentTLW->IsTopLevel() ) - { - parentTLW = parentTLW->GetParent(); - } - wxTopLevelWindowPalm* tlw = wxDynamicCast(parentTLW, wxTopLevelWindowPalm); - if(!tlw) + SetParent(parent); + SetId( id == wxID_ANY ? NewControlId() : id ); + FormType* form = GetParentForm(); + if(form==NULL) return false; - FormType* form = tlw->GetForm(); - SetParent(parent); + m_label = label; m_control = CtlNewControl( (void **)&form, - id, + GetId(), style, - label.c_str(), - pos.x, - pos.y, - size.x, - size.y, + 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, boldFont, 0, false @@ -133,6 +129,19 @@ bool wxControl::PalmCreateControl(ControlStyleType style, // various accessors // ---------------------------------------------------------------------------- +FormType* 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(); +} + wxBorder wxControl::GetDefaultBorder() const { // we want to automatically give controls a sunken style (confusingly, @@ -141,6 +150,33 @@ wxBorder wxControl::GetDefaultBorder() const return wxBORDER_SUNKEN; } +void wxControl::SetIntValue(int val) +{ + FormType* form = 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 = 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); @@ -170,10 +206,16 @@ bool wxControl::IsShown() const bool wxControl::Show( bool show ) { + FormType* form = 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; } @@ -184,7 +226,10 @@ void wxControl::SetLabel(const wxString& label) ( wxDynamicCast(this,wxCheckBox) != NULL ) || ( wxDynamicCast(this,wxToggleButton) != NULL ) ) { - CtlSetLabel(m_control,label); + m_label = label; + // TODO: as manual states, it crashes here + // needs own manipulation on used string pointers + // CtlSetLabel(m_control,m_label); } } @@ -195,7 +240,7 @@ wxString wxControl::GetLabel() wxDynamicCast(this,wxCheckBox) || wxDynamicCast(this,wxToggleButton) ) { - return CtlGetLabel(m_control); + return m_label; } return wxEmptyString; diff --git a/src/palmos/slider.cpp b/src/palmos/slider.cpp index a6341e03a2..2604f0bce5 100644 --- a/src/palmos/slider.cpp +++ b/src/palmos/slider.cpp @@ -109,21 +109,15 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id, const wxValidator& validator, const wxString& name) { - wxWindow* parentTLW = GetParent(); - while ( parentTLW && !parentTLW->IsTopLevel() ) - { - parentTLW = parentTLW->GetParent(); - } - wxTopLevelWindowPalm* tlw = wxDynamicCast(parentTLW, wxTopLevelWindowPalm); - if(!tlw) - return false; - FormType* form = tlw->GetForm(); - SetParent(parent); + SetId( id == wxID_ANY ? NewControlId() : id ); + FormType* form = GetParentForm(); + if(form==NULL) + return false; SliderControlType *slider = CtlNewSliderControl ( (void **)&form, - id, + GetId(), feedbackSliderCtl, NULL, 0, @@ -138,9 +132,7 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id, value ); - m_control = (ControlType*) slider; - - if(m_control==NULL) + if(slider==NULL) return false; Show(); @@ -181,6 +173,7 @@ int wxSlider::GetValue() const void wxSlider::SetValue(int value) { + SetIntValue(value); } void wxSlider::DoGetSize(int *width, int *height) const diff --git a/src/palmos/statbrpalm.cpp b/src/palmos/statbrpalm.cpp index ba68ff9a26..567076d39c 100644 --- a/src/palmos/statbrpalm.cpp +++ b/src/palmos/statbrpalm.cpp @@ -63,11 +63,10 @@ bool wxStatusBarPalm::Create(wxWindow *parent, SetName(name); SetParent(parent); + SetId( id == wxID_ANY ? NewControlId() : id ); parent->AddChild(this); - m_windowId = id == wxID_ANY ? NewControlId() : id; - SetFieldsCount(1); SubclassWin(m_hWnd); diff --git a/src/palmos/tglbtn.cpp b/src/palmos/tglbtn.cpp index 9e69fc4b82..e4b49b65ab 100644 --- a/src/palmos/tglbtn.cpp +++ b/src/palmos/tglbtn.cpp @@ -76,11 +76,12 @@ wxSize wxToggleButton::DoGetBestSize() const void wxToggleButton::SetValue(bool val) { + SetBoolValue(val); } bool wxToggleButton::GetValue() const { - return false; + return GetBoolValue(); } void wxToggleButton::Command(wxCommandEvent & event) diff --git a/src/palmos/toplevel.cpp b/src/palmos/toplevel.cpp index 58fe1ddc46..3f09270a6d 100644 --- a/src/palmos/toplevel.cpp +++ b/src/palmos/toplevel.cpp @@ -98,12 +98,14 @@ bool wxTopLevelWindowPalm::Create(wxWindow *parent, if ( parent ) parent->AddChild(this); - m_windowId = id == wxID_ANY ? NewControlId() : id; + SetId( id == wxID_ANY ? NewControlId() : id ); WinConstraintsType constraints; memset(&constraints, 0, sizeof(WinConstraintsType)); + // position constraints.x_pos = ( pos.x == wxDefaultCoord ) ? winUndefConstraint : pos.x; constraints.y_pos = ( pos.y == wxDefaultCoord ) ? winUndefConstraint : pos.y; + // size constraints.x_min = winUndefConstraint; constraints.x_max = winMaxConstraint; constraints.x_pref = ( size.x == wxDefaultCoord ) ? winUndefConstraint : size.x; @@ -112,7 +114,7 @@ bool wxTopLevelWindowPalm::Create(wxWindow *parent, constraints.y_pref = ( size.y == wxDefaultCoord ) ? winUndefConstraint : size.y; FrameForm = FrmNewFormWithConstraints( - m_windowId, + GetId(), title.c_str(), winFlagBackBuffer, &constraints, diff --git a/src/palmos/window.cpp b/src/palmos/window.cpp index 39bff56d6a..d908c96629 100644 --- a/src/palmos/window.cpp +++ b/src/palmos/window.cpp @@ -2,10 +2,10 @@ // Name: src/palmos/windows.cpp // Purpose: wxWindow // Author: William Osborne - minimal working wxPalmOS port -// Modified by: +// Modified by: Wlodzimierz ABX Skiba - more than minimal functionality // Created: 10/13/04 // RCS-ID: $Id$ -// Copyright: (c) William Osborne +// Copyright: (c) William Osborne, Wlodzimierz Skiba // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -83,10 +83,7 @@ #include "wx/textctrl.h" #include "wx/notebook.h" #include "wx/listctrl.h" - -#include - -#include "wx/palmos/window.h" +#include "wx/window.h" // --------------------------------------------------------------------------- // global variables @@ -96,12 +93,6 @@ wxMenu *wxCurrentPopupMenu = NULL; #endif // wxUSE_MENUS_NATIVE -#ifdef __WXWINCE__ -extern wxChar *wxCanvasClassName; -#else -extern const wxChar *wxCanvasClassName; -#endif - // true if we had already created the std colour map, used by // wxGetStdColourMap() and wxWindow::OnSysColourChanged() (FIXME-MT) static bool gs_hasStdCmap = false; @@ -706,37 +697,6 @@ bool wxWindowPalm::PalmCreate(const wxChar *wclass, // Palm message handlers // =========================================================================== -// --------------------------------------------------------------------------- -// WM_NOTIFY -// --------------------------------------------------------------------------- - -#ifdef __WIN95__ - -bool wxWindowPalm::HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) -{ - return false; -} - -#if wxUSE_TOOLTIPS - -bool wxWindowPalm::HandleTooltipNotify(WXUINT code, - WXLPARAM lParam, - const wxString& ttip) -{ - return false; -} - -#endif // wxUSE_TOOLTIPS - -bool wxWindowPalm::PalmOnNotify(int WXUNUSED(idCtrl), - WXLPARAM lParam, - WXLPARAM* WXUNUSED(result)) -{ - return false; -} - -#endif // __WIN95__ - // --------------------------------------------------------------------------- // end session messages // --------------------------------------------------------------------------- -- 2.47.2