]> Pileus Git - ~andy/gtk/blobdiff - tests/testfilechooserbutton.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / tests / testfilechooserbutton.c
index 11d7fea78c6c7fef9c4d07b4e29a166e9187c078..40270110991df5ec704bfd9c923e7b475b5cfbe5 100644 (file)
  * Library General Public License for more details.
  *
  * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <config.h>
+#include "config.h"
 
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 
 #include <gtk/gtk.h>
 
-#ifdef G_OS_WIN32
-#include <direct.h> /* for _getcwd() */
-#endif
-
 #include "prop-editor.h"
 
 static gchar *backend = "gtk+";
@@ -53,10 +47,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
@@ -142,6 +141,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)
@@ -161,7 +167,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, 0);
       gtk_container_add (GTK_CONTAINER (tests), box);
       gtk_widget_show (box);
 
@@ -183,6 +189,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);
     }
@@ -237,9 +249,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);
+    }
 }
 
 
@@ -251,7 +266,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);
@@ -265,16 +280,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, 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);
@@ -287,11 +303,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, 6);
   gtk_container_add (GTK_CONTAINER (alignment), group_box);
 
   /* OPEN */
-  hbox = gtk_hbox_new (FALSE, 12);
+  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
   gtk_box_pack_start (GTK_BOX (group_box), hbox, FALSE, FALSE, 0);
 
   label = gtk_label_new_with_mnemonic ("_Open:");
@@ -299,9 +315,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);
@@ -310,7 +325,7 @@ main (int   argc,
   g_signal_connect (chooser, "selection-changed", G_CALLBACK (chooser_selection_changed_cb), NULL);
   g_signal_connect (chooser, "file-activated", G_CALLBACK (chooser_file_activated_cb), NULL);
   g_signal_connect (chooser, "update-preview", G_CALLBACK (chooser_update_preview_cb), NULL);
-  gtk_container_add (GTK_CONTAINER (hbox), chooser);
+  gtk_box_pack_start (GTK_BOX (hbox), chooser, TRUE, TRUE, 0);
 
   button = gtk_button_new_from_stock (GTK_STOCK_PROPERTIES);
   g_signal_connect (button, "clicked", G_CALLBACK (properties_button_clicked_cb), chooser);
@@ -321,7 +336,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, 12);
   gtk_box_pack_start (GTK_BOX (group_box), hbox, FALSE, FALSE, 0);
 
   label = gtk_label_new_with_mnemonic ("Select _Folder:");
@@ -329,9 +344,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);
@@ -341,7 +355,7 @@ main (int   argc,
   g_signal_connect (chooser, "selection-changed", G_CALLBACK (chooser_selection_changed_cb), NULL);
   g_signal_connect (chooser, "file-activated", G_CALLBACK (chooser_file_activated_cb), NULL);
   g_signal_connect (chooser, "update-preview", G_CALLBACK (chooser_update_preview_cb), NULL);
-  gtk_container_add (GTK_CONTAINER (hbox), chooser);
+  gtk_box_pack_start (GTK_BOX (hbox), chooser, TRUE, TRUE, 0);
 
   button = gtk_button_new_from_stock (GTK_STOCK_PROPERTIES);
   g_signal_connect (button, "clicked", G_CALLBACK (properties_button_clicked_cb), chooser);
@@ -358,7 +372,5 @@ main (int   argc,
 
   gtk_main ();
 
-  gtk_widget_destroy (win);
-
   return 0;
 }