added a menu allowing to quickly switch to any page
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38775 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
		@@ -59,6 +59,8 @@ enum
 | 
				
			|||||||
    Widgets_ClearLog = 100,
 | 
					    Widgets_ClearLog = 100,
 | 
				
			||||||
    Widgets_Quit,
 | 
					    Widgets_Quit,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Widgets_BookCtrl,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if wxUSE_TOOLTIPS
 | 
					#if wxUSE_TOOLTIPS
 | 
				
			||||||
    Widgets_SetTooltip,
 | 
					    Widgets_SetTooltip,
 | 
				
			||||||
#endif // wxUSE_TOOLTIPS
 | 
					#endif // wxUSE_TOOLTIPS
 | 
				
			||||||
@@ -73,7 +75,10 @@ enum
 | 
				
			|||||||
    Widgets_BorderRaised,
 | 
					    Widgets_BorderRaised,
 | 
				
			||||||
    Widgets_BorderSunken,
 | 
					    Widgets_BorderSunken,
 | 
				
			||||||
    Widgets_BorderDouble,
 | 
					    Widgets_BorderDouble,
 | 
				
			||||||
    Widgets_BorderDefault
 | 
					    Widgets_BorderDefault,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Widgets_GoToPage,
 | 
				
			||||||
 | 
					    Widgets_GoToPageLast = Widgets_GoToPage + 100
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ----------------------------------------------------------------------------
 | 
					// ----------------------------------------------------------------------------
 | 
				
			||||||
@@ -109,6 +114,9 @@ protected:
 | 
				
			|||||||
    void OnExit(wxCommandEvent& event);
 | 
					    void OnExit(wxCommandEvent& event);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if wxUSE_MENUS
 | 
					#if wxUSE_MENUS
 | 
				
			||||||
 | 
					    void OnPageChanged(wxBookCtrlEvent& event);
 | 
				
			||||||
 | 
					    void OnGoToPage(wxCommandEvent& event);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if wxUSE_TOOLTIPS
 | 
					#if wxUSE_TOOLTIPS
 | 
				
			||||||
    void OnSetTooltip(wxCommandEvent& event);
 | 
					    void OnSetTooltip(wxCommandEvent& event);
 | 
				
			||||||
#endif // wxUSE_TOOLTIPS
 | 
					#endif // wxUSE_TOOLTIPS
 | 
				
			||||||
@@ -233,6 +241,11 @@ BEGIN_EVENT_TABLE(WidgetsFrame, wxFrame)
 | 
				
			|||||||
    EVT_MENU(Widgets_SetTooltip, WidgetsFrame::OnSetTooltip)
 | 
					    EVT_MENU(Widgets_SetTooltip, WidgetsFrame::OnSetTooltip)
 | 
				
			||||||
#endif // wxUSE_TOOLTIPS
 | 
					#endif // wxUSE_TOOLTIPS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if wxUSE_MENUS
 | 
				
			||||||
 | 
					    EVT_BOOKCTRL_PAGE_CHANGED(Widgets_BookCtrl, WidgetsFrame::OnPageChanged)
 | 
				
			||||||
 | 
					    EVT_MENU_RANGE(Widgets_GoToPage, Widgets_GoToPageLast,
 | 
				
			||||||
 | 
					                   WidgetsFrame::OnGoToPage)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    EVT_MENU(Widgets_SetFgColour, WidgetsFrame::OnSetFgCol)
 | 
					    EVT_MENU(Widgets_SetFgColour, WidgetsFrame::OnSetFgCol)
 | 
				
			||||||
    EVT_MENU(Widgets_SetBgColour, WidgetsFrame::OnSetBgCol)
 | 
					    EVT_MENU(Widgets_SetBgColour, WidgetsFrame::OnSetBgCol)
 | 
				
			||||||
    EVT_MENU(Widgets_SetFont,     WidgetsFrame::OnSetFont)
 | 
					    EVT_MENU(Widgets_SetFont,     WidgetsFrame::OnSetFont)
 | 
				
			||||||
@@ -242,6 +255,7 @@ BEGIN_EVENT_TABLE(WidgetsFrame, wxFrame)
 | 
				
			|||||||
                   WidgetsFrame::OnSetBorder)
 | 
					                   WidgetsFrame::OnSetBorder)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    EVT_MENU(wxID_EXIT, WidgetsFrame::OnExit)
 | 
					    EVT_MENU(wxID_EXIT, WidgetsFrame::OnExit)
 | 
				
			||||||
 | 
					#endif // wxUSE_MENUS
 | 
				
			||||||
END_EVENT_TABLE()
 | 
					END_EVENT_TABLE()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ============================================================================
 | 
					// ============================================================================
 | 
				
			||||||
@@ -350,7 +364,7 @@ WidgetsFrame::WidgetsFrame(const wxString& title)
 | 
				
			|||||||
    // Uncomment to suppress page theme (draw in solid colour)
 | 
					    // Uncomment to suppress page theme (draw in solid colour)
 | 
				
			||||||
    //style |= wxNB_NOPAGETHEME;
 | 
					    //style |= wxNB_NOPAGETHEME;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    m_book = new wxBookCtrl(m_panel, wxID_ANY, wxDefaultPosition,
 | 
					    m_book = new wxBookCtrl(m_panel, Widgets_BookCtrl, wxDefaultPosition,
 | 
				
			||||||
#ifdef __WXMOTIF__
 | 
					#ifdef __WXMOTIF__
 | 
				
			||||||
        wxSize(500, wxDefaultCoord), // under Motif, height is a function of the width...
 | 
					        wxSize(500, wxDefaultCoord), // under Motif, height is a function of the width...
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
@@ -416,19 +430,31 @@ void WidgetsFrame::InitBook()
 | 
				
			|||||||
    ArrayWidgetsPage pages;
 | 
					    ArrayWidgetsPage pages;
 | 
				
			||||||
    wxArrayString labels;
 | 
					    wxArrayString labels;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    wxMenu *menuPages = new wxMenu;
 | 
				
			||||||
 | 
					    unsigned nPage = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // we need to first create all pages and only then add them to the book
 | 
					    // we need to first create all pages and only then add them to the book
 | 
				
			||||||
    // as we need the image list first
 | 
					    // as we need the image list first
 | 
				
			||||||
    WidgetsPageInfo *info = WidgetsPage::ms_widgetPages;
 | 
					    //
 | 
				
			||||||
    while ( info )
 | 
					    // we also construct the pages menu during this first iteration
 | 
				
			||||||
 | 
					    for ( WidgetsPageInfo *info = WidgetsPage::ms_widgetPages;
 | 
				
			||||||
 | 
					          info;
 | 
				
			||||||
 | 
					          info = info->GetNext(), nPage++ )
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        WidgetsPage *page = (*info->GetCtor())(m_book, m_imaglist);
 | 
					        WidgetsPage *page = (*info->GetCtor())(m_book, m_imaglist);
 | 
				
			||||||
        pages.Add(page);
 | 
					        pages.Add(page);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        labels.Add(info->GetLabel());
 | 
					        labels.Add(info->GetLabel());
 | 
				
			||||||
 | 
					        menuPages->AppendRadioItem
 | 
				
			||||||
        info = info->GetNext();
 | 
					                   (
 | 
				
			||||||
 | 
					                    Widgets_GoToPage + nPage,
 | 
				
			||||||
 | 
					                    wxString::Format("%s\tF%u",
 | 
				
			||||||
 | 
					                                     info->GetLabel().c_str(), nPage + 1)
 | 
				
			||||||
 | 
					                   );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    GetMenuBar()->Append(menuPages, _T("&Page"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    m_book->SetImageList(m_imaglist);
 | 
					    m_book->SetImageList(m_imaglist);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // now do add them
 | 
					    // now do add them
 | 
				
			||||||
@@ -470,6 +496,17 @@ void WidgetsFrame::OnButtonClearLog(wxCommandEvent& WXUNUSED(event))
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#if wxUSE_MENUS
 | 
					#if wxUSE_MENUS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void WidgetsFrame::OnPageChanged(wxBookCtrlEvent& event)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    GetMenuBar()->Check(Widgets_GoToPage + event.GetSelection(), true);
 | 
				
			||||||
 | 
					    event.Skip();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void WidgetsFrame::OnGoToPage(wxCommandEvent& event)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    m_book->SetSelection(event.GetId() - Widgets_GoToPage);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if wxUSE_TOOLTIPS
 | 
					#if wxUSE_TOOLTIPS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void WidgetsFrame::OnSetTooltip(wxCommandEvent& WXUNUSED(event))
 | 
					void WidgetsFrame::OnSetTooltip(wxCommandEvent& WXUNUSED(event))
 | 
				
			||||||
@@ -636,7 +673,7 @@ WidgetsPageInfo::WidgetsPageInfo(Constructor ctor, const wxChar *label)
 | 
				
			|||||||
    m_next = NULL;
 | 
					    m_next = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // dummy sorting: add and immediately sort in the list according to label
 | 
					    // dummy sorting: add and immediately sort in the list according to label
 | 
				
			||||||
    if(WidgetsPage::ms_widgetPages)
 | 
					    if ( WidgetsPage::ms_widgetPages )
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        WidgetsPageInfo *node_prev = WidgetsPage::ms_widgetPages;
 | 
					        WidgetsPageInfo *node_prev = WidgetsPage::ms_widgetPages;
 | 
				
			||||||
        if ( wxStrcmp(label, node_prev->GetLabel().c_str()) < 0 )
 | 
					        if ( wxStrcmp(label, node_prev->GetLabel().c_str()) < 0 )
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user