2001-06-26 17:05:06 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2004-05-25 07:20:37 -04:00
|
|
|
// Program: wxWidgets Widgets Sample
|
2001-06-26 17:05:06 -04:00
|
|
|
// Name: radiobox.cpp
|
|
|
|
// Purpose: Part of the widgets sample showing wxRadioBox
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Created: 15.04.01
|
|
|
|
// Copyright: (c) 2001 Vadim Zeitlin
|
2010-07-13 09:29:13 -04:00
|
|
|
// Licence: wxWindows licence
|
2001-06-26 17:05:06 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// declarations
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// for compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
2004-11-23 06:45:07 -05:00
|
|
|
#if wxUSE_RADIOBOX
|
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
// for all others, include the necessary headers
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/log.h"
|
|
|
|
|
2003-03-23 10:12:41 -05:00
|
|
|
#include "wx/bitmap.h"
|
2001-06-26 17:05:06 -04:00
|
|
|
#include "wx/button.h"
|
|
|
|
#include "wx/checkbox.h"
|
|
|
|
#include "wx/radiobox.h"
|
|
|
|
#include "wx/statbox.h"
|
|
|
|
#include "wx/textctrl.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/sizer.h"
|
|
|
|
|
|
|
|
#include "widgets.h"
|
2004-11-23 06:45:07 -05:00
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
#include "icons/radiobox.xpm"
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// control ids
|
|
|
|
enum
|
|
|
|
{
|
2006-05-22 06:39:40 -04:00
|
|
|
RadioPage_Reset = wxID_HIGHEST,
|
2001-06-26 17:05:06 -04:00
|
|
|
RadioPage_Update,
|
|
|
|
RadioPage_Selection,
|
|
|
|
RadioPage_Label,
|
|
|
|
RadioPage_LabelBtn,
|
2005-11-29 14:26:38 -05:00
|
|
|
RadioPage_EnableItem,
|
|
|
|
RadioPage_ShowItem,
|
2001-06-26 17:05:06 -04:00
|
|
|
RadioPage_Radio
|
|
|
|
};
|
|
|
|
|
|
|
|
// default values for the number of radiobox items
|
2002-09-08 14:11:02 -04:00
|
|
|
static const unsigned int DEFAULT_NUM_ENTRIES = 12;
|
|
|
|
static const unsigned int DEFAULT_MAJOR_DIM = 3;
|
2001-06-26 17:05:06 -04:00
|
|
|
|
2005-11-29 14:26:38 -05:00
|
|
|
// this item is enabled/disabled shown/hidden by the test checkboxes
|
|
|
|
static const int TEST_BUTTON = 1;
|
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// RadioWidgetsPage
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class RadioWidgetsPage : public WidgetsPage
|
|
|
|
{
|
|
|
|
public:
|
2006-05-17 15:49:09 -04:00
|
|
|
RadioWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist);
|
2001-06-26 17:05:06 -04:00
|
|
|
|
2015-07-31 11:53:55 -04:00
|
|
|
virtual wxWindow *GetWidget() const wxOVERRIDE { return m_radio; }
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual void RecreateWidget() wxOVERRIDE { CreateRadio(); }
|
2004-11-19 14:03:04 -05:00
|
|
|
|
2006-06-06 10:10:06 -04:00
|
|
|
// lazy creation of the content
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual void CreateContent() wxOVERRIDE;
|
2006-06-06 10:10:06 -04:00
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
protected:
|
|
|
|
// event handlers
|
|
|
|
void OnCheckOrRadioBox(wxCommandEvent& event);
|
|
|
|
void OnRadioBox(wxCommandEvent& event);
|
|
|
|
|
|
|
|
void OnButtonReset(wxCommandEvent& event);
|
|
|
|
void OnButtonRecreate(wxCommandEvent& event);
|
|
|
|
|
|
|
|
void OnButtonSelection(wxCommandEvent& event);
|
|
|
|
void OnButtonSetLabel(wxCommandEvent& event);
|
|
|
|
|
2005-11-29 14:26:38 -05:00
|
|
|
void OnEnableItem(wxCommandEvent& event);
|
|
|
|
void OnShowItem(wxCommandEvent& event);
|
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
void OnUpdateUIReset(wxUpdateUIEvent& event);
|
|
|
|
void OnUpdateUIUpdate(wxUpdateUIEvent& event);
|
|
|
|
void OnUpdateUISelection(wxUpdateUIEvent& event);
|
2005-11-29 14:26:38 -05:00
|
|
|
void OnUpdateUIEnableItem(wxUpdateUIEvent& event);
|
|
|
|
void OnUpdateUIShowItem(wxUpdateUIEvent& event);
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
// reset the wxRadioBox parameters
|
|
|
|
void Reset();
|
|
|
|
|
|
|
|
// (re)create the wxRadioBox
|
|
|
|
void CreateRadio();
|
|
|
|
|
|
|
|
// the controls
|
|
|
|
// ------------
|
|
|
|
|
|
|
|
// the check/radio boxes for styles
|
2009-06-03 18:33:32 -04:00
|
|
|
wxCheckBox *m_chkSpecifyRows;
|
2005-11-29 14:26:38 -05:00
|
|
|
wxCheckBox *m_chkEnableItem;
|
|
|
|
wxCheckBox *m_chkShowItem;
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
// the gauge itself and the sizer it is in
|
|
|
|
wxRadioBox *m_radio;
|
|
|
|
wxSizer *m_sizerRadio;
|
|
|
|
|
|
|
|
// the text entries for command parameters
|
|
|
|
wxTextCtrl *m_textNumBtns,
|
|
|
|
*m_textMajorDim,
|
|
|
|
*m_textCurSel,
|
|
|
|
*m_textSel,
|
|
|
|
*m_textLabel,
|
|
|
|
*m_textLabelBtns;
|
|
|
|
|
|
|
|
private:
|
2014-03-30 03:07:55 -04:00
|
|
|
wxDECLARE_EVENT_TABLE();
|
2001-11-25 10:18:38 -05:00
|
|
|
DECLARE_WIDGETS_PAGE(RadioWidgetsPage)
|
2001-06-26 17:05:06 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// event tables
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2014-03-30 03:07:55 -04:00
|
|
|
wxBEGIN_EVENT_TABLE(RadioWidgetsPage, WidgetsPage)
|
2001-06-26 17:05:06 -04:00
|
|
|
EVT_BUTTON(RadioPage_Reset, RadioWidgetsPage::OnButtonReset)
|
|
|
|
|
|
|
|
EVT_BUTTON(RadioPage_Update, RadioWidgetsPage::OnButtonRecreate)
|
|
|
|
EVT_BUTTON(RadioPage_LabelBtn, RadioWidgetsPage::OnButtonRecreate)
|
|
|
|
|
|
|
|
EVT_BUTTON(RadioPage_Selection, RadioWidgetsPage::OnButtonSelection)
|
|
|
|
EVT_BUTTON(RadioPage_Label, RadioWidgetsPage::OnButtonSetLabel)
|
|
|
|
|
2019-01-27 09:00:29 -05:00
|
|
|
EVT_UPDATE_UI(RadioPage_Reset, RadioWidgetsPage::OnUpdateUIReset)
|
2001-06-26 17:05:06 -04:00
|
|
|
EVT_UPDATE_UI(RadioPage_Update, RadioWidgetsPage::OnUpdateUIUpdate)
|
|
|
|
EVT_UPDATE_UI(RadioPage_Selection, RadioWidgetsPage::OnUpdateUISelection)
|
|
|
|
|
|
|
|
EVT_RADIOBOX(RadioPage_Radio, RadioWidgetsPage::OnRadioBox)
|
|
|
|
|
2005-11-29 14:26:38 -05:00
|
|
|
EVT_CHECKBOX(RadioPage_EnableItem, RadioWidgetsPage::OnEnableItem)
|
|
|
|
EVT_CHECKBOX(RadioPage_ShowItem, RadioWidgetsPage::OnShowItem)
|
|
|
|
|
|
|
|
EVT_UPDATE_UI(RadioPage_EnableItem, RadioWidgetsPage::OnUpdateUIEnableItem)
|
|
|
|
EVT_UPDATE_UI(RadioPage_ShowItem, RadioWidgetsPage::OnUpdateUIShowItem)
|
|
|
|
|
2003-12-11 05:32:15 -05:00
|
|
|
EVT_CHECKBOX(wxID_ANY, RadioWidgetsPage::OnCheckOrRadioBox)
|
|
|
|
EVT_RADIOBOX(wxID_ANY, RadioWidgetsPage::OnCheckOrRadioBox)
|
2014-03-30 03:07:55 -04:00
|
|
|
wxEND_EVENT_TABLE()
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// implementation
|
|
|
|
// ============================================================================
|
|
|
|
|
2006-05-22 06:39:40 -04:00
|
|
|
#if defined(__WXUNIVERSAL__)
|
|
|
|
#define FAMILY_CTRLS UNIVERSAL_CTRLS
|
|
|
|
#else
|
|
|
|
#define FAMILY_CTRLS NATIVE_CTRLS
|
|
|
|
#endif
|
|
|
|
|
2018-09-28 21:45:15 -04:00
|
|
|
IMPLEMENT_WIDGETS_PAGE(RadioWidgetsPage, "Radio",
|
2006-05-22 06:39:40 -04:00
|
|
|
FAMILY_CTRLS | WITH_ITEMS_CTRLS
|
2006-05-17 15:49:09 -04:00
|
|
|
);
|
2001-06-26 17:05:06 -04:00
|
|
|
|
2006-05-17 15:49:09 -04:00
|
|
|
RadioWidgetsPage::RadioWidgetsPage(WidgetsBookCtrl *book,
|
2004-11-23 06:45:07 -05:00
|
|
|
wxImageList *imaglist)
|
2006-05-26 10:07:47 -04:00
|
|
|
: WidgetsPage(book, imaglist, radio_xpm)
|
2001-06-26 17:05:06 -04:00
|
|
|
{
|
|
|
|
// init everything
|
2009-06-03 18:33:32 -04:00
|
|
|
m_chkSpecifyRows = (wxCheckBox *)NULL;
|
2005-11-29 14:26:38 -05:00
|
|
|
m_chkEnableItem = (wxCheckBox *)NULL;
|
|
|
|
m_chkShowItem = (wxCheckBox *)NULL;
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
m_textNumBtns =
|
|
|
|
m_textLabelBtns =
|
|
|
|
m_textLabel = (wxTextCtrl *)NULL;
|
|
|
|
|
2019-01-27 08:48:48 -05:00
|
|
|
m_radio = (wxRadioBox *)NULL;
|
2001-06-26 17:05:06 -04:00
|
|
|
m_sizerRadio = (wxSizer *)NULL;
|
2006-06-06 10:10:06 -04:00
|
|
|
}
|
2001-06-26 17:05:06 -04:00
|
|
|
|
2006-06-06 10:10:06 -04:00
|
|
|
void RadioWidgetsPage::CreateContent()
|
|
|
|
{
|
2001-06-26 17:05:06 -04:00
|
|
|
wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
|
|
|
|
// left pane
|
2018-09-28 21:45:15 -04:00
|
|
|
wxStaticBox *box = new wxStaticBox(this, wxID_ANY, "&Set style");
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
|
|
|
|
|
2009-06-03 18:33:32 -04:00
|
|
|
m_chkSpecifyRows = CreateCheckBoxAndAddToSizer
|
|
|
|
(
|
|
|
|
sizerLeft,
|
|
|
|
"Major specifies &rows count"
|
|
|
|
);
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
wxSizer *sizerRow;
|
2018-09-28 21:45:15 -04:00
|
|
|
sizerRow = CreateSizerWithTextAndLabel("&Major dimension:",
|
2003-12-11 05:32:15 -05:00
|
|
|
wxID_ANY,
|
2001-06-26 17:05:06 -04:00
|
|
|
&m_textMajorDim);
|
2019-01-27 09:00:29 -05:00
|
|
|
sizerLeft->Add(sizerRow, wxSizerFlags().Expand().Border());
|
2001-06-26 17:05:06 -04:00
|
|
|
|
2018-09-28 21:45:15 -04:00
|
|
|
sizerRow = CreateSizerWithTextAndLabel("&Number of buttons:",
|
2003-12-11 05:32:15 -05:00
|
|
|
wxID_ANY,
|
2001-06-26 17:05:06 -04:00
|
|
|
&m_textNumBtns);
|
2019-01-27 09:00:29 -05:00
|
|
|
sizerLeft->Add(sizerRow, wxSizerFlags().Expand().Border());
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
wxButton *btn;
|
2018-09-28 21:45:15 -04:00
|
|
|
btn = new wxButton(this, RadioPage_Update, "&Update");
|
2019-01-27 09:00:29 -05:00
|
|
|
sizerLeft->Add(btn, wxSizerFlags().CentreHorizontal().Border());
|
2001-06-26 17:05:06 -04:00
|
|
|
|
2019-01-27 09:00:29 -05:00
|
|
|
sizerLeft->AddSpacer(5);
|
2001-06-26 17:05:06 -04:00
|
|
|
|
2018-09-28 21:45:15 -04:00
|
|
|
btn = new wxButton(this, RadioPage_Reset, "&Reset");
|
2019-01-27 09:00:29 -05:00
|
|
|
sizerLeft->Add(btn, wxSizerFlags().CentreHorizontal().Border(wxALL, 15));
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
// middle pane
|
2018-09-28 21:45:15 -04:00
|
|
|
wxStaticBox *box2 = new wxStaticBox(this, wxID_ANY, "&Change parameters");
|
2001-06-26 17:05:06 -04:00
|
|
|
wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL);
|
|
|
|
|
2018-09-28 21:45:15 -04:00
|
|
|
sizerRow = CreateSizerWithTextAndLabel("Current selection:",
|
2003-12-11 05:32:15 -05:00
|
|
|
wxID_ANY,
|
2001-06-26 17:05:06 -04:00
|
|
|
&m_textCurSel);
|
2019-01-27 09:00:29 -05:00
|
|
|
sizerMiddle->Add(sizerRow, wxSizerFlags().Expand().Border());
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
sizerRow = CreateSizerWithTextAndButton(RadioPage_Selection,
|
2018-09-28 21:45:15 -04:00
|
|
|
"&Change selection:",
|
2003-12-11 05:32:15 -05:00
|
|
|
wxID_ANY,
|
2001-06-26 17:05:06 -04:00
|
|
|
&m_textSel);
|
2019-01-27 09:00:29 -05:00
|
|
|
sizerMiddle->Add(sizerRow, wxSizerFlags().Expand().Border());
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
sizerRow = CreateSizerWithTextAndButton(RadioPage_Label,
|
2018-09-28 21:45:15 -04:00
|
|
|
"&Label for box:",
|
2003-12-11 05:32:15 -05:00
|
|
|
wxID_ANY,
|
2001-06-26 17:05:06 -04:00
|
|
|
&m_textLabel);
|
2019-01-27 09:00:29 -05:00
|
|
|
sizerMiddle->Add(sizerRow, wxSizerFlags().Expand().Border());
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
sizerRow = CreateSizerWithTextAndButton(RadioPage_LabelBtn,
|
2018-09-28 21:45:15 -04:00
|
|
|
"&Label for buttons:",
|
2003-12-11 05:32:15 -05:00
|
|
|
wxID_ANY,
|
2001-06-26 17:05:06 -04:00
|
|
|
&m_textLabelBtns);
|
2019-01-27 09:00:29 -05:00
|
|
|
sizerMiddle->Add(sizerRow, wxSizerFlags().Expand().Border());
|
2001-06-26 17:05:06 -04:00
|
|
|
|
2005-11-29 14:26:38 -05:00
|
|
|
m_chkEnableItem = CreateCheckBoxAndAddToSizer(sizerMiddle,
|
2018-09-28 21:45:15 -04:00
|
|
|
"Disable &2nd item",
|
2005-11-29 14:26:38 -05:00
|
|
|
RadioPage_EnableItem);
|
|
|
|
m_chkShowItem = CreateCheckBoxAndAddToSizer(sizerMiddle,
|
2018-09-28 21:45:15 -04:00
|
|
|
"Hide 2nd &item",
|
2005-11-29 14:26:38 -05:00
|
|
|
RadioPage_ShowItem);
|
2005-02-23 10:50:48 -05:00
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
// right pane
|
|
|
|
wxSizer *sizerRight = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
m_sizerRadio = sizerRight; // save it to modify it later
|
|
|
|
|
|
|
|
Reset();
|
|
|
|
CreateRadio();
|
|
|
|
|
|
|
|
// the 3 panes panes compose the window
|
2019-01-27 09:00:29 -05:00
|
|
|
sizerTop->Add(sizerLeft,
|
|
|
|
wxSizerFlags(0).Expand().Border((wxALL & ~wxLEFT), 10));
|
|
|
|
sizerTop->Add(sizerMiddle,
|
|
|
|
wxSizerFlags(1).Expand().Border(wxALL, 10));
|
|
|
|
sizerTop->Add(sizerRight,
|
|
|
|
wxSizerFlags(0).Expand().Border((wxALL & ~wxRIGHT), 10));
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
// final initializations
|
|
|
|
SetSizer(sizerTop);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// operations
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void RadioWidgetsPage::Reset()
|
|
|
|
{
|
2018-09-28 21:45:15 -04:00
|
|
|
m_textMajorDim->SetValue(wxString::Format("%u", DEFAULT_MAJOR_DIM));
|
|
|
|
m_textNumBtns->SetValue(wxString::Format("%u", DEFAULT_NUM_ENTRIES));
|
|
|
|
m_textLabel->SetValue("I'm a radiobox");
|
|
|
|
m_textLabelBtns->SetValue("item");
|
2001-06-26 17:05:06 -04:00
|
|
|
|
2009-06-03 18:33:32 -04:00
|
|
|
m_chkSpecifyRows->SetValue(false);
|
2005-11-29 14:26:38 -05:00
|
|
|
m_chkEnableItem->SetValue(true);
|
|
|
|
m_chkShowItem->SetValue(true);
|
2001-06-26 17:05:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void RadioWidgetsPage::CreateRadio()
|
|
|
|
{
|
|
|
|
int sel;
|
|
|
|
if ( m_radio )
|
|
|
|
{
|
|
|
|
sel = m_radio->GetSelection();
|
|
|
|
|
Deprecated wxSizer::Remove( wxWindow* ), s/Remove/Detach/ in most places.
Made wxSizer child list typesafe. I've not added the wxList implicit
conversion kludge yet, let's see who complains first perhaps..
Deprecated wxSizer::{G,S}etOption in favour of {G,S}etProportion in line
with the parameter name change in the docs.
Added {G,S}etSpacer consistent with the accessors for windows/sizers.
Made all wxSizer index parameters size_t -- we support no sensible
interpretation for negative indexes in them. Hopefully this will
cause no real problems, but code doing (eg. Remove( 0 )) will need
to change to use 0u to resolve the ambiguity with overloaded members.
This is probably a Good Thing though, ymmv.
s/FALSE/false/g ; s/TRUE/true/g ; s/wxASSERT/wxASSERT_MSG/g in sizer.{cpp,h}
Fixed (I hope) the brokenness in wxSizer::Show -- I have no code to test
this yet, so it's a blind change, but spacers should now be hidden correctly
instead of ignored, and it should be properly reversable over multiple
calls now too.
removed pointless private scoping around DECLARE_CLASS macros.
Replace 0's I added previously with NULL -- not like that will end the
email thread either..
Added Add( wxSizerItem * ) & co. There are probably a couple of other
places we can usefully do something like this too. Stopped short of
refactoring everything to raise some issues about sizer method recursion
on -dev.
Updated wxSizer docs some more, they are still incomplete but getting
better.
wrapped KeyCode in wxDEPRECATED, converted all (gtk build) instances
to GetKeyCode. There may be a few left for other ports.
Fixed a couple of other random compile warnings along the way.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@18616 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2003-01-07 05:22:07 -05:00
|
|
|
m_sizerRadio->Detach( m_radio );
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
delete m_radio;
|
|
|
|
}
|
|
|
|
else // first time creation, no old selection to preserve
|
|
|
|
{
|
|
|
|
sel = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long count;
|
|
|
|
if ( !m_textNumBtns->GetValue().ToULong(&count) )
|
|
|
|
{
|
2018-09-28 21:45:15 -04:00
|
|
|
wxLogWarning("Should have a valid number for number of items.");
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
// fall back to default
|
|
|
|
count = DEFAULT_NUM_ENTRIES;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long majorDim;
|
|
|
|
if ( !m_textMajorDim->GetValue().ToULong(&majorDim) )
|
|
|
|
{
|
2018-09-28 21:45:15 -04:00
|
|
|
wxLogWarning("Should have a valid major dimension number.");
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
// fall back to default
|
|
|
|
majorDim = DEFAULT_MAJOR_DIM;
|
|
|
|
}
|
|
|
|
|
2019-01-27 09:00:29 -05:00
|
|
|
wxArrayString items;
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
wxString labelBtn = m_textLabelBtns->GetValue();
|
|
|
|
for ( size_t n = 0; n < count; n++ )
|
|
|
|
{
|
2019-01-27 09:00:29 -05:00
|
|
|
items.push_back(wxString::Format("%s %lu",
|
|
|
|
labelBtn, (unsigned long)n + 1));
|
2001-06-26 17:05:06 -04:00
|
|
|
}
|
|
|
|
|
2009-06-03 18:33:32 -04:00
|
|
|
int flags = m_chkSpecifyRows->GetValue() ? wxRA_SPECIFY_ROWS
|
|
|
|
: wxRA_SPECIFY_COLS;
|
2001-06-26 17:05:06 -04:00
|
|
|
|
2015-01-02 09:26:53 -05:00
|
|
|
flags |= GetAttrs().m_defaultFlags;
|
2006-04-16 19:39:11 -04:00
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
m_radio = new wxRadioBox(this, RadioPage_Radio,
|
|
|
|
m_textLabel->GetValue(),
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
2019-01-27 09:00:29 -05:00
|
|
|
items,
|
2001-06-26 17:05:06 -04:00
|
|
|
majorDim,
|
|
|
|
flags);
|
|
|
|
|
|
|
|
if ( sel >= 0 && (size_t)sel < count )
|
|
|
|
{
|
|
|
|
m_radio->SetSelection(sel);
|
|
|
|
}
|
|
|
|
|
2019-01-27 09:00:29 -05:00
|
|
|
if ( count > TEST_BUTTON )
|
|
|
|
{
|
|
|
|
m_radio->Enable(TEST_BUTTON, m_chkEnableItem->IsChecked());
|
|
|
|
m_radio->Show(TEST_BUTTON, m_chkShowItem->IsChecked());
|
|
|
|
}
|
2005-02-23 10:50:48 -05:00
|
|
|
|
2019-01-27 09:00:29 -05:00
|
|
|
m_sizerRadio->Add(m_radio, wxSizerFlags(1).Expand());
|
|
|
|
Layout();
|
|
|
|
|
|
|
|
m_chkEnableItem->Enable(count > TEST_BUTTON);
|
|
|
|
m_chkShowItem->Enable(count > TEST_BUTTON);
|
2001-06-26 17:05:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// event handlers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void RadioWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
|
|
|
|
CreateRadio();
|
|
|
|
}
|
|
|
|
|
2003-07-31 09:59:28 -04:00
|
|
|
void RadioWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event))
|
2001-06-26 17:05:06 -04:00
|
|
|
{
|
|
|
|
CreateRadio();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RadioWidgetsPage::OnRadioBox(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
int sel = m_radio->GetSelection();
|
2003-12-11 06:25:46 -05:00
|
|
|
int event_sel = event.GetSelection();
|
|
|
|
wxUnusedVar(event_sel);
|
2001-06-26 17:05:06 -04:00
|
|
|
|
2018-09-28 21:45:15 -04:00
|
|
|
wxLogMessage("Radiobox selection changed, now %d", sel);
|
2001-06-26 17:05:06 -04:00
|
|
|
|
2003-12-11 06:25:46 -05:00
|
|
|
wxASSERT_MSG( sel == event_sel,
|
2018-09-28 21:45:15 -04:00
|
|
|
"selection should be the same in event and radiobox" );
|
2001-06-26 17:05:06 -04:00
|
|
|
|
2018-09-28 21:45:15 -04:00
|
|
|
m_textCurSel->SetValue(wxString::Format("%d", sel));
|
2001-06-26 17:05:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void RadioWidgetsPage::OnButtonRecreate(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
CreateRadio();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RadioWidgetsPage::OnButtonSetLabel(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
m_radio->wxControl::SetLabel(m_textLabel->GetValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
void RadioWidgetsPage::OnButtonSelection(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
unsigned long sel;
|
|
|
|
if ( !m_textSel->GetValue().ToULong(&sel) ||
|
|
|
|
(sel >= (size_t)m_radio->GetCount()) )
|
|
|
|
{
|
2018-09-28 21:45:15 -04:00
|
|
|
wxLogWarning("Invalid number specified as new selection.");
|
2001-06-26 17:05:06 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_radio->SetSelection(sel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-29 14:26:38 -05:00
|
|
|
void RadioWidgetsPage::OnEnableItem(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
m_radio->Enable(TEST_BUTTON, event.IsChecked());
|
|
|
|
}
|
|
|
|
|
|
|
|
void RadioWidgetsPage::OnShowItem(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
m_radio->Show(TEST_BUTTON, event.IsChecked());
|
|
|
|
}
|
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
void RadioWidgetsPage::OnUpdateUIUpdate(wxUpdateUIEvent& event)
|
|
|
|
{
|
|
|
|
unsigned long n;
|
|
|
|
event.Enable( m_textNumBtns->GetValue().ToULong(&n) &&
|
|
|
|
m_textMajorDim->GetValue().ToULong(&n) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void RadioWidgetsPage::OnUpdateUISelection(wxUpdateUIEvent& event)
|
|
|
|
{
|
|
|
|
unsigned long n;
|
|
|
|
event.Enable( m_textSel->GetValue().ToULong(&n) &&
|
|
|
|
(n < (size_t)m_radio->GetCount()) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void RadioWidgetsPage::OnUpdateUIReset(wxUpdateUIEvent& event)
|
|
|
|
{
|
|
|
|
// only enable it if something is not set to default
|
2009-06-03 18:33:32 -04:00
|
|
|
bool enable = m_chkSpecifyRows->GetValue();
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
if ( !enable )
|
|
|
|
{
|
|
|
|
unsigned long numEntries;
|
|
|
|
|
|
|
|
enable = !m_textNumBtns->GetValue().ToULong(&numEntries) ||
|
|
|
|
numEntries != DEFAULT_NUM_ENTRIES;
|
|
|
|
|
|
|
|
if ( !enable )
|
|
|
|
{
|
|
|
|
unsigned long majorDim;
|
|
|
|
|
|
|
|
enable = !m_textMajorDim->GetValue().ToULong(&majorDim) ||
|
|
|
|
majorDim != DEFAULT_MAJOR_DIM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
event.Enable(enable);
|
|
|
|
}
|
|
|
|
|
2005-11-29 14:26:38 -05:00
|
|
|
void RadioWidgetsPage::OnUpdateUIEnableItem(wxUpdateUIEvent& event)
|
|
|
|
{
|
2019-01-27 09:00:29 -05:00
|
|
|
if ( m_radio->GetCount() <= TEST_BUTTON )
|
|
|
|
return;
|
|
|
|
|
2018-09-28 21:45:15 -04:00
|
|
|
event.SetText(m_radio->IsItemEnabled(TEST_BUTTON) ? "Disable &2nd item"
|
|
|
|
: "Enable &2nd item");
|
2005-11-29 14:26:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void RadioWidgetsPage::OnUpdateUIShowItem(wxUpdateUIEvent& event)
|
|
|
|
{
|
2019-01-27 09:00:29 -05:00
|
|
|
if ( m_radio->GetCount() <= TEST_BUTTON )
|
|
|
|
return;
|
|
|
|
|
2018-09-28 21:45:15 -04:00
|
|
|
event.SetText(m_radio->IsItemShown(TEST_BUTTON) ? "Hide 2nd &item"
|
|
|
|
: "Show 2nd &item");
|
2005-11-29 14:26:38 -05:00
|
|
|
}
|
|
|
|
|
2004-11-23 06:45:07 -05:00
|
|
|
#endif // wxUSE_RADIOBOX
|