wxvbam: Convert a nasty #define into a nice(er) function

This was way more work than it should have been.
This commit is contained in:
Arthur Moore 2015-01-09 01:02:20 -05:00
parent 046faf53ba
commit fedaa24799
1 changed files with 28 additions and 28 deletions

View File

@ -2049,6 +2049,32 @@ public:
} throttle_ctrl; } throttle_ctrl;
///////////////////////////// /////////////////////////////
#define LoadXRCDialog(name) LoadXRCDialog1(d,name,this)
void LoadXRCDialog1(wxDialog* & dialog,const char * name,MainFrame * theframe)
{
/* why do I have to manually Fit()? */
/* since I do, always do it for last item so other init happens first */
/* don't forget to Fit() the last dialog! */
if(dialog != NULL)
{
dialog->Fit();
}
wxString dname = wxString::FromUTF8(name);
/* using this instead of LoadDialog() allows non-wxDialog classes that */
/* are derived from wxDialog (like wxPropertyDialog) to work */
dialog = wxDynamicCast(wxXmlResource::Get()->LoadObject(theframe, dname, wxEmptyString), wxDialog);
if(!dialog)
{
wxLogError(_("Unable to load dialog %s from resources"), name);
exit(1);
}
/* 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);
mark_recursive(dialog);
}
bool MainFrame::InitMore(void) bool MainFrame::InitMore(void)
{ {
@ -2302,38 +2328,12 @@ bool MainFrame::InitMore(void)
// user's responsibility to ensure that the GUI works as intended after // user's responsibility to ensure that the GUI works as intended after
// modifications // modifications
wxDialog *d = 0; wxDialog *d = NULL;
const wxChar *dname;
#define baddialog() do { \
wxLogError(_("Unable to load dialog %s from resources"), dname); \
return false; \
} while(0)
#define baddialogcv(n) do { \ #define baddialogcv(n) do { \
wxLogError(_("Unable to load dialog %s (control %s) from resources"), dname, n); \ wxLogError(_("Unable to load dialog (control %s) from resources"), n); \
return false; \ return false; \
} while(0) } while(0)
#define baddialogc(n) baddialogcv(wxT(n)) #define baddialogc(n) baddialogcv(wxT(n))
#define LoadXRCDialog(n) do { \
/* why do I have to manually Fit()? */ \
/* since I do, always do it for last item so other init happens first */ \
/* don't forget to Fit() the last dialog! */ \
if(d != 0) \
d->Fit(); \
dname = wxT(n); \
/* using this instead of LoadDialog() allows non-wxDialog classes that */ \
/* are derived from wxDialog (like wxPropertyDialog) to work */ \
d = wxDynamicCast(wxXmlResource::Get()->LoadObject(this, dname, wxEmptyString), \
wxDialog); \
if(!d) \
baddialog(); \
/* 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(!d->GetParent()) \
d->Reparent(this); \
\
mark_recursive(d); \
} while(0)
#define vfld(f, t) do { \ #define vfld(f, t) do { \
if(!XRCCTRL(*d, f, t)) \ if(!XRCCTRL(*d, f, t)) \