From 808e3bce622d9ec7ae8c43581472ae699ed47221 Mon Sep 17 00:00:00 2001
From: =?utf8?q?W=C5=82odzimierz=20Skiba?= <abx@abx.art.pl>
Date: Fri, 28 Jan 2005 10:58:13 +0000
Subject: [PATCH] Use stock labels. Native wxRadioButton. Getting position and
 size for the controls. Getting size for wxTLW. Default size and position for
 wxButton according to l&f guidelines. Removed wxUSE_CTL3D from wxPalmOS port.
 Better font for controls.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31616 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 build/palmos/makefile        |  1 +
 docs/changes.txt             |  1 +
 include/wx/palmos/control.h  |  8 +++++-
 include/wx/palmos/radiobut.h |  9 ++-----
 include/wx/palmos/setup0.h   |  2 +-
 include/wx/palmos/toplevel.h |  5 +++-
 include/wx/radiobut.h        |  2 ++
 src/common/stockitem.cpp     |  4 +--
 src/palmos/button.cpp        | 52 +++++++++++++++++++++++++++++++++---
 src/palmos/control.cpp       | 42 ++++++++++++++++++++++++-----
 src/palmos/dialog.cpp        | 16 -----------
 src/palmos/radiobox.cpp      |  6 -----
 src/palmos/radiobut.cpp      | 17 +++++-------
 src/palmos/textctrl.cpp      |  6 -----
 src/palmos/toplevel.cpp      | 14 ++++++++--
 15 files changed, 121 insertions(+), 64 deletions(-)

diff --git a/build/palmos/makefile b/build/palmos/makefile
index a7d4ff8a31..15b2192563 100644
--- a/build/palmos/makefile
+++ b/build/palmos/makefile
@@ -151,6 +151,7 @@ SOURCES =  ../../samples/minimal/minimal.cpp \
 ../../src/common/sizer.cpp \
 ../../src/common/socket.cpp \
 ../../src/common/statbar.cpp \
+../../src/common/stockitem.cpp \
 ../../src/common/strconv.cpp \
 ../../src/common/stream.cpp \
 ../../src/common/string.cpp \
diff --git a/docs/changes.txt b/docs/changes.txt
index 161058e300..f10bfdee64 100644
--- a/docs/changes.txt
+++ b/docs/changes.txt
@@ -118,6 +118,7 @@ wxPalmOS:
 - native wxCheckBox implementation
 - native wxSlider implementation
 - native wxToggleButton implementation
+- native wxRadioButton implementation
 
 
 2.5.3
diff --git a/include/wx/palmos/control.h b/include/wx/palmos/control.h
index c3dc2f6ffb..99db04e3e0 100644
--- a/include/wx/palmos/control.h
+++ b/include/wx/palmos/control.h
@@ -89,6 +89,10 @@ protected:
     // return default best size (doesn't really make any sense, override this)
     virtual wxSize DoGetBestSize() const;
 
+    // getting and setting sizes
+    virtual void DoGetPosition( int *x, int *y ) const;
+    virtual void DoGetSize( int *width, int *height ) const;
+
     // create the control of the given ControlStyleType: this is typically called
     // from Create() method of the derived class passing its label, pos and
     // size parameter (style parameter is not needed because m_windowStyle is
@@ -117,7 +121,9 @@ protected:
 
 private:
 
-    // Label stores label in case of wxButton, wxCheckBox, wxToggleButton etc.
+    virtual void DoGetBounds( RectangleType &rect ) const;
+
+    // m_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
diff --git a/include/wx/palmos/radiobut.h b/include/wx/palmos/radiobut.h
index 954295f422..90ffc63c18 100644
--- a/include/wx/palmos/radiobut.h
+++ b/include/wx/palmos/radiobut.h
@@ -2,10 +2,10 @@
 // Name:        wx/palmos/radiobut.h
 // Purpose:     wxRadioButton class
 // Author:      William Osborne - minimal working wxPalmOS port
-// Modified by:
+// Modified by: Wlodzimierz ABX Skiba - native wxRadioButton implementation
 // Created:     10/13/04
 // RCS-ID:      $Id$
