From: Vadim Zeitlin Date: Fri, 19 Oct 2012 22:03:25 +0000 (+0000) Subject: Allow specifying all wxFlexGridSizer parameters in XRC. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/5a3eee0dbafc6d2b6afa4bab9926c094abe5119b Allow specifying all wxFlexGridSizer parameters in XRC. Add support for specifying flexible direction, grow mode in non-flexible direction and row/column proportions for the growable ones. Closes #14767. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72710 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index aa5fafda43..095511a1d9 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -572,6 +572,7 @@ All (GUI): - Implement incremental search in wxGenericListCtrl (Jonathan Dagresta). - Make TAB behaviour in wxGrid more flexible (Fulvio Senore). - Add missing styles support to wxWindow XRC hanlder (Steffen Olszewski). +- Allow specifying all wxFlexGridSizer parameters in XRC (Steffen Olszewski). wxGTK: diff --git a/docs/doxygen/overviews/xrc_format.h b/docs/doxygen/overviews/xrc_format.h index 84e60f92fb..3f46e151f3 100644 --- a/docs/doxygen/overviews/xrc_format.h +++ b/docs/doxygen/overviews/xrc_format.h @@ -1919,8 +1919,8 @@ Example of sizers XRC code: 0 0 0 - 0 - 0 + 0:1 + 0:1 wxALIGN_CENTRE|wxALL 5 @@ -2001,12 +2001,22 @@ class-specific properties. All classes support the following properties: @row3col{cols, integer, Number of columns in the grid (default: 0 - determine automatically).} @row3col{vgap, integer, Vertical gap between children (default: 0).} @row3col{hgap, integer, Horizontal gap between children (default: 0).} +@row3col{flexibledirection, @ref overview_xrcformat_type_style, + Flexible direction, @c wxVERTICAL, @c wxHORIZONTAL or @c wxBOTH (default). + This property is only available since wxWidgets 2.9.5.} +@row3col{nonflexiblegrowmode, @ref overview_xrcformat_type_style, + Grow mode in the non-flexible direction, + @c wxFLEX_GROWMODE_NONE, @c wxFLEX_GROWMODE_SPECIFIED (default) or + @c wxFLEX_GROWMODE_ALL. + This property is only available since wxWidgets 2.9.5.} @row3col{growablerows, comma-separated integers list, - Comma-separated list of indexes of rows that are growable - (default: none).} + Comma-separated list of indexes of rows that are growable (none by default). + Since wxWidgets 2.9.5 optional proportion can be appended to each number + after a colon (@c :).} @row3col{growablecols, comma-separated integers list, - Comma-separated list of indexes of columns that are growable - (default: none).} + Comma-separated list of indexes of columns that are growable (none by default). + Since wxWidgets 2.9.5 optional proportion can be appended to each number + after a colon (@c :).} @endTable @subsection overview_xrcformat_wxgridbagsizer wxGridBagSizer @@ -2015,11 +2025,21 @@ class-specific properties. All classes support the following properties: @hdr3col{property, type, description} @row3col{vgap, integer, Vertical gap between children (default: 0).} @row3col{hgap, integer, Horizontal gap between children (default: 0).} +@row3col{flexibledirection, @ref overview_xrcformat_type_style, + Flexible direction, @c wxVERTICAL, @c wxHORIZONTAL, @c wxBOTH (default: @c wxBOTH).} +@row3col{nonflexiblegrowmode, @ref overview_xrcformat_type_style, + Grow mode in the non-flexible direction, + @c wxFLEX_GROWMODE_NONE, @c wxFLEX_GROWMODE_SPECIFIED, @c wxFLEX_GROWMODE_ALL + (default: @c wxFLEX_GROWMODE_SPECIFIED).} @row3col{growablerows, comma-separated integers list, - Comma-separated list of indexes of rows that are growable + Comma-separated list of indexes of rows that are growable, + optionally the proportion can be appended after each number + separated by a @c : (default: none).} @row3col{growablecols, comma-separated integers list, - Comma-separated list of indexes of columns that are growable + Comma-separated list of indexes of columns that are growable, + optionally the proportion can be appended after each number + separated by a @c : (default: none).} @endTable diff --git a/include/wx/xrc/xh_sizer.h b/include/wx/xrc/xh_sizer.h index 5c941dea97..d38f778d95 100644 --- a/include/wx/xrc/xh_sizer.h +++ b/include/wx/xrc/xh_sizer.h @@ -51,6 +51,7 @@ private: wxSizer* Handle_wxWrapSizer(); bool ValidateGridSizerChildren(); + void SetFlexibleMode(wxFlexGridSizer* fsizer); void SetGrowables(wxFlexGridSizer* fsizer, const wxChar* param, bool rows); wxGBPosition GetGBPos(const wxString& param); wxGBSpan GetGBSpan(const wxString& param); diff --git a/src/xrc/xh_sizer.cpp b/src/xrc/xh_sizer.cpp index 6fbe286e96..ad9fd57986 100644 --- a/src/xrc/xh_sizer.cpp +++ b/src/xrc/xh_sizer.cpp @@ -270,6 +270,7 @@ wxObject* wxSizerXmlHandler::Handle_sizer() // set growable rows and cols for sizers which support this if ( wxFlexGridSizer *flexsizer = wxDynamicCast(sizer, wxFlexGridSizer) ) { + SetFlexibleMode(flexsizer); SetGrowables(flexsizer, wxT("growablerows"), true); SetGrowables(flexsizer, wxT("growablecols"), false); } @@ -395,6 +396,50 @@ bool wxSizerXmlHandler::ValidateGridSizerChildren() } +void wxSizerXmlHandler::SetFlexibleMode(wxFlexGridSizer* fsizer) +{ + if (HasParam(wxT("flexibledirection"))) + { + wxString dir = GetParamValue(wxT("flexibledirection")); + + if (dir == wxT("wxVERTICAL")) + fsizer->SetFlexibleDirection(wxVERTICAL); + else if (dir == wxT("wxHORIZONTAL")) + fsizer->SetFlexibleDirection(wxHORIZONTAL); + else if (dir == wxT("wxBOTH")) + fsizer->SetFlexibleDirection(wxBOTH); + else + { + ReportParamError + ( + wxT("flexibledirection"), + wxString::Format("unknown direction \"%s\"", dir) + ); + } + } + + if (HasParam(wxT("nonflexiblegrowmode"))) + { + wxString mode = GetParamValue(wxT("nonflexiblegrowmode")); + + if (mode == wxT("wxFLEX_GROWMODE_NONE")) + fsizer->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_NONE); + else if (mode == wxT("wxFLEX_GROWMODE_SPECIFIED")) + fsizer->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED); + else if (mode == wxT("wxFLEX_GROWMODE_ALL")) + fsizer->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_ALL); + else + { + ReportParamError + ( + wxT("nonflexiblegrowmode"), + wxString::Format("unknown grow mode \"%s\"", mode) + ); + } + } +} + + void wxSizerXmlHandler::SetGrowables(wxFlexGridSizer* sizer, const wxChar* param, bool rows) @@ -408,18 +453,35 @@ void wxSizerXmlHandler::SetGrowables(wxFlexGridSizer* sizer, while (tkn.HasMoreTokens()) { - unsigned long l; - if (!tkn.GetNextToken().ToULong(&l)) + wxString propStr; + wxString idxStr = tkn.GetNextToken().BeforeFirst(wxT(':'), &propStr); + + unsigned long li; + if (!idxStr.ToULong(&li)) { ReportParamError ( param, - "value must be comma-separated list of row numbers" + "value must be a comma-separated list of numbers" ); break; } - const int n = static_cast(l); + unsigned long lp = 0; + if (!propStr.empty()) + { + if (!propStr.ToULong(&lp)) + { + ReportParamError + ( + param, + "value must be a comma-separated list of numbers" + ); + break; + } + } + + const int n = static_cast(li); if ( n >= nslots ) { ReportParamError @@ -439,9 +501,9 @@ void wxSizerXmlHandler::SetGrowables(wxFlexGridSizer* sizer, } if (rows) - sizer->AddGrowableRow(n); + sizer->AddGrowableRow(n, static_cast(lp)); else - sizer->AddGrowableCol(n); + sizer->AddGrowableCol(n, static_cast(lp)); } }