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>
24 using namespace ::com::sun::star
;
26 // ---------------------- AtkHyperlink ----------------------
31 AtkHyperlink
const atk_hyper_link
;
33 uno::Reference
< accessibility::XAccessibleHyperlink
> xLink
;
38 static uno::Reference
< accessibility::XAccessibleHyperlink
> const &
39 getHyperlink( AtkHyperlink
*pHyperlink
)
41 HyperLink
*pLink
= reinterpret_cast<HyperLink
*>(pHyperlink
);
45 static GObjectClass
*hyper_parent_class
= nullptr;
50 hyper_link_finalize (GObject
*obj
)
52 HyperLink
*hl
= reinterpret_cast<HyperLink
*>(obj
);
54 hyper_parent_class
->finalize (obj
);
58 hyper_link_get_uri( AtkHyperlink
*pLink
,
62 uno::Any aAny
= getHyperlink( pLink
)->getAccessibleActionObject( i
);
63 OUString aUri
= aAny
.get
< OUString
> ();
64 return OUStringToGChar(aUri
);
66 catch(const uno::Exception
&) {
67 g_warning( "Exception in hyper_link_get_uri" );
73 hyper_link_get_object( AtkHyperlink
*,
76 g_warning( "FIXME: hyper_link_get_object unimplemented" );
80 hyper_link_get_end_index( AtkHyperlink
*pLink
)
83 return getHyperlink( pLink
)->getEndIndex();
85 catch(const uno::Exception
&) {
90 hyper_link_get_start_index( AtkHyperlink
*pLink
)
93 return getHyperlink( pLink
)->getStartIndex();
95 catch(const uno::Exception
&) {
100 hyper_link_is_valid( AtkHyperlink
*pLink
)
103 return getHyperlink( pLink
)->isValid();
105 catch(const uno::Exception
&) {
110 hyper_link_get_n_anchors( AtkHyperlink
*pLink
)
113 return getHyperlink( pLink
)->getAccessibleActionCount();
115 catch(const uno::Exception
&) {
121 hyper_link_link_state( AtkHyperlink
* )
123 g_warning( "FIXME: hyper_link_link_state unimplemented" );
127 hyper_link_is_selected_link( AtkHyperlink
* )
129 g_warning( "FIXME: hyper_link_is_selected_link unimplemented" );
134 hyper_link_class_init (gpointer klass_
, gpointer
)
136 auto const klass
= static_cast<AtkHyperlinkClass
*>(klass_
);
137 GObjectClass
*gobject_class
= G_OBJECT_CLASS (klass
);
139 gobject_class
->finalize
= hyper_link_finalize
;
141 hyper_parent_class
= static_cast<GObjectClass
*>(g_type_class_peek_parent (klass
));
143 klass
->get_uri
= hyper_link_get_uri
;
144 klass
->get_object
= hyper_link_get_object
;
145 klass
->get_end_index
= hyper_link_get_end_index
;
146 klass
->get_start_index
= hyper_link_get_start_index
;
147 klass
->is_valid
= hyper_link_is_valid
;
148 klass
->get_n_anchors
= hyper_link_get_n_anchors
;
149 klass
->link_state
= hyper_link_link_state
;
150 klass
->is_selected_link
= hyper_link_is_selected_link
;
154 hyper_link_get_type()
156 static GType type
= 0;
159 static const GTypeInfo tinfo
= {
160 sizeof (AtkHyperlinkClass
),
161 nullptr, /* base init */
162 nullptr, /* base finalize */
163 hyper_link_class_init
,
164 nullptr, /* class finalize */
165 nullptr, /* class data */
166 sizeof (HyperLink
), /* instance size */
167 0, /* nb preallocs */
168 nullptr, /* instance init */
169 nullptr /* value table */
172 static const GInterfaceInfo atk_action_info
= {
178 type
= g_type_register_static (ATK_TYPE_HYPERLINK
,
179 "OOoAtkObjHyperLink", &tinfo
,
181 g_type_add_interface_static (type
, ATK_TYPE_ACTION
,
188 // ---------------------- AtkHyperText ----------------------
190 /// @throws uno::RuntimeException
191 static css::uno::Reference
<css::accessibility::XAccessibleHypertext
>
192 getHypertext( AtkHypertext
*pHypertext
)
194 AtkObjectWrapper
*pWrap
= ATK_OBJECT_WRAPPER( pHypertext
);
197 if( !pWrap
->mpHypertext
.is() )
199 pWrap
->mpHypertext
.set(pWrap
->mpContext
, css::uno::UNO_QUERY
);
202 return pWrap
->mpHypertext
;
205 return css::uno::Reference
<css::accessibility::XAccessibleHypertext
>();
208 static AtkHyperlink
*
209 hypertext_get_link( AtkHypertext
*hypertext
,
213 css::uno::Reference
<css::accessibility::XAccessibleHypertext
> pHypertext
214 = getHypertext( hypertext
);
215 if( pHypertext
.is() )
217 HyperLink
*pLink
= static_cast<HyperLink
*>(g_object_new( hyper_link_get_type(), nullptr ));
218 pLink
->xLink
= pHypertext
->getHyperLink( link_index
);
219 if( !pLink
->xLink
.is() ) {
220 g_object_unref( G_OBJECT( pLink
) );
223 return ATK_HYPERLINK( pLink
);
226 catch(const uno::Exception
&) {
227 g_warning( "Exception in getHyperLink()" );
234 hypertext_get_n_links( AtkHypertext
*hypertext
)
237 css::uno::Reference
<css::accessibility::XAccessibleHypertext
> pHypertext
238 = getHypertext( hypertext
);
239 if( pHypertext
.is() )
240 return pHypertext
->getHyperLinkCount();
242 catch(const uno::Exception
&) {
243 g_warning( "Exception in getHyperLinkCount()" );
250 hypertext_get_link_index( AtkHypertext
*hypertext
,
254 css::uno::Reference
<css::accessibility::XAccessibleHypertext
> pHypertext
255 = getHypertext( hypertext
);
256 if( pHypertext
.is() )
257 return pHypertext
->getHyperLinkIndex( index
);
259 catch(const uno::Exception
&) {
260 g_warning( "Exception in getHyperLinkIndex()" );
269 hypertextIfaceInit (gpointer iface_
, gpointer
)
271 auto const iface
= static_cast<AtkHypertextIface
*>(iface_
);
272 g_return_if_fail (iface
!= nullptr);
274 iface
->get_link
= hypertext_get_link
;
275 iface
->get_n_links
= hypertext_get_n_links
;
276 iface
->get_link_index
= hypertext_get_link_index
;
279 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */