From 789f6795165f19cd16f0ba9f799add6a92720454 Mon Sep 17 00:00:00 2001 From: =?utf8?q?W=C5=82odzimierz=20Skiba?= Date: Wed, 23 Feb 2005 16:39:25 +0000 Subject: [PATCH] Linup API of wxRadioBox::Show on all ports. Move wxRadioBox::IsValid from wxUniversal to base class (+ GTK which do not use base class) and use it where applicable. Minor source cleaning. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32325 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/cocoa/radiobox.h | 2 +- include/wx/ctrlsub.h | 5 +++++ include/wx/gtk/radiobox.h | 6 +++++- include/wx/gtk1/radiobox.h | 6 +++++- include/wx/motif/radiobox.h | 4 ++-- include/wx/msw/radiobox.h | 2 +- include/wx/radiobox.h | 2 +- src/cocoa/radiobox.mm | 4 +++- src/gtk/radiobox.cpp | 18 ++++++++++-------- src/gtk1/radiobox.cpp | 18 ++++++++++-------- src/motif/radiobox.cpp | 18 ++++++++++-------- src/msw/radiobox.cpp | 21 ++++++++++++--------- 12 files changed, 65 insertions(+), 41 deletions(-) diff --git a/include/wx/cocoa/radiobox.h b/include/wx/cocoa/radiobox.h index f7bb99c4e4..13c2391dbc 100644 --- a/include/wx/cocoa/radiobox.h +++ b/include/wx/cocoa/radiobox.h @@ -90,7 +90,7 @@ public: virtual void SetString(int n, const wxString& label); // change the individual radio button state virtual bool Enable(int n, bool enable = true); - virtual void Show(int n, bool show = true); + virtual bool Show(int n, bool show = true); // layout parameters virtual int GetColumnCount() const; virtual int GetRowCount() const; diff --git a/include/wx/ctrlsub.h b/include/wx/ctrlsub.h index 1736c324e6..c7cddfe660 100644 --- a/include/wx/ctrlsub.h +++ b/include/wx/ctrlsub.h @@ -65,6 +65,11 @@ public: // reads better for multi-selection ones void Select(int n) { SetSelection(n); } + +protected: + + // check that the index is valid + inline bool IsValid(int n) const { return n >= 0 && n < GetCount(); } }; class WXDLLEXPORT wxItemContainer : public wxItemContainerImmutable diff --git a/include/wx/gtk/radiobox.h b/include/wx/gtk/radiobox.h index cf76a447e5..14fdae0c8b 100644 --- a/include/wx/gtk/radiobox.h +++ b/include/wx/gtk/radiobox.h @@ -87,7 +87,7 @@ public: wxString GetString( int n ) const; void SetString( int n, const wxString& label ); - void Show( int item, bool show ); + virtual bool Show( int item, bool show = true ); virtual bool Enable( int item, bool enable = true ); virtual wxString GetStringSelection() const; @@ -142,6 +142,10 @@ protected: // common part of all ctors void Init(); + // check that the index is valid + // FIXME: remove once GTK will derive from wxRadioBoxBase + inline bool IsValid(int n) const { return n >= 0 && n < GetCount(); } + private: DECLARE_DYNAMIC_CLASS(wxRadioBox) }; diff --git a/include/wx/gtk1/radiobox.h b/include/wx/gtk1/radiobox.h index cf76a447e5..14fdae0c8b 100644 --- a/include/wx/gtk1/radiobox.h +++ b/include/wx/gtk1/radiobox.h @@ -87,7 +87,7 @@ public: wxString GetString( int n ) const; void SetString( int n, const wxString& label ); - void Show( int item, bool show ); + virtual bool Show( int item, bool show = true ); virtual bool Enable( int item, bool enable = true ); virtual wxString GetStringSelection() const; @@ -142,6 +142,10 @@ protected: // common part of all ctors void Init(); + // check that the index is valid + // FIXME: remove once GTK will derive from wxRadioBoxBase + inline bool IsValid(int n) const { return n >= 0 && n < GetCount(); } + private: DECLARE_DYNAMIC_CLASS(wxRadioBox) }; diff --git a/include/wx/motif/radiobox.h b/include/wx/motif/radiobox.h index a37b8f6628..e9bd2dfbad 100644 --- a/include/wx/motif/radiobox.h +++ b/include/wx/motif/radiobox.h @@ -84,8 +84,8 @@ public: wxString GetString(int item) const; virtual bool Enable(bool enable = true); virtual bool Enable(int item, bool enable = true); - void Show(int item, bool show) ; - virtual bool Show(bool show = true) ; + virtual bool Show(int item, bool show = true); + virtual bool Show(bool show = true); virtual wxString GetStringSelection() const; virtual bool SetStringSelection(const wxString& s); diff --git a/include/wx/msw/radiobox.h b/include/wx/msw/radiobox.h index ac8dac414d..2658783a36 100644 --- a/include/wx/msw/radiobox.h +++ b/include/wx/msw/radiobox.h @@ -93,7 +93,7 @@ public: virtual wxString GetString(int n) const; virtual void SetString(int n, const wxString& label); virtual bool Enable(int n, bool enable = true); - virtual void Show(int n, bool show = true); + virtual bool Show(int n, bool show = true); virtual int GetColumnCount() const { return GetNumHor(); } virtual int GetRowCount() const { return GetNumVer(); } diff --git a/include/wx/radiobox.h b/include/wx/radiobox.h index 376de2c623..25fc92c152 100644 --- a/include/wx/radiobox.h +++ b/include/wx/radiobox.h @@ -33,7 +33,7 @@ class WXDLLEXPORT wxRadioBoxBase : public wxItemContainerImmutable public: // change the individual radio button state virtual bool Enable(int n, bool enable = true) = 0; - virtual void Show(int n, bool show = true) = 0; + virtual bool Show(int n, bool show = true) = 0; // layout parameters virtual int GetColumnCount() const = 0; diff --git a/src/cocoa/radiobox.mm b/src/cocoa/radiobox.mm index 1e807be0c6..5d04a08528 100644 --- a/src/cocoa/radiobox.mm +++ b/src/cocoa/radiobox.mm @@ -97,8 +97,10 @@ bool wxRadioBox::Enable(int n, bool enable) return false; } -void wxRadioBox::Show(int n, bool show) +bool wxRadioBox::Show(int n, bool show) { + // TODO + return false; } // layout parameters diff --git a/src/gtk/radiobox.cpp b/src/gtk/radiobox.cpp index eaff2e8e6c..1053519c93 100644 --- a/src/gtk/radiobox.cpp +++ b/src/gtk/radiobox.cpp @@ -435,7 +435,7 @@ bool wxRadioBox::Show( bool show ) int wxRadioBox::FindString( const wxString &find ) const { - wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid radiobox") ); + wxCHECK_MSG( m_widget != NULL, wxNOT_FOUND, wxT("invalid radiobox") ); int count = 0; @@ -456,7 +456,7 @@ int wxRadioBox::FindString( const wxString &find ) const node = node->GetNext(); } - return -1; + return wxNOT_FOUND; } void wxRadioBox::SetFocus() @@ -497,7 +497,7 @@ void wxRadioBox::SetSelection( int n ) int wxRadioBox::GetSelection(void) const { - wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid radiobox") ); + wxCHECK_MSG( m_widget != NULL, wxNOT_FOUND, wxT("invalid radiobox") ); int count = 0; @@ -512,7 +512,7 @@ int wxRadioBox::GetSelection(void) const wxFAIL_MSG( wxT("wxRadioBox none selected") ); - return -1; + return wxNOT_FOUND; } wxString wxRadioBox::GetString( int n ) const @@ -592,13 +592,13 @@ bool wxRadioBox::Enable( int item, bool enable ) return true; } -void wxRadioBox::Show( int item, bool show ) +bool wxRadioBox::Show( int item, bool show ) { - wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") ); + wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") ); wxList::compatibility_iterator node = m_boxes.Item( item ); - wxCHECK_RET( node, wxT("radiobox wrong index") ); + wxCHECK_MSG( node, false, wxT("radiobox wrong index") ); GtkWidget *button = GTK_WIDGET( node->GetData() ); @@ -606,6 +606,8 @@ void wxRadioBox::Show( int item, bool show ) gtk_widget_show( button ); else gtk_widget_hide( button ); + + return true; } wxString wxRadioBox::GetStringSelection() const @@ -639,7 +641,7 @@ bool wxRadioBox::SetStringSelection( const wxString &s ) wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") ); int res = FindString( s ); - if (res == -1) return false; + if (res == wxNOT_FOUND) return false; SetSelection( res ); return true; diff --git a/src/gtk1/radiobox.cpp b/src/gtk1/radiobox.cpp index eaff2e8e6c..1053519c93 100644 --- a/src/gtk1/radiobox.cpp +++ b/src/gtk1/radiobox.cpp @@ -435,7 +435,7 @@ bool wxRadioBox::Show( bool show ) int wxRadioBox::FindString( const wxString &find ) const { - wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid radiobox") ); + wxCHECK_MSG( m_widget != NULL, wxNOT_FOUND, wxT("invalid radiobox") ); int count = 0; @@ -456,7 +456,7 @@ int wxRadioBox::FindString( const wxString &find ) const node = node->GetNext(); } - return -1; + return wxNOT_FOUND; } void wxRadioBox::SetFocus() @@ -497,7 +497,7 @@ void wxRadioBox::SetSelection( int n ) int wxRadioBox::GetSelection(void) const { - wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid radiobox") ); + wxCHECK_MSG( m_widget != NULL, wxNOT_FOUND, wxT("invalid radiobox") ); int count = 0; @@ -512,7 +512,7 @@ int wxRadioBox::GetSelection(void) const wxFAIL_MSG( wxT("wxRadioBox none selected") ); - return -1; + return wxNOT_FOUND; } wxString wxRadioBox::GetString( int n ) const @@ -592,13 +592,13 @@ bool wxRadioBox::Enable( int item, bool enable ) return true; } -void wxRadioBox::Show( int item, bool show ) +bool wxRadioBox::Show( int item, bool show ) { - wxCHECK_RET( m_widget != NULL, wxT("invalid radiobox") ); + wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") ); wxList::compatibility_iterator node = m_boxes.Item( item ); - wxCHECK_RET( node, wxT("radiobox wrong index") ); + wxCHECK_MSG( node, false, wxT("radiobox wrong index") ); GtkWidget *button = GTK_WIDGET( node->GetData() ); @@ -606,6 +606,8 @@ void wxRadioBox::Show( int item, bool show ) gtk_widget_show( button ); else gtk_widget_hide( button ); + + return true; } wxString wxRadioBox::GetStringSelection() const @@ -639,7 +641,7 @@ bool wxRadioBox::SetStringSelection( const wxString &s ) wxCHECK_MSG( m_widget != NULL, false, wxT("invalid radiobox") ); int res = FindString( s ); - if (res == -1) return false; + if (res == wxNOT_FOUND) return false; SetSelection( res ); return true; diff --git a/src/motif/radiobox.cpp b/src/motif/radiobox.cpp index 2ddeee2d44..55234658d2 100644 --- a/src/motif/radiobox.cpp +++ b/src/motif/radiobox.cpp @@ -182,7 +182,7 @@ wxRadioBox::~wxRadioBox() void wxRadioBox::SetString(int item, const wxString& label) { - if (item < 0 || item >= m_noItems) + if (!IsValid(item)) return; Widget widget = (Widget) m_radioButtons[item]; @@ -204,12 +204,12 @@ int wxRadioBox::FindString(const wxString& s) const for (i = 0; i < m_noItems; i++) if (s == m_radioButtonLabels[i]) return i; - return -1; + return wxNOT_FOUND; } void wxRadioBox::SetSelection(int n) { - if ((n < 0) || (n >= m_noItems)) + if (!IsValid(n)) return; m_selectedButton = n; @@ -235,7 +235,7 @@ int wxRadioBox::GetSelection() const // Find string for position wxString wxRadioBox::GetString(int n) const { - if ((n < 0) || (n >= m_noItems)) + if (!IsValid(n)) return wxEmptyString; return m_radioButtonLabels[n]; } @@ -267,7 +267,7 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) // Enable a specific button bool wxRadioBox::Enable(int n, bool enable) { - if ((n < 0) || (n >= m_noItems)) + if (!IsValid(n)) return false; XtSetSensitive ((Widget) m_radioButtons[n], (Boolean) enable); @@ -294,7 +294,7 @@ bool wxRadioBox::Show(bool show) } // Show a specific button -void wxRadioBox::Show(int n, bool show) +bool wxRadioBox::Show(int n, bool show) { // This method isn't complete, and we try do do our best... // It's main purpose isn't for allowing Show/Unshow dynamically, @@ -307,8 +307,8 @@ void wxRadioBox::Show(int n, bool show) // In my case, this is a 'direction' box, and the Show(5,False) is // coupled with an Enable(5,False) // - if ((n < 0) || (n >= m_noItems)) - return; + if (!IsValid(n)) + return false; XtVaSetValues ((Widget) m_radioButtons[n], XmNindicatorOn, (unsigned char) show, @@ -320,6 +320,8 @@ void wxRadioBox::Show(int n, bool show) // after this call!! if (!show) wxRadioBox::SetString (n, " "); + + return true; } // For single selection items only diff --git a/src/msw/radiobox.cpp b/src/msw/radiobox.cpp index c1bac089c2..f4a4178a0e 100644 --- a/src/msw/radiobox.cpp +++ b/src/msw/radiobox.cpp @@ -366,7 +366,7 @@ int wxRadioBox::GetNumHor() const void wxRadioBox::SetString(int item, const wxString& label) { - wxCHECK_RET( item >= 0 && item < GetCount(), wxT("invalid radiobox index") ); + wxCHECK_RET( IsValid(item), wxT("invalid radiobox index") ); m_radioWidth[item] = m_radioHeight[item] = wxDefaultCoord; @@ -376,7 +376,7 @@ void wxRadioBox::SetString(int item, const wxString& label) void wxRadioBox::SetSelection(int N) { - wxCHECK_RET( (N >= 0) && (N < GetCount()), wxT("invalid radiobox index") ); + wxCHECK_RET( IsValid(N), wxT("invalid radiobox index") ); // unselect the old button if ( m_selectedButton != wxNOT_FOUND ) @@ -391,7 +391,7 @@ void wxRadioBox::SetSelection(int N) // Find string for position wxString wxRadioBox::GetString(int item) const { - wxCHECK_MSG( item >= 0 && item < GetCount(), wxEmptyString, + wxCHECK_MSG( IsValid(item), wxEmptyString, wxT("invalid radiobox index") ); return wxGetWindowText((*m_radioButtons)[item]); @@ -410,20 +410,23 @@ void wxRadioBox::SetFocus() // Enable a specific button bool wxRadioBox::Enable(int item, bool enable) { - wxCHECK_MSG( item >= 0 && item < GetCount(), false, + wxCHECK_MSG( IsValid(item), false, wxT("invalid item in wxRadioBox::Enable()") ); - ::EnableWindow((*m_radioButtons)[item], enable); - return true; + BOOL ret = ::EnableWindow((*m_radioButtons)[item], enable); + + return (ret == 0) == enable; } // Show a specific button -void wxRadioBox::Show(int item, bool show) +bool wxRadioBox::Show(int item, bool show) { - wxCHECK_RET( item >= 0 && item < GetCount(), + wxCHECK_MSG( IsValid(item), false, wxT("invalid item in wxRadioBox::Show()") ); - ::ShowWindow((*m_radioButtons)[item], show ? SW_SHOW : SW_HIDE); + BOOL ret = ::ShowWindow((*m_radioButtons)[item], show ? SW_SHOW : SW_HIDE); + + return (ret != 0) == show; } WX_FORWARD_STD_METHODS_TO_SUBWINDOWS(wxRadioBox, wxStaticBox, m_radioButtons) -- 2.45.2