From 50c202914e449f57a1d1a6d07447c6988f392005 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 22 Aug 2011 12:18:49 +0000 Subject: [PATCH] No changes, just factor our wxDirection parsing code in wxXRC. Move it from wxButtonXmlHandler into a reusable wxXmlResourceHandler:: GetDirection() that can used by the other handlers too. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68839 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/xrc/xmlres.h | 3 +++ interface/wx/xrc/xmlres.h | 12 ++++++++++++ src/xrc/xh_bttn.cpp | 29 ++--------------------------- src/xrc/xmlres.cpp | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 27 deletions(-) diff --git a/include/wx/xrc/xmlres.h b/include/wx/xrc/xmlres.h index f7c6867929..1d226c11af 100644 --- a/include/wx/xrc/xmlres.h +++ b/include/wx/xrc/xmlres.h @@ -558,6 +558,9 @@ protected: wxCoord GetDimension(const wxString& param, wxCoord defaultv = 0, wxWindow *windowToUse = NULL); + // Gets a direction, complains if the value is invalid. + wxDirection GetDirection(const wxString& param, wxDirection dir = wxLEFT); + // Gets a bitmap. wxBitmap GetBitmap(const wxString& param = wxT("bitmap"), const wxArtClient& defaultArtClient = wxART_OTHER, diff --git a/interface/wx/xrc/xmlres.h b/interface/wx/xrc/xmlres.h index 269aa39ec8..28709171bc 100644 --- a/interface/wx/xrc/xmlres.h +++ b/interface/wx/xrc/xmlres.h @@ -553,6 +553,18 @@ protected: wxCoord GetDimension(const wxString& param, wxCoord defaultv = 0, wxWindow* windowToUse = 0); + /** + Gets a direction. + + If the given @a param is not present or has empty value, @a dir is + returned by default. Otherwise the value of the parameter is parsed and + a warning is generated if it's not one of @c wxLEFT, @c wxTOP, @c + wxRIGHT or @c wxBOTTOM. + + @since 2.9.3 + */ + wxDirection GetDirection(const wxString& param, wxDirection dir = wxLEFT); + /** Gets a font. */ diff --git a/src/xrc/xh_bttn.cpp b/src/xrc/xh_bttn.cpp index 926b6849b9..7f2058cdd2 100644 --- a/src/xrc/xh_bttn.cpp +++ b/src/xrc/xh_bttn.cpp @@ -53,33 +53,8 @@ wxObject *wxButtonXmlHandler::DoCreateResource() if ( GetParamNode("bitmap") ) { - wxDirection dir; - const wxString dirstr = GetParamValue("bitmapposition"); - if ( dirstr.empty() || dirstr == "wxLEFT" ) - dir = wxLEFT; - else if ( dirstr == "wxRIGHT" ) - dir = wxRIGHT; - else if ( dirstr == "wxTOP" ) - dir = wxTOP; - else if ( dirstr == "wxBOTTOM" ) - dir = wxBOTTOM; - else - { - ReportError - ( - GetParamNode("bitmapposition"), - wxString::Format - ( - "Invalid bitmap position \"%s\": must be one of " - "wxLEFT|wxRIGHT|wxTOP|wxBOTTOM.", - dirstr - ) - ); - - dir = wxLEFT; - } - - button->SetBitmap(GetBitmap("bitmap", wxART_BUTTON), dir); + button->SetBitmap(GetBitmap("bitmap", wxART_BUTTON), + GetDirection("bitmapposition")); } SetupWindow(button); diff --git a/src/xrc/xmlres.cpp b/src/xrc/xmlres.cpp index 95525ac90a..7a3041e630 100644 --- a/src/xrc/xmlres.cpp +++ b/src/xrc/xmlres.cpp @@ -2150,6 +2150,40 @@ wxCoord wxXmlResourceHandler::GetDimension(const wxString& param, return sx; } +wxDirection +wxXmlResourceHandler::GetDirection(const wxString& param, wxDirection dirDefault) +{ + wxDirection dir; + + const wxString dirstr = GetParamValue(param); + if ( dirstr.empty() ) + dir = dirDefault; + else if ( dirstr == "wxLEFT" ) + dir = wxLEFT; + else if ( dirstr == "wxRIGHT" ) + dir = wxRIGHT; + else if ( dirstr == "wxTOP" ) + dir = wxTOP; + else if ( dirstr == "wxBOTTOM" ) + dir = wxBOTTOM; + else + { + ReportError + ( + GetParamNode(param), + wxString::Format + ( + "Invalid direction \"%s\": must be one of " + "wxLEFT|wxRIGHT|wxTOP|wxBOTTOM.", + dirstr + ) + ); + + dir = dirDefault; + } + + return dir; +} // Get system font index using indexname static wxFont GetSystemFont(const wxString& name) -- 2.47.2