]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkdialog.c
filechooser: Rename _gtk_file_is_path_not_local() to _gtk_file_has_native_path()
[~andy/gtk] / gtk / gtkdialog.c
index b765b72aff84c5ad04cdbbcd88a9c2a01698a090..b88ca5f5ba5d637f51e1ade6beafebf6d0a07540 100644 (file)
@@ -12,9 +12,7 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser 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/>.
  */
 
 /*
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
  */
 
+#include "config.h"
+
 #include <stdlib.h>
 #include <string.h>
-#include "config.h"
+
 #include "gtkbutton.h"
 #include "gtkdialog.h"
-#include "gtkhbbox.h"
+#include "gtkbbox.h"
 #include "gtklabel.h"
 #include "gtkmarshalers.h"
-#include "gtkvbox.h"
-#include "gdkkeysyms.h"
+#include "gtkbox.h"
+#include "gtkboxprivate.h"
 #include "gtkmain.h"
 #include "gtkintl.h"
 #include "gtkbindings.h"
 #include "gtkprivate.h"
 #include "gtkbuildable.h"
+#include "gtksettings.h"
 
+/**
+ * SECTION:gtkdialog
+ * @Short_description: Create popup windows
+ * @Title: GtkDialog
+ * @See_also: #GtkVBox, #GtkWindow, #GtkButton
+ *
+ * Dialog boxes are a convenient way to prompt the user for a small amount
+ * of input, e.g. to display a message, ask a question, or anything else
+ * that does not require extensive effort on the user's part.
+ *
+ * GTK+ treats a dialog as a window split vertically. The top section is a
+ * #GtkVBox, and is where widgets such as a #GtkLabel or a #GtkEntry should
+ * be packed. The bottom area is known as the
+ * <structfield>action_area</structfield>. This is generally used for
+ * packing buttons into the dialog which may perform functions such as
+ * cancel, ok, or apply.
+ *
+ * #GtkDialog boxes are created with a call to gtk_dialog_new() or
+ * gtk_dialog_new_with_buttons(). gtk_dialog_new_with_buttons() is
+ * recommended; it allows you to set the dialog title, some convenient flags,
+ * and add simple buttons.
+ *
+ * If 'dialog' is a newly created dialog, the two primary areas of the
+ * window can be accessed through gtk_dialog_get_content_area() and
+ * gtk_dialog_get_action_area(), as can be seen from the example below.
+ *
+ * A 'modal' dialog (that is, one which freezes the rest of the application
+ * from user input), can be created by calling gtk_window_set_modal() on the
+ * dialog. Use the GTK_WINDOW() macro to cast the widget returned from
+ * gtk_dialog_new() into a #GtkWindow. When using gtk_dialog_new_with_buttons()
+ * you can also pass the #GTK_DIALOG_MODAL flag to make a dialog modal.
+ *
+ * If you add buttons to #GtkDialog using gtk_dialog_new_with_buttons(),
+ * gtk_dialog_add_button(), gtk_dialog_add_buttons(), or
+ * gtk_dialog_add_action_widget(), clicking the button will emit a signal
+ * called #GtkDialog::response with a response ID that you specified. GTK+
+ * will never assign a meaning to positive response IDs; these are entirely
+ * user-defined. But for convenience, you can use the response IDs in the
+ * #GtkResponseType enumeration (these all have values less than zero). If
+ * a dialog receives a delete event, the #GtkDialog::response signal will
+ * be emitted with a response ID of #GTK_RESPONSE_DELETE_EVENT.
+ *
+ * If you want to block waiting for a dialog to return before returning
+ * control flow to your code, you can call gtk_dialog_run(). This function
+ * enters a recursive main loop and waits for the user to respond to the
+ * dialog, returning the response ID corresponding to the button the user
+ * clicked.
+ *
+ * For the simple dialog in the following example, in reality you'd probably
+ * use #GtkMessageDialog to save yourself some effort. But you'd need to
+ * create the dialog contents manually if you had more than a simple message
+ * in the dialog.
+ * <example>
+ * <title>Simple GtkDialog usage</title>
+ * <programlisting>
+ * /&ast; Function to open a dialog box displaying the message provided. &ast;/
+ * void
+ * quick_message (gchar *message)
+ * {
+ *    GtkWidget *dialog, *label, *content_area;
+ *
+ *    /&ast; Create the widgets &ast;/
+ *    dialog = gtk_dialog_new_with_buttons ("Message",
+ *                                          main_application_window,
+ *                                          GTK_DIALOG_DESTROY_WITH_PARENT,
+ *                                          GTK_STOCK_OK,
+ *                                          GTK_RESPONSE_NONE,
+ *                                          NULL);
+ *    content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+ *    label = gtk_label_new (message);
+ *
+ *    /&ast; Ensure that the dialog box is destroyed when the user responds &ast;/
+ *    g_signal_connect_swapped (dialog,
+ *                              "response",
+ *                              G_CALLBACK (gtk_widget_destroy),
+ *                              dialog);
+ *
+ *    /&ast; Add the label, and show everything we've added to the dialog &ast;/
+ *
+ *    gtk_container_add (GTK_CONTAINER (content_area), label);
+ *    gtk_widget_show_all (dialog);
+ * }
+ * </programlisting>
+ * </example>
+ *
+ * <refsect2 id="GtkDialog-BUILDER-UI"><title>GtkDialog as GtkBuildable</title>
+ * <para>
+ * The GtkDialog implementation of the #GtkBuildable interface exposes the
+ * @vbox and @action_area as internal children with the names "vbox" and
+ * "action_area".
+ * </para>
+ * <para>
+ * GtkDialog supports a custom &lt;action-widgets&gt; element, which
+ * can contain multiple &lt;action-widget&gt; elements. The "response"
+ * attribute specifies a numeric response, and the content of the element
+ * is the id of widget (which should be a child of the dialogs @action_area).
+ * </para>
+ * <example>
+ * <title>A <structname>GtkDialog</structname> UI definition fragment.</title>
+ * <programlisting><![CDATA[
+ * <object class="GtkDialog" id="dialog1">
+ *   <child internal-child="vbox">"
+ *     <object class="GtkVBox" id="vbox">
+ *       <child internal-child="action_area">
+ *         <object class="GtkHButtonBox" id="button_box">
+ *           <child>
+ *             <object class="GtkButton" id="button_cancel"/>
+ *           </child>
+ *           <child>
+ *             <object class="GtkButton" id="button_ok"/>
+ *           </child>
+ *         </object>
+ *       </child>
+ *     </object>
+ *   </child>
+ *   <action-widgets>
+ *     <action-widget response="3">button_ok</action-widget>
+ *     <action-widget response="-5">button_cancel</action-widget>
+ *   </action-widgets>
+ * </object>
+ * ]]></programlisting>
+ * </example>
+ * </refsect2>
+ */
 
 struct _GtkDialogPrivate
 {
@@ -61,8 +186,7 @@ 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_style_set            (GtkWidget    *widget,
-                                                  GtkStyle     *prev_style);
+static void      gtk_dialog_style_updated        (GtkWidget    *widget);
 static void      gtk_dialog_map                  (GtkWidget    *widget);
 
 static void      gtk_dialog_close                (GtkDialog    *dialog);
@@ -115,7 +239,9 @@ gtk_dialog_class_init (GtkDialogClass *class)
   widget_class = GTK_WIDGET_CLASS (class);
 
   widget_class->map = gtk_dialog_map;
-  widget_class->style_set = gtk_dialog_style_set;
+  widget_class->style_updated = gtk_dialog_style_updated;
+
+  gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_DIALOG);
 
   class->close = gtk_dialog_close;
 
