From 9a727a3bb8d1ea77ef561b6fa4af05c7b5602595 Mon Sep 17 00:00:00 2001
From: =?utf8?q?W=C5=82odzimierz=20Skiba?= <abx@abx.art.pl>
Date: Tue, 1 Feb 2005 09:58:58 +0000
Subject: [PATCH] Further cleaning of the wxPalmOS radiobox code. Sending
 update event from slider. New styles for wxRadioBox and wxRadioButton for
 using alternative appearance of the control.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31690 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 include/wx/chkconf.h         | 12 +++++++---
 include/wx/defs.h            |  5 ++++
 include/wx/palmos/radiobox.h | 14 +----------
 include/wx/palmos/setup0.h   |  2 +-
 include/wx/palmos/slider.h   |  3 +++
 src/palmos/control.cpp       | 13 ++++++++---
 src/palmos/radiobox.cpp      | 45 ------------------------------------
 src/palmos/radiobut.cpp      |  4 ++++
 src/palmos/slider.cpp        | 12 ++++++++++
 src/palmos/toplevel.cpp      |  5 ++++
 10 files changed, 50 insertions(+), 65 deletions(-)

diff --git a/include/wx/chkconf.h b/include/wx/chkconf.h
index 6a51a7ad71..5ff16d4f32 100644
--- a/include/wx/chkconf.h
+++ b/include/wx/chkconf.h
@@ -1546,13 +1546,19 @@
 #endif
 
 #if wxUSE_RADIOBOX
-#   if !wxUSE_RADIOBTN || !wxUSE_STATBOX
+#   if !wxUSE_RADIOBTN
 #        ifdef wxABORT_ON_CONFIG_ERROR
-#            error "wxUSE_RADIOBOX requires wxUSE_RADIOBTN and wxUSE_STATBOX"
+#            error "wxUSE_RADIOBOX requires wxUSE_RADIOBTN"
 #        else
 #            undef wxUSE_RADIOBTN
-#            undef wxUSE_STATBOX
 #            define wxUSE_RADIOBTN 1
+#        endif
+#   endif
+#   if !wxUSE_STATBOX && !defined(__WXPALMOS__)
+#        ifdef wxABORT_ON_CONFIG_ERROR
+#            error "wxUSE_RADIOBOX requires wxUSE_STATBOX"
+#        else
+#            undef wxUSE_STATBOX
 #            define wxUSE_STATBOX 1
 #        endif
 #   endif
diff --git a/include/wx/defs.h b/include/wx/defs.h
index 786b6af3cc..32572213e6 100644
--- a/include/wx/defs.h
+++ b/include/wx/defs.h
@@ -1419,11 +1419,16 @@ enum wxBorder
 #define wxRA_HORIZONTAL     wxHORIZONTAL
 #define wxRA_VERTICAL       wxVERTICAL
 
+/*  Use alternative object for single control */
+
+#define wxRA_USE_SUBSTITUTE 0x0010
+
 /*
  * wxRadioButton style flag
  */
 #define wxRB_GROUP          0x0004
 #define wxRB_SINGLE         0x0008
