Merge branch 'updateui-ischeckable'
Add a flag to wxUpdateUIEvent to tell if the item supports the check action. See https://github.com/wxWidgets/wxWidgets/pull/2027
This commit is contained in:
@@ -211,6 +211,11 @@ public:
|
|||||||
void SetAlignment(int l) { m_alignment = l; }
|
void SetAlignment(int l) { m_alignment = l; }
|
||||||
int GetAlignment() const { return m_alignment; }
|
int GetAlignment() const { return m_alignment; }
|
||||||
|
|
||||||
|
bool CanBeToggled() const
|
||||||
|
{
|
||||||
|
return m_kind == wxITEM_CHECK || m_kind == wxITEM_RADIO;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
wxWindow* m_window; // item's associated window
|
wxWindow* m_window; // item's associated window
|
||||||
|
@@ -2892,6 +2892,7 @@ public:
|
|||||||
m_setShown =
|
m_setShown =
|
||||||
m_setText =
|
m_setText =
|
||||||
m_setChecked = false;
|
m_setChecked = false;
|
||||||
|
m_isCheckable = true;
|
||||||
}
|
}
|
||||||
wxUpdateUIEvent(const wxUpdateUIEvent& event)
|
wxUpdateUIEvent(const wxUpdateUIEvent& event)
|
||||||
: wxCommandEvent(event),
|
: wxCommandEvent(event),
|
||||||
@@ -2902,6 +2903,7 @@ public:
|
|||||||
m_setShown(event.m_setShown),
|
m_setShown(event.m_setShown),
|
||||||
m_setText(event.m_setText),
|
m_setText(event.m_setText),
|
||||||
m_setChecked(event.m_setChecked),
|
m_setChecked(event.m_setChecked),
|
||||||
|
m_isCheckable(event.m_isCheckable),
|
||||||
m_text(event.m_text)
|
m_text(event.m_text)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
@@ -2919,6 +2921,10 @@ public:
|
|||||||
void Show(bool show) { m_shown = show; m_setShown = true; }
|
void Show(bool show) { m_shown = show; m_setShown = true; }
|
||||||
void SetText(const wxString& text) { m_text = text; m_setText = true; }
|
void SetText(const wxString& text) { m_text = text; m_setText = true; }
|
||||||
|
|
||||||
|
// A flag saying if the item can be checked. True by default.
|
||||||
|
bool IsCheckable() const { return m_isCheckable; }
|
||||||
|
void DisallowCheck() { m_isCheckable = false; }
|
||||||
|
|
||||||
// Sets the interval between updates in milliseconds.
|
// Sets the interval between updates in milliseconds.
|
||||||
// Set to -1 to disable updates, or to 0 to update as frequently as possible.
|
// Set to -1 to disable updates, or to 0 to update as frequently as possible.
|
||||||
static void SetUpdateInterval(long updateInterval) { sm_updateInterval = updateInterval; }
|
static void SetUpdateInterval(long updateInterval) { sm_updateInterval = updateInterval; }
|
||||||
@@ -2951,6 +2957,7 @@ protected:
|
|||||||
bool m_setShown;
|
bool m_setShown;
|
||||||
bool m_setText;
|
bool m_setText;
|
||||||
bool m_setChecked;
|
bool m_setChecked;
|
||||||
|
bool m_isCheckable;
|
||||||
wxString m_text;
|
wxString m_text;
|
||||||
#if wxUSE_LONGLONG
|
#if wxUSE_LONGLONG
|
||||||
static wxLongLong sm_lastUpdate;
|
static wxLongLong sm_lastUpdate;
|
||||||
|
@@ -407,6 +407,13 @@ public:
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
int GetAlignment() const;
|
int GetAlignment() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns whether the toolbar item can be toggled.
|
||||||
|
|
||||||
|
@since 3.1.5
|
||||||
|
*/
|
||||||
|
bool CanBeToggled() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -2374,6 +2374,26 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool GetEnabled() const;
|
bool GetEnabled() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns @true if the UI element can be checked.
|
||||||
|
|
||||||
|
For the event handlers that can be used for multiple items, not all of
|
||||||
|
which can be checked, this method can be useful to determine whether
|
||||||
|
to call Check() on the event object or not, i.e. the main use case for
|
||||||
|
this method is:
|
||||||
|
@code
|
||||||
|
void MyWindow::OnUpdateUI(wxUpdateUIEvent& event)
|
||||||
|
{
|
||||||
|
....
|
||||||
|
if ( event.IsCheckable() )
|
||||||
|
event.Check(...some condition...);
|
||||||
|
}
|
||||||
|
@endcode
|
||||||
|
|
||||||
|
@since 3.1.5
|
||||||
|
*/
|
||||||
|
bool IsCheckable() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Static function returning a value specifying how wxWidgets will send update
|
Static function returning a value specifying how wxWidgets will send update
|
||||||
events: to all windows, or only to those which specify that they will process
|
events: to all windows, or only to those which specify that they will process
|
||||||
|
@@ -1546,7 +1546,7 @@ void wxAuiToolBar::ToggleTool(int tool_id, bool state)
|
|||||||
{
|
{
|
||||||
wxAuiToolBarItem* tool = FindTool(tool_id);
|
wxAuiToolBarItem* tool = FindTool(tool_id);
|
||||||
|
|
||||||
if (tool && (tool->m_kind == wxITEM_CHECK || tool->m_kind == wxITEM_RADIO))
|
if ( tool && tool->CanBeToggled() )
|
||||||
{
|
{
|
||||||
if (tool->m_kind == wxITEM_RADIO)
|
if (tool->m_kind == wxITEM_RADIO)
|
||||||
{
|
{
|
||||||
@@ -1587,13 +1587,8 @@ bool wxAuiToolBar::GetToolToggled(int tool_id) const
|
|||||||
{
|
{
|
||||||
wxAuiToolBarItem* tool = FindTool(tool_id);
|
wxAuiToolBarItem* tool = FindTool(tool_id);
|
||||||
|
|
||||||
if (tool)
|
if ( tool && tool->CanBeToggled() )
|
||||||
{
|
|
||||||
if ( (tool->m_kind != wxITEM_CHECK) && (tool->m_kind != wxITEM_RADIO) )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return (tool->m_state & wxAUI_BUTTON_STATE_CHECKED) ? true : false;
|
return (tool->m_state & wxAUI_BUTTON_STATE_CHECKED) ? true : false;
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -2200,6 +2195,9 @@ void wxAuiToolBar::DoIdleUpdate()
|
|||||||
wxUpdateUIEvent evt(item.m_toolId);
|
wxUpdateUIEvent evt(item.m_toolId);
|
||||||
evt.SetEventObject(this);
|
evt.SetEventObject(this);
|
||||||
|
|
||||||
|
if ( !item.CanBeToggled() )
|
||||||
|
evt.DisallowCheck();
|
||||||
|
|
||||||
if (handler->ProcessEvent(evt))
|
if (handler->ProcessEvent(evt))
|
||||||
{
|
{
|
||||||
if (evt.GetSetEnabled())
|
if (evt.GetSetEnabled())
|
||||||
|
@@ -617,6 +617,9 @@ void wxMenuBase::UpdateUI(wxEvtHandler* source)
|
|||||||
wxUpdateUIEvent event(itemid);
|
wxUpdateUIEvent event(itemid);
|
||||||
event.SetEventObject( this );
|
event.SetEventObject( this );
|
||||||
|
|
||||||
|
if ( !item->IsCheckable() )
|
||||||
|
event.DisallowCheck();
|
||||||
|
|
||||||
if ( source->ProcessEvent(event) )
|
if ( source->ProcessEvent(event) )
|
||||||
{
|
{
|
||||||
// if anything changed, update the changed attribute
|
// if anything changed, update the changed attribute
|
||||||
|
@@ -739,6 +739,9 @@ void wxToolBarBase::UpdateWindowUI(long flags)
|
|||||||
wxUpdateUIEvent event(toolid);
|
wxUpdateUIEvent event(toolid);
|
||||||
event.SetEventObject(this);
|
event.SetEventObject(this);
|
||||||
|
|
||||||
|
if ( !tool->CanBeToggled() )
|
||||||
|
event.DisallowCheck();
|
||||||
|
|
||||||
if ( evtHandler->ProcessEvent(event) )
|
if ( evtHandler->ProcessEvent(event) )
|
||||||
{
|
{
|
||||||
if ( event.GetSetEnabled() )
|
if ( event.GetSetEnabled() )
|
||||||
|
@@ -324,6 +324,9 @@ bool wxMenu::HandleCommandUpdateStatus( wxMenuItem* item, wxWindow* senderWindow
|
|||||||
wxUpdateUIEvent event(menuid);
|
wxUpdateUIEvent event(menuid);
|
||||||
event.SetEventObject( this );
|
event.SetEventObject( this );
|
||||||
|
|
||||||
|
if ( !item || !item->IsCheckable() )
|
||||||
|
event.DisallowCheck();
|
||||||
|
|
||||||
bool processed = DoProcessEvent(this, event, GetWindow());
|
bool processed = DoProcessEvent(this, event, GetWindow());
|
||||||
|
|
||||||
if ( !processed && senderWindow != NULL)
|
if ( !processed && senderWindow != NULL)
|
||||||
|
Reference in New Issue
Block a user