/src/libreoffice/sw/source/uibase/inc/pview.hxx
Line | Count | Source |
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 <tools/link.hxx> |
22 | | #include <tools/fract.hxx> |
23 | | #include <vcl/weld/Scrollbar.hxx> |
24 | | #include <vcl/window.hxx> |
25 | | #include <sfx2/viewfrm.hxx> |
26 | | #include <sfx2/viewfac.hxx> |
27 | | #include <sfx2/viewsh.hxx> |
28 | | #include <sfx2/zoomitem.hxx> |
29 | | #include <swdllapi.h> |
30 | | #include <shellid.hxx> |
31 | | |
32 | | class SwDocShell; |
33 | | class SwScrollbar; |
34 | | class SwViewShell; |
35 | | class SwPagePreview; |
36 | | class SwRect; |
37 | | class CommandEvent; |
38 | | class SwPagePreviewLayout; |
39 | | |
40 | | /// Provides the VCL widget that is used for the main area of the File -> Print Preview window. |
41 | | class SAL_DLLPUBLIC_RTTI SwPagePreviewWin final : public vcl::Window |
42 | | { |
43 | | SwViewShell* mpViewShell; |
44 | | sal_uInt16 mnSttPage; |
45 | | sal_Int16 mnRow; |
46 | | sal_Int16 mnCol; |
47 | | Size maPxWinSize; |
48 | | double mfScale; |
49 | | SwPagePreview& mrView; |
50 | | bool mbCalcScaleForPreviewLayout; |
51 | | tools::Rectangle maPaintedPreviewDocRect; |
52 | | SwPagePreviewLayout* mpPgPreviewLayout; |
53 | | |
54 | | void SetPagePreview( sal_Int16 nRow, sal_Int16 nCol ); |
55 | | |
56 | | using Window::Scroll; |
57 | | |
58 | | public: |
59 | | SwPagePreviewWin( vcl::Window* pParent, SwPagePreview& rView ); |
60 | | virtual ~SwPagePreviewWin() override; |
61 | | |
62 | | // calls SwViewShell::Paint |
63 | | virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override; |
64 | | virtual void KeyInput( const KeyEvent & ) override; |
65 | | virtual void Command( const CommandEvent& rCEvt ) override; |
66 | | virtual void MouseButtonDown(const MouseEvent& rMEvt) override; |
67 | | virtual void DataChanged( const DataChangedEvent& ) override; |
68 | | |
69 | | void SetViewShell( SwViewShell* pShell ); |
70 | | |
71 | | SwViewShell* GetViewShell() const |
72 | 0 | { |
73 | 0 | return mpViewShell; |
74 | 0 | } |
75 | | |
76 | | sal_Int16 GetRow() const |
77 | 0 | { |
78 | 0 | return mnRow; |
79 | 0 | } |
80 | | |
81 | | sal_Int16 GetCol() const |
82 | 0 | { |
83 | 0 | return mnCol; |
84 | 0 | } |
85 | | |
86 | | sal_uInt16 GetSttPage() const |
87 | 0 | { |
88 | 0 | return mnSttPage; |
89 | 0 | } |
90 | | |
91 | | void SetSttPage(sal_uInt16 n) |
92 | 0 | { |
93 | 0 | mnSttPage = n; |
94 | 0 | } |
95 | | |
96 | | /** get selected page number of document preview |
97 | | |
98 | | @return selected page number |
99 | | */ |
100 | | sal_uInt16 SelectedPage() const; |
101 | | |
102 | | /** set selected page number in document preview |
103 | | |
104 | | @param _nSelectedPageNum |
105 | | input parameter - physical page number of page that will be the selected one. |
106 | | */ |
107 | | void SetSelectedPage( sal_uInt16 _nSelectedPageNum ); |
108 | | |
109 | | // If we only have one column we do not have a oth page |
110 | 0 | sal_uInt16 GetDefSttPage() const { return 1 == mnCol ? 1 : 0; } |
111 | | |
112 | | void CalcWish( sal_Int16 nNewRow, sal_Int16 nNewCol ); |
113 | | |
114 | | void SetWinSize( const Size& rNewSize ); |
115 | | |
116 | | // Add <MV_SELPAGE>, <MV_SCROLL> |
117 | | enum MoveMode{ MV_CALC, MV_PAGE_UP, MV_PAGE_DOWN, MV_DOC_STT, MV_DOC_END, |
118 | | MV_SELPAGE, MV_SCROLL, MV_NEWWINSIZE, MV_SPECIFIC_PAGE }; |
119 | | bool MovePage( int eMoveMode ); |
120 | | |
121 | | // Create the status bar's string |
122 | | OUString GetStatusStr( sal_uInt16 nPageCount ) const; |
123 | | |
124 | | void RepaintCoreRect( const SwRect& rRect ); |
125 | | |
126 | | /** Method to adjust preview to a new zoom factor |
127 | | paint of preview is prepared for a new zoom factor |
128 | | Zoom type has also been considered. |
129 | | Thus, add new parameter <_eZoomType> |
130 | | */ |
131 | | void AdjustPreviewToNewZoom( const sal_uInt16 _nZoomFactor, |
132 | | const SvxZoomType _eZoomType ); |
133 | | |
134 | | const tools::Rectangle& GetPaintedPreviewDocRect() const |
135 | 0 | { |
136 | 0 | return maPaintedPreviewDocRect; |
137 | 0 | } |
138 | | |
139 | | void Scroll(tools::Long nXMove, tools::Long nYMove, ScrollFlags nFlags = ScrollFlags::NONE) override; |
140 | | |
141 | | /** Method to enable/disable book preview |
142 | | @param _bBookPreview |
143 | | input parameter - boolean indicating, if book preview mode has to |
144 | | switch on <true> or of <false> |
145 | | |
146 | | @return boolean indicating, if book preview mode has changed. |
147 | | */ |
148 | | bool SetBookPreviewMode( const bool _bBookPreview ); |
149 | | |
150 | | virtual rtl::Reference<comphelper::OAccessible> CreateAccessible() override; |
151 | | |
152 | | void ReInit(); |
153 | | }; |
154 | | |
155 | | /** |
156 | | * View of a document |
157 | | */ |
158 | | class SW_DLLPUBLIC SwPagePreview final : public SfxViewShell |
159 | | { |
160 | | // ViewWindow and handle to core |
161 | | // current dispatcher shell |
162 | | VclPtr<SwPagePreviewWin> m_pViewWin; |
163 | | //viewdata of the previous SwView and the new cursor position |
164 | | OUString m_sSwViewData; |
165 | | //and the new cursor position if the user double click in the PagePreview |
166 | | OUString m_sNewCursorPosition; |
167 | | // to support keyboard the number of the page to go to can be set too |
168 | | sal_uInt16 m_nNewPage; |
169 | | // visible range |
170 | | OUString m_sPageStr; |
171 | | Size m_aDocSize; |
172 | | tools::Rectangle m_aVisArea; |
173 | | |
174 | | // MDI control elements |
175 | | VclPtr<SwScrollbar> m_pHScrollbar; |
176 | | VclPtr<SwScrollbar> m_pVScrollbar; |
177 | | bool mbHScrollbarEnabled : 1; |
178 | | bool mbVScrollbarEnabled : 1; |
179 | | |
180 | | sal_uInt16 mnPageCount; |
181 | | bool m_bNormalPrint; |
182 | | |
183 | | // New members to reset design mode at draw view for form shell on switching |
184 | | // back from writer page preview to normal view. |
185 | | bool mbResetFormDesignMode:1; |
186 | | bool mbFormDesignModeToReset:1; |
187 | | |
188 | | SAL_DLLPRIVATE void Init(); |
189 | | SAL_DLLPRIVATE Point AlignToPixel(const Point& rPt) const; |
190 | | |
191 | | SAL_DLLPRIVATE void CreateScrollbar( bool bHori); |
192 | | DECL_DLLPRIVATE_LINK(HoriScrollHdl, weld::Scrollbar&, void); |
193 | | DECL_DLLPRIVATE_LINK(VertScrollHdl, weld::Scrollbar&, void); |
194 | | SAL_DLLPRIVATE void ScrollHdl(const weld::Scrollbar&, bool bHorizontal); |
195 | | SAL_DLLPRIVATE void EndScrollHdl(const weld::Scrollbar&, bool bHorizontal); |
196 | | SAL_DLLPRIVATE bool ChgPage( int eMvMode, bool bUpdateScrollbar = true ); |
197 | | |
198 | | SAL_DLLPRIVATE virtual SfxPrinter* GetPrinter( bool bCreate = false ) override; |
199 | | SAL_DLLPRIVATE virtual sal_uInt16 SetPrinter( SfxPrinter *pNewPrinter, SfxPrinterChangeFlags nDiffFlags = SFX_PRINTER_ALL ) override; |
200 | | SAL_DLLPRIVATE virtual bool HasPrintOptionsPage() const override; |
201 | | SAL_DLLPRIVATE virtual std::unique_ptr<SfxTabPage> CreatePrintOptionsPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet &rOptions) override; |
202 | | |
203 | | SAL_DLLPRIVATE void CalcAndSetBorderPixel( SvBorder &rToFill ); |
204 | | |
205 | | /** Helper method to execute SfxRequest FN_PAGE_UP and FN_PAGE_DOWN |
206 | | |
207 | | @param _bPgUp |
208 | | input parameter - boolean that indicates, if FN_PAGE_UP or FN_PAGE_DOWN |
209 | | has to be executed. |
210 | | |
211 | | @param _pReq |
212 | | optional input parameter - pointer to the <SfxRequest> instance, if existing. |
213 | | */ |
214 | | SAL_DLLPRIVATE void ExecPgUpAndPgDown( const bool _bPgUp, |
215 | | SfxRequest* _pReq ); |
216 | | |
217 | | virtual void InnerResizePixel( const Point &rOfs, const Size &rSize, bool inplaceEditModeChange ) override; |
218 | | virtual void OuterResizePixel( const Point &rOfs, const Size &rSize ) override; |
219 | | |
220 | | void Activate(bool bMDI) override; |
221 | | |
222 | | void SetZoom(SvxZoomType eSet, sal_uInt16 nFactor); |
223 | | |
224 | | public: |
225 | | SFX_DECL_VIEWFACTORY(SwPagePreview); |
226 | | SFX_DECL_INTERFACE(SW_PAGEPREVIEW) |
227 | | |
228 | | private: |
229 | | /// SfxInterface initializer. |
230 | | static void InitInterface_Impl(); |
231 | | |
232 | | public: |
233 | | SwViewShell* GetViewShell() const |
234 | 0 | { return m_pViewWin->GetViewShell(); } |
235 | | void RepaintCoreRect( const SwRect& rRect ) |
236 | 0 | { m_pViewWin->RepaintCoreRect( rRect ); } |
237 | | |
238 | | void DocSzChgd(const Size& rNewSize); |
239 | | |
240 | | void SetVisArea( const tools::Rectangle& ); |
241 | | |
242 | | void ScrollViewSzChg(); |
243 | | void ScrollDocSzChg(); |
244 | | void ShowHScrollbar(bool bShow); |
245 | | void ShowVScrollbar(bool bShow); |
246 | | void EnableHScrollbar(bool bEnable); |
247 | | void EnableVScrollbar(bool bEnable); |
248 | | |
249 | 0 | sal_uInt16 GetPageCount() const { return mnPageCount; } |
250 | 0 | sal_uInt16 GetSelectedPage() const {return m_pViewWin->SelectedPage();} |
251 | | |
252 | | bool HandleWheelCommands( const CommandEvent& ); |
253 | | |
254 | 0 | const OUString& GetPrevSwViewData() const { return m_sSwViewData; } |
255 | 0 | void SetNewCursorPos( const OUString& rStr ) { m_sNewCursorPosition = rStr; } |
256 | 0 | const OUString& GetNewCursorPos() const { return m_sNewCursorPosition; } |
257 | | |
258 | 0 | sal_uInt16 GetNewPage() const {return m_nNewPage;} |
259 | | |
260 | | // Handler |
261 | | void Execute(SfxRequest&); |
262 | | void GetState(SfxItemSet&); |
263 | | static void StateUndo(SfxItemSet&); |
264 | | |
265 | | SwDocShell* GetDocShell(); |
266 | | |
267 | | // Inline method to request values of new members |
268 | | // <mbResetFormDesignMode> and <mbFormDesignModeToReset> |
269 | | bool ResetFormDesignMode() const |
270 | 0 | { |
271 | 0 | return mbResetFormDesignMode; |
272 | 0 | } |
273 | | |
274 | | bool FormDesignModeToReset() const |
275 | 0 | { |
276 | 0 | return mbFormDesignModeToReset; |
277 | 0 | } |
278 | | |
279 | | /** Adjust position of vertical scrollbar |
280 | | |
281 | | Currently used, if the complete preview layout rows fit into to the given |
282 | | window, if a new page is selected and this page is visible. |
283 | | |
284 | | @param _nNewThumbPos |
285 | | input parameter - new position, which will be assigned to the vertical |
286 | | scrollbar. |
287 | | */ |
288 | | void SetVScrollbarThumbPos( const sal_uInt16 _nNewThumbPos ); |
289 | | |
290 | | void PrintSettingsChanged(); |
291 | | |
292 | | SwPagePreview(SfxViewFrame& rFrame, SfxViewShell*); |
293 | | virtual ~SwPagePreview() override; |
294 | | }; |
295 | | |
296 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |