summaryrefslogtreecommitdiff
path: root/sw/source/uibase/inc/pview.hxx
blob: 4d1414efe362692bc8cce830d0e29f309b27cabb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */
#ifndef INCLUDED_SW_SOURCE_UIBASE_INC_PVIEW_HXX
#define INCLUDED_SW_SOURCE_UIBASE_INC_PVIEW_HXX

#include <tools/link.hxx>
#include <tools/fract.hxx>
#include <vcl/window.hxx>
#include <sfx2/viewfrm.hxx>
#include <sfx2/viewfac.hxx>
#include <sfx2/viewsh.hxx>
#include <sfx2/zoomitem.hxx>
#include <swdllapi.h>
#include <shellid.hxx>

class SwViewOption;
class SwDocShell;
class SwScrollbar;
class SwViewShell;
class SwPagePreview;
class ImageButton;
class Button;
class SwRect;
class DataChangedEvent;
class CommandEvent;
class SvtAccessibilityOptions;
class SwPagePreviewLayout;

// Delete member <mnVirtPage> and its accessor
class SAL_DLLPUBLIC_RTTI SwPagePreviewWin : public vcl::Window
{
    SwViewShell* mpViewShell;
    sal_uInt16 mnSttPage;
    sal_uInt8 mnRow;
    sal_uInt8 mnCol;
    Size maPxWinSize;
    Fraction maScale;
    SwPagePreview& mrView;
    bool mbCalcScaleForPreviewLayout;
    tools::Rectangle maPaintedPreviewDocRect;
    SwPagePreviewLayout* mpPgPreviewLayout;

    void SetPagePreview( sal_uInt8 nRow, sal_uInt8 nCol );

    using Window::Scroll;

public:
    SwPagePreviewWin( vcl::Window* pParent, SwPagePreview& rView );
    virtual ~SwPagePreviewWin() override;

    // calls SwViewShell::Paint
    virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
    virtual void KeyInput( const KeyEvent & ) override;
    virtual void Command( const CommandEvent& rCEvt ) override;
    virtual void MouseButtonDown(const MouseEvent& rMEvt) override;
    virtual void DataChanged( const DataChangedEvent& ) override;

    void SetViewShell( SwViewShell* pShell );

    SwViewShell* GetViewShell() const
    {
        return mpViewShell;
    }

    sal_uInt8 GetRow() const
    {
        return mnRow;
    }

    sal_uInt8 GetCol() const
    {
        return mnCol;
    }

    sal_uInt16 GetSttPage() const
    {
        return mnSttPage;
    }

    void SetSttPage(sal_uInt16 n)
    {
        mnSttPage = n;
    }

    /** get selected page number of document preview

        @return selected page number
    */
    sal_uInt16 SelectedPage() const;

    /** set selected page number in document preview

        @param _nSelectedPageNum
        input parameter - physical page number of page that will be the selected one.
    */
    void SetSelectedPage( sal_uInt16 _nSelectedPageNum );

    // If we only have one column we do not have a oth page
    sal_uInt16 GetDefSttPage() const   { return 1 == mnCol ? 1 : 0; }

    void CalcWish( sal_uInt8 nNewRow, sal_uInt8 nNewCol );

    void SetWinSize( const Size& rNewSize );

    // Add <MV_SELPAGE>, <MV_SCROLL>
    enum MoveMode{ MV_CALC, MV_PAGE_UP, MV_PAGE_DOWN, MV_DOC_STT, MV_DOC_END,
                   MV_SELPAGE, MV_SCROLL, MV_NEWWINSIZE, MV_SPECIFIC_PAGE };
    bool MovePage( int eMoveMode );

    // Create the status bar's string
    OUString GetStatusStr( sal_uInt16 nPageCount ) const;

    void RepaintCoreRect( const SwRect& rRect );

    /** Method to adjust preview to a new zoom factor
        paint of preview is prepared for a new zoom factor
        Zoom type has also been considered.
        Thus, add new parameter <_eZoomType>
    */
    void AdjustPreviewToNewZoom( const sal_uInt16 _nZoomFactor,
                                 const SvxZoomType _eZoomType );

    const tools::Rectangle& GetPaintedPreviewDocRect() const
    {
        return maPaintedPreviewDocRect;
    }

    void Scroll(long nXMove, long nYMove, ScrollFlags nFlags = ScrollFlags::NONE) override;

    /** Method to enable/disable book preview
        @param _bBookPreview
        input parameter - boolean indicating, if book preview mode has to
        switch on <true> or of <false>

        @return boolean indicating, if book preview mode has changed.
    */
    bool SetBookPreviewMode( const bool _bBookPreview );

    virtual css::uno::Reference<css::accessibility::XAccessible> CreateAccessible() override;
};

/**
 * View of a document
 */
class SW_DLLPUBLIC SwPagePreview: public SfxViewShell
{
    // ViewWindow and handle to core
    // current dispatcher shell
    VclPtr<SwPagePreviewWin> m_pViewWin;
    //viewdata of the previous SwView and the new cursor position
    OUString m_sSwViewData;
    //and the new cursor position if the user double click in the PagePreview
    OUString m_sNewCursorPosition;
    // to support keyboard the number of the page to go to can be set too
    sal_uInt16 m_nNewPage;
    // visible range
    OUString const m_sPageStr;
    Size m_aDocSize;
    tools::Rectangle               m_aVisArea;

