1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: atkeditabletext.cxx,v $
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>
46 using namespace ::com::sun::star
;
48 static accessibility::XAccessibleEditableText
*
49 getEditableText( AtkEditableText
*pEditableText
) throw (uno::RuntimeException
)
51 AtkObjectWrapper
*pWrap
= ATK_OBJECT_WRAPPER( pEditableText
);
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
;
68 /*****************************************************************************/
73 editable_text_wrapper_set_run_attributes( AtkEditableText
*text
,
74 AtkAttributeSet
*attribute_set
,
79 accessibility::XAccessibleEditableText
* pEditableText
= getEditableText( text
);
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()" );
96 editable_text_wrapper_set_text_contents( AtkEditableText
*text
,
100 accessibility::XAccessibleEditableText
* pEditableText
= getEditableText( text
);
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()" );
113 editable_text_wrapper_insert_text( AtkEditableText
*text
,
119 accessibility::XAccessibleEditableText
* pEditableText
= getEditableText( text
);
122 rtl::OUString
aString ( string
, length
, RTL_TEXTENCODING_UTF8
);
123 if( pEditableText
->insertText( aString
, *pos
) )
127 catch(const uno::Exception
& e
) {
128 g_warning( "Exception in insertText()" );
133 editable_text_wrapper_cut_text( AtkEditableText
*text
,
138 accessibility::XAccessibleEditableText
* pEditableText
= getEditableText( text
);
140 pEditableText
->cutText( start
, end
);
142 catch(const uno::Exception
& e
) {
143 g_warning( "Exception in cutText()" );
148 editable_text_wrapper_delete_text( AtkEditableText
*text
,
153 accessibility::XAccessibleEditableText
* pEditableText
= getEditableText( text
);
155 pEditableText
->deleteText( start
, end
);
157 catch(const uno::Exception
& e
) {
158 g_warning( "Exception in deleteText()" );
163 editable_text_wrapper_paste_text( AtkEditableText
*text
,
167 accessibility::XAccessibleEditableText
* pEditableText
= getEditableText( text
);
169 pEditableText
->pasteText( pos
);
171 catch(const uno::Exception
& e
) {
172 g_warning( "Exception in pasteText()" );
177 editable_text_wrapper_copy_text( AtkEditableText
*text
,
182 accessibility::XAccessibleEditableText
* pEditableText
= getEditableText( text
);
184 pEditableText
->copyText( start
, end
);
186 catch(const uno::Exception
& e
) {
187 g_warning( "Exception in copyText()" );
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
;