]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkaboutdialog.c
css: Port margin properties to GtkCssNumber
[~andy/gtk] / gtk / gtkaboutdialog.c
index 18f59512a316179981a544022c0705696263c4e3..2a9757cc74fbbde15565c1890b55087abbae295a 100644 (file)
@@ -49,7 +49,7 @@
 #include "gtktextview.h"
 #include "gtkiconfactory.h"
 #include "gtkshow.h"
-#include "gtkmainprivate.h"
+#include "gtkmain.h"
 #include "gtkmessagedialog.h"
 #include "gtktogglebutton.h"
 #include "gtktypebuiltins.h"
  *                        "title" _("About ExampleCode"),
  *                        NULL);
  * </programlisting></informalexample>
+ *
+ * It is also possible to show a #GtkAboutDialog like any other #GtkDialog,
+ * e.g. using gtk_dialog_run(). In this case, you might need to know that
+ * the 'Close' button returns the #GTK_RESPONSE_CANCEL response id.
  */
 
 static GdkColor default_link_color = { 0, 0, 0, 0xeeee };
@@ -118,6 +122,12 @@ static const gchar *gtk_license_urls[] = {
   "http://opensource.org/licenses/artistic-license-2.0.php"
 };
 
+typedef struct
+{
+  gchar *heading;
+  gchar **people;
+} CreditSection;
+
 struct _GtkAboutDialogPrivate 
 {
   gchar *name;
@@ -133,6 +143,9 @@ struct _GtkAboutDialogPrivate
   gchar **documenters;
   gchar **artists;
 
+
+  GSList *credit_sections;
+
   gint credits_page;
   gint license_page;
 
@@ -159,6 +172,8 @@ struct _GtkAboutDialogPrivate
   guint wrap_license : 1;
 };
 
+
+
 #define GTK_ABOUT_DIALOG_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ABOUT_DIALOG, GtkAboutDialogPrivate))
 
 
@@ -557,6 +572,7 @@ update_credits_button_visibility (GtkAboutDialog *about)
   show = (priv->authors != NULL ||
           priv->documenters != NULL ||
           priv->artists != NULL ||
+          priv->credit_sections != NULL ||
          (priv->translator_credits != NULL &&
           strcmp (priv->translator_credits, "translator_credits") &&
           strcmp (priv->translator_credits, "translator-credits")));
@@ -771,6 +787,15 @@ gtk_about_dialog_init (GtkAboutDialog *about)
   gtk_about_dialog_set_logo (about, NULL);
 }
 
+static void
+destroy_credit_section (gpointer data)
+{
+  CreditSection *cs = data;
+  g_free (cs->heading);
+  g_strfreev (cs->people);
+  g_slice_free (CreditSection, data);
+}
+
 static void
 gtk_about_dialog_finalize (GObject *object)
 {
@@ -790,6 +815,8 @@ gtk_about_dialog_finalize (GObject *object)
   g_strfreev (priv->documenters);
   g_strfreev (priv->artists);
 
+  g_slist_free_full (priv->credit_sections, destroy_credit_section);
+
   g_slist_foreach (priv->visited_links, (GFunc)g_free, NULL);
   g_slist_free (priv->visited_links);
 
@@ -1938,7 +1965,7 @@ text_view_event_after (GtkWidget      *text_view,
 
   button_event = (GdkEventButton *)event;
 
-  if (button_event->button != 1)
+  if (button_event->button != GDK_BUTTON_PRIMARY)
     return FALSE;
 
   buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
@@ -2109,7 +2136,7 @@ text_view_new (GtkAboutDialog  *about,
   size = pango_font_description_get_size (gtk_style_context_get_font (context, state));
   font_desc = pango_font_description_new ();
   pango_font_description_set_size (font_desc, size * PANGO_SCALE_SMALL);
-  gtk_widget_modify_font (view, font_desc);
+  gtk_widget_override_font (view, font_desc);
   pango_font_description_free (font_desc);
 
   gtk_text_view_set_left_margin (text_view, 8);
@@ -2239,7 +2266,8 @@ add_credits_section (GtkAboutDialog *about,
   label = gtk_label_new (markup);
   gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
   g_free (markup);
-  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
+  gtk_widget_set_halign (label, GTK_ALIGN_END);
+  gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
   gtk_grid_attach (grid, label, 0, *row, 1, 1);
 
   for (p = people; *p; p++)
@@ -2328,7 +2356,8 @@ add_credits_section (GtkAboutDialog *about,
       label = gtk_label_new (str->str);
       gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
       g_string_free (str, TRUE);
-      gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+      gtk_widget_set_halign (label, GTK_ALIGN_START);
+      gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
       gtk_grid_attach (grid, label, 1, *row, 1, 1);
       (*row)++;
     }
@@ -2387,6 +2416,16 @@ create_credits_page (GtkAboutDialog *about)
   if (priv->artists != NULL)
     add_credits_section (about, GTK_GRID (grid), &row, _("Artwork by"), priv->artists);
 
+  if (priv->credit_sections != NULL)
+    {
+      GSList *cs;
+      for (cs = priv->credit_sections; cs != NULL; cs = cs->next)
+       {
+         CreditSection *section = cs->data;
+         add_credits_section (about, GTK_GRID (grid), &row, section->heading, section->people);
+       }
+    }
+
   gtk_widget_show_all (sw);
 }
 
@@ -2477,7 +2516,7 @@ close_cb (GtkAboutDialog *about)
  * gtk_show_about_dialog:
  * @parent: (allow-none): transient parent, or %NULL for none
  * @first_property_name: the name of the first property
- * @Varargs: value of first property, followed by more properties, %NULL-terminated
+ * @...: value of first property, followed by more properties, %NULL-terminated
  *
  * This is a convenience function for showing an application's about box.
  * The constructed dialog is associated with the parent window and
@@ -2621,3 +2660,35 @@ gtk_about_dialog_get_license_type (GtkAboutDialog *about)
 
   return about->priv->license_type;
 }
+
+/**
+ * gtk_about_dialog_add_credit_section:
+ * @about: A #GtkAboutDialog
+ * @section_name: The name of the section
+ * @people: The people who belong to that section
+ *
+ * Creates a new section in the Credits page.
+ *
+ * Since: 3.4
+ */
+void
+gtk_about_dialog_add_credit_section (GtkAboutDialog  *about,
+                                     const gchar     *section_name,
+                                     const gchar    **people)
+{
+  GtkAboutDialogPrivate *priv;
+  CreditSection *new_entry;
+
+  g_return_if_fail (GTK_IS_ABOUT_DIALOG (about));
+  g_return_if_fail (section_name != NULL);
+  g_return_if_fail (people != NULL);
+
+  priv = about->priv;
+
+  new_entry = g_slice_new (CreditSection);
+  new_entry->heading = g_strdup ((gchar *)section_name);
+  new_entry->people = g_strdupv ((gchar **)people);
+
+  priv->credit_sections = g_slist_append (priv->credit_sections, new_entry);
+  update_credits_button_visibility (about);
+}