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
This commit is contained in:
@@ -459,6 +459,10 @@ All (GUI):
|
|||||||
wxDataViewCtrl (Andrew Xu).
|
wxDataViewCtrl (Andrew Xu).
|
||||||
- Fix item alignment in icon view in the generic wxListCtrl.
|
- Fix item alignment in icon view in the generic wxListCtrl.
|
||||||
|
|
||||||
|
GTK:
|
||||||
|
|
||||||
|
- Fix wxNotebook best size calculation.
|
||||||
|
|
||||||
MSW:
|
MSW:
|
||||||
|
|
||||||
- Fixed regression with initial focus in the dialogs in 2.9.3.
|
- Fixed regression with initial focus in the dialogs in 2.9.3.
|
||||||
|
@@ -68,13 +68,13 @@ public:
|
|||||||
bool SetPageImage(size_t nPage, int nImage);
|
bool SetPageImage(size_t nPage, int nImage);
|
||||||
|
|
||||||
// control the appearance of the notebook pages
|
// 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)
|
// set the padding between tabs (in pixels)
|
||||||
void SetPadding(const wxSize& padding);
|
void SetPadding(const wxSize& padding);
|
||||||
// sets the size of the tabs (assumes all tabs are the same size)
|
// sets the size of the tabs (assumes all tabs are the same size)
|
||||||
void SetTabSize(const wxSize& sz);
|
void SetTabSize(const wxSize& sz);
|
||||||
|
|
||||||
|
// geometry
|
||||||
|
virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const;
|
||||||
virtual int HitTest(const wxPoint& pt, long *flags = NULL) const;
|
virtual int HitTest(const wxPoint& pt, long *flags = NULL) const;
|
||||||
|
|
||||||
// operations
|
// operations
|
||||||
|
@@ -239,6 +239,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
|||||||
EVT_MENU(ID_NEXT_PAGE, MyFrame::OnNextPage)
|
EVT_MENU(ID_NEXT_PAGE, MyFrame::OnNextPage)
|
||||||
EVT_MENU(ID_CHANGE_SELECTION, MyFrame::OnChangeSelection)
|
EVT_MENU(ID_CHANGE_SELECTION, MyFrame::OnChangeSelection)
|
||||||
EVT_MENU(ID_SET_SELECTION, MyFrame::OnSetSelection)
|
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
|
#if wxUSE_HELP
|
||||||
EVT_MENU(ID_CONTEXT_HELP, MyFrame::OnContextHelp)
|
EVT_MENU(ID_CONTEXT_HELP, MyFrame::OnContextHelp)
|
||||||
@@ -369,6 +371,9 @@ MyFrame::MyFrame()
|
|||||||
menuPageOperations->AppendSeparator();
|
menuPageOperations->AppendSeparator();
|
||||||
menuPageOperations->Append(ID_CHANGE_SELECTION, wxT("&Change selection to 0\tCtrl-0"));
|
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->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;
|
wxMenu *menuOperations = new wxMenu;
|
||||||
#if wxUSE_HELP
|
#if wxUSE_HELP
|
||||||
@@ -908,6 +913,33 @@ void MyFrame::OnSetSelection(wxCommandEvent& WXUNUSED(event))
|
|||||||
currBook->SetSelection(0);
|
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) )
|
void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) )
|
||||||
{
|
{
|
||||||
static int s_nPages = wxNOT_FOUND;
|
static int s_nPages = wxNOT_FOUND;
|
||||||
|
@@ -52,6 +52,8 @@ public:
|
|||||||
void OnNextPage(wxCommandEvent& event);
|
void OnNextPage(wxCommandEvent& event);
|
||||||
void OnChangeSelection(wxCommandEvent &event);
|
void OnChangeSelection(wxCommandEvent &event);
|
||||||
void OnSetSelection(wxCommandEvent &event);
|
void OnSetSelection(wxCommandEvent &event);
|
||||||
|
void OnGetPageSize(wxCommandEvent &event);
|
||||||
|
void OnSetPageSize(wxCommandEvent &event);
|
||||||
|
|
||||||
void OnAddSubPage(wxCommandEvent& event);
|
void OnAddSubPage(wxCommandEvent& event);
|
||||||
void OnAddPageBefore(wxCommandEvent& event);
|
void OnAddPageBefore(wxCommandEvent& event);
|
||||||
@@ -167,6 +169,8 @@ enum ID_COMMANDS
|
|||||||
ID_ADD_SUB_PAGE,
|
ID_ADD_SUB_PAGE,
|
||||||
ID_CHANGE_SELECTION,
|
ID_CHANGE_SELECTION,
|
||||||
ID_SET_SELECTION,
|
ID_SET_SELECTION,
|
||||||
|
ID_GET_PAGE_SIZE,
|
||||||
|
ID_SET_PAGE_SIZE,
|
||||||
|
|
||||||
#if wxUSE_HELP
|
#if wxUSE_HELP
|
||||||
ID_CONTEXT_HELP,
|
ID_CONTEXT_HELP,
|
||||||
|
@@ -304,9 +304,34 @@ bool wxNotebook::SetPageImage( size_t page, int image )
|
|||||||
return true;
|
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 )
|
void wxNotebook::SetPadding( const wxSize &padding )
|
||||||
|
Reference in New Issue
Block a user