]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/assertdlg_gtk.c
Updating with Vadim's API changes.
[wxWidgets.git] / src / gtk / assertdlg_gtk.c
index b5a877aab2eee628cb6cfb57261712fe62280cfe..a51e832ebb852fcc77f759a5112ee03048a770d7 100644 (file)
@@ -20,6 +20,9 @@ extern "C" {
 
 #include <gtk/gtk.h>
 
+/* For FILE */
+#include <stdio.h>
+
 
 #if GTK_CHECK_VERSION(2,4,0)
 #include <gtk/gtkexpander.h>
@@ -68,14 +71,16 @@ GtkWidget *gtk_assert_dialog_add_button_to (GtkBox *box, const gchar *label,
     return button;
 }
 
-void gtk_assert_dialog_add_button (GtkAssertDialog *dlg, const gchar *label,
-                                   const gchar *stock, gint response_id)
+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);
 
     /* add the button to the dialog's action area */
     gtk_dialog_add_action_widget (GTK_DIALOG (dlg), button, response_id);
+
+    return button;
 }
 
 void gtk_assert_dialog_append_text_column (GtkWidget *treeview, const gchar *name, int index)
@@ -101,7 +106,7 @@ GtkWidget *gtk_assert_dialog_create_backtrace_list_model ()
                                 G_TYPE_UINT,        // stack frame number
                                 G_TYPE_STRING,      // function name
                                 G_TYPE_STRING,      // source file name
-                                G_TYPE_UINT,        // line number
+                                G_TYPE_STRING,      // line number
                                 G_TYPE_STRING);     // function arguments
 
     /* create the tree view */
@@ -219,6 +224,15 @@ void gtk_assert_dialog_copy_callback (GtkWidget *widget, GtkAssertDialog *dlg)
     g_string_free (str, TRUE);
 }
 
+void gtk_assert_dialog_continue_callback (GtkWidget *widget, GtkAssertDialog *dlg)
+{
+    gint response =
+        gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(dlg->shownexttime)) ?
+            GTK_ASSERT_DIALOG_CONTINUE : GTK_ASSERT_DIALOG_CONTINUE_SUPPRESSING;
+
+    gtk_dialog_response (GTK_DIALOG(dlg), response);
+}
+
 
 /* ----------------------------------------------------------------------------
    GtkAssertDialogClass implementation
@@ -231,7 +245,7 @@ static void     gtk_assert_dialog_class_init        (GtkAssertDialogClass *klass
 GtkType gtk_assert_dialog_get_type (void)
 {
     static GtkType assert_dialog_type = 0;
-    
+
     if (!assert_dialog_type)
     {
         static const GTypeInfo assert_dialog_info =
@@ -260,7 +274,7 @@ void gtk_assert_dialog_class_init(GtkAssertDialogClass *klass)
 
 void gtk_assert_dialog_init(GtkAssertDialog *dlg)
 {
-    GtkWidget *vbox, *hbox, *image;
+    GtkWidget *vbox, *hbox, *image, *continuebtn;
 
     /* start the main vbox */
     gtk_widget_push_composite_child ();
@@ -354,13 +368,19 @@ void gtk_assert_dialog_init(GtkAssertDialog *dlg)
         g_signal_connect (button, "clicked", G_CALLBACK(gtk_assert_dialog_copy_callback), dlg);
     }
 
-    /* add the buttons */
+    /* 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);
+
+    /* add the stop button */
     gtk_assert_dialog_add_button (dlg, "_Stop", GTK_STOCK_QUIT, GTK_ASSERT_DIALOG_STOP);
-    gtk_assert_dialog_add_button (dlg, "_Continue", GTK_STOCK_YES, GTK_ASSERT_DIALOG_CONTINUE);
-    gtk_assert_dialog_add_button (dlg, "Continue su_ppressing", GTK_STOCK_OK,
-                                  GTK_ASSERT_DIALOG_CONTINUE_SUPPRESSING);
     gtk_dialog_set_default_response (GTK_DIALOG (dlg), GTK_ASSERT_DIALOG_STOP);
 
