Bump version to 21.06.18.1
[LibreOffice.git] / sd / source / ui / view / viewshe2.cxx
blob8bfc9739e6e792764cefbb6c8f8a903e7aeb531f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/embed/EmbedVerbs.hpp>
21 #include <com/sun/star/embed/XEmbeddedObject.hpp>
23 #include <ViewShell.hxx>
24 #include <ViewShellHint.hxx>
26 #include <ViewShellImplementation.hxx>
27 #include <FactoryIds.hxx>
29 #include <svx/svxids.hrc>
30 #include <vcl/scrbar.hxx>
31 #include <svx/svdpagv.hxx>
32 #include <sfx2/dispatch.hxx>
33 #include <svx/ruler.hxx>
34 #include <editeng/outlobj.hxx>
35 #include <editeng/outliner.hxx>
36 #include <svtools/ehdl.hxx>
37 #include <svx/svdoole2.hxx>
38 #include <svtools/sfxecode.hxx>
39 #include <unotools/moduleoptions.hxx>
40 #include <comphelper/classids.hxx>
42 #include <strings.hrc>
43 #include <app.hrc>
44 #include <unokywds.hxx>
46 #include <sdundogr.hxx>
47 #include <FrameView.hxx>
48 #include <sdresid.hxx>
49 #include <drawdoc.hxx>
50 #include <View.hxx>
51 #include <fupoor.hxx>
52 #include <Client.hxx>
53 #include <DrawDocShell.hxx>
54 #include <sdpage.hxx>
55 #include <DrawViewShell.hxx>
56 #include <ViewShellBase.hxx>
58 #include <Window.hxx>
60 #include <sfx2/viewfrm.hxx>
61 #include <svtools/soerr.hxx>
62 #include <svx/charthelper.hxx>
63 #include <comphelper/lok.hxx>
65 using namespace com::sun::star;
67 namespace sd {
69 /**
70 * adjust Thumbpos and VisibleSize
72 void ViewShell::UpdateScrollBars()
74 if (mpHorizontalScrollBar)
76 ::tools::Long nW = static_cast<::tools::Long>(mpContentWindow->GetVisibleWidth() * 32000);
77 ::tools::Long nX = static_cast<::tools::Long>(mpContentWindow->GetVisibleX() * 32000);
78 mpHorizontalScrollBar->SetVisibleSize(nW);
79 mpHorizontalScrollBar->SetThumbPos(nX);
80 nW = 32000 - nW;
81 ::tools::Long nLine = static_cast<::tools::Long>(mpContentWindow->GetScrlLineWidth() * nW);
82 ::tools::Long nPage = static_cast<::tools::Long>(mpContentWindow->GetScrlPageWidth() * nW);
83 mpHorizontalScrollBar->SetLineSize(nLine);
84 mpHorizontalScrollBar->SetPageSize(nPage);
87 if (mpVerticalScrollBar)
89 ::tools::Long nH = static_cast<::tools::Long>(mpContentWindow->GetVisibleHeight() * 32000);
90 ::tools::Long nY = static_cast<::tools::Long>(mpContentWindow->GetVisibleY() * 32000);
92 if(IsPageFlipMode()) // ie in zoom mode where no panning
94 SdPage* pPage = static_cast<DrawViewShell*>(this)->GetActualPage();
95 sal_uInt16 nCurPage = (pPage->GetPageNum() - 1) / 2;
96 sal_uInt16 nTotalPages = GetDoc()->GetSdPageCount(pPage->GetPageKind());
97 mpVerticalScrollBar->SetRange(Range(0,256*nTotalPages));
98 mpVerticalScrollBar->SetVisibleSize(256);
99 mpVerticalScrollBar->SetThumbPos(256*nCurPage);
100 mpVerticalScrollBar->SetLineSize(256);
101 mpVerticalScrollBar->SetPageSize(256);
103 else
105 mpVerticalScrollBar->SetRange(Range(0,32000));
106 mpVerticalScrollBar->SetVisibleSize(nH);
107 mpVerticalScrollBar->SetThumbPos(nY);
108 nH = 32000 - nH;
109 ::tools::Long nLine = static_cast<::tools::Long>(mpContentWindow->GetScrlLineHeight() * nH);
110 ::tools::Long nPage = static_cast<::tools::Long>(mpContentWindow->GetScrlPageHeight() * nH);
111 mpVerticalScrollBar->SetLineSize(nLine);
112 mpVerticalScrollBar->SetPageSize(nPage);
116 if (mbHasRulers)
118 UpdateHRuler();
119 UpdateVRuler();
124 * Handling for horizontal Scrollbars
126 IMPL_LINK(ViewShell, HScrollHdl, ScrollBar *, pHScroll, void )
128 VirtHScrollHdl(pHScroll);
132 * virtual scroll handler for horizontal Scrollbars
134 void ViewShell::VirtHScrollHdl(ScrollBar* pHScroll)
136 ::tools::Long nDelta = pHScroll->GetDelta();
138 if (nDelta == 0)
139 return;
141 double fX = static_cast<double>(pHScroll->GetThumbPos()) / pHScroll->GetRange().Len();
143 // scroll all windows of the column
144 ::sd::View* pView = GetView();
145 OutlinerView* pOLV = nullptr;
147 if (pView)
148 pOLV = pView->GetTextEditOutlinerView();
150 if (pOLV)
151 pOLV->HideCursor();
153 mpContentWindow->SetVisibleXY(fX, -1);
155 ::tools::Rectangle aVisArea = GetDocSh()->GetVisArea(ASPECT_CONTENT);
156 Point aVisAreaPos = GetActiveWindow()->PixelToLogic( Point(0,0) );
157 aVisArea.SetPos(aVisAreaPos);
158 GetDocSh()->SetVisArea(aVisArea);
160 Size aVisSizePixel = GetActiveWindow()->GetOutputSizePixel();
161 ::tools::Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( ::tools::Rectangle( Point(0,0), aVisSizePixel) );
162 VisAreaChanged(aVisAreaWin);
164 if (pView)
166 pView->VisAreaChanged(GetActiveWindow());
169 if (pOLV)
170 pOLV->ShowCursor();
172 if (mbHasRulers)
173 UpdateHRuler();
177 * handling for vertical Scrollbars
179 IMPL_LINK(ViewShell, VScrollHdl, ScrollBar *, pVScroll, void )
181 VirtVScrollHdl(pVScroll);
185 * handling for vertical Scrollbars
187 void ViewShell::VirtVScrollHdl(ScrollBar* pVScroll)
189 if(IsPageFlipMode())
191 SdPage* pPage = static_cast<DrawViewShell*>(this)->GetActualPage();
192 sal_uInt16 nCurPage = (pPage->GetPageNum() - 1) >> 1;
193 sal_uInt16 nNewPage = static_cast<sal_uInt16>(pVScroll->GetThumbPos())/256;
194 if( nCurPage != nNewPage )
195 static_cast<DrawViewShell*>(this)->SwitchPage(nNewPage);
197 else //panning mode
199 double fY = static_cast<double>(pVScroll->GetThumbPos()) / pVScroll->GetRange().Len();
201 ::sd::View* pView = GetView();
202 OutlinerView* pOLV = nullptr;
204 if (pView)
205 pOLV = pView->GetTextEditOutlinerView();
207 if (pOLV)
208 pOLV->HideCursor();
210 mpContentWindow->SetVisibleXY(-1, fY);
212 ::tools::Rectangle aVisArea = GetDocSh()->GetVisArea(ASPECT_CONTENT);
213 Point aVisAreaPos = GetActiveWindow()->PixelToLogic( Point(0,0) );
214 aVisArea.SetPos(aVisAreaPos);
215 GetDocSh()->SetVisArea(aVisArea);
217 Size aVisSizePixel = GetActiveWindow()->GetOutputSizePixel();
218 ::tools::Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( ::tools::Rectangle( Point(0,0), aVisSizePixel) );
219 VisAreaChanged(aVisAreaWin);
221 if (pView)
223 pView->VisAreaChanged(GetActiveWindow());
226 if (pOLV)
227 pOLV->ShowCursor();
229 if (mbHasRulers)
230 UpdateVRuler();
235 VclPtr<SvxRuler> ViewShell::CreateHRuler(::sd::Window* )
237 return nullptr;
240 VclPtr<SvxRuler> ViewShell::CreateVRuler(::sd::Window* )
242 return nullptr;
245 void ViewShell::UpdateHRuler()
249 void ViewShell::UpdateVRuler()
254 * Scroll a specific number of lines. Is used in the automatic scrolling
255 * (character/drag).
257 void ViewShell::ScrollLines(::tools::Long nLinesX, ::tools::Long nLinesY)
259 if ( nLinesX )
261 nLinesX *= mpHorizontalScrollBar->GetLineSize();
263 if ( nLinesY )
265 nLinesY *= mpVerticalScrollBar->GetLineSize();
268 Scroll(nLinesX, nLinesY);
271 void ViewShell::Scroll(::tools::Long nScrollX, ::tools::Long nScrollY)
273 if (nScrollX)
275 ::tools::Long nNewThumb = mpHorizontalScrollBar->GetThumbPos() + nScrollX;
276 mpHorizontalScrollBar->SetThumbPos(nNewThumb);
278 if (nScrollY)
280 ::tools::Long nNewThumb = mpVerticalScrollBar->GetThumbPos() + nScrollY;
281 mpVerticalScrollBar->SetThumbPos(nNewThumb);
283 double fX = static_cast<double>(mpHorizontalScrollBar->GetThumbPos()) /
284 mpHorizontalScrollBar->GetRange().Len();
285 double fY = static_cast<double>(mpVerticalScrollBar->GetThumbPos()) /
286 mpVerticalScrollBar->GetRange().Len();
288 GetActiveWindow()->SetVisibleXY(fX, fY);
290 ::tools::Rectangle aVisArea = GetDocSh()->GetVisArea(ASPECT_CONTENT);
291 Point aVisAreaPos = GetActiveWindow()->PixelToLogic( Point(0,0) );
292 aVisArea.SetPos(aVisAreaPos);
293 GetDocSh()->SetVisArea(aVisArea);
295 Size aVisSizePixel = GetActiveWindow()->GetOutputSizePixel();
296 ::tools::Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( ::tools::Rectangle( Point(0,0), aVisSizePixel) );
297 VisAreaChanged(aVisAreaWin);
299 ::sd::View* pView = GetView();
300 if (pView)
302 pView->VisAreaChanged(GetActiveWindow());
305 if (mbHasRulers)
307 UpdateHRuler();
308 UpdateVRuler();
313 * Set zoom factor for all split windows.
315 void ViewShell::SetZoom(::tools::Long nZoom)
317 Fraction aUIScale(nZoom, 100);
318 aUIScale *= GetDoc()->GetUIScale();
320 if (mpHorizontalRuler)
321 mpHorizontalRuler->SetZoom(aUIScale);
323 if (mpVerticalRuler)
324 mpVerticalRuler->SetZoom(aUIScale);
326 if (mpContentWindow)
328 mpContentWindow->SetZoomIntegral(nZoom);
330 // #i74769# Here is a 2nd way (besides Window::Scroll) to set the visible prt
331 // of the window. It needs - like Scroll(ScrollFlags::Children) does - also to move
332 // the child windows. I am trying InvalidateFlags::Children here which makes things better,
333 // but does not solve the problem completely. Need to ask PL.
334 mpContentWindow->Invalidate(InvalidateFlags::Children);
337 Size aVisSizePixel = GetActiveWindow()->GetOutputSizePixel();
338 ::tools::Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( ::tools::Rectangle( Point(0,0), aVisSizePixel) );
339 VisAreaChanged(aVisAreaWin);
341 ::sd::View* pView = GetView();
342 if (pView)
344 pView->VisAreaChanged(GetActiveWindow());
347 UpdateScrollBars();
350 ::tools::Long ViewShell::GetZoom() const
352 if (mpContentWindow)
354 return mpContentWindow->GetZoom();
357 return 0;
361 * Set zoom rectangle for active window. Sets all split windows to the same zoom
362 * factor.
364 void ViewShell::SetZoomRect(const ::tools::Rectangle& rZoomRect)
366 ::tools::Long nZoom = GetActiveWindow()->SetZoomRect(rZoomRect);
367 Fraction aUIScale(nZoom, 100);
368 aUIScale *= GetDoc()->GetUIScale();
370 Point aPos = GetActiveWindow()->GetWinViewPos();
372 if (mpHorizontalRuler)
373 mpHorizontalRuler->SetZoom(aUIScale);
375 if (mpVerticalRuler)
376 mpVerticalRuler->SetZoom(aUIScale);
378 if (mpContentWindow)
380 Point aNewPos = mpContentWindow->GetWinViewPos();
381 aNewPos.setX( aPos.X() );
382 aNewPos.setY( aPos.Y() );
383 mpContentWindow->SetZoomIntegral(nZoom);
384 mpContentWindow->SetWinViewPos(aNewPos);
385 mpContentWindow->UpdateMapOrigin();
387 // When tiled rendering, UpdateMapOrigin() doesn't touch the map mode.
388 if (!comphelper::LibreOfficeKit::isActive())
389 // #i74769# see above
390 mpContentWindow->Invalidate(InvalidateFlags::Children);
393 Size aVisSizePixel = GetActiveWindow()->GetOutputSizePixel();
394 ::tools::Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( ::tools::Rectangle( Point(0,0), aVisSizePixel) );
395 VisAreaChanged(aVisAreaWin);
397 ::sd::View* pView = GetView();
398 if (pView)
400 pView->VisAreaChanged(GetActiveWindow());
403 UpdateScrollBars();
407 * Initialize imaging parameters for all split windows.
409 void ViewShell::InitWindows(const Point& rViewOrigin, const Size& rViewSize,
410 const Point& rWinPos, bool bUpdate)
412 if (mpContentWindow)
414 mpContentWindow->SetViewOrigin(rViewOrigin);
415 mpContentWindow->SetViewSize(rViewSize);
416 mpContentWindow->SetWinViewPos(rWinPos);
418 if ( bUpdate )
420 mpContentWindow->UpdateMapOrigin();
421 mpContentWindow->Invalidate();
425 Size aVisSizePixel = GetActiveWindow()->GetOutputSizePixel();
426 ::tools::Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( ::tools::Rectangle( Point(0,0), aVisSizePixel) );
427 VisAreaChanged(aVisAreaWin);
429 ::sd::View* pView = GetView();
430 if (pView)
432 pView->VisAreaChanged(GetActiveWindow());
437 * Invalidate all split windows below the ?provided rectangle.
439 void ViewShell::InvalidateWindows()
441 if (mpContentWindow)
442 mpContentWindow->Invalidate();
446 * Draw a selection rectangle with the ?provided pen on all split windows.
448 void ViewShell::DrawMarkRect(const ::tools::Rectangle& rRect) const
450 if (mpContentWindow)
452 mpContentWindow->InvertTracking(rRect, ShowTrackFlags::Object | ShowTrackFlags::TrackWindow);
456 void ViewShell::SetPageSizeAndBorder(PageKind ePageKind, const Size& rNewSize,
457 ::tools::Long nLeft, ::tools::Long nRight,
458 ::tools::Long nUpper, ::tools::Long nLower, bool bScaleAll,
459 Orientation eOrientation, sal_uInt16 nPaperBin,
460 bool bBackgroundFullSize)
462 const sal_uInt16 nMasterPageCnt(GetDoc()->GetMasterSdPageCount(ePageKind));
463 const sal_uInt16 nPageCnt(GetDoc()->GetSdPageCount(ePageKind));
465 if(0 == nPageCnt && 0 == nMasterPageCnt)
467 return;
470 std::unique_ptr<SdUndoGroup> pUndoGroup;
471 SfxViewShell* pViewShell(GetViewShell());
472 if (pViewShell)
474 pUndoGroup.reset(new SdUndoGroup(GetDoc()));
475 pUndoGroup->SetComment(SdResId(STR_UNDO_CHANGE_PAGEFORMAT));
477 Broadcast (ViewShellHint(ViewShellHint::HINT_PAGE_RESIZE_START));
479 // use Model-based method at SdDrawDocument
480 GetDoc()->AdaptPageSizeForAllPages(
481 rNewSize,
482 ePageKind,
483 pUndoGroup.get(),
484 nLeft,
485 nRight,
486 nUpper,
487 nLower,
488 bScaleAll,
489 eOrientation,
490 nPaperBin,
491 bBackgroundFullSize);
493 // adjust handout page to new format of the standard page
494 if(0 != nPageCnt && ((ePageKind == PageKind::Standard) || (ePageKind == PageKind::Handout)))
496 GetDoc()->GetSdPage(0, PageKind::Handout)->CreateTitleAndLayout(true);
499 // handed over undo group to undo manager
500 if (pViewShell)
502 pViewShell->GetViewFrame()->GetObjectShell()->GetUndoManager()->AddUndoAction(std::move(pUndoGroup));
505 // calculate View-Sizes
506 SdPage* pPage(0 != nPageCnt
507 ? GetDoc()->GetSdPage(0, ePageKind)
508 : GetDoc()->GetMasterSdPage(0, ePageKind));
509 const ::tools::Long nWidth(pPage->GetSize().Width());
510 const ::tools::Long nHeight(pPage->GetSize().Height());
511 const Point aPageOrg(nWidth, nHeight / 2);
512 const Size aViewSize(nWidth * 3, nHeight * 2);
513 Point aVisAreaPos;
514 ::sd::View* pView(GetView());
515 const Point aNewOrigin(pPage->GetLeftBorder(), pPage->GetUpperBorder());
517 InitWindows(aPageOrg, aViewSize, Point(-1, -1), true);
519 if ( GetDocSh()->GetCreateMode() == SfxObjectCreateMode::EMBEDDED )
521 aVisAreaPos = GetDocSh()->GetVisArea(ASPECT_CONTENT).TopLeft();
524 if (pView)
526 pView->SetWorkArea(::tools::Rectangle(Point() - aVisAreaPos - aPageOrg, aViewSize));
529 UpdateScrollBars();
531 if (pView)
533 pView->GetSdrPageView()->SetPageOrigin(aNewOrigin);
536 if(nullptr != pViewShell)
538 pViewShell->GetViewFrame()->GetBindings().Invalidate(SID_RULER_NULL_OFFSET);
539 // zoom onto (new) page size
540 pViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_SIZE_PAGE, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
543 Broadcast(ViewShellHint(ViewShellHint::HINT_PAGE_RESIZE_END));
547 * Set zoom factor for InPlace
549 void ViewShell::SetZoomFactor(const Fraction& rZoomX, const Fraction&)
551 ::tools::Long nZoom = static_cast<::tools::Long>(static_cast<double>(rZoomX) * 100);
552 SetZoom(nZoom);
555 void ViewShell::SetActiveWindow (::sd::Window* pWin)
557 SfxViewShell* pViewShell = GetViewShell();
558 OSL_ASSERT (pViewShell!=nullptr);
560 if (pViewShell->GetWindow() != pWin)
562 // #i31551# was wrong, it may have been a problem with the repaint at that time.
563 // For transparent form controls, it is necessary to have that flag set, all apps
564 // do set it. Enabling again.
565 if (pWin)
567 pWin->EnableChildTransparentMode();
571 if (mpActiveWindow.get() != pWin)
572 mpActiveWindow = pWin;
574 // The rest of this function is not guarded anymore against calling this
575 // method with an already active window because the functions may still
576 // point to the old window when the new one has already been assigned to
577 // pWindow elsewhere.
578 ::sd::View* pView = GetView();
579 if (pView)
581 pView->SetActualWin(pWin);
583 if(HasCurrentFunction())
585 GetCurrentFunction()->SetWindow(pWin);
589 bool ViewShell::RequestHelp(const HelpEvent& rHEvt)
591 bool bReturn = false;
593 if (bool(rHEvt.GetMode()))
595 if(HasCurrentFunction())
597 bReturn = GetCurrentFunction()->RequestHelp(rHEvt);
601 return bReturn;
604 void ViewShell::SetFrameView (FrameView* pNewFrameView)
606 mpFrameView = pNewFrameView;
607 ReadFrameViewData (mpFrameView);
610 /*************************************************************************
612 |* Read FrameViews data and set actual views data
614 \************************************************************************/
616 void ViewShell::ReadFrameViewData(FrameView*)
620 /*************************************************************************
622 |* Write actual views data to FrameView
624 \************************************************************************/
626 void ViewShell::WriteFrameViewData()
630 bool ViewShell::ActivateObject(SdrOle2Obj* pObj, ::tools::Long nVerb)
632 ErrCode aErrCode = ERRCODE_NONE;
634 SfxErrorContext aEC(ERRCTX_SO_DOVERB, GetFrameWeld(), RID_SO_ERRCTX);
635 bool bAbort = false;
636 GetDocSh()->SetWaitCursor( true );
637 SfxViewShell* pViewShell = GetViewShell();
638 OSL_ASSERT (pViewShell!=nullptr);
639 bool bChangeDefaultsForChart = false;
641 uno::Reference < embed::XEmbeddedObject > xObj = pObj->GetObjRef();
642 if ( !xObj.is() )
644 // provide OLE object to empty OLE object
645 OUString aName = pObj->GetProgName();
646 OUString aObjName;
647 SvGlobalName aClass;
649 if( aName == "StarChart" || aName == "StarOrg" )
651 if( SvtModuleOptions().IsChart() )
653 aClass = SvGlobalName( SO3_SCH_CLASSID );
654 bChangeDefaultsForChart = true;
657 else if( aName == "StarCalc" )
659 if( SvtModuleOptions().IsCalc() )
660 aClass = SvGlobalName( SO3_SC_CLASSID );
662 else if( aName == "StarMath" )
664 if( SvtModuleOptions().IsMath() )
665 aClass = SvGlobalName( SO3_SM_CLASSID );
668 if ( aClass != SvGlobalName() )
669 xObj = GetDocSh()->GetEmbeddedObjectContainer().CreateEmbeddedObject( aClass.GetByteSequence(), aObjName );
671 if( !xObj.is() )
673 aName.clear();
675 // call dialog "insert OLE object"
676 GetDocSh()->SetWaitCursor( false );
677 pViewShell->GetViewFrame()->GetDispatcher()->Execute(
678 SID_INSERT_OBJECT,
679 SfxCallMode::SYNCHRON | SfxCallMode::RECORD);
680 xObj = pObj->GetObjRef();
681 GetDocSh()->SetWaitCursor( true );
683 if (!xObj.is())
685 bAbort = true;
689 if ( xObj.is() )
691 // OLE object is no longer empty
692 pObj->SetEmptyPresObj(false);
693 pObj->SetOutlinerParaObject(nullptr);
694 pObj->ClearGraphic();
696 // the empty OLE object gets a new IPObj
697 if (!aName.isEmpty())
699 pObj->SetObjRef(xObj);
700 pObj->SetName(aObjName);
701 pObj->SetPersistName(aObjName);
703 else
705 // insertion was done by the dialog
706 pObj->SetObjRef(xObj);
709 ::tools::Rectangle aRect = pObj->GetLogicRect();
711 if ( pObj->GetAspect() != embed::Aspects::MSOLE_ICON )
713 awt::Size aSz;
714 aSz.Width = aRect.GetWidth();
715 aSz.Height = aRect.GetHeight();
716 xObj->setVisualAreaSize( pObj->GetAspect(), aSz );
719 GetViewShellBase().SetVerbs( xObj->getSupportedVerbs() );
721 nVerb = embed::EmbedVerbs::MS_OLEVERB_SHOW;
723 else
725 aErrCode = ERRCODE_SFX_OLEGENERAL;
729 if( aErrCode == ERRCODE_NONE )
731 ::sd::View* pView = GetView();
733 if (pView->IsTextEdit())
735 pView->SdrEndTextEdit();
738 SfxInPlaceClient* pSdClient =
739 pViewShell->FindIPClient(pObj->GetObjRef(), GetActiveWindow());
741 if ( !pSdClient )
743 pSdClient = new Client(pObj, this, GetActiveWindow());
746 ::tools::Rectangle aRect = pObj->GetLogicRect();
749 // #i118485# center on BoundRect for activation,
750 // OLE may be sheared/rotated now
751 const ::tools::Rectangle& rBoundRect = pObj->GetCurrentBoundRect();
752 const Point aDelta(rBoundRect.Center() - aRect.Center());
753 aRect.Move(aDelta.X(), aDelta.Y());
756 Size aDrawSize = aRect.GetSize();
758 MapMode aMapMode( GetDoc()->GetScaleUnit() );
759 Size aObjAreaSize = pObj->GetOrigObjSize( &aMapMode );
760 if( pObj->IsChart() ) //charts never should be stretched see #i84323# for example
761 aObjAreaSize = aDrawSize;
763 Fraction aScaleWidth (aDrawSize.Width(), aObjAreaSize.Width() );
764 Fraction aScaleHeight(aDrawSize.Height(), aObjAreaSize.Height() );
765 aScaleWidth.ReduceInaccurate(10); // compatible to the SdrOle2Obj
766 aScaleHeight.ReduceInaccurate(10);
767 pSdClient->SetSizeScale(aScaleWidth, aScaleHeight);
769 // visible section is only changed in-place!
770 aRect.SetSize(aObjAreaSize);
771 // the object area size must be set after scaling, since it triggers the resizing
772 pSdClient->SetObjArea(aRect);
774 if( bChangeDefaultsForChart && xObj.is())
776 ChartHelper::AdaptDefaultsForChart( xObj );
779 pSdClient->DoVerb(nVerb); // if necessary, ErrCode is outputted by Sfx
780 pViewShell->GetViewFrame()->GetBindings().Invalidate(
781 SID_NAVIGATOR_STATE, true);
784 GetDocSh()->SetWaitCursor( false );
786 if (aErrCode != ERRCODE_NONE && !bAbort)
788 ErrorHandler::HandleError(* new StringErrorInfo(aErrCode, OUString() ) );
791 return aErrCode == ERRCODE_NONE;
795 * @returns enclosing rectangle of all (split-) windows.
797 const ::tools::Rectangle& ViewShell::GetAllWindowRect()
799 maAllWindowRectangle.SetPos(
800 mpContentWindow->OutputToScreenPixel(Point(0,0)));
801 return maAllWindowRectangle;
804 void ViewShell::ReadUserData()
806 // zoom onto VisArea from FrameView
807 GetViewShell()->GetViewFrame()->GetDispatcher()->Execute(SID_SIZE_VISAREA,
808 SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
811 void ViewShell::WriteUserData()
813 // writing of our data is always done in WriteFrameViewData()
814 WriteFrameViewData();
818 * Switch ruler on/off
820 void ViewShell::SetRuler(bool bRuler)
822 mbHasRulers = ( bRuler && !GetDocSh()->IsPreview() ); // no rulers on preview mode
824 if (mpHorizontalRuler)
826 if (mbHasRulers)
828 mpHorizontalRuler->Show();
830 else
832 mpHorizontalRuler->Hide();
836 if (mpVerticalRuler)
838 if (mbHasRulers)
840 mpVerticalRuler->Show();
842 else
844 mpVerticalRuler->Hide();
848 OSL_ASSERT(GetViewShell()!=nullptr);
849 if (IsMainViewShell())
850 GetViewShell()->InvalidateBorder();
853 void ViewShell::SetScrollBarsVisible(bool bVisible)
855 if (mpVerticalScrollBar)
856 mpVerticalScrollBar->Show( bVisible );
858 if (mpHorizontalScrollBar)
859 mpHorizontalScrollBar->Show( bVisible );
861 if (mpScrollBarBox)
862 mpScrollBarBox->Show(bVisible);
865 sal_Int8 ViewShell::AcceptDrop (
866 const AcceptDropEvent& rEvt,
867 DropTargetHelper& rTargetHelper,
868 ::sd::Window* /*pTargetWindow*/,
869 sal_uInt16 /*nPage*/,
870 SdrLayerID nLayer)
872 ::sd::View* pView = GetView();
873 return( pView ? pView->AcceptDrop( rEvt, rTargetHelper, nLayer ) : DND_ACTION_NONE );
876 sal_Int8 ViewShell::ExecuteDrop (
877 const ExecuteDropEvent& rEvt,
878 DropTargetHelper& /*rTargetHelper*/,
879 ::sd::Window* pTargetWindow,
880 sal_uInt16 nPage,
881 SdrLayerID nLayer)
883 ::sd::View* pView = GetView();
884 return pView ? pView->ExecuteDrop( rEvt, pTargetWindow, nPage, nLayer ) : DND_ACTION_NONE;
887 void ViewShell::WriteUserDataSequence ( css::uno::Sequence < css::beans::PropertyValue >& rSequence )
889 const sal_Int32 nIndex = rSequence.getLength();
890 rSequence.realloc( nIndex + 1 );
892 OSL_ASSERT (GetViewShell()!=nullptr);
893 // Get the view id from the view shell in the center pane. This will
894 // usually be the called view shell, but to be on the safe side we call
895 // the main view shell explicitly.
896 SfxInterfaceId nViewID (IMPRESS_FACTORY_ID);
897 if (GetViewShellBase().GetMainViewShell() != nullptr)
898 nViewID = GetViewShellBase().GetMainViewShell()->mpImpl->GetViewId();
899 rSequence[nIndex].Name = sUNO_View_ViewId;
900 rSequence[nIndex].Value <<= "view" + OUString::number( static_cast<sal_uInt16>(nViewID));
902 mpFrameView->WriteUserDataSequence( rSequence );
905 void ViewShell::ReadUserDataSequence ( const css::uno::Sequence < css::beans::PropertyValue >& rSequence )
907 mpFrameView->ReadUserDataSequence( rSequence );
910 void ViewShell::VisAreaChanged(const ::tools::Rectangle& /*rRect*/)
912 OSL_ASSERT (GetViewShell()!=nullptr);
913 GetViewShell()->VisAreaChanged();
916 void ViewShell::SetWinViewPos(const Point& rWinPos)
918 if (mpContentWindow)
920 mpContentWindow->SetWinViewPos(rWinPos);
922 mpContentWindow->UpdateMapOrigin();
923 mpContentWindow->Invalidate();
926 if (mbHasRulers)
928 UpdateHRuler();
929 UpdateVRuler();
932 UpdateScrollBars();
934 Size aVisSizePixel = GetActiveWindow()->GetOutputSizePixel();
935 ::tools::Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( ::tools::Rectangle( Point(0,0), aVisSizePixel) );
936 VisAreaChanged(aVisAreaWin);
938 ::sd::View* pView = GetView();
939 if (pView)
941 pView->VisAreaChanged(GetActiveWindow());
945 Point const & ViewShell::GetWinViewPos() const
947 return mpContentWindow->GetWinViewPos();
950 Point const & ViewShell::GetViewOrigin() const
952 return mpContentWindow->GetViewOrigin();
955 } // end of namespace sd
957 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */