From f68c67aa859c2cc1007271aca886aaf89d90c4bf Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 6 Jul 2016 18:44:07 +0200 Subject: [PATCH] Use "pair of ints" type for wxGridBagSizer size and position in XRC Introduce a new type for XRC values imaginatively called just "pair of integers" which can be used for values not expressed in pixels and hence for which it doesn't make sense to use dialog units nor to scale them by the DPI. Use this new type for wxGridBagSizer position and span elements to prevent them from being changed when using higher than normal DPI. Closes #17592. --- docs/doxygen/overviews/xrc_format.h | 17 ++++++++++++++--- include/wx/xrc/xmlres.h | 3 +++ include/wx/xrc/xmlreshandler.h | 5 +++++ misc/schema/xrc_schema.rnc | 13 +++++++------ src/xrc/xh_sizer.cpp | 6 +++--- src/xrc/xmlres.cpp | 22 ++++++++++++++++++++++ 6 files changed, 54 insertions(+), 12 deletions(-) diff --git a/docs/doxygen/overviews/xrc_format.h b/docs/doxygen/overviews/xrc_format.h index a6a2c7edae..1cf826545c 100644 --- a/docs/doxygen/overviews/xrc_format.h +++ b/docs/doxygen/overviews/xrc_format.h @@ -281,6 +281,17 @@ preceding it is interpreted as dialog units in the parent window, otherwise it's a DPI-independent pixel value. +@subsection overview_xrcformat_type_pair_ints Pair of integers + +This is similar to @ref overview_xrcformat_type_size size, but for values that +are not expressed in pixels and so doesn't allow "d" suffix nor does any +DPI-dependent scaling, i.e. the format is just + + size := x "," y + +and @c x and @c y are just integers which are not interpreted in any way. + + @subsection overview_xrcformat_type_text Text String properties use several escape sequences that are translated according to @@ -2316,11 +2327,11 @@ properties: (default: 0).} @row3col{minsize, @ref overview_xrcformat_type_size, Minimal size of this item (default: no min size).} -@row3col{ratio, @ref overview_xrcformat_type_size, +@row3col{ratio, @ref overview_xrcformat_type_pair_ints, Item ratio, see wxSizer::SetRatio() (default: no ratio).} -@row3col{cellpos, @ref overview_xrcformat_type_pos, +@row3col{cellpos, @ref overview_xrcformat_type_pair_ints, (wxGridBagSizer only) Position, see wxGBSizerItem::SetPos() (required). } -@row3col{cellspan, @ref overview_xrcformat_type_size, +@row3col{cellspan, @ref overview_xrcformat_type_pair_ints, (wxGridBagSizer only) Span, see wxGBSizerItem::SetSpan() (required). } @endTable diff --git a/include/wx/xrc/xmlres.h b/include/wx/xrc/xmlres.h index e7fe700330..de31ea27a4 100644 --- a/include/wx/xrc/xmlres.h +++ b/include/wx/xrc/xmlres.h @@ -544,6 +544,9 @@ public: wxCoord GetDimension(const wxString& param, wxCoord defaultv = 0, wxWindow *windowToUse = NULL) wxOVERRIDE; + // Gets a size which is not expressed in pixels, so not in dialog units. + wxSize GetPairInts(const wxString& param) wxOVERRIDE; + // Gets a direction, complains if the value is invalid. wxDirection GetDirection(const wxString& param, wxDirection dirDefault = wxLEFT) wxOVERRIDE; diff --git a/include/wx/xrc/xmlreshandler.h b/include/wx/xrc/xmlreshandler.h index 0dab73b3d4..5c2f6b4be1 100644 --- a/include/wx/xrc/xmlreshandler.h +++ b/include/wx/xrc/xmlreshandler.h @@ -74,6 +74,7 @@ public: virtual wxPoint GetPosition(const wxString& param = wxT("pos")) = 0; virtual wxCoord GetDimension(const wxString& param, wxCoord defaultv = 0, wxWindow *windowToUse = NULL) = 0; + virtual wxSize GetPairInts(const wxString& param) = 0; virtual wxDirection GetDirection(const wxString& param, wxDirection dir = wxLEFT) = 0; virtual wxBitmap GetBitmap(const wxString& param = wxT("bitmap"), const wxArtClient& defaultArtClient = wxART_OTHER, @@ -296,6 +297,10 @@ protected: { return GetImpl()->GetDimension(param, defaultv, windowToUse); } + wxSize GetPairInts(const wxString& param) + { + return GetImpl()->GetPairInts(param); + } wxDirection GetDirection(const wxString& param, wxDirection dir = wxLEFT) { return GetImpl()->GetDirection(param, dir); diff --git a/misc/schema/xrc_schema.rnc b/misc/schema/xrc_schema.rnc index fe6858f794..b290ec057a 100644 --- a/misc/schema/xrc_schema.rnc +++ b/misc/schema/xrc_schema.rnc @@ -442,6 +442,7 @@ t_colour = xsd:string { pattern = "#[0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-z xsd:string { pattern = "[^#].*" } t_position = t_size t_size = xsd:string { pattern = "(-?\d+),(-?\d+)d?" } +t_pair_ints = xsd:string { pattern = "(-?\d+),(-?\d+)" } t_dimension = xsd:string { pattern = "(-?\d+)d?" } t_bitmap = t_url?, @@ -1756,7 +1757,7 @@ wxBoxSizer_horz_item = [xrc:p="o"] element option {_, t_integer }* & [xrc:p="o"] element border {_, t_dimension }* & [xrc:p="o"] element minsize {_, t_size }* & - [xrc:p="o"] element ratio {_, t_size }* & + [xrc:p="o"] element ratio {_, t_pair_ints }* & [xrc:p="o"] element flag {_, t_horz_sizer_flags}* } @@ -1777,7 +1778,7 @@ wxBoxSizer_vert_item = [xrc:p="o"] element option {_, t_integer }* & [xrc:p="o"] element border {_, t_dimension }* & [xrc:p="o"] element minsize {_, t_size }* & - [xrc:p="o"] element ratio {_, t_size }* & + [xrc:p="o"] element ratio {_, t_pair_ints }* & [xrc:p="o"] element flag {_, t_vert_sizer_flags }* } @@ -1797,7 +1798,7 @@ wxGridSizer_item = stdObjectNodeAttributes & [xrc:p="o"] element border {_, t_dimension }* & [xrc:p="o"] element minsize {_, t_size }* & - [xrc:p="o"] element ratio {_, t_size }* & + [xrc:p="o"] element ratio {_, t_pair_ints }* & [xrc:p="o"] element flag {_, t_grid_sizer_flags }* } @@ -1817,9 +1818,9 @@ wxSizerGB_item = stdObjectNodeAttributes & [xrc:p="o"] element border {_, t_dimension }* & [xrc:p="o"] element minsize {_, t_size }* & - [xrc:p="o"] element ratio {_, t_size }* & - [xrc:p="o"] element cellpos {_, t_position }* & - [xrc:p="o"] element cellspan {_, t_size }* & + [xrc:p="o"] element ratio {_, t_pair_ints }* & + [xrc:p="o"] element cellpos {_, t_pair_ints }* & + [xrc:p="o"] element cellspan {_, t_pair_ints }* & [xrc:p="o"] element flag {_, xsd:string { pattern = "(wxLEFT|wxRIGHT|wxTOP|wxBOTTOM|wxNORTH|wxSOUTH|wxEAST|wxWEST|wxALL|wxGROW|wxEXPAND|wxSHAPED|wxSTRETCH_NOT|wxALIGN_CENTER|wxALIGN_CENTRE|wxALIGN_LEFT|wxALIGN_RIGHT|wxALIGN_TOP|wxALIGN_BOTTOM|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTRE_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALIGN_CENTRE_VERTICAL|wxRESERVE_SPACE_EVEN_IF_HIDDEN)( *\| *(wxLEFT|wxRIGHT|wxTOP|wxBOTTOM|wxNORTH|wxSOUTH|wxEAST|wxWEST|wxALL|wxGROW|wxEXPAND|wxSHAPED|wxSTRETCH_NOT|wxALIGN_CENTER|wxALIGN_CENTRE|wxALIGN_LEFT|wxALIGN_RIGHT|wxALIGN_TOP|wxALIGN_BOTTOM|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTRE_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALIGN_CENTRE_VERTICAL|wxRESERVE_SPACE_EVEN_IF_HIDDEN))*" diff --git a/src/xrc/xh_sizer.cpp b/src/xrc/xh_sizer.cpp index fbb22cf828..4c38078acc 100644 --- a/src/xrc/xh_sizer.cpp +++ b/src/xrc/xh_sizer.cpp @@ -514,7 +514,7 @@ void wxSizerXmlHandler::SetGrowables(wxFlexGridSizer* sizer, wxGBPosition wxSizerXmlHandler::GetGBPos(const wxString& param) { - wxSize sz = GetSize(param); + wxSize sz = GetPairInts(param); if (sz.x < 0) sz.x = 0; if (sz.y < 0) sz.y = 0; return wxGBPosition(sz.x, sz.y); @@ -522,7 +522,7 @@ wxGBPosition wxSizerXmlHandler::GetGBPos(const wxString& param) wxGBSpan wxSizerXmlHandler::GetGBSpan(const wxString& param) { - wxSize sz = GetSize(param); + wxSize sz = GetPairInts(param); if (sz.x < 1) sz.x = 1; if (sz.y < 1) sz.y = 1; return wxGBSpan(sz.x, sz.y); @@ -856,7 +856,7 @@ void wxSizerXmlHandler::SetSizerItemAttributes(wxSizerItem* sitem) wxSize sz = GetSize(wxT("minsize")); if (!(sz == wxDefaultSize)) sitem->SetMinSize(sz); - sz = GetSize(wxT("ratio")); + sz = GetPairInts(wxT("ratio")); if (!(sz == wxDefaultSize)) sitem->SetRatio(sz); diff --git a/src/xrc/xmlres.cpp b/src/xrc/xmlres.cpp index 8e91c6cc8a..6a1e813c26 100644 --- a/src/xrc/xmlres.cpp +++ b/src/xrc/xmlres.cpp @@ -2172,6 +2172,28 @@ wxCoord wxXmlResourceHandlerImpl::GetDimension(const wxString& param, return ParseValueInPixels(this, param, defaultv, windowToUse); } + +wxSize wxXmlResourceHandlerImpl::GetPairInts(const wxString& param) +{ + const wxString s = GetParamValue(param); + if ( s.empty() ) + return wxDefaultSize; + + wxSize sz; + if ( !XRCConvertFromAbsValue(s, sz) ) + { + ReportParamError + ( + param, + wxString::Format("cannot parse \"%s\" as pair of integers", s) + ); + return wxDefaultSize; + } + + return sz; +} + + wxDirection wxXmlResourceHandlerImpl::GetDirection(const wxString& param, wxDirection dirDefault) {