+    /* add the continue button */
+    continuebtn = gtk_assert_dialog_add_button (dlg, "_Continue", GTK_STOCK_YES, GTK_ASSERT_DIALOG_CONTINUE);
+    g_signal_connect (continuebtn, "clicked", G_CALLBACK(gtk_assert_dialog_continue_callback), dlg);
+
     /* complete creation */
     dlg->callback = NULL;
     dlg->userdata = NULL;
@@ -389,8 +409,8 @@ gchar *gtk_assert_dialog_get_message (GtkAssertDialog *dlg)
 
 gchar *gtk_assert_dialog_get_backtrace (GtkAssertDialog *dlg)
 {
-    gchar *function, *arguments, *sourcefile;
-    guint count, linenum;
+    gchar *function, *arguments, *sourcefile, *linenum;
+    guint count;
 
     GtkTreeModel *model;
     GtkTreeIter iter;
@@ -415,17 +435,18 @@ gchar *gtk_assert_dialog_get_backtrace (GtkAssertDialog *dlg)
                             LINE_NUMBER_COLIDX, &linenum,
                             -1);
 
+        g_string_append_printf (string, "[%d] %s(%s)",
+                                count, function, arguments);
         if (sourcefile[0] != '\0')
-            g_string_append_printf (string, "[%d] %s(%s) %s:%d\n",
-                                    count, function, arguments,
-                                    sourcefile, linenum);
-        else
-            g_string_append_printf (string, "[%d] %s(%s)\n",
-                                    count, function, arguments);
+            g_string_append_printf (string, " %s", sourcefile);
+        if (linenum[0] != '\0')
+            g_string_append_printf (string, ":%s", linenum);
+        g_string_append (string, "\n");
 
         g_free (function);
         g_free (arguments);
         g_free (sourcefile);
+        g_free (linenum);
 
     } while (gtk_tree_model_iter_next (model, &iter));
 
@@ -435,13 +456,17 @@ gchar *gtk_assert_dialog_get_backtrace (GtkAssertDialog *dlg)
 
 void gtk_assert_dialog_set_message(GtkAssertDialog *dlg, const gchar *msg)
 {
-    /* prepend and append the <b> tag */
-    gchar *decorated_msg = g_strdup_printf("<b>%s</b>", msg);
+    /* prepend and append the <b> tag
+       NOTE: g_markup_printf_escaped() is not used because it's available
+             only for glib >= 2.4 */
+    gchar *escaped_msg = g_markup_escape_text (msg, -1);
+    gchar *decorated_msg = g_strdup_printf ("<b>%s</b>", escaped_msg);
 
     g_return_if_fail (GTK_IS_ASSERT_DIALOG (dlg));
     gtk_label_set_markup (GTK_LABEL(dlg->message), decorated_msg);
 
     g_free (decorated_msg);
+    g_free (escaped_msg);
 }
 
 void gtk_assert_dialog_set_backtrace_callback(GtkAssertDialog *assertdlg,
@@ -467,6 +492,7 @@ void gtk_assert_dialog_append_stack_frame(GtkAssertDialog *dlg,
 {
     GtkTreeModel *model;
     GtkTreeIter iter;
+    GString *linenum;
     gint count;
 
     g_return_if_fail (GTK_IS_ASSERT_DIALOG (dlg));
@@ -475,6 +501,10 @@ void gtk_assert_dialog_append_stack_frame(GtkAssertDialog *dlg,
     /* how many items are in the list up to now ? */
     count = gtk_tree_model_iter_n_children (model, NULL);
 
+    linenum = g_string_new("");
+    if ( line_number != 0 )
+        g_string_printf (linenum, "%d", line_number);
+
     /* add data to the list store */
     gtk_list_store_append (GTK_LIST_STORE(model), &iter);
     gtk_list_store_set (GTK_LIST_STORE(model), &iter,
@@ -482,8 +512,10 @@ void gtk_assert_dialog_append_stack_frame(GtkAssertDialog *dlg,
                         FUNCTION_NAME_COLIDX, function,
                         FUNCTION_ARGS_COLIDX, arguments,
                         SOURCE_FILE_COLIDX, sourcefile,
-                        LINE_NUMBER_COLIDX, line_number,
+                        LINE_NUMBER_COLIDX, linenum->str,
                         -1);
+
+    g_string_free (linenum, TRUE);
 }
 
 GtkWidget *gtk_assert_dialog_new(void)