Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
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.
15 : : *
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).
21 : : *
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.
26 : : *
27 : : ************************************************************************/
28 : : #ifndef _ANCHOREDOBJECT_HXX
29 : : #define _ANCHOREDOBJECT_HXX
30 : :
31 : : #include <tools/rtti.hxx>
32 : : #include <swtypes.hxx>
33 : : #include <swrect.hxx>
34 : : #include <libxml/xmlwriter.h>
35 : :
36 : : class SdrObject;
37 : : class SwFrm;
38 : : class SwLayoutFrm;
39 : : class SwTxtFrm;
40 : :
41 : : class SwPageFrm;
42 : : class SwObjPositioningInProgress;
43 : :
44 : : class SwFrmFmt;
45 : : class SwFmtAnchor;
46 : :
47 : : /** wrapper class for the positioning of Writer fly frames and drawing objects
48 : :
49 : : Purpose of this class is to provide a unified interface for the positioning
50 : : of Writer fly frames (derived classes of <SwFlyFrm>) and of drawing objects
51 : : (derived classes of <SwDrawFrm>).
52 : :
53 : : @author OD
54 : : */
55 : : class SW_DLLPUBLIC SwAnchoredObject
56 : : {
57 : : private:
58 : : // drawing object representing the anchored object in the drawing layer
59 : : SdrObject* mpDrawObj;
60 : : // frame the object is anchored at
61 : : SwFrm* mpAnchorFrm;
62 : : // #i28701 - page frame the object is registered at
63 : : // note: no page frame for as-character anchored objects
64 : : SwPageFrm* mpPageFrm;
65 : : // current relative position (relative to anchor position of anchor frame)
66 : : Point maRelPos;
67 : :
68 : : // for to-character anchored objects:
69 : : // Last known anchor character retangle.
70 : : // Used to decide, if invalidation has to been performed, if anchor position
71 : : // has changed, and used to position object.
72 : : SwRect maLastCharRect;
73 : :
74 : : // for to-character anchored objects:
75 : : // Last known top of line, in which the anchor character is in.
76 : : // Used to decide, if invalidation has to been performed, if anchor position
77 : : // has changed, and used to position object.
78 : : SwTwips mnLastTopOfLine;
79 : :
80 : : // for to-paragraph and to-character anchored objects:
81 : : // Layout frame vertical position is orient at - typically its the upper
82 : : // of the anchor frame, but it could also by the upper of a follow or
83 : : // a following layout frame in the text flow.
84 : : const SwLayoutFrm* mpVertPosOrientFrm;
85 : :
86 : : // i#i28701 boolean, indicating that the object
87 : : // positioning algorithm is in progress.
88 : : bool mbPositioningInProgress;
89 : :
90 : : // Booleans needed for the layout process.
91 : : // Values only of relevance for to-paragraph and to-character anchored
92 : : // floating screen object, for whose the 'straight-forward positioning
93 : : // process are applied
94 : : // Otherwise value of <mbConsiderForTextWrap> is treated as <true>,
95 : : // value of <mbPositionLocked> is treated as <false> and
96 : : // value of <mbRestartLayoutProcess> is treated as <false>.
97 : : // i#35911 - add boolean <mbClearEnvironment>
98 : : // Indicates that due to its position and wrapping style its layout
99 : : // environment is cleared - all content is moved forward.
100 : : // Treated as <false>, if not the 'straight-forward positioning process"
101 : : // is applied.
102 : : bool mbConsiderForTextWrap;
103 : : bool mbPositionLocked;
104 : : // boolean needed to keep position of
105 : : // anchored object locked due to special object positioning for sections.
106 : : bool mbKeepPositionLockedForSection;
107 : :
108 : : bool mbRestartLayoutProcess;
109 : : bool mbClearedEnvironment;
110 : :
111 : : // i#i3317 - boolean, indicating that temporarly
112 : : // the wrapping style influence of the anchored object has to be
113 : : // considered during its positioning.
114 : : // This boolean is used, if compatibility option 'Consider wrapping style
115 : : // influence on object positioning' is OFF and a positioning loop is
116 : : // detected in method <SwFlyAtCntFrm::MakeAll()> or method
117 : : // <SwAnchoredDrawObject::_MakeObjPosAnchoredAtPara()>.
118 : : // The boolean is reset to <false>, when the layout process for a
119 : : // page frame starts - see class <NotifyLayoutOfPageInProgress>.
120 : : bool mbTmpConsiderWrapInfluence;
121 : :
122 : : mutable SwRect maObjRectWithSpaces;
123 : : mutable bool mbObjRectWithSpacesValid;
124 : : mutable SwRect maLastObjRect;
125 : :
126 : : /** method to indicate, that positioning of anchored object is in progress
127 : :
128 : : note: method is implemented empty
129 : :
130 : : @author OD
131 : : */
132 : : friend class SwObjPositioningInProgress;
133 : 9544 : inline void SetPositioningInProgress( const bool _bPosInProgress )
134 : : {
135 : 9544 : mbPositioningInProgress = _bPosInProgress;
136 : 9544 : }
137 : :
138 : :
139 : : /** check anchor character rectangle
140 : :
141 : : helper method for method <CheckCharRectAndTopOfLine()>
142 : : For to-character anchored Writer fly frames the member <maLastCharRect>
143 : : is updated. This is checked for change and depending on the applied
144 : : positioning, it's decided, if the Writer fly frame has to be invalidated.
145 : : improvement - add second parameter <_rAnchorCharFrm>
146 : :
147 : : @author OD
148 : :
149 : : @param _rAnch
150 : : input parameter - reference to anchor position
151 : :
152 : : @param _rAnchorCharFrm
153 : : input parameter - reference to the text frame containing the anchor
154 : : character.
155 : : */
156 : : void _CheckCharRect( const SwFmtAnchor& _rAnch,
157 : : const SwTxtFrm& _rAnchorCharFrm );
158 : :
159 : : /** check top of line
160 : :
161 : : helper method for method <CheckCharRectAndTopOfLine()>
162 : : For to-character anchored Writer fly frames the member <mnLastTopOfLine>
163 : : is updated. This is checked for change and depending on the applied
164 : : positioning, it's decided, if the Writer fly frame has to be invalidated.
165 : :
166 : : @author OD
167 : :
168 : : @param _rAnch
169 : : input parameter - reference to anchor position
170 : :
171 : : @param _rAnchorCharFrm
172 : : input parameter - reference to the text frame containing the anchor
173 : : character.
174 : : */
175 : : void _CheckTopOfLine( const SwFmtAnchor& _rAnch,
176 : : const SwTxtFrm& _rAnchorCharFrm );
177 : :
178 : : // method <lcl_HideObj(..)> sets needed data structure values for the
179 : : // object positioning
180 : : friend bool lcl_HideObj( const SwTxtFrm& _rFrm,
181 : : const RndStdIds _eAnchorType,
182 : : const xub_StrLen _nObjAnchorPos,
183 : : SwAnchoredObject* _pAnchoredObj );
184 : : protected:
185 : : SwAnchoredObject();
186 : :
187 : : void SetVertPosOrientFrm( const SwLayoutFrm& _rVertPosOrientFrm );
188 : :
189 : : /** method to assure that anchored object is registered at the correct
190 : : page frame
191 : :
192 : : @author OD
193 : : */
194 : : virtual void RegisterAtCorrectPage() = 0;
195 : :
196 : : /** method to indicate, that anchored object is attached to a anchor frame
197 : :
198 : : @author OD
199 : : */
200 : : virtual void ObjectAttachedToAnchorFrame();
201 : :
202 : : /** method to determine, if other anchored objects, also attached at
203 : : to the anchor frame, have to consider its wrap influence.
204 : :
205 : : @author OD
206 : : */
207 : : bool ConsiderObjWrapInfluenceOfOtherObjs() const;
208 : :
209 : : /** method to apply temporary consideration of wrapping style influence
210 : : to the anchored objects, which are anchored at the same anchor frame
211 : :
212 : : @author OD
213 : : */
214 : : void SetTmpConsiderWrapInfluenceOfOtherObjs( const bool bTmpConsiderWrapInfluence );
215 : :
216 : : virtual bool _SetObjTop( const SwTwips _nTop) = 0;
217 : : virtual bool _SetObjLeft( const SwTwips _nLeft) = 0;
218 : :
219 : : virtual const SwRect GetObjBoundRect() const = 0;
220 : : public:
221 : : TYPEINFO();
222 : :
223 : : virtual ~SwAnchoredObject();
224 : :
225 : : // accessors to member <mpDrawObj>
226 : : void SetDrawObj( SdrObject& _rDrawObj );
227 : : const SdrObject* GetDrawObj() const;
228 : : SdrObject* DrawObj();
229 : :
230 : : // accessors to member <mpAnchorFrm>
231 : : const SwFrm* GetAnchorFrm() const;
232 : : SwFrm* AnchorFrm();
233 : : void ChgAnchorFrm( SwFrm* _pNewAnchorFrm );
234 : : /** determine anchor frame containing the anchor position
235 : :
236 : : the anchor frame, which is determined, is <mpAnchorFrm>
237 : : for an at-page, at-frame or at-paragraph anchored object
238 : : and the anchor character frame for an at-character and as-character
239 : : anchored object.
240 : :
241 : : @author OD
242 : : */
243 : : SwFrm* GetAnchorFrmContainingAnchPos();
244 : :
245 : : SwPageFrm* GetPageFrm();
246 : : const SwPageFrm* GetPageFrm() const;
247 : : void SetPageFrm( SwPageFrm* _pNewPageFrm );
248 : :
249 : : /** method to determine the page frame, on which the 'anchor' of
250 : : the given anchored object is.
251 : :
252 : : Adjust meaning of method and thus its name: If the anchored object
253 : : or its anchor isn't correctly inserted in the layout, no page frame
254 : : can be found. Thus, the return type changed to be a pointer and can
255 : : be NULL.
256 : :
257 : : @author OD
258 : :
259 : : @param _rAnchoredObj
260 : : input parameter - anchored object, for which the page frame of its
261 : : 'anchor' has to be determined.
262 : :
263 : : @return SwPageFrm&
264 : : page frame, the 'anchor' of the given anchored object is on
265 : : */
266 : : SwPageFrm* FindPageFrmOfAnchor();
267 : :
268 : : /** get frame, which contains the anchor character, if the object
269 : : is anchored at-character or as-character.
270 : :
271 : : @author OD
272 : :
273 : : @return SwTxtFrm*
274 : : text frame containing the anchor character. It's NULL, if the object
275 : : isn't anchored at-character resp. as-character.
276 : : */
277 : : SwTxtFrm* FindAnchorCharFrm();
278 : :
279 : : // accessors to data of position calculation:
280 : : // frame vertical position is orient at
281 : 3183 : inline const SwLayoutFrm* GetVertPosOrientFrm() const
282 : : {
283 : 3183 : return mpVertPosOrientFrm;
284 : : }
285 : : // method to clear member <mpVertPosOrientFrm>
286 : 180 : inline void ClearVertPosOrientFrm()
287 : : {
288 : 180 : mpVertPosOrientFrm = 0L;
289 : 180 : }
290 : :
291 : : /** check anchor character rectangle and top of line
292 : :
293 : : For to-character anchored Writer fly frames the members <maLastCharRect>
294 : : and <maLastTopOfLine> are updated. These are checked for change and
295 : : depending on the applied positioning, it's decided, if the Writer fly
296 : : frame has to be invalidated.
297 : :
298 : : @author OD
299 : :
300 : : @param _bCheckForParaPorInf
301 : : input parameter - boolean indicating, if check on paragraph portion
302 : : information has to be done.
303 : : */
304 : : void CheckCharRectAndTopOfLine( const bool _bCheckForParaPorInf = true );
305 : :
306 : : // accessors to member <maLastCharRect>
307 : : const SwRect& GetLastCharRect() const;
308 : : SwTwips GetRelCharX( const SwFrm* pFrm ) const;
309 : : SwTwips GetRelCharY( const SwFrm* pFrm ) const;
310 : : void AddLastCharY( long nDiff );
311 : : void ResetLastCharRectHeight();
312 : :
313 : : // accessor to member <nmLastTopOfLine>
314 : : SwTwips GetLastTopOfLine() const;
315 : : void AddLastTopOfLineY( SwTwips _nDiff );
316 : :
317 : : /** reset members <maLastCharRect> and <mnLastTopOfLine>
318 : :
319 : : @author OD
320 : : */
321 : : void ClearCharRectAndTopOfLine();
322 : :
323 : : /** method to determine position for the object and set the position
324 : : at the object
325 : :
326 : : @author OD
327 : : */
328 : : virtual void MakeObjPos() = 0;
329 : :
330 : : /** is positioning of anchored object in progress
331 : :
332 : : @author OD
333 : : */
334 : 10200 : inline bool IsPositioningInProgress() const
335 : : {
336 : 10200 : return mbPositioningInProgress;
337 : : }
338 : :
339 : : /** method to determine, if invalidation of position is allowed
340 : :
341 : : @author OD
342 : : */
343 : : bool InvalidationOfPosAllowed() const;
344 : :
345 : : /** method to invalidate position of the anchored object
346 : :
347 : : @author OD
348 : : */
349 : : virtual void InvalidateObjPos() = 0;
350 : :
351 : : /** method to perform necessary invalidations for the positioning of
352 : : objects, for whose the wrapping style influence has to be considered
353 : : on the object positioning.
354 : :
355 : : @author OD
356 : : */
357 : : void InvalidateObjPosForConsiderWrapInfluence( const bool _bNotifyBackgrd );
358 : :
359 : : /** method to trigger notification of 'background'
360 : :
361 : : @author OD
362 : : */
363 : : virtual void NotifyBackground( SwPageFrm* _pPageFrm,
364 : : const SwRect& _rRect,
365 : : PrepareHint _eHint ) = 0;
366 : :
367 : : // accessors to the current relative position (relative to anchor
368 : : // position of anchor frame)
369 : : const Point GetCurrRelPos() const;
370 : : void SetCurrRelPos( Point _aRelPos );
371 : :
372 : : // accessors to the format
373 : : virtual SwFrmFmt& GetFrmFmt() = 0;
374 : : virtual const SwFrmFmt& GetFrmFmt() const = 0;
375 : :
376 : : // accessors to the object area and its position
377 : : virtual const SwRect GetObjRect() const = 0;
378 : :
379 : : void SetObjTop( const SwTwips _nTop);
380 : : void SetObjLeft( const SwTwips _nLeft);
381 : :
382 : : /** method update layout direction the layout direction, the anchored
383 : : object is assigned to
384 : :
385 : : method has typically to be called, if the anchored object gets its
386 : : anchor frame assigned and if the anchor frame changes its layout direction
387 : :
388 : : @author OD
389 : : */
390 : : virtual void UpdateLayoutDir();
391 : :
392 : : /** method to determine object area inclusive its spacing
393 : :
394 : : @author OD
395 : : */
396 : : const SwRect& GetObjRectWithSpaces() const;
397 : :
398 : 2585 : inline void InvalidateObjRectWithSpaces() const
399 : : {
400 : 2585 : mbObjRectWithSpacesValid = false;
401 : 2585 : }
402 : :
403 : : /** method to determine, if wrapping style influence of the anchored
404 : : object has to be considered on the object positioning
405 : :
406 : : Note: result of this method also decides, if the boolean for the
407 : : layout process are of relevance.
408 : :
409 : : @author OD
410 : : */
411 : : bool ConsiderObjWrapInfluenceOnObjPos() const;
412 : :
413 : : // accessors to booleans for layout process
414 : : bool ConsiderForTextWrap() const;
415 : : void SetConsiderForTextWrap( const bool _bConsiderForTextWrap );
416 : : bool PositionLocked() const;
417 : 24 : inline void LockPosition()
418 : : {
419 : 24 : mbPositionLocked = true;
420 : 24 : }
421 : 1029 : inline void UnlockPosition()
422 : : {
423 [ + - ]: 1029 : if ( !mbKeepPositionLockedForSection )
424 : : {
425 : 1029 : mbPositionLocked = false;
426 : : }
427 : 1029 : }
428 : :
429 : 0 : inline void SetKeepPosLocked( const bool _bKeepPosLocked )
430 : : {
431 : 0 : mbKeepPositionLockedForSection = _bKeepPosLocked;
432 : 0 : }
433 : :
434 : : bool RestartLayoutProcess() const;
435 : : void SetRestartLayoutProcess( const bool _bRestartLayoutProcess );
436 : : // accessors for <mbClearedEnvironment>
437 : : bool ClearedEnvironment() const;
438 : : void SetClearedEnvironment( const bool _bClearedEnvironment );
439 : :
440 : : // reset booleans for layout process
441 : 696 : inline void ResetLayoutProcessBools()
442 : : {
443 : 696 : mbPositioningInProgress = false;
444 : 696 : mbConsiderForTextWrap = false;
445 : 696 : mbPositionLocked = false;
446 : 696 : mbKeepPositionLockedForSection = false;
447 : 696 : mbRestartLayoutProcess = false;
448 : 696 : mbClearedEnvironment = false;
449 : 696 : mbTmpConsiderWrapInfluence = false;
450 : 696 : }
451 : :
452 : : /** method to determine, if due to anchored object size and wrapping
453 : : style, its layout environment is cleared.
454 : :
455 : : @author OD
456 : : */
457 : : bool HasClearedEnvironment() const;
458 : :
459 : : /** method to update anchored object in the <SwSortedObjs> lists
460 : :
461 : : Method is not proposed to be called during a layout process is
462 : : running. It has been used on the change of the anchored object
463 : : attributes, which belongs the sort criteria of <SwSortedObjs>.
464 : : If document compatibility option 'Consider wrapping style influence
465 : : on object positioning' is ON, additionally all anchored objects
466 : : at the anchor frame and all following anchored objects on the page
467 : : frame are invalidated.
468 : :
469 : : @author OD
470 : : */
471 : : void UpdateObjInSortedList();
472 : :
473 : : /** method to determine, if a format on the anchored object is possible
474 : :
475 : : A format isn't possible, if anchored object is in an invisible layer.
476 : : Note: method is virtual to refine the conditions for the sub-classes.
477 : :
478 : : @author OD
479 : : */
480 : : virtual bool IsFormatPossible() const;
481 : :
482 : : // accessors to member <mbTmpConsiderWrapInfluence>
483 : : void SetTmpConsiderWrapInfluence( const bool _bTmpConsiderWrapInfluence );
484 : : bool IsTmpConsiderWrapInfluence() const;
485 : :
486 : : /** method to determine, if the anchored object is overlapping with a
487 : : previous column
488 : :
489 : : overlapping with a previous column means, that the object overlaps
490 : : with a column, which is a previous one of the column its anchor
491 : : frame is in.
492 : : Only applied for at-paragraph and at-character anchored objects.
493 : :
494 : : @author OD
495 : : */
496 : : bool OverlapsPrevColumn() const;
497 : :
498 : : /** method to determine position of anchored object relative to
499 : : anchor frame
500 : :
501 : : Usage: Needed layout information for WW8 export
502 : :
503 : : @author OD
504 : :
505 : : @return Point - determined relative position
506 : : */
507 : : Point GetRelPosToAnchorFrm() const;
508 : :
509 : : /** method to determine position of anchored object relative to
510 : : page frame
511 : :
512 : : Usage: Needed layout information for WW8 export
513 : :
514 : : If <_bFollowTextFlow> is set and object is anchored inside table,
515 : : the position relative to the table cell is determined. Output
516 : : parameter <_obRelToTableCell> reflects this situation
517 : :
518 : : @author OD
519 : :
520 : : @param _bFollowTextFlow
521 : : input parameter - boolean indicating, if the anchored object has to
522 : : follow the text flow.
523 : :
524 : : @param _obRelToTableCell
525 : : output parameter - boolean indicating, the determine position is
526 : : relative to the table cell
527 : :
528 : : @return Point - determined relative position
529 : : */
530 : : Point GetRelPosToPageFrm( const bool _bFollowTextFlow,
531 : : bool& _obRelToTableCell ) const;
532 : :
533 : : /** method to determine position of anchored object relative to
534 : : anchor character
535 : :
536 : : Usage: Needed layout information for WW8 export
537 : :
538 : : @author OD
539 : :
540 : : @return Point - determined relative position
541 : : */
542 : : Point GetRelPosToChar() const;
543 : :
544 : : /** method to determine position of anchored object relative to
545 : : top of line
546 : :
547 : : Usage: Needed layout information for WW8 export
548 : :
549 : : @author OD
550 : :
551 : : @return Point - determined relative position
552 : : */
553 : : Point GetRelPosToLine() const;
554 : :
555 : : /** Dump a bunch of useful data to an XML representation to ease
556 : : layout understanding, debugging and testing.
557 : : */
558 : : virtual void dumpAsXml( xmlTextWriterPtr pWriter );
559 : :
560 : : /** The element name to show in the XML dump.
561 : : */
562 : 0 : virtual const char* getElementName( ) { return "SwAnchoredObject"; }
563 : : };
564 : :
565 : : // ============================================================================
566 : : // helper class for notify that positioning of an anchored object is in progress
567 : : // ============================================================================
568 : : class SwObjPositioningInProgress
569 : : {
570 : : private:
571 : : SwAnchoredObject* mpAnchoredObj;
572 : : // boolean indicating old state
573 : : // of anchored object regarding positioning in progress in order to
574 : : // consider nested usage of class <SwObjPositioningInProgress>
575 : : bool mbOldObjPositioningInProgress;
576 : :
577 : : public:
578 : : SwObjPositioningInProgress( SdrObject& _rSdrObj );
579 : : SwObjPositioningInProgress( SwAnchoredObject& _rAnchoredObj );
580 : : ~SwObjPositioningInProgress();
581 : : };
582 : :
583 : : #endif
584 : :
585 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|