]> git.saurik.com Git - wxWidgets.git/commitdiff
Implement wxNotebook::CalcSizeFromPage() for wxGTK.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 24 Dec 2011 18:19:26 +0000 (18:19 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 24 Dec 2011 18:19:26 +0000 (18:19 +0000)
The implementation is far from perfect as it relies on hard-coded margins but
is better than nothing as it allows wxNotebook best size determination and
SetPageSize() method to work correctly.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70112 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
include/wx/gtk/notebook.h
samples/notebook/notebook.cpp
samples/notebook/notebook.h
src/gtk/notebook.cpp

index f231ffda8854c4c673dbb3c3fc86e2b6f5e261a1..90bd87fe2237d6c65e348f9446da6cddcbf31b1d 100644 (file)
@@ -459,6 +459,10 @@ All (GUI):
   wxDataViewCtrl (Andrew Xu).
 - Fix item alignment in icon view in the generic wxListCtrl.
 
+GTK:
+
+- Fix wxNotebook best size calculation.
+
 MSW:
 
 - Fixed regression with initial focus in the dialogs in 2.9.3.
index aeb5399ea28ca95b9d5a29e054fdec2ddca06652..2d116acdd08afd39db8e6b95350634f501482fcc 100644 (file)
@@ -68,13 +68,13 @@ public:
   bool SetPageImage(size_t nPage, int nImage);
 
   // control the appearance of the notebook pages
-    // set the size (the same for all pages)
-  void SetPageSize(const wxSize& size);
     // set the padding between tabs (in pixels)
   void SetPadding(const wxSize& padding);
     // sets the size of the tabs (assumes all tabs are the same size)
   void SetTabSize(const wxSize& sz);
 
+  // geometry
+  virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const;
   virtual int HitTest(const wxPoint& pt, long *flags = NULL) const;
 
   // operations
index f43dee7bd894e6e1bb6714be097115dcdb27ab2a..200ed5e34c5f1e668bcc5165ae2f93f2765ffd7a 100644 (file)
@@ -239,6 +239,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
     EVT_MENU(ID_NEXT_PAGE, MyFrame::OnNextPage)
     EVT_MENU(ID_CHANGE_SELECTION, MyFrame::OnChangeSelection)
     EVT_MENU(ID_SET_SELECTION, MyFrame::OnSetSelection)
+    EVT_MENU(ID_GET_PAGE_SIZE, MyFrame::OnGetPageSize)
+    EVT_MENU(ID_SET_PAGE_SIZE, MyFrame::OnSetPageSize)
 
 #if wxUSE_HELP
     EVT_MENU(ID_CONTEXT_HELP, MyFrame::OnContextHelp)
@@ -369,6 +371,9 @@ MyFrame::MyFrame()
     menuPageOperations->AppendSeparator();
     menuPageOperations->Append(ID_CHANGE_SELECTION, wxT("&Change selection to 0\tCtrl-0"));
     menuPageOperations->Append(ID_SET_SELECTION, wxT("&Set selection to 0\tShift-Ctrl-0"));
+    menuPageOperations->AppendSeparator();
+    menuPageOperations->Append(ID_GET_PAGE_SIZE, "Sho&w page size");
+    menuPageOperations->Append(ID_SET_PAGE_SIZE, "Set &page size");
 
     wxMenu *menuOperations = new wxMenu;
 #if wxUSE_HELP
@@ -908,6 +913,33 @@ void MyFrame::OnSetSelection(wxCommandEvent& WXUNUSED(event))
         currBook->SetSelection(0);
 }
 
+void MyFrame::OnGetPageSize(wxCommandEvent& WXUNUSED(event))
+{
+    wxBookCtrlBase* const currBook = GetCurrentBook();
+    if ( !currBook )
+        return;
+
+    const wxSize sizePage = currBook->GetPage(0)->GetSize();
+    const wxSize sizeBook = currBook->GetSize();
+
+    wxLogMessage("Page size is (%d, %d), book size (%d, %d)",
+                 sizePage.x, sizePage.y,
+                 sizeBook.x, sizeBook.y);
+}
+
+void MyFrame::OnSetPageSize(wxCommandEvent& WXUNUSED(event))
+{
+    wxBookCtrlBase* const currBook = GetCurrentBook();
+    if ( !currBook )
+        return;
+
+    const wxSize sizePage(300, 300);
+    currBook->SetPageSize(sizePage);
+
+    wxLogMessage("Page size set to (%d, %d)",
+                 sizePage.x, sizePage.y);
+}
+
 void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) )
 {
     static int s_nPages = wxNOT_FOUND;
index f08ffd630b43a5fef4f422b4c5d4f9d0427344f7..d0b48b4afb905568815d742ffe8950764b2ec0c2 100644 (file)
@@ -52,6 +52,8 @@ public:
     void OnNextPage(wxCommandEvent& event);
     void OnChangeSelection(wxCommandEvent &event);
     void OnSetSelection(wxCommandEvent &event);
+    void OnGetPageSize(wxCommandEvent &event);
+    void OnSetPageSize(wxCommandEvent &event);
 
     void OnAddSubPage(wxCommandEvent& event);
     void OnAddPageBefore(wxCommandEvent& event);
@@ -167,6 +169,8 @@ enum ID_COMMANDS
     ID_ADD_SUB_PAGE,
     ID_CHANGE_SELECTION,
     ID_SET_SELECTION,
+    ID_GET_PAGE_SIZE,
+    ID_SET_PAGE_SIZE,
 
 #if wxUSE_HELP
     ID_CONTEXT_HELP,
index f2e48a5e052a663f97fc8f106a4468de86006887..e8e55440c396a9b60718c219ff1f66986c30ac5f 100644 (file)
@@ -304,9 +304,34 @@ bool wxNotebook::SetPageImage( size_t page, int image )
     return true;
 }
 
-void wxNotebook::SetPageSize( const wxSize &WXUNUSED(size) )
+wxSize wxNotebook::CalcSizeFromPage(const wxSize& sizePage) const
 {
-    wxFAIL_MSG( wxT("wxNotebook::SetPageSize not implemented") );
+    // Compute the max size of the tab labels.
+    wxSize sizeTabMax;
+    const size_t pageCount = GetPageCount();
+    for ( size_t n = 0; n < pageCount; n++ )
+    {
+        GtkRequisition req;
+        gtk_widget_size_request(GetNotebookPage(n)->m_box, &req);
+        sizeTabMax.IncTo(wxSize(req.width, req.height));
+    }
+
+    // Unfortunately this doesn't account for the real tab size and I don't
+    // know how to find it, e.g. where do the margins below come from.
+    const int PAGE_MARGIN = 3;
+    const int TAB_MARGIN = 4;
+
+    sizeTabMax.IncBy(3*TAB_MARGIN);
+
+    wxSize sizeFull(sizePage);
+    if ( IsVertical() )
+        sizeFull.y += sizeTabMax.y;
+    else
+        sizeFull.x += sizeTabMax.x;
+
+    sizeFull.IncBy(2*PAGE_MARGIN);
+
+    return sizeFull;
 }
 
 void wxNotebook::SetPadding( const wxSize &padding )