Revamped some of the wx load dialog error handling.
C++ has built in error handling, but C programmers never seem to use it.
This commit is contained in:
parent
aeb033072c
commit
30876d227e
|
@ -7,6 +7,8 @@
|
|||
|
||||
#include "wxvbam.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include <wx/stockitem.h>
|
||||
#include <wx/spinctrl.h>
|
||||
#include <wx/clrpicker.h>
|
||||
|
@ -2049,23 +2051,24 @@ public:
|
|||
} throttle_ctrl;
|
||||
|
||||
/////////////////////////////
|
||||
#define LoadXRCDialog(name) d=LoadXRCDialog1(name,this)
|
||||
wxDialog * LoadXRCDialog1(const char * name,MainFrame * theframe)
|
||||
wxDialog * MainFrame::LoadXRCDialog(const char * name)
|
||||
{
|
||||
wxString dname = wxString::FromUTF8(name);
|
||||
/* using this instead of LoadDialog() allows non-wxDialog classes that */
|
||||
/* are derived from wxDialog (like wxPropertyDialog) to work */
|
||||
wxDialog * dialog = wxDynamicCast(wxXmlResource::Get()->LoadObject(theframe, dname, wxEmptyString), wxDialog);
|
||||
/* are derived from wxDialog (like wxPropertySheetDialog) to work */
|
||||
wxDialog * dialog = wxDynamicCast(wxXmlResource::Get()->LoadObject(this, dname, wxEmptyString), wxDialog);
|
||||
if(!dialog)
|
||||
{
|
||||
wxLogError(_("Unable to load dialog %s from resources"), name);
|
||||
exit(1);
|
||||
std::string errormessage = "Unable to load a dialog from the builtin xrc file: ";
|
||||
errormessage+=name;
|
||||
throw std::runtime_error(errormessage);
|
||||
return NULL;
|
||||
}
|
||||
/* wx-2.9.1 doesn't set parent for propertysheetdialogs for some reason */
|
||||
/* this will generate a gtk warning but it is necessary for later */
|
||||
/* retrieval using FindWindow() */
|
||||
if(!dialog->GetParent())
|
||||
dialog->Reparent(theframe);
|
||||
dialog->Reparent(this);
|
||||
mark_recursive(dialog);
|
||||
return dialog;
|
||||
}
|
||||
|
@ -2321,40 +2324,40 @@ bool MainFrame::InitMore(void)
|
|||
// note that the only verification done is to ensure no crashes. It's the
|
||||
// user's responsibility to ensure that the GUI works as intended after
|
||||
// modifications
|
||||
try {
|
||||
|
||||
wxDialog *d = NULL;
|
||||
#define baddialogcv(n) do { \
|
||||
wxLogError(_("Unable to load dialog (control %s) from resources"), n); \
|
||||
return false; \
|
||||
} while(0)
|
||||
#define baddialogc(n) baddialogcv(wxT(n))
|
||||
#define baddialogc(name) { \
|
||||
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) do { \
|
||||
#define vfld(f, t) \
|
||||
if(!XRCCTRL(*d, f, t)) \
|
||||
baddialogc(f); \
|
||||
} while(0)
|
||||
#define getfld(v, f, t) do { \
|
||||
if(!(v = XRCCTRL(*d, f, t))) \
|
||||
baddialogc(f); \
|
||||
} while(0)
|
||||
#define getfldv(v, f, t) do { \
|
||||
if(!(v = XRCCTRL_D(*d, f, t))) \
|
||||
baddialogcv(f.c_str()); \
|
||||
} while(0)
|
||||
baddialogc(f);
|
||||
#define getfld(v, f, t) \
|
||||
v = XRCCTRL(*d, f, t); \
|
||||
if(!v) \
|
||||
baddialogc(f);
|
||||
#define getfldv(v, f, t) \
|
||||
v = XRCCTRL_D(*d, f, t); \
|
||||
if(!v) \
|
||||
baddialogc(f.mb_str());
|
||||
|
||||
//// displayed during run
|
||||
LoadXRCDialog("GBPrinter");
|
||||
d=LoadXRCDialog("GBPrinter");
|
||||
// just verify preview window & mag sel present
|
||||
{
|
||||
wxPanel *prev;
|
||||
getfld(prev, "Preview", wxPanel);
|
||||
if(!wxDynamicCast(prev->GetParent(), wxScrolledWindow))
|
||||
baddialogc("Preview");
|
||||
throw std::runtime_error("Unable to load a dialog control from the builtin xrc file: Preview");
|
||||
vfld("Magnification", wxControlWithItems);
|
||||
}
|
||||
|
||||
//// File menu
|
||||
LoadXRCDialog("GBAROMInfo");
|
||||
d=LoadXRCDialog("GBAROMInfo");
|
||||
// just verify fields present
|
||||
wxControl *lab;
|
||||
#define getlab(n) getfld(lab, n, wxControl)
|
||||
|
@ -2367,7 +2370,7 @@ bool MainFrame::InitMore(void)
|
|||
getlab("Version");
|
||||
getlab("CRC");
|
||||
|
||||
LoadXRCDialog("GBROMInfo");
|
||||
d=LoadXRCDialog("GBROMInfo");
|
||||
// just verify fields present
|
||||
getlab("Title");
|
||||
getlab("MakerCode");
|
||||
|
@ -2383,11 +2386,11 @@ bool MainFrame::InitMore(void)
|
|||
getlab("LicCode");
|
||||
getlab("Checksum");
|
||||
|
||||
LoadXRCDialog("CodeSelect");
|
||||
d=LoadXRCDialog("CodeSelect");
|
||||
// just verify list present
|
||||
vfld("CodeList", wxControlWithItems);
|
||||
|
||||
LoadXRCDialog("ExportSPS");
|
||||
d=LoadXRCDialog("ExportSPS");
|
||||
// just verify text fields present
|
||||
vfld("Title", wxTextCtrl);
|
||||
vfld("Description", wxTextCtrl);
|
||||
|
@ -2395,7 +2398,7 @@ bool MainFrame::InitMore(void)
|
|||
|
||||
//// Emulation menu
|
||||
#ifndef NO_LINK
|
||||
LoadXRCDialog("NetLink");
|
||||
d=LoadXRCDialog("NetLink");
|
||||
#endif
|
||||
wxRadioButton *rb;
|
||||
#define getrbi(n, o, v) do { \
|
||||
|
@ -2492,14 +2495,14 @@ bool MainFrame::InitMore(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
LoadXRCDialog("CheatList");
|
||||
d=LoadXRCDialog("CheatList");
|
||||
{
|
||||
cheat_list_handler.dlg = d;
|
||||
d->SetEscapeId(wxID_OK);
|
||||
wxCheckedListCtrl *cl;
|
||||
getfld(cl, "Cheats", wxCheckedListCtrl);
|
||||
if(!cl->Init())
|
||||
baddialogc("Cheats");
|
||||
throw std::runtime_error("Unable to load a dialog control from the builtin xrc file: Cheats");
|
||||
cheat_list_handler.list = cl;
|
||||
cl->SetValidator(CheatListFill());
|
||||
cl->InsertColumn(0, _("Code"));
|
||||
|
@ -2566,7 +2569,7 @@ bool MainFrame::InitMore(void)
|
|||
NULL, &cheat_list_handler);
|
||||
}
|
||||
|
||||
LoadXRCDialog("CheatEdit");
|
||||
d=LoadXRCDialog("CheatEdit");
|
||||
wxChoice *ch;
|
||||
#define getch(n, o) do { \
|
||||
getfld(ch, n, wxChoice); \
|
||||
|
@ -2582,7 +2585,7 @@ bool MainFrame::InitMore(void)
|
|||
cheat_list_handler.ce_codes_tc = tc;
|
||||
}
|
||||
|
||||
LoadXRCDialog("CheatCreate");
|
||||
d=LoadXRCDialog("CheatCreate");
|
||||
{
|
||||
cheat_find_handler.dlg = d;
|
||||
d->SetEscapeId(wxID_OK);
|
||||
|
@ -2652,7 +2655,7 @@ bool MainFrame::InitMore(void)
|
|||
NULL, &cheat_find_handler);
|
||||
}
|
||||
|
||||
LoadXRCDialog("CheatAdd");
|
||||
d=LoadXRCDialog("CheatAdd");
|
||||
{
|
||||
// d->Reparent(cheat_find_handler.dlg); // broken
|
||||
gettc("Desc", cheat_find_handler.ca_desc);
|
||||
|
@ -2671,7 +2674,7 @@ bool MainFrame::InitMore(void)
|
|||
}
|
||||
|
||||
//// config menu
|
||||
LoadXRCDialog("GeneralConfig");
|
||||
d=LoadXRCDialog("GeneralConfig");
|
||||
wxCheckBox *cb;
|
||||
#define getcbb(n, o) do { \
|
||||
getfld(cb, n, wxCheckBox); \
|
||||
|
@ -2729,7 +2732,7 @@ bool MainFrame::InitMore(void)
|
|||
getfld(fp, n, wxFilePickerCtrl); \
|
||||
fp->SetValidator(wxFileDirPickerValidator(&o)); \
|
||||
} while(0)
|
||||
LoadXRCDialog("GameBoyConfig");
|
||||
d=LoadXRCDialog("GameBoyConfig");
|
||||
{
|
||||
/// System and Peripherals
|
||||
getch("System", gbEmulatorType);
|
||||
|
@ -2808,7 +2811,7 @@ bool MainFrame::InitMore(void)
|
|||
}
|
||||
}
|
||||
|
||||
LoadXRCDialog("GameBoyAdvanceConfig");
|
||||
d=LoadXRCDialog("GameBoyAdvanceConfig");
|
||||
{
|
||||
/// System and peripherals
|
||||
getch("SaveType", gopts.save_type);
|
||||
|
@ -2821,7 +2824,7 @@ bool MainFrame::InitMore(void)
|
|||
#define getgbaw(n) do { \
|
||||
wxWindow *w = d->FindWindow(XRCID(n)); \
|
||||
if(!w) \
|
||||
baddialogc(n); \
|
||||
baddialogc(n); \
|
||||
w->SetValidator(GBACtrlEnabler()); \
|
||||
} while(0)
|
||||
getgbaw("Detect");
|
||||
|
@ -2861,7 +2864,7 @@ bool MainFrame::InitMore(void)
|
|||
vfld("OvMirroring", wxChoice);
|
||||
}
|
||||
|
||||
LoadXRCDialog("DisplayConfig");
|
||||
d=LoadXRCDialog("DisplayConfig");
|
||||
{
|
||||
/// On-Screen Display
|
||||
getch("SpeedIndicator", gopts.osd_speed);
|
||||
|
@ -2930,7 +2933,7 @@ bool MainFrame::InitMore(void)
|
|||
getch("IFB", gopts.ifb);
|
||||
}
|
||||
|
||||
LoadXRCDialog("SoundConfig");
|
||||
d=LoadXRCDialog("SoundConfig");
|
||||
wxSlider *sl;
|
||||
#define getsl(n, o) do { \
|
||||
getfld(sl, n, wxSlider); \
|
||||
|
@ -3010,7 +3013,7 @@ bool MainFrame::InitMore(void)
|
|||
getfld(dp, n, wxDirPickerCtrl); \
|
||||
dp->SetValidator(wxFileDirPickerValidator(&o)); \
|
||||
} while(0)
|
||||
LoadXRCDialog("DirectoriesConfig");
|
||||
d=LoadXRCDialog("DirectoriesConfig");
|
||||
{
|
||||
getdp("GBARoms", gopts.gba_rom_dir);
|
||||
getdp("GBRoms", gopts.gb_rom_dir);
|
||||
|
@ -3020,7 +3023,7 @@ bool MainFrame::InitMore(void)
|
|||
getdp("Recordings", gopts.recording_dir);
|
||||
}
|
||||
|
||||
LoadXRCDialog("JoypadConfig");
|
||||
d=LoadXRCDialog("JoypadConfig");
|
||||
wxFarRadio *r = 0;
|
||||
for(int i = 0; i < 4; i++) {
|
||||
wxString pn;
|
||||
|
@ -3045,7 +3048,7 @@ bool MainFrame::InitMore(void)
|
|||
for(int j = 0; j < NUM_KEYS; j++) {
|
||||
wxJoyKeyTextCtrl *tc = XRCCTRL_D(*w, joynames[j], wxJoyKeyTextCtrl);
|
||||
if(!tc)
|
||||
baddialogcv(joynames[j]);
|
||||
baddialogc(wxString(joynames[j]).mb_str());
|
||||
wxWindow *p = tc->GetParent();
|
||||
if(p == prevp)
|
||||
tc->MoveAfterInTabOrder(prev);
|
||||
|
@ -3064,7 +3067,7 @@ bool MainFrame::InitMore(void)
|
|||
}
|
||||
|
||||
#ifndef NO_LINK
|
||||
LoadXRCDialog("LinkConfig");
|
||||
d=LoadXRCDialog("LinkConfig");
|
||||
{
|
||||
getcbbe("Joybus", gba_joybus_enabled);
|
||||
getlab("JoybusHostLab");
|
||||
|
@ -3082,7 +3085,7 @@ bool MainFrame::InitMore(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
LoadXRCDialog("AccelConfig");
|
||||
d=LoadXRCDialog("AccelConfig");
|
||||
{
|
||||
wxTreeCtrl *tc;
|
||||
getfld(tc, "Commands", wxTreeCtrl);
|
||||
|
@ -3177,6 +3180,12 @@ bool MainFrame::InitMore(void)
|
|||
wxCommandEventHandler(AccelConfig_t::CheckKey),
|
||||
NULL, &accel_config_handler);
|
||||
}
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
wxLogError(wxString::FromUTF8(e.what()));
|
||||
return false;
|
||||
}
|
||||
|
||||
//// Debug menu
|
||||
// actually, the viewers can be instantiated multiple times.
|
||||
|
|
|
@ -244,6 +244,8 @@ private:
|
|||
void OnDropFile(wxDropFilesEvent&);
|
||||
// pop up menu in fullscreen mode
|
||||
void OnMenu(wxContextMenuEvent &);
|
||||
/// Load a named wxDialog from the XRC file (also loads wxPropertySheetDialog)
|
||||
wxDialog * LoadXRCDialog(const char * name);
|
||||
#include "cmdhandlers.h"
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue