added a menu allowing to change the border style used by the widget

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38772 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2006-04-16 23:39:11 +00:00
parent 6493aacaeb
commit 1301e2289f
13 changed files with 89 additions and 17 deletions

View File

@@ -83,6 +83,7 @@ public:
virtual ~ButtonWidgetsPage(){};
virtual wxControl *GetWidget() const { return m_button; }
virtual void RecreateWidget() { CreateButton(); }
protected:
// event handlers
@@ -311,7 +312,7 @@ void ButtonWidgetsPage::CreateButton()
label = m_textLabel->GetValue();
}
int flags = 0;
int flags = ms_defaultFlags;
switch ( m_radioHAlign->GetSelection() )
{
case ButtonHAlign_Left:

View File

@@ -77,6 +77,7 @@ public:
virtual ~CheckBoxWidgetsPage(){};
virtual wxControl *GetWidget() const { return m_checkbox; }
virtual void RecreateWidget() { CreateCheckbox(); }
protected:
// event handlers
@@ -243,7 +244,7 @@ void CheckBoxWidgetsPage::CreateCheckbox()
delete m_checkbox;
int flags = 0;
int flags = ms_defaultFlags;
if ( m_chkRight->IsChecked() )
flags |= wxALIGN_RIGHT;

View File

@@ -88,6 +88,7 @@ public:
ComboboxWidgetsPage(wxBookCtrlBase *book, wxImageList *imaglist);
virtual wxControl *GetWidget() const { return m_combobox; }
virtual void RecreateWidget() { CreateCombo(); }
protected:
// event handlers
@@ -334,7 +335,7 @@ void ComboboxWidgetsPage::Reset()
void ComboboxWidgetsPage::CreateCombo()
{
int flags = 0;
int flags = ms_defaultFlags;
if ( m_chkSort->GetValue() )
flags |= wxCB_SORT;

View File

@@ -75,6 +75,7 @@ public:
virtual ~GaugeWidgetsPage();
virtual wxControl *GetWidget() const { return m_gauge; }
virtual void RecreateWidget() { CreateGauge(); }
protected:
// event handlers
@@ -259,7 +260,7 @@ void GaugeWidgetsPage::Reset()
void GaugeWidgetsPage::CreateGauge()
{
int flags = 0;
int flags = ms_defaultFlags;
if ( m_chkVert->GetValue() )
flags |= wxGA_VERTICAL;

View File

@@ -79,6 +79,7 @@ public:
ListboxWidgetsPage(wxBookCtrlBase *book, wxImageList *imaglist);
virtual wxControl *GetWidget() const { return m_lbox; }
virtual void RecreateWidget() { CreateLbox(); }
protected:
// event handlers
@@ -334,7 +335,7 @@ void ListboxWidgetsPage::Reset()
void ListboxWidgetsPage::CreateLbox()
{
int flags = 0;
int flags = ms_defaultFlags;
switch ( m_radioSelMode->GetSelection() )
{
default:

View File

@@ -90,6 +90,7 @@ public:
virtual ~NotebookWidgetsPage();
virtual wxControl *GetWidget() const { return m_notebook; }
virtual void RecreateWidget() { CreateNotebook(); }
protected:
// event handlers
@@ -344,7 +345,7 @@ void NotebookWidgetsPage::CreateImageList()
void NotebookWidgetsPage::CreateNotebook()
{
int flags;
int flags = ms_defaultFlags;
switch ( m_radioOrient->GetSelection() )
{
default:
@@ -352,19 +353,19 @@ void NotebookWidgetsPage::CreateNotebook()
// fall through
case Orient_Top:
flags = wxBK_TOP;
flags |= wxBK_TOP;
break;
case Orient_Bottom:
flags = wxBK_BOTTOM;
flags |= wxBK_BOTTOM;
break;
case Orient_Left:
flags = wxBK_LEFT;
flags |= wxBK_LEFT;
break;
case Orient_Right:
flags = wxBK_RIGHT;
flags |= wxBK_RIGHT;
break;
}

View File

@@ -87,6 +87,7 @@ public:
virtual ~RadioWidgetsPage(){};
virtual wxControl *GetWidget() const { return m_radio; }
virtual void RecreateWidget() { CreateRadio(); }
protected:
// event handlers
@@ -356,6 +357,8 @@ void RadioWidgetsPage::CreateRadio()
int flags = m_chkVert->GetValue() ? wxRA_VERTICAL
: wxRA_HORIZONTAL;
flags |= ms_defaultFlags;
#ifdef wxRA_LEFTTORIGHT
switch ( m_radioDir->GetSelection() )
{

View File

@@ -93,6 +93,7 @@ public:
virtual ~SliderWidgetsPage(){};
virtual wxControl *GetWidget() const { return m_slider; }
virtual void RecreateWidget() { CreateSlider(); }
protected:
// event handlers
@@ -333,7 +334,7 @@ void SliderWidgetsPage::Reset()
void SliderWidgetsPage::CreateSlider()
{
int flags = 0;
int flags = ms_defaultFlags;
if ( m_chkInverse->GetValue() )
{

View File

@@ -78,6 +78,7 @@ public:
virtual wxControl *GetWidget() const { return m_spinbtn; }
virtual wxControl *GetWidget2() const { return m_spinctrl; }
virtual void RecreateWidget() { CreateSpin(); }
protected:
// event handlers
@@ -268,7 +269,7 @@ void SpinBtnWidgetsPage::Reset()
void SpinBtnWidgetsPage::CreateSpin()
{
int flags = 0;
int flags = ms_defaultFlags;
bool isVert = m_chkVert->GetValue();
if ( isVert )

View File

@@ -143,6 +143,7 @@ public:
virtual ~StaticWidgetsPage(){};
virtual wxControl *GetWidget() const { return m_statText; }
virtual void RecreateWidget() { CreateStatic(); }
protected:
// event handlers
@@ -333,7 +334,7 @@ void StaticWidgetsPage::CreateStatic()
}
int flagsBox = 0,
flagsText = 0;
flagsText = ms_defaultFlags;
if ( !m_chkAutoResize->GetValue() )
{

View File

@@ -136,6 +136,7 @@ public:
virtual ~TextWidgetsPage(){};
virtual wxControl *GetWidget() const { return m_text; }
virtual void RecreateWidget() { CreateText(); }
protected:
// create an info text contorl
@@ -599,7 +600,7 @@ void TextWidgetsPage::Reset()
void TextWidgetsPage::CreateText()
{
int flags = 0;
int flags = ms_defaultFlags;
switch ( m_radioTextLines->GetSelection() )
{
default:

View File

@@ -58,13 +58,22 @@ enum
{
Widgets_ClearLog = 100,
Widgets_Quit,
#if wxUSE_TOOLTIPS
Widgets_SetTooltip,
#endif // wxUSE_TOOLTIPS
Widgets_SetFgColour,
Widgets_SetBgColour,
Widgets_SetFont,
Widgets_Enable
Widgets_Enable,
Widgets_BorderNone,
Widgets_BorderStatic,
Widgets_BorderSimple,
Widgets_BorderRaised,
Widgets_BorderSunken,
Widgets_BorderDouble,
Widgets_BorderDefault
};
// ----------------------------------------------------------------------------
@@ -107,6 +116,7 @@ protected:
void OnSetBgCol(wxCommandEvent& event);
void OnSetFont(wxCommandEvent& event);
void OnEnable(wxCommandEvent& event);
void OnSetBorder(wxCommandEvent& event);
#endif // wxUSE_MENUS
// initialize the book: add all pages to it
@@ -228,6 +238,9 @@ BEGIN_EVENT_TABLE(WidgetsFrame, wxFrame)
EVT_MENU(Widgets_SetFont, WidgetsFrame::OnSetFont)
EVT_MENU(Widgets_Enable, WidgetsFrame::OnEnable)
EVT_MENU_RANGE(Widgets_BorderNone, Widgets_BorderDefault,
WidgetsFrame::OnSetBorder)
EVT_MENU(wxID_EXIT, WidgetsFrame::OnExit)
END_EVENT_TABLE()
@@ -305,6 +318,17 @@ WidgetsFrame::WidgetsFrame(const wxString& title)
menuWidget->Append(Widgets_SetBgColour, _T("Set &background...\tCtrl-B"));
menuWidget->Append(Widgets_SetFont, _T("Set f&ont...\tCtrl-O"));
menuWidget->AppendCheckItem(Widgets_Enable, _T("&Enable/disable\tCtrl-E"));
wxMenu *menuBorders = new wxMenu;
menuBorders->AppendRadioItem(Widgets_BorderDefault, _T("De&fault\tCtrl-Shift-9"));
menuBorders->AppendRadioItem(Widgets_BorderNone, _T("&None\tCtrl-Shift-0"));
menuBorders->AppendRadioItem(Widgets_BorderSimple, _T("&Simple\tCtrl-Shift-1"));
menuBorders->AppendRadioItem(Widgets_BorderDouble, _T("&Double\tCtrl-Shift-2"));
menuBorders->AppendRadioItem(Widgets_BorderStatic, _T("Stati&c\tCtrl-Shift-3"));
menuBorders->AppendRadioItem(Widgets_BorderRaised, _T("&Raised\tCtrl-Shift-4"));
menuBorders->AppendRadioItem(Widgets_BorderSunken, _T("S&unken\tCtrl-Shift-5"));
menuWidget->AppendSubMenu(menuBorders, _T("Set &border"));
menuWidget->AppendSeparator();
menuWidget->Append(wxID_EXIT, _T("&Quit\tCtrl-Q"));
mbar->Append(menuWidget, _T("&Widget"));
@@ -577,14 +601,38 @@ void WidgetsFrame::OnEnable(wxCommandEvent& event)
page->GetWidget()->Enable(event.IsChecked());
}
void WidgetsFrame::OnSetBorder(wxCommandEvent& event)
{
int border;
switch ( event.GetId() )
{
case Widgets_BorderNone: border = wxBORDER_NONE; break;
case Widgets_BorderStatic: border = wxBORDER_STATIC; break;
case Widgets_BorderSimple: border = wxBORDER_SIMPLE; break;
case Widgets_BorderRaised: border = wxBORDER_RAISED; break;
case Widgets_BorderSunken: border = wxBORDER_SUNKEN; break;
case Widgets_BorderDouble: border = wxBORDER_DOUBLE; break;
default:
wxFAIL_MSG( _T("unknown border style") );
// fall through
case Widgets_BorderDefault: border = wxBORDER_DEFAULT; break;
}
WidgetsPage::ms_defaultFlags &= ~wxBORDER_MASK;
WidgetsPage::ms_defaultFlags |= border;
WidgetsPage *page = wxStaticCast(m_book->GetCurrentPage(), WidgetsPage);
page->RecreateWidget();
}
#endif // wxUSE_MENUS
// ----------------------------------------------------------------------------
// WidgetsPageInfo
// ----------------------------------------------------------------------------
WidgetsPageInfo *WidgetsPage::ms_widgetPages = NULL;
WidgetsPageInfo::WidgetsPageInfo(Constructor ctor, const wxChar *label)
: m_label(label)
{
@@ -644,6 +692,9 @@ WidgetsPageInfo::WidgetsPageInfo(Constructor ctor, const wxChar *label)
// WidgetsPage
// ----------------------------------------------------------------------------
int WidgetsPage::ms_defaultFlags = wxBORDER_DEFAULT;
WidgetsPageInfo *WidgetsPage::ms_widgetPages = NULL;
WidgetsPage::WidgetsPage(wxBookCtrlBase *book)
: wxPanel(book, wxID_ANY,
wxDefaultPosition, wxDefaultSize,

View File

@@ -45,6 +45,14 @@ public:
// some pages show 2 controls, in this case override this one as well
virtual wxControl *GetWidget2() const { return NULL; }
// recreate the control shown by this page
//
// this is currently used only to take into account the border flags
virtual void RecreateWidget() = 0;
// the default flags for the widget, currently only contains border flags
static int ms_defaultFlags;
protected:
// several helper functions for page creation