Allow using wxEVT_UPDATE_UI with wxRibbonButtonBar.
Generate wxUpdateUIEvent for the ribbon buttons to allow updating their state using wxEVT_UPDATE_UI. Also update the same to show this. Closes #12003. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70180 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -461,6 +461,7 @@ All (GUI):
|
|||||||
- Support font-family/style, text-decoration in wxHtmlWindow (Blake Oleander).
|
- Support font-family/style, text-decoration in wxHtmlWindow (Blake Oleander).
|
||||||
- Show ribbon tools help strings in tooltips (John Roberts).
|
- Show ribbon tools help strings in tooltips (John Roberts).
|
||||||
- Improve row/column selection modes in wxGrid (joostn).
|
- Improve row/column selection modes in wxGrid (joostn).
|
||||||
|
- Allow using wxEVT_UPDATE_UI with wxRibbonButtonBar (Emilien Kia).
|
||||||
|
|
||||||
GTK:
|
GTK:
|
||||||
|
|
||||||
|
@@ -120,6 +120,7 @@ protected:
|
|||||||
static wxBitmap MakeDisabledBitmap(const wxBitmap& original);
|
static wxBitmap MakeDisabledBitmap(const wxBitmap& original);
|
||||||
void FetchButtonSizeInfo(wxRibbonButtonBarButtonBase* button,
|
void FetchButtonSizeInfo(wxRibbonButtonBarButtonBase* button,
|
||||||
wxRibbonButtonBarButtonState size, wxDC& dc);
|
wxRibbonButtonBarButtonState size, wxDC& dc);
|
||||||
|
virtual void UpdateWindowUI(long flags);
|
||||||
|
|
||||||
wxArrayRibbonButtonBarLayout m_layouts;
|
wxArrayRibbonButtonBarLayout m_layouts;
|
||||||
wxArrayRibbonButtonBarButtonBase m_buttons;
|
wxArrayRibbonButtonBarButtonBase m_buttons;
|
||||||
|
@@ -72,9 +72,26 @@ public:
|
|||||||
ID_POSITION_LEFT,
|
ID_POSITION_LEFT,
|
||||||
ID_POSITION_LEFT_LABELS,
|
ID_POSITION_LEFT_LABELS,
|
||||||
ID_POSITION_LEFT_BOTH,
|
ID_POSITION_LEFT_BOTH,
|
||||||
ID_TOGGLE_PANELS
|
ID_TOGGLE_PANELS,
|
||||||
|
ID_ENABLE,
|
||||||
|
ID_DISABLE,
|
||||||
|
ID_DISABLED,
|
||||||
|
ID_UI_ENABLE_UPDATED,
|
||||||
|
ID_CHECK,
|
||||||
|
ID_UI_CHECK_UPDATED,
|
||||||
|
ID_CHANGE_TEXT1,
|
||||||
|
ID_CHANGE_TEXT2,
|
||||||
|
ID_UI_CHANGE_TEXT_UPDATED
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void OnEnableUpdateUI(wxUpdateUIEvent& evt);
|
||||||
|
void OnCheckUpdateUI(wxUpdateUIEvent& evt);
|
||||||
|
void OnChangeTextUpdateUI(wxUpdateUIEvent& evt);
|
||||||
|
void OnCheck(wxRibbonButtonBarEvent& evt);
|
||||||
|
void OnEnable(wxRibbonButtonBarEvent& evt);
|
||||||
|
void OnDisable(wxRibbonButtonBarEvent& evt);
|
||||||
|
void OnChangeText1(wxRibbonButtonBarEvent& evt);
|
||||||
|
void OnChangeText2(wxRibbonButtonBarEvent& evt);
|
||||||
void OnCircleButton(wxRibbonButtonBarEvent& evt);
|
void OnCircleButton(wxRibbonButtonBarEvent& evt);
|
||||||
void OnCrossButton(wxRibbonButtonBarEvent& evt);
|
void OnCrossButton(wxRibbonButtonBarEvent& evt);
|
||||||
void OnTriangleButton(wxRibbonButtonBarEvent& evt);
|
void OnTriangleButton(wxRibbonButtonBarEvent& evt);
|
||||||
@@ -133,6 +150,9 @@ protected:
|
|||||||
wxColour m_default_secondary;
|
wxColour m_default_secondary;
|
||||||
wxColour m_default_tertiary;
|
wxColour m_default_tertiary;
|
||||||
wxMemoryDC m_bitmap_creation_dc;
|
wxMemoryDC m_bitmap_creation_dc;
|
||||||
|
bool m_bEnabled;
|
||||||
|
bool m_bChecked;
|
||||||
|
wxString m_new_text;
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
@@ -151,6 +171,14 @@ bool MyApp::OnInit()
|
|||||||
}
|
}
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||||
|
EVT_RIBBONBUTTONBAR_CLICKED(ID_ENABLE, MyFrame::OnEnable)
|
||||||
|
EVT_RIBBONBUTTONBAR_CLICKED(ID_DISABLE, MyFrame::OnDisable)
|
||||||
|
EVT_UPDATE_UI(ID_UI_ENABLE_UPDATED, MyFrame::OnEnableUpdateUI)
|
||||||
|
EVT_RIBBONBUTTONBAR_CLICKED(ID_CHECK, MyFrame::OnCheck)
|
||||||
|
EVT_UPDATE_UI(ID_UI_CHECK_UPDATED, MyFrame::OnCheckUpdateUI)
|
||||||
|
EVT_RIBBONBUTTONBAR_CLICKED(ID_CHANGE_TEXT1, MyFrame::OnChangeText1)
|
||||||
|
EVT_RIBBONBUTTONBAR_CLICKED(ID_CHANGE_TEXT2, MyFrame::OnChangeText2)
|
||||||
|
EVT_UPDATE_UI(ID_UI_CHANGE_TEXT_UPDATED, MyFrame::OnChangeTextUpdateUI)
|
||||||
EVT_RIBBONBUTTONBAR_CLICKED(ID_DEFAULT_PROVIDER, MyFrame::OnDefaultProvider)
|
EVT_RIBBONBUTTONBAR_CLICKED(ID_DEFAULT_PROVIDER, MyFrame::OnDefaultProvider)
|
||||||
EVT_RIBBONBUTTONBAR_CLICKED(ID_AUI_PROVIDER, MyFrame::OnAUIProvider)
|
EVT_RIBBONBUTTONBAR_CLICKED(ID_AUI_PROVIDER, MyFrame::OnAUIProvider)
|
||||||
EVT_RIBBONBUTTONBAR_CLICKED(ID_MSW_PROVIDER, MyFrame::OnMSWProvider)
|
EVT_RIBBONBUTTONBAR_CLICKED(ID_MSW_PROVIDER, MyFrame::OnMSWProvider)
|
||||||
@@ -315,6 +343,29 @@ MyFrame::MyFrame()
|
|||||||
m_secondary_gallery = PopulateColoursPanel(secondary_panel,
|
m_secondary_gallery = PopulateColoursPanel(secondary_panel,
|
||||||
m_default_secondary, ID_SECONDARY_COLOUR);
|
m_default_secondary, ID_SECONDARY_COLOUR);
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
wxRibbonPage* page = new wxRibbonPage(m_ribbon, wxID_ANY, wxT("UI Updated"), ribbon_xpm);
|
||||||
|
wxRibbonPanel *panel = new wxRibbonPanel(page, wxID_ANY, wxT("Enable/Disable"), ribbon_xpm);
|
||||||
|
wxRibbonButtonBar *bar = new wxRibbonButtonBar(panel, wxID_ANY);
|
||||||
|
bar->AddButton(ID_DISABLED, wxT("Disabled"), ribbon_xpm);
|
||||||
|
bar->AddButton(ID_ENABLE, wxT("Enable"), ribbon_xpm);
|
||||||
|
bar->AddButton(ID_DISABLE, wxT("Disable"), ribbon_xpm);
|
||||||
|
bar->AddButton(ID_UI_ENABLE_UPDATED, wxT("Enable UI updated"), ribbon_xpm);
|
||||||
|
bar->EnableButton(ID_DISABLED, false);
|
||||||
|
m_bEnabled = true;
|
||||||
|
|
||||||
|
panel = new wxRibbonPanel(page, wxID_ANY, wxT("Toggle"), ribbon_xpm);
|
||||||
|
bar = new wxRibbonButtonBar(panel, wxID_ANY);
|
||||||
|
bar->AddButton(ID_CHECK, wxT("Toggle"), ribbon_xpm);
|
||||||
|
bar->AddToggleButton(ID_UI_CHECK_UPDATED, wxT("Toggled UI updated"), ribbon_xpm);
|
||||||
|
m_bChecked = true;
|
||||||
|
|
||||||
|
panel = new wxRibbonPanel(page, wxID_ANY, wxT("Change text"), ribbon_xpm);
|
||||||
|
bar = new wxRibbonButtonBar(panel, wxID_ANY);
|
||||||
|
bar->AddButton(ID_CHANGE_TEXT1, wxT("One"), ribbon_xpm);
|
||||||
|
bar->AddButton(ID_CHANGE_TEXT2, wxT("Two"), ribbon_xpm);
|
||||||
|
bar->AddButton(ID_UI_CHANGE_TEXT_UPDATED, wxT("Zero"), ribbon_xpm);
|
||||||
|
}
|
||||||
new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Empty Page"), empty_xpm);
|
new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Empty Page"), empty_xpm);
|
||||||
new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Another Page"), empty_xpm);
|
new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Another Page"), empty_xpm);
|
||||||
|
|
||||||
@@ -507,6 +558,50 @@ void MyFrame::ResetGalleryArtProviders()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MyFrame::OnChangeText1(wxRibbonButtonBarEvent& WXUNUSED(evt))
|
||||||
|
{
|
||||||
|
m_new_text = wxT("One");
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyFrame::OnChangeText2(wxRibbonButtonBarEvent& WXUNUSED(evt))
|
||||||
|
{
|
||||||
|
m_new_text = wxT("Two");
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyFrame::OnEnable(wxRibbonButtonBarEvent& WXUNUSED(evt))
|
||||||
|
{
|
||||||
|
m_bEnabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyFrame::OnDisable(wxRibbonButtonBarEvent& WXUNUSED(evt))
|
||||||
|
{
|
||||||
|
m_bEnabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyFrame::OnCheck(wxRibbonButtonBarEvent& WXUNUSED(evt))
|
||||||
|
{
|
||||||
|
m_bChecked = !m_bChecked;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyFrame::OnEnableUpdateUI(wxUpdateUIEvent& evt)
|
||||||
|
{
|
||||||
|
evt.Enable(m_bEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyFrame::OnCheckUpdateUI(wxUpdateUIEvent& evt)
|
||||||
|
{
|
||||||
|
evt.Check(m_bChecked);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyFrame::OnChangeTextUpdateUI(wxUpdateUIEvent& evt)
|
||||||
|
{
|
||||||
|
if ( !m_new_text.IsEmpty() )
|
||||||
|
{
|
||||||
|
evt.SetText(m_new_text);
|
||||||
|
m_new_text = wxT("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MyFrame::OnSelectionExpandHButton(wxRibbonButtonBarEvent& WXUNUSED(evt))
|
void MyFrame::OnSelectionExpandHButton(wxRibbonButtonBarEvent& WXUNUSED(evt))
|
||||||
{
|
{
|
||||||
AddText(wxT("Expand selection horizontally button clicked."));
|
AddText(wxT("Expand selection horizontally button clicked."));
|
||||||
|
@@ -598,6 +598,42 @@ wxSize wxRibbonButtonBar::DoGetNextLargerSize(wxOrientation direction,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxRibbonButtonBar::UpdateWindowUI(long flags)
|
||||||
|
{
|
||||||
|
wxWindowBase::UpdateWindowUI(flags);
|
||||||
|
|
||||||
|
// don't waste time updating state of tools in a hidden toolbar
|
||||||
|
if ( !IsShown() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
size_t btn_count = m_buttons.size();
|
||||||
|
bool rerealize = false;
|
||||||
|
for ( size_t btn_i = 0; btn_i < btn_count; ++btn_i )
|
||||||
|
{
|
||||||
|
wxRibbonButtonBarButtonBase& btn = *m_buttons.Item(btn_i);
|
||||||
|
int id = btn.id;
|
||||||
|
|
||||||
|
wxUpdateUIEvent event(id);
|
||||||
|
event.SetEventObject(this);
|
||||||
|
|
||||||
|
if ( ProcessWindowEvent(event) )
|
||||||
|
{
|
||||||
|
if ( event.GetSetEnabled() )
|
||||||
|
EnableButton(id, event.GetEnabled());
|
||||||
|
if ( event.GetSetChecked() )
|
||||||
|
ToggleButton(id, event.GetChecked());
|
||||||
|
if ( event.GetSetText() )
|
||||||
|
{
|
||||||
|
btn.label = event.GetText();
|
||||||
|
rerealize = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( rerealize )
|
||||||
|
Realize();
|
||||||
|
}
|
||||||
|
|
||||||
void wxRibbonButtonBar::OnEraseBackground(wxEraseEvent& WXUNUSED(evt))
|
void wxRibbonButtonBar::OnEraseBackground(wxEraseEvent& WXUNUSED(evt))
|
||||||
{
|
{
|
||||||
// All painting done in main paint handler to minimise flicker
|
// All painting done in main paint handler to minimise flicker
|
||||||
|
Reference in New Issue
Block a user