1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_vcl.hxx" 26 27 #include "atkwrapper.hxx" 28 29 #include <com/sun/star/accessibility/XAccessibleHypertext.hpp> 30 31 #include <stdio.h> 32 33 using namespace ::com::sun::star; 34 35 36 // ---------------------- AtkHyperlink ---------------------- 37 38 typedef struct { 39 AtkHyperlink atk_hyper_link; 40 41 uno::Reference< accessibility::XAccessibleHyperlink > xLink; 42 } HyperLink; 43 44 static uno::Reference< accessibility::XAccessibleHyperlink > 45 getHyperlink( AtkHyperlink *pHyperlink ) 46 { 47 HyperLink *pLink = (HyperLink *) pHyperlink; 48 return pLink->xLink; 49 } 50 51 static GObjectClass *hyper_parent_class = NULL; 52 53 extern "C" { 54 55 static void 56 hyper_link_finalize (GObject *obj) 57 { 58 HyperLink *hl = (HyperLink *) obj; 59 hl->xLink.clear(); 60 hyper_parent_class->finalize (obj); 61 } 62 63 static gchar * 64 hyper_link_get_uri( AtkHyperlink *pLink, 65 gint i ) 66 { 67 try { 68 uno::Any aAny = getHyperlink( pLink )->getAccessibleActionObject( i ); 69 rtl::OUString aUri = aAny.get< rtl::OUString > (); 70 return OUStringToGChar(aUri); 71 } 72 catch(const uno::Exception& e) { 73 g_warning( "Exception in hyper_link_get_uri" ); 74 } 75 return NULL; 76 } 77 78 static AtkObject * 79 hyper_link_get_object( AtkHyperlink *pLink, 80 gint i) 81 { 82 try { 83 uno::Any aAny = getHyperlink( pLink )->getAccessibleActionObject( i ); 84 uno::Reference< accessibility::XAccessible > xObj( aAny, uno::UNO_QUERY_THROW ); 85 return atk_object_wrapper_ref( xObj ); 86 } 87 catch(const uno::Exception& e) { 88 g_warning( "Exception in hyper_link_get_object" ); 89 } 90 return NULL; 91 } 92 static gint 93 hyper_link_get_end_index( AtkHyperlink *pLink ) 94 { 95 try { 96 return getHyperlink( pLink )->getEndIndex(); 97 } 98 catch(const uno::Exception& e) { 99 } 100 return -1; 101 } 102 static gint 103 hyper_link_get_start_index( AtkHyperlink *pLink ) 104 { 105 try { 106 return getHyperlink( pLink )->getStartIndex(); 107 } 108 catch(const uno::Exception& e) { 109 } 110 return -1; 111 } 112 static gboolean 113 hyper_link_is_valid( AtkHyperlink *pLink ) 114 { 115 try { 116 return getHyperlink( pLink )->isValid(); 117 } 118 catch(const uno::Exception& e) { 119 } 120 return FALSE; 121 } 122 static gint 123 hyper_link_get_n_anchors( AtkHyperlink *pLink ) 124 { 125 try { 126 return getHyperlink( pLink )->getAccessibleActionCount(); 127 } 128 catch(const uno::Exception& e) { 129 } 130 return 0; 131 } 132 133 static guint 134 hyper_link_link_state( AtkHyperlink * ) 135 { 136 g_warning( "FIXME: hyper_link_link_state unimplemented" ); 137 return 0; 138 } 139 static gboolean 140 hyper_link_is_selected_link( AtkHyperlink * ) 141 { 142 g_warning( "FIXME: hyper_link_is_selected_link unimplemented" ); 143 return FALSE; 144 } 145 146 static void 147 hyper_link_class_init (AtkHyperlinkClass *klass) 148 { 149 GObjectClass *gobject_class = G_OBJECT_CLASS (klass); 150 151 gobject_class->finalize = hyper_link_finalize; 152 153 hyper_parent_class = (GObjectClass *)g_type_class_peek_parent (klass); 154 155 klass->get_uri = hyper_link_get_uri; 156 klass->get_object = hyper_link_get_object; 157 klass->get_end_index = hyper_link_get_end_index; 158 klass->get_start_index = hyper_link_get_start_index; 159 klass->is_valid = hyper_link_is_valid; 160 klass->get_n_anchors = hyper_link_get_n_anchors; 161 klass->link_state = hyper_link_link_state; 162 klass->is_selected_link = hyper_link_is_selected_link; 163 } 164 165 static GType 166 hyper_link_get_type (void) 167 { 168 static GType type = 0; 169 170 if (!type) { 171 static const GTypeInfo tinfo = { 172 sizeof (AtkHyperlinkClass), 173 NULL, /* base init */ 174 NULL, /* base finalize */ 175 (GClassInitFunc) hyper_link_class_init, 176 NULL, /* class finalize */ 177 NULL, /* class data */ 178 sizeof (HyperLink), /* instance size */ 179 0, /* nb preallocs */ 180 NULL, /* instance init */ 181 NULL /* value table */ 182 }; 183 184 static const GInterfaceInfo atk_action_info = { 185 (GInterfaceInitFunc) actionIfaceInit, 186 (GInterfaceFinalizeFunc) NULL, 187 NULL 188 }; 189 190 type = g_type_register_static (ATK_TYPE_HYPERLINK, 191 "OOoAtkObjHyperLink", &tinfo, 192 (GTypeFlags)0); 193 g_type_add_interface_static (type, ATK_TYPE_ACTION, 194 &atk_action_info); 195 } 196 197 return type; 198 } 199 200 // ---------------------- AtkHyperText ---------------------- 201 202 static accessibility::XAccessibleHypertext* 203 getHypertext( AtkHypertext *pHypertext ) throw (uno::RuntimeException) 204 { 205 AtkObjectWrapper *pWrap = ATK_OBJECT_WRAPPER( pHypertext ); 206 if( pWrap ) 207 { 208 if( !pWrap->mpHypertext && pWrap->mpContext ) 209 { 210 uno::Any any = pWrap->mpContext->queryInterface( accessibility::XAccessibleHypertext::static_type(NULL) ); 211 pWrap->mpHypertext = reinterpret_cast< accessibility::XAccessibleHypertext * > (any.pReserved); 212 pWrap->mpHypertext->acquire(); 213 } 214 215 return pWrap->mpHypertext; 216 } 217 218 return NULL; 219 } 220 221 222 static AtkHyperlink * 223 hypertext_get_link( AtkHypertext *hypertext, 224 gint link_index) 225 { 226 try { 227 accessibility::XAccessibleHypertext* pHypertext = getHypertext( hypertext ); 228 if( pHypertext ) 229 { 230 HyperLink *pLink = (HyperLink *)g_object_new( hyper_link_get_type(), NULL ); 231 pLink->xLink = pHypertext->getHyperLink( link_index ); 232 if( !pLink->xLink.is() ) { 233 g_object_unref( G_OBJECT( pLink ) ); 234 pLink = NULL; 235 } 236 return ATK_HYPERLINK( pLink ); 237 } 238 } 239 catch(const uno::Exception& e) { 240 g_warning( "Exception in getHyperLink()" ); 241 } 242 243 return NULL; 244 } 245 246 static gint 247 hypertext_get_n_links( AtkHypertext *hypertext ) 248 { 249 try { 250 accessibility::XAccessibleHypertext* pHypertext = getHypertext( hypertext ); 251 if( pHypertext ) 252 return pHypertext->getHyperLinkCount(); 253 } 254 catch(const uno::Exception& e) { 255 g_warning( "Exception in getHyperLinkCount()" ); 256 } 257 258 return 0; 259 } 260 261 static gint 262 hypertext_get_link_index( AtkHypertext *hypertext, 263 gint index) 264 { 265 try { 266 accessibility::XAccessibleHypertext* pHypertext = getHypertext( hypertext ); 267 if( pHypertext ) 268 return pHypertext->getHyperLinkIndex( index ); 269 } 270 catch(const uno::Exception& e) { 271 g_warning( "Exception in getHyperLinkIndex()" ); 272 } 273 274 return 0; 275 } 276 277 } // extern "C" 278 279 void 280 hypertextIfaceInit (AtkHypertextIface *iface) 281 { 282 g_return_if_fail (iface != NULL); 283 284 iface->get_link = hypertext_get_link; 285 iface->get_n_links = hypertext_get_n_links; 286 iface->get_link_index = hypertext_get_link_index; 287 } 288