1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_SW_SOURCE_UIBASE_INC_PVIEW_HXX
20 #define INCLUDED_SW_SOURCE_UIBASE_INC_PVIEW_HXX
22 #include <tools/link.hxx>
23 #include <tools/fract.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>
30 #include <shellid.hxx>
40 class DataChangedEvent
;
42 class SwPagePreviewLayout
;
44 /// Provides the VCL widget that is used for the main area of the File -> Print Preview window.
45 class SAL_DLLPUBLIC_RTTI SwPagePreviewWin final
: public vcl::Window
47 SwViewShell
* mpViewShell
;
53 SwPagePreview
& mrView
;
54 bool mbCalcScaleForPreviewLayout
;
55 tools::Rectangle maPaintedPreviewDocRect
;
56 SwPagePreviewLayout
* mpPgPreviewLayout
;
58 void SetPagePreview( sal_Int16 nRow
, sal_Int16 nCol
);
63 SwPagePreviewWin( vcl::Window
* pParent
, SwPagePreview
& rView
);
64 virtual ~SwPagePreviewWin() override
;
66 // calls SwViewShell::Paint
67 virtual void Paint( vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
) override
;
68 virtual void KeyInput( const KeyEvent
& ) override
;
69 virtual void Command( const CommandEvent
& rCEvt
) override
;
70 virtual void MouseButtonDown(const MouseEvent
& rMEvt
) override
;
71 virtual void DataChanged( const DataChangedEvent
& ) override
;
73 void SetViewShell( SwViewShell
* pShell
);
75 SwViewShell
* GetViewShell() const
80 sal_Int16
GetRow() const
85 sal_Int16
GetCol() const
90 sal_uInt16
GetSttPage() const
95 void SetSttPage(sal_uInt16 n
)
100 /** get selected page number of document preview
102 @return selected page number
104 sal_uInt16
SelectedPage() const;
106 /** set selected page number in document preview
108 @param _nSelectedPageNum
109 input parameter - physical page number of page that will be the selected one.
111 void SetSelectedPage( sal_uInt16 _nSelectedPageNum
);
113 // If we only have one column we do not have a oth page
114 sal_uInt16
GetDefSttPage() const { return 1 == mnCol
? 1 : 0; }
116 void CalcWish( sal_Int16 nNewRow
, sal_Int16 nNewCol
);
118 void SetWinSize( const Size
& rNewSize
);
120 // Add <MV_SELPAGE>, <MV_SCROLL>
121 enum MoveMode
{ MV_CALC
, MV_PAGE_UP
, MV_PAGE_DOWN
, MV_DOC_STT
, MV_DOC_END
,
122 MV_SELPAGE
, MV_SCROLL
, MV_NEWWINSIZE
, MV_SPECIFIC_PAGE
};
123 bool MovePage( int eMoveMode
);
125 // Create the status bar's string
126 OUString
GetStatusStr( sal_uInt16 nPageCount
) const;
128 void RepaintCoreRect( const SwRect
& rRect
);
130 /** Method to adjust preview to a new zoom factor
131 paint of preview is prepared for a new zoom factor
132 Zoom type has also been considered.
133 Thus, add new parameter <_eZoomType>
135 void AdjustPreviewToNewZoom( const sal_uInt16 _nZoomFactor
,
136 const SvxZoomType _eZoomType
);
138 const tools::Rectangle
& GetPaintedPreviewDocRect() const
140 return maPaintedPreviewDocRect
;
143 void Scroll(tools::Long nXMove
, tools::Long nYMove
, ScrollFlags nFlags
= ScrollFlags::NONE
) override
;
145 /** Method to enable/disable book preview
147 input parameter - boolean indicating, if book preview mode has to
148 switch on <true> or of <false>
150 @return boolean indicating, if book preview mode has changed.
152 bool SetBookPreviewMode( const bool _bBookPreview
);
154 virtual css::uno::Reference
<css::accessibility::XAccessible
> CreateAccessible() override
;
160 class SW_DLLPUBLIC SwPagePreview final
: public SfxViewShell
162 // ViewWindow and handle to core
163 // current dispatcher shell
164 VclPtr
<SwPagePreviewWin
> m_pViewWin
;
165 //viewdata of the previous SwView and the new cursor position
166 OUString m_sSwViewData
;
167 //and the new cursor position if the user double click in the PagePreview
168 OUString m_sNewCursorPosition
;
169 // to support keyboard the number of the page to go to can be set too
170 sal_uInt16 m_nNewPage
;
174 tools::Rectangle m_aVisArea
;
176 // MDI control elements
177 VclPtr
<SwScrollbar
> m_pHScrollbar
;
178 VclPtr
<SwScrollbar
> m_pVScrollbar
;
179 bool mbHScrollbarEnabled
: 1;
180 bool mbVScrollbarEnabled
: 1;
182 sal_uInt16 mnPageCount
;
185 // New members to reset design mode at draw view for form shell on switching
186 // back from writer page preview to normal view.
187 bool mbResetFormDesignMode
:1;
188 bool mbFormDesignModeToReset
:1;
190 SAL_DLLPRIVATE
void Init();
191 SAL_DLLPRIVATE Point
AlignToPixel(const Point
& rPt
) const;
193 SAL_DLLPRIVATE
void CreateScrollbar( bool bHori
);
194 DECL_DLLPRIVATE_LINK(HoriScrollHdl
, weld::Scrollbar
&, void);
195 DECL_DLLPRIVATE_LINK(VertScrollHdl
, weld::Scrollbar
&, void);
196 SAL_DLLPRIVATE
void ScrollHdl(weld::Scrollbar
&, bool bHorizontal
);
197 SAL_DLLPRIVATE
void EndScrollHdl(weld::Scrollbar
&, bool bHorizontal
);
198 SAL_DLLPRIVATE
bool ChgPage( int eMvMode
, bool bUpdateScrollbar
= true );
200 SAL_DLLPRIVATE
virtual SfxPrinter
* GetPrinter( bool bCreate
= false ) override
;
201 SAL_DLLPRIVATE
virtual sal_uInt16
SetPrinter( SfxPrinter
*pNewPrinter
, SfxPrinterChangeFlags nDiffFlags
= SFX_PRINTER_ALL
) override
;
202 SAL_DLLPRIVATE
virtual bool HasPrintOptionsPage() const override
;
203 SAL_DLLPRIVATE
virtual std::unique_ptr
<SfxTabPage
> CreatePrintOptionsPage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
&rOptions
) override
;
205 SAL_DLLPRIVATE
void CalcAndSetBorderPixel( SvBorder
&rToFill
);
207 /** Helper method to execute SfxRequest FN_PAGE_UP and FN_PAGE_DOWN
210 input parameter - boolean that indicates, if FN_PAGE_UP or FN_PAGE_DOWN
214 optional input parameter - pointer to the <SfxRequest> instance, if existing.
216 SAL_DLLPRIVATE
void ExecPgUpAndPgDown( const bool _bPgUp
,
219 virtual void InnerResizePixel( const Point
&rOfs
, const Size
&rSize
, bool inplaceEditModeChange
) override
;
220 virtual void OuterResizePixel( const Point
&rOfs
, const Size
&rSize
) override
;
222 void Activate(bool bMDI
) override
;
224 void SetZoom(SvxZoomType eSet
, sal_uInt16 nFactor
);
227 SFX_DECL_VIEWFACTORY(SwPagePreview
);
228 SFX_DECL_INTERFACE(SW_PAGEPREVIEW
)
231 /// SfxInterface initializer.
232 static void InitInterface_Impl();
235 SwViewShell
* GetViewShell() const
236 { return m_pViewWin
->GetViewShell(); }
237 void RepaintCoreRect( const SwRect
& rRect
)
238 { m_pViewWin
->RepaintCoreRect( rRect
); }
240 void DocSzChgd(const Size
& rNewSize
);
242 void SetVisArea( const tools::Rectangle
& );
244 void ScrollViewSzChg();
245 void ScrollDocSzChg();
246 void ShowHScrollbar(bool bShow
);
247 void ShowVScrollbar(bool bShow
);
248 void EnableHScrollbar(bool bEnable
);
249 void EnableVScrollbar(bool bEnable
);
251 sal_uInt16
GetPageCount() const { return mnPageCount
; }
252 sal_uInt16
GetSelectedPage() const {return m_pViewWin
->SelectedPage();}
254 bool HandleWheelCommands( const CommandEvent
& );
256 const OUString
& GetPrevSwViewData() const { return m_sSwViewData
; }
257 void SetNewCursorPos( const OUString
& rStr
) { m_sNewCursorPosition
= rStr
; }
258 const OUString
& GetNewCursorPos() const { return m_sNewCursorPosition
; }
260 sal_uInt16
GetNewPage() const {return m_nNewPage
;}
263 void Execute(SfxRequest
&);
264 void GetState(SfxItemSet
&);
265 static void StateUndo(SfxItemSet
&);
267 SwDocShell
* GetDocShell();
269 // Inline method to request values of new members
270 // <mbResetFormDesignMode> and <mbFormDesignModeToReset>
271 bool ResetFormDesignMode() const
273 return mbResetFormDesignMode
;
276 bool FormDesignModeToReset() const
278 return mbFormDesignModeToReset
;
281 /** Adjust position of vertical scrollbar
283 Currently used, if the complete preview layout rows fit into to the given
284 window, if a new page is selected and this page is visible.
287 input parameter - new position, which will be assigned to the vertical
290 void SetVScrollbarThumbPos( const sal_uInt16 _nNewThumbPos
);
292 SwPagePreview(SfxViewFrame
& rFrame
, SfxViewShell
*);
293 virtual ~SwPagePreview() override
;
299 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */