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 #pragma once
20 
21 #include <vcl/window.hxx>
22 #include "printfun.hxx"
23 #include <markdata.hxx>
24 
25 #include <vector>
26 
27 class ScDocShell;
28 class ScPreviewShell;
29 class FmFormView;
30 
31 class SAL_DLLPUBLIC_RTTI ScPreview : public vcl::Window
32 {
33 private:
34     ScMarkData::MarkedTabsType maSelectedTabs;
35                                         // set:
36     tools::Long            nPageNo;            // Pages in document
37     sal_uInt16          nZoom;              // set Zoom
38     Point           aOffset;            // positive
39 
40                                         // calculated:
41     SCTAB           nTabCount;
42     SCTAB           nTabsTested;        // for how many sheets is nPages valid?
43     std::vector<tools::Long>       nPages;
44     std::vector<tools::Long>       nFirstAttr;
45     SCTAB           nTab;               // Sheet
46     tools::Long            nTabPage;           // Page of sheet
47     tools::Long            nTabStart;          // First (real) page of the sheet
48     tools::Long            nDisplayStart;      // same as above, relative to the start of counting
49     DateTime        aDateTime;
50     tools::Long            nTotalPages;
51     ScPrintState    aState;
52     std::unique_ptr<ScPreviewLocationData> pLocationData;   // stores table layout for accessibility API
53     std::unique_ptr<FmFormView> pDrawView;
54 
55                                         // internal:
56     ScDocShell*     pDocShell;
57     ScPreviewShell* pViewShell;
58 
59     bool            bInGetState:1;
60     bool            bValid:1;             // the following values true
61     bool            bStateValid:1;
62     bool            bLocationValid:1;
63     bool            bInPaint:1;
64     bool            bInSetZoom:1;
65     bool            bLeftRulerMove:1;
66     bool            bRightRulerMove:1;
67     bool            bTopRulerMove:1;
68     bool            bBottomRulerMove:1;
69     bool            bHeaderRulerMove:1;
70     bool            bFooterRulerMove:1;
71     bool            bLeftRulerChange:1;
72     bool            bRightRulerChange:1;
73     bool            bTopRulerChange:1;
74     bool            bBottomRulerChange:1;
75     bool            bHeaderRulerChange:1;
76     bool            bFooterRulerChange:1;
77     bool            bPageMargin:1;
78     bool            bColRulerMove:1;
79     bool            mbHasEmptyRangeTable:1; /// we have at least one sheet with empty print range (print range set to '- none -').
80 
81     ScRange         aPageArea;
82     std::vector<tools::Long> mvRight;
83     tools::Long            nLeftPosition;
84     tools::Long            mnScale;
85     SCCOL           nColNumberButtonDown;
86     Point           aButtonDownChangePoint;
87     Point           aButtonDownPt;
88     Point           aButtonUpPt;
89     tools::Long            nHeaderHeight;
90     tools::Long            nFooterHeight;
91 
92     void    TestLastPage();
93     void    CalcPages();
94     void    RecalcPages();
95     void    UpdateDrawView();
96     void    DoPrint( ScPreviewLocationData* pFillLocation );
97 
98     void    InvalidateLocationData( SfxHintId nId );
99 
100     using Window::SetZoom;
101 
102 protected:
103     virtual void   Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
104     virtual void   Command( const CommandEvent& rCEvt ) override;
105     virtual void   KeyInput( const KeyEvent& rKEvt ) override;
106     virtual void   MouseMove( const MouseEvent& rMEvt ) override;
107     virtual void   MouseButtonDown( const MouseEvent& rMEvt ) override;
108     virtual void   MouseButtonUp( const MouseEvent& rMEvt ) override;
109 
110     virtual void   GetFocus() override;
111     virtual void   LoseFocus() override;
112 
113     virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible() override;
114 
115 public:
116             ScPreview( vcl::Window* pParent, ScDocShell* pDocSh, ScPreviewShell* pViewSh );
117             virtual ~ScPreview() override;
118     virtual void dispose() override;
119 
120     virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
121 
122     SC_DLLPUBLIC void    DataChanged(bool bNewTime);             //  Instead of calling Invalidate
123     void    DoInvalidate();
124 
125     void    SetXOffset( tools::Long nX );
126     void    SetYOffset( tools::Long nY );
127     void    SetZoom(sal_uInt16 nNewZoom);
128     SC_DLLPUBLIC void    SetPageNo( tools::Long nPage );
129 
GetPageMargins() const130     bool    GetPageMargins() const { return bPageMargin; }
SetPageMargins(bool bVal)131     void    SetPageMargins( bool bVal )  { bPageMargin = bVal; }
132     void    DrawInvert( tools::Long nDragPos, PointerStyle nFlags );
133     void    DragMove( tools::Long nDragMovePos, PointerStyle nFlags );
134 
135     const ScPreviewLocationData& GetLocationData();
136 
137     OUString  GetPosString();
138 
GetPageNo() const139     tools::Long    GetPageNo() const   { return nPageNo; }
GetZoom() const140     sal_uInt16  GetZoom() const     { return nZoom; }
GetOffset() const141     const Point& GetOffset() const   { return aOffset; }
142 
GetTab()143     SCTAB   GetTab()            { if (!bValid) { CalcPages(); RecalcPages(); } return nTab; }
GetTotalPages()144     tools::Long    GetTotalPages()     { if (!bValid) { CalcPages(); RecalcPages(); } return nTotalPages; }
145 
AllTested() const146     bool    AllTested() const   { return bValid && nTabsTested >= nTabCount; }
147 
148     sal_uInt16  GetOptimalZoom(bool bWidthOnly);
149     SC_DLLPUBLIC tools::Long    GetFirstPage(SCTAB nTab);
150 
CalcAll()151     void    CalcAll()           { CalcPages(); }
SetInGetState(bool bSet)152     void    SetInGetState(bool bSet) { bInGetState = bSet; }
153 
154     DECL_STATIC_LINK( ScPreview, InvalidateHdl, void*, void );
155     static void StaticInvalidate();
156 
GetDrawView()157     FmFormView* GetDrawView() { return pDrawView.get(); }
158 
159     SC_DLLPUBLIC void SetSelectedTabs(const ScMarkData& rMark);
GetSelectedTabs() const160     const ScMarkData::MarkedTabsType& GetSelectedTabs() const { return maSelectedTabs; }
161 };
162 
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
164