Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include <algorithm>
22 : #include <editeng/eeitem.hxx>
23 : #include <com/sun/star/i18n/WordType.hpp>
24 :
25 : #include <svl/itemset.hxx>
26 : #include <editeng/editeng.hxx>
27 : #include <editeng/editview.hxx>
28 : #include <editeng/unoedhlp.hxx>
29 : #include <editeng/editdata.hxx>
30 : #include <editeng/outliner.hxx>
31 : #include <editeng/editobj.hxx>
32 :
33 : #include <editeng/unofored.hxx>
34 :
35 : using namespace ::com::sun::star;
36 :
37 :
38 :
39 0 : SvxEditEngineForwarder::SvxEditEngineForwarder( EditEngine& rEngine ) :
40 0 : rEditEngine( rEngine )
41 : {
42 0 : }
43 :
44 0 : SvxEditEngineForwarder::~SvxEditEngineForwarder()
45 : {
46 : // the EditEngine may need to be deleted from the outside
47 0 : }
48 :
49 0 : sal_Int32 SvxEditEngineForwarder::GetParagraphCount() const
50 : {
51 0 : return rEditEngine.GetParagraphCount();
52 : }
53 :
54 0 : sal_Int32 SvxEditEngineForwarder::GetTextLen( sal_Int32 nParagraph ) const
55 : {
56 0 : return rEditEngine.GetTextLen( nParagraph );
57 : }
58 :
59 0 : OUString SvxEditEngineForwarder::GetText( const ESelection& rSel ) const
60 : {
61 0 : return convertLineEnd(rEditEngine.GetText(rSel, LINEEND_LF), GetSystemLineEnd());
62 : }
63 :
64 0 : SfxItemSet SvxEditEngineForwarder::GetAttribs( const ESelection& rSel, EditEngineAttribs nOnlyHardAttrib ) const
65 : {
66 0 : if( rSel.nStartPara == rSel.nEndPara )
67 : {
68 0 : sal_uInt8 nFlags = 0;
69 0 : switch( nOnlyHardAttrib )
70 : {
71 : case EditEngineAttribs_All:
72 0 : nFlags = GETATTRIBS_ALL;
73 0 : break;
74 : case EditEngineAttribs_HardAndPara:
75 0 : nFlags = GETATTRIBS_PARAATTRIBS|GETATTRIBS_CHARATTRIBS;
76 0 : break;
77 : case EditEngineAttribs_OnlyHard:
78 0 : nFlags = GETATTRIBS_CHARATTRIBS;
79 0 : break;
80 : default:
81 : OSL_FAIL("unknown flags for SvxOutlinerForwarder::GetAttribs");
82 : }
83 :
84 0 : return rEditEngine.GetAttribs( rSel.nStartPara, rSel.nStartPos, rSel.nEndPos, nFlags );
85 : }
86 : else
87 : {
88 0 : return rEditEngine.GetAttribs( rSel, nOnlyHardAttrib );
89 : }
90 : }
91 :
92 0 : SfxItemSet SvxEditEngineForwarder::GetParaAttribs( sal_Int32 nPara ) const
93 : {
94 0 : SfxItemSet aSet( rEditEngine.GetParaAttribs( nPara ) );
95 :
96 0 : sal_uInt16 nWhich = EE_PARA_START;
97 0 : while( nWhich <= EE_PARA_END )
98 : {
99 0 : if( aSet.GetItemState( nWhich, true ) != SFX_ITEM_ON )
100 : {
101 0 : if( rEditEngine.HasParaAttrib( nPara, nWhich ) )
102 0 : aSet.Put( rEditEngine.GetParaAttrib( nPara, nWhich ) );
103 : }
104 0 : nWhich++;
105 : }
106 :
107 0 : return aSet;
108 : }
109 :
110 0 : void SvxEditEngineForwarder::SetParaAttribs( sal_Int32 nPara, const SfxItemSet& rSet )
111 : {
112 0 : rEditEngine.SetParaAttribs( nPara, rSet );
113 0 : }
114 :
115 0 : void SvxEditEngineForwarder::RemoveAttribs( const ESelection& rSelection, bool bRemoveParaAttribs, sal_uInt16 nWhich )
116 : {
117 0 : rEditEngine.RemoveAttribs( rSelection, bRemoveParaAttribs, nWhich );
118 0 : }
119 :
120 0 : SfxItemPool* SvxEditEngineForwarder::GetPool() const
121 : {
122 0 : return rEditEngine.GetEmptyItemSet().GetPool();
123 : }
124 :
125 0 : void SvxEditEngineForwarder::GetPortions( sal_Int32 nPara, std::vector<sal_Int32>& rList ) const
126 : {
127 0 : rEditEngine.GetPortions( nPara, rList );
128 0 : }
129 :
130 0 : void SvxEditEngineForwarder::QuickInsertText( const OUString& rText, const ESelection& rSel )
131 : {
132 0 : rEditEngine.QuickInsertText( rText, rSel );
133 0 : }
134 :
135 0 : void SvxEditEngineForwarder::QuickInsertLineBreak( const ESelection& rSel )
136 : {
137 0 : rEditEngine.QuickInsertLineBreak( rSel );
138 0 : }
139 :
140 0 : void SvxEditEngineForwarder::QuickInsertField( const SvxFieldItem& rFld, const ESelection& rSel )
141 : {
142 0 : rEditEngine.QuickInsertField( rFld, rSel );
143 0 : }
144 :
145 0 : void SvxEditEngineForwarder::QuickSetAttribs( const SfxItemSet& rSet, const ESelection& rSel )
146 : {
147 0 : rEditEngine.QuickSetAttribs( rSet, rSel );
148 0 : }
149 :
150 0 : bool SvxEditEngineForwarder::IsValid() const
151 : {
152 : // cannot reliably query EditEngine state
153 : // while in the middle of an update
154 0 : return rEditEngine.GetUpdateMode();
155 : }
156 :
157 0 : OUString SvxEditEngineForwarder::CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rpTxtColor, Color*& rpFldColor )
158 : {
159 0 : return rEditEngine.CalcFieldValue( rField, nPara, nPos, rpTxtColor, rpFldColor );
160 : }
161 :
162 0 : void SvxEditEngineForwarder::FieldClicked( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos )
163 : {
164 0 : rEditEngine.FieldClicked( rField, nPara, nPos );
165 0 : }
166 :
167 0 : sal_uInt16 GetSvxEditEngineItemState( EditEngine& rEditEngine, const ESelection& rSel, sal_uInt16 nWhich )
168 : {
169 0 : std::vector<EECharAttrib> aAttribs;
170 :
171 0 : const SfxPoolItem* pLastItem = NULL;
172 :
173 0 : SfxItemState eState = SFX_ITEM_DEFAULT;
174 :
175 : // check all paragraphs inside the selection
176 0 : for( sal_Int32 nPara = rSel.nStartPara; nPara <= rSel.nEndPara; nPara++ )
177 : {
178 0 : SfxItemState eParaState = SFX_ITEM_DEFAULT;
179 :
180 : // calculate start and endpos for this paragraph
181 0 : sal_Int32 nPos = 0;
182 0 : if( rSel.nStartPara == nPara )
183 0 : nPos = rSel.nStartPos;
184 :
185 0 : sal_Int32 nEndPos = rSel.nEndPos;
186 0 : if( rSel.nEndPara != nPara )
187 0 : nEndPos = rEditEngine.GetTextLen( nPara );
188 :
189 :
190 : // get list of char attribs
191 0 : rEditEngine.GetCharAttribs( nPara, aAttribs );
192 :
193 0 : sal_Bool bEmpty = sal_True; // we found no item inside the selection of this paragraph
194 0 : sal_Bool bGaps = sal_False; // we found items but theire gaps between them
195 0 : sal_Int32 nLastEnd = nPos;
196 :
197 0 : const SfxPoolItem* pParaItem = NULL;
198 :
199 0 : for(std::vector<EECharAttrib>::const_iterator i = aAttribs.begin(); i < aAttribs.end(); ++i)
200 : {
201 : DBG_ASSERT(i->pAttr, "GetCharAttribs gives corrupt data");
202 :
203 0 : const sal_Bool bEmptyPortion = i->nStart == i->nEnd;
204 0 : if((!bEmptyPortion && i->nStart >= nEndPos) ||
205 0 : (bEmptyPortion && i->nStart > nEndPos))
206 0 : break; // break if we are already behind our selection
207 :
208 0 : if((!bEmptyPortion && i->nEnd <= nPos) ||
209 0 : (bEmptyPortion && i->nEnd < nPos))
210 0 : continue; // or if the attribute ends before our selection
211 :
212 0 : if(i->pAttr->Which() != nWhich)
213 0 : continue; // skip if is not the searched item
214 :
215 : // if we already found an item
216 0 : if( pParaItem )
217 : {
218 : // ... and its different to this one than the state is dont care
219 0 : if(*pParaItem != *(i->pAttr))
220 0 : return SFX_ITEM_DONTCARE;
221 : }
222 : else
223 0 : pParaItem = i->pAttr;
224 :
225 0 : if( bEmpty )
226 0 : bEmpty = sal_False;
227 :
228 0 : if(!bGaps && i->nStart > nLastEnd)
229 0 : bGaps = sal_True;
230 :
231 0 : nLastEnd = i->nEnd;
232 : }
233 :
234 0 : if( !bEmpty && !bGaps && nLastEnd < ( nEndPos - 1 ) )
235 0 : bGaps = sal_True;
236 :
237 0 : if( bEmpty )
238 0 : eParaState = SFX_ITEM_DEFAULT;
239 0 : else if( bGaps )
240 0 : eParaState = SFX_ITEM_DONTCARE;
241 : else
242 0 : eParaState = SFX_ITEM_SET;
243 :
244 : // if we already found an item check if we found the same
245 0 : if( pLastItem )
246 : {
247 0 : if( (pParaItem == NULL) || (*pLastItem != *pParaItem) )
248 0 : return SFX_ITEM_DONTCARE;
249 : }
250 : else
251 : {
252 0 : pLastItem = pParaItem;
253 0 : eState = eParaState;
254 : }
255 : }
256 :
257 0 : return eState;
258 : }
259 :
260 0 : sal_uInt16 SvxEditEngineForwarder::GetItemState( const ESelection& rSel, sal_uInt16 nWhich ) const
261 : {
262 0 : return GetSvxEditEngineItemState( rEditEngine, rSel, nWhich );
263 : }
264 :
265 0 : sal_uInt16 SvxEditEngineForwarder::GetItemState( sal_Int32 nPara, sal_uInt16 nWhich ) const
266 : {
267 0 : const SfxItemSet& rSet = rEditEngine.GetParaAttribs( nPara );
268 0 : return rSet.GetItemState( nWhich );
269 : }
270 :
271 0 : LanguageType SvxEditEngineForwarder::GetLanguage( sal_Int32 nPara, sal_Int32 nIndex ) const
272 : {
273 0 : return rEditEngine.GetLanguage(nPara, nIndex);
274 : }
275 :
276 0 : sal_Int32 SvxEditEngineForwarder::GetFieldCount( sal_Int32 nPara ) const
277 : {
278 0 : return rEditEngine.GetFieldCount(nPara);
279 : }
280 :
281 0 : EFieldInfo SvxEditEngineForwarder::GetFieldInfo( sal_Int32 nPara, sal_uInt16 nField ) const
282 : {
283 0 : return rEditEngine.GetFieldInfo( nPara, nField );
284 : }
285 :
286 0 : EBulletInfo SvxEditEngineForwarder::GetBulletInfo( sal_Int32 ) const
287 : {
288 0 : return EBulletInfo();
289 : }
290 :
291 0 : Rectangle SvxEditEngineForwarder::GetCharBounds( sal_Int32 nPara, sal_Int32 nIndex ) const
292 : {
293 : // #101701#
294 : // EditEngine's 'internal' methods like GetCharacterBounds()
295 : // don't rotate for vertical text.
296 0 : Size aSize( rEditEngine.CalcTextWidth(), rEditEngine.GetTextHeight() );
297 0 : ::std::swap( aSize.Width(), aSize.Height() );
298 0 : bool bIsVertical( rEditEngine.IsVertical() );
299 :
300 : // #108900# Handle virtual position one-past-the end of the string
301 0 : if( nIndex >= rEditEngine.GetTextLen(nPara) )
302 : {
303 0 : Rectangle aLast;
304 :
305 0 : if( nIndex )
306 : {
307 : // use last character, if possible
308 0 : aLast = rEditEngine.GetCharacterBounds( EPosition(nPara, nIndex-1) );
309 :
310 : // move at end of this last character, make one pixel wide
311 0 : aLast.Move( aLast.Right() - aLast.Left(), 0 );
312 0 : aLast.SetSize( Size(1, aLast.GetHeight()) );
313 :
314 : // take care for CTL
315 0 : aLast = SvxEditSourceHelper::EEToUserSpace( aLast, aSize, bIsVertical );
316 : }
317 : else
318 : {
319 : // #109864# Bounds must lie within the paragraph
320 0 : aLast = GetParaBounds( nPara );
321 :
322 : // #109151# Don't use paragraph height, but line height
323 : // instead. aLast is already CTL-correct
324 0 : if( bIsVertical)
325 0 : aLast.SetSize( Size( rEditEngine.GetLineHeight(nPara,0), 1 ) );
326 : else
327 0 : aLast.SetSize( Size( 1, rEditEngine.GetLineHeight(nPara,0) ) );
328 : }
329 :
330 0 : return aLast;
331 : }
332 : else
333 : {
334 0 : return SvxEditSourceHelper::EEToUserSpace( rEditEngine.GetCharacterBounds( EPosition(nPara, nIndex) ),
335 0 : aSize, bIsVertical );
336 : }
337 : }
338 :
339 0 : Rectangle SvxEditEngineForwarder::GetParaBounds( sal_Int32 nPara ) const
340 : {
341 0 : const Point aPnt = rEditEngine.GetDocPosTopLeft( nPara );
342 : sal_uLong nWidth;
343 : sal_uLong nHeight;
344 : sal_uLong nTextWidth;
345 :
346 0 : if( rEditEngine.IsVertical() )
347 : {
348 : // #101701#
349 : // Hargl. EditEngine's 'external' methods return the rotated
350 : // dimensions, 'internal' methods like GetTextHeight( n )
351 : // don't rotate.
352 0 : nWidth = rEditEngine.GetTextHeight( nPara );
353 0 : nHeight = rEditEngine.GetTextHeight();
354 0 : nTextWidth = rEditEngine.GetTextHeight();
355 :
356 0 : return Rectangle( nTextWidth - aPnt.Y() - nWidth, 0, nTextWidth - aPnt.Y(), nHeight );
357 : }
358 : else
359 : {
360 0 : nWidth = rEditEngine.CalcTextWidth();
361 0 : nHeight = rEditEngine.GetTextHeight( nPara );
362 :
363 0 : return Rectangle( 0, aPnt.Y(), nWidth, aPnt.Y() + nHeight );
364 : }
365 : }
366 :
367 0 : MapMode SvxEditEngineForwarder::GetMapMode() const
368 : {
369 0 : return rEditEngine.GetRefMapMode();
370 : }
371 :
372 0 : OutputDevice* SvxEditEngineForwarder::GetRefDevice() const
373 : {
374 0 : return rEditEngine.GetRefDevice();
375 : }
376 :
377 0 : bool SvxEditEngineForwarder::GetIndexAtPoint( const Point& rPos, sal_Int32& nPara, sal_Int32& nIndex ) const
378 : {
379 0 : Size aSize( rEditEngine.CalcTextWidth(), rEditEngine.GetTextHeight() );
380 0 : ::std::swap( aSize.Width(), aSize.Height() );
381 : Point aEEPos( SvxEditSourceHelper::UserSpaceToEE( rPos,
382 : aSize,
383 0 : rEditEngine.IsVertical() ));
384 :
385 0 : EPosition aDocPos = rEditEngine.FindDocPosition( aEEPos );
386 :
387 0 : nPara = aDocPos.nPara;
388 0 : nIndex = aDocPos.nIndex;
389 :
390 0 : return true;
391 : }
392 :
393 0 : bool SvxEditEngineForwarder::GetWordIndices( sal_Int32 nPara, sal_Int32 nIndex, sal_Int32& nStart, sal_Int32& nEnd ) const
394 : {
395 0 : ESelection aRes = rEditEngine.GetWord( ESelection(nPara, nIndex, nPara, nIndex), com::sun::star::i18n::WordType::DICTIONARY_WORD );
396 :
397 0 : if( aRes.nStartPara == nPara &&
398 0 : aRes.nStartPara == aRes.nEndPara )
399 : {
400 0 : nStart = aRes.nStartPos;
401 0 : nEnd = aRes.nEndPos;
402 :
403 0 : return true;
404 : }
405 :
406 0 : return false;
407 : }
408 :
409 0 : bool SvxEditEngineForwarder::GetAttributeRun( sal_Int32& nStartIndex, sal_Int32& nEndIndex, sal_Int32 nPara, sal_Int32 nIndex, bool bInCell ) const
410 : {
411 0 : return SvxEditSourceHelper::GetAttributeRun( nStartIndex, nEndIndex, rEditEngine, nPara, nIndex, bInCell );
412 : }
413 :
414 0 : sal_Int32 SvxEditEngineForwarder::GetLineCount( sal_Int32 nPara ) const
415 : {
416 0 : return rEditEngine.GetLineCount(nPara);
417 : }
418 :
419 0 : sal_Int32 SvxEditEngineForwarder::GetLineLen( sal_Int32 nPara, sal_Int32 nLine ) const
420 : {
421 0 : return rEditEngine.GetLineLen(nPara, nLine);
422 : }
423 :
424 0 : void SvxEditEngineForwarder::GetLineBoundaries( /*out*/sal_Int32 &rStart, /*out*/sal_Int32 &rEnd, sal_Int32 nPara, sal_Int32 nLine ) const
425 : {
426 0 : rEditEngine.GetLineBoundaries(rStart, rEnd, nPara, nLine);
427 0 : }
428 :
429 0 : sal_Int32 SvxEditEngineForwarder::GetLineNumberAtIndex( sal_Int32 nPara, sal_Int32 nIndex ) const
430 : {
431 0 : return rEditEngine.GetLineNumberAtIndex(nPara, nIndex);
432 : }
433 :
434 :
435 0 : bool SvxEditEngineForwarder::QuickFormatDoc( bool )
436 : {
437 0 : rEditEngine.QuickFormatDoc();
438 :
439 0 : return true;
440 : }
441 :
442 0 : bool SvxEditEngineForwarder::Delete( const ESelection& rSelection )
443 : {
444 0 : rEditEngine.QuickDelete( rSelection );
445 0 : rEditEngine.QuickFormatDoc();
446 :
447 0 : return true;
448 : }
449 :
450 0 : bool SvxEditEngineForwarder::InsertText( const OUString& rStr, const ESelection& rSelection )
451 : {
452 0 : rEditEngine.QuickInsertText( rStr, rSelection );
453 0 : rEditEngine.QuickFormatDoc();
454 :
455 0 : return true;
456 : }
457 :
458 0 : sal_Int16 SvxEditEngineForwarder::GetDepth( sal_Int32 ) const
459 : {
460 : // EditEngine does not support outline depth
461 0 : return -1;
462 : }
463 :
464 0 : bool SvxEditEngineForwarder::SetDepth( sal_Int32, sal_Int16 nNewDepth )
465 : {
466 : // EditEngine does not support outline depth
467 0 : return nNewDepth == -1;
468 : }
469 :
470 0 : const SfxItemSet * SvxEditEngineForwarder::GetEmptyItemSetPtr()
471 : {
472 0 : return &rEditEngine.GetEmptyItemSet();
473 : }
474 :
475 0 : void SvxEditEngineForwarder::AppendParagraph()
476 : {
477 0 : rEditEngine.InsertParagraph( rEditEngine.GetParagraphCount(), OUString() );
478 0 : }
479 :
480 0 : sal_Int32 SvxEditEngineForwarder::AppendTextPortion( sal_Int32 nPara, const OUString &rText, const SfxItemSet & /*rSet*/ )
481 : {
482 0 : sal_Int32 nLen = 0;
483 :
484 0 : sal_Int32 nParaCount = rEditEngine.GetParagraphCount();
485 : DBG_ASSERT( nPara < nParaCount, "paragraph index out of bounds" );
486 0 : if (0 <= nPara && nPara < nParaCount)
487 : {
488 0 : nLen = rEditEngine.GetTextLen( nPara );
489 0 : rEditEngine.QuickInsertText( rText, ESelection( nPara, nLen, nPara, nLen ) );
490 : }
491 :
492 0 : return nLen;
493 : }
494 :
495 0 : void SvxEditEngineForwarder::CopyText(const SvxTextForwarder& rSource)
496 : {
497 0 : const SvxEditEngineForwarder* pSourceForwarder = dynamic_cast< const SvxEditEngineForwarder* >( &rSource );
498 0 : if( !pSourceForwarder )
499 0 : return;
500 0 : EditTextObject* pNewTextObject = pSourceForwarder->rEditEngine.CreateTextObject();
501 0 : rEditEngine.SetText( *pNewTextObject );
502 0 : delete pNewTextObject;
503 : }
504 :
505 :
506 :
507 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|