]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkfilechooserdialog.c
Call ::initial_focus() on the child before calling ::map() on our parent
[~andy/gtk] / gtk / gtkfilechooserdialog.c
index 83c8ebe2903d235cd8f8bcb9485a1db5554e5f88..32a9fa9ce3bb9770ae1e57855008f8971a4b1eff 100644 (file)
  */
 
 #include <config.h>
-#include "gtkalias.h"
+#include "gtkfilechooserprivate.h"
 #include "gtkfilechooserdialog.h"
 #include "gtkfilechooserwidget.h"
 #include "gtkfilechooserutils.h"
 #include "gtkfilechooserembed.h"
 #include "gtkfilesystem.h"
 #include "gtktypebuiltins.h"
+#include "gtkintl.h"
+#include "gtkalias.h"
 
 #include <stdarg.h>
 
-struct _GtkFileChooserDialogPrivate
-{
-  GtkWidget *widget;
-  
-  char *file_system;
-
-  /* for use with GtkFileChooserEmbed */
-  gint default_width;
-  gint default_height;
-  gboolean resize_horizontally;
-  gboolean resize_vertically;
-};
-
 #define GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE(o)  (GTK_FILE_CHOOSER_DIALOG (o)->priv)
 
 static void gtk_file_chooser_dialog_class_init (GtkFileChooserDialogClass *class);
@@ -60,6 +49,8 @@ static void     gtk_file_chooser_dialog_get_property (GObject               *obj
                                                      GValue                *value,
                                                      GParamSpec            *pspec);
 
+static void     gtk_file_chooser_dialog_map          (GtkWidget             *widget);
+static void     gtk_file_chooser_dialog_unmap        (GtkWidget             *widget);
 static void     gtk_file_chooser_dialog_style_set    (GtkWidget             *widget,
                                                      GtkStyle              *previous_style);
 
@@ -95,7 +86,7 @@ gtk_file_chooser_dialog_get_type (void)
        NULL                                                        /* interface_data */
       };
 
-      file_chooser_dialog_type = g_type_register_static (GTK_TYPE_DIALOG, "GtkFileChooserDialog",
+      file_chooser_dialog_type = g_type_register_static (GTK_TYPE_DIALOG, I_("GtkFileChooserDialog"),
                                                         &file_chooser_dialog_info, 0);
       g_type_add_interface_static (file_chooser_dialog_type,
                                   GTK_TYPE_FILE_CHOOSER,
@@ -118,6 +109,8 @@ gtk_file_chooser_dialog_class_init (GtkFileChooserDialogClass *class)
   gobject_class->get_property = gtk_file_chooser_dialog_get_property;
   gobject_class->finalize = gtk_file_chooser_dialog_finalize;
 
+  widget_class->map       = gtk_file_chooser_dialog_map;
+  widget_class->unmap     = gtk_file_chooser_dialog_unmap;
   widget_class->style_set = gtk_file_chooser_dialog_style_set;
 
   _gtk_file_chooser_install_properties (gobject_class);
@@ -180,7 +173,7 @@ file_chooser_widget_file_activated (GtkFileChooser       *chooser,
       int response_id;
 
       widget = GTK_WIDGET (l->data);
-      response_id = _gtk_dialog_get_response_for_widget (GTK_DIALOG (dialog), widget);
+      response_id = gtk_dialog_get_response_for_widget (GTK_DIALOG (dialog), widget);
       if (response_id == GTK_RESPONSE_ACCEPT
          || response_id == GTK_RESPONSE_OK
          || response_id == GTK_RESPONSE_YES
@@ -397,8 +390,6 @@ gtk_file_chooser_dialog_constructor (GType                  type,
   _gtk_file_chooser_set_delegate (GTK_FILE_CHOOSER (object),
                                  GTK_FILE_CHOOSER (priv->widget));
 
-  _gtk_file_chooser_embed_initial_focus (GTK_FILE_CHOOSER_EMBED (priv->widget));
-
   gtk_widget_pop_composite_child ();
 
   return object;
@@ -487,6 +478,39 @@ set_default_size (GtkFileChooserDialog *dialog)
 }
 #endif
 
+/* GtkWidget::map handler */
+static void
+gtk_file_chooser_dialog_map (GtkWidget *widget)
+{
+  GtkFileChooserDialog *dialog = GTK_FILE_CHOOSER_DIALOG (widget);
+  GtkFileChooserDialogPrivate *priv = GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE (dialog);
+
+  if (!GTK_WIDGET_MAPPED (priv->widget))
+    gtk_widget_map (priv->widget);
+
+  _gtk_file_chooser_embed_initial_focus (GTK_FILE_CHOOSER_EMBED (priv->widget));
+
+  GTK_WIDGET_CLASS (parent_class)->map (widget);
+}
+
+/* GtkWidget::unmap handler */
+static void
+gtk_file_chooser_dialog_unmap (GtkWidget *widget)
+{
+  GtkFileChooserDialog *dialog = GTK_FILE_CHOOSER_DIALOG (widget);
+  GtkFileChooserDialogPrivate *priv = GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE (dialog);
+
+  GTK_WIDGET_CLASS (parent_class)->unmap (widget);
+
+  /* See bug #145470.  We unmap the GtkFileChooserWidget so that if the dialog
+   * is remapped, the widget will be remapped as well.  Implementations should
+   * refresh their contents when this happens, as some applications keep a
+   * single file chooser alive and map/unmap it as needed, rather than creating
+   * a new file chooser every time they need one.
+   */
+  gtk_widget_unmap (priv->widget);
+}
+
 static void
 gtk_file_chooser_dialog_style_set (GtkWidget *widget,
                                   GtkStyle  *previous_style)
@@ -599,8 +623,8 @@ gtk_file_chooser_dialog_new (const gchar         *title,
  * gtk_file_chooser_dialog_new_with_backend:
  * @title: Title of the dialog, or %NULL
  * @parent: Transient parent of the dialog, or %NULL
- * @backend: The name of the specific filesystem backend to use.
  * @action: Open or save mode for the dialog
+ * @backend: The name of the specific filesystem backend to use.
  * @first_button_text: stock ID or text to go in the first button, or %NULL
  * @Varargs: response ID for the first button, then additional (button, id) pairs, ending with %NULL
  *
@@ -632,3 +656,6 @@ gtk_file_chooser_dialog_new_with_backend (const gchar          *title,
 
   return result;
 }
+
+#define __GTK_FILE_CHOOSER_DIALOG_C__
+#include "gtkaliasdef.c"