* src/hildon-dialog.c * src/hildon-dialog.h (hildon_dialog_new_with_buttons): New...
authorAlberto Garcia <agarcia@igalia.com>
Wed, 14 May 2008 10:41:30 +0000 (10:41 +0000)
committerAlberto Garcia <agarcia@igalia.com>
Wed, 14 May 2008 10:41:30 +0000 (10:41 +0000)
* examples/hildon-dialog-example.c
(main): Update the example to use the new
hildon_dialog_new_with_buttons().

* examples/hildon-pannable-area-example.c
(main): Update example.

ChangeLog
examples/hildon-dialog-example.c
examples/hildon-pannable-area-example.c
src/hildon-dialog.c
src/hildon-dialog.h

index 383f486..21af265 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2008-05-14  Alberto Garcia  <agarcia@igalia.com>
+
+       * src/hildon-dialog.c
+       (hildon_dialog_new_with_buttons): New constructor.
+
+       * examples/hildon-dialog-example.c
+       (main): Update the example to use the new
+       hildon_dialog_new_with_buttons().
+
+       * examples/hildon-pannable-area-example.c
+       (main): Update example.
+
 2008-05-13 Alberto Garcia <agarcia@igalia.com>
 
        * doc/hildon-docs.sgml
index f34eda0..20464fd 100644 (file)
@@ -28,11 +28,13 @@ int
 main                                            (int argc,
                                                  char **args)
 {
-    HildonDialog *d;
-    GtkWidget *label;
+    HildonDialog *d, *d2;
+    GtkWidget *label, *label2;
 
     gtk_init (&argc, &args);
 
+    /* First dialog, using hildon_dialog_new() */
+
     d = HILDON_DIALOG (hildon_dialog_new ());
     label = gtk_label_new ("Hello, world!");
 
@@ -44,5 +46,24 @@ main                                            (int argc,
 
     gtk_dialog_run (GTK_DIALOG (d));
 
+    /* Second dialog, using hildon_dialog_new_with_buttons() */
+
+    d2 = HILDON_DIALOG (hildon_dialog_new_with_buttons ("Hi again!",
+                                                        GTK_WINDOW (d),
+                                                        GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                        GTK_STOCK_OK,
+                                                        GTK_RESPONSE_ACCEPT,
+                                                        GTK_STOCK_CANCEL,
+                                                        GTK_RESPONSE_REJECT,
+                                                        NULL));
+
+    label2 = gtk_label_new ("Hello, again!");
+
+    gtk_container_add (GTK_CONTAINER (GTK_DIALOG(d2)->vbox), label2);
+
+    gtk_widget_show_all (GTK_WIDGET (d2));
+
+    gtk_dialog_run (GTK_DIALOG (d2));
+
     return 0;
 }
index 3c66ce7..f0ba7ca 100644 (file)
@@ -40,19 +40,25 @@ int
 main (int argc, char **args)
 {
     int i;
+    HildonProgram *program;
+    GtkWidget *window, *tv, *panarea;
+    GtkTreeViewColumn *col;
+    GtkCellRenderer *renderer;
+    GtkListStore *store;
+    GtkVBox *vbox;
 
     gtk_init (&argc, &args);
 
-    HildonProgram *program = hildon_program_get_instance ();
+    program = hildon_program_get_instance ();
 
     /* Create the main window */
-    GtkWidget *window = hildon_window_new ();
+    window = hildon_window_new ();
     hildon_program_add_window (program, HILDON_WINDOW (window));
 
     gtk_container_set_border_width (GTK_CONTAINER (window), 5);
 
     /* Create a VBox and pack some buttons */
-    GtkVBox *vbox = GTK_VBOX (gtk_vbox_new (FALSE, 1));
+    vbox = GTK_VBOX (gtk_vbox_new (FALSE, 1));
     for (i = 0; i < 30; i++) {
             gchar *label = g_strdup_printf ("Button number %d", i);
             GtkWidget *but = gtk_button_new_with_label (label);
@@ -62,13 +68,13 @@ main (int argc, char **args)
     }
 
     /* Create a treeview */
-    GtkWidget *tv = gtk_tree_view_new ();
-    GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
-    GtkTreeViewColumn *col = gtk_tree_view_column_new_with_attributes ("Title", renderer, "text", TEXT_COLUMN, NULL);
+    tv = gtk_tree_view_new ();
+    renderer = gtk_cell_renderer_text_new ();
+    col = gtk_tree_view_column_new_with_attributes ("Title", renderer, "text", TEXT_COLUMN, NULL);
     gtk_tree_view_append_column (GTK_TREE_VIEW(tv), col);
 
     /* Add some rows to the treeview */
-    GtkListStore *store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING);
+    store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING);
     for (i = 0; i < 100; i++) {
             GtkTreeIter iter;
             gchar *label = g_strdup_printf ("Row number %d", i);
@@ -83,7 +89,7 @@ main (int argc, char **args)
     gtk_box_pack_start (GTK_BOX (vbox), tv, TRUE, TRUE, 0);
 
     /* Put everything in a pannable area */
-    GtkWidget *panarea = hildon_pannable_area_new ();
+    panarea = hildon_pannable_area_new ();
     hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (panarea), GTK_WIDGET (vbox));
     gtk_container_add (GTK_CONTAINER (window), panarea);
 