-// Copyright:   (c) William Osborne
+// Copyright:   (c) William Osborne, Wlodzimierz Skiba
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
@@ -50,7 +50,6 @@ public:
     virtual bool GetValue() const;
 
     // implementation only from now on
-    virtual bool MSWCommand(WXUINT param, WXWORD id);
     virtual void Command(wxCommandEvent& event);
     virtual void ApplyParentThemeBackground(const wxColour& bg)
         { SetBackgroundColour(bg); }
@@ -63,10 +62,6 @@ private:
     // common part of all ctors
     void Init();
 
-    // we need to store the state internally as the result of GetValue()
-    // sometimes gets out of sync in WM_COMMAND handler
-    bool m_isChecked;
-
     DECLARE_DYNAMIC_CLASS_NO_COPY(wxRadioButton)
 };
 
diff --git a/include/wx/palmos/setup0.h b/include/wx/palmos/setup0.h
index c268fc861c..eafc44cfbb 100644
--- a/include/wx/palmos/setup0.h
+++ b/include/wx/palmos/setup0.h
@@ -521,7 +521,7 @@
 #define wxUSE_LISTBOX      0    // wxListBox
 #define wxUSE_LISTCTRL     0    // wxListCtrl
 #define wxUSE_RADIOBOX     0    // wxRadioBox
-#define wxUSE_RADIOBTN     0    // wxRadioButton
+#define wxUSE_RADIOBTN     1    // wxRadioButton
 #define wxUSE_SCROLLBAR    0    // wxScrollBar
 #define wxUSE_SLIDER       1    // wxSlider
 #define wxUSE_SPINBTN      0    // wxSpinButton
diff --git a/include/wx/palmos/toplevel.h b/include/wx/palmos/toplevel.h
index f53a646cff..143863c62a 100644
--- a/include/wx/palmos/toplevel.h
+++ b/include/wx/palmos/toplevel.h
@@ -82,12 +82,15 @@ public:
     wxWindow *GetLastFocus() const { return m_winLastFocused; }
 
     // interface to native frame structure
-    FormType *GetForm();
+    FormType *GetForm() const;
 
 protected:
     // common part of all ctors
     void Init();
 
+    // getting and setting sizes
+    virtual void DoGetSize( int *width, int *height ) const;
+
     // common part of Iconize(), Maximize() and Restore()
     void DoShowWindow(int nShowCmd);
 
diff --git a/include/wx/radiobut.h b/include/wx/radiobut.h
index 5b086935e5..4485b1cc3f 100644
--- a/include/wx/radiobut.h
+++ b/include/wx/radiobut.h
@@ -47,6 +47,8 @@ extern WXDLLEXPORT_DATA(const wxChar*) wxRadioButtonNameStr;
     #include "wx/cocoa/radiobut.h"
 #elif defined(__WXPM__)
     #include "wx/os2/radiobut.h"
+#elif defined(__WXPALMOS__)
+    #include "wx/palmos/radiobut.h"
 #endif
 
 #endif // wxUSE_RADIOBTN
diff --git a/src/common/stockitem.cpp b/src/common/stockitem.cpp
index 1a75aed568..5f4bc508ba 100644
--- a/src/common/stockitem.cpp
+++ b/src/common/stockitem.cpp
@@ -30,7 +30,7 @@
 
 #include "wx/stockitem.h"
 #include "wx/intl.h"
-
+#include "wx/utils.h" // for wxStripMenuCodes()
 
 bool wxIsStockID(wxWindowID id)
 {
@@ -95,7 +95,7 @@ bool wxIsStockID(wxWindowID id)
 
 wxString wxGetStockLabel(wxWindowID id)
 {
-#ifdef __SMARTPHONE__
+#if defined(__SMARTPHONE__) || defined(__WXPALMOS__)
     #define STOCKITEM(stockid, label) \
         case stockid:                 \
             return wxStripMenuCodes(label);
diff --git a/src/palmos/button.cpp b/src/palmos/button.cpp
index a53ae3f19a..17baee2123 100644
--- a/src/palmos/button.cpp
+++ b/src/palmos/button.cpp
@@ -38,6 +38,9 @@
     #include "wx/bmpbuttn.h"
     #include "wx/settings.h"
     #include "wx/dcscreen.h"
+    #include "wx/frame.h"
+    #include "wx/dialog.h"
+    #include "wx/stockitem.h"
 #endif
 
 // ----------------------------------------------------------------------------
@@ -126,7 +129,48 @@ bool wxButton::Create(wxWindow *parent,
                       const wxValidator& validator,
                       const wxString& name)
 {
-    wxControl::PalmCreateControl(buttonCtl, parent, id, label, pos, size);
+    // Default coordinates based on the knowledgebase recipe "Buttons"
+    wxSize palmSize(size.x==wxDefaultCoord?36:size.x,
+                    size.y==wxDefaultCoord?12:size.y);
+
+    // Default placement depends on dialog vs. frame type of parent
+    wxPoint palmPos(pos);
+    if((palmPos.x==wxDefaultCoord)||(palmPos.y==wxDefaultCoord))
+    {
+        wxSize parentSize(parent->GetSize());
+        wxWindow* parentTLW = parent;
+        while ( parentTLW && !parentTLW->IsTopLevel() )
+        {
+            parentTLW = parentTLW->GetParent();
+        }
+
+        if(wxDynamicCast(parentTLW, wxFrame)!=NULL)
+        {
+            if(palmPos.x==wxDefaultCoord)
+                palmPos.x = 1;
+            if(palmPos.y==wxDefaultCoord)
+                palmPos.y = parentSize.y-palmSize.y;
+        }
+        else if(wxDynamicCast(parentTLW, wxDialog)!=NULL)
+        {
+            if(palmPos.x==wxDefaultCoord)
+                palmPos.x = 5;
+            if(palmPos.y==wxDefaultCoord)
+                palmPos.y = parentSize.y-palmSize.y-5;
+        }
+        else
+        {
+            // something seriously broken
+            return false;
+        }
+    }
+
+    // take the stock label
+    wxString palmLabel = label;
+    if( palmLabel.empty() && wxIsStockID(id) )
+        palmLabel = wxGetStockLabel(id);
+
+    wxControl::PalmCreateControl(buttonCtl, parent, id, palmLabel, palmPos, palmSize);
     return true;
 }
 
@@ -140,13 +184,13 @@ wxButton::~wxButton()
 
 wxSize wxButton::DoGetBestSize() const
 {
-    return wxSize(0,0);
+    return wxSize(36,12);
 }
 
 /* static */
 wxSize wxButtonBase::GetDefaultSize()
 {
-    return wxSize(0,0);
+    return wxSize(36,12);
 }
 
 void wxButton::SetDefault()
@@ -180,7 +224,7 @@ bool wxButton::SendClickEvent()
     return false;
 }
 
-void wxButton::Command(wxCommandEvent & event)
+void wxButton::Command(wxCommandEvent &event)
 {
 }
 
diff --git a/src/palmos/control.cpp b/src/palmos/control.cpp
index 25fcb3225e..b5a89e8932 100644
--- a/src/palmos/control.cpp
+++ b/src/palmos/control.cpp
@@ -43,6 +43,7 @@
 #include "wx/button.h"
 #include "wx/checkbox.h"
 #include "wx/tglbtn.h"
+#include "wx/radiobut.h"
 
 // ----------------------------------------------------------------------------
 // wxWin macros
@@ -113,7 +114,7 @@ bool wxControl::PalmCreateControl(ControlStyleType style,
                     ( pos.y == wxDefaultCoord ) ? winUndefConstraint : pos.y,
                     ( size.x == wxDefaultCoord ) ? winUndefConstraint : size.x,
                     ( size.y == wxDefaultCoord ) ? winUndefConstraint : size.y,
-                    boldFont,
+                    stdFont,
                     0,
                     false
                 );
@@ -182,6 +183,37 @@ wxSize wxControl::DoGetBestSize() const
     return wxSize(16, 16);
 }
 
+void wxControl::DoGetBounds( RectangleType &rect ) const
+{
+    FormType* form = GetParentForm();
+    if(form==NULL)
+        return;
+    uint16_t index = FrmGetObjectIndex(form,GetId());
+    if(index==frmInvalidObjectId)
+        return;
+    FrmGetObjectBounds(form,index,&rect);
+}
+
+void wxControl::DoGetPosition( int *x, int *y ) const
+{
+    RectangleType rect;
+    DoGetBounds(rect);
+    if(x)
+        *x = rect.topLeft.x;
+    if(y)
+        *y = rect.topLeft.y;
+}
+
+void wxControl::DoGetSize( int *width, int *height ) const
+{
+    RectangleType rect;
+    DoGetBounds(rect);
+    if(width)
+        *width = rect.extent.x;
+    if(height)
+        *height = rect.extent.y;
+}
+
 bool wxControl::Enable(bool enable)
 {
     if( m_control == NULL )
@@ -224,6 +256,7 @@ void wxControl::SetLabel(const wxString& label)
     // setting in wrong control causes crash
     if ( ( wxDynamicCast(this,wxButton) != NULL ) ||
          ( wxDynamicCast(this,wxCheckBox) != NULL ) ||
+         ( wxDynamicCast(this,wxRadioButton) != NULL ) ||
          ( wxDynamicCast(this,wxToggleButton) != NULL ) )
     {
         m_label = label;
@@ -238,6 +271,7 @@ wxString wxControl::GetLabel()
     // setting in wrong control causes crash
     if ( wxDynamicCast(this,wxButton) ||
          wxDynamicCast(this,wxCheckBox) ||
+         wxDynamicCast(this,wxRadioButton) ||
          wxDynamicCast(this,wxToggleButton) )
     {
         return m_label;
@@ -290,15 +324,9 @@ void wxControl::OnEraseBackground(wxEraseEvent& event)
 }
 
 WXHBRUSH wxControl::OnCtlColor(WXHDC pDC, WXHWND WXUNUSED(pWnd), WXUINT WXUNUSED(nCtlColor),
-#if wxUSE_CTL3D
-                               WXUINT message,
-                               WXWPARAM wParam,
-                               WXLPARAM lParam
-#else
                                WXUINT WXUNUSED(message),
                                WXWPARAM WXUNUSED(wParam),
                                WXLPARAM WXUNUSED(lParam)
-#endif
     )
 {
     return (WXHBRUSH)0;
diff --git a/src/palmos/dialog.cpp b/src/palmos/dialog.cpp
index 1b415a9465..c014f4ac35 100644
--- a/src/palmos/dialog.cpp
+++ b/src/palmos/dialog.cpp
@@ -247,19 +247,3 @@ WXLRESULT wxDialog::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lPar
 {
     return false;
 }
-
-#if wxUSE_CTL3D
-
-// Define for each class of dialog and control
-WXHBRUSH wxDialog::OnCtlColor(WXHDC WXUNUSED(pDC),
-                              WXHWND WXUNUSED(pWnd),
-                              WXUINT WXUNUSED(nCtlColor),
-                              WXUINT message,
-                              WXWPARAM wParam,
-                              WXLPARAM lParam)
-{
-    return (WXHBRUSH)Ctl3dCtlColorEx(message, wParam, lParam);
-}
-
-#endif // wxUSE_CTL3D
-
diff --git a/src/palmos/radiobox.cpp b/src/palmos/radiobox.cpp
index 606509e649..152fbc7a31 100644
--- a/src/palmos/radiobox.cpp
+++ b/src/palmos/radiobox.cpp
@@ -304,15 +304,9 @@ WXLRESULT wxRadioBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara
 }
 
 WXHBRUSH wxRadioBox::OnCtlColor(WXHDC pDC, WXHWND WXUNUSED(pWnd), WXUINT WXUNUSED(nCtlColor),
-#if wxUSE_CTL3D
-                               WXUINT message,
-                               WXWPARAM wParam,
-                               WXLPARAM lParam
-#else
                                WXUINT WXUNUSED(message),
                                WXWPARAM WXUNUSED(wParam),
                                WXLPARAM WXUNUSED(lParam)
-#endif
     )
 {
     return (WXHBRUSH)0;
diff --git a/src/palmos/radiobut.cpp b/src/palmos/radiobut.cpp
index 20135cce58..d7c45e609b 100644
--- a/src/palmos/radiobut.cpp
+++ b/src/palmos/radiobut.cpp
@@ -2,10 +2,10 @@
 // Name:        src/palmos/radiobut.cpp
 // Purpose:     wxRadioButton
 // Author:      William Osborne - minimal working wxPalmOS port
-// Modified by:
+// Modified by: Wlodzimierz ABX Skiba - native wxRadioButton implementation
 // Created:     10/13/04
 // RCS-ID:      $Id$
-// Copyright:   (c) William Osborne
+// Copyright:   (c) William Osborne, Wlodzimierz Skiba
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
@@ -36,8 +36,6 @@
     #include "wx/dcscreen.h"
 #endif
 
-#include "wx/palmos/private.h"
-
 // ============================================================================
 // wxRadioButton implementation
 // ============================================================================
@@ -115,7 +113,8 @@ bool wxRadioButton::Create(wxWindow *parent,
                            const wxValidator& validator,
                            const wxString& name)
 {
-    return false;
+    wxControl::PalmCreateControl(pushButtonCtl, parent, id, label, pos, size);
+    return true;
 }
 
 // ----------------------------------------------------------------------------
@@ -124,11 +123,12 @@ bool wxRadioButton::Create(wxWindow *parent,
 
 void wxRadioButton::SetValue(bool value)
 {
+    SetBoolValue(value);
 }
 
 bool wxRadioButton::GetValue() const
 {
-    return false;
+    return GetBoolValue();
 }
 
 // ----------------------------------------------------------------------------
@@ -139,11 +139,6 @@ void wxRadioButton::Command (wxCommandEvent& event)
 {
 }
 
-bool wxRadioButton::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
-{
-    return false;
-}
-
 // ----------------------------------------------------------------------------
 // wxRadioButton geometry
 // ----------------------------------------------------------------------------
diff --git a/src/palmos/textctrl.cpp b/src/palmos/textctrl.cpp
index c7d62851d3..8e4bf4b8c6 100644
--- a/src/palmos/textctrl.cpp
+++ b/src/palmos/textctrl.cpp
@@ -568,15 +568,9 @@ bool wxTextCtrl::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
 }
 
 WXHBRUSH wxTextCtrl::OnCtlColor(WXHDC pDC, WXHWND WXUNUSED(pWnd), WXUINT WXUNUSED(nCtlColor),
-#if wxUSE_CTL3D
-                               WXUINT message,
-                               WXWPARAM wParam,
-                               WXLPARAM lParam
-#else
                                WXUINT WXUNUSED(message),
                                WXWPARAM WXUNUSED(wParam),
                                WXLPARAM WXUNUSED(lParam)
-#endif
     )
 {
     return (WXHBRUSH) 0;
diff --git a/src/palmos/toplevel.cpp b/src/palmos/toplevel.cpp
index 3f09270a6d..2a31a6b83e 100644
--- a/src/palmos/toplevel.cpp
+++ b/src/palmos/toplevel.cpp
@@ -186,6 +186,16 @@ void wxTopLevelWindowPalm::Restore()
 {
 }
 
+void wxTopLevelWindowPalm::DoGetSize( int *width, int *height ) const
+{
+    RectangleType rect;
+    FrmGetFormBounds( GetForm() , &rect );
+    if(width)
+        *width = rect.extent.x;
+    if(height)
+        *height = rect.extent.y;
+}
+
 // ----------------------------------------------------------------------------
 // wxTopLevelWindowPalm fullscreen
 // ----------------------------------------------------------------------------
@@ -212,9 +222,9 @@ bool wxTopLevelWindowPalm::EnableCloseButton(bool enable)
     return false;
 }
 
-FormType *wxTopLevelWindowPalm::GetForm()
+FormType *wxTopLevelWindowPalm::GetForm() const
 {
-    return FrmGetActiveForm ();
+    return FrmGetActiveForm();
 }
 
 #ifndef __WXWINCE__
-- 
2.47.2