wxPageSizer (was Hiding wxNotebook tabs)

Armel Asselin armelasselin at hotmail.com
Thu Aug 3 07:27:08 PDT 2006


interesting :)
thank you very much
Armel

"Werner Smekal" <smekal at iap.tuwien.ac.at> a écrit dans le message de news: 
44D2054D.5050908 at iap.tuwien.ac.at...
> Hi,
>
> our cl_PageSwitcher is maybe of your interest.
>
> examples code:
>
> Pages = new cl_PageSwitcher( m_panel );
>
>   // declare various windows/moduls
>   Pages->AddPage<cl_CLIPanel>(         &CLIPanel,        false );
>
>   //          panel class name        pointer          scroll select
>   Pages->AddPage<cl_SamplePanel>(    &SamplePanel,   false, true );
>   Pages->AddPage<cl_PeakPanel>(    &PeakPanel,   true );
>   Pages->AddPage<cl_ParameterPanel>( &ParameterPanel, true );
>   Pages->AddPage<cl_SourcePanel>(    &SourcePanel );
>   ....
>
> header file and implementation file added.
>
> regards,
> Werner
>
> Armel Asselin wrote:
>> Hello,
>>
>> just wanted to know if there was a sizer doing exactly the notebook job,
>> without any visual artifacts?
>> this sizer would:
>> - take the place of the biggest contained object
>> - allow to select one of the objects at a time
>>
>> if not, it could be used as the placement principle for many widgets such 
>> as
>> notebook,  wizard... it would avoid code duplication. I would have been
>> happy to have when I made the options box of ecmerge.
>>
>> so, is there already something like that?
>> Armel
>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: wx-users-unsubscribe at lists.wxwidgets.org
>> For additional commands, e-mail: wx-users-help at lists.wxwidgets.org
>>
>
>
> -- 
> Dipl. Ing. Werner Smekal
> Institut fuer Allgemeine Physik
> Technische Universitaet Wien
> Wiedner Hauptstr 8-10
> A-1040 Wien
> Austria
>
> email: smekal at iap.tuwien.ac.at
> web:   http://www.iap.tuwien.ac.at/~smekal
> phone: +43-(0)1-58801-13463 (office)
>        +43-(0)1-58801-13469 (laboratory)
> fax:   +43-(0)1-58801-13499
>


--------------------------------------------------------------------------------


> /*!
> * @file PageSwitcher.cpp
> * @brief source file for our notebook replacement
> *
> * @author Fabian Moser
> */
>
> // include common wx headers (precompiled)
> #include "stdwx.h"
>
> #include "PageSwitcher.h"
>
> //----------------------------------------------------------------------------
> // cl_PageSwitcher
> //----------------------------------------------------------------------------
>
> #include <wx/listimpl.cpp>
> WX_DEFINE_LIST( cl_PanelList );
>
> // IMPLEMENT_DYNAMIC_CLASS( cl_PageSwitcher, wxPanel );
>
> BEGIN_EVENT_TABLE( cl_PageSwitcher, wxPanel )
>  EVT_MOUSE_EVENTS( cl_PageSwitcher::OnMouseEvent )
> END_EVENT_TABLE()
>
> /*!
> * Constructor of the Page Switcher
> *
> * @author Fabian Moser
> *
> * @date 2004.03.28
> *
> * @param parent : address of parent window
> * @param id : id of this window
> * @param pos : position of window on screen
> * @param size : size of this window on screen
> * @param style : wxWindow style parameters (see documentation)
> * @param name : name of the panel
> */
> cl_PageSwitcher::cl_PageSwitcher(wxWindow* parent, wxWindowID id, const 
> wxPoint& pos,
>                    const wxSize& size, long style, const wxString& name) :
>                 wxPanel(parent, id, pos, size, style, name)
> {
>     panelList = new cl_PanelList();
>     oldIndex = -1;
> }
>
>
> /*!
> * In the deconstructor of the PageSwitcher we have to destroy the panels
> * which are currently not displayed. The active panel will be destroyed
> * by wxWidgets.
> *
> * @author Werner Smekal
> * @date 2004.11.08
> */
> cl_PageSwitcher::~cl_PageSwitcher( void )
> {
> delete panelList;
> }
>
>
> /*!
> * Selects a page previously added by given panel pointer.
> *
> * @author Fabian Moser
> * @date 2004.03.28
> * @param panel : The panel to be shown
> * @return The index of the now shown page and -1 on failure
> */
> int cl_PageSwitcher::SelectPage( wxPanel* panel )
> {
> int pageIndex = panelList->IndexOf(panel);
> if (pageIndex < 0)
> {
> pageIndex = panelList->IndexOf( (wxPanel*) panel->GetParent());
> }
>
> return SelectPage( pageIndex );
> }
>
>
> /*!
> * Selects a page previously added
> *
> * @author Fabian Moser
> * @date 2004.03.28
> * @param index : The index of the page to be shown
> * @return The index of the now shown page and -1 on failure
> */
>
> int cl_PageSwitcher::SelectPage( int index )
> {
>     if ( index == oldIndex ) return index;
>     if ( ( static_cast<int>(panelList->GetCount()) <= index ) || ( index < 
> 0 ) ) return -1;
>
>     wxBoxSizer* box = new wxBoxSizer( wxHORIZONTAL );
>
>     int i = 0;
>     for ( cl_PanelList::Node *node = panelList->GetFirst(); node; node = 
> node->GetNext() )
>     {
>         wxPanel *current = node->GetData();
>         current->Show( i == index );
>         i++;
>     }
>
>     box->Add( panelList->Item( index )->GetData(), 1, wxEXPAND );
>
>     SetAutoLayout( true );
>     SetSizer( box );
>     Layout();
>
>     return oldIndex=index;   // current page is stored in oldIndex
> }
>
>
> wxPanel* cl_PageSwitcher::GetCurrentPage(void)
> {
> return (wxPanel*) panelList->Item( oldIndex )->GetData();
> }
>
>
> void cl_PageSwitcher::OnMouseEvent( wxMouseEvent& event )
> {
>     if ( event.LeftDown() )
>     {
>         wxLogDebug(" We shouldn't see this");
>         cl_PanelList::Node *node = panelList->GetFirst();
>         wxPanel *current = node->GetData();
>         if ( current->GetEvtHandlerEnabled() )
>         {
>         wxLogDebug(" + OK");
>         }
>     }
>     event.Skip();
>
> }
>
>


--------------------------------------------------------------------------------


> /*!
> * @file PageSwitcher.h
> * @brief header file for our notebook replacement
> *
> * @author Fabian Moser
> */
>
> #ifndef __CL_PAGESWITCHER_H__
> #define __CL_PAGESWITCHER_H__
>
> // STL & C headers
> #include <list>
>
> //----------------------------------------------------------------------------
> // cl_PageSwitcher
> //----------------------------------------------------------------------------
>
> /*!
> * @brief Panel switching between defined pages
> *
> * This child of wxPanel allows you to add and switch between multiple 
> panels.
> * We use this for our mainframe to toggle between the different pages
> *
> * @author Fabian Moser
> *
> * @date 2004.03.28
> *
> */
>
> WX_DECLARE_LIST( wxPanel, cl_PanelList );
>
> class cl_PageSwitcher: public wxPanel
> {
> public:
>    // DECLARE_DYNAMIC_CLASS (cl_PageSwitcher);
>
>    cl_PageSwitcher() : wxPanel() {};
>    cl_PageSwitcher(wxWindow* parent, wxWindowID id = -1, const wxPoint& 
> pos = wxDefaultPosition,
>                    const wxSize& size = wxDefaultSize, long style = 
> wxTAB_TRAVERSAL,
>                    const wxString& name = "PanelSwitcher");
> ~cl_PageSwitcher( void );
>
>    template< class T_Panel >
> int AddPage( T_Panel** newPanel, bool scroll = false, bool select = 
> false );  //!< Adds a new page to the panel switcher
>
>    int  SelectPage( int index );                    //!< Selects a page 
> from the list
>    int  SelectPage( wxPanel* panel );               //!< Selects a page 
> from the list
> wxPanel* GetCurrentPage(void); //!< Returns the currently shown page
>
> protected:
>    cl_PanelList* panelList;                 //!< Stores the pointer to the 
> containing panels
>    int             oldIndex;                    //!< The index of the 
> shown page
>
>    virtual void OnMouseEvent( wxMouseEvent& event ); //!< event handler 
> called when the user presses the left mouse button
>
> private:
>    DECLARE_EVENT_TABLE()
>
> };
>
> /*!
> * Adds pages to the switcher.
> *
> * @author Fabian Moser
> * @date 2004.03.28
> * @param newPanel : The panel to be added
> * @param select : True if the new panel should be shown immediately
> * @return The index of the new page and -1 on failure
> */
> template< class T_Panel >
> int cl_PageSwitcher::AddPage( T_Panel** newPanel, bool scroll, bool 
> select )
> {
> wxPanel* actualPanel = (wxPanel*) NULL;
>
> // If this page should be scrolling, wrap the given panel into a scrolling 
> window
> if (scroll)
> {
> wxScrolledWindow* wrapperPanel = new wxScrolledWindow( this, -1, 
> wxDefaultPosition, wxDefaultSize, wxVSCROLL );
>
> *newPanel = (T_Panel*) new T_Panel( wrapperPanel );
>
> wxBoxSizer* box = new wxBoxSizer( wxHORIZONTAL );
>
> box->Add( *newPanel, 1, wxEXPAND );
>
> wrapperPanel->SetAutoLayout( true );
> wrapperPanel->SetSizer( box );
> wrapperPanel->SetScrollbars( 0, 1, 0, 0 );
> wrapperPanel->Layout();
>
> actualPanel = wrapperPanel;
> } else {
> *newPanel = (T_Panel*) new T_Panel( this );
> actualPanel = (wxPanel*) *newPanel;
> }
>
> cl_PanelList::Node* node = panelList->Append( actualPanel );   // TODO: 
> not used, what gives?
>  wxUnusedVar( node );
>
> if( select )
> SelectPage( panelList->IndexOf( actualPanel ) );
> else
> actualPanel->Show( false );
>
> return panelList->IndexOf( actualPanel );
> }
>
> #endif
>
>


--------------------------------------------------------------------------------


> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wx-users-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wx-users-help at lists.wxwidgets.org 








More information about the wx-users mailing list