Update ooo320-m1
[ooovba.git] / vcl / unx / gtk / a11y / atkeditabletext.cxx
blobc854d1f0fd211290738054d77ad409d412342508
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: atkeditabletext.cxx,v $
10 * $Revision: 1.4 $
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"
35 #include "atktextattributes.hxx"
37 #include <com/sun/star/accessibility/XAccessibleEditableText.hpp>
38 #include <com/sun/star/accessibility/TextSegment.hpp>
40 // #include <functional>
41 // #include <hash_map>
43 #include <stdio.h>
44 #include <string.h>
46 using namespace ::com::sun::star;
48 static accessibility::XAccessibleEditableText*
49 getEditableText( AtkEditableText *pEditableText ) throw (uno::RuntimeException)
51 AtkObjectWrapper *pWrap = ATK_OBJECT_WRAPPER( pEditableText );
52 if( pWrap )
54 if( !pWrap->mpEditableText && pWrap->mpContext )
56 uno::Any any = pWrap->mpContext->queryInterface( accessibility::XAccessibleEditableText::static_type(NULL) );
57 pWrap->mpEditableText = reinterpret_cast< accessibility::XAccessibleEditableText * > (any.pReserved);
58 pWrap->mpEditableText->acquire();
61 return pWrap->mpEditableText;
64 return NULL;
68 /*****************************************************************************/
70 extern "C" {
72 static gboolean
73 editable_text_wrapper_set_run_attributes( AtkEditableText *text,
74 AtkAttributeSet *attribute_set,
75 gint nStartOffset,
76 gint nEndOffset)
78 try {
79 accessibility::XAccessibleEditableText* pEditableText = getEditableText( text );
80 if( pEditableText )
82 uno::Sequence< beans::PropertyValue > aAttributeList;
84 if( attribute_set_map_to_property_values( attribute_set, aAttributeList ) )
85 return pEditableText->setAttributes(nStartOffset, nEndOffset, aAttributeList);
88 catch(const uno::Exception& e) {
89 g_warning( "Exception in setAttributes()" );
92 return FALSE;
95 static void
96 editable_text_wrapper_set_text_contents( AtkEditableText *text,
97 const gchar *string )
99 try {
100 accessibility::XAccessibleEditableText* pEditableText = getEditableText( text );
101 if( pEditableText )
103 rtl::OUString aString ( string, strlen(string), RTL_TEXTENCODING_UTF8 );
104 pEditableText->setText( aString );
107 catch(const uno::Exception& e) {
108 g_warning( "Exception in setText()" );
112 static void
113 editable_text_wrapper_insert_text( AtkEditableText *text,
114 const gchar *string,
115 gint length,
116 gint *pos )
118 try {
119 accessibility::XAccessibleEditableText* pEditableText = getEditableText( text );
120 if( pEditableText )
122 rtl::OUString aString ( string, length, RTL_TEXTENCODING_UTF8 );
123 if( pEditableText->insertText( aString, *pos ) )
124 *pos += length;
127 catch(const uno::Exception& e) {
128 g_warning( "Exception in insertText()" );
132 static void
133 editable_text_wrapper_cut_text( AtkEditableText *text,
134 gint start,
135 gint end )
137 try {
138 accessibility::XAccessibleEditableText* pEditableText = getEditableText( text );
139 if( pEditableText )
140 pEditableText->cutText( start, end );
142 catch(const uno::Exception& e) {
143 g_warning( "Exception in cutText()" );
147 static void
148 editable_text_wrapper_delete_text( AtkEditableText *text,
149 gint start,
150 gint end )
152 try {
153 accessibility::XAccessibleEditableText* pEditableText = getEditableText( text );
154 if( pEditableText )
155 pEditableText->deleteText( start, end );
157 catch(const uno::Exception& e) {
158 g_warning( "Exception in deleteText()" );
162 static void
163 editable_text_wrapper_paste_text( AtkEditableText *text,
164 gint pos )
166 try {
167 accessibility::XAccessibleEditableText* pEditableText = getEditableText( text );
168 if( pEditableText )
169 pEditableText->pasteText( pos );
171 catch(const uno::Exception& e) {
172 g_warning( "Exception in pasteText()" );
176 static void
177 editable_text_wrapper_copy_text( AtkEditableText *text,
178 gint start,
179 gint end )
181 try {
182 accessibility::XAccessibleEditableText* pEditableText = getEditableText( text );
183 if( pEditableText )
184 pEditableText->copyText( start, end );
186 catch(const uno::Exception& e) {
187 g_warning( "Exception in copyText()" );
191 } // extern "C"
193 void
194 editableTextIfaceInit (AtkEditableTextIface *iface)
196 g_return_if_fail (iface != NULL);
198 iface->set_text_contents = editable_text_wrapper_set_text_contents;
199 iface->insert_text = editable_text_wrapper_insert_text;
200 iface->copy_text = editable_text_wrapper_copy_text;
201 iface->cut_text = editable_text_wrapper_cut_text;
202 iface->delete_text = editable_text_wrapper_delete_text;
203 iface->paste_text = editable_text_wrapper_paste_text;
204 iface->set_run_attributes = editable_text_wrapper_set_run_attributes;