From: Vadim Zeitlin Date: Sat, 24 Dec 2011 18:19:26 +0000 (+0000) Subject: Implement wxNotebook::CalcSizeFromPage() for wxGTK. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/864181f4f6a135e543c91e24d4a1580455ad242f?ds=sidebyside Implement wxNotebook::CalcSizeFromPage() for wxGTK. 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 --- diff --git a/docs/changes.txt b/docs/changes.txt index f231ffda88..90bd87fe22 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -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. diff --git a/include/wx/gtk/notebook.h b/include/wx/gtk/notebook.h index aeb5399ea2..2d116acdd0 100644 --- a/include/wx/gtk/notebook.h +++ b/include/wx/gtk/notebook.h @@ -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 diff --git a/samples/notebook/notebook.cpp b/samples/notebook/notebook.cpp index f43dee7bd8..200ed5e34c 100644 --- a/samples/notebook/notebook.cpp +++ b/samples/notebook/notebook.cpp @@ -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; diff --git a/samples/notebook/notebook.h b/samples/notebook/notebook.h index f08ffd630b..d0b48b4afb 100644 --- a/samples/notebook/notebook.h +++ b/samples/notebook/notebook.h @@ -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, diff --git a/src/gtk/notebook.cpp b/src/gtk/notebook.cpp index f2e48a5e05..e8e55440c3 100644 --- a/src/gtk/notebook.cpp +++ b/src/gtk/notebook.cpp @@ -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 )