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_UIBASE_INC_PVIEW_HXX
20 : #define INCLUDED_SW_SOURCE_UIBASE_INC_PVIEW_HXX
21 :
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>
29 : #include "swdllapi.h"
30 : #include "shellid.hxx"
31 :
32 : class SwViewOption;
33 : class SwDocShell;
34 : class SwScrollbar;
35 : class SwViewShell;
36 : class SwPagePreview;
37 : class ImageButton;
38 : class Button;
39 : class SwRect;
40 : class DataChangedEvent;
41 : class CommandEvent;
42 : class SvtAccessibilityOptions;
43 : class SwPagePreviewLayout;
44 :
45 : // Delete member <mnVirtPage> and its accessor
46 : class SwPagePreviewWin : public vcl::Window
47 : {
48 : SwViewShell* mpViewShell;
49 : sal_uInt16 mnSttPage;
50 : sal_uInt8 mnRow;
51 : sal_uInt8 mnCol;
52 : Size maPxWinSize;
53 : Fraction maScale;
54 : SwPagePreview& mrView;
55 : bool mbCalcScaleForPreviewLayout;
56 : Rectangle maPaintedPreviewDocRect;
57 : SwPagePreviewLayout* mpPgPreviewLayout;
58 :
59 : void SetPagePreview( sal_uInt8 nRow, sal_uInt8 nCol );
60 :
61 : using Window::Scroll;
62 :
63 : public:
64 : SwPagePreviewWin( vcl::Window* pParent, SwPagePreview& rView );
65 : virtual ~SwPagePreviewWin();
66 :
67 : // calls SwViewShell::Paint
68 : virtual void Paint( vcl::RenderContext& rRenderContext, const Rectangle& rRect ) SAL_OVERRIDE;
69 : virtual void KeyInput( const KeyEvent & ) SAL_OVERRIDE;
70 : virtual void Command( const CommandEvent& rCEvt ) SAL_OVERRIDE;
71 : virtual void MouseButtonDown(const MouseEvent& rMEvt) SAL_OVERRIDE;
72 : virtual void DataChanged( const DataChangedEvent& ) SAL_OVERRIDE;
73 :
74 : void SetViewShell( SwViewShell* pShell );
75 :
76 0 : SwViewShell* GetViewShell() const
77 : {
78 0 : return mpViewShell;
79 : }
80 :
81 0 : sal_uInt8 GetRow() const
82 : {
83 0 : return mnRow;
84 : }
85 :
86 : void SetRow(sal_uInt8 n)
87 : {
88 : if(n)
89 : mnRow = n;
90 : }
91 :
92 0 : sal_uInt8 GetCol() const
93 : {
94 0 : return mnCol;
95 : }
96 : void SetCol(sal_uInt8 n)
97 : {
98 : if(n)
99 : mnCol = n;
100 : }
101 :
102 0 : sal_uInt16 GetSttPage() const
103 : {
104 0 : return mnSttPage;
105 : }
106 :
107 0 : void SetSttPage(sal_uInt16 n)
108 : {
109 0 : mnSttPage = n;
110 0 : }
111 :
112 : /** get selected page number of document preview
113 :
114 : @return selected page number
115 : */
116 : sal_uInt16 SelectedPage() const;
117 :
118 : /** set selected page number in document preview
119 :
120 : @param _nSelectedPageNum
121 : input parameter - physical page number of page that will be the selected one.
122 : */
123 : void SetSelectedPage( sal_uInt16 _nSelectedPageNum );
124 :
125 : // If we only have one column we do not have a oth page
126 0 : sal_uInt16 GetDefSttPage() const { return 1 == mnCol ? 1 : 0; }
127 :
128 : void CalcWish( sal_uInt8 nNewRow, sal_uInt8 nNewCol );
129 :
130 : const Size& GetWinSize() const { return maPxWinSize; }
131 : void SetWinSize( const Size& rNewSize );
132 :
133 : // Add <MV_SELPAGE>, <MV_SCROLL>
134 : enum MoveMode{ MV_CALC, MV_PAGE_UP, MV_PAGE_DOWN, MV_DOC_STT, MV_DOC_END,
135 : MV_SELPAGE, MV_SCROLL, MV_NEWWINSIZE };
136 : bool MovePage( int eMoveMode );
137 :
138 : // Create the status bar's string
139 : OUString GetStatusStr( sal_uInt16 nPageCount ) const;
140 :
141 : void RepaintCoreRect( const SwRect& rRect );
142 :
143 : /** Method to adjust preview to a new zoom factor
144 : paint of preview is prepared for a new zoom factor
145 : Zoom type has also been considered.
146 : Thus, add new parameter <_eZoomType>
147 : */
148 : void AdjustPreviewToNewZoom( const sal_uInt16 _nZoomFactor,
149 : const SvxZoomType _eZoomType );
150 :
151 0 : const Rectangle& GetPaintedPreviewDocRect() const
152 : {
153 0 : return maPaintedPreviewDocRect;
154 : }
155 :
156 : void Scroll(long nXMove, long nYMove, ScrollFlags nFlags = ScrollFlags::NONE) SAL_OVERRIDE;
157 :
158 : /** Method to enable/disable book preview
159 : @param _bBookPreview
160 : input parameter - boolean indicating, if book preview mode has to
161 : switch on <true> or of <false>
162 :
163 : @return boolean indicating, if book preview mode has changed.
164 : */
165 : bool SetBookPreviewMode( const bool _bBookPreview );
166 :
167 : virtual css::uno::Reference<css::accessibility::XAccessible> CreateAccessible() SAL_OVERRIDE;
168 : };
169 :
170 : /**
171 : * View of a document
172 : */
173 : class SW_DLLPUBLIC SwPagePreview: public SfxViewShell
174 : {
175 : // ViewWindow and handle to core
176 : // current dispatcher shell
177 : VclPtr<SwPagePreviewWin> pViewWin;
178 : //viewdata of the previous SwView and the new crsrposition
179 : OUString sSwViewData;
180 : //and the new cursor position if the user double click in the PagePreview
181 : OUString sNewCrsrPos;
182 : // to support keyboard the number of the page to go to can be set too
183 : sal_uInt16 nNewPage;
184 : // visible range
185 : OUString sPageStr;
186 : Size aDocSz;
187 : Rectangle aVisArea;
188 :
189 : // MDI control elements
190 : VclPtr<SwScrollbar> pHScrollbar;
191 : VclPtr<SwScrollbar> pVScrollbar;
192 : bool mbHScrollbarEnabled : 1;
193 : bool mbVScrollbarEnabled : 1;
194 : VclPtr<ImageButton> pPageUpBtn;
195 : VclPtr<ImageButton> pPageDownBtn;
196 : // dummy window for filling the lower right edge when both scrollbars are active
197 : VclPtr<vcl::Window> pScrollFill;
198 :
199 : sal_uInt16 mnPageCount;
200 : bool bNormalPrint;
201 :
202 : // New members to reset design mode at draw view for form shell on switching
203 : // back from writer page preview to normal view.
204 : bool mbResetFormDesignMode:1;
205 : bool mbFormDesignModeToReset:1;
206 :
207 : SAL_DLLPRIVATE void Init(const SwViewOption* = 0);
208 : SAL_DLLPRIVATE Point AlignToPixel(const Point& rPt) const;
209 :
210 : SAL_DLLPRIVATE int _CreateScrollbar( bool bHori);
211 : DECL_DLLPRIVATE_LINK(ScrollHdl, SwScrollbar*);
212 : DECL_DLLPRIVATE_LINK(EndScrollHdl, SwScrollbar*);
213 : DECL_DLLPRIVATE_LINK(BtnPage, Button*);
214 : SAL_DLLPRIVATE bool ChgPage( int eMvMode, bool bUpdateScrollbar = true );
215 :
216 : SAL_DLLPRIVATE virtual SfxPrinter* GetPrinter( bool bCreate = false ) SAL_OVERRIDE;
217 : SAL_DLLPRIVATE virtual sal_uInt16 SetPrinter( SfxPrinter *pNewPrinter, SfxPrinterChangeFlags nDiffFlags = SFX_PRINTER_ALL, bool bIsAPI=false ) SAL_OVERRIDE;
218 : SAL_DLLPRIVATE virtual bool HasPrintOptionsPage() const SAL_OVERRIDE;
219 : SAL_DLLPRIVATE virtual VclPtr<SfxTabPage> CreatePrintOptionsPage(vcl::Window *pParent, const SfxItemSet &rOptions ) SAL_OVERRIDE;
220 :
221 : SAL_DLLPRIVATE void CalcAndSetBorderPixel( SvBorder &rToFill, bool bInner );
222 :
223 : /** Helper method to execute SfxRequest FN_PAGE_UP and FN_PAGE_DOWN
224 :
225 : @param _bPgUp
226 : input parameter - boolean that indicates, if FN_PAGE_UP or FN_PAGE_DOWN
227 : has to be executed.
228 :
229 : @param _pReq
230 : optional input parameter - pointer to the <SfxRequest> instance, if existing.
231 : */
232 : SAL_DLLPRIVATE void _ExecPgUpAndPgDown( const bool _bPgUp,
233 : SfxRequest* _pReq = 0 );
234 :
235 : protected:
236 : virtual void InnerResizePixel( const Point &rOfs, const Size &rSize ) SAL_OVERRIDE;
237 : virtual void OuterResizePixel( const Point &rOfs, const Size &rSize ) SAL_OVERRIDE;
238 :
239 : void SetZoom(SvxZoomType eSet, sal_uInt16 nFactor);
240 :
241 : public:
242 177 : SFX_DECL_VIEWFACTORY(SwPagePreview);
243 59 : SFX_DECL_INTERFACE(SW_PAGEPREVIEW)
244 : TYPEINFO_OVERRIDE();
245 :
246 : private:
247 : /// SfxInterface initializer.
248 : static void InitInterface_Impl();
249 :
250 : public:
251 : inline vcl::Window& GetFrameWindow() const
252 : { return GetViewFrame()->GetWindow(); }
253 0 : inline SwViewShell* GetViewShell() const
254 0 : { return pViewWin->GetViewShell(); }
255 : inline const Rectangle& GetVisArea() const
256 : { return aVisArea; }
257 : inline void GrabFocusViewWin()
258 : { pViewWin->GrabFocus(); }
259 0 : inline void RepaintCoreRect( const SwRect& rRect )
260 0 : { pViewWin->RepaintCoreRect( rRect ); }
261 :
262 : void DocSzChgd(const Size& rNewSize);
263 : const Size& GetDocSz() const
264 : { return aDocSz; }
265 :
266 : void SetVisArea( const Rectangle&, bool bUpdateScrollbar = true);
267 :
268 : inline void AdjustEditWin();
269 :
270 : void ScrollViewSzChg();
271 : void ScrollDocSzChg();
272 : void ShowHScrollbar(bool bShow);
273 : void ShowVScrollbar(bool bShow);
274 : void EnableHScrollbar(bool bEnable);
275 : void EnableVScrollbar(bool bEnable);
276 :
277 0 : sal_uInt16 GetPageCount() const { return mnPageCount; }
278 0 : sal_uInt16 GetSelectedPage() const {return pViewWin->SelectedPage();}
279 :
280 : bool HandleWheelCommands( const CommandEvent& );
281 :
282 0 : OUString GetPrevSwViewData() const { return sSwViewData; }
283 0 : void SetNewCrsrPos( const OUString& rStr ) { sNewCrsrPos = rStr; }
284 0 : const OUString& GetNewCrsrPos() const { return sNewCrsrPos; }
285 :
286 0 : sal_uInt16 GetNewPage() const {return nNewPage;}
287 0 : void SetNewPage(sal_uInt16 nSet) {nNewPage = nSet;}
288 :
289 : // Handler
290 : void Execute(SfxRequest&);
291 : void GetState(SfxItemSet&);
292 : static void StateUndo(SfxItemSet&);
293 :
294 : SwDocShell* GetDocShell();
295 :
296 : // apply Accessiblity options
297 : void ApplyAccessiblityOptions(SvtAccessibilityOptions& rAccessibilityOptions);
298 :
299 : // Inline method to request values of new members
300 : // <mbResetFormDesignMode> and <mbFormDesignModeToReset>
301 0 : inline bool ResetFormDesignMode() const
302 : {
303 0 : return mbResetFormDesignMode;
304 : }
305 :
306 0 : inline bool FormDesignModeToReset() const
307 : {
308 0 : return mbFormDesignModeToReset;
309 : }
310 :
311 : /** Adjust position of vertical scrollbar
312 :
313 : Currently used, if the complete preview layout rows fit into to the given
314 : window, if a new page is selected and this page is visible.
315 :
316 : @param _nNewThumbPos
317 : input parameter - new position, which will be assigned to the vertical
318 : scrollbar.
319 : */
320 : void SetVScrollbarThumbPos( const sal_uInt16 _nNewThumbPos );
321 :
322 : SwPagePreview( SfxViewFrame* pFrame, SfxViewShell* );
323 : virtual ~SwPagePreview();
324 : };
325 :
326 : inline void SwPagePreview::AdjustEditWin()
327 : {
328 : OuterResizePixel( Point(), GetFrameWindow().GetOutputSizePixel() );
329 : }
330 :
331 : #endif
332 :
333 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|