X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/23b22b10a8d5ff80bfb7d5b2b1c75c4ceb6383c0..fb8d7eb7a880f1f2e32d8830f9c5e12b2536e05f:/src/gtk/assertdlg_gtk.cpp?ds=sidebyside diff --git a/src/gtk/assertdlg_gtk.cpp b/src/gtk/assertdlg_gtk.cpp index e71571bd75..6f1ef8eb1d 100644 --- a/src/gtk/assertdlg_gtk.cpp +++ b/src/gtk/assertdlg_gtk.cpp @@ -1,5 +1,5 @@ /* /////////////////////////////////////////////////////////////////////////// -// Name: src/gtk/assertdlg_gtk.c +// Name: src/gtk/assertdlg_gtk.cpp // Purpose: GtkAssertDialog // Author: Francesco Montorsi // Id: $Id$ @@ -7,23 +7,16 @@ // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////// */ -#ifdef VMS -#define XCheckIfEvent XCHECKIFEVENT -#endif +#include "wx/wxprec.h" -#include "wx/platform.h" -#include "wx/gtk/assertdlg_gtk.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +#if wxDEBUG_LEVEL #include +#include "wx/gtk/assertdlg_gtk.h" +#include "wx/gtk/private/gtk2-compat.h" -/* For FILE */ #include - /* ---------------------------------------------------------------------------- Constants ---------------------------------------------------------------------------- */ @@ -33,33 +26,25 @@ extern "C" { in gtk_assert_dialog_create_backtrace_list_model() function */ #define STACKFRAME_LEVEL_COLIDX 0 -#define FUNCTION_NAME_COLIDX 1 +#define FUNCTION_PROTOTYPE_COLIDX 1 #define SOURCE_FILE_COLIDX 2 #define LINE_NUMBER_COLIDX 3 -#define FUNCTION_ARGS_COLIDX 4 - - - /* ---------------------------------------------------------------------------- GtkAssertDialog helpers ---------------------------------------------------------------------------- */ +static GtkWidget *gtk_assert_dialog_add_button_to (GtkBox *box, const gchar *label, - const gchar *stock, gint response_id) + const gchar *stock) { /* create the button */ GtkWidget *button = gtk_button_new_with_mnemonic (label); - GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); + gtk_widget_set_can_default(button, true); -#if GTK_CHECK_VERSION(2,6,0) - if (!gtk_check_version (2, 6, 0)) - { - /* add a stock icon inside it */ - GtkWidget *image = gtk_image_new_from_stock (stock, GTK_ICON_SIZE_BUTTON); - gtk_button_set_image (GTK_BUTTON (button), image); - } -#endif + /* add a stock icon inside it */ + GtkWidget *image = gtk_image_new_from_stock (stock, GTK_ICON_SIZE_BUTTON); + gtk_button_set_image (GTK_BUTTON (button), image); /* add to the given (container) widget */ if (box) @@ -68,11 +53,12 @@ GtkWidget *gtk_assert_dialog_add_button_to (GtkBox *box, const gchar *label, return button; } +static GtkWidget *gtk_assert_dialog_add_button (GtkAssertDialog *dlg, const gchar *label, const gchar *stock, gint response_id) { /* create the button */ - GtkWidget *button = gtk_assert_dialog_add_button_to (NULL, label, stock, response_id); + GtkWidget* button = gtk_assert_dialog_add_button_to(NULL, label, stock); /* add the button to the dialog's action area */ gtk_dialog_add_action_widget (GTK_DIALOG (dlg), button, response_id); @@ -80,6 +66,9 @@ GtkWidget *gtk_assert_dialog_add_button (GtkAssertDialog *dlg, const gchar *labe return button; } +#if wxUSE_STACKWALKER + +static void gtk_assert_dialog_append_text_column (GtkWidget *treeview, const gchar *name, int index) { GtkCellRenderer *renderer; @@ -93,18 +82,18 @@ void gtk_assert_dialog_append_text_column (GtkWidget *treeview, const gchar *nam gtk_tree_view_column_set_reorderable (column, TRUE); } +static GtkWidget *gtk_assert_dialog_create_backtrace_list_model () { GtkListStore *store; GtkWidget *treeview; /* create list store */ - store = gtk_list_store_new (5, + store = gtk_list_store_new (4, G_TYPE_UINT, /* stack frame number */ - G_TYPE_STRING, /* function name */ + G_TYPE_STRING, /* function prototype */ G_TYPE_STRING, /* source file name */ - G_TYPE_STRING, /* line number */ - G_TYPE_STRING); /* function arguments */ + G_TYPE_STRING); /* line number */ /* create the tree view */ treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL(store)); @@ -113,18 +102,18 @@ GtkWidget *gtk_assert_dialog_create_backtrace_list_model () /* append columns */ gtk_assert_dialog_append_text_column(treeview, "#", STACKFRAME_LEVEL_COLIDX); - gtk_assert_dialog_append_text_column(treeview, "Function name", FUNCTION_NAME_COLIDX); - gtk_assert_dialog_append_text_column(treeview, "Function args", FUNCTION_ARGS_COLIDX); + gtk_assert_dialog_append_text_column(treeview, "Function Prototype", FUNCTION_PROTOTYPE_COLIDX); gtk_assert_dialog_append_text_column(treeview, "Source file", SOURCE_FILE_COLIDX); gtk_assert_dialog_append_text_column(treeview, "Line #", LINE_NUMBER_COLIDX); return treeview; } +static void gtk_assert_dialog_process_backtrace (GtkAssertDialog *dlg) { /* set busy cursor */ - GdkWindow *parent = GTK_WIDGET(dlg)->window; + GdkWindow *parent = gtk_widget_get_window(GTK_WIDGET(dlg)); GdkCursor *cur = gdk_cursor_new (GDK_WATCH); gdk_window_set_cursor (parent, cur); gdk_flush (); @@ -133,16 +122,19 @@ void gtk_assert_dialog_process_backtrace (GtkAssertDialog *dlg) /* toggle busy cursor */ gdk_window_set_cursor (parent, NULL); +#ifdef __WXGTK3__ + g_object_unref(cur); +#else gdk_cursor_unref (cur); +#endif } - - +extern "C" { /* ---------------------------------------------------------------------------- GtkAssertDialog signal handlers ---------------------------------------------------------------------------- */ -void gtk_assert_dialog_expander_callback (GtkWidget *widget, GtkAssertDialog *dlg) +static void gtk_assert_dialog_expander_callback(GtkWidget*, GtkAssertDialog* dlg) { /* status is not yet updated so we need to invert it to get the new one */ gboolean expanded = !gtk_expander_get_expanded (GTK_EXPANDER(dlg->expander)); @@ -157,7 +149,7 @@ void gtk_assert_dialog_expander_callback (GtkWidget *widget, GtkAssertDialog *dl dlg->callback = NULL; } -void gtk_assert_dialog_save_backtrace_callback (GtkWidget *widget, GtkAssertDialog *dlg) +static void gtk_assert_dialog_save_backtrace_callback(GtkWidget*, GtkAssertDialog* dlg) { GtkWidget *dialog; @@ -195,7 +187,7 @@ void gtk_assert_dialog_save_backtrace_callback (GtkWidget *widget, GtkAssertDial gtk_widget_destroy (dialog); } -void gtk_assert_dialog_copy_callback (GtkWidget *widget, GtkAssertDialog *dlg) +static void gtk_assert_dialog_copy_callback(GtkWidget*, GtkAssertDialog* dlg) { char *msg, *backtrace; GtkClipboard *clipboard; @@ -220,8 +212,12 @@ void gtk_assert_dialog_copy_callback (GtkWidget *widget, GtkAssertDialog *dlg) g_free (backtrace); g_string_free (str, TRUE); } +} // extern "C" + +#endif // wxUSE_STACKWALKER -void gtk_assert_dialog_continue_callback (GtkWidget *widget, GtkAssertDialog *dlg) +extern "C" { +static void gtk_assert_dialog_continue_callback(GtkWidget*, GtkAssertDialog* dlg) { gint response = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(dlg->shownexttime)) ? @@ -229,19 +225,19 @@ void gtk_assert_dialog_continue_callback (GtkWidget *widget, GtkAssertDialog *dl gtk_dialog_response (GTK_DIALOG(dlg), response); } - +} // extern "C" /* ---------------------------------------------------------------------------- GtkAssertDialogClass implementation ---------------------------------------------------------------------------- */ -static void gtk_assert_dialog_init (GtkAssertDialog *self); -static void gtk_assert_dialog_class_init (GtkAssertDialogClass *klass); - +extern "C" { +static void gtk_assert_dialog_init(GTypeInstance* instance, void*); +} -GtkType gtk_assert_dialog_get_type (void) +GType gtk_assert_dialog_get_type() { - static GtkType assert_dialog_type = 0; + static GType assert_dialog_type; if (!assert_dialog_type) { @@ -250,12 +246,12 @@ GtkType gtk_assert_dialog_get_type (void) sizeof (GtkAssertDialogClass), NULL, /* base_init */ NULL, /* base_finalize */ - (GClassInitFunc) gtk_assert_dialog_class_init, + NULL, NULL, /* class_finalize */ NULL, /* class_data */ sizeof (GtkAssertDialog), 16, /* n_preallocs */ - (GInstanceInitFunc) gtk_assert_dialog_init, + gtk_assert_dialog_init, NULL }; assert_dialog_type = g_type_register_static (GTK_TYPE_DIALOG, "GtkAssertDialog", &assert_dialog_info, (GTypeFlags)0); @@ -264,13 +260,10 @@ GtkType gtk_assert_dialog_get_type (void) return assert_dialog_type; } -void gtk_assert_dialog_class_init(GtkAssertDialogClass *klass) -{ - /* no special initializations required */ -} - -void gtk_assert_dialog_init(GtkAssertDialog *dlg) +extern "C" { +static void gtk_assert_dialog_init(GTypeInstance* instance, void*) { + GtkAssertDialog* dlg = GTK_ASSERT_DIALOG(instance); GtkWidget *continuebtn; { @@ -278,13 +271,13 @@ void gtk_assert_dialog_init(GtkAssertDialog *dlg) /* start the main vbox */ gtk_widget_push_composite_child (); - vbox = gtk_vbox_new (FALSE, 8); + vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8); gtk_container_set_border_width (GTK_CONTAINER(vbox), 8); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), vbox, TRUE, TRUE, 5); + gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dlg))), vbox, true, true, 5); /* add the icon+message hbox */ - hbox = gtk_hbox_new (FALSE, 0); + hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0); /* icon */ @@ -295,7 +288,7 @@ void gtk_assert_dialog_init(GtkAssertDialog *dlg) GtkWidget *vbox2, *info; /* message */ - vbox2 = gtk_vbox_new (FALSE, 0); + vbox2 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 0); info = gtk_label_new ("An assertion failed!"); gtk_box_pack_start (GTK_BOX(vbox2), info, TRUE, TRUE, 8); @@ -310,18 +303,20 @@ void gtk_assert_dialog_init(GtkAssertDialog *dlg) gtk_box_pack_end (GTK_BOX(vbox2), GTK_WIDGET(dlg->message), TRUE, TRUE, 8); } +#if wxUSE_STACKWALKER /* add the expander */ dlg->expander = gtk_expander_new_with_mnemonic ("Back_trace:"); gtk_box_pack_start (GTK_BOX(vbox), dlg->expander, TRUE, TRUE, 0); - g_signal_connect (GTK_EXPANDER(dlg->expander), "activate", + g_signal_connect (dlg->expander, "activate", G_CALLBACK(gtk_assert_dialog_expander_callback), dlg); +#endif // wxUSE_STACKWALKER } - +#if wxUSE_STACKWALKER { GtkWidget *hbox, *vbox, *button, *sw; /* create expander's vbox */ - vbox = gtk_vbox_new (FALSE, 0); + vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gtk_container_add (GTK_CONTAINER (dlg->expander), vbox); /* add a scrollable window under the expander */ @@ -337,25 +332,26 @@ void gtk_assert_dialog_init(GtkAssertDialog *dlg) gtk_container_add (GTK_CONTAINER (sw), dlg->treeview); /* create button's hbox */ - hbox = gtk_hbutton_box_new (); + hbox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL); gtk_box_pack_end (GTK_BOX(vbox), hbox, FALSE, FALSE, 0); gtk_button_box_set_layout (GTK_BUTTON_BOX(hbox), GTK_BUTTONBOX_END); /* add the buttons */ button = gtk_assert_dialog_add_button_to (GTK_BOX(hbox), "Save to _file", - GTK_STOCK_SAVE, GTK_RESPONSE_NONE); + GTK_STOCK_SAVE); g_signal_connect (button, "clicked", G_CALLBACK(gtk_assert_dialog_save_backtrace_callback), dlg); button = gtk_assert_dialog_add_button_to (GTK_BOX(hbox), "Copy to clip_board", - GTK_STOCK_COPY, GTK_RESPONSE_NONE); + GTK_STOCK_COPY); g_signal_connect (button, "clicked", G_CALLBACK(gtk_assert_dialog_copy_callback), dlg); } +#endif // wxUSE_STACKWALKER /* add the checkbutton */ dlg->shownexttime = gtk_check_button_new_with_mnemonic("Show this _dialog the next time"); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(dlg->shownexttime), TRUE); - gtk_box_pack_end (GTK_BOX(GTK_DIALOG(dlg)->action_area), dlg->shownexttime, FALSE, TRUE, 8); + gtk_box_pack_end(GTK_BOX(gtk_dialog_get_action_area(GTK_DIALOG(dlg))), dlg->shownexttime, false, true, 8); /* add the stop button */ gtk_assert_dialog_add_button (dlg, "_Stop", GTK_STOCK_QUIT, GTK_ASSERT_DIALOG_STOP); @@ -369,14 +365,13 @@ void gtk_assert_dialog_init(GtkAssertDialog *dlg) dlg->callback = NULL; dlg->userdata = NULL; - /* the resizeable property of this window is modified by the expander: - when it's collapsed, the window must be non-resizeable! */ + /* the resizable property of this window is modified by the expander: + when it's collapsed, the window must be non-resizable! */ gtk_window_set_resizable (GTK_WINDOW (dlg), FALSE); gtk_widget_pop_composite_child (); gtk_widget_show_all (GTK_WIDGET(dlg)); } - - +} /* ---------------------------------------------------------------------------- GtkAssertDialog public API @@ -391,9 +386,11 @@ gchar *gtk_assert_dialog_get_message (GtkAssertDialog *dlg) return g_strdup (gtk_label_get_text (GTK_LABEL(dlg->message))); } +#if wxUSE_STACKWALKER + gchar *gtk_assert_dialog_get_backtrace (GtkAssertDialog *dlg) { - gchar *function, *arguments, *sourcefile, *linenum; + gchar *function, *sourcefile, *linenum; guint count; GtkTreeModel *model; @@ -411,16 +408,15 @@ gchar *gtk_assert_dialog_get_backtrace (GtkAssertDialog *dlg) do { /* append this stack frame's info to the string */ - gtk_tree_model_get (model, &iter, + gtk_tree_model_get(model, &iter, STACKFRAME_LEVEL_COLIDX, &count, - FUNCTION_NAME_COLIDX, &function, - FUNCTION_ARGS_COLIDX, &arguments, + FUNCTION_PROTOTYPE_COLIDX, &function, SOURCE_FILE_COLIDX, &sourcefile, LINE_NUMBER_COLIDX, &linenum, -1); - g_string_append_printf (string, "[%u] %s(%s)", - count, function, arguments); + g_string_append_printf(string, "[%u] %s", + count, function); if (sourcefile[0] != '\0') g_string_append_printf (string, " %s", sourcefile); if (linenum[0] != '\0') @@ -428,7 +424,6 @@ gchar *gtk_assert_dialog_get_backtrace (GtkAssertDialog *dlg) g_string_append (string, "\n"); g_free (function); - g_free (arguments); g_free (sourcefile); g_free (linenum); @@ -438,6 +433,8 @@ gchar *gtk_assert_dialog_get_backtrace (GtkAssertDialog *dlg) return g_string_free (string, FALSE); } +#endif // wxUSE_STACKWALKER + void gtk_assert_dialog_set_message(GtkAssertDialog *dlg, const gchar *msg) { /* prepend and append the tag @@ -453,6 +450,8 @@ void gtk_assert_dialog_set_message(GtkAssertDialog *dlg, const gchar *msg) g_free (escaped_msg); } +#if wxUSE_STACKWALKER + void gtk_assert_dialog_set_backtrace_callback(GtkAssertDialog *assertdlg, GtkAssertDialogStackFrameCallback callback, void *userdata) @@ -463,7 +462,6 @@ void gtk_assert_dialog_set_backtrace_callback(GtkAssertDialog *assertdlg, void gtk_assert_dialog_append_stack_frame(GtkAssertDialog *dlg, const gchar *function, - const gchar *arguments, const gchar *sourcefile, guint line_number) { @@ -486,8 +484,7 @@ void gtk_assert_dialog_append_stack_frame(GtkAssertDialog *dlg, gtk_list_store_append (GTK_LIST_STORE(model), &iter); gtk_list_store_set (GTK_LIST_STORE(model), &iter, STACKFRAME_LEVEL_COLIDX, count+1, /* start from 1 and not from 0 */ - FUNCTION_NAME_COLIDX, function, - FUNCTION_ARGS_COLIDX, arguments, + FUNCTION_PROTOTYPE_COLIDX, function, SOURCE_FILE_COLIDX, sourcefile, LINE_NUMBER_COLIDX, linenum->str, -1); @@ -495,13 +492,13 @@ void gtk_assert_dialog_append_stack_frame(GtkAssertDialog *dlg, g_string_free (linenum, TRUE); } +#endif // wxUSE_STACKWALKER + GtkWidget *gtk_assert_dialog_new(void) { - GtkAssertDialog *dialog = g_object_new (GTK_TYPE_ASSERT_DIALOG, NULL); + void* dialog = g_object_new(GTK_TYPE_ASSERT_DIALOG, NULL); return GTK_WIDGET (dialog); } -#ifdef __cplusplus -} -#endif /* __cplusplus */ +#endif // wxDEBUG_LEVEL