From 657327ccbbeed326cd443222c1f81cfee3f064f9 Mon Sep 17 00:00:00 2001 From: Eduardo Fiss Beloni Date: Wed, 23 Apr 2014 11:59:24 -0300 Subject: [PATCH] Xtt script: command QuestionBox --- xtt/lib/cow/gtk/cow_wow_gtk.cpp | 38 ++++++++++++++++++++++++++++++++++ xtt/lib/cow/gtk/cow_wow_gtk.h | 1 + xtt/lib/cow/src/cow_wow.h | 1 + xtt/lib/xtt/src/xtt_xnav_command.cpp | 31 +++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 0 deletions(-) diff --git a/xtt/lib/cow/gtk/cow_wow_gtk.cpp b/xtt/lib/cow/gtk/cow_wow_gtk.cpp index dbc097e..3ae2dcd 100644 --- a/xtt/lib/cow/gtk/cow_wow_gtk.cpp +++ b/xtt/lib/cow/gtk/cow_wow_gtk.cpp @@ -215,6 +215,44 @@ static gint inputdialog_delete_event( GtkWidget *w, GdkEvent *event, gpointer da return TRUE; } +int CoWowGtk::CreateYesNoDialog( const char *title, const char *text) +{ + GtkWidget *dialog; + GtkWidget *vbox; + GtkWidget *hbox; + GtkWidget *label; + GtkWidget *image; + gint resp; + + dialog = gtk_dialog_new_with_buttons( title, NULL, GTK_DIALOG_MODAL, + GTK_STOCK_YES, GTK_RESPONSE_ACCEPT, + GTK_STOCK_NO, GTK_RESPONSE_REJECT, + NULL); + + label = gtk_label_new( translate_utf8( text)); + + image = (GtkWidget *)g_object_new( GTK_TYPE_IMAGE, + "stock", GTK_STOCK_DIALOG_QUESTION, + "icon-size", GTK_ICON_SIZE_DIALOG, + "xalign", 0.5, + "yalign", 1.0, + NULL); + + hbox = gtk_hbox_new( FALSE, 0); + gtk_box_pack_start( GTK_BOX(hbox), image, FALSE, FALSE, 15); + gtk_box_pack_start( GTK_BOX(hbox), label, TRUE, TRUE, 15); + + vbox = gtk_dialog_get_content_area( GTK_DIALOG(dialog)); + gtk_box_pack_start( GTK_BOX(vbox), hbox, TRUE, TRUE, 30); + gtk_box_pack_start( GTK_BOX(vbox), gtk_hseparator_new(), FALSE, FALSE, 0); + gtk_widget_show_all( dialog); + + resp = gtk_dialog_run( GTK_DIALOG(dialog)); + gtk_widget_destroy( dialog); + + return resp == GTK_RESPONSE_ACCEPT; +} + /************************************************************************ * * Name: CreateInputDialog diff --git a/xtt/lib/cow/gtk/cow_wow_gtk.h b/xtt/lib/cow/gtk/cow_wow_gtk.h index ad0ffd4..5f6e715 100644 --- a/xtt/lib/cow/gtk/cow_wow_gtk.h +++ b/xtt/lib/cow/gtk/cow_wow_gtk.h @@ -128,6 +128,7 @@ class CoWowGtk : public CoWow { void *data); void DisplayError( const char *title, const char *text); void DisplayText( const char *title, const char *text, int width = 0, int height = 0); + int CreateYesNoDialog( const char *title, const char *text); void CreateInputDialog( void *ctx, const char *title, const char *text, void (* inputdialogbox_ok) ( void *, void *, char *), void (* inputdialogbox_cancel) ( void *, void *), diff --git a/xtt/lib/cow/src/cow_wow.h b/xtt/lib/cow/src/cow_wow.h index 0c41926..b4d57fb 100644 --- a/xtt/lib/cow/src/cow_wow.h +++ b/xtt/lib/cow/src/cow_wow.h @@ -118,6 +118,7 @@ class CoWow { void *data) {} virtual void DisplayError( const char *title, const char *text) {} virtual void DisplayText( const char *title, const char *text, int width = 0, int height = 0) {} + virtual int CreateYesNoDialog( const char *title, const char *text) { return 0; }; virtual void CreateInputDialog( void *ctx, const char *title, const char *text, void (* inputdialogbox_ok) ( void *, void *, char *), void (* inputdialogbox_cancel) ( void *, void *), diff --git a/xtt/lib/xtt/src/xtt_xnav_command.cpp b/xtt/lib/xtt/src/xtt_xnav_command.cpp index 9dd4e08..406d185 100644 --- a/xtt/lib/xtt/src/xtt_xnav_command.cpp +++ b/xtt/lib/xtt/src/xtt_xnav_command.cpp @@ -7509,6 +7509,35 @@ static int xnav_messageinfo_func( return 1; } +static int xnav_questionbox_func( + void *filectx, + ccm_sArg *arg_list, + int arg_count, + int *return_decl, + ccm_tFloat *return_float, + ccm_tInt *return_int, + char *return_string) +{ + XNav *xnav; + ccm_sArg *arg_p2; + + if ( arg_count != 2) + return CCM__ARGMISM; + + arg_p2 = arg_list->next; + + if ( arg_list->value_decl != CCM_DECL_STRING) + return CCM__ARGMISM; + if ( arg_p2->value_decl != CCM_DECL_STRING) + return CCM__ARGMISM; + + xnav_get_stored_xnav( &xnav); + *return_int = xnav->wow->CreateYesNoDialog( arg_p2->value_string, arg_list->value_string); + *return_decl = CCM_DECL_INT; + + return 1; +} + static int xnav_cutobjectname_func( void *filectx, ccm_sArg *arg_list, @@ -7678,6 +7707,8 @@ int XNav::readcmdfile( char *incommand) if ( EVEN(sts)) return sts; sts = ccm_register_function( "GetAttribute", xnav_getattribute_func); if ( EVEN(sts)) return sts; + sts = ccm_register_function( "QuestionBox", xnav_questionbox_func); + if ( EVEN(sts)) return sts; ccm_func_registred = 1; } -- 1.7.4.1