// Name: notebook.cpp
// Purpose:
// Author: Robert Roebling
-// Id: $id$
+// Id: $Id$
// Copyright: (c) 1998 Robert Roebling, Vadim Zeitlin
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
m_box = (GtkWidget *) NULL;
}
-//private:
int m_id;
wxString m_text;
int m_image;
win->SetSize( alloc->x, alloc->y, alloc->width, alloc->height );
}
+//-----------------------------------------------------------------------------
+// InsertChild callback for wxNotebook
+//-----------------------------------------------------------------------------
+
+static void wxInsertChildInNotebook( wxNotebook* parent, wxWindow* child )
+{
+ wxNotebookPage *page = new wxNotebookPage();
+
+ page->m_id = parent->GetPageCount();
+
+ page->m_box = gtk_hbox_new (FALSE, 0);
+ gtk_container_border_width(GTK_CONTAINER(page->m_box), 2);
+
+ GtkNotebook *notebook = GTK_NOTEBOOK(parent->m_widget);
+
+ page->m_client = child;
+ gtk_notebook_append_page( notebook, child->m_widget, page->m_box );
+
+ page->m_page = (GtkNotebookPage*) (g_list_last(notebook->children)->data);
+
+ page->m_parent = notebook;
+
+ gtk_signal_connect( GTK_OBJECT(child->m_widget), "size_allocate",
+ GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)child );
+
+ if (!page->m_page)
+ {
+ wxLogFatalError( "Notebook page creation error" );
+ return;
+ }
+
+ parent->m_pages.Append( page );
+}
+
//-----------------------------------------------------------------------------
// wxNotebook
//-----------------------------------------------------------------------------
long style, const wxString& name )
{
m_needParent = TRUE;
+ m_insertCallback = (wxInsertChildFunction)wxInsertChildInNotebook;
PreCreation( parent, id, pos, size, style, name );
(gpointer)this
);
+ m_parent->AddChild( this );
+
+ (m_parent->m_insertCallback)( m_parent, this );
+
PostCreation();
Show( TRUE );
int wxNotebook::GetSelection() const
{
+ wxCHECK_MSG( m_widget != NULL, -1, "invalid notebook" );
+
if (m_pages.Number() == 0) return -1;
GtkNotebookPage *g_page = GTK_NOTEBOOK(m_widget)->cur_page;
wxString wxNotebook::GetPageText( int page ) const
{
+ wxCHECK_MSG( m_widget != NULL, "", "invalid notebook" );
+
wxNotebookPage* nb_page = GetNotebookPage(page);
if (nb_page)
return nb_page->m_text;
int wxNotebook::GetPageImage( int page ) const
{
+ wxCHECK_MSG( m_widget != NULL, 0, "invalid notebook" );
+
wxNotebookPage* nb_page = GetNotebookPage(page);
if (nb_page)
return nb_page->m_image;
wxNotebookPage* wxNotebook::GetNotebookPage(int page) const
{
+ wxCHECK_MSG( m_widget != NULL, (wxNotebookPage*)NULL, "invalid notebook" );
+
wxNotebookPage *nb_page = (wxNotebookPage *) NULL;
wxNode *node = m_pages.First();
int wxNotebook::SetSelection( int page )
{
+ wxCHECK_MSG( m_widget != NULL, -1, "invalid notebook" );
+
int selOld = GetSelection();
wxNotebookPage* nb_page = GetNotebookPage(page);
void wxNotebook::AdvanceSelection( bool bForward )
{
+ wxCHECK_RET( m_widget != NULL, "invalid notebook" );
+
int sel = GetSelection();
int max = GetPageCount();
bool wxNotebook::SetPageText( int page, const wxString &text )
{
+ wxCHECK_MSG( m_widget != NULL, FALSE, "invalid notebook" );
+
wxNotebookPage* nb_page = GetNotebookPage(page);
if (!nb_page) return FALSE;
bool wxNotebook::DeleteAllPages()
{
+ wxCHECK_MSG( m_widget != NULL, FALSE, "invalid notebook" );
+
wxNode *page_node = m_pages.First();
while (page_node)
{
bool wxNotebook::AddPage(wxWindow* win, const wxString& text,
bool bSelect, int imageId)
{
+ wxCHECK_MSG( m_widget != NULL, FALSE, "invalid notebook" );
+
// we've created the notebook page in AddChild(). Now we just have to set
// the caption for the page and set the others parameters.
wxWindow *wxNotebook::GetPage( int page ) const
{
+ wxCHECK_MSG( m_widget != NULL, (wxWindow*) NULL, "invalid notebook" );
+
wxNotebookPage* nb_page = GetNotebookPage(page);
if (!nb_page)
return (wxWindow *) NULL;
return nb_page->m_client;
}
-void wxNotebook::AddChild( wxWindow *win )
-{
- m_children.Append(win);
-
- wxNotebookPage *page = new wxNotebookPage();
-
- page->m_id = GetPageCount();
-
- page->m_box = gtk_hbox_new (FALSE, 0);
- gtk_container_border_width(GTK_CONTAINER(page->m_box), 2);
-
- page->m_client = win;
- gtk_notebook_append_page( GTK_NOTEBOOK(m_widget), win->m_widget, page->m_box );
-
- page->m_page =
- (GtkNotebookPage*) (g_list_last(GTK_NOTEBOOK(m_widget)->children)->data);
-
- page->m_parent = GTK_NOTEBOOK(m_widget);
-
- gtk_signal_connect( GTK_OBJECT(win->m_widget), "size_allocate",
- GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)win );
-
- if (!page->m_page)
- {
- wxLogFatalError( "Notebook page creation error" );
- return;
- }
-
- m_pages.Append( page );
-}
-
// override these 2 functions to do nothing: everything is done in OnSize
void wxNotebook::SetConstraintSizes( bool WXUNUSED(recurse) )
{
return TRUE;
}
+void wxNotebook::ApplyWidgetStyle()
+{
+ SetWidgetStyle();
+ gtk_widget_set_style( m_widget, m_widgetStyle );
+}
+
//-----------------------------------------------------------------------------
// wxNotebookEvent
//-----------------------------------------------------------------------------