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 : #include "dcontact.hxx"
21 : #include "dflyobj.hxx"
22 : #include "pam.hxx"
23 : #include "flyfrm.hxx"
24 : #include "rootfrm.hxx"
25 : #include "frmfmt.hxx"
26 : #include "viewsh.hxx"
27 :
28 : #include <vcl/outdev.hxx>
29 : #include <editeng/lrspitem.hxx>
30 : #include <editeng/ulspitem.hxx>
31 : #include <fmtanchr.hxx>
32 : #include <fmtflcnt.hxx>
33 : #include <fmtornt.hxx>
34 : #include <frmatr.hxx>
35 : #include "flyfrms.hxx"
36 : #include "txatbase.hxx"
37 : #include "porfly.hxx"
38 : #include "porlay.hxx"
39 : #include "inftxt.hxx"
40 :
41 : // OD 2004-05-24 #i28701#
42 : #include <sortedobjs.hxx>
43 :
44 : // class SwFlyPortion => we expect a frame-locale SwRect!
45 :
46 0 : void SwFlyPortion::Paint( const SwTxtPaintInfo& ) const
47 : {
48 0 : }
49 :
50 0 : bool SwFlyPortion::Format( SwTxtFormatInfo &rInf )
51 : {
52 : OSL_ENSURE( Fix() >= rInf.X(), "SwFlyPortion::Format" );
53 : // tabs must be expanded (Bug 8537)
54 0 : if( rInf.GetLastTab() )
55 0 : ((SwLinePortion*)rInf.GetLastTab())->FormatEOL( rInf );
56 :
57 0 : rInf.GetLast()->FormatEOL( rInf );
58 0 : PrtWidth( static_cast<sal_uInt16>(Fix() - rInf.X() + PrtWidth()) );
59 0 : if( !Width() )
60 : {
61 : OSL_ENSURE( Width(), "+SwFlyPortion::Format: a fly is a fly is a fly" );
62 0 : Width(1);
63 : }
64 :
65 : // resetting
66 0 : rInf.SetFly( 0 );
67 0 : rInf.Width( rInf.RealWidth() );
68 0 : rInf.GetParaPortion()->SetFly( true );
69 :
70 : // trailing blank:
71 0 : if( rInf.GetIdx() < rInf.GetTxt().getLength() && 1 < rInf.GetIdx()
72 0 : && !rInf.GetRest()
73 0 : && ' ' == rInf.GetChar( rInf.GetIdx() )
74 0 : && ' ' != rInf.GetChar( rInf.GetIdx() - 1 )
75 0 : && ( !rInf.GetLast() || !rInf.GetLast()->IsBreakPortion() ) )
76 : {
77 0 : SetBlankWidth( rInf.GetTxtSize(OUString(' ')).Width() );
78 0 : SetLen( 1 );
79 : }
80 :
81 0 : const sal_uInt16 nNewWidth = static_cast<sal_uInt16>(rInf.X() + PrtWidth());
82 0 : if( rInf.Width() <= nNewWidth )
83 : {
84 0 : Truncate();
85 0 : if( nNewWidth > rInf.Width() )
86 : {
87 0 : PrtWidth( nNewWidth - rInf.Width() );
88 0 : SetFixWidth( PrtWidth() );
89 : }
90 0 : return true;
91 : }
92 0 : return false;
93 : }
94 :
95 0 : bool SwFlyCntPortion::Format( SwTxtFormatInfo &rInf )
96 : {
97 0 : bool bFull = rInf.Width() < rInf.X() + PrtWidth();
98 :
99 0 : if( bFull )
100 : {
101 : // 3924: if the line is full, and the character-bound frame is at
102 : // the beginning of a line
103 : // 5157: if it is not possible to side step into a Fly
104 : // "Begin of line" criteria ( ! rInf.X() ) has to be extended.
105 : // KerningPortions at beginning of line, e.g., for grid layout
106 : // must be considered.
107 0 : const SwLinePortion* pLastPor = rInf.GetLast();
108 0 : const sal_uInt16 nLeft = ( pLastPor &&
109 0 : ( pLastPor->IsKernPortion() ||
110 0 : pLastPor->IsErgoSumPortion() ) ) ?
111 0 : pLastPor->Width() :
112 0 : 0;
113 :
114 0 : if( nLeft == rInf.X() && ! rInf.GetFly() )
115 : {
116 0 : Width( rInf.Width() );
117 0 : bFull = false; // so that notes can still be placed in this line
118 : }
119 : else
120 : {
121 0 : if( !rInf.GetFly() )
122 0 : rInf.SetNewLine( true );
123 0 : Width(0);
124 0 : SetAscent(0);
125 0 : SetLen(0);
126 0 : if( rInf.GetLast() )
127 0 : rInf.GetLast()->FormatEOL( rInf );
128 :
129 0 : return bFull;
130 : }
131 : }
132 :
133 0 : rInf.GetParaPortion()->SetFly( true );
134 0 : return bFull;
135 : }
136 :
137 : //TODO: improve documentation
138 : /** move character-bound objects inside the given area
139 : *
140 : * This allows moving those objects from Master to Follow, or vice versa.
141 : *
142 : * @param pNew
143 : * @param nStart
144 : * @param nEnd
145 : */
146 0 : void SwTxtFrm::MoveFlyInCnt( SwTxtFrm *pNew, sal_Int32 nStart, sal_Int32 nEnd )
147 : {
148 0 : SwSortedObjs *pObjs = 0L;
149 0 : if ( 0 != (pObjs = GetDrawObjs()) )
150 : {
151 0 : for ( sal_uInt32 i = 0; GetDrawObjs() && i < pObjs->Count(); ++i )
152 : {
153 : // OD 2004-03-29 #i26791#
154 : // #i28701# - consider changed type of
155 : // <SwSortedList> entries
156 0 : SwAnchoredObject* pAnchoredObj = (*pObjs)[i];
157 0 : const SwFmtAnchor& rAnch = pAnchoredObj->GetFrmFmt().GetAnchor();
158 0 : if (rAnch.GetAnchorId() == FLY_AS_CHAR)
159 : {
160 0 : const SwPosition* pPos = rAnch.GetCntntAnchor();
161 0 : const sal_Int32 nIdx = pPos->nContent.GetIndex();
162 0 : if ( nIdx >= nStart && nEnd > nIdx )
163 : {
164 0 : if ( pAnchoredObj->ISA(SwFlyFrm) )
165 : {
166 0 : RemoveFly( static_cast<SwFlyFrm*>(pAnchoredObj) );
167 0 : pNew->AppendFly( static_cast<SwFlyFrm*>(pAnchoredObj) );
168 : }
169 0 : else if ( pAnchoredObj->ISA(SwAnchoredDrawObject) )
170 : {
171 0 : RemoveDrawObj( *pAnchoredObj );
172 0 : pNew->AppendDrawObj( *pAnchoredObj );
173 : }
174 0 : --i;
175 : }
176 : }
177 : }
178 : }
179 0 : }
180 :
181 0 : sal_Int32 SwTxtFrm::CalcFlyPos( SwFrmFmt* pSearch )
182 : {
183 0 : SwpHints* pHints = GetTxtNode()->GetpSwpHints();
184 : OSL_ENSURE( pHints, "CalcFlyPos: Why me?" );
185 0 : if( !pHints )
186 0 : return COMPLETE_STRING;
187 0 : SwTxtAttr* pFound = NULL;
188 0 : for ( sal_uInt16 i = 0; i < pHints->Count(); i++)
189 : {
190 0 : SwTxtAttr *pHt = pHints->GetTextHint( i );
191 0 : if( RES_TXTATR_FLYCNT == pHt->Which() )
192 : {
193 0 : SwFrmFmt* pFrmFmt = pHt->GetFlyCnt().GetFrmFmt();
194 0 : if( pFrmFmt == pSearch )
195 0 : pFound = pHt;
196 : }
197 : }
198 : OSL_ENSURE( pHints, "CalcFlyPos: Not Found!" );
199 0 : if( !pFound )
200 0 : return COMPLETE_STRING;
201 0 : return *pFound->GetStart();
202 : }
203 :
204 0 : void SwFlyCntPortion::Paint( const SwTxtPaintInfo &rInf ) const
205 : {
206 0 : if( bDraw )
207 : {
208 0 : if( !((SwDrawContact*)pContact)->GetAnchorFrm() )
209 : {
210 : // OD 2004-04-01 #i26791# - no direct positioning of the drawing
211 : // object is needed.
212 0 : SwDrawContact* pDrawContact = static_cast<SwDrawContact*>(pContact);
213 0 : pDrawContact->ConnectToLayout();
214 : }
215 : }
216 : else
217 : {
218 : // baseline output
219 : // 7922: re-paint everything at a CompletePaint call
220 0 : SwRect aRepaintRect( rInf.GetPaintRect() );
221 :
222 0 : if ( rInf.GetTxtFrm()->IsRightToLeft() )
223 0 : rInf.GetTxtFrm()->SwitchLTRtoRTL( aRepaintRect );
224 :
225 0 : if ( rInf.GetTxtFrm()->IsVertical() )
226 0 : rInf.GetTxtFrm()->SwitchHorizontalToVertical( aRepaintRect );
227 :
228 0 : if( (GetFlyFrm()->IsCompletePaint() ||
229 0 : GetFlyFrm()->Frm().IsOver( aRepaintRect )) &&
230 0 : SwFlyFrm::IsPaint( (SdrObject*)GetFlyFrm()->GetVirtDrawObj(),
231 0 : GetFlyFrm()->getRootFrm()->GetCurrShell() ))
232 : {
233 0 : SwRect aRect( GetFlyFrm()->Frm() );
234 0 : if( !GetFlyFrm()->IsCompletePaint() )
235 0 : aRect._Intersection( aRepaintRect );
236 :
237 : // GetFlyFrm() may change the layout mode at the output device.
238 : {
239 0 : SwLayoutModeModifier aLayoutModeModifier( *rInf.GetOut() );
240 0 : GetFlyFrm()->Paint( aRect );
241 : }
242 : ((SwTxtPaintInfo&)rInf).GetRefDev()->SetLayoutMode(
243 0 : rInf.GetOut()->GetLayoutMode() );
244 :
245 : // As the OutputDevice might be anything, the font must be re-selected.
246 : // Being in const method should not be a problem.
247 0 : ((SwTxtPaintInfo&)rInf).SelectFont();
248 :
249 : OSL_ENSURE( ! rInf.GetVsh() || rInf.GetVsh()->GetOut() == rInf.GetOut(),
250 : "SwFlyCntPortion::Paint: Outdev has changed" );
251 0 : if( rInf.GetVsh() )
252 0 : ((SwTxtPaintInfo&)rInf).SetOut( rInf.GetVsh()->GetOut() );
253 : }
254 : }
255 0 : }
256 :
257 : // use the dimensions of pFly->OutRect()
258 : // OD 29.07.2003 #110978# - use new datatype for parameter <nFlags>
259 0 : SwFlyCntPortion::SwFlyCntPortion( const SwTxtFrm& rFrm,
260 : SwFlyInCntFrm *pFly, const Point &rBase,
261 : long nLnAscent, long nLnDescent,
262 : long nFlyAsc, long nFlyDesc,
263 : objectpositioning::AsCharFlags nFlags ) :
264 : pContact( pFly ),
265 : bDraw( false ),
266 : bMax( false ),
267 0 : nAlign( 0 )
268 : {
269 : OSL_ENSURE( pFly, "SwFlyCntPortion::SwFlyCntPortion: no SwFlyInCntFrm!" );
270 0 : nLineLength = 1;
271 0 : nFlags |= AS_CHAR_ULSPACE | AS_CHAR_INIT;
272 0 : SetBase( rFrm, rBase, nLnAscent, nLnDescent, nFlyAsc, nFlyDesc, nFlags );
273 0 : SetWhichPor( POR_FLYCNT );
274 0 : }
275 :
276 : // OD 29.07.2003 #110978# - use new datatype for parameter <nFlags>
277 0 : SwFlyCntPortion::SwFlyCntPortion( const SwTxtFrm& rFrm,
278 : SwDrawContact *pDrawContact, const Point &rBase,
279 : long nLnAscent, long nLnDescent,
280 : long nFlyAsc, long nFlyDesc,
281 : objectpositioning::AsCharFlags nFlags ) :
282 : pContact( pDrawContact ),
283 : bDraw( true ),
284 : bMax( false ),
285 0 : nAlign( 0 )
286 : {
287 : OSL_ENSURE( pDrawContact, "SwFlyCntPortion::SwFlyCntPortion: no SwDrawContact!" );
288 0 : if( !pDrawContact->GetAnchorFrm() )
289 : {
290 : // OD 2004-04-01 #i26791# - no direct positioning needed any more
291 0 : pDrawContact->ConnectToLayout();
292 : // #i40333# - follow-up of #i35635#
293 : // move object to visible layer
294 0 : pDrawContact->MoveObjToVisibleLayer( pDrawContact->GetMaster() );
295 : }
296 0 : nLineLength = 1;
297 0 : nFlags |= AS_CHAR_ULSPACE | AS_CHAR_INIT;
298 :
299 0 : SetBase( rFrm, rBase, nLnAscent, nLnDescent, nFlyAsc, nFlyDesc, nFlags );
300 :
301 0 : SetWhichPor( POR_FLYCNT );
302 0 : }
303 :
304 : // after setting the RefPoints, the ascent needs to be recalculated because it is dependent on RelPos.
305 : // OD 29.07.2003 #110978# - use new datatype for parameter <nFlags>
306 : /// @param rBase CAUTION:needs to be an absolute value
307 0 : void SwFlyCntPortion::SetBase( const SwTxtFrm& rFrm, const Point &rBase,
308 : long nLnAscent, long nLnDescent,
309 : long nFlyAsc, long nFlyDesc,
310 : objectpositioning::AsCharFlags nFlags )
311 : {
312 : // OD 28.10.2003 #113049# - use new class to position object
313 : // determine drawing object
314 0 : SdrObject* pSdrObj = 0L;
315 0 : if( bDraw )
316 : {
317 : // OD 20.06.2003 #108784# - determine drawing object ('master' or 'virtual')
318 : // by frame.
319 0 : pSdrObj = GetDrawContact()->GetDrawObjectByAnchorFrm( rFrm );
320 0 : if ( !pSdrObj )
321 : {
322 : OSL_FAIL( "SwFlyCntPortion::SetBase(..) - No drawing object found by <GetDrawContact()->GetDrawObjectByAnchorFrm( rFrm )>" );
323 0 : pSdrObj = GetDrawContact()->GetMaster();
324 : }
325 : // #i65798#
326 : // call <SwAnchoredDrawObject::MakeObjPos()> to assure that flag at
327 : // the <DrawFrmFmt> and at the <SwAnchoredDrawObject> instance are
328 : // correctly set.
329 0 : if ( pSdrObj )
330 : {
331 0 : GetDrawContact()->GetAnchoredObj( pSdrObj )->MakeObjPos();
332 : }
333 : }
334 : else
335 : {
336 0 : pSdrObj = GetFlyFrm()->GetVirtDrawObj();
337 : }
338 :
339 0 : if (!pSdrObj)
340 0 : return;
341 :
342 : // position object
343 : objectpositioning::SwAsCharAnchoredObjectPosition aObjPositioning(
344 : *pSdrObj,
345 : rBase, nFlags,
346 0 : nLnAscent, nLnDescent, nFlyAsc, nFlyDesc );
347 :
348 : // OD 2004-04-13 #i26791# - scope of local variable <aObjPosInProgress>
349 : {
350 : // OD 2004-04-13 #i26791#
351 0 : SwObjPositioningInProgress aObjPosInProgress( *pSdrObj );
352 0 : aObjPositioning.CalcPosition();
353 : }
354 :
355 0 : SetAlign( aObjPositioning.GetLineAlignment() );
356 :
357 0 : aRef = aObjPositioning.GetAnchorPos();
358 0 : if( nFlags & AS_CHAR_ROTATE )
359 0 : SvXSize( aObjPositioning.GetObjBoundRectInclSpacing().SSize() );
360 : else
361 0 : SvLSize( aObjPositioning.GetObjBoundRectInclSpacing().SSize() );
362 0 : if( Height() )
363 : {
364 : // GetRelPosY returns the relative position to baseline (if 0, the
365 : // upper border of the FlyCnt if on the baseline of a line)
366 0 : SwTwips nRelPos = aObjPositioning.GetRelPosY();
367 0 : if ( nRelPos < 0 )
368 : {
369 0 : nAscent = static_cast<sal_uInt16>(-nRelPos);
370 0 : if( nAscent > Height() )
371 0 : Height( nAscent );
372 : }
373 : else
374 : {
375 0 : nAscent = 0;
376 0 : Height( Height() + static_cast<sal_uInt16>(nRelPos) );
377 : }
378 : }
379 : else
380 : {
381 0 : Height( 1 );
382 0 : nAscent = 0;
383 0 : }
384 : }
385 :
386 0 : sal_Int32 SwFlyCntPortion::GetFlyCrsrOfst( const KSHORT nOfst,
387 : const Point &rPoint, SwPosition *pPos, SwCrsrMoveState* pCMS ) const
388 : {
389 : // Da die FlyCnt nicht an der Seite haengen, wird ihr
390 : // GetCrsrOfst() nicht gerufen. Um die Layoutseite
391 : // von unnoetiger Verwaltung zu entlasten, ruft der Absatz
392 : // das GetCrsrOfst des FlyFrm, wenn es erforderlich ist.
393 0 : Point aPoint( rPoint );
394 0 : if( !pPos || bDraw || !( GetFlyFrm()->GetCrsrOfst( pPos, aPoint, pCMS ) ) )
395 0 : return SwLinePortion::GetCrsrOfst( nOfst );
396 : else
397 0 : return 0;
398 : }
399 :
400 0 : sal_Int32 SwFlyCntPortion::GetCrsrOfst( const KSHORT nOfst ) const
401 : {
402 : // OSL_ENSURE( !this, "SwFlyCntPortion::GetCrsrOfst: use GetFlyCrsrOfst()" );
403 0 : return SwLinePortion::GetCrsrOfst( nOfst );
404 : }
405 :
406 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|