]> git.saurik.com Git - wxWidgets.git/blobdiff - src/palmos/control.cpp
Add support for wxSL_INVERSE flag. Also uses new inverse logic to make Mac vertical...
[wxWidgets.git] / src / palmos / control.cpp
index c4360886e7d9753eb0ad9ad76ccb891a7a2ea655..25fcb3225ecfe43f8c5e1b91f08aef4660498f2e 100644 (file)
@@ -2,10 +2,10 @@
 // Name:        src/palmos/control.cpp
 // Purpose:     wxControl class
 // Author:      William Osborne - minimal working wxPalmOS port
-// Modified by:
+// Modified by: Wlodzimierz ABX Skiba - native implementation
 // Created:     10/13/04
 // RCS-ID:      $Id$
-// Copyright:   (c) William Osborne
+// Copyright:   (c) William Osborne, Wlodzimierz Skiba
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 #endif
 
 #include "wx/control.h"
+#include "wx/toplevel.h"
+#include "wx/button.h"
+#include "wx/checkbox.h"
+#include "wx/tglbtn.h"
 
 // ----------------------------------------------------------------------------
 // wxWin macros
@@ -92,16 +96,23 @@ bool wxControl::PalmCreateControl(ControlStyleType style,
                                   const wxPoint& pos,
                                   const wxSize& size)
 {
-    FormType* form = FrmGetActiveForm ();
-    m_control = CtlNewControl (
+    SetParent(parent);
+    SetId( id == wxID_ANY ? NewControlId() : id );
+    FormType* form = GetParentForm();
+    if(form==NULL)
+        return false;
+
+    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
@@ -110,8 +121,6 @@ bool wxControl::PalmCreateControl(ControlStyleType style,
     if(m_control==NULL)
         return false;
 
-    form = FrmGetActiveForm ();
-    m_objectIndex = FrmGetObjectIndex(form, id);
     Show();
     return true;
 }
@@ -120,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,
@@ -128,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);
@@ -157,13 +206,46 @@ 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)
-        FrmShowObject(FrmGetActiveForm(), m_objectIndex);
+        FrmShowObject(form,index);
     else
-        FrmHideObject(FrmGetActiveForm(), m_objectIndex);
+        FrmHideObject(form,index);
     return true;
 }
 
+void wxControl::SetLabel(const wxString& label)
+{
+    // setting in wrong control causes crash
+    if ( ( wxDynamicCast(this,wxButton) != NULL ) ||
+         ( wxDynamicCast(this,wxCheckBox) != NULL ) ||
+         ( wxDynamicCast(this,wxToggleButton) != NULL ) )
+    {
+        m_label = label;
+        // TODO: as manual states, it crashes here
+        // needs own manipulation on used string pointers
+        // CtlSetLabel(m_control,m_label);
+    }
+}
+
+wxString wxControl::GetLabel()
+{
+    // setting in wrong control causes crash
+    if ( wxDynamicCast(this,wxButton) ||
+         wxDynamicCast(this,wxCheckBox) ||
+         wxDynamicCast(this,wxToggleButton) )
+    {
+        return m_label;
+    }
+
+    return wxEmptyString;
+}
+
 /* static */ wxVisualAttributes
 wxControl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
 {