1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sc.hxx" 30 31 32 33 // INCLUDE --------------------------------------------------------------- 34 35 #include "scitems.hxx" 36 #include <editeng/eeitem.hxx> 37 38 #include <sfx2/app.hxx> 39 #include <editeng/sizeitem.hxx> 40 #include <svl/srchitem.hxx> 41 #include <svx/zoomslideritem.hxx> 42 #include <svx/svdview.hxx> 43 //CHINA001 #include <svx/zoom.hxx> 44 #include <sfx2/dispatch.hxx> 45 #include <sfx2/objface.hxx> 46 #include <sfx2/request.hxx> 47 #include <svl/stritem.hxx> 48 #include <svl/whiter.hxx> 49 #include <vcl/msgbox.hxx> 50 #include <vcl/help.hxx> 51 #include <tools/urlobj.hxx> 52 #include <sfx2/docfile.hxx> 53 #include <sfx2/printer.hxx> 54 55 #ifndef _SVX_ZOOMSLIDERITEM_HXX 56 #include <svx/zoomslideritem.hxx> 57 #endif 58 #include "prevwsh.hxx" 59 #include "preview.hxx" 60 #include "printfun.hxx" 61 #include "attrib.hxx" 62 #include "scmod.hxx" 63 #include "inputhdl.hxx" 64 #include "docsh.hxx" 65 #include "tabvwsh.hxx" 66 #include "stlpool.hxx" 67 #include "editutil.hxx" 68 #include "scresid.hxx" 69 #include "globstr.hrc" 70 #include "sc.hrc" 71 #include "ViewSettingsSequenceDefines.hxx" 72 #include "tpprint.hxx" 73 #include "printopt.hxx" 74 #include <xmloff/xmluconv.hxx> 75 #include <rtl/ustrbuf.hxx> 76 77 #include <svx/svxdlg.hxx> //CHINA001 78 #include <svx/dialogs.hrc> //CHINA001 79 80 #ifndef _SVX_ZOOM_HXX 81 #include <svx/zoom_def.hxx> 82 #endif 83 84 #include "sc.hrc" //CHINA001 85 #include "scabstdlg.hxx" //CHINA001 86 // fuer Rad-Maus 87 #define SC_DELTA_ZOOM 10 88 #define MINZOOM_SLIDER 10 89 #define MAXZOOM_SLIDER 400 90 91 #define SC_USERDATA_SEP ';' 92 93 using namespace com::sun::star; 94 95 // ----------------------------------------------------------------------- 96 97 #define ScPreviewShell 98 #include "scslots.hxx" 99 100 TYPEINIT1( ScPreviewShell, SfxViewShell ); 101 102 SFX_IMPL_INTERFACE( ScPreviewShell, SfxViewShell, ScResId(SCSTR_PREVIEWSHELL) ) 103 { 104 SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT|SFX_VISIBILITY_STANDARD| 105 SFX_VISIBILITY_SERVER|SFX_VISIBILITY_READONLYDOC, 106 ScResId(RID_OBJECTBAR_PREVIEW)); 107 SFX_POPUPMENU_REGISTRATION(ScResId(RID_POPUP_PREVIEW)); 108 } 109 110 SFX_IMPL_NAMED_VIEWFACTORY( ScPreviewShell, "PrintPreview" ) 111 { 112 SFX_VIEW_REGISTRATION(ScDocShell); 113 } 114 115 //------------------------------------------------------------------ 116 117 void ScPreviewShell::Construct( Window* pParent ) 118 { 119 eZoom = SVX_ZOOM_WHOLEPAGE; 120 121 pCorner = new ScrollBarBox( pParent, WB_SIZEABLE ); 122 123 pHorScroll = new ScrollBar(pParent, WB_HSCROLL ); 124 pVerScroll = new ScrollBar(pParent, WB_VSCROLL); 125 126 // SSA: --- RTL --- no mirroring for horizontal scrollbars 127 pHorScroll->EnableRTL( sal_False ); 128 129 pHorScroll->SetEndScrollHdl( LINK( this, ScPreviewShell, ScrollHandler ) ); 130 pVerScroll->SetEndScrollHdl( LINK( this, ScPreviewShell, ScrollHandler ) ); 131 132 pPreview = new ScPreview( pParent, pDocShell, this ); 133 134 SetPool( &SC_MOD()->GetPool() ); 135 SetWindow( pPreview ); 136 StartListening(*pDocShell,sal_True); 137 StartListening(*SFX_APP(),sal_True); // #i62045# #i62046# application is needed for Calc's own hints 138 SfxBroadcaster* pDrawBC = pDocShell->GetDocument()->GetDrawBroadcaster(); 139 if (pDrawBC) 140 StartListening(*pDrawBC); 141 142 pHorScroll->Show(); 143 pVerScroll->Show(); 144 pCorner->Show(); 145 SetHelpId( HID_SCSHELL_PREVWSH ); 146 SetName(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("Preview"))); 147 } 148 149 ScPreviewShell::ScPreviewShell( SfxViewFrame* pViewFrame, 150 SfxViewShell* pOldSh ) : 151 SfxViewShell( pViewFrame, SFX_VIEW_CAN_PRINT | SFX_VIEW_HAS_PRINTOPTIONS ), 152 pDocShell( (ScDocShell*)pViewFrame->GetObjectShell() ), 153 nSourceDesignMode( SC_FORCEMODE_NONE ), 154 pAccessibilityBroadcaster( NULL ) 155 { 156 Construct( &pViewFrame->GetWindow() ); 157 158 if ( pOldSh && pOldSh->ISA( ScTabViewShell ) ) 159 { 160 // store view settings, show table from TabView 161 //! store live ScViewData instead, and update on ScTablesHint? 162 //! or completely forget aSourceData on ScTablesHint? 163 164 ScTabViewShell* pTabViewShell = ((ScTabViewShell*)pOldSh); 165 ScViewData* pData = pTabViewShell->GetViewData(); 166 pData->WriteUserDataSequence( aSourceData ); 167 InitStartTable( pData->GetTabNo() ); 168 169 // #106334# also have to store the TabView's DesignMode state 170 // (only if draw view exists) 171 SdrView* pDrawView = pTabViewShell->GetSdrView(); 172 if ( pDrawView ) 173 nSourceDesignMode = pDrawView->IsDesignMode(); 174 } 175 } 176 177 __EXPORT ScPreviewShell::~ScPreviewShell() 178 { 179 // #108333#; notify Accessibility that Shell is dying and before destroy all 180 BroadcastAccessibility( SfxSimpleHint( SFX_HINT_DYING ) ); 181 DELETEZ(pAccessibilityBroadcaster); 182 183 SfxBroadcaster* pDrawBC = pDocShell->GetDocument()->GetDrawBroadcaster(); 184 if (pDrawBC) 185 EndListening(*pDrawBC); 186 EndListening(*SFX_APP()); 187 EndListening(*pDocShell); 188 189 SetWindow(0); 190 delete pPreview; 191 delete pHorScroll; 192 delete pVerScroll; 193 delete pCorner; 194 195 // #97612# normal mode of operation is switching back to default view in the same frame, 196 // so there's no need to activate any other window here anymore 197 } 198 199 void ScPreviewShell::InitStartTable(SCTAB nTab) 200 { 201 pPreview->SetPageNo( pPreview->GetFirstPage(nTab) ); 202 } 203 204 //------------------------------------------------------------------ 205 206 String __EXPORT ScPreviewShell::GetDescription() const 207 { 208 return String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(" ** Test ** ")); 209 } 210 211 Size __EXPORT ScPreviewShell::GetOptimalSizePixel() const 212 { 213 Size aOptSize(100,100); 214 215 ScTabViewShell* pViewSh = pDocShell->GetBestViewShell(); 216 217 if ( pViewSh ) 218 { 219 ScViewData* pViewData = pViewSh->GetViewData(); 220 SCTAB nCurTab = pViewData->GetTabNo(); 221 ScDocument* pDoc = pDocShell->GetDocument(); 222 ScStyleSheetPool* pStylePool = pDoc->GetStyleSheetPool(); 223 SfxStyleSheetBase* pStyleSheet = pStylePool->Find( 224 pDoc->GetPageStyle( nCurTab ), 225 SFX_STYLE_FAMILY_PAGE ); 226 227 DBG_ASSERT( pStyleSheet, "PageStyle not found :-/" ); 228 229 if ( pStyleSheet ) 230 { 231 const SfxItemSet& rSet = pStyleSheet->GetItemSet(); 232 const SvxSizeItem& rItem = (const SvxSizeItem&)rSet.Get( ATTR_PAGE_SIZE ); 233 const Size& rPageSize = rItem.GetSize(); 234 235 aOptSize.Width() = (long) (rPageSize.Width() * pViewData->GetPPTX()); 236 aOptSize.Height() = (long) (rPageSize.Height() * pViewData->GetPPTY()); 237 } 238 } 239 else 240 { 241 DBG_ERROR( "TabViewShell not found :-/" ); 242 } 243 244 return aOptSize; 245 } 246 247 void __EXPORT ScPreviewShell::AdjustPosSizePixel( const Point &rPos, const Size &rSize ) 248 { 249 long nBarW = GetViewFrame()->GetWindow().GetSettings().GetStyleSettings().GetScrollBarSize(); 250 long nBarH = nBarW; 251 // long nBarW = pVerScroll->GetSizePixel().Width(); 252 // long nBarH = pHorScroll->GetSizePixel().Height(); 253 254 Size aOutSize( rSize.Width()-nBarW, rSize.Height()-nBarH ); 255 pPreview->SetPosSizePixel( rPos, aOutSize ); 256 pHorScroll->SetPosSizePixel( Point( rPos.X(), rPos.Y() + aOutSize.Height() ), 257 Size( aOutSize.Width(), nBarH ) ); 258 pVerScroll->SetPosSizePixel( Point( rPos.X() + aOutSize.Width(), rPos.Y() ), 259 Size( nBarW, aOutSize.Height() ) ); 260 pCorner->SetPosSizePixel( Point( rPos.X() + aOutSize.Width(), rPos.Y() + aOutSize.Height() ), 261 Size( nBarW, nBarH ) ); 262 263 if ( SVX_ZOOM_WHOLEPAGE == eZoom ) 264 pPreview->SetZoom( pPreview->GetOptimalZoom(sal_False) ); 265 else if ( SVX_ZOOM_PAGEWIDTH == eZoom ) 266 pPreview->SetZoom( pPreview->GetOptimalZoom(sal_True) ); 267 268 UpdateScrollBars(); 269 } 270 271 void __EXPORT ScPreviewShell::InnerResizePixel( const Point &rOfs, const Size &rSize ) 272 { 273 AdjustPosSizePixel( rOfs,rSize ); 274 } 275 276 void __EXPORT ScPreviewShell::OuterResizePixel( const Point &rOfs, const Size &rSize ) 277 { 278 AdjustPosSizePixel( rOfs,rSize ); 279 } 280 281 void ScPreviewShell::UpdateScrollBars() 282 { 283 ScDocument* pDoc = pDocShell->GetDocument(); 284 SCTAB nTab = pPreview->GetTab(); 285 286 ScStyleSheetPool* pStylePool = pDoc->GetStyleSheetPool(); 287 SfxStyleSheetBase* pStyleSheet = pStylePool->Find( pDoc->GetPageStyle( nTab ), 288 SFX_STYLE_FAMILY_PAGE ); 289 DBG_ASSERT(pStyleSheet,"StyleSheet nicht gefunden"); 290 if (!pStyleSheet) return; 291 const SfxItemSet* pParamSet = &pStyleSheet->GetItemSet(); 292 293 Size aPageSize = ((const SvxSizeItem&) pParamSet->Get(ATTR_PAGE_SIZE)).GetSize(); 294 aPageSize.Width() = (long) (aPageSize.Width() * HMM_PER_TWIPS ); 295 aPageSize.Height() = (long) (aPageSize.Height() * HMM_PER_TWIPS ); 296 297 // for centering, page size without the shadow is used 298 299 Size aWindowSize = pPreview->GetOutputSize(); 300 301 Point aOfs = pPreview->GetOffset(); 302 long nMaxPos; 303 304 if( pHorScroll ) 305 { 306 pHorScroll->SetRange( Range( 0, aPageSize.Width() ) ); 307 pHorScroll->SetLineSize( aWindowSize.Width() / 16 ); 308 pHorScroll->SetPageSize( aWindowSize.Width() ); 309 pHorScroll->SetVisibleSize( aWindowSize.Width() ); 310 nMaxPos = aPageSize.Width() - aWindowSize.Width(); 311 if ( nMaxPos<0 ) 312 { 313 // page smaller than window -> center (but put scrollbar to 0) 314 aOfs.X() = 0; 315 pPreview->SetXOffset( nMaxPos / 2 ); 316 } 317 else if (aOfs.X() < 0) 318 { 319 // page larger than window -> never use negative offset 320 aOfs.X() = 0; 321 pPreview->SetXOffset( 0 ); 322 } 323 else if (aOfs.X() > nMaxPos) 324 { 325 // limit offset to align with right edge of window 326 aOfs.X() = nMaxPos; 327 pPreview->SetXOffset(nMaxPos); 328 } 329 pHorScroll->SetThumbPos( aOfs.X() ); 330 } 331 332 if( pVerScroll ) 333 { 334 long nPageNo = pPreview->GetPageNo(); 335 long nTotalPages = pPreview->GetTotalPages(); 336 337 nMaxVertPos = aPageSize.Height() - aWindowSize.Height(); 338 pVerScroll->SetLineSize( aWindowSize.Height() / 16 ); 339 pVerScroll->SetPageSize( aWindowSize.Height() ); 340 pVerScroll->SetVisibleSize( aWindowSize.Height() ); 341 if ( nMaxVertPos < 0 ) 342 { 343 // page smaller than window -> center (but put scrollbar to 0) 344 aOfs.Y() = 0; 345 pPreview->SetYOffset( nMaxVertPos / 2 ); 346 pVerScroll->SetThumbPos( nPageNo * aWindowSize.Height() ); 347 pVerScroll->SetRange( Range( 0, aWindowSize.Height() * nTotalPages )); 348 } 349 else if (aOfs.Y() < 0) 350 { 351 // page larger than window -> never use negative offset 352 pVerScroll->SetRange( Range( 0, aPageSize.Height() ) ); 353 aOfs.Y() = 0; 354 pPreview->SetYOffset( 0 ); 355 pVerScroll->SetThumbPos( aOfs.Y() ); 356 } 357 else if (aOfs.Y() > nMaxVertPos ) 358 { 359 // limit offset to align with window bottom 360 pVerScroll->SetRange( Range( 0, aPageSize.Height() ) ); 361 aOfs.Y() = nMaxVertPos; 362 pPreview->SetYOffset( nMaxVertPos ); 363 pVerScroll->SetThumbPos( aOfs.Y() ); 364 } 365 } 366 } 367 368 IMPL_LINK (ScPreviewShell,ScrollHandler, ScrollBar* ,pScroll ) 369 { 370 long nPos = pScroll->GetThumbPos(); 371 long nDelta = pScroll->GetDelta(); 372 long nMaxRange = pScroll->GetRangeMax(); 373 long nTotalPages = pPreview->GetTotalPages(); 374 long nPageNo = 0; 375 long nPerPageLength = 0; 376 sal_Bool bIsDivide = sal_True; 377 378 if( nTotalPages ) 379 nPerPageLength = nMaxRange / nTotalPages; 380 381 if( nPerPageLength ) 382 { 383 nPageNo = nPos / nPerPageLength; 384 if( nPos % nPerPageLength ) 385 { 386 bIsDivide = sal_False; 387 nPageNo ++; 388 } 389 } 390 391 sal_Bool bHoriz = ( pScroll == pHorScroll ); 392 393 if( bHoriz ) 394 pPreview->SetXOffset( nPos ); 395 else 396 { 397 if( nMaxVertPos > 0 ) 398 pPreview->SetYOffset( nPos ); 399 else 400 { 401 Point aMousePos = pScroll->OutputToNormalizedScreenPixel( pScroll->GetPointerPosPixel() ); 402 Point aPos = pScroll->GetParent()->OutputToNormalizedScreenPixel( pScroll->GetPosPixel() ); 403 String aHelpStr; 404 Rectangle aRect; 405 sal_uInt16 nAlign; 406 407 if( nDelta < 0 ) 408 { 409 if ( nTotalPages && nPageNo > 0 && !bIsDivide ) 410 pPreview->SetPageNo( nPageNo-1 ); 411 if( bIsDivide ) 412 pPreview->SetPageNo( nPageNo ); 413 414 aHelpStr = ScGlobal::GetRscString( STR_PAGE ); 415 aHelpStr += ' '; 416 aHelpStr += String::CreateFromInt32( nPageNo ); 417 418 aHelpStr.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " / " )); 419 aHelpStr += String::CreateFromInt32( nTotalPages ); 420 } 421 else if( nDelta > 0 ) 422 { 423 sal_Bool bAllTested = pPreview->AllTested(); 424 if ( nTotalPages && ( nPageNo < nTotalPages || !bAllTested ) ) 425 pPreview->SetPageNo( nPageNo ); 426 427 aHelpStr = ScGlobal::GetRscString( STR_PAGE ); 428 aHelpStr += ' '; 429 aHelpStr += String::CreateFromInt32( nPageNo+1 ); 430 431 aHelpStr.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " / " )); 432 aHelpStr += String::CreateFromInt32( nTotalPages ); 433 } 434 435 aRect.Left() = aPos.X() - 8; 436 aRect.Top() = aMousePos.Y(); 437 aRect.Right() = aRect.Left(); 438 aRect.Top() = aRect.Top(); 439 nAlign = QUICKHELP_BOTTOM|QUICKHELP_CENTER; 440 Help::ShowQuickHelp( pScroll->GetParent(), aRect, aHelpStr, nAlign ); 441 } 442 } 443 444 return 0; 445 } 446 447 sal_Bool ScPreviewShell::ScrollCommand( const CommandEvent& rCEvt ) 448 { 449 sal_Bool bDone = sal_False; 450 const CommandWheelData* pData = rCEvt.GetWheelData(); 451 if ( pData && pData->GetMode() == COMMAND_WHEEL_ZOOM ) 452 { 453 long nOld = pPreview->GetZoom(); 454 long nNew = nOld; 455 if ( pData->GetDelta() < 0 ) 456 nNew = Max( (long) MINZOOM, (long)( nOld - SC_DELTA_ZOOM ) ); 457 else 458 nNew = Min( (long) MAXZOOM, (long)( nOld + SC_DELTA_ZOOM ) ); 459 460 if ( nNew != nOld ) 461 { 462 eZoom = SVX_ZOOM_PERCENT; 463 pPreview->SetZoom( (sal_uInt16)nNew ); 464 } 465 466 bDone = sal_True; 467 } 468 else 469 { 470 bDone = pPreview->HandleScrollCommand( rCEvt, pHorScroll, pVerScroll ); 471 } 472 473 return bDone; 474 } 475 476 SfxPrinter* __EXPORT ScPreviewShell::GetPrinter( sal_Bool bCreate ) 477 { 478 return pDocShell->GetPrinter(bCreate); 479 } 480 481 sal_uInt16 __EXPORT ScPreviewShell::SetPrinter( SfxPrinter *pNewPrinter, sal_uInt16 nDiffFlags, bool ) 482 { 483 return pDocShell->SetPrinter( pNewPrinter, nDiffFlags ); 484 } 485 486 SfxTabPage* ScPreviewShell::CreatePrintOptionsPage( Window *pParent, const SfxItemSet &rOptions ) 487 { 488 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); 489 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001 490 //CHINA001 return ScTpPrintOptions::Create( pParent, rOptions ); 491 ::CreateTabPage ScTpPrintOptionsCreate = pFact->GetTabPageCreatorFunc( RID_SCPAGE_PRINT ); 492 if ( ScTpPrintOptionsCreate ) 493 return (*ScTpPrintOptionsCreate)( pParent, rOptions); 494 return 0; 495 } 496 497 //------------------------------------------------------------------------ 498 499 void __EXPORT ScPreviewShell::Activate(sal_Bool bMDI) 500 { 501 SfxViewShell::Activate(bMDI); 502 503 //! Basic etc. -> auslagern in eigene Datei (s. tabvwsh4) 504 505 if (bMDI) 506 { 507 // InputHdl ist jetzt meistens Null, keine Assertion mehr! 508 ScInputHandler* pInputHdl = SC_MOD()->GetInputHdl(); 509 if ( pInputHdl ) 510 pInputHdl->NotifyChange( NULL ); 511 } 512 } 513 514 void __EXPORT ScPreviewShell::Deactivate(sal_Bool bMDI) 515 { 516 SfxViewShell::Deactivate(bMDI); 517 518 if (bMDI) 519 { 520 } 521 } 522 523 //------------------------------------------------------------------------ 524 525 void __EXPORT ScPreviewShell::Execute( SfxRequest& rReq ) 526 { 527 sal_uInt16 nSlot = rReq.GetSlot(); 528 const SfxItemSet* pReqArgs = rReq.GetArgs(); 529 530 switch ( nSlot ) 531 { 532 case SID_FORMATPAGE: 533 case SID_STATUS_PAGESTYLE: 534 case SID_HFEDIT: 535 pDocShell->ExecutePageStyle( *this, rReq, pPreview->GetTab() ); 536 break; 537 case SID_REPAINT: 538 pPreview->Invalidate(); 539 rReq.Done(); 540 break; 541 case SID_PREV_TABLE: // Accelerator 542 case SID_PREVIEW_PREVIOUS: 543 { 544 long nPage = pPreview->GetPageNo(); 545 long nTotal = pPreview->GetTotalPages(); 546 if (nTotal && nPage > 0) 547 pPreview->SetPageNo( nPage-1 ); 548 } 549 break; 550 case SID_NEXT_TABLE: // Accelerator 551 case SID_PREVIEW_NEXT: 552 { 553 sal_Bool bAllTested = pPreview->AllTested(); 554 long nPage = pPreview->GetPageNo(); 555 long nTotal = pPreview->GetTotalPages(); 556 if (nTotal && (nPage+1 < nTotal || !bAllTested)) 557 pPreview->SetPageNo( nPage+1 ); 558 } 559 break; 560 case SID_CURSORTOPOFFILE: // Accelerator 561 case SID_PREVIEW_FIRST: 562 { 563 long nPage = pPreview->GetPageNo(); 564 long nTotal = pPreview->GetTotalPages(); 565 if (nTotal && nPage != 0) 566 pPreview->SetPageNo( 0 ); 567 } 568 break; 569 case SID_CURSORENDOFFILE: // Accelerator 570 case SID_PREVIEW_LAST: 571 { 572 if (!pPreview->AllTested()) 573 pPreview->CalcAll(); 574 575 long nPage = pPreview->GetPageNo(); 576 long nTotal = pPreview->GetTotalPages(); 577 if (nTotal && nPage+1 != nTotal) 578 pPreview->SetPageNo( nTotal-1 ); 579 } 580 break; 581 case SID_ATTR_ZOOM: 582 case FID_SCALE: 583 { 584 sal_uInt16 nZoom = 100; 585 sal_Bool bCancel = sal_False; 586 587 eZoom = SVX_ZOOM_PERCENT; 588 589 if ( pReqArgs ) 590 { 591 592 const SvxZoomItem& rZoomItem = (const SvxZoomItem&) 593 pReqArgs->Get(SID_ATTR_ZOOM); 594 595 eZoom = rZoomItem.GetType(); 596 nZoom = rZoomItem.GetValue(); 597 } 598 else 599 { 600 SfxItemSet aSet ( GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM ); 601 SvxZoomItem aZoomItem( SVX_ZOOM_PERCENT, pPreview->GetZoom(), SID_ATTR_ZOOM ); 602 603 aSet.Put( aZoomItem ); 604 //CHINA001 SvxZoomDialog* pDlg = pDlg = new SvxZoomDialog( NULL, aSet ); 605 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); 606 if(pFact) 607 { 608 AbstractSvxZoomDialog* pDlg = pFact->CreateSvxZoomDialog(NULL, aSet); 609 DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001 610 pDlg->SetLimits( 20, 400 ); 611 pDlg->HideButton( ZOOMBTN_OPTIMAL ); 612 bCancel = ( RET_CANCEL == pDlg->Execute() ); 613 614 if ( !bCancel ) 615 { 616 const SvxZoomItem& rZoomItem = (const SvxZoomItem&) 617 pDlg->GetOutputItemSet()-> 618 Get( SID_ATTR_ZOOM ); 619 620 eZoom = rZoomItem.GetType(); 621 nZoom = rZoomItem.GetValue(); 622 } 623 624 delete pDlg; 625 } 626 } 627 628 if ( !bCancel ) 629 { 630 switch ( eZoom ) 631 { 632 case SVX_ZOOM_OPTIMAL: 633 case SVX_ZOOM_WHOLEPAGE: 634 nZoom = pPreview->GetOptimalZoom(sal_False); 635 break; 636 case SVX_ZOOM_PAGEWIDTH: 637 nZoom = pPreview->GetOptimalZoom(sal_True); 638 break; 639 default: 640 { 641 // added to avoid warnings 642 } 643 } 644 645 pPreview->SetZoom( nZoom ); 646 rReq.Done(); 647 } 648 } 649 break; 650 case SID_PREVIEW_ZOOMIN: 651 { 652 sal_uInt16 nNew = pPreview->GetZoom() + 20 ; 653 nNew -= nNew % 20; 654 pPreview->SetZoom( nNew ); 655 eZoom = SVX_ZOOM_PERCENT; 656 rReq.Done(); 657 } 658 break; 659 case SID_PREVIEW_ZOOMOUT: 660 { 661 sal_uInt16 nNew = pPreview->GetZoom() - 1; 662 nNew -= nNew % 20; 663 pPreview->SetZoom( nNew ); 664 eZoom = SVX_ZOOM_PERCENT; 665 rReq.Done(); 666 } 667 break; 668 case SID_PREVIEW_MARGIN: 669 { 670 sal_Bool bMargin = pPreview->GetPageMargins(); 671 pPreview->SetPageMargins( !bMargin ); 672 pPreview->Invalidate(); 673 rReq.Done(); 674 } 675 break; 676 case SID_ATTR_ZOOMSLIDER: 677 { 678 const SfxPoolItem* pItem; 679 eZoom = SVX_ZOOM_PERCENT; 680 if( pReqArgs && SFX_ITEM_SET == pReqArgs->GetItemState( SID_ATTR_ZOOMSLIDER, sal_True, &pItem ) ) 681 { 682 const sal_uInt16 nCurrentZoom = ((const SvxZoomSliderItem*)pItem)->GetValue(); 683 if( nCurrentZoom ) 684 { 685 pPreview->SetZoom( nCurrentZoom ); 686 rReq.Done(); 687 } 688 } 689 } 690 break; 691 case SID_PREVIEW_SCALINGFACTOR: 692 { 693 const SfxPoolItem* pItem; 694 SCTAB nTab = pPreview->GetTab(); 695 String aOldName = pDocShell->GetDocument()->GetPageStyle( pPreview->GetTab() ); 696 ScStyleSheetPool* pStylePool = pDocShell->GetDocument()->GetStyleSheetPool(); 697 SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aOldName, SFX_STYLE_FAMILY_PAGE ); 698 DBG_ASSERT( pStyleSheet, "PageStyle not found! :-/" ); 699 700 if ( pReqArgs && pStyleSheet && SFX_ITEM_SET == pReqArgs->GetItemState( SID_PREVIEW_SCALINGFACTOR, sal_True, &pItem ) ) 701 { 702 const sal_uInt16 nCurrentZoom = ((const SvxZoomSliderItem *)pItem)->GetValue(); 703 SfxItemSet& rSet = pStyleSheet->GetItemSet(); 704 rSet.Put( SfxUInt16Item( ATTR_PAGE_SCALE, nCurrentZoom ) ); 705 ScPrintFunc aPrintFunc( pDocShell, pDocShell->GetPrinter(), nTab ); 706 aPrintFunc.UpdatePages(); 707 rReq.Done(); 708 } 709 GetViewFrame()->GetBindings().Invalidate( nSlot ); 710 } 711 break; 712 case SID_PRINTPREVIEW: 713 case SID_PREVIEW_CLOSE: 714 // print preview is now always in the same frame as the tab view 715 // -> always switch this frame back to normal view 716 // (ScTabViewShell ctor reads stored view data) 717 718 GetViewFrame()->GetDispatcher()->Execute( SID_VIEWSHELL0, SFX_CALLMODE_ASYNCHRON ); 719 break; 720 case SID_CURSORPAGEUP: 721 case SID_CURSORPAGEDOWN: 722 case SID_CURSORHOME: 723 case SID_CURSOREND: 724 case SID_CURSORUP: 725 case SID_CURSORDOWN: 726 case SID_CURSORLEFT: 727 case SID_CURSORRIGHT: 728 DoScroll( nSlot ); 729 break; 730 case SID_CANCEL: 731 if( ScViewUtil::IsFullScreen( *this ) ) 732 ScViewUtil::SetFullScreen( *this, false ); 733 break; 734 735 default: 736 break; 737 } 738 } 739 740 void __EXPORT ScPreviewShell::GetState( SfxItemSet& rSet ) 741 { 742 pPreview->SetInGetState(sal_True); 743 744 SCTAB nTab = pPreview->GetTab(); 745 long nPage = pPreview->GetPageNo(); 746 long nTotal = pPreview->GetTotalPages(); 747 sal_uInt16 nZoom = pPreview->GetZoom(); 748 sal_Bool bAllTested = pPreview->AllTested(); 749 750 SfxWhichIter aIter(rSet); 751 sal_uInt16 nWhich = aIter.FirstWhich(); 752 while ( nWhich ) 753 { 754 switch (nWhich) 755 { 756 case SID_STATUS_PAGESTYLE: 757 case SID_HFEDIT: 758 pDocShell->GetStatePageStyle( *this, rSet, nTab ); 759 break; 760 case SID_UNDO: 761 case SID_REDO: 762 case SID_REPEAT: 763 rSet.DisableItem(nWhich); 764 break; 765 case SID_PREVIEW_PREVIOUS: 766 case SID_PREVIEW_FIRST: 767 if (!nTotal || nPage==0) 768 rSet.DisableItem(nWhich); 769 break; 770 case SID_PREVIEW_NEXT: 771 case SID_PREVIEW_LAST: 772 if (bAllTested) 773 if (!nTotal || nPage==nTotal-1) 774 rSet.DisableItem(nWhich); 775 break; 776 case SID_PREVIEW_ZOOMIN: 777 if (nZoom >= 400) 778 rSet.DisableItem(nWhich); 779 break; 780 case SID_PREVIEW_ZOOMOUT: 781 if (nZoom <= 20) 782 rSet.DisableItem(nWhich); 783 break; 784 case SID_ATTR_ZOOM: 785 { 786 SvxZoomItem aZoom( eZoom, nZoom, nWhich ); 787 aZoom.SetValueSet( SVX_ZOOM_ENABLE_ALL & ~SVX_ZOOM_ENABLE_OPTIMAL ); 788 rSet.Put( aZoom ); 789 } 790 break; 791 case SID_ATTR_ZOOMSLIDER: 792 { 793 SvxZoomSliderItem aZoomSliderItem( nZoom, MINZOOM, MAXZOOM, SID_ATTR_ZOOMSLIDER ); 794 aZoomSliderItem.AddSnappingPoint( 100 ); 795 rSet.Put( aZoomSliderItem ); 796 } 797 break; 798 case SID_PREVIEW_SCALINGFACTOR: 799 { 800 if( pDocShell->IsReadOnly() ) 801 rSet.DisableItem( nWhich ); 802 else 803 { 804 String aOldName = pDocShell->GetDocument()->GetPageStyle( pPreview->GetTab() ); 805 ScStyleSheetPool* pStylePool = pDocShell->GetDocument()->GetStyleSheetPool(); 806 SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aOldName, SFX_STYLE_FAMILY_PAGE ); 807 DBG_ASSERT( pStyleSheet, "PageStyle not found! :-/" ); 808 809 if ( pStyleSheet ) 810 { 811 SfxItemSet& rStyleSet = pStyleSheet->GetItemSet(); 812 sal_uInt16 nCurrentZoom = ((const SfxUInt16Item&)rStyleSet.Get(ATTR_PAGE_SCALE)).GetValue(); 813 if( nCurrentZoom ) 814 { 815 SvxZoomSliderItem aZoomSliderItem( nCurrentZoom, MINZOOM_SLIDER, MAXZOOM_SLIDER, SID_PREVIEW_SCALINGFACTOR ); 816 aZoomSliderItem.AddSnappingPoint( 100 ); 817 rSet.Put( aZoomSliderItem ); 818 } 819 else 820 rSet.DisableItem( nWhich ); 821 } 822 } 823 } 824 break; 825 case SID_STATUS_DOCPOS: 826 rSet.Put( SfxStringItem( nWhich, pPreview->GetPosString() ) ); 827 break; 828 case SID_PRINTPREVIEW: 829 rSet.Put( SfxBoolItem( nWhich, sal_True ) ); 830 break; 831 case SID_FORMATPAGE: 832 case SID_PREVIEW_MARGIN: 833 if( pDocShell->IsReadOnly() ) 834 rSet.DisableItem( nWhich ); 835 break; 836 } 837 838 nWhich = aIter.NextWhich(); 839 } 840 841 pPreview->SetInGetState(sal_False); 842 } 843 844 void ScPreviewShell::FillFieldData( ScHeaderFieldData& rData ) 845 { 846 ScDocument* pDoc = pDocShell->GetDocument(); 847 SCTAB nTab = pPreview->GetTab(); 848 pDoc->GetName( nTab, rData.aTabName ); 849 850 rData.aTitle = pDocShell->GetTitle(); 851 const INetURLObject& rURLObj = pDocShell->GetMedium()->GetURLObject(); 852 rData.aLongDocName = rURLObj.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ); 853 if ( rData.aLongDocName.Len() ) 854 rData.aShortDocName = rURLObj.GetName( INetURLObject::DECODE_UNAMBIGUOUS ); 855 else 856 rData.aShortDocName = rData.aLongDocName = rData.aTitle; 857 rData.nPageNo = pPreview->GetPageNo() + 1; 858 859 sal_Bool bAllTested = pPreview->AllTested(); 860 if (bAllTested) 861 rData.nTotalPages = pPreview->GetTotalPages(); 862 else 863 rData.nTotalPages = 99; 864 865 // eNumType kennt der Dialog selber 866 } 867 868 void __EXPORT ScPreviewShell::WriteUserData(String& rData, sal_Bool /* bBrowse */) 869 { 870 // nZoom 871 // nPageNo 872 873 rData = String::CreateFromInt32(pPreview->GetZoom()); 874 rData += (sal_Unicode) SC_USERDATA_SEP; 875 rData += String::CreateFromInt32(pPreview->GetPageNo()); 876 } 877 878 void __EXPORT ScPreviewShell::ReadUserData(const String& rData, sal_Bool /* bBrowse */) 879 { 880 xub_StrLen nCount = rData.GetTokenCount(); 881 if (nCount) 882 { 883 xub_StrLen nIndex = 0; 884 pPreview->SetZoom((sal_uInt16)rData.GetToken( 0, SC_USERDATA_SEP, nIndex ).ToInt32()); 885 pPreview->SetPageNo(rData.GetToken( 0, SC_USERDATA_SEP, nIndex ).ToInt32()); 886 eZoom = SVX_ZOOM_PERCENT; 887 } 888 } 889 890 void __EXPORT ScPreviewShell::WriteUserDataSequence(uno::Sequence < beans::PropertyValue >& rSeq, sal_Bool /* bBrowse */) 891 { 892 rSeq.realloc(3); 893 beans::PropertyValue* pSeq = rSeq.getArray(); 894 if(pSeq) 895 { 896 sal_uInt16 nViewID(GetViewFrame()->GetCurViewId()); 897 pSeq[0].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_VIEWID)); 898 rtl::OUStringBuffer sBuffer(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_VIEW))); 899 SvXMLUnitConverter::convertNumber(sBuffer, static_cast<sal_Int32>(nViewID)); 900 pSeq[0].Value <<= sBuffer.makeStringAndClear(); 901 pSeq[1].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_ZOOMVALUE)); 902 pSeq[1].Value <<= sal_Int32 (pPreview->GetZoom()); 903 pSeq[2].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PageNumber")); 904 pSeq[2].Value <<= pPreview->GetPageNo(); 905 } 906 } 907 908 void __EXPORT ScPreviewShell::ReadUserDataSequence(const uno::Sequence < beans::PropertyValue >& rSeq, sal_Bool /* bBrowse */) 909 { 910 sal_Int32 nCount(rSeq.getLength()); 911 if (nCount) 912 { 913 sal_Int32 nTemp = 0; 914 const beans::PropertyValue* pSeq = rSeq.getConstArray(); 915 if(pSeq) 916 { 917 for(sal_Int32 i = 0; i < nCount; i++, pSeq++) 918 { 919 rtl::OUString sName(pSeq->Name); 920 if(sName.compareToAscii(SC_ZOOMVALUE) == 0) 921 { 922 if (pSeq->Value >>= nTemp) 923 pPreview->SetZoom(sal_uInt16(nTemp)); 924 } 925 else if (sName.compareToAscii("PageNumber") == 0) 926 { 927 if (pSeq->Value >>= nTemp) 928 pPreview->SetPageNo(nTemp); 929 } 930 } 931 } 932 } 933 } 934 935 void ScPreviewShell::DoScroll( sal_uInt16 nMode ) 936 { 937 Point aCurPos, aPrevPos; 938 939 long nHRange = pHorScroll->GetRange().Max(); 940 long nHLine = pHorScroll->GetLineSize(); 941 long nHPage = pHorScroll->GetPageSize(); 942 long nVRange = pVerScroll->GetRange().Max(); 943 long nVLine = pVerScroll->GetLineSize(); 944 long nVPage = pVerScroll->GetPageSize(); 945 946 aCurPos.X() = pHorScroll->GetThumbPos(); 947 aCurPos.Y() = pVerScroll->GetThumbPos(); 948 aPrevPos = aCurPos; 949 950 long nThumbPos = pVerScroll->GetThumbPos(); 951 long nRangeMax = pVerScroll->GetRangeMax(); 952 953 switch( nMode ) 954 { 955 case SID_CURSORUP: 956 if( nMaxVertPos<0 ) 957 { 958 long nPage = pPreview->GetPageNo(); 959 960 if( nPage>0 ) 961 { 962 SfxViewFrame* pSfxViewFrame = GetViewFrame(); 963 SfxRequest aSfxRequest( pSfxViewFrame, SID_PREVIEW_PREVIOUS ); 964 Execute( aSfxRequest ); 965 } 966 } 967 else 968 aCurPos.Y() -= nVLine; 969 break; 970 case SID_CURSORDOWN: 971 if( nMaxVertPos<0 ) 972 { 973 long nPage = pPreview->GetPageNo(); 974 long nTotal = pPreview->GetTotalPages(); 975 976 // before testing for last page, make sure all page counts are calculated 977 if ( nPage+1 == nTotal && !pPreview->AllTested() ) 978 { 979 pPreview->CalcAll(); 980 nTotal = pPreview->GetTotalPages(); 981 } 982 983 if( nPage<nTotal-1 ) 984 { 985 SfxViewFrame* pSfxViewFrame = GetViewFrame(); 986 SfxRequest aSfxRequest( pSfxViewFrame, SID_PREVIEW_NEXT ); 987 Execute( aSfxRequest ); 988 } 989 } 990 else 991 aCurPos.Y() += nVLine; 992 break; 993 case SID_CURSORLEFT: 994 aCurPos.X() -= nHLine; 995 break; 996 case SID_CURSORRIGHT: 997 aCurPos.X() += nHLine; 998 break; 999 case SID_CURSORPAGEUP: 1000 if( nThumbPos==0 || nMaxVertPos<0 ) 1001 { 1002 long nPage = pPreview->GetPageNo(); 1003 1004 if( nPage>0 ) 1005 { 1006 SfxViewFrame* pSfxViewFrame = GetViewFrame(); 1007 SfxRequest aSfxRequest( pSfxViewFrame, SID_PREVIEW_PREVIOUS ); 1008 Execute( aSfxRequest ); 1009 aCurPos.Y() = nVRange; 1010 } 1011 } 1012 else 1013 aCurPos.Y() -= nVPage; 1014 break; 1015 case SID_CURSORPAGEDOWN: 1016 if( (abs(nVPage+nThumbPos-nRangeMax)<10) || nMaxVertPos<0 ) 1017 { 1018 long nPage = pPreview->GetPageNo(); 1019 long nTotal = pPreview->GetTotalPages(); 1020 1021 // before testing for last page, make sure all page counts are calculated 1022 if ( nPage+1 == nTotal && !pPreview->AllTested() ) 1023 { 1024 pPreview->CalcAll(); 1025 nTotal = pPreview->GetTotalPages(); 1026 } 1027 if( nPage<nTotal-1 ) 1028 { 1029 SfxViewFrame* pSfxViewFrame = GetViewFrame(); 1030 SfxRequest aSfxRequest( pSfxViewFrame, SID_PREVIEW_NEXT ); 1031 Execute( aSfxRequest ); 1032 aCurPos.Y() = 0; 1033 } 1034 } 1035 else 1036 aCurPos.Y() += nVPage; 1037 break; 1038 case SID_CURSORHOME: 1039 if( nMaxVertPos<0 ) 1040 { 1041 long nPage = pPreview->GetPageNo(); 1042 long nTotal = pPreview->GetTotalPages(); 1043 if( nTotal && nPage != 0 ) 1044 { 1045 SfxViewFrame* pSfxViewFrame = GetViewFrame(); 1046 SfxRequest aSfxRequest( pSfxViewFrame, SID_PREVIEW_FIRST ); 1047 Execute( aSfxRequest ); 1048 } 1049 } 1050 else 1051 { 1052 aCurPos.Y() = 0; 1053 aCurPos.X() = 0; 1054 } 1055 break; 1056 case SID_CURSOREND: 1057 if( nMaxVertPos<0 ) 1058 { 1059 if( !pPreview->AllTested() ) 1060 pPreview->CalcAll(); 1061 long nPage = pPreview->GetPageNo(); 1062 long nTotal = pPreview->GetTotalPages(); 1063 if( nTotal && nPage+1 != nTotal ) 1064 { 1065 SfxViewFrame* pSfxViewFrame = GetViewFrame(); 1066 SfxRequest aSfxRequest( pSfxViewFrame, SID_PREVIEW_LAST ); 1067 Execute( aSfxRequest ); 1068 } 1069 } 1070 else 1071 { 1072 aCurPos.Y() = nVRange; 1073 aCurPos.X() = nHRange; 1074 } 1075 break; 1076 } 1077 1078 // nHRange-nHPage kann negativ sein, deshalb Abfrage auf < 0 hinterher 1079 1080 if( aCurPos.Y() > (nVRange-nVPage) ) 1081 aCurPos.Y() = (nVRange-nVPage); 1082 if( aCurPos.Y() < 0 ) 1083 aCurPos.Y() = 0; 1084 if( aCurPos.X() > (nHRange-nHPage) ) 1085 aCurPos.X() = (nHRange-nHPage); 1086 if( aCurPos.X() < 0 ) 1087 aCurPos.X() = 0; 1088 1089 if( nMaxVertPos>=0 ) 1090 { 1091 if( aCurPos.Y() != aPrevPos.Y() ) 1092 { 1093 pVerScroll->SetThumbPos( aCurPos.Y() ); 1094 pPreview->SetYOffset( aCurPos.Y() ); 1095 } 1096 } 1097 1098 if( aCurPos.X() != aPrevPos.X() ) 1099 { 1100 pHorScroll->SetThumbPos( aCurPos.X() ); 1101 pPreview->SetXOffset( aCurPos.X() ); 1102 } 1103 1104 } 1105 1106 void ScPreviewShell::AddAccessibilityObject( SfxListener& rObject ) 1107 { 1108 if (!pAccessibilityBroadcaster) 1109 pAccessibilityBroadcaster = new SfxBroadcaster; 1110 1111 rObject.StartListening( *pAccessibilityBroadcaster ); 1112 } 1113 1114 void ScPreviewShell::RemoveAccessibilityObject( SfxListener& rObject ) 1115 { 1116 if (pAccessibilityBroadcaster) 1117 rObject.EndListening( *pAccessibilityBroadcaster ); 1118 else 1119 { 1120 DBG_ERROR("kein Accessibility-Broadcaster?"); 1121 } 1122 } 1123 1124 void ScPreviewShell::BroadcastAccessibility( const SfxHint &rHint ) 1125 { 1126 if (pAccessibilityBroadcaster) 1127 pAccessibilityBroadcaster->Broadcast( rHint ); 1128 } 1129 1130 sal_Bool ScPreviewShell::HasAccessibilityObjects() 1131 { 1132 return pAccessibilityBroadcaster && pAccessibilityBroadcaster->HasListeners(); 1133 } 1134 1135 const ScPreviewLocationData& ScPreviewShell::GetLocationData() 1136 { 1137 return pPreview->GetLocationData(); 1138 } 1139 1140 ScDocument* ScPreviewShell::GetDocument() 1141 { 1142 return pDocShell->GetDocument(); 1143 } 1144 1145 1146