@@ -225,6 +351,7 @@ update_spacings (GtkDialog *dialog)
                         "action-area-border", &action_area_border,
                         NULL);
 
+  
   gtk_container_set_border_width (GTK_CONTAINER (priv->vbox),
                                   content_area_border);
   if (!_gtk_box_get_spacing_set (GTK_BOX (priv->vbox)))
@@ -273,6 +400,8 @@ gtk_dialog_init (GtkDialog *dialog)
   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);
+
+  update_spacings (dialog);
 }
 
 static GtkBuildableIface *parent_buildable_iface;
@@ -382,9 +511,10 @@ gtk_dialog_map (GtkWidget *widget)
 }
 
 static void
-gtk_dialog_style_set (GtkWidget *widget,
-                      GtkStyle  *prev_style)
+gtk_dialog_style_updated (GtkWidget *widget)
 {
+  GTK_WIDGET_CLASS (gtk_dialog_parent_class)->style_updated (widget);
+
   update_spacings (GTK_DIALOG (widget));
 }
 
@@ -431,6 +561,16 @@ gtk_dialog_close (GtkDialog *dialog)
   gdk_event_free (event);
 }
 
+/**
+ * gtk_dialog_new:
+ *
+ * Creates a new dialog box.
+ *
+ * Widgets should not be packed into this #GtkWindow
+ * directly, but into the @vbox and @action_area, as described above.
+ *
+ * Returns: the new dialog as a #GtkWidget
+ */
 GtkWidget*
 gtk_dialog_new (void)
 {
@@ -467,7 +607,7 @@ gtk_dialog_new_empty (const gchar     *title,
  * @parent: (allow-none): Transient parent of the dialog, or %NULL
  * @flags: from #GtkDialogFlags
  * @first_button_text: (allow-none): stock ID or text to go in first button, or %NULL
- * @Varargs: response ID for first button, then additional buttons, ending with %NULL
+ * @...: response ID for first button, then additional buttons, ending with %NULL
  *
  * Creates a new #GtkDialog with title @title (or %NULL for the default
  * title; see gtk_window_set_title()) and transient parent @parent (or
@@ -501,7 +641,7 @@ gtk_dialog_new_empty (const gchar     *title,
  * ]|
  *
  * Return value: a new #GtkDialog
- **/
+ */
 GtkWidget*
 gtk_dialog_new_with_buttons (const gchar    *title,
                              GtkWindow      *parent,
@@ -632,7 +772,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: (transfer full): the button widget that was added
+ * Return value: (transfer none): the #GtkButton widget that was added
  **/
 GtkWidget*
 gtk_dialog_add_button (GtkDialog   *dialog,
@@ -688,13 +828,13 @@ gtk_dialog_add_buttons_valist (GtkDialog      *dialog,
  * gtk_dialog_add_buttons:
  * @dialog: a #GtkDialog
  * @first_button_text: button text or stock ID
- * @Varargs: response ID for first button, then more text-response_id pairs
+ * @...: response ID for first button, then more text-response_id pairs
  *
  * Adds more buttons, same as calling gtk_dialog_add_button()
  * repeatedly.  The variable argument list should be %NULL-terminated
  * as with gtk_dialog_new_with_buttons(). Each button must have both
  * text and response ID.
- **/
+ */
 void
 gtk_dialog_add_buttons (GtkDialog   *dialog,
                         const gchar *first_button_text,
@@ -966,9 +1106,9 @@ gtk_dialog_run (GtkDialog *dialog)
 
   ri.loop = g_main_loop_new (NULL, FALSE);
 
-  GDK_THREADS_LEAVE ();
+  gdk_threads_leave ();
   g_main_loop_run (ri.loop);
-  GDK_THREADS_ENTER ();
+  gdk_threads_enter ();
 
   g_main_loop_unref (ri.loop);
 
@@ -998,7 +1138,8 @@ gtk_dialog_run (GtkDialog *dialog)
  * Gets the widget button that uses the given response ID in the action area
  * of a dialog.
  *
- * Returns: (transfer none):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
  */
@@ -1124,7 +1265,7 @@ gtk_dialog_set_alternative_button_order_valist (GtkDialog *dialog,
  * gtk_dialog_set_alternative_button_order:
  * @dialog: a #GtkDialog
  * @first_response_id: a response id used by one @dialog's buttons
- * @Varargs: a list of more response ids of @dialog's buttons, terminated by -1
+ * @...: a list of more response ids of @dialog's buttons, terminated by -1
  *
  * Sets an alternative button order. If the
  * #GtkSettings:gtk-alternative-button-order setting is set to %TRUE,
@@ -1189,7 +1330,8 @@ gtk_dialog_set_alternative_button_order (GtkDialog *dialog,
  * gtk_dialog_set_alternative_button_order_from_array:
  * @dialog: a #GtkDialog
  * @n_params: the number of response ids in @new_order
- * @new_order: an array of response ids of @dialog's buttons
+ * @new_order: (array length=n_params): an array of response ids of
+ *     @dialog's buttons
  *
  * Sets an alternative button order. If the
  * #GtkSettings:gtk-alternative-button-order setting is set to %TRUE,