1 /*-
2  * Copyright (c) 2004-2006 os-cillation e.K.
3  *
4  * Written by Benedikt Meurer <benny@xfce.org>.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25 
26 #ifdef HAVE_LIBINTL_H
27 #include <libintl.h>
28 #endif
29 #ifdef HAVE_LOCALE_H
30 #include <locale.h>
31 #endif
32 
33 #include "exo-private.h"
34 #include "exo-string.h"
35 
36 #define             I_(string)  g_intern_static_string(string)
37 
38 /*
39 void
40 _exo_i18n_init (void)
41 {
42   static gboolean inited = FALSE;
43 
44   if (G_UNLIKELY (!inited))
45     {
46       inited = TRUE;
47 
48       bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
49 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
50       bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
51 #endif
52     }
53 }
54 */
55 
56 
57 void
_exo_gtk_widget_send_focus_change(GtkWidget * widget,gboolean in)58 _exo_gtk_widget_send_focus_change (GtkWidget *widget,
59                                    gboolean   in)
60 {
61   GdkEvent *fevent;
62 
63 #if !GTK_CHECK_VERSION(2, 22, 0)
64   g_object_ref (G_OBJECT (widget));
65 #endif
66 
67   gtk_widget_set_can_focus (widget, in);
68 
69   fevent = gdk_event_new (GDK_FOCUS_CHANGE);
70   fevent->focus_change.type = GDK_FOCUS_CHANGE;
71   fevent->focus_change.window = g_object_ref (gtk_widget_get_window (widget));
72   fevent->focus_change.in = in;
73 
74 #if GTK_CHECK_VERSION(2, 22, 0)
75   gtk_widget_send_focus_change (widget, fevent);
76 #else
77   if (in)
78     GTK_OBJECT_FLAGS (widget) |= GTK_HAS_FOCUS;
79   else
80     GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_FOCUS);
81   gtk_widget_event (widget, fevent);
82 
83   g_object_notify (G_OBJECT (widget), "has-focus");
84 
85   g_object_unref (G_OBJECT (widget));
86 #endif
87 
88   gdk_event_free (fevent);
89 }
90 
91 
92 
93 /**
94  * _exo_g_type_register_simple:
95  * @type_parent      : the parent #GType.
96  * @type_name_static : the name of the new #GType, must reside in static
97  *                     storage and remain unchanged during the lifetime
98  *                     of the process.
99  * @class_size       : the size of the class structure in bytes.
100  * @class_init       : the class init function or %NULL.
101  * @instance_size    : the size of the instance structure in bytes.
102  * @instance_init    : the constructor function or %NULL.
103  *
104  * Simple wrapper for g_type_register_static(), which takes the most
105  * important aspects of the type as parameters to avoid relocations
106  * when using static constant #GTypeInfo<!---->s.
107  *
108  * Return value: the newly registered #GType.
109  **/
110 GType
_exo_g_type_register_simple(GType type_parent,const gchar * type_name_static,guint class_size,gpointer class_init,guint instance_size,gpointer instance_init)111 _exo_g_type_register_simple (GType        type_parent,
112                              const gchar *type_name_static,
113                              guint        class_size,
114                              gpointer     class_init,
115                              guint        instance_size,
116                              gpointer     instance_init)
117 {
118   /* generate the type info (on the stack) */
119   GTypeInfo info =
120   {
121     class_size,
122     NULL,
123     NULL,
124     class_init,
125     NULL,
126     NULL,
127     instance_size,
128     0,
129     instance_init,
130     NULL,
131   };
132 
133   /* register the static type */
134   return g_type_register_static (type_parent, I_(type_name_static), &info, 0);
135 }
136 
137 
138 
139 /**
140  * _exo_g_type_add_interface_simple:
141  * @instance_type       : the #GType which should implement the @interface_type.
142  * @interface_type      : the #GType of the interface.
143  * @interface_init_func : initialization function for the interface.
144  *
145  * Simple wrapper for g_type_add_interface_static(), which helps to avoid unnecessary
146  * relocations for the #GInterfaceInfo<!---->s.
147  **/
148 void
_exo_g_type_add_interface_simple(GType instance_type,GType interface_type,GInterfaceInitFunc interface_init_func)149 _exo_g_type_add_interface_simple (GType              instance_type,
150                                   GType              interface_type,
151                                   GInterfaceInitFunc interface_init_func)
152 {
153   GInterfaceInfo info =
154   {
155     interface_init_func,
156     NULL,
157     NULL,
158   };
159 
160   g_type_add_interface_static (instance_type, interface_type, &info);
161 }
162