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.
25 #include "AccEditableText.h"
27 #include <vcl/svapp.hxx>
29 #include <com/sun/star/accessibility/XAccessible.hpp>
30 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
31 #include <com/sun/star/accessibility/XAccessibleText.hpp>
32 #include <com/sun/star/awt/FontSlant.hpp>
33 #include <com/sun/star/beans/PropertyValue.hpp>
34 #include <com/sun/star/style/LineSpacing.hpp>
35 #include <com/sun/star/style/TabStop.hpp>
38 using namespace com::sun::star::accessibility
;
39 using namespace com::sun::star::uno
;
40 using namespace com::sun::star::awt
;
41 using namespace com::sun::star::beans
;
45 * Copys a range of text to the clipboard.
47 * @param startOffset the start offset of copying.
48 * @param endOffset the end offset of copying.
49 * @param success the boolean result to be returned.
51 STDMETHODIMP
CAccEditableText::copyText(long startOffset
, long endOffset
)
63 if ( GetXInterface()->copyText( startOffset
, endOffset
) )
72 * Deletes a range of text.
74 * @param startOffset the start offset of deleting.
75 * @param endOffset the end offset of deleting.
76 * @param success the boolean result to be returned.
78 STDMETHODIMP
CAccEditableText::deleteText(long startOffset
, long endOffset
)
87 if( GetXInterface()->deleteText( startOffset
, endOffset
) )
96 * Inserts text at a specified offset.
98 * @param offset the offset of inserting.
99 * @param text the text to be inserted.
100 * @param success the boolean result to be returned.
102 STDMETHODIMP
CAccEditableText::insertText(long offset
, BSTR
* text
)
106 ENTER_PROTECTED_BLOCK
111 if( !pRXEdtTxt
.is() )
114 ::rtl::OUString
ouStr(*text
);
116 if( GetXInterface()->insertText( ouStr
, offset
) )
121 LEAVE_PROTECTED_BLOCK
125 * Cuts a range of text to the clipboard.
127 * @param startOffset the start offset of cuting.
128 * @param endOffset the end offset of cuting.
129 * @param success the boolean result to be returned.
131 STDMETHODIMP
CAccEditableText::cutText(long startOffset
, long endOffset
)
135 ENTER_PROTECTED_BLOCK
137 if( !pRXEdtTxt
.is() )
140 if( GetXInterface()->cutText( startOffset
, endOffset
) )
145 LEAVE_PROTECTED_BLOCK
149 * Pastes text from clipboard at specified offset.
151 * @param offset the offset of pasting.
152 * @param success the boolean result to be returned.
154 STDMETHODIMP
CAccEditableText::pasteText(long offset
)
158 ENTER_PROTECTED_BLOCK
160 if( !pRXEdtTxt
.is() )
163 if( GetXInterface()->pasteText( offset
) )
168 LEAVE_PROTECTED_BLOCK
172 * Replaces range of text with new text.
174 * @param startOffset the start offset of replacing.
175 * @param endOffset the end offset of replacing.
176 * @param text the replacing text.
177 * @param success the boolean result to be returned.
179 STDMETHODIMP
CAccEditableText::replaceText(long startOffset
, long endOffset
, BSTR
* text
)
183 ENTER_PROTECTED_BLOCK
188 if( !pRXEdtTxt
.is() )
191 ::rtl::OUString
ouStr(*text
);
193 if( GetXInterface()->replaceText( startOffset
,endOffset
, ouStr
) )
197 LEAVE_PROTECTED_BLOCK
201 * Sets attributes of range of text.
203 * @param startOffset the start offset.
204 * @param endOffset the end offset.
205 * @param attributes the attribute text.
206 * @param success the boolean result to be returned.
208 STDMETHODIMP
CAccEditableText::setAttributes(long startOffset
, long endOffset
, BSTR
* attributes
)
212 ENTER_PROTECTED_BLOCK
215 if (attributes
== NULL
)
217 if( !pRXEdtTxt
.is() )
220 ::rtl::OUString
ouStr(*attributes
);
222 sal_Int32 nIndex
= 0;
223 sal_Unicode cTok
= ';';
224 vector
< ::rtl::OUString
> vecAttr
;
227 ::rtl::OUString ouToken
= ouStr
.getToken(0, cTok
, nIndex
);
228 vecAttr
.push_back(ouToken
);
232 Sequence
< PropertyValue
> beanSeq(vecAttr
.size());
233 for(unsigned int i
= 0; i
< vecAttr
.size(); i
++)
235 ::rtl::OUString attr
= vecAttr
[i
];
236 sal_Int32 nPos
= attr
.indexOf(':');
239 ::rtl::OUString attrName
= attr
.copy(0, nPos
);
240 ::rtl::OUString attrValue
= attr
.copy(nPos
+ 1, attr
.getLength() - nPos
- 1);
241 beanSeq
[i
].Name
= attrName
;
242 get_AnyFromOLECHAR(attrName
, attrValue
, beanSeq
[i
].Value
);
246 if( GetXInterface()->setAttributes( startOffset
,endOffset
, beanSeq
) )
251 LEAVE_PROTECTED_BLOCK
255 * Convert attributes string to Any type.
256 * Reference to infra\accessibility\bridge\org\openoffice\java\accessibility\AccessibleTextImpl.java
258 * @param ouName the string of attribute name.
259 * @param ouValue the string of attribute value.
260 * @param rAny the Any object to be returned.
262 void CAccEditableText::get_AnyFromOLECHAR(const ::rtl::OUString
&ouName
, const ::rtl::OUString
&ouValue
, Any
&rAny
)
264 if(ouName
.equals(L
"CharBackColor") ||
265 ouName
.equals(L
"CharColor") ||
266 ouName
.equals(L
"ParaAdjust") ||
267 ouName
.equals(L
"ParaFirstLineIndent") ||
268 ouName
.equals(L
"ParaLeftMargin") ||
269 ouName
.equals(L
"ParaRightMargin") ||
270 ouName
.equals(L
"ParaTopMargin") ||
271 ouName
.equals(L
"ParaBottomMargin") ||
272 ouName
.equals(L
"CharFontPitch") )
275 // NOTE: CharFontPitch is not implemented in java file.
276 sal_Int32 nValue
= ouValue
.toInt32();
277 rAny
.setValue(&nValue
, cppu::UnoType
<sal_Int32
>::get());
279 else if(ouName
.equals(L
"CharShadowed") ||
280 ouName
.equals(L
"CharContoured") )
282 // Convert to boolean.
283 boolean nValue
= (boolean
)ouValue
.toBoolean();
284 rAny
.setValue(&nValue
, cppu::UnoType
<sal_Bool
>::get() );
286 else if(ouName
.equals(L
"CharEscapement") ||
287 ouName
.equals(L
"CharStrikeout") ||
288 ouName
.equals(L
"CharUnderline") ||
289 ouName
.equals(L
"CharFontPitch") )
292 short nValue
= (short)ouValue
.toInt32();
293 rAny
.setValue(&nValue
, cppu::UnoType
<short>::get());
295 else if(ouName
.equals(L
"CharHeight") ||
296 ouName
.equals(L
"CharWeight") )
299 float fValue
= ouValue
.toFloat();
300 rAny
.setValue(&fValue
, cppu::UnoType
<float>::get());
302 else if(ouName
.equals(L
"CharFontName") )
304 // Convert to string.
305 rAny
.setValue(&ouValue
, cppu::UnoType
<rtl::OUString
>::get());
307 else if(ouName
.equals(L
"CharPosture") )
309 // Convert to FontSlant.
310 ::com::sun::star::awt::FontSlant fontSlant
= (::com::sun::star::awt::FontSlant
)ouValue
.toInt32();
311 rAny
.setValue(&fontSlant
, cppu::UnoType
<com::sun::star::awt::FontSlant
>::get());
313 else if(ouName
.equals(L
"ParaTabStops") )
316 // Convert to the Sequence with TabStop element.
317 vector
< ::com::sun::star::style::TabStop
> vecTabStop
;
318 ::com::sun::star::style::TabStop tabStop
;
319 ::rtl::OUString ouSubValue
;
320 sal_Int32 pos
= 0, posComma
= 0;
325 pos
= ouValue
.indexOf(L
"Position=", pos
);
328 posComma
= ouValue
.indexOf(',', pos
+ 9); // 9 = length of "Position=".
331 ouSubValue
= ouValue
.copy(pos
+ 9, posComma
- pos
- 9);
332 tabStop
.Position
= ouSubValue
.toInt32();
336 pos
= ouValue
.indexOf(L
"TabAlign=", pos
);
339 posComma
= ouValue
.indexOf(',', pos
+ 9); // 9 = length of "TabAlign=".
342 ouSubValue
= ouValue
.copy(pos
+ 9, posComma
- pos
- 9);
343 tabStop
.Alignment
= (::com::sun::star::style::TabAlign
)ouSubValue
.toInt32();
347 pos
= ouValue
.indexOf(L
"DecimalChar=", pos
);
350 posComma
= ouValue
.indexOf(',', pos
+ 11); // 11 = length of "TabAlign=".
353 ouSubValue
= ouValue
.copy(pos
+ 11, posComma
- pos
- 11);
354 tabStop
.DecimalChar
= (sal_Unicode
)ouSubValue
.toChar();
358 pos
= ouValue
.indexOf(L
"FillChar=", pos
);
361 posComma
= ouValue
.indexOf(',', pos
+ 9); // 9 = length of "TabAlign=".
364 ouSubValue
= ouValue
.copy(pos
+ 9, posComma
- pos
- 9);
365 tabStop
.DecimalChar
= (sal_Unicode
)ouSubValue
.toChar();
368 // Complete TabStop element.
369 vecTabStop
.push_back(tabStop
);
372 break; // No match comma.
375 break; // No match FillChar.
378 break; // No match comma.
381 break; // No match DecimalChar.
384 break; // No match comma.
387 break; // No match TabAlign.
390 break; // No match comma.
393 break; // No match Position.
395 while(pos
< ouValue
.getLength());
398 // Dump into Sequence.
399 int iSeqLen
= (vecTabStop
.size() == 0) ? 1 : vecTabStop
.size();
400 Sequence
< ::com::sun::star::style::TabStop
> seqTabStop(iSeqLen
);
402 if(vecTabStop
.size() != 0)
404 // Dump every element.
405 for(int i
= 0; i
< iSeqLen
; i
++)
407 seqTabStop
[i
] = vecTabStop
[i
];
412 // Create default value.
413 seqTabStop
[0].Position
= 0;
414 seqTabStop
[0].Alignment
= ::com::sun::star::style::TabAlign_DEFAULT
;
415 seqTabStop
[0].DecimalChar
= '.';
416 seqTabStop
[0].FillChar
= ' ';
419 // Assign to Any object.
420 rAny
.setValue(&seqTabStop
, cppu::UnoType
<Sequence
< ::com::sun::star::style::TabStop
>>::get());
422 else if(ouName
.equals(L
"ParaLineSpacing") )
424 // Parse value string.
425 ::com::sun::star::style::LineSpacing lineSpacing
;
426 ::rtl::OUString ouSubValue
;
427 sal_Int32 pos
= 0, posComma
= 0;
429 pos
= ouValue
.indexOf(L
"Mode=", pos
);
432 posComma
= ouValue
.indexOf(',', pos
+ 5); // 5 = length of "Mode=".
435 ouSubValue
= ouValue
.copy(pos
+ 5, posComma
- pos
- 5);
436 lineSpacing
.Mode
= (sal_Int16
)ouSubValue
.toInt32();
439 pos
= ouValue
.indexOf(L
"Height=", pos
);
442 ouSubValue
= ouValue
.copy(pos
+ 7, ouValue
.getLength() - pos
- 7);
443 lineSpacing
.Height
= (sal_Int16
)ouSubValue
.toInt32();
447 lineSpacing
.Height
= (sal_Int16
)100; // Default height.
452 lineSpacing
.Height
= (sal_Int16
)100; // Default height.
457 // Default Mode and Height.
458 lineSpacing
.Mode
= (sal_Int16
)0;
459 lineSpacing
.Height
= (sal_Int16
)100; // Default height.
462 // Convert to Any object.
463 rAny
.setValue(&lineSpacing
, cppu::UnoType
<com::sun::star::style::LineSpacing
>::get());
468 sal_Int32 nDefault
= 0;
469 rAny
.setValue(&nDefault
, cppu::UnoType
<sal_Int32
>::get());
474 * Override of IUNOXWrapper.
476 * @param pXInterface the pointer of UNO interface.
478 STDMETHODIMP
CAccEditableText::put_XInterface(hyper pXInterface
)
480 // internal IUNOXWrapper - no mutex meeded
482 ENTER_PROTECTED_BLOCK
484 CUNOXWrapper::put_XInterface(pXInterface
);
486 if(pUNOInterface
== NULL
)
488 Reference
<XAccessibleContext
> pRContext
= pUNOInterface
->getAccessibleContext();
489 if( !pRContext
.is() )
493 Reference
<XAccessibleEditableText
> pRXI(pRContext
,UNO_QUERY
);
497 pRXEdtTxt
= pRXI
.get();
500 LEAVE_PROTECTED_BLOCK
503 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */