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_LAYACT_HXX
20 #define INCLUDED_SW_SOURCE_CORE_INC_LAYACT_HXX
21 
22 #include <sal/config.h>
23 
24 #include <vcl/inputtypes.hxx>
25 #include <vcl/TaskStopwatch.hxx>
26 #include <tools/color.hxx>
27 
28 #include <ctime>
29 #include <memory>
30 
31 #include <swrect.hxx>
32 
33 class OutputDevice;
34 class SwRootFrame;
35 class SwLayoutFrame;
36 class SwPageFrame;
37 class SwFlyFrame;
38 class SwContentFrame;
39 class SwTabFrame;
40 class SwViewShellImp;
41 class SwContentNode;
42 class SwWait;
43 
44 /**
45  * The usage of LayAction is always the same:
46  *
47  * 1. Generation of the LayAction object.
48  * 2. Specifying the wanted behaviour via the Set-methods
49  * 3. Calling Action()
50  * 4. Soon after that the destruction of the object
51  *
52  * The object registers at the SwViewShellImp in the ctor and deregisters not until
53  * the dtor!
54  * It's a typical stack object.
55  */
56 class SwLayAction
57 {
58     SwRootFrame  *m_pRoot;
59     SwViewShellImp  *m_pImp; // here the action logs in and off
60     TaskStopwatch* m_pWatch;
61 
62     // For the sake of optimization, so that the tables stick a bit better to
63     // the Cursor when hitting return/backspace in front of one.
64     // The first TabFrame that paints itself (per page) adds itself to the pointer.
65     // The ContentFrames beneath the page do not need to deregister at the Shell for
66     // painting.
67     const SwTabFrame *m_pOptTab;
68 
69     std::unique_ptr<SwWait> m_pWait;
70 
71     // If a paragraph (or anything else) moved more than one page when
72     // formatting, it adds its new page number here.
73     // The InternalAction can then take the appropriate steps.
74     sal_uInt16 m_nPreInvaPage;
75 
76     std::clock_t m_nStartTicks;      // The Action's starting time; if too much time passes the
77                                 // WaitCursor can be enabled via CheckWaitCursor()
78 
79     sal_uInt16 m_nEndPage;        // StatBar control
80     sal_uInt16 m_nCheckPageNum;   // CheckPageDesc() was delayed if != USHRT_MAX
81                                 // check from this page onwards
82 
83     bool m_bPaint;         // painting or only formatting?
84     bool m_bComplete;      // Format everything or just the visible Area?
85     bool m_bCalcLayout;    // Complete reformatting?
86     bool m_bAgain;         // For the automatically repeated Action if Pages are deleted
87     bool m_bNextCycle;     // Reset on the first invalid Page
88     bool m_bReschedule;    // Call Reschedule depending on Progress?
89     bool m_bInterrupt;     // For termination the layouting
90     bool m_bCheckPages;    // Run CheckPageDescs() or delay it
91     bool m_bUpdateExpFields; // Is set if, after Formatting, we need to do another round for ExpField
92     bool m_bBrowseActionStop; // Terminate Action early (as per bInput) and leave the rest to the Idler
93     bool m_bWaitAllowed;      // Waitcursor allowed?
94     bool m_bPaintExtraData;   // Painting line numbers (or similar) enabled?
95     bool m_bActionInProgress; // Is set in Action() at the beginning and deleted at the end
96 
97     // OD 14.04.2003 #106346# - new flag for content formatting on interrupt.
98     bool    mbFormatContentOnInterrupt;
99 
100     // for loop control by disabling in-row splitting within embedded tables
101     const SwPageFrame  *m_pCurPage;
102     sal_uInt16 m_nTabLevel;  // embedding level
103     sal_uInt32 m_nCallCount; // calling FormatLayoutTab on the same page
104 
105     void PaintContent( const SwContentFrame *, const SwPageFrame *,
106                      const SwRect &rOldRect, long nOldBottom );
107     bool PaintWithoutFlys( const SwRect &, const SwContentFrame *,
108                            const SwPageFrame * );
109     inline bool PaintContent_( const SwContentFrame *, const SwPageFrame *,
110                              const SwRect & );
111 
112     bool FormatLayout( OutputDevice* pRenderContext, SwLayoutFrame *, bool bAddRect = true );
113     bool FormatLayoutTab( SwTabFrame *, bool bAddRect );
114     bool FormatContent( const SwPageFrame* pPage );
115     void FormatContent_( const SwContentFrame* pContent,
116                        const SwPageFrame* pPage );
117     bool IsShortCut( SwPageFrame *& );
118 
119     bool TurboAction();
120     bool TurboAction_( const SwContentFrame * );
121     void InternalAction(OutputDevice* pRenderContext);
122 
123     static SwPageFrame *CheckFirstVisPage( SwPageFrame *pPage );
124 
125     bool RemoveEmptyBrowserPages();
126 
127 public:
128     SwLayAction(SwRootFrame *pRt, SwViewShellImp *pImp, TaskStopwatch* pWatch = nullptr);
129     ~SwLayAction();
130 
SetCheckPages(bool bNew)131     void SetCheckPages      ( bool bNew )   { m_bCheckPages = bNew; }
SetBrowseActionStop(bool bNew)132     void SetBrowseActionStop( bool bNew )   { m_bBrowseActionStop = bNew; }
SetNextCycle(bool bNew)133     void SetNextCycle       ( bool bNew )   { m_bNextCycle = bNew; }
134 
IsWaitAllowed() const135     bool IsWaitAllowed()        const       { return m_bWaitAllowed; }
IsNextCycle() const136     bool IsNextCycle()          const       { return m_bNextCycle; }
IsPaint() const137     bool IsPaint()              const       { return m_bPaint; }
IsReschedule() const138     bool IsReschedule()         const       { return m_bReschedule;  }
IsIdle() const139     bool IsIdle()               const       { return m_pWatch != nullptr; }
IsPaintExtraData() const140     bool IsPaintExtraData()     const       { return m_bPaintExtraData; }
141     bool IsInterrupt();
142 
143     // adjusting Action to the wanted behaviour
SetPaint(bool bNew)144     void SetPaint       ( bool bNew )   { m_bPaint = bNew; }
SetComplete(bool bNew)145     void SetComplete    ( bool bNew )   { m_bComplete = bNew; }
146     void SetStatBar     ( bool bNew );
SetCalcLayout(bool bNew)147     void SetCalcLayout  ( bool bNew )   { m_bCalcLayout = bNew; }
SetReschedule(bool bNew)148     void SetReschedule  ( bool bNew )   { m_bReschedule = bNew; }
SetWaitAllowed(bool bNew)149     void SetWaitAllowed ( bool bNew )   { m_bWaitAllowed = bNew; }
150 
SetAgain()151     void SetAgain()         { m_bAgain = true; }
SetUpdateExpFields()152     void SetUpdateExpFields() {m_bUpdateExpFields = true; }
153 
154     inline void SetCheckPageNum( sal_uInt16 nNew );
SetCheckPageNumDirect(sal_uInt16 nNew)155     void SetCheckPageNumDirect( sal_uInt16 nNew ) { m_nCheckPageNum = nNew; }
156 
157     void Action(OutputDevice* pRenderContext); // here it begins
158     void Reset();   // back to CTor-defaults
159 
IsAgain() const160     bool IsAgain()      const { return m_bAgain; }
IsComplete() const161     bool IsComplete()   const { return m_bComplete; }
IsExpFields() const162     bool IsExpFields()    const { return m_bUpdateExpFields; }
IsCalcLayout() const163     bool IsCalcLayout() const { return m_bCalcLayout;  }
IsCheckPages() const164     bool IsCheckPages() const { return m_bCheckPages;  }
IsBrowseActionStop() const165     bool IsBrowseActionStop() const { return m_bBrowseActionStop; }
IsActionInProgress() const166     bool IsActionInProgress() const { return m_bActionInProgress; }
167 
GetCheckPageNum() const168     sal_uInt16 GetCheckPageNum() const { return m_nCheckPageNum; }
169 
170     // others should be able to activate the WaitCursor, too
171     void CheckWaitCursor();
172 
173     // #i28701# - method is now public;
174     // delete 2nd parameter, because it's not used;
175     void FormatLayoutFly( SwFlyFrame * );
176     // #i28701# - method is now public
177     void FormatFlyContent( const SwFlyFrame * );
178 
179 };
180 
181 class SwLayIdle
182 {
183     TaskStopwatch m_aWatch;
184     SwRootFrame *pRoot;
185     SwViewShellImp  *pImp;           // The Idler registers and deregisters here
186     SwContentNode *pContentNode;    // The current cursor position is saved here
187     sal_Int32  nTextPos;
188     bool        bPageValid;     // Were we able to evaluate everything on the whole page?
189 #ifdef DBG_UTIL
190     bool m_bIndicator;
191 
192     void ShowIdle( Color eName );
193 #endif
194 
195     bool IsInterrupt();
196     enum IdleJobType{ ONLINE_SPELLING, AUTOCOMPLETE_WORDS, WORD_COUNT, SMART_TAGS };
197     bool DoIdleJob_( const SwContentFrame*, IdleJobType );
198     bool DoIdleJob( IdleJobType, bool bVisAreaOnly );
199 
200 public:
201     SwLayIdle( SwRootFrame *pRt, SwViewShellImp *pImp );
202     ~SwLayIdle();
203 };
204 
SetCheckPageNum(sal_uInt16 nNew)205 inline void SwLayAction::SetCheckPageNum( sal_uInt16 nNew )
206 {
207     if ( nNew < m_nCheckPageNum )
208         m_nCheckPageNum = nNew;
209 }
210 
211 #endif // INCLUDED_SW_SOURCE_CORE_INC_LAYACT_HXX
212 
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
214