xref: /aoo4110/main/vcl/unx/gtk/a11y/atkimage.cxx (revision b1cdbd2c)
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/XAccessibleImage.hpp>
30 
31 #include <stdio.h>
32 
33 using namespace ::com::sun::star;
34 
35 // FIXME
36 static G_CONST_RETURN gchar *
getAsConst(rtl::OUString rString)37 getAsConst( rtl::OUString rString )
38 {
39     static const int nMax = 10;
40     static rtl::OString aUgly[nMax];
41     static int nIdx = 0;
42     nIdx = (nIdx + 1) % nMax;
43     aUgly[nIdx] = rtl::OUStringToOString( rString, RTL_TEXTENCODING_UTF8 );
44     return aUgly[ nIdx ].getStr();
45 }
46 
47 static accessibility::XAccessibleImage*
getImage(AtkImage * pImage)48     getImage( AtkImage *pImage ) throw (uno::RuntimeException)
49 {
50     AtkObjectWrapper *pWrap = ATK_OBJECT_WRAPPER( pImage );
51     if( pWrap )
52     {
53         if( !pWrap->mpImage && pWrap->mpContext )
54         {
55             uno::Any any = pWrap->mpContext->queryInterface( accessibility::XAccessibleImage::static_type(NULL) );
56             pWrap->mpImage = reinterpret_cast< accessibility::XAccessibleImage * > (any.pReserved);
57             pWrap->mpImage->acquire();
58         }
59 
60         return pWrap->mpImage;
61     }
62 
63     return NULL;
64 }
65 
66 extern "C" {
67 
68 static G_CONST_RETURN gchar *
image_get_image_description(AtkImage * image)69 image_get_image_description( AtkImage *image )
70 {
71     try {
72         accessibility::XAccessibleImage* pImage = getImage( image );
73         if( pImage )
74             return getAsConst( pImage->getAccessibleImageDescription() );
75     }
76     catch(const uno::Exception& e) {
77         g_warning( "Exception in getAccessibleImageDescription()" );
78     }
79 
80     return NULL;
81 }
82 
83 static void
image_get_image_position(AtkImage * image,gint * x,gint * y,AtkCoordType coord_type)84 image_get_image_position( AtkImage     *image,
85                           gint         *x,
86                           gint         *y,
87                           AtkCoordType  coord_type )
88 {
89     *x = *y = 0;
90     if( ATK_IS_COMPONENT( image ) )
91         atk_component_get_position( ATK_COMPONENT( image ), x, y, coord_type );
92     else
93         g_warning( "FIXME: no image position information" );
94 }
95 
96 static void
image_get_image_size(AtkImage * image,gint * width,gint * height)97 image_get_image_size( AtkImage *image,
98                       gint     *width,
99                       gint     *height )
100 {
101     *width = 0;
102     *height = 0;
103     try {
104         accessibility::XAccessibleImage* pImage = getImage( image );
105         if( pImage )
106         {
107             *width = pImage->getAccessibleImageWidth();
108             *height = pImage->getAccessibleImageHeight();
109         }
110     }
111     catch(const uno::Exception& e) {
112         g_warning( "Exception in getAccessibleImageHeight() or Width" );
113     }
114 }
115 
116 static gboolean
image_set_image_description(AtkImage *,const gchar *)117 image_set_image_description( AtkImage *, const gchar * )
118 {
119     g_warning ("FIXME: no set image description");
120     return FALSE;
121 }
122 
123 } // extern "C"
124 
125 void
imageIfaceInit(AtkImageIface * iface)126 imageIfaceInit (AtkImageIface *iface)
127 {
128   g_return_if_fail (iface != NULL);
129 
130   iface->set_image_description = image_set_image_description;
131   iface->get_image_description = image_get_image_description;
132   iface->get_image_position = image_get_image_position;
133   iface->get_image_size = image_get_image_size;
134 }
135