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.
This commit is contained in:
Vadim Zeitlin
2016-07-06 18:44:07 +02:00
parent c4d2ba1335
commit f68c67aa85
6 changed files with 54 additions and 12 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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);

View File

@@ -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))*"

View File

@@ -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);

View File

@@ -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)
{