]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/notebook.cpp
wxFrame: OnSize() has a SEGV if wxFrame has no child. Fixed.
[wxWidgets.git] / src / gtk / notebook.cpp
index eb1ac6d1b55a4f2d56dd689b14493c2564c12113..9b6ec68ef5a00bef51911d74e3e515df0c9eba46 100644 (file)
 #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
 //-----------------------------------------------------------------------------
@@ -195,7 +231,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 +341,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 +364,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 +392,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 +436,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
 //-----------------------------------------------------------------------------