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 #include "atktextattributes.hxx"
29
30 #include <com/sun/star/accessibility/XAccessibleEditableText.hpp>
31 #include <com/sun/star/accessibility/TextSegment.hpp>
32
33 // #include <functional>
34 // #include <hash_map>
35
36 #include <stdio.h>
37 #include <string.h>
38
39 using namespace ::com::sun::star;
40
41 static accessibility::XAccessibleEditableText*
getEditableText(AtkEditableText * pEditableText)42 getEditableText( AtkEditableText *pEditableText ) throw (uno::RuntimeException)
43 {
44 AtkObjectWrapper *pWrap = ATK_OBJECT_WRAPPER( pEditableText );
45 if( pWrap )
46 {
47 if( !pWrap->mpEditableText && pWrap->mpContext )
48 {
49 uno::Any any = pWrap->mpContext->queryInterface( accessibility::XAccessibleEditableText::static_type(NULL) );
50 pWrap->mpEditableText = reinterpret_cast< accessibility::XAccessibleEditableText * > (any.pReserved);
51 pWrap->mpEditableText->acquire();
52 }
53
54 return pWrap->mpEditableText;
55 }
56
57 return NULL;
58 }
59
60
61 /*****************************************************************************/
62
63 extern "C" {
64
65 static gboolean
editable_text_wrapper_set_run_attributes(AtkEditableText * text,AtkAttributeSet * attribute_set,gint nStartOffset,gint nEndOffset)66 editable_text_wrapper_set_run_attributes( AtkEditableText *text,
67 AtkAttributeSet *attribute_set,
68 gint nStartOffset,
69 gint nEndOffset)
70 {
71 try {
72 accessibility::XAccessibleEditableText* pEditableText = getEditableText( text );
73 if( pEditableText )
74 {
75 uno::Sequence< beans::PropertyValue > aAttributeList;
76
77 if( attribute_set_map_to_property_values( attribute_set, aAttributeList ) )
78 return pEditableText->setAttributes(nStartOffset, nEndOffset, aAttributeList);
79 }
80 }
81 catch(const uno::Exception& e) {
82 g_warning( "Exception in setAttributes()" );
83 }
84
85 return FALSE;
86 }
87
88 static void
editable_text_wrapper_set_text_contents(AtkEditableText * text,const gchar * string)89 editable_text_wrapper_set_text_contents( AtkEditableText *text,
90 const gchar *string )
91 {
92 try {
93 accessibility::XAccessibleEditableText* pEditableText = getEditableText( text );
94 if( pEditableText )
95 {
96 rtl::OUString aString ( string, strlen(string), RTL_TEXTENCODING_UTF8 );
97 pEditableText->setText( aString );
98 }
99 }
100 catch(const uno::Exception& e) {
101 g_warning( "Exception in setText()" );
102 }
103 }
104
105 static void
editable_text_wrapper_insert_text(AtkEditableText * text,const gchar * string,gint length,gint * pos)106 editable_text_wrapper_insert_text( AtkEditableText *text,
107 const gchar *string,
108 gint length,
109 gint *pos )
110 {
111 try {
112 accessibility::XAccessibleEditableText* pEditableText = getEditableText( text );
113 if( pEditableText )
114 {
115 rtl::OUString aString ( string, length, RTL_TEXTENCODING_UTF8 );
116 if( pEditableText->insertText( aString, *pos ) )
117 *pos += length;
118 }
119 }
120 catch(const uno::Exception& e) {
121 g_warning( "Exception in insertText()" );
122 }
123 }
124
125 static void
editable_text_wrapper_cut_text(AtkEditableText * text,gint start,gint end)126 editable_text_wrapper_cut_text( AtkEditableText *text,
127 gint start,
128 gint end )
129 {
130 try {
131 accessibility::XAccessibleEditableText* pEditableText = getEditableText( text );
132 if( pEditableText )
133 pEditableText->cutText( start, end );
134 }
135 catch(const uno::Exception& e) {
136 g_warning( "Exception in cutText()" );
137 }
138 }
139
140 static void
editable_text_wrapper_delete_text(AtkEditableText * text,gint start,gint end)141 editable_text_wrapper_delete_text( AtkEditableText *text,
142 gint start,
143 gint end )
144 {
145 try {
146 accessibility::XAccessibleEditableText* pEditableText = getEditableText( text );
147 if( pEditableText )
148 pEditableText->deleteText( start, end );
149 }
150 catch(const uno::Exception& e) {
151 g_warning( "Exception in deleteText()" );
152 }
153 }
154
155 static void
editable_text_wrapper_paste_text(AtkEditableText * text,gint pos)156 editable_text_wrapper_paste_text( AtkEditableText *text,
157 gint pos )
158 {
159 try {
160 accessibility::XAccessibleEditableText* pEditableText = getEditableText( text );
161 if( pEditableText )
162 pEditableText->pasteText( pos );
163 }
164 catch(const uno::Exception& e) {
165 g_warning( "Exception in pasteText()" );
166 }
167 }
168
169 static void
editable_text_wrapper_copy_text(AtkEditableText * text,gint start,gint end)170 editable_text_wrapper_copy_text( AtkEditableText *text,
171 gint start,
172 gint end )
173 {
174 try {
175 accessibility::XAccessibleEditableText* pEditableText = getEditableText( text );
176 if( pEditableText )
177 pEditableText->copyText( start, end );
178 }
179 catch(const uno::Exception& e) {
180 g_warning( "Exception in copyText()" );
181 }
182 }
183
184 } // extern "C"
185
186 void
editableTextIfaceInit(AtkEditableTextIface * iface)187 editableTextIfaceInit (AtkEditableTextIface *iface)
188 {
189 g_return_if_fail (iface != NULL);
190
191 iface->set_text_contents = editable_text_wrapper_set_text_contents;
192 iface->insert_text = editable_text_wrapper_insert_text;
193 iface->copy_text = editable_text_wrapper_copy_text;
194 iface->cut_text = editable_text_wrapper_cut_text;
195 iface->delete_text = editable_text_wrapper_delete_text;
196 iface->paste_text = editable_text_wrapper_paste_text;
197 iface->set_run_attributes = editable_text_wrapper_set_run_attributes;
198 }
199