]> git.saurik.com Git - wxWidgets.git/blobdiff - src/palmos/control.cpp
use GetFileAttributes() to check for readonly files under Win9x, the NT method doesn...
[wxWidgets.git] / src / palmos / control.cpp
index 88fd6fac820c5682ec30647b14fc3f7827d4f53d..39033e863d4d3c87d377e345e2d8959f6ece8a15 100644 (file)
 // 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"
 
 
 #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 "wx/radiobut.h"
-#include "wx/slider.h"
+
+#include <Control.h>
+#include <Form.h>
+#ifdef __WXPALMOS6__
+    #include <StatusBar.h>
+#else
+    #include <PenInputMgr.h>
+#endif // __WXPALMOS6__
 
 // ----------------------------------------------------------------------------
 // wxWin macros
@@ -74,6 +79,15 @@ wxControl::~wxControl()
 {
     SetLabel(wxEmptyString);
     m_isBeingDeleted = true;
+
+    DestroyChildren();
+
+    uint16_t index;
+    FormType* form = (FormType*)GetObjectFormIndex(index);
+    if(form!=NULL && index!=frmInvalidObjectId)
+    {
+        FrmRemoveObject((FormType **)&form,index);
+    }
 }
 
 // ----------------------------------------------------------------------------
@@ -98,28 +112,43 @@ bool wxControl::Create(wxWindow *parent,
     return true;
 }
 
-bool wxControl::PalmCreateControl(ControlStyleType style,
+bool wxControl::PalmCreateControl(int style,
                                   const wxString& label,
                                   const wxPoint& pos,
                                   const wxSize& size,
-                                  int groupID)
+                                  uint8_t groupID)
 {
-    FormType* form = GetParentForm();
+    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())
+    {
+        win = win->GetParent();
+        wxPoint pt(win->GetClientAreaOrigin());
+        x += pt.x;
+        y += pt.y;
+    }
+
     ControlType *control = CtlNewControl(
                                (void **)&form,
                                GetId(),
-                               style,
-                               wxEmptyString,
-                               ( pos.x == wxDefaultCoord ) ? winUndefConstraint : pos.x,
-                               ( pos.y == wxDefaultCoord ) ? winUndefConstraint : pos.y,
-                               ( size.x == wxDefaultCoord ) ? winUndefConstraint : size.x,
-                               ( size.y == wxDefaultCoord ) ? winUndefConstraint : size.y,
+                               (ControlStyleType)style,
+                               NULL,
+                               x,
+                               y,
+                               w,
+                               h,
                                stdFont,
                                groupID,
-                               false
+                               true
                            );
 
     if(control==NULL)
@@ -127,6 +156,7 @@ bool wxControl::PalmCreateControl(ControlStyleType style,
 
     m_palmControl = true;
 
+    SetInitialSize(size);
     SetLabel(label);
     Show();
     return true;
@@ -137,28 +167,35 @@ bool wxControl::PalmCreateField(const wxString& label,
                                 const wxSize& size,
                                 bool editable,
                                 bool underlined,
-                                JustificationType justification)
+                                int justification)
 {
-    FormType* form = GetParentForm();
+    FormType* form = (FormType*)GetParentForm();
     if(form==NULL)
         return false;
 
     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(),
-                           ( pos.x == wxDefaultCoord ) ? winUndefConstraint : pos.x,
-                           ( pos.y == wxDefaultCoord ) ? winUndefConstraint : pos.y,
-                           ( size.x == wxDefaultCoord ) ? winUndefConstraint : size.x,
-                           ( size.y == wxDefaultCoord ) ? winUndefConstraint : size.y,
+                           x,
+                           y,
+                           w,
+                           h,
                            stdFont,
                            10,
                            editable,
                            underlined,
                            false,
                            false,
-                           justification,
+                           (JustificationType)justification,
                            false,
                            false,
                            false
@@ -169,8 +206,9 @@ bool wxControl::PalmCreateField(const wxString& label,
 
     m_palmField = true;
 
-    Show();
+    SetInitialSize(size);
     SetLabel(label);
+    Show();
     return true;
 }
 
@@ -178,7 +216,7 @@ bool wxControl::PalmCreateField(const wxString& label,
 // various accessors
 // ----------------------------------------------------------------------------
 
-FormType* wxControl::GetParentForm() const
+WXFORMPTR wxControl::GetParentForm() const
 {
     wxWindow* parentTLW = GetParent();
     while ( parentTLW && !parentTLW->IsTopLevel() )
@@ -191,19 +229,21 @@ FormType* wxControl::GetParentForm() const
     return tlw->GetForm();
 }
 
-uint16_t wxControl::GetObjectIndex() const
+WXFORMPTR wxControl::GetObjectFormIndex(uint16_t& index) const
 {
-    FormType* form = GetParentForm();
-    if(form==NULL)return frmInvalidObjectId;
-    return FrmGetObjectIndex(form, GetId());
+    FormType* form = (FormType* )GetParentForm();
+    if(form!=NULL)
+        index = FrmGetObjectIndex(form, GetId());
+    else
+        index = frmInvalidObjectId;
+    return form;
 }
 
 void* wxControl::GetObjectPtr() const
 {
-    FormType* form = GetParentForm();
-    if(form==NULL)return NULL;
-    uint16_t index = FrmGetObjectIndex(form, GetId());
-    if(index==frmInvalidObjectId)return NULL;
+    uint16_t index;
+    FormType* form = (FormType*)GetObjectFormIndex(index);
+    if(form==NULL || index==frmInvalidObjectId)return NULL;
     return FrmGetObjectPtr(form,index);
 }
 
@@ -217,7 +257,7 @@ wxBorder wxControl::GetDefaultBorder() const
 
 void wxControl::SetIntValue(int val)
 {
-    FormType* form = GetParentForm();
+    FormType* form = (FormType*)GetParentForm();
     if(form==NULL)
         return;
     uint16_t index = FrmGetObjectIndex(form, GetId());
@@ -233,7 +273,7 @@ void wxControl::SetBoolValue(bool val)
 
 bool wxControl::GetBoolValue() const
 {
-    FormType* form = GetParentForm();
+    FormType* form = (FormType*)GetParentForm();
     if(form==NULL)
         return false;
     uint16_t index = FrmGetObjectIndex(form, GetId());
@@ -247,41 +287,73 @@ wxSize wxControl::DoGetBestSize() const
     return wxSize(16, 16);
 }
 
-void wxControl::DoGetBounds( RectangleType &rect ) const
+void wxControl::DoGetBounds( WXRECTANGLEPTR rect ) const
 {
-    FormType* form = GetParentForm();
+    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,&rect);
+    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);
+    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);
+    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)
 {
     ControlType *control = (ControlType *)GetObjectPtr();
-    if( (IsPalmControl()) || (control == NULL))
+    if( !IsPalmControl() || (control == NULL))
         return false;
     if( CtlEnabled(control) == enable)
         return false;
@@ -292,7 +364,7 @@ bool wxControl::Enable(bool enable)
 bool wxControl::IsEnabled() const
 {
     ControlType *control = (ControlType *)GetObjectPtr();
-    if( (IsPalmControl()) || (control == NULL))
+    if( !IsPalmControl() || (control == NULL))
         return false;
     return CtlEnabled(control);
 }
@@ -304,7 +376,7 @@ bool wxControl::IsShown() const
 
 bool wxControl::Show( bool show )
 {
-    FormType* form = GetParentForm();
+    FormType* form = (FormType*)GetParentForm();
     if(form==NULL)
         return false;
     uint16_t index = FrmGetObjectIndex(form,GetId());
@@ -323,7 +395,7 @@ void wxControl::SetFieldLabel(const wxString& label)
     if(field==NULL)
         return;
 
-    uint16_t newSize = label.Length() + 1;
+    uint16_t newSize = label.length() + 1;
     MemHandle strHandle = FldGetTextHandle(field);
     FldSetTextHandle(field, NULL );
     if (strHandle)
@@ -353,7 +425,7 @@ void wxControl::SetControlLabel(const wxString& label)
     ControlType* control = (ControlType*)GetObjectPtr();
     if(control==NULL)
         return;
-    CtlSetLabel(control,wxEmptyString);
+    CtlSetLabel(control, "");
     m_label = label;
     if(!m_label.empty())
         CtlSetLabel(control,m_label.c_str());
@@ -384,7 +456,7 @@ wxString wxControl::GetControlLabel()
         return wxEmptyString;
     return CtlGetLabel(control);
 }
-
+#if 0
 wxString wxControl::GetLabel()
 {
     if(IsPalmField())
@@ -396,7 +468,7 @@ wxString wxControl::GetLabel()
 
     return wxEmptyString;
 }
-
+#endif
 /* static */ wxVisualAttributes
 wxControl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
 {
@@ -433,24 +505,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),
-                               WXUINT WXUNUSED(message),
-                               WXWPARAM WXUNUSED(wParam),
-                               WXLPARAM WXUNUSED(lParam)
-    )
-{
-    return (WXHBRUSH)0;
-}
-
-// ---------------------------------------------------------------------------
-// global functions
-// ---------------------------------------------------------------------------
-
 #endif // wxUSE_CONTROLS