Now fully use the error checking function instead of the C macro

This commit is contained in:
wowzaman12 2015-03-28 01:20:41 +00:00
parent 76ef5906a0
commit 07eb6564e0
1 changed files with 20 additions and 20 deletions

View File

@ -1943,15 +1943,26 @@ public:
} throttle_ctrl; } throttle_ctrl;
///////////////////////////// /////////////////////////////
//Helper functions to convert WX's crazy string types to std::string
std::string ToString(wxCharBuffer aString)
{
return std::string(aString);
}
std::string ToString(const wxChar* aString)
{
return std::string(wxString(aString).mb_str(wxConvUTF8));
}
//Check if a pointer from the XRC file is valid. If it's not, throw an error telling the user. //Check if a pointer from the XRC file is valid. If it's not, throw an error telling the user.
template <typename T> template <typename T>
void CheckThrowXRCError(T pointer,std::string name) void CheckThrowXRCError(T pointer,std::string name)
{ {
if(pointer == NULL) if(pointer == NULL)
{ {
std::string errormessage = "Unable to load a "; std::string errormessage = "Unable to load a \"";
errormessage+=typeid(pointer).name(); errormessage+=typeid(pointer).name();
errormessage+=" from the builtin xrc file: "; errormessage+="\" from the builtin xrc file: ";
errormessage+=name; errormessage+=name;
throw std::runtime_error(errormessage); throw std::runtime_error(errormessage);
} }
@ -1961,7 +1972,8 @@ wxDialog * MainFrame::LoadXRCDialog(const char * name)
wxString dname = wxString::FromUTF8(name); wxString dname = wxString::FromUTF8(name);
/* using this instead of LoadDialog() allows non-wxDialog classes that */ /* using this instead of LoadDialog() allows non-wxDialog classes that */
/* are derived from wxDialog (like wxPropertySheetDialog) to work */ /* are derived from wxDialog (like wxPropertySheetDialog) to work */
wxDialog * dialog = wxDynamicCast(wxXmlResource::Get()->LoadObject(this, dname, wxEmptyString), wxDialog); wxObject * anObject = wxXmlResource::Get()->LoadObject(this, dname, wxEmptyString);
wxDialog * dialog = wxDynamicCast(anObject, wxDialog);
CheckThrowXRCError(dialog,name); CheckThrowXRCError(dialog,name);
/* wx-2.9.1 doesn't set parent for propertysheetdialogs for some reason */ /* wx-2.9.1 doesn't set parent for propertysheetdialogs for some reason */
@ -2227,23 +2239,13 @@ bool MainFrame::InitMore(void)
try { try {
wxDialog *d = NULL; wxDialog *d = NULL;
#define baddialogc(name) { \ #define vfld(f, t) CheckThrowXRCError(XRCCTRL(*d, f, t),f)
std::string errormessage = "Unable to load a dialog control from the builtin xrc file: "; \
errormessage+=name; \
throw std::runtime_error(errormessage); \
}
#define vfld(f, t) \
if(!XRCCTRL(*d, f, t)) \
baddialogc(f);
#define getfld(v, f, t) \ #define getfld(v, f, t) \
v = XRCCTRL(*d, f, t); \ v = XRCCTRL(*d, f, t); \
if(!v) \ CheckThrowXRCError(v,f)
baddialogc(f);
#define getfldv(v, f, t) \ #define getfldv(v, f, t) \
v = XRCCTRL_D(*d, f, t); \ v = XRCCTRL_D(*d, f, t); \
if(!v) \ CheckThrowXRCError(v,ToString(f))
baddialogc(f.mb_str());
//// displayed during run //// displayed during run
d=LoadXRCDialog("GBPrinter"); d=LoadXRCDialog("GBPrinter");
@ -2722,8 +2724,7 @@ bool MainFrame::InitMore(void)
NULL, &BatConfigHandler); NULL, &BatConfigHandler);
#define getgbaw(n) do { \ #define getgbaw(n) do { \
wxWindow *w = d->FindWindow(XRCID(n)); \ wxWindow *w = d->FindWindow(XRCID(n)); \
if(!w) \ CheckThrowXRCError(w,n); \
baddialogc(n); \
w->SetValidator(GBACtrlEnabler()); \ w->SetValidator(GBACtrlEnabler()); \
} while(0) } while(0)
getgbaw("Detect"); getgbaw("Detect");
@ -2946,8 +2947,7 @@ bool MainFrame::InitMore(void)
wxWindow *prev = NULL, *prevp = NULL; wxWindow *prev = NULL, *prevp = NULL;
for(int j = 0; j < NUM_KEYS; j++) { for(int j = 0; j < NUM_KEYS; j++) {
wxJoyKeyTextCtrl *tc = XRCCTRL_D(*w, joynames[j], wxJoyKeyTextCtrl); wxJoyKeyTextCtrl *tc = XRCCTRL_D(*w, joynames[j], wxJoyKeyTextCtrl);
if(!tc) CheckThrowXRCError(tc,ToString(joynames[j]));
baddialogc(wxString(joynames[j]).mb_str());
wxWindow *p = tc->GetParent(); wxWindow *p = tc->GetParent();
if(p == prevp) if(p == prevp)
tc->MoveAfterInTabOrder(prev); tc->MoveAfterInTabOrder(prev);