X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/054f177b001d34bf1314b364c8289bec4c08b17c..115eded74f98a265636f0d484f821638b3e2c146:/src/aui/auibar.cpp diff --git a/src/aui/auibar.cpp b/src/aui/auibar.cpp index 03789c7a4c..1abf08a60a 100644 --- a/src/aui/auibar.cpp +++ b/src/aui/auibar.cpp @@ -46,11 +46,11 @@ WX_DEFINE_OBJARRAY(wxAuiToolBarItemArray) -DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN) -DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK) -DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK) -DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK) -DEFINE_EVENT_TYPE(wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG) +wxDEFINE_EVENT( wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN, wxAuiToolBarEvent ); +wxDEFINE_EVENT( wxEVT_COMMAND_AUITOOLBAR_OVERFLOW_CLICK, wxAuiToolBarEvent ); +wxDEFINE_EVENT( wxEVT_COMMAND_AUITOOLBAR_RIGHT_CLICK, wxAuiToolBarEvent ); +wxDEFINE_EVENT( wxEVT_COMMAND_AUITOOLBAR_MIDDLE_CLICK, wxAuiToolBarEvent ); +wxDEFINE_EVENT( wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG, wxAuiToolBarEvent ); IMPLEMENT_CLASS(wxAuiToolBar, wxControl) @@ -1460,15 +1460,39 @@ void wxAuiToolBar::ToggleTool(int tool_id, bool state) { wxAuiToolBarItem* tool = FindTool(tool_id); - if (tool) + if (tool && (tool->kind == wxITEM_CHECK || tool->kind == wxITEM_RADIO)) { - if (tool->kind != wxITEM_CHECK) - return; - - if (state == true) + if (tool->kind == wxITEM_RADIO) + { + int i, idx, count; + idx = GetToolIndex(tool_id); + count = (int)m_items.GetCount(); + + if (idx >= 0 && idx < count) + { + for (i = idx; i < count; ++i) + { + if (m_items[i].kind != wxITEM_RADIO) + break; + m_items[i].state &= ~wxAUI_BUTTON_STATE_CHECKED; + } + for (i = idx; i > 0; i--) + { + if (m_items[i].kind != wxITEM_RADIO) + break; + m_items[i].state &= ~wxAUI_BUTTON_STATE_CHECKED; + } + } + tool->state |= wxAUI_BUTTON_STATE_CHECKED; - else - tool->state &= ~wxAUI_BUTTON_STATE_CHECKED; + } + else if (tool->kind == wxITEM_CHECK) + { + if (state == true) + tool->state |= wxAUI_BUTTON_STATE_CHECKED; + else + tool->state &= ~wxAUI_BUTTON_STATE_CHECKED; + } } } @@ -1478,7 +1502,7 @@ bool wxAuiToolBar::GetToolToggled(int tool_id) const if (tool) { - if (tool->kind != wxITEM_CHECK) + if ( (tool->kind != wxITEM_CHECK) && (tool->kind != wxITEM_RADIO) ) return false; return (tool->state & wxAUI_BUTTON_STATE_CHECKED) ? true : false; @@ -1744,6 +1768,7 @@ bool wxAuiToolBar::Realize() case wxITEM_CHECK: case wxITEM_NORMAL: + case wxITEM_RADIO: { wxSize size = m_art->GetToolSize(dc, this, item); sizer_item = sizer->Add(size.x + (m_tool_border_padding*2), @@ -2202,6 +2227,11 @@ void wxAuiToolBar::OnPaint(wxPaintEvent& WXUNUSED(evt)) // draw a toggle button m_art->DrawButton(dc, this, item, item_rect); } + else if (item.kind == wxITEM_RADIO) + { + // draw a toggle button + m_art->DrawButton(dc, this, item, item_rect); + } else if (item.kind == wxITEM_CONTROL) { // draw the control's label @@ -2260,7 +2290,7 @@ void wxAuiToolBar::OnLeftDown(wxMouseEvent& evt) e.SetEventObject(this); e.SetToolId(-1); e.SetClickPoint(wxPoint(evt.GetX(), evt.GetY())); - bool processed = ProcessEvent(e); + bool processed = GetEventHandler()->ProcessEvent(e); if (processed) { @@ -2297,7 +2327,7 @@ void wxAuiToolBar::OnLeftDown(wxMouseEvent& evt) { wxCommandEvent e(wxEVT_COMMAND_MENU_SELECTED, res); e.SetEventObject(this); - GetParent()->ProcessEvent(e); + GetParent()->GetEventHandler()->ProcessEvent(e); } } @@ -2338,7 +2368,7 @@ void wxAuiToolBar::OnLeftDown(wxMouseEvent& evt) e.SetClickPoint(evt.GetPosition()); e.SetItemRect(rect); - ProcessEvent(e); + GetEventHandler()->ProcessEvent(e); DoIdleUpdate(); } } @@ -2371,7 +2401,7 @@ void wxAuiToolBar::OnLeftUp(wxMouseEvent& evt) { UnsetToolTip(); - if (hit_item->kind == wxITEM_CHECK) + if (hit_item->kind == wxITEM_CHECK || hit_item->kind == wxITEM_RADIO) { bool toggle = false; @@ -2381,17 +2411,21 @@ void wxAuiToolBar::OnLeftUp(wxMouseEvent& evt) toggle = true; ToggleTool(m_action_item->id, toggle); - + + // repaint immediately + Refresh(false); + Update(); + wxCommandEvent e(wxEVT_COMMAND_MENU_SELECTED, m_action_item->id); e.SetEventObject(this); - ProcessEvent(e); + GetEventHandler()->ProcessEvent(e); DoIdleUpdate(); } else { wxCommandEvent e(wxEVT_COMMAND_MENU_SELECTED, m_action_item->id); e.SetEventObject(this); - ProcessEvent(e); + GetEventHandler()->ProcessEvent(e); DoIdleUpdate(); } } @@ -2454,7 +2488,7 @@ void wxAuiToolBar::OnRightUp(wxMouseEvent& evt) e.SetEventObject(this); e.SetToolId(m_action_item->id); e.SetClickPoint(m_action_pos); - ProcessEvent(e); + GetEventHandler()->ProcessEvent(e); DoIdleUpdate(); } } @@ -2465,7 +2499,7 @@ void wxAuiToolBar::OnRightUp(wxMouseEvent& evt) e.SetEventObject(this); e.SetToolId(-1); e.SetClickPoint(m_action_pos); - ProcessEvent(e); + GetEventHandler()->ProcessEvent(e); DoIdleUpdate(); } @@ -2525,7 +2559,7 @@ void wxAuiToolBar::OnMiddleUp(wxMouseEvent& evt) e.SetEventObject(this); e.SetToolId(m_action_item->id); e.SetClickPoint(m_action_pos); - ProcessEvent(e); + GetEventHandler()->ProcessEvent(e); DoIdleUpdate(); } } @@ -2550,7 +2584,7 @@ void wxAuiToolBar::OnMotion(wxMouseEvent& evt) wxAuiToolBarEvent e(wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG, GetId()); e.SetEventObject(this); e.SetToolId(m_action_item->id); - ProcessEvent(e); + GetEventHandler()->ProcessEvent(e); DoIdleUpdate(); return; }