1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_vcl.hxx" 30 31 #include "atkwrapper.hxx" 32 33 #include <com/sun/star/accessibility/XAccessibleImage.hpp> 34 35 #include <stdio.h> 36 37 using namespace ::com::sun::star; 38 39 // FIXME 40 static G_CONST_RETURN gchar * 41 getAsConst( rtl::OUString rString ) 42 { 43 static const int nMax = 10; 44 static rtl::OString aUgly[nMax]; 45 static int nIdx = 0; 46 nIdx = (nIdx + 1) % nMax; 47 aUgly[nIdx] = rtl::OUStringToOString( rString, RTL_TEXTENCODING_UTF8 ); 48 return aUgly[ nIdx ]; 49 } 50 51 static accessibility::XAccessibleImage* 52 getImage( AtkImage *pImage ) throw (uno::RuntimeException) 53 { 54 AtkObjectWrapper *pWrap = ATK_OBJECT_WRAPPER( pImage ); 55 if( pWrap ) 56 { 57 if( !pWrap->mpImage && pWrap->mpContext ) 58 { 59 uno::Any any = pWrap->mpContext->queryInterface( accessibility::XAccessibleImage::static_type(NULL) ); 60 pWrap->mpImage = reinterpret_cast< accessibility::XAccessibleImage * > (any.pReserved); 61 pWrap->mpImage->acquire(); 62 } 63 64 return pWrap->mpImage; 65 } 66 67 return NULL; 68 } 69 70 extern "C" { 71 72 static G_CONST_RETURN gchar * 73 image_get_image_description( AtkImage *image ) 74 { 75 try { 76 accessibility::XAccessibleImage* pImage = getImage( image ); 77 if( pImage ) 78 return getAsConst( pImage->getAccessibleImageDescription() ); 79 } 80 catch(const uno::Exception& e) { 81 g_warning( "Exception in getAccessibleImageDescription()" ); 82 } 83 84 return NULL; 85 } 86 87 static void 88 image_get_image_position( AtkImage *image, 89 gint *x, 90 gint *y, 91 AtkCoordType coord_type ) 92 { 93 *x = *y = 0; 94 if( ATK_IS_COMPONENT( image ) ) 95 atk_component_get_position( ATK_COMPONENT( image ), x, y, coord_type ); 96 else 97 g_warning( "FIXME: no image position information" ); 98 } 99 100 static void 101 image_get_image_size( AtkImage *image, 102 gint *width, 103 gint *height ) 104 { 105 *width = 0; 106 *height = 0; 107 try { 108 accessibility::XAccessibleImage* pImage = getImage( image ); 109 if( pImage ) 110 { 111 *width = pImage->getAccessibleImageWidth(); 112 *height = pImage->getAccessibleImageHeight(); 113 } 114 } 115 catch(const uno::Exception& e) { 116 g_warning( "Exception in getAccessibleImageHeight() or Width" ); 117 } 118 } 119 120 static gboolean 121 image_set_image_description( AtkImage *, const gchar * ) 122 { 123 g_warning ("FIXME: no set image description"); 124 return FALSE; 125 } 126 127 } // extern "C" 128 129 void 130 imageIfaceInit (AtkImageIface *iface) 131 { 132 g_return_if_fail (iface != NULL); 133 134 iface->set_image_description = image_set_image_description; 135 iface->get_image_description = image_get_image_description; 136 iface->get_image_position = image_get_image_position; 137 iface->get_image_size = image_get_image_size; 138 } 139