1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "atkwrapper.hxx"
21 #include "atktextattributes.hxx"
23 #include <com/sun/star/accessibility/XAccessibleEditableText.hpp>
27 using namespace ::com::sun::star
;
29 /// @throws uno::RuntimeException
30 static css::uno::Reference
<css::accessibility::XAccessibleEditableText
>
31 getEditableText( AtkEditableText
*pEditableText
)
33 AtkObjectWrapper
*pWrap
= ATK_OBJECT_WRAPPER( pEditableText
);
36 if( !pWrap
->mpEditableText
.is() )
38 pWrap
->mpEditableText
.set(pWrap
->mpContext
, css::uno::UNO_QUERY
);
41 return pWrap
->mpEditableText
;
44 return css::uno::Reference
<css::accessibility::XAccessibleEditableText
>();
47 /*****************************************************************************/
52 editable_text_wrapper_set_run_attributes( AtkEditableText
*text
,
53 AtkAttributeSet
*attribute_set
,
58 css::uno::Reference
<css::accessibility::XAccessibleEditableText
>
59 pEditableText
= getEditableText( text
);
60 if( pEditableText
.is() )
62 uno::Sequence
< beans::PropertyValue
> aAttributeList
;
64 if( attribute_set_map_to_property_values( attribute_set
, aAttributeList
) )
65 return pEditableText
->setAttributes(nStartOffset
, nEndOffset
, aAttributeList
);
68 catch(const uno::Exception
&) {
69 g_warning( "Exception in setAttributes()" );
76 editable_text_wrapper_set_text_contents( AtkEditableText
*text
,
80 css::uno::Reference
<css::accessibility::XAccessibleEditableText
>
81 pEditableText
= getEditableText( text
);
82 if( pEditableText
.is() )
84 OUString
aString ( string
, strlen(string
), RTL_TEXTENCODING_UTF8
);
85 pEditableText
->setText( aString
);
88 catch(const uno::Exception
&) {
89 g_warning( "Exception in setText()" );
94 editable_text_wrapper_insert_text( AtkEditableText
*text
,
100 css::uno::Reference
<css::accessibility::XAccessibleEditableText
>
101 pEditableText
= getEditableText( text
);
102 if( pEditableText
.is() )
104 OUString
aString ( string
, length
, RTL_TEXTENCODING_UTF8
);
105 if( pEditableText
->insertText( aString
, *pos
) )
109 catch(const uno::Exception
&) {
110 g_warning( "Exception in insertText()" );
115 editable_text_wrapper_cut_text( AtkEditableText
*text
,
120 css::uno::Reference
<css::accessibility::XAccessibleEditableText
>
121 pEditableText
= getEditableText( text
);
122 if( pEditableText
.is() )
123 pEditableText
->cutText( start
, end
);
125 catch(const uno::Exception
&) {
126 g_warning( "Exception in cutText()" );
131 editable_text_wrapper_delete_text( AtkEditableText
*text
,
136 css::uno::Reference
<css::accessibility::XAccessibleEditableText
>
137 pEditableText
= getEditableText( text
);
138 if( pEditableText
.is() )
139 pEditableText
->deleteText( start
, end
);
141 catch(const uno::Exception
&) {
142 g_warning( "Exception in deleteText()" );
147 editable_text_wrapper_paste_text( AtkEditableText
*text
,
151 css::uno::Reference
<css::accessibility::XAccessibleEditableText
>
152 pEditableText
= getEditableText( text
);
153 if( pEditableText
.is() )
154 pEditableText
->pasteText( pos
);
156 catch(const uno::Exception
&) {
157 g_warning( "Exception in pasteText()" );
162 editable_text_wrapper_copy_text( AtkEditableText
*text
,
167 css::uno::Reference
<css::accessibility::XAccessibleEditableText
>
168 pEditableText
= getEditableText( text
);
169 if( pEditableText
.is() )
170 pEditableText
->copyText( start
, end
);
172 catch(const uno::Exception
&) {
173 g_warning( "Exception in copyText()" );
180 editableTextIfaceInit (gpointer iface_
, gpointer
)
182 auto const iface
= static_cast<AtkEditableTextIface
*>(iface_
);
183 g_return_if_fail (iface
!= nullptr);
185 iface
->set_text_contents
= editable_text_wrapper_set_text_contents
;
186 iface
->insert_text
= editable_text_wrapper_insert_text
;
187 iface
->copy_text
= editable_text_wrapper_copy_text
;
188 iface
->cut_text
= editable_text_wrapper_cut_text
;
189 iface
->delete_text
= editable_text_wrapper_delete_text
;
190 iface
->paste_text
= editable_text_wrapper_paste_text
;
191 iface
->set_run_attributes
= editable_text_wrapper_set_run_attributes
;
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */