wxPageSizer (was Hiding wxNotebook tabs)

Werner Smekal smekal at iap.tuwien.ac.at
Thu Aug 3 07:16:45 PDT 2006


Hi,

our cl_PageSwitcher is maybe of your interest.

examples code:

Pages =3D 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
-------------- next part --------------
/*!
 * @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 wxP=
oint& pos,
                    const wxSize& size, long style, const wxString& name) :
                 wxPanel(parent, id, pos, size, style, name)
{
     panelList =3D new cl_PanelList();
     oldIndex =3D -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 =3D panelList->IndexOf(panel);
	if (pageIndex < 0)
	{
		pageIndex =3D 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 =3D=3D oldIndex ) return index;
     if ( ( static_cast<int>(panelList->GetCount()) <=3D index ) || ( index=
 < 0 ) ) return -1;

     wxBoxSizer* box =3D new wxBoxSizer( wxHORIZONTAL );

     int i =3D 0;
     for ( cl_PanelList::Node *node =3D panelList->GetFirst(); node; node =
=3D node->GetNext() )
     {
         wxPanel *current =3D node->GetData();
         current->Show( i =3D=3D index );
         i++;
     }

     box->Add( panelList->Item( index )->GetData(), 1, wxEXPAND );

     SetAutoLayout( true );
     SetSizer( box );
     Layout();
     =

     return oldIndex=3Dindex;   // 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 =3D panelList->GetFirst();
         wxPanel *current =3D node->GetData();
         if ( current->GetEvtHandlerEnabled() )
         {
         	wxLogDebug(" + OK");
         }
     }
     event.Skip();

}

-------------- next part --------------
/*!
 * @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 pane=
ls.
 * 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 =3D -1, const wxPoint& =
pos =3D wxDefaultPosition,
                    const wxSize& size =3D wxDefaultSize, long style =3D wx=
TAB_TRAVERSAL,
                    const wxString& name =3D "PanelSwitcher");
		~cl_PageSwitcher( void );

    template< class T_Panel >
	int AddPage( T_Panel** newPanel, bool scroll =3D false, bool select =3D fa=
lse );  	//!< Adds a new page to the panel switcher

    int  SelectPage( int index );                    	//!< Selects a page f=
rom the list
    int  SelectPage( wxPanel* panel );               	//!< Selects a page f=
rom 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 sh=
own page

    virtual void OnMouseEvent( wxMouseEvent& event ); 	//!< event handler c=
alled 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 =3D (wxPanel*) NULL;

	// If this page should be scrolling, wrap the given panel into a scrolling=
 window
	if (scroll)
	{
		wxScrolledWindow* wrapperPanel =3D new wxScrolledWindow( this, -1, wxDefa=
ultPosition, wxDefaultSize, wxVSCROLL );

		*newPanel =3D (T_Panel*) new T_Panel( wrapperPanel );

		wxBoxSizer* box =3D new wxBoxSizer( wxHORIZONTAL );

		box->Add( *newPanel, 1, wxEXPAND );

		wrapperPanel->SetAutoLayout( true );
		wrapperPanel->SetSizer( box );
		wrapperPanel->SetScrollbars( 0, 1, 0, 0 );
		wrapperPanel->Layout();

		actualPanel =3D wrapperPanel;
	} else {
		*newPanel =3D (T_Panel*) new T_Panel( this );
		actualPanel =3D (wxPanel*) *newPanel;
	}

	cl_PanelList::Node* node =3D 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


More information about the wx-users mailing list