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: button.cpp
|
|
|
|
// Purpose: Part of the widgets sample showing wxButton
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Created: 10.04.01
|
|
|
|
// Id: $Id$
|
|
|
|
// Copyright: (c) 2001 Vadim Zeitlin
|
|
|
|
// License: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// declarations
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// for compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// for all others, include the necessary headers
|
|
|
|
#ifndef WX_PRECOMP
|
2001-07-03 15:38:19 -04:00
|
|
|
#include "wx/app.h"
|
2001-06-26 17:05:06 -04:00
|
|
|
#include "wx/log.h"
|
|
|
|
|
2005-11-02 20:28:17 -05:00
|
|
|
#include "wx/bmpbuttn.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
|
|
|
|
|
2002-04-20 19:30:23 -04:00
|
|
|
#include "wx/artprov.h"
|
2001-06-26 17:05:06 -04:00
|
|
|
#include "wx/sizer.h"
|
2005-11-02 20:28:17 -05:00
|
|
|
#include "wx/dcmemory.h"
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
#include "widgets.h"
|
2002-04-20 19:30:23 -04:00
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
#include "icons/button.xpm"
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// control ids
|
|
|
|
enum
|
|
|
|
{
|
2006-05-22 06:39:40 -04:00
|
|
|
ButtonPage_Reset = wxID_HIGHEST,
|
2001-06-26 17:05:06 -04:00
|
|
|
ButtonPage_ChangeLabel,
|
|
|
|
ButtonPage_Button
|
|
|
|
};
|
|
|
|
|
|
|
|
// radio boxes
|
2009-06-15 00:23:54 -04:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
ButtonImagePos_Left,
|
|
|
|
ButtonImagePos_Right,
|
|
|
|
ButtonImagePos_Top,
|
|
|
|
ButtonImagePos_Bottom
|
|
|
|
};
|
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
ButtonHAlign_Left,
|
|
|
|
ButtonHAlign_Centre,
|
|
|
|
ButtonHAlign_Right
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
ButtonVAlign_Top,
|
|
|
|
ButtonVAlign_Centre,
|
|
|
|
ButtonVAlign_Bottom
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// ButtonWidgetsPage
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class ButtonWidgetsPage : public WidgetsPage
|
|
|
|
{
|
|
|
|
public:
|
2006-05-17 15:49:09 -04:00
|
|
|
ButtonWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist);
|
2004-10-04 16:25:15 -04:00
|
|
|
virtual ~ButtonWidgetsPage(){};
|
2001-06-26 17:05:06 -04:00
|
|
|
|
2004-11-19 14:03:04 -05:00
|
|
|
virtual wxControl *GetWidget() const { return m_button; }
|
2006-04-16 19:39:11 -04:00
|
|
|
virtual void RecreateWidget() { CreateButton(); }
|
2004-11-19 14:03:04 -05:00
|
|
|
|
2006-06-06 10:10:06 -04:00
|
|
|
// lazy creation of the content
|
|
|
|
virtual void CreateContent();
|
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
protected:
|
|
|
|
// event handlers
|
|
|
|
void OnCheckOrRadioBox(wxCommandEvent& event);
|
|
|
|
|
|
|
|
void OnButton(wxCommandEvent& event);
|
|
|
|
void OnButtonReset(wxCommandEvent& event);
|
|
|
|
void OnButtonChangeLabel(wxCommandEvent& event);
|
|
|
|
|
|
|
|
// reset the wxButton parameters
|
|
|
|
void Reset();
|
|
|
|
|
|
|
|
// (re)create the wxButton
|
|
|
|
void CreateButton();
|
|
|
|
|
2005-11-02 20:28:17 -05:00
|
|
|
// add m_button to m_sizerButton using current value of m_chkFit
|
|
|
|
void AddButtonToSizer();
|
|
|
|
|
|
|
|
// helper function: create a bitmap for wxBitmapButton
|
|
|
|
wxBitmap CreateBitmap(const wxString& label);
|
|
|
|
|
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
// the controls
|
|
|
|
// ------------
|
|
|
|
|
|
|
|
// the check/radio boxes for styles
|
2009-06-15 16:18:10 -04:00
|
|
|
wxCheckBox *m_chkBitmapOnly,
|
|
|
|
*m_chkTextAndBitmap,
|
2001-06-26 17:05:06 -04:00
|
|
|
*m_chkFit,
|
|
|
|
*m_chkDefault;
|
|
|
|
|
2005-11-03 14:29:18 -05:00
|
|
|
// more checkboxes for wxBitmapButton only
|
2009-06-15 16:18:10 -04:00
|
|
|
wxCheckBox *m_chkUsePressed,
|
2005-11-03 14:29:18 -05:00
|
|
|
*m_chkUseFocused,
|
2009-06-15 16:18:10 -04:00
|
|
|
*m_chkUseCurrent,
|
2005-11-03 14:29:18 -05:00
|
|
|
*m_chkUseDisabled;
|
|
|
|
|
2009-06-15 16:18:10 -04:00
|
|
|
// and an image position choice used if m_chkTextAndBitmap is on
|
2009-06-15 00:23:54 -04:00
|
|
|
wxRadioBox *m_radioImagePos;
|
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
wxRadioBox *m_radioHAlign,
|
|
|
|
*m_radioVAlign;
|
|
|
|
|
2004-07-25 08:23:52 -04:00
|
|
|
// the button itself and the sizer it is in
|
2001-06-26 17:05:06 -04:00
|
|
|
wxButton *m_button;
|
|
|
|
wxSizer *m_sizerButton;
|
|
|
|
|
|
|
|
// the text entries for command parameters
|
|
|
|
wxTextCtrl *m_textLabel;
|
|
|
|
|
|
|
|
private:
|
2001-11-25 10:18:38 -05:00
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
DECLARE_WIDGETS_PAGE(ButtonWidgetsPage)
|
2001-06-26 17:05:06 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// event tables
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(ButtonWidgetsPage, WidgetsPage)
|
|
|
|
EVT_BUTTON(ButtonPage_Button, ButtonWidgetsPage::OnButton)
|
|
|
|
|
|
|
|
EVT_BUTTON(ButtonPage_Reset, ButtonWidgetsPage::OnButtonReset)
|
|
|
|
EVT_BUTTON(ButtonPage_ChangeLabel, ButtonWidgetsPage::OnButtonChangeLabel)
|
|
|
|
|
2003-12-11 05:32:15 -05:00
|
|
|
EVT_CHECKBOX(wxID_ANY, ButtonWidgetsPage::OnCheckOrRadioBox)
|
|
|
|
EVT_RADIOBOX(wxID_ANY, ButtonWidgetsPage::OnCheckOrRadioBox)
|
2001-06-26 17:05:06 -04:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// implementation
|
|
|
|
// ============================================================================
|
|
|
|
|
2006-05-18 11:36:44 -04:00
|
|
|
#if defined(__WXUNIVERSAL__)
|
2006-05-19 06:17:43 -04:00
|
|
|
#define FAMILY_CTRLS UNIVERSAL_CTRLS
|
2006-05-18 11:36:44 -04:00
|
|
|
#else
|
2006-05-22 06:39:40 -04:00
|
|
|
#define FAMILY_CTRLS NATIVE_CTRLS
|
2006-05-18 11:36:44 -04:00
|
|
|
#endif
|
2006-05-19 06:17:43 -04:00
|
|
|
|
2009-07-23 16:30:22 -04:00
|
|
|
IMPLEMENT_WIDGETS_PAGE(ButtonWidgetsPage, wxT("Button"), FAMILY_CTRLS );
|
2001-06-26 17:05:06 -04:00
|
|
|
|
2006-05-17 15:49:09 -04:00
|
|
|
ButtonWidgetsPage::ButtonWidgetsPage(WidgetsBookCtrl *book,
|
2004-11-23 06:45:07 -05:00
|
|
|
wxImageList *imaglist)
|
2006-05-26 10:07:47 -04:00
|
|
|
: WidgetsPage(book, imaglist, button_xpm)
|
2001-06-26 17:05:06 -04:00
|
|
|
{
|
|
|
|
// init everything
|
2009-06-15 16:18:10 -04:00
|
|
|
m_chkBitmapOnly =
|
|
|
|
m_chkTextAndBitmap =
|
2001-06-26 17:05:06 -04:00
|
|
|
m_chkFit =
|
2005-11-03 14:29:18 -05:00
|
|
|
m_chkDefault =
|
2009-06-15 16:18:10 -04:00
|
|
|
m_chkUsePressed =
|
2005-11-03 14:29:18 -05:00
|
|
|
m_chkUseFocused =
|
2009-06-15 16:18:10 -04:00
|
|
|
m_chkUseCurrent =
|
2005-11-03 14:29:18 -05:00
|
|
|
m_chkUseDisabled = (wxCheckBox *)NULL;
|
2001-06-26 17:05:06 -04:00
|
|
|
|
2009-06-15 00:23:54 -04:00
|
|
|
m_radioImagePos =
|
2001-06-26 17:05:06 -04:00
|
|
|
m_radioHAlign =
|
|
|
|
m_radioVAlign = (wxRadioBox *)NULL;
|
|
|
|
|
|
|
|
m_textLabel = (wxTextCtrl *)NULL;
|
|
|
|
|
|
|
|
m_button = (wxButton *)NULL;
|
|
|
|
m_sizerButton = (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 ButtonWidgetsPage::CreateContent()
|
|
|
|
{
|
2001-06-26 17:05:06 -04:00
|
|
|
wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
|
|
|
|
// left pane
|
2009-07-23 16:30:22 -04:00
|
|
|
wxStaticBox *box = new wxStaticBox(this, wxID_ANY, wxT("&Set style"));
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
|
|
|
|
|
2009-06-15 16:18:10 -04:00
|
|
|
m_chkBitmapOnly = CreateCheckBoxAndAddToSizer(sizerLeft, "&Bitmap only");
|
|
|
|
m_chkTextAndBitmap = CreateCheckBoxAndAddToSizer(sizerLeft, "Text &and &bitmap");
|
2009-07-23 16:30:22 -04:00
|
|
|
m_chkFit = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("&Fit exactly"));
|
|
|
|
m_chkDefault = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("&Default"));
|
2001-06-26 17:05:06 -04:00
|
|
|
|
2005-11-03 14:29:18 -05:00
|
|
|
sizerLeft->AddSpacer(5);
|
|
|
|
|
|
|
|
wxSizer *sizerUseLabels =
|
2009-06-15 16:18:10 -04:00
|
|
|
new wxStaticBoxSizer(wxVERTICAL, this,
|
|
|
|
"&Use the following bitmaps in addition to the normal one?");
|
|
|
|
m_chkUsePressed = CreateCheckBoxAndAddToSizer(sizerUseLabels,
|
|
|
|
"&Pressed (small help icon)");
|
|
|
|
m_chkUseFocused = CreateCheckBoxAndAddToSizer(sizerUseLabels,
|
|
|
|
"&Focused (small error icon)");
|
|
|
|
m_chkUseCurrent = CreateCheckBoxAndAddToSizer(sizerUseLabels,
|
|
|
|
"&Current (small warning icon)");
|
|
|
|
m_chkUseDisabled = CreateCheckBoxAndAddToSizer(sizerUseLabels,
|
|
|
|
"&Disabled (broken image icon)");
|
2005-11-03 14:29:18 -05:00
|
|
|
sizerLeft->Add(sizerUseLabels, wxSizerFlags().Expand().Border());
|
|
|
|
|
2009-06-15 00:23:54 -04:00
|
|
|
sizerLeft->AddSpacer(10);
|
|
|
|
|
|
|
|
static const wxString dirs[] =
|
|
|
|
{
|
|
|
|
"left", "right", "top", "bottom",
|
|
|
|
};
|
|
|
|
m_radioImagePos = new wxRadioBox(this, wxID_ANY, "Image &position",
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
WXSIZEOF(dirs), dirs);
|
|
|
|
sizerLeft->Add(m_radioImagePos, 0, wxGROW | wxALL, 5);
|
2005-11-03 14:29:18 -05:00
|
|
|
sizerLeft->AddSpacer(15);
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
// should be in sync with enums Button[HV]Align!
|
|
|
|
static const wxString halign[] =
|
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
wxT("left"),
|
|
|
|
wxT("centre"),
|
|
|
|
wxT("right"),
|
2001-06-26 17:05:06 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
static const wxString valign[] =
|
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
wxT("top"),
|
|
|
|
wxT("centre"),
|
|
|
|
wxT("bottom"),
|
2001-06-26 17:05:06 -04:00
|
|
|
};
|
|
|
|
|
2009-07-23 16:30:22 -04:00
|
|
|
m_radioHAlign = new wxRadioBox(this, wxID_ANY, wxT("&Horz alignment"),
|
2001-06-26 17:05:06 -04:00
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
WXSIZEOF(halign), halign);
|
2009-07-23 16:30:22 -04:00
|
|
|
m_radioVAlign = new wxRadioBox(this, wxID_ANY, wxT("&Vert alignment"),
|
2001-06-26 17:05:06 -04:00
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
WXSIZEOF(valign), valign);
|
|
|
|
|
|
|
|
sizerLeft->Add(m_radioHAlign, 0, wxGROW | wxALL, 5);
|
|
|
|
sizerLeft->Add(m_radioVAlign, 0, wxGROW | wxALL, 5);
|
|
|
|
|
|
|
|
sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
|
|
|
|
|
2009-07-23 16:30:22 -04:00
|
|
|
wxButton *btn = new wxButton(this, ButtonPage_Reset, wxT("&Reset"));
|
2001-06-26 17:05:06 -04:00
|
|
|
sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
|
|
|
|
|
|
|
|
// middle pane
|
2009-07-23 16:30:22 -04:00
|
|
|
wxStaticBox *box2 = new wxStaticBox(this, wxID_ANY, wxT("&Operations"));
|
2001-06-26 17:05:06 -04:00
|
|
|
wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL);
|
|
|
|
|
|
|
|
wxSizer *sizerRow = CreateSizerWithTextAndButton(ButtonPage_ChangeLabel,
|
2009-07-23 16:30:22 -04:00
|
|
|
wxT("Change label"),
|
2003-12-11 05:32:15 -05:00
|
|
|
wxID_ANY,
|
2001-06-26 17:05:06 -04:00
|
|
|
&m_textLabel);
|
2009-07-23 16:30:22 -04:00
|
|
|
m_textLabel->SetValue(wxT("&Press me!"));
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
|
|
|
|
|
|
|
|
// right pane
|
2005-11-02 20:28:17 -05:00
|
|
|
m_sizerButton = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
m_sizerButton->SetMinSize(150, 0);
|
2001-06-26 17:05:06 -04:00
|
|
|
|
|
|
|
// the 3 panes panes compose the window
|
|
|
|
sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10);
|
|
|
|
sizerTop->Add(sizerMiddle, 1, wxGROW | wxALL, 10);
|
2005-11-02 20:28:17 -05:00
|
|
|
sizerTop->Add(m_sizerButton, 1, wxGROW | (wxALL & ~wxRIGHT), 10);
|
2001-06-26 17:05:06 -04:00
|
|
|
|
2005-11-03 14:29:18 -05:00
|
|
|
// do create the main control
|
2001-06-26 17:05:06 -04:00
|
|
|
Reset();
|
2005-11-03 14:29:18 -05:00
|
|
|
CreateButton();
|
2005-11-02 20:28:17 -05:00
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
SetSizer(sizerTop);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// operations
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void ButtonWidgetsPage::Reset()
|
|
|
|
{
|
2009-06-15 16:18:10 -04:00
|
|
|
m_chkBitmapOnly->SetValue(false);
|
2003-12-11 05:32:15 -05:00
|
|
|
m_chkFit->SetValue(true);
|
2009-06-15 16:18:10 -04:00
|
|
|
m_chkTextAndBitmap->SetValue(false);
|
2003-12-11 05:32:15 -05:00
|
|
|
m_chkDefault->SetValue(false);
|
2001-06-26 17:05:06 -04:00
|
|
|
|
2009-06-15 16:18:10 -04:00
|
|
|
m_chkUsePressed->SetValue(true);
|
2005-11-03 14:29:18 -05:00
|
|
|
m_chkUseFocused->SetValue(true);
|
2009-06-15 16:18:10 -04:00
|
|
|
m_chkUseCurrent->SetValue(true);
|
2005-11-03 14:29:18 -05:00
|
|
|
m_chkUseDisabled->SetValue(true);
|
|
|
|
|
2009-06-15 00:23:54 -04:00
|
|
|
m_radioImagePos->SetSelection(ButtonImagePos_Left);
|
2001-06-26 17:05:06 -04:00
|
|
|
m_radioHAlign->SetSelection(ButtonHAlign_Centre);
|
|
|
|
m_radioVAlign->SetSelection(ButtonVAlign_Centre);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ButtonWidgetsPage::CreateButton()
|
|
|
|
{
|
|
|
|
wxString label;
|
|
|
|
if ( m_button )
|
|
|
|
{
|
|
|
|
label = m_button->GetLabel();
|
|
|
|
|
|
|
|
size_t count = m_sizerButton->GetChildren().GetCount();
|
|
|
|
for ( size_t n = 0; n < count; n++ )
|
|
|
|
{
|
2003-01-26 09:03:29 -05:00
|
|
|
m_sizerButton->Remove( 0 );
|
2001-06-26 17:05:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
delete m_button;
|
|
|
|
}
|
2005-11-02 20:28:17 -05:00
|
|
|
|
|
|
|
if ( label.empty() )
|
2001-06-26 17:05:06 -04:00
|
|
|
{
|
2005-11-02 20:28:17 -05:00
|
|
|
// creating for the first time or recreating a button after bitmap
|
|
|
|
// button
|
|
|
|
label = m_textLabel->GetValue();
|
2001-06-26 17:05:06 -04:00
|
|
|
}
|
|
|
|
|
2006-04-16 19:39:11 -04:00
|
|
|
int flags = ms_defaultFlags;
|
2001-06-26 17:05:06 -04:00
|
|
|
switch ( m_radioHAlign->GetSelection() )
|
|
|
|
{
|
|
|
|
case ButtonHAlign_Left:
|
2002-09-02 08:29:44 -04:00
|
|
|
flags |= wxBU_LEFT;
|
2001-06-26 17:05:06 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2009-07-23 16:30:22 -04:00
|
|
|
wxFAIL_MSG(wxT("unexpected radiobox selection"));
|
2001-06-26 17:05:06 -04:00
|
|
|
// fall through
|
|
|
|
|
|
|
|
case ButtonHAlign_Centre:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ButtonHAlign_Right:
|
2002-09-02 08:29:44 -04:00
|
|
|
flags |= wxBU_RIGHT;
|
2001-06-26 17:05:06 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ( m_radioVAlign->GetSelection() )
|
|
|
|
{
|
|
|
|
case ButtonVAlign_Top:
|
2002-09-02 08:29:44 -04:00
|
|
|
flags |= wxBU_TOP;
|
2001-06-26 17:05:06 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2009-07-23 16:30:22 -04:00
|
|
|
wxFAIL_MSG(wxT("unexpected radiobox selection"));
|
2001-06-26 17:05:06 -04:00
|
|
|
// fall through
|
|
|
|
|
|
|
|
case ButtonVAlign_Centre:
|
2006-01-18 04:16:59 -05:00
|
|
|
// centre vertical alignment is the default (no style)
|
2001-06-26 17:05:06 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ButtonVAlign_Bottom:
|
2002-09-02 08:29:44 -04:00
|
|
|
flags |= wxBU_BOTTOM;
|
2001-06-26 17:05:06 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-06-15 16:18:10 -04:00
|
|
|
bool showsBitmap = false;
|
|
|
|
if ( m_chkBitmapOnly->GetValue() )
|
2005-11-02 20:28:17 -05:00
|
|
|
{
|
2009-06-15 16:18:10 -04:00
|
|
|
showsBitmap = true;
|
|
|
|
|
2005-11-02 20:28:17 -05:00
|
|
|
wxBitmapButton *bbtn = new wxBitmapButton(this, ButtonPage_Button,
|
2009-07-23 16:30:22 -04:00
|
|
|
CreateBitmap(wxT("normal")));
|
2009-06-15 16:18:10 -04:00
|
|
|
if ( m_chkUsePressed->GetValue() )
|
2009-07-23 16:30:22 -04:00
|
|
|
bbtn->SetBitmapPressed(CreateBitmap(wxT("pushed")));
|
2005-11-03 14:29:18 -05:00
|
|
|
if ( m_chkUseFocused->GetValue() )
|
2009-07-23 16:30:22 -04:00
|
|
|
bbtn->SetBitmapFocus(CreateBitmap(wxT("focused")));
|
2009-06-15 16:18:10 -04:00
|
|
|
if ( m_chkUseCurrent->GetValue() )
|
2009-07-23 16:30:22 -04:00
|
|
|
bbtn->SetBitmapCurrent(CreateBitmap(wxT("hover")));
|
2005-11-03 14:29:18 -05:00
|
|
|
if ( m_chkUseDisabled->GetValue() )
|
2009-07-23 16:30:22 -04:00
|
|
|
bbtn->SetBitmapDisabled(CreateBitmap(wxT("disabled")));
|
2005-11-02 20:28:17 -05:00
|
|
|
m_button = bbtn;
|
|
|
|
}
|
|
|
|
else // normal button
|
|
|
|
{
|
|
|
|
m_button = new wxButton(this, ButtonPage_Button, label,
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
flags);
|
|
|
|
}
|
2001-06-26 17:05:06 -04:00
|
|
|
|
2009-06-15 16:18:10 -04:00
|
|
|
if ( !showsBitmap && m_chkTextAndBitmap->GetValue() )
|
2001-06-26 17:05:06 -04:00
|
|
|
{
|
2009-06-15 16:18:10 -04:00
|
|
|
showsBitmap = true;
|
|
|
|
|
2009-06-15 00:23:54 -04:00
|
|
|
static const wxDirection positions[] =
|
|
|
|
{
|
|
|
|
wxLEFT, wxRIGHT, wxTOP, wxBOTTOM
|
|
|
|
};
|
|
|
|
|
|
|
|
m_button->SetBitmap(wxArtProvider::GetIcon(wxART_INFORMATION),
|
|
|
|
positions[m_radioImagePos->GetSelection()]);
|
2009-06-15 16:18:10 -04:00
|
|
|
|
|
|
|
if ( m_chkUsePressed->GetValue() )
|
|
|
|
m_button->SetBitmapPressed(wxArtProvider::GetIcon(wxART_HELP));
|
|
|
|
if ( m_chkUseFocused->GetValue() )
|
|
|
|
m_button->SetBitmapFocus(wxArtProvider::GetIcon(wxART_ERROR));
|
|
|
|
if ( m_chkUseCurrent->GetValue() )
|
|
|
|
m_button->SetBitmapCurrent(wxArtProvider::GetIcon(wxART_WARNING));
|
|
|
|
if ( m_chkUseDisabled->GetValue() )
|
|
|
|
m_button->SetBitmapDisabled(wxArtProvider::GetIcon(wxART_MISSING_IMAGE));
|
2001-06-26 17:05:06 -04:00
|
|
|
}
|
|
|
|
|
2009-06-15 16:18:10 -04:00
|
|
|
m_chkUsePressed->Enable(showsBitmap);
|
|
|
|
m_chkUseFocused->Enable(showsBitmap);
|
|
|
|
m_chkUseCurrent->Enable(showsBitmap);
|
|
|
|
m_chkUseDisabled->Enable(showsBitmap);
|
|
|
|
|
2001-06-26 17:05:06 -04:00
|
|
|
if ( m_chkDefault->GetValue() )
|
|
|
|
{
|
|
|
|
m_button->SetDefault();
|
|
|
|
}
|
|
|
|
|
2005-11-02 20:28:17 -05:00
|
|
|
AddButtonToSizer();
|
|
|
|
|
|
|
|
m_sizerButton->Layout();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ButtonWidgetsPage::AddButtonToSizer()
|
|
|
|
{
|
2001-06-26 17:05:06 -04:00
|
|
|
if ( m_chkFit->GetValue() )
|
|
|
|
{
|
2005-11-02 20:28:17 -05:00
|
|
|
m_sizerButton->AddStretchSpacer(1);
|
|
|
|
m_sizerButton->Add(m_button, wxSizerFlags(0).Centre().Border());
|
|
|
|
m_sizerButton->AddStretchSpacer(1);
|
2001-06-26 17:05:06 -04:00
|
|
|
}
|
2005-11-02 20:28:17 -05:00
|
|
|
else // take up the entire space
|
2001-06-26 17:05:06 -04:00
|
|
|
{
|
2005-11-02 20:28:17 -05:00
|
|
|
m_sizerButton->Add(m_button, wxSizerFlags(1).Expand().Border());
|
2001-06-26 17:05:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// event handlers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void ButtonWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
|
|
|
|
CreateButton();
|
|
|
|
}
|
|
|
|
|
2003-07-31 09:59:28 -04:00
|
|
|
void ButtonWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event))
|
2001-06-26 17:05:06 -04:00
|
|
|
{
|
|
|
|
CreateButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ButtonWidgetsPage::OnButtonChangeLabel(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
m_button->SetLabel(m_textLabel->GetValue());
|
2009-06-22 14:37:09 -04:00
|
|
|
|
|
|
|
m_sizerButton->Layout();
|
2001-06-26 17:05:06 -04:00
|
|
|
}
|
|
|
|
|
2003-07-31 09:59:28 -04:00
|
|
|
void ButtonWidgetsPage::OnButton(wxCommandEvent& WXUNUSED(event))
|
2001-06-26 17:05:06 -04:00
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
wxLogMessage(wxT("Test button clicked."));
|
2001-06-26 17:05:06 -04:00
|
|
|
}
|
|
|
|
|
2005-11-02 20:28:17 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// bitmap button stuff
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
wxBitmap ButtonWidgetsPage::CreateBitmap(const wxString& label)
|
|
|
|
{
|
|
|
|
wxBitmap bmp(180, 70); // shouldn't hardcode but it's simpler like this
|
|
|
|
wxMemoryDC dc;
|
|
|
|
dc.SelectObject(bmp);
|
2009-07-09 09:11:52 -04:00
|
|
|
dc.SetBackground(wxBrush(*wxCYAN));
|
2005-11-02 20:28:17 -05:00
|
|
|
dc.Clear();
|
2009-07-09 09:11:52 -04:00
|
|
|
dc.SetTextForeground(*wxBLACK);
|
2009-07-23 16:30:22 -04:00
|
|
|
dc.DrawLabel(wxStripMenuCodes(m_textLabel->GetValue()) + wxT("\n")
|
|
|
|
wxT("(") + label + wxT(" state)"),
|
2005-11-02 20:28:17 -05:00
|
|
|
wxArtProvider::GetBitmap(wxART_INFORMATION),
|
|
|
|
wxRect(10, 10, bmp.GetWidth() - 20, bmp.GetHeight() - 20),
|
|
|
|
wxALIGN_CENTRE);
|
|
|
|
|
|
|
|
return bmp;
|
|
|
|
}
|
|
|
|
|