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