#include "wx/panel.h"
#include "wx/utils.h"
#include "wx/imaglist.h"
+#include "wx/intl.h"
+#include "wx/log.h"
//-----------------------------------------------------------------------------
// wxNotebookPage
int m_image;
void *m_clientData;
GtkNotebookPage *m_page;
- wxPanel *m_clientPanel;
+ GtkLabel *m_label;
+ wxWindow *m_clientPanel;
- wxNotebookPage(void)
+ wxNotebookPage()
{
m_id = -1;
m_text = "";
wxNotebook::wxNotebook(void)
{
m_imageList = NULL;
- m_frame = NULL;
m_pages.DeleteContents( TRUE );
};
const long style, const wxString& name )
{
m_imageList = NULL;
- m_frame = NULL;
m_pages.DeleteContents( TRUE );
Create( parent, id, pos, size, style, name );
};
wxString wxNotebook::GetPageText( const int page ) const
{
- wxNotebookPage *nb_page = NULL;
-
- wxNode *node = m_pages.First();
- while (node)
- {
- nb_page = (wxNotebookPage*)node->Data();
- if (nb_page->m_id == page) break;
- node = node->Next();
- };
- if (!node) return "";
-
- return nb_page->m_text;
+ wxNotebookPage* nb_page = GetNotebookPage(page);
+ if (nb_page)
+ return nb_page->m_text;
+ else
+ return "";
};
int wxNotebook::GetPageImage( const int page ) const
{
- wxNotebookPage *nb_page = NULL;
-
- wxNode *node = m_pages.First();
- while (node)
- {
- nb_page = (wxNotebookPage*)node->Data();
- if (nb_page->m_id == page) break;
- node = node->Next();
- };
- if (!node) return -1;
-
- return nb_page->m_image;
+ wxNotebookPage* nb_page = GetNotebookPage(page);
+ if (nb_page)
+ return nb_page->m_image;
+ else
+ return 0;
};
void* wxNotebook::GetPageData( const int page ) const
+{
+ wxNotebookPage* nb_page = GetNotebookPage(page);
+ if (nb_page)
+ return nb_page->m_clientData;
+ else
+ return NULL;
+};
+
+wxNotebookPage* wxNotebook::GetNotebookPage(int page) const
{
wxNotebookPage *nb_page = NULL;
node = node->Next();
};
if (!node) return NULL;
-
- return nb_page->m_clientData;
+ return nb_page;
};
int wxNotebook::SetSelection( const int page )
{
- wxNotebookPage *nb_page = NULL;
-
- wxNode *node = m_pages.First();
- while (node)
- {
- nb_page = (wxNotebookPage*)node->Data();
- if (nb_page->m_id == page) break;
- node = node->Next();
- };
- if (!node) return -1;
+ wxNotebookPage* nb_page = GetNotebookPage(page);
+ if (!nb_page) return -1;
int page_num = 0;
GList *child = GTK_NOTEBOOK(m_widget)->children;
bool wxNotebook::SetPageText( const int page, const wxString &text )
{
- wxNotebookPage *nb_page = NULL;
-
- wxNode *node = m_pages.First();
- while (node)
- {
- nb_page = (wxNotebookPage*)node->Data();
- if (nb_page->m_id == page) break;
- node = node->Next();
- };
- if (!node) return FALSE;
+ wxNotebookPage* nb_page = GetNotebookPage(page);
+ if (!nb_page) return FALSE;
nb_page->m_text = text;
bool wxNotebook::SetPageImage( const int page, const int image )
{
- wxNotebookPage *nb_page = NULL;
-
- wxNode *node = m_pages.First();
- while (node)
- {
- nb_page = (wxNotebookPage*)node->Data();
- if (nb_page->m_id == page) break;
- node = node->Next();
- };
- if (!node) return FALSE;
+ wxNotebookPage* nb_page = GetNotebookPage(page);
+ if (!nb_page)
+ return FALSE;
nb_page->m_image = image;
bool wxNotebook::SetPageData( const int page, void* data )
{
- wxNotebookPage *nb_page = NULL;
+ wxNotebookPage* nb_page = GetNotebookPage(page);
+ if (!nb_page) return FALSE;
- wxNode *node = m_pages.First();
- while (node)
- {
- nb_page = (wxNotebookPage*)node->Data();
- if (nb_page->m_id == page) break;
- node = node->Next();
- };
- if (!node) return FALSE;
-
nb_page->m_clientData = data;
return TRUE;
bool wxNotebook::DeletePage( const int page )
{
- wxNotebookPage *nb_page = NULL;
-
- wxNode *node = m_pages.First();
- while (node)
- {
- nb_page = (wxNotebookPage*)node->Data();
- if (nb_page->m_id == page) break;
- node = node->Next();
- };
- if (!node) return FALSE;
+ wxNotebookPage* nb_page = GetNotebookPage(page);
+ if (!nb_page) return FALSE;
int page_num = 0;
GList *child = GTK_NOTEBOOK(m_widget)->children;
page_num++;
child = child->next;
};
-
- if (!child) wxFatalError( "Notebook delete error" );;
+
+ wxASSERT( child );
+
+ delete nb_page->m_clientPanel;
- gtk_notebook_remove_page( GTK_NOTEBOOK(m_widget), page_num );
+// Amazingly, this is not necessary
+// gtk_notebook_remove_page( GTK_NOTEBOOK(m_widget), page_num );
m_pages.DeleteObject( nb_page );
return TRUE;
};
-wxPanel *wxNotebook::CreatePage( const int item, const wxString &text, const int imageId, void* data )
+bool wxNotebook::AddPage(wxWindow* win, const wxString& text, const int imageId, void* data)
{
- wxNotebookPage *page = new wxNotebookPage;
+ // we've created the notebook page in AddChild(). Now we just have to set
+ // the caption for the page and set the others parameters.
+
+ // first, find the page
+ wxNotebookPage *page = NULL;
+
+ wxNode *node = m_pages.First();
+ while (node)
+ {
+ page = (wxNotebookPage*)node->Data();
+ if ( page->m_clientPanel == win )
+ break; // found
+ node = node->Next();
+ };
+
+ if ( page == NULL ) {
+ wxFAIL_MSG("Can't add a page whose parent is not the notebook!");
+
+ return FALSE;
+ }
+ // then set the attributes
page->m_text = text;
- if (page->m_text.IsNull()) page->m_text = "";
- page->m_id = item;
+ if ( page->m_text.IsEmpty() )
+ page->m_text = "";
page->m_image = imageId;
page->m_clientData = data;
-
- m_frame = gtk_label_new( page->m_text );
- gtk_misc_set_alignment( GTK_MISC(m_frame), 0.0, 0.5 );
+ gtk_label_set(page->m_label, page->m_text);
- page->m_clientPanel = new wxPanel( this, -1, wxPoint(0,0), wxSize(100,100) );
-
- m_frame = NULL;
-
- page->m_page = GTK_NOTEBOOK(m_widget)->cur_page;
-
- m_pages.Append( page );
-
- return page->m_clientPanel;
+ return TRUE;
};
-wxPanel *wxNotebook::GetPanel( const int page )
+wxWindow *wxNotebook::GetPageWindow( const int page ) const
{
- wxNotebookPage *nb_page = NULL;
-
- wxNode *node = m_pages.First();
- while (node)
- {
- nb_page = (wxNotebookPage*)node->Data();
- if (nb_page->m_id == page) break;
- node = node->Next();
- };
- if (!node) return NULL;
+ wxNotebookPage* nb_page = GetNotebookPage(page);
+ if (!nb_page) return NULL;
return nb_page->m_clientPanel;
};
void wxNotebook::AddChild( wxWindow *win )
{
- if (!m_frame) wxFatalError( "Notebook::Addchild() must not be called directly." );
+ wxNotebookPage *page = new wxNotebookPage();
+
+ page->m_id = GetPageCount();
+ page->m_label = (GtkLabel *)gtk_label_new("no caption");
+ page->m_clientPanel = win;
+ gtk_notebook_append_page(GTK_NOTEBOOK(m_widget), win->m_widget,
+ (GtkWidget *)page->m_label);
+ gtk_misc_set_alignment(GTK_MISC(page->m_label), 0.0, 0.5);
+
+ page->m_page = (GtkNotebookPage*)
+ (
+ g_list_last(GTK_NOTEBOOK(m_widget)->children)->data
+ );
- gtk_notebook_append_page( GTK_NOTEBOOK(m_widget), win->m_widget, m_frame );
+ if (!page->m_page)
+ {
+ wxLogFatalError( "Notebook page creation error" );
+ return;
+ }
+
+ m_pages.Append( page );
};
//-----------------------------------------------------------------------------