1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: atkhypertext.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
34 #include "atkwrapper.hxx"
36 #include <com/sun/star/accessibility/XAccessibleHypertext.hpp>
40 using namespace ::com::sun::star
;
43 // ---------------------- AtkHyperlink ----------------------
46 AtkHyperlink atk_hyper_link
;
48 uno::Reference
< accessibility::XAccessibleHyperlink
> xLink
;
51 static uno::Reference
< accessibility::XAccessibleHyperlink
>
52 getHyperlink( AtkHyperlink
*pHyperlink
)
54 HyperLink
*pLink
= (HyperLink
*) pHyperlink
;
58 static GObjectClass
*hyper_parent_class
= NULL
;
63 hyper_link_finalize (GObject
*obj
)
65 HyperLink
*hl
= (HyperLink
*) obj
;
67 hyper_parent_class
->finalize (obj
);
71 hyper_link_get_uri( AtkHyperlink
*pLink
,
75 uno::Any aAny
= getHyperlink( pLink
)->getAccessibleActionObject( i
);
76 rtl::OUString aUri
= aAny
.get
< rtl::OUString
> ();
77 return OUStringToGChar(aUri
);
79 catch(const uno::Exception
& e
) {
80 g_warning( "Exception in hyper_link_get_uri" );
86 hyper_link_get_object( AtkHyperlink
*pLink
,
90 uno::Any aAny
= getHyperlink( pLink
)->getAccessibleActionObject( i
);
91 uno::Reference
< accessibility::XAccessible
> xObj( aAny
, uno::UNO_QUERY_THROW
);
92 return atk_object_wrapper_ref( xObj
);
94 catch(const uno::Exception
& e
) {
95 g_warning( "Exception in hyper_link_get_object" );
100 hyper_link_get_end_index( AtkHyperlink
*pLink
)
103 return getHyperlink( pLink
)->getEndIndex();
105 catch(const uno::Exception
& e
) {
110 hyper_link_get_start_index( AtkHyperlink
*pLink
)
113 return getHyperlink( pLink
)->getStartIndex();
115 catch(const uno::Exception
& e
) {
120 hyper_link_is_valid( AtkHyperlink
*pLink
)
123 return getHyperlink( pLink
)->isValid();
125 catch(const uno::Exception
& e
) {
130 hyper_link_get_n_anchors( AtkHyperlink
*pLink
)
133 return getHyperlink( pLink
)->getAccessibleActionCount();
135 catch(const uno::Exception
& e
) {
141 hyper_link_link_state( AtkHyperlink
* )
143 g_warning( "FIXME: hyper_link_link_state unimplemented" );
147 hyper_link_is_selected_link( AtkHyperlink
* )
149 g_warning( "FIXME: hyper_link_is_selected_link unimplemented" );
154 hyper_link_class_init (AtkHyperlinkClass
*klass
)
156 GObjectClass
*gobject_class
= G_OBJECT_CLASS (klass
);
158 gobject_class
->finalize
= hyper_link_finalize
;
160 hyper_parent_class
= (GObjectClass
*)g_type_class_peek_parent (klass
);
162 klass
->get_uri
= hyper_link_get_uri
;
163 klass
->get_object
= hyper_link_get_object
;
164 klass
->get_end_index
= hyper_link_get_end_index
;
165 klass
->get_start_index
= hyper_link_get_start_index
;
166 klass
->is_valid
= hyper_link_is_valid
;
167 klass
->get_n_anchors
= hyper_link_get_n_anchors
;
168 klass
->link_state
= hyper_link_link_state
;
169 klass
->is_selected_link
= hyper_link_is_selected_link
;
173 hyper_link_get_type (void)
175 static GType type
= 0;
178 static const GTypeInfo tinfo
= {
179 sizeof (AtkHyperlinkClass
),
180 NULL
, /* base init */
181 NULL
, /* base finalize */
182 (GClassInitFunc
) hyper_link_class_init
,
183 NULL
, /* class finalize */
184 NULL
, /* class data */
185 sizeof (HyperLink
), /* instance size */
186 0, /* nb preallocs */
187 NULL
, /* instance init */
188 NULL
/* value table */
191 static const GInterfaceInfo atk_action_info
= {
192 (GInterfaceInitFunc
) actionIfaceInit
,
193 (GInterfaceFinalizeFunc
) NULL
,
197 type
= g_type_register_static (ATK_TYPE_HYPERLINK
,
198 "OOoAtkObjHyperLink", &tinfo
,
200 g_type_add_interface_static (type
, ATK_TYPE_ACTION
,
207 // ---------------------- AtkHyperText ----------------------
209 static accessibility::XAccessibleHypertext
*
210 getHypertext( AtkHypertext
*pHypertext
) throw (uno::RuntimeException
)
212 AtkObjectWrapper
*pWrap
= ATK_OBJECT_WRAPPER( pHypertext
);
215 if( !pWrap
->mpHypertext
&& pWrap
->mpContext
)
217 uno::Any any
= pWrap
->mpContext
->queryInterface( accessibility::XAccessibleHypertext::static_type(NULL
) );
218 pWrap
->mpHypertext
= reinterpret_cast< accessibility::XAccessibleHypertext
* > (any
.pReserved
);
219 pWrap
->mpHypertext
->acquire();
222 return pWrap
->mpHypertext
;
229 static AtkHyperlink
*
230 hypertext_get_link( AtkHypertext
*hypertext
,
234 accessibility::XAccessibleHypertext
* pHypertext
= getHypertext( hypertext
);
237 HyperLink
*pLink
= (HyperLink
*)g_object_new( hyper_link_get_type(), NULL
);
238 pLink
->xLink
= pHypertext
->getHyperLink( link_index
);
239 if( !pLink
->xLink
.is() ) {
240 g_object_unref( G_OBJECT( pLink
) );
243 return ATK_HYPERLINK( pLink
);
246 catch(const uno::Exception
& e
) {
247 g_warning( "Exception in getHyperLink()" );
254 hypertext_get_n_links( AtkHypertext
*hypertext
)
257 accessibility::XAccessibleHypertext
* pHypertext
= getHypertext( hypertext
);
259 return pHypertext
->getHyperLinkCount();
261 catch(const uno::Exception
& e
) {
262 g_warning( "Exception in getHyperLinkCount()" );
269 hypertext_get_link_index( AtkHypertext
*hypertext
,
273 accessibility::XAccessibleHypertext
* pHypertext
= getHypertext( hypertext
);
275 return pHypertext
->getHyperLinkIndex( index
);
277 catch(const uno::Exception
& e
) {
278 g_warning( "Exception in getHyperLinkIndex()" );
287 hypertextIfaceInit (AtkHypertextIface
*iface
)
289 g_return_if_fail (iface
!= NULL
);
291 iface
->get_link
= hypertext_get_link
;
292 iface
->get_n_links
= hypertext_get_n_links
;
293 iface
->get_link_index
= hypertext_get_link_index
;