1 /* misc.c : Glue for overriding vms of AtkMisc
2  *
3  * Author: Mike Kestner  <mkestner@novell.com>
4  *
5  * Copyright (c) 2008 Novell, Inc.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of version 2 of the Lesser GNU General
9  * Public License as published by the Free Software Foundation.
10  *
11  * This program 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  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this program; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
22 #include <atk/atk.h>
23 
24 static const gchar *__prefix = "__gtksharp_";
25 
26 #define HAS_PREFIX(a) (*((guint64 *)(a)) == *((guint64 *) __prefix))
27 
28 static GObjectClass *
get_threshold_class(GObject * obj)29 get_threshold_class (GObject *obj)
30 {
31 	GType gtype = G_TYPE_FROM_INSTANCE (obj);
32 	while (HAS_PREFIX (g_type_name (gtype)))
33 		gtype = g_type_parent (gtype);
34 	GObjectClass *klass = g_type_class_peek (gtype);
35 	if (klass == NULL) klass = g_type_class_ref (gtype);
36 	return klass;
37 }
38 
39 void atksharp_misc_override_threads_enter (GType gtype, gpointer cb);
40 void atksharp_misc_base_threads_enter (AtkMisc *misc);
41 
42 void
atksharp_misc_override_threads_enter(GType gtype,gpointer cb)43 atksharp_misc_override_threads_enter (GType gtype, gpointer cb)
44 {
45 	AtkMiscClass *klass = g_type_class_peek (gtype);
46 	if (!klass)
47 		klass = g_type_class_ref (gtype);
48 	((AtkMiscClass *) klass)->threads_enter = cb;
49 }
50 
51 void
atksharp_misc_base_threads_enter(AtkMisc * misc)52 atksharp_misc_base_threads_enter (AtkMisc *misc)
53 {
54 	AtkMiscClass *parent = (AtkMiscClass *)get_threshold_class (G_OBJECT (misc));
55 	if (parent->threads_enter)
56 		(*parent->threads_enter) (misc);
57 }
58 
59 void atksharp_misc_override_threads_leave (GType gtype, gpointer cb);
60 void atksharp_misc_base_threads_leave (AtkMisc *misc);
61 
62 void
atksharp_misc_override_threads_leave(GType gtype,gpointer cb)63 atksharp_misc_override_threads_leave (GType gtype, gpointer cb)
64 {
65 	AtkMiscClass *klass = g_type_class_peek (gtype);
66 	if (!klass)
67 		klass = g_type_class_ref (gtype);
68 	((AtkMiscClass *) klass)->threads_leave = cb;
69 }
70 
71 void
atksharp_misc_base_threads_leave(AtkMisc * misc)72 atksharp_misc_base_threads_leave (AtkMisc *misc)
73 {
74 	AtkMiscClass *parent = (AtkMiscClass *)get_threshold_class (G_OBJECT (misc));
75 	if (parent->threads_leave)
76 		(*parent->threads_leave) (misc);
77 }
78 
79 void atksharp_misc_set_singleton_instance (AtkMisc *misc);
80 
81 void
atksharp_misc_set_singleton_instance(AtkMisc * misc)82 atksharp_misc_set_singleton_instance (AtkMisc *misc)
83 {
84 	atk_misc_instance = misc;
85 }
86