From 8be10866cedb04e1072e411a094524d0efe98525 Mon Sep 17 00:00:00 2001 From: =?utf8?q?W=C5=82odzimierz=20Skiba?= Date: Tue, 8 Feb 2005 09:38:08 +0000 Subject: [PATCH 1/1] wxSlider event handling as described by Vadim in thread 'Slider events' at wx-dev. More changes towards wxRadioBox on Palm. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31852 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/palmos/control.h | 2 +- include/wx/palmos/radiobox.h | 8 ++--- include/wx/palmos/radiobut.h | 3 ++ include/wx/palmos/slider.h | 5 +-- src/palmos/control.cpp | 2 +- src/palmos/radiobox.cpp | 30 ++++++++++++++-- src/palmos/radiobut.cpp | 9 ++++- src/palmos/slider.cpp | 69 ++++++++++++------------------------ 8 files changed, 71 insertions(+), 57 deletions(-) diff --git a/include/wx/palmos/control.h b/include/wx/palmos/control.h index 08a1918e0e..edc21f7626 100644 --- a/include/wx/palmos/control.h +++ b/include/wx/palmos/control.h @@ -111,7 +111,7 @@ protected: const wxString& label, const wxPoint& pos, const wxSize& size, - int groupID = 0); + uint8_t groupID = 0); inline bool IsPalmControl() const { return m_palmControl; } bool PalmCreateField(const wxString& label, diff --git a/include/wx/palmos/radiobox.h b/include/wx/palmos/radiobox.h index 11eef5e47f..12ff7bac7c 100644 --- a/include/wx/palmos/radiobox.h +++ b/include/wx/palmos/radiobox.h @@ -34,7 +34,7 @@ public: const wxSize& size = wxDefaultSize, int n = 0, const wxString choices[] = NULL, int majorDim = 0, - long style = wxRA_HORIZONTAL, + long style = wxRA_SPECIFY_COLS, const wxValidator& val = wxDefaultValidator, const wxString& name = wxRadioBoxNameStr) { @@ -48,7 +48,7 @@ public: const wxSize& size, const wxArrayString& choices, int majorDim = 0, - long style = wxRA_HORIZONTAL, + long style = wxRA_SPECIFY_COLS, const wxValidator& val = wxDefaultValidator, const wxString& name = wxRadioBoxNameStr) { @@ -65,7 +65,7 @@ public: const wxSize& size = wxDefaultSize, int n = 0, const wxString choices[] = NULL, int majorDim = 0, - long style = wxRA_HORIZONTAL, + long style = wxRA_SPECIFY_COLS, const wxValidator& val = wxDefaultValidator, const wxString& name = wxRadioBoxNameStr); @@ -76,7 +76,7 @@ public: const wxSize& size, const wxArrayString& choices, int majorDim = 0, - long style = wxRA_HORIZONTAL, + long style = wxRA_SPECIFY_COLS, const wxValidator& val = wxDefaultValidator, const wxString& name = wxRadioBoxNameStr); diff --git a/include/wx/palmos/radiobut.h b/include/wx/palmos/radiobut.h index 120e940d93..db4746f1d3 100644 --- a/include/wx/palmos/radiobut.h +++ b/include/wx/palmos/radiobut.h @@ -51,6 +51,7 @@ public: // implementation only from now on virtual void Command(wxCommandEvent& event); + void SetGroup(uint8_t group); // send a notification event, return true if processed bool SendClickEvent(); @@ -66,6 +67,8 @@ private: // common part of all ctors void Init(); + uint8_t m_groupID; + // pushButtonCtl or checkboxCtl ControlStyleType m_radioStyle; DECLARE_DYNAMIC_CLASS_NO_COPY(wxRadioButton) diff --git a/include/wx/palmos/slider.h b/include/wx/palmos/slider.h index 4b0053e234..b96e40ce15 100644 --- a/include/wx/palmos/slider.h +++ b/include/wx/palmos/slider.h @@ -85,8 +85,9 @@ protected: private: void Init(); - int m_oldPos; - int m_lineSize; + int m_oldPos; // needed for tracing thumb position during scrolling + int m_oldValue; // needed for comparing thumb position before and after scrolling + int m_lineSize; // imitate line size DECLARE_DYNAMIC_CLASS_NO_COPY(wxSlider) }; diff --git a/src/palmos/control.cpp b/src/palmos/control.cpp index b9bb06863e..0d68b27055 100644 --- a/src/palmos/control.cpp +++ b/src/palmos/control.cpp @@ -111,7 +111,7 @@ bool wxControl::PalmCreateControl(ControlStyleType style, const wxString& label, const wxPoint& pos, const wxSize& size, - int groupID) + uint8_t groupID) { FormType* form = GetParentForm(); if(form==NULL) diff --git a/src/palmos/radiobox.cpp b/src/palmos/radiobox.cpp index adc3f453bb..f592c79cd8 100644 --- a/src/palmos/radiobox.cpp +++ b/src/palmos/radiobox.cpp @@ -42,6 +42,8 @@ #include "wx/tooltip.h" #endif // wxUSE_TOOLTIPS +#include "wx/radiobut.h" + // TODO: wxCONSTRUCTOR #if 0 // wxUSE_EXTENDED_RTTI WX_DEFINE_FLAGS( wxRadioBoxStyle ) @@ -152,7 +154,28 @@ bool wxRadioBox::Create(wxWindow *parent, const wxValidator& val, const wxString& name) { - return false; + // initialize members + m_majorDim = majorDim == 0 ? n : majorDim; + + if(!wxControl::Create(parent, id, pos, size, style, val, name)) + return false; + + for(int i=0; iSetGroup( id ); + rb->Create( + this, + wxID_ANY, + choices[n], + pos, + size, + ( n == 0 ? wxRB_GROUP : 0 ) | + ( style & wxRA_USE_CHECKBOX ) ? wxRB_USE_CHECKBOX : 0 + ); + } + + SetSize(size); } bool wxRadioBox::Create(wxWindow *parent, @@ -166,7 +189,10 @@ bool wxRadioBox::Create(wxWindow *parent, const wxValidator& val, const wxString& name) { - return false; + wxCArrayString chs(choices); + + return Create( parent, id, title, pos, size, chs.GetCount(), + chs.GetStrings(), majorDim, style, val, name ); } wxRadioBox::~wxRadioBox() diff --git a/src/palmos/radiobut.cpp b/src/palmos/radiobut.cpp index e189985762..2e008218e0 100644 --- a/src/palmos/radiobut.cpp +++ b/src/palmos/radiobut.cpp @@ -103,6 +103,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl) void wxRadioButton::Init() { m_radioStyle = pushButtonCtl; + m_groupID = 0; } bool wxRadioButton::Create(wxWindow *parent, @@ -126,10 +127,16 @@ bool wxRadioButton::Create(wxWindow *parent, m_radioStyle == checkboxCtl ? checkboxCtl : pushButtonCtl, label, pos, - size + size, + m_groupID ); } +void wxRadioButton::SetGroup(uint8_t group) +{ + m_groupID = group; +} + // ---------------------------------------------------------------------------- // wxRadioButton functions // ---------------------------------------------------------------------------- diff --git a/src/palmos/slider.cpp b/src/palmos/slider.cpp index 94dcd78357..8c9b711b7c 100644 --- a/src/palmos/slider.cpp +++ b/src/palmos/slider.cpp @@ -100,7 +100,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl) // Slider void wxSlider::Init() { - m_oldPos = 0; + m_oldValue = m_oldPos = 0; m_lineSize = 1; } @@ -120,7 +120,7 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id, // wxSL_INVERSE is ignored - always off // wxSL_VERTICAL is impossible in native form wxCHECK_MSG(!(style & wxSL_VERTICAL), false, _T("non vertical slider on PalmOS")); - + if(!wxControl::Create(parent, id, pos, size, style, validator, name)) return false; @@ -128,7 +128,7 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id, if(form==NULL) return false; - m_oldPos = value; + m_oldValue = m_oldPos = value; SliderControlType *slider = CtlNewSliderControl ( (void **)&form, @@ -201,7 +201,7 @@ int wxSlider::GetValue() const void wxSlider::SetValue(int value) { SetIntValue(value); - m_oldPos = value; + m_oldValue = m_oldPos = value; } wxSize wxSlider::DoGetBestSize() const @@ -298,65 +298,42 @@ bool wxSlider::SendUpdatedEvent() { m_oldPos = GetValue(); - // first track event + // first thumb event wxScrollEvent eventWxTrack(wxEVT_SCROLL_THUMBRELEASE, GetId()); eventWxTrack.SetPosition(m_oldPos); eventWxTrack.SetEventObject(this); - GetEventHandler()->ProcessEvent(eventWxTrack); + bool handled = GetEventHandler()->ProcessEvent(eventWxTrack); + + // then slider event if position changed + if( m_oldValue != m_oldPos ) + { + m_oldValue = m_oldPos; + wxCommandEvent event(wxEVT_COMMAND_SLIDER_UPDATED, GetId()); + event.SetEventObject(this); + event.SetInt(m_oldPos); + return ProcessCommand(event); + } - // then scroll event - wxCommandEvent event(wxEVT_COMMAND_SLIDER_UPDATED, GetId()); - event.SetEventObject(this); - event.SetInt(m_oldPos); - return ProcessCommand(event); + return handled; } bool wxSlider::SendScrollEvent(EventType* event) { wxEventType scrollEvent; int newPos = event->data.ctlRepeat.value; - if ( newPos == GetMax() ) - { - scrollEvent = wxEVT_SCROLL_TOP; - } - else if ( newPos == GetMin() ) - { - scrollEvent = wxEVT_SCROLL_BOTTOM; - } - else if ( newPos == ( m_oldPos + GetLineSize() ) ) - { - scrollEvent = wxEVT_SCROLL_LINEUP; - } - else if ( newPos == ( m_oldPos - GetLineSize() ) ) - { - scrollEvent = wxEVT_SCROLL_LINEDOWN; - } - else if ( newPos == ( m_oldPos + GetPageSize() ) ) - { - scrollEvent = wxEVT_SCROLL_PAGEUP; - } - else if ( newPos == ( m_oldPos - GetPageSize() ) ) - { - scrollEvent = wxEVT_SCROLL_PAGEDOWN; - } - else + if ( newPos == m_oldPos ) { + // nothing changed since last event return false; } m_oldPos = newPos; // first track event - wxScrollEvent eventWxTrack(wxEVT_SCROLL_THUMBTRACK, GetId()); - eventWxTrack.SetPosition(newPos); - eventWxTrack.SetEventObject(this); - GetEventHandler()->ProcessEvent(eventWxTrack); - - // then scroll event - wxScrollEvent eventWxScroll(scrollEvent, GetId()); - eventWxScroll.SetPosition(newPos); - eventWxScroll.SetEventObject(this); - return GetEventHandler()->ProcessEvent(eventWxScroll); + wxScrollEvent eventWx(wxEVT_SCROLL_THUMBTRACK, GetId()); + eventWx.SetPosition(newPos); + eventWx.SetEventObject(this); + return GetEventHandler()->ProcessEvent(eventWx); } void wxSlider::Command (wxCommandEvent & event) -- 2.47.2