Rename and move the methods to set flags to hildon-private.h
[hildon] / hildon / hildon-private.c
1 /*
2  * This file is a part of hildon
3  *
4  * Copyright (C) 2005, 2006, 2009 Nokia Corporation, all rights reserved.
5  *
6  * Contact: Rodrigo Novo <rodrigo.novo@nokia.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; version 2.1 of
11  * the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  *
23  */
24
25 #undef                                          HILDON_DISABLE_DEPRECATED
26
27 #ifdef                                          HAVE_CONFIG_H
28 #include                                        <config.h>
29 #endif
30
31 #include                                        "hildon-private.h"
32 #include                                        "hildon-date-editor.h"
33 #include                                        "hildon-time-editor.h"
34 #include                                        "hildon-defines.h"
35
36 /* This function is a private function of hildon. It hadles focus 
37  * changing for composite hildon widgets: HildonDateEditor, 
38  * HildonNumberEditor, HildonTimeEditor, HildonWeekdayPicker. 
39  * Its purpose is to focus the first widget (from left) inside the container 
40  * regardless of where the focus is coming from.
41  */
42 gboolean G_GNUC_INTERNAL
43 hildon_private_composite_focus                  (GtkWidget *widget,
44                                                  GtkDirectionType direction,
45                                                  GtkDirectionType *effective_direction)
46 {
47   GtkWidget *toplevel = NULL;
48   GtkWidget *focus_widget = NULL;
49   gboolean coming_from_outside = FALSE;
50
51   toplevel = gtk_widget_get_toplevel (widget);
52
53   focus_widget = GTK_WINDOW (toplevel)->focus_widget;
54
55   if (focus_widget == NULL || gtk_widget_is_ancestor (focus_widget, widget) == FALSE)
56     {
57       /* When coming from outside we want to give focus to the first
58          item in the widgets */
59       *effective_direction = GTK_DIR_TAB_FORWARD;
60       coming_from_outside = TRUE;
61     }
62   else
63     *effective_direction = direction;
64
65   switch (direction) {
66       case GTK_DIR_UP:
67       case GTK_DIR_DOWN:
68       case GTK_DIR_TAB_FORWARD:
69       case GTK_DIR_TAB_BACKWARD:
70         if ((HILDON_IS_DATE_EDITOR (widget) || HILDON_IS_TIME_EDITOR(widget)) &&
71             !coming_from_outside)
72             return FALSE;
73         /* fall through */
74       default:
75         return TRUE;
76   }
77
78   g_assert_not_reached ();
79   return TRUE;
80 }
81
82
83 G_GNUC_INTERNAL GtkWidget *
84 hildon_private_create_animation                 (gfloat       framerate,
85                                                  const gchar *template,
86                                                  gint         nframes)
87 {
88     GtkWidget *image;
89     GdkPixbufSimpleAnim *anim;
90     GtkIconTheme *theme;
91     gint i;
92
93     anim = gdk_pixbuf_simple_anim_new (HILDON_ICON_PIXEL_SIZE_STYLUS,
94                                        HILDON_ICON_PIXEL_SIZE_STYLUS,
95                                        framerate);
96     gdk_pixbuf_simple_anim_set_loop (anim, TRUE);
97     theme = gtk_icon_theme_get_default ();
98
99     for (i = 1; i <= nframes; i++) {
100         GdkPixbuf *frame;
101         GError *error = NULL;
102         gchar *icon_name = g_strdup_printf (template, i);
103         frame = gtk_icon_theme_load_icon (theme, icon_name,
104                                           HILDON_ICON_PIXEL_SIZE_STYLUS,
105                                           0, &error);
106
107         if (error) {
108             g_warning ("Icon theme lookup for icon `%s' failed: %s",
109                        icon_name, error->message);
110             g_error_free (error);
111         } else {
112             gdk_pixbuf_simple_anim_add_frame (anim, frame);
113         }
114
115         g_object_unref (frame);
116         g_free (icon_name);
117     }
118
119     image = gtk_image_new_from_animation (GDK_PIXBUF_ANIMATION (anim));
120     g_object_unref (anim);
121
122     return image;
123 }
124
125
126 void
127 hildon_gtk_window_set_clear_window_flag                           (GtkWindow   *window,
128                                                                    const gchar *atomname,
129                                                                    Atom         xatom,
130                                                                    gboolean     flag)
131 {
132     GdkWindow *gdkwin = GTK_WIDGET (window)->window;
133     GdkAtom atom = gdk_atom_intern (atomname, FALSE);
134
135     if (flag) {
136         guint32 set = 1;
137         gdk_property_change (gdkwin, atom, gdk_x11_xatom_to_atom (xatom),
138                              32, GDK_PROP_MODE_REPLACE, (const guchar *) &set, 1);
139     } else {
140         gdk_property_delete (gdkwin, atom);
141     }
142 }
143
144 void
145 hildon_gtk_window_set_flag                                        (GtkWindow      *window,
146                                                                    HildonFlagFunc  func,
147                                                                    gpointer        userdata)
148 {
149      g_return_if_fail (GTK_IS_WINDOW (window));
150      if (GTK_WIDGET_REALIZED (window)) {
151         (*func) (window, userdata);
152      } else {
153          g_signal_handlers_disconnect_matched (window, G_SIGNAL_MATCH_FUNC,
154                                                0, 0, NULL, func, NULL);
155          g_signal_connect (window, "realize", G_CALLBACK (func), userdata);
156      }
157 }