1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
31 #include <svl/style.hxx>
32 #include <com/sun/star/i18n/WordType.hpp>
34 #include <svl/itemset.hxx>
35 #include <editeng/editeng.hxx>
36 #include <editeng/editdata.hxx>
37 #include <editeng/outliner.hxx>
38 #include <editeng/unoedhlp.hxx>
39 #include <svl/poolitem.hxx>
40 #include <vcl/wrkwin.hxx>
41 #include <editeng/eeitem.hxx>
43 #include <editeng/unoforou.hxx>
44 #include <editeng/unofored.hxx>
45 #include <editeng/outlobj.hxx>
47 using namespace ::com::sun::star
;
49 //------------------------------------------------------------------------
51 SvxOutlinerForwarder::SvxOutlinerForwarder( Outliner
& rOutl
, sal_Bool bOutlText
/* = sal_False */ ) :
53 bOutlinerText( bOutlText
),
54 mpAttribsCache( NULL
),
55 mpParaAttribsCache( NULL
),
56 mnParaAttribsCache( 0 )
60 SvxOutlinerForwarder::~SvxOutlinerForwarder()
65 sal_uInt16
SvxOutlinerForwarder::GetParagraphCount() const
67 return (sal_uInt16
)rOutliner
.GetParagraphCount();
70 sal_uInt16
SvxOutlinerForwarder::GetTextLen( sal_uInt16 nParagraph
) const
72 return rOutliner
.GetEditEngine().GetTextLen( nParagraph
);
75 String
SvxOutlinerForwarder::GetText( const ESelection
& rSel
) const
77 //! GetText (ESelection) should probably also be in the Outliner
78 // in the time beeing use as the hack for the EditEngine:
79 EditEngine
* pEditEngine
= (EditEngine
*)&rOutliner
.GetEditEngine();
80 return pEditEngine
->GetText( rSel
, LINEEND_LF
);
83 static SfxItemSet
ImplOutlinerForwarderGetAttribs( const ESelection
& rSel
, sal_Bool bOnlyHardAttrib
, EditEngine
& rEditEngine
)
85 if( rSel
.nStartPara
== rSel
.nEndPara
)
89 switch( bOnlyHardAttrib
)
91 case EditEngineAttribs_All
:
92 nFlags
= GETATTRIBS_ALL
;
94 case EditEngineAttribs_HardAndPara
:
95 nFlags
= GETATTRIBS_PARAATTRIBS
|GETATTRIBS_CHARATTRIBS
;
97 case EditEngineAttribs_OnlyHard
:
98 nFlags
= GETATTRIBS_CHARATTRIBS
;
101 OSL_FAIL("unknown flags for SvxOutlinerForwarder::GetAttribs");
103 return rEditEngine
.GetAttribs( rSel
.nStartPara
, rSel
.nStartPos
, rSel
.nEndPos
, nFlags
);
107 return rEditEngine
.GetAttribs( rSel
, bOnlyHardAttrib
);
111 SfxItemSet
SvxOutlinerForwarder::GetAttribs( const ESelection
& rSel
, sal_Bool bOnlyHardAttrib
) const
113 if( mpAttribsCache
&& ( 0 == bOnlyHardAttrib
) )
115 // have we the correct set in cache?
116 if( ((SvxOutlinerForwarder
*)this)->maAttribCacheSelection
.IsEqual(rSel
) )
118 // yes! just return the cache
119 return *mpAttribsCache
;
123 // no, we need delete the old cache
124 delete mpAttribsCache
;
125 mpAttribsCache
= NULL
;
129 //! Does it not exist on the Outliner?
130 //! and why is the GetAttribs on the EditEngine not a const?
131 EditEngine
& rEditEngine
= (EditEngine
&)rOutliner
.GetEditEngine();
133 SfxItemSet
aSet( ImplOutlinerForwarderGetAttribs( rSel
, bOnlyHardAttrib
, rEditEngine
) );
135 if( 0 == bOnlyHardAttrib
)
137 mpAttribsCache
= new SfxItemSet( aSet
);
138 maAttribCacheSelection
= rSel
;
141 SfxStyleSheet
* pStyle
= rEditEngine
.GetStyleSheet( rSel
.nStartPara
);
143 aSet
.SetParent( &(pStyle
->GetItemSet() ) );
148 SfxItemSet
SvxOutlinerForwarder::GetParaAttribs( sal_uInt16 nPara
) const
150 if( mpParaAttribsCache
)
152 // have we the correct set in cache?
153 if( nPara
== mnParaAttribsCache
)
155 // yes! just return the cache
156 return *mpParaAttribsCache
;
160 // no, we need delete the old cache
161 delete mpParaAttribsCache
;
162 mpParaAttribsCache
= NULL
;
166 mpParaAttribsCache
= new SfxItemSet( rOutliner
.GetParaAttribs( nPara
) );
167 mnParaAttribsCache
= nPara
;
169 EditEngine
& rEditEngine
= (EditEngine
&)rOutliner
.GetEditEngine();
171 SfxStyleSheet
* pStyle
= rEditEngine
.GetStyleSheet( nPara
);
173 mpParaAttribsCache
->SetParent( &(pStyle
->GetItemSet() ) );
175 return *mpParaAttribsCache
;
178 void SvxOutlinerForwarder::SetParaAttribs( sal_uInt16 nPara
, const SfxItemSet
& rSet
)
182 const SfxItemSet
* pOldParent
= rSet
.GetParent();
184 ((SfxItemSet
*)&rSet
)->SetParent( NULL
);
186 rOutliner
.SetParaAttribs( nPara
, rSet
);
189 ((SfxItemSet
*)&rSet
)->SetParent( pOldParent
);
192 void SvxOutlinerForwarder::RemoveAttribs( const ESelection
& rSelection
, sal_Bool bRemoveParaAttribs
, sal_uInt16 nWhich
)
194 rOutliner
.RemoveAttribs( rSelection
, bRemoveParaAttribs
, nWhich
);
197 SfxItemPool
* SvxOutlinerForwarder::GetPool() const
199 return rOutliner
.GetEmptyItemSet().GetPool();
202 void SvxOutlinerForwarder::GetPortions( sal_uInt16 nPara
, std::vector
<sal_uInt16
>& rList
) const
204 ((EditEngine
&)rOutliner
.GetEditEngine()).GetPortions( nPara
, rList
);
207 void SvxOutlinerForwarder::QuickInsertText( const String
& rText
, const ESelection
& rSel
)
210 if( rText
.Len() == 0 )
212 rOutliner
.QuickDelete( rSel
);
216 rOutliner
.QuickInsertText( rText
, rSel
);
220 void SvxOutlinerForwarder::QuickInsertLineBreak( const ESelection
& rSel
)
223 rOutliner
.QuickInsertLineBreak( rSel
);
226 void SvxOutlinerForwarder::QuickInsertField( const SvxFieldItem
& rFld
, const ESelection
& rSel
)
229 rOutliner
.QuickInsertField( rFld
, rSel
);
232 void SvxOutlinerForwarder::QuickSetAttribs( const SfxItemSet
& rSet
, const ESelection
& rSel
)
235 rOutliner
.QuickSetAttribs( rSet
, rSel
);
238 XubString
SvxOutlinerForwarder::CalcFieldValue( const SvxFieldItem
& rField
, sal_uInt16 nPara
, sal_uInt16 nPos
, Color
*& rpTxtColor
, Color
*& rpFldColor
)
240 return rOutliner
.CalcFieldValue( rField
, nPara
, nPos
, rpTxtColor
, rpFldColor
);
243 void SvxOutlinerForwarder::FieldClicked( const SvxFieldItem
& rField
, sal_uInt16 nPara
, xub_StrLen nPos
)
245 rOutliner
.FieldClicked( rField
, nPara
, nPos
);
248 sal_Bool
SvxOutlinerForwarder::IsValid() const
250 // cannot reliably query outliner state
251 // while in the middle of an update
252 return rOutliner
.GetUpdateMode();
255 extern sal_uInt16
GetSvxEditEngineItemState( EditEngine
& rEditEngine
, const ESelection
& rSel
, sal_uInt16 nWhich
);
257 sal_uInt16
SvxOutlinerForwarder::GetItemState( const ESelection
& rSel
, sal_uInt16 nWhich
) const
259 return GetSvxEditEngineItemState( (EditEngine
&)rOutliner
.GetEditEngine(), rSel
, nWhich
);
262 sal_uInt16
SvxOutlinerForwarder::GetItemState( sal_uInt16 nPara
, sal_uInt16 nWhich
) const
264 const SfxItemSet
& rSet
= rOutliner
.GetParaAttribs( nPara
);
265 return rSet
.GetItemState( nWhich
);
269 void SvxOutlinerForwarder::flushCache()
273 delete mpAttribsCache
;
274 mpAttribsCache
= NULL
;
277 if( mpParaAttribsCache
)
279 delete mpParaAttribsCache
;
280 mpParaAttribsCache
= NULL
;
284 LanguageType
SvxOutlinerForwarder::GetLanguage( sal_uInt16 nPara
, sal_uInt16 nIndex
) const
286 return rOutliner
.GetLanguage(nPara
, nIndex
);
289 sal_uInt16
SvxOutlinerForwarder::GetFieldCount( sal_uInt16 nPara
) const
291 return rOutliner
.GetEditEngine().GetFieldCount(nPara
);
294 EFieldInfo
SvxOutlinerForwarder::GetFieldInfo( sal_uInt16 nPara
, sal_uInt16 nField
) const
296 return rOutliner
.GetEditEngine().GetFieldInfo( nPara
, nField
);
299 EBulletInfo
SvxOutlinerForwarder::GetBulletInfo( sal_uInt16 nPara
) const
301 return rOutliner
.GetBulletInfo( nPara
);
304 Rectangle
SvxOutlinerForwarder::GetCharBounds( sal_uInt16 nPara
, sal_uInt16 nIndex
) const
306 // EditEngine's 'internal' methods like GetCharacterBounds()
307 // don't rotate for vertical text.
308 Size
aSize( rOutliner
.CalcTextSize() );
309 ::std::swap( aSize
.Width(), aSize
.Height() );
310 bool bIsVertical( rOutliner
.IsVertical() == sal_True
);
312 // #108900# Handle virtual position one-past-the end of the string
313 if( nIndex
>= GetTextLen(nPara
) )
319 // use last character, if possible
320 aLast
= rOutliner
.GetEditEngine().GetCharacterBounds( EPosition(nPara
, nIndex
-1) );
322 // move at end of this last character, make one pixel wide
323 aLast
.Move( aLast
.Right() - aLast
.Left(), 0 );
324 aLast
.SetSize( Size(1, aLast
.GetHeight()) );
327 aLast
= SvxEditSourceHelper::EEToUserSpace( aLast
, aSize
, bIsVertical
);
331 // #109864# Bounds must lie within the paragraph
332 aLast
= GetParaBounds( nPara
);
334 // #109151# Don't use paragraph height, but line height
335 // instead. aLast is already CTL-correct
337 aLast
.SetSize( Size( rOutliner
.GetLineHeight(nPara
,0), 1 ) );
339 aLast
.SetSize( Size( 1, rOutliner
.GetLineHeight(nPara
,0) ) );
346 return SvxEditSourceHelper::EEToUserSpace( rOutliner
.GetEditEngine().GetCharacterBounds( EPosition(nPara
, nIndex
) ),
347 aSize
, bIsVertical
);
351 Rectangle
SvxOutlinerForwarder::GetParaBounds( sal_uInt16 nPara
) const
353 Point aPnt
= rOutliner
.GetDocPosTopLeft( nPara
);
354 Size aSize
= rOutliner
.CalcTextSize();
356 if( rOutliner
.IsVertical() )
358 // Hargl. Outliner's 'external' methods return the rotated
359 // dimensions, 'internal' methods like GetTextHeight( n )
361 sal_uLong nWidth
= rOutliner
.GetTextHeight( nPara
);
363 return Rectangle( aSize
.Width() - aPnt
.Y() - nWidth
, 0, aSize
.Width() - aPnt
.Y(), aSize
.Height() );
367 sal_uLong nHeight
= rOutliner
.GetTextHeight( nPara
);
369 return Rectangle( 0, aPnt
.Y(), aSize
.Width(), aPnt
.Y() + nHeight
);
373 MapMode
SvxOutlinerForwarder::GetMapMode() const
375 return rOutliner
.GetRefMapMode();
378 OutputDevice
* SvxOutlinerForwarder::GetRefDevice() const
380 return rOutliner
.GetRefDevice();
383 sal_Bool
SvxOutlinerForwarder::GetIndexAtPoint( const Point
& rPos
, sal_uInt16
& nPara
, sal_uInt16
& nIndex
) const
385 Size
aSize( rOutliner
.CalcTextSize() );
386 ::std::swap( aSize
.Width(), aSize
.Height() );
387 Point
aEEPos( SvxEditSourceHelper::UserSpaceToEE( rPos
,
389 rOutliner
.IsVertical() == sal_True
));
391 EPosition aDocPos
= rOutliner
.GetEditEngine().FindDocPosition( aEEPos
);
393 nPara
= aDocPos
.nPara
;
394 nIndex
= aDocPos
.nIndex
;
399 sal_Bool
SvxOutlinerForwarder::GetWordIndices( sal_uInt16 nPara
, sal_uInt16 nIndex
, sal_uInt16
& nStart
, sal_uInt16
& nEnd
) const
401 ESelection aRes
= rOutliner
.GetEditEngine().GetWord( ESelection(nPara
, nIndex
, nPara
, nIndex
), com::sun::star::i18n::WordType::DICTIONARY_WORD
);
403 if( aRes
.nStartPara
== nPara
&&
404 aRes
.nStartPara
== aRes
.nEndPara
)
406 nStart
= aRes
.nStartPos
;
415 sal_Bool
SvxOutlinerForwarder::GetAttributeRun( sal_uInt16
& nStartIndex
, sal_uInt16
& nEndIndex
, sal_uInt16 nPara
, sal_uInt16 nIndex
) const
417 return SvxEditSourceHelper::GetAttributeRun( nStartIndex
, nEndIndex
, rOutliner
.GetEditEngine(), nPara
, nIndex
);
420 sal_uInt16
SvxOutlinerForwarder::GetLineCount( sal_uInt16 nPara
) const
422 return static_cast < sal_uInt16
>( rOutliner
.GetLineCount(nPara
) );
425 sal_uInt16
SvxOutlinerForwarder::GetLineLen( sal_uInt16 nPara
, sal_uInt16 nLine
) const
427 return rOutliner
.GetLineLen(nPara
, nLine
);
430 void SvxOutlinerForwarder::GetLineBoundaries( /*out*/sal_uInt16
&rStart
, /*out*/sal_uInt16
&rEnd
, sal_uInt16 nPara
, sal_uInt16 nLine
) const
432 return rOutliner
.GetEditEngine().GetLineBoundaries( rStart
, rEnd
, nPara
, nLine
);
435 sal_uInt16
SvxOutlinerForwarder::GetLineNumberAtIndex( sal_uInt16 nPara
, sal_uInt16 nIndex
) const
437 return rOutliner
.GetEditEngine().GetLineNumberAtIndex( nPara
, nIndex
);
440 sal_Bool
SvxOutlinerForwarder::QuickFormatDoc( sal_Bool
)
442 rOutliner
.QuickFormatDoc();
447 sal_Bool
SvxOutlinerForwarder::Delete( const ESelection
& rSelection
)
450 rOutliner
.QuickDelete( rSelection
);
451 rOutliner
.QuickFormatDoc();
456 sal_Bool
SvxOutlinerForwarder::InsertText( const String
& rStr
, const ESelection
& rSelection
)
459 rOutliner
.QuickInsertText( rStr
, rSelection
);
460 rOutliner
.QuickFormatDoc();
465 sal_Int16
SvxOutlinerForwarder::GetDepth( sal_uInt16 nPara
) const
467 DBG_ASSERT( nPara
< GetParagraphCount(), "SvxOutlinerForwarder::GetDepth: Invalid paragraph index");
469 Paragraph
* pPara
= rOutliner
.GetParagraph( nPara
);
471 sal_Int16 nLevel
= -1;
474 nLevel
= rOutliner
.GetDepth( nPara
);
479 sal_Bool
SvxOutlinerForwarder::SetDepth( sal_uInt16 nPara
, sal_Int16 nNewDepth
)
481 DBG_ASSERT( nPara
< GetParagraphCount(), "SvxOutlinerForwarder::SetDepth: Invalid paragraph index");
483 if( (nNewDepth
>= -1) && (nNewDepth
<= 9) && (nPara
< GetParagraphCount()) )
485 Paragraph
* pPara
= rOutliner
.GetParagraph( nPara
);
488 rOutliner
.SetDepth( pPara
, nNewDepth
);
490 // const bool bOutlinerText = pSdrObject && (pSdrObject->GetObjInventor() == SdrInventor) && (pSdrObject->GetObjIdentifier() == OBJ_OUTLINETEXT);
492 rOutliner
.SetLevelDependendStyleSheet( nPara
);
501 sal_Int16
SvxOutlinerForwarder::GetNumberingStartValue( sal_uInt16 nPara
)
503 if( nPara
< GetParagraphCount() )
505 return rOutliner
.GetNumberingStartValue( nPara
);
509 OSL_FAIL( "SvxOutlinerForwarder::GetNumberingStartValue)(), Invalid paragraph index");
514 void SvxOutlinerForwarder::SetNumberingStartValue( sal_uInt16 nPara
, sal_Int16 nNumberingStartValue
)
516 if( nPara
< GetParagraphCount() )
518 rOutliner
.SetNumberingStartValue( nPara
, nNumberingStartValue
);
522 OSL_FAIL( "SvxOutlinerForwarder::SetNumberingStartValue)(), Invalid paragraph index");
526 sal_Bool
SvxOutlinerForwarder::IsParaIsNumberingRestart( sal_uInt16 nPara
)
528 if( nPara
< GetParagraphCount() )
530 return rOutliner
.IsParaIsNumberingRestart( nPara
);
534 OSL_FAIL( "SvxOutlinerForwarder::IsParaIsNumberingRestart)(), Invalid paragraph index");
539 void SvxOutlinerForwarder::SetParaIsNumberingRestart( sal_uInt16 nPara
, sal_Bool bParaIsNumberingRestart
)
541 if( nPara
< GetParagraphCount() )
543 rOutliner
.SetParaIsNumberingRestart( nPara
, bParaIsNumberingRestart
);
547 OSL_FAIL( "SvxOutlinerForwarder::SetParaIsNumberingRestart)(), Invalid paragraph index");
551 const SfxItemSet
* SvxOutlinerForwarder::GetEmptyItemSetPtr()
553 EditEngine
& rEditEngine
= const_cast< EditEngine
& >( rOutliner
.GetEditEngine() );
554 return &rEditEngine
.GetEmptyItemSet();
557 void SvxOutlinerForwarder::AppendParagraph()
559 EditEngine
& rEditEngine
= const_cast< EditEngine
& >( rOutliner
.GetEditEngine() );
560 rEditEngine
.InsertParagraph( rEditEngine
.GetParagraphCount(), String::EmptyString() );
563 xub_StrLen
SvxOutlinerForwarder::AppendTextPortion( sal_uInt16 nPara
, const String
&rText
, const SfxItemSet
& /*rSet*/ )
567 EditEngine
& rEditEngine
= const_cast< EditEngine
& >( rOutliner
.GetEditEngine() );
568 sal_uInt16 nParaCount
= rEditEngine
.GetParagraphCount();
569 DBG_ASSERT( nPara
< nParaCount
, "paragraph index out of bounds" );
570 if (/*0 <= nPara && */nPara
< nParaCount
)
572 nLen
= rEditEngine
.GetTextLen( nPara
);
573 rEditEngine
.QuickInsertText( rText
, ESelection( nPara
, nLen
, nPara
, nLen
) );
579 void SvxOutlinerForwarder::CopyText(const SvxTextForwarder
& rSource
)
581 const SvxOutlinerForwarder
* pSourceForwarder
= dynamic_cast< const SvxOutlinerForwarder
* >( &rSource
);
582 if( !pSourceForwarder
)
584 OutlinerParaObject
* pNewOutlinerParaObject
= pSourceForwarder
->rOutliner
.CreateParaObject();
585 rOutliner
.SetText( *pNewOutlinerParaObject
);
586 delete pNewOutlinerParaObject
;
589 //------------------------------------------------------------------------
592 sal_Int16
SvxTextForwarder::GetNumberingStartValue( sal_uInt16
)
597 void SvxTextForwarder::SetNumberingStartValue( sal_uInt16
, sal_Int16
)
601 sal_Bool
SvxTextForwarder::IsParaIsNumberingRestart( sal_uInt16
)
606 void SvxTextForwarder::SetParaIsNumberingRestart( sal_uInt16
, sal_Bool
)
610 //------------------------------------------------------------------------
612 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */