// 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
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
if(m_control==NULL)
return false;
- form = FrmGetActiveForm ();
- m_objectIndex = FrmGetObjectIndex(form, id);
Show();
return true;
}
// 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,
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);
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))
{