1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_sw.hxx" 26 27 #include <sfx2/objface.hxx> 28 #include <vcl/timer.hxx> 29 #include <vcl/field.hxx> 30 #include <vcl/fixed.hxx> 31 #include <vcl/help.hxx> 32 #include <vcl/cmdevt.hxx> 33 #include <vcl/button.hxx> 34 #include <svl/whiter.hxx> 35 #include <svl/stritem.hxx> 36 #include <svl/eitem.hxx> 37 #include <sfx2/printer.hxx> 38 #include <sfx2/progress.hxx> 39 #include <sfx2/app.hxx> 40 #include <sfx2/bindings.hxx> 41 #include <sfx2/request.hxx> 42 #include <sfx2/dispatch.hxx> 43 #include <vcl/msgbox.hxx> 44 #include <svx/stddlg.hxx> 45 #include <editeng/paperinf.hxx> 46 #include <svl/srchitem.hxx> 47 #include <svx/svdview.hxx> 48 #include <svx/dlgutil.hxx> 49 #include <svx/zoomslideritem.hxx> 50 #include <svx/svxids.hrc> 51 52 #include <swwait.hxx> 53 #include <globdoc.hxx> 54 #include <wdocsh.hxx> 55 #include <pvprtdat.hxx> 56 #include <swmodule.hxx> 57 #include <modcfg.hxx> 58 #include <wrtsh.hxx> 59 #include <docsh.hxx> 60 #include <viewopt.hxx> 61 #include <doc.hxx> 62 #include <pview.hxx> 63 #include <view.hxx> 64 #include <textsh.hxx> 65 #include <scroll.hxx> 66 #include <prtopt.hxx> 67 #include <docstat.hxx> 68 #include <usrpref.hxx> 69 #include <viewfunc.hxx> 70 71 #include <helpid.h> 72 #include <cmdid.h> 73 #include <globals.hrc> 74 #include <popup.hrc> 75 #include <pview.hrc> 76 77 #define SwPagePreView 78 #include <sfx2/msg.hxx> 79 #include <swslots.hxx> 80 // OD 12.12.2002 #103492# 81 #include <pagepreviewlayout.hxx> 82 83 #include <svx/svxdlg.hxx> 84 #include <svx/dialogs.hrc> 85 #include <vos/mutex.hxx> 86 87 88 using namespace ::com::sun::star; 89 90 SFX_IMPL_NAMED_VIEWFACTORY(SwPagePreView, "PrintPreview") 91 { 92 SFX_VIEW_REGISTRATION(SwDocShell); 93 SFX_VIEW_REGISTRATION(SwWebDocShell); 94 SFX_VIEW_REGISTRATION(SwGlobalDocShell); 95 } 96 97 SFX_IMPL_INTERFACE(SwPagePreView, SfxViewShell, SW_RES(RID_PVIEW_TOOLBOX)) 98 { 99 SFX_POPUPMENU_REGISTRATION(SW_RES(MN_PPREVIEW_POPUPMENU)); 100 SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT|SFX_VISIBILITY_STANDARD| 101 SFX_VISIBILITY_CLIENT|SFX_VISIBILITY_FULLSCREEN| 102 SFX_VISIBILITY_READONLYDOC, 103 SW_RES(RID_PVIEW_TOOLBOX)); 104 } 105 106 107 TYPEINIT1(SwPagePreView,SfxViewShell) 108 109 #define SWVIEWFLAGS ( SFX_VIEW_CAN_PRINT|SFX_VIEW_HAS_PRINTOPTIONS ) 110 111 #define MIN_PREVIEW_ZOOM 25 112 #define MAX_PREVIEW_ZOOM 600 113 /* */ 114 /* -----------------26.11.2002 10:41----------------- 115 * 116 * --------------------------------------------------*/ 117 sal_uInt16 lcl_GetNextZoomStep(sal_uInt16 nCurrentZoom, sal_Bool bZoomIn) 118 { 119 static sal_uInt16 aZoomArr[] = 120 { 121 25, 50, 75, 100, 150, 200, 400, 600 122 }; 123 const sal_uInt16 nZoomArrSize = sizeof(aZoomArr)/sizeof(sal_uInt16); 124 if(bZoomIn) 125 for(int i = nZoomArrSize - 1; i >= 0; --i) 126 { 127 if(nCurrentZoom > aZoomArr[i] || !i) 128 return aZoomArr[i]; 129 } 130 else 131 for(int i = 0; i < nZoomArrSize; ++i) 132 { 133 if(nCurrentZoom < aZoomArr[i]) 134 return aZoomArr[i]; 135 } 136 return bZoomIn ? MAX_PREVIEW_ZOOM : MIN_PREVIEW_ZOOM; 137 }; 138 /* -----------------02.12.2002 09:11----------------- 139 * 140 * --------------------------------------------------*/ 141 void lcl_InvalidateZoomSlots(SfxBindings& rBindings) 142 { 143 static sal_uInt16 __READONLY_DATA aInval[] = 144 { 145 SID_ATTR_ZOOM, SID_ZOOM_OUT, SID_ZOOM_IN, SID_ATTR_ZOOMSLIDER, FN_PREVIEW_ZOOM, FN_STAT_ZOOM, 146 0 147 }; 148 rBindings.Invalidate( aInval ); 149 } 150 /*-------------------------------------------------------------------- 151 Beschreibung: 152 --------------------------------------------------------------------*/ 153 154 // erstmal der Zoom-Dialog 155 156 class SwPreViewZoomDlg : public SvxStandardDialog 157 { 158 FixedText aRowLbl; 159 NumericField aRowEdit; 160 FixedText aColLbl; 161 NumericField aColEdit; 162 163 OKButton aOkBtn; 164 CancelButton aCancelBtn; 165 HelpButton aHelpBtn; 166 167 virtual void Apply(); 168 169 public: 170 SwPreViewZoomDlg( SwPagePreViewWin& rParent ); 171 ~SwPreViewZoomDlg(); 172 }; 173 174 /*-------------------------------------------------------------------- 175 Beschreibung: 176 --------------------------------------------------------------------*/ 177 178 179 SwPreViewZoomDlg::SwPreViewZoomDlg( SwPagePreViewWin& rParent ) : 180 SvxStandardDialog( &rParent, SW_RES(DLG_PAGEPREVIEW_ZOOM) ), 181 aRowLbl(this,SW_RES(FT_ROW)), 182 aRowEdit(this,SW_RES(ED_ROW)), 183 aColLbl(this,SW_RES(FT_COL)), 184 aColEdit(this,SW_RES(ED_COL)), 185 aOkBtn(this,SW_RES(BT_OK)), 186 aCancelBtn(this,SW_RES(BT_CANCEL)), 187 aHelpBtn(this,SW_RES(BT_HELP)) 188 { 189 FreeResource(); 190 191 aRowEdit.SetValue( rParent.GetRow() ); 192 aColEdit.SetValue( rParent.GetCol() ); 193 } 194 195 /*-------------------------------------------------------------------- 196 Beschreibung: 197 --------------------------------------------------------------------*/ 198 199 SwPreViewZoomDlg::~SwPreViewZoomDlg() {} 200 201 202 void SwPreViewZoomDlg::Apply() 203 { 204 ((SwPagePreViewWin*)GetParent())->CalcWish( 205 sal_uInt8(aRowEdit.GetValue()), 206 sal_uInt8(aColEdit.GetValue()) ); 207 } 208 209 /*-------------------------------------------------------------------- 210 Beschreibung: 211 --------------------------------------------------------------------*/ 212 213 // alles fuers SwPagePreViewWin 214 215 216 SwPagePreViewWin::SwPagePreViewWin( Window *pParent, SwPagePreView& rPView ) 217 : Window( pParent, WinBits( WB_CLIPCHILDREN) ), 218 mpViewShell( 0 ), 219 mrView( rPView ), 220 mbCalcScaleForPreviewLayout( true ), 221 maPaintedPreviewDocRect( Rectangle(0,0,0,0) ) 222 { 223 SetOutDevViewType( OUTDEV_VIEWTYPE_PRINTPREVIEW ); //#106611# 224 SetHelpId(HID_PAGEPREVIEW); 225 SetFillColor( GetBackground().GetColor() ); 226 SetLineColor( GetBackground().GetColor()); 227 SetMapMode( MapMode(MAP_TWIP) ); 228 229 const SwMasterUsrPref *pUsrPref = SW_MOD()->GetUsrPref(sal_False); 230 mnRow = pUsrPref->GetPagePrevRow(); // 1 Zeile 231 mnCol = pUsrPref->GetPagePrevCol(); // 1 Spalte 232 // OD 24.03.2003 #108282# - member <mnVirtPage> no longer exists. 233 mnSttPage = USHRT_MAX; 234 } 235 236 /*-------------------------------------------------------------------- 237 Beschreibung: 238 --------------------------------------------------------------------*/ 239 240 241 SwPagePreViewWin::~SwPagePreViewWin() 242 { 243 if( mpViewShell ) 244 delete mpViewShell; 245 } 246 247 /*-------------------------------------------------------------------- 248 Beschreibung: 249 --------------------------------------------------------------------*/ 250 251 252 void SwPagePreViewWin::Paint( const Rectangle& rRect ) 253 { 254 if( !mpViewShell || !mpViewShell->GetLayout() ) 255 return; 256 257 if( USHRT_MAX == mnSttPage ) // wurde noch nie berechnet ? (Init-Phase!) 258 { 259 // das ist die Size, auf die ich mich immer beziehe 260 if( !maPxWinSize.Height() || !maPxWinSize.Width() ) 261 maPxWinSize = GetOutputSizePixel(); 262 263 Rectangle aRect( LogicToPixel( rRect )); 264 mpPgPrevwLayout->Prepare( 1, Point(0,0), maPxWinSize, 265 mnSttPage, maPaintedPreviewDocRect ); 266 SetSelectedPage( 1 ); 267 mpPgPrevwLayout->Paint( PixelToLogic( aRect ) ); 268 SetPagePreview(mnRow, mnCol); 269 } 270 else 271 { 272 MapMode aMM( GetMapMode() ); 273 aMM.SetScaleX( maScale ); 274 aMM.SetScaleY( maScale ); 275 SetMapMode( aMM ); 276 mpPgPrevwLayout->Paint( rRect ); 277 } 278 } 279 280 /*-------------------------------------------------------------------- 281 Beschreibung: 282 --------------------------------------------------------------------*/ 283 void SwPagePreViewWin::CalcWish( sal_uInt8 nNewRow, sal_uInt8 nNewCol ) 284 { 285 if( !mpViewShell || !mpViewShell->GetLayout() ) 286 return; 287 288 sal_uInt16 nOldCol = mnCol; 289 // OD 02.12.2002 #103492# - update <mnRow> and <mnCol>. 290 mnRow = nNewRow; 291 mnCol = nNewCol; 292 sal_uInt16 nPages = mnRow * mnCol, 293 nLastSttPg = mrView.GetPageCount()+1 > nPages 294 ? mrView.GetPageCount()+1 - nPages : 0; 295 if( mnSttPage > nLastSttPg ) 296 mnSttPage = nLastSttPg; 297 298 mpPgPrevwLayout->Init( mnCol, mnRow, maPxWinSize, true ); 299 mpPgPrevwLayout->Prepare( mnSttPage, Point(0,0), maPxWinSize, 300 mnSttPage, maPaintedPreviewDocRect ); 301 SetSelectedPage( mnSttPage ); 302 SetPagePreview(mnRow, mnCol); 303 maScale = GetMapMode().GetScaleX(); 304 305 // falls an der Spaltigkeit gedreht wurde, so muss der Sonderfall 306 // Einspaltig beachtet und ggfs. der Scrollbar korrigiert werden 307 if( (1 == nOldCol) ^ (1 == mnCol) ) 308 mrView.ScrollDocSzChg(); 309 310 // Sortierung muss eingehalten werden!! 311 // OD 24.03.2003 #108282# - additional invalidate page status. 312 static sal_uInt16 __READONLY_DATA aInval[] = 313 { 314 SID_ATTR_ZOOM, SID_ZOOM_OUT, SID_ZOOM_IN, 315 FN_PREVIEW_ZOOM, 316 FN_START_OF_DOCUMENT, FN_END_OF_DOCUMENT, FN_PAGEUP, FN_PAGEDOWN, 317 FN_STAT_PAGE, FN_STAT_ZOOM, 318 FN_SHOW_TWO_PAGES, FN_SHOW_MULTIPLE_PAGES, 319 0 320 }; 321 SfxBindings& rBindings = mrView.GetViewFrame()->GetBindings(); 322 rBindings.Invalidate( aInval ); 323 rBindings.Update( FN_SHOW_TWO_PAGES ); 324 rBindings.Update( FN_SHOW_MULTIPLE_PAGES ); 325 // OD 18.12.2002 #103492# - adjust scrollbars 326 mrView.ScrollViewSzChg(); 327 } 328 /*-------------------------------------------------------------------- 329 Beschreibung:, mnSttPage is Absolute 330 --------------------------------------------------------------------*/ 331 332 333 int SwPagePreViewWin::MovePage( int eMoveMode ) 334 { 335 // soviele Seiten hoch 336 sal_uInt16 nPages = mnRow * mnCol; 337 sal_uInt16 nNewSttPage = mnSttPage; 338 // OD 04.12.2002 #103492# 339 sal_uInt16 nPageCount = mrView.GetPageCount(); 340 sal_uInt16 nDefSttPg = GetDefSttPage(); 341 // OD 06.12.2002 #103492# 342 bool bPaintPageAtFirstCol = true; 343 344 switch( eMoveMode ) 345 { 346 case MV_PAGE_UP: 347 { 348 const sal_uInt16 nRelSttPage = mpPgPrevwLayout->ConvertAbsoluteToRelativePageNum( mnSttPage ); 349 const sal_uInt16 nNewAbsSttPage = nRelSttPage - nPages > 0 ? 350 mpPgPrevwLayout->ConvertRelativeToAbsolutePageNum( nRelSttPage - nPages ) : 351 nDefSttPg; 352 nNewSttPage = nNewAbsSttPage; 353 354 const sal_uInt16 nRelSelPage = mpPgPrevwLayout->ConvertAbsoluteToRelativePageNum( SelectedPage() ); 355 const sal_uInt16 nNewRelSelPage = nRelSelPage - nPages > 0 ? 356 nRelSelPage - nPages : 357 1; 358 SetSelectedPage( mpPgPrevwLayout->ConvertRelativeToAbsolutePageNum( nNewRelSelPage ) ); 359 360 break; 361 } 362 case MV_PAGE_DOWN: 363 { 364 const sal_uInt16 nRelSttPage = mpPgPrevwLayout->ConvertAbsoluteToRelativePageNum( mnSttPage ); 365 const sal_uInt16 nNewAbsSttPage = mpPgPrevwLayout->ConvertRelativeToAbsolutePageNum( nRelSttPage + nPages ); 366 nNewSttPage = nNewAbsSttPage < nPageCount ? nNewAbsSttPage : nPageCount; 367 368 const sal_uInt16 nRelSelPage = mpPgPrevwLayout->ConvertAbsoluteToRelativePageNum( SelectedPage() ); 369 const sal_uInt16 nNewAbsSelPage = mpPgPrevwLayout->ConvertRelativeToAbsolutePageNum( nRelSelPage + nPages ); 370 SetSelectedPage( nNewAbsSelPage < nPageCount ? nNewAbsSelPage : nPageCount ); 371 372 break; 373 } 374 case MV_DOC_STT: 375 nNewSttPage = nDefSttPg; 376 SetSelectedPage( mpPgPrevwLayout->ConvertRelativeToAbsolutePageNum( nNewSttPage ? nNewSttPage : 1 ) ); 377 break; 378 case MV_DOC_END: 379 // OD 03.12.2002 #103492# - correct calculation of new start page. 380 nNewSttPage = nPageCount; 381 SetSelectedPage( nPageCount ); 382 break; 383 // OD 12.12.2002 #103492# - add new move mode 384 case MV_SELPAGE: 385 // <nNewSttPage> and <SelectedPage()> are already set. 386 // OD 20.02.2003 #107369# - not start at first column, only if the 387 // complete preview layout columns doesn't fit into window. 388 if ( !mpPgPrevwLayout->DoesPreviewLayoutColsFitIntoWindow() ) 389 bPaintPageAtFirstCol = false; 390 break; 391 case MV_SCROLL: 392 // OD 17.01.2003 #103492# - check, if paint page at first column 393 // has to be avoided 394 if ( !mpPgPrevwLayout->DoesPreviewLayoutRowsFitIntoWindow() || 395 !mpPgPrevwLayout->DoesPreviewLayoutColsFitIntoWindow() ) 396 bPaintPageAtFirstCol = false; 397 break; 398 case MV_NEWWINSIZE: 399 // OD 18.12.2002 #103492# - nothing special to do. 400 break; 401 case MV_CALC: 402 // OD 18.12.2002 #103492# - re-init page preview layout. 403 mpPgPrevwLayout->ReInit(); 404 405 // OD 03.12.2002 #103492# - correct calculation of new start page. 406 if( nNewSttPage > nPageCount ) 407 nNewSttPage = nPageCount; 408 409 // OD 18.12.2002 #103492# - correct selected page number 410 if( SelectedPage() > nPageCount ) 411 SetSelectedPage( nNewSttPage ? nNewSttPage : 1 ); 412 } 413 414 mpPgPrevwLayout->Prepare( nNewSttPage, Point(0,0), maPxWinSize, 415 nNewSttPage, 416 maPaintedPreviewDocRect, bPaintPageAtFirstCol ); 417 if( nNewSttPage == mnSttPage && 418 eMoveMode != MV_SELPAGE ) 419 return sal_False; 420 421 SetPagePreview(mnRow, mnCol); 422 mnSttPage = nNewSttPage; 423 424 // OD 24.03.2003 #108282# - additional invalidate page status. 425 static sal_uInt16 __READONLY_DATA aInval[] = 426 { 427 FN_START_OF_DOCUMENT, FN_END_OF_DOCUMENT, FN_PAGEUP, FN_PAGEDOWN, 428 FN_STAT_PAGE, 0 429 }; 430 431 SfxBindings& rBindings = mrView.GetViewFrame()->GetBindings(); 432 rBindings.Invalidate( aInval ); 433 434 return sal_True; 435 } 436 437 /*-------------------------------------------------------------------- 438 Beschreibung: 439 --------------------------------------------------------------------*/ 440 441 442 void SwPagePreViewWin::SetWinSize( const Size& rNewSize ) 443 { 444 // die Size wollen wir aber immer in Pixel-Einheiten haben 445 maPxWinSize = LogicToPixel( rNewSize ); 446 447 if( USHRT_MAX == mnSttPage ) 448 { 449 mnSttPage = GetDefSttPage(); 450 SetSelectedPage( GetDefSttPage() ); 451 } 452 453 if ( mbCalcScaleForPreviewLayout ) 454 { 455 mpPgPrevwLayout->Init( mnCol, mnRow, maPxWinSize, true ); 456 maScale = GetMapMode().GetScaleX(); 457 } 458 mpPgPrevwLayout->Prepare( mnSttPage, Point(0,0), maPxWinSize, 459 mnSttPage, maPaintedPreviewDocRect ); 460 if ( mbCalcScaleForPreviewLayout ) 461 { 462 SetSelectedPage( mnSttPage ); 463 mbCalcScaleForPreviewLayout = false; 464 } 465 SetPagePreview(mnRow, mnCol); 466 maScale = GetMapMode().GetScaleX(); 467 } 468 469 470 /*-------------------------------------------------------------------- 471 Beschreibung: 472 --------------------------------------------------------------------*/ 473 474 475 void SwPagePreViewWin::GetStatusStr( String& rStr, sal_uInt16 nPageCnt ) const 476 { 477 // OD 24.03.2003 #108282# - show physical and virtual page number of 478 // selected page, if it's visible. 479 sal_uInt16 nPageNum; 480 if ( mpPgPrevwLayout->IsPageVisible( mpPgPrevwLayout->SelectedPage() ) ) 481 { 482 nPageNum = mpPgPrevwLayout->SelectedPage(); 483 } 484 else 485 { 486 nPageNum = mnSttPage > 1 ? mnSttPage : 1; 487 } 488 sal_uInt16 nVirtPageNum = mpPgPrevwLayout->GetVirtPageNumByPageNum( nPageNum ); 489 if( nVirtPageNum && nVirtPageNum != nPageNum ) 490 { 491 rStr += String::CreateFromInt32( nVirtPageNum ); 492 rStr += ' '; 493 } 494 rStr += String::CreateFromInt32( nPageNum ); 495 rStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM(" / ")); 496 rStr += String::CreateFromInt32( nPageCnt ); 497 } 498 499 /*-------------------------------------------------------------------- 500 Beschreibung: 501 --------------------------------------------------------------------*/ 502 503 504 void SwPagePreViewWin::KeyInput( const KeyEvent &rKEvt ) 505 { 506 const KeyCode& rKeyCode = rKEvt.GetKeyCode(); 507 sal_uInt16 nKey = rKeyCode.GetCode(); 508 sal_Bool bHandled = sal_False; 509 if(!rKeyCode.GetModifier()) 510 { 511 sal_uInt16 nSlot = 0; 512 switch(nKey) 513 { 514 case KEY_ADD : nSlot = SID_ZOOM_OUT; break; 515 case KEY_ESCAPE: nSlot = FN_CLOSE_PAGEPREVIEW; break; 516 case KEY_SUBTRACT : nSlot = SID_ZOOM_IN; break; 517 } 518 if(nSlot) 519 { 520 bHandled = sal_True; 521 mrView.GetViewFrame()->GetDispatcher()->Execute( 522 nSlot, SFX_CALLMODE_ASYNCHRON ); 523 } 524 } 525 if( !bHandled && !mrView.KeyInput( rKEvt ) ) 526 Window::KeyInput( rKEvt ); 527 } 528 529 /****************************************************************************** 530 * Beschreibung: 531 ******************************************************************************/ 532 533 void SwPagePreViewWin::Command( const CommandEvent& rCEvt ) 534 { 535 sal_Bool bCallBase = sal_True; 536 switch( rCEvt.GetCommand() ) 537 { 538 case COMMAND_CONTEXTMENU: 539 mrView.GetViewFrame()->GetDispatcher()->ExecutePopup(); 540 bCallBase = sal_False; 541 break; 542 543 case COMMAND_WHEEL: 544 case COMMAND_STARTAUTOSCROLL: 545 case COMMAND_AUTOSCROLL: 546 { 547 const CommandWheelData* pData = rCEvt.GetWheelData(); 548 if( pData ) 549 { 550 const CommandWheelData aDataNew(pData->GetDelta(),pData->GetNotchDelta(),COMMAND_WHEEL_PAGESCROLL, 551 pData->GetMode(),pData->GetModifier(),pData->IsHorz(), pData->IsDeltaPixel()); 552 const CommandEvent aEvent( rCEvt.GetMousePosPixel(),rCEvt.GetCommand(),rCEvt.IsMouseEvent(),&aDataNew); 553 bCallBase = !mrView.HandleWheelCommands( aEvent ); 554 } 555 else 556 bCallBase = !mrView.HandleWheelCommands( rCEvt ); 557 } 558 break; 559 default: 560 // OD 17.12.2002 #103492# - delete assertion 561 ; 562 } 563 564 if( bCallBase ) 565 Window::Command( rCEvt ); 566 } 567 568 void SwPagePreViewWin::MouseButtonDown( const MouseEvent& rMEvt ) 569 { 570 // OD 17.12.2002 #103492# - consider single-click to set selected page 571 if( MOUSE_LEFT == ( rMEvt.GetModifier() + rMEvt.GetButtons() ) ) 572 { 573 Point aPrevwPos( PixelToLogic( rMEvt.GetPosPixel() ) ); 574 Point aDocPos; 575 bool bPosInEmptyPage; 576 sal_uInt16 nNewSelectedPage; 577 bool bIsDocPos = 578 mpPgPrevwLayout->IsPrevwPosInDocPrevwPage( aPrevwPos, 579 aDocPos, bPosInEmptyPage, nNewSelectedPage ); 580 if ( bIsDocPos && rMEvt.GetClicks() == 2 ) 581 { 582 // close page preview, set new cursor position and switch to 583 // normal view. 584 String sNewCrsrPos( String::CreateFromInt32( aDocPos.X() )); 585 ((( sNewCrsrPos += ';' ) 586 += String::CreateFromInt32( aDocPos.Y() )) ) 587 += ';'; 588 mrView.SetNewCrsrPos( sNewCrsrPos ); 589 590 SfxViewFrame *pTmpFrm = mrView.GetViewFrame(); 591 pTmpFrm->GetBindings().Execute( SID_VIEWSHELL0, NULL, 0, 592 SFX_CALLMODE_ASYNCHRON ); 593 } 594 else if ( bIsDocPos || bPosInEmptyPage ) 595 // OD 2004-03-04 #i20684# - add missing parenthesis 596 { 597 // show clicked page as the selected one 598 mpPgPrevwLayout->MarkNewSelectedPage( nNewSelectedPage ); 599 GetViewShell()->ShowPreViewSelection( nNewSelectedPage ); 600 // OD 19.02.2003 #107369# - adjust position at vertical scrollbar. 601 if ( mpPgPrevwLayout->DoesPreviewLayoutRowsFitIntoWindow() ) 602 { 603 mrView.SetVScrollbarThumbPos( nNewSelectedPage ); 604 } 605 // OD 24.03.2003 #108282# - invalidate page status. 606 static sal_uInt16 __READONLY_DATA aInval[] = 607 { 608 FN_STAT_PAGE, 0 609 }; 610 SfxBindings& rBindings = mrView.GetViewFrame()->GetBindings(); 611 rBindings.Invalidate( aInval ); 612 } 613 } 614 } 615 616 /****************************************************************************** 617 * Beschreibung: Userprefs bzw Viewoptions setzen 618 ******************************************************************************/ 619 620 621 void SwPagePreViewWin::SetPagePreview( sal_uInt8 nRow, sal_uInt8 nCol ) 622 { 623 SwMasterUsrPref *pOpt = (SwMasterUsrPref *)SW_MOD()->GetUsrPref(sal_False); 624 625 if (nRow != pOpt->GetPagePrevRow() || nCol != pOpt->GetPagePrevCol()) 626 { 627 pOpt->SetPagePrevRow( nRow ); 628 pOpt->SetPagePrevCol( nCol ); 629 pOpt->SetModified(); 630 631 //Scrollbar updaten! 632 mrView.ScrollViewSzChg(); 633 } 634 } 635 636 /** get selected page in document preview 637 638 OD 13.12.2002 #103492# 639 640 @author OD 641 */ 642 sal_uInt16 SwPagePreViewWin::SelectedPage() const 643 { 644 return mpPgPrevwLayout->SelectedPage(); 645 } 646 647 /** set selected page number in document preview 648 649 OD 13.12.2002 #103492# 650 651 @author OD 652 */ 653 void SwPagePreViewWin::SetSelectedPage( sal_uInt16 _nSelectedPageNum ) 654 { 655 mpPgPrevwLayout->SetSelectedPage( _nSelectedPageNum ); 656 } 657 658 /** method to enable/disable book preview 659 660 OD 2004-03-05 #i18143# 661 662 @author OD 663 */ 664 bool SwPagePreViewWin::SetBookPreviewMode( const bool _bBookPreview ) 665 { 666 return mpPgPrevwLayout->SetBookPreviewMode( _bBookPreview, 667 mnSttPage, 668 maPaintedPreviewDocRect ); 669 } 670 671 void SwPagePreViewWin::DataChanged( const DataChangedEvent& rDCEvt ) 672 { 673 Window::DataChanged( rDCEvt ); 674 675 switch( rDCEvt.GetType() ) 676 { 677 case DATACHANGED_SETTINGS: 678 // ScrollBars neu anordnen bzw. Resize ausloesen, da sich 679 // ScrollBar-Groesse geaendert haben kann. Dazu muss dann im 680 // Resize-Handler aber auch die Groesse der ScrollBars aus 681 // den Settings abgefragt werden. 682 if( rDCEvt.GetFlags() & SETTINGS_STYLE ) 683 mrView.InvalidateBorder(); //Scrollbarbreiten 684 //#106746# zoom has to be disabled if Accessibility support is switched on 685 lcl_InvalidateZoomSlots(mrView.GetViewFrame()->GetBindings()); 686 break; 687 688 case DATACHANGED_PRINTER: 689 case DATACHANGED_DISPLAY: 690 case DATACHANGED_FONTS: 691 case DATACHANGED_FONTSUBSTITUTION: 692 mrView.GetDocShell()->UpdateFontList(); //Fontwechsel 693 if ( mpViewShell->GetWin() ) 694 mpViewShell->GetWin()->Invalidate(); 695 break; 696 } 697 } 698 699 /** help method to execute SfxRequest FN_PAGEUP and FN_PAGEDOWN 700 701 OD 04.03.2003 #107369# 702 703 @author OD 704 */ 705 void SwPagePreView::_ExecPgUpAndPgDown( const bool _bPgUp, 706 SfxRequest* _pReq ) 707 { 708 SwPagePreviewLayout* pPagePrevwLay = GetViewShell()->PagePreviewLayout(); 709 // check, if top/bottom of preview is *not* already visible. 710 if( pPagePrevwLay->GetWinPagesScrollAmount( _bPgUp ? -1 : 1 ) != 0 ) 711 { 712 if ( pPagePrevwLay->DoesPreviewLayoutRowsFitIntoWindow() && 713 pPagePrevwLay->DoesPreviewLayoutColsFitIntoWindow() ) 714 { 715 const int eMvMode = _bPgUp ? 716 SwPagePreViewWin::MV_PAGE_UP : 717 SwPagePreViewWin::MV_PAGE_DOWN; 718 if ( ChgPage( eMvMode, sal_True ) ) 719 aViewWin.Invalidate(); 720 } 721 else 722 { 723 SwTwips nScrollAmount; 724 sal_uInt16 nNewSelectedPageNum = 0; 725 const sal_uInt16 nVisPages = aViewWin.GetRow() * aViewWin.GetCol(); 726 if( _bPgUp ) 727 { 728 if ( pPagePrevwLay->DoesPreviewLayoutRowsFitIntoWindow() ) 729 { 730 nScrollAmount = pPagePrevwLay->GetWinPagesScrollAmount( -1 ); 731 if ( (aViewWin.SelectedPage() - nVisPages) > 0 ) 732 nNewSelectedPageNum = aViewWin.SelectedPage() - nVisPages; 733 else 734 nNewSelectedPageNum = 1; 735 } 736 else 737 nScrollAmount = - Min( aViewWin.GetOutputSize().Height(), 738 aViewWin.GetPaintedPreviewDocRect().Top() ); 739 } 740 else 741 { 742 if ( pPagePrevwLay->DoesPreviewLayoutRowsFitIntoWindow() ) 743 { 744 nScrollAmount = pPagePrevwLay->GetWinPagesScrollAmount( 1 ); 745 if ( (aViewWin.SelectedPage() + nVisPages) <= mnPageCount ) 746 nNewSelectedPageNum = aViewWin.SelectedPage() + nVisPages; 747 else 748 nNewSelectedPageNum = mnPageCount; 749 } 750 else 751 nScrollAmount = Min( aViewWin.GetOutputSize().Height(), 752 ( pPagePrevwLay->GetPrevwDocSize().Height() - 753 aViewWin.GetPaintedPreviewDocRect().Bottom() ) ); 754 } 755 aViewWin.Scroll( 0, nScrollAmount ); 756 if ( nNewSelectedPageNum != 0 ) 757 { 758 aViewWin.SetSelectedPage( nNewSelectedPageNum ); 759 } 760 ScrollViewSzChg(); 761 // OD 24.03.2003 #108282# - additional invalidate page status. 762 static sal_uInt16 __READONLY_DATA aInval[] = 763 { 764 FN_START_OF_DOCUMENT, FN_END_OF_DOCUMENT, FN_PAGEUP, FN_PAGEDOWN, 765 FN_STAT_PAGE, 0 766 }; 767 SfxBindings& rBindings = GetViewFrame()->GetBindings(); 768 rBindings.Invalidate( aInval ); 769 aViewWin.Invalidate(); 770 } 771 } 772 773 if ( _pReq ) 774 _pReq->Done(); 775 } 776 777 /*-------------------------------------------------------------------- 778 Beschreibung: 779 --------------------------------------------------------------------*/ 780 // dann mal alles fuer die SwPagePreView 781 void SwPagePreView::Execute( SfxRequest &rReq ) 782 { 783 int eMvMode; 784 sal_uInt8 nRow = 1; 785 sal_Bool bRetVal = sal_False; 786 bool bRefresh = true; 787 788 switch(rReq.GetSlot()) 789 { 790 case FN_REFRESH_VIEW: 791 case FN_STAT_PAGE: 792 case FN_STAT_ZOOM: 793 break; 794 795 case FN_SHOW_MULTIPLE_PAGES: 796 { 797 const SfxItemSet *pArgs = rReq.GetArgs(); 798 if( pArgs && pArgs->Count() >= 2 ) 799 { 800 sal_uInt8 nCols = (sal_uInt8)((SfxUInt16Item &)pArgs->Get( 801 SID_ATTR_TABLE_COLUMN)).GetValue(); 802 sal_uInt8 nRows = (sal_uInt8)((SfxUInt16Item &)pArgs->Get( 803 SID_ATTR_TABLE_ROW)).GetValue(); 804 aViewWin.CalcWish( nRows, nCols ); 805 806 } 807 else 808 SwPreViewZoomDlg( aViewWin ).Execute(); 809 810 } 811 break; 812 case FN_SHOW_BOOKVIEW: 813 { 814 const SfxItemSet* pArgs = rReq.GetArgs(); 815 const SfxPoolItem* pItem; 816 bool bBookPreview = GetViewShell()->GetViewOptions()->IsPagePrevBookview(); 817 if( pArgs && SFX_ITEM_SET == pArgs->GetItemState( FN_SHOW_BOOKVIEW, sal_False, &pItem ) ) 818 { 819 bBookPreview = static_cast< const SfxBoolItem* >( pItem )->GetValue(); 820 ( ( SwViewOption* ) GetViewShell()->GetViewOptions() )->SetPagePrevBookview( bBookPreview ); 821 // cast is not gentleman like, but it's common use in writer and in this case 822 } 823 if ( aViewWin.SetBookPreviewMode( bBookPreview ) ) 824 { 825 // book preview mode changed. Thus, adjust scrollbars and 826 // invalidate corresponding states. 827 ScrollViewSzChg(); 828 static sal_uInt16 __READONLY_DATA aInval[] = 829 { 830 FN_START_OF_DOCUMENT, FN_END_OF_DOCUMENT, FN_PAGEUP, FN_PAGEDOWN, 831 FN_STAT_PAGE, FN_SHOW_BOOKVIEW, 0 832 }; 833 SfxBindings& rBindings = GetViewFrame()->GetBindings(); 834 rBindings.Invalidate( aInval ); 835 aViewWin.Invalidate(); 836 } 837 838 } 839 break; 840 case FN_SHOW_TWO_PAGES: 841 aViewWin.CalcWish( nRow, 2 ); 842 break; 843 844 case FN_PREVIEW_ZOOM: 845 case SID_ATTR_ZOOM: 846 { 847 const SfxItemSet *pArgs = rReq.GetArgs(); 848 const SfxPoolItem* pItem; 849 AbstractSvxZoomDialog *pDlg = 0; 850 if(!pArgs) 851 { 852 SfxItemSet aCoreSet(GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM); 853 const SwViewOption* pVOpt = GetViewShell()->GetViewOptions(); 854 SvxZoomItem aZoom( (SvxZoomType)pVOpt->GetZoomType(), 855 pVOpt->GetZoom() ); 856 aZoom.SetValueSet( 857 SVX_ZOOM_ENABLE_50| 858 SVX_ZOOM_ENABLE_75| 859 SVX_ZOOM_ENABLE_100| 860 SVX_ZOOM_ENABLE_150| 861 SVX_ZOOM_ENABLE_200| 862 SVX_ZOOM_ENABLE_WHOLEPAGE); 863 aCoreSet.Put( aZoom ); 864 865 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); 866 if(pFact) 867 { 868 pDlg = pFact->CreateSvxZoomDialog(&GetViewFrame()->GetWindow(), aCoreSet); 869 DBG_ASSERT(pDlg, "Dialogdiet fail!"); 870 } 871 872 pDlg->SetLimits( MINZOOM, MAXZOOM ); 873 874 if( pDlg->Execute() != RET_CANCEL ) 875 pArgs = pDlg->GetOutputItemSet(); 876 } 877 if( pArgs ) 878 { 879 enum SvxZoomType eType = SVX_ZOOM_PERCENT; 880 sal_uInt16 nZoomFactor = USHRT_MAX; 881 if(SFX_ITEM_SET == pArgs->GetItemState(SID_ATTR_ZOOM, sal_True, &pItem)) 882 { 883 eType = ((const SvxZoomItem *)pItem)->GetType(); 884 nZoomFactor = ((const SvxZoomItem *)pItem)->GetValue(); 885 } 886 else if(SFX_ITEM_SET == pArgs->GetItemState(FN_PREVIEW_ZOOM, sal_True, &pItem)) 887 nZoomFactor = ((const SfxUInt16Item *)pItem)->GetValue(); 888 if(USHRT_MAX != nZoomFactor) 889 SetZoom(eType, nZoomFactor); 890 } 891 delete pDlg; 892 } 893 break; 894 case SID_ATTR_ZOOMSLIDER : 895 { 896 const SfxItemSet *pArgs = rReq.GetArgs(); 897 const SfxPoolItem* pItem; 898 899 if ( pArgs && SFX_ITEM_SET == pArgs->GetItemState(SID_ATTR_ZOOMSLIDER, sal_True, &pItem ) ) 900 { 901 const sal_uInt16 nCurrentZoom = ((const SvxZoomSliderItem *)pItem)->GetValue(); 902 SetZoom( SVX_ZOOM_PERCENT, nCurrentZoom ); 903 } 904 } 905 break; 906 case SID_ZOOM_IN: 907 case SID_ZOOM_OUT: 908 { 909 enum SvxZoomType eType = SVX_ZOOM_PERCENT; 910 const SwViewOption* pVOpt = GetViewShell()->GetViewOptions(); 911 SetZoom(eType, 912 lcl_GetNextZoomStep(pVOpt->GetZoom(), SID_ZOOM_IN == rReq.GetSlot())); 913 } 914 break; 915 case FN_CHAR_LEFT: 916 case FN_CHAR_RIGHT: 917 case FN_LINE_UP: 918 case FN_LINE_DOWN: 919 { 920 SwPagePreviewLayout* pPagePrevwLay = GetViewShell()->PagePreviewLayout(); 921 sal_uInt16 nNewSelectedPage; 922 sal_uInt16 nNewStartPage; 923 Point aNewStartPos; 924 sal_Int16 nHoriMove = 0; 925 sal_Int16 nVertMove = 0; 926 switch(rReq.GetSlot()) 927 { 928 case FN_CHAR_LEFT: nHoriMove = -1; break; 929 case FN_CHAR_RIGHT: nHoriMove = 1; break; 930 case FN_LINE_UP: nVertMove = -1; break; 931 case FN_LINE_DOWN: nVertMove = 1; break; 932 } 933 pPagePrevwLay->CalcStartValuesForSelectedPageMove( nHoriMove, nVertMove, 934 nNewSelectedPage, nNewStartPage, aNewStartPos ); 935 if ( aViewWin.SelectedPage() != nNewSelectedPage ) 936 { 937 if ( pPagePrevwLay->IsPageVisible( nNewSelectedPage ) ) 938 { 939 pPagePrevwLay->MarkNewSelectedPage( nNewSelectedPage ); 940 // OD 19.02.2003 #107369# - adjust position at vertical scrollbar. 941 SetVScrollbarThumbPos( nNewSelectedPage ); 942 bRefresh = false; 943 } 944 else 945 { 946 aViewWin.SetSelectedPage( nNewSelectedPage ); 947 aViewWin.SetSttPage( nNewStartPage ); 948 int nRet = ChgPage( SwPagePreViewWin::MV_SELPAGE, sal_True ); 949 bRefresh = 0 != nRet; 950 } 951 GetViewShell()->ShowPreViewSelection( nNewSelectedPage ); 952 // OD 24.03.2003 #108282# - invalidate page status. 953 static sal_uInt16 __READONLY_DATA aInval[] = 954 { 955 FN_STAT_PAGE, 0 956 }; 957 SfxBindings& rBindings = GetViewFrame()->GetBindings(); 958 rBindings.Invalidate( aInval ); 959 rReq.Done(); 960 } 961 else 962 { 963 bRefresh = false; 964 } 965 break; 966 } 967 case FN_PAGEUP: 968 case FN_PAGEDOWN: 969 { 970 _ExecPgUpAndPgDown( rReq.GetSlot() == FN_PAGEUP, &rReq ); 971 break; 972 } 973 case FN_START_OF_LINE: 974 case FN_START_OF_DOCUMENT: 975 aViewWin.SetSelectedPage( 1 ); 976 eMvMode = SwPagePreViewWin::MV_DOC_STT; bRetVal = sal_True; goto MOVEPAGE; 977 case FN_END_OF_LINE: 978 case FN_END_OF_DOCUMENT: 979 aViewWin.SetSelectedPage( mnPageCount ); 980 eMvMode = SwPagePreViewWin::MV_DOC_END; bRetVal = sal_True; goto MOVEPAGE; 981 MOVEPAGE: 982 { 983 int nRet = ChgPage( eMvMode, sal_True ); 984 // return value fuer Basic 985 if(bRetVal) 986 rReq.SetReturnValue(SfxBoolItem(rReq.GetSlot(), nRet == 0)); 987 988 bRefresh = 0 != nRet; 989 rReq.Done(); 990 } 991 break; 992 993 case FN_PRINT_PAGEPREVIEW: 994 { 995 const SwPagePreViewPrtData* pPPVPD = aViewWin.GetViewShell()->GetDoc()->GetPreViewPrtData(); 996 // die Sache mit der Orientation 997 if(pPPVPD) 998 { 999 SfxPrinter* pPrinter = GetPrinter( sal_True ); 1000 if((pPrinter->GetOrientation() == ORIENTATION_LANDSCAPE) 1001 != pPPVPD->GetLandscape()) 1002 pPrinter->SetOrientation(pPPVPD->GetLandscape() ? ORIENTATION_LANDSCAPE : ORIENTATION_PORTRAIT); 1003 } 1004 ::SetAppPrintOptions( aViewWin.GetViewShell(), sal_False ); 1005 bNormalPrint = sal_False; 1006 sal_uInt16 nPrtSlot = SID_PRINTDOC; 1007 rReq.SetSlot( nPrtSlot ); 1008 SfxViewShell::ExecuteSlot( rReq, SfxViewShell::GetInterface() ); 1009 rReq.SetSlot( FN_PRINT_PAGEPREVIEW ); 1010 return; 1011 } 1012 case SID_PRINTDOCDIRECT: 1013 case SID_PRINTDOC: 1014 ::SetAppPrintOptions( aViewWin.GetViewShell(), sal_False ); 1015 bNormalPrint = sal_True; 1016 SfxViewShell::ExecuteSlot( rReq, SfxViewShell::GetInterface() ); 1017 return; 1018 case FN_CLOSE_PAGEPREVIEW: 1019 case SID_PRINTPREVIEW: 1020 // print preview is now always in the same frame as the tab view 1021 // -> always switch this frame back to normal view 1022 // (ScTabViewShell ctor reads stored view data) 1023 GetViewFrame()->GetDispatcher()->Execute( SID_VIEWSHELL0, 0, 0, SFX_CALLMODE_ASYNCHRON ); 1024 break; 1025 case FN_INSERT_BREAK: 1026 { 1027 sal_uInt16 nSelPage = aViewWin.SelectedPage(); 1028 //if a dummy page is selected (e.g. a non-existing right/left page) 1029 //the direct neighbor is used 1030 if(GetViewShell()->IsDummyPage( nSelPage ) && GetViewShell()->IsDummyPage( --nSelPage )) 1031 nSelPage +=2; 1032 SetNewPage( nSelPage ); 1033 SfxViewFrame *pTmpFrm = GetViewFrame(); 1034 pTmpFrm->GetBindings().Execute( SID_VIEWSHELL0, NULL, 0, 1035 SFX_CALLMODE_ASYNCHRON ); 1036 } 1037 break; 1038 default: 1039 ASSERT(!this, falscher Dispatcher); 1040 return; 1041 } 1042 1043 if( bRefresh ) 1044 aViewWin.Invalidate(); 1045 } 1046 1047 /*-------------------------------------------------------------------- 1048 Beschreibung: 1049 --------------------------------------------------------------------*/ 1050 1051 1052 void SwPagePreView::GetState( SfxItemSet& rSet ) 1053 { 1054 SfxWhichIter aIter(rSet); 1055 sal_uInt8 nRow = 1; 1056 sal_uInt16 nWhich = aIter.FirstWhich(); 1057 ASSERT(nWhich, leeres Set); 1058 SwPagePreviewLayout* pPagePrevwLay = GetViewShell()->PagePreviewLayout(); 1059 //#106746# zoom has to be disabled if Accessibility support is switched on 1060 // MT 2010/01, see #110498# 1061 sal_Bool bZoomEnabled = sal_True; // !Application::GetSettings().GetMiscSettings().GetEnableATToolSupport(); 1062 1063 while(nWhich) 1064 { 1065 switch(nWhich) 1066 { 1067 case SID_BROWSER_MODE: 1068 case FN_PRINT_LAYOUT: 1069 rSet.DisableItem(nWhich); 1070 break; 1071 case FN_START_OF_DOCUMENT: 1072 { 1073 if ( pPagePrevwLay->IsPageVisible( 1 ) ) 1074 rSet.DisableItem(nWhich); 1075 break; 1076 } 1077 case FN_END_OF_DOCUMENT: 1078 { 1079 if ( pPagePrevwLay->IsPageVisible( mnPageCount ) ) 1080 rSet.DisableItem(nWhich); 1081 break; 1082 } 1083 case FN_PAGEUP: 1084 { 1085 if( pPagePrevwLay->GetWinPagesScrollAmount( -1 ) == 0 ) 1086 rSet.DisableItem(nWhich); 1087 break; 1088 } 1089 case FN_PAGEDOWN: 1090 { 1091 if( pPagePrevwLay->GetWinPagesScrollAmount( 1 ) == 0 ) 1092 rSet.DisableItem(nWhich); 1093 break; 1094 } 1095 1096 case FN_STAT_PAGE: 1097 { 1098 String aStr( sPageStr ); 1099 aViewWin.GetStatusStr( aStr, mnPageCount ); 1100 rSet.Put( SfxStringItem( nWhich, aStr) ); 1101 } 1102 break; 1103 1104 case SID_ATTR_ZOOM: 1105 case FN_STAT_ZOOM: 1106 { 1107 if(bZoomEnabled) 1108 { 1109 const SwViewOption* pVOpt = GetViewShell()->GetViewOptions(); 1110 SvxZoomItem aZoom((SvxZoomType)pVOpt->GetZoomType(), 1111 pVOpt->GetZoom()); 1112 aZoom.SetValueSet( 1113 SVX_ZOOM_ENABLE_50| 1114 SVX_ZOOM_ENABLE_75| 1115 SVX_ZOOM_ENABLE_100| 1116 SVX_ZOOM_ENABLE_150| 1117 SVX_ZOOM_ENABLE_200); 1118 rSet.Put( aZoom ); 1119 } 1120 else 1121 rSet.DisableItem(nWhich); 1122 } 1123 break; 1124 case SID_ATTR_ZOOMSLIDER : 1125 { 1126 if(bZoomEnabled) 1127 { 1128 const SwViewOption* pVOpt = GetViewShell()->GetViewOptions(); 1129 const sal_uInt16 nCurrentZoom = pVOpt->GetZoom(); 1130 SvxZoomSliderItem aZoomSliderItem( nCurrentZoom, MINZOOM, MAXZOOM ); 1131 aZoomSliderItem.AddSnappingPoint( 100 ); 1132 rSet.Put( aZoomSliderItem ); 1133 } 1134 else 1135 rSet.DisableItem(nWhich); 1136 } 1137 break; 1138 case FN_PREVIEW_ZOOM: 1139 { 1140 if(bZoomEnabled) 1141 { 1142 const SwViewOption* pVOpt = GetViewShell()->GetViewOptions(); 1143 rSet.Put(SfxUInt16Item(nWhich, pVOpt->GetZoom())); 1144 } 1145 else 1146 rSet.DisableItem(nWhich); 1147 } 1148 break; 1149 case SID_ZOOM_IN: 1150 case SID_ZOOM_OUT: 1151 { 1152 const SwViewOption* pVOpt = GetViewShell()->GetViewOptions(); 1153 if(!bZoomEnabled || (SID_ZOOM_OUT == nWhich && pVOpt->GetZoom() >= MAX_PREVIEW_ZOOM)|| 1154 (SID_ZOOM_IN == nWhich && pVOpt->GetZoom() <= MIN_PREVIEW_ZOOM)) 1155 { 1156 rSet.DisableItem(nWhich); 1157 } 1158 } 1159 break; 1160 case FN_SHOW_MULTIPLE_PAGES: 1161 //should never be disabled 1162 break; 1163 case FN_SHOW_BOOKVIEW: 1164 { 1165 sal_Bool b = GetViewShell()->GetViewOptions()->IsPagePrevBookview(); 1166 rSet.Put(SfxBoolItem(nWhich, b)); 1167 } 1168 break; 1169 1170 case FN_SHOW_TWO_PAGES: 1171 if( 2 == aViewWin.GetCol() && nRow == aViewWin.GetRow() ) 1172 rSet.DisableItem( nWhich ); 1173 break; 1174 1175 case FN_PRINT_PAGEPREVIEW: 1176 // hat den gleichen Status wie das normale Drucken 1177 { 1178 const SfxPoolItem* pItem; 1179 SfxItemSet aSet( *rSet.GetPool(), SID_PRINTDOC, SID_PRINTDOC ); 1180 GetSlotState( SID_PRINTDOC, SfxViewShell::GetInterface(), &aSet ); 1181 if( SFX_ITEM_DISABLED == aSet.GetItemState( SID_PRINTDOC, 1182 sal_False, &pItem )) 1183 rSet.DisableItem( nWhich ); 1184 else if( SFX_ITEM_SET == aSet.GetItemState( SID_PRINTDOC, 1185 sal_False, &pItem )) 1186 { 1187 ((SfxPoolItem*)pItem)->SetWhich( FN_PRINT_PAGEPREVIEW ); 1188 rSet.Put( *pItem ); 1189 } 1190 } 1191 break; 1192 1193 case SID_PRINTPREVIEW: 1194 rSet.Put( SfxBoolItem( nWhich, sal_True ) ); 1195 break; 1196 1197 case SID_PRINTDOC: 1198 case SID_PRINTDOCDIRECT: 1199 GetSlotState( nWhich, SfxViewShell::GetInterface(), &rSet ); 1200 break; 1201 } 1202 nWhich = aIter.NextWhich(); 1203 } 1204 } 1205 1206 /*-------------------------------------------------------------------- 1207 Beschreibung: 1208 --------------------------------------------------------------------*/ 1209 1210 1211 void SwPagePreView::StateUndo(SfxItemSet& rSet) 1212 { 1213 SfxWhichIter aIter(rSet); 1214 sal_uInt16 nWhich = aIter.FirstWhich(); 1215 1216 while (nWhich) 1217 { 1218 rSet.DisableItem(nWhich); 1219 nWhich = aIter.NextWhich(); 1220 } 1221 } 1222 1223 /*-------------------------------------------------------------------- 1224 Beschreibung: 1225 --------------------------------------------------------------------*/ 1226 1227 1228 void SwPagePreView::Init(const SwViewOption * pPrefs) 1229 { 1230 if ( GetViewShell()->HasDrawView() ) 1231 GetViewShell()->GetDrawView()->SetAnimationEnabled( sal_False ); 1232 1233 bNormalPrint = sal_True; 1234 1235 // Die DocSize erfragen und verarbeiten. Ueber die Handler konnte 1236 // die Shell nicht gefunden werden, weil die Shell innerhalb CTOR-Phase 1237 // nicht in der SFX-Verwaltung bekannt ist. 1238 1239 if( !pPrefs ) 1240 pPrefs = SW_MOD()->GetUsrPref(sal_False); 1241 1242 // die Felder aktualisieren 1243 // ACHTUNG: hochcasten auf die EditShell, um die SS zu nutzen. 1244 // In den Methoden wird auf die akt. Shell abgefragt! 1245 SwEditShell* pESh = (SwEditShell*)GetViewShell(); 1246 sal_Bool bIsModified = pESh->IsModified(); 1247 1248 1249 SwViewOption aOpt( *pPrefs ); 1250 aOpt.SetPagePreview(sal_True); 1251 aOpt.SetTab( sal_False ); 1252 aOpt.SetBlank( sal_False ); 1253 aOpt.SetHardBlank( sal_False ); 1254 aOpt.SetParagraph( sal_False ); 1255 aOpt.SetLineBreak( sal_False ); 1256 aOpt.SetPageBreak( sal_False ); 1257 aOpt.SetColumnBreak( sal_False ); 1258 aOpt.SetSoftHyph( sal_False ); 1259 aOpt.SetFldName( sal_False ); 1260 aOpt.SetPostIts( sal_False ); 1261 aOpt.SetShowHiddenChar( sal_False ); 1262 aOpt.SetShowHiddenField( sal_False ); 1263 aOpt.SetShowHiddenPara( sal_False ); 1264 aOpt.SetViewHRuler( sal_False ); 1265 aOpt.SetViewVRuler( sal_False ); 1266 aOpt.SetGraphic( sal_True ); 1267 aOpt.SetTable( sal_True ); 1268 aOpt.SetSnap( sal_False ); 1269 aOpt.SetGridVisible( sal_False ); 1270 1271 GetViewShell()->ApplyViewOptions( aOpt ); 1272 GetViewShell()->ApplyAccessiblityOptions(SW_MOD()->GetAccessibilityOptions()); 1273 1274 // OD 09.01.2003 #i6467# - adjust view shell option to the same as for print 1275 SwPrintData const aPrintOptions = *SW_MOD()->GetPrtOptions(false); 1276 GetViewShell()->AdjustOptionsForPagePreview( aPrintOptions ); 1277 1278 GetViewShell()->CalcLayout(); 1279 DocSzChgd( GetViewShell()->GetDocSize() ); 1280 1281 if( !bIsModified ) 1282 pESh->ResetModified(); 1283 1284 pVScrollbar->ExtendedShow(pPrefs->IsViewVScrollBar()); 1285 pHScrollbar->ExtendedShow(pPrefs->IsViewHScrollBar()); 1286 pScrollFill->Show(pPrefs->IsViewVScrollBar() && pPrefs->IsViewHScrollBar()); 1287 } 1288 1289 1290 /*-------------------------------------------------------------------- 1291 Beschreibung: 1292 --------------------------------------------------------------------*/ 1293 1294 1295 SwPagePreView::SwPagePreView(SfxViewFrame *pViewFrame, SfxViewShell* pOldSh): 1296 SfxViewShell( pViewFrame, SWVIEWFLAGS ), 1297 aViewWin( &pViewFrame->GetWindow(), *this ), 1298 nNewPage(USHRT_MAX), 1299 pHScrollbar(0), 1300 pVScrollbar(0), 1301 pPageUpBtn(0), 1302 pPageDownBtn(0), 1303 pScrollFill(new ScrollBarBox( &pViewFrame->GetWindow(), 1304 pViewFrame->GetFrame().GetParentFrame() ? 0 : WB_SIZEABLE )), 1305 mnPageCount( 0 ), 1306 // OD 09.01.2003 #106334# 1307 mbResetFormDesignMode( false ), 1308 mbFormDesignModeToReset( false ) 1309 { 1310 SetName(String::CreateFromAscii("PageView" )); 1311 SetWindow( &aViewWin ); 1312 SetHelpId(SW_PAGEPREVIEW); 1313 _CreateScrollbar( sal_True ); 1314 _CreateScrollbar( sal_False ); 1315 1316 SfxObjectShell* pObjShell = pViewFrame->GetObjectShell(); 1317 if ( !pOldSh ) 1318 { 1319 //Gibt es schon eine Sicht auf das Dokument? 1320 SfxViewFrame *pF = SfxViewFrame::GetFirst( pObjShell ); 1321 if ( pF == pViewFrame ) 1322 pF = SfxViewFrame::GetNext( *pF, pObjShell ); 1323 if ( pF ) 1324 pOldSh = pF->GetViewShell(); 1325 } 1326 1327 ViewShell *pVS, *pNew; 1328 1329 if( pOldSh && pOldSh->IsA( TYPE( SwPagePreView ) ) ) 1330 pVS = ((SwPagePreView*)pOldSh)->GetViewShell(); 1331 else 1332 { 1333 if( pOldSh && pOldSh->IsA( TYPE( SwView ) ) ) 1334 { 1335 pVS = ((SwView*)pOldSh)->GetWrtShellPtr(); 1336 // save the current ViewData of the previous SwView 1337 pOldSh->WriteUserData( sSwViewData, sal_False ); 1338 } 1339 else 1340 pVS = GetDocShell()->GetWrtShell(); 1341 if( pVS ) 1342 { 1343 // setze die akt. Seite als die erste 1344 sal_uInt16 nPhysPg, nVirtPg; 1345 ((SwCrsrShell*)pVS)->GetPageNum( nPhysPg, nVirtPg, /*sal_False*/sal_True, sal_False ); 1346 if( 1 != aViewWin.GetCol() && 1 == nPhysPg ) 1347 --nPhysPg; 1348 aViewWin.SetSttPage( nPhysPg ); 1349 } 1350 } 1351 1352 // OD 09.01.2003 #106334# - for form shell remember design mode of draw view 1353 // of previous view shell 1354 if ( pVS && pVS->HasDrawView() ) 1355 { 1356 mbResetFormDesignMode = true; 1357 mbFormDesignModeToReset = pVS->GetDrawView()->IsDesignMode(); 1358 } 1359 1360 if( pVS ) 1361 pNew = new ViewShell( *pVS, &aViewWin, 0, VSHELLFLAG_ISPREVIEW ); 1362 else 1363 pNew = new ViewShell( 1364 *((SwDocShell*)pViewFrame->GetObjectShell())->GetDoc(), 1365 &aViewWin, 0, 0, VSHELLFLAG_ISPREVIEW ); 1366 1367 aViewWin.SetViewShell( pNew ); 1368 pNew->SetSfxViewShell( this ); 1369 Init(); 1370 } 1371 1372 1373 /*-------------------------------------------------------------------- 1374 Beschreibung: 1375 --------------------------------------------------------------------*/ 1376 1377 1378 SwPagePreView::~SwPagePreView() 1379 { 1380 SetWindow( 0 ); 1381 1382 delete pScrollFill; 1383 delete pHScrollbar; 1384 delete pVScrollbar; 1385 delete pPageUpBtn; 1386 delete pPageDownBtn; 1387 1388 /* SfxObjectShell* pDocSh = GetDocShell(); 1389 for( SfxViewFrame *pFrame = SfxViewFrame::GetFirst( pDocSh ); 1390 pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, pDocSh ) ) 1391 if( pFrame != GetViewFrame() ) 1392 { 1393 // es gibt noch eine weitere Sicht auf unser Dokument, also 1394 // aktiviere dieses 1395 pFrame->GetFrame().Appear(); 1396 break; 1397 } 1398 */} 1399 1400 /*-------------------------------------------------------------------- 1401 Beschreibung: 1402 --------------------------------------------------------------------*/ 1403 1404 1405 SwDocShell* SwPagePreView::GetDocShell() 1406 { 1407 return PTR_CAST(SwDocShell, GetViewFrame()->GetObjectShell()); 1408 } 1409 1410 /*-------------------------------------------------------------------- 1411 Beschreibung: 1412 --------------------------------------------------------------------*/ 1413 1414 1415 int SwPagePreView::_CreateScrollbar( sal_Bool bHori ) 1416 { 1417 Window *pMDI = &GetViewFrame()->GetWindow(); 1418 SwScrollbar** ppScrollbar = bHori ? &pHScrollbar : &pVScrollbar; 1419 1420 ASSERT( !*ppScrollbar, "vorher abpruefen!" ) 1421 1422 if( !bHori ) 1423 { 1424 1425 pPageUpBtn = new ImageButton(pMDI, SW_RES( BTN_PAGEUP ) ); 1426 pPageUpBtn->SetHelpId(GetStaticInterface()->GetSlot(FN_PAGEUP)->GetCommand()); 1427 pPageDownBtn = new ImageButton(pMDI, SW_RES( BTN_PAGEDOWN ) ); 1428 pPageDownBtn->SetHelpId(GetStaticInterface()->GetSlot(FN_PAGEDOWN)->GetCommand()); 1429 Link aLk( LINK( this, SwPagePreView, BtnPage ) ); 1430 pPageUpBtn->SetClickHdl( aLk ); 1431 pPageDownBtn->SetClickHdl( aLk ); 1432 pPageUpBtn->Show(); 1433 pPageDownBtn->Show(); 1434 } 1435 1436 *ppScrollbar = new SwScrollbar( pMDI, bHori ); 1437 1438 ScrollDocSzChg(); 1439 (*ppScrollbar)->EnableDrag( sal_True ); 1440 (*ppScrollbar)->SetEndScrollHdl( LINK( this, SwPagePreView, EndScrollHdl )); 1441 1442 1443 (*ppScrollbar)->SetScrollHdl( LINK( this, SwPagePreView, ScrollHdl )); 1444 1445 InvalidateBorder(); 1446 (*ppScrollbar)->ExtendedShow(); 1447 return 1; 1448 } 1449 1450 /*-------------------------------------------------------------------- 1451 Beschreibung: 1452 --------------------------------------------------------------------*/ 1453 1454 1455 1456 /*-------------------------------------------------------------------- 1457 Beschreibung: 1458 --------------------------------------------------------------------*/ 1459 1460 /* 1461 * Button-Handler 1462 */ 1463 IMPL_LINK_INLINE_START( SwPagePreView, BtnPage, Button *, pButton ) 1464 { 1465 // OD 04.03.2003 #107369# - use new helper method to perform page up 1466 // respectively page down. 1467 _ExecPgUpAndPgDown( pButton == pPageUpBtn ); 1468 return 0; 1469 } 1470 IMPL_LINK_INLINE_END( SwPagePreView, BtnPage, Button *, pButton ) 1471 1472 /*-------------------------------------------------------------------- 1473 Beschreibung: 1474 --------------------------------------------------------------------*/ 1475 1476 1477 int SwPagePreView::ChgPage( int eMvMode, int bUpdateScrollbar ) 1478 { 1479 Rectangle aPixVisArea( aViewWin.LogicToPixel( aVisArea ) ); 1480 int bChg = aViewWin.MovePage( eMvMode ) || 1481 eMvMode == SwPagePreViewWin::MV_CALC || 1482 eMvMode == SwPagePreViewWin::MV_NEWWINSIZE; 1483 aVisArea = aViewWin.PixelToLogic( aPixVisArea ); 1484 1485 if( bChg ) 1486 { 1487 // Statusleiste updaten 1488 String aStr( sPageStr ); 1489 aViewWin.GetStatusStr( aStr, mnPageCount ); 1490 SfxBindings& rBindings = GetViewFrame()->GetBindings(); 1491 1492 if( bUpdateScrollbar ) 1493 { 1494 ScrollViewSzChg(); 1495 1496 static sal_uInt16 __READONLY_DATA aInval[] = 1497 { 1498 FN_START_OF_DOCUMENT, FN_END_OF_DOCUMENT, 1499 FN_PAGEUP, FN_PAGEDOWN, 0 1500 }; 1501 rBindings.Invalidate( aInval ); 1502 } 1503 rBindings.SetState( SfxStringItem( FN_STAT_PAGE, aStr ) ); 1504 } 1505 return bChg; 1506 } 1507 1508 1509 /* */ 1510 /*-------------------------------------------------------------------- 1511 Beschreibung: 1512 --------------------------------------------------------------------*/ 1513 1514 1515 // ab hier alles aus der SwView uebernommen 1516 1517 1518 void SwPagePreView::CalcAndSetBorderPixel( SvBorder &rToFill, sal_Bool /*bInner*/ ) 1519 { 1520 // const long nAdd = bInner ? 0 : ScrollBar::GetWindowOverlapPixel(); 1521 const StyleSettings &rSet = aViewWin.GetSettings().GetStyleSettings(); 1522 const long nTmp = rSet.GetScrollBarSize();// - nAdd; 1523 if ( pVScrollbar->IsVisible( sal_False )) 1524 rToFill.Right() = nTmp; 1525 if ( pHScrollbar->IsVisible( sal_False ) ) 1526 rToFill.Bottom() = nTmp; 1527 SetBorderPixel( rToFill ); 1528 } 1529 1530 /*-------------------------------------------------------------------- 1531 Beschreibung: 1532 --------------------------------------------------------------------*/ 1533 1534 1535 void SwPagePreView::InnerResizePixel( const Point &rOfst, const Size &rSize ) 1536 { 1537 SvBorder aBorder; 1538 CalcAndSetBorderPixel( aBorder, sal_True ); 1539 Rectangle aRect( rOfst, rSize ); 1540 aRect += aBorder; 1541 ViewResizePixel( aViewWin, aRect.TopLeft(), aRect.GetSize(), 1542 aViewWin.GetOutputSizePixel(), 1543 sal_True, 1544 *pVScrollbar, *pHScrollbar, pPageUpBtn, pPageDownBtn, 0, 1545 *pScrollFill ); 1546 1547 //EditWin niemals einstellen! 1548 //VisArea niemals einstellen! 1549 } 1550 1551 /*-------------------------------------------------------------------- 1552 Beschreibung: 1553 --------------------------------------------------------------------*/ 1554 1555 1556 void SwPagePreView::OuterResizePixel( const Point &rOfst, const Size &rSize ) 1557 { 1558 SvBorder aBorder; 1559 CalcAndSetBorderPixel( aBorder, sal_False ); 1560 ViewResizePixel( aViewWin, rOfst, rSize, aViewWin.GetOutputSizePixel(), 1561 sal_False, *pVScrollbar, 1562 *pHScrollbar, pPageUpBtn, pPageDownBtn, 0, *pScrollFill ); 1563 1564 //EditWin niemals einstellen! 1565 1566 Size aTmpSize( aViewWin.GetOutputSizePixel() ); 1567 Point aBottomRight( aViewWin.PixelToLogic( Point( aTmpSize.Width(), aTmpSize.Height() ) ) ); 1568 SetVisArea( Rectangle( Point(), aBottomRight ) ); 1569 1570 //Aufruf der DocSzChgd-Methode der Scrollbars ist noetig, da vom maximalen 1571 //Scrollrange immer die halbe Hoehe der VisArea abgezogen wird. 1572 if ( pVScrollbar && 1573 aTmpSize.Width() > 0 && aTmpSize.Height() > 0 ) 1574 { 1575 ScrollDocSzChg(); 1576 } 1577 } 1578 1579 /*-------------------------------------------------------------------- 1580 Beschreibung: 1581 --------------------------------------------------------------------*/ 1582 1583 1584 void SwPagePreView::SetVisArea( const Rectangle &rRect, sal_Bool bUpdateScrollbar ) 1585 { 1586 const Point aTopLeft(AlignToPixel(rRect.TopLeft())); 1587 const Point aBottomRight(AlignToPixel(rRect.BottomRight())); 1588 Rectangle aLR(aTopLeft,aBottomRight); 1589 1590 if(aLR == aVisArea) 1591 return; 1592 // keine negative Position, keine neg. Groesse 1593 1594 if(aLR.Top() < 0) 1595 { 1596 aLR.Bottom() += Abs(aLR.Top()); 1597 aLR.Top() = 0; 1598 } 1599 1600 if(aLR.Left() < 0) 1601 { 1602 aLR.Right() += Abs(aLR.Left()); 1603 aLR.Left() = 0; 1604 } 1605 if(aLR.Right() < 0) aLR.Right() = 0; 1606 if(aLR.Bottom() < 0) aLR.Bottom() = 0; 1607 if(aLR == aVisArea || 1608 // JP 29.10.97: Bug 45173 - Leeres Rechteck nicht beachten 1609 ( 0 == aLR.Bottom() - aLR.Top() && 0 == aLR.Right() - aLR.Left() ) ) 1610 return; 1611 1612 if( aLR.Left() > aLR.Right() || aLR.Top() > aLR.Bottom() ) 1613 return; 1614 1615 //Bevor die Daten veraendert werden ggf. ein Update rufen. Dadurch wird 1616 //sichergestellt, da? anliegende Paints korrekt in Dokumentkoordinaten 1617 //umgerechnet werden. 1618 //Vorsichtshalber tun wir das nur wenn an der Shell eine Action laeuft, 1619 //denn dann wir nicht wirklich gepaintet sondern die Rechtecke werden 1620 //lediglich (in Dokumentkoordinaten) vorgemerkt. 1621 if( GetViewShell()->ActionPend() ) 1622 aViewWin.Update(); 1623 1624 // setze am View-Win die aktuelle Size 1625 aVisArea = aLR; 1626 aViewWin.SetWinSize( aLR.GetSize() ); 1627 // OD 18.12.2002 #103492# - use new mode 1628 ChgPage( SwPagePreViewWin::MV_NEWWINSIZE, bUpdateScrollbar ); 1629 1630 aViewWin.Invalidate(); 1631 } 1632 1633 /*-------------------------------------------------------------------- 1634 Beschreibung: 1635 --------------------------------------------------------------------*/ 1636 1637 1638 IMPL_LINK( SwPagePreView, ScrollHdl, SwScrollbar *, pScrollbar ) 1639 { 1640 if(!GetViewShell()) 1641 return 0; 1642 if( !pScrollbar->IsHoriScroll() && 1643 pScrollbar->GetType() == SCROLL_DRAG && 1644 Help::IsQuickHelpEnabled() && 1645 GetViewShell()->PagePreviewLayout()->DoesPreviewLayoutRowsFitIntoWindow()) 1646 { 1647 // wieviele Seiten scrollen ?? 1648 String sStateStr(sPageStr); 1649 sal_uInt16 nThmbPos = (sal_uInt16)pScrollbar->GetThumbPos(); 1650 if( 1 == aViewWin.GetCol() || !nThmbPos ) 1651 ++nThmbPos; 1652 sStateStr += String::CreateFromInt32( nThmbPos ); 1653 Point aPos = pScrollbar->GetParent()->OutputToScreenPixel( 1654 pScrollbar->GetPosPixel()); 1655 aPos.Y() = pScrollbar->OutputToScreenPixel(pScrollbar->GetPointerPosPixel()).Y(); 1656 Size aSize = pScrollbar->GetSizePixel(); 1657 Rectangle aRect; 1658 aRect.Left() = aPos.X() -8; 1659 aRect.Right() = aRect.Left(); 1660 aRect.Top() = aPos.Y(); 1661 aRect.Bottom() = aRect.Top(); 1662 1663 Help::ShowQuickHelp(pScrollbar, aRect, sStateStr, 1664 QUICKHELP_RIGHT|QUICKHELP_VCENTER); 1665 1666 } 1667 else 1668 EndScrollHdl( pScrollbar ); 1669 return 0; 1670 } 1671 1672 /*-------------------------------------------------------------------- 1673 Beschreibung: 1674 --------------------------------------------------------------------*/ 1675 1676 1677 IMPL_LINK( SwPagePreView, EndScrollHdl, SwScrollbar *, pScrollbar ) 1678 { 1679 if(!GetViewShell()) 1680 return 0; 1681 1682 // OD 04.03.2003 #107369# - boolean to avoid unnecessary invalidation of the window. 1683 bool bInvalidateWin = true; 1684 1685 if( !pScrollbar->IsHoriScroll() ) // scroll vertically 1686 { 1687 if ( Help::IsQuickHelpEnabled() ) 1688 Help::ShowQuickHelp(pScrollbar, Rectangle(), aEmptyStr, 0); 1689 if ( GetViewShell()->PagePreviewLayout()->DoesPreviewLayoutRowsFitIntoWindow() ) 1690 { 1691 // wieviele Seiten scrollen ?? 1692 sal_uInt16 nThmbPos = (sal_uInt16)pScrollbar->GetThumbPos(); 1693 // OD 05.12.2002 #103492# - adjust to new preview functionality 1694 if( nThmbPos != aViewWin.SelectedPage() ) 1695 { 1696 // OD 17.01.2003 #103492# - consider case that page <nThmbPos> 1697 // is already visible 1698 SwPagePreviewLayout* pPagePrevwLay = GetViewShell()->PagePreviewLayout(); 1699 if ( pPagePrevwLay->IsPageVisible( nThmbPos ) ) 1700 { 1701 pPagePrevwLay->MarkNewSelectedPage( nThmbPos ); 1702 // OD 04.03.2003 #107369# - invalidation of window is unnecessary 1703 bInvalidateWin = false; 1704 } 1705 else 1706 { 1707 // OD 17.01.2003 #103492# - consider whether layout columns 1708 // fit or not. 1709 if ( !pPagePrevwLay->DoesPreviewLayoutColsFitIntoWindow() ) 1710 { 1711 aViewWin.SetSttPage( nThmbPos ); 1712 aViewWin.SetSelectedPage( nThmbPos ); 1713 ChgPage( SwPagePreViewWin::MV_SCROLL, sal_False ); 1714 // OD 20.01.2003 #103492# - update scrollbars 1715 ScrollViewSzChg(); 1716 } 1717 else 1718 { 1719 // OD 04.03.2003 #107369# - correct scroll amount 1720 const sal_Int16 nPageDiff = nThmbPos - aViewWin.SelectedPage(); 1721 const sal_uInt16 nVisPages = aViewWin.GetRow() * aViewWin.GetCol(); 1722 sal_Int16 nWinPagesToScroll = nPageDiff / nVisPages; 1723 if ( nPageDiff % nVisPages ) 1724 { 1725 // decrease/increase number of preview pages to scroll 1726 nPageDiff < 0 ? --nWinPagesToScroll : ++nWinPagesToScroll; 1727 } 1728 aViewWin.SetSelectedPage( nThmbPos ); 1729 aViewWin.Scroll( 0, pPagePrevwLay->GetWinPagesScrollAmount( nWinPagesToScroll ) ); 1730 } 1731 } 1732 // OD 17.01.2003 #103492# - update accessibility 1733 GetViewShell()->ShowPreViewSelection( nThmbPos ); 1734 } 1735 else 1736 { 1737 // OD 04.03.2003 #107369# - invalidation of window is unnecessary 1738 bInvalidateWin = false; 1739 } 1740 } 1741 else 1742 { 1743 long nThmbPos = pScrollbar->GetThumbPos(); 1744 aViewWin.Scroll(0, nThmbPos - aViewWin.GetPaintedPreviewDocRect().Top()); 1745 } 1746 } 1747 else 1748 { 1749 long nThmbPos = pScrollbar->GetThumbPos(); 1750 aViewWin.Scroll(nThmbPos - aViewWin.GetPaintedPreviewDocRect().Left(), 0); 1751 } 1752 // OD 24.03.2003 #108282# - additional invalidate page status. 1753 static sal_uInt16 __READONLY_DATA aInval[] = 1754 { 1755 FN_START_OF_DOCUMENT, FN_END_OF_DOCUMENT, FN_PAGEUP, FN_PAGEDOWN, 1756 FN_STAT_PAGE, 0 1757 }; 1758 SfxBindings& rBindings = GetViewFrame()->GetBindings(); 1759 rBindings.Invalidate( aInval ); 1760 // OD 04.03.2003 #107369# - control invalidation of window 1761 if ( bInvalidateWin ) 1762 { 1763 aViewWin.Invalidate(); 1764 } 1765 return 0; 1766 } 1767 /*-------------------------------------------------------------------- 1768 Beschreibung: 1769 --------------------------------------------------------------------*/ 1770 1771 1772 Point SwPagePreView::AlignToPixel(const Point &rPt) const 1773 { 1774 return aViewWin.PixelToLogic( aViewWin.LogicToPixel( rPt ) ); 1775 } 1776 1777 /*-------------------------------------------------------------------- 1778 Beschreibung: 1779 --------------------------------------------------------------------*/ 1780 1781 1782 void SwPagePreView::DocSzChgd( const Size &rSz ) 1783 { 1784 if( aDocSz == rSz ) 1785 return; 1786 1787 aDocSz = rSz; 1788 1789 // --> OD 2009-08-20 #i96726# 1790 // Due to the multiple page layout it is needed to trigger recalculation 1791 // of the page preview layout, even if the count of pages is not changing. 1792 mnPageCount = GetViewShell()->GetNumPages(); 1793 1794 if( aVisArea.GetWidth() ) 1795 { 1796 ChgPage( SwPagePreViewWin::MV_CALC, sal_True ); 1797 ScrollDocSzChg(); 1798 1799 aViewWin.Invalidate(); 1800 } 1801 // <-- 1802 } 1803 1804 /*-------------------------------------------------------------------- 1805 Beschreibung: 1806 --------------------------------------------------------------------*/ 1807 1808 1809 void SwPagePreView::ScrollViewSzChg() 1810 { 1811 if(!GetViewShell()) 1812 return ; 1813 if(pVScrollbar) 1814 { 1815 if(GetViewShell()->PagePreviewLayout()->DoesPreviewLayoutRowsFitIntoWindow()) 1816 { 1817 //vertical scrolling by row 1818 // OD 04.12.2002 #103492# - adjust to new preview functionality 1819 sal_uInt16 nVisPages = aViewWin.GetRow() * aViewWin.GetCol(); 1820 pVScrollbar->SetVisibleSize( nVisPages ); 1821 // OD 19.02.2003 #107369# - set selected page as scroll bar position, 1822 // if it is visible. 1823 SwPagePreviewLayout* pPagePrevwLay = GetViewShell()->PagePreviewLayout(); 1824 if ( pPagePrevwLay->IsPageVisible( aViewWin.SelectedPage() ) ) 1825 { 1826 pVScrollbar->SetThumbPos( aViewWin.SelectedPage() ); 1827 } 1828 else 1829 { 1830 pVScrollbar->SetThumbPos( aViewWin.GetSttPage() ); 1831 } 1832 pVScrollbar->SetLineSize( aViewWin.GetCol() ); 1833 pVScrollbar->SetPageSize( nVisPages ); 1834 // calculate and set scrollbar range 1835 Range aScrollbarRange( 1, mnPageCount ); 1836 // increase range by one, because left-top-corner is left blank. 1837 ++aScrollbarRange.Max(); 1838 // OD 17.01.2003 #103492# - increase range in order to access all pages 1839 aScrollbarRange.Max() += ( nVisPages - 1 ); 1840 pVScrollbar->SetRange( aScrollbarRange ); 1841 } 1842 else //vertical scrolling by pixel 1843 { 1844 const Rectangle& rDocRect = aViewWin.GetPaintedPreviewDocRect(); 1845 const Size& rPreviewSize = 1846 GetViewShell()->PagePreviewLayout()->GetPrevwDocSize(); 1847 pVScrollbar->SetRangeMax(rPreviewSize.Height()) ; 1848 long nVisHeight = rDocRect.GetHeight(); 1849 pVScrollbar->SetVisibleSize( nVisHeight ); 1850 pVScrollbar->SetThumbPos( rDocRect.Top() ); 1851 pVScrollbar->SetLineSize( nVisHeight / 10 ); 1852 pVScrollbar->SetPageSize( nVisHeight / 2 ); 1853 } 1854 } 1855 if(pHScrollbar) 1856 { 1857 const Rectangle& rDocRect = aViewWin.GetPaintedPreviewDocRect(); 1858 const Size& rPreviewSize = 1859 GetViewShell()->PagePreviewLayout()->GetPrevwDocSize(); 1860 long nVisWidth = 0; 1861 long nThumb = 0; 1862 Range aRange(0,0); 1863 1864 if(rDocRect.GetWidth() < rPreviewSize.Width()) 1865 { 1866 nVisWidth = rDocRect.GetWidth(); 1867 nThumb = rDocRect.Left(); 1868 aRange = Range(0, rPreviewSize.Width()); 1869 } 1870 pHScrollbar->SetRange( aRange ); 1871 pHScrollbar->SetVisibleSize( nVisWidth ); 1872 pHScrollbar->SetThumbPos( nThumb ); 1873 pHScrollbar->SetLineSize( nVisWidth / 10 ); 1874 pHScrollbar->SetPageSize( nVisWidth / 2 ); 1875 } 1876 } 1877 1878 /*-------------------------------------------------------------------- 1879 Beschreibung: 1880 --------------------------------------------------------------------*/ 1881 1882 1883 void SwPagePreView::ScrollDocSzChg() 1884 { 1885 ScrollViewSzChg(); 1886 } 1887 1888 1889 /* */ 1890 /*-------------------------------------------------------------------- 1891 Beschreibung: 1892 --------------------------------------------------------------------*/ 1893 1894 1895 // alles zum Thema Drucken 1896 1897 SfxPrinter* SwPagePreView::GetPrinter( sal_Bool bCreate ) 1898 { 1899 return aViewWin.GetViewShell()->getIDocumentDeviceAccess()->getPrinter( bCreate ); 1900 } 1901 1902 /*-------------------------------------------------------------------- 1903 Beschreibung: 1904 --------------------------------------------------------------------*/ 1905 1906 1907 sal_uInt16 SwPagePreView::SetPrinter( SfxPrinter *pNew, sal_uInt16 nDiffFlags, bool ) 1908 { 1909 ViewShell &rSh = *GetViewShell(); 1910 SfxPrinter* pOld = rSh.getIDocumentDeviceAccess()->getPrinter( false ); 1911 if ( pOld && pOld->IsPrinting() ) 1912 return SFX_PRINTERROR_BUSY; 1913 1914 SwEditShell &rESh = (SwEditShell&)rSh; //Buh... 1915 if( ( SFX_PRINTER_PRINTER | SFX_PRINTER_JOBSETUP ) & nDiffFlags ) 1916 { 1917 rSh.getIDocumentDeviceAccess()->setPrinter( pNew, true, true ); 1918 if( nDiffFlags & SFX_PRINTER_PRINTER ) 1919 rESh.SetModified(); 1920 } 1921 if ( ( nDiffFlags & SFX_PRINTER_OPTIONS ) == SFX_PRINTER_OPTIONS ) 1922 ::SetPrinter( rSh.getIDocumentDeviceAccess(), pNew, sal_False ); 1923 1924 const sal_Bool bChgOri = nDiffFlags & SFX_PRINTER_CHG_ORIENTATION ? sal_True : sal_False; 1925 const sal_Bool bChgSize= nDiffFlags & SFX_PRINTER_CHG_SIZE ? sal_True : sal_False; 1926 if ( bChgOri || bChgSize ) 1927 { 1928 rESh.StartAllAction(); 1929 if ( bChgOri ) 1930 rSh.ChgAllPageOrientation( sal_uInt16(pNew->GetOrientation()) ); 1931 if ( bChgSize ) 1932 { 1933 Size aSz( SvxPaperInfo::GetPaperSize( pNew ) ); 1934 rSh.ChgAllPageSize( aSz ); 1935 } 1936 if( !bNormalPrint ) 1937 aViewWin.CalcWish( aViewWin.GetRow(), aViewWin.GetCol() ); 1938 rESh.SetModified(); 1939 rESh.EndAllAction(); 1940 1941 static sal_uInt16 __READONLY_DATA aInval[] = 1942 { 1943 SID_ATTR_LONG_ULSPACE, SID_ATTR_LONG_LRSPACE, 1944 SID_RULER_BORDERS, SID_RULER_PAGE_POS, 0 1945 }; 1946 #ifdef DBG_UTIL 1947 { 1948 const sal_uInt16* pPtr = aInval + 1; 1949 do { 1950 ASSERT( *(pPtr - 1) < *pPtr, "falsche Sortierung!" ); 1951 } while( *++pPtr ); 1952 } 1953 #endif 1954 1955 GetViewFrame()->GetBindings().Invalidate(aInval); 1956 } 1957 1958 return 0; 1959 } 1960 1961 /*-------------------------------------------------------------------- 1962 Beschreibung: 1963 --------------------------------------------------------------------*/ 1964 1965 1966 SfxTabPage* SwPagePreView::CreatePrintOptionsPage( Window *pParent, 1967 const SfxItemSet &rOptions ) 1968 { 1969 return ::CreatePrintOptionsPage( pParent, rOptions, !bNormalPrint ); 1970 } 1971 1972 /*-------------------------------------------------------------------- 1973 Beschreibung: 1974 --------------------------------------------------------------------*/ 1975 1976 1977 // OD 18.12.2002 #103492# - no longer needed ?? 1978 Size SwPagePreView::GetOptimalSizePixel() const 1979 { 1980 ASSERT( false, "overloaded virtual method <SwPagePreView::GetOptimalSizePixel()> needed ??" ) 1981 return Size( -1, -1 ); 1982 /* 1983 //JP 09.06.99: was wird hier errechnet ????? 1984 // ALT: 1985 // SfxApplicationWindow* pWin = SFX_APPWINDOW ; 1986 // Rectangle aRect = pWin->GetClientAreaPixel(); 1987 1988 Window& rWin = GetViewFrame()->GetWindow(); 1989 Rectangle aRect( Point(0, 0), rWin.GetOutputSizePixel() ); 1990 Size aMaxSize( aRect.GetWidth(), aRect.GetHeight() ); 1991 Size aInSize = rWin.GetOutputSizePixel(); 1992 Size aOutSize = rWin.GetSizePixel(); 1993 sal_uInt16 nXBorder = sal_uInt16(aOutSize.Width() - aInSize.Width()); 1994 sal_uInt16 nYBorder = sal_uInt16(aOutSize.Height() - aInSize.Height()); 1995 aMaxSize.Width() -= nXBorder; 1996 //'auf Verdacht' etwas vom Border abziehen (Menue) 1997 nYBorder -= (nYBorder - nXBorder) / 2; 1998 aMaxSize.Height() -= nYBorder; 1999 //mit der max. moeglichen Outputsize guenstigstes Verhaeltnis ausrechnen 2000 aViewWin.GetOptimalSize(aMaxSize); 2001 // Border wieder dazuzaehlen 2002 aMaxSize.Height() += nYBorder; 2003 aMaxSize.Width() += nXBorder; 2004 return aMaxSize; 2005 */ 2006 } 2007 2008 /*-------------------------------------------------------------------- 2009 Beschreibung: 2010 --------------------------------------------------------------------*/ 2011 2012 // OD 12.12.2002 #103492# 2013 void SwPagePreViewWin::SetViewShell( ViewShell* pShell ) 2014 { 2015 mpViewShell = pShell; 2016 if ( mpViewShell && mpViewShell->IsPreView() ) 2017 { 2018 mpPgPrevwLayout = mpViewShell->PagePreviewLayout(); 2019 } 2020 } 2021 2022 void SwPagePreViewWin::RepaintCoreRect( const SwRect& rRect ) 2023 { 2024 // OD 2004-03-04 #i24183# 2025 if ( mpPgPrevwLayout->PreviewLayoutValid() ) 2026 { 2027 mpPgPrevwLayout->Repaint( Rectangle( rRect.Pos(), rRect.SSize() ) ); 2028 } 2029 } 2030 2031 /** method to adjust preview to a new zoom factor 2032 2033 OD 02.12.2002 #103492# 2034 OD 24.09.2003 #i19975# - also consider zoom type - adding parameter <_eZoomType> 2035 */ 2036 void SwPagePreViewWin::AdjustPreviewToNewZoom( const sal_uInt16 _nZoomFactor, 2037 const SvxZoomType _eZoomType ) 2038 { 2039 // OD 24.09.2003 #i19975# - consider zoom type 2040 if ( _eZoomType == SVX_ZOOM_WHOLEPAGE ) 2041 { 2042 mnRow = 1; 2043 mnCol = 1; 2044 mpPgPrevwLayout->Init( mnCol, mnRow, maPxWinSize, true ); 2045 mpPgPrevwLayout->Prepare( mnSttPage, Point(0,0), maPxWinSize, 2046 mnSttPage, maPaintedPreviewDocRect ); 2047 SetSelectedPage( mnSttPage ); 2048 SetPagePreview(mnRow, mnCol); 2049 maScale = GetMapMode().GetScaleX(); 2050 } 2051 else if ( _nZoomFactor != 0 ) 2052 { 2053 // calculate new scaling and set mapping mode appropriately. 2054 Fraction aNewScale( _nZoomFactor, 100 ); 2055 MapMode aNewMapMode = GetMapMode(); 2056 aNewMapMode.SetScaleX( aNewScale ); 2057 aNewMapMode.SetScaleY( aNewScale ); 2058 SetMapMode( aNewMapMode ); 2059 2060 // calculate new start position for preview paint 2061 Size aNewWinSize = PixelToLogic( maPxWinSize ); 2062 Point aNewPaintStartPos = 2063 mpPgPrevwLayout->GetPreviewStartPosForNewScale( aNewScale, maScale, aNewWinSize ); 2064 2065 // remember new scaling and prepare preview paint 2066 // Note: paint of preview will be performed by a corresponding invalidate 2067 // due to property changes. 2068 maScale = aNewScale; 2069 mpPgPrevwLayout->Prepare( 0, aNewPaintStartPos, maPxWinSize, 2070 mnSttPage, maPaintedPreviewDocRect ); 2071 } 2072 2073 } 2074 /* -----------------04.12.2002 10:46----------------- 2075 * pixel scrolling - horizontally always or vertically 2076 * when less than the desired number of rows fits into 2077 * the view 2078 * --------------------------------------------------*/ 2079 void SwPagePreViewWin::Scroll(long nXMove, long nYMove, sal_uInt16 /*nFlags*/) 2080 { 2081 maPaintedPreviewDocRect.Move(nXMove, nYMove); 2082 mpPgPrevwLayout->Prepare( 0, maPaintedPreviewDocRect.TopLeft(), 2083 maPxWinSize, mnSttPage, 2084 maPaintedPreviewDocRect ); 2085 2086 } 2087 2088 sal_Bool SwPagePreView::HandleWheelCommands( const CommandEvent& rCEvt ) 2089 { 2090 sal_Bool bOk = sal_False; 2091 const CommandWheelData* pWData = rCEvt.GetWheelData(); 2092 if( pWData && COMMAND_WHEEL_ZOOM == pWData->GetMode() ) 2093 { 2094 if(!Application::GetSettings().GetMiscSettings().GetEnableATToolSupport()) 2095 { 2096 sal_uInt16 nFactor = GetViewShell()->GetViewOptions()->GetZoom(); 2097 const sal_uInt16 nOffset = 10; 2098 if( 0L > pWData->GetDelta() ) 2099 { 2100 nFactor -= nOffset; 2101 if(nFactor < MIN_PREVIEW_ZOOM) 2102 nFactor = MIN_PREVIEW_ZOOM; 2103 } 2104 else 2105 { 2106 nFactor += nOffset; 2107 if(nFactor > MAX_PREVIEW_ZOOM) 2108 nFactor = MAX_PREVIEW_ZOOM; 2109 } 2110 SetZoom(SVX_ZOOM_PERCENT, nFactor); 2111 } 2112 bOk = sal_True; 2113 } 2114 else 2115 bOk = aViewWin.HandleScrollCommand( rCEvt, pHScrollbar, pVScrollbar ); 2116 return bOk; 2117 } 2118 2119 2120 uno::Reference< ::com::sun::star::accessibility::XAccessible > 2121 SwPagePreViewWin::CreateAccessible() 2122 { 2123 vos::OGuard aGuard(Application::GetSolarMutex()); // this should have 2124 // happend already!!! 2125 2126 DBG_ASSERT( GetViewShell() != NULL, "We need a view shell" ); 2127 return GetViewShell()->CreateAccessiblePreview(); 2128 } 2129 2130 /* -----------------------------06.05.2002 13:18------------------------------ 2131 2132 ---------------------------------------------------------------------------*/ 2133 void SwPagePreView::ApplyAccessiblityOptions(SvtAccessibilityOptions& rAccessibilityOptions) 2134 { 2135 GetViewShell()->ApplyAccessiblityOptions(rAccessibilityOptions); 2136 } 2137 /* -----------------------------2002/06/26 14:30------------------------------ 2138 2139 ---------------------------------------------------------------------------*/ 2140 void SwPagePreView::ShowHScrollbar(sal_Bool bShow) 2141 { 2142 pHScrollbar->Show(bShow); 2143 InvalidateBorder(); 2144 } 2145 2146 /* -----------------------------2002/06/26 14:30------------------------------ 2147 2148 ---------------------------------------------------------------------------*/ 2149 void SwPagePreView::ShowVScrollbar(sal_Bool bShow) 2150 { 2151 pVScrollbar->Show(bShow); 2152 InvalidateBorder(); 2153 } 2154 2155 /* -----------------25.11.2002 16:36----------------- 2156 * 2157 * --------------------------------------------------*/ 2158 void SwPagePreView::SetZoom(SvxZoomType eType, sal_uInt16 nFactor) 2159 { 2160 ViewShell& rSh = *GetViewShell(); 2161 SwViewOption aOpt(*rSh.GetViewOptions()); 2162 // OD 16.12.2002 #103492# - perform action only on changes of zoom or zoom type. 2163 if ( aOpt.GetZoom() != nFactor || 2164 aOpt.GetZoomType() != eType ) 2165 { 2166 aOpt.SetZoom(nFactor); 2167 aOpt.SetZoomType(eType); 2168 rSh.ApplyViewOptions( aOpt ); 2169 lcl_InvalidateZoomSlots(GetViewFrame()->GetBindings()); 2170 // OD 02.12.2002 #103492# 2171 // OD 24.09.2003 #i19975# - also consider zoom type 2172 aViewWin.AdjustPreviewToNewZoom( nFactor, eType ); 2173 ScrollViewSzChg(); 2174 } 2175 } 2176 2177 /** adjust position of vertical scrollbar 2178 2179 OD 19.02.2003 #107369 2180 2181 @author OD 2182 */ 2183 void SwPagePreView::SetVScrollbarThumbPos( const sal_uInt16 _nNewThumbPos ) 2184 { 2185 if ( pVScrollbar ) 2186 { 2187 pVScrollbar->SetThumbPos( _nNewThumbPos ); 2188 } 2189 } 2190