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 .
21 * AccEditableText.cpp : Implementation of CUAccCOMApp and DLL registration.
24 #include "AccEditableText.h"
27 #pragma clang diagnostic push
28 #pragma clang diagnostic ignored "-Wnon-virtual-dtor"
32 #pragma clang diagnostic pop
35 #include <vcl/svapp.hxx>
37 #include <com/sun/star/accessibility/XAccessible.hpp>
38 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
39 #include <com/sun/star/accessibility/XAccessibleText.hpp>
40 #include <com/sun/star/awt/FontSlant.hpp>
41 #include <com/sun/star/beans/PropertyValue.hpp>
42 #include <com/sun/star/style/LineSpacing.hpp>
43 #include <com/sun/star/style/TabStop.hpp>
46 using namespace com::sun::star::accessibility
;
47 using namespace com::sun::star::uno
;
48 using namespace com::sun::star::awt
;
49 using namespace com::sun::star::beans
;
53 * Copy a range of text to the clipboard.
55 * @param startOffset the start offset of copying.
56 * @param endOffset the end offset of copying.
57 * @param success the boolean result to be returned.
59 STDMETHODIMP
CAccEditableText::copyText(long startOffset
, long endOffset
)
71 if ( GetXInterface()->copyText( startOffset
, endOffset
) )
80 * Deletes a range of text.
82 * @param startOffset the start offset of deleting.
83 * @param endOffset the end offset of deleting.
84 * @param success the boolean result to be returned.
86 STDMETHODIMP
CAccEditableText::deleteText(long startOffset
, long endOffset
)
95 if( GetXInterface()->deleteText( startOffset
, endOffset
) )
100 LEAVE_PROTECTED_BLOCK
104 * Inserts text at a specified offset.
106 * @param offset the offset of inserting.
107 * @param text the text to be inserted.
108 * @param success the boolean result to be returned.
110 STDMETHODIMP
CAccEditableText::insertText(long offset
, BSTR
* text
)
114 ENTER_PROTECTED_BLOCK
119 if( !pRXEdtTxt
.is() )
122 ::rtl::OUString
ouStr(*text
);
124 if( GetXInterface()->insertText( ouStr
, offset
) )
129 LEAVE_PROTECTED_BLOCK
133 * Cuts a range of text to the clipboard.
135 * @param startOffset the start offset of cutting.
136 * @param endOffset the end offset of cutting.
137 * @param success the boolean result to be returned.
139 STDMETHODIMP
CAccEditableText::cutText(long startOffset
, long endOffset
)
143 ENTER_PROTECTED_BLOCK
145 if( !pRXEdtTxt
.is() )
148 if( GetXInterface()->cutText( startOffset
, endOffset
) )
153 LEAVE_PROTECTED_BLOCK
157 * Pastes text from clipboard at specified offset.
159 * @param offset the offset of pasting.
160 * @param success the boolean result to be returned.
162 STDMETHODIMP
CAccEditableText::pasteText(long offset
)
166 ENTER_PROTECTED_BLOCK
168 if( !pRXEdtTxt
.is() )
171 if( GetXInterface()->pasteText( offset
) )
176 LEAVE_PROTECTED_BLOCK
180 * Replaces range of text with new text.
182 * @param startOffset the start offset of replacing.
183 * @param endOffset the end offset of replacing.
184 * @param text the replacing text.
185 * @param success the boolean result to be returned.
187 STDMETHODIMP
CAccEditableText::replaceText(long startOffset
, long endOffset
, BSTR
* text
)
191 ENTER_PROTECTED_BLOCK
196 if( !pRXEdtTxt
.is() )
199 ::rtl::OUString
ouStr(*text
);
201 if( GetXInterface()->replaceText( startOffset
,endOffset
, ouStr
) )
205 LEAVE_PROTECTED_BLOCK
209 * Sets attributes of range of text.
211 * @param startOffset the start offset.
212 * @param endOffset the end offset.
213 * @param attributes the attribute text.
214 * @param success the boolean result to be returned.
216 STDMETHODIMP
CAccEditableText::setAttributes(long startOffset
, long endOffset
, BSTR
* attributes
)
220 ENTER_PROTECTED_BLOCK
223 if (attributes
== NULL
)
225 if( !pRXEdtTxt
.is() )
228 ::rtl::OUString
ouStr(*attributes
);
230 sal_Int32 nIndex
= 0;
231 sal_Unicode cTok
= ';';
232 vector
< ::rtl::OUString
> vecAttr
;
235 ::rtl::OUString ouToken
= ouStr
.getToken(0, cTok
, nIndex
);
236 vecAttr
.push_back(ouToken
);
240 Sequence
< PropertyValue
> beanSeq(vecAttr
.size());
241 for(unsigned int i
= 0; i
< vecAttr
.size(); i
++)
243 ::rtl::OUString attr
= vecAttr
[i
];
244 sal_Int32 nPos
= attr
.indexOf(':');
247 ::rtl::OUString attrName
= attr
.copy(0, nPos
);
248 ::rtl::OUString attrValue
= attr
.copy(nPos
+ 1, attr
.getLength() - nPos
- 1);
249 beanSeq
[i
].Name
= attrName
;
250 get_AnyFromOLECHAR(attrName
, attrValue
, beanSeq
[i
].Value
);
254 if( GetXInterface()->setAttributes( startOffset
,endOffset
, beanSeq
) )
259 LEAVE_PROTECTED_BLOCK
263 * Convert attributes string to Any type.
265 * @param ouName the string of attribute name.
266 * @param ouValue the string of attribute value.
267 * @param rAny the Any object to be returned.
269 void CAccEditableText::get_AnyFromOLECHAR(const ::rtl::OUString
&ouName
, const ::rtl::OUString
&ouValue
, Any
&rAny
)
271 if(ouName
.equals(L
"CharBackColor") ||
272 ouName
.equals(L
"CharColor") ||
273 ouName
.equals(L
"ParaAdjust") ||
274 ouName
.equals(L
"ParaFirstLineIndent") ||
275 ouName
.equals(L
"ParaLeftMargin") ||
276 ouName
.equals(L
"ParaRightMargin") ||
277 ouName
.equals(L
"ParaTopMargin") ||
278 ouName
.equals(L
"ParaBottomMargin") ||
279 ouName
.equals(L
"CharFontPitch") )
282 // NOTE: CharFontPitch is not implemented in java file.
283 sal_Int32 nValue
= ouValue
.toInt32();
284 rAny
.setValue(&nValue
, cppu::UnoType
<sal_Int32
>::get());
286 else if(ouName
.equals(L
"CharShadowed") ||
287 ouName
.equals(L
"CharContoured") )
289 // Convert to boolean.
290 rAny
<<= ouValue
.toBoolean();
292 else if(ouName
.equals(L
"CharEscapement") ||
293 ouName
.equals(L
"CharStrikeout") ||
294 ouName
.equals(L
"CharUnderline") ||
295 ouName
.equals(L
"CharFontPitch") )
298 short nValue
= (short)ouValue
.toInt32();
299 rAny
.setValue(&nValue
, cppu::UnoType
<short>::get());
301 else if(ouName
.equals(L
"CharHeight") ||
302 ouName
.equals(L
"CharWeight") )
305 float fValue
= ouValue
.toFloat();
306 rAny
.setValue(&fValue
, cppu::UnoType
<float>::get());
308 else if(ouName
.equals(L
"CharFontName") )
310 // Convert to string.
311 rAny
.setValue(&ouValue
, cppu::UnoType
<rtl::OUString
>::get());
313 else if(ouName
.equals(L
"CharPosture") )
315 // Convert to FontSlant.
316 css::awt::FontSlant fontSlant
= (css::awt::FontSlant
)ouValue
.toInt32();
317 rAny
.setValue(&fontSlant
, cppu::UnoType
<css::awt::FontSlant
>::get());
319 else if(ouName
.equals(L
"ParaTabStops") )
322 // Convert to the Sequence with TabStop element.
323 vector
< css::style::TabStop
> vecTabStop
;
324 css::style::TabStop tabStop
;
325 ::rtl::OUString ouSubValue
;
326 sal_Int32 pos
= 0, posComma
= 0;
331 pos
= ouValue
.indexOf(L
"Position=", pos
);
334 posComma
= ouValue
.indexOf(',', pos
+ 9); // 9 = length of "Position=".
337 ouSubValue
= ouValue
.copy(pos
+ 9, posComma
- pos
- 9);
338 tabStop
.Position
= ouSubValue
.toInt32();
342 pos
= ouValue
.indexOf(L
"TabAlign=", pos
);
345 posComma
= ouValue
.indexOf(',', pos
+ 9); // 9 = length of "TabAlign=".
348 ouSubValue
= ouValue
.copy(pos
+ 9, posComma
- pos
- 9);
349 tabStop
.Alignment
= (css::style::TabAlign
)ouSubValue
.toInt32();
353 pos
= ouValue
.indexOf(L
"DecimalChar=", pos
);
356 posComma
= ouValue
.indexOf(',', pos
+ 11); // 11 = length of "TabAlign=".
359 ouSubValue
= ouValue
.copy(pos
+ 11, posComma
- pos
- 11);
360 tabStop
.DecimalChar
= (sal_Unicode
)ouSubValue
.toChar();
364 pos
= ouValue
.indexOf(L
"FillChar=", pos
);
367 posComma
= ouValue
.indexOf(',', pos
+ 9); // 9 = length of "TabAlign=".
370 ouSubValue
= ouValue
.copy(pos
+ 9, posComma
- pos
- 9);
371 tabStop
.DecimalChar
= (sal_Unicode
)ouSubValue
.toChar();
374 // Complete TabStop element.
375 vecTabStop
.push_back(tabStop
);
378 break; // No match comma.
381 break; // No match FillChar.
384 break; // No match comma.
387 break; // No match DecimalChar.
390 break; // No match comma.
393 break; // No match TabAlign.
396 break; // No match comma.
399 break; // No match Position.
401 while(pos
< ouValue
.getLength());
404 // Dump into Sequence.
405 int iSeqLen
= (vecTabStop
.size() == 0) ? 1 : vecTabStop
.size();
406 Sequence
< css::style::TabStop
> seqTabStop(iSeqLen
);
408 if(vecTabStop
.size() != 0)
410 // Dump every element.
411 for(int i
= 0; i
< iSeqLen
; i
++)
413 seqTabStop
[i
] = vecTabStop
[i
];
418 // Create default value.
419 seqTabStop
[0].Position
= 0;
420 seqTabStop
[0].Alignment
= css::style::TabAlign_DEFAULT
;
421 seqTabStop
[0].DecimalChar
= '.';
422 seqTabStop
[0].FillChar
= ' ';
425 // Assign to Any object.
426 rAny
.setValue(&seqTabStop
, cppu::UnoType
<Sequence
< css::style::TabStop
>>::get());
428 else if(ouName
.equals(L
"ParaLineSpacing") )
430 // Parse value string.
431 css::style::LineSpacing lineSpacing
;
432 ::rtl::OUString ouSubValue
;
433 sal_Int32 pos
= 0, posComma
= 0;
435 pos
= ouValue
.indexOf(L
"Mode=", pos
);
438 posComma
= ouValue
.indexOf(',', pos
+ 5); // 5 = length of "Mode=".
441 ouSubValue
= ouValue
.copy(pos
+ 5, posComma
- pos
- 5);
442 lineSpacing
.Mode
= (sal_Int16
)ouSubValue
.toInt32();
445 pos
= ouValue
.indexOf(L
"Height=", pos
);
448 ouSubValue
= ouValue
.copy(pos
+ 7, ouValue
.getLength() - pos
- 7);
449 lineSpacing
.Height
= (sal_Int16
)ouSubValue
.toInt32();
453 lineSpacing
.Height
= (sal_Int16
)100; // Default height.
458 lineSpacing
.Height
= (sal_Int16
)100; // Default height.
463 // Default Mode and Height.
464 lineSpacing
.Mode
= (sal_Int16
)0;
465 lineSpacing
.Height
= (sal_Int16
)100; // Default height.
468 // Convert to Any object.
469 rAny
.setValue(&lineSpacing
, cppu::UnoType
<css::style::LineSpacing
>::get());
474 sal_Int32 nDefault
= 0;
475 rAny
.setValue(&nDefault
, cppu::UnoType
<sal_Int32
>::get());
480 * Override of IUNOXWrapper.
482 * @param pXInterface the pointer of UNO interface.
484 STDMETHODIMP
CAccEditableText::put_XInterface(hyper pXInterface
)
486 // internal IUNOXWrapper - no mutex meeded
488 ENTER_PROTECTED_BLOCK
490 CUNOXWrapper::put_XInterface(pXInterface
);
492 if(pUNOInterface
== NULL
)
494 Reference
<XAccessibleContext
> pRContext
= pUNOInterface
->getAccessibleContext();
495 if( !pRContext
.is() )
499 Reference
<XAccessibleEditableText
> pRXI(pRContext
,UNO_QUERY
);
503 pRXEdtTxt
= pRXI
.get();
506 LEAVE_PROTECTED_BLOCK
509 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */