From be041a9cfce339d1846ac41274f0111b9cbf502e Mon Sep 17 00:00:00 2001 From: Kp Date: Wed, 4 Dec 2013 22:37:23 +0000 Subject: [PATCH] Add type checking for ui_create_dialog --- common/include/ui.h | 20 +++++++++++++++++++- common/ui/dialog.cpp | 3 ++- common/ui/file.cpp | 2 +- common/ui/menu.cpp | 2 +- common/ui/message.cpp | 2 +- d1x-rebirth/editor/ehostage.cpp | 2 +- similar/editor/centers.cpp | 4 ++-- similar/editor/eswitch.cpp | 2 +- similar/editor/med.cpp | 6 +++--- similar/editor/medrobot.cpp | 4 ++-- similar/editor/medwall.cpp | 2 +- 11 files changed, 34 insertions(+), 15 deletions(-) diff --git a/common/include/ui.h b/common/include/ui.h index 44138b932..eca449c8c 100644 --- a/common/include/ui.h +++ b/common/include/ui.h @@ -239,7 +239,25 @@ typedef cstring_tie<10> ui_messagebox_tie; int ui_messagebox( short xc, short yc, const char * text, const ui_messagebox_tie &Button ); #define ui_messagebox(X,Y,N,T,...) ((ui_messagebox)((X),(Y),(T), ui_messagebox_tie(__VA_ARGS__))) -extern UI_DIALOG * ui_create_dialog( short x, short y, short w, short h, enum dialog_flags flags, int (*callback)(UI_DIALOG *, struct d_event *, void *), void *userdata ); +template +class ui_subfunction_t +{ +public: + typedef int (*type)(UI_DIALOG *, d_event *, T *); +}; + +class unused_ui_userdata_t; +static unused_ui_userdata_t *const unused_ui_userdata = NULL; + +template +UI_DIALOG * ui_create_dialog( short x, short y, short w, short h, enum dialog_flags flags, typename ui_subfunction_t::type callback, T *userdata ) +{ + return ui_create_dialog(x, y, w, h, flags, (ui_subfunction_t::type) callback, (void *)userdata); +} + +template <> +UI_DIALOG * ui_create_dialog( short x, short y, short w, short h, enum dialog_flags flags, typename ui_subfunction_t::type callback, void *userdata ); + extern struct window *ui_dialog_get_window(UI_DIALOG *dlg); extern void ui_dialog_set_current_canvas(UI_DIALOG *dlg); extern void ui_close_dialog( UI_DIALOG * dlg ); diff --git a/common/ui/dialog.cpp b/common/ui/dialog.cpp index 733ce84dd..eb5ec2e9b 100644 --- a/common/ui/dialog.cpp +++ b/common/ui/dialog.cpp @@ -220,7 +220,8 @@ static int ui_dialog_handler(window *wind, d_event *event, UI_DIALOG *dlg) return rval; } -UI_DIALOG * ui_create_dialog( short x, short y, short w, short h, enum dialog_flags flags, int (*callback)(UI_DIALOG *, d_event *, void *), void *userdata ) +template <> +UI_DIALOG * ui_create_dialog( short x, short y, short w, short h, enum dialog_flags flags, ui_subfunction_t::type callback, void *userdata ) { UI_DIALOG *dlg; int sw, sh, req_w, req_h; diff --git a/common/ui/file.cpp b/common/ui/file.cpp index 271845d2f..f0ee5b38d 100644 --- a/common/ui/file.cpp +++ b/common/ui/file.cpp @@ -306,7 +306,7 @@ int ui_get_filename( char * filename, const char * filespec, const char * messag b->spaces[i] = ' '; b->spaces[34] = 0; - dlg = ui_create_dialog( 200, 100, 400, 370, static_cast(DF_DIALOG | DF_MODAL), (int (*)(UI_DIALOG *, d_event *, void *))browser_handler, b ); + dlg = ui_create_dialog( 200, 100, 400, 370, static_cast(DF_DIALOG | DF_MODAL), browser_handler, b ); b->user_file = ui_add_gadget_inputbox( dlg, 60, 30, PATH_MAX, 40, InputText ); diff --git a/common/ui/menu.cpp b/common/ui/menu.cpp index 9cc3465c1..af2e0f09e 100644 --- a/common/ui/menu.cpp +++ b/common/ui/menu.cpp @@ -115,7 +115,7 @@ int MenuX( int x, int y, int NumButtons, const char *const text[] ) y = h - height; } - dlg = ui_create_dialog( x, y, width, height, static_cast(DF_FILLED | DF_SAVE_BG | DF_MODAL), (int (*)(UI_DIALOG *, d_event *, void *))menu_handler, m ); + dlg = ui_create_dialog( x, y, width, height, static_cast(DF_FILLED | DF_SAVE_BG | DF_MODAL), menu_handler, m ); x = MENU_BORDER+3; y = MENU_BORDER+3; diff --git a/common/ui/message.cpp b/common/ui/message.cpp index 9be455221..d2054471c 100644 --- a/common/ui/message.cpp +++ b/common/ui/message.cpp @@ -173,7 +173,7 @@ int (ui_messagebox)( short xc, short yc, const char * text, const ui_messagebox_ y = h - height; } - dlg = ui_create_dialog( x, y, width, height, static_cast(DF_DIALOG | DF_MODAL), (int (*)(UI_DIALOG *, d_event *, void *))messagebox_handler, m ); + dlg = ui_create_dialog( x, y, width, height, static_cast(DF_DIALOG | DF_MODAL), messagebox_handler, m ); //ui_draw_line_in( MESSAGEBOX_BORDER, MESSAGEBOX_BORDER, width-MESSAGEBOX_BORDER, height-MESSAGEBOX_BORDER ); diff --git a/d1x-rebirth/editor/ehostage.cpp b/d1x-rebirth/editor/ehostage.cpp index 5fe0c9022..74718404a 100644 --- a/d1x-rebirth/editor/ehostage.cpp +++ b/d1x-rebirth/editor/ehostage.cpp @@ -268,7 +268,7 @@ int do_hostage_dialog() SelectClosestHostage(); // Open a window with a quit button - MainWindow = ui_create_dialog( TMAPBOX_X+10, TMAPBOX_Y+20, 765-TMAPBOX_X, 545-TMAPBOX_Y, DF_DIALOG, (int (*)(UI_DIALOG *, d_event *, void *))hostage_dialog_handler, h ); + MainWindow = ui_create_dialog( TMAPBOX_X+10, TMAPBOX_Y+20, 765-TMAPBOX_X, 545-TMAPBOX_Y, DF_DIALOG, hostage_dialog_handler, h ); h->quitButton = ui_add_gadget_button( MainWindow, 20, 222, 48, 40, "Done", NULL ); h->hostageText = ui_add_gadget_inputbox( MainWindow, 10, 50, HOSTAGE_MESSAGE_LEN, HOSTAGE_MESSAGE_LEN, HostageMessage ); diff --git a/similar/editor/centers.cpp b/similar/editor/centers.cpp index fb0966bb7..8cc8c9968 100644 --- a/similar/editor/centers.cpp +++ b/similar/editor/centers.cpp @@ -86,10 +86,10 @@ int do_centers_dialog() // Open a window with a quit button #if defined(DXX_BUILD_DESCENT_I) - MainWindow = ui_create_dialog( TMAPBOX_X+20, TMAPBOX_Y+20, 765-TMAPBOX_X, 545-TMAPBOX_Y, DF_DIALOG, (int (*)(UI_DIALOG *, d_event *, void *))centers_dialog_handler, c ); + MainWindow = ui_create_dialog( TMAPBOX_X+20, TMAPBOX_Y+20, 765-TMAPBOX_X, 545-TMAPBOX_Y, DF_DIALOG, centers_dialog_handler, c ); i = 80; #elif defined(DXX_BUILD_DESCENT_II) - MainWindow = ui_create_dialog( 20, TMAPBOX_Y+20, 740, 545-TMAPBOX_Y, DF_DIALOG, (int (*)(UI_DIALOG *, d_event *, void *))centers_dialog_handler, c ); + MainWindow = ui_create_dialog( 20, TMAPBOX_Y+20, 740, 545-TMAPBOX_Y, DF_DIALOG, centers_dialog_handler, c ); i = 40; #endif c->quitButton = ui_add_gadget_button( MainWindow, 20, 252, 48, 40, "Done", NULL ); diff --git a/similar/editor/eswitch.cpp b/similar/editor/eswitch.cpp index f532ca96f..98169bc73 100644 --- a/similar/editor/eswitch.cpp +++ b/similar/editor/eswitch.cpp @@ -312,7 +312,7 @@ int do_trigger_dialog() hostage_close_window(); // Open a window with a quit button - MainWindow = ui_create_dialog( TMAPBOX_X+20, TMAPBOX_Y+20, 765-TMAPBOX_X, 545-TMAPBOX_Y, DF_DIALOG, (int (*)(UI_DIALOG *, d_event *, void *))trigger_dialog_handler, t ); + MainWindow = ui_create_dialog( TMAPBOX_X+20, TMAPBOX_Y+20, 765-TMAPBOX_X, 545-TMAPBOX_Y, DF_DIALOG, trigger_dialog_handler, t ); // These are the checkboxes for each door flag. i = 44; diff --git a/similar/editor/med.cpp b/similar/editor/med.cpp index ebb097190..ea0431d27 100644 --- a/similar/editor/med.cpp +++ b/similar/editor/med.cpp @@ -305,7 +305,7 @@ static int padnum=0; static void init_editor_screen(); static void gamestate_restore_check(); -static int editor_handler(UI_DIALOG *dlg, d_event *event, void *data); +static int editor_handler(UI_DIALOG *dlg, d_event *event, unused_ui_userdata_t *data); void init_editor() { @@ -745,7 +745,7 @@ void init_editor_screen() gr_set_curfont(editor_font); gr_set_fontcolor( CBLACK, CWHITE ); - EditorWindow = ui_create_dialog( 0 , 0, ED_SCREEN_W, ED_SCREEN_H, DF_FILLED, editor_handler, NULL ); + EditorWindow = ui_create_dialog( 0 , 0, ED_SCREEN_W, ED_SCREEN_H, DF_FILLED, editor_handler, unused_ui_userdata ); LargeViewBox = ui_add_gadget_userbox( EditorWindow,LVIEW_X,LVIEW_Y,LVIEW_W,LVIEW_H); #if ORTHO_VIEWS @@ -1002,7 +1002,7 @@ int RestoreGameState() { } // Handler for the main editor dialog -int editor_handler(UI_DIALOG *dlg, d_event *event, void *data) +int editor_handler(UI_DIALOG *dlg, d_event *event, unused_ui_userdata_t *) { editor_view *new_cv; int keypress = 0; diff --git a/similar/editor/medrobot.cpp b/similar/editor/medrobot.cpp index 2c5709cce..0336afdb0 100644 --- a/similar/editor/medrobot.cpp +++ b/similar/editor/medrobot.cpp @@ -469,7 +469,7 @@ int do_robot_dialog() memset(&r->goody_angles, 0, sizeof(vms_angvec)); // Open a window with a quit button - MainWindow = ui_create_dialog( TMAPBOX_X+20, TMAPBOX_Y+20, 765-TMAPBOX_X, 545-TMAPBOX_Y, DF_DIALOG, (int (*)(UI_DIALOG *, d_event *, void *))robot_dialog_handler, r ); + MainWindow = ui_create_dialog( TMAPBOX_X+20, TMAPBOX_Y+20, 765-TMAPBOX_X, 545-TMAPBOX_Y, DF_DIALOG, robot_dialog_handler, r ); r->quitButton = ui_add_gadget_button( MainWindow, 20, 286, 40, 32, "Done", NULL ); ui_add_gadget_button( MainWindow, GOODY_X+50, GOODY_Y-3, 25, 22, "<<", GoodyPrevType ); @@ -758,7 +758,7 @@ int do_object_dialog() Cur_goody_count = 0; // Open a window with a quit button - MattWindow = ui_create_dialog( TMAPBOX_X+20, TMAPBOX_Y+20, 765-TMAPBOX_X, 545-TMAPBOX_Y, DF_DIALOG, (int (*)(UI_DIALOG *, d_event *, void *))object_dialog_handler, o ); + MattWindow = ui_create_dialog( TMAPBOX_X+20, TMAPBOX_Y+20, 765-TMAPBOX_X, 545-TMAPBOX_Y, DF_DIALOG, object_dialog_handler, o ); o->quitButton = ui_add_gadget_button( MattWindow, 20, 286, 40, 32, "Done", NULL ); o->quitButton->hotkey = KEY_ENTER; diff --git a/similar/editor/medwall.cpp b/similar/editor/medwall.cpp index c468aaef9..6ca78ad39 100644 --- a/similar/editor/medwall.cpp +++ b/similar/editor/medwall.cpp @@ -366,7 +366,7 @@ int do_wall_dialog() close_all_windows(); // Open a window with a quit button - MainWindow = ui_create_dialog( TMAPBOX_X+20, TMAPBOX_Y+20, 765-TMAPBOX_X, 545-TMAPBOX_Y, DF_DIALOG, (int (*)(UI_DIALOG *, d_event *, void *))wall_dialog_handler, wd ); + MainWindow = ui_create_dialog( TMAPBOX_X+20, TMAPBOX_Y+20, 765-TMAPBOX_X, 545-TMAPBOX_Y, DF_DIALOG, wall_dialog_handler, wd ); wd->quitButton = ui_add_gadget_button( MainWindow, 20, 252, 48, 40, "Done", NULL ); // These are the checkboxes for each door flag.