1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_editeng.hxx"
26 #include <svl/intitem.hxx>
27 #include <editeng/editeng.hxx>
28 #include <editeng/editview.hxx>
29 #include <editeng/editdata.hxx>
30 #include <editeng/eerdll.hxx>
31 #include <editeng/lrspitem.hxx>
32 #include <editeng/fhgtitem.hxx>
33 
34 #define _OUTLINER_CXX
35 #include <editeng/outliner.hxx>
36 #include <outleeng.hxx>
37 #include <paralist.hxx>
38 #include <editeng/editrids.hrc>
39 #include <svl/itemset.hxx>
40 #include <editeng/eeitem.hxx>
41 #include <editeng/editstat.hxx>
42 #include "outlundo.hxx"
43 
OutlinerEditEng(Outliner * pEngOwner,SfxItemPool * pPool)44 OutlinerEditEng::OutlinerEditEng( Outliner* pEngOwner, SfxItemPool* pPool )
45  : EditEngine( pPool )
46 {
47 	pOwner = pEngOwner;
48 }
49 
~OutlinerEditEng()50 OutlinerEditEng::~OutlinerEditEng()
51 {
52 }
53 
PaintingFirstLine(sal_uInt32 nPara,const Point & rStartPos,long nBaseLineY,const Point & rOrigin,short nOrientation,OutputDevice * pOutDev)54 void OutlinerEditEng::PaintingFirstLine( sal_uInt32 nPara, const Point& rStartPos, long nBaseLineY, const Point& rOrigin, short nOrientation, OutputDevice* pOutDev )
55 {
56 	if( GetControlWord() & EE_CNTRL_OUTLINER )
57 	{
58 		PaintFirstLineInfo aInfo( nPara, rStartPos, nBaseLineY, rOrigin, nOrientation, pOutDev );
59 		pOwner->maPaintFirstLineHdl.Call( &aInfo );
60 	}
61 
62     pOwner->PaintBullet( nPara, rStartPos, rOrigin, nOrientation, pOutDev );
63 }
64 
GetNumberFormat(sal_uInt32 nPara) const65 const SvxNumberFormat* OutlinerEditEng::GetNumberFormat( sal_uInt32 nPara ) const
66 {
67     const SvxNumberFormat* pFmt = NULL;
68     if (pOwner)
69         pFmt = pOwner->GetNumberFormat( nPara );
70     return pFmt;
71 }
72 
73 
GetBulletArea(sal_uInt32 nPara)74 Rectangle OutlinerEditEng::GetBulletArea( sal_uInt32 nPara )
75 {
76 	Rectangle aBulletArea = Rectangle( Point(), Point() );
77 	if ( nPara < pOwner->pParaList->GetParagraphCount() )
78 	{
79 		if ( pOwner->ImplHasNumberFormat( nPara ) )
80 			aBulletArea = pOwner->ImpCalcBulletArea( nPara, sal_False, sal_False );
81 	}
82 	return aBulletArea;
83 }
84 
ParagraphInserted(sal_uInt32 nNewParagraph)85 void OutlinerEditEng::ParagraphInserted( sal_uInt32 nNewParagraph )
86 {
87 	pOwner->ParagraphInserted( nNewParagraph );
88 
89     EditEngine::ParagraphInserted( nNewParagraph );
90 }
91 
ParagraphDeleted(sal_uInt32 nDeletedParagraph)92 void OutlinerEditEng::ParagraphDeleted( sal_uInt32 nDeletedParagraph )
93 {
94 	pOwner->ParagraphDeleted( nDeletedParagraph );
95 
96     EditEngine::ParagraphDeleted( nDeletedParagraph );
97 }
98 
ParagraphConnected(sal_uInt32,sal_uInt32 nRightParagraph)99 void OutlinerEditEng::ParagraphConnected( sal_uInt32 /*nLeftParagraph*/, sal_uInt32 nRightParagraph )
100 {
101     if( pOwner && pOwner->IsUndoEnabled() && !const_cast<EditEngine&>(pOwner->GetEditEngine()).IsInUndo() )
102     {
103         Paragraph* pPara = pOwner->GetParagraph( nRightParagraph );
104         if( pPara && pOwner->HasParaFlag( pPara, PARAFLAG_ISPAGE ) )
105         {
106             pOwner->InsertUndo( new OutlinerUndoChangeParaFlags( pOwner, nRightParagraph, PARAFLAG_ISPAGE, 0 ) );
107         }
108     }
109 }
110 
111 
StyleSheetChanged(SfxStyleSheet * pStyle)112 void OutlinerEditEng::StyleSheetChanged( SfxStyleSheet* pStyle )
113 {
114 	pOwner->StyleSheetChanged( pStyle );
115 }
116 
ParaAttribsChanged(sal_uInt32 nPara)117 void OutlinerEditEng::ParaAttribsChanged( sal_uInt32 nPara )
118 {
119 	pOwner->ParaAttribsChanged( nPara );
120 }
121 
SpellNextDocument()122 sal_Bool OutlinerEditEng::SpellNextDocument()
123 {
124 	return pOwner->SpellNextDocument();
125 }
126 
ConvertNextDocument()127 sal_Bool OutlinerEditEng::ConvertNextDocument()
128 {
129     return pOwner->ConvertNextDocument();
130 }
131 
GetUndoComment(sal_uInt16 nUndoId) const132 XubString OutlinerEditEng::GetUndoComment( sal_uInt16 nUndoId ) const
133 {
134 	switch( nUndoId )
135 	{
136 		case OLUNDO_DEPTH:
137 			return XubString( EditResId( RID_OUTLUNDO_DEPTH ));
138 
139 		case OLUNDO_EXPAND:
140 			return XubString( EditResId( RID_OUTLUNDO_EXPAND ));
141 
142 		case OLUNDO_COLLAPSE:
143 			return XubString( EditResId( RID_OUTLUNDO_COLLAPSE ));
144 
145 		case OLUNDO_ATTR:
146 			return XubString( EditResId( RID_OUTLUNDO_ATTR ));
147 
148 		case OLUNDO_INSERT:
149 			return XubString( EditResId( RID_OUTLUNDO_INSERT ));
150 
151 		default:
152 			return EditEngine::GetUndoComment( nUndoId );
153 	}
154 }
155 
156 // #101498#
DrawingText(const Point & rStartPos,const XubString & rText,sal_uInt16 nTextStart,sal_uInt16 nTextLen,const sal_Int32 * pDXArray,const SvxFont & rFont,sal_uInt32 nPara,sal_uInt16 nIndex,sal_uInt8 nRightToLeft,const EEngineData::WrongSpellVector * pWrongSpellVector,const SvxFieldData * pFieldData,bool bEndOfLine,bool bEndOfParagraph,bool bEndOfBullet,const::com::sun::star::lang::Locale * pLocale,const Color & rOverlineColor,const Color & rTextLineColor)157 void OutlinerEditEng::DrawingText( const Point& rStartPos, const XubString& rText, sal_uInt16 nTextStart, sal_uInt16 nTextLen,
158     const sal_Int32* pDXArray, const SvxFont& rFont, sal_uInt32 nPara, sal_uInt16 nIndex, sal_uInt8 nRightToLeft,
159     const EEngineData::WrongSpellVector* pWrongSpellVector,
160     const SvxFieldData* pFieldData,
161     bool bEndOfLine,
162     bool bEndOfParagraph,
163     bool bEndOfBullet,
164     const ::com::sun::star::lang::Locale* pLocale,
165     const Color& rOverlineColor,
166     const Color& rTextLineColor)
167 {
168     // why do bullet here at all? Just use GetEditEnginePtr()->PaintingFirstLine
169     // inside of ImpEditEngine::Paint which calls pOwner->PaintBullet with the correct
170     // values for hor and ver. No change for not-layouting (painting).
171     // changed, bullet rendering now using PaintBullet via
172 /*	if ( nIndex == 0 )
173 	{
174 		// Dann das Bullet 'malen', dort wird bStrippingPortions ausgewertet
175 		// und Outliner::DrawingText gerufen
176 
177 		// DrawingText liefert die BaseLine, DrawBullet braucht Top().
178 
179 		if(true)
180 		{
181 			// ##
182 			// another error: This call happens when only stripping, but the position
183 			// is already aligned to text output. For bullet rendering, it needs to be reset
184 			// to the correct value in x and y. PaintBullet takes care of X-start offset itself
185 			const Point aDocPosTopLeft(GetDocPosTopLeft( nPara ));
186 			const Point aCorrectedPos(rStartPos.X() - aDocPosTopLeft.X(), aDocPosTopLeft.Y() + GetFirstLineOffset( nPara ));
187 			pOwner->PaintBullet( nPara, aCorrectedPos, Point(), 0, GetRefDevice() );
188 		}
189 		else
190 		{
191 			Point aCorrectedPos( rStartPos );
192 			aCorrectedPos.Y() = GetDocPosTopLeft( nPara ).Y();
193 			aCorrectedPos.Y() += GetFirstLineOffset( nPara );
194 			pOwner->PaintBullet( nPara, aCorrectedPos, Point(), 0, GetRefDevice() );
195 		}
196 	} */
197 
198 	// #101498#
199 	pOwner->DrawingText(rStartPos,rText,nTextStart,nTextLen,pDXArray,rFont,nPara,nIndex,nRightToLeft,
200         pWrongSpellVector, pFieldData, bEndOfLine, bEndOfParagraph, bEndOfBullet, pLocale, rOverlineColor, rTextLineColor);
201 }
202 
FieldClicked(const SvxFieldItem & rField,sal_uInt32 nPara,sal_uInt16 nPos)203 void OutlinerEditEng::FieldClicked( const SvxFieldItem& rField, sal_uInt32 nPara, sal_uInt16 nPos )
204 {
205 	EditEngine::FieldClicked( rField, nPara, nPos );	// Falls URL
206 	pOwner->FieldClicked( rField, nPara, nPos );
207 }
208 
FieldSelected(const SvxFieldItem & rField,sal_uInt32 nPara,sal_uInt16 nPos)209 void OutlinerEditEng::FieldSelected( const SvxFieldItem& rField, sal_uInt32 nPara, sal_uInt16 nPos )
210 {
211 	pOwner->FieldSelected( rField, nPara, nPos );
212 }
213 
CalcFieldValue(const SvxFieldItem & rField,sal_uInt32 nPara,sal_uInt16 nPos,Color * & rpTxtColor,Color * & rpFldColor)214 XubString OutlinerEditEng::CalcFieldValue( const SvxFieldItem& rField, sal_uInt32 nPara, sal_uInt16 nPos, Color*& rpTxtColor, Color*& rpFldColor )
215 {
216 	return pOwner->CalcFieldValue( rField, nPara, nPos, rpTxtColor, rpFldColor );
217 }
218 
SetParaAttribs(sal_uInt32 nPara,const SfxItemSet & rSet)219 void OutlinerEditEng::SetParaAttribs( sal_uInt32 nPara, const SfxItemSet& rSet )
220 {
221 	Paragraph* pPara = pOwner->pParaList->GetParagraph( nPara );
222 	if( pPara )
223 	{
224 		if ( !IsInUndo() && IsUndoEnabled() )
225 			pOwner->UndoActionStart( OLUNDO_ATTR );
226 
227         EditEngine::SetParaAttribs( nPara, rSet );
228 
229 		pOwner->ImplCheckNumBulletItem( nPara );
230         // --> OD 2009-03-10 #i100014#
231         // It is not a good idea to subtract 1 from a count and cast the result
232         // to sal_uInt16 without check, if the count is 0.
233         pOwner->ImplCheckParagraphs( nPara, (sal_uInt32) (pOwner->pParaList->GetParagraphCount()) );
234         // <--
235 
236 		if ( !IsInUndo() && IsUndoEnabled() )
237 			pOwner->UndoActionEnd( OLUNDO_ATTR );
238 	}
239 }
240 
241