xref: /aoo42x/main/vcl/unx/gtk/a11y/atkhypertext.cxx (revision 9f62ea84)
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
10*9f62ea84SAndrew Rist  *
11*9f62ea84SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9f62ea84SAndrew Rist  *
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.
19*9f62ea84SAndrew Rist  *
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 "atkwrapper.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessibleHypertext.hpp>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <stdio.h>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir using namespace ::com::sun::star;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir 
36cdf0e10cSrcweir // ---------------------- AtkHyperlink ----------------------
37cdf0e10cSrcweir 
38cdf0e10cSrcweir typedef struct {
39cdf0e10cSrcweir     AtkHyperlink atk_hyper_link;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir     uno::Reference< accessibility::XAccessibleHyperlink > xLink;
42cdf0e10cSrcweir } HyperLink;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir static uno::Reference< accessibility::XAccessibleHyperlink >
getHyperlink(AtkHyperlink * pHyperlink)45cdf0e10cSrcweir     getHyperlink( AtkHyperlink *pHyperlink )
46cdf0e10cSrcweir {
47cdf0e10cSrcweir     HyperLink *pLink = (HyperLink *) pHyperlink;
48cdf0e10cSrcweir     return pLink->xLink;
49cdf0e10cSrcweir }
50cdf0e10cSrcweir 
51cdf0e10cSrcweir static GObjectClass *hyper_parent_class = NULL;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir extern "C" {
54cdf0e10cSrcweir 
55cdf0e10cSrcweir static void
hyper_link_finalize(GObject * obj)56cdf0e10cSrcweir hyper_link_finalize (GObject *obj)
57cdf0e10cSrcweir {
58cdf0e10cSrcweir     HyperLink *hl = (HyperLink *) obj;
59cdf0e10cSrcweir     hl->xLink.clear();
60cdf0e10cSrcweir     hyper_parent_class->finalize (obj);
61cdf0e10cSrcweir }
62cdf0e10cSrcweir 
63cdf0e10cSrcweir static gchar *
hyper_link_get_uri(AtkHyperlink * pLink,gint i)64cdf0e10cSrcweir hyper_link_get_uri( AtkHyperlink *pLink,
65cdf0e10cSrcweir                     gint          i )
66cdf0e10cSrcweir {
67cdf0e10cSrcweir     try {
68cdf0e10cSrcweir         uno::Any aAny = getHyperlink( pLink )->getAccessibleActionObject( i );
69cdf0e10cSrcweir         rtl::OUString aUri = aAny.get< rtl::OUString > ();
70cdf0e10cSrcweir         return OUStringToGChar(aUri);
71cdf0e10cSrcweir     }
72cdf0e10cSrcweir     catch(const uno::Exception& e) {
73cdf0e10cSrcweir         g_warning( "Exception in hyper_link_get_uri" );
74cdf0e10cSrcweir     }
75cdf0e10cSrcweir     return NULL;
76cdf0e10cSrcweir }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir static AtkObject *
hyper_link_get_object(AtkHyperlink * pLink,gint i)79cdf0e10cSrcweir hyper_link_get_object( AtkHyperlink *pLink,
80cdf0e10cSrcweir                        gint          i)
81cdf0e10cSrcweir {
82cdf0e10cSrcweir     try {
83cdf0e10cSrcweir         uno::Any aAny = getHyperlink( pLink )->getAccessibleActionObject( i );
84cdf0e10cSrcweir         uno::Reference< accessibility::XAccessible > xObj( aAny, uno::UNO_QUERY_THROW );
85cdf0e10cSrcweir         return atk_object_wrapper_ref( xObj );
86cdf0e10cSrcweir     }
87cdf0e10cSrcweir     catch(const uno::Exception& e) {
88cdf0e10cSrcweir         g_warning( "Exception in hyper_link_get_object" );
89cdf0e10cSrcweir     }
90cdf0e10cSrcweir     return NULL;
91cdf0e10cSrcweir }
92cdf0e10cSrcweir static gint
hyper_link_get_end_index(AtkHyperlink * pLink)93cdf0e10cSrcweir hyper_link_get_end_index( AtkHyperlink *pLink )
94cdf0e10cSrcweir {
95cdf0e10cSrcweir     try {
96cdf0e10cSrcweir         return getHyperlink( pLink )->getEndIndex();
97cdf0e10cSrcweir     }
98cdf0e10cSrcweir     catch(const uno::Exception& e) {
99cdf0e10cSrcweir     }
100cdf0e10cSrcweir     return -1;
101cdf0e10cSrcweir }
102cdf0e10cSrcweir static gint
hyper_link_get_start_index(AtkHyperlink * pLink)103cdf0e10cSrcweir hyper_link_get_start_index( AtkHyperlink *pLink )
104cdf0e10cSrcweir {
105cdf0e10cSrcweir     try {
106cdf0e10cSrcweir         return getHyperlink( pLink )->getStartIndex();
107cdf0e10cSrcweir     }
108cdf0e10cSrcweir     catch(const uno::Exception& e) {
109cdf0e10cSrcweir     }
110cdf0e10cSrcweir     return -1;
111cdf0e10cSrcweir }
112cdf0e10cSrcweir static gboolean
hyper_link_is_valid(AtkHyperlink * pLink)113cdf0e10cSrcweir hyper_link_is_valid( AtkHyperlink *pLink )
114cdf0e10cSrcweir {
115cdf0e10cSrcweir     try {
116cdf0e10cSrcweir         return getHyperlink( pLink )->isValid();
117cdf0e10cSrcweir     }
118cdf0e10cSrcweir     catch(const uno::Exception& e) {
119cdf0e10cSrcweir     }
120cdf0e10cSrcweir     return FALSE;
121cdf0e10cSrcweir }
122cdf0e10cSrcweir static gint
hyper_link_get_n_anchors(AtkHyperlink * pLink)123cdf0e10cSrcweir hyper_link_get_n_anchors( AtkHyperlink *pLink )
124cdf0e10cSrcweir {
125cdf0e10cSrcweir     try {
126cdf0e10cSrcweir         return getHyperlink( pLink )->getAccessibleActionCount();
127cdf0e10cSrcweir     }
128cdf0e10cSrcweir     catch(const uno::Exception& e) {
129cdf0e10cSrcweir     }
130cdf0e10cSrcweir     return 0;
131cdf0e10cSrcweir }
132cdf0e10cSrcweir 
133cdf0e10cSrcweir static guint
hyper_link_link_state(AtkHyperlink *)134cdf0e10cSrcweir hyper_link_link_state( AtkHyperlink * )
135cdf0e10cSrcweir {
136cdf0e10cSrcweir     g_warning( "FIXME: hyper_link_link_state unimplemented" );
137cdf0e10cSrcweir     return 0;
138cdf0e10cSrcweir }
139cdf0e10cSrcweir static gboolean
hyper_link_is_selected_link(AtkHyperlink *)140cdf0e10cSrcweir hyper_link_is_selected_link( AtkHyperlink * )
141cdf0e10cSrcweir {
142cdf0e10cSrcweir     g_warning( "FIXME: hyper_link_is_selected_link unimplemented" );
143cdf0e10cSrcweir     return FALSE;
144cdf0e10cSrcweir }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir static void
hyper_link_class_init(AtkHyperlinkClass * klass)147cdf0e10cSrcweir hyper_link_class_init (AtkHyperlinkClass *klass)
148cdf0e10cSrcweir {
149cdf0e10cSrcweir     GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
150cdf0e10cSrcweir 
151cdf0e10cSrcweir     gobject_class->finalize = hyper_link_finalize;
152cdf0e10cSrcweir 
153cdf0e10cSrcweir     hyper_parent_class = (GObjectClass *)g_type_class_peek_parent (klass);
154cdf0e10cSrcweir 
155cdf0e10cSrcweir     klass->get_uri = hyper_link_get_uri;
156cdf0e10cSrcweir     klass->get_object = hyper_link_get_object;
157cdf0e10cSrcweir     klass->get_end_index = hyper_link_get_end_index;
158cdf0e10cSrcweir     klass->get_start_index = hyper_link_get_start_index;
159cdf0e10cSrcweir     klass->is_valid = hyper_link_is_valid;
160cdf0e10cSrcweir     klass->get_n_anchors = hyper_link_get_n_anchors;
161cdf0e10cSrcweir     klass->link_state = hyper_link_link_state;
162cdf0e10cSrcweir     klass->is_selected_link = hyper_link_is_selected_link;
163cdf0e10cSrcweir }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir static GType
hyper_link_get_type(void)166cdf0e10cSrcweir hyper_link_get_type (void)
167cdf0e10cSrcweir {
168cdf0e10cSrcweir     static GType type = 0;
169cdf0e10cSrcweir 
170cdf0e10cSrcweir     if (!type) {
171cdf0e10cSrcweir         static const GTypeInfo tinfo = {
172cdf0e10cSrcweir             sizeof (AtkHyperlinkClass),
173cdf0e10cSrcweir             NULL,               /* base init */
174cdf0e10cSrcweir             NULL,               /* base finalize */
175cdf0e10cSrcweir             (GClassInitFunc) hyper_link_class_init,
176cdf0e10cSrcweir             NULL,               /* class finalize */
177cdf0e10cSrcweir             NULL,               /* class data */
178cdf0e10cSrcweir             sizeof (HyperLink), /* instance size */
179cdf0e10cSrcweir             0,                  /* nb preallocs */
180cdf0e10cSrcweir             NULL,               /* instance init */
181cdf0e10cSrcweir             NULL                /* value table */
182cdf0e10cSrcweir         };
183cdf0e10cSrcweir 
184cdf0e10cSrcweir         static const GInterfaceInfo atk_action_info = {
185cdf0e10cSrcweir             (GInterfaceInitFunc) actionIfaceInit,
186cdf0e10cSrcweir             (GInterfaceFinalizeFunc) NULL,
187cdf0e10cSrcweir             NULL
188cdf0e10cSrcweir         };
189cdf0e10cSrcweir 
190cdf0e10cSrcweir         type = g_type_register_static (ATK_TYPE_HYPERLINK,
191cdf0e10cSrcweir                                        "OOoAtkObjHyperLink", &tinfo,
192cdf0e10cSrcweir                                        (GTypeFlags)0);
193cdf0e10cSrcweir         g_type_add_interface_static (type, ATK_TYPE_ACTION,
194cdf0e10cSrcweir                                      &atk_action_info);
195cdf0e10cSrcweir     }
196cdf0e10cSrcweir 
197cdf0e10cSrcweir     return type;
198cdf0e10cSrcweir }
199cdf0e10cSrcweir 
200cdf0e10cSrcweir // ---------------------- AtkHyperText ----------------------
201cdf0e10cSrcweir 
202cdf0e10cSrcweir static accessibility::XAccessibleHypertext*
getHypertext(AtkHypertext * pHypertext)203cdf0e10cSrcweir     getHypertext( AtkHypertext *pHypertext ) throw (uno::RuntimeException)
204cdf0e10cSrcweir {
205cdf0e10cSrcweir     AtkObjectWrapper *pWrap = ATK_OBJECT_WRAPPER( pHypertext );
206cdf0e10cSrcweir     if( pWrap )
207cdf0e10cSrcweir     {
208cdf0e10cSrcweir         if( !pWrap->mpHypertext && pWrap->mpContext )
209cdf0e10cSrcweir         {
210cdf0e10cSrcweir             uno::Any any = pWrap->mpContext->queryInterface( accessibility::XAccessibleHypertext::static_type(NULL) );
211cdf0e10cSrcweir             pWrap->mpHypertext = reinterpret_cast< accessibility::XAccessibleHypertext * > (any.pReserved);
212cdf0e10cSrcweir             pWrap->mpHypertext->acquire();
213cdf0e10cSrcweir         }
214cdf0e10cSrcweir 
215cdf0e10cSrcweir         return pWrap->mpHypertext;
216cdf0e10cSrcweir     }
217cdf0e10cSrcweir 
218cdf0e10cSrcweir     return NULL;
219cdf0e10cSrcweir }
220cdf0e10cSrcweir 
221cdf0e10cSrcweir 
222cdf0e10cSrcweir static AtkHyperlink *
hypertext_get_link(AtkHypertext * hypertext,gint link_index)223cdf0e10cSrcweir hypertext_get_link( AtkHypertext *hypertext,
224cdf0e10cSrcweir                     gint          link_index)
225cdf0e10cSrcweir {
226cdf0e10cSrcweir     try {
227cdf0e10cSrcweir         accessibility::XAccessibleHypertext* pHypertext = getHypertext( hypertext );
228cdf0e10cSrcweir         if( pHypertext )
229cdf0e10cSrcweir         {
230cdf0e10cSrcweir             HyperLink *pLink = (HyperLink *)g_object_new( hyper_link_get_type(), NULL );
231cdf0e10cSrcweir             pLink->xLink = pHypertext->getHyperLink( link_index );
232cdf0e10cSrcweir             if( !pLink->xLink.is() ) {
233cdf0e10cSrcweir                 g_object_unref( G_OBJECT( pLink ) );
234cdf0e10cSrcweir                 pLink = NULL;
235cdf0e10cSrcweir             }
236cdf0e10cSrcweir             return ATK_HYPERLINK( pLink );
237cdf0e10cSrcweir         }
238cdf0e10cSrcweir     }
239cdf0e10cSrcweir     catch(const uno::Exception& e) {
240cdf0e10cSrcweir         g_warning( "Exception in getHyperLink()" );
241cdf0e10cSrcweir     }
242cdf0e10cSrcweir 
243cdf0e10cSrcweir     return NULL;
244cdf0e10cSrcweir }
245cdf0e10cSrcweir 
246cdf0e10cSrcweir static gint
hypertext_get_n_links(AtkHypertext * hypertext)247cdf0e10cSrcweir hypertext_get_n_links( AtkHypertext *hypertext )
248cdf0e10cSrcweir {
249cdf0e10cSrcweir     try {
250cdf0e10cSrcweir         accessibility::XAccessibleHypertext* pHypertext = getHypertext( hypertext );
251cdf0e10cSrcweir         if( pHypertext )
252cdf0e10cSrcweir             return pHypertext->getHyperLinkCount();
253cdf0e10cSrcweir     }
254cdf0e10cSrcweir     catch(const uno::Exception& e) {
255cdf0e10cSrcweir         g_warning( "Exception in getHyperLinkCount()" );
256cdf0e10cSrcweir     }
257cdf0e10cSrcweir 
258cdf0e10cSrcweir     return 0;
259cdf0e10cSrcweir }
260cdf0e10cSrcweir 
261cdf0e10cSrcweir static gint
hypertext_get_link_index(AtkHypertext * hypertext,gint index)262cdf0e10cSrcweir hypertext_get_link_index( AtkHypertext *hypertext,
263cdf0e10cSrcweir                           gint          index)
264cdf0e10cSrcweir {
265cdf0e10cSrcweir     try {
266cdf0e10cSrcweir         accessibility::XAccessibleHypertext* pHypertext = getHypertext( hypertext );
267cdf0e10cSrcweir         if( pHypertext )
268cdf0e10cSrcweir             return pHypertext->getHyperLinkIndex( index );
269cdf0e10cSrcweir     }
270cdf0e10cSrcweir     catch(const uno::Exception& e) {
271cdf0e10cSrcweir         g_warning( "Exception in getHyperLinkIndex()" );
272cdf0e10cSrcweir     }
273cdf0e10cSrcweir 
274cdf0e10cSrcweir     return 0;
275cdf0e10cSrcweir }
276cdf0e10cSrcweir 
277cdf0e10cSrcweir } // extern "C"
278cdf0e10cSrcweir 
279cdf0e10cSrcweir void
hypertextIfaceInit(AtkHypertextIface * iface)280cdf0e10cSrcweir hypertextIfaceInit (AtkHypertextIface *iface)
281cdf0e10cSrcweir {
282cdf0e10cSrcweir   g_return_if_fail (iface != NULL);
283cdf0e10cSrcweir 
284cdf0e10cSrcweir   iface->get_link = hypertext_get_link;
285cdf0e10cSrcweir   iface->get_n_links = hypertext_get_n_links;
286cdf0e10cSrcweir   iface->get_link_index = hypertext_get_link_index;
287cdf0e10cSrcweir }
288