Add possibility to hide and show again wxRibbonBar pages.

Added wxRibbonBar::ShowPage(), HidePage() and IsPageShown() methods and show
them in the sample.

Also add GetPageNumber() helper.

Closes #14471.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72070 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2012-07-13 11:46:43 +00:00
parent 516fdb4f52
commit 5c14ec2640
5 changed files with 133 additions and 1 deletions

View File

@@ -528,6 +528,7 @@ Major new features in this release
All (GUI):
- Add possibility to hide and show again wxRibbonBar pages (wxBen).
- Fix item data access in wxDataViewListCtrl (Kry).

View File

@@ -80,6 +80,7 @@ public:
int minimum_width;
bool active;
bool hovered;
bool shown;
};
#ifndef SWIG
@@ -115,10 +116,15 @@ public:
wxRibbonPage* GetPage(int n);
size_t GetPageCount() const;
bool DismissExpandedPanel();
int GetPageNumber(wxRibbonPage* page) const;
void DeletePage(size_t n);
void ClearPages();
bool IsPageShown(size_t page) const;
void ShowPage(size_t page, bool show = true);
void HidePage(size_t page) { ShowPage(page, false); }
void ShowPanels(bool show = true);
void HidePanels() { ShowPanels(false); }
bool ArePanelsShown() const { return m_arePanelsShown; }

View File