index 199d068..97490d8 100644 (file)
@@ -84,3 +84,70 @@ hildon_dialog_new                               (void)
 
     return self;
 }
+
+/**
+ * hildon_dialog_new_with_buttons:
+ * @title: Title of the dialog, or %NULL
+ * @parent: Transient parent of the dialog, or %NULL
+ * @flags: from #GtkDialogFlags
+ * @first_button_text: stock ID or text to go in first button, or %NULL
+ * @Varargs: response ID for first button, then additional buttons, ending with %NULL
+ *
+ * Creates a new #HildonDialog. See gtk_dialog_new_with_buttons() for
+ * more information.
+ *
+ * Return value: a new #HildonDialog
+ */
+GtkWidget*
+hildon_dialog_new_with_buttons (const gchar    *title,
+                                GtkWindow      *parent,
+                                GtkDialogFlags  flags,
+                                const gchar    *first_button_text,
+                                ...)
+{
+  GtkWidget *dialog;
+
+  dialog = g_object_new (HILDON_TYPE_DIALOG, NULL);
+
+  /* This code is copied from gtk_dialog_new_empty(), as it's a
+   * private function that we cannot use here */
+  if (title)
+    gtk_window_set_title (GTK_WINDOW (dialog), title);
+
+  if (parent)
+    gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
+
+  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);
+
+  /* This is almost copied from gtk_dialog_add_buttons_valist() */
+  if (first_button_text != NULL)
+    {
+      va_list args;
+      const gchar *text;
+      gint response_id;
+
+      va_start (args, first_button_text);
+      text = first_button_text;
+      response_id = va_arg (args, gint);
+
+      while (text != NULL)
+        {
+          gtk_dialog_add_button (GTK_DIALOG (dialog), text, response_id);
+
+          text = va_arg (args, gchar*);
+          if (text == NULL)
+             break;
+          response_id = va_arg (args, int);
+        }
+      va_end (args);
+    }
+
+  return dialog;
+}
index dfb11be..ef41a87 100644 (file)
@@ -77,6 +77,13 @@ hildon_dialog_get_type                          (void);
 GtkWidget*
 hildon_dialog_new                               (void);
 
+GtkWidget*
+hildon_dialog_new_with_buttons                  (const gchar    *title,
+                                                 GtkWindow      *parent,
+                                                 GtkDialogFlags  flags,
+                                                 const gchar    *first_button_text,
+                                                 ...);
+
 G_END_DECLS
 
 #endif                                          /* __HILDON_DIALOG_H__ */