    // MDI control elements
    VclPtr<SwScrollbar> m_pHScrollbar;
    VclPtr<SwScrollbar> m_pVScrollbar;
    bool mbHScrollbarEnabled : 1;
    bool mbVScrollbarEnabled : 1;
    // dummy window for filling the lower right edge when both scrollbars are active
    VclPtr<vcl::Window> m_pScrollFill;

    sal_uInt16 mnPageCount;
    bool m_bNormalPrint;

    // New members to reset design mode at draw view for form shell on switching
    // back from writer page preview to normal view.
    bool mbResetFormDesignMode:1;
    bool mbFormDesignModeToReset:1;

    SAL_DLLPRIVATE void Init();
    SAL_DLLPRIVATE Point AlignToPixel(const Point& rPt) const;

    SAL_DLLPRIVATE void CreateScrollbar( bool bHori);
    DECL_DLLPRIVATE_LINK(ScrollHdl, ScrollBar*, void);
    DECL_DLLPRIVATE_LINK(EndScrollHdl, ScrollBar*, void);
    SAL_DLLPRIVATE bool ChgPage( int eMvMode, bool bUpdateScrollbar = true );

    SAL_DLLPRIVATE virtual SfxPrinter*     GetPrinter( bool bCreate = false ) override;
    SAL_DLLPRIVATE virtual sal_uInt16      SetPrinter( SfxPrinter *pNewPrinter, SfxPrinterChangeFlags nDiffFlags = SFX_PRINTER_ALL ) override;
    SAL_DLLPRIVATE virtual bool            HasPrintOptionsPage() const override;
    SAL_DLLPRIVATE virtual std::unique_ptr<SfxTabPage> CreatePrintOptionsPage(TabPageParent pParent, const SfxItemSet &rOptions) override;

    SAL_DLLPRIVATE void CalcAndSetBorderPixel( SvBorder &rToFill );

    /** Helper method to execute SfxRequest FN_PAGE_UP and FN_PAGE_DOWN

        @param _bPgUp
        input parameter - boolean that indicates, if FN_PAGE_UP or FN_PAGE_DOWN
        has to be executed.

        @param _pReq
        optional input parameter - pointer to the <SfxRequest> instance, if existing.
    */
    SAL_DLLPRIVATE void ExecPgUpAndPgDown( const bool  _bPgUp,
                             SfxRequest* _pReq );

protected:
    virtual void    InnerResizePixel( const Point &rOfs, const Size &rSize, bool inplaceEditModeChange ) override;
    virtual void    OuterResizePixel( const Point &rOfs, const Size &rSize ) override;

    void         SetZoom(SvxZoomType eSet, sal_uInt16 nFactor);

public:
    SFX_DECL_VIEWFACTORY(SwPagePreview);
    SFX_DECL_INTERFACE(SW_PAGEPREVIEW)

private:
    /// SfxInterface initializer.
    static void InitInterface_Impl();

public:
    SwViewShell* GetViewShell() const
    { return m_pViewWin->GetViewShell(); }
    void RepaintCoreRect( const SwRect& rRect )
    { m_pViewWin->RepaintCoreRect( rRect ); }

    void DocSzChgd(const Size& rNewSize);

    void SetVisArea( const tools::Rectangle& );

    void ScrollViewSzChg();
    void ScrollDocSzChg();
    void ShowHScrollbar(bool bShow);
    void ShowVScrollbar(bool bShow);
    void EnableHScrollbar(bool bEnable);
    void EnableVScrollbar(bool bEnable);

    sal_uInt16 GetPageCount() const        { return mnPageCount; }
    sal_uInt16 GetSelectedPage() const {return m_pViewWin->SelectedPage();}

    bool HandleWheelCommands( const CommandEvent& );

    const OUString& GetPrevSwViewData() const       { return m_sSwViewData; }
    void SetNewCursorPos( const OUString& rStr ) { m_sNewCursorPosition = rStr; }
    const OUString& GetNewCursorPos() const           { return m_sNewCursorPosition; }

    sal_uInt16 GetNewPage() const {return m_nNewPage;}

    // Handler
    void Execute(SfxRequest&);
    void GetState(SfxItemSet&);
    static void StateUndo(SfxItemSet&);

    SwDocShell* GetDocShell();

    // apply Accessibility options
    void ApplyAccessibilityOptions(SvtAccessibilityOptions const & rAccessibilityOptions);

    // Inline method to request values of new members
    // <mbResetFormDesignMode> and <mbFormDesignModeToReset>
    bool ResetFormDesignMode() const
    {
        return mbResetFormDesignMode;
    }

    bool FormDesignModeToReset() const
    {
        return mbFormDesignModeToReset;
    }

    /** Adjust position of vertical scrollbar

        Currently used, if the complete preview layout rows fit into to the given
        window, if a new page is selected and this page is visible.

        @param _nNewThumbPos
        input parameter - new position, which will be assigned to the vertical
        scrollbar.
    */
    void SetVScrollbarThumbPos( const sal_uInt16 _nNewThumbPos );

    SwPagePreview( SfxViewFrame* pFrame, SfxViewShell* );
    virtual ~SwPagePreview() override;
};


#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */