99746d42c9c5da6551db19afda5c97d363babe05
[platform/core/uifw/at-spi2-atk.git] / libspi / application.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2001 Sun Microsystems Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 /*
24  * application.c: implements Application.idl
25  *
26  */
27 #include <config.h>
28 #include <bonobo/Bonobo.h>
29 #include <atk/atkutil.h>
30
31 /*
32  * This pulls the CORBA definitions for the "Accessibility::Accessible" server
33  */
34 #include <libspi/Accessibility.h>
35
36 /*
37  * This pulls the definition for the BonoboObject (GObject Type)
38  */
39 #include "application.h"
40
41 /*
42  * Our parent Gtk object type
43  */
44 #define PARENT_TYPE ACCESSIBLE_TYPE
45
46 /*
47  * A pointer to our parent object class
48  */
49 static AccessibleClass *application_parent_class;
50
51 /*
52  * Implemented GObject::finalize
53  */
54 static void
55 accessible_application_finalize (GObject *object)
56 {
57   /* TODO: any necessary cleanup */
58   Accessible *accessible = ACCESSIBLE (object);
59
60   g_object_unref (accessible->atko);
61   accessible->atko = NULL;
62
63   /* TODO: chain to parent class instead */
64 }
65
66 static CORBA_string
67 impl_accessibility_application_get_toolkit_name (PortableServer_Servant servant,
68                                                  CORBA_Environment *ev)
69 {
70   CORBA_char *retval;
71   Application *application = APPLICATION (bonobo_object_from_servant (servant));
72   retval = CORBA_string_dup (atk_get_toolkit_name ());
73   return retval;
74 }
75
76 static CORBA_string
77 impl_accessibility_application_get_version (PortableServer_Servant servant,
78                                             CORBA_Environment *ev)
79 {
80   CORBA_char *retval;
81   Application *application = APPLICATION (bonobo_object_from_servant (servant));
82   retval = CORBA_string_dup (atk_get_toolkit_version ());
83   return retval;
84 }
85
86 static CORBA_string
87 impl_accessibility_application_get_id (PortableServer_Servant servant,
88                                                  CORBA_Environment *ev)
89 {
90   CORBA_char *retval;
91   Application *application = APPLICATION (bonobo_object_from_servant (servant));
92   retval = CORBA_string_dup (application->id);
93   return retval;
94 }
95
96 static void
97 impl_accessibility_application_set_id (PortableServer_Servant servant,
98                                        const CORBA_char *id,
99                                        CORBA_Environment *ev)
100 {
101   Application *application = APPLICATION (bonobo_object_from_servant (servant));
102   application->id = id;
103 }
104
105 static void
106 application_class_init (ApplicationClass *klass)
107 {
108   GObjectClass * object_class = (GObjectClass *) klass;
109   POA_Accessibility_Application__epv *epv = &klass->epv;
110
111   application_parent_class = g_type_class_ref (ACCESSIBLE_TYPE);
112
113   object_class->finalize = accessible_application_finalize;
114
115   epv->_get_toolkitName = impl_accessibility_application_get_toolkit_name;
116   epv->_get_version = impl_accessibility_application_get_version;
117   epv->_get_id = impl_accessibility_application_get_id;
118   epv->_set_id = impl_accessibility_application_set_id;
119 }
120
121 static void
122 application_init (Application  *application)
123 {
124   ACCESSIBLE (application)->atko = g_object_new (atk_object_get_type(), NULL);
125 }
126
127 GType
128 application_get_type (void)
129 {
130         static GType type = 0;
131
132         if (!type) {
133                 static const GTypeInfo tinfo = {
134                         sizeof (ApplicationClass),
135                         (GBaseInitFunc) NULL,
136                         (GBaseFinalizeFunc) NULL,
137                         (GClassInitFunc) application_class_init,
138                         (GClassFinalizeFunc) NULL,
139                         NULL, /* class data */
140                         sizeof (Application),
141                         0, /* n preallocs */
142                         (GInstanceInitFunc) application_init,
143                         NULL /* value table */
144                 };
145                 /*
146                  * Bonobo_type_unique auto-generates a load of
147                  * CORBA structures for us. All derived types must
148                  * use bonobo_type_unique.
149                  */
150                 type = bonobo_type_unique (
151                         PARENT_TYPE,
152                         POA_Accessibility_Application__init,
153                         NULL,
154                         G_STRUCT_OFFSET (ApplicationClass, epv),
155                         &tinfo,
156                         "Application");
157         }
158
159         return type;
160 }
161
162 Application *
163 application_new (AtkObject *app_root)
164 {
165     Application *retval =
166                APPLICATION (g_object_new (application_get_type (), NULL));
167     ACCESSIBLE (retval)->atko = app_root;
168     return retval;
169 }