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 : #ifndef INCLUDED_SW_SOURCE_CORE_INC_ROOTFRM_HXX
20 : #define INCLUDED_SW_SOURCE_CORE_INC_ROOTFRM_HXX
21 :
22 : #include "layfrm.hxx"
23 : #include <viewsh.hxx>
24 : #include <doc.hxx>
25 : #include <IDocumentTimerAccess.hxx>
26 :
27 : class SwContentFrm;
28 : class SwViewShell;
29 : class SdrPage;
30 : class SwFrameFormat;
31 : class SwPaM;
32 : class SwCursor;
33 : class SwShellCrsr;
34 : class SwTableCursor;
35 : class SwLayVout;
36 : class SwDestroyList;
37 : class SwCurrShells;
38 : class SwViewOption;
39 : class SwSelectionList;
40 : struct SwPosition;
41 : struct SwCrsrMoveState;
42 :
43 : #define INV_SIZE 1
44 : #define INV_PRTAREA 2
45 : #define INV_POS 4
46 : #define INV_TABLE 8
47 : #define INV_SECTION 16
48 : #define INV_LINENUM 32
49 : #define INV_DIRECTION 64
50 :
51 : #include <vector>
52 :
53 : /// The root element of a Writer document layout.
54 : class SwRootFrm: public SwLayoutFrm
55 : {
56 : // Needs to disable the Superfluous temporarily
57 : friend void AdjustSizeChgNotify( SwRootFrm *pRoot );
58 :
59 : // Maintains the mpLastPage (Cut() and Paste() of SwPageFrm
60 : friend inline void SetLastPage( SwPageFrm* );
61 :
62 : // For creating and destroying of the virtual output device manager
63 : friend void _FrmInit(); // Creates mpVout
64 : friend void _FrmFinit(); // Destroys mpVout
65 :
66 : std::vector<SwRect> maPageRects;// returns the current rectangle for each page frame
67 : // the rectangle is extended to the top/bottom/left/right
68 : // for pages located at the outer margins
69 : SwRect maPagesArea; // the area covered by the pages
70 : long mnViewWidth; // the current page layout bases on this view width
71 : sal_uInt16 mnColumns; // the current page layout bases on this number of columns
72 : bool mbBookMode; // the current page layout is in book view
73 : bool mbSidebarChanged; // the notes sidebar state has changed
74 :
75 : bool mbNeedGrammarCheck; // true when sth needs to be checked (not necessarily started yet!)
76 :
77 : static SwLayVout *mpVout;
78 : static bool mbInPaint; // Protection against double Paints
79 : static bool mbNoVirDev;// No virt. Device for SystemPaints
80 :
81 : bool mbCheckSuperfluous :1; // Search for empty Pages?
82 : bool mbIdleFormat :1; // Trigger Idle Formatter?
83 : bool mbBrowseWidthValid :1; // Is mnBrowseWidth valid?
84 : bool mbTurboAllowed :1;
85 : bool mbAssertFlyPages :1; // Insert more Pages for Flys if needed?
86 : bool mbIsVirtPageNum :1; // Do we have a virtual pagenumber?
87 : bool mbIsNewLayout :1; // Layout loaded or newly created
88 : bool mbCallbackActionEnabled:1; // No Action in Notification desired
89 : // @see dcontact.cxx, ::Changed()
90 : bool mbLayoutFreezed;
91 :
92 : /**
93 : * For BrowseMode
94 : * mnBrowseWidth is the outer margin of the object most to the right.
95 : * The page's right edge should not be smaller than this value.
96 : */
97 : long mnBrowseWidth;
98 :
99 : /// If we only have to format one ContentFrm, its in mpTurbo
100 : const SwContentFrm *mpTurbo;
101 :
102 : /// We should not need to always struggle to find the last page, so store it here
103 : SwPageFrm *mpLastPage;
104 :
105 : /** [ Comment from the original StarOffice checkin ]:
106 : * The root takes care of the shell access. Via the document
107 : * it should be possible to get at the root frame, and thus always
108 : * have access to the shell.
109 : * the pointer mpCurrShell is the pointer to any of the shells for
110 : * the document.
111 : * Because sometimes it matters which shell is used, it is necessary to
112 : * know the active shell.
113 : * this is approximated by setting the pointer mpCurrShell when a
114 : * shell gets the focus (FEShell). Acditionally the pointer will be
115 : * set temporarily by SwCurrShell typically via SET_CURR_SHELL
116 : * The macro and class can be found in the SwViewShell. These object can
117 : * be created nested (also for different kinds of Shells). They are
118 : * collected into the Array mpCurrShells.
119 : * Furthermore it can happen that a shell is activated while a curshell
120 : * object is still 'active'. This one will be entered into mpWaitingCurrShell
121 : * and will be activated by the last d'tor of CurrShell.
122 : * One other problem is the destruction of a shell while it is active.
123 : * The pointer mpCurrShell is then reset to an arbitrary other shell.
124 : * If at the time of the destruction of a shell, which is still referneced
125 : * by a curshell object, that will be cleaned up as well.
126 : */
127 : friend class CurrShell;
128 : friend void SetShell( SwViewShell *pSh );
129 : friend void InitCurrShells( SwRootFrm *pRoot );
130 : SwViewShell *mpCurrShell;
131 : SwViewShell *mpWaitingCurrShell;
132 : SwCurrShells *mpCurrShells;
133 :
134 : /// One Page per DrawModel per Document; is always the size of the Root
135 : SdrPage *mpDrawPage;
136 :
137 : SwDestroyList* mpDestroy;
138 :
139 : sal_uInt16 mnPhyPageNums; /// Page count
140 : sal_uInt16 mnAccessibleShells; // Number of accessible shells
141 :
142 : void ImplCalcBrowseWidth();
143 : void ImplInvalidateBrowseWidth();
144 :
145 : void _DeleteEmptySct(); // Destroys the registered SectionFrms
146 : void _RemoveFromList( SwSectionFrm* pSct ); // Removes SectionFrms from the Delete List
147 :
148 : virtual void DestroyImpl() SAL_OVERRIDE;
149 : virtual ~SwRootFrm();
150 :
151 : protected:
152 :
153 : virtual void MakeAll() SAL_OVERRIDE;
154 :
155 : public:
156 :
157 : /// Remove MasterObjects from the Page (called by the ctors)
158 : static void RemoveMasterObjs( SdrPage *pPg );
159 :
160 : void AllCheckPageDescs() const;
161 : void AllInvalidateAutoCompleteWords() const;
162 : void AllAddPaintRect() const;
163 : void AllRemoveFootnotes() ;
164 : void AllInvalidateSmartTagsOrSpelling(bool bSmartTags) const;
165 :
166 : /// Output virtual Device (e.g. for animations)
167 : static bool FlushVout();
168 :
169 : /// Save Clipping if exactly the ClipRect is outputted
170 : static bool HasSameRect( const SwRect& rRect );
171 :
172 : SwRootFrm( SwFrameFormat*, SwViewShell* );
173 : void Init(SwFrameFormat*);
174 :
175 56542145 : SwViewShell *GetCurrShell() const { return mpCurrShell; }
176 : void DeRegisterShell( SwViewShell *pSh );
177 :
178 : /**
179 : * Set up Start-/EndAction for all Shells on a as high as possible
180 : * (Shell section) level.
181 : * For the StarONE binding, which does not know the Shells directly.
182 : * The ChangeLinkd of the CrsrShell (UI notifications) is called
183 : * automatically in the EndAllAction.
184 : */
185 : void StartAllAction();
186 : void EndAllAction( bool bVirDev = false );
187 :
188 : /**
189 : * Certain UNO Actions (e.g. table cursor) require that all Actions are reset temporarily
190 : * In order for that to work, every SwViewShell needs to remember its old Action counter
191 : */
192 : void UnoRemoveAllActions();
193 : void UnoRestoreAllActions();
194 :
195 : const SdrPage* GetDrawPage() const { return mpDrawPage; }
196 12618 : SdrPage* GetDrawPage() { return mpDrawPage; }
197 0 : void SetDrawPage( SdrPage* pNew ){ mpDrawPage = pNew; }
198 :
199 : virtual bool GetCrsrOfst( SwPosition *, Point&,
200 : SwCrsrMoveState* = 0, bool bTestBackground = false ) const SAL_OVERRIDE;
201 :
202 : virtual void Paint( SwRect const&,
203 : SwPrintData const*const pPrintData = NULL ) const SAL_OVERRIDE;
204 : virtual SwTwips ShrinkFrm( SwTwips, bool bTst = false, bool bInfo = false ) SAL_OVERRIDE;
205 : virtual SwTwips GrowFrm ( SwTwips, bool bTst = false, bool bInfo = false ) SAL_OVERRIDE;
206 : #ifdef DBG_UTIL
207 : virtual void Cut() SAL_OVERRIDE;
208 : virtual void Paste( SwFrm* pParent, SwFrm* pSibling = 0 ) SAL_OVERRIDE;
209 : #endif
210 :
211 : virtual bool FillSelection( SwSelectionList& rList, const SwRect& rRect ) const SAL_OVERRIDE;
212 :
213 : Point GetNextPrevContentPos( const Point &rPoint, bool bNext ) const;
214 :
215 : virtual Size ChgSize( const Size& aNewSize ) SAL_OVERRIDE;
216 :
217 260942 : void SetIdleFlags()
218 : {
219 260942 : mbIdleFormat = true;
220 :
221 260942 : SwViewShell* pCurrShell = GetCurrShell();
222 : // May be NULL if called from SfxBaseModel::dispose
223 : // (this happens in the build test 'rtfexport').
224 260942 : if (pCurrShell != NULL)
225 260416 : pCurrShell->GetDoc()->getIDocumentTimerAccess().StartBackgroundJobs();
226 260942 : }
227 26780446 : bool IsIdleFormat() const { return mbIdleFormat; }
228 5385 : void ResetIdleFormat() { mbIdleFormat = false; }
229 :
230 26780446 : bool IsNeedGrammarCheck() const { return mbNeedGrammarCheck; }
231 171673 : void SetNeedGrammarCheck( bool bVal )
232 : {
233 171673 : mbNeedGrammarCheck = bVal;
234 :
235 171673 : if ( bVal )
236 : {
237 171673 : SwViewShell* pCurrShell = GetCurrShell();
238 : // May be NULL if called from SfxBaseModel::dispose
239 : // (this happens in the build test 'rtfexport').
240 171673 : if (pCurrShell != NULL)
241 171502 : pCurrShell->GetDoc()->getIDocumentTimerAccess().StartBackgroundJobs();
242 : }
243 171673 : }
244 :
245 : /// Makes sure that all requested page-bound Flys find a Page
246 524 : void SetAssertFlyPages() { mbAssertFlyPages = true; }
247 : void AssertFlyPages();
248 16552 : bool IsAssertFlyPages() { return mbAssertFlyPages; }
249 :
250 : /**
251 : * Makes sure that, starting from the passed Page, all page-bound Frames
252 : * are on the right Page (pagenumber).
253 : */
254 : static void AssertPageFlys( SwPageFrm * );
255 :
256 : /// Invalidate all Content, Size or PrtArea
257 : void InvalidateAllContent( sal_uInt8 nInvalidate = INV_SIZE );
258 :
259 : /**
260 : * Invalidate/re-calculate the position of all floating
261 : * screen objects (Writer fly frames and drawing objects), which are
262 : * anchored to paragraph or to character.
263 : */
264 : void InvalidateAllObjPos();
265 :
266 : /// Remove superfluous Pages
267 1511 : void SetSuperfluous() { mbCheckSuperfluous = true; }
268 19001 : bool IsSuperfluous() const { return mbCheckSuperfluous; }
269 : void RemoveSuperfluous();
270 :
271 : /**
272 : * Query/set the current Page and the collective Page count
273 : * We'll format as much as necessary
274 : */
275 : sal_uInt16 GetCurrPage( const SwPaM* ) const;
276 : sal_uInt16 SetCurrPage( SwCursor*, sal_uInt16 nPageNum );
277 : Point GetPagePos( sal_uInt16 nPageNum ) const;
278 40543 : sal_uInt16 GetPageNum() const { return mnPhyPageNums; }
279 267 : void DecrPhyPageNums() { --mnPhyPageNums; }
280 4721 : void IncrPhyPageNums() { ++mnPhyPageNums; }
281 7351 : bool IsVirtPageNum() const { return mbIsVirtPageNum; }
282 : inline void SetVirtPageNum( const bool bOf ) const;
283 : bool IsDummyPage( sal_uInt16 nPageNum ) const;
284 :
285 : /**
286 : * Point rPt: The point that should be used to find the page
287 : * Size pSize: If given, we return the (first) page that overlaps with the
288 : * rectangle defined by rPt and pSize
289 : * bool bExtend: Extend each page to the left/right/top/botton up to the
290 : * next page margin
291 : */
292 : const SwPageFrm* GetPageAtPos( const Point& rPt, const Size* pSize = 0, bool bExtend = false ) const;
293 :
294 : void CalcFrmRects( SwShellCrsr& );
295 :
296 : /**
297 : * Calculates the cells included from the current selection
298 : *
299 : * @returns false: There was no result because of an invalid layout
300 : * @returns true: Everything worked fine.
301 : */
302 : bool MakeTableCrsrs( SwTableCursor& );
303 :
304 26911895 : void DisallowTurbo() const { const_cast<SwRootFrm*>(this)->mbTurboAllowed = false; }
305 26817313 : void ResetTurboFlag() const { const_cast<SwRootFrm*>(this)->mbTurboAllowed = true; }
306 160630 : bool IsTurboAllowed() const { return mbTurboAllowed; }
307 5969 : void SetTurbo( const SwContentFrm *pContent ) { mpTurbo = pContent; }
308 26818883 : void ResetTurbo() { mpTurbo = 0; }
309 27147556 : const SwContentFrm *GetTurbo() { return mpTurbo; }
310 :
311 : /// Update the footernumbers of all Pages
312 : void UpdateFootnoteNums(); // Only for page by page numnbering!
313 :
314 : /// Remove all footnotes (but no references)
315 : void RemoveFootnotes( SwPageFrm *pPage = 0, bool bPageOnly = false,
316 : bool bEndNotes = false );
317 : void CheckFootnotePageDescs( bool bEndNote );
318 :
319 : const SwPageFrm *GetLastPage() const { return mpLastPage; }
320 171 : SwPageFrm *GetLastPage() { return mpLastPage; }
321 :
322 6253 : static bool IsInPaint() { return mbInPaint; }
323 :
324 9382 : static void SetNoVirDev( const bool bNew ) { mbNoVirDev = bNew; }
325 :
326 : inline long GetBrowseWidth() const;
327 : void SetBrowseWidth( long n ) { mbBrowseWidthValid = true; mnBrowseWidth = n;}
328 : inline void InvalidateBrowseWidth();
329 :
330 2685 : bool IsNewLayout() const { return mbIsNewLayout; }
331 3105 : void ResetNewLayout() { mbIsNewLayout = false;}
332 :
333 : /**
334 : * Empty SwSectionFrms are registered here for deletion and
335 : * destroyed later on or deregistered.
336 : */
337 : void InsertEmptySct( SwSectionFrm* pDel );
338 26831014 : void DeleteEmptySct() { if( mpDestroy ) _DeleteEmptySct(); }
339 677 : void RemoveFromList( SwSectionFrm* pSct ) { if( mpDestroy ) _RemoveFromList( pSct ); }
340 : #ifdef DBG_UTIL
341 : bool IsInDelList( SwSectionFrm* pSct ) const;
342 : #endif
343 :
344 64428 : void SetCallbackActionEnabled( bool b ) { mbCallbackActionEnabled = b; }
345 57493 : bool IsCallbackActionEnabled() const { return mbCallbackActionEnabled; }
346 :
347 293288 : bool IsAnyShellAccessible() const { return mnAccessibleShells > 0; }
348 12 : void AddAccessibleShell() { ++mnAccessibleShells; }
349 12 : void RemoveAccessibleShell() { --mnAccessibleShells; }
350 :
351 : /**
352 : * Get page frame by phyiscal page number
353 : * looping through the lowers, which are page frame, in order to find the
354 : * page frame with the given physical page number.
355 : * if no page frame is found, 0 is returned.
356 : * Note: Empty page frames are also returned.
357 : *
358 : * @param _nPageNum: physical page number of page frame to be searched and
359 : * returned.
360 : *
361 : * @return pointer to the page frame with the given physical page number
362 : */
363 : SwPageFrm* GetPageByPageNum( sal_uInt16 _nPageNum ) const;
364 :
365 : void CheckViewLayout( const SwViewOption* pViewOpt, const SwRect* pVisArea );
366 : bool IsLeftToRightViewLayout() const;
367 906 : const SwRect& GetPagesArea() const { return maPagesArea; }
368 167 : void SetSidebarChanged() { mbSidebarChanged = true; }
369 :
370 8 : bool IsLayoutFreezed() const { return mbLayoutFreezed; }
371 10 : void FreezeLayout( bool freeze ) { mbLayoutFreezed = freeze; }
372 : };
373 :
374 100 : inline long SwRootFrm::GetBrowseWidth() const
375 : {
376 100 : if ( !mbBrowseWidthValid )
377 84 : const_cast<SwRootFrm*>(this)->ImplCalcBrowseWidth();
378 100 : return mnBrowseWidth;
379 : }
380 :
381 5366 : inline void SwRootFrm::InvalidateBrowseWidth()
382 : {
383 5366 : if ( mbBrowseWidthValid )
384 78 : ImplInvalidateBrowseWidth();
385 5366 : }
386 :
387 154 : inline void SwRootFrm::SetVirtPageNum( const bool bOf) const
388 : {
389 154 : const_cast<SwRootFrm*>(this)->mbIsVirtPageNum = bOf;
390 154 : }
391 :
392 : #endif // INCLUDED_SW_SOURCE_CORE_INC_ROOTFRM_HXX
393 :
394 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|