xref: /AOO41X/main/vcl/unx/gtk/a11y/atkfactory.cxx (revision 9f62ea84a806e17e6f2bbff75724a7257a0eb5d9)
1*9f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9f62ea84SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9f62ea84SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9f62ea84SAndrew Rist  * distributed with this work for additional information
6*9f62ea84SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9f62ea84SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9f62ea84SAndrew Rist  * "License"); you may not use this file except in compliance
9*9f62ea84SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*9f62ea84SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*9f62ea84SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9f62ea84SAndrew Rist  * software distributed under the License is distributed on an
15*9f62ea84SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9f62ea84SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9f62ea84SAndrew Rist  * specific language governing permissions and limitations
18*9f62ea84SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*9f62ea84SAndrew Rist  *************************************************************/
21*9f62ea84SAndrew Rist 
22*9f62ea84SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_vcl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <unx/gtk/gtkframe.hxx>
28cdf0e10cSrcweir #include <vcl/window.hxx>
29cdf0e10cSrcweir #include "atkwrapper.hxx"
30cdf0e10cSrcweir #include "atkfactory.hxx"
31cdf0e10cSrcweir #include "atkregistry.hxx"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir using namespace ::com::sun::star;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir extern "C" {
36cdf0e10cSrcweir 
37cdf0e10cSrcweir /*
38cdf0e10cSrcweir  *  Instances of this dummy object class are returned whenever we have to
39cdf0e10cSrcweir  *  create an AtkObject, but can't touch the OOo object anymore since it
40cdf0e10cSrcweir  *  is already disposed.
41cdf0e10cSrcweir  */
42cdf0e10cSrcweir 
43cdf0e10cSrcweir static AtkStateSet *
noop_wrapper_ref_state_set(AtkObject *)44cdf0e10cSrcweir noop_wrapper_ref_state_set( AtkObject * )
45cdf0e10cSrcweir {
46cdf0e10cSrcweir     AtkStateSet *state_set = atk_state_set_new();
47cdf0e10cSrcweir     atk_state_set_add_state( state_set, ATK_STATE_DEFUNCT );
48cdf0e10cSrcweir     return state_set;
49cdf0e10cSrcweir }
50cdf0e10cSrcweir 
51cdf0e10cSrcweir static void
atk_noop_object_wrapper_class_init(AtkNoOpObjectClass * klass)52cdf0e10cSrcweir atk_noop_object_wrapper_class_init(AtkNoOpObjectClass *klass)
53cdf0e10cSrcweir {
54cdf0e10cSrcweir     AtkObjectClass *atk_class = ATK_OBJECT_CLASS( klass );
55cdf0e10cSrcweir     atk_class->ref_state_set = noop_wrapper_ref_state_set;
56cdf0e10cSrcweir }
57cdf0e10cSrcweir 
58cdf0e10cSrcweir static GType
atk_noop_object_wrapper_get_type(void)59cdf0e10cSrcweir atk_noop_object_wrapper_get_type(void)
60cdf0e10cSrcweir {
61cdf0e10cSrcweir     static GType type = 0;
62cdf0e10cSrcweir 
63cdf0e10cSrcweir     if (!type)
64cdf0e10cSrcweir     {
65cdf0e10cSrcweir         static const GTypeInfo typeInfo =
66cdf0e10cSrcweir         {
67cdf0e10cSrcweir             sizeof (AtkNoOpObjectClass),
68cdf0e10cSrcweir             (GBaseInitFunc) NULL,
69cdf0e10cSrcweir             (GBaseFinalizeFunc) NULL,
70cdf0e10cSrcweir             (GClassInitFunc) atk_noop_object_wrapper_class_init,
71cdf0e10cSrcweir             (GClassFinalizeFunc) NULL,
72cdf0e10cSrcweir             NULL,
73cdf0e10cSrcweir             sizeof (AtkObjectWrapper),
74cdf0e10cSrcweir             0,
75cdf0e10cSrcweir             (GInstanceInitFunc) NULL,
76cdf0e10cSrcweir             NULL
77cdf0e10cSrcweir         } ;
78cdf0e10cSrcweir 
79cdf0e10cSrcweir         type = g_type_register_static (ATK_TYPE_OBJECT, "OOoAtkNoOpObj", &typeInfo, (GTypeFlags)0) ;
80cdf0e10cSrcweir   }
81cdf0e10cSrcweir   return type;
82cdf0e10cSrcweir }
83cdf0e10cSrcweir 
84cdf0e10cSrcweir AtkObject*
atk_noop_object_wrapper_new()85cdf0e10cSrcweir atk_noop_object_wrapper_new()
86cdf0e10cSrcweir {
87cdf0e10cSrcweir   AtkObject *accessible;
88cdf0e10cSrcweir 
89cdf0e10cSrcweir   accessible = (AtkObject *) g_object_new (atk_noop_object_wrapper_get_type(), NULL);
90cdf0e10cSrcweir   g_return_val_if_fail (accessible != NULL, NULL);
91cdf0e10cSrcweir 
92cdf0e10cSrcweir   accessible->role = ATK_ROLE_INVALID;
93cdf0e10cSrcweir   accessible->layer = ATK_LAYER_INVALID;
94cdf0e10cSrcweir 
95cdf0e10cSrcweir   return accessible;
96cdf0e10cSrcweir }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir /*
99cdf0e10cSrcweir  * The wrapper factory
100cdf0e10cSrcweir  */
101cdf0e10cSrcweir 
102cdf0e10cSrcweir static GType
wrapper_factory_get_accessible_type(void)103cdf0e10cSrcweir wrapper_factory_get_accessible_type(void)
104cdf0e10cSrcweir {
105cdf0e10cSrcweir   return atk_object_wrapper_get_type();
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
108cdf0e10cSrcweir static AtkObject*
wrapper_factory_create_accessible(GObject * obj)109cdf0e10cSrcweir wrapper_factory_create_accessible( GObject *obj )
110cdf0e10cSrcweir {
111cdf0e10cSrcweir     GtkWidget* parent_widget = gtk_widget_get_parent( GTK_WIDGET( obj ) );
112cdf0e10cSrcweir 
113cdf0e10cSrcweir     // gail_container_real_remove_gtk tries to re-instanciate an accessible
114cdf0e10cSrcweir     // for a widget that is about to vanish ..
115cdf0e10cSrcweir     if( ! parent_widget )
116cdf0e10cSrcweir         return atk_noop_object_wrapper_new();
117cdf0e10cSrcweir 
118cdf0e10cSrcweir     GtkSalFrame* pFrame = GtkSalFrame::getFromWindow( GTK_WINDOW( parent_widget ) );
119cdf0e10cSrcweir     g_return_val_if_fail( pFrame != NULL, NULL );
120cdf0e10cSrcweir 
121cdf0e10cSrcweir     Window* pFrameWindow = pFrame->GetWindow();
122cdf0e10cSrcweir     if( pFrameWindow )
123cdf0e10cSrcweir     {
124cdf0e10cSrcweir         Window* pWindow = pFrameWindow;
125cdf0e10cSrcweir 
126cdf0e10cSrcweir         // skip accessible objects already exposed by the frame objects
127cdf0e10cSrcweir         if( WINDOW_BORDERWINDOW == pWindow->GetType() )
128cdf0e10cSrcweir             pWindow = pFrameWindow->GetAccessibleChildWindow(0);
129cdf0e10cSrcweir 
130cdf0e10cSrcweir         if( pWindow )
131cdf0e10cSrcweir         {
132cdf0e10cSrcweir              uno::Reference< accessibility::XAccessible > xAccessible = pWindow->GetAccessible(true);
133cdf0e10cSrcweir             if( xAccessible.is() )
134cdf0e10cSrcweir             {
135cdf0e10cSrcweir                 AtkObject *accessible = ooo_wrapper_registry_get( xAccessible );
136cdf0e10cSrcweir 
137cdf0e10cSrcweir                 if( accessible )
138cdf0e10cSrcweir                     g_object_ref( G_OBJECT(accessible) );
139cdf0e10cSrcweir                 else
140cdf0e10cSrcweir                     accessible = atk_object_wrapper_new( xAccessible, gtk_widget_get_accessible(parent_widget) );
141cdf0e10cSrcweir 
142cdf0e10cSrcweir                 return accessible;
143cdf0e10cSrcweir             }
144cdf0e10cSrcweir         }
145cdf0e10cSrcweir     }
146cdf0e10cSrcweir 
147cdf0e10cSrcweir     return NULL;
148cdf0e10cSrcweir }
149cdf0e10cSrcweir 
150cdf0e10cSrcweir static void
wrapper_factory_class_init(AtkObjectFactoryClass * klass)151cdf0e10cSrcweir wrapper_factory_class_init( AtkObjectFactoryClass *klass )
152cdf0e10cSrcweir {
153cdf0e10cSrcweir   klass->create_accessible   = wrapper_factory_create_accessible;
154cdf0e10cSrcweir   klass->get_accessible_type = wrapper_factory_get_accessible_type;
155cdf0e10cSrcweir }
156cdf0e10cSrcweir 
157cdf0e10cSrcweir GType
wrapper_factory_get_type(void)158cdf0e10cSrcweir wrapper_factory_get_type (void)
159cdf0e10cSrcweir {
160cdf0e10cSrcweir   static GType t = 0;
161cdf0e10cSrcweir 
162cdf0e10cSrcweir   if (!t) {
163cdf0e10cSrcweir     static const GTypeInfo tinfo =
164cdf0e10cSrcweir     {
165cdf0e10cSrcweir       sizeof (AtkObjectFactoryClass),
166cdf0e10cSrcweir       NULL, NULL, (GClassInitFunc) wrapper_factory_class_init,
167cdf0e10cSrcweir       NULL, NULL, sizeof (AtkObjectFactory), 0, NULL, NULL
168cdf0e10cSrcweir     };
169cdf0e10cSrcweir 
170cdf0e10cSrcweir     t = g_type_register_static (
171cdf0e10cSrcweir         ATK_TYPE_OBJECT_FACTORY, "OOoAtkObjectWrapperFactory",
172cdf0e10cSrcweir         &tinfo, (GTypeFlags) 0);
173cdf0e10cSrcweir   }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir   return t;
176cdf0e10cSrcweir }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir } // extern C
179cdf0e10cSrcweir 
180