1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "atkwrapper.hxx"
22 #include <com/sun/star/accessibility/XAccessibleHypertext.hpp>
26 using namespace ::com::sun::star
;
28 // ---------------------- AtkHyperlink ----------------------
31 AtkHyperlink atk_hyper_link
;
33 uno::Reference
< accessibility::XAccessibleHyperlink
> xLink
;
36 static uno::Reference
< accessibility::XAccessibleHyperlink
>
37 getHyperlink( AtkHyperlink
*pHyperlink
)
39 HyperLink
*pLink
= reinterpret_cast<HyperLink
*>(pHyperlink
);
43 static GObjectClass
*hyper_parent_class
= NULL
;
48 hyper_link_finalize (GObject
*obj
)
50 HyperLink
*hl
= reinterpret_cast<HyperLink
*>(obj
);
52 hyper_parent_class
->finalize (obj
);
56 hyper_link_get_uri( AtkHyperlink
*pLink
,
60 uno::Any aAny
= getHyperlink( pLink
)->getAccessibleActionObject( i
);
61 OUString aUri
= aAny
.get
< OUString
> ();
62 return OUStringToGChar(aUri
);
64 catch(const uno::Exception
&) {
65 g_warning( "Exception in hyper_link_get_uri" );
71 hyper_link_get_object( AtkHyperlink
*pLink
,
75 uno::Any aAny
= getHyperlink( pLink
)->getAccessibleActionObject( i
);
76 uno::Reference
< accessibility::XAccessible
> xObj( aAny
, uno::UNO_QUERY_THROW
);
77 return atk_object_wrapper_ref( xObj
);
79 catch(const uno::Exception
&) {
80 g_warning( "Exception in hyper_link_get_object" );
85 hyper_link_get_end_index( AtkHyperlink
*pLink
)
88 return getHyperlink( pLink
)->getEndIndex();
90 catch(const uno::Exception
&) {
95 hyper_link_get_start_index( AtkHyperlink
*pLink
)
98 return getHyperlink( pLink
)->getStartIndex();
100 catch(const uno::Exception
&) {
105 hyper_link_is_valid( AtkHyperlink
*pLink
)
108 return getHyperlink( pLink
)->isValid();
110 catch(const uno::Exception
&) {
115 hyper_link_get_n_anchors( AtkHyperlink
*pLink
)
118 return getHyperlink( pLink
)->getAccessibleActionCount();
120 catch(const uno::Exception
&) {
126 hyper_link_link_state( AtkHyperlink
* )
128 g_warning( "FIXME: hyper_link_link_state unimplemented" );
132 hyper_link_is_selected_link( AtkHyperlink
* )
134 g_warning( "FIXME: hyper_link_is_selected_link unimplemented" );
139 hyper_link_class_init (AtkHyperlinkClass
*klass
)
141 GObjectClass
*gobject_class
= G_OBJECT_CLASS (klass
);
143 gobject_class
->finalize
= hyper_link_finalize
;
145 hyper_parent_class
= static_cast<GObjectClass
*>(g_type_class_peek_parent (klass
));
147 klass
->get_uri
= hyper_link_get_uri
;
148 klass
->get_object
= hyper_link_get_object
;
149 klass
->get_end_index
= hyper_link_get_end_index
;
150 klass
->get_start_index
= hyper_link_get_start_index
;
151 klass
->is_valid
= hyper_link_is_valid
;
152 klass
->get_n_anchors
= hyper_link_get_n_anchors
;
153 klass
->link_state
= hyper_link_link_state
;
154 klass
->is_selected_link
= hyper_link_is_selected_link
;
158 hyper_link_get_type()
160 static GType type
= 0;
163 static const GTypeInfo tinfo
= {
164 sizeof (AtkHyperlinkClass
),
165 NULL
, /* base init */
166 NULL
, /* base finalize */
167 reinterpret_cast<GClassInitFunc
>(hyper_link_class_init
),
168 NULL
, /* class finalize */
169 NULL
, /* class data */
170 sizeof (HyperLink
), /* instance size */
171 0, /* nb preallocs */
172 NULL
, /* instance init */
173 NULL
/* value table */
176 static const GInterfaceInfo atk_action_info
= {
177 reinterpret_cast<GInterfaceInitFunc
>(actionIfaceInit
),
178 (GInterfaceFinalizeFunc
) NULL
,
182 type
= g_type_register_static (ATK_TYPE_HYPERLINK
,
183 "OOoAtkObjHyperLink", &tinfo
,
185 g_type_add_interface_static (type
, ATK_TYPE_ACTION
,
192 // ---------------------- AtkHyperText ----------------------
194 static accessibility::XAccessibleHypertext
*
195 getHypertext( AtkHypertext
*pHypertext
) throw (uno::RuntimeException
)
197 AtkObjectWrapper
*pWrap
= ATK_OBJECT_WRAPPER( pHypertext
);
200 if( !pWrap
->mpHypertext
&& pWrap
->mpContext
)
202 uno::Any any
= pWrap
->mpContext
->queryInterface( cppu::UnoType
<accessibility::XAccessibleHypertext
>::get() );
203 pWrap
->mpHypertext
= static_cast< accessibility::XAccessibleHypertext
* > (any
.pReserved
);
204 pWrap
->mpHypertext
->acquire();
207 return pWrap
->mpHypertext
;
213 static AtkHyperlink
*
214 hypertext_get_link( AtkHypertext
*hypertext
,
218 accessibility::XAccessibleHypertext
* pHypertext
= getHypertext( hypertext
);
221 HyperLink
*pLink
= static_cast<HyperLink
*>(g_object_new( hyper_link_get_type(), NULL
));
222 pLink
->xLink
= pHypertext
->getHyperLink( link_index
);
223 if( !pLink
->xLink
.is() ) {
224 g_object_unref( G_OBJECT( pLink
) );
227 return ATK_HYPERLINK( pLink
);
230 catch(const uno::Exception
&) {
231 g_warning( "Exception in getHyperLink()" );
238 hypertext_get_n_links( AtkHypertext
*hypertext
)
241 accessibility::XAccessibleHypertext
* pHypertext
= getHypertext( hypertext
);
243 return pHypertext
->getHyperLinkCount();
245 catch(const uno::Exception
&) {
246 g_warning( "Exception in getHyperLinkCount()" );
253 hypertext_get_link_index( AtkHypertext
*hypertext
,
257 accessibility::XAccessibleHypertext
* pHypertext
= getHypertext( hypertext
);
259 return pHypertext
->getHyperLinkIndex( index
);
261 catch(const uno::Exception
&) {
262 g_warning( "Exception in getHyperLinkIndex()" );
271 hypertextIfaceInit (AtkHypertextIface
*iface
)
273 g_return_if_fail (iface
!= NULL
);
275 iface
->get_link
= hypertext_get_link
;
276 iface
->get_n_links
= hypertext_get_n_links
;
277 iface
->get_link_index
= hypertext_get_link_index
;
280 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */