// Author: Peter Cawley
// Modified by:
// Created: 2009-05-23
-// RCS-ID: $Id$
// Copyright: (C) Peter Cawley
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#include "wx/ribbon/art.h"
#include "wx/dcbuffer.h"
#include "wx/app.h"
+#include "wx/vector.h"
#ifndef WX_PRECOMP
#endif
WX_DEFINE_USER_EXPORTED_OBJARRAY(wxRibbonPageTabInfoArray)
-wxDEFINE_EVENT(wxEVT_COMMAND_RIBBONBAR_PAGE_CHANGED, wxRibbonBarEvent);
-wxDEFINE_EVENT(wxEVT_COMMAND_RIBBONBAR_PAGE_CHANGING, wxRibbonBarEvent);
-wxDEFINE_EVENT(wxEVT_COMMAND_RIBBONBAR_TAB_MIDDLE_DOWN, wxRibbonBarEvent);
-wxDEFINE_EVENT(wxEVT_COMMAND_RIBBONBAR_TAB_MIDDLE_UP, wxRibbonBarEvent);
-wxDEFINE_EVENT(wxEVT_COMMAND_RIBBONBAR_TAB_RIGHT_DOWN, 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);
-wxDEFINE_EVENT(wxEVT_COMMAND_RIBBONBAR_HELP_CLICKED, wxRibbonBarEvent);
+wxDEFINE_EVENT(wxEVT_RIBBONBAR_PAGE_CHANGED, wxRibbonBarEvent);
+wxDEFINE_EVENT(wxEVT_RIBBONBAR_PAGE_CHANGING, wxRibbonBarEvent);
+wxDEFINE_EVENT(wxEVT_RIBBONBAR_TAB_MIDDLE_DOWN, wxRibbonBarEvent);
+wxDEFINE_EVENT(wxEVT_RIBBONBAR_TAB_MIDDLE_UP, wxRibbonBarEvent);
+wxDEFINE_EVENT(wxEVT_RIBBONBAR_TAB_RIGHT_DOWN, wxRibbonBarEvent);
+wxDEFINE_EVENT(wxEVT_RIBBONBAR_TAB_RIGHT_UP, wxRibbonBarEvent);
+wxDEFINE_EVENT(wxEVT_RIBBONBAR_TAB_LEFT_DCLICK, wxRibbonBarEvent);
+wxDEFINE_EVENT(wxEVT_RIBBONBAR_TOGGLED, wxRibbonBarEvent);
+wxDEFINE_EVENT(wxEVT_RIBBONBAR_HELP_CLICK, wxRibbonBarEvent);
IMPLEMENT_CLASS(wxRibbonBar, wxRibbonControl)
IMPLEMENT_DYNAMIC_CLASS(wxRibbonBarEvent, wxNotifyEvent)
RecalculateTabSizes();
}
-static int OrderPageTabInfoBySmallWidthAsc(wxRibbonPageTabInfo **first, wxRibbonPageTabInfo **second)
+struct PageComparedBySmallWidthAsc
{
- 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;
+};
void wxRibbonBar::RecalculateTabSizes()
{
if(width >= total_small_width)
{
// Do (2)
- 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);
width -= tabsep * (numtabs - 1);
for(i = 0; i < numtabs; ++i)
{
- wxRibbonPageTabInfo& info = sorted_pages.Item(i);
- if (!info.shown)
+ wxRibbonPageTabInfo* info = sorted_pages[i].m_page;
+ if (!info->shown)
continue;
- if(info.small_must_have_separator_width * (int)(numtabs - i) <= width)
+ if(info->small_must_have_separator_width * (int)(numtabs - i) <= width)
{
- info.rect.width = info.small_must_have_separator_width;;
+ info->rect.width = info->small_must_have_separator_width;;
}
else
{
- info.rect.width = width / (numtabs - i);
+ info->rect.width = width / (numtabs - i);
}
- width -= info.rect.width;
+ width -= info->rect.width;
}
for(i = 0; i < numtabs; ++i)
{
info.rect.y = y;
info.rect.height = m_tab_height;
x += info.rect.width + tabsep;
- sorted_pages.Detach(numtabs - (i + 1));
}
}
else
m_tab_scroll_right_button_state = wxRIBBON_SCROLL_BTN_NORMAL;
m_tab_scroll_buttons_shown = false;
m_arePanelsShown = true;
+ m_help_button_hovered = false;
}
wxRibbonBar::wxRibbonBar(wxWindow* parent,
}
if(tab && tab != &m_pages.Item(m_current_page))
{
- wxRibbonBarEvent query(wxEVT_COMMAND_RIBBONBAR_PAGE_CHANGING, GetId(), tab->page);
+ wxRibbonBarEvent query(wxEVT_RIBBONBAR_PAGE_CHANGING, GetId(), tab->page);
query.SetEventObject(this);
ProcessWindowEvent(query);
if(query.IsAllowed())
{
SetActivePage(query.GetPage());
- wxRibbonBarEvent notification(wxEVT_COMMAND_RIBBONBAR_PAGE_CHANGED, GetId(), m_pages.Item(m_current_page).page);
+ wxRibbonBarEvent notification(wxEVT_RIBBONBAR_PAGE_CHANGED, GetId(), m_pages.Item(m_current_page).page);
notification.SetEventObject(this);
ProcessWindowEvent(notification);
}
m_ribbon_state = wxRIBBON_BAR_MINIMIZED;
else
m_ribbon_state = wxRIBBON_BAR_PINNED;
- wxRibbonBarEvent event(wxEVT_COMMAND_RIBBONBAR_TOGGLED, GetId());
+ wxRibbonBarEvent event(wxEVT_RIBBONBAR_TOGGLED, GetId());
event.SetEventObject(this);
ProcessWindowEvent(event);
}
if ( m_help_button_rect.Contains(position) )
{
- wxRibbonBarEvent event(wxEVT_COMMAND_RIBBONBAR_HELP_CLICKED, GetId());
+ wxRibbonBarEvent event(wxEVT_RIBBONBAR_HELP_CLICK, GetId());
event.SetEventObject(this);
ProcessWindowEvent(event);
}
void wxRibbonBar::OnMouseMiddleDown(wxMouseEvent& evt)
{
- DoMouseButtonCommon(evt, wxEVT_COMMAND_RIBBONBAR_TAB_MIDDLE_DOWN);
+ DoMouseButtonCommon(evt, wxEVT_RIBBONBAR_TAB_MIDDLE_DOWN);
}
void wxRibbonBar::OnMouseMiddleUp(wxMouseEvent& evt)
{
- DoMouseButtonCommon(evt, wxEVT_COMMAND_RIBBONBAR_TAB_MIDDLE_UP);
+ DoMouseButtonCommon(evt, wxEVT_RIBBONBAR_TAB_MIDDLE_UP);
}
void wxRibbonBar::OnMouseRightDown(wxMouseEvent& evt)
{
- DoMouseButtonCommon(evt, wxEVT_COMMAND_RIBBONBAR_TAB_RIGHT_DOWN);
+ DoMouseButtonCommon(evt, wxEVT_RIBBONBAR_TAB_RIGHT_DOWN);
}
void wxRibbonBar::OnMouseRightUp(wxMouseEvent& evt)
{
- DoMouseButtonCommon(evt, wxEVT_COMMAND_RIBBONBAR_TAB_RIGHT_UP);
+ DoMouseButtonCommon(evt, wxEVT_RIBBONBAR_TAB_RIGHT_UP);
}
void wxRibbonBar::OnMouseDoubleClick(wxMouseEvent& evt)