]> git.saurik.com Git - wxWidgets.git/commitdiff
Get/SetValue() and other improvements to the native PalmOS controls.
authorWłodzimierz Skiba <abx@abx.art.pl>
Thu, 27 Jan 2005 11:01:06 +0000 (11:01 +0000)
committerWłodzimierz Skiba <abx@abx.art.pl>
Thu, 27 Jan 2005 11:01:06 +0000 (11:01 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31604 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/palmos/control.h
include/wx/palmos/window.h
src/common/wincmn.cpp
src/palmos/button.cpp
src/palmos/checkbox.cpp
src/palmos/control.cpp
src/palmos/slider.cpp
src/palmos/statbrpalm.cpp
src/palmos/tglbtn.cpp
src/palmos/toplevel.cpp
src/palmos/window.cpp

index db397571b0573f889f18c34f28ac447c1742dcc6..c3dc2f6ffb44030b89bb5b0c27b872d07bef3a51 100644 (file)
@@ -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()
 };
index b103474cdc05d8b1d11c5c988b061ac014045455..8c1f1dd31ebcf2a615b525e384476d28544e5aca 100644 (file)
@@ -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;
 
index 4fb4d5b26fd8d09f5e3deb75073c1ab520d3072f..d109b28adf13a61b74d05b08cc87cbbb50970381 100644 (file)
@@ -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;
index c72fc9402ff7ee23b75c19a4ff8e14cea4aabe83..a53ae3f19a8cdf02298bad711147cac26ee59686 100644 (file)
@@ -151,6 +151,10 @@ wxSize wxButtonBase::GetDefaultSize()
 
 void wxButton::SetDefault()
 {
+    FormType* form = GetParentForm();
+    if(form==NULL)
+        return;
+    FrmSetDefaultButtonID(form,GetId());
 }
 
 void wxButton::SetTmpDefault()
index 77f06f5409afb04451ae43f5807a6a398dcc32d2..5b55dd7c0024b6f38a9fe8bb10876f58b4bbb294 100644 (file)
@@ -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)
index df1399f819b7aa04d0e0330f0e7aba65d44fe54b..25fcb3225ecfe43f8c5e1b91f08aef4660498f2e 100644 (file)
@@ -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;
index a6341e03a280073fd5796dd238912f540e17470a..2604f0bce5186e27a8a04b08f352692487c10cc6 100644 (file)
@@ -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
index ba68ff9a26ea2242db566baaebac71f76c864e92..567076d39ced9a72df17fa1d6b634fdfab1ca571 100644 (file)
@@ -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);
 
index 9e69fc4b8291ea8ff0001e1559be4ea822d63b24..e4b49b65ab743b10e694c580bbed7b987fa1be35 100644 (file)
@@ -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)
index 58fe1ddc4661615deafaf676665bb977a248a30f..3f09270a6d3ac1573082b56158d359d4eb0f58dd 100644 (file)
@@ -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,
index 39bff56d6a2f2cd8cda62deebde41290294218bc..d908c9662942c068278f10cbe18d5073f9852840 100644 (file)
@@ -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
 /////////////////////////////////////////////////////////////////////////////
 
 #include "wx/textctrl.h"
 #include "wx/notebook.h"
 #include "wx/listctrl.h"
-
-#include <string.h>
-
-#include "wx/palmos/window.h"
+#include "wx/window.h"
 
 // ---------------------------------------------------------------------------
 // global variables
 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
 // ---------------------------------------------------------------------------