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 .
20 #include <config_wasm_strip.h>
22 #include <sfx2/objface.hxx>
23 #include <vcl/help.hxx>
24 #include <vcl/commandevent.hxx>
25 #include <vcl/settings.hxx>
26 #include <vcl/svapp.hxx>
27 #include <vcl/syswin.hxx>
28 #include <vcl/weld.hxx>
30 #include <svl/whiter.hxx>
31 #include <svl/slstitm.hxx>
32 #include <svl/eitem.hxx>
33 #include <sfx2/printer.hxx>
34 #include <sfx2/bindings.hxx>
35 #include <sfx2/request.hxx>
36 #include <sfx2/dispatch.hxx>
37 #include <editeng/paperinf.hxx>
38 #include <svx/svdview.hxx>
39 #include <svx/viewlayoutitem.hxx>
40 #include <svx/zoomslideritem.hxx>
41 #include <tools/svborder.hxx>
42 #include <osl/diagnose.h>
44 #include <globdoc.hxx>
46 #include <pvprtdat.hxx>
47 #include <swmodule.hxx>
50 #include <viewopt.hxx>
52 #include <IDocumentDeviceAccess.hxx>
57 #include <usrpref.hxx>
58 #include "viewfunc.hxx"
62 #include <strings.hrc>
64 #define ShellClass_SwPagePreview
65 #include <sfx2/msg.hxx>
66 #include <swslots.hxx>
67 #include <pagepreviewlayout.hxx>
69 #include <svx/svxdlg.hxx>
72 #include <vcl/EnumContext.hxx>
73 #include <vcl/notebookbar/notebookbar.hxx>
75 using namespace ::com::sun::star
;
76 SFX_IMPL_NAMED_VIEWFACTORY(SwPagePreview
, "PrintPreview")
78 SFX_VIEW_REGISTRATION(SwDocShell
);
79 SFX_VIEW_REGISTRATION(SwWebDocShell
);
80 SFX_VIEW_REGISTRATION(SwGlobalDocShell
);
83 SFX_IMPL_INTERFACE(SwPagePreview
, SfxViewShell
)
85 void SwPagePreview::InitInterface_Impl()
87 GetStaticInterface()->RegisterPopupMenu("preview");
88 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT
,
89 SfxVisibilityFlags::Standard
|SfxVisibilityFlags::Client
|SfxVisibilityFlags::FullScreen
|SfxVisibilityFlags::ReadonlyDoc
,
90 ToolbarId::PView_Toolbox
);
94 #define SWVIEWFLAGS SfxViewShellFlags::HAS_PRINTOPTIONS
96 #define MIN_PREVIEW_ZOOM 25
97 #define MAX_PREVIEW_ZOOM 600
99 static sal_uInt16
lcl_GetNextZoomStep(sal_uInt16 nCurrentZoom
, bool bZoomIn
)
101 static const sal_uInt16 aZoomArr
[] =
103 25, 50, 75, 100, 150, 200, 400, 600
105 const int nZoomArrSize
= static_cast<int>(SAL_N_ELEMENTS(aZoomArr
));
108 for(sal_uInt16 i
: aZoomArr
)
116 for(int i
= nZoomArrSize
- 1; i
>= 0; --i
)
118 if(nCurrentZoom
> aZoomArr
[i
] || !i
)
122 return bZoomIn
? MAX_PREVIEW_ZOOM
: MIN_PREVIEW_ZOOM
;
125 static void lcl_InvalidateZoomSlots(SfxBindings
& rBindings
)
127 static sal_uInt16
const aInval
[] =
129 SID_ATTR_ZOOM
, SID_ZOOM_OUT
, SID_ZOOM_IN
, SID_ATTR_ZOOMSLIDER
, FN_PREVIEW_ZOOM
, FN_STAT_ZOOM
,
132 rBindings
.Invalidate( aInval
);
137 // At first the zoom dialog
138 class SwPreviewZoomDlg
: public weld::GenericDialogController
140 SwPagePreviewWin
& m_rParent
;
141 std::unique_ptr
<weld::SpinButton
> m_xRowEdit
;
142 std::unique_ptr
<weld::SpinButton
> m_xColEdit
;
145 SwPreviewZoomDlg(SwPagePreviewWin
& rParent
)
146 : GenericDialogController(rParent
.GetFrameWeld(), "modules/swriter/ui/previewzoomdialog.ui", "PreviewZoomDialog")
148 , m_xRowEdit(m_xBuilder
->weld_spin_button("rows"))
149 , m_xColEdit(m_xBuilder
->weld_spin_button("cols"))
151 m_xRowEdit
->set_value(rParent
.GetRow());
152 m_xColEdit
->set_value(rParent
.GetCol());
159 m_rParent
.CalcWish(m_xRowEdit
->get_value(), m_xColEdit
->get_value());
166 // all for SwPagePreviewWin
167 SwPagePreviewWin::SwPagePreviewWin( vcl::Window
*pParent
, SwPagePreview
& rPView
)
168 : Window(pParent
, WinBits(WB_CLIPCHILDREN
))
169 , mpViewShell(nullptr)
171 , mbCalcScaleForPreviewLayout(true)
172 , maPaintedPreviewDocRect(tools::Rectangle(0,0,0,0))
173 , mpPgPreviewLayout(nullptr)
175 GetOutDev()->SetOutDevViewType( OutDevViewType::PrintPreview
);
176 SetHelpId(HID_PAGEPREVIEW
);
177 GetOutDev()->SetFillColor( GetBackground().GetColor() );
178 GetOutDev()->SetLineColor( GetBackground().GetColor());
179 SetMapMode( MapMode(MapUnit::MapTwip
) );
181 const SwMasterUsrPref
*pUsrPref
= SW_MOD()->GetUsrPref(false);
182 mnRow
= pUsrPref
->GetPagePrevRow(); // 1 row
183 mnCol
= pUsrPref
->GetPagePrevCol(); // 1 column
184 mnSttPage
= USHRT_MAX
;
187 SwPagePreviewWin::~SwPagePreviewWin()
191 void SwPagePreviewWin::Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
)
193 if (!mpViewShell
|| !mpViewShell
->GetLayout())
196 if (USHRT_MAX
== mnSttPage
) // was never calculated ? (Init-Phase!)
198 // This is the size to which I always relate.
199 if (!maPxWinSize
.Height() || !maPxWinSize
.Width())
200 maPxWinSize
= GetOutputSizePixel();
202 tools::Rectangle
aRect(rRenderContext
.LogicToPixel(rRect
));
203 mpPgPreviewLayout
->Prepare(1, Point(0,0), maPxWinSize
,
204 mnSttPage
, maPaintedPreviewDocRect
);
206 mpPgPreviewLayout
->Paint(rRenderContext
, rRenderContext
.PixelToLogic(aRect
));
207 SetPagePreview(mnRow
, mnCol
);
211 MapMode
aMM(rRenderContext
.GetMapMode());
212 aMM
.SetScaleX(maScale
);
213 aMM
.SetScaleY(maScale
);
214 rRenderContext
.SetMapMode(aMM
);
215 mpPgPreviewLayout
->GetParentViewShell().setOutputToWindow(true);
216 mpPgPreviewLayout
->Paint(rRenderContext
, rRect
);
217 mpPgPreviewLayout
->GetParentViewShell().setOutputToWindow(false);
221 void SwPagePreviewWin::CalcWish( sal_Int16 nNewRow
, sal_Int16 nNewCol
)
223 if( !mpViewShell
|| !mpViewShell
->GetLayout() )
226 const sal_Int16 nOldCol
= mnCol
;
229 const sal_uInt16 nPages
= mnRow
* mnCol
;
230 const sal_uInt16 nLastSttPg
= mrView
.GetPageCount()+1 > nPages
231 ? mrView
.GetPageCount()+1 - nPages
: 0;
232 if( mnSttPage
> nLastSttPg
)
233 mnSttPage
= nLastSttPg
;
235 mpPgPreviewLayout
->Init( mnCol
, mnRow
, maPxWinSize
);
236 mpPgPreviewLayout
->Prepare( mnSttPage
, Point(0,0), maPxWinSize
,
237 mnSttPage
, maPaintedPreviewDocRect
);
238 SetSelectedPage( mnSttPage
);
239 SetPagePreview(mnRow
, mnCol
);
240 maScale
= GetMapMode().GetScaleX();
242 // If changes have taken place at the columns, the special case "single column"
243 // must be considered and corrected if necessary.
244 if( (1 == nOldCol
) != (1 == mnCol
) )
245 mrView
.ScrollDocSzChg();
247 // Order must be maintained!
248 // additional invalidate page status.
249 static sal_uInt16 aInval
[] =
251 SID_ATTR_ZOOM
, SID_ZOOM_OUT
, SID_ZOOM_IN
,
253 FN_START_OF_DOCUMENT
, FN_END_OF_DOCUMENT
, FN_PAGEUP
, FN_PAGEDOWN
,
254 FN_STAT_PAGE
, FN_STAT_ZOOM
,
255 FN_SHOW_TWO_PAGES
, FN_SHOW_MULTIPLE_PAGES
,
258 SfxBindings
& rBindings
= mrView
.GetViewFrame().GetBindings();
259 rBindings
.Invalidate( aInval
);
260 rBindings
.Update( FN_SHOW_TWO_PAGES
);
261 rBindings
.Update( FN_SHOW_MULTIPLE_PAGES
);
263 mrView
.ScrollViewSzChg();
266 // mnSttPage is Absolute
267 bool SwPagePreviewWin::MovePage( int eMoveMode
)
269 // number of pages up
270 const sal_uInt16 nPages
= mnRow
* mnCol
;
271 sal_uInt16 nNewSttPage
= mnSttPage
;
272 const sal_uInt16 nPageCount
= mrView
.GetPageCount();
273 const sal_uInt16 nDefSttPg
= GetDefSttPage();
274 bool bPaintPageAtFirstCol
= true;
280 const sal_uInt16 nRelSttPage
= mpPgPreviewLayout
->ConvertAbsoluteToRelativePageNum( mnSttPage
);
281 const sal_uInt16 nNewAbsSttPage
= nRelSttPage
- nPages
> 0 ?
282 mpPgPreviewLayout
->ConvertRelativeToAbsolutePageNum( nRelSttPage
- nPages
) :
284 nNewSttPage
= nNewAbsSttPage
;
286 const sal_uInt16 nRelSelPage
= mpPgPreviewLayout
->ConvertAbsoluteToRelativePageNum( SelectedPage() );
287 const sal_uInt16 nNewRelSelPage
= nRelSelPage
- nPages
> 0 ?
288 nRelSelPage
- nPages
:
290 SetSelectedPage( mpPgPreviewLayout
->ConvertRelativeToAbsolutePageNum( nNewRelSelPage
) );
296 const sal_uInt16 nRelSttPage
= mpPgPreviewLayout
->ConvertAbsoluteToRelativePageNum( mnSttPage
);
297 const sal_uInt16 nNewAbsSttPage
= mpPgPreviewLayout
->ConvertRelativeToAbsolutePageNum( nRelSttPage
+ nPages
);
298 nNewSttPage
= std::min(nNewAbsSttPage
, nPageCount
);
300 const sal_uInt16 nRelSelPage
= mpPgPreviewLayout
->ConvertAbsoluteToRelativePageNum( SelectedPage() );
301 const sal_uInt16 nNewAbsSelPage
= mpPgPreviewLayout
->ConvertRelativeToAbsolutePageNum( nRelSelPage
+ nPages
);
302 SetSelectedPage( std::min(nNewAbsSelPage
, nPageCount
) );
307 nNewSttPage
= nDefSttPg
;
308 SetSelectedPage( mpPgPreviewLayout
->ConvertRelativeToAbsolutePageNum( nNewSttPage
? nNewSttPage
: 1 ) );
311 // correct calculation of new start page.
312 nNewSttPage
= nPageCount
;
313 SetSelectedPage( nPageCount
);
317 // <nNewSttPage> and <SelectedPage()> are already set.
318 // not start at first column, only if the
319 // complete preview layout columns doesn't fit into window.
320 if ( !mpPgPreviewLayout
->DoesPreviewLayoutColsFitIntoWindow() )
321 bPaintPageAtFirstCol
= false;
324 // check, if paint page at first column
326 if ( !mpPgPreviewLayout
->DoesPreviewLayoutRowsFitIntoWindow() ||
327 !mpPgPreviewLayout
->DoesPreviewLayoutColsFitIntoWindow() )
328 bPaintPageAtFirstCol
= false;
331 // nothing special to do.
334 // re-init page preview layout.
335 mpPgPreviewLayout
->ReInit();
337 // correct calculation of new start page.
338 if( nNewSttPage
> nPageCount
)
339 nNewSttPage
= nPageCount
;
341 // correct selected page number
342 if( SelectedPage() > nPageCount
)
343 SetSelectedPage( nNewSttPage
? nNewSttPage
: 1 );
346 mpPgPreviewLayout
->Prepare( nNewSttPage
, Point(0,0), maPxWinSize
,
348 maPaintedPreviewDocRect
, bPaintPageAtFirstCol
);
349 if( nNewSttPage
== mnSttPage
&&
350 eMoveMode
!= MV_SELPAGE
)
353 SetPagePreview(mnRow
, mnCol
);
354 mnSttPage
= nNewSttPage
;
356 // additional invalidate page status.
357 static sal_uInt16 aInval
[] =
359 FN_START_OF_DOCUMENT
, FN_END_OF_DOCUMENT
, FN_PAGEUP
, FN_PAGEDOWN
,
363 SfxBindings
& rBindings
= mrView
.GetViewFrame().GetBindings();
364 rBindings
.Invalidate( aInval
);
369 void SwPagePreviewWin::SetWinSize( const Size
& rNewSize
)
371 // We always want the size as pixel units.
372 maPxWinSize
= LogicToPixel( rNewSize
);
374 if( USHRT_MAX
== mnSttPage
)
376 mnSttPage
= GetDefSttPage();
377 SetSelectedPage( GetDefSttPage() );
380 if ( mbCalcScaleForPreviewLayout
)
382 mpPgPreviewLayout
->Init( mnCol
, mnRow
, maPxWinSize
);
383 maScale
= GetMapMode().GetScaleX();
385 mpPgPreviewLayout
->Prepare( mnSttPage
, Point(0,0), maPxWinSize
,
386 mnSttPage
, maPaintedPreviewDocRect
);
387 if ( mbCalcScaleForPreviewLayout
)
389 SetSelectedPage( mnSttPage
);
390 mbCalcScaleForPreviewLayout
= false;
392 SetPagePreview(mnRow
, mnCol
);
393 maScale
= GetMapMode().GetScaleX();
396 OUString
SwPagePreviewWin::GetStatusStr( sal_uInt16 nPageCnt
) const
398 // show physical and virtual page number of
399 // selected page, if it's visible.
400 const sal_uInt16 nPageNum
= mpPgPreviewLayout
->IsPageVisible( mpPgPreviewLayout
->SelectedPage() )
401 ? mpPgPreviewLayout
->SelectedPage() : std::max
<sal_uInt16
>(mnSttPage
, 1);
404 const sal_uInt16 nVirtPageNum
= mpPgPreviewLayout
->GetVirtPageNumByPageNum( nPageNum
);
405 if( nVirtPageNum
&& nVirtPageNum
!= nPageNum
)
407 aStatusStr
= OUString::number(nVirtPageNum
) + " " ;
409 return aStatusStr
+ OUString::number(nPageNum
) + " / " + OUString::number(nPageCnt
);
412 void SwPagePreviewWin::KeyInput( const KeyEvent
&rKEvt
)
414 const vcl::KeyCode
& rKeyCode
= rKEvt
.GetKeyCode();
415 bool bHandled
= false;
416 if(!rKeyCode
.GetModifier())
418 sal_uInt16 nSlot
= 0;
419 switch(rKeyCode
.GetCode())
421 case KEY_ADD
: nSlot
= SID_ZOOM_IN
; break;
422 case KEY_ESCAPE
: nSlot
= FN_CLOSE_PAGEPREVIEW
; break;
423 case KEY_SUBTRACT
: nSlot
= SID_ZOOM_OUT
; break;
428 mrView
.GetViewFrame().GetDispatcher()->Execute(
429 nSlot
, SfxCallMode::ASYNCHRON
);
432 if( !bHandled
&& !mrView
.KeyInput( rKEvt
) )
433 Window::KeyInput( rKEvt
);
436 void SwPagePreviewWin::Command( const CommandEvent
& rCEvt
)
438 bool bCallBase
= true;
439 switch( rCEvt
.GetCommand() )
441 case CommandEventId::ContextMenu
:
442 SfxDispatcher::ExecutePopup();
446 case CommandEventId::Wheel
:
447 case CommandEventId::StartAutoScroll
:
448 case CommandEventId::AutoScroll
:
450 const CommandWheelData
* pData
= rCEvt
.GetWheelData();
453 const CommandWheelData
aDataNew(pData
->GetDelta(),pData
->GetNotchDelta(),COMMAND_WHEEL_PAGESCROLL
,
454 pData
->GetMode(),pData
->GetModifier(),pData
->IsHorz(), pData
->IsDeltaPixel());
455 const CommandEvent
aEvent( rCEvt
.GetMousePosPixel(),rCEvt
.GetCommand(),rCEvt
.IsMouseEvent(),&aDataNew
);
456 bCallBase
= !mrView
.HandleWheelCommands( aEvent
);
459 bCallBase
= !mrView
.HandleWheelCommands( rCEvt
);
467 Window::Command( rCEvt
);
470 void SwPagePreviewWin::MouseButtonDown( const MouseEvent
& rMEvt
)
472 // consider single-click to set selected page
473 if( MOUSE_LEFT
!= ( rMEvt
.GetModifier() + rMEvt
.GetButtons() ) )
476 Point
aPreviewPos( PixelToLogic( rMEvt
.GetPosPixel() ) );
478 bool bPosInEmptyPage
;
479 sal_uInt16 nNewSelectedPage
;
481 mpPgPreviewLayout
->IsPreviewPosInDocPreviewPage( aPreviewPos
,
482 aDocPos
, bPosInEmptyPage
, nNewSelectedPage
);
483 if ( bIsDocPos
&& rMEvt
.GetClicks() == 2 )
485 // close page preview, set new cursor position and switch to
487 OUString sNewCursorPos
= OUString::number( aDocPos
.X() ) + ";" +
488 OUString::number( aDocPos
.Y() ) + ";";
489 mrView
.SetNewCursorPos( sNewCursorPos
);
491 SfxViewFrame
& rTmpFrame
= mrView
.GetViewFrame();
492 rTmpFrame
.GetBindings().Execute( SID_VIEWSHELL0
, nullptr,
493 SfxCallMode::ASYNCHRON
);
495 else if ( bIsDocPos
|| bPosInEmptyPage
)
497 // show clicked page as the selected one
498 mpPgPreviewLayout
->MarkNewSelectedPage( nNewSelectedPage
);
499 GetViewShell()->ShowPreviewSelection( nNewSelectedPage
);
500 // adjust position at vertical scrollbar.
501 if ( mpPgPreviewLayout
->DoesPreviewLayoutRowsFitIntoWindow() )
503 mrView
.SetVScrollbarThumbPos( nNewSelectedPage
);
505 // invalidate page status.
506 static sal_uInt16 aInval
[] =
510 SfxBindings
& rBindings
= mrView
.GetViewFrame().GetBindings();
511 rBindings
.Invalidate( aInval
);
515 // Set user prefs or view options
517 void SwPagePreviewWin::SetPagePreview( sal_Int16 nRow
, sal_Int16 nCol
)
519 SwMasterUsrPref
*pOpt
= const_cast<SwMasterUsrPref
*>(SW_MOD()->GetUsrPref(false));
521 if (nRow
!= pOpt
->GetPagePrevRow() || nCol
!= pOpt
->GetPagePrevCol())
523 pOpt
->SetPagePrevRow( nRow
);
524 pOpt
->SetPagePrevCol( nCol
);
528 mrView
.ScrollViewSzChg();
532 /** get selected page in document preview */
533 sal_uInt16
SwPagePreviewWin::SelectedPage() const
535 return mpPgPreviewLayout
->SelectedPage();
538 /** set selected page number in document preview */
539 void SwPagePreviewWin::SetSelectedPage( sal_uInt16 _nSelectedPageNum
)
541 mpPgPreviewLayout
->SetSelectedPage( _nSelectedPageNum
);
544 /** method to enable/disable book preview */
545 bool SwPagePreviewWin::SetBookPreviewMode( const bool _bBookPreview
)
547 return mpPgPreviewLayout
->SetBookPreviewMode( _bBookPreview
,
549 maPaintedPreviewDocRect
);
552 void SwPagePreviewWin::DataChanged( const DataChangedEvent
& rDCEvt
)
554 Window::DataChanged( rDCEvt
);
556 switch( rDCEvt
.GetType() )
558 case DataChangedEventType::SETTINGS
:
559 // Rearrange the scrollbars or trigger resize, because the
560 // size of the scrollbars may have be changed. Also the
561 // size of the scrollbars has to be retrieved from the settings
562 // out of the resize handler.
563 if( rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
)
564 mrView
.InvalidateBorder(); // Scrollbar widths
565 // zoom has to be disabled if Accessibility support is switched on
566 lcl_InvalidateZoomSlots(mrView
.GetViewFrame().GetBindings());
569 case DataChangedEventType::PRINTER
:
570 case DataChangedEventType::DISPLAY
:
571 case DataChangedEventType::FONTS
:
572 case DataChangedEventType::FONTSUBSTITUTION
:
573 mrView
.GetDocShell()->UpdateFontList(); // Font change
574 mpViewShell
->InvalidateLayout(true);
575 if ( mpViewShell
->GetWin() )
576 mpViewShell
->GetWin()->Invalidate();
582 /** help method to execute SfxRequest FN_PAGEUP and FN_PAGEDOWN */
583 void SwPagePreview::ExecPgUpAndPgDown( const bool _bPgUp
,
586 SwPagePreviewLayout
* pPagePreviewLay
= GetViewShell()->PagePreviewLayout();
587 // check, if top/bottom of preview is *not* already visible.
588 if( pPagePreviewLay
->GetWinPagesScrollAmount( _bPgUp
? -1 : 1 ) != 0 )
590 if ( pPagePreviewLay
->DoesPreviewLayoutRowsFitIntoWindow() &&
591 pPagePreviewLay
->DoesPreviewLayoutColsFitIntoWindow() )
593 const int eMvMode
= _bPgUp
?
594 SwPagePreviewWin::MV_PAGE_UP
:
595 SwPagePreviewWin::MV_PAGE_DOWN
;
596 if ( ChgPage( eMvMode
) )
597 m_pViewWin
->Invalidate();
601 SwTwips nScrollAmount
;
602 sal_uInt16 nNewSelectedPageNum
= 0;
603 const sal_uInt16 nVisPages
= m_pViewWin
->GetRow() * m_pViewWin
->GetCol();
606 if ( pPagePreviewLay
->DoesPreviewLayoutRowsFitIntoWindow() )
608 nScrollAmount
= pPagePreviewLay
->GetWinPagesScrollAmount( -1 );
609 if ( (m_pViewWin
->SelectedPage() - nVisPages
) > 0 )
610 nNewSelectedPageNum
= m_pViewWin
->SelectedPage() - nVisPages
;
612 nNewSelectedPageNum
= 1;
615 nScrollAmount
= - std::min( m_pViewWin
->GetOutDev()->GetOutputSize().Height(),
616 m_pViewWin
->GetPaintedPreviewDocRect().Top() );
620 if ( pPagePreviewLay
->DoesPreviewLayoutRowsFitIntoWindow() )
622 nScrollAmount
= pPagePreviewLay
->GetWinPagesScrollAmount( 1 );
623 if ( (m_pViewWin
->SelectedPage() + nVisPages
) <= mnPageCount
)
624 nNewSelectedPageNum
= m_pViewWin
->SelectedPage() + nVisPages
;
626 nNewSelectedPageNum
= mnPageCount
;
629 nScrollAmount
= std::min( m_pViewWin
->GetOutDev()->GetOutputSize().Height(),
630 ( pPagePreviewLay
->GetPreviewDocSize().Height() -
631 m_pViewWin
->GetPaintedPreviewDocRect().Bottom() ) );
633 m_pViewWin
->Scroll( 0, nScrollAmount
);
634 if ( nNewSelectedPageNum
!= 0 )
636 m_pViewWin
->SetSelectedPage( nNewSelectedPageNum
);
639 // additional invalidate page status.
640 static sal_uInt16 aInval
[] =
642 FN_START_OF_DOCUMENT
, FN_END_OF_DOCUMENT
, FN_PAGEUP
, FN_PAGEDOWN
,
645 SfxBindings
& rBindings
= GetViewFrame().GetBindings();
646 rBindings
.Invalidate( aInval
);
647 m_pViewWin
->Invalidate();
655 // Then all for the SwPagePreview
656 void SwPagePreview::Execute( SfxRequest
&rReq
)
658 int eMvMode
= SwPagePreviewWin::MV_DOC_END
;
660 bool bRefresh
= true;
662 switch(rReq
.GetSlot())
664 case SID_REFRESH_VIEW
:
669 case FN_SHOW_MULTIPLE_PAGES
:
671 const SfxItemSet
*pArgs
= rReq
.GetArgs();
672 if( pArgs
&& pArgs
->Count() >= 2 )
674 sal_Int16 nCols
= pArgs
->Get(SID_ATTR_TABLE_COLUMN
).GetValue();
675 sal_Int16 nRows
= pArgs
->Get(SID_ATTR_TABLE_ROW
).GetValue();
676 m_pViewWin
->CalcWish( nRows
, nCols
);
681 SwPreviewZoomDlg
aDlg(*m_pViewWin
);
686 case FN_SHOW_BOOKVIEW
:
688 const SfxItemSet
* pArgs
= rReq
.GetArgs();
689 const SfxPoolItem
* pItem
;
690 bool bBookPreview
= GetViewShell()->GetViewOptions()->IsPagePrevBookview();
691 if( pArgs
&& SfxItemState::SET
== pArgs
->GetItemState( FN_SHOW_BOOKVIEW
, false, &pItem
) )
693 bBookPreview
= static_cast< const SfxBoolItem
* >( pItem
)->GetValue();
694 const_cast<SwViewOption
*>(GetViewShell()->GetViewOptions())->SetPagePrevBookview( bBookPreview
);
695 // cast is not gentleman like, but it's common use in writer and in this case
697 if ( m_pViewWin
->SetBookPreviewMode( bBookPreview
) )
699 // book preview mode changed. Thus, adjust scrollbars and
700 // invalidate corresponding states.
702 static sal_uInt16 aInval
[] =
704 FN_START_OF_DOCUMENT
, FN_END_OF_DOCUMENT
, FN_PAGEUP
, FN_PAGEDOWN
,
705 FN_STAT_PAGE
, FN_SHOW_BOOKVIEW
, 0
707 SfxBindings
& rBindings
= GetViewFrame().GetBindings();
708 rBindings
.Invalidate( aInval
);
709 m_pViewWin
->Invalidate();
714 case FN_SHOW_TWO_PAGES
:
715 m_pViewWin
->CalcWish( nRow
, 2 );
718 case FN_SHOW_SINGLE_PAGE
:
719 m_pViewWin
->CalcWish( nRow
, 1 );
722 case FN_PREVIEW_ZOOM
:
725 const SfxItemSet
*pArgs
= rReq
.GetArgs();
726 ScopedVclPtr
<AbstractSvxZoomDialog
> pDlg
;
729 SfxItemSetFixed
<SID_ATTR_ZOOM
, SID_ATTR_ZOOM
> aCoreSet(GetPool());
730 const SwViewOption
* pVOpt
= GetViewShell()->GetViewOptions();
731 SvxZoomItem
aZoom( pVOpt
->GetZoomType(), pVOpt
->GetZoom() );
733 SvxZoomEnableFlags::N50
|
734 SvxZoomEnableFlags::N75
|
735 SvxZoomEnableFlags::N100
|
736 SvxZoomEnableFlags::N150
|
737 SvxZoomEnableFlags::N200
|
738 SvxZoomEnableFlags::WHOLEPAGE
);
739 aCoreSet
.Put( aZoom
);
741 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
742 pDlg
.disposeAndReset(pFact
->CreateSvxZoomDialog(GetViewFrame().GetFrameWeld(), aCoreSet
));
743 pDlg
->SetLimits( MINZOOM
, MAXZOOM
);
745 if( pDlg
->Execute() != RET_CANCEL
)
746 pArgs
= pDlg
->GetOutputItemSet();
750 SvxZoomType eType
= SvxZoomType::PERCENT
;
751 sal_uInt16 nZoomFactor
= USHRT_MAX
;
752 if(const SvxZoomItem
* pZoomItem
= pArgs
->GetItemIfSet(SID_ATTR_ZOOM
))
754 eType
= pZoomItem
->GetType();
755 nZoomFactor
= pZoomItem
->GetValue();
757 else if(const SfxUInt16Item
* pPreviewItem
= pArgs
->GetItemIfSet(FN_PREVIEW_ZOOM
))
758 nZoomFactor
= pPreviewItem
->GetValue();
759 if(USHRT_MAX
!= nZoomFactor
)
760 SetZoom(eType
, nZoomFactor
);
764 case SID_ATTR_ZOOMSLIDER
:
766 const SfxItemSet
*pArgs
= rReq
.GetArgs();
767 const SvxZoomSliderItem
* pItem
;
769 if ( pArgs
&& (pItem
= pArgs
->GetItemIfSet(SID_ATTR_ZOOMSLIDER
) ) )
771 const sal_uInt16 nCurrentZoom
= pItem
->GetValue();
772 SetZoom( SvxZoomType::PERCENT
, nCurrentZoom
);
779 const SwViewOption
* pVOpt
= GetViewShell()->GetViewOptions();
780 SetZoom(SvxZoomType::PERCENT
,
781 lcl_GetNextZoomStep(pVOpt
->GetZoom(), SID_ZOOM_IN
== rReq
.GetSlot()));
789 SwPagePreviewLayout
* pPagePreviewLay
= GetViewShell()->PagePreviewLayout();
790 sal_uInt16 nNewSelectedPage
;
791 sal_uInt16 nNewStartPage
;
793 sal_Int16 nHoriMove
= 0;
794 sal_Int16 nVertMove
= 0;
795 switch(rReq
.GetSlot())
797 case FN_CHAR_LEFT
: nHoriMove
= -1; break;
798 case FN_CHAR_RIGHT
: nHoriMove
= 1; break;
799 case FN_LINE_UP
: nVertMove
= -1; break;
800 case FN_LINE_DOWN
: nVertMove
= 1; break;
802 pPagePreviewLay
->CalcStartValuesForSelectedPageMove( nHoriMove
, nVertMove
,
803 nNewSelectedPage
, nNewStartPage
, aNewStartPos
);
804 if ( m_pViewWin
->SelectedPage() != nNewSelectedPage
)
806 if ( pPagePreviewLay
->IsPageVisible( nNewSelectedPage
) )
808 pPagePreviewLay
->MarkNewSelectedPage( nNewSelectedPage
);
809 // adjust position at vertical scrollbar.
810 SetVScrollbarThumbPos( nNewSelectedPage
);
815 m_pViewWin
->SetSelectedPage( nNewSelectedPage
);
816 m_pViewWin
->SetSttPage( nNewStartPage
);
817 bRefresh
= ChgPage( SwPagePreviewWin::MV_SELPAGE
);
819 GetViewShell()->ShowPreviewSelection( nNewSelectedPage
);
820 // invalidate page status.
821 static sal_uInt16 aInval
[] =
825 SfxBindings
& rBindings
= GetViewFrame().GetBindings();
826 rBindings
.Invalidate( aInval
);
838 ExecPgUpAndPgDown( rReq
.GetSlot() == FN_PAGEUP
, &rReq
);
841 case SID_JUMP_TO_SPECIFIC_PAGE
:
843 const SfxItemSet
*pArgs
= rReq
.GetArgs();
844 if( pArgs
&& pArgs
->Count())
846 sal_uInt16 nPageNum
= static_cast<const SfxUInt16Item
&>(pArgs
->Get(SID_JUMP_TO_SPECIFIC_PAGE
)).GetValue();
848 if( nPageNum
> 0 && nPageNum
<= mnPageCount
)
850 m_pViewWin
->SetSttPage( nPageNum
);
851 m_pViewWin
->SetSelectedPage( nPageNum
);
852 ChgPage( SwPagePreviewWin::MV_SPECIFIC_PAGE
, false );
858 case FN_START_OF_LINE
:
859 case FN_START_OF_DOCUMENT
:
860 eMvMode
= SwPagePreviewWin::MV_DOC_STT
;
863 case FN_END_OF_DOCUMENT
:
864 m_pViewWin
->SetSelectedPage(eMvMode
== SwPagePreviewWin::MV_DOC_STT
? 1 : mnPageCount
);
866 bool bRet
= ChgPage( eMvMode
);
867 // return value for Basic
868 rReq
.SetReturnValue(SfxBoolItem(rReq
.GetSlot(), !bRet
));
875 case FN_PRINT_PAGEPREVIEW
:
877 const SwPagePreviewPrtData
* pPPVPD
= m_pViewWin
->GetViewShell()->GetDoc()->GetPreviewPrtData();
878 // The thing with the orientation
881 SfxPrinter
* pPrinter
= GetPrinter( true );
882 if((pPrinter
->GetOrientation() == Orientation::Landscape
)
883 != pPPVPD
->GetLandscape())
884 pPrinter
->SetOrientation(pPPVPD
->GetLandscape() ? Orientation::Landscape
: Orientation::Portrait
);
886 ::SetAppPrintOptions( m_pViewWin
->GetViewShell(), false );
887 m_bNormalPrint
= false;
888 rReq
.SetSlot( SID_PRINTDOC
);
889 SfxViewShell::ExecuteSlot( rReq
, SfxViewShell::GetInterface() );
890 rReq
.SetSlot( FN_PRINT_PAGEPREVIEW
);
893 case SID_PRINTDOCDIRECT
:
895 ::SetAppPrintOptions( m_pViewWin
->GetViewShell(), false );
896 m_bNormalPrint
= true;
897 SfxViewShell::ExecuteSlot( rReq
, SfxViewShell::GetInterface() );
899 case FN_CLOSE_PAGEPREVIEW
:
900 case SID_PRINTPREVIEW
:
901 // print preview is now always in the same frame as the tab view
902 // -> always switch this frame back to normal view
903 // (ScTabViewShell ctor reads stored view data)
904 GetViewFrame().GetDispatcher()->Execute( SID_VIEWSHELL0
, SfxCallMode::ASYNCHRON
);
906 case FN_INSERT_BREAK
:
908 sal_uInt16 nSelPage
= m_pViewWin
->SelectedPage();
909 //if a dummy page is selected (e.g. a non-existing right/left page)
910 //the direct neighbor is used
911 if(GetViewShell()->IsDummyPage( nSelPage
) && GetViewShell()->IsDummyPage( --nSelPage
))
913 m_nNewPage
= nSelPage
;
914 SfxViewFrame
& rTmpFrame
= GetViewFrame();
915 rTmpFrame
.GetBindings().Execute( SID_VIEWSHELL0
, nullptr,
916 SfxCallMode::ASYNCHRON
);
920 OSL_ENSURE(false, "wrong dispatcher");
925 m_pViewWin
->Invalidate();
928 void SwPagePreview::GetState( SfxItemSet
& rSet
)
930 SfxWhichIter
aIter(rSet
);
931 sal_uInt16 nWhich
= aIter
.FirstWhich();
932 OSL_ENSURE(nWhich
, "empty set");
933 SwPagePreviewLayout
* pPagePreviewLay
= GetViewShell()->PagePreviewLayout();
939 case SID_BROWSER_MODE
:
940 case FN_PRINT_LAYOUT
:
941 rSet
.DisableItem(nWhich
);
943 case FN_START_OF_DOCUMENT
:
945 if ( pPagePreviewLay
->IsPageVisible( 1 ) )
946 rSet
.DisableItem(nWhich
);
949 case FN_END_OF_DOCUMENT
:
951 if ( pPagePreviewLay
->IsPageVisible( mnPageCount
) )
952 rSet
.DisableItem(nWhich
);
957 if( pPagePreviewLay
->GetWinPagesScrollAmount( -1 ) == 0 )
958 rSet
.DisableItem(nWhich
);
963 if( pPagePreviewLay
->GetWinPagesScrollAmount( 1 ) == 0 )
964 rSet
.DisableItem(nWhich
);
970 std::vector
<OUString
> aStringList
972 m_sPageStr
+ m_pViewWin
->GetStatusStr(mnPageCount
),
975 rSet
.Put(SfxStringListItem(FN_STAT_PAGE
, &aStringList
));
982 const SwViewOption
* pVOpt
= GetViewShell()->GetViewOptions();
983 SvxZoomItem
aZoom(pVOpt
->GetZoomType(), pVOpt
->GetZoom());
985 SvxZoomEnableFlags::N50
|
986 SvxZoomEnableFlags::N75
|
987 SvxZoomEnableFlags::N100
|
988 SvxZoomEnableFlags::N150
|
989 SvxZoomEnableFlags::N200
);
993 case SID_ATTR_ZOOMSLIDER
:
995 const SwViewOption
* pVOpt
= GetViewShell()->GetViewOptions();
996 const sal_uInt16 nCurrentZoom
= pVOpt
->GetZoom();
997 SvxZoomSliderItem
aZoomSliderItem( nCurrentZoom
, MINZOOM
, MAXZOOM
);
998 aZoomSliderItem
.AddSnappingPoint( 100 );
999 rSet
.Put( aZoomSliderItem
);
1002 case FN_PREVIEW_ZOOM
:
1004 const SwViewOption
* pVOpt
= GetViewShell()->GetViewOptions();
1005 rSet
.Put(SfxUInt16Item(nWhich
, pVOpt
->GetZoom()));
1011 const SwViewOption
* pVOpt
= GetViewShell()->GetViewOptions();
1012 if((SID_ZOOM_IN
== nWhich
&& pVOpt
->GetZoom() >= MAX_PREVIEW_ZOOM
) ||
1013 (SID_ZOOM_OUT
== nWhich
&& pVOpt
->GetZoom() <= MIN_PREVIEW_ZOOM
))
1015 rSet
.DisableItem(nWhich
);
1019 case SID_ATTR_VIEWLAYOUT
:
1021 rSet
.DisableItem( SID_ATTR_VIEWLAYOUT
);
1024 case FN_SHOW_MULTIPLE_PAGES
:
1025 // should never be disabled
1027 case FN_SHOW_BOOKVIEW
:
1029 bool b
= GetViewShell()->GetViewOptions()->IsPagePrevBookview();
1030 rSet
.Put(SfxBoolItem(nWhich
, b
));
1034 case FN_SHOW_TWO_PAGES
:
1035 if( 2 == m_pViewWin
->GetCol() && 1 == m_pViewWin
->GetRow() )
1036 rSet
.DisableItem( nWhich
);
1039 case FN_PRINT_PAGEPREVIEW
:
1040 // has the same status like the normal printing
1042 const SfxPoolItem
* pItem
;
1043 SfxItemSetFixed
<SID_PRINTDOC
, SID_PRINTDOC
> aSet( *rSet
.GetPool() );
1044 GetSlotState( SID_PRINTDOC
, SfxViewShell::GetInterface(), &aSet
);
1045 if( SfxItemState::DISABLED
== aSet
.GetItemState( SID_PRINTDOC
, false ))
1046 rSet
.DisableItem( nWhich
);
1047 else if( SfxItemState::SET
== aSet
.GetItemState( SID_PRINTDOC
,
1050 const_cast<SfxPoolItem
*>(pItem
)->SetWhich( FN_PRINT_PAGEPREVIEW
);
1056 case SID_PRINTPREVIEW
:
1057 rSet
.Put( SfxBoolItem( nWhich
, true ) );
1061 case SID_PRINTDOCDIRECT
:
1062 GetSlotState( nWhich
, SfxViewShell::GetInterface(), &rSet
);
1065 nWhich
= aIter
.NextWhich();
1069 void SwPagePreview::StateUndo(SfxItemSet
& rSet
)
1071 SfxWhichIter
aIter(rSet
);
1072 sal_uInt16 nWhich
= aIter
.FirstWhich();
1076 rSet
.DisableItem(nWhich
);
1077 nWhich
= aIter
.NextWhich();
1081 void SwPagePreview::Init()
1083 if ( GetViewShell()->HasDrawView() )
1084 GetViewShell()->GetDrawView()->SetAnimationEnabled( false );
1086 m_bNormalPrint
= true;
1088 // Check and process the DocSize. The shell could not be found via
1089 // the handler, because the shell is unknown to the SFX management
1090 // within the CTOR phase.
1092 const SwViewOption
* pPrefs
= SW_MOD()->GetUsrPref(false);
1094 mbHScrollbarEnabled
= pPrefs
->IsViewHScrollBar();
1095 mbVScrollbarEnabled
= pPrefs
->IsViewVScrollBar();
1097 // Update the fields
1098 // ATTENTION: Do cast the EditShell up, to use the SS.
1099 // At the methods the current shell will be queried!
1100 SwEditShell
* pESh
= dynamic_cast<SwEditShell
*>(GetViewShell());
1101 bool bIsModified
= pESh
!= nullptr && pESh
->IsModified();
1103 SwViewOption
aOpt( *pPrefs
);
1104 aOpt
.SetPagePreview(true);
1105 aOpt
.SetTab( false );
1106 aOpt
.SetBlank( false );
1107 aOpt
.SetHardBlank( false );
1108 aOpt
.SetParagraph( false );
1109 aOpt
.SetLineBreak( false );
1110 aOpt
.SetPageBreak( false );
1111 aOpt
.SetColumnBreak( false );
1112 aOpt
.SetSoftHyph( false );
1113 aOpt
.SetFieldName( false );
1114 aOpt
.SetPostIts( false );
1115 aOpt
.SetShowBookmarks( false );
1116 aOpt
.SetShowHiddenChar( false );
1117 aOpt
.SetShowHiddenField( false );
1118 aOpt
.SetShowHiddenPara( false );
1119 aOpt
.SetViewHRuler( false );
1120 aOpt
.SetViewVRuler( false );
1121 aOpt
.SetGraphic( true );
1122 aOpt
.SetTable( true );
1123 aOpt
.SetSnap( false );
1124 aOpt
.SetGridVisible( false );
1125 aOpt
.SetOnlineSpell( false );
1126 aOpt
.SetHideWhitespaceMode( false );
1128 GetViewShell()->ApplyViewOptions( aOpt
);
1129 #if !ENABLE_WASM_STRIP_ACCESSIBILITY
1130 GetViewShell()->ApplyAccessibilityOptions();
1133 // adjust view shell option to the same as for print
1134 SwPrintData
const aPrintOptions
= *SW_MOD()->GetPrtOptions(false);
1135 GetViewShell()->AdjustOptionsForPagePreview( aPrintOptions
);
1137 GetViewShell()->CalcLayout();
1138 DocSzChgd( GetViewShell()->GetDocSize() );
1140 if( !bIsModified
&& pESh
!= nullptr )
1141 pESh
->ResetModified();
1144 SwPagePreview::SwPagePreview(SfxViewFrame
& rViewFrame
, SfxViewShell
* pOldSh
):
1145 SfxViewShell(rViewFrame
, SWVIEWFLAGS
),
1146 m_pViewWin( VclPtr
<SwPagePreviewWin
>::Create(&GetViewFrame().GetWindow(), *this ) ),
1147 m_nNewPage(USHRT_MAX
),
1148 m_sPageStr(SwResId(STR_PAGE
)),
1149 m_pHScrollbar(nullptr),
1150 m_pVScrollbar(nullptr),
1152 mbResetFormDesignMode( false ),
1153 mbFormDesignModeToReset( false )
1155 SetName("PageView");
1156 SetWindow( m_pViewWin
);
1157 CreateScrollbar( true );
1158 CreateScrollbar( false );
1160 SfxShell::SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::Printpreview
));
1162 SfxObjectShell
* pObjShell
= rViewFrame
.GetObjectShell();
1165 // Exists already a view on the document?
1166 SfxViewFrame
*pF
= SfxViewFrame::GetFirst( pObjShell
);
1167 if (pF
== &rViewFrame
)
1168 pF
= SfxViewFrame::GetNext( *pF
, pObjShell
);
1170 pOldSh
= pF
->GetViewShell();
1173 SwViewShell
*pVS
, *pNew
;
1175 if (SwPagePreview
* pPagePreview
= dynamic_cast<SwPagePreview
*>(pOldSh
))
1176 pVS
= pPagePreview
->GetViewShell();
1179 if (SwView
* pView
= dynamic_cast<SwView
*>(pOldSh
))
1181 pVS
= pView
->GetWrtShellPtr();
1182 // save the current ViewData of the previous SwView
1183 pOldSh
->WriteUserData( m_sSwViewData
);
1186 pVS
= GetDocShell()->GetWrtShell();
1189 // Set the current page as the first.
1190 sal_uInt16 nPhysPg
, nVirtPg
;
1191 static_cast<SwCursorShell
*>(pVS
)->GetPageNum( nPhysPg
, nVirtPg
, true, false );
1192 if( 1 != m_pViewWin
->GetCol() && 1 == nPhysPg
)
1194 m_pViewWin
->SetSttPage( nPhysPg
);
1198 // for form shell remember design mode of draw view
1199 // of previous view shell
1200 if ( pVS
&& pVS
->HasDrawView() )
1202 mbResetFormDesignMode
= true;
1203 mbFormDesignModeToReset
= pVS
->GetDrawView()->IsDesignMode();
1207 pNew
= new SwViewShell( *pVS
, m_pViewWin
, nullptr, VSHELLFLAG_ISPREVIEW
);
1209 pNew
= new SwViewShell(
1210 *static_cast<SwDocShell
*>(rViewFrame
.GetObjectShell())->GetDoc(),
1211 m_pViewWin
, nullptr, nullptr, VSHELLFLAG_ISPREVIEW
);
1213 m_pViewWin
->SetViewShell( pNew
);
1214 pNew
->SetSfxViewShell( this );
1218 SwPagePreview::~SwPagePreview()
1220 SetWindow( nullptr );
1221 SwViewShell
* pVShell
= m_pViewWin
->GetViewShell();
1222 pVShell
->SetWin(nullptr);
1225 m_pViewWin
.disposeAndClear();
1226 m_pHScrollbar
.disposeAndClear();
1227 m_pVScrollbar
.disposeAndClear();
1230 void SwPagePreview::Activate(bool bMDI
)
1232 SfxViewShell::Activate(bMDI
);
1233 SfxShell::Activate(bMDI
);
1236 SwDocShell
* SwPagePreview::GetDocShell()
1238 return dynamic_cast<SwDocShell
*>( GetViewFrame().GetObjectShell() );
1241 void SwPagePreview::CreateScrollbar( bool bHori
)
1243 vcl::Window
*pMDI
= &GetViewFrame().GetWindow();
1244 VclPtr
<SwScrollbar
>& ppScrollbar
= bHori
? m_pHScrollbar
: m_pVScrollbar
;
1246 assert(!ppScrollbar
); //check beforehand!
1247 ppScrollbar
= VclPtr
<SwScrollbar
>::Create( pMDI
, bHori
);
1252 ppScrollbar
->SetScrollHdl( LINK( this, SwPagePreview
, HoriScrollHdl
));
1254 ppScrollbar
->SetScrollHdl( LINK( this, SwPagePreview
, VertScrollHdl
));
1257 ppScrollbar
->ExtendedShow();
1260 bool SwPagePreview::ChgPage( int eMvMode
, bool bUpdateScrollbar
)
1262 tools::Rectangle
aPixVisArea( m_pViewWin
->LogicToPixel( m_aVisArea
) );
1263 bool bChg
= m_pViewWin
->MovePage( eMvMode
) ||
1264 eMvMode
== SwPagePreviewWin::MV_CALC
||
1265 eMvMode
== SwPagePreviewWin::MV_NEWWINSIZE
;
1266 m_aVisArea
= m_pViewWin
->PixelToLogic( aPixVisArea
);
1271 SfxBindings
& rBindings
= GetViewFrame().GetBindings();
1273 if( bUpdateScrollbar
)
1277 static sal_uInt16 aInval
[] =
1279 FN_START_OF_DOCUMENT
, FN_END_OF_DOCUMENT
,
1280 FN_PAGEUP
, FN_PAGEDOWN
, 0
1282 rBindings
.Invalidate( aInval
);
1284 std::vector
<OUString
> aStringList
1286 m_sPageStr
+ m_pViewWin
->GetStatusStr(mnPageCount
),
1289 rBindings
.SetState(SfxStringListItem(FN_STAT_PAGE
, &aStringList
));
1294 // From here, everything was taken from the SwView.
1295 void SwPagePreview::CalcAndSetBorderPixel( SvBorder
&rToFill
)
1297 const StyleSettings
&rSet
= m_pViewWin
->GetSettings().GetStyleSettings();
1298 const tools::Long nTmp
= rSet
.GetScrollBarSize();
1299 if (m_pVScrollbar
->IsScrollbarVisible(true))
1300 rToFill
.Right() = nTmp
;
1301 if (m_pHScrollbar
->IsScrollbarVisible(true))
1302 rToFill
.Bottom() = nTmp
;
1303 SetBorderPixel( rToFill
);
1306 void SwPagePreview::InnerResizePixel( const Point
&rOfst
, const Size
&rSize
, bool )
1309 CalcAndSetBorderPixel( aBorder
);
1310 tools::Rectangle
aRect( rOfst
, rSize
);
1312 ViewResizePixel( *m_pViewWin
->GetOutDev(), aRect
.TopLeft(), aRect
.GetSize(),
1313 m_pViewWin
->GetOutputSizePixel(),
1314 *m_pVScrollbar
, *m_pHScrollbar
);
1316 // Never set EditWin !
1317 // Never set VisArea !
1320 void SwPagePreview::OuterResizePixel( const Point
&rOfst
, const Size
&rSize
)
1323 CalcAndSetBorderPixel( aBorder
);
1325 // Never set EditWin !
1327 Size
aTmpSize( m_pViewWin
->GetOutputSizePixel() );
1328 Point
aBottomRight( m_pViewWin
->PixelToLogic( Point( aTmpSize
.Width(), aTmpSize
.Height() ) ) );
1329 SetVisArea( tools::Rectangle( Point(), aBottomRight
) );
1331 // Call of the DocSzChgd-Method of the scrollbars is necessary,
1332 // because from the maximum scroll range half the height of the
1333 // VisArea is always deducted.
1334 if ( m_pVScrollbar
&& !aTmpSize
.IsEmpty() )
1339 SvBorder aBorderNew
;
1340 CalcAndSetBorderPixel( aBorderNew
);
1341 ViewResizePixel( *m_pViewWin
->GetOutDev(), rOfst
, rSize
, m_pViewWin
->GetOutputSizePixel(),
1342 *m_pVScrollbar
, *m_pHScrollbar
);
1345 void SwPagePreview::SetVisArea( const tools::Rectangle
&rRect
)
1347 const Point
aTopLeft(AlignToPixel(rRect
.TopLeft()));
1348 const Point
aBottomRight(AlignToPixel(rRect
.BottomRight()));
1349 tools::Rectangle
aLR(aTopLeft
,aBottomRight
);
1351 if(aLR
== m_aVisArea
)
1353 // No negative position, no negative size
1357 aLR
.AdjustBottom(std::abs(aLR
.Top()) );
1363 aLR
.AdjustRight(std::abs(aLR
.Left()) );
1366 if(aLR
.Right() < 0) aLR
.SetRight( 0 );
1367 if(aLR
.Bottom() < 0) aLR
.SetBottom( 0 );
1368 if(aLR
== m_aVisArea
||
1369 // Ignore empty rectangle
1370 ( 0 == aLR
.Bottom() - aLR
.Top() && 0 == aLR
.Right() - aLR
.Left() ) )
1373 if( aLR
.Left() > aLR
.Right() || aLR
.Top() > aLR
.Bottom() )
1376 // Before the data can be changed call an update if necessary.
1377 // Thereby ensured, that adjacent paints are correctly converted into
1378 // document coordinates.
1379 // As a precaution, we do this only when at the shell runs an action,
1380 // because then we do not really paint but the rectangles are just
1381 // bookmarked (in document coordinates).
1382 if( GetViewShell()->ActionPend() )
1383 m_pViewWin
->PaintImmediately();
1385 // Set at View-Win the current size
1387 m_pViewWin
->SetWinSize( aLR
.GetSize() );
1388 ChgPage( SwPagePreviewWin::MV_NEWWINSIZE
);
1390 m_pViewWin
->Invalidate();
1393 IMPL_LINK(SwPagePreview
, HoriScrollHdl
, weld::Scrollbar
&, rScrollbar
, void)
1395 ScrollHdl(rScrollbar
, true);
1398 IMPL_LINK(SwPagePreview
, VertScrollHdl
, weld::Scrollbar
&, rScrollbar
, void)
1400 ScrollHdl(rScrollbar
, false);
1403 void SwPagePreview::ScrollHdl(weld::Scrollbar
& rScrollbar
, bool bHori
)
1408 EndScrollHdl(rScrollbar
, bHori
);
1411 rScrollbar
.get_scroll_type() == ScrollType::Drag
&&
1412 Help::IsQuickHelpEnabled() &&
1413 GetViewShell()->PagePreviewLayout()->DoesPreviewLayoutRowsFitIntoWindow())
1415 // Scroll how many pages??
1416 OUString
sStateStr(m_sPageStr
);
1417 tools::Long nThmbPos
= rScrollbar
.adjustment_get_value();
1418 if( 1 == m_pViewWin
->GetCol() || !nThmbPos
)
1420 sStateStr
+= OUString::number( nThmbPos
);
1421 Point aPos
= m_pVScrollbar
->GetParent()->OutputToScreenPixel(
1422 m_pVScrollbar
->GetPosPixel());
1423 aPos
.setY( m_pVScrollbar
->OutputToScreenPixel(m_pVScrollbar
->GetPointerPosPixel()).Y() );
1424 tools::Rectangle aRect
;
1425 aRect
.SetLeft( aPos
.X() -8 );
1426 aRect
.SetRight( aRect
.Left() );
1427 aRect
.SetTop( aPos
.Y() );
1428 aRect
.SetBottom( aRect
.Top() );
1430 Help::ShowQuickHelp(m_pVScrollbar
, aRect
, sStateStr
,
1431 QuickHelpFlags::Right
|QuickHelpFlags::VCenter
);
1436 void SwPagePreview::EndScrollHdl(weld::Scrollbar
& rScrollbar
, bool bHori
)
1441 // boolean to avoid unnecessary invalidation of the window.
1442 bool bInvalidateWin
= true;
1444 if (!bHori
) // scroll vertically
1446 if ( Help::IsQuickHelpEnabled() )
1447 Help::ShowQuickHelp(m_pVScrollbar
, tools::Rectangle(), OUString());
1448 if ( GetViewShell()->PagePreviewLayout()->DoesPreviewLayoutRowsFitIntoWindow() )
1450 // Scroll how many pages ??
1451 const sal_uInt16 nThmbPos
= o3tl::narrowing
<sal_uInt16
>(rScrollbar
.adjustment_get_value());
1452 // adjust to new preview functionality
1453 if( nThmbPos
!= m_pViewWin
->SelectedPage() )
1455 // consider case that page <nThmbPos>
1456 // is already visible
1457 SwPagePreviewLayout
* pPagePreviewLay
= GetViewShell()->PagePreviewLayout();
1458 if ( pPagePreviewLay
->IsPageVisible( nThmbPos
) )
1460 pPagePreviewLay
->MarkNewSelectedPage( nThmbPos
);
1461 // invalidation of window is unnecessary
1462 bInvalidateWin
= false;
1466 // consider whether layout columns
1468 if ( !pPagePreviewLay
->DoesPreviewLayoutColsFitIntoWindow() )
1470 m_pViewWin
->SetSttPage( nThmbPos
);
1471 m_pViewWin
->SetSelectedPage( nThmbPos
);
1472 ChgPage( SwPagePreviewWin::MV_SCROLL
, false );
1473 // update scrollbars
1478 // correct scroll amount
1479 const sal_Int16 nPageDiff
= nThmbPos
- m_pViewWin
->SelectedPage();
1480 const sal_uInt16 nVisPages
= m_pViewWin
->GetRow() * m_pViewWin
->GetCol();
1481 sal_Int16 nWinPagesToScroll
= nPageDiff
/ nVisPages
;
1482 if ( nPageDiff
% nVisPages
)
1484 // decrease/increase number of preview pages to scroll
1485 nPageDiff
< 0 ? --nWinPagesToScroll
: ++nWinPagesToScroll
;
1487 m_pViewWin
->SetSelectedPage( nThmbPos
);
1488 m_pViewWin
->Scroll( 0, pPagePreviewLay
->GetWinPagesScrollAmount( nWinPagesToScroll
) );
1491 // update accessibility
1492 GetViewShell()->ShowPreviewSelection( nThmbPos
);
1496 // invalidation of window is unnecessary
1497 bInvalidateWin
= false;
1502 tools::Long nThmbPos
= rScrollbar
.adjustment_get_value();
1503 m_pViewWin
->Scroll(0, nThmbPos
- m_pViewWin
->GetPaintedPreviewDocRect().Top());
1508 tools::Long nThmbPos
= rScrollbar
.adjustment_get_value();
1509 m_pViewWin
->Scroll(nThmbPos
- m_pViewWin
->GetPaintedPreviewDocRect().Left(), 0);
1511 // additional invalidate page status.
1512 static sal_uInt16 aInval
[] =
1514 FN_START_OF_DOCUMENT
, FN_END_OF_DOCUMENT
, FN_PAGEUP
, FN_PAGEDOWN
,
1517 SfxBindings
& rBindings
= GetViewFrame().GetBindings();
1518 rBindings
.Invalidate( aInval
);
1519 // control invalidation of window
1520 if ( bInvalidateWin
)
1522 m_pViewWin
->Invalidate();
1526 Point
SwPagePreview::AlignToPixel(const Point
&rPt
) const
1528 return m_pViewWin
->PixelToLogic( m_pViewWin
->LogicToPixel( rPt
) );
1531 void SwPagePreview::DocSzChgd( const Size
&rSz
)
1533 if( m_aDocSize
== rSz
)
1539 // Due to the multiple page layout it is needed to trigger recalculation
1540 // of the page preview layout, even if the count of pages is not changing.
1541 mnPageCount
= GetViewShell()->GetNumPages();
1543 if( m_aVisArea
.GetWidth() )
1545 ChgPage( SwPagePreviewWin::MV_CALC
);
1548 m_pViewWin
->Invalidate();
1552 void SwPagePreview::ScrollViewSzChg()
1557 bool bShowVScrollbar
= false, bShowHScrollbar
= false;
1561 if(GetViewShell()->PagePreviewLayout()->DoesPreviewLayoutRowsFitIntoWindow())
1563 //vertical scrolling by row
1564 // adjust to new preview functionality
1565 const sal_uInt16 nVisPages
= m_pViewWin
->GetRow() * m_pViewWin
->GetCol();
1567 m_pVScrollbar
->SetVisibleSize( nVisPages
);
1568 // set selected page as scroll bar position,
1569 // if it is visible.
1570 SwPagePreviewLayout
* pPagePreviewLay
= GetViewShell()->PagePreviewLayout();
1571 if ( pPagePreviewLay
->IsPageVisible( m_pViewWin
->SelectedPage() ) )
1573 m_pVScrollbar
->SetThumbPos( m_pViewWin
->SelectedPage() );
1577 m_pVScrollbar
->SetThumbPos( m_pViewWin
->GetSttPage() );
1579 m_pVScrollbar
->SetLineSize( m_pViewWin
->GetCol() );
1580 m_pVScrollbar
->SetPageSize( nVisPages
);
1581 // calculate and set scrollbar range
1582 Range
aScrollbarRange( 1, mnPageCount
);
1583 // increase range by one, because left-top-corner is left blank.
1584 ++aScrollbarRange
.Max();
1585 // increase range in order to access all pages
1586 aScrollbarRange
.Max() += ( nVisPages
- 1 );
1587 m_pVScrollbar
->SetRange( aScrollbarRange
);
1589 bShowVScrollbar
= nVisPages
< mnPageCount
;
1591 else //vertical scrolling by pixel
1593 const tools::Rectangle
& rDocRect
= m_pViewWin
->GetPaintedPreviewDocRect();
1594 const Size
& rPreviewSize
=
1595 GetViewShell()->PagePreviewLayout()->GetPreviewDocSize();
1596 m_pVScrollbar
->SetRangeMax(rPreviewSize
.Height()) ;
1597 tools::Long nVisHeight
= rDocRect
.GetHeight();
1598 m_pVScrollbar
->SetVisibleSize( nVisHeight
);
1599 m_pVScrollbar
->SetThumbPos( rDocRect
.Top() );
1600 m_pVScrollbar
->SetLineSize( nVisHeight
/ 10 );
1601 m_pVScrollbar
->SetPageSize( nVisHeight
/ 2 );
1603 bShowVScrollbar
= true;
1606 if (!mbVScrollbarEnabled
)
1607 bShowVScrollbar
= false;
1609 ShowVScrollbar(bShowVScrollbar
);
1613 const tools::Rectangle
& rDocRect
= m_pViewWin
->GetPaintedPreviewDocRect();
1614 const Size
& rPreviewSize
=
1615 GetViewShell()->PagePreviewLayout()->GetPreviewDocSize();
1618 if(rDocRect
.GetWidth() < rPreviewSize
.Width())
1620 bShowHScrollbar
= true;
1622 tools::Long nVisWidth
= rDocRect
.GetWidth();
1623 tools::Long nThumb
= rDocRect
.Left();
1624 aRange
= Range(0, rPreviewSize
.Width());
1626 m_pHScrollbar
->SetRange( aRange
);
1627 m_pHScrollbar
->SetVisibleSize( nVisWidth
);
1628 m_pHScrollbar
->SetThumbPos( nThumb
);
1629 m_pHScrollbar
->SetLineSize( nVisWidth
/ 10 );
1630 m_pHScrollbar
->SetPageSize( nVisWidth
/ 2 );
1633 if (!mbHScrollbarEnabled
)
1634 bShowHScrollbar
= false;
1636 ShowHScrollbar(bShowHScrollbar
);
1640 void SwPagePreview::ScrollDocSzChg()
1645 // All about printing
1646 SfxPrinter
* SwPagePreview::GetPrinter( bool bCreate
)
1648 return m_pViewWin
->GetViewShell()->getIDocumentDeviceAccess().getPrinter( bCreate
);
1651 sal_uInt16
SwPagePreview::SetPrinter( SfxPrinter
*pNew
, SfxPrinterChangeFlags nDiffFlags
)
1653 SwViewShell
&rSh
= *GetViewShell();
1654 SfxPrinter
* pOld
= rSh
.getIDocumentDeviceAccess().getPrinter( false );
1655 if ( pOld
&& pOld
->IsPrinting() )
1656 return SFX_PRINTERROR_BUSY
;
1658 SwEditShell
&rESh
= static_cast<SwEditShell
&>(rSh
); //Buh...
1659 if( ( SfxPrinterChangeFlags::PRINTER
| SfxPrinterChangeFlags::JOBSETUP
) & nDiffFlags
)
1661 rSh
.getIDocumentDeviceAccess().setPrinter( pNew
, true, true );
1662 if( nDiffFlags
& SfxPrinterChangeFlags::PRINTER
)
1665 if ( ( nDiffFlags
& SfxPrinterChangeFlags::OPTIONS
) == SfxPrinterChangeFlags::OPTIONS
)
1666 ::SetPrinter( &rSh
.getIDocumentDeviceAccess(), pNew
, false );
1668 const bool bChgOri
= bool(nDiffFlags
& SfxPrinterChangeFlags::CHG_ORIENTATION
);
1669 const bool bChgSize
= bool(nDiffFlags
& SfxPrinterChangeFlags::CHG_SIZE
);
1670 if ( bChgOri
|| bChgSize
)
1672 rESh
.StartAllAction();
1674 rSh
.ChgAllPageOrientation( pNew
->GetOrientation() );
1677 Size
aSz( SvxPaperInfo::GetPaperSize( pNew
) );
1678 rSh
.ChgAllPageSize( aSz
);
1680 if( !m_bNormalPrint
)
1681 m_pViewWin
->CalcWish( m_pViewWin
->GetRow(), m_pViewWin
->GetCol() );
1683 rESh
.EndAllAction();
1685 static sal_uInt16 aInval
[] =
1687 SID_ATTR_LONG_ULSPACE
, SID_ATTR_LONG_LRSPACE
,
1688 SID_RULER_BORDERS
, SID_RULER_PAGE_POS
, 0
1690 #if OSL_DEBUG_LEVEL > 0
1692 const sal_uInt16
* pPtr
= aInval
+ 1;
1694 OSL_ENSURE( *(pPtr
- 1) < *pPtr
, "wrong sorting!" );
1699 GetViewFrame().GetBindings().Invalidate(aInval
);
1705 bool SwPagePreview::HasPrintOptionsPage() const
1710 std::unique_ptr
<SfxTabPage
> SwPagePreview::CreatePrintOptionsPage(weld::Container
* pPage
, weld::DialogController
* pController
,
1711 const SfxItemSet
&rOptions
)
1713 return ::CreatePrintOptionsPage(pPage
, pController
, rOptions
, !m_bNormalPrint
);
1716 void SwPagePreviewWin::SetViewShell( SwViewShell
* pShell
)
1718 mpViewShell
= pShell
;
1719 if ( mpViewShell
&& mpViewShell
->IsPreview() )
1721 mpPgPreviewLayout
= mpViewShell
->PagePreviewLayout();
1725 void SwPagePreviewWin::RepaintCoreRect( const SwRect
& rRect
)
1728 if ( mpPgPreviewLayout
->PreviewLayoutValid() )
1730 mpPgPreviewLayout
->Repaint( tools::Rectangle( rRect
.Pos(), rRect
.SSize() ) );
1734 /** method to adjust preview to a new zoom factor
1736 #i19975# also consider zoom type - adding parameter <_eZoomType>
1738 void SwPagePreviewWin::AdjustPreviewToNewZoom( const sal_uInt16 _nZoomFactor
,
1739 const SvxZoomType _eZoomType
)
1741 // #i19975# consider zoom type
1742 if ( _eZoomType
== SvxZoomType::WHOLEPAGE
)
1746 mpPgPreviewLayout
->Init( mnCol
, mnRow
, maPxWinSize
);
1747 mpPgPreviewLayout
->Prepare( mnSttPage
, Point(0,0), maPxWinSize
,
1748 mnSttPage
, maPaintedPreviewDocRect
);
1749 SetSelectedPage( mnSttPage
);
1750 SetPagePreview(mnRow
, mnCol
);
1751 maScale
= GetMapMode().GetScaleX();
1753 else if ( _nZoomFactor
!= 0 )
1755 // calculate new scaling and set mapping mode appropriately.
1756 Fraction
aNewScale( _nZoomFactor
, 100 );
1757 MapMode aNewMapMode
= GetMapMode();
1758 aNewMapMode
.SetScaleX( aNewScale
);
1759 aNewMapMode
.SetScaleY( aNewScale
);
1760 SetMapMode( aNewMapMode
);
1762 // calculate new start position for preview paint
1763 Size aNewWinSize
= PixelToLogic( maPxWinSize
);
1764 Point aNewPaintStartPos
=
1765 mpPgPreviewLayout
->GetPreviewStartPosForNewScale( aNewScale
, maScale
, aNewWinSize
);
1767 // remember new scaling and prepare preview paint
1768 // Note: paint of preview will be performed by a corresponding invalidate
1769 // due to property changes.
1770 maScale
= aNewScale
;
1771 mpPgPreviewLayout
->Prepare( 0, aNewPaintStartPos
, maPxWinSize
,
1772 mnSttPage
, maPaintedPreviewDocRect
);
1778 * pixel scrolling - horizontally always or vertically
1779 * when less than the desired number of rows fits into
1782 void SwPagePreviewWin::Scroll(tools::Long nXMove
, tools::Long nYMove
, ScrollFlags
/*nFlags*/)
1784 maPaintedPreviewDocRect
.Move(nXMove
, nYMove
);
1785 mpPgPreviewLayout
->Prepare( 0, maPaintedPreviewDocRect
.TopLeft(),
1786 maPxWinSize
, mnSttPage
,
1787 maPaintedPreviewDocRect
);
1791 bool SwPagePreview::HandleWheelCommands( const CommandEvent
& rCEvt
)
1794 const CommandWheelData
* pWData
= rCEvt
.GetWheelData();
1795 if( pWData
&& CommandWheelMode::ZOOM
== pWData
->GetMode() )
1797 //only the Preference shouldn't control the Zoom, it is better to detect AT tools running. So the bridge can be used here
1798 if (!Application::GetSettings().GetMiscSettings().GetEnableATToolSupport())
1800 sal_uInt16 nFactor
= GetViewShell()->GetViewOptions()->GetZoom();
1801 const sal_uInt16 nOffset
= 10;
1802 if( 0L > pWData
->GetDelta() )
1805 if(nFactor
< MIN_PREVIEW_ZOOM
)
1806 nFactor
= MIN_PREVIEW_ZOOM
;
1811 if(nFactor
> MAX_PREVIEW_ZOOM
)
1812 nFactor
= MAX_PREVIEW_ZOOM
;
1814 SetZoom(SvxZoomType::PERCENT
, nFactor
);
1819 bOk
= m_pViewWin
->HandleScrollCommand( rCEvt
, m_pHScrollbar
, m_pVScrollbar
);
1823 uno::Reference
< css::accessibility::XAccessible
>
1824 SwPagePreviewWin::CreateAccessible()
1826 SolarMutexGuard aGuard
; // this should have happened already!!!
1827 #if !ENABLE_WASM_STRIP_ACCESSIBILITY
1828 OSL_ENSURE( GetViewShell() != nullptr, "We need a view shell" );
1829 css::uno::Reference
< css::accessibility::XAccessible
> xAcc
= GetAccessible( false );
1836 css::uno::Reference
< css::accessibility::XAccessible
> xAccPreview
= mpViewShell
->CreateAccessiblePreview();
1837 SetAccessible(xAccPreview
);
1840 return GetAccessible( false );
1843 void SwPagePreview::ApplyAccessibilityOptions()
1845 GetViewShell()->ApplyAccessibilityOptions();
1848 void SwPagePreview::ShowHScrollbar(bool bShow
)
1850 m_pHScrollbar
->Show(bShow
);
1854 void SwPagePreview::ShowVScrollbar(bool bShow
)
1856 m_pVScrollbar
->Show(bShow
);
1860 void SwPagePreview::EnableHScrollbar(bool bEnable
)
1862 if (mbHScrollbarEnabled
!= bEnable
)
1864 mbHScrollbarEnabled
= bEnable
;
1869 void SwPagePreview::EnableVScrollbar(bool bEnable
)
1871 if (mbVScrollbarEnabled
!= bEnable
)
1873 mbVScrollbarEnabled
= bEnable
;
1878 void SwPagePreview::SetZoom(SvxZoomType eType
, sal_uInt16 nFactor
)
1880 SwViewShell
& rSh
= *GetViewShell();
1881 SwViewOption
aOpt(*rSh
.GetViewOptions());
1882 // perform action only on changes of zoom or zoom type.
1883 if ( aOpt
.GetZoom() != nFactor
||
1884 aOpt
.GetZoomType() != eType
)
1886 aOpt
.SetZoom(nFactor
);
1887 aOpt
.SetZoomType(eType
);
1888 rSh
.ApplyViewOptions( aOpt
);
1889 lcl_InvalidateZoomSlots(GetViewFrame().GetBindings());
1890 // #i19975# also consider zoom type
1891 m_pViewWin
->AdjustPreviewToNewZoom( nFactor
, eType
);
1896 /** adjust position of vertical scrollbar */
1897 void SwPagePreview::SetVScrollbarThumbPos( const sal_uInt16 _nNewThumbPos
)
1899 if ( m_pVScrollbar
)
1901 m_pVScrollbar
->SetThumbPos( _nNewThumbPos
);
1905 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */