1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 5 * This Source Code Form is subject to the terms of the Mozilla Public 6 * License, v. 2.0. If a copy of the MPL was not distributed with this 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 11 * Licensed to the Apache Software Foundation (ASF) under one or more 12 * contributor license agreements. See the NOTICE file distributed 13 * with this work for additional information regarding copyright 14 * ownership. The ASF licenses this file to you under the Apache 15 * License, Version 2.0 (the "License"); you may not use this file 16 * except in compliance with the License. You may obtain a copy of 17 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 18 */ 19 20 #include <sfx2/objface.hxx> 21 #include <vcl/timer.hxx> 22 #include <vcl/field.hxx> 23 #include <vcl/fixed.hxx> 24 #include <vcl/help.hxx> 25 #include <vcl/commandevent.hxx> 26 #include <vcl/button.hxx> 27 #include <vcl/settings.hxx> 28 #include <vcl/weld.hxx> 29 30 #include <svl/whiter.hxx> 31 #include <svl/stritem.hxx> 32 #include <svl/eitem.hxx> 33 #include <sfx2/printer.hxx> 34 #include <sfx2/progress.hxx> 35 #include <sfx2/app.hxx> 36 #include <sfx2/bindings.hxx> 37 #include <sfx2/request.hxx> 38 #include <sfx2/dispatch.hxx> 39 #include <svx/stddlg.hxx> 40 #include <editeng/paperinf.hxx> 41 #include <svl/srchitem.hxx> 42 #include <svx/svdview.hxx> 43 #include <svx/dlgutil.hxx> 44 #include <svx/zoomslideritem.hxx> 45 #include <svx/svxids.hrc> 46 47 #include <swwait.hxx> 48 #include <globdoc.hxx> 49 #include <wdocsh.hxx> 50 #include <pvprtdat.hxx> 51 #include <swmodule.hxx> 52 #include <modcfg.hxx> 53 #include <wrtsh.hxx> 54 #include <docsh.hxx> 55 #include <viewopt.hxx> 56 #include <doc.hxx> 57 #include <IDocumentDeviceAccess.hxx> 58 #include <pview.hxx> 59 #include <view.hxx> 60 #include <textsh.hxx> 61 #include <scroll.hxx> 62 #include <prtopt.hxx> 63 #include <docstat.hxx> 64 #include <usrpref.hxx> 65 #include "viewfunc.hxx" 66 67 #include <helpids.h> 68 #include <cmdid.h> 69 #include <globals.hrc> 70 #include <strings.hrc> 71 72 #define ShellClass_SwPagePreview 73 #include <sfx2/msg.hxx> 74 #include <swslots.hxx> 75 #include <pagepreviewlayout.hxx> 76 77 #include <svx/svxdlg.hxx> 78 #include <svx/dialogs.hrc> 79 80 #include <memory> 81 #include <vcl/EnumContext.hxx> 82 #include <vcl/notebookbar.hxx> 83 #include <prevwpage.hxx> 84 85 using namespace ::com::sun::star; 86 SFX_IMPL_NAMED_VIEWFACTORY(SwPagePreview, "PrintPreview") 87 { 88 SFX_VIEW_REGISTRATION(SwDocShell); 89 SFX_VIEW_REGISTRATION(SwWebDocShell); 90 SFX_VIEW_REGISTRATION(SwGlobalDocShell); 91 } 92 93 SFX_IMPL_INTERFACE(SwPagePreview, SfxViewShell) 94 95 void SwPagePreview::InitInterface_Impl() 96 { 97 GetStaticInterface()->RegisterPopupMenu("preview"); 98 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, 99 SfxVisibilityFlags::Standard|SfxVisibilityFlags::Client|SfxVisibilityFlags::FullScreen|SfxVisibilityFlags::ReadonlyDoc, 100 ToolbarId::PView_Toolbox); 101 } 102 103 104 #define SWVIEWFLAGS SfxViewShellFlags::HAS_PRINTOPTIONS 105 106 #define MIN_PREVIEW_ZOOM 25 107 #define MAX_PREVIEW_ZOOM 600 108 109 static sal_uInt16 lcl_GetNextZoomStep(sal_uInt16 nCurrentZoom, bool bZoomIn) 110 { 111 static const sal_uInt16 aZoomArr[] = 112 { 113 25, 50, 75, 100, 150, 200, 400, 600 114 }; 115 const int nZoomArrSize = static_cast<int>(SAL_N_ELEMENTS(aZoomArr)); 116 if (bZoomIn) 117 { 118 for(int i = nZoomArrSize - 1; i >= 0; --i) 119 { 120 if(nCurrentZoom > aZoomArr[i] || !i) 121 return aZoomArr[i]; 122 } 123 } 124 else 125 { 126 for(sal_uInt16 i : aZoomArr) 127 { 128 if(nCurrentZoom < i) 129 return i; 130 } 131 } 132 return bZoomIn ? MAX_PREVIEW_ZOOM : MIN_PREVIEW_ZOOM; 133 }; 134 135 static void lcl_InvalidateZoomSlots(SfxBindings& rBindings) 136 { 137 static sal_uInt16 const aInval[] = 138 { 139 SID_ATTR_ZOOM, SID_ZOOM_OUT, SID_ZOOM_IN, SID_ATTR_ZOOMSLIDER, FN_PREVIEW_ZOOM, FN_STAT_ZOOM, 140 0 141 }; 142 rBindings.Invalidate( aInval ); 143 } 144 145 // At first the zoom dialog 146 class SwPreviewZoomDlg : public weld::GenericDialogController 147 { 148 SwPagePreviewWin& m_rParent; 149 std::unique_ptr<weld::SpinButton> m_xRowEdit; 150 std::unique_ptr<weld::SpinButton> m_xColEdit; 151 152 public: 153 SwPreviewZoomDlg(SwPagePreviewWin& rParent) 154 : GenericDialogController(rParent.GetFrameWeld(), "modules/swriter/ui/previewzoomdialog.ui", "PreviewZoomDialog") 155 , m_rParent(rParent) 156 , m_xRowEdit(m_xBuilder->weld_spin_button("rows")) 157 , m_xColEdit(m_xBuilder->weld_spin_button("cols")) 158 { 159 m_xRowEdit->set_value(rParent.GetRow()); 160 m_xColEdit->set_value(rParent.GetCol()); 161 } 162 163 void execute() 164 { 165 if (run() == RET_OK) 166 { 167 m_rParent.CalcWish(sal_uInt8(m_xRowEdit->get_value()), sal_uInt8(m_xColEdit->get_value())); 168 } 169 } 170 }; 171 172 // all for SwPagePreviewWin 173 SwPagePreviewWin::SwPagePreviewWin( vcl::Window *pParent, SwPagePreview& rPView ) 174 : Window(pParent, WinBits(WB_CLIPCHILDREN)) 175 , mpViewShell(nullptr) 176 , mrView(rPView) 177 , mbCalcScaleForPreviewLayout(true) 178 , maPaintedPreviewDocRect(tools::Rectangle(0,0,0,0)) 179 , mpPgPreviewLayout(nullptr) 180 { 181 SetOutDevViewType( OutDevViewType::PrintPreview ); 182 SetHelpId(HID_PAGEPREVIEW); 183 SetFillColor( GetBackground().GetColor() ); 184 SetLineColor( GetBackground().GetColor()); 185 SetMapMode( MapMode(MapUnit::MapTwip) ); 186 187 const SwMasterUsrPref *pUsrPref = SW_MOD()->GetUsrPref(false); 188 mnRow = pUsrPref->GetPagePrevRow(); // 1 row 189 mnCol = pUsrPref->GetPagePrevCol(); // 1 column 190 mnSttPage = USHRT_MAX; 191 } 192 193 SwPagePreviewWin::~SwPagePreviewWin() 194 { 195 } 196 197 void SwPagePreviewWin::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) 198 { 199 if (!mpViewShell || !mpViewShell->GetLayout()) 200 return; 201 202 if (USHRT_MAX == mnSttPage) // was never calculated ? (Init-Phase!) 203 { 204 // This is the size to which I always relate. 205 if (!maPxWinSize.Height() || !maPxWinSize.Width()) 206 maPxWinSize = GetOutputSizePixel(); 207 208 tools::Rectangle aRect(rRenderContext.LogicToPixel(rRect)); 209 mpPgPreviewLayout->Prepare(1, Point(0,0), maPxWinSize, 210 mnSttPage, maPaintedPreviewDocRect); 211 SetSelectedPage(1); 212 mpPgPreviewLayout->Paint(rRenderContext, rRenderContext.PixelToLogic(aRect)); 213 SetPagePreview(mnRow, mnCol); 214 } 215 else 216 { 217 MapMode aMM(rRenderContext.GetMapMode()); 218 aMM.SetScaleX(maScale); 219 aMM.SetScaleY(maScale); 220 rRenderContext.SetMapMode(aMM); 221 mpPgPreviewLayout->GetParentViewShell().setOutputToWindow(true); 222 mpPgPreviewLayout->Paint(rRenderContext, rRect); 223 mpPgPreviewLayout->GetParentViewShell().setOutputToWindow(false); 224 } 225 } 226 227 void SwPagePreviewWin::CalcWish( sal_uInt8 nNewRow, sal_uInt8 nNewCol ) 228 { 229 if( !mpViewShell || !mpViewShell->GetLayout() ) 230 return; 231 232 const sal_uInt8 nOldCol = mnCol; 233 mnRow = nNewRow; 234 mnCol = nNewCol; 235 const sal_uInt16 nPages = mnRow * mnCol; 236 const sal_uInt16 nLastSttPg = mrView.GetPageCount()+1 > nPages 237 ? mrView.GetPageCount()+1 - nPages : 0; 238 if( mnSttPage > nLastSttPg ) 239 mnSttPage = nLastSttPg; 240 241 mpPgPreviewLayout->Init( mnCol, mnRow, maPxWinSize ); 242 mpPgPreviewLayout->Prepare( mnSttPage, Point(0,0), maPxWinSize, 243 mnSttPage, maPaintedPreviewDocRect ); 244 SetSelectedPage( mnSttPage ); 245 SetPagePreview(mnRow, mnCol); 246 maScale = GetMapMode().GetScaleX(); 247 248 // If changes have taken place at the columns, the special case "single column" 249 // must be considered and corrected if necessary. 250 if( (1 == nOldCol) != (1 == mnCol) ) 251 mrView.ScrollDocSzChg(); 252 253 // Order must be maintained! 254 // additional invalidate page status. 255 static sal_uInt16 aInval[] = 256 { 257 SID_ATTR_ZOOM, SID_ZOOM_OUT, SID_ZOOM_IN, 258 FN_PREVIEW_ZOOM, 259 FN_START_OF_DOCUMENT, FN_END_OF_DOCUMENT, FN_PAGEUP, FN_PAGEDOWN, 260 FN_STAT_PAGE, FN_STAT_ZOOM, 261 FN_SHOW_TWO_PAGES, FN_SHOW_MULTIPLE_PAGES, 262 0 263 }; 264 SfxBindings& rBindings = mrView.GetViewFrame()->GetBindings(); 265 rBindings.Invalidate( aInval ); 266 rBindings.Update( FN_SHOW_TWO_PAGES ); 267 rBindings.Update( FN_SHOW_MULTIPLE_PAGES ); 268 // adjust scrollbars 269 mrView.ScrollViewSzChg(); 270 } 271 272 // mnSttPage is Absolute 273 bool SwPagePreviewWin::MovePage( int eMoveMode ) 274 { 275 // number of pages up 276 const sal_uInt16 nPages = mnRow * mnCol; 277 sal_uInt16 nNewSttPage = mnSttPage; 278 const sal_uInt16 nPageCount = mrView.GetPageCount(); 279 const sal_uInt16 nDefSttPg = GetDefSttPage(); 280 bool bPaintPageAtFirstCol = true; 281 282 switch( eMoveMode ) 283 { 284 case MV_PAGE_UP: 285 { 286 const sal_uInt16 nRelSttPage = mpPgPreviewLayout->ConvertAbsoluteToRelativePageNum( mnSttPage ); 287 const sal_uInt16 nNewAbsSttPage = nRelSttPage - nPages > 0 ? 288 mpPgPreviewLayout->ConvertRelativeToAbsolutePageNum( nRelSttPage - nPages ) : 289 nDefSttPg; 290 nNewSttPage = nNewAbsSttPage; 291 292 const sal_uInt16 nRelSelPage = mpPgPreviewLayout->ConvertAbsoluteToRelativePageNum( SelectedPage() ); 293 const sal_uInt16 nNewRelSelPage = nRelSelPage - nPages > 0 ? 294 nRelSelPage - nPages : 295 1; 296 SetSelectedPage( mpPgPreviewLayout->ConvertRelativeToAbsolutePageNum( nNewRelSelPage ) ); 297 298 break; 299 } 300 case MV_PAGE_DOWN: 301 { 302 const sal_uInt16 nRelSttPage = mpPgPreviewLayout->ConvertAbsoluteToRelativePageNum( mnSttPage ); 303 const sal_uInt16 nNewAbsSttPage = mpPgPreviewLayout->ConvertRelativeToAbsolutePageNum( nRelSttPage + nPages ); 304 nNewSttPage = std::min(nNewAbsSttPage, nPageCount); 305 306 const sal_uInt16 nRelSelPage = mpPgPreviewLayout->ConvertAbsoluteToRelativePageNum( SelectedPage() ); 307 const sal_uInt16 nNewAbsSelPage = mpPgPreviewLayout->ConvertRelativeToAbsolutePageNum( nRelSelPage + nPages ); 308 SetSelectedPage( std::min(nNewAbsSelPage, nPageCount) ); 309 310 break; 311 } 312 case MV_DOC_STT: 313 nNewSttPage = nDefSttPg; 314 SetSelectedPage( mpPgPreviewLayout->ConvertRelativeToAbsolutePageNum( nNewSttPage ? nNewSttPage : 1 ) ); 315 break; 316 case MV_DOC_END: 317 // correct calculation of new start page. 318 nNewSttPage = nPageCount; 319 SetSelectedPage( nPageCount ); 320 break; 321 322 case MV_SELPAGE: 323 // <nNewSttPage> and <SelectedPage()> are already set. 324 // not start at first column, only if the 325 // complete preview layout columns doesn't fit into window. 326 if ( !mpPgPreviewLayout->DoesPreviewLayoutColsFitIntoWindow() ) 327 bPaintPageAtFirstCol = false; 328 break; 329 case MV_SCROLL: 330 // check, if paint page at first column 331 // has to be avoided 332 if ( !mpPgPreviewLayout->DoesPreviewLayoutRowsFitIntoWindow() || 333 !mpPgPreviewLayout->DoesPreviewLayoutColsFitIntoWindow() ) 334 bPaintPageAtFirstCol = false; 335 break; 336 case MV_NEWWINSIZE: 337 // nothing special to do. 338 break; 339 case MV_CALC: 340 // re-init page preview layout. 341 mpPgPreviewLayout->ReInit(); 342 343 // correct calculation of new start page. 344 if( nNewSttPage > nPageCount ) 345 nNewSttPage = nPageCount; 346 347 // correct selected page number 348 if( SelectedPage() > nPageCount ) 349 SetSelectedPage( nNewSttPage ? nNewSttPage : 1 ); 350 } 351 352 mpPgPreviewLayout->Prepare( nNewSttPage, Point(0,0), maPxWinSize, 353 nNewSttPage, 354 maPaintedPreviewDocRect, bPaintPageAtFirstCol ); 355 if( nNewSttPage == mnSttPage && 356 eMoveMode != MV_SELPAGE ) 357 return false; 358 359 SetPagePreview(mnRow, mnCol); 360 mnSttPage = nNewSttPage; 361 362 // additional invalidate page status. 363 static sal_uInt16 aInval[] = 364 { 365 FN_START_OF_DOCUMENT, FN_END_OF_DOCUMENT, FN_PAGEUP, FN_PAGEDOWN, 366 FN_STAT_PAGE, 0 367 }; 368 369 SfxBindings& rBindings = mrView.GetViewFrame()->GetBindings(); 370 rBindings.Invalidate( aInval ); 371 372 return true; 373 } 374 375 void SwPagePreviewWin::SetWinSize( const Size& rNewSize ) 376 { 377 // We always want the size as pixel units. 378 maPxWinSize = LogicToPixel( rNewSize ); 379 380 if( USHRT_MAX == mnSttPage ) 381 { 382 mnSttPage = GetDefSttPage(); 383 SetSelectedPage( GetDefSttPage() ); 384 } 385 386 if ( mbCalcScaleForPreviewLayout ) 387 { 388 mpPgPreviewLayout->Init( mnCol, mnRow, maPxWinSize ); 389 maScale = GetMapMode().GetScaleX(); 390 } 391 mpPgPreviewLayout->Prepare( mnSttPage, Point(0,0), maPxWinSize, 392 mnSttPage, maPaintedPreviewDocRect ); 393 if ( mbCalcScaleForPreviewLayout ) 394 { 395 SetSelectedPage( mnSttPage ); 396 mbCalcScaleForPreviewLayout = false; 397 } 398 SetPagePreview(mnRow, mnCol); 399 maScale = GetMapMode().GetScaleX(); 400 } 401 402 OUString SwPagePreviewWin::GetStatusStr( sal_uInt16 nPageCnt ) const 403 { 404 // show physical and virtual page number of 405 // selected page, if it's visible. 406 const sal_uInt16 nPageNum = mpPgPreviewLayout->IsPageVisible( mpPgPreviewLayout->SelectedPage() ) 407 ? mpPgPreviewLayout->SelectedPage() : std::max<sal_uInt16>(mnSttPage, 1); 408 409 OUStringBuffer aStatusStr; 410 const sal_uInt16 nVirtPageNum = mpPgPreviewLayout->GetVirtPageNumByPageNum( nPageNum ); 411 if( nVirtPageNum && nVirtPageNum != nPageNum ) 412 { 413 aStatusStr.append( OUString::number(nVirtPageNum) + " " ); 414 } 415 aStatusStr.append( OUString::number(nPageNum) + " / " + OUString::number(nPageCnt) ); 416 return aStatusStr.makeStringAndClear(); 417 } 418 419 void SwPagePreviewWin::KeyInput( const KeyEvent &rKEvt ) 420 { 421 const vcl::KeyCode& rKeyCode = rKEvt.GetKeyCode(); 422 bool bHandled = false; 423 if(!rKeyCode.GetModifier()) 424 { 425 sal_uInt16 nSlot = 0; 426 switch(rKeyCode.GetCode()) 427 { 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; 431 } 432 if(nSlot) 433 { 434 bHandled = true; 435 mrView.GetViewFrame()->GetDispatcher()->Execute( 436 nSlot, SfxCallMode::ASYNCHRON ); 437 } 438 } 439 if( !bHandled && !mrView.KeyInput( rKEvt ) ) 440 Window::KeyInput( rKEvt ); 441 } 442 443 void SwPagePreviewWin::Command( const CommandEvent& rCEvt ) 444 { 445 bool bCallBase = true; 446 switch( rCEvt.GetCommand() ) 447 { 448 case CommandEventId::ContextMenu: 449 SfxDispatcher::ExecutePopup(); 450 bCallBase = false; 451 break; 452 453 case CommandEventId::Wheel: 454 case CommandEventId::StartAutoScroll: 455 case CommandEventId::AutoScroll: 456 { 457 const CommandWheelData* pData = rCEvt.GetWheelData(); 458 if( pData ) 459 { 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 ); 464 } 465 else 466 bCallBase = !mrView.HandleWheelCommands( rCEvt ); 467 } 468 break; 469 default: 470 ; 471 } 472 473 if( bCallBase ) 474 Window::Command( rCEvt ); 475 } 476 477 void SwPagePreviewWin::MouseButtonDown( const MouseEvent& rMEvt ) 478 { 479 // consider single-click to set selected page 480 if( MOUSE_LEFT == ( rMEvt.GetModifier() + rMEvt.GetButtons() ) ) 481 { 482 Point aPreviewPos( PixelToLogic( rMEvt.GetPosPixel() ) ); 483 Point aDocPos; 484 bool bPosInEmptyPage; 485 sal_uInt16 nNewSelectedPage; 486 bool bIsDocPos = 487 mpPgPreviewLayout->IsPreviewPosInDocPreviewPage( aPreviewPos, 488 aDocPos, bPosInEmptyPage, nNewSelectedPage ); 489 if ( bIsDocPos && rMEvt.GetClicks() == 2 ) 490 { 491 // close page preview, set new cursor position and switch to 492 // normal view. 493 OUString sNewCursorPos = OUString::number( aDocPos.X() ) + ";" + 494 OUString::number( aDocPos.Y() ) + ";"; 495 mrView.SetNewCursorPos( sNewCursorPos ); 496 497 SfxViewFrame *pTmpFrame = mrView.GetViewFrame(); 498 pTmpFrame->GetBindings().Execute( SID_VIEWSHELL0, nullptr, 499 SfxCallMode::ASYNCHRON ); 500 } 501 else if ( bIsDocPos || bPosInEmptyPage ) 502 { 503 // show clicked page as the selected one 504 mpPgPreviewLayout->MarkNewSelectedPage( nNewSelectedPage ); 505 GetViewShell()->ShowPreviewSelection( nNewSelectedPage ); 506 // adjust position at vertical scrollbar. 507 if ( mpPgPreviewLayout->DoesPreviewLayoutRowsFitIntoWindow() ) 508 { 509 mrView.SetVScrollbarThumbPos( nNewSelectedPage ); 510 } 511 // invalidate page status. 512 static sal_uInt16 aInval[] = 513 { 514 FN_STAT_PAGE, 0 515 }; 516 SfxBindings& rBindings = mrView.GetViewFrame()->GetBindings(); 517 rBindings.Invalidate( aInval ); 518 } 519 } 520 } 521 522 // Set user prefs or view options 523 524 void SwPagePreviewWin::SetPagePreview( sal_uInt8 nRow, sal_uInt8 nCol ) 525 { 526 SwMasterUsrPref *pOpt = const_cast<SwMasterUsrPref *>(SW_MOD()->GetUsrPref(false)); 527 528 if (nRow != pOpt->GetPagePrevRow() || nCol != pOpt->GetPagePrevCol()) 529 { 530 pOpt->SetPagePrevRow( nRow ); 531 pOpt->SetPagePrevCol( nCol ); 532 pOpt->SetModified(); 533 534 // Update scrollbar! 535 mrView.ScrollViewSzChg(); 536 } 537 } 538 539 /** get selected page in document preview */ 540 sal_uInt16 SwPagePreviewWin::SelectedPage() const 541 { 542 return mpPgPreviewLayout->SelectedPage(); 543 } 544 545 /** set selected page number in document preview */ 546 void SwPagePreviewWin::SetSelectedPage( sal_uInt16 _nSelectedPageNum ) 547 { 548 mpPgPreviewLayout->SetSelectedPage( _nSelectedPageNum ); 549 } 550 551 /** method to enable/disable book preview */ 552 bool SwPagePreviewWin::SetBookPreviewMode( const bool _bBookPreview ) 553 { 554 return mpPgPreviewLayout->SetBookPreviewMode( _bBookPreview, 555 mnSttPage, 556 maPaintedPreviewDocRect ); 557 } 558 559 void SwPagePreviewWin::DataChanged( const DataChangedEvent& rDCEvt ) 560 { 561 Window::DataChanged( rDCEvt ); 562 563 switch( rDCEvt.GetType() ) 564 { 565 case DataChangedEventType::SETTINGS: 566 // Rearrange the scrollbars or trigger resize, because the 567 // size of the scrollbars may have be changed. Also the 568 // size of the scrollbars has to be retrieved from the settings 569 // out of the resize handler. 570 if( rDCEvt.GetFlags() & AllSettingsFlags::STYLE ) 571 mrView.InvalidateBorder(); // Scrollbar widths 572 // zoom has to be disabled if Accessibility support is switched on 573 lcl_InvalidateZoomSlots(mrView.GetViewFrame()->GetBindings()); 574 break; 575 576 case DataChangedEventType::PRINTER: 577 case DataChangedEventType::DISPLAY: 578 case DataChangedEventType::FONTS: 579 case DataChangedEventType::FONTSUBSTITUTION: 580 mrView.GetDocShell()->UpdateFontList(); // Font change 581 mpViewShell->InvalidateLayout(true); 582 if ( mpViewShell->GetWin() ) 583 mpViewShell->GetWin()->Invalidate(); 584 break; 585 default: break; 586 } 587 } 588 589 /** help method to execute SfxRequest FN_PAGEUP and FN_PAGEDOWN */ 590 void SwPagePreview::ExecPgUpAndPgDown( const bool _bPgUp, 591 SfxRequest* _pReq ) 592 { 593 SwPagePreviewLayout* pPagePreviewLay = GetViewShell()->PagePreviewLayout(); 594 // check, if top/bottom of preview is *not* already visible. 595 if( pPagePreviewLay->GetWinPagesScrollAmount( _bPgUp ? -1 : 1 ) != 0 ) 596 { 597 if ( pPagePreviewLay->DoesPreviewLayoutRowsFitIntoWindow() && 598 pPagePreviewLay->DoesPreviewLayoutColsFitIntoWindow() ) 599 { 600 const int eMvMode = _bPgUp ? 601 SwPagePreviewWin::MV_PAGE_UP : 602 SwPagePreviewWin::MV_PAGE_DOWN; 603 if ( ChgPage( eMvMode ) ) 604 m_pViewWin->Invalidate(); 605 } 606 else 607 { 608 SwTwips nScrollAmount; 609 sal_uInt16 nNewSelectedPageNum = 0; 610 const sal_uInt16 nVisPages = m_pViewWin->GetRow() * m_pViewWin->GetCol(); 611 if( _bPgUp ) 612 { 613 if ( pPagePreviewLay->DoesPreviewLayoutRowsFitIntoWindow() ) 614 { 615 nScrollAmount = pPagePreviewLay->GetWinPagesScrollAmount( -1 ); 616 if ( (m_pViewWin->SelectedPage() - nVisPages) > 0 ) 617 nNewSelectedPageNum = m_pViewWin->SelectedPage() - nVisPages; 618 else 619 nNewSelectedPageNum = 1; 620 } 621 else 622 nScrollAmount = - std::min( m_pViewWin->GetOutputSize().Height(), 623 m_pViewWin->GetPaintedPreviewDocRect().Top() ); 624 } 625 else 626 { 627 if ( pPagePreviewLay->DoesPreviewLayoutRowsFitIntoWindow() ) 628 { 629 nScrollAmount = pPagePreviewLay->GetWinPagesScrollAmount( 1 ); 630 if ( (m_pViewWin->SelectedPage() + nVisPages) <= mnPageCount ) 631 nNewSelectedPageNum = m_pViewWin->SelectedPage() + nVisPages; 632 else 633 nNewSelectedPageNum = mnPageCount; 634 } 635 else 636 nScrollAmount = std::min( m_pViewWin->GetOutputSize().Height(), 637 ( pPagePreviewLay->GetPreviewDocSize().Height() - 638 m_pViewWin->GetPaintedPreviewDocRect().Bottom() ) ); 639 } 640 m_pViewWin->Scroll( 0, nScrollAmount ); 641 if ( nNewSelectedPageNum != 0 ) 642 { 643 m_pViewWin->SetSelectedPage( nNewSelectedPageNum ); 644 } 645 ScrollViewSzChg(); 646 // additional invalidate page status. 647 static sal_uInt16 aInval[] = 648 { 649 FN_START_OF_DOCUMENT, FN_END_OF_DOCUMENT, FN_PAGEUP, FN_PAGEDOWN, 650 FN_STAT_PAGE, 0 651 }; 652 SfxBindings& rBindings = GetViewFrame()->GetBindings(); 653 rBindings.Invalidate( aInval ); 654 m_pViewWin->Invalidate(); 655 } 656 } 657 658 if ( _pReq ) 659 _pReq->Done(); 660 } 661 662 // Then all for the SwPagePreview 663 void SwPagePreview::Execute( SfxRequest &rReq ) 664 { 665 int eMvMode; 666 sal_uInt8 nRow = 1; 667 bool bRetVal = false; 668 bool bRefresh = true; 669 670 switch(rReq.GetSlot()) 671 { 672 case FN_REFRESH_VIEW: 673 case FN_STAT_PAGE: 674 case FN_STAT_ZOOM: 675 break; 676 677 case FN_SHOW_MULTIPLE_PAGES: 678 { 679 const SfxItemSet *pArgs = rReq.GetArgs(); 680 if( pArgs && pArgs->Count() >= 2 ) 681 { 682 sal_uInt8 nCols = static_cast<sal_uInt8>(pArgs->Get(SID_ATTR_TABLE_COLUMN).GetValue()); 683 sal_uInt8 nRows = static_cast<sal_uInt8>(pArgs->Get(SID_ATTR_TABLE_ROW).GetValue()); 684 m_pViewWin->CalcWish( nRows, nCols ); 685 686 } 687 else 688 { 689 SwPreviewZoomDlg aDlg(*m_pViewWin); 690 aDlg.execute(); 691 } 692 } 693 break; 694 case FN_SHOW_BOOKVIEW: 695 { 696 const SfxItemSet* pArgs = rReq.GetArgs(); 697 const SfxPoolItem* pItem; 698 bool bBookPreview = GetViewShell()->GetViewOptions()->IsPagePrevBookview(); 699 if( pArgs && SfxItemState::SET == pArgs->GetItemState( FN_SHOW_BOOKVIEW, false, &pItem ) ) 700 { 701 bBookPreview = static_cast< const SfxBoolItem* >( pItem )->GetValue(); 702 const_cast<SwViewOption*>(GetViewShell()->GetViewOptions())->SetPagePrevBookview( bBookPreview ); 703 // cast is not gentleman like, but it's common use in writer and in this case 704 } 705 if ( m_pViewWin->SetBookPreviewMode( bBookPreview ) ) 706 { 707 // book preview mode changed. Thus, adjust scrollbars and 708 // invalidate corresponding states. 709 ScrollViewSzChg(); 710 static sal_uInt16 aInval[] = 711 { 712 FN_START_OF_DOCUMENT, FN_END_OF_DOCUMENT, FN_PAGEUP, FN_PAGEDOWN, 713 FN_STAT_PAGE, FN_SHOW_BOOKVIEW, 0 714 }; 715 SfxBindings& rBindings = GetViewFrame()->GetBindings(); 716 rBindings.Invalidate( aInval ); 717 m_pViewWin->Invalidate(); 718 } 719 720 } 721 break; 722 case FN_SHOW_TWO_PAGES: 723 m_pViewWin->CalcWish( nRow, 2 ); 724 break; 725 726 case FN_SHOW_SINGLE_PAGE: 727 m_pViewWin->CalcWish( nRow, 1 ); 728 break; 729 730 case FN_PREVIEW_ZOOM: 731 case SID_ATTR_ZOOM: 732 { 733 const SfxItemSet *pArgs = rReq.GetArgs(); 734 const SfxPoolItem* pItem; 735 ScopedVclPtr<AbstractSvxZoomDialog> pDlg; 736 if(!pArgs) 737 { 738 SfxItemSet aCoreSet(GetPool(), svl::Items<SID_ATTR_ZOOM, SID_ATTR_ZOOM>{}); 739 const SwViewOption* pVOpt = GetViewShell()->GetViewOptions(); 740 SvxZoomItem aZoom( pVOpt->GetZoomType(), pVOpt->GetZoom() ); 741 aZoom.SetValueSet( 742 SvxZoomEnableFlags::N50| 743 SvxZoomEnableFlags::N75| 744 SvxZoomEnableFlags::N100| 745 SvxZoomEnableFlags::N150| 746 SvxZoomEnableFlags::N200| 747 SvxZoomEnableFlags::WHOLEPAGE); 748 aCoreSet.Put( aZoom ); 749 750 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); 751 pDlg.disposeAndReset(pFact->CreateSvxZoomDialog(GetViewFrame()->GetWindow().GetFrameWeld(), aCoreSet)); 752 pDlg->SetLimits( MINZOOM, MAXZOOM ); 753 754 if( pDlg->Execute() != RET_CANCEL ) 755 pArgs = pDlg->GetOutputItemSet(); 756 } 757 if( pArgs ) 758 { 759 SvxZoomType eType = SvxZoomType::PERCENT; 760 sal_uInt16 nZoomFactor = USHRT_MAX; 761 if(SfxItemState::SET == pArgs->GetItemState(SID_ATTR_ZOOM, true, &pItem)) 762 { 763 eType = static_cast<const SvxZoomItem *>(pItem)->GetType(); 764 nZoomFactor = static_cast<const SvxZoomItem *>(pItem)->GetValue(); 765 } 766 else if(SfxItemState::SET == pArgs->GetItemState(FN_PREVIEW_ZOOM, true, &pItem)) 767 nZoomFactor = static_cast<const SfxUInt16Item *>(pItem)->GetValue(); 768 if(USHRT_MAX != nZoomFactor) 769 SetZoom(eType, nZoomFactor); 770 } 771 } 772 break; 773 case SID_ATTR_ZOOMSLIDER : 774 { 775 const SfxItemSet *pArgs = rReq.GetArgs(); 776 const SfxPoolItem* pItem; 777 778 if ( pArgs && SfxItemState::SET == pArgs->GetItemState(SID_ATTR_ZOOMSLIDER, true, &pItem ) ) 779 { 780 const sal_uInt16 nCurrentZoom = static_cast<const SvxZoomSliderItem *>(pItem)->GetValue(); 781 SetZoom( SvxZoomType::PERCENT, nCurrentZoom ); 782 } 783 } 784 break; 785 case SID_ZOOM_IN: 786 case SID_ZOOM_OUT: 787 { 788 const SwViewOption* pVOpt = GetViewShell()->GetViewOptions(); 789 SetZoom(SvxZoomType::PERCENT, 790 lcl_GetNextZoomStep(pVOpt->GetZoom(), SID_ZOOM_IN == rReq.GetSlot())); 791 } 792 break; 793 case FN_CHAR_LEFT: 794 case FN_CHAR_RIGHT: 795 case FN_LINE_UP: 796 case FN_LINE_DOWN: 797 { 798 SwPagePreviewLayout* pPagePreviewLay = GetViewShell()->PagePreviewLayout(); 799 sal_uInt16 nNewSelectedPage; 800 sal_uInt16 nNewStartPage; 801 Point aNewStartPos; 802 sal_Int16 nHoriMove = 0; 803 sal_Int16 nVertMove = 0; 804 switch(rReq.GetSlot()) 805 { 806 case FN_CHAR_LEFT: nHoriMove = -1; break; 807 case FN_CHAR_RIGHT: nHoriMove = 1; break; 808 case FN_LINE_UP: nVertMove = -1; break; 809 case FN_LINE_DOWN: nVertMove = 1; break; 810 } 811 pPagePreviewLay->CalcStartValuesForSelectedPageMove( nHoriMove, nVertMove, 812 nNewSelectedPage, nNewStartPage, aNewStartPos ); 813 if ( m_pViewWin->SelectedPage() != nNewSelectedPage ) 814 { 815 if ( pPagePreviewLay->IsPageVisible( nNewSelectedPage ) ) 816 { 817 pPagePreviewLay->MarkNewSelectedPage( nNewSelectedPage ); 818 // adjust position at vertical scrollbar. 819 SetVScrollbarThumbPos( nNewSelectedPage ); 820 bRefresh = false; 821 } 822 else 823 { 824 m_pViewWin->SetSelectedPage( nNewSelectedPage ); 825 m_pViewWin->SetSttPage( nNewStartPage ); 826 bRefresh = ChgPage( SwPagePreviewWin::MV_SELPAGE ); 827 } 828 GetViewShell()->ShowPreviewSelection( nNewSelectedPage ); 829 // invalidate page status. 830 static sal_uInt16 aInval[] = 831 { 832 FN_STAT_PAGE, 0 833 }; 834 SfxBindings& rBindings = GetViewFrame()->GetBindings(); 835 rBindings.Invalidate( aInval ); 836 rReq.Done(); 837 } 838 else 839 { 840 bRefresh = false; 841 } 842 break; 843 } 844 case FN_PAGEUP: 845 case FN_PAGEDOWN: 846 { 847 ExecPgUpAndPgDown( rReq.GetSlot() == FN_PAGEUP, &rReq ); 848 break; 849 } 850 case SID_JUMP_TO_SPECIFIC_PAGE: 851 { 852 sal_uInt16 nPageNum = 1; 853 const SfxItemSet *pArgs = rReq.GetArgs(); 854 if( pArgs && pArgs->Count()) 855 { 856 nPageNum = static_cast<const SfxUInt16Item &>(pArgs->Get(SID_JUMP_TO_SPECIFIC_PAGE)).GetValue(); 857 858 if( nPageNum > 0 && nPageNum <= mnPageCount ) 859 { 860 m_pViewWin->SetSttPage( nPageNum); 861 m_pViewWin->SetSelectedPage( nPageNum ); 862 ChgPage( SwPagePreviewWin::MV_SPECIFIC_PAGE, false ); 863 ScrollViewSzChg(); 864 } 865 } 866 } 867 break; 868 case FN_START_OF_LINE: 869 case FN_START_OF_DOCUMENT: 870 m_pViewWin->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 m_pViewWin->SetSelectedPage( mnPageCount ); 875 eMvMode = SwPagePreviewWin::MV_DOC_END; bRetVal = true; goto MOVEPAGE; 876 MOVEPAGE: 877 { 878 bool bRet = ChgPage( eMvMode ); 879 // return value for Basic 880 if(bRetVal) 881 rReq.SetReturnValue(SfxBoolItem(rReq.GetSlot(), !bRet)); 882 883 bRefresh = bRet; 884 rReq.Done(); 885 } 886 break; 887 888 case FN_PRINT_PAGEPREVIEW: 889 { 890 const SwPagePreviewPrtData* pPPVPD = m_pViewWin->GetViewShell()->GetDoc()->GetPreviewPrtData(); 891 // The thing with the orientation 892 if(pPPVPD) 893 { 894 SfxPrinter* pPrinter = GetPrinter( true ); 895 if((pPrinter->GetOrientation() == Orientation::Landscape) 896 != pPPVPD->GetLandscape()) 897 pPrinter->SetOrientation(pPPVPD->GetLandscape() ? Orientation::Landscape : Orientation::Portrait); 898 } 899 ::SetAppPrintOptions( m_pViewWin->GetViewShell(), false ); 900 m_bNormalPrint = false; 901 rReq.SetSlot( SID_PRINTDOC ); 902 SfxViewShell::ExecuteSlot( rReq, SfxViewShell::GetInterface() ); 903 rReq.SetSlot( FN_PRINT_PAGEPREVIEW ); 904 return; 905 } 906 case SID_PRINTDOCDIRECT: 907 case SID_PRINTDOC: 908 ::SetAppPrintOptions( m_pViewWin->GetViewShell(), false ); 909 m_bNormalPrint = true; 910 SfxViewShell::ExecuteSlot( rReq, SfxViewShell::GetInterface() ); 911 return; 912 case FN_CLOSE_PAGEPREVIEW: 913 case SID_PRINTPREVIEW: 914 // print preview is now always in the same frame as the tab view 915 // -> always switch this frame back to normal view 916 // (ScTabViewShell ctor reads stored view data) 917 GetViewFrame()->GetDispatcher()->Execute( SID_VIEWSHELL0, SfxCallMode::ASYNCHRON ); 918 break; 919 case FN_INSERT_BREAK: 920 { 921 sal_uInt16 nSelPage = m_pViewWin->SelectedPage(); 922 //if a dummy page is selected (e.g. a non-existing right/left page) 923 //the direct neighbor is used 924 if(GetViewShell()->IsDummyPage( nSelPage ) && GetViewShell()->IsDummyPage( --nSelPage )) 925 nSelPage +=2; 926 m_nNewPage = nSelPage; 927 SfxViewFrame *pTmpFrame = GetViewFrame(); 928 pTmpFrame->GetBindings().Execute( SID_VIEWSHELL0, nullptr, 929 SfxCallMode::ASYNCHRON ); 930 } 931 break; 932 default: 933 OSL_ENSURE(false, "wrong dispatcher"); 934 return; 935 } 936 937 if( bRefresh ) 938 m_pViewWin->Invalidate(); 939 } 940 941 void SwPagePreview::GetState( SfxItemSet& rSet ) 942 { 943 SfxWhichIter aIter(rSet); 944 sal_uInt16 nWhich = aIter.FirstWhich(); 945 OSL_ENSURE(nWhich, "empty set"); 946 SwPagePreviewLayout* pPagePreviewLay = GetViewShell()->PagePreviewLayout(); 947 948 while(nWhich) 949 { 950 switch(nWhich) 951 { 952 case SID_BROWSER_MODE: 953 case FN_PRINT_LAYOUT: 954 rSet.DisableItem(nWhich); 955 break; 956 case FN_START_OF_DOCUMENT: 957 { 958 if ( pPagePreviewLay->IsPageVisible( 1 ) ) 959 rSet.DisableItem(nWhich); 960 break; 961 } 962 case FN_END_OF_DOCUMENT: 963 { 964 if ( pPagePreviewLay->IsPageVisible( mnPageCount ) ) 965 rSet.DisableItem(nWhich); 966 break; 967 } 968 case FN_PAGEUP: 969 { 970 if( pPagePreviewLay->GetWinPagesScrollAmount( -1 ) == 0 ) 971 rSet.DisableItem(nWhich); 972 break; 973 } 974 case FN_PAGEDOWN: 975 { 976 if( pPagePreviewLay->GetWinPagesScrollAmount( 1 ) == 0 ) 977 rSet.DisableItem(nWhich); 978 break; 979 } 980 981 case FN_STAT_PAGE: 982 { 983 OUString aStr = m_sPageStr + m_pViewWin->GetStatusStr( mnPageCount ); 984 rSet.Put( SfxStringItem( nWhich, aStr) ); 985 } 986 break; 987 988 case SID_ATTR_ZOOM: 989 case FN_STAT_ZOOM: 990 { 991 const SwViewOption* pVOpt = GetViewShell()->GetViewOptions(); 992 SvxZoomItem aZoom(pVOpt->GetZoomType(), pVOpt->GetZoom()); 993 aZoom.SetValueSet( 994 SvxZoomEnableFlags::N50| 995 SvxZoomEnableFlags::N75| 996 SvxZoomEnableFlags::N100| 997 SvxZoomEnableFlags::N150| 998 SvxZoomEnableFlags::N200); 999 rSet.Put( aZoom ); 1000 } 1001 break; 1002 case SID_ATTR_ZOOMSLIDER : 1003 { 1004 const SwViewOption* pVOpt = GetViewShell()->GetViewOptions(); 1005 const sal_uInt16 nCurrentZoom = pVOpt->GetZoom(); 1006 SvxZoomSliderItem aZoomSliderItem( nCurrentZoom, MINZOOM, MAXZOOM ); 1007 aZoomSliderItem.AddSnappingPoint( 100 ); 1008 rSet.Put( aZoomSliderItem ); 1009 } 1010 break; 1011 case FN_PREVIEW_ZOOM: 1012 { 1013 const SwViewOption* pVOpt = GetViewShell()->GetViewOptions(); 1014 rSet.Put(SfxUInt16Item(nWhich, pVOpt->GetZoom())); 1015 } 1016 break; 1017 case SID_ZOOM_IN: 1018 case SID_ZOOM_OUT: 1019 { 1020 const SwViewOption* pVOpt = GetViewShell()->GetViewOptions(); 1021 if((SID_ZOOM_OUT == nWhich && pVOpt->GetZoom() >= MAX_PREVIEW_ZOOM)|| 1022 (SID_ZOOM_IN == nWhich && pVOpt->GetZoom() <= MIN_PREVIEW_ZOOM)) 1023 { 1024 rSet.DisableItem(nWhich); 1025 } 1026 } 1027 break; 1028 case FN_SHOW_MULTIPLE_PAGES: 1029 // should never be disabled 1030 break; 1031 case FN_SHOW_BOOKVIEW: 1032 { 1033 bool b = GetViewShell()->GetViewOptions()->IsPagePrevBookview(); 1034 rSet.Put(SfxBoolItem(nWhich, b)); 1035 } 1036 break; 1037 1038 case FN_SHOW_TWO_PAGES: 1039 if( 2 == m_pViewWin->GetCol() && 1 == m_pViewWin->GetRow() ) 1040 rSet.DisableItem( nWhich ); 1041 break; 1042 1043 case FN_PRINT_PAGEPREVIEW: 1044 // has the same status like the normal printing 1045 { 1046 const SfxPoolItem* pItem; 1047 SfxItemSet aSet( *rSet.GetPool(), svl::Items<SID_PRINTDOC, SID_PRINTDOC>{} ); 1048 GetSlotState( SID_PRINTDOC, SfxViewShell::GetInterface(), &aSet ); 1049 if( SfxItemState::DISABLED == aSet.GetItemState( SID_PRINTDOC, 1050 false, &pItem )) 1051 rSet.DisableItem( nWhich ); 1052 else if( SfxItemState::SET == aSet.GetItemState( SID_PRINTDOC, 1053 false, &pItem )) 1054 { 1055 const_cast<SfxPoolItem*>(pItem)->SetWhich( FN_PRINT_PAGEPREVIEW ); 1056 rSet.Put( *pItem ); 1057 } 1058 } 1059 break; 1060 1061 case SID_PRINTPREVIEW: 1062 rSet.Put( SfxBoolItem( nWhich, true ) ); 1063 break; 1064 1065 case SID_PRINTDOC: 1066 case SID_PRINTDOCDIRECT: 1067 GetSlotState( nWhich, SfxViewShell::GetInterface(), &rSet ); 1068 break; 1069 } 1070 nWhich = aIter.NextWhich(); 1071 } 1072 } 1073 1074 void SwPagePreview::StateUndo(SfxItemSet& rSet) 1075 { 1076 SfxWhichIter aIter(rSet); 1077 sal_uInt16 nWhich = aIter.FirstWhich(); 1078 1079 while (nWhich) 1080 { 1081 rSet.DisableItem(nWhich); 1082 nWhich = aIter.NextWhich(); 1083 } 1084 } 1085 1086 void SwPagePreview::Init() 1087 { 1088 if ( GetViewShell()->HasDrawView() ) 1089 GetViewShell()->GetDrawView()->SetAnimationEnabled( false ); 1090 1091 m_bNormalPrint = true; 1092 1093 // Check and process the DocSize. The shell could not be found via 1094 // the handler, because the shell is unknown to the SFX management 1095 // within the CTOR phase. 1096 1097 const SwViewOption * pPrefs = SW_MOD()->GetUsrPref(false); 1098 1099 mbHScrollbarEnabled = pPrefs->IsViewHScrollBar(); 1100 mbVScrollbarEnabled = pPrefs->IsViewVScrollBar(); 1101 1102 // Update the fields 1103 // ATTENTION: Do cast the EditShell up, to use the SS. 1104 // At the methods the current shell will be queried! 1105 SwEditShell* pESh = dynamic_cast<SwEditShell*>(GetViewShell()); 1106 bool bIsModified = pESh != nullptr && pESh->IsModified(); 1107 1108 SwViewOption aOpt( *pPrefs ); 1109 aOpt.SetPagePreview(true); 1110 aOpt.SetTab( false ); 1111 aOpt.SetBlank( false ); 1112 aOpt.SetHardBlank( false ); 1113 aOpt.SetParagraph( false ); 1114 aOpt.SetLineBreak( false ); 1115 aOpt.SetPageBreak( false ); 1116 aOpt.SetColumnBreak( false ); 1117 aOpt.SetSoftHyph( false ); 1118 aOpt.SetFieldName( false ); 1119 aOpt.SetPostIts( false ); 1120 aOpt.SetShowHiddenChar( false ); 1121 aOpt.SetShowHiddenField( false ); 1122 aOpt.SetShowHiddenPara( false ); 1123 aOpt.SetViewHRuler( false ); 1124 aOpt.SetViewVRuler( false ); 1125 aOpt.SetGraphic( true ); 1126 aOpt.SetTable( true ); 1127 aOpt.SetSnap( false ); 1128 aOpt.SetGridVisible( false ); 1129 aOpt.SetOnlineSpell( false ); 1130 aOpt.SetHideWhitespaceMode( false ); 1131 1132 GetViewShell()->ApplyViewOptions( aOpt ); 1133 GetViewShell()->ApplyAccessiblityOptions(SW_MOD()->GetAccessibilityOptions()); 1134 1135 // adjust view shell option to the same as for print 1136 SwPrintData const aPrintOptions = *SW_MOD()->GetPrtOptions(false); 1137 GetViewShell()->AdjustOptionsForPagePreview( aPrintOptions ); 1138 1139 GetViewShell()->CalcLayout(); 1140 DocSzChgd( GetViewShell()->GetDocSize() ); 1141 1142 if( !bIsModified && pESh != nullptr ) 1143 pESh->ResetModified(); 1144 } 1145 1146 SwPagePreview::SwPagePreview(SfxViewFrame *pViewFrame, SfxViewShell* pOldSh): 1147 SfxViewShell( pViewFrame, SWVIEWFLAGS ), 1148 m_pViewWin( VclPtr<SwPagePreviewWin>::Create(&GetViewFrame()->GetWindow(), *this ) ), 1149 m_nNewPage(USHRT_MAX), 1150 m_sPageStr(SwResId(STR_PAGE)), 1151 m_pHScrollbar(nullptr), 1152 m_pVScrollbar(nullptr), 1153 m_pScrollFill(VclPtr<ScrollBarBox>::Create( &pViewFrame->GetWindow(), WB_SIZEABLE )), 1154 mnPageCount( 0 ), 1155 mbResetFormDesignMode( false ), 1156 mbFormDesignModeToReset( false ) 1157 { 1158 SetName("PageView"); 1159 SetWindow( m_pViewWin ); 1160 CreateScrollbar( true ); 1161 CreateScrollbar( false ); 1162 1163 //notify notebookbar change in context 1164 SfxShell::SetContextBroadcasterEnabled(true); 1165 SfxShell::SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::Printpreview)); 1166 SfxShell::BroadcastContextForActivation(true); 1167 //removelisteners for notebookbar 1168 if (auto& pBar = SfxViewFrame::Current()->GetWindow().GetSystemWindow()->GetNotebookBar()) 1169 pBar->ControlListener(true); 1170 1171 SfxObjectShell* pObjShell = pViewFrame->GetObjectShell(); 1172 if ( !pOldSh ) 1173 { 1174 // Exists already a view on the document? 1175 SfxViewFrame *pF = SfxViewFrame::GetFirst( pObjShell ); 1176 if ( pF == pViewFrame ) 1177 pF = SfxViewFrame::GetNext( *pF, pObjShell ); 1178 if ( pF ) 1179 pOldSh = pF->GetViewShell(); 1180 } 1181 1182 SwViewShell *pVS, *pNew; 1183 1184 if (SwPagePreview* pPagePreview = dynamic_cast<SwPagePreview*>(pOldSh)) 1185 pVS = pPagePreview->GetViewShell(); 1186 else 1187 { 1188 if (SwView* pView = dynamic_cast<SwView *>(pOldSh)) 1189 { 1190 pVS = pView->GetWrtShellPtr(); 1191 // save the current ViewData of the previous SwView 1192 pOldSh->WriteUserData( m_sSwViewData ); 1193 } 1194 else 1195 pVS = GetDocShell()->GetWrtShell(); 1196 if( pVS ) 1197 { 1198 // Set the current page as the first. 1199 sal_uInt16 nPhysPg, nVirtPg; 1200 static_cast<SwCursorShell*>(pVS)->GetPageNum( nPhysPg, nVirtPg, true, false ); 1201 if( 1 != m_pViewWin->GetCol() && 1 == nPhysPg ) 1202 --nPhysPg; 1203 m_pViewWin->SetSttPage( nPhysPg ); 1204 } 1205 } 1206 1207 // for form shell remember design mode of draw view 1208 // of previous view shell 1209 if ( pVS && pVS->HasDrawView() ) 1210 { 1211 mbResetFormDesignMode = true; 1212 mbFormDesignModeToReset = pVS->GetDrawView()->IsDesignMode(); 1213 } 1214 1215 if( pVS ) 1216 pNew = new SwViewShell( *pVS, m_pViewWin, nullptr, VSHELLFLAG_ISPREVIEW ); 1217 else 1218 pNew = new SwViewShell( 1219 *static_cast<SwDocShell*>(pViewFrame->GetObjectShell())->GetDoc(), 1220 m_pViewWin, nullptr, nullptr, VSHELLFLAG_ISPREVIEW ); 1221 1222 m_pViewWin->SetViewShell( pNew ); 1223 pNew->SetSfxViewShell( this ); 1224 Init(); 1225 } 1226 1227 SwPagePreview::~SwPagePreview() 1228 { 1229 SetWindow( nullptr ); 1230 SwViewShell* pVShell = m_pViewWin->GetViewShell(); 1231 pVShell->SetWin(nullptr); 1232 delete pVShell; 1233 1234 m_pViewWin.disposeAndClear(); 1235 if (SfxViewFrame* pCurrent = SfxViewFrame::Current()) 1236 if (auto& pBar = pCurrent->GetWindow().GetSystemWindow()->GetNotebookBar()) 1237 pBar->ControlListener(false); 1238 m_pScrollFill.disposeAndClear(); 1239 m_pHScrollbar.disposeAndClear(); 1240 m_pVScrollbar.disposeAndClear(); 1241 } 1242 1243 SwDocShell* SwPagePreview::GetDocShell() 1244 { 1245 return dynamic_cast<SwDocShell*>( GetViewFrame()->GetObjectShell() ); 1246 } 1247 1248 void SwPagePreview::CreateScrollbar( bool bHori ) 1249 { 1250 vcl::Window *pMDI = &GetViewFrame()->GetWindow(); 1251 VclPtr<SwScrollbar>& ppScrollbar = bHori ? m_pHScrollbar : m_pVScrollbar; 1252 1253 assert(!ppScrollbar.get()); //check beforehand! 1254 1255 ppScrollbar = VclPtr<SwScrollbar>::Create( pMDI, bHori ); 1256 1257 ScrollDocSzChg(); 1258 ppScrollbar->EnableDrag(); 1259 ppScrollbar->SetEndScrollHdl( LINK( this, SwPagePreview, EndScrollHdl )); 1260 1261 ppScrollbar->SetScrollHdl( LINK( this, SwPagePreview, ScrollHdl )); 1262 1263 InvalidateBorder(); 1264 ppScrollbar->ExtendedShow(); 1265 } 1266 1267 bool SwPagePreview::ChgPage( int eMvMode, bool bUpdateScrollbar ) 1268 { 1269 tools::Rectangle aPixVisArea( m_pViewWin->LogicToPixel( m_aVisArea ) ); 1270 bool bChg = m_pViewWin->MovePage( eMvMode ) || 1271 eMvMode == SwPagePreviewWin::MV_CALC || 1272 eMvMode == SwPagePreviewWin::MV_NEWWINSIZE; 1273 m_aVisArea = m_pViewWin->PixelToLogic( aPixVisArea ); 1274 1275 if( bChg ) 1276 { 1277 // Update statusbar 1278 OUString aStr = m_sPageStr + m_pViewWin->GetStatusStr( mnPageCount ); 1279 SfxBindings& rBindings = GetViewFrame()->GetBindings(); 1280 1281 if( bUpdateScrollbar ) 1282 { 1283 ScrollViewSzChg(); 1284 1285 static sal_uInt16 aInval[] = 1286 { 1287 FN_START_OF_DOCUMENT, FN_END_OF_DOCUMENT, 1288 FN_PAGEUP, FN_PAGEDOWN, 0 1289 }; 1290 rBindings.Invalidate( aInval ); 1291 } 1292 rBindings.SetState( SfxStringItem( FN_STAT_PAGE, aStr ) ); 1293 } 1294 return bChg; 1295 } 1296 1297 // From here, everything was taken from the SwView. 1298 void SwPagePreview::CalcAndSetBorderPixel( SvBorder &rToFill ) 1299 { 1300 const StyleSettings &rSet = m_pViewWin->GetSettings().GetStyleSettings(); 1301 const long nTmp = rSet.GetScrollBarSize(); 1302 if ( m_pVScrollbar->IsVisible( true ) ) 1303 rToFill.Right() = nTmp; 1304 if ( m_pHScrollbar->IsVisible( true ) ) 1305 rToFill.Bottom() = nTmp; 1306 SetBorderPixel( rToFill ); 1307 } 1308 1309 void SwPagePreview::InnerResizePixel( const Point &rOfst, const Size &rSize, bool ) 1310 { 1311 SvBorder aBorder; 1312 CalcAndSetBorderPixel( aBorder ); 1313 tools::Rectangle aRect( rOfst, rSize ); 1314 aRect += aBorder; 1315 ViewResizePixel( *m_pViewWin, aRect.TopLeft(), aRect.GetSize(), 1316 m_pViewWin->GetOutputSizePixel(), 1317 *m_pVScrollbar, *m_pHScrollbar, *m_pScrollFill ); 1318 1319 // Never set EditWin ! 1320 // Never set VisArea ! 1321 } 1322 1323 void SwPagePreview::OuterResizePixel( const Point &rOfst, const Size &rSize ) 1324 { 1325 SvBorder aBorder; 1326 CalcAndSetBorderPixel( aBorder ); 1327 1328 // Never set EditWin ! 1329 1330 Size aTmpSize( m_pViewWin->GetOutputSizePixel() ); 1331 Point aBottomRight( m_pViewWin->PixelToLogic( Point( aTmpSize.Width(), aTmpSize.Height() ) ) ); 1332 SetVisArea( tools::Rectangle( Point(), aBottomRight ) ); 1333 1334 // Call of the DocSzChgd-Method of the scrollbars is necessary, 1335 // because from the maximum scroll range half the height of the 1336 // VisArea is always deducted. 1337 if ( m_pVScrollbar && aTmpSize.Width() > 0 && aTmpSize.Height() > 0 ) 1338 { 1339 ScrollDocSzChg(); 1340 } 1341 1342 SvBorder aBorderNew; 1343 CalcAndSetBorderPixel( aBorderNew ); 1344 ViewResizePixel( *m_pViewWin, rOfst, rSize, m_pViewWin->GetOutputSizePixel(), 1345 *m_pVScrollbar, *m_pHScrollbar, *m_pScrollFill ); 1346 } 1347 1348 void SwPagePreview::SetVisArea( const tools::Rectangle &rRect ) 1349 { 1350 const Point aTopLeft(AlignToPixel(rRect.TopLeft())); 1351 const Point aBottomRight(AlignToPixel(rRect.BottomRight())); 1352 tools::Rectangle aLR(aTopLeft,aBottomRight); 1353 1354 if(aLR == m_aVisArea) 1355 return; 1356 // No negative position, no negative size 1357 1358 if(aLR.Top() < 0) 1359 { 1360 aLR.AdjustBottom(std::abs(aLR.Top()) ); 1361 aLR.SetTop( 0 ); 1362 } 1363 1364 if(aLR.Left() < 0) 1365 { 1366 aLR.AdjustRight(std::abs(aLR.Left()) ); 1367 aLR.SetLeft( 0 ); 1368 } 1369 if(aLR.Right() < 0) aLR.SetRight( 0 ); 1370 if(aLR.Bottom() < 0) aLR.SetBottom( 0 ); 1371 if(aLR == m_aVisArea || 1372 // Ignore empty rectangle 1373 ( 0 == aLR.Bottom() - aLR.Top() && 0 == aLR.Right() - aLR.Left() ) ) 1374 return; 1375 1376 if( aLR.Left() > aLR.Right() || aLR.Top() > aLR.Bottom() ) 1377 return; 1378 1379 // Before the data can be changed call an update if necessary. 1380 // Thereby ensured, that adjacent paints are correctly converted into 1381 // document coordinates. 1382 // As a precaution, we do this only when at the shell runs an action, 1383 // because then we do not really paint but the rectangles are just 1384 // bookmarked (in document coordinates). 1385 if( GetViewShell()->ActionPend() ) 1386 m_pViewWin->Update(); 1387 1388 // Set at View-Win the current size 1389 m_aVisArea = aLR; 1390 m_pViewWin->SetWinSize( aLR.GetSize() ); 1391 ChgPage( SwPagePreviewWin::MV_NEWWINSIZE ); 1392 1393 m_pViewWin->Invalidate(); 1394 } 1395 1396 IMPL_LINK( SwPagePreview, ScrollHdl, ScrollBar *, p, void ) 1397 { 1398 SwScrollbar* pScrollbar = static_cast<SwScrollbar*>(p); 1399 if(!GetViewShell()) 1400 return; 1401 if( !pScrollbar->IsHoriScroll() && 1402 pScrollbar->GetType() == ScrollType::Drag && 1403 Help::IsQuickHelpEnabled() && 1404 GetViewShell()->PagePreviewLayout()->DoesPreviewLayoutRowsFitIntoWindow()) 1405 { 1406 // Scroll how many pages?? 1407 OUString sStateStr(m_sPageStr); 1408 long nThmbPos = pScrollbar->GetThumbPos(); 1409 if( 1 == m_pViewWin->GetCol() || !nThmbPos ) 1410 ++nThmbPos; 1411 sStateStr += OUString::number( nThmbPos ); 1412 Point aPos = pScrollbar->GetParent()->OutputToScreenPixel( 1413 pScrollbar->GetPosPixel()); 1414 aPos.setY( pScrollbar->OutputToScreenPixel(pScrollbar->GetPointerPosPixel()).Y() ); 1415 tools::Rectangle aRect; 1416 aRect.SetLeft( aPos.X() -8 ); 1417 aRect.SetRight( aRect.Left() ); 1418 aRect.SetTop( aPos.Y() ); 1419 aRect.SetBottom( aRect.Top() ); 1420 1421 Help::ShowQuickHelp(pScrollbar, aRect, sStateStr, 1422 QuickHelpFlags::Right|QuickHelpFlags::VCenter); 1423 1424 } 1425 else 1426 EndScrollHdl( pScrollbar ); 1427 } 1428 1429 IMPL_LINK( SwPagePreview, EndScrollHdl, ScrollBar *, p, void ) 1430 { 1431 SwScrollbar* pScrollbar = static_cast<SwScrollbar*>(p); 1432 if(!GetViewShell()) 1433 return; 1434 1435 // boolean to avoid unnecessary invalidation of the window. 1436 bool bInvalidateWin = true; 1437 1438 if( !pScrollbar->IsHoriScroll() ) // scroll vertically 1439 { 1440 if ( Help::IsQuickHelpEnabled() ) 1441 Help::ShowQuickHelp(pScrollbar, tools::Rectangle(), OUString()); 1442 if ( GetViewShell()->PagePreviewLayout()->DoesPreviewLayoutRowsFitIntoWindow() ) 1443 { 1444 // Scroll how many pages ?? 1445 const sal_uInt16 nThmbPos = static_cast<sal_uInt16>(pScrollbar->GetThumbPos()); 1446 // adjust to new preview functionality 1447 if( nThmbPos != m_pViewWin->SelectedPage() ) 1448 { 1449 // consider case that page <nThmbPos> 1450 // is already visible 1451 SwPagePreviewLayout* pPagePreviewLay = GetViewShell()->PagePreviewLayout(); 1452 if ( pPagePreviewLay->IsPageVisible( nThmbPos ) ) 1453 { 1454 pPagePreviewLay->MarkNewSelectedPage( nThmbPos ); 1455 // invalidation of window is unnecessary 1456 bInvalidateWin = false; 1457 } 1458 else 1459 { 1460 // consider whether layout columns 1461 // fit or not. 1462 if ( !pPagePreviewLay->DoesPreviewLayoutColsFitIntoWindow() ) 1463 { 1464 m_pViewWin->SetSttPage( nThmbPos ); 1465 m_pViewWin->SetSelectedPage( nThmbPos ); 1466 ChgPage( SwPagePreviewWin::MV_SCROLL, false ); 1467 // update scrollbars 1468 ScrollViewSzChg(); 1469 } 1470 else 1471 { 1472 // correct scroll amount 1473 const sal_Int16 nPageDiff = nThmbPos - m_pViewWin->SelectedPage(); 1474 const sal_uInt16 nVisPages = m_pViewWin->GetRow() * m_pViewWin->GetCol(); 1475 sal_Int16 nWinPagesToScroll = nPageDiff / nVisPages; 1476 if ( nPageDiff % nVisPages ) 1477 { 1478 // decrease/increase number of preview pages to scroll 1479 nPageDiff < 0 ? --nWinPagesToScroll : ++nWinPagesToScroll; 1480 } 1481 m_pViewWin->SetSelectedPage( nThmbPos ); 1482 m_pViewWin->Scroll( 0, pPagePreviewLay->GetWinPagesScrollAmount( nWinPagesToScroll ) ); 1483 } 1484 } 1485 // update accessibility 1486 GetViewShell()->ShowPreviewSelection( nThmbPos ); 1487 } 1488 else 1489 { 1490 // invalidation of window is unnecessary 1491 bInvalidateWin = false; 1492 } 1493 } 1494 else 1495 { 1496 long nThmbPos = pScrollbar->GetThumbPos(); 1497 m_pViewWin->Scroll(0, nThmbPos - m_pViewWin->GetPaintedPreviewDocRect().Top()); 1498 } 1499 } 1500 else 1501 { 1502 long nThmbPos = pScrollbar->GetThumbPos(); 1503 m_pViewWin->Scroll(nThmbPos - m_pViewWin->GetPaintedPreviewDocRect().Left(), 0); 1504 } 1505 // additional invalidate page status. 1506 static sal_uInt16 aInval[] = 1507 { 1508 FN_START_OF_DOCUMENT, FN_END_OF_DOCUMENT, FN_PAGEUP, FN_PAGEDOWN, 1509 FN_STAT_PAGE, 0 1510 }; 1511 SfxBindings& rBindings = GetViewFrame()->GetBindings(); 1512 rBindings.Invalidate( aInval ); 1513 // control invalidation of window 1514 if ( bInvalidateWin ) 1515 { 1516 m_pViewWin->Invalidate(); 1517 } 1518 } 1519 1520 Point SwPagePreview::AlignToPixel(const Point &rPt) const 1521 { 1522 return m_pViewWin->PixelToLogic( m_pViewWin->LogicToPixel( rPt ) ); 1523 } 1524 1525 void SwPagePreview::DocSzChgd( const Size &rSz ) 1526 { 1527 if( m_aDocSize == rSz ) 1528 return; 1529 1530 m_aDocSize = rSz; 1531 1532 // #i96726# 1533 // Due to the multiple page layout it is needed to trigger recalculation 1534 // of the page preview layout, even if the count of pages is not changing. 1535 mnPageCount = GetViewShell()->GetNumPages(); 1536 1537 if( m_aVisArea.GetWidth() ) 1538 { 1539 ChgPage( SwPagePreviewWin::MV_CALC ); 1540 ScrollDocSzChg(); 1541 1542 m_pViewWin->Invalidate(); 1543 } 1544 } 1545 1546 void SwPagePreview::ScrollViewSzChg() 1547 { 1548 if(!GetViewShell()) 1549 return ; 1550 1551 bool bShowVScrollbar = false, bShowHScrollbar = false; 1552 1553 if(m_pVScrollbar) 1554 { 1555 if(GetViewShell()->PagePreviewLayout()->DoesPreviewLayoutRowsFitIntoWindow()) 1556 { 1557 //vertical scrolling by row 1558 // adjust to new preview functionality 1559 const sal_uInt16 nVisPages = m_pViewWin->GetRow() * m_pViewWin->GetCol(); 1560 1561 m_pVScrollbar->SetVisibleSize( nVisPages ); 1562 // set selected page as scroll bar position, 1563 // if it is visible. 1564 SwPagePreviewLayout* pPagePreviewLay = GetViewShell()->PagePreviewLayout(); 1565 if ( pPagePreviewLay->IsPageVisible( m_pViewWin->SelectedPage() ) ) 1566 { 1567 m_pVScrollbar->SetThumbPos( m_pViewWin->SelectedPage() ); 1568 } 1569 else 1570 { 1571 m_pVScrollbar->SetThumbPos( m_pViewWin->GetSttPage() ); 1572 } 1573 m_pVScrollbar->SetLineSize( m_pViewWin->GetCol() ); 1574 m_pVScrollbar->SetPageSize( nVisPages ); 1575 // calculate and set scrollbar range 1576 Range aScrollbarRange( 1, mnPageCount ); 1577 // increase range by one, because left-top-corner is left blank. 1578 ++aScrollbarRange.Max(); 1579 // increase range in order to access all pages 1580 aScrollbarRange.Max() += ( nVisPages - 1 ); 1581 m_pVScrollbar->SetRange( aScrollbarRange ); 1582 1583 bShowVScrollbar = nVisPages < mnPageCount; 1584 } 1585 else //vertical scrolling by pixel 1586 { 1587 const tools::Rectangle& rDocRect = m_pViewWin->GetPaintedPreviewDocRect(); 1588 const Size& rPreviewSize = 1589 GetViewShell()->PagePreviewLayout()->GetPreviewDocSize(); 1590 m_pVScrollbar->SetRangeMax(rPreviewSize.Height()) ; 1591 long nVisHeight = rDocRect.GetHeight(); 1592 m_pVScrollbar->SetVisibleSize( nVisHeight ); 1593 m_pVScrollbar->SetThumbPos( rDocRect.Top() ); 1594 m_pVScrollbar->SetLineSize( nVisHeight / 10 ); 1595 m_pVScrollbar->SetPageSize( nVisHeight / 2 ); 1596 1597 bShowVScrollbar = true; 1598 } 1599 1600 if (!mbVScrollbarEnabled) 1601 bShowVScrollbar = false; 1602 1603 ShowVScrollbar(bShowVScrollbar); 1604 } 1605 if(m_pHScrollbar) 1606 { 1607 const tools::Rectangle& rDocRect = m_pViewWin->GetPaintedPreviewDocRect(); 1608 const Size& rPreviewSize = 1609 GetViewShell()->PagePreviewLayout()->GetPreviewDocSize(); 1610 Range aRange(0,0); 1611 1612 if(rDocRect.GetWidth() < rPreviewSize.Width()) 1613 { 1614 bShowHScrollbar = true; 1615 1616 long nVisWidth = rDocRect.GetWidth(); 1617 long nThumb = rDocRect.Left(); 1618 aRange = Range(0, rPreviewSize.Width()); 1619 1620 m_pHScrollbar->SetRange( aRange ); 1621 m_pHScrollbar->SetVisibleSize( nVisWidth ); 1622 m_pHScrollbar->SetThumbPos( nThumb ); 1623 m_pHScrollbar->SetLineSize( nVisWidth / 10 ); 1624 m_pHScrollbar->SetPageSize( nVisWidth / 2 ); 1625 } 1626 1627 if (!mbHScrollbarEnabled) 1628 bShowHScrollbar = false; 1629 1630 ShowHScrollbar(bShowHScrollbar); 1631 } 1632 m_pScrollFill->Show(bShowVScrollbar && bShowHScrollbar); 1633 } 1634 1635 void SwPagePreview::ScrollDocSzChg() 1636 { 1637 ScrollViewSzChg(); 1638 } 1639 1640 // All about printing 1641 SfxPrinter* SwPagePreview::GetPrinter( bool bCreate ) 1642 { 1643 return m_pViewWin->GetViewShell()->getIDocumentDeviceAccess().getPrinter( bCreate ); 1644 } 1645 1646 sal_uInt16 SwPagePreview::SetPrinter( SfxPrinter *pNew, SfxPrinterChangeFlags nDiffFlags ) 1647 { 1648 SwViewShell &rSh = *GetViewShell(); 1649 SfxPrinter* pOld = rSh.getIDocumentDeviceAccess().getPrinter( false ); 1650 if ( pOld && pOld->IsPrinting() ) 1651 return SFX_PRINTERROR_BUSY; 1652 1653 SwEditShell &rESh = static_cast<SwEditShell&>(rSh); //Buh... 1654 if( ( SfxPrinterChangeFlags::PRINTER | SfxPrinterChangeFlags::JOBSETUP ) & nDiffFlags ) 1655 { 1656 rSh.getIDocumentDeviceAccess().setPrinter( pNew, true, true ); 1657 if( nDiffFlags & SfxPrinterChangeFlags::PRINTER ) 1658 rESh.SetModified(); 1659 } 1660 if ( ( nDiffFlags & SfxPrinterChangeFlags::OPTIONS ) == SfxPrinterChangeFlags::OPTIONS ) 1661 ::SetPrinter( &rSh.getIDocumentDeviceAccess(), pNew, false ); 1662 1663 const bool bChgOri = bool(nDiffFlags & SfxPrinterChangeFlags::CHG_ORIENTATION); 1664 const bool bChgSize = bool(nDiffFlags & SfxPrinterChangeFlags::CHG_SIZE); 1665 if ( bChgOri || bChgSize ) 1666 { 1667 rESh.StartAllAction(); 1668 if ( bChgOri ) 1669 rSh.ChgAllPageOrientation( pNew->GetOrientation() ); 1670 if ( bChgSize ) 1671 { 1672 Size aSz( SvxPaperInfo::GetPaperSize( pNew ) ); 1673 rSh.ChgAllPageSize( aSz ); 1674 } 1675 if( !m_bNormalPrint ) 1676 m_pViewWin->CalcWish( m_pViewWin->GetRow(), m_pViewWin->GetCol() ); 1677 rESh.SetModified(); 1678 rESh.EndAllAction(); 1679 1680 static sal_uInt16 aInval[] = 1681 { 1682 SID_ATTR_LONG_ULSPACE, SID_ATTR_LONG_LRSPACE, 1683 SID_RULER_BORDERS, SID_RULER_PAGE_POS, 0 1684 }; 1685 #if OSL_DEBUG_LEVEL > 0 1686 { 1687 const sal_uInt16* pPtr = aInval + 1; 1688 do { 1689 OSL_ENSURE( *(pPtr - 1) < *pPtr, "wrong sorting!" ); 1690 } while( *++pPtr ); 1691 } 1692 #endif 1693 1694 GetViewFrame()->GetBindings().Invalidate(aInval); 1695 } 1696 1697 return 0; 1698 } 1699 1700 bool SwPagePreview::HasPrintOptionsPage() const 1701 { 1702 return true; 1703 } 1704 1705 VclPtr<SfxTabPage> SwPagePreview::CreatePrintOptionsPage( weld::Container* pPage, 1706 const SfxItemSet &rOptions ) 1707 { 1708 return ::CreatePrintOptionsPage(pPage, rOptions, !m_bNormalPrint); 1709 } 1710 1711 void SwPagePreviewWin::SetViewShell( SwViewShell* pShell ) 1712 { 1713 mpViewShell = pShell; 1714 if ( mpViewShell && mpViewShell->IsPreview() ) 1715 { 1716 mpPgPreviewLayout = mpViewShell->PagePreviewLayout(); 1717 } 1718 } 1719 1720 void SwPagePreviewWin::RepaintCoreRect( const SwRect& rRect ) 1721 { 1722 // #i24183# 1723 if ( mpPgPreviewLayout->PreviewLayoutValid() ) 1724 { 1725 mpPgPreviewLayout->Repaint( tools::Rectangle( rRect.Pos(), rRect.SSize() ) ); 1726 } 1727 } 1728 1729 /** method to adjust preview to a new zoom factor 1730 1731 #i19975# also consider zoom type - adding parameter <_eZoomType> 1732 */ 1733 void SwPagePreviewWin::AdjustPreviewToNewZoom( const sal_uInt16 _nZoomFactor, 1734 const SvxZoomType _eZoomType ) 1735 { 1736 // #i19975# consider zoom type 1737 if ( _eZoomType == SvxZoomType::WHOLEPAGE ) 1738 { 1739 mnRow = 1; 1740 mnCol = 1; 1741 mpPgPreviewLayout->Init( mnCol, mnRow, maPxWinSize ); 1742 mpPgPreviewLayout->Prepare( mnSttPage, Point(0,0), maPxWinSize, 1743 mnSttPage, maPaintedPreviewDocRect ); 1744 SetSelectedPage( mnSttPage ); 1745 SetPagePreview(mnRow, mnCol); 1746 maScale = GetMapMode().GetScaleX(); 1747 } 1748 else if ( _nZoomFactor != 0 ) 1749 { 1750 // calculate new scaling and set mapping mode appropriately. 1751 Fraction aNewScale( _nZoomFactor, 100 ); 1752 MapMode aNewMapMode = GetMapMode(); 1753 aNewMapMode.SetScaleX( aNewScale ); 1754 aNewMapMode.SetScaleY( aNewScale ); 1755 SetMapMode( aNewMapMode ); 1756 1757 // calculate new start position for preview paint 1758 Size aNewWinSize = PixelToLogic( maPxWinSize ); 1759 Point aNewPaintStartPos = 1760 mpPgPreviewLayout->GetPreviewStartPosForNewScale( aNewScale, maScale, aNewWinSize ); 1761 1762 // remember new scaling and prepare preview paint 1763 // Note: paint of preview will be performed by a corresponding invalidate 1764 // due to property changes. 1765 maScale = aNewScale; 1766 mpPgPreviewLayout->Prepare( 0, aNewPaintStartPos, maPxWinSize, 1767 mnSttPage, maPaintedPreviewDocRect ); 1768 } 1769 1770 } 1771 1772 /** 1773 * pixel scrolling - horizontally always or vertically 1774 * when less than the desired number of rows fits into 1775 * the view 1776 */ 1777 void SwPagePreviewWin::Scroll(long nXMove, long nYMove, ScrollFlags /*nFlags*/) 1778 { 1779 maPaintedPreviewDocRect.Move(nXMove, nYMove); 1780 mpPgPreviewLayout->Prepare( 0, maPaintedPreviewDocRect.TopLeft(), 1781 maPxWinSize, mnSttPage, 1782 maPaintedPreviewDocRect ); 1783 1784 } 1785 1786 bool SwPagePreview::HandleWheelCommands( const CommandEvent& rCEvt ) 1787 { 1788 bool bOk = false; 1789 const CommandWheelData* pWData = rCEvt.GetWheelData(); 1790 if( pWData && CommandWheelMode::ZOOM == pWData->GetMode() ) 1791 { 1792 //only the Preference shouldn't control the Zoom, it is better to detect AT tools running. So the bridge can be used here 1793 if (!Application::GetSettings().GetMiscSettings().GetEnableATToolSupport()) 1794 { 1795 sal_uInt16 nFactor = GetViewShell()->GetViewOptions()->GetZoom(); 1796 const sal_uInt16 nOffset = 10; 1797 if( 0L > pWData->GetDelta() ) 1798 { 1799 nFactor -= nOffset; 1800 if(nFactor < MIN_PREVIEW_ZOOM) 1801 nFactor = MIN_PREVIEW_ZOOM; 1802 } 1803 else 1804 { 1805 nFactor += nOffset; 1806 if(nFactor > MAX_PREVIEW_ZOOM) 1807 nFactor = MAX_PREVIEW_ZOOM; 1808 } 1809 SetZoom(SvxZoomType::PERCENT, nFactor); 1810 } 1811 bOk = true; 1812 } 1813 else 1814 bOk = m_pViewWin->HandleScrollCommand( rCEvt, m_pHScrollbar, m_pVScrollbar ); 1815 return bOk; 1816 } 1817 1818 uno::Reference< css::accessibility::XAccessible > 1819 SwPagePreviewWin::CreateAccessible() 1820 { 1821 SolarMutexGuard aGuard; // this should have happened already!!! 1822 1823 OSL_ENSURE( GetViewShell() != nullptr, "We need a view shell" ); 1824 css::uno::Reference< css::accessibility::XAccessible > xAcc = GetAccessible( false ); 1825 if (xAcc.is()) 1826 { 1827 return xAcc; 1828 } 1829 if (mpViewShell) 1830 { 1831 css::uno::Reference< css::accessibility::XAccessible > xAccPreview = mpViewShell->CreateAccessiblePreview(); 1832 SetAccessible(xAccPreview); 1833 } 1834 return GetAccessible( false ); 1835 } 1836 1837 void SwPagePreview::ApplyAccessiblityOptions(SvtAccessibilityOptions const & rAccessibilityOptions) 1838 { 1839 GetViewShell()->ApplyAccessiblityOptions(rAccessibilityOptions); 1840 } 1841 1842 void SwPagePreview::ShowHScrollbar(bool bShow) 1843 { 1844 m_pHScrollbar->Show(bShow); 1845 InvalidateBorder(); 1846 } 1847 1848 void SwPagePreview::ShowVScrollbar(bool bShow) 1849 { 1850 m_pVScrollbar->Show(bShow); 1851 InvalidateBorder(); 1852 } 1853 1854 void SwPagePreview::EnableHScrollbar(bool bEnable) 1855 { 1856 if (mbHScrollbarEnabled != bEnable) 1857 { 1858 mbHScrollbarEnabled = bEnable; 1859 ScrollViewSzChg(); 1860 } 1861 } 1862 1863 void SwPagePreview::EnableVScrollbar(bool bEnable) 1864 { 1865 if (mbVScrollbarEnabled != bEnable) 1866 { 1867 mbVScrollbarEnabled = bEnable; 1868 ScrollViewSzChg(); 1869 } 1870 } 1871 1872 void SwPagePreview::SetZoom(SvxZoomType eType, sal_uInt16 nFactor) 1873 { 1874 SwViewShell& rSh = *GetViewShell(); 1875 SwViewOption aOpt(*rSh.GetViewOptions()); 1876 // perform action only on changes of zoom or zoom type. 1877 if ( aOpt.GetZoom() != nFactor || 1878 aOpt.GetZoomType() != eType ) 1879 { 1880 aOpt.SetZoom(nFactor); 1881 aOpt.SetZoomType(eType); 1882 rSh.ApplyViewOptions( aOpt ); 1883 lcl_InvalidateZoomSlots(GetViewFrame()->GetBindings()); 1884 // #i19975# also consider zoom type 1885 m_pViewWin->AdjustPreviewToNewZoom( nFactor, eType ); 1886 ScrollViewSzChg(); 1887 } 1888 } 1889 1890 /** adjust position of vertical scrollbar */ 1891 void SwPagePreview::SetVScrollbarThumbPos( const sal_uInt16 _nNewThumbPos ) 1892 { 1893 if ( m_pVScrollbar ) 1894 { 1895 m_pVScrollbar->SetThumbPos( _nNewThumbPos ); 1896 } 1897 } 1898 1899 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 1900
