]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkdialog.c
Add GtkScrollable interface
[~andy/gtk] / gtk / gtkdialog.c
index 7cce1d4416a93c246b92b1d3fd8b1555ee56e13c..86e28e320d3d37fedab7b504743a3550d1812d93 100644 (file)
@@ -31,7 +31,6 @@
 #include "gtkdialog.h"
 #include "gtkhbbox.h"
 #include "gtklabel.h"
-#include "gtkhseparator.h"
 #include "gtkmarshalers.h"
 #include "gtkvbox.h"
 #include "gdkkeysyms.h"
 #include "gtkbuildable.h"
 
 
-struct _GtkDialogPriv
+struct _GtkDialogPrivate
 {
   GtkWidget *vbox;
   GtkWidget *action_area;
-
-  GtkWidget *separator;
-
-  guint ignore_separator : 1;
 };
 
 typedef struct _ResponseData ResponseData;
@@ -66,15 +61,6 @@ static void      gtk_dialog_add_buttons_valist   (GtkDialog    *dialog,
 static gboolean  gtk_dialog_delete_event_handler (GtkWidget    *widget,
                                                   GdkEventAny  *event,
                                                   gpointer      user_data);
-
-static void      gtk_dialog_set_property         (GObject      *object,
-                                                  guint         prop_id,
-                                                  const GValue *value,
-                                                  GParamSpec   *pspec);
-static void      gtk_dialog_get_property         (GObject      *object,
-                                                  guint         prop_id,
-                                                  GValue       *value,
-                                                  GParamSpec   *pspec);
 static void      gtk_dialog_style_set            (GtkWidget    *widget,
                                                   GtkStyle     *prev_style);
 static void      gtk_dialog_map                  (GtkWidget    *widget);
@@ -124,32 +110,16 @@ gtk_dialog_class_init (GtkDialogClass *class)
   GObjectClass *gobject_class;
   GtkWidgetClass *widget_class;
   GtkBindingSet *binding_set;
-  
+
   gobject_class = G_OBJECT_CLASS (class);
   widget_class = GTK_WIDGET_CLASS (class);
-  
-  gobject_class->set_property = gtk_dialog_set_property;
-  gobject_class->get_property = gtk_dialog_get_property;
-  
+
   widget_class->map = gtk_dialog_map;
   widget_class->style_set = gtk_dialog_style_set;
 
   class->close = gtk_dialog_close;
-  
-  g_type_class_add_private (gobject_class, sizeof (GtkDialogPriv));
 
-  /**
-   * GtkDialog:has-separator:
-   *
-   * When %TRUE, the dialog has a separator bar above its buttons.
-   */
-  g_object_class_install_property (gobject_class,
-                                   PROP_HAS_SEPARATOR,
-                                   g_param_spec_boolean ("has-separator",
-                                                        P_("Has separator"),
-                                                        P_("The dialog has a separator bar above its buttons"),
-                                                         TRUE,
-                                                         GTK_PARAM_READWRITE));
+  g_type_class_add_private (gobject_class, sizeof (GtkDialogPrivate));
 
   /**
    * GtkDialog::response:
@@ -236,13 +206,13 @@ gtk_dialog_class_init (GtkDialogClass *class)
 
   binding_set = gtk_binding_set_by_class (class);
   
-  gtk_binding_entry_add_signal (binding_set, GDK_Escape, 0, "close", 0);
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0, "close", 0);
 }
 
 static void
 update_spacings (GtkDialog *dialog)
 {
-  GtkDialogPriv *priv = dialog->priv;
+  GtkDialogPrivate *priv = dialog->priv;
   gint content_area_border;
   gint content_area_spacing;
   gint button_spacing;
@@ -271,15 +241,13 @@ update_spacings (GtkDialog *dialog)
 static void
 gtk_dialog_init (GtkDialog *dialog)
 {
-  GtkDialogPriv *priv;
+  GtkDialogPrivate *priv;
 
   dialog->priv = G_TYPE_INSTANCE_GET_PRIVATE (dialog,
                                               GTK_TYPE_DIALOG,
-                                              GtkDialogPriv);
+                                              GtkDialogPrivate);
   priv = dialog->priv;
 
-  priv->ignore_separator = FALSE;
-
   /* To avoid breaking old code that prevents destroy on delete event
    * by connecting a handler, we have to have the FIRST signal
    * connection on the dialog.
@@ -303,10 +271,6 @@ gtk_dialog_init (GtkDialog *dialog)
                     FALSE, TRUE, 0);
   gtk_widget_show (priv->action_area);
 
-  priv->separator = gtk_hseparator_new ();
-  gtk_box_pack_end (GTK_BOX (priv->vbox), priv->separator, FALSE, TRUE, 0);
-  gtk_widget_show (priv->separator);
-
   gtk_window_set_type_hint (GTK_WINDOW (dialog),
                            GDK_WINDOW_TYPE_HINT_DIALOG);
   gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER_ON_PARENT);
@@ -328,7 +292,7 @@ gtk_dialog_buildable_get_internal_child (GtkBuildable *buildable,
                                         GtkBuilder   *builder,
                                         const gchar  *childname)
 {
-  GtkDialogPriv *priv = GTK_DIALOG (buildable)->priv;
+  GtkDialogPrivate *priv = GTK_DIALOG (buildable)->priv;
 
   if (strcmp (childname, "vbox") == 0)
     return G_OBJECT (priv->vbox);
@@ -340,49 +304,6 @@ gtk_dialog_buildable_get_internal_child (GtkBuildable *buildable,
                                                      childname);
 }
 
-static void 
-gtk_dialog_set_property (GObject      *object,
-                         guint         prop_id,
-                         const GValue *value,
-                         GParamSpec   *pspec)
-{
-  GtkDialog *dialog;
-  
-  dialog = GTK_DIALOG (object);
-  
-  switch (prop_id)
-    {
-    case PROP_HAS_SEPARATOR:
-      gtk_dialog_set_has_separator (dialog, g_value_get_boolean (value));
-      break;
-
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-      break;
-    }
-}
-
-static void 
-gtk_dialog_get_property (GObject     *object,
-                         guint        prop_id,
-                         GValue      *value,
-                         GParamSpec  *pspec)
-{
-  GtkDialog *dialog = GTK_DIALOG (object);
-  GtkDialogPriv *priv = dialog->priv;
-  
-  switch (prop_id)
-    {
-    case PROP_HAS_SEPARATOR:
-      g_value_set_boolean (value, priv->separator != NULL);
-      break;
-
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-      break;
-    }
-}
-
 static gboolean
 gtk_dialog_delete_event_handler (GtkWidget   *widget,
                                  GdkEventAny *event,
@@ -407,44 +328,50 @@ gtk_dialog_delete_event_handler (GtkWidget   *widget,
 static void
 gtk_dialog_map (GtkWidget *widget)
 {
+  GtkWidget *default_widget, *focus;
   GtkWindow *window = GTK_WINDOW (widget);
   GtkDialog *dialog = GTK_DIALOG (widget);
-  GtkDialogPriv *priv = dialog->priv;
+  GtkDialogPrivate *priv = dialog->priv;
   
   GTK_WIDGET_CLASS (gtk_dialog_parent_class)->map (widget);
 
-  if (!window->focus_widget)
+  focus = gtk_window_get_focus (window);
+  if (!focus)
     {
       GList *children, *tmp_list;
       GtkWidget *first_focus = NULL;
-      
-      do 
-       {
-         g_signal_emit_by_name (window, "move_focus", GTK_DIR_TAB_FORWARD);
 
-         if (first_focus == NULL)
-           first_focus = window->focus_widget;
-         else if (first_focus == window->focus_widget)
+      do
+        {
+          g_signal_emit_by_name (window, "move_focus", GTK_DIR_TAB_FORWARD);
+
+          focus = gtk_window_get_focus (window);
+          if (GTK_IS_LABEL (focus) &&
+              !gtk_label_get_current_uri (GTK_LABEL (focus)))
+            gtk_label_select_region (GTK_LABEL (focus), 0, 0);
+
+          if (first_focus == NULL)
+            first_focus = focus;
+          else if (first_focus == focus)
             break;
-         if (!GTK_IS_LABEL (window->focus_widget))
-           break;
-          if (!gtk_label_get_current_uri (GTK_LABEL (window->focus_widget)))
-            gtk_label_select_region (GTK_LABEL (window->focus_widget), 0, 0);
-       }
+
+          if (!GTK_IS_LABEL (focus))
+            break;
+        }
       while (TRUE);
 
       tmp_list = children = gtk_container_get_children (GTK_CONTAINER (priv->action_area));
-      
+
       while (tmp_list)
        {
          GtkWidget *child = tmp_list->data;
-         
-         if ((window->focus_widget == NULL || 
-              child == window->focus_widget) && 
-             child != window->default_widget &&
-             window->default_widget)
+
+          default_widget = gtk_window_get_default_widget (window);
+         if ((focus == NULL || child == focus) &&
+             child != default_widget &&
+             default_widget)
            {
-             gtk_widget_grab_focus (window->default_widget);
+             gtk_widget_grab_focus (default_widget);
              break;
            }
          
@@ -466,7 +393,7 @@ static GtkWidget *
 dialog_find_button (GtkDialog *dialog,
                    gint       response_id)
 {
-  GtkDialogPriv *priv = dialog->priv;
+  GtkDialogPrivate *priv = dialog->priv;
   GtkWidget *child = NULL;
   GList *children, *tmp_list;
       
@@ -497,8 +424,8 @@ gtk_dialog_close (GtkDialog *dialog)
   GdkEvent *event;
 
   event = gdk_event_new (GDK_DELETE);
-  
-  event->any.window = g_object_ref (widget->window);
+
+  event->any.window = g_object_ref (gtk_widget_get_window (widget));
   event->any.send_event = TRUE;
   
   gtk_main_do_event (event);
@@ -528,13 +455,10 @@ gtk_dialog_new_empty (const gchar     *title,
 
   if (flags & GTK_DIALOG_MODAL)
     gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
-  
+
   if (flags & GTK_DIALOG_DESTROY_WITH_PARENT)
     gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
 
-  if (flags & GTK_DIALOG_NO_SEPARATOR)
-    gtk_dialog_set_has_separator (dialog, FALSE);
-  
   return GTK_WIDGET (dialog);
 }
 
@@ -656,7 +580,7 @@ gtk_dialog_add_action_widget (GtkDialog *dialog,
                               GtkWidget *child,
                               gint       response_id)
 {
-  GtkDialogPriv *priv;
+  GtkDialogPrivate *priv;
   ResponseData *ad;
   guint signal_id;
   
@@ -709,7 +633,7 @@ gtk_dialog_add_action_widget (GtkDialog *dialog,
  * appended to the end of the dialog's action area. The button widget is 
  * returned, but usually you don't need it.
  *
- * Return value: the button widget that was added
+ * Return value: (transfer full): the button widget that was added
  **/
 GtkWidget*
 gtk_dialog_add_button (GtkDialog   *dialog,
@@ -803,7 +727,7 @@ gtk_dialog_set_response_sensitive (GtkDialog *dialog,
                                    gint       response_id,
                                    gboolean   setting)
 {
-  GtkDialogPriv *priv;
+  GtkDialogPrivate *priv;
   GList *children;
   GList *tmp_list;
 
@@ -841,7 +765,7 @@ void
 gtk_dialog_set_default_response (GtkDialog *dialog,
                                  gint       response_id)
 {
-  GtkDialogPriv *priv;
+  GtkDialogPrivate *priv;
   GList *children;
   GList *tmp_list;
 
@@ -866,69 +790,6 @@ gtk_dialog_set_default_response (GtkDialog *dialog,
   g_list_free (children);
 }
 
-/**
- * gtk_dialog_set_has_separator:
- * @dialog: a #GtkDialog
- * @setting: %TRUE to have a separator
- *
- * Sets whether the dialog has a separator above the buttons.
- * %TRUE by default.
- **/
-void
-gtk_dialog_set_has_separator (GtkDialog *dialog,
-                              gboolean   setting)
-{
-  GtkDialogPriv *priv;
-
-  g_return_if_fail (GTK_IS_DIALOG (dialog));
-
-  priv = dialog->priv;
-
-  /* this might fail if we get called before _init() somehow */
-  g_assert (priv->vbox != NULL);
-
-  if (priv->ignore_separator)
-    {
-      g_warning ("Ignoring the separator setting");
-      return;
-    }
-  
-  if (setting && priv->separator == NULL)
-    {
-      priv->separator = gtk_hseparator_new ();
-      gtk_box_pack_end (GTK_BOX (priv->vbox), priv->separator, FALSE, TRUE, 0);
-
-      /* The app programmer could screw this up, but, their own fault.
-       * Moves the separator just above the action area.
-       */
-      gtk_box_reorder_child (GTK_BOX (priv->vbox), priv->separator, 1);
-      gtk_widget_show (priv->separator);
-    }
-  else if (!setting && priv->separator != NULL)
-    {
-      gtk_widget_destroy (priv->separator);
-      priv->separator = NULL;
-    }
-
-  g_object_notify (G_OBJECT (dialog), "has-separator");
-}
-
-/**
- * gtk_dialog_get_has_separator:
- * @dialog: a #GtkDialog
- * 
- * Accessor for whether the dialog has a separator.
- * 
- * Return value: %TRUE if the dialog has a separator
- **/
-gboolean
-gtk_dialog_get_has_separator (GtkDialog *dialog)
-{
-  g_return_val_if_fail (GTK_IS_DIALOG (dialog), FALSE);
-
-  return dialog->priv->separator != NULL;
-}
-
 /**
  * gtk_dialog_response:
  * @dialog: a #GtkDialog
@@ -1073,7 +934,7 @@ gtk_dialog_run (GtkDialog *dialog)
 
   g_object_ref (dialog);
 
-  was_modal = GTK_WINDOW (dialog)->modal;
+  was_modal = gtk_window_get_modal (GTK_WINDOW (dialog));
   if (!was_modal)
     gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
 
@@ -1130,15 +991,6 @@ gtk_dialog_run (GtkDialog *dialog)
   return ri.response_id;
 }
 
-void
-_gtk_dialog_set_ignore_separator (GtkDialog *dialog,
-                                 gboolean   ignore_separator)
-{
-  GtkDialogPriv *priv = dialog->priv;
-
-  priv->ignore_separator = ignore_separator;
-}
-
 /**
  * gtk_dialog_get_widget_for_response:
  * @dialog: a #GtkDialog
@@ -1147,7 +999,7 @@ _gtk_dialog_set_ignore_separator (GtkDialog *dialog,
  * Gets the widget button that uses the given response ID in the action area
  * of a dialog.
  *
- * Returns: the @widget button that uses the given @response_id, or %NULL.
+ * Returns: (transfer none):the @widget button that uses the given @response_id, or %NULL.
  *
  * Since: 2.20
  */
@@ -1155,7 +1007,7 @@ GtkWidget*
 gtk_dialog_get_widget_for_response (GtkDialog *dialog,
                                    gint       response_id)
 {
-  GtkDialogPriv *priv;
+  GtkDialogPrivate *priv;
   GList *children;
   GList *tmp_list;
 
@@ -1251,7 +1103,7 @@ gtk_dialog_set_alternative_button_order_valist (GtkDialog *dialog,
                                                gint       first_response_id,
                                                va_list    args)
 {
-  GtkDialogPriv *priv = dialog->priv;
+  GtkDialogPrivate *priv = dialog->priv;
   GtkWidget *child;
   gint response_id;
   gint position;
@@ -1356,7 +1208,7 @@ gtk_dialog_set_alternative_button_order_from_array (GtkDialog *dialog,
                                                     gint       n_params,
                                                     gint      *new_order)
 {
-  GtkDialogPriv *priv = dialog->priv;
+  GtkDialogPrivate *priv = dialog->priv;
   GdkScreen *screen;
   GtkWidget *child;
   gint position;
@@ -1474,7 +1326,7 @@ gtk_dialog_buildable_custom_finished (GtkBuildable *buildable,
                                      gpointer      user_data)
 {
   GtkDialog *dialog = GTK_DIALOG (buildable);
-  GtkDialogPriv *priv = dialog->priv;
+  GtkDialogPrivate *priv = dialog->priv;
   GSList *l;
   ActionWidgetsSubParserData *parser_data;
   GObject *object;