Created a single template that does the same thing as several of the C macros

This commit is contained in:
Arthur Moore 2015-01-11 00:09:28 -05:00
parent d8fad4d69e
commit d84f04219c
1 changed files with 18 additions and 9 deletions

View File

@ -9,6 +9,7 @@
#include <typeinfo> #include <typeinfo>
#include <stdexcept> #include <stdexcept>
#include <algorithm>
#include <wx/stockitem.h> #include <wx/stockitem.h>
#include <wx/spinctrl.h> #include <wx/spinctrl.h>
@ -18,7 +19,6 @@
#include <wx/tokenzr.h> #include <wx/tokenzr.h>
#include "wx/checkedlistctrl.h" #include "wx/checkedlistctrl.h"
#include <wx/progdlg.h> #include <wx/progdlg.h>
#include <algorithm>
#include "../gba/CheatSearch.h" #include "../gba/CheatSearch.h"
// The program icon, in case it's missing from .xrc (MSW gets it from .rc file) // The program icon, in case it's missing from .xrc (MSW gets it from .rc file)
@ -2100,6 +2100,17 @@ wxPropertySheetDialog * MainFrame::LoadXRCropertySheetDialog(const char * name)
mark_recursive(dialog); mark_recursive(dialog);
return dialog; return dialog;
} }
///This just adds some error checking to the wx XRCCTRL macro
template <typename T>
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) bool MainFrame::InitMore(void)
{ {
@ -2355,13 +2366,11 @@ bool MainFrame::InitMore(void)
try { try {
wxDialog *d = NULL; wxDialog *d = NULL;
#define vfld(dialog_pointer, name, type) CheckThrowXRCError(XRCCTRL(*dialog_pointer, name, type),name)
#define getfld(return_value, dialog_pointer, name, type) \ #define vfld(dialog_pointer, name, type) SafeXRCCTRL<type>(dialog_pointer,name)
return_value = XRCCTRL(*dialog_pointer, name, type); \ #define getfld(return_value, dialog_pointer, name, type) return_value=SafeXRCCTRL<type>(dialog_pointer,name)
CheckThrowXRCError(return_value,name) #define getfldv(return_value, dialog_pointer, name, type) \
#define getfldv(return_value, dialog_pointer, name, t) \ return_value=SafeXRCCTRL<type>(dialog_pointer,ToString(name).c_str())
return_value = XRCCTRL_D(*dialog_pointer, name, t); \
CheckThrowXRCError(return_value,ToString(name))
//// displayed during run //// displayed during run
d=LoadXRCDialog("GBPrinter"); d=LoadXRCDialog("GBPrinter");
@ -2371,7 +2380,7 @@ bool MainFrame::InitMore(void)
getfld(prev, d, "Preview", wxPanel); getfld(prev, d, "Preview", wxPanel);
if(!wxDynamicCast(prev->GetParent(), wxScrolledWindow)) if(!wxDynamicCast(prev->GetParent(), wxScrolledWindow))
throw std::runtime_error("Unable to load a dialog control from the builtin xrc file: Preview"); throw std::runtime_error("Unable to load a dialog control from the builtin xrc file: Preview");
vfld(d, "Magnification", wxControlWithItems); SafeXRCCTRL<wxControlWithItems>(d, "Magnification");
} }
//// File menu //// File menu