Add new wxCommandLinkButton class.
A command link button wraps a native MSW control under recent Windows versions and is implemented generically as a simple bitmap button elsewhere. In the future, GTK implementation should allow using a different font for the button label and its note. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65327 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
#include "wx/artprov.h"
|
||||
#include "wx/sizer.h"
|
||||
#include "wx/dcmemory.h"
|
||||
#include "wx/commandlinkbutton.h"
|
||||
|
||||
#include "widgets.h"
|
||||
|
||||
@@ -54,6 +55,7 @@ enum
|
||||
{
|
||||
ButtonPage_Reset = wxID_HIGHEST,
|
||||
ButtonPage_ChangeLabel,
|
||||
ButtonPage_ChangeNote,
|
||||
ButtonPage_Button
|
||||
};
|
||||
|
||||
@@ -103,6 +105,7 @@ protected:
|
||||
void OnButton(wxCommandEvent& event);
|
||||
void OnButtonReset(wxCommandEvent& event);
|
||||
void OnButtonChangeLabel(wxCommandEvent& event);
|
||||
void OnButtonChangeNote(wxCommandEvent& event);
|
||||
|
||||
// reset the wxButton parameters
|
||||
void Reset();
|
||||
@@ -125,6 +128,7 @@ protected:
|
||||
*m_chkTextAndBitmap,
|
||||
*m_chkFit,
|
||||
*m_chkAuthNeeded,
|
||||
*m_chkCommandLink,
|
||||
*m_chkDefault;
|
||||
|
||||
// more checkboxes for wxBitmapButton only
|
||||
@@ -141,11 +145,24 @@ protected:
|
||||
|
||||
// the button itself and the sizer it is in
|
||||
wxButton *m_button;
|
||||
|
||||
#if wxUSE_COMMANDLINKBUTTON
|
||||
// same as m_button or NULL if not showing a command link button currently
|
||||
wxCommandLinkButton *m_cmdLnkButton;
|
||||
#endif // wxUSE_COMMANDLINKBUTTON
|
||||
|
||||
wxSizer *m_sizerButton;
|
||||
|
||||
// the text entries for command parameters
|
||||
wxTextCtrl *m_textLabel;
|
||||
|
||||
#if wxUSE_COMMANDLINKBUTTON
|
||||
wxTextCtrl *m_textNote;
|
||||
|
||||
// used to hide or show button for changing note
|
||||
wxSizer *m_sizerNote;
|
||||
#endif // wxUSE_COMMANDLINKBUTTON
|
||||
|
||||
private:
|
||||
DECLARE_EVENT_TABLE()
|
||||
DECLARE_WIDGETS_PAGE(ButtonWidgetsPage)
|
||||
@@ -160,6 +177,7 @@ BEGIN_EVENT_TABLE(ButtonWidgetsPage, WidgetsPage)
|
||||
|
||||
EVT_BUTTON(ButtonPage_Reset, ButtonWidgetsPage::OnButtonReset)
|
||||
EVT_BUTTON(ButtonPage_ChangeLabel, ButtonWidgetsPage::OnButtonChangeLabel)
|
||||
EVT_BUTTON(ButtonPage_ChangeNote, ButtonWidgetsPage::OnButtonChangeNote)
|
||||
|
||||
EVT_CHECKBOX(wxID_ANY, ButtonWidgetsPage::OnCheckOrRadioBox)
|
||||
EVT_RADIOBOX(wxID_ANY, ButtonWidgetsPage::OnCheckOrRadioBox)
|
||||
@@ -186,6 +204,7 @@ ButtonWidgetsPage::ButtonWidgetsPage(WidgetsBookCtrl *book,
|
||||
m_chkTextAndBitmap =
|
||||
m_chkFit =
|
||||
m_chkAuthNeeded =
|
||||
m_chkCommandLink =
|
||||
m_chkDefault =
|
||||
m_chkUsePressed =
|
||||
m_chkUseFocused =
|
||||
@@ -215,6 +234,9 @@ void ButtonWidgetsPage::CreateContent()
|
||||
m_chkTextAndBitmap = CreateCheckBoxAndAddToSizer(sizerLeft, "Text &and bitmap");
|
||||
m_chkFit = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("&Fit exactly"));
|
||||
m_chkAuthNeeded = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("Require a&uth"));
|
||||
#if wxUSE_COMMANDLINKBUTTON
|
||||
m_chkCommandLink = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("Use command &link button"));
|
||||
#endif
|
||||
m_chkDefault = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("&Default"));
|
||||
|
||||
sizerLeft->AddSpacer(5);
|
||||
@@ -283,9 +305,18 @@ void ButtonWidgetsPage::CreateContent()
|
||||
wxID_ANY,
|
||||
&m_textLabel);
|
||||
m_textLabel->SetValue(wxT("&Press me!"));
|
||||
|
||||
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
|
||||
|
||||
#if wxUSE_COMMANDLINKBUTTON
|
||||
m_sizerNote = CreateSizerWithTextAndButton(ButtonPage_ChangeNote,
|
||||
wxT("Change note"),
|
||||
wxID_ANY,
|
||||
&m_textNote);
|
||||
m_textNote->SetValue(wxT("Writes down button clicks in the log."));
|
||||
|
||||
sizerMiddle->Add(m_sizerNote, 0, wxALL | wxGROW, 5);
|
||||
#endif
|
||||
|
||||
// right pane
|
||||
m_sizerButton = new wxBoxSizer(wxHORIZONTAL);
|
||||
m_sizerButton->SetMinSize(150, 0);
|
||||
@@ -313,6 +344,9 @@ void ButtonWidgetsPage::Reset()
|
||||
m_chkAuthNeeded->SetValue(false);
|
||||
m_chkTextAndBitmap->SetValue(false);
|
||||
m_chkDefault->SetValue(false);
|
||||
#if wxUSE_COMMANDLINKBUTTON
|
||||
m_chkCommandLink->SetValue(false);
|
||||
#endif
|
||||
|
||||
m_chkUsePressed->SetValue(true);
|
||||
m_chkUseFocused->SetValue(true);
|
||||
@@ -329,7 +363,12 @@ void ButtonWidgetsPage::CreateButton()
|
||||
wxString label;
|
||||
if ( m_button )
|
||||
{
|
||||
label = m_button->GetLabel();
|
||||
#if wxUSE_COMMANDLINKBUTTON
|
||||
if ( m_cmdLnkButton )
|
||||
label = m_cmdLnkButton->GetMainLabel();
|
||||
else
|
||||
#endif
|
||||
label = m_button->GetLabel();
|
||||
|
||||
size_t count = m_sizerButton->GetChildren().GetCount();
|
||||
for ( size_t n = 0; n < count; n++ )
|
||||
@@ -385,6 +424,10 @@ void ButtonWidgetsPage::CreateButton()
|
||||
break;
|
||||
}
|
||||
|
||||
#if wxUSE_COMMANDLINKBUTTON
|
||||
m_sizerNote->Show(m_chkCommandLink->GetValue());
|
||||
#endif
|
||||
|
||||
bool showsBitmap = false;
|
||||
if ( m_chkBitmapOnly->GetValue() )
|
||||
{
|
||||
@@ -401,12 +444,32 @@ void ButtonWidgetsPage::CreateButton()
|
||||
if ( m_chkUseDisabled->GetValue() )
|
||||
bbtn->SetBitmapDisabled(CreateBitmap(wxT("disabled")));
|
||||
m_button = bbtn;
|
||||
#if wxUSE_COMMANDLINKBUTTON
|
||||
m_cmdLnkButton = NULL;
|
||||
#endif
|
||||
}
|
||||
else // normal button
|
||||
{
|
||||
m_button = new wxButton(this, ButtonPage_Button, label,
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
flags);
|
||||
#if wxUSE_COMMANDLINKBUTTON
|
||||
m_cmdLnkButton = NULL;
|
||||
|
||||
if ( m_chkCommandLink->GetValue() )
|
||||
{
|
||||
m_cmdLnkButton = new wxCommandLinkButton(this, ButtonPage_Button,
|
||||
label,
|
||||
m_textNote->GetValue(),
|
||||
wxDefaultPosition,
|
||||
wxDefaultSize,
|
||||
flags);
|
||||
m_button = m_cmdLnkButton;
|
||||
}
|
||||
else
|
||||
#endif // wxUSE_COMMANDLINKBUTTON
|
||||
{
|
||||
m_button = new wxButton(this, ButtonPage_Button, label,
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
flags);
|
||||
}
|
||||
}
|
||||
|
||||
if ( !showsBitmap && m_chkTextAndBitmap->GetValue() )
|
||||
@@ -475,15 +538,30 @@ void ButtonWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
|
||||
void ButtonWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
CreateButton();
|
||||
Layout(); // make sure the text field for changing note displays correctly.
|
||||
}
|
||||
|
||||
void ButtonWidgetsPage::OnButtonChangeLabel(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
m_button->SetLabel(m_textLabel->GetValue());
|
||||
#if wxUSE_COMMANDLINKBUTTON
|
||||
if ( m_cmdLnkButton )
|
||||
m_cmdLnkButton->SetMainLabel(m_textLabel->GetValue());
|
||||
else
|
||||
#endif // wxUSE_COMMANDLINKBUTTON
|
||||
m_button->SetLabel(m_textLabel->GetValue());
|
||||
|
||||
m_sizerButton->Layout();
|
||||
}
|
||||
|
||||
void ButtonWidgetsPage::OnButtonChangeNote(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
#if wxUSE_COMMANDLINKBUTTON
|
||||
m_cmdLnkButton->SetNote(m_textNote->GetValue());
|
||||
|
||||
m_sizerButton->Layout();
|
||||
#endif // wxUSE_COMMANDLINKBUTTON
|
||||
}
|
||||
|
||||
void ButtonWidgetsPage::OnButton(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
wxLogMessage(wxT("Test button clicked."));
|
||||
|
Reference in New Issue
Block a user