]> Pileus Git - ~andy/gtk/blobdiff - tests/testfilechooserbutton.c
Use gtk_box_new() instead gtk_[v|h]box_new()
[~andy/gtk] / tests / testfilechooserbutton.c
index 00215302dc0a26dfdd1809d1cbc40bc824b77a54..3f13bd93c31c1f4b7b8e57f230ba28c4011ac716 100644 (file)
@@ -20,7 +20,7 @@
  * Boston, MA 02111-1307, USA.
  */
 
-#include <config.h>
+#include "config.h"
 
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
@@ -28,7 +28,6 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <unistd.h>
 
 #include <string.h>
 
@@ -50,10 +49,15 @@ static gchar *gtk_src_dir = NULL;
 static void
 win_style_set_cb (GtkWidget *win)
 {
-  gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (win)->vbox), 12);
-  gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (win)->vbox), 24);
-  gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (win)->action_area), 0);
-  gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (win)->action_area), 6);
+  GtkWidget *content_area, *action_area;
+
+  content_area = gtk_dialog_get_content_area (GTK_DIALOG (win));
+  action_area = gtk_dialog_get_action_area (GTK_DIALOG (win));
+
+  gtk_container_set_border_width (GTK_CONTAINER (content_area), 12);
+  gtk_box_set_spacing (GTK_BOX (content_area), 24);
+  gtk_container_set_border_width (GTK_CONTAINER (action_area), 0);
+  gtk_box_set_spacing (GTK_BOX (action_area), 6);
 }
 
 static gboolean
@@ -139,6 +143,13 @@ del_pwds_parent_as_shortcut_clicked_cb (GtkWidget *button,
     }
 }
 
+static void
+unselect_all_clicked_cb (GtkWidget *button,
+                         gpointer   user_data)
+{
+  gtk_file_chooser_unselect_all (user_data);
+}
+
 static void
 tests_button_clicked_cb (GtkButton *real_button,
                         gpointer   user_data)
@@ -158,7 +169,7 @@ tests_button_clicked_cb (GtkButton *real_button,
       gtk_window_set_transient_for (GTK_WINDOW (tests),
                                    GTK_WINDOW (gtk_widget_get_toplevel (user_data)));
 
-      box = gtk_vbox_new (FALSE, 0);
+      box = gtk_box_new (GTK_ORIENTATION_VERTICAL, FALSE, 0);
       gtk_container_add (GTK_CONTAINER (tests), box);
       gtk_widget_show (box);
 
@@ -180,6 +191,12 @@ tests_button_clicked_cb (GtkButton *real_button,
       gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
       gtk_widget_show (button);
 
+      button = gtk_button_new_with_label ("Unselect all");
+      g_signal_connect (button, "clicked",
+                       G_CALLBACK (unselect_all_clicked_cb), user_data);
+      gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
+      gtk_widget_show (button);
+
       g_signal_connect (tests, "delete-event", G_CALLBACK (delete_event_cb), NULL);
       g_object_set_data (user_data, "tests-dialog", tests);
     }
@@ -234,9 +251,12 @@ chooser_update_preview_cb (GtkFileChooser *chooser,
   gchar *filename;
 
   filename = gtk_file_chooser_get_preview_uri (chooser);
-  g_message ("%s::update-preview\n\tPreview Filename: `%s'\nDone.\n",
-            G_OBJECT_TYPE_NAME (chooser), filename);
-  g_free (filename);
+  if (filename != NULL)
+    {
+      g_message ("%s::update-preview\n\tPreview Filename: `%s'\nDone.\n",
+                G_OBJECT_TYPE_NAME (chooser), filename);
+      g_free (filename);
+    }
 }
 
 
@@ -248,7 +268,7 @@ main (int   argc,
   GtkWidget *hbox, *label, *chooser, *button;
   GtkSizeGroup *label_group;
   GOptionContext *context;
-  gchar cwd[2048];
+  gchar *cwd;
 
   context = g_option_context_new ("- test GtkFileChooserButton widget");
   g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
@@ -262,16 +282,17 @@ main (int   argc,
   if (rtl)
     gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
 
-  getcwd (cwd, sizeof (cwd));
+  cwd = g_get_current_dir();
   gtk_src_dir = g_path_get_dirname (cwd);
+  g_free (cwd);
 
-  win = gtk_dialog_new_with_buttons ("TestFileChooserButton", NULL, GTK_DIALOG_NO_SEPARATOR,
+  win = gtk_dialog_new_with_buttons ("TestFileChooserButton", NULL, 0,
                                     GTK_STOCK_QUIT, GTK_RESPONSE_CLOSE, NULL);
   g_signal_connect (win, "style-set", G_CALLBACK (win_style_set_cb), NULL);
   g_signal_connect (win, "response", G_CALLBACK (gtk_main_quit), NULL);
 
-  vbox = gtk_vbox_new (FALSE, 18);
-  gtk_container_add (GTK_CONTAINER (GTK_DIALOG (win)->vbox), vbox);
+  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, FALSE, 18);
+  gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (win))), vbox);
 
   frame = gtk_frame_new ("<b>GtkFileChooserButton</b>");
   gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
@@ -284,11 +305,11 @@ main (int   argc,
   
   label_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
   
-  group_box = gtk_vbox_new (FALSE, 6);
+  group_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, FALSE, 6);
   gtk_container_add (GTK_CONTAINER (alignment), group_box);
 
   /* OPEN */
-  hbox = gtk_hbox_new (FALSE, 12);
+  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, FALSE, 12);
   gtk_box_pack_start (GTK_BOX (group_box), hbox, FALSE, FALSE, 0);
 
   label = gtk_label_new_with_mnemonic ("_Open:");
@@ -296,9 +317,8 @@ main (int   argc,
   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
   gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
 
-  chooser = gtk_file_chooser_button_new_with_backend ("Select A File - testfilechooserbutton",
-                                                     GTK_FILE_CHOOSER_ACTION_OPEN,
-                                                     backend);
+  chooser = gtk_file_chooser_button_new ("Select A File - testfilechooserbutton",
+                                         GTK_FILE_CHOOSER_ACTION_OPEN);
   gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (chooser), gtk_src_dir, NULL);
   gtk_file_chooser_remove_shortcut_folder (GTK_FILE_CHOOSER (chooser), gtk_src_dir, NULL);
   gtk_label_set_mnemonic_widget (GTK_LABEL (label), chooser);
@@ -318,7 +338,7 @@ main (int   argc,
   gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
 
   /* SELECT_FOLDER */
-  hbox = gtk_hbox_new (FALSE, 12);
+  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, FALSE, 12);
   gtk_box_pack_start (GTK_BOX (group_box), hbox, FALSE, FALSE, 0);
 
   label = gtk_label_new_with_mnemonic ("Select _Folder:");
@@ -326,9 +346,8 @@ main (int   argc,
   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
   gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
 
-  chooser = gtk_file_chooser_button_new_with_backend ("Select A Folder - testfilechooserbutton",
-                                                     GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
-                                                     backend);
+  chooser = gtk_file_chooser_button_new ("Select A Folder - testfilechooserbutton",
+                                         GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
   gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (chooser), gtk_src_dir, NULL);
   gtk_file_chooser_remove_shortcut_folder (GTK_FILE_CHOOSER (chooser), gtk_src_dir, NULL);
   gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (chooser), gtk_src_dir, NULL);
@@ -355,7 +374,5 @@ main (int   argc,
 
   gtk_main ();
 
-  gtk_widget_destroy (win);
-
   return 0;
 }