This is so typically wxWidgets. I am spending the second day now on one freaking dialog. If you want anything more complicated than a button and a static text, you're totally lost...
Rick: This subclassing stuff is no alternative. I looked into that too, and it is an evil hack, even for wxWidgets. There is no documentation for this either, except an article written by three people who have tampered with it some day and somehow got it to run for themselves.
Game_Ender: Just a
wxGrid with two columns is needed, no fancy stuff, just two columns and a couple of rows where the user can enter data. My problem is not writing the XRC, though. That's easy.
The problem is that
wxWidgets 2.6.2 has no XRC handler for
wxGrid:
D:\wxWidgets-2.6.2\src\xrc>grep IsOfClass *.cpp
xh_bmp.cpp: return IsOfClass(node, wxT("wxBitmap"));
xh_bmp.cpp: return IsOfClass(node, wxT("wxIcon"));
xh_bmpbt.cpp: return IsOfClass(node, wxT("wxBitmapButton"));
xh_bttn.cpp: return IsOfClass(node, wxT("wxButton"));
xh_cald.cpp: return IsOfClass(node, wxT("wxCalendarCtrl"));
xh_chckb.cpp: return IsOfClass(node, wxT("wxCheckBox"));
xh_chckl.cpp: return (IsOfClass(node, wxT("wxCheckListBox")) ||
xh_chckl.cpp: IsOfClass(node, wxT("wxCheckList")) ||
xh_choic.cpp: return (IsOfClass(node, wxT("wxChoice")) ||
xh_choicbk.cpp: return ((!m_isInside && IsOfClass(node, wxT("wxChoicebook"))) ||
xh_choicbk.cpp: (m_isInside && IsOfClass(node, wxT("choicebookpage"))));
xh_combo.cpp: return (IsOfClass(node, wxT("wxComboBox")) ||
xh_datectrl.cpp: return IsOfClass(node, wxT("wxDatePickerCtrl"));
xh_dlg.cpp: return IsOfClass(node, wxT("wxDialog"));
xh_frame.cpp: return IsOfClass(node, wxT("wxFrame"));
xh_gauge.cpp: return IsOfClass(node, wxT("wxGauge"));
xh_gdctl.cpp: return IsOfClass(node, wxT("wxGenericDirCtrl"));
xh_html.cpp: return IsOfClass(node, wxT("wxHtmlWindow"));
xh_listb.cpp: return (IsOfClass(node, wxT("wxListBox")) ||
xh_listbk.cpp: return ((!m_isInside && IsOfClass(node, wxT("wxListbook"))) ||
xh_listbk.cpp: (m_isInside && IsOfClass(node, wxT("listbookpage"))));
xh_listc.cpp: return IsOfClass(node, wxT("wxListCtrl"));
xh_mdi.cpp: return (IsOfClass(node, wxT("wxMDIParentFrame")) ||
xh_mdi.cpp: IsOfClass(node, wxT("wxMDIChildFrame")));
xh_menu.cpp: return IsOfClass(node, wxT("wxMenu")) ||
xh_menu.cpp: (IsOfClass(node, wxT("wxMenuItem")) ||
xh_menu.cpp: IsOfClass(node, wxT("break")) ||
xh_menu.cpp: IsOfClass(node, wxT("separator")))
xh_menu.cpp: return IsOfClass(node, wxT("wxMenuBar"));
xh_notbk.cpp: return ((!m_isInside && IsOfClass(node, wxT("wxNotebook"))) ||
xh_notbk.cpp: (m_isInside && IsOfClass(node, wxT("notebookpage"))));
xh_panel.cpp: return IsOfClass(node, wxT("wxPanel"));
xh_radbt.cpp: return IsOfClass(node, wxT("wxRadioButton"));
xh_radbx.cpp: return (IsOfClass(node, wxT("wxRadioBox")) ||
xh_scrol.cpp: return IsOfClass(node, wxT("wxScrollBar"));
xh_scwin.cpp: return IsOfClass(node, wxT("wxScrolledWindow"));
xh_sizer.cpp: (m_isInside && IsOfClass(node, wxT("sizeritem"))) ||
xh_sizer.cpp: (m_isInside && IsOfClass(node, wxT("spacer")))
xh_sizer.cpp: return (IsOfClass(node, wxT("wxBoxSizer"))) ||
xh_sizer.cpp: (IsOfClass(node, wxT("wxStaticBoxSizer"))) ||
xh_sizer.cpp: (IsOfClass(node, wxT("wxGridSizer"))) ||
xh_sizer.cpp: (IsOfClass(node, wxT("wxFlexGridSizer"))) ||
xh_sizer.cpp: (IsOfClass(node, wxT("wxGridBagSizer")));
xh_sizer.cpp: return (!m_isInside && IsOfClass(node, wxT("wxStdDialogButtonSizer"))) ||
xh_sizer.cpp: (m_isInside && IsOfClass(node, wxT("button")));
xh_slidr.cpp: return IsOfClass(node, wxT("wxSlider"));
xh_spin.cpp: return IsOfClass(node, wxT("wxSpinButton"));
xh_spin.cpp: return IsOfClass(node, wxT("wxSpinCtrl"));
xh_split.cpp: return IsOfClass(node, wxT("wxSplitterWindow"));
xh_statbar.cpp: return IsOfClass(node, wxT("wxStatusBar"));
xh_stbmp.cpp: return IsOfClass(node, wxT("wxStaticBitmap"));
xh_stbox.cpp: return IsOfClass(node, wxT("wxStaticBox"));
xh_stlin.cpp: return IsOfClass(node, wxT("wxStaticLine"));
xh_sttxt.cpp: return IsOfClass(node, wxT("wxStaticText"));
xh_text.cpp: return IsOfClass(node, wxT("wxTextCtrl"));
xh_tglbtn.cpp: return IsOfClass(node, wxT("wxToggleButton"));
xh_toolb.cpp: if (!IsOfClass(n, wxT("tool")) &&
xh_toolb.cpp: !IsOfClass(n, wxT("separator")) &&
xh_toolb.cpp: return ((!m_isInside && IsOfClass(node, wxT("wxToolBar"))) ||
xh_toolb.cpp: (m_isInside && IsOfClass(node, wxT("tool"))) ||
xh_toolb.cpp: (m_isInside && IsOfClass(node, wxT("separator"))));
xh_tree.cpp: return IsOfClass(node, wxT("wxTreeCtrl"));
xh_unkwn.cpp: return IsOfClass(node, wxT("unknown"));
xh_wizrd.cpp: return IsOfClass(node, wxT("wxWizard")) ||
xh_wizrd.cpp: (IsOfClass(node, wxT("wxWizardPage")) ||
xh_wizrd.cpp: IsOfClass(node, wxT("wxWizardPageSimple")))I created a
wxGrid manually and added it to a sizer, and assigned that sizer to the parent panel. Creating dialogs programmatically is the kind of stuff which I try to avoid, but there seems no other way.
However, unless you explicitely give the wxGrid an
absolute size, it renders in a size of about 60x20, no matter what kind of sizer you provide or whether you call
FitInside() or
SetSizeHints(). And when given the size of its parent, then it is of course bigger than the parent and adds a horizontal scroll bar. Stupid me, of course "same size" means "make it bigger", I should have known...
wxPanel *panel = XRCCTRL(*this, "panel", wxPanel);
// wxGrid *grid = new wxGrid(panel, -1, wxDefaultPosition, wxDefaultSize); // see left side of image
wxGrid *grid = new wxGrid(panel, -1, wxDefaultPosition, panel->GetSize()); // ow man...
grid->CreateGrid(25,2);
//grid->AutoSizeColumns(true); // sizes according to the *contents*, not do the bounding box
grid->SetColSize(0, panel->GetSize().x / 2); // duh...
grid->SetColSize(1, panel->GetSize().x / 2);
grid->SetRowLabelSize(0);
wxGridSizer *s = new wxGridSizer(1,1);
//wxFlexGridSizer *s = new wxFlexGridSizer( 1, 1, 0, 0); // flex grid does not work any better
//s->AddGrowableCol(0); s->AddGrowableRow(0);
s->Add(grid, 0, wxEXPAND);
//s->FitInside(panel); // does nothing
panel->SetSizer(s);
//s->FitInside(panel); // does nothing
panel->SetBackgroundColour(*wxRED); // let's see the panel's full size...I am seriously thinking about simply adding a dozen rows of textedit controls by hand - this is probably easier.