android: Update app-specific/MIME type icons
[LibreOffice.git] / sd / source / ui / view / viewshe2.cxx
blobfd4d2649b4fd9a6e2d996fd6239360e1211984e6
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 <svx/svdpagv.hxx>
31 #include <sfx2/dispatch.hxx>
32 #include <svx/ruler.hxx>
33 #include <editeng/outliner.hxx>
34 #include <svtools/ehdl.hxx>
35 #include <svx/svdoole2.hxx>
36 #include <svtools/sfxecode.hxx>
37 #include <unotools/moduleoptions.hxx>
38 #include <comphelper/classids.hxx>
39 #include <osl/diagnose.h>
41 #include <strings.hrc>
42 #include <app.hrc>
43 #include <unokywds.hxx>
45 #include <sdundogr.hxx>
46 #include <FrameView.hxx>
47 #include <sdresid.hxx>
48 #include <drawdoc.hxx>
49 #include <View.hxx>
50 #include <fupoor.hxx>
51 #include <Client.hxx>
52 #include <DrawDocShell.hxx>
53 #include <sdpage.hxx>
54 #include <DrawViewShell.hxx>
55 #include <ViewShellBase.hxx>
57 #include <Window.hxx>
59 #include <sfx2/viewfrm.hxx>
60 #include <svtools/soerr.hxx>
61 #include <svx/charthelper.hxx>
62 #include <comphelper/lok.hxx>
64 using namespace com::sun::star;
66 namespace sd {
68 /**
69 * adjust Thumbpos and VisibleSize
71 void ViewShell::UpdateScrollBars()
73 if (mpHorizontalScrollBar)
75 ::tools::Long nW = static_cast<::tools::Long>(mpContentWindow->GetVisibleWidth() * 32000);
76 ::tools::Long nX = static_cast<::tools::Long>(mpContentWindow->GetVisibleX() * 32000);
77 mpHorizontalScrollBar->SetVisibleSize(nW);
78 mpHorizontalScrollBar->SetThumbPos(nX);
79 nW = 32000 - nW;
80 ::tools::Long nLine = static_cast<::tools::Long>(mpContentWindow->GetScrlLineWidth() * nW);
81 ::tools::Long nPage = static_cast<::tools::Long>(mpContentWindow->GetScrlPageWidth() * nW);
82 mpHorizontalScrollBar->SetLineSize(nLine);
83 mpHorizontalScrollBar->SetPageSize(nPage);
86 if (mpVerticalScrollBar)
88 ::tools::Long nH = static_cast<::tools::Long>(mpContentWindow->GetVisibleHeight() * 32000);
89 ::tools::Long nY = static_cast<::tools::Long>(mpContentWindow->GetVisibleY() * 32000);
91 if(IsPageFlipMode()) // ie in zoom mode where no panning
93 SdPage* pPage = static_cast<DrawViewShell*>(this)->GetActualPage();
94 sal_uInt16 nCurPage = (pPage->GetPageNum() - 1) / 2;
95 sal_uInt16 nTotalPages = GetDoc()->GetSdPageCount(pPage->GetPageKind());
96 mpVerticalScrollBar->SetRange(Range(0,256*nTotalPages));
97 mpVerticalScrollBar->SetVisibleSize(256);
98 mpVerticalScrollBar->SetThumbPos(256*nCurPage);
99 mpVerticalScrollBar->SetLineSize(256);
100 mpVerticalScrollBar->SetPageSize(256);
102 else
104 mpVerticalScrollBar->SetRange(Range(0,32000));
105 mpVerticalScrollBar->SetVisibleSize(nH);
106 mpVerticalScrollBar->SetThumbPos(nY);
107 nH = 32000 - nH;
108 ::tools::Long nLine = static_cast<::tools::Long>(mpContentWindow->GetScrlLineHeight() * nH);
109 ::tools::Long nPage = static_cast<::tools::Long>(mpContentWindow->GetScrlPageHeight() * nH);
110 mpVerticalScrollBar->SetLineSize(nLine);
111 mpVerticalScrollBar->SetPageSize(nPage);
115 if (mbHasRulers)
117 UpdateHRuler();
118 UpdateVRuler();
123 * Handling for horizontal Scrollbars
125 IMPL_LINK_NOARG(ViewShell, HScrollHdl, weld::Scrollbar&, void)
127 VirtHScrollHdl(mpHorizontalScrollBar);
131 * virtual scroll handler for horizontal Scrollbars
133 void ViewShell::VirtHScrollHdl(ScrollAdaptor* pHScroll)
135 double fX = static_cast<double>(pHScroll->GetThumbPos()) / pHScroll->GetRange().Len();
137 // scroll all windows of the column
138 ::sd::View* pView = GetView();
139 OutlinerView* pOLV = nullptr;
141 if (pView)
142 pOLV = pView->GetTextEditOutlinerView();
144 if (pOLV)
145 pOLV->HideCursor();
147 mpContentWindow->SetVisibleXY(fX, -1);
149 ::tools::Rectangle aVisArea = GetDocSh()->GetVisArea(ASPECT_CONTENT);
150 Point aVisAreaPos = GetActiveWindow()->PixelToLogic( Point(0,0) );
151 aVisArea.SetPos(aVisAreaPos);
152 GetDocSh()->SetVisArea(aVisArea);
154 Size aVisSizePixel = GetActiveWindow()->GetOutputSizePixel();
155 ::tools::Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( ::tools::Rectangle( Point(0,0), aVisSizePixel) );
156 VisAreaChanged(aVisAreaWin);
158 if (pView)
160 pView->VisAreaChanged(GetActiveWindow()->GetOutDev());
163 if (pOLV)
164 pOLV->ShowCursor();
166 if (mbHasRulers)
167 UpdateHRuler();
171 * handling for vertical Scrollbars
173 IMPL_LINK_NOARG(ViewShell, VScrollHdl, weld::Scrollbar&, void)
175 VirtVScrollHdl(mpVerticalScrollBar);
179 * handling for vertical Scrollbars
181 void ViewShell::VirtVScrollHdl(ScrollAdaptor* pVScroll)
183 if(IsPageFlipMode())
185 SdPage* pPage = static_cast<DrawViewShell*>(this)->GetActualPage();
186 sal_uInt16 nCurPage = (pPage->GetPageNum() - 1) >> 1;
187 sal_uInt16 nNewPage = static_cast<sal_uInt16>(pVScroll->GetThumbPos())/256;
188 if( nCurPage != nNewPage )
189 static_cast<DrawViewShell*>(this)->SwitchPage(nNewPage);
191 else //panning mode
193 double fY = static_cast<double>(pVScroll->GetThumbPos()) / pVScroll->GetRange().Len();
195 ::sd::View* pView = GetView();
196 OutlinerView* pOLV = nullptr;
198 if (pView)
199 pOLV = pView->GetTextEditOutlinerView();
201 if (pOLV)
202 pOLV->HideCursor();
204 mpContentWindow->SetVisibleXY(-1, fY);
206 ::tools::Rectangle aVisArea = GetDocSh()->GetVisArea(ASPECT_CONTENT);
207 Point aVisAreaPos = GetActiveWindow()->PixelToLogic( Point(0,0) );
208 aVisArea.SetPos(aVisAreaPos);
209 GetDocSh()->SetVisArea(aVisArea);
211 Size aVisSizePixel = GetActiveWindow()->GetOutputSizePixel();
212 ::tools::Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( ::tools::Rectangle( Point(0,0), aVisSizePixel) );
213 VisAreaChanged(aVisAreaWin);
215 if (pView)
217 pView->VisAreaChanged(GetActiveWindow()->GetOutDev());
220 if (pOLV)
221 pOLV->ShowCursor();
223 if (mbHasRulers)
224 UpdateVRuler();
229 VclPtr<SvxRuler> ViewShell::CreateHRuler(::sd::Window* )
231 return nullptr;
234 VclPtr<SvxRuler> ViewShell::CreateVRuler(::sd::Window* )
236 return nullptr;
239 void ViewShell::UpdateHRuler()
243 void ViewShell::UpdateVRuler()
248 * Scroll a specific number of lines. Is used in the automatic scrolling
249 * (character/drag).
251 void ViewShell::ScrollLines(::tools::Long nLinesX, ::tools::Long nLinesY)
253 if ( nLinesX )
255 nLinesX *= mpHorizontalScrollBar->GetLineSize();
257 if ( nLinesY )
259 nLinesY *= mpVerticalScrollBar->GetLineSize();
262 Scroll(nLinesX, nLinesY);
265 void ViewShell::Scroll(::tools::Long nScrollX, ::tools::Long nScrollY)
267 if (nScrollX)
269 ::tools::Long nNewThumb = mpHorizontalScrollBar->GetThumbPos() + nScrollX;
270 mpHorizontalScrollBar->SetThumbPos(nNewThumb);
272 if (nScrollY)
274 ::tools::Long nNewThumb = mpVerticalScrollBar->GetThumbPos() + nScrollY;
275 mpVerticalScrollBar->SetThumbPos(nNewThumb);
277 double fX = static_cast<double>(mpHorizontalScrollBar->GetThumbPos()) /
278 mpHorizontalScrollBar->GetRange().Len();
279 double fY = static_cast<double>(mpVerticalScrollBar->GetThumbPos()) /
280 mpVerticalScrollBar->GetRange().Len();
282 GetActiveWindow()->SetVisibleXY(fX, fY);
284 ::tools::Rectangle aVisArea = GetDocSh()->GetVisArea(ASPECT_CONTENT);
285 Point aVisAreaPos = GetActiveWindow()->PixelToLogic( Point(0,0) );
286 aVisArea.SetPos(aVisAreaPos);
287 GetDocSh()->SetVisArea(aVisArea);
289 Size aVisSizePixel = GetActiveWindow()->GetOutputSizePixel();
290 ::tools::Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( ::tools::Rectangle( Point(0,0), aVisSizePixel) );
291 VisAreaChanged(aVisAreaWin);
293 ::sd::View* pView = GetView();
294 if (pView)
296 pView->VisAreaChanged(GetActiveWindow()->GetOutDev());
299 if (mbHasRulers)
301 UpdateHRuler();
302 UpdateVRuler();
307 * Set zoom factor for all split windows.
309 void ViewShell::SetZoom(::tools::Long nZoom)
311 Fraction aUIScale(nZoom, 100);
312 aUIScale *= GetDoc()->GetUIScale();
314 if (mpHorizontalRuler)
315 mpHorizontalRuler->SetZoom(aUIScale);
317 if (mpVerticalRuler)
318 mpVerticalRuler->SetZoom(aUIScale);
320 if (mpContentWindow)
322 mpContentWindow->SetZoomIntegral(nZoom);
324 // #i74769# Here is a 2nd way (besides Window::Scroll) to set the visible prt
325 // of the window. It needs - like Scroll(ScrollFlags::Children) does - also to move
326 // the child windows. I am trying InvalidateFlags::Children here which makes things better,
327 // but does not solve the problem completely. Need to ask PL.
328 mpContentWindow->Invalidate(InvalidateFlags::Children);
331 Size aVisSizePixel = GetActiveWindow()->GetOutputSizePixel();
332 ::tools::Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( ::tools::Rectangle( Point(0,0), aVisSizePixel) );
333 VisAreaChanged(aVisAreaWin);
335 ::sd::View* pView = GetView();
336 if (pView)
338 pView->VisAreaChanged(GetActiveWindow()->GetOutDev());
341 UpdateScrollBars();
344 ::tools::Long ViewShell::GetZoom() const
346 if (mpContentWindow)
348 return mpContentWindow->GetZoom();
351 return 0;
355 * Set zoom rectangle for active window. Sets all split windows to the same zoom
356 * factor.
358 void ViewShell::SetZoomRect(const ::tools::Rectangle& rZoomRect)
360 ::tools::Long nZoom = GetActiveWindow()->SetZoomRect(rZoomRect);
361 Fraction aUIScale(nZoom, 100);
362 aUIScale *= GetDoc()->GetUIScale();
364 Point aPos = GetActiveWindow()->GetWinViewPos();
366 if (mpHorizontalRuler)
367 mpHorizontalRuler->SetZoom(aUIScale);
369 if (mpVerticalRuler)
370 mpVerticalRuler->SetZoom(aUIScale);
372 if (mpContentWindow)
374 Point aNewPos = mpContentWindow->GetWinViewPos();
375 aNewPos.setX( aPos.X() );
376 aNewPos.setY( aPos.Y() );
377 mpContentWindow->SetZoomIntegral(nZoom);
378 mpContentWindow->SetWinViewPos(aNewPos);
379 mpContentWindow->UpdateMapOrigin();
381 // When tiled rendering, UpdateMapOrigin() doesn't touch the map mode.
382 if (!comphelper::LibreOfficeKit::isActive())
383 // #i74769# see above
384 mpContentWindow->Invalidate(InvalidateFlags::Children);
387 Size aVisSizePixel = GetActiveWindow()->GetOutputSizePixel();
388 ::tools::Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( ::tools::Rectangle( Point(0,0), aVisSizePixel) );
389 VisAreaChanged(aVisAreaWin);
391 ::sd::View* pView = GetView();
392 if (pView)
394 pView->VisAreaChanged(GetActiveWindow()->GetOutDev());
397 UpdateScrollBars();
401 * Initialize imaging parameters for all split windows.
403 void ViewShell::InitWindows(const Point& rViewOrigin, const Size& rViewSize,
404 const Point& rWinPos, bool bUpdate)
406 if (mpContentWindow)
408 mpContentWindow->SetViewOrigin(rViewOrigin);
409 mpContentWindow->SetViewSize(rViewSize);
410 mpContentWindow->SetWinViewPos(rWinPos);
412 if ( bUpdate )
414 mpContentWindow->UpdateMapOrigin();
415 mpContentWindow->Invalidate();
419 Size aVisSizePixel = GetActiveWindow()->GetOutputSizePixel();
420 ::tools::Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( ::tools::Rectangle( Point(0,0), aVisSizePixel) );
421 VisAreaChanged(aVisAreaWin);
423 ::sd::View* pView = GetView();
424 if (pView)
426 pView->VisAreaChanged(GetActiveWindow()->GetOutDev());
431 * Invalidate all split windows below the ?provided rectangle.
433 void ViewShell::InvalidateWindows()
435 if (mpContentWindow)
436 mpContentWindow->Invalidate();
440 * Draw a selection rectangle with the ?provided pen on all split windows.
442 void ViewShell::DrawMarkRect(const ::tools::Rectangle& rRect) const
444 if (mpContentWindow)
446 mpContentWindow->InvertTracking(rRect, ShowTrackFlags::Object | ShowTrackFlags::TrackWindow);
450 void ViewShell::SetPageSizeAndBorder(PageKind ePageKind, const Size& rNewSize,
451 ::tools::Long nLeft, ::tools::Long nRight,
452 ::tools::Long nUpper, ::tools::Long nLower, bool bScaleAll,
453 Orientation eOrientation, sal_uInt16 nPaperBin,
454 bool bBackgroundFullSize)
456 const sal_uInt16 nMasterPageCnt(GetDoc()->GetMasterSdPageCount(ePageKind));
457 const sal_uInt16 nPageCnt(GetDoc()->GetSdPageCount(ePageKind));
459 if(0 == nPageCnt && 0 == nMasterPageCnt)
461 return;
464 std::unique_ptr<SdUndoGroup> pUndoGroup;
465 SfxViewShell* pViewShell(GetViewShell());
466 if (pViewShell)
468 pUndoGroup.reset(new SdUndoGroup(GetDoc()));
469 pUndoGroup->SetComment(SdResId(STR_UNDO_CHANGE_PAGEFORMAT));
471 Broadcast (ViewShellHint(ViewShellHint::HINT_PAGE_RESIZE_START));
473 // use Model-based method at SdDrawDocument
474 GetDoc()->AdaptPageSizeForAllPages(
475 rNewSize,
476 ePageKind,
477 pUndoGroup.get(),
478 nLeft,
479 nRight,
480 nUpper,
481 nLower,
482 bScaleAll,
483 eOrientation,
484 nPaperBin,
485 bBackgroundFullSize);
487 // adjust handout page to new format of the standard page
488 if(0 != nPageCnt && ((ePageKind == PageKind::Standard) || (ePageKind == PageKind::Handout)))
490 GetDoc()->GetSdPage(0, PageKind::Handout)->CreateTitleAndLayout(true);
493 // handed over undo group to undo manager
494 if (pViewShell)
496 pViewShell->GetViewFrame().GetObjectShell()->GetUndoManager()->AddUndoAction(std::move(pUndoGroup));
499 // calculate View-Sizes
500 SdPage* pPage(0 != nPageCnt
501 ? GetDoc()->GetSdPage(0, ePageKind)
502 : GetDoc()->GetMasterSdPage(0, ePageKind));
503 const ::tools::Long nWidth(pPage->GetSize().Width());
504 const ::tools::Long nHeight(pPage->GetSize().Height());
505 const Point aPageOrg(nWidth, nHeight / 2);
506 const Size aViewSize(nWidth * 3, nHeight * 2);
507 Point aVisAreaPos;
508 ::sd::View* pView(GetView());
509 const Point aNewOrigin(pPage->GetLeftBorder(), pPage->GetUpperBorder());
511 InitWindows(aPageOrg, aViewSize, Point(-1, -1), true);
513 if ( GetDocSh()->GetCreateMode() == SfxObjectCreateMode::EMBEDDED )
515 aVisAreaPos = GetDocSh()->GetVisArea(ASPECT_CONTENT).TopLeft();
518 if (pView)
520 pView->SetWorkArea(::tools::Rectangle(Point() - aVisAreaPos - aPageOrg, aViewSize));
523 UpdateScrollBars();
525 if (pView)
527 pView->GetSdrPageView()->SetPageOrigin(aNewOrigin);
530 if(nullptr != pViewShell)
532 pViewShell->GetViewFrame().GetBindings().Invalidate(SID_RULER_NULL_OFFSET);
533 // zoom onto (new) page size
534 pViewShell->GetViewFrame().GetDispatcher()->Execute(SID_SIZE_PAGE, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
537 Broadcast(ViewShellHint(ViewShellHint::HINT_PAGE_RESIZE_END));
541 * Set zoom factor for InPlace
543 void ViewShell::SetZoomFactor(const Fraction& rZoomX, const Fraction&)
545 ::tools::Long nZoom = static_cast<::tools::Long>(static_cast<double>(rZoomX) * 100);
546 SetZoom(nZoom);
549 void ViewShell::SetActiveWindow (::sd::Window* pWin)
551 SfxViewShell* pViewShell = GetViewShell();
552 OSL_ASSERT (pViewShell!=nullptr);
554 if (pViewShell->GetWindow() != pWin)
556 // #i31551# was wrong, it may have been a problem with the repaint at that time.
557 // For transparent form controls, it is necessary to have that flag set, all apps
558 // do set it. Enabling again.
559 if (pWin)
561 pWin->EnableChildTransparentMode();
565 if (mpActiveWindow.get() != pWin)
566 mpActiveWindow = pWin;
568 // The rest of this function is not guarded anymore against calling this
569 // method with an already active window because the functions may still
570 // point to the old window when the new one has already been assigned to
571 // pWindow elsewhere.
572 ::sd::View* pView = GetView();
573 if (pView)
575 pView->SetActualWin(pWin->GetOutDev());
577 if(HasCurrentFunction())
579 GetCurrentFunction()->SetWindow(pWin);
583 bool ViewShell::RequestHelp(const HelpEvent& rHEvt)
585 bool bReturn = false;
587 if (bool(rHEvt.GetMode()))
589 if(HasCurrentFunction())
591 bReturn = GetCurrentFunction()->RequestHelp(rHEvt);
595 return bReturn;
598 void ViewShell::SetFrameView (FrameView* pNewFrameView)
600 mpFrameView = pNewFrameView;
601 ReadFrameViewData (mpFrameView);
604 /*************************************************************************
606 |* Read FrameViews data and set actual views data
608 \************************************************************************/
610 void ViewShell::ReadFrameViewData(FrameView*)
614 /*************************************************************************
616 |* Write actual views data to FrameView
618 \************************************************************************/
620 void ViewShell::WriteFrameViewData()
624 bool ViewShell::ActivateObject(SdrOle2Obj* pObj, sal_Int32 nVerb)
626 ErrCode aErrCode = ERRCODE_NONE;
628 SfxErrorContext aEC(ERRCTX_SO_DOVERB, GetFrameWeld(), RID_SO_ERRCTX);
629 bool bAbort = false;
630 GetDocSh()->SetWaitCursor( true );
631 SfxViewShell* pViewShell = GetViewShell();
632 OSL_ASSERT (pViewShell!=nullptr);
633 bool bChangeDefaultsForChart = false;
635 uno::Reference < embed::XEmbeddedObject > xObj = pObj->GetObjRef();
636 if ( !xObj.is() )
638 // provide OLE object to empty OLE object
639 OUString aName = pObj->GetProgName();
640 OUString aObjName;
641 SvGlobalName aClass;
643 if( aName == "StarChart" || aName == "StarOrg" )
645 if( SvtModuleOptions().IsChart() )
647 aClass = SvGlobalName( SO3_SCH_CLASSID );
648 bChangeDefaultsForChart = true;
651 else if( aName == "StarCalc" )
653 if( SvtModuleOptions().IsCalc() )
654 aClass = SvGlobalName( SO3_SC_CLASSID );
656 else if( aName == "StarMath" )
658 if( SvtModuleOptions().IsMath() )
659 aClass = SvGlobalName( SO3_SM_CLASSID );
662 if ( aClass != SvGlobalName() )
663 xObj = GetDocSh()->GetEmbeddedObjectContainer().CreateEmbeddedObject( aClass.GetByteSequence(), aObjName );
665 if( !xObj.is() )
667 aName.clear();
669 // call dialog "insert OLE object"
670 GetDocSh()->SetWaitCursor( false );
671 pViewShell->GetViewFrame().GetDispatcher()->Execute(
672 SID_INSERT_OBJECT,
673 SfxCallMode::SYNCHRON | SfxCallMode::RECORD);
674 xObj = pObj->GetObjRef();
675 GetDocSh()->SetWaitCursor( true );
677 if (!xObj.is())
679 bAbort = true;
683 if ( xObj.is() )
685 // OLE object is no longer empty
686 pObj->SetEmptyPresObj(false);
687 pObj->SetOutlinerParaObject(std::nullopt);
688 pObj->ClearGraphic();
690 // the empty OLE object gets a new IPObj
691 if (!aName.isEmpty())
693 pObj->SetObjRef(xObj);
694 pObj->SetName(aObjName);
695 pObj->SetPersistName(aObjName);
697 else
699 // insertion was done by the dialog
700 pObj->SetObjRef(xObj);
703 ::tools::Rectangle aRect = pObj->GetLogicRect();
705 if ( pObj->GetAspect() != embed::Aspects::MSOLE_ICON )
707 awt::Size aSz;
708 aSz.Width = aRect.GetWidth();
709 aSz.Height = aRect.GetHeight();
710 xObj->setVisualAreaSize( pObj->GetAspect(), aSz );
713 GetViewShellBase().SetVerbs( xObj->getSupportedVerbs() );
715 nVerb = embed::EmbedVerbs::MS_OLEVERB_SHOW;
717 else
719 aErrCode = ERRCODE_SFX_OLEGENERAL;
723 if( aErrCode == ERRCODE_NONE )
725 ::sd::View* pView = GetView();
727 if (pView->IsTextEdit())
729 pView->SdrEndTextEdit();
732 SfxInPlaceClient* pSdClient =
733 pViewShell->FindIPClient(pObj->GetObjRef(), GetActiveWindow());
735 if ( !pSdClient )
737 pSdClient = new Client(pObj, this, GetActiveWindow());
740 ::tools::Rectangle aRect = pObj->GetLogicRect();
743 // #i118485# center on BoundRect for activation,
744 // OLE may be sheared/rotated now
745 const ::tools::Rectangle& rBoundRect = pObj->GetCurrentBoundRect();
746 const Point aDelta(rBoundRect.Center() - aRect.Center());
747 aRect.Move(aDelta.X(), aDelta.Y());
750 Size aDrawSize = aRect.GetSize();
752 MapMode aMapMode( GetDoc()->GetScaleUnit() );
753 Size aObjAreaSize = pObj->GetOrigObjSize( &aMapMode );
754 if( pObj->IsChart() ) //charts never should be stretched see #i84323# for example
755 aObjAreaSize = aDrawSize;
757 Fraction aScaleWidth (aDrawSize.Width(), aObjAreaSize.Width() );
758 Fraction aScaleHeight(aDrawSize.Height(), aObjAreaSize.Height() );
759 aScaleWidth.ReduceInaccurate(10); // compatible to the SdrOle2Obj
760 aScaleHeight.ReduceInaccurate(10);
761 pSdClient->SetSizeScale(aScaleWidth, aScaleHeight);
763 // visible section is only changed in-place!
764 aRect.SetSize(aObjAreaSize);
765 // the object area size must be set after scaling, since it triggers the resizing
766 pSdClient->SetObjArea(aRect);
768 if( bChangeDefaultsForChart && xObj.is())
770 ChartHelper::AdaptDefaultsForChart( xObj );
773 pSdClient->DoVerb(nVerb); // if necessary, ErrCode is outputted by Sfx
774 pViewShell->GetViewFrame().GetBindings().Invalidate(
775 SID_NAVIGATOR_STATE, true);
778 GetDocSh()->SetWaitCursor( false );
780 if (aErrCode != ERRCODE_NONE && !bAbort)
782 ErrorHandler::HandleError(* new StringErrorInfo(aErrCode, OUString() ) );
785 return aErrCode == ERRCODE_NONE;
789 * @returns enclosing rectangle of all (split-) windows.
791 const ::tools::Rectangle& ViewShell::GetAllWindowRect()
793 maAllWindowRectangle.SetPos(
794 mpContentWindow->OutputToScreenPixel(Point(0,0)));
795 return maAllWindowRectangle;
798 void ViewShell::ReadUserData()
800 // zoom onto VisArea from FrameView
801 GetViewShell()->GetViewFrame().GetDispatcher()->Execute(SID_SIZE_VISAREA,
802 SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
805 void ViewShell::WriteUserData()
807 // writing of our data is always done in WriteFrameViewData()
808 WriteFrameViewData();
812 * Switch ruler on/off
814 void ViewShell::SetRuler(bool bRuler)
816 mbHasRulers = ( bRuler && !GetDocSh()->IsPreview() ); // no rulers on preview mode
818 if (mpHorizontalRuler)
820 if (mbHasRulers)
822 mpHorizontalRuler->Show();
824 else
826 mpHorizontalRuler->Hide();
830 if (mpVerticalRuler)
832 if (mbHasRulers)
834 mpVerticalRuler->Show();
836 else
838 mpVerticalRuler->Hide();
842 OSL_ASSERT(GetViewShell()!=nullptr);
843 if (IsMainViewShell())
844 GetViewShell()->InvalidateBorder();
847 void ViewShell::SetScrollBarsVisible(bool bVisible)
849 if (mpVerticalScrollBar)
850 mpVerticalScrollBar->Show( bVisible );
852 if (mpHorizontalScrollBar)
853 mpHorizontalScrollBar->Show( bVisible );
856 sal_Int8 ViewShell::AcceptDrop (
857 const AcceptDropEvent& rEvt,
858 DropTargetHelper& rTargetHelper,
859 ::sd::Window* /*pTargetWindow*/,
860 sal_uInt16 /*nPage*/,
861 SdrLayerID nLayer)
863 ::sd::View* pView = GetView();
864 return( pView ? pView->AcceptDrop( rEvt, rTargetHelper, nLayer ) : DND_ACTION_NONE );
867 sal_Int8 ViewShell::ExecuteDrop (
868 const ExecuteDropEvent& rEvt,
869 DropTargetHelper& /*rTargetHelper*/,
870 ::sd::Window* pTargetWindow,
871 sal_uInt16 nPage,
872 SdrLayerID nLayer)
874 ::sd::View* pView = GetView();
875 return pView ? pView->ExecuteDrop( rEvt, pTargetWindow, nPage, nLayer ) : DND_ACTION_NONE;
878 void ViewShell::WriteUserDataSequence ( css::uno::Sequence < css::beans::PropertyValue >& rSequence )
880 const sal_Int32 nIndex = rSequence.getLength();
881 rSequence.realloc( nIndex + 1 );
882 auto pSequence = rSequence.getArray();
884 OSL_ASSERT (GetViewShell()!=nullptr);
885 // Get the view id from the view shell in the center pane. This will
886 // usually be the called view shell, but to be on the safe side we call
887 // the main view shell explicitly.
888 SfxInterfaceId nViewID (IMPRESS_FACTORY_ID);
889 if (GetViewShellBase().GetMainViewShell() != nullptr)
890 nViewID = GetViewShellBase().GetMainViewShell()->mpImpl->GetViewId();
891 pSequence[nIndex].Name = sUNO_View_ViewId;
892 pSequence[nIndex].Value <<= "view" + OUString::number( static_cast<sal_uInt16>(nViewID));
894 mpFrameView->WriteUserDataSequence( rSequence );
897 void ViewShell::ReadUserDataSequence ( const css::uno::Sequence < css::beans::PropertyValue >& rSequence )
899 mpFrameView->ReadUserDataSequence( rSequence );
902 void ViewShell::VisAreaChanged(const ::tools::Rectangle& /*rRect*/)
904 OSL_ASSERT (GetViewShell()!=nullptr);
905 GetViewShell()->VisAreaChanged();
908 void ViewShell::SetWinViewPos(const Point& rWinPos)
910 if (mpContentWindow)
912 mpContentWindow->SetWinViewPos(rWinPos);
914 mpContentWindow->UpdateMapOrigin();
915 mpContentWindow->Invalidate();
918 if (mbHasRulers)
920 UpdateHRuler();
921 UpdateVRuler();
924 UpdateScrollBars();
926 Size aVisSizePixel = GetActiveWindow()->GetOutputSizePixel();
927 ::tools::Rectangle aVisAreaWin = GetActiveWindow()->PixelToLogic( ::tools::Rectangle( Point(0,0), aVisSizePixel) );
928 VisAreaChanged(aVisAreaWin);
930 ::sd::View* pView = GetView();
931 if (pView)
933 pView->VisAreaChanged(GetActiveWindow()->GetOutDev());
937 Point const & ViewShell::GetWinViewPos() const
939 return mpContentWindow->GetWinViewPos();
942 Point const & ViewShell::GetViewOrigin() const
944 return mpContentWindow->GetViewOrigin();
947 } // end of namespace sd
949 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */