bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / uiview / pview.cxx
blobc7c5e41586b0d8891a2400424eaaac8cca516d51
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 #include <sfx2/objface.hxx>
22 #include <vcl/timer.hxx>
23 #include <vcl/field.hxx>
24 #include <vcl/fixed.hxx>
25 #include <vcl/help.hxx>
26 #include <vcl/cmdevt.hxx>
27 #include <vcl/button.hxx>
28 #include <svl/whiter.hxx>
29 #include <svl/stritem.hxx>
30 #include <svl/eitem.hxx>
31 #include <sfx2/printer.hxx>
32 #include <sfx2/progress.hxx>
33 #include <sfx2/app.hxx>
34 #include <sfx2/bindings.hxx>
35 #include <sfx2/request.hxx>
36 #include <sfx2/dispatch.hxx>
37 #include <vcl/msgbox.hxx>
38 #include <svx/stddlg.hxx>
39 #include <editeng/paperinf.hxx>
40 #include <svl/srchitem.hxx>
41 #include <svx/svdview.hxx>
42 #include <svx/dlgutil.hxx>
43 #include <svx/zoomslideritem.hxx>
44 #include <svx/svxids.hrc>
46 #include <swwait.hxx>
47 #include <globdoc.hxx>
48 #include <wdocsh.hxx>
49 #include <pvprtdat.hxx>
50 #include <swmodule.hxx>
51 #include <modcfg.hxx>
52 #include <wrtsh.hxx>
53 #include <docsh.hxx>
54 #include <viewopt.hxx>
55 #include <doc.hxx>
56 #include <pview.hxx>
57 #include <view.hxx>
58 #include <textsh.hxx>
59 #include <scroll.hxx>
60 #include <prtopt.hxx>
61 #include <docstat.hxx>
62 #include <usrpref.hxx>
63 #include <viewfunc.hxx>
65 #include <helpid.h>
66 #include <cmdid.h>
67 #include <globals.hrc>
68 #include <popup.hrc>
69 #include <view.hrc>
71 #define SwPagePreView
72 #include <sfx2/msg.hxx>
73 #include <swslots.hxx>
74 #include <pagepreviewlayout.hxx>
76 #include <svx/svxdlg.hxx>
77 #include <svx/dialogs.hrc>
78 #include <osl/mutex.hxx>
81 using namespace ::com::sun::star;
82 SFX_IMPL_NAMED_VIEWFACTORY(SwPagePreView, "PrintPreview")
84 SFX_VIEW_REGISTRATION(SwDocShell);
85 SFX_VIEW_REGISTRATION(SwWebDocShell);
86 SFX_VIEW_REGISTRATION(SwGlobalDocShell);
89 SFX_IMPL_INTERFACE(SwPagePreView, SfxViewShell, SW_RES(RID_PVIEW_TOOLBOX))
91 SFX_POPUPMENU_REGISTRATION(SW_RES(MN_PPREVIEW_POPUPMENU));
92 SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT|SFX_VISIBILITY_STANDARD|
93 SFX_VISIBILITY_CLIENT|SFX_VISIBILITY_FULLSCREEN|
94 SFX_VISIBILITY_READONLYDOC,
95 SW_RES(RID_PVIEW_TOOLBOX));
98 TYPEINIT1(SwPagePreView,SfxViewShell)
100 #define SWVIEWFLAGS ( SFX_VIEW_CAN_PRINT|SFX_VIEW_HAS_PRINTOPTIONS )
102 #define MIN_PREVIEW_ZOOM 25
103 #define MAX_PREVIEW_ZOOM 600
105 static sal_uInt16 lcl_GetNextZoomStep(sal_uInt16 nCurrentZoom, sal_Bool bZoomIn)
107 static sal_uInt16 aZoomArr[] =
109 25, 50, 75, 100, 150, 200, 400, 600
111 const sal_uInt16 nZoomArrSize = sizeof(aZoomArr)/sizeof(sal_uInt16);
112 if(bZoomIn)
113 for(int i = nZoomArrSize - 1; i >= 0; --i)
115 if(nCurrentZoom > aZoomArr[i] || !i)
116 return aZoomArr[i];
118 else
119 for(int i = 0; i < nZoomArrSize; ++i)
121 if(nCurrentZoom < aZoomArr[i])
122 return aZoomArr[i];
124 return bZoomIn ? MAX_PREVIEW_ZOOM : MIN_PREVIEW_ZOOM;
127 static void lcl_InvalidateZoomSlots(SfxBindings& rBindings)
129 static sal_uInt16 const aInval[] =
131 SID_ATTR_ZOOM, SID_ZOOM_OUT, SID_ZOOM_IN, SID_ATTR_ZOOMSLIDER, FN_PREVIEW_ZOOM, FN_STAT_ZOOM,
134 rBindings.Invalidate( aInval );
137 // erstmal der Zoom-Dialog
138 class SwPreViewZoomDlg : public SvxStandardDialog
140 NumericField* m_pRowEdit;
141 NumericField* m_pColEdit;
143 virtual void Apply();
145 public:
146 SwPreViewZoomDlg( SwPagePreViewWin& rParent );
149 SwPreViewZoomDlg::SwPreViewZoomDlg( SwPagePreViewWin& rParent )
150 : SvxStandardDialog(&rParent, "PreviewZoomDialog", "modules/swriter/ui/previewzoomdialog.ui")
152 get(m_pRowEdit, "rows");
153 get(m_pColEdit, "cols");
155 m_pRowEdit->SetValue( rParent.GetRow() );
156 m_pColEdit->SetValue( rParent.GetCol() );
159 void SwPreViewZoomDlg::Apply()
161 ((SwPagePreViewWin*)GetParent())->CalcWish(
162 sal_uInt8(m_pRowEdit->GetValue()),
163 sal_uInt8(m_pColEdit->GetValue()) );
166 // all for SwPagePreViewWin
167 SwPagePreViewWin::SwPagePreViewWin( Window *pParent, SwPagePreView& rPView )
168 : Window( pParent, WinBits( WB_CLIPCHILDREN) ),
169 mpViewShell( 0 ),
170 mrView( rPView ),
171 mbCalcScaleForPreviewLayout( true ),
172 maPaintedPreviewDocRect( Rectangle(0,0,0,0) )
174 SetOutDevViewType( OUTDEV_VIEWTYPE_PRINTPREVIEW );
175 SetHelpId(HID_PAGEPREVIEW);
176 SetFillColor( GetBackground().GetColor() );
177 SetLineColor( GetBackground().GetColor());
178 SetMapMode( MapMode(MAP_TWIP) );
180 const SwMasterUsrPref *pUsrPref = SW_MOD()->GetUsrPref(sal_False);
181 mnRow = pUsrPref->GetPagePrevRow(); // 1 Zeile
182 mnCol = pUsrPref->GetPagePrevCol(); // 1 Spalte
183 mnSttPage = USHRT_MAX;
186 SwPagePreViewWin::~SwPagePreViewWin()
188 delete mpViewShell;
191 void SwPagePreViewWin::Paint( const Rectangle& rRect )
193 if( !mpViewShell || !mpViewShell->GetLayout() )
194 return;
196 if( USHRT_MAX == mnSttPage ) // wurde noch nie berechnet ? (Init-Phase!)
198 // das ist die Size, auf die ich mich immer beziehe
199 if( !maPxWinSize.Height() || !maPxWinSize.Width() )
200 maPxWinSize = GetOutputSizePixel();
202 Rectangle aRect( LogicToPixel( rRect ));
203 mpPgPrevwLayout->Prepare( 1, Point(0,0), maPxWinSize,
204 mnSttPage, maPaintedPreviewDocRect );
205 SetSelectedPage( 1 );
206 mpPgPrevwLayout->Paint( PixelToLogic( aRect ) );
207 SetPagePreview(mnRow, mnCol);
209 else
211 MapMode aMM( GetMapMode() );
212 aMM.SetScaleX( maScale );
213 aMM.SetScaleY( maScale );
214 SetMapMode( aMM );
215 mpPgPrevwLayout->Paint( rRect );
219 void SwPagePreViewWin::CalcWish( sal_uInt8 nNewRow, sal_uInt8 nNewCol )
221 if( !mpViewShell || !mpViewShell->GetLayout() )
222 return;
224 sal_uInt16 nOldCol = mnCol;
225 mnRow = nNewRow;
226 mnCol = nNewCol;
227 sal_uInt16 nPages = mnRow * mnCol,
228 nLastSttPg = mrView.GetPageCount()+1 > nPages
229 ? mrView.GetPageCount()+1 - nPages : 0;
230 if( mnSttPage > nLastSttPg )
231 mnSttPage = nLastSttPg;
233 mpPgPrevwLayout->Init( mnCol, mnRow, maPxWinSize, true );
234 mpPgPrevwLayout->Prepare( mnSttPage, Point(0,0), maPxWinSize,
235 mnSttPage, maPaintedPreviewDocRect );
236 SetSelectedPage( mnSttPage );
237 SetPagePreview(mnRow, mnCol);
238 maScale = GetMapMode().GetScaleX();
240 // falls an der Spaltigkeit gedreht wurde, so muss der Sonderfall
241 // Einspaltig beachtet und ggfs. der Scrollbar korrigiert werden
242 if( (1 == nOldCol) ^ (1 == mnCol) )
243 mrView.ScrollDocSzChg();
245 // Sortierung muss eingehalten werden!!
246 // additional invalidate page status.
247 static sal_uInt16 aInval[] =
249 SID_ATTR_ZOOM, SID_ZOOM_OUT, SID_ZOOM_IN,
250 FN_PREVIEW_ZOOM,
251 FN_START_OF_DOCUMENT, FN_END_OF_DOCUMENT, FN_PAGEUP, FN_PAGEDOWN,
252 FN_STAT_PAGE, FN_STAT_ZOOM,
253 FN_SHOW_TWO_PAGES, FN_SHOW_MULTIPLE_PAGES,
256 SfxBindings& rBindings = mrView.GetViewFrame()->GetBindings();
257 rBindings.Invalidate( aInval );
258 rBindings.Update( FN_SHOW_TWO_PAGES );
259 rBindings.Update( FN_SHOW_MULTIPLE_PAGES );
260 // adjust scrollbars
261 mrView.ScrollViewSzChg();
264 /*--------------------------------------------------------------------
265 Beschreibung:, mnSttPage is Absolute
266 --------------------------------------------------------------------*/
267 int SwPagePreViewWin::MovePage( int eMoveMode )
269 // soviele Seiten hoch
270 sal_uInt16 nPages = mnRow * mnCol;
271 sal_uInt16 nNewSttPage = mnSttPage;
272 sal_uInt16 nPageCount = mrView.GetPageCount();
273 sal_uInt16 nDefSttPg = GetDefSttPage();
274 bool bPaintPageAtFirstCol = true;
276 switch( eMoveMode )
278 case MV_PAGE_UP:
280 const sal_uInt16 nRelSttPage = mpPgPrevwLayout->ConvertAbsoluteToRelativePageNum( mnSttPage );
281 const sal_uInt16 nNewAbsSttPage = nRelSttPage - nPages > 0 ?
282 mpPgPrevwLayout->ConvertRelativeToAbsolutePageNum( nRelSttPage - nPages ) :
283 nDefSttPg;
284 nNewSttPage = nNewAbsSttPage;
286 const sal_uInt16 nRelSelPage = mpPgPrevwLayout->ConvertAbsoluteToRelativePageNum( SelectedPage() );
287 const sal_uInt16 nNewRelSelPage = nRelSelPage - nPages > 0 ?
288 nRelSelPage - nPages :
290 SetSelectedPage( mpPgPrevwLayout->ConvertRelativeToAbsolutePageNum( nNewRelSelPage ) );
292 break;
294 case MV_PAGE_DOWN:
296 const sal_uInt16 nRelSttPage = mpPgPrevwLayout->ConvertAbsoluteToRelativePageNum( mnSttPage );
297 const sal_uInt16 nNewAbsSttPage = mpPgPrevwLayout->ConvertRelativeToAbsolutePageNum( nRelSttPage + nPages );
298 nNewSttPage = nNewAbsSttPage < nPageCount ? nNewAbsSttPage : nPageCount;
300 const sal_uInt16 nRelSelPage = mpPgPrevwLayout->ConvertAbsoluteToRelativePageNum( SelectedPage() );
301 const sal_uInt16 nNewAbsSelPage = mpPgPrevwLayout->ConvertRelativeToAbsolutePageNum( nRelSelPage + nPages );
302 SetSelectedPage( nNewAbsSelPage < nPageCount ? nNewAbsSelPage : nPageCount );
304 break;
306 case MV_DOC_STT:
307 nNewSttPage = nDefSttPg;
308 SetSelectedPage( mpPgPrevwLayout->ConvertRelativeToAbsolutePageNum( nNewSttPage ? nNewSttPage : 1 ) );
309 break;
310 case MV_DOC_END:
311 // correct calculation of new start page.
312 nNewSttPage = nPageCount;
313 SetSelectedPage( nPageCount );
314 break;
315 case MV_SELPAGE:
316 // <nNewSttPage> and <SelectedPage()> are already set.
317 // not start at first column, only if the
318 // complete preview layout columns doesn't fit into window.
319 if ( !mpPgPrevwLayout->DoesPreviewLayoutColsFitIntoWindow() )
320 bPaintPageAtFirstCol = false;
321 break;
322 case MV_SCROLL:
323 // check, if paint page at first column
324 // has to be avoided
325 if ( !mpPgPrevwLayout->DoesPreviewLayoutRowsFitIntoWindow() ||
326 !mpPgPrevwLayout->DoesPreviewLayoutColsFitIntoWindow() )
327 bPaintPageAtFirstCol = false;
328 break;
329 case MV_NEWWINSIZE:
330 // nothing special to do.
331 break;
332 case MV_CALC:
333 // re-init page preview layout.
334 mpPgPrevwLayout->ReInit();
336 // correct calculation of new start page.
337 if( nNewSttPage > nPageCount )
338 nNewSttPage = nPageCount;
340 // correct selected page number
341 if( SelectedPage() > nPageCount )
342 SetSelectedPage( nNewSttPage ? nNewSttPage : 1 );
345 mpPgPrevwLayout->Prepare( nNewSttPage, Point(0,0), maPxWinSize,
346 nNewSttPage,
347 maPaintedPreviewDocRect, bPaintPageAtFirstCol );
348 if( nNewSttPage == mnSttPage &&
349 eMoveMode != MV_SELPAGE )
350 return sal_False;
352 SetPagePreview(mnRow, mnCol);
353 mnSttPage = nNewSttPage;
355 // additional invalidate page status.
356 static sal_uInt16 aInval[] =
358 FN_START_OF_DOCUMENT, FN_END_OF_DOCUMENT, FN_PAGEUP, FN_PAGEDOWN,
359 FN_STAT_PAGE, 0
362 SfxBindings& rBindings = mrView.GetViewFrame()->GetBindings();
363 rBindings.Invalidate( aInval );
365 return sal_True;
368 void SwPagePreViewWin::SetWinSize( const Size& rNewSize )
370 // die Size wollen wir aber immer in Pixel-Einheiten haben
371 maPxWinSize = LogicToPixel( rNewSize );
373 if( USHRT_MAX == mnSttPage )
375 mnSttPage = GetDefSttPage();
376 SetSelectedPage( GetDefSttPage() );
379 if ( mbCalcScaleForPreviewLayout )
381 mpPgPrevwLayout->Init( mnCol, mnRow, maPxWinSize, true );
382 maScale = GetMapMode().GetScaleX();
384 mpPgPrevwLayout->Prepare( mnSttPage, Point(0,0), maPxWinSize,
385 mnSttPage, maPaintedPreviewDocRect );
386 if ( mbCalcScaleForPreviewLayout )
388 SetSelectedPage( mnSttPage );
389 mbCalcScaleForPreviewLayout = false;
391 SetPagePreview(mnRow, mnCol);
392 maScale = GetMapMode().GetScaleX();
395 OUString SwPagePreViewWin::GetStatusStr( sal_uInt16 nPageCnt ) const
397 // show physical and virtual page number of
398 // selected page, if it's visible.
399 sal_uInt16 nPageNum;
400 if ( mpPgPrevwLayout->IsPageVisible( mpPgPrevwLayout->SelectedPage() ) )
402 nPageNum = mpPgPrevwLayout->SelectedPage();
404 else
406 nPageNum = mnSttPage > 1 ? mnSttPage : 1;
408 OUStringBuffer aStatusStr;
409 sal_uInt16 nVirtPageNum = mpPgPrevwLayout->GetVirtPageNumByPageNum( nPageNum );
410 if( nVirtPageNum && nVirtPageNum != nPageNum )
412 aStatusStr.append( OUString::number(nVirtPageNum) + " " );
414 aStatusStr.append( OUString::number(nPageNum) + " / " + OUString::number(nPageCnt) );
415 return aStatusStr.makeStringAndClear();
418 void SwPagePreViewWin::KeyInput( const KeyEvent &rKEvt )
420 const KeyCode& rKeyCode = rKEvt.GetKeyCode();
421 sal_uInt16 nKey = rKeyCode.GetCode();
422 bool bHandled = false;
423 if(!rKeyCode.GetModifier())
425 sal_uInt16 nSlot = 0;
426 switch(nKey)
428 case KEY_ADD : nSlot = SID_ZOOM_OUT; break;
429 case KEY_ESCAPE: nSlot = FN_CLOSE_PAGEPREVIEW; break;
430 case KEY_SUBTRACT : nSlot = SID_ZOOM_IN; break;
432 if(nSlot)
434 bHandled = true;
435 mrView.GetViewFrame()->GetDispatcher()->Execute(
436 nSlot, SFX_CALLMODE_ASYNCHRON );
439 if( !bHandled && !mrView.KeyInput( rKEvt ) )
440 Window::KeyInput( rKEvt );
443 void SwPagePreViewWin::Command( const CommandEvent& rCEvt )
445 bool bCallBase = true;
446 switch( rCEvt.GetCommand() )
448 case COMMAND_CONTEXTMENU:
449 mrView.GetViewFrame()->GetDispatcher()->ExecutePopup();
450 bCallBase = false;
451 break;
453 case COMMAND_WHEEL:
454 case COMMAND_STARTAUTOSCROLL:
455 case COMMAND_AUTOSCROLL:
457 const CommandWheelData* pData = rCEvt.GetWheelData();
458 if( pData )
460 const CommandWheelData aDataNew(pData->GetDelta(),pData->GetNotchDelta(),COMMAND_WHEEL_PAGESCROLL,
461 pData->GetMode(),pData->GetModifier(),pData->IsHorz(), pData->IsDeltaPixel());
462 const CommandEvent aEvent( rCEvt.GetMousePosPixel(),rCEvt.GetCommand(),rCEvt.IsMouseEvent(),&aDataNew);
463 bCallBase = !mrView.HandleWheelCommands( aEvent );
465 else
466 bCallBase = !mrView.HandleWheelCommands( rCEvt );
468 break;
469 default:
473 if( bCallBase )
474 Window::Command( rCEvt );
477 void SwPagePreViewWin::MouseButtonDown( const MouseEvent& rMEvt )
479 // consider single-click to set selected page
480 if( MOUSE_LEFT == ( rMEvt.GetModifier() + rMEvt.GetButtons() ) )
482 Point aPrevwPos( PixelToLogic( rMEvt.GetPosPixel() ) );
483 Point aDocPos;
484 bool bPosInEmptyPage;
485 sal_uInt16 nNewSelectedPage;
486 bool bIsDocPos =
487 mpPgPrevwLayout->IsPrevwPosInDocPrevwPage( aPrevwPos,
488 aDocPos, bPosInEmptyPage, nNewSelectedPage );
489 if ( bIsDocPos && rMEvt.GetClicks() == 2 )
491 // close page preview, set new cursor position and switch to
492 // normal view.
493 String sNewCrsrPos( OUString::number( aDocPos.X() ));
494 ((( sNewCrsrPos += ';' )
495 += OUString::number( aDocPos.Y() )) )
496 += ';';
497 mrView.SetNewCrsrPos( sNewCrsrPos );
499 SfxViewFrame *pTmpFrm = mrView.GetViewFrame();
500 pTmpFrm->GetBindings().Execute( SID_VIEWSHELL0, NULL, 0,
501 SFX_CALLMODE_ASYNCHRON );
503 else if ( bIsDocPos || bPosInEmptyPage )
505 // show clicked page as the selected one
506 mpPgPrevwLayout->MarkNewSelectedPage( nNewSelectedPage );
507 GetViewShell()->ShowPreViewSelection( nNewSelectedPage );
508 // adjust position at vertical scrollbar.
509 if ( mpPgPrevwLayout->DoesPreviewLayoutRowsFitIntoWindow() )
511 mrView.SetVScrollbarThumbPos( nNewSelectedPage );
513 // invalidate page status.
514 static sal_uInt16 aInval[] =
516 FN_STAT_PAGE, 0
518 SfxBindings& rBindings = mrView.GetViewFrame()->GetBindings();
519 rBindings.Invalidate( aInval );
524 /******************************************************************************
525 * Beschreibung: Userprefs bzw Viewoptions setzen
526 ******************************************************************************/
527 void SwPagePreViewWin::SetPagePreview( sal_uInt8 nRow, sal_uInt8 nCol )
529 SwMasterUsrPref *pOpt = (SwMasterUsrPref *)SW_MOD()->GetUsrPref(sal_False);
531 if (nRow != pOpt->GetPagePrevRow() || nCol != pOpt->GetPagePrevCol())
533 pOpt->SetPagePrevRow( nRow );
534 pOpt->SetPagePrevCol( nCol );
535 pOpt->SetModified();
537 //Scrollbar updaten!
538 mrView.ScrollViewSzChg();
542 /** get selected page in document preview
544 @author OD
546 sal_uInt16 SwPagePreViewWin::SelectedPage() const
548 return mpPgPrevwLayout->SelectedPage();
551 /** set selected page number in document preview
553 @author OD
555 void SwPagePreViewWin::SetSelectedPage( sal_uInt16 _nSelectedPageNum )
557 mpPgPrevwLayout->SetSelectedPage( _nSelectedPageNum );
560 /** method to enable/disable book preview
562 @author OD
564 bool SwPagePreViewWin::SetBookPreviewMode( const bool _bBookPreview )
566 return mpPgPrevwLayout->SetBookPreviewMode( _bBookPreview,
567 mnSttPage,
568 maPaintedPreviewDocRect );
571 void SwPagePreViewWin::DataChanged( const DataChangedEvent& rDCEvt )
573 Window::DataChanged( rDCEvt );
575 switch( rDCEvt.GetType() )
577 case DATACHANGED_SETTINGS:
578 // ScrollBars neu anordnen bzw. Resize ausloesen, da sich
579 // ScrollBar-Groesse geaendert haben kann. Dazu muss dann im
580 // Resize-Handler aber auch die Groesse der ScrollBars aus
581 // den Settings abgefragt werden.
582 if( rDCEvt.GetFlags() & SETTINGS_STYLE )
583 mrView.InvalidateBorder(); //Scrollbarbreiten
584 // zoom has to be disabled if Accessibility support is switched on
585 lcl_InvalidateZoomSlots(mrView.GetViewFrame()->GetBindings());
586 break;
588 case DATACHANGED_PRINTER:
589 case DATACHANGED_DISPLAY:
590 case DATACHANGED_FONTS:
591 case DATACHANGED_FONTSUBSTITUTION:
592 mrView.GetDocShell()->UpdateFontList(); //Fontwechsel
593 if ( mpViewShell->GetWin() )
594 mpViewShell->GetWin()->Invalidate();
595 break;
599 /** help method to execute SfxRequest FN_PAGEUP and FN_PAGEDOWN
601 @author OD
603 void SwPagePreView::_ExecPgUpAndPgDown( const bool _bPgUp,
604 SfxRequest* _pReq )
606 SwPagePreviewLayout* pPagePrevwLay = GetViewShell()->PagePreviewLayout();
607 // check, if top/bottom of preview is *not* already visible.
608 if( pPagePrevwLay->GetWinPagesScrollAmount( _bPgUp ? -1 : 1 ) != 0 )
610 if ( pPagePrevwLay->DoesPreviewLayoutRowsFitIntoWindow() &&
611 pPagePrevwLay->DoesPreviewLayoutColsFitIntoWindow() )
613 const int eMvMode = _bPgUp ?
614 SwPagePreViewWin::MV_PAGE_UP :
615 SwPagePreViewWin::MV_PAGE_DOWN;
616 if ( ChgPage( eMvMode, sal_True ) )
617 aViewWin.Invalidate();
619 else
621 SwTwips nScrollAmount;
622 sal_uInt16 nNewSelectedPageNum = 0;
623 const sal_uInt16 nVisPages = aViewWin.GetRow() * aViewWin.GetCol();
624 if( _bPgUp )
626 if ( pPagePrevwLay->DoesPreviewLayoutRowsFitIntoWindow() )
628 nScrollAmount = pPagePrevwLay->GetWinPagesScrollAmount( -1 );
629 if ( (aViewWin.SelectedPage() - nVisPages) > 0 )
630 nNewSelectedPageNum = aViewWin.SelectedPage() - nVisPages;
631 else
632 nNewSelectedPageNum = 1;
634 else
635 nScrollAmount = - std::min( aViewWin.GetOutputSize().Height(),
636 aViewWin.GetPaintedPreviewDocRect().Top() );
638 else
640 if ( pPagePrevwLay->DoesPreviewLayoutRowsFitIntoWindow() )
642 nScrollAmount = pPagePrevwLay->GetWinPagesScrollAmount( 1 );
643 if ( (aViewWin.SelectedPage() + nVisPages) <= mnPageCount )
644 nNewSelectedPageNum = aViewWin.SelectedPage() + nVisPages;
645 else
646 nNewSelectedPageNum = mnPageCount;
648 else
649 nScrollAmount = std::min( aViewWin.GetOutputSize().Height(),
650 ( pPagePrevwLay->GetPrevwDocSize().Height() -
651 aViewWin.GetPaintedPreviewDocRect().Bottom() ) );
653 aViewWin.Scroll( 0, nScrollAmount );
654 if ( nNewSelectedPageNum != 0 )
656 aViewWin.SetSelectedPage( nNewSelectedPageNum );
658 ScrollViewSzChg();
659 // additional invalidate page status.
660 static sal_uInt16 aInval[] =
662 FN_START_OF_DOCUMENT, FN_END_OF_DOCUMENT, FN_PAGEUP, FN_PAGEDOWN,
663 FN_STAT_PAGE, 0
665 SfxBindings& rBindings = GetViewFrame()->GetBindings();
666 rBindings.Invalidate( aInval );
667 aViewWin.Invalidate();
671 if ( _pReq )
672 _pReq->Done();
675 // dann mal alles fuer die SwPagePreView
676 void SwPagePreView::Execute( SfxRequest &rReq )
678 int eMvMode;
679 sal_uInt8 nRow = 1;
680 bool bRetVal = false;
681 bool bRefresh = true;
683 switch(rReq.GetSlot())
685 case FN_REFRESH_VIEW:
686 case FN_STAT_PAGE:
687 case FN_STAT_ZOOM:
688 break;
690 case FN_SHOW_MULTIPLE_PAGES:
692 const SfxItemSet *pArgs = rReq.GetArgs();
693 if( pArgs && pArgs->Count() >= 2 )
695 sal_uInt8 nCols = (sal_uInt8)((SfxUInt16Item &)pArgs->Get(
696 SID_ATTR_TABLE_COLUMN)).GetValue();
697 sal_uInt8 nRows = (sal_uInt8)((SfxUInt16Item &)pArgs->Get(
698 SID_ATTR_TABLE_ROW)).GetValue();
699 aViewWin.CalcWish( nRows, nCols );
702 else
703 SwPreViewZoomDlg( aViewWin ).Execute();
706 break;
707 case FN_SHOW_BOOKVIEW:
709 const SfxItemSet* pArgs = rReq.GetArgs();
710 const SfxPoolItem* pItem;
711 bool bBookPreview = GetViewShell()->GetViewOptions()->IsPagePrevBookview();
712 if( pArgs && SFX_ITEM_SET == pArgs->GetItemState( FN_SHOW_BOOKVIEW, sal_False, &pItem ) )
714 bBookPreview = static_cast< const SfxBoolItem* >( pItem )->GetValue();
715 ( ( SwViewOption* ) GetViewShell()->GetViewOptions() )->SetPagePrevBookview( bBookPreview );
716 // cast is not gentleman like, but it's common use in writer and in this case
718 if ( aViewWin.SetBookPreviewMode( bBookPreview ) )
720 // book preview mode changed. Thus, adjust scrollbars and
721 // invalidate corresponding states.
722 ScrollViewSzChg();
723 static sal_uInt16 aInval[] =
725 FN_START_OF_DOCUMENT, FN_END_OF_DOCUMENT, FN_PAGEUP, FN_PAGEDOWN,
726 FN_STAT_PAGE, FN_SHOW_BOOKVIEW, 0
728 SfxBindings& rBindings = GetViewFrame()->GetBindings();
729 rBindings.Invalidate( aInval );
730 aViewWin.Invalidate();
734 break;
735 case FN_SHOW_TWO_PAGES:
736 aViewWin.CalcWish( nRow, 2 );
737 break;
739 case FN_PREVIEW_ZOOM:
740 case SID_ATTR_ZOOM:
742 const SfxItemSet *pArgs = rReq.GetArgs();
743 const SfxPoolItem* pItem;
744 AbstractSvxZoomDialog *pDlg = 0;
745 if(!pArgs)
747 SfxItemSet aCoreSet(GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM);
748 const SwViewOption* pVOpt = GetViewShell()->GetViewOptions();
749 SvxZoomItem aZoom( (SvxZoomType)pVOpt->GetZoomType(),
750 pVOpt->GetZoom() );
751 aZoom.SetValueSet(
752 SVX_ZOOM_ENABLE_50|
753 SVX_ZOOM_ENABLE_75|
754 SVX_ZOOM_ENABLE_100|
755 SVX_ZOOM_ENABLE_150|
756 SVX_ZOOM_ENABLE_200|
757 SVX_ZOOM_ENABLE_WHOLEPAGE);
758 aCoreSet.Put( aZoom );
760 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
761 if(pFact)
763 pDlg = pFact->CreateSvxZoomDialog(&GetViewFrame()->GetWindow(), aCoreSet);
764 OSL_ENSURE(pDlg, "Dialogdiet fail!");
767 pDlg->SetLimits( MINZOOM, MAXZOOM );
769 if( pDlg->Execute() != RET_CANCEL )
770 pArgs = pDlg->GetOutputItemSet();
772 if( pArgs )
774 enum SvxZoomType eType = SVX_ZOOM_PERCENT;
775 sal_uInt16 nZoomFactor = USHRT_MAX;
776 if(SFX_ITEM_SET == pArgs->GetItemState(SID_ATTR_ZOOM, sal_True, &pItem))
778 eType = ((const SvxZoomItem *)pItem)->GetType();
779 nZoomFactor = ((const SvxZoomItem *)pItem)->GetValue();
781 else if(SFX_ITEM_SET == pArgs->GetItemState(FN_PREVIEW_ZOOM, sal_True, &pItem))
782 nZoomFactor = ((const SfxUInt16Item *)pItem)->GetValue();
783 if(USHRT_MAX != nZoomFactor)
784 SetZoom(eType, nZoomFactor);
786 delete pDlg;
788 break;
789 case SID_ATTR_ZOOMSLIDER :
791 const SfxItemSet *pArgs = rReq.GetArgs();
792 const SfxPoolItem* pItem;
794 if ( pArgs && SFX_ITEM_SET == pArgs->GetItemState(SID_ATTR_ZOOMSLIDER, sal_True, &pItem ) )
796 const sal_uInt16 nCurrentZoom = ((const SvxZoomSliderItem *)pItem)->GetValue();
797 SetZoom( SVX_ZOOM_PERCENT, nCurrentZoom );
800 break;
801 case SID_ZOOM_IN:
802 case SID_ZOOM_OUT:
804 enum SvxZoomType eType = SVX_ZOOM_PERCENT;
805 const SwViewOption* pVOpt = GetViewShell()->GetViewOptions();
806 SetZoom(eType,
807 lcl_GetNextZoomStep(pVOpt->GetZoom(), SID_ZOOM_IN == rReq.GetSlot()));
809 break;
810 case FN_CHAR_LEFT:
811 case FN_CHAR_RIGHT:
812 case FN_LINE_UP:
813 case FN_LINE_DOWN:
815 SwPagePreviewLayout* pPagePrevwLay = GetViewShell()->PagePreviewLayout();
816 sal_uInt16 nNewSelectedPage;
817 sal_uInt16 nNewStartPage;
818 Point aNewStartPos;
819 sal_Int16 nHoriMove = 0;
820 sal_Int16 nVertMove = 0;
821 switch(rReq.GetSlot())
823 case FN_CHAR_LEFT: nHoriMove = -1; break;
824 case FN_CHAR_RIGHT: nHoriMove = 1; break;
825 case FN_LINE_UP: nVertMove = -1; break;
826 case FN_LINE_DOWN: nVertMove = 1; break;
828 pPagePrevwLay->CalcStartValuesForSelectedPageMove( nHoriMove, nVertMove,
829 nNewSelectedPage, nNewStartPage, aNewStartPos );
830 if ( aViewWin.SelectedPage() != nNewSelectedPage )
832 if ( pPagePrevwLay->IsPageVisible( nNewSelectedPage ) )
834 pPagePrevwLay->MarkNewSelectedPage( nNewSelectedPage );
835 // adjust position at vertical scrollbar.
836 SetVScrollbarThumbPos( nNewSelectedPage );
837 bRefresh = false;
839 else
841 aViewWin.SetSelectedPage( nNewSelectedPage );
842 aViewWin.SetSttPage( nNewStartPage );
843 int nRet = ChgPage( SwPagePreViewWin::MV_SELPAGE, sal_True );
844 bRefresh = 0 != nRet;
846 GetViewShell()->ShowPreViewSelection( nNewSelectedPage );
847 // invalidate page status.
848 static sal_uInt16 aInval[] =
850 FN_STAT_PAGE, 0
852 SfxBindings& rBindings = GetViewFrame()->GetBindings();
853 rBindings.Invalidate( aInval );
854 rReq.Done();
856 else
858 bRefresh = false;
860 break;
862 case FN_PAGEUP:
863 case FN_PAGEDOWN:
865 _ExecPgUpAndPgDown( rReq.GetSlot() == FN_PAGEUP, &rReq );
866 break;
868 case FN_START_OF_LINE:
869 case FN_START_OF_DOCUMENT:
870 aViewWin.SetSelectedPage( 1 );
871 eMvMode = SwPagePreViewWin::MV_DOC_STT; bRetVal = true; goto MOVEPAGE;
872 case FN_END_OF_LINE:
873 case FN_END_OF_DOCUMENT:
874 aViewWin.SetSelectedPage( mnPageCount );
875 eMvMode = SwPagePreViewWin::MV_DOC_END; bRetVal = true; goto MOVEPAGE;
876 MOVEPAGE:
878 int nRet = ChgPage( eMvMode, sal_True );
879 // return value fuer Basic
880 if(bRetVal)
881 rReq.SetReturnValue(SfxBoolItem(rReq.GetSlot(), nRet == 0));
883 bRefresh = 0 != nRet;
884 rReq.Done();
886 break;
888 case FN_PRINT_PAGEPREVIEW:
890 const SwPagePreViewPrtData* pPPVPD = aViewWin.GetViewShell()->GetDoc()->GetPreViewPrtData();
891 // die Sache mit der Orientation
892 if(pPPVPD)
894 SfxPrinter* pPrinter = GetPrinter( sal_True );
895 if((pPrinter->GetOrientation() == ORIENTATION_LANDSCAPE)
896 != pPPVPD->GetLandscape())
897 pPrinter->SetOrientation(pPPVPD->GetLandscape() ? ORIENTATION_LANDSCAPE : ORIENTATION_PORTRAIT);
899 ::SetAppPrintOptions( aViewWin.GetViewShell(), sal_False );
900 bNormalPrint = sal_False;
901 sal_uInt16 nPrtSlot = SID_PRINTDOC;
902 rReq.SetSlot( nPrtSlot );
903 SfxViewShell::ExecuteSlot( rReq, SfxViewShell::GetInterface() );
904 rReq.SetSlot( FN_PRINT_PAGEPREVIEW );
905 return;
907 case SID_PRINTDOCDIRECT:
908 case SID_PRINTDOC:
909 ::SetAppPrintOptions( aViewWin.GetViewShell(), sal_False );
910 bNormalPrint = sal_True;
911 SfxViewShell::ExecuteSlot( rReq, SfxViewShell::GetInterface() );
912 return;
913 case FN_CLOSE_PAGEPREVIEW:
914 case SID_PRINTPREVIEW:
915 // print preview is now always in the same frame as the tab view
916 // -> always switch this frame back to normal view
917 // (ScTabViewShell ctor reads stored view data)
918 GetViewFrame()->GetDispatcher()->Execute( SID_VIEWSHELL0, 0, 0, SFX_CALLMODE_ASYNCHRON );
919 break;
920 case FN_INSERT_BREAK:
922 sal_uInt16 nSelPage = aViewWin.SelectedPage();
923 //if a dummy page is selected (e.g. a non-existing right/left page)
924 //the direct neighbor is used
925 if(GetViewShell()->IsDummyPage( nSelPage ) && GetViewShell()->IsDummyPage( --nSelPage ))
926 nSelPage +=2;
927 SetNewPage( nSelPage );
928 SfxViewFrame *pTmpFrm = GetViewFrame();
929 pTmpFrm->GetBindings().Execute( SID_VIEWSHELL0, NULL, 0,
930 SFX_CALLMODE_ASYNCHRON );
932 break;
933 default:
934 OSL_ENSURE(!this, "wrong dispatcher");
935 return;
938 if( bRefresh )
939 aViewWin.Invalidate();
942 void SwPagePreView::GetState( SfxItemSet& rSet )
944 SfxWhichIter aIter(rSet);
945 sal_uInt8 nRow = 1;
946 sal_uInt16 nWhich = aIter.FirstWhich();
947 OSL_ENSURE(nWhich, "empty set");
948 SwPagePreviewLayout* pPagePrevwLay = GetViewShell()->PagePreviewLayout();
950 while(nWhich)
952 switch(nWhich)
954 case SID_BROWSER_MODE:
955 case FN_PRINT_LAYOUT:
956 rSet.DisableItem(nWhich);
957 break;
958 case FN_START_OF_DOCUMENT:
960 if ( pPagePrevwLay->IsPageVisible( 1 ) )
961 rSet.DisableItem(nWhich);
962 break;
964 case FN_END_OF_DOCUMENT:
966 if ( pPagePrevwLay->IsPageVisible( mnPageCount ) )
967 rSet.DisableItem(nWhich);
968 break;
970 case FN_PAGEUP:
972 if( pPagePrevwLay->GetWinPagesScrollAmount( -1 ) == 0 )
973 rSet.DisableItem(nWhich);
974 break;
976 case FN_PAGEDOWN:
978 if( pPagePrevwLay->GetWinPagesScrollAmount( 1 ) == 0 )
979 rSet.DisableItem(nWhich);
980 break;
983 case FN_STAT_PAGE:
985 OUString aStr = sPageStr + aViewWin.GetStatusStr( mnPageCount );
986 rSet.Put( SfxStringItem( nWhich, aStr) );
988 break;
990 case SID_ATTR_ZOOM:
991 case FN_STAT_ZOOM:
993 const SwViewOption* pVOpt = GetViewShell()->GetViewOptions();
994 SvxZoomItem aZoom((SvxZoomType)pVOpt->GetZoomType(),
995 pVOpt->GetZoom());
996 aZoom.SetValueSet(
997 SVX_ZOOM_ENABLE_50|
998 SVX_ZOOM_ENABLE_75|
999 SVX_ZOOM_ENABLE_100|
1000 SVX_ZOOM_ENABLE_150|
1001 SVX_ZOOM_ENABLE_200);
1002 rSet.Put( aZoom );
1004 break;
1005 case SID_ATTR_ZOOMSLIDER :
1007 const SwViewOption* pVOpt = GetViewShell()->GetViewOptions();
1008 const sal_uInt16 nCurrentZoom = pVOpt->GetZoom();
1009 SvxZoomSliderItem aZoomSliderItem( nCurrentZoom, MINZOOM, MAXZOOM );
1010 aZoomSliderItem.AddSnappingPoint( 100 );
1011 rSet.Put( aZoomSliderItem );
1013 break;
1014 case FN_PREVIEW_ZOOM:
1016 const SwViewOption* pVOpt = GetViewShell()->GetViewOptions();
1017 rSet.Put(SfxUInt16Item(nWhich, pVOpt->GetZoom()));
1019 break;
1020 case SID_ZOOM_IN:
1021 case SID_ZOOM_OUT:
1023 const SwViewOption* pVOpt = GetViewShell()->GetViewOptions();
1024 if((SID_ZOOM_OUT == nWhich && pVOpt->GetZoom() >= MAX_PREVIEW_ZOOM)||
1025 (SID_ZOOM_IN == nWhich && pVOpt->GetZoom() <= MIN_PREVIEW_ZOOM))
1027 rSet.DisableItem(nWhich);
1030 break;
1031 case FN_SHOW_MULTIPLE_PAGES:
1032 //should never be disabled
1033 break;
1034 case FN_SHOW_BOOKVIEW:
1036 sal_Bool b = GetViewShell()->GetViewOptions()->IsPagePrevBookview();
1037 rSet.Put(SfxBoolItem(nWhich, b));
1039 break;
1041 case FN_SHOW_TWO_PAGES:
1042 if( 2 == aViewWin.GetCol() && nRow == aViewWin.GetRow() )
1043 rSet.DisableItem( nWhich );
1044 break;
1046 case FN_PRINT_PAGEPREVIEW:
1047 // hat den gleichen Status wie das normale Drucken
1049 const SfxPoolItem* pItem;
1050 SfxItemSet aSet( *rSet.GetPool(), SID_PRINTDOC, SID_PRINTDOC );
1051 GetSlotState( SID_PRINTDOC, SfxViewShell::GetInterface(), &aSet );
1052 if( SFX_ITEM_DISABLED == aSet.GetItemState( SID_PRINTDOC,
1053 sal_False, &pItem ))
1054 rSet.DisableItem( nWhich );
1055 else if( SFX_ITEM_SET == aSet.GetItemState( SID_PRINTDOC,
1056 sal_False, &pItem ))
1058 ((SfxPoolItem*)pItem)->SetWhich( FN_PRINT_PAGEPREVIEW );
1059 rSet.Put( *pItem );
1062 break;
1064 case SID_PRINTPREVIEW:
1065 rSet.Put( SfxBoolItem( nWhich, sal_True ) );
1066 break;
1068 case SID_PRINTDOC:
1069 case SID_PRINTDOCDIRECT:
1070 GetSlotState( nWhich, SfxViewShell::GetInterface(), &rSet );
1071 break;
1073 nWhich = aIter.NextWhich();
1077 void SwPagePreView::StateUndo(SfxItemSet& rSet)
1079 SfxWhichIter aIter(rSet);
1080 sal_uInt16 nWhich = aIter.FirstWhich();
1082 while (nWhich)
1084 rSet.DisableItem(nWhich);
1085 nWhich = aIter.NextWhich();
1089 void SwPagePreView::Init(const SwViewOption * pPrefs)
1091 if ( GetViewShell()->HasDrawView() )
1092 GetViewShell()->GetDrawView()->SetAnimationEnabled( sal_False );
1094 bNormalPrint = sal_True;
1096 // Die DocSize erfragen und verarbeiten. Ueber die Handler konnte
1097 // die Shell nicht gefunden werden, weil die Shell innerhalb CTOR-Phase
1098 // nicht in der SFX-Verwaltung bekannt ist.
1100 if( !pPrefs )
1101 pPrefs = SW_MOD()->GetUsrPref(sal_False);
1103 mbHScrollbarEnabled = pPrefs->IsViewHScrollBar();
1104 mbVScrollbarEnabled = pPrefs->IsViewVScrollBar();
1106 // die Felder aktualisieren
1107 // ACHTUNG: hochcasten auf die EditShell, um die SS zu nutzen.
1108 // In den Methoden wird auf die akt. Shell abgefragt!
1109 SwEditShell* pESh = (SwEditShell*)GetViewShell();
1110 sal_Bool bIsModified = pESh->IsModified();
1113 SwViewOption aOpt( *pPrefs );
1114 aOpt.SetPagePreview(sal_True);
1115 aOpt.SetTab( sal_False );
1116 aOpt.SetBlank( sal_False );
1117 aOpt.SetHardBlank( sal_False );
1118 aOpt.SetParagraph( sal_False );
1119 aOpt.SetLineBreak( sal_False );
1120 aOpt.SetPageBreak( sal_False );
1121 aOpt.SetColumnBreak( sal_False );
1122 aOpt.SetSoftHyph( sal_False );
1123 aOpt.SetFldName( sal_False );
1124 aOpt.SetPostIts( sal_False );
1125 aOpt.SetShowHiddenChar( sal_False );
1126 aOpt.SetShowHiddenField( sal_False );
1127 aOpt.SetShowHiddenPara( sal_False );
1128 aOpt.SetViewHRuler( sal_False );
1129 aOpt.SetViewVRuler( sal_False );
1130 aOpt.SetGraphic( sal_True );
1131 aOpt.SetTable( sal_True );
1132 aOpt.SetSnap( sal_False );
1133 aOpt.SetGridVisible( sal_False );
1135 GetViewShell()->ApplyViewOptions( aOpt );
1136 GetViewShell()->ApplyAccessiblityOptions(SW_MOD()->GetAccessibilityOptions());
1138 // adjust view shell option to the same as for print
1139 SwPrintData const aPrintOptions = *SW_MOD()->GetPrtOptions(false);
1140 GetViewShell()->AdjustOptionsForPagePreview( aPrintOptions );
1142 GetViewShell()->CalcLayout();
1143 DocSzChgd( GetViewShell()->GetDocSize() );
1145 if( !bIsModified )
1146 pESh->ResetModified();
1149 SwPagePreView::SwPagePreView(SfxViewFrame *pViewFrame, SfxViewShell* pOldSh):
1150 SfxViewShell( pViewFrame, SWVIEWFLAGS ),
1151 aViewWin( &pViewFrame->GetWindow(), *this ),
1152 nNewPage(USHRT_MAX),
1153 sPageStr(SW_RES(STR_PAGE)),
1154 pHScrollbar(0),
1155 pVScrollbar(0),
1156 pPageUpBtn(0),
1157 pPageDownBtn(0),
1158 pScrollFill(new ScrollBarBox( &pViewFrame->GetWindow(),
1159 pViewFrame->GetFrame().GetParentFrame() ? 0 : WB_SIZEABLE )),
1160 mnPageCount( 0 ),
1161 mbResetFormDesignMode( false ),
1162 mbFormDesignModeToReset( false )
1164 SetName(OUString("PageView" ));
1165 SetWindow( &aViewWin );
1166 SetHelpId(SW_PAGEPREVIEW);
1167 _CreateScrollbar( sal_True );
1168 _CreateScrollbar( sal_False );
1170 SfxObjectShell* pObjShell = pViewFrame->GetObjectShell();
1171 if ( !pOldSh )
1173 //Gibt es schon eine Sicht auf das Dokument?
1174 SfxViewFrame *pF = SfxViewFrame::GetFirst( pObjShell );
1175 if ( pF == pViewFrame )
1176 pF = SfxViewFrame::GetNext( *pF, pObjShell );
1177 if ( pF )
1178 pOldSh = pF->GetViewShell();
1181 ViewShell *pVS, *pNew;
1183 if( pOldSh && pOldSh->IsA( TYPE( SwPagePreView ) ) )
1184 pVS = ((SwPagePreView*)pOldSh)->GetViewShell();
1185 else
1187 if( pOldSh && pOldSh->IsA( TYPE( SwView ) ) )
1189 pVS = ((SwView*)pOldSh)->GetWrtShellPtr();
1190 // save the current ViewData of the previous SwView
1191 pOldSh->WriteUserData( sSwViewData, sal_False );
1193 else
1194 pVS = GetDocShell()->GetWrtShell();
1195 if( pVS )
1197 // setze die akt. Seite als die erste
1198 sal_uInt16 nPhysPg, nVirtPg;
1199 ((SwCrsrShell*)pVS)->GetPageNum( nPhysPg, nVirtPg, sal_True, sal_False );
1200 if( 1 != aViewWin.GetCol() && 1 == nPhysPg )
1201 --nPhysPg;
1202 aViewWin.SetSttPage( nPhysPg );
1206 // for form shell remember design mode of draw view
1207 // of previous view shell
1208 if ( pVS && pVS->HasDrawView() )
1210 mbResetFormDesignMode = true;
1211 mbFormDesignModeToReset = pVS->GetDrawView()->IsDesignMode();
1214 if( pVS )
1215 pNew = new ViewShell( *pVS, &aViewWin, 0, VSHELLFLAG_ISPREVIEW );
1216 else
1217 pNew = new ViewShell(
1218 *((SwDocShell*)pViewFrame->GetObjectShell())->GetDoc(),
1219 &aViewWin, 0, 0, VSHELLFLAG_ISPREVIEW );
1221 aViewWin.SetViewShell( pNew );
1222 pNew->SetSfxViewShell( this );
1223 Init();
1226 SwPagePreView::~SwPagePreView()
1228 SetWindow( 0 );
1230 delete pScrollFill;
1231 delete pHScrollbar;
1232 delete pVScrollbar;
1233 delete pPageUpBtn;
1234 delete pPageDownBtn;
1238 SwDocShell* SwPagePreView::GetDocShell()
1240 return PTR_CAST(SwDocShell, GetViewFrame()->GetObjectShell());
1243 int SwPagePreView::_CreateScrollbar( sal_Bool bHori )
1245 Window *pMDI = &GetViewFrame()->GetWindow();
1246 SwScrollbar** ppScrollbar = bHori ? &pHScrollbar : &pVScrollbar;
1248 OSL_ENSURE( !*ppScrollbar, "vorher abpruefen!" );
1250 if( !bHori )
1253 pPageUpBtn = new ImageButton(pMDI, SW_RES( BTN_PAGEUP ) );
1254 pPageUpBtn->SetHelpId(GetStaticInterface()->GetSlot(FN_PAGEUP)->GetCommand());
1255 pPageDownBtn = new ImageButton(pMDI, SW_RES( BTN_PAGEDOWN ) );
1256 pPageDownBtn->SetHelpId(GetStaticInterface()->GetSlot(FN_PAGEDOWN)->GetCommand());
1257 Link aLk( LINK( this, SwPagePreView, BtnPage ) );
1258 pPageUpBtn->SetClickHdl( aLk );
1259 pPageDownBtn->SetClickHdl( aLk );
1260 pPageUpBtn->Show();
1261 pPageDownBtn->Show();
1264 *ppScrollbar = new SwScrollbar( pMDI, bHori );
1266 ScrollDocSzChg();
1267 (*ppScrollbar)->EnableDrag( sal_True );
1268 (*ppScrollbar)->SetEndScrollHdl( LINK( this, SwPagePreView, EndScrollHdl ));
1271 (*ppScrollbar)->SetScrollHdl( LINK( this, SwPagePreView, ScrollHdl ));
1273 InvalidateBorder();
1274 (*ppScrollbar)->ExtendedShow();
1275 return 1;
1279 * Button-Handler
1281 IMPL_LINK_INLINE_START( SwPagePreView, BtnPage, Button *, pButton )
1283 // use new helper method to perform page up
1284 // respectively page down.
1285 _ExecPgUpAndPgDown( pButton == pPageUpBtn );
1286 return 0;
1288 IMPL_LINK_INLINE_END( SwPagePreView, BtnPage, Button *, pButton )
1290 int SwPagePreView::ChgPage( int eMvMode, int bUpdateScrollbar )
1292 Rectangle aPixVisArea( aViewWin.LogicToPixel( aVisArea ) );
1293 int bChg = aViewWin.MovePage( eMvMode ) ||
1294 eMvMode == SwPagePreViewWin::MV_CALC ||
1295 eMvMode == SwPagePreViewWin::MV_NEWWINSIZE;
1296 aVisArea = aViewWin.PixelToLogic( aPixVisArea );
1298 if( bChg )
1300 // Statusleiste updaten
1301 OUString aStr = sPageStr + aViewWin.GetStatusStr( mnPageCount );
1302 SfxBindings& rBindings = GetViewFrame()->GetBindings();
1304 if( bUpdateScrollbar )
1306 ScrollViewSzChg();
1308 static sal_uInt16 aInval[] =
1310 FN_START_OF_DOCUMENT, FN_END_OF_DOCUMENT,
1311 FN_PAGEUP, FN_PAGEDOWN, 0
1313 rBindings.Invalidate( aInval );
1315 rBindings.SetState( SfxStringItem( FN_STAT_PAGE, aStr ) );
1317 return bChg;
1320 // ab hier alles aus der SwView uebernommen
1321 void SwPagePreView::CalcAndSetBorderPixel( SvBorder &rToFill, sal_Bool /*bInner*/ )
1323 const StyleSettings &rSet = aViewWin.GetSettings().GetStyleSettings();
1324 const long nTmp = rSet.GetScrollBarSize();
1325 if ( pVScrollbar->IsVisible( true ) )
1326 rToFill.Right() = nTmp;
1327 if ( pHScrollbar->IsVisible( true ) )
1328 rToFill.Bottom() = nTmp;
1329 SetBorderPixel( rToFill );
1332 void SwPagePreView::InnerResizePixel( const Point &rOfst, const Size &rSize )
1334 SvBorder aBorder;
1335 CalcAndSetBorderPixel( aBorder, sal_True );
1336 Rectangle aRect( rOfst, rSize );
1337 aRect += aBorder;
1338 ViewResizePixel( aViewWin, aRect.TopLeft(), aRect.GetSize(),
1339 aViewWin.GetOutputSizePixel(),
1340 sal_True,
1341 *pVScrollbar, *pHScrollbar, pPageUpBtn, pPageDownBtn, 0,
1342 *pScrollFill );
1344 //EditWin niemals einstellen!
1345 //VisArea niemals einstellen!
1348 void SwPagePreView::OuterResizePixel( const Point &rOfst, const Size &rSize )
1350 SvBorder aBorder;
1351 CalcAndSetBorderPixel( aBorder, sal_False );
1353 //EditWin niemals einstellen!
1355 Size aTmpSize( aViewWin.GetOutputSizePixel() );
1356 Point aBottomRight( aViewWin.PixelToLogic( Point( aTmpSize.Width(), aTmpSize.Height() ) ) );
1357 SetVisArea( Rectangle( Point(), aBottomRight ) );
1359 //Aufruf der DocSzChgd-Methode der Scrollbars ist noetig, da vom maximalen
1360 //Scrollrange immer die halbe Hoehe der VisArea abgezogen wird.
1361 if ( pVScrollbar && aTmpSize.Width() > 0 && aTmpSize.Height() > 0 )
1363 ScrollDocSzChg();
1366 SvBorder aBorderNew;
1367 CalcAndSetBorderPixel( aBorderNew, sal_False );
1368 ViewResizePixel( aViewWin, rOfst, rSize, aViewWin.GetOutputSizePixel(),
1369 sal_False, *pVScrollbar,
1370 *pHScrollbar, pPageUpBtn, pPageDownBtn, 0, *pScrollFill );
1373 void SwPagePreView::SetVisArea( const Rectangle &rRect, sal_Bool bUpdateScrollbar )
1375 const Point aTopLeft(AlignToPixel(rRect.TopLeft()));
1376 const Point aBottomRight(AlignToPixel(rRect.BottomRight()));
1377 Rectangle aLR(aTopLeft,aBottomRight);
1379 if(aLR == aVisArea)
1380 return;
1381 // keine negative Position, keine neg. Groesse
1383 if(aLR.Top() < 0)
1385 aLR.Bottom() += std::abs(aLR.Top());
1386 aLR.Top() = 0;
1389 if(aLR.Left() < 0)
1391 aLR.Right() += std::abs(aLR.Left());
1392 aLR.Left() = 0;
1394 if(aLR.Right() < 0) aLR.Right() = 0;
1395 if(aLR.Bottom() < 0) aLR.Bottom() = 0;
1396 if(aLR == aVisArea ||
1397 // Leeres Rechteck nicht beachten
1398 ( 0 == aLR.Bottom() - aLR.Top() && 0 == aLR.Right() - aLR.Left() ) )
1399 return;
1401 if( aLR.Left() > aLR.Right() || aLR.Top() > aLR.Bottom() )
1402 return;
1404 //Bevor die Daten veraendert werden ggf. ein Update rufen. Dadurch wird
1405 //sichergestellt, da? anliegende Paints korrekt in Dokumentkoordinaten
1406 //umgerechnet werden.
1407 //Vorsichtshalber tun wir das nur wenn an der Shell eine Action laeuft,
1408 //denn dann wir nicht wirklich gepaintet sondern die Rechtecke werden
1409 //lediglich (in Dokumentkoordinaten) vorgemerkt.
1410 if( GetViewShell()->ActionPend() )
1411 aViewWin.Update();
1413 // setze am View-Win die aktuelle Size
1414 aVisArea = aLR;
1415 aViewWin.SetWinSize( aLR.GetSize() );
1416 ChgPage( SwPagePreViewWin::MV_NEWWINSIZE, bUpdateScrollbar );
1418 aViewWin.Invalidate();
1421 IMPL_LINK( SwPagePreView, ScrollHdl, SwScrollbar *, pScrollbar )
1423 if(!GetViewShell())
1424 return 0;
1425 if( !pScrollbar->IsHoriScroll() &&
1426 pScrollbar->GetType() == SCROLL_DRAG &&
1427 Help::IsQuickHelpEnabled() &&
1428 GetViewShell()->PagePreviewLayout()->DoesPreviewLayoutRowsFitIntoWindow())
1430 // wieviele Seiten scrollen ??
1431 String sStateStr(sPageStr);
1432 sal_uInt16 nThmbPos = (sal_uInt16)pScrollbar->GetThumbPos();
1433 if( 1 == aViewWin.GetCol() || !nThmbPos )
1434 ++nThmbPos;
1435 sStateStr += OUString::number( nThmbPos );
1436 Point aPos = pScrollbar->GetParent()->OutputToScreenPixel(
1437 pScrollbar->GetPosPixel());
1438 aPos.Y() = pScrollbar->OutputToScreenPixel(pScrollbar->GetPointerPosPixel()).Y();
1439 Rectangle aRect;
1440 aRect.Left() = aPos.X() -8;
1441 aRect.Right() = aRect.Left();
1442 aRect.Top() = aPos.Y();
1443 aRect.Bottom() = aRect.Top();
1445 Help::ShowQuickHelp(pScrollbar, aRect, sStateStr,
1446 QUICKHELP_RIGHT|QUICKHELP_VCENTER);
1449 else
1450 EndScrollHdl( pScrollbar );
1451 return 0;
1454 IMPL_LINK( SwPagePreView, EndScrollHdl, SwScrollbar *, pScrollbar )
1456 if(!GetViewShell())
1457 return 0;
1459 // boolean to avoid unnecessary invalidation of the window.
1460 bool bInvalidateWin = true;
1462 if( !pScrollbar->IsHoriScroll() ) // scroll vertically
1464 if ( Help::IsQuickHelpEnabled() )
1465 Help::ShowQuickHelp(pScrollbar, Rectangle(), aEmptyStr, 0);
1466 if ( GetViewShell()->PagePreviewLayout()->DoesPreviewLayoutRowsFitIntoWindow() )
1468 // wieviele Seiten scrollen ??
1469 sal_uInt16 nThmbPos = (sal_uInt16)pScrollbar->GetThumbPos();
1470 // adjust to new preview functionality
1471 if( nThmbPos != aViewWin.SelectedPage() )
1473 // consider case that page <nThmbPos>
1474 // is already visible
1475 SwPagePreviewLayout* pPagePrevwLay = GetViewShell()->PagePreviewLayout();
1476 if ( pPagePrevwLay->IsPageVisible( nThmbPos ) )
1478 pPagePrevwLay->MarkNewSelectedPage( nThmbPos );
1479 // invalidation of window is unnecessary
1480 bInvalidateWin = false;
1482 else
1484 // consider whether layout columns
1485 // fit or not.
1486 if ( !pPagePrevwLay->DoesPreviewLayoutColsFitIntoWindow() )
1488 aViewWin.SetSttPage( nThmbPos );
1489 aViewWin.SetSelectedPage( nThmbPos );
1490 ChgPage( SwPagePreViewWin::MV_SCROLL, sal_False );
1491 // update scrollbars
1492 ScrollViewSzChg();
1494 else
1496 // correct scroll amount
1497 const sal_Int16 nPageDiff = nThmbPos - aViewWin.SelectedPage();
1498 const sal_uInt16 nVisPages = aViewWin.GetRow() * aViewWin.GetCol();
1499 sal_Int16 nWinPagesToScroll = nPageDiff / nVisPages;
1500 if ( nPageDiff % nVisPages )
1502 // decrease/increase number of preview pages to scroll
1503 nPageDiff < 0 ? --nWinPagesToScroll : ++nWinPagesToScroll;
1505 aViewWin.SetSelectedPage( nThmbPos );
1506 aViewWin.Scroll( 0, pPagePrevwLay->GetWinPagesScrollAmount( nWinPagesToScroll ) );
1509 // update accessibility
1510 GetViewShell()->ShowPreViewSelection( nThmbPos );
1512 else
1514 // invalidation of window is unnecessary
1515 bInvalidateWin = false;
1518 else
1520 long nThmbPos = pScrollbar->GetThumbPos();
1521 aViewWin.Scroll(0, nThmbPos - aViewWin.GetPaintedPreviewDocRect().Top());
1524 else
1526 long nThmbPos = pScrollbar->GetThumbPos();
1527 aViewWin.Scroll(nThmbPos - aViewWin.GetPaintedPreviewDocRect().Left(), 0);
1529 // additional invalidate page status.
1530 static sal_uInt16 aInval[] =
1532 FN_START_OF_DOCUMENT, FN_END_OF_DOCUMENT, FN_PAGEUP, FN_PAGEDOWN,
1533 FN_STAT_PAGE, 0
1535 SfxBindings& rBindings = GetViewFrame()->GetBindings();
1536 rBindings.Invalidate( aInval );
1537 // control invalidation of window
1538 if ( bInvalidateWin )
1540 aViewWin.Invalidate();
1542 return 0;
1545 Point SwPagePreView::AlignToPixel(const Point &rPt) const
1547 return aViewWin.PixelToLogic( aViewWin.LogicToPixel( rPt ) );
1550 void SwPagePreView::DocSzChgd( const Size &rSz )
1552 if( aDocSz == rSz )
1553 return;
1555 aDocSz = rSz;
1557 // #i96726#
1558 // Due to the multiple page layout it is needed to trigger recalculation
1559 // of the page preview layout, even if the count of pages is not changing.
1560 mnPageCount = GetViewShell()->GetNumPages();
1562 if( aVisArea.GetWidth() )
1564 ChgPage( SwPagePreViewWin::MV_CALC, sal_True );
1565 ScrollDocSzChg();
1567 aViewWin.Invalidate();
1571 void SwPagePreView::ScrollViewSzChg()
1573 if(!GetViewShell())
1574 return ;
1576 bool bShowVScrollbar = false, bShowHScrollbar = false;
1578 if(pVScrollbar)
1580 if(GetViewShell()->PagePreviewLayout()->DoesPreviewLayoutRowsFitIntoWindow())
1582 //vertical scrolling by row
1583 // adjust to new preview functionality
1584 sal_uInt16 nVisPages = aViewWin.GetRow() * aViewWin.GetCol();
1586 pVScrollbar->SetVisibleSize( nVisPages );
1587 // set selected page as scroll bar position,
1588 // if it is visible.
1589 SwPagePreviewLayout* pPagePrevwLay = GetViewShell()->PagePreviewLayout();
1590 if ( pPagePrevwLay->IsPageVisible( aViewWin.SelectedPage() ) )
1592 pVScrollbar->SetThumbPos( aViewWin.SelectedPage() );
1594 else
1596 pVScrollbar->SetThumbPos( aViewWin.GetSttPage() );
1598 pVScrollbar->SetLineSize( aViewWin.GetCol() );
1599 pVScrollbar->SetPageSize( nVisPages );
1600 // calculate and set scrollbar range
1601 Range aScrollbarRange( 1, mnPageCount );
1602 // increase range by one, because left-top-corner is left blank.
1603 ++aScrollbarRange.Max();
1604 // increase range in order to access all pages
1605 aScrollbarRange.Max() += ( nVisPages - 1 );
1606 pVScrollbar->SetRange( aScrollbarRange );
1608 bShowVScrollbar = nVisPages < mnPageCount;
1610 else //vertical scrolling by pixel
1612 const Rectangle& rDocRect = aViewWin.GetPaintedPreviewDocRect();
1613 const Size& rPreviewSize =
1614 GetViewShell()->PagePreviewLayout()->GetPrevwDocSize();
1615 pVScrollbar->SetRangeMax(rPreviewSize.Height()) ;
1616 long nVisHeight = rDocRect.GetHeight();
1617 pVScrollbar->SetVisibleSize( nVisHeight );
1618 pVScrollbar->SetThumbPos( rDocRect.Top() );
1619 pVScrollbar->SetLineSize( nVisHeight / 10 );
1620 pVScrollbar->SetPageSize( nVisHeight / 2 );
1622 bShowVScrollbar = true;
1625 if (!mbVScrollbarEnabled)
1626 bShowVScrollbar = false;
1628 ShowVScrollbar(bShowVScrollbar);
1629 pPageUpBtn->Show(bShowVScrollbar);
1630 pPageDownBtn->Show(bShowVScrollbar);
1632 if(pHScrollbar)
1634 const Rectangle& rDocRect = aViewWin.GetPaintedPreviewDocRect();
1635 const Size& rPreviewSize =
1636 GetViewShell()->PagePreviewLayout()->GetPrevwDocSize();
1637 long nVisWidth = 0;
1638 long nThumb = 0;
1639 Range aRange(0,0);
1641 if(rDocRect.GetWidth() < rPreviewSize.Width())
1643 bShowHScrollbar = true;
1645 nVisWidth = rDocRect.GetWidth();
1646 nThumb = rDocRect.Left();
1647 aRange = Range(0, rPreviewSize.Width());
1649 pHScrollbar->SetRange( aRange );
1650 pHScrollbar->SetVisibleSize( nVisWidth );
1651 pHScrollbar->SetThumbPos( nThumb );
1652 pHScrollbar->SetLineSize( nVisWidth / 10 );
1653 pHScrollbar->SetPageSize( nVisWidth / 2 );
1656 if (!mbHScrollbarEnabled)
1657 bShowHScrollbar = false;
1659 ShowHScrollbar(bShowHScrollbar);
1661 pScrollFill->Show(bShowVScrollbar && bShowHScrollbar);
1664 void SwPagePreView::ScrollDocSzChg()
1666 ScrollViewSzChg();
1669 // alles zum Thema Drucken
1670 SfxPrinter* SwPagePreView::GetPrinter( sal_Bool bCreate )
1672 return aViewWin.GetViewShell()->getIDocumentDeviceAccess()->getPrinter( bCreate );
1675 sal_uInt16 SwPagePreView::SetPrinter( SfxPrinter *pNew, sal_uInt16 nDiffFlags, bool )
1677 ViewShell &rSh = *GetViewShell();
1678 SfxPrinter* pOld = rSh.getIDocumentDeviceAccess()->getPrinter( false );
1679 if ( pOld && pOld->IsPrinting() )
1680 return SFX_PRINTERROR_BUSY;
1682 SwEditShell &rESh = (SwEditShell&)rSh; //Buh...
1683 if( ( SFX_PRINTER_PRINTER | SFX_PRINTER_JOBSETUP ) & nDiffFlags )
1685 rSh.getIDocumentDeviceAccess()->setPrinter( pNew, true, true );
1686 if( nDiffFlags & SFX_PRINTER_PRINTER )
1687 rESh.SetModified();
1689 if ( ( nDiffFlags & SFX_PRINTER_OPTIONS ) == SFX_PRINTER_OPTIONS )
1690 ::SetPrinter( rSh.getIDocumentDeviceAccess(), pNew, sal_False );
1692 const bool bChgOri = nDiffFlags & SFX_PRINTER_CHG_ORIENTATION;
1693 const bool bChgSize= nDiffFlags & SFX_PRINTER_CHG_SIZE;
1694 if ( bChgOri || bChgSize )
1696 rESh.StartAllAction();
1697 if ( bChgOri )
1698 rSh.ChgAllPageOrientation( sal_uInt16(pNew->GetOrientation()) );
1699 if ( bChgSize )
1701 Size aSz( SvxPaperInfo::GetPaperSize( pNew ) );
1702 rSh.ChgAllPageSize( aSz );
1704 if( !bNormalPrint )
1705 aViewWin.CalcWish( aViewWin.GetRow(), aViewWin.GetCol() );
1706 rESh.SetModified();
1707 rESh.EndAllAction();
1709 static sal_uInt16 aInval[] =
1711 SID_ATTR_LONG_ULSPACE, SID_ATTR_LONG_LRSPACE,
1712 SID_RULER_BORDERS, SID_RULER_PAGE_POS, 0
1714 #if OSL_DEBUG_LEVEL > 0
1716 const sal_uInt16* pPtr = aInval + 1;
1717 do {
1718 OSL_ENSURE( *(pPtr - 1) < *pPtr, "wrong sorting!" );
1719 } while( *++pPtr );
1721 #endif
1723 GetViewFrame()->GetBindings().Invalidate(aInval);
1726 return 0;
1729 bool SwPagePreView::HasPrintOptionsPage() const
1731 return true;
1734 SfxTabPage* SwPagePreView::CreatePrintOptionsPage( Window *pParent,
1735 const SfxItemSet &rOptions )
1737 return ::CreatePrintOptionsPage( pParent, rOptions, !bNormalPrint );
1740 void SwPagePreViewWin::SetViewShell( ViewShell* pShell )
1742 mpViewShell = pShell;
1743 if ( mpViewShell && mpViewShell->IsPreView() )
1745 mpPgPrevwLayout = mpViewShell->PagePreviewLayout();
1749 void SwPagePreViewWin::RepaintCoreRect( const SwRect& rRect )
1751 // #i24183#
1752 if ( mpPgPrevwLayout->PreviewLayoutValid() )
1754 mpPgPrevwLayout->Repaint( Rectangle( rRect.Pos(), rRect.SSize() ) );
1758 /** method to adjust preview to a new zoom factor
1760 #i19975# also consider zoom type - adding parameter <_eZoomType>
1762 void SwPagePreViewWin::AdjustPreviewToNewZoom( const sal_uInt16 _nZoomFactor,
1763 const SvxZoomType _eZoomType )
1765 // #i19975# consider zoom type
1766 if ( _eZoomType == SVX_ZOOM_WHOLEPAGE )
1768 mnRow = 1;
1769 mnCol = 1;
1770 mpPgPrevwLayout->Init( mnCol, mnRow, maPxWinSize, true );
1771 mpPgPrevwLayout->Prepare( mnSttPage, Point(0,0), maPxWinSize,
1772 mnSttPage, maPaintedPreviewDocRect );
1773 SetSelectedPage( mnSttPage );
1774 SetPagePreview(mnRow, mnCol);
1775 maScale = GetMapMode().GetScaleX();
1777 else if ( _nZoomFactor != 0 )
1779 // calculate new scaling and set mapping mode appropriately.
1780 Fraction aNewScale( _nZoomFactor, 100 );
1781 MapMode aNewMapMode = GetMapMode();
1782 aNewMapMode.SetScaleX( aNewScale );
1783 aNewMapMode.SetScaleY( aNewScale );
1784 SetMapMode( aNewMapMode );
1786 // calculate new start position for preview paint
1787 Size aNewWinSize = PixelToLogic( maPxWinSize );
1788 Point aNewPaintStartPos =
1789 mpPgPrevwLayout->GetPreviewStartPosForNewScale( aNewScale, maScale, aNewWinSize );
1791 // remember new scaling and prepare preview paint
1792 // Note: paint of preview will be performed by a corresponding invalidate
1793 // due to property changes.
1794 maScale = aNewScale;
1795 mpPgPrevwLayout->Prepare( 0, aNewPaintStartPos, maPxWinSize,
1796 mnSttPage, maPaintedPreviewDocRect );
1802 * pixel scrolling - horizontally always or vertically
1803 * when less than the desired number of rows fits into
1804 * the view
1806 void SwPagePreViewWin::Scroll(long nXMove, long nYMove, sal_uInt16 /*nFlags*/)
1808 maPaintedPreviewDocRect.Move(nXMove, nYMove);
1809 mpPgPrevwLayout->Prepare( 0, maPaintedPreviewDocRect.TopLeft(),
1810 maPxWinSize, mnSttPage,
1811 maPaintedPreviewDocRect );
1815 sal_Bool SwPagePreView::HandleWheelCommands( const CommandEvent& rCEvt )
1817 sal_Bool bOk = sal_False;
1818 const CommandWheelData* pWData = rCEvt.GetWheelData();
1819 if( pWData && COMMAND_WHEEL_ZOOM == pWData->GetMode() )
1821 if(!Application::GetSettings().GetMiscSettings().GetEnableATToolSupport())
1823 sal_uInt16 nFactor = GetViewShell()->GetViewOptions()->GetZoom();
1824 const sal_uInt16 nOffset = 10;
1825 if( 0L > pWData->GetDelta() )
1827 nFactor -= nOffset;
1828 if(nFactor < MIN_PREVIEW_ZOOM)
1829 nFactor = MIN_PREVIEW_ZOOM;
1831 else
1833 nFactor += nOffset;
1834 if(nFactor > MAX_PREVIEW_ZOOM)
1835 nFactor = MAX_PREVIEW_ZOOM;
1837 SetZoom(SVX_ZOOM_PERCENT, nFactor);
1839 bOk = sal_True;
1841 else
1842 bOk = aViewWin.HandleScrollCommand( rCEvt, pHScrollbar, pVScrollbar );
1843 return bOk;
1846 uno::Reference< ::com::sun::star::accessibility::XAccessible >
1847 SwPagePreViewWin::CreateAccessible()
1849 SolarMutexGuard aGuard; // this should have happened already!!!
1851 OSL_ENSURE( GetViewShell() != NULL, "We need a view shell" );
1852 return GetViewShell()->CreateAccessiblePreview();
1855 void SwPagePreView::ApplyAccessiblityOptions(SvtAccessibilityOptions& rAccessibilityOptions)
1857 GetViewShell()->ApplyAccessiblityOptions(rAccessibilityOptions);
1860 void SwPagePreView::ShowHScrollbar(sal_Bool bShow)
1862 pHScrollbar->Show(bShow);
1863 InvalidateBorder();
1866 void SwPagePreView::ShowVScrollbar(sal_Bool bShow)
1868 pVScrollbar->Show(bShow);
1869 InvalidateBorder();
1872 void SwPagePreView::EnableHScrollbar(bool bEnable)
1874 if (mbHScrollbarEnabled != bEnable)
1876 mbHScrollbarEnabled = bEnable;
1877 ScrollViewSzChg();
1881 void SwPagePreView::EnableVScrollbar(bool bEnable)
1883 if (mbVScrollbarEnabled != bEnable)
1885 mbVScrollbarEnabled = bEnable;
1886 ScrollViewSzChg();
1890 void SwPagePreView::SetZoom(SvxZoomType eType, sal_uInt16 nFactor)
1892 ViewShell& rSh = *GetViewShell();
1893 SwViewOption aOpt(*rSh.GetViewOptions());
1894 // perform action only on changes of zoom or zoom type.
1895 if ( aOpt.GetZoom() != nFactor ||
1896 aOpt.GetZoomType() != eType )
1898 aOpt.SetZoom(nFactor);
1899 aOpt.SetZoomType(eType);
1900 rSh.ApplyViewOptions( aOpt );
1901 lcl_InvalidateZoomSlots(GetViewFrame()->GetBindings());
1902 // #i19975# also consider zoom type
1903 aViewWin.AdjustPreviewToNewZoom( nFactor, eType );
1904 ScrollViewSzChg();
1908 /** adjust position of vertical scrollbar
1910 @author OD
1912 void SwPagePreView::SetVScrollbarThumbPos( const sal_uInt16 _nNewThumbPos )
1914 if ( pVScrollbar )
1916 pVScrollbar->SetThumbPos( _nNewThumbPos );
1920 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */