]> Pileus Git - ~andy/gtk/blobdiff - tests/teststatusicon.c
tooltip-text and tooltip-markup properties: Interpret an empty string as a
[~andy/gtk] / tests / teststatusicon.c
index 85007e3f34c3cef6faff669fe10aa0edd857cd0b..86473601f89381bf6b119bb4f84c14eac40e909b 100755 (executable)
@@ -22,6 +22,9 @@
  */
 
 #include <gtk/gtk.h>
+#include <stdlib.h>
+
+#include "prop-editor.h"
 
 typedef enum
 {
@@ -33,6 +36,36 @@ static TestStatus status = TEST_STATUS_INFO;
 static gint timeout = 0;
 static GSList *icons = NULL;
 
+static void
+size_changed_cb (GtkStatusIcon *icon,
+                int size)
+{
+  g_print ("status icon %p size-changed size = %d\n", icon, size);
+}
+
+static void
+embedded_changed_cb (GtkStatusIcon *icon)
+{
+  g_print ("status icon %p embedded changed to %d\n", icon,
+          gtk_status_icon_is_embedded (icon));
+}
+
+static void
+orientation_changed_cb (GtkStatusIcon *icon)
+{
+  GtkOrientation orientation;
+
+  g_object_get (icon, "orientation", &orientation, NULL);
+  g_print ("status icon %p orientation changed to %d\n", icon, orientation);
+}
+
+static void
+screen_changed_cb (GtkStatusIcon *icon)
+{
+  g_print ("status icon %p screen changed to %p\n", icon,
+          gtk_status_icon_get_screen (icon));
+}
+
 static void
 update_icons (void)
 {
@@ -43,7 +76,7 @@ update_icons (void)
   if (status == TEST_STATUS_INFO)
     {
       icon_name = GTK_STOCK_DIALOG_INFO;
-      tooltip = "Some Infromation ...";
+      tooltip = "Some Information ...";
     }
   else
     {
@@ -103,7 +136,7 @@ timeout_toggle_toggled (GtkToggleButton *toggle)
     }
   else
     {
-      timeout = g_timeout_add (2000, timeout_handler, NULL);
+      timeout = gdk_threads_add_timeout (2000, timeout_handler, NULL);
     }
 }
 
@@ -192,6 +225,20 @@ check_activated (GtkCheckMenuItem *item)
   gtk_status_icon_set_screen (GTK_STATUS_ICON (icons->data), screen);
 }
 
+static void
+do_properties (GtkMenuItem   *item,
+              GtkStatusIcon *icon)
+{
+       static GtkWidget *editor = NULL;
+
+       if (editor == NULL) {
+               editor = create_prop_editor (G_OBJECT (icon), GTK_TYPE_STATUS_ICON);
+               g_signal_connect (editor, "destroy", G_CALLBACK (gtk_widget_destroyed), &editor);
+       }
+
+       gtk_window_present (GTK_WINDOW (editor));
+}
+
 static void
 do_quit (GtkMenuItem *item)
 {
@@ -211,6 +258,12 @@ do_quit (GtkMenuItem *item)
   gtk_main_quit ();
 }
 
+static void
+do_exit (GtkMenuItem *item)
+{
+  exit (0);
+}
+
 static void 
 popup_menu (GtkStatusIcon *icon,
            guint          button,
@@ -232,6 +285,13 @@ popup_menu (GtkStatusIcon *icon,
 
   gtk_widget_show (menuitem);
 
+  menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_PROPERTIES, NULL);
+  g_signal_connect (menuitem, "activate", G_CALLBACK (do_properties), icon);
+
+  gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
+
+  gtk_widget_show (menuitem);
+
   menuitem = gtk_menu_item_new_with_label ("Quit");
   g_signal_connect (menuitem, "activate", G_CALLBACK (do_quit), NULL);
 
@@ -239,8 +299,16 @@ popup_menu (GtkStatusIcon *icon,
 
   gtk_widget_show (menuitem);
 
+  menuitem = gtk_menu_item_new_with_label ("Exit abruptly");
+  g_signal_connect (menuitem, "activate", G_CALLBACK (do_exit), NULL);
+
+  gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
+
+  gtk_widget_show (menuitem);
+
   gtk_menu_popup (GTK_MENU (menu), 
-                 NULL, NULL, NULL, NULL, 
+                 NULL, NULL,
+                 gtk_status_icon_position_menu, icon,
                  button, activate_time);
 }
 
@@ -264,7 +332,12 @@ main (int argc, char **argv)
       gtk_status_icon_set_screen (icon, gdk_display_get_screen (display, i));
       update_icons ();
 
-      gtk_status_icon_set_blinking (GTK_STATUS_ICON (icon), TRUE);
+      g_signal_connect (icon, "size-changed", G_CALLBACK (size_changed_cb), NULL);
+      g_signal_connect (icon, "notify::embedded", G_CALLBACK (embedded_changed_cb), NULL);
+      g_signal_connect (icon, "notify::orientation", G_CALLBACK (orientation_changed_cb), NULL);
+      g_signal_connect (icon, "notify::screen", G_CALLBACK (screen_changed_cb), NULL);
+      g_print ("icon size %d\n", gtk_status_icon_get_size (icon));
+      gtk_status_icon_set_blinking (GTK_STATUS_ICON (icon), FALSE);
 
       g_signal_connect (icon, "activate",
                         G_CALLBACK (icon_activated), NULL);
@@ -274,7 +347,9 @@ main (int argc, char **argv)
 
       icons = g_slist_append (icons, icon);
  
-      timeout = g_timeout_add (2000, timeout_handler, icon);
+      update_icons ();
+
+      timeout = gdk_threads_add_timeout (2000, timeout_handler, icon);
     }
 
   gtk_main ();