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 SAL_DLLPUBLIC_RTTI 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 tools::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() override; 66 67 // calls SwViewShell::Paint 68 virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override; 69 virtual void KeyInput( const KeyEvent & ) override; 70 virtual void Command( const CommandEvent& rCEvt ) override; 71 virtual void MouseButtonDown(const MouseEvent& rMEvt) override; 72 virtual void DataChanged( const DataChangedEvent& ) override; 73 74 void SetViewShell( SwViewShell* pShell ); 75 GetViewShell() const76 SwViewShell* GetViewShell() const 77 { 78 return mpViewShell; 79 } 80 GetRow() const81 sal_uInt8 GetRow() const 82 { 83 return mnRow; 84 } 85 GetCol() const86 sal_uInt8 GetCol() const 87 { 88 return mnCol; 89 } 90 GetSttPage() const91 sal_uInt16 GetSttPage() const 92 { 93 return mnSttPage; 94 } 95 SetSttPage(sal_uInt16 n)96 void SetSttPage(sal_uInt16 n) 97 { 98 mnSttPage = n; 99 } 100 101 /** get selected page number of document preview 102 103 @return selected page number 104 */ 105 sal_uInt16 SelectedPage() const; 106 107 /** set selected page number in document preview 108 109 @param _nSelectedPageNum 110 input parameter - physical page number of page that will be the selected one. 111 */ 112 void SetSelectedPage( sal_uInt16 _nSelectedPageNum ); 113 114 // If we only have one column we do not have a oth page GetDefSttPage() const115 sal_uInt16 GetDefSttPage() const { return 1 == mnCol ? 1 : 0; } 116 117 void CalcWish( sal_uInt8 nNewRow, sal_uInt8 nNewCol ); 118 119 void SetWinSize( const Size& rNewSize ); 120 121 // Add <MV_SELPAGE>, <MV_SCROLL> 122 enum MoveMode{ MV_CALC, MV_PAGE_UP, MV_PAGE_DOWN, MV_DOC_STT, MV_DOC_END, 123 MV_SELPAGE, MV_SCROLL, MV_NEWWINSIZE, MV_SPECIFIC_PAGE }; 124 bool MovePage( int eMoveMode ); 125 126 // Create the status bar's string 127 OUString GetStatusStr( sal_uInt16 nPageCount ) const; 128 129 void RepaintCoreRect( const SwRect& rRect ); 130 131 /** Method to adjust preview to a new zoom factor 132 paint of preview is prepared for a new zoom factor 133 Zoom type has also been considered. 134 Thus, add new parameter <_eZoomType> 135 */ 136 void AdjustPreviewToNewZoom( const sal_uInt16 _nZoomFactor, 137 const SvxZoomType _eZoomType ); 138 GetPaintedPreviewDocRect() const139 const tools::Rectangle& GetPaintedPreviewDocRect() const 140 { 141 return maPaintedPreviewDocRect; 142 } 143 144 void Scroll(long nXMove, long nYMove, ScrollFlags nFlags = ScrollFlags::NONE) override; 145 146 /** Method to enable/disable book preview 147 @param _bBookPreview 148 input parameter - boolean indicating, if book preview mode has to 149 switch on <true> or of <false> 150 151 @return boolean indicating, if book preview mode has changed. 152 */ 153 bool SetBookPreviewMode( const bool _bBookPreview ); 154 155 virtual css::uno::Reference<css::accessibility::XAccessible> CreateAccessible() override; 156 }; 157 158 /** 159 * View of a document 160 */ 161 class SW_DLLPUBLIC SwPagePreview: public SfxViewShell 162 { 163 // ViewWindow and handle to core 164 // current dispatcher shell 165 VclPtr<SwPagePreviewWin> m_pViewWin; 166 //viewdata of the previous SwView and the new cursor position 167 OUString m_sSwViewData; 168 //and the new cursor position if the user double click in the PagePreview 169 OUString m_sNewCursorPosition; 170 // to support keyboard the number of the page to go to can be set too 171 sal_uInt16 m_nNewPage; 172 // visible range 173 OUString const m_sPageStr; 174 Size m_aDocSize; 175 tools::Rectangle m_aVisArea; 176 177 // MDI control elements 178 VclPtr<SwScrollbar> m_pHScrollbar; 179 VclPtr<SwScrollbar> m_pVScrollbar; 180 bool mbHScrollbarEnabled : 1; 181 bool mbVScrollbarEnabled : 1; 182 // dummy window for filling the lower right edge when both scrollbars are active 183 VclPtr<vcl::Window> m_pScrollFill; 184 185 sal_uInt16 mnPageCount; 186 bool m_bNormalPrint; 187 188 // New members to reset design mode at draw view for form shell on switching 189 // back from writer page preview to normal view. 190 bool mbResetFormDesignMode:1; 191 bool mbFormDesignModeToReset:1; 192 193 SAL_DLLPRIVATE void Init(); 194 SAL_DLLPRIVATE Point AlignToPixel(const Point& rPt) const; 195 196 SAL_DLLPRIVATE void CreateScrollbar( bool bHori); 197 DECL_DLLPRIVATE_LINK(ScrollHdl, ScrollBar*, void); 198 DECL_DLLPRIVATE_LINK(EndScrollHdl, ScrollBar*, void); 199 SAL_DLLPRIVATE bool ChgPage( int eMvMode, bool bUpdateScrollbar = true ); 200 201 SAL_DLLPRIVATE virtual SfxPrinter* GetPrinter( bool bCreate = false ) override; 202 SAL_DLLPRIVATE virtual sal_uInt16 SetPrinter( SfxPrinter *pNewPrinter, SfxPrinterChangeFlags nDiffFlags = SFX_PRINTER_ALL ) override; 203 SAL_DLLPRIVATE virtual bool HasPrintOptionsPage() const override; 204 SAL_DLLPRIVATE virtual std::unique_ptr<SfxTabPage> CreatePrintOptionsPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet &rOptions) override; 205 206 SAL_DLLPRIVATE void CalcAndSetBorderPixel( SvBorder &rToFill ); 207 208 /** Helper method to execute SfxRequest FN_PAGE_UP and FN_PAGE_DOWN 209 210 @param _bPgUp 211 input parameter - boolean that indicates, if FN_PAGE_UP or FN_PAGE_DOWN 212 has to be executed. 213 214 @param _pReq 215 optional input parameter - pointer to the <SfxRequest> instance, if existing. 216 */ 217 SAL_DLLPRIVATE void ExecPgUpAndPgDown( const bool _bPgUp, 218 SfxRequest* _pReq ); 219 220 protected: 221 virtual void InnerResizePixel( const Point &rOfs, const Size &rSize, bool inplaceEditModeChange ) override; 222 virtual void OuterResizePixel( const Point &rOfs, const Size &rSize ) override; 223 224 void SetZoom(SvxZoomType eSet, sal_uInt16 nFactor); 225 226 public: 227 SFX_DECL_VIEWFACTORY(SwPagePreview); 228 SFX_DECL_INTERFACE(SW_PAGEPREVIEW) 229 230 private: 231 /// SfxInterface initializer. 232 static void InitInterface_Impl(); 233 234 public: GetViewShell() const235 SwViewShell* GetViewShell() const 236 { return m_pViewWin->GetViewShell(); } RepaintCoreRect(const SwRect & rRect)237 void RepaintCoreRect( const SwRect& rRect ) 238 { m_pViewWin->RepaintCoreRect( rRect ); } 239 240 void DocSzChgd(const Size& rNewSize); 241 242 void SetVisArea( const tools::Rectangle& ); 243 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); 250 GetPageCount() const251 sal_uInt16 GetPageCount() const { return mnPageCount; } GetSelectedPage() const252 sal_uInt16 GetSelectedPage() const {return m_pViewWin->SelectedPage();} 253 254 bool HandleWheelCommands( const CommandEvent& ); 255 GetPrevSwViewData() const256 const OUString& GetPrevSwViewData() const { return m_sSwViewData; } SetNewCursorPos(const OUString & rStr)257 void SetNewCursorPos( const OUString& rStr ) { m_sNewCursorPosition = rStr; } GetNewCursorPos() const258 const OUString& GetNewCursorPos() const { return m_sNewCursorPosition; } 259 GetNewPage() const260 sal_uInt16 GetNewPage() const {return m_nNewPage;} 261 262 // Handler 263 void Execute(SfxRequest&); 264 void GetState(SfxItemSet&); 265 static void StateUndo(SfxItemSet&); 266 267 SwDocShell* GetDocShell(); 268 269 // apply Accessibility options 270 void ApplyAccessibilityOptions(SvtAccessibilityOptions const & rAccessibilityOptions); 271 272 // Inline method to request values of new members 273 // <mbResetFormDesignMode> and <mbFormDesignModeToReset> ResetFormDesignMode() const274 bool ResetFormDesignMode() const 275 { 276 return mbResetFormDesignMode; 277 } 278 FormDesignModeToReset() const279 bool FormDesignModeToReset() const 280 { 281 return mbFormDesignModeToReset; 282 } 283 284 /** Adjust position of vertical scrollbar 285 286 Currently used, if the complete preview layout rows fit into to the given 287 window, if a new page is selected and this page is visible. 288 289 @param _nNewThumbPos 290 input parameter - new position, which will be assigned to the vertical 291 scrollbar. 292 */ 293 void SetVScrollbarThumbPos( const sal_uInt16 _nNewThumbPos ); 294 295 SwPagePreview( SfxViewFrame* pFrame, SfxViewShell* ); 296 virtual ~SwPagePreview() override; 297 }; 298 299 300 #endif 301 302 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 303