@@ -221,6 +221,15 @@ public:
*/
bool DismissExpandedPanel();
/**
Returns the number for a given ribbon bar page.
The number can be used in other ribbon bar calls.
@since 2.9.5
*/
int GetPageNumber(wxRibbonPage* page) const;
/**
Delete a single page from this ribbon bar.
@@ -238,6 +247,36 @@ public:
*/
void ClearPages();
/**
Indicates whether the tab for the given page is shown to the user or
not.
By default all page tabs are shown.
@since 2.9.5
*/
bool IsPageShown(size_t page) const;
/**
Show or hide the tab for a given page.
After showing or hiding a tab, you need to call wxRibbonBar::Realize().
If you hide the tab for the currently active page (GetActivePage) then
you should call SetActivePage to activate a different page.
@since 2.9.5
*/
void ShowPage(size_t page, bool show_tab=true);
/**
Hides the tab for a given page.
Equivalent to @c ShowPage(page, false).
@since 2.9.5
*/
void HidePage(size_t page);
/**
Shows or hides the panel area of the ribbon bar.

View File

@@ -83,7 +83,9 @@ public:
ID_CHANGE_TEXT1,
ID_CHANGE_TEXT2,
ID_UI_CHANGE_TEXT_UPDATED,
ID_REMOVE_PAGE
ID_REMOVE_PAGE,
ID_HIDE_PAGES,
ID_SHOW_PAGES
};
void OnEnableUpdateUI(wxUpdateUIEvent& evt);
@@ -129,6 +131,8 @@ public:
void OnPositionLeftBoth(wxCommandEvent& evt);
void OnPositionLeftDropdown(wxRibbonToolBarEvent& evt);
void OnRemovePage(wxRibbonButtonBarEvent& evt);
void OnHidePages(wxRibbonButtonBarEvent& evt);
void OnShowPages(wxRibbonButtonBarEvent& evt);
void OnTogglePanels(wxCommandEvent& evt);
void OnExtButton(wxRibbonPanelEvent& evt);
@@ -228,6 +232,8 @@ EVT_MENU(ID_POSITION_TOP_BOTH, MyFrame::OnPositionTopBoth)
EVT_TOGGLEBUTTON(ID_TOGGLE_PANELS, MyFrame::OnTogglePanels)
EVT_RIBBONPANEL_EXTBUTTON_ACTIVATED(wxID_ANY, MyFrame::OnExtButton)
EVT_RIBBONBUTTONBAR_CLICKED(ID_REMOVE_PAGE, MyFrame::OnRemovePage)
EVT_RIBBONBUTTONBAR_CLICKED(ID_HIDE_PAGES, MyFrame::OnHidePages)
EVT_RIBBONBUTTONBAR_CLICKED(ID_SHOW_PAGES, MyFrame::OnShowPages)
END_EVENT_TABLE()
#include "align_center.xpm"
@@ -393,6 +399,8 @@ MyFrame::MyFrame()
wxRibbonPanel *panel = new wxRibbonPanel(page, wxID_ANY, wxT("Page manipulation"), ribbon_xpm);
wxRibbonButtonBar *bar = new wxRibbonButtonBar(panel, wxID_ANY);
bar->AddButton(ID_REMOVE_PAGE, wxT("Remove"), wxArtProvider::GetBitmap(wxART_DELETE, wxART_OTHER, wxSize(24, 24)));
bar->AddButton(ID_HIDE_PAGES, wxT("Hide Pages"), ribbon_xpm);
bar->AddButton(ID_SHOW_PAGES, wxT("Show Pages"), ribbon_xpm);
}
m_ribbon->Realize();
@@ -984,3 +992,19 @@ void MyFrame::OnRemovePage(wxRibbonButtonBarEvent& WXUNUSED(evt))
m_ribbon->Realize();
}
}
void MyFrame::OnHidePages(wxRibbonButtonBarEvent& WXUNUSED(evt))
{
m_ribbon->HidePage(1);
m_ribbon->HidePage(2);
m_ribbon->HidePage(3);
m_ribbon->Realize();
}
void MyFrame::OnShowPages(wxRibbonButtonBarEvent& WXUNUSED(evt))
{
m_ribbon->ShowPage(1);
m_ribbon->ShowPage(2);
m_ribbon->ShowPage(3);
m_ribbon->Realize();
}

View File

@@ -66,6 +66,7 @@ void wxRibbonBar::AddPage(wxRibbonPage *page)
info.page = page;
info.active = false;
info.hovered = false;
info.shown = true;
// info.rect not set (intentional)
wxClientDC dcTemp(this);
@@ -141,6 +142,8 @@ bool wxRibbonBar::Realize()
for(i = 0; i < numtabs; ++i)
{
wxRibbonPageTabInfo& info = m_pages.Item(i);
if (!info.shown)
continue;
RepositionPage(info.page);
if(!info.page->Realize())
{
@@ -281,6 +284,20 @@ size_t wxRibbonBar::GetPageCount() const
return m_pages.GetCount();
}
bool wxRibbonBar::IsPageShown(size_t page) const
{
if (page >= m_pages.GetCount())
return false;
return m_pages.Item(page).shown;
}
void wxRibbonBar::ShowPage(size_t page, bool show)
{
if(page >= m_pages.GetCount())
return;
m_pages.Item(page).shown = show;
}
void wxRibbonBar::DeletePage(size_t n)
{
if(n < m_pages.GetCount())
@@ -361,6 +378,7 @@ bool wxRibbonBar::SetActivePage(size_t page)
}
m_current_page = (int)page;
m_pages.Item(page).active = true;
m_pages.Item(page).shown = true;
{
wxRibbonPage* wnd = m_pages.Item(page).page;
RepositionPage(wnd);
@@ -386,6 +404,20 @@ bool wxRibbonBar::SetActivePage(wxRibbonPage* page)
return false;
}
int wxRibbonBar::GetPageNumber(wxRibbonPage* page) const
{
size_t numpages = m_pages.GetCount();
for(size_t i = 0; i < numpages; ++i)
{
if(m_pages.Item(i).page == page)
{
return i;
}
}
return wxNOT_FOUND;
}
int wxRibbonBar::GetActivePage() const
{
return m_current_page;
@@ -423,6 +455,8 @@ void wxRibbonBar::RecalculateTabSizes()
for(i = 0; i < numtabs; ++i)
{
wxRibbonPageTabInfo& info = m_pages.Item(i);
if (!info.shown)
continue;
info.rect.x = x;
info.rect.y = y;
info.rect.width = info.ideal_width;
@@ -440,6 +474,8 @@ void wxRibbonBar::RecalculateTabSizes()
for(i = 0; i < numtabs; ++i)
{
wxRibbonPageTabInfo& info = m_pages.Item(i);
if (!info.shown)
continue;
info.rect.x = x;
info.rect.y = y;
info.rect.width = info.minimum_width;
@@ -476,6 +512,8 @@ void wxRibbonBar::RecalculateTabSizes()
for(i = 0; i < numtabs; ++i)
{
wxRibbonPageTabInfo& info = m_pages.Item(i);
if (!info.shown)
continue;
info.rect.x -= m_tab_scroll_amount;
}
}
@@ -497,6 +535,8 @@ void wxRibbonBar::RecalculateTabSizes()
for(i = 0; i < numtabs; ++i)
{
wxRibbonPageTabInfo& info = m_pages.Item(i);
if (!info.shown)
continue;
if(info.small_must_have_separator_width < smallest_tab_width)
{
smallest_tab_width = info.small_must_have_separator_width;
@@ -512,6 +552,8 @@ void wxRibbonBar::RecalculateTabSizes()
for(i = 0; i < numtabs; ++i)
{
wxRibbonPageTabInfo& info = m_pages.Item(i);
if (!info.shown)
continue;
int delta = info.ideal_width - info.small_must_have_separator_width;
info.rect.x = x;
info.rect.y = y;
@@ -530,6 +572,8 @@ void wxRibbonBar::RecalculateTabSizes()
for(i = 0; i < numtabs; ++i)
{
wxRibbonPageTabInfo& info = m_pages.Item(i);
if (!info.shown)
continue;
if(info.minimum_width < smallest_tab_width)
{
total_small_width += smallest_tab_width;
@@ -546,6 +590,8 @@ void wxRibbonBar::RecalculateTabSizes()
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);
@@ -553,6 +599,8 @@ void wxRibbonBar::RecalculateTabSizes()
for(i = 0; i < numtabs; ++i)
{
wxRibbonPageTabInfo& info = sorted_pages.Item(i);
if (!info.shown)
continue;
if(info.small_must_have_separator_width * (int)(numtabs - i) <= width)
{
info.rect.width = info.small_must_have_separator_width;;
@@ -566,6 +614,8 @@ void wxRibbonBar::RecalculateTabSizes()
for(i = 0; i < numtabs; ++i)
{
wxRibbonPageTabInfo& info = m_pages.Item(i);
if (!info.shown)
continue;
info.rect.x = x;
info.rect.y = y;
info.rect.height = m_tab_height;
@@ -583,6 +633,8 @@ void wxRibbonBar::RecalculateTabSizes()
for(i = 0; i < numtabs; ++i)
{
wxRibbonPageTabInfo& info = m_pages.Item(i);
if (!info.shown)
continue;
int delta = smallest_tab_width - info.minimum_width;
info.rect.x = x;
info.rect.y = y;
@@ -718,6 +770,8 @@ void wxRibbonBar::OnPaint(wxPaintEvent& WXUNUSED(evt))
for(i = 0; i < numtabs; ++i)
{
wxRibbonPageTabInfo& info = m_pages.Item(i);
if (!info.shown)
continue;
dc.DestroyClippingRegion();
if(m_tab_scroll_buttons_shown)
@@ -750,6 +804,8 @@ void wxRibbonBar::OnPaint(wxPaintEvent& WXUNUSED(evt))
for(i = 0; i < numtabs - 1; ++i)
{
wxRibbonPageTabInfo& info = m_pages.Item(i);
if (!info.shown)
continue;
rect.x = info.rect.x + info.rect.width;
if(m_tab_scroll_buttons_shown && !tabs_rect.Intersects(rect))
@@ -822,6 +878,8 @@ wxRibbonPageTabInfo* wxRibbonBar::HitTestTabs(wxPoint position, int* index)
for(i = 0; i < numtabs; ++i)
{
wxRibbonPageTabInfo& info = m_pages.Item(i);
if (!info.shown)
continue;
if(info.rect.Contains(position))
{
if(index != NULL)
@@ -919,6 +977,8 @@ void wxRibbonBar::ScrollTabBar(int amount)
for(i = 0; i < numtabs; ++i)
{
wxRibbonPageTabInfo& info = m_pages.Item(i);
if (!info.shown)
continue;
info.rect.SetX(info.rect.GetX() - amount);
}
if(show_right != (m_tab_scroll_right_button_rect.GetWidth() != 0) ||
@@ -1009,6 +1069,8 @@ void wxRibbonBar::RecalculateMinSize()
for(i = 1; i < numtabs; ++i)
{
wxRibbonPageTabInfo& info = m_pages.Item(i);
if (!info.shown)
continue;
wxSize page_min = info.page->GetMinSize();
min_size.x = wxMax(min_size.x, page_min.x);