From d858e35d012a9702b83ca69c93e20677d9dfe4fb Mon Sep 17 00:00:00 2001 From: wowzaman12 Date: Sat, 28 Mar 2015 01:52:20 +0000 Subject: [PATCH] Created a single template that does the same thing as several of the C macros --- src/wx/guiinit.cpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/wx/guiinit.cpp b/src/wx/guiinit.cpp index c264d0bc..a5c99c72 100644 --- a/src/wx/guiinit.cpp +++ b/src/wx/guiinit.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -18,7 +19,6 @@ #include #include "wx/checkedlistctrl.h" #include -#include #include "../gba/CheatSearch.h" // The program icon, in case it's missing from .xrc (MSW gets it from .rc file) @@ -1992,6 +1992,18 @@ wxPropertySheetDialog * MainFrame::LoadXRCropertySheetDialog(const char * name) return dialog; } +//This just adds some error checking to the wx XRCCTRL macro +template +T * SafeXRCCTRL( wxWindow *window,const char * name) +{ + wxString dname = wxString::FromUTF8(name); + //This is needed to work around a bug in XRCCTRL + wxString Ldname=dname; + T * output = XRCCTRL(*window, dname, T); + CheckThrowXRCError(output,name); + return output; +} + bool MainFrame::InitMore(void) { // Make sure display panel present and correct type @@ -2246,13 +2258,11 @@ bool MainFrame::InitMore(void) try { wxDialog *d = NULL; -#define vfld(dialog_pointer, name, type) CheckThrowXRCError(XRCCTRL(*dialog_pointer, name, type),name) -#define getfld(return_value, dialog_pointer, name, type) \ - return_value = XRCCTRL(*dialog_pointer, name, type); \ - CheckThrowXRCError(return_value,name) -#define getfldv(return_value, dialog_pointer, name, t) \ - return_value = XRCCTRL_D(*dialog_pointer, name, t); \ - CheckThrowXRCError(return_value,ToString(name)) + +#define vfld(dialog_pointer, name, type) SafeXRCCTRL(dialog_pointer,name) +#define getfld(return_value, dialog_pointer, name, type) return_value=SafeXRCCTRL(dialog_pointer,name) +#define getfldv(return_value, dialog_pointer, name, type) \ + return_value=SafeXRCCTRL(dialog_pointer,ToString(name).c_str()) //// displayed during run d=LoadXRCDialog("GBPrinter"); @@ -2262,7 +2272,7 @@ bool MainFrame::InitMore(void) getfld(prev, d, "Preview", wxPanel); if(!wxDynamicCast(prev->GetParent(), wxScrolledWindow)) throw std::runtime_error("Unable to load a dialog control from the builtin xrc file: Preview"); - vfld(d, "Magnification", wxControlWithItems); + SafeXRCCTRL(d, "Magnification"); } //// File menu