+#define wxRB_USE_SUBSTITUTE 0x0010
 
 /*
  * wxSlider flags
diff --git a/include/wx/palmos/radiobox.h b/include/wx/palmos/radiobox.h
index 043faa661f..11eef5e47f 100644
--- a/include/wx/palmos/radiobox.h
+++ b/include/wx/palmos/radiobox.h
@@ -68,6 +68,7 @@ public:
                 long style = wxRA_HORIZONTAL,
                 const wxValidator& val = wxDefaultValidator,
                 const wxString& name = wxRadioBoxNameStr);
+
     bool Create(wxWindow *parent,
                 wxWindowID id,
                 const wxString& title,
@@ -104,17 +105,8 @@ public:
     // implementation only from now on
     // -------------------------------
 
-    // FIXME: are they used? missing "Do" prefix?
-    void GetSize(int *x, int *y) const;
-    void GetPosition(int *x, int *y) const;
-
     virtual bool SetFont(const wxFont& font);
 
-    virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
-                                WXUINT message,
-                                WXWPARAM wParam, WXLPARAM lParam);
-    WXHWND *GetRadioButtons() const { return m_radioButtons; }
-    bool ContainsHWND(WXHWND hWnd) const;
     void SendNotificationEvent();
 
     // get the number of buttons per column/row
@@ -128,16 +120,12 @@ protected:
     // we can't compute our best size before the items are added to the control
     virtual void SetInitialBestSize(const wxSize& WXUNUSED(size)) { }
 
-    // subclass one radio button
-    void SubclassRadioButton(WXHWND hWndBtn);
-
     // get the max size of radio buttons
     wxSize GetMaxButtonSize() const;
 
     // get the total size occupied by the radio box buttons
     wxSize GetTotalButtonSize(const wxSize& sizeBtn) const;
 
-    WXHWND *          m_radioButtons;
     int               m_majorDim;
     int *             m_radioWidth;  // for bitmaps
     int *             m_radioHeight;
diff --git a/include/wx/palmos/setup0.h b/include/wx/palmos/setup0.h
index 70906e6031..6a2dd44c5c 100644
--- a/include/wx/palmos/setup0.h
+++ b/include/wx/palmos/setup0.h
@@ -520,7 +520,7 @@
 #define wxUSE_GAUGE        0    // wxGauge
 #define wxUSE_LISTBOX      0    // wxListBox
 #define wxUSE_LISTCTRL     0    // wxListCtrl
-#define wxUSE_RADIOBOX     0    // wxRadioBox
+#define wxUSE_RADIOBOX     1    // wxRadioBox
 #define wxUSE_RADIOBTN     1    // wxRadioButton
 #define wxUSE_SCROLLBAR    0    // wxScrollBar
 #define wxUSE_SLIDER       1    // wxSlider
diff --git a/include/wx/palmos/slider.h b/include/wx/palmos/slider.h
index 63d7b1ccdf..187e258d89 100644
--- a/include/wx/palmos/slider.h
+++ b/include/wx/palmos/slider.h
@@ -70,6 +70,9 @@ public:
     // implementation
     void Command(wxCommandEvent& event);
 
+    // send a notification event, return true if processed
+    bool SendUpdatedEvent();
+
 protected:
     virtual wxSize DoGetBestSize() const;
 
diff --git a/src/palmos/control.cpp b/src/palmos/control.cpp
index 54b61fd862..88fd6fac82 100644
--- a/src/palmos/control.cpp
+++ b/src/palmos/control.cpp
@@ -72,6 +72,7 @@ void wxControl::Init()
 
 wxControl::~wxControl()
 {
+    SetLabel(wxEmptyString);
     m_isBeingDeleted = true;
 }
 
@@ -107,13 +108,11 @@ bool wxControl::PalmCreateControl(ControlStyleType style,
     if(form==NULL)
         return false;
 
-    m_label = label;
-
     ControlType *control = CtlNewControl(
                                (void **)&form,
                                GetId(),
                                style,
-                               m_label.c_str(),
+                               wxEmptyString,
                                ( pos.x == wxDefaultCoord ) ? winUndefConstraint : pos.x,
                                ( pos.y == wxDefaultCoord ) ? winUndefConstraint : pos.y,
                                ( size.x == wxDefaultCoord ) ? winUndefConstraint : size.x,
@@ -128,6 +127,7 @@ bool wxControl::PalmCreateControl(ControlStyleType style,
 
     m_palmControl = true;
 
+    SetLabel(label);
     Show();
     return true;
 }
@@ -350,6 +350,13 @@ void wxControl::SetFieldLabel(const wxString& label)
 
 void wxControl::SetControlLabel(const wxString& label)
 {
+    ControlType* control = (ControlType*)GetObjectPtr();
+    if(control==NULL)
+        return;
+    CtlSetLabel(control,wxEmptyString);
+    m_label = label;
+    if(!m_label.empty())
+        CtlSetLabel(control,m_label.c_str());
 }
 
 void wxControl::SetLabel(const wxString& label)
diff --git a/src/palmos/radiobox.cpp b/src/palmos/radiobox.cpp
index d6ead07206..adc3f453bb 100644
--- a/src/palmos/radiobox.cpp
+++ b/src/palmos/radiobox.cpp
@@ -38,8 +38,6 @@
     #include "wx/log.h"
 #endif
 
-#include "wx/palmos/private.h"
-
 #if wxUSE_TOOLTIPS
     #include "wx/tooltip.h"
 #endif // wxUSE_TOOLTIPS
@@ -102,19 +100,6 @@ IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl)
         item
 */
 
-#define RADIOBTN_PARENT_IS_RADIOBOX 0
-
-// ---------------------------------------------------------------------------
-// private functions
-// ---------------------------------------------------------------------------
-
-// ---------------------------------------------------------------------------
-// global vars
-// ---------------------------------------------------------------------------
-
-// the pointer to standard radio button wnd proc
-static WXFARPROC s_wndprocRadioBtn = (WXFARPROC)NULL;
-
 // ===========================================================================
 // implementation
 // ===========================================================================
@@ -234,14 +219,6 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
 {
 }
 
-void wxRadioBox::GetSize(int *width, int *height) const
-{
-}
-
-void wxRadioBox::GetPosition(int *x, int *y) const
-{
-}
-
 void wxRadioBox::SetFocus()
 {
 }
@@ -267,19 +244,10 @@ void wxRadioBox::Show(int item, bool show)
 {
 }
 
-bool wxRadioBox::ContainsHWND(WXHWND hWnd) const
-{
-    return false;
-}
-
 void wxRadioBox::Command(wxCommandEvent & event)
 {
 }
 
-void wxRadioBox::SubclassRadioButton(WXHWND hWndBtn)
-{
-}
-
 void wxRadioBox::SendNotificationEvent()
 {
 }
@@ -289,17 +257,4 @@ bool wxRadioBox::SetFont(const wxFont& font)
     return false;
 }
 
-// ----------------------------------------------------------------------------
-// our window proc
-// ----------------------------------------------------------------------------
-
-WXHBRUSH wxRadioBox::OnCtlColor(WXHDC pDC, WXHWND WXUNUSED(pWnd), WXUINT WXUNUSED(nCtlColor),
-                               WXUINT WXUNUSED(message),
-                               WXWPARAM WXUNUSED(wParam),
-                               WXLPARAM WXUNUSED(lParam)
-    )
-{
-    return (WXHBRUSH)0;
-}
-
 #endif // wxUSE_RADIOBOX
diff --git a/src/palmos/radiobut.cpp b/src/palmos/radiobut.cpp
index fe3a1845ee..3a344102aa 100644
--- a/src/palmos/radiobut.cpp
+++ b/src/palmos/radiobut.cpp
@@ -114,6 +114,10 @@ bool wxRadioButton::Create(wxWindow *parent,
                            const wxValidator& validator,
                            const wxString& name)
 {
+    // replace native push button with native checkbox
+    if ( style & wxRB_USE_SUBSTITUTE )
+        m_radioStyle = checkboxCtl;
+
     if(!wxControl::Create(parent, id, pos, size, style, validator, name))
         return false;
 
diff --git a/src/palmos/slider.cpp b/src/palmos/slider.cpp
index b638ca961e..ccc69ab7d7 100644
--- a/src/palmos/slider.cpp
+++ b/src/palmos/slider.cpp
@@ -251,6 +251,18 @@ void wxSlider::SetTick(int tickPos)
 {
 }
 
+// ----------------------------------------------------------------------------
+// helpers
+// ----------------------------------------------------------------------------
+
+bool wxSlider::SendUpdatedEvent()
+{
+    wxCommandEvent event(wxEVT_COMMAND_SLIDER_UPDATED, GetId());
+    event.SetEventObject(this);
+    event.SetInt(GetValue());
+    return ProcessCommand(event);
+}
+
 void wxSlider::Command (wxCommandEvent & event)
 {
 }
diff --git a/src/palmos/toplevel.cpp b/src/palmos/toplevel.cpp
index 78e34bc01f..2ff38362b7 100644
--- a/src/palmos/toplevel.cpp
+++ b/src/palmos/toplevel.cpp
@@ -47,6 +47,7 @@
 #include "wx/checkbox.h"
 #include "wx/radiobut.h"
 #include "wx/tglbtn.h"
+#include "wx/slider.h"
 
 // ----------------------------------------------------------------------------
 // globals
@@ -268,6 +269,10 @@ bool wxTopLevelWindowPalm::HandleControlSelect(EventType* event)
     if(radio)
         return radio->SendClickEvent();
 
+    wxSlider* slider = wxDynamicCast(win,wxSlider);
+    if(slider)
+        return slider->SendUpdatedEvent();
+
     return false;
 }
 
-- 
2.47.2