wxDEFINE_EVENT(wxEVT_COMMAND_RIBBONBAR_TAB_RIGHT_UP, wxRibbonBarEvent);
wxDEFINE_EVENT(wxEVT_COMMAND_RIBBONBAR_TAB_LEFT_DCLICK, wxRibbonBarEvent);
wxDEFINE_EVENT(wxEVT_COMMAND_RIBBONBAR_TOGGLED, wxRibbonBarEvent);
wxDEFINE_EVENT(wxEVT_COMMAND_RIBBONBAR_TAB_RIGHT_UP, wxRibbonBarEvent);
wxDEFINE_EVENT(wxEVT_COMMAND_RIBBONBAR_TAB_LEFT_DCLICK, wxRibbonBarEvent);
wxDEFINE_EVENT(wxEVT_COMMAND_RIBBONBAR_TOGGLED, wxRibbonBarEvent);
IMPLEMENT_CLASS(wxRibbonBar, wxRibbonControl)
IMPLEMENT_DYNAMIC_CLASS(wxRibbonBarEvent, wxNotifyEvent)
IMPLEMENT_CLASS(wxRibbonBar, wxRibbonControl)
IMPLEMENT_DYNAMIC_CLASS(wxRibbonBarEvent, wxNotifyEvent)
EVT_RIGHT_UP(wxRibbonBar::OnMouseRightUp)
EVT_LEFT_DCLICK(wxRibbonBar::OnMouseDoubleClick)
EVT_SIZE(wxRibbonBar::OnSize)
EVT_RIGHT_UP(wxRibbonBar::OnMouseRightUp)
EVT_LEFT_DCLICK(wxRibbonBar::OnMouseDoubleClick)
EVT_SIZE(wxRibbonBar::OnSize)
- HitTestToggleButton(evt.GetPosition());
+ if ( m_flags & wxRIBBON_BAR_SHOW_TOGGLE_BUTTON )
+ HitTestRibbonButton(m_toggle_button_rect, evt.GetPosition(), m_toggle_button_hovered);
+ if ( m_flags & wxRIBBON_BAR_SHOW_HELP_BUTTON )
+ HitTestRibbonButton(m_help_button_rect, evt.GetPosition(), m_help_button_hovered);
- return (**first).small_must_have_separator_width - (**second).small_must_have_separator_width;
-}
+ wxEXPLICIT PageComparedBySmallWidthAsc(wxRibbonPageTabInfo* page)
+ : m_page(page)
+ {
+ }
+
+ bool operator<(const PageComparedBySmallWidthAsc& other) const
+ {
+ return m_page->small_must_have_separator_width
+ < other.m_page->small_must_have_separator_width;
+ }
+
+ wxRibbonPageTabInfo *m_page;
+};
m_tab_scroll_left_button_rect.SetWidth(m_art->GetScrollButtonMinimumSize(temp_dc, this, wxRIBBON_SCROLL_BTN_LEFT | wxRIBBON_SCROLL_BTN_NORMAL | wxRIBBON_SCROLL_BTN_FOR_TABS).GetWidth());
m_tab_scroll_left_button_rect.SetHeight(m_tab_height);
m_tab_scroll_left_button_rect.SetX(m_tab_margin_left);
m_tab_scroll_left_button_rect.SetY(0);
m_tab_scroll_right_button_rect.SetWidth(m_art->GetScrollButtonMinimumSize(temp_dc, this, wxRIBBON_SCROLL_BTN_RIGHT | wxRIBBON_SCROLL_BTN_NORMAL | wxRIBBON_SCROLL_BTN_FOR_TABS).GetWidth());
m_tab_scroll_right_button_rect.SetHeight(m_tab_height);
m_tab_scroll_left_button_rect.SetWidth(m_art->GetScrollButtonMinimumSize(temp_dc, this, wxRIBBON_SCROLL_BTN_LEFT | wxRIBBON_SCROLL_BTN_NORMAL | wxRIBBON_SCROLL_BTN_FOR_TABS).GetWidth());
m_tab_scroll_left_button_rect.SetHeight(m_tab_height);
m_tab_scroll_left_button_rect.SetX(m_tab_margin_left);
m_tab_scroll_left_button_rect.SetY(0);
m_tab_scroll_right_button_rect.SetWidth(m_art->GetScrollButtonMinimumSize(temp_dc, this, wxRIBBON_SCROLL_BTN_RIGHT | wxRIBBON_SCROLL_BTN_NORMAL | wxRIBBON_SCROLL_BTN_FOR_TABS).GetWidth());
m_tab_scroll_right_button_rect.SetHeight(m_tab_height);
- wxRibbonPageTabInfoArray sorted_pages;
- for(i = 0; i < numtabs; ++i)
- {
- // Sneaky obj array trickery to not copy the tab descriptors
- if (!m_pages.Item(i).shown)
- continue;
- sorted_pages.Add(&m_pages.Item(i));
- }
- sorted_pages.Sort(OrderPageTabInfoBySmallWidthAsc);
+ wxVector<PageComparedBySmallWidthAsc> sorted_pages;
+ sorted_pages.reserve(numtabs);
+ for ( i = 0; i < numtabs; ++i )
+ sorted_pages.push_back(PageComparedBySmallWidthAsc(&m_pages.Item(i)));
+
+ wxVectorSort(sorted_pages);
- m_toggle_button_rect = m_art->GetBarToggleButtonArea(dc, this, GetSize());
+ if ( m_flags & wxRIBBON_BAR_SHOW_HELP_BUTTON )
+ m_help_button_rect = m_art->GetRibbonHelpButtonArea(GetSize());
+ if ( m_flags & wxRIBBON_BAR_SHOW_TOGGLE_BUTTON )
+ m_toggle_button_rect = m_art->GetBarToggleButtonArea(GetSize());
m_art->DrawScrollButton(dc, this, m_tab_scroll_left_button_rect, wxRIBBON_SCROLL_BTN_LEFT | m_tab_scroll_left_button_state | wxRIBBON_SCROLL_BTN_FOR_TABS);
}
if(m_tab_scroll_right_button_rect.GetWidth() != 0)
{
m_art->DrawScrollButton(dc, this, m_tab_scroll_left_button_rect, wxRIBBON_SCROLL_BTN_LEFT | m_tab_scroll_left_button_state | wxRIBBON_SCROLL_BTN_FOR_TABS);
}
if(m_tab_scroll_right_button_rect.GetWidth() != 0)
{
m_art->DrawScrollButton(dc, this, m_tab_scroll_right_button_rect, wxRIBBON_SCROLL_BTN_RIGHT | m_tab_scroll_right_button_state | wxRIBBON_SCROLL_BTN_FOR_TABS);
}
}
m_art->DrawScrollButton(dc, this, m_tab_scroll_right_button_rect, wxRIBBON_SCROLL_BTN_RIGHT | m_tab_scroll_right_button_state | wxRIBBON_SCROLL_BTN_FOR_TABS);
}
}
- wxRect rect(GetClientSize().GetWidth() - 30, 6, 12, 12);
+
+ if ( m_flags & wxRIBBON_BAR_SHOW_HELP_BUTTON )
+ m_art->DrawHelpButton(dc, this, m_help_button_rect);
- m_art->DrawToggleButton(dc, this, rect, ArePanelsShown());
+ m_art->DrawToggleButton(dc, this, m_toggle_button_rect, m_ribbon_state);
+
void wxRibbonBar::OnMouseLeftDown(wxMouseEvent& evt)
{
wxRibbonPageTabInfo *tab = HitTestTabs(evt.GetPosition());
void wxRibbonBar::OnMouseLeftDown(wxMouseEvent& evt)
{
wxRibbonPageTabInfo *tab = HitTestTabs(evt.GetPosition());
+ SetFocus();
+ if ( tab )
+ {
+ if ( m_ribbon_state == wxRIBBON_BAR_MINIMIZED )
+ {
+ ShowPanels();
+ m_ribbon_state = wxRIBBON_BAR_EXPANDED;
+ }
+ else if ( (tab == &m_pages.Item(m_current_page)) && (m_ribbon_state == wxRIBBON_BAR_EXPANDED) )
+ {
+ HidePanels();
+ m_ribbon_state = wxRIBBON_BAR_MINIMIZED;
+ }
+ }
+ else
+ {
+ if ( m_ribbon_state == wxRIBBON_BAR_EXPANDED )
+ {
+ HidePanels();
+ m_ribbon_state = wxRIBBON_BAR_MINIMIZED;
+ }
+ }
if(tab && tab != &m_pages.Item(m_current_page))
{
wxRibbonBarEvent query(wxEVT_COMMAND_RIBBONBAR_PAGE_CHANGING, GetId(), tab->page);
if(tab && tab != &m_pages.Item(m_current_page))
{
wxRibbonBarEvent query(wxEVT_COMMAND_RIBBONBAR_PAGE_CHANGING, GetId(), tab->page);
wxRibbonBarEvent event(wxEVT_COMMAND_RIBBONBAR_TOGGLED, GetId());
event.SetEventObject(this);
ProcessWindowEvent(event);
}
wxRibbonBarEvent event(wxEVT_COMMAND_RIBBONBAR_TOGGLED, GetId());
event.SetEventObject(this);
ProcessWindowEvent(event);
}
+ if ( m_help_button_rect.Contains(position) )
+ {
+ wxRibbonBarEvent event(wxEVT_COMMAND_RIBBONBAR_HELP_CLICKED, GetId());
+ event.SetEventObject(this);
+ ProcessWindowEvent(event);
+ }
- DoMouseButtonCommon(evt, wxEVT_COMMAND_RIBBONBAR_TAB_LEFT_DCLICK);
+ wxRibbonPageTabInfo *tab = HitTestTabs(evt.GetPosition());
+ SetFocus();
+ if ( tab && tab == &m_pages.Item(m_current_page) )
+ {
+ if ( m_ribbon_state == wxRIBBON_BAR_PINNED )
+ {
+ m_ribbon_state = wxRIBBON_BAR_MINIMIZED;
+ HidePanels();
+ }
+ else
+ {
+ m_ribbon_state = wxRIBBON_BAR_PINNED;
+ ShowPanels();
+ }
+ }
{
bool hovered = false, toggle_button_hovered = false;
if(position.x >= 0 && position.y >= 0)
{
bool hovered = false, toggle_button_hovered = false;
if(position.x >= 0 && position.y >= 0)
+void wxRibbonBar::HideIfExpanded()
+{
+ if ( m_ribbon_state == wxRIBBON_BAR_EXPANDED )
+ {
+ HidePanels();
+ m_ribbon_state = wxRIBBON_BAR_MINIMIZED;
+ }
+ else
+ {
+ ShowPanels();
+ m_ribbon_state = wxRIBBON_BAR_PINNED;
+ }
+}
+
+void wxRibbonBar::OnKillFocus(wxFocusEvent& WXUNUSED(evt))
+{
+ HideIfExpanded();
+}
+