]> Pileus Git - ~andy/gtk/blobdiff - demos/gtk-demo/appwindow.c
Apply a cleanup patch by Kjartan Maraas (#341812)
[~andy/gtk] / demos / gtk-demo / appwindow.c
index 4ac1c2c7461bdf73542b51f7660a38d67aac5d0e..6e0f36ecb717f43ee4c9b1c60c3699cd358bab95 100644 (file)
@@ -1,9 +1,10 @@
 /* Application main window
  *
- * Demonstrates a typical application window, with menubar, toolbar, statusbar.
+ * Demonstrates a typical application window with menubar, toolbar, statusbar.
  */
 
 #include <gtk/gtk.h>
+#include "config.h"
 #include "demo-common.h"
 
 static GtkWidget *window = NULL;
@@ -48,7 +49,8 @@ activate_radio_action (GtkAction *action, GtkRadioAction *current)
                                       GTK_DIALOG_DESTROY_WITH_PARENT,
                                       GTK_MESSAGE_INFO,
                                       GTK_BUTTONS_CLOSE,
-                                      "You activated radio action: \"%s\" of type \"%s\".\nCurrent value: %d",
+                                      "You activated radio action: \"%s\" of type \"%s\".\n"
+                                      "Current value: %d",
                                       name, typename, value);
 
       /* Close dialog on user response */
@@ -61,9 +63,115 @@ activate_radio_action (GtkAction *action, GtkRadioAction *current)
     }
 }
 
+static void 
+activate_email (GtkAboutDialog *about,
+               const gchar    *link,
+               gpointer        data)
+{
+  g_print ("send mail to %s\n", link);
+}
+
+static void 
+activate_url (GtkAboutDialog *about,
+             const gchar    *link,
+             gpointer        data)
+{
+  g_print ("show url %s\n", link);
+}
+
+static void
+about_cb (GtkAction *action,
+         GtkWidget *window)
+{
+  GdkPixbuf *pixbuf, *transparent;
+  gchar *filename;
+
+  const gchar *authors[] = {
+    "Peter Mattis",
+    "Spencer Kimball",
+    "Josh MacDonald",
+    "and many more...",
+    NULL
+  };
+
+  const gchar *documentors[] = {
+    "Owen Taylor",
+    "Tony Gale",
+    "Matthias Clasen <mclasen@redhat.com>",
+    "and many more...",
+    NULL
+  };
+
+  const gchar *license =
+    "This library is free software; you can redistribute it and/or\n"
+    "modify it under the terms of the GNU Library General Public License as\n"
+    "published by the Free Software Foundation; either version 2 of the\n"
+    "License, or (at your option) any later version.\n"
+    "\n"
+    "This library is distributed in the hope that it will be useful,\n"
+    "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
+    "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n"
+    "Library General Public License for more details.\n"
+    "\n"
+    "You should have received a copy of the GNU Library General Public\n"
+    "License along with the Gnome Library; see the file COPYING.LIB.  If not,\n"
+    "write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,\n"
+    "Boston, MA 02111-1307, USA.\n";
+
+  pixbuf = NULL;
+  transparent = NULL;
+  filename = demo_find_file ("gtk-logo-rgb.gif", NULL);
+  if (filename)
+    {
+      pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
+      g_free (filename);
+      transparent = gdk_pixbuf_add_alpha (pixbuf, TRUE, 0xff, 0xff, 0xff);
+      g_object_unref (pixbuf);
+    }
+
+  gtk_about_dialog_set_email_hook (activate_email, NULL, NULL);
+  gtk_about_dialog_set_url_hook (activate_url, NULL, NULL);
+  gtk_show_about_dialog (GTK_WINDOW (window),
+                        "name", "GTK+ Code Demos",
+                        "version", PACKAGE_VERSION,
+                        "copyright", "(C) 1997-2005 The GTK+ Team",
+                        "license", license,
+                        "website", "http://www.gtk.org",
+                        "comments", "Program to demonstrate GTK+ functions.",
+                        "authors", authors,
+                        "documenters", documentors,
+                        "logo", transparent,
+                        NULL);
+
+  g_object_unref (transparent);
+}
+
+typedef struct 
+{
+  GtkAction action;
+} ToolMenuAction;
+
+typedef struct 
+{
+  GtkActionClass parent_class;
+} ToolMenuActionClass;
+
+G_DEFINE_TYPE(ToolMenuAction, tool_menu_action, GTK_TYPE_ACTION)
+
+static void
+tool_menu_action_class_init (ToolMenuActionClass *class)
+{
+  GTK_ACTION_CLASS (class)->toolbar_item_type = GTK_TYPE_MENU_TOOL_BUTTON;
+}
+
+static void
+tool_menu_action_init (ToolMenuAction *action)
+{
+}
 
 static GtkActionEntry entries[] = {
   { "FileMenu", NULL, "_File" },               /* name, stock id, label */
+  { "OpenMenu", NULL, "_Open" },               /* name, stock id, label */
   { "PreferencesMenu", NULL, "_Preferences" }, /* name, stock id, label */
   { "ColorMenu", NULL, "_Color"  },            /* name, stock id, label */
   { "ShapeMenu", NULL, "_Shape" },             /* name, stock id, label */
@@ -72,9 +180,9 @@ static GtkActionEntry entries[] = {
     "_New", "<control>N",                      /* label, accelerator */
     "Create a new file",                       /* tooltip */ 
     G_CALLBACK (activate_action) },      
-  { "Open", GTK_STOCK_OPEN,                    /* name, stock id */
-    "_Open","<control>O",                      /* label, accelerator */     
-    "Open a file",                             /* tooltip */
+  { "File1", NULL,                             /* name, stock id */
+    "File1", NULL,                             /* label, accelerator */     
+    "Open first file",                         /* tooltip */
     G_CALLBACK (activate_action) }, 
   { "Save", GTK_STOCK_SAVE,                    /* name, stock id */
     "_Save","<control>S",                      /* label, accelerator */     
@@ -91,7 +199,7 @@ static GtkActionEntry entries[] = {
   { "About", NULL,                             /* name, stock id */
     "_About", "<control>A",                    /* label, accelerator */     
     "About",                                   /* tooltip */  
-    G_CALLBACK (activate_action) },
+    G_CALLBACK (about_cb) },
   { "Logo", "demo-gtk-logo",                   /* name, stock id */
      NULL, NULL,                               /* label, accelerator */     
     "GTK+",                                    /* tooltip */
@@ -131,7 +239,7 @@ static guint n_color_entries = G_N_ELEMENTS (color_entries);
 enum {
   SHAPE_SQUARE,
   SHAPE_RECTANGLE,
-  SHAPE_OVAL,
+  SHAPE_OVAL
 };
 
 static GtkRadioActionEntry shape_entries[] = {
@@ -175,8 +283,12 @@ static const gchar *ui_info =
 "      <menuitem action='About'/>"
 "    </menu>"
 "  </menubar>"
-"  <toolbar  name='ToolBar'>"
-"    <toolitem action='Open'/>"
+"  <toolbar name='ToolBar'>"
+"    <toolitem action='Open'>"
+"      <menu action='OpenMenu'>"
+"        <menuitem action='File1'/>"
+"      </menu>"  
+"    </toolitem>"
 "    <toolitem action='Quit'/>"
 "    <separator action='Sep1'/>"
 "    <toolitem action='Logo'/>"
@@ -217,7 +329,7 @@ register_stock_icons (void)
       factory = gtk_icon_factory_new ();
       gtk_icon_factory_add_default (factory);
 
-      /* demo_find_file() looks in the the current directory first,
+      /* demo_find_file() looks in the current directory first,
        * so you can run gtk-demo without installing GTK, then looks
        * in the location where the file is installed.
        */
@@ -261,7 +373,9 @@ update_statusbar (GtkTextBuffer *buffer,
   gint count;
   GtkTextIter iter;
   
-  gtk_statusbar_pop (statusbar, 0); /* clear any previous message, underflow is allowed */
+  gtk_statusbar_pop (statusbar, 0); /* clear any previous message, 
+                                    * underflow is allowed 
+                                    */
 
   count = gtk_text_buffer_get_char_count (buffer);
 
@@ -294,13 +408,20 @@ update_resize_grip (GtkWidget           *widget,
                    GdkEventWindowState *event,
                    GtkStatusbar        *statusbar)
 {
-  if (event->changed_mask & (GDK_WINDOW_STATE_MAXIMIZED | GDK_WINDOW_STATE_FULLSCREEN))
-    gtk_statusbar_set_has_resize_grip (statusbar, !(event->new_window_state & (GDK_WINDOW_STATE_MAXIMIZED | GDK_WINDOW_STATE_FULLSCREEN)));
+  if (event->changed_mask & (GDK_WINDOW_STATE_MAXIMIZED | 
+                            GDK_WINDOW_STATE_FULLSCREEN))
+    {
+      gboolean maximized;
+
+      maximized = event->new_window_state & (GDK_WINDOW_STATE_MAXIMIZED | 
+                                            GDK_WINDOW_STATE_FULLSCREEN);
+      gtk_statusbar_set_has_resize_grip (statusbar, !maximized);
+    }
 }
                    
 
 GtkWidget *
-do_appwindow (void)
+do_appwindow (GtkWidget *do_widget)
 {  
   if (!window)
     {
@@ -311,6 +432,7 @@ do_appwindow (void)
       GtkWidget *bar;
       GtkTextBuffer *buffer;
       GtkActionGroup *action_group;
+      GtkAction *open_action;
       GtkUIManager *merge;
       GError *error = NULL;
 
@@ -320,7 +442,10 @@ do_appwindow (void)
        */
       
       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+      gtk_window_set_screen (GTK_WINDOW (window),
+                            gtk_widget_get_screen (do_widget));
       gtk_window_set_title (GTK_WINDOW (window), "Application Window");
+      gtk_window_set_icon_name (GTK_WINDOW (window), "gtk-open");
 
       /* NULL window variable when window is closed */
       g_signal_connect (window, "destroy",
@@ -335,9 +460,16 @@ do_appwindow (void)
        */
       
       action_group = gtk_action_group_new ("AppWindowActions");
+      open_action = g_object_new (tool_menu_action_get_type (), 
+                                 "name", "Open",
+                                 "label", "_Open",
+                                 "tooltip", "Open a file",
+                                 "stock-id", GTK_STOCK_OPEN,
+                                 NULL);
+      gtk_action_group_add_action (action_group, open_action);
       gtk_action_group_add_actions (action_group, 
                                    entries, n_entries, 
-                                   NULL);
+                                   window);
       gtk_action_group_add_toggle_actions (action_group, 
                                           toggle_entries, n_toggle_entries, 
                                           NULL);
@@ -353,7 +485,8 @@ do_appwindow (void)
                                          NULL);
 
       merge = gtk_ui_manager_new ();
-      g_object_set_data_full (G_OBJECT (window), "ui-manager", merge, g_object_unref);
+      g_object_set_data_full (G_OBJECT (window), "ui-manager", merge, 
+                             g_object_unref);
       gtk_ui_manager_insert_action_group (merge, action_group, 0);
       gtk_window_add_accel_group (GTK_WINDOW (window), 
                                  gtk_ui_manager_get_accel_group (merge));
@@ -374,6 +507,7 @@ do_appwindow (void)
                         0,                         0);
 
       bar = gtk_ui_manager_get_widget (merge, "/ToolBar");
+      gtk_toolbar_set_tooltips (GTK_TOOLBAR (bar), TRUE);
       gtk_widget_show (bar);
       gtk_table_attach (GTK_TABLE (table),
                        bar,