X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/debe6624c1e9d4bf3243381153d1e173c849bcd8..14d1ccd89decb9d84f394fb2218eddbfdba56baf:/src/gtk/notebook.cpp diff --git a/src/gtk/notebook.cpp b/src/gtk/notebook.cpp index eb1ac6d1b5..e1e9b250b3 100644 --- a/src/gtk/notebook.cpp +++ b/src/gtk/notebook.cpp @@ -19,13 +19,40 @@ #include "wx/intl.h" #include "wx/log.h" +//----------------------------------------------------------------------------- +// wxNotebookPage +//----------------------------------------------------------------------------- + +class wxNotebookPage: public wxObject +{ +public: + wxNotebookPage() + { + m_id = -1; + m_text = ""; + m_image = -1; + m_page = NULL; + m_client = NULL; + m_parent = NULL; + }; + +//private: + int m_id; + wxString m_text; + int m_image; + GtkNotebookPage *m_page; + GtkLabel *m_label; + wxWindow *m_client; + GtkNotebook *m_parent; +}; + //----------------------------------------------------------------------------- // GTK callbacks //----------------------------------------------------------------------------- // page change callback -static void gtk_notebook_page_change_callback(GtkNotebook *widget, - GtkNotebookPage *page, +static void gtk_notebook_page_change_callback(GtkNotebook *WXUNUSED(widget), + GtkNotebookPage *WXUNUSED(page), gint nPage, gpointer data) { @@ -42,31 +69,40 @@ static void gtk_notebook_page_change_callback(GtkNotebook *widget, notebook->ProcessEvent(event); } -//----------------------------------------------------------------------------- -// wxNotebookPage -//----------------------------------------------------------------------------- - -class wxNotebookPage: public wxObject -{ -public: - wxNotebookPage() +static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxWindow *win ) +{ + if ((win->m_x == alloc->x) && + (win->m_y == alloc->y) && + (win->m_width == alloc->width) && + (win->m_height == alloc->height)) { - m_id = -1; - m_text = ""; - m_image = -1; - m_page = NULL; - m_clientPanel = NULL; + return; }; - -//private: - int m_id; - wxString m_text; - int m_image; - GtkNotebookPage *m_page; - GtkLabel *m_label; - wxWindow *m_clientPanel; + +/* + printf( "OnResize from " ); + if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) + printf( win->GetClassInfo()->GetClassName() ); + printf( " .\n" ); + + printf( " Old: X: %d Y: %d ", win->m_x, win->m_y ); + printf( " W: %d H: %d ", win->m_width, win->m_height ); + printf( " .\n" ); + + printf( " New: X: %d Y: %d ", alloc->x, alloc->y ); + printf( " W: %d H: %d ", alloc->width, alloc->height ); + printf( " .\n" ); +*/ + + win->SetSize( alloc->x, alloc->y, alloc->width, alloc->height ); + +/* + printf( " Res: X: %d Y: %d ", win->m_x, win->m_y ); + printf( " W: %d H: %d ", win->m_width, win->m_height ); + printf( " .\n" ); +*/ }; - + //----------------------------------------------------------------------------- // wxNotebook //----------------------------------------------------------------------------- @@ -117,6 +153,9 @@ bool wxNotebook::Create(wxWindow *parent, wxWindowID id, PreCreation( parent, id, pos, size, style, name ); m_widget = gtk_notebook_new(); + + gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget), 1 ); + m_idHandler = gtk_signal_connect ( GTK_OBJECT(m_widget), "switch_page", @@ -195,7 +234,7 @@ wxNotebookPage* wxNotebook::GetNotebookPage(int page) const node = node->Next(); }; - wxLogDebug("Notebook page %d not found!", page); + wxLogDebug( "Notebook page %d not found!", page ); return NULL; }; @@ -305,7 +344,7 @@ bool wxNotebook::DeletePage( int page ) wxASSERT( child ); - delete nb_page->m_clientPanel; + delete nb_page->m_client; // Amazingly, this is not necessary // gtk_notebook_remove_page( GTK_NOTEBOOK(m_widget), page_num ); @@ -328,7 +367,7 @@ bool wxNotebook::AddPage(wxWindow* win, const wxString& text, while (node) { page = (wxNotebookPage*)node->Data(); - if ( page->m_clientPanel == win ) + if ( page->m_client == win ) break; // found node = node->Next(); }; @@ -356,29 +395,35 @@ wxWindow *wxNotebook::GetPage( int page ) const if (!nb_page) return NULL; else - return nb_page->m_clientPanel; + return nb_page->m_client; }; void wxNotebook::AddChild( wxWindow *win ) { // @@@ normally done in wxWindow::AddChild but for some reason wxNotebook // case is special there (Robert?) + // Robert: Don't you think the code below looks different from the one + // in wxWindow::AddChild :-) + m_children.Append(win); 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); + page->m_label = (GtkLabel *)gtk_label_new("Handle"); + page->m_client = 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 - ); + 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" ); @@ -394,16 +439,32 @@ void wxNotebook::OnSize(wxSizeEvent& event) wxNode *node = m_pages.First(); while (node) { - wxNotebookPage *page = (wxNotebookPage*)node->Data(); - // @@@@ This -50 is completely wrong - instead, we should substract - // the height of the tabs - page->m_clientPanel->SetSize(event.GetSize().GetX(), - event.GetSize().GetY() - 50); - + wxWindow *page = ((wxNotebookPage*)node->Data())->m_client; + // @@@@ the numbers I substract here are completely arbitrary, instead we + // should somehow calculate the size of the page from the size of the + // notebook +/* page->SetSize(event.GetSize().GetX() - 5, + event.GetSize().GetY() - 30); + + if ( page->GetAutoLayout() ) + page->Layout(); +*/ node = node->Next(); }; } +// override these 2 functions to do nothing: everything is done in OnSize +void wxNotebook::SetConstraintSizes(bool /* recurse */) +{ + // don't set the sizes of the pages - their correct size is not yet known + wxControl::SetConstraintSizes(FALSE); +} + +bool wxNotebook::DoPhase(int /* nPhase */) +{ + return TRUE; +} + //----------------------------------------------------------------------------- // wxNotebookEvent //-----------------------------------------------------------------------------