X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ff829f3f6d9d138e36286ab7db81e93ac67cd598..0f217db31814dde7432ceb2e00ddf42b968b9fa3:/src/gtk1/notebook.cpp diff --git a/src/gtk1/notebook.cpp b/src/gtk1/notebook.cpp index 0c0f939051..089d875e5c 100644 --- a/src/gtk1/notebook.cpp +++ b/src/gtk1/notebook.cpp @@ -16,16 +16,42 @@ #include "wx/panel.h" #include "wx/utils.h" #include "wx/imaglist.h" -#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,29 +68,41 @@ static void gtk_notebook_page_change_callback(GtkNotebook *widget, notebook->ProcessEvent(event); } -//----------------------------------------------------------------------------- -// wxNotebookPage -//----------------------------------------------------------------------------- - -class wxNotebookPage: public wxObject +static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxWindow *win ) { -public: - wxNotebookPage() + if ( win->GetAutoLayout() ) + win->Layout(); + + 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" ); +*/ }; //----------------------------------------------------------------------------- @@ -89,9 +127,9 @@ wxNotebook::wxNotebook() Init(); }; -wxNotebook::wxNotebook( wxWindow *parent, const wxWindowID id, +wxNotebook::wxNotebook( wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, - const long style, const wxString& name ) + long style, const wxString& name ) { Init(); Create( parent, id, pos, size, style, name ); @@ -103,20 +141,21 @@ wxNotebook::~wxNotebook() if ( m_idHandler != 0 ) gtk_signal_disconnect(GTK_OBJECT(m_widget), m_idHandler); - if (m_imageList) - delete m_imageList; DeleteAllPages(); }; -bool wxNotebook::Create(wxWindow *parent, const wxWindowID id, +bool wxNotebook::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, - const long style, const wxString& name ) + long style, const wxString& name ) { m_needParent = TRUE; 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; }; @@ -253,7 +292,7 @@ bool wxNotebook::SetPageText( int page, const wxString &text ) return TRUE; }; -bool wxNotebook::SetPageImage( int page, const int image ) +bool wxNotebook::SetPageImage( int page, int image ) { wxNotebookPage* nb_page = GetNotebookPage(page); if (!nb_page) @@ -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,28 +395,34 @@ 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) { @@ -388,20 +433,16 @@ void wxNotebook::AddChild( wxWindow *win ) m_pages.Append( page ); }; -void wxNotebook::OnSize(wxSizeEvent& event) +// override these 2 functions to do nothing: everything is done in OnSize +void wxNotebook::SetConstraintSizes(bool /* recurse */) { - // forward this event to all pages - 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); + // don't set the sizes of the pages - their correct size is not yet known + wxControl::SetConstraintSizes(FALSE); +} - node = node->Next(); - }; +bool wxNotebook::DoPhase(int /* nPhase */) +{ + return TRUE; } //-----------------------------------------------------------------------------