I'm writing some wxWidgets samples for educational purposes. My problem is simple: I'm using wxNotebook, and I need some trick to get current size of a single tab, especially height. In simple terms, if I place a wxNotebook inside a wxFrame which have, for example, his wxMenubar - which, obviously, take up place in height -, I would get tab height value only, NOT wxFrame height value which also includes size of wxMenubar. I need this information to properly center new components.
See the sample code below for an example.
#include "wx/wx.h"
#include "wx/gbsizer.h"
class MyFrame : public wxFrame
{
public:
MyFrame() : wxFrame(NULL, wxID_ANY, wxT("Application"), wxDefaultPosition, wxSize(500, 300))
{
wxNotebook *tabs = new wxNotebook(this, wxID_ANY, wxPoint(-1,-1), wxSize(-1,-1), wxNB_TOP);
wxPanel *extPanel = new wxPanel(tabs, wxID_ANY); // external panel will be directly added to wxNotebook
wxPanel *innerPanel = new wxPanel(extPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize); /* for now, innerPanel has default size */
innerPanel->SetBackgroundColour(wxColor(0, 0, 255)); // I change background color for debug only
innerPanel->SetMinSize(wxSize(200, 200)); // I use SetMinSize() method to communicate to the sizer _required_ size for the panel
wxGridBagSizer *gbs = new wxGridBagSizer(3, 3); // I use a wxGridBagSizer to position one panel inside external
/* **** THE FOLLOWING IS THE CRITICAL LINE **** */
wxSize mainSize = this->GetSize(); /* for now, I get the _wxFRAME_ wxSize; I would get wxNOTEBOOK size instead */
wxSize innPSize = innerPanel->GetMinSize(); // I get current (Min)Size of innerPanel
wxSize emptyCellSize((mainSize.GetWidth() - innPSize.GetWidth()) / 2, (mainSize.GetHeight() - innPSize.GetHeight()) / 2);
gbs->SetEmptyCellSize(emptyCellSize); // I Use SetEmptyCellSize() method to center the inner panel
gbs->Add(innerPanel, wxGBPosition(1, 1)); // 1, 1: central cell
extPanel->SetSizer(gbs);
tabs->AddPage(extPanel, wxT("Positioning test"));
Show(true);
}
};
class MyApp : public wxApp
{
public:
virtual bool OnInit()
{
MyFrame *frame = new MyFrame();
}
};
IMPLEMENT_APP(MyApp);
As you can see, layout is imperfect. p.s. If you know another, more efficient way to center a component using wxGridBagSizer, let me know.