Add HildonAppMenu::changed signal
[hildon] / hildon / hildon-gtk.c
index fd1f9f4..f6b8ae2 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is a part of hildon
  *
- * Copyright (C) 2008 Nokia Corporation, all rights reserved.
+ * Copyright (C) 2008, 2009 Nokia Corporation, all rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser Public License as published by
  * easily perform frequent tasks.
  */
 
-#include <X11/Xatom.h>
-#include <gdk/gdkx.h>
-
 #include "hildon-gtk.h"
-
-typedef void (*HildonFlagFunc) (GtkWindow *window, gpointer userdata);
+#include "hildon-window.h"
+#include "hildon-window-private.h"
+#include "hildon-edit-toolbar.h"
+#include "hildon-edit-toolbar-private.h"
+#include "hildon-private.h"
 
 static void
 image_visible_changed_cb                        (GtkWidget  *image,
@@ -110,8 +110,8 @@ hildon_gtk_menu_new                             (void)
  * This is a convenience function to create a #GtkButton setting its
  * size to one of the pre-defined Hildon sizes.
  *
- * Buttons created with this function also override the
- * "gtk-button-images" setting. Images set using
+ * Buttons created with this function also override
+ * #GtkSettings:gtk-button-images. Images set using
  * gtk_button_set_image() are always shown.
  *
  * Buttons created using this function have #GtkButton:focus-on-click
@@ -136,8 +136,8 @@ hildon_gtk_button_new                           (HildonSizeType size)
  * This is a convenience function to create a #GtkToggleButton setting
  * its size to one of the pre-defined Hildon sizes.
  *
- * Buttons created with this function also override the
- * "gtk-button-images" setting. Images set using
+ * Buttons created with this function also override
+ * #GtkSettings:gtk-button-images. Images set using
  * gtk_button_set_image() are always shown.
  *
  * Buttons created using this function have #GtkButton:focus-on-click
@@ -164,8 +164,8 @@ hildon_gtk_toggle_button_new                    (HildonSizeType size)
  * This is a convenience function to create a #GtkRadioButton setting
  * its size to one of the pre-defined Hildon sizes.
  *
- * Buttons created with this function also override the
- * "gtk-button-images" setting. Images set using
+ * Buttons created with this function also override
+ * #GtkSettings:gtk-button-images. Images set using
  * gtk_button_set_image() are always shown.
  *
  * Buttons created using this function have #GtkButton:focus-on-click
@@ -192,8 +192,8 @@ hildon_gtk_radio_button_new                     (HildonSizeType  size,
  * This is a convenience function to create a #GtkRadioButton setting
  * its size to one of the pre-defined Hildon sizes.
  *
- * Buttons created with this function also override the
- * "gtk-button-images" setting. Images set using
+ * Buttons created with this function also override
+ * #GtkSettings:gtk-button-images. Images set using
  * gtk_button_set_image() are always shown.
  *
  * Buttons created using this function have #GtkButton:focus-on-click
@@ -322,29 +322,12 @@ hildon_gtk_icon_view_set_ui_mode                (GtkIconView  *iconview,
 #endif /* MAEMO_GTK */
 
 static void
-set_clear_window_flag                           (GtkWindow   *window,
-                                                 const gchar *atomname,
-                                                 Atom         xatom,
-                                                 gboolean     flag)
-{
-    GdkWindow *gdkwin = GTK_WIDGET (window)->window;
-    GdkAtom atom = gdk_atom_intern (atomname, FALSE);
-
-    if (flag) {
-        guint32 set = 1;
-        gdk_property_change (gdkwin, atom, gdk_x11_xatom_to_atom (xatom),
-                             32, GDK_PROP_MODE_REPLACE, (const guchar *) &set, 1);
-    } else {
-        gdk_property_delete (gdkwin, atom);
-    }
-}
-
-static void
 do_set_progress_indicator                       (GtkWindow *window,
                                                  gpointer   stateptr)
 {
     guint state = GPOINTER_TO_UINT (stateptr);
-    set_clear_window_flag (window, "_HILDON_WM_WINDOW_PROGRESS_INDICATOR", XA_INTEGER, state);
+    hildon_gtk_window_set_clear_window_flag (window, "_HILDON_WM_WINDOW_PROGRESS_INDICATOR",
+                                             XA_INTEGER, state);
     g_signal_handlers_disconnect_matched (window, G_SIGNAL_MATCH_FUNC,
                                           0, 0, NULL, do_set_progress_indicator, NULL);
 }
@@ -354,7 +337,8 @@ do_set_do_not_disturb                           (GtkWindow *window,
                                                  gpointer   dndptr)
 {
     gboolean dndflag = GPOINTER_TO_INT (dndptr);
-    set_clear_window_flag (window, "_HILDON_DO_NOT_DISTURB", XA_INTEGER, dndflag);
+    hildon_gtk_window_set_clear_window_flag (window, "_HILDON_DO_NOT_DISTURB",
+                                             XA_INTEGER, dndflag);
     g_signal_handlers_disconnect_matched (window, G_SIGNAL_MATCH_FUNC,
                                           0, 0, NULL, do_set_do_not_disturb, NULL);
 }
@@ -365,30 +349,17 @@ do_set_portrait_flags                           (GtkWindow *window,
 {
     HildonPortraitFlags flags = GPOINTER_TO_INT (flagsptr);
 
-    set_clear_window_flag (window, "_HILDON_PORTRAIT_MODE_REQUEST", XA_CARDINAL,
-                           flags & HILDON_PORTRAIT_MODE_REQUEST);
-    set_clear_window_flag (window, "_HILDON_PORTRAIT_MODE_SUPPORT", XA_CARDINAL,
-                           flags & HILDON_PORTRAIT_MODE_SUPPORT);
+    hildon_gtk_window_set_clear_window_flag (window, "_HILDON_PORTRAIT_MODE_REQUEST",
+                                             XA_CARDINAL,
+                                             flags & HILDON_PORTRAIT_MODE_REQUEST);
+    hildon_gtk_window_set_clear_window_flag (window, "_HILDON_PORTRAIT_MODE_SUPPORT",
+                                             XA_CARDINAL,
+                                             flags & HILDON_PORTRAIT_MODE_SUPPORT);
 
     g_signal_handlers_disconnect_matched (window, G_SIGNAL_MATCH_FUNC,
                                           0, 0, NULL, do_set_portrait_flags, NULL);
 }
 
-static void
-set_flag                                        (GtkWindow      *window,
-                                                 HildonFlagFunc  func,
-                                                 gpointer        userdata)
-{
-     g_return_if_fail (GTK_IS_WINDOW (window));
-     if (GTK_WIDGET_REALIZED (window)) {
-        (*func) (window, userdata);
-     } else {
-         g_signal_handlers_disconnect_matched (window, G_SIGNAL_MATCH_FUNC,
-                                               0, 0, NULL, func, NULL);
-         g_signal_connect (window, "realize", G_CALLBACK (func), userdata);
-     }
-}
-
 /**
  * hildon_gtk_window_set_progress_indicator:
  * @window: a #GtkWindow.
@@ -402,10 +373,17 @@ set_flag                                        (GtkWindow      *window,
  * Since: 2.2
  **/
 void
-hildon_gtk_window_set_progress_indicator        (GtkWindow    *window,
-                                                 guint         state)
+hildon_gtk_window_set_progress_indicator        (GtkWindow *window,
+                                                 guint      state)
 {
-    set_flag (window, (HildonFlagFunc) do_set_progress_indicator, GUINT_TO_POINTER (state));
+    hildon_gtk_window_set_flag (window, (HildonFlagFunc) do_set_progress_indicator, GUINT_TO_POINTER (state));
+    if (HILDON_IS_WINDOW (window)) {
+        HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (window);
+        if (priv->edit_toolbar) {
+            HildonEditToolbar *tb = HILDON_EDIT_TOOLBAR (priv->edit_toolbar);
+            hildon_edit_toolbar_set_progress_indicator (tb, state);
+        }
+    }
 }
 
 /**
@@ -422,7 +400,7 @@ void
 hildon_gtk_window_set_do_not_disturb            (GtkWindow *window,
                                                  gboolean   dndflag)
 {
-    set_flag (window, (HildonFlagFunc) do_set_do_not_disturb, GUINT_TO_POINTER (dndflag));
+    hildon_gtk_window_set_flag (window, (HildonFlagFunc) do_set_do_not_disturb, GUINT_TO_POINTER (dndflag));
 }
 
 /**
@@ -438,9 +416,43 @@ void
 hildon_gtk_window_set_portrait_flags            (GtkWindow           *window,
                                                  HildonPortraitFlags  portrait_flags)
 {
-    set_flag (window, (HildonFlagFunc) do_set_portrait_flags, GUINT_TO_POINTER (portrait_flags));
+    hildon_gtk_window_set_flag (window, (HildonFlagFunc) do_set_portrait_flags, GUINT_TO_POINTER (portrait_flags));
+}
+
+/**
+ * hildon_gtk_window_take_screenshot:
+ * @window: a #GtkWindow
+ * @take: %TRUE to take a screenshot, %FALSE to destroy the existing one.
+ *
+ * Tells the window manager to take a screenshot of @window, or to
+ * destroy the existing one. @window must be mapped.
+ **/
+void
+hildon_gtk_window_take_screenshot               (GtkWindow *window,
+                                                 gboolean   take)
+{
+    GdkEventClient *ev;
+    GdkWindow *rootwin;
+
+    g_return_if_fail (GTK_IS_WINDOW (window));
+    g_return_if_fail (GTK_WIDGET_MAPPED (window));
+
+    rootwin = gdk_screen_get_root_window (gtk_window_get_screen (window));
+
+    ev = (GdkEventClient *) gdk_event_new (GDK_CLIENT_EVENT);
+    ev->window = g_object_ref (rootwin);
+    ev->send_event = TRUE;
+    ev->message_type = gdk_atom_intern ("_HILDON_LOADING_SCREENSHOT", FALSE);
+    ev->data_format = 32;
+    ev->data.l[0] = take ? 1 : 0;
+    ev->data.l[1] = GDK_WINDOW_XID (GTK_WIDGET (window)->window);
+
+    gdk_event_send_client_message ((GdkEvent *) ev, GDK_WINDOW_XWINDOW (rootwin));
+
+    gdk_event_free ((GdkEvent *) ev);
 }
 
+
 /**
  * hildon_gtk_hscale_new:
  *