cid#1607171 Data race condition
[LibreOffice.git] / sd / source / ui / view / viewshel.cxx
blob6c139827182e278f17c9606359b85684b9f6c96e
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 <framework/FrameworkHelper.hxx>
21 #include <framework/ViewShellWrapper.hxx>
22 #include <memory>
23 #include <ViewShell.hxx>
24 #include <ViewShellImplementation.hxx>
25 #include <createtableobjectbar.hxx>
27 #include <ViewShellBase.hxx>
28 #include <ShellFactory.hxx>
29 #include <DrawController.hxx>
30 #include <LayerTabBar.hxx>
31 #include <Outliner.hxx>
33 #include <sal/log.hxx>
34 #include <sfx2/viewfrm.hxx>
35 #include <sfx2/bindings.hxx>
36 #include <sfx2/dispatch.hxx>
37 #include <vcl/commandevent.hxx>
38 #include <svl/eitem.hxx>
39 #include <svx/ruler.hxx>
40 #include <svx/svxids.hrc>
41 #include <svx/fmshell.hxx>
42 #include <WindowUpdater.hxx>
43 #include <sdxfer.hxx>
45 #include <app.hrc>
47 #include <OutlineView.hxx>
48 #include <DrawViewShell.hxx>
49 #include <DrawDocShell.hxx>
50 #include <slideshow.hxx>
51 #include <drawdoc.hxx>
52 #include <sdpage.hxx>
53 #include <zoomlist.hxx>
54 #include <FrameView.hxx>
55 #include <BezierObjectBar.hxx>
56 #include <TextObjectBar.hxx>
57 #include <GraphicObjectBar.hxx>
58 #include <MediaObjectBar.hxx>
59 #include <SlideSorter.hxx>
60 #include <SlideSorterViewShell.hxx>
61 #include <ViewShellManager.hxx>
62 #include <FormShellManager.hxx>
63 #include <EventMultiplexer.hxx>
64 #include <svx/extrusionbar.hxx>
65 #include <svx/fontworkbar.hxx>
66 #include <svx/svdoutl.hxx>
67 #include <tools/svborder.hxx>
68 #include <comphelper/lok.hxx>
70 #include <svl/slstitm.hxx>
71 #include <sfx2/request.hxx>
72 #include <SpellDialogChildWindow.hxx>
73 #include <controller/SlideSorterController.hxx>
74 #include <controller/SlsPageSelector.hxx>
75 #include <controller/SlsSelectionObserver.hxx>
76 #include <view/SlideSorterView.hxx>
78 #include <basegfx/utils/zoomtools.hxx>
80 #include <Window.hxx>
81 #include <fupoor.hxx>
82 #include <futext.hxx>
84 #include <editeng/numitem.hxx>
85 #include <editeng/eeitem.hxx>
86 #include <editeng/editview.hxx>
87 #include <editeng/editeng.hxx>
88 #include <editeng/editund2.hxx>
89 #include <svl/itempool.hxx>
90 #include <svl/intitem.hxx>
91 #include <svl/poolitem.hxx>
92 #include <strings.hxx>
93 #include <sdmod.hxx>
94 #include <AccessibleDocumentViewBase.hxx>
96 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
97 #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
98 #include <com/sun/star/drawing/framework/XConfiguration.hpp>
99 #include <com/sun/star/drawing/framework/XView.hpp>
100 #include <com/sun/star/frame/XFrame.hpp>
102 using namespace ::com::sun::star;
103 using namespace ::com::sun::star::uno;
104 using namespace ::com::sun::star::presentation;
106 namespace {
108 class ViewShellObjectBarFactory
109 : public ::sd::ShellFactory<SfxShell>
111 public:
112 explicit ViewShellObjectBarFactory (::sd::ViewShell& rViewShell);
113 virtual SfxShell* CreateShell( ::sd::ShellId nId ) override;
114 virtual void ReleaseShell (SfxShell* pShell) override;
115 private:
116 ::sd::ViewShell& mrViewShell;
119 } // end of anonymous namespace
121 namespace sd {
123 /// When true, scrolling to bottom of a page switches to the next page.
124 bool ViewShell::CanPanAcrossPages() const
126 return dynamic_cast<const DrawViewShell*>(this) && mpContentWindow &&
127 mpContentWindow->GetVisibleHeight() < 1.0;
130 bool ViewShell::IsPageFlipMode() const
132 return dynamic_cast< const DrawViewShell *>( this ) != nullptr && mpContentWindow &&
133 mpContentWindow->GetVisibleHeight() >= 1.0;
136 SfxViewFrame* ViewShell::GetViewFrame() const
138 const SfxViewShell* pViewShell = GetViewShell();
139 if (pViewShell != nullptr)
141 return &pViewShell->GetViewFrame();
143 else
145 OSL_ASSERT (GetViewShell()!=nullptr);
146 return nullptr;
150 /// declare SFX-Slotmap and standard interface
152 ViewShell::ViewShell( vcl::Window* pParentWindow, ViewShellBase& rViewShellBase)
153 : SfxShell(&rViewShellBase)
154 , mpParentWindow(pParentWindow)
156 construct();
159 ViewShell::~ViewShell()
161 // Keep the content window from accessing in its destructor the
162 // WindowUpdater.
163 if (mpContentWindow)
164 suppress_fun_call_w_exception(mpContentWindow->SetViewShell(nullptr));
166 mpZoomList.reset();
168 mpLayerTabBar.disposeAndClear();
170 if (mpImpl->mpSubShellFactory)
171 GetViewShellBase().GetViewShellManager()->RemoveSubShellFactory(
172 this,mpImpl->mpSubShellFactory);
174 if (mpContentWindow)
176 SAL_INFO(
177 "sd.view",
178 "destroying mpContentWindow at " << mpContentWindow.get()
179 << " with parent " << mpContentWindow->GetParent());
180 mpContentWindow.disposeAndClear();
183 mpVerticalRuler.disposeAndClear();
184 mpHorizontalRuler.disposeAndClear();
185 mpVerticalScrollBar.disposeAndClear();
186 mpHorizontalScrollBar.disposeAndClear();
190 * common initialization part of both constructors
192 void ViewShell::construct()
194 mbHasRulers = false;
195 mpActiveWindow = nullptr;
196 mpView = nullptr;
197 mpFrameView = nullptr;
198 mpZoomList = nullptr;
199 mfLastZoomScale = 0;
200 mbStartShowWithDialog = false;
201 mnPrintedHandoutPageNum = 1;
202 mnPrintedHandoutPageCount = 0;
203 mpWindowUpdater.reset( new ::sd::WindowUpdater() );
204 mpImpl.reset(new Implementation(*this));
205 meShellType = ST_NONE;
207 OSL_ASSERT (GetViewShell()!=nullptr);
209 if (IsMainViewShell())
210 GetDocSh()->Connect (this);
212 mpZoomList.reset( new ZoomList( this ) );
214 mpContentWindow.reset(VclPtr< ::sd::Window >::Create(GetParentWindow()));
215 SetActiveWindow (mpContentWindow.get());
217 GetParentWindow()->SetBackground(Application::GetSettings().GetStyleSettings().GetFaceColor());
218 mpContentWindow->SetBackground (Wallpaper());
219 mpContentWindow->SetCenterAllowed(true);
220 mpContentWindow->SetViewShell(this);
221 mpContentWindow->SetPosSizePixel(
222 GetParentWindow()->GetPosPixel(),GetParentWindow()->GetSizePixel());
224 if ( ! GetDocSh()->IsPreview())
226 // Create scroll bars and the filler between the scroll bars.
227 mpHorizontalScrollBar.reset (VclPtr<ScrollAdaptor>::Create(GetParentWindow(), true));
228 mpHorizontalScrollBar->EnableRTL (false);
229 mpHorizontalScrollBar->SetRange(Range(0, 32000));
230 mpHorizontalScrollBar->SetScrollHdl(LINK(this, ViewShell, HScrollHdl));
232 mpVerticalScrollBar.reset (VclPtr<ScrollAdaptor>::Create(GetParentWindow(), false));
233 mpVerticalScrollBar->SetRange(Range(0, 32000));
234 mpVerticalScrollBar->SetScrollHdl(LINK(this, ViewShell, VScrollHdl));
237 SetName (u"ViewShell"_ustr);
239 GetDoc()->StartOnlineSpelling(false);
241 mpWindowUpdater->SetDocument (GetDoc());
243 // Re-initialize the spell dialog.
244 ::sd::SpellDialogChildWindow* pSpellDialog =
245 static_cast< ::sd::SpellDialogChildWindow*> (
246 GetViewFrame()->GetChildWindow (
247 ::sd::SpellDialogChildWindow::GetChildWindowId()));
248 if (pSpellDialog != nullptr)
249 pSpellDialog->InvalidateSpellDialog();
251 // Register the sub shell factory.
252 mpImpl->mpSubShellFactory = std::make_shared<ViewShellObjectBarFactory>(*this);
253 GetViewShellBase().GetViewShellManager()->AddSubShellFactory(this,mpImpl->mpSubShellFactory);
256 void ViewShell::doShow()
258 mpContentWindow->Show();
259 static_cast< vcl::Window*>(mpContentWindow.get())->Resize();
260 SAL_INFO(
261 "sd.view",
262 "content window has size " << mpContentWindow->GetSizePixel().Width()
263 << " " << mpContentWindow->GetSizePixel().Height());
265 if ( ! GetDocSh()->IsPreview())
267 // Show scroll bars
268 mpHorizontalScrollBar->Show();
270 mpVerticalScrollBar->Show();
271 maScrBarWH = Size(
272 mpVerticalScrollBar->GetSizePixel().Width(),
273 mpHorizontalScrollBar->GetSizePixel().Height());
276 GetParentWindow()->Show();
279 void ViewShell::Init (bool bIsMainViewShell)
281 mpImpl->mbIsInitialized = true;
282 SetIsMainViewShell(bIsMainViewShell);
283 if (bIsMainViewShell)
284 SetActiveWindow (mpContentWindow.get());
287 void ViewShell::Exit()
289 sd::View* pView = GetView();
290 if (pView!=nullptr && pView->IsTextEdit())
292 pView->SdrEndTextEdit();
293 pView->UnmarkAll();
296 Deactivate (true);
298 if (IsMainViewShell())
299 GetDocSh()->Disconnect(this);
301 SetIsMainViewShell(false);
305 * set focus to working window
307 void ViewShell::Activate(bool bIsMDIActivate)
309 // Do not forward to SfxShell::Activate()
311 /* According to MI, nobody is allowed to call GrabFocus, who does not
312 exactly know from which window the focus is grabbed. Since Activate()
313 is sent sometimes asynchronous, it can happen, that the wrong window
314 gets the focus. */
316 if (mpHorizontalRuler)
317 mpHorizontalRuler->SetActive();
318 if (mpVerticalRuler)
319 mpVerticalRuler->SetActive();
321 if (bIsMDIActivate)
323 // thus, the Navigator will also get a current status
324 SfxBoolItem aItem( SID_NAVIGATOR_INIT, true );
325 if (GetDispatcher() != nullptr)
327 SfxCallMode nCall = SfxCallMode::RECORD;
328 if (comphelper::LibreOfficeKit::isActive())
330 // Make sure the LOK case doesn't dispatch async events while switching views, that
331 // would lead to a loop, see SfxHintPoster::DoEvent_Impl().
332 nCall |= SfxCallMode::SYNCHRON;
334 else
336 nCall |= SfxCallMode::ASYNCHRON;
338 GetDispatcher()->ExecuteList(
339 SID_NAVIGATOR_INIT,
340 nCall,
341 { &aItem });
344 SfxViewShell* pViewShell = GetViewShell();
345 assert(pViewShell!=nullptr);
346 SfxBindings& rBindings = pViewShell->GetViewFrame().GetBindings();
347 rBindings.Invalidate( SID_3D_STATE, true );
349 rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( GetViewShellBase() ) );
350 if (xSlideShow.is() && xSlideShow->isRunning()) //IASS
352 bool bSuccess = xSlideShow->activate(GetViewShellBase());
353 assert(bSuccess && "can only return false with a PresentationViewShell"); (void)bSuccess;
356 if(HasCurrentFunction())
357 GetCurrentFunction()->Activate();
359 if(!GetDocSh()->IsUIActive())
360 UpdatePreview( GetActualPage() );
363 ReadFrameViewData( mpFrameView );
365 if (IsMainViewShell())
366 GetDocSh()->Connect(this);
369 void ViewShell::UIActivating( SfxInPlaceClient* )
371 OSL_ASSERT (GetViewShell()!=nullptr);
372 GetViewShellBase().GetToolBarManager()->ToolBarsDestroyed();
375 void ViewShell::UIDeactivated( SfxInPlaceClient* )
377 OSL_ASSERT (GetViewShell()!=nullptr);
378 GetViewShellBase().GetToolBarManager()->ToolBarsDestroyed();
379 if ( GetDrawView() )
380 GetViewShellBase().GetToolBarManager()->SelectionHasChanged(*this, *GetDrawView());
383 void ViewShell::Deactivate(bool bIsMDIActivate)
385 // remove view from a still active drag'n'drop session
386 SdTransferable* pDragTransferable = SdModule::get()->pTransferDrag;
388 if (IsMainViewShell())
389 GetDocSh()->Disconnect(this);
391 if( pDragTransferable )
392 pDragTransferable->SetView( nullptr );
394 OSL_ASSERT (GetViewShell()!=nullptr);
396 // remember view attributes of FrameView
397 WriteFrameViewData();
399 if (bIsMDIActivate)
401 rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( GetViewShellBase() ) );
402 if(xSlideShow.is() && xSlideShow->isRunning() ) //IASS
403 xSlideShow->deactivate();
405 if(HasCurrentFunction())
406 GetCurrentFunction()->Deactivate();
409 if (mpHorizontalRuler)
410 mpHorizontalRuler->SetActive(false);
411 if (mpVerticalRuler)
412 mpVerticalRuler->SetActive(false);
414 SfxShell::Deactivate(bIsMDIActivate);
417 void ViewShell::BroadcastContextForActivation(const bool bIsActivated)
419 auto getFrameworkResourceIdForShell
420 = [&]() -> uno::Reference<drawing::framework::XResourceId> const
422 DrawController* pDrawController = GetViewShellBase().GetDrawController();
423 if (!pDrawController)
424 return {};
426 Reference<::css::drawing::framework::XConfigurationController> xConfigurationController
427 = pDrawController->getConfigurationController();
428 if (!xConfigurationController.is())
429 return {};
431 Reference<::css::drawing::framework::XConfiguration> xConfiguration
432 = xConfigurationController->getCurrentConfiguration();
433 if (!xConfiguration.is())
434 return {};
436 auto aResIdsIndirect
437 = xConfiguration->getResources({}, "", drawing::framework::AnchorBindingMode_INDIRECT);
439 for (const uno::Reference<drawing::framework::XResourceId>& rResId : aResIdsIndirect)
441 auto pFrameworkHelper = framework::FrameworkHelper::Instance(GetViewShellBase());
443 uno::Reference<drawing::framework::XView> xView;
444 if (rResId->getResourceURL().match(framework::FrameworkHelper::msViewURLPrefix))
446 xView.set(xConfigurationController->getResource(rResId), UNO_QUERY);
448 if (xView.is())
450 if (auto pViewShellWrapper = dynamic_cast<framework::ViewShellWrapper*>(xView.get()))
452 if (pViewShellWrapper->GetViewShell().get() == this)
454 return rResId;
460 return {};
463 if (bIsActivated)
465 GetViewShellBase().GetEventMultiplexer()->MultiplexEvent(
466 EventMultiplexerEventId::FocusShifted, nullptr, getFrameworkResourceIdForShell());
469 if (GetDispatcher())
470 SfxShell::BroadcastContextForActivation(bIsActivated);
473 void ViewShell::Shutdown()
475 Exit ();
478 // IASS: Check if commands should be used for SlideShow
479 // This is the case when IASS is on, SlideShow is active
480 // and the SlideShow Window has the focus
481 bool ViewShell::useInputForSlideShow() const
483 rtl::Reference< SlideShow > xSlideShow(SlideShow::GetSlideShow(GetViewShellBase()));
485 if (!xSlideShow.is())
486 // no SlideShow, do not use
487 return false;
489 if (!xSlideShow->isRunning())
490 // SlideShow not running, do not use
491 return false;
493 if(!xSlideShow->IsInteractiveSlideshow())
494 // if IASS is deactivated, do what was done before when
495 // SlideSHow is running: use for SlideShow
496 return true;
498 // else, check if SlideShow Window has the focus
499 OutputDevice* pShOut(xSlideShow->getShowWindow());
500 vcl::Window* pShWin(pShOut ? pShOut->GetOwnerWindow() : nullptr);
502 // return true if we got the SlideShow Window and it has the focus
503 return nullptr != pShWin && pShWin->HasFocus();
506 bool ViewShell::KeyInput(const KeyEvent& rKEvt, ::sd::Window* pWin)
508 bool bReturn(false);
510 if(pWin)
511 SetActiveWindow(pWin);
513 // give key input first to SfxViewShell to give CTRL+Key
514 // (e.g. CTRL+SHIFT+'+', to front) priority.
515 OSL_ASSERT(GetViewShell() != nullptr);
516 bReturn = GetViewShell()->KeyInput(rKEvt);
518 if (sd::View* pView = GetView())
520 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
521 const size_t OriCount = rMarkList.GetMarkCount();
522 if(!bReturn)
524 if(useInputForSlideShow()) //IASS
526 // use for SlideShow
527 rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( GetViewShellBase() ) );
528 bReturn = xSlideShow->keyInput(rKEvt);
530 else
532 bool bConsumed = false;
533 bConsumed = pView->getSmartTags().KeyInput(rKEvt);
535 if( !bConsumed )
537 rtl::Reference< sdr::SelectionController > xSelectionController( pView->getSelectionController() );
538 if( !xSelectionController.is() || !xSelectionController->onKeyInput( rKEvt, pWin ) )
540 if(HasCurrentFunction())
541 bReturn = GetCurrentFunction()->KeyInput(rKEvt);
543 else
545 bReturn = true;
546 if (HasCurrentFunction())
548 FuText* pTextFunction = dynamic_cast<FuText*>(GetCurrentFunction().get());
549 if(pTextFunction != nullptr)
550 pTextFunction->InvalidateBindings();
556 const size_t EndCount = rMarkList.GetMarkCount();
557 // Here, oriCount or endCount must have one value=0, another value > 0, then to switch focus between Document and shape objects
558 if(bReturn && (OriCount + EndCount > 0) && (OriCount * EndCount == 0))
559 SwitchActiveViewFireFocus();
562 if(!bReturn && GetActiveWindow())
564 vcl::KeyCode aKeyCode = rKEvt.GetKeyCode();
566 if (aKeyCode.IsMod1() && aKeyCode.IsShift()
567 && aKeyCode.GetCode() == KEY_R)
569 InvalidateWindows();
570 bReturn = true;
574 return bReturn;
577 void ViewShell::MouseButtonDown(const MouseEvent& rMEvt, ::sd::Window* pWin)
579 // We have to lock tool bar updates while the mouse button is pressed in
580 // order to prevent the shape under the mouse to be moved (this happens
581 // when the number of docked tool bars changes as result of a changed
582 // selection; this changes the window size and thus the mouse position
583 // in model coordinates: with respect to model coordinates the mouse
584 // moves.)
585 OSL_ASSERT(mpImpl->mpUpdateLockForMouse.expired());
586 mpImpl->mpUpdateLockForMouse = ViewShell::Implementation::ToolBarManagerLock::Create(
587 GetViewShellBase().GetToolBarManager());
589 if ( pWin && !pWin->HasFocus() )
591 pWin->GrabFocus();
592 SetActiveWindow(pWin);
595 ::sd::View* pView = GetView();
596 if (!pView)
597 return;
599 // insert MouseEvent into E3dView
600 pView->SetMouseEvent(rMEvt);
602 bool bConsumed = false;
603 bConsumed = pView->getSmartTags().MouseButtonDown( rMEvt );
605 if( bConsumed )
606 return;
608 rtl::Reference< sdr::SelectionController > xSelectionController( pView->getSelectionController() );
609 if( !xSelectionController.is() || !xSelectionController->onMouseButtonDown( rMEvt, pWin ) )
611 if(HasCurrentFunction())
612 GetCurrentFunction()->MouseButtonDown(rMEvt);
614 else
616 if (HasCurrentFunction())
618 FuText* pTextFunction = dynamic_cast<FuText*>(GetCurrentFunction().get());
619 if (pTextFunction != nullptr)
620 pTextFunction->InvalidateBindings();
625 void ViewShell::SetCursorMm100Position(const Point& rPosition, bool bPoint, bool bClearMark)
627 if (SdrView* pSdrView = GetView())
629 rtl::Reference<sdr::SelectionController> xSelectionController(GetView()->getSelectionController());
630 if (!xSelectionController.is() || !xSelectionController->setCursorLogicPosition(rPosition, bPoint))
632 if (pSdrView->GetTextEditObject())
634 EditView& rEditView = pSdrView->GetTextEditOutlinerView()->GetEditView();
635 rEditView.SetCursorLogicPosition(rPosition, bPoint, bClearMark);
641 uno::Reference<datatransfer::XTransferable> ViewShell::GetSelectionTransferable() const
643 SdrView* pSdrView = GetView();
644 if (!pSdrView)
645 return uno::Reference<datatransfer::XTransferable>();
647 if (!pSdrView->GetTextEditObject())
648 return uno::Reference<datatransfer::XTransferable>();
650 EditView& rEditView = pSdrView->GetTextEditOutlinerView()->GetEditView();
651 return rEditView.getEditEngine().CreateTransferable(rEditView.GetSelection());
654 void ViewShell::SetGraphicMm100Position(bool bStart, const Point& rPosition)
656 if (bStart)
658 MouseEvent aClickEvent(rPosition, 1, MouseEventModifiers::SIMPLECLICK, MOUSE_LEFT);
659 MouseButtonDown(aClickEvent, mpActiveWindow);
660 MouseEvent aMoveEvent(Point(rPosition.getX(), rPosition.getY()), 0, MouseEventModifiers::SIMPLEMOVE, MOUSE_LEFT);
661 MouseMove(aMoveEvent, mpActiveWindow);
663 else
665 MouseEvent aMoveEvent(Point(rPosition.getX(), rPosition.getY()), 0, MouseEventModifiers::SIMPLEMOVE, MOUSE_LEFT);
666 MouseMove(aMoveEvent, mpActiveWindow);
667 MouseEvent aClickEvent(rPosition, 1, MouseEventModifiers::SIMPLECLICK, MOUSE_LEFT);
668 MouseButtonUp(aClickEvent, mpActiveWindow);
672 void ViewShell::MouseMove(const MouseEvent& rMEvt, ::sd::Window* pWin)
674 if (rMEvt.IsLeaveWindow())
676 if ( ! mpImpl->mpUpdateLockForMouse.expired())
678 std::shared_ptr<ViewShell::Implementation::ToolBarManagerLock> pLock(
679 mpImpl->mpUpdateLockForMouse);
680 if (pLock != nullptr)
681 pLock->Release();
685 if ( pWin )
687 SetActiveWindow(pWin);
690 // insert MouseEvent into E3dView
691 if (GetView() != nullptr)
692 GetView()->SetMouseEvent(rMEvt);
694 if(HasCurrentFunction())
696 rtl::Reference< sdr::SelectionController > xSelectionController( GetView()->getSelectionController() );
697 if( !xSelectionController.is() || !xSelectionController->onMouseMove( rMEvt, pWin ) )
699 if(HasCurrentFunction())
700 GetCurrentFunction()->MouseMove(rMEvt);
705 void ViewShell::MouseButtonUp(const MouseEvent& rMEvt, ::sd::Window* pWin)
707 if ( pWin )
708 SetActiveWindow(pWin);
710 // insert MouseEvent into E3dView
711 if (GetView() != nullptr)
712 GetView()->SetMouseEvent(rMEvt);
714 if( HasCurrentFunction())
716 rtl::Reference< sdr::SelectionController > xSelectionController( GetView()->getSelectionController() );
717 if( !xSelectionController.is() || !xSelectionController->onMouseButtonUp( rMEvt, pWin ) )
719 if(HasCurrentFunction())
720 GetCurrentFunction()->MouseButtonUp(rMEvt);
722 else
724 if (HasCurrentFunction())
726 FuText* pTextFunction = dynamic_cast<FuText*>(GetCurrentFunction().get());
727 if (pTextFunction != nullptr)
728 pTextFunction->InvalidateBindings();
733 if ( ! mpImpl->mpUpdateLockForMouse.expired())
735 std::shared_ptr<ViewShell::Implementation::ToolBarManagerLock> pLock(
736 mpImpl->mpUpdateLockForMouse);
737 if (pLock != nullptr)
738 pLock->Release();
742 void ViewShell::Command(const CommandEvent& rCEvt, ::sd::Window* pWin)
744 bool bDone = HandleScrollCommand (rCEvt, pWin);
746 if( bDone )
747 return;
749 if( rCEvt.GetCommand() == CommandEventId::InputLanguageChange )
751 //#i42732# update state of fontname if input language changes
752 GetViewFrame()->GetBindings().Invalidate( SID_ATTR_CHAR_FONT );
753 GetViewFrame()->GetBindings().Invalidate( SID_ATTR_CHAR_FONTHEIGHT );
755 else
757 bool bConsumed = false;
758 if( GetView() )
759 bConsumed = GetView()->getSmartTags().Command(rCEvt);
761 if( !bConsumed && HasCurrentFunction())
762 GetCurrentFunction()->Command(rCEvt);
766 bool ViewShell::Notify(NotifyEvent const & rNEvt, ::sd::Window* pWin)
768 // handle scroll commands when they arrived at child windows
769 bool bRet = false;
770 if( rNEvt.GetType() == NotifyEventType::COMMAND )
772 // note: dynamic_cast is not possible as GetData() returns a void*
773 CommandEvent* pCmdEvent = static_cast< CommandEvent* >(rNEvt.GetData());
774 bRet = HandleScrollCommand(*pCmdEvent, pWin);
776 return bRet;
779 bool ViewShell::HandleScrollCommand(const CommandEvent& rCEvt, ::sd::Window* pWin)
781 bool bDone = false;
783 switch( rCEvt.GetCommand() )
785 case CommandEventId::GestureSwipe:
787 if(useInputForSlideShow()) //IASS
789 // use for SlideShow
790 rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( GetViewShellBase() ) );
791 const CommandGestureSwipeData* pSwipeData = rCEvt.GetGestureSwipeData();
792 bDone = xSlideShow->swipe(*pSwipeData);
795 break;
796 case CommandEventId::GestureLongPress:
798 if(useInputForSlideShow()) //IASS
800 // use for SlideShow
801 rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( GetViewShellBase() ) );
802 const CommandGestureLongPressData* pLongPressData = rCEvt.GetLongPressData();
803 bDone = xSlideShow->longpress(*pLongPressData);
806 break;
808 case CommandEventId::Wheel:
810 Reference< XSlideShowController > xSlideShowController( SlideShow::GetSlideShowController(GetViewShellBase() ) );
811 if( xSlideShowController.is() )
813 if(useInputForSlideShow()) //IASS
815 // use for SlideShow
816 // We ignore zooming with control+mouse wheel.
817 const CommandWheelData* pData = rCEvt.GetWheelData();
818 if( pData && !pData->GetModifier() && ( pData->GetMode() == CommandWheelMode::SCROLL ) && !pData->IsHorz() )
820 ::tools::Long nDelta = pData->GetDelta();
821 if( nDelta > 0 )
822 xSlideShowController->gotoPreviousSlide();
823 else if( nDelta < 0 )
824 xSlideShowController->gotoNextEffect();
826 break;
830 [[fallthrough]];
831 case CommandEventId::StartAutoScroll:
832 case CommandEventId::AutoScroll:
834 const CommandWheelData* pData = rCEvt.GetWheelData();
836 if (pData != nullptr)
838 if (pData->IsMod1())
840 if( !GetDocSh()->IsUIActive() )
842 const sal_uInt16 nOldZoom = GetActiveWindow()->GetZoom();
843 sal_uInt16 nNewZoom;
844 Point aOldMousePos = GetActiveWindow()->PixelToLogic(rCEvt.GetMousePosPixel());
846 if( pData->GetDelta() < 0 )
847 nNewZoom = std::max<sal_uInt16>( pWin->GetMinZoom(), basegfx::zoomtools::zoomOut( nOldZoom ));
848 else
849 nNewZoom = std::min<sal_uInt16>( pWin->GetMaxZoom(), basegfx::zoomtools::zoomIn( nOldZoom ));
851 SetZoom( nNewZoom );
852 // Keep mouse at same doc point before zoom
853 Point aNewMousePos = GetActiveWindow()->PixelToLogic(rCEvt.GetMousePosPixel());
854 SetWinViewPos(GetWinViewPos() - (aNewMousePos - aOldMousePos));
856 Invalidate( SID_ATTR_ZOOM );
857 Invalidate( SID_ATTR_ZOOMSLIDER );
859 bDone = true;
862 else
864 if( mpContentWindow.get() == pWin )
866 double nScrollLines = pData->GetScrollLines();
867 if(IsPageFlipMode())
868 nScrollLines = COMMAND_WHEEL_PAGESCROLL;
869 CommandWheelData aWheelData( pData->GetDelta(),pData->GetNotchDelta(),
870 nScrollLines,pData->GetMode(),pData->GetModifier(),pData->IsHorz() );
871 CommandEvent aReWrite( rCEvt.GetMousePosPixel(),rCEvt.GetCommand(),
872 rCEvt.IsMouseEvent(),static_cast<const void *>(&aWheelData) );
873 bDone = pWin->HandleScrollCommand( aReWrite,
874 mpHorizontalScrollBar.get(),
875 mpVerticalScrollBar.get());
880 break;
882 case CommandEventId::GesturePan:
884 bDone = pWin->HandleScrollCommand(rCEvt, mpHorizontalScrollBar.get(),
885 mpVerticalScrollBar.get());
887 break;
889 case CommandEventId::GestureZoom:
891 const CommandGestureZoomData* pData = rCEvt.GetGestureZoomData();
893 if (pData->meEventType == GestureEventZoomType::Begin)
895 mfLastZoomScale = pData->mfScaleDelta;
896 bDone = true;
897 break;
900 if (pData->meEventType == GestureEventZoomType::Update)
902 double deltaBetweenEvents = (pData->mfScaleDelta - mfLastZoomScale) / mfLastZoomScale;
903 mfLastZoomScale = pData->mfScaleDelta;
905 if (!GetDocSh()->IsUIActive() && !useInputForSlideShow()) //IASS
907 const ::tools::Long nOldZoom = GetActiveWindow()->GetZoom();
908 ::tools::Long nNewZoom;
909 Point aOldMousePos = GetActiveWindow()->PixelToLogic(rCEvt.GetMousePosPixel());
911 // Accumulate fractional zoom to avoid small zoom changes from being ignored
912 mfAccumulatedZoom += deltaBetweenEvents;
913 int nZoomChangePercent = mfAccumulatedZoom * 100;
914 mfAccumulatedZoom -= nZoomChangePercent / 100.0;
916 nNewZoom = nOldZoom + nZoomChangePercent;
917 nNewZoom = std::max<::tools::Long>(pWin->GetMinZoom(), nNewZoom);
918 nNewZoom = std::min<::tools::Long>(pWin->GetMaxZoom(), nNewZoom);
920 SetZoom(nNewZoom);
922 // Keep mouse at same doc point before zoom
923 Point aNewMousePos = GetActiveWindow()->PixelToLogic(rCEvt.GetMousePosPixel());
924 SetWinViewPos(GetWinViewPos() - (aNewMousePos - aOldMousePos));
926 Invalidate(SID_ATTR_ZOOM);
927 Invalidate(SID_ATTR_ZOOMSLIDER);
931 bDone = true;
933 break;
935 default:
936 break;
939 return bDone;
942 void ViewShell::SetupRulers()
944 if(!mbHasRulers || !mpContentWindow )
945 return;
947 if( SlideShow::IsRunning(GetViewShellBase()) && !SlideShow::IsInteractiveSlideshow(&GetViewShellBase())) // IASS
948 return;
950 ::tools::Long nHRulerOfs = 0;
952 if ( !mpVerticalRuler )
954 mpVerticalRuler.reset(CreateVRuler(GetActiveWindow()));
955 if ( mpVerticalRuler )
957 nHRulerOfs = mpVerticalRuler->GetSizePixel().Width();
958 mpVerticalRuler->SetActive();
959 mpVerticalRuler->Show();
962 if ( !mpHorizontalRuler )
964 mpHorizontalRuler.reset(CreateHRuler(GetActiveWindow()));
965 if ( mpHorizontalRuler )
967 mpHorizontalRuler->SetWinPos(nHRulerOfs);
968 mpHorizontalRuler->SetActive();
969 mpHorizontalRuler->Show();
974 const SvxNumBulletItem* ViewShell::GetNumBulletItem(SfxItemSet& aNewAttr, TypedWhichId<SvxNumBulletItem>& nNumItemId)
976 const SvxNumBulletItem* pTmpItem = aNewAttr.GetItemIfSet(nNumItemId, false);
977 if(pTmpItem)
978 return pTmpItem;
980 nNumItemId = aNewAttr.GetPool()->GetWhichIDFromSlotID(SID_ATTR_NUMBERING_RULE);
981 pTmpItem = aNewAttr.GetItemIfSet(nNumItemId, false);
982 if(pTmpItem)
983 return pTmpItem;
985 bool bOutliner = false;
986 bool bTitle = false;
988 if( mpView )
990 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
991 const size_t nCount = rMarkList.GetMarkCount();
993 for(size_t nNum = 0; nNum < nCount; ++nNum)
995 SdrObject* pObj = rMarkList.GetMark(nNum)->GetMarkedSdrObj();
996 if( pObj->GetObjInventor() == SdrInventor::Default )
998 switch(pObj->GetObjIdentifier())
1000 case SdrObjKind::TitleText:
1001 bTitle = true;
1002 break;
1003 case SdrObjKind::OutlineText:
1004 bOutliner = true;
1005 break;
1006 default:
1007 break;
1013 const SvxNumBulletItem *pItem = nullptr;
1014 if(bOutliner)
1016 SfxStyleSheetBasePool* pSSPool = mpView->GetDocSh()->GetStyleSheetPool();
1017 SfxStyleSheetBase* pFirstStyleSheet = pSSPool->Find( STR_LAYOUT_OUTLINE + " 1", SfxStyleFamily::Pseudo);
1018 if( pFirstStyleSheet )
1019 pItem = pFirstStyleSheet->GetItemSet().GetItemIfSet(EE_PARA_NUMBULLET, false);
1022 if( pItem == nullptr )
1023 pItem = aNewAttr.GetPool()->GetSecondaryPool()->GetUserDefaultItem(EE_PARA_NUMBULLET);
1025 aNewAttr.Put(pItem->CloneSetWhich(EE_PARA_NUMBULLET));
1027 const SvxNumBulletItem* pBulletItem = nullptr;
1028 if(bTitle && aNewAttr.GetItemState(EE_PARA_NUMBULLET, true, &pBulletItem) == SfxItemState::SET )
1030 const SvxNumRule& rRule = pBulletItem->GetNumRule();
1031 SvxNumRule aNewRule( rRule );
1032 aNewRule.SetFeatureFlag( SvxNumRuleFlags::NO_NUMBERS );
1034 SvxNumBulletItem aNewItem( std::move(aNewRule), EE_PARA_NUMBULLET );
1035 aNewAttr.Put(aNewItem);
1038 pTmpItem = aNewAttr.GetItemIfSet(nNumItemId, false);
1040 return pTmpItem;
1043 void ViewShell::Resize()
1045 SetupRulers ();
1047 if (mpParentWindow == nullptr)
1048 return;
1050 // Make sure that the new size is not degenerate.
1051 const Size aSize (mpParentWindow->GetSizePixel());
1052 if (aSize.IsEmpty())
1053 return;
1055 // Remember the new position and size.
1056 maViewPos = Point(0,0);
1057 maViewSize = aSize;
1059 // Rearrange the UI elements to take care of the new position and size.
1060 ArrangeGUIElements ();
1061 // end of included AdjustPosSizePixel.
1063 ::sd::View* pView = GetView();
1065 if (pView)
1066 pView->VisAreaChanged(GetActiveWindow()->GetOutDev());
1069 SvBorder ViewShell::GetBorder()
1071 SvBorder aBorder;
1073 // Horizontal scrollbar.
1074 if (mpHorizontalScrollBar
1075 && mpHorizontalScrollBar->IsVisible())
1077 aBorder.Bottom() = maScrBarWH.Height();
1080 // Vertical scrollbar.
1081 if (mpVerticalScrollBar
1082 && mpVerticalScrollBar->IsVisible())
1084 aBorder.Right() = maScrBarWH.Width();
1087 // Place horizontal ruler below tab bar.
1088 if (mbHasRulers && mpContentWindow)
1090 SetupRulers();
1091 if (mpHorizontalRuler)
1092 aBorder.Top() = mpHorizontalRuler->GetSizePixel().Height();
1093 if (mpVerticalRuler)
1094 aBorder.Left() = mpVerticalRuler->GetSizePixel().Width();
1097 return aBorder;
1100 void ViewShell::ArrangeGUIElements()
1102 if (mpImpl->mbArrangeActive)
1103 return;
1104 if (maViewSize.IsEmpty())
1105 return;
1106 mpImpl->mbArrangeActive = true;
1108 // Calculate border for in-place editing.
1109 ::tools::Long nLeft = maViewPos.X();
1110 ::tools::Long nTop = maViewPos.Y();
1111 ::tools::Long nRight = maViewPos.X() + maViewSize.Width();
1112 ::tools::Long nBottom = maViewPos.Y() + maViewSize.Height();
1114 // Horizontal scrollbar.
1115 if (mpHorizontalScrollBar
1116 && mpHorizontalScrollBar->IsVisible())
1118 nBottom -= maScrBarWH.Height();
1119 if (mpLayerTabBar && mpLayerTabBar->IsVisible())
1120 nBottom -= mpLayerTabBar->GetSizePixel().Height();
1121 mpHorizontalScrollBar->SetPosSizePixel (
1122 Point(nLeft, nBottom),
1123 Size(nRight - nLeft - maScrBarWH.Width(), maScrBarWH.Height()));
1126 // Vertical scrollbar.
1127 if (mpVerticalScrollBar
1128 && mpVerticalScrollBar->IsVisible())
1130 nRight -= maScrBarWH.Width();
1131 mpVerticalScrollBar->SetPosSizePixel (
1132 Point(nRight,nTop),
1133 Size (maScrBarWH.Width(), nBottom-nTop));
1136 // Place horizontal ruler below tab bar.
1137 if (mbHasRulers && mpContentWindow)
1139 if (mpHorizontalRuler)
1141 Size aRulerSize = mpHorizontalRuler->GetSizePixel();
1142 aRulerSize.setWidth( nRight - nLeft );
1143 mpHorizontalRuler->SetPosSizePixel (
1144 Point(nLeft,nTop), aRulerSize);
1145 if (mpVerticalRuler)
1146 mpHorizontalRuler->SetBorderPos(
1147 mpVerticalRuler->GetSizePixel().Width()-1);
1148 nTop += aRulerSize.Height();
1150 if (mpVerticalRuler)
1152 Size aRulerSize = mpVerticalRuler->GetSizePixel();
1153 aRulerSize.setHeight( nBottom - nTop );
1154 mpVerticalRuler->SetPosSizePixel (
1155 Point (nLeft,nTop), aRulerSize);
1156 nLeft += aRulerSize.Width();
1160 rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( GetViewShellBase() ) );
1162 // The size of the window of the center pane is set differently from
1163 // that of the windows in the docking windows.
1164 bool bSlideShowActive = (xSlideShow.is() && xSlideShow->isRunning()) //IASS
1165 && !xSlideShow->isFullScreen() && xSlideShow->getAnimationMode() == ANIMATIONMODE_SHOW;
1166 if ( !bSlideShowActive)
1168 OSL_ASSERT (GetViewShell()!=nullptr);
1170 if (mpContentWindow)
1171 mpContentWindow->SetPosSizePixel(
1172 Point(nLeft,nTop),
1173 Size(nRight-nLeft,nBottom-nTop));
1176 // Windows in the center and rulers at the left and top side.
1177 maAllWindowRectangle = ::tools::Rectangle(
1178 maViewPos,
1179 Size(maViewSize.Width()-maScrBarWH.Width(),
1180 maViewSize.Height()-maScrBarWH.Height()));
1182 if (mpContentWindow)
1183 mpContentWindow->UpdateMapOrigin();
1185 UpdateScrollBars();
1187 mpImpl->mbArrangeActive = false;
1190 void ViewShell::SetUIUnit(FieldUnit eUnit)
1192 // Set unit at horizontal and vertical rulers.
1193 if (mpHorizontalRuler)
1194 mpHorizontalRuler->SetUnit(eUnit);
1196 if (mpVerticalRuler)
1197 mpVerticalRuler->SetUnit(eUnit);
1201 * set DefTab at horizontal rulers
1203 void ViewShell::SetDefTabHRuler( sal_uInt16 nDefTab )
1205 if (mpHorizontalRuler)
1206 mpHorizontalRuler->SetDefTabDist( nDefTab );
1209 /** Tell the FmFormShell that the view shell is closing. Give it the
1210 opportunity to prevent that.
1212 bool ViewShell::PrepareClose (bool bUI)
1214 bool bResult = true;
1216 FmFormShell* pFormShell = GetViewShellBase().GetFormShellManager()->GetFormShell();
1217 if (pFormShell != nullptr)
1218 bResult = pFormShell->PrepareClose (bUI);
1220 return bResult;
1223 void ViewShell::UpdatePreview (SdPage*)
1225 // Do nothing. After the actual preview has been removed,
1226 // OutlineViewShell::UpdatePreview() is the place where something
1227 // useful is still done.
1230 SfxUndoManager* ViewShell::ImpGetUndoManager() const
1232 const ViewShell* pMainViewShell = GetViewShellBase().GetMainViewShell().get();
1234 if( pMainViewShell == nullptr )
1235 pMainViewShell = this;
1237 ::sd::View* pView = pMainViewShell->GetView();
1239 // check for text edit our outline view
1240 if( pView )
1242 if( pMainViewShell->GetShellType() == ViewShell::ST_OUTLINE )
1244 OutlineView* pOlView = dynamic_cast< OutlineView* >( pView );
1245 if( pOlView )
1247 ::Outliner& rOutl = pOlView->GetOutliner();
1248 return &rOutl.GetUndoManager();
1251 else if( pView->IsTextEdit() )
1253 SdrOutliner* pOL = pView->GetTextEditOutliner();
1254 if( pOL )
1255 return &pOL->GetUndoManager();
1259 if( GetDocSh() )
1260 return GetDocSh()->GetUndoManager();
1262 return nullptr;
1265 void ViewShell::ImpGetUndoStrings(SfxItemSet &rSet) const
1267 SfxUndoManager* pUndoManager = ImpGetUndoManager();
1268 if(!pUndoManager)
1269 return;
1271 sal_uInt16 nCount(pUndoManager->GetUndoActionCount());
1272 if(nCount)
1274 // prepare list
1275 std::vector<OUString> aStringList;
1276 aStringList.reserve(nCount);
1277 for (sal_uInt16 a = 0; a < nCount; ++a)
1279 // generate one String in list per undo step
1280 aStringList.push_back( pUndoManager->GetUndoActionComment(a) );
1283 // set item
1284 rSet.Put(SfxStringListItem(SID_GETUNDOSTRINGS, &aStringList));
1286 else
1288 rSet.DisableItem(SID_GETUNDOSTRINGS);
1292 void ViewShell::ImpGetRedoStrings(SfxItemSet &rSet) const
1294 SfxUndoManager* pUndoManager = ImpGetUndoManager();
1295 if(!pUndoManager)
1296 return;
1298 sal_uInt16 nCount(pUndoManager->GetRedoActionCount());
1299 if(nCount)
1301 // prepare list
1302 ::std::vector< OUString > aStringList;
1303 aStringList.reserve(nCount);
1304 for(sal_uInt16 a = 0; a < nCount; a++)
1305 // generate one String in list per undo step
1306 aStringList.push_back( pUndoManager->GetRedoActionComment(a) );
1308 // set item
1309 rSet.Put(SfxStringListItem(SID_GETREDOSTRINGS, &aStringList));
1311 else
1313 rSet.DisableItem(SID_GETREDOSTRINGS);
1317 namespace {
1319 class KeepSlideSorterInSyncWithPageChanges
1321 sd::slidesorter::view::SlideSorterView::DrawLock m_aDrawLock;
1322 sd::slidesorter::controller::SlideSorterController::ModelChangeLock m_aModelLock;
1323 sd::slidesorter::controller::PageSelector::UpdateLock m_aUpdateLock;
1324 sd::slidesorter::controller::SelectionObserver::Context m_aContext;
1326 public:
1327 explicit KeepSlideSorterInSyncWithPageChanges(sd::slidesorter::SlideSorter const & rSlideSorter)
1328 : m_aDrawLock(rSlideSorter)
1329 , m_aModelLock(rSlideSorter.GetController())
1330 , m_aUpdateLock(rSlideSorter)
1331 , m_aContext(rSlideSorter)
1338 void ViewShell::ImpSidUndo(SfxRequest& rReq)
1340 //The xWatcher keeps the SlideSorter selection in sync
1341 //with the page insertions/deletions that Undo may introduce
1342 std::unique_ptr<KeepSlideSorterInSyncWithPageChanges, o3tl::default_delete<KeepSlideSorterInSyncWithPageChanges>> xWatcher;
1343 slidesorter::SlideSorterViewShell* pSlideSorterViewShell
1344 = slidesorter::SlideSorterViewShell::GetSlideSorter(GetViewShellBase());
1345 if (pSlideSorterViewShell)
1346 xWatcher.reset(new KeepSlideSorterInSyncWithPageChanges(pSlideSorterViewShell->GetSlideSorter()));
1348 SfxUndoManager* pUndoManager = ImpGetUndoManager();
1349 sal_uInt16 nNumber(1);
1350 const SfxItemSet* pReqArgs = rReq.GetArgs();
1351 bool bRepair = false;
1353 if(pReqArgs)
1355 const SfxUInt16Item* pUIntItem = static_cast<const SfxUInt16Item*>(&pReqArgs->Get(SID_UNDO));
1356 nNumber = pUIntItem->GetValue();
1358 // Repair mode: allow undo/redo of all undo actions, even if access would
1359 // be limited based on the view shell ID.
1360 if (const SfxBoolItem* pRepairItem = pReqArgs->GetItemIfSet(SID_REPAIRPACKAGE, false))
1361 bRepair = pRepairItem->GetValue();
1364 if(nNumber && pUndoManager)
1366 sal_uInt16 nCount(pUndoManager->GetUndoActionCount());
1367 if(nCount >= nNumber)
1369 if (comphelper::LibreOfficeKit::isActive() && !bRepair)
1371 // If another view created the first undo action, prevent redoing it from this view.
1372 const SfxUndoAction* pAction = pUndoManager->GetUndoAction();
1373 if (pAction->GetViewShellId() != GetViewShellBase().GetViewShellId())
1375 rReq.SetReturnValue(SfxUInt32Item(SID_UNDO, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)));
1376 return;
1382 // when UndoStack is cleared by ModifyPageUndoAction
1383 // the nCount may have changed, so test GetUndoActionCount()
1384 while (nNumber && pUndoManager->GetUndoActionCount())
1386 pUndoManager->Undo();
1387 --nNumber;
1390 catch( const Exception& )
1392 // no need to handle. By definition, the UndoManager handled this by clearing the
1393 // Undo/Redo stacks
1397 // refresh rulers, maybe UNDO was move of TAB marker in ruler
1398 if (mbHasRulers)
1399 Invalidate(SID_ATTR_TABSTOP);
1402 // This one is corresponding to the default handling
1403 // of SID_UNDO in sfx2
1404 GetViewFrame()->GetBindings().InvalidateAll(false);
1406 rReq.Done();
1409 void ViewShell::ImpSidRedo(SfxRequest& rReq)
1411 //The xWatcher keeps the SlideSorter selection in sync
1412 //with the page insertions/deletions that Undo may introduce
1413 std::unique_ptr<KeepSlideSorterInSyncWithPageChanges, o3tl::default_delete<KeepSlideSorterInSyncWithPageChanges>> xWatcher;
1414 slidesorter::SlideSorterViewShell* pSlideSorterViewShell
1415 = slidesorter::SlideSorterViewShell::GetSlideSorter(GetViewShellBase());
1416 if (pSlideSorterViewShell)
1417 xWatcher.reset(new KeepSlideSorterInSyncWithPageChanges(pSlideSorterViewShell->GetSlideSorter()));
1419 SfxUndoManager* pUndoManager = ImpGetUndoManager();
1420 sal_uInt16 nNumber(1);
1421 const SfxItemSet* pReqArgs = rReq.GetArgs();
1422 bool bRepair = false;
1424 if(pReqArgs)
1426 const SfxUInt16Item* pUIntItem = static_cast<const SfxUInt16Item*>(&pReqArgs->Get(SID_REDO));
1427 nNumber = pUIntItem->GetValue();
1428 // Repair mode: allow undo/redo of all undo actions, even if access would
1429 // be limited based on the view shell ID.
1430 if (const SfxBoolItem* pRepairItem = pReqArgs->GetItemIfSet(SID_REPAIRPACKAGE, false))
1431 bRepair = pRepairItem->GetValue();
1434 if(nNumber && pUndoManager)
1436 sal_uInt16 nCount(pUndoManager->GetRedoActionCount());
1437 if(nCount >= nNumber)
1439 if (comphelper::LibreOfficeKit::isActive() && !bRepair)
1441 // If another view created the first undo action, prevent redoing it from this view.
1442 const SfxUndoAction* pAction = pUndoManager->GetRedoAction();
1443 if (pAction->GetViewShellId() != GetViewShellBase().GetViewShellId())
1445 rReq.SetReturnValue(SfxUInt32Item(SID_REDO, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)));
1446 return;
1452 // when UndoStack is cleared by ModifyPageRedoAction
1453 // the nCount may have changed, so test GetRedoActionCount()
1454 while (nNumber && pUndoManager->GetRedoActionCount())
1456 pUndoManager->Redo();
1457 --nNumber;
1460 catch( const Exception& )
1462 // no need to handle. By definition, the UndoManager handled this by clearing the
1463 // Undo/Redo stacks
1467 // refresh rulers, maybe REDO was move of TAB marker in ruler
1468 if (mbHasRulers)
1470 Invalidate(SID_ATTR_TABSTOP);
1474 // This one is corresponding to the default handling
1475 // of SID_UNDO in sfx2
1476 GetViewFrame()->GetBindings().InvalidateAll(false);
1478 rReq.Done();
1481 void ViewShell::ExecReq( SfxRequest& rReq )
1483 sal_uInt16 nSlot = rReq.GetSlot();
1484 switch( nSlot )
1486 case SID_MAIL_SCROLLBODY_PAGEDOWN:
1488 rtl::Reference<FuPoor> xFunc( GetCurrentFunction() );
1489 if( xFunc.is() )
1490 ScrollLines( 0, -1 );
1492 rReq.Done();
1494 break;
1496 case SID_OUTPUT_QUALITY_COLOR:
1497 case SID_OUTPUT_QUALITY_GRAYSCALE:
1498 case SID_OUTPUT_QUALITY_BLACKWHITE:
1499 case SID_OUTPUT_QUALITY_CONTRAST:
1501 DrawModeFlags nMode = OUTPUT_DRAWMODE_COLOR;
1503 switch( nSlot )
1505 case SID_OUTPUT_QUALITY_COLOR: nMode = OUTPUT_DRAWMODE_COLOR; break;
1506 case SID_OUTPUT_QUALITY_GRAYSCALE: nMode = OUTPUT_DRAWMODE_GRAYSCALE; break;
1507 case SID_OUTPUT_QUALITY_BLACKWHITE: nMode = OUTPUT_DRAWMODE_BLACKWHITE; break;
1508 case SID_OUTPUT_QUALITY_CONTRAST: nMode = OUTPUT_DRAWMODE_CONTRAST; break;
1511 GetActiveWindow()->GetOutDev()->SetDrawMode( nMode );
1512 mpFrameView->SetDrawMode( nMode );
1514 GetActiveWindow()->Invalidate();
1516 Invalidate();
1517 rReq.Done();
1518 break;
1523 /** This default implementation returns only an empty reference. See derived
1524 classes for more interesting examples.
1526 css::uno::Reference<css::accessibility::XAccessible>
1527 ViewShell::CreateAccessibleDocumentView (::sd::Window* )
1529 OSL_FAIL("ViewShell::CreateAccessibleDocumentView should not be called!, perhaps Meyers, 3rd edition, Item 9:");
1531 return css::uno::Reference<css::accessibility::XAccessible> ();
1534 ::sd::WindowUpdater* ViewShell::GetWindowUpdater() const
1536 return mpWindowUpdater.get();
1539 ViewShellBase& ViewShell::GetViewShellBase() const
1541 return *static_cast<ViewShellBase*>(GetViewShell());
1544 ViewShell::ShellType ViewShell::GetShellType() const
1546 return meShellType;
1549 DrawDocShell* ViewShell::GetDocSh() const
1551 return GetViewShellBase().GetDocShell();
1554 SdDrawDocument* ViewShell::GetDoc() const
1556 return GetViewShellBase().GetDocument();
1559 ErrCode ViewShell::DoVerb(sal_Int32 /*nVerb*/)
1561 return ERRCODE_NONE;
1564 void ViewShell::SetCurrentFunction( const rtl::Reference<FuPoor>& xFunction)
1566 if( mxCurrentFunction.is() && (mxOldFunction != mxCurrentFunction) )
1567 mxCurrentFunction->Dispose();
1568 rtl::Reference<FuPoor> xDisposeAfterNewOne( mxCurrentFunction );
1569 mxCurrentFunction = xFunction;
1572 void ViewShell::SetOldFunction(const rtl::Reference<FuPoor>& xFunction)
1574 if( mxOldFunction.is() && (xFunction != mxOldFunction) && (mxCurrentFunction != mxOldFunction) )
1575 mxOldFunction->Dispose();
1577 rtl::Reference<FuPoor> xDisposeAfterNewOne( mxOldFunction );
1578 mxOldFunction = xFunction;
1581 /** this method deactivates the current function. If an old function is
1582 saved, this will become activated and current function.
1584 void ViewShell::Cancel()
1586 if(mxCurrentFunction.is() && (mxCurrentFunction != mxOldFunction ))
1588 rtl::Reference<FuPoor> xTemp( mxCurrentFunction );
1589 mxCurrentFunction.clear();
1590 xTemp->Deactivate();
1591 xTemp->Dispose();
1594 if(mxOldFunction.is())
1596 mxCurrentFunction = mxOldFunction;
1597 mxCurrentFunction->Activate();
1601 void ViewShell::DeactivateCurrentFunction( bool bPermanent /* == false */ )
1603 if( mxCurrentFunction.is() )
1605 if(bPermanent && (mxOldFunction == mxCurrentFunction))
1606 mxOldFunction.clear();
1608 mxCurrentFunction->Deactivate();
1609 if( mxCurrentFunction != mxOldFunction )
1610 mxCurrentFunction->Dispose();
1612 rtl::Reference<FuPoor> xDisposeAfterNewOne( mxCurrentFunction );
1613 mxCurrentFunction.clear();
1617 void ViewShell::DisposeFunctions()
1619 if(mxCurrentFunction.is())
1621 rtl::Reference<FuPoor> xTemp( mxCurrentFunction );
1622 mxCurrentFunction.clear();
1623 xTemp->Deactivate();
1624 xTemp->Dispose();
1627 if(mxOldFunction.is())
1629 rtl::Reference<FuPoor> xDisposeAfterNewOne( mxOldFunction );
1630 mxOldFunction->Dispose();
1631 mxOldFunction.clear();
1635 bool ViewShell::IsMainViewShell() const
1637 return mpImpl->mbIsMainViewShell;
1640 void ViewShell::SetIsMainViewShell (bool bIsMainViewShell)
1642 if (bIsMainViewShell != mpImpl->mbIsMainViewShell)
1644 mpImpl->mbIsMainViewShell = bIsMainViewShell;
1645 if (bIsMainViewShell)
1646 GetDocSh()->Connect (this);
1647 else
1648 GetDocSh()->Disconnect (this);
1652 void ViewShell::PrePaint()
1656 void ViewShell::Paint (const ::tools::Rectangle&, ::sd::Window* )
1660 void ViewShell::ShowUIControls (bool bVisible)
1662 if (mbHasRulers)
1664 if (mpHorizontalRuler)
1665 mpHorizontalRuler->Show( bVisible );
1667 if (mpVerticalRuler)
1668 mpVerticalRuler->Show( bVisible );
1671 if (mpVerticalScrollBar)
1672 mpVerticalScrollBar->Show( bVisible );
1674 if (mpHorizontalScrollBar)
1675 mpHorizontalScrollBar->Show( bVisible );
1677 if (mpContentWindow)
1678 mpContentWindow->Show( bVisible );
1681 bool ViewShell::RelocateToParentWindow (vcl::Window* pParentWindow)
1683 mpParentWindow = pParentWindow;
1685 mpParentWindow->SetBackground (Wallpaper());
1687 if (mpContentWindow)
1688 mpContentWindow->SetParent(pParentWindow);
1690 if (mpHorizontalScrollBar)
1691 mpHorizontalScrollBar->SetParent(mpParentWindow);
1692 if (mpVerticalScrollBar)
1693 mpVerticalScrollBar->SetParent(mpParentWindow);
1695 return true;
1698 void ViewShell::SwitchViewFireFocus(const css::uno::Reference< css::accessibility::XAccessible >& xAcc )
1700 if (xAcc)
1702 ::accessibility::AccessibleDocumentViewBase* pBase = static_cast< ::accessibility::AccessibleDocumentViewBase* >(xAcc.get());
1703 if (pBase)
1704 pBase->SwitchViewActivated();
1707 void ViewShell::SwitchActiveViewFireFocus()
1709 if (mpContentWindow)
1711 SwitchViewFireFocus(mpContentWindow->GetAccessible(false));
1714 // move these two methods from DrawViewShell.
1715 void ViewShell::fireSwitchCurrentPage(sal_Int32 pageIndex)
1717 GetViewShellBase().GetDrawController()->fireSwitchCurrentPage(pageIndex);
1719 void ViewShell::NotifyAccUpdate( )
1721 GetViewShellBase().GetDrawController()->NotifyAccUpdate();
1724 weld::Window* ViewShell::GetFrameWeld() const
1726 return mpActiveWindow ? mpActiveWindow->GetFrameWeld() : nullptr;
1729 sd::Window* ViewShell::GetContentWindow() const
1731 return mpContentWindow.get();
1734 } // end of namespace sd
1736 //===== ViewShellObjectBarFactory =============================================
1738 namespace {
1740 ViewShellObjectBarFactory::ViewShellObjectBarFactory (
1741 ::sd::ViewShell& rViewShell)
1742 : mrViewShell (rViewShell)
1746 SfxShell* ViewShellObjectBarFactory::CreateShell( ::sd::ShellId nId )
1748 SfxShell* pShell = nullptr;
1750 ::sd::View* pView = mrViewShell.GetView();
1751 switch (nId)
1753 case ToolbarId::Bezier_Toolbox_Sd:
1754 pShell = new ::sd::BezierObjectBar(&mrViewShell, pView);
1755 break;
1757 case ToolbarId::Draw_Text_Toolbox_Sd:
1758 pShell = new ::sd::TextObjectBar(
1759 &mrViewShell, mrViewShell.GetDoc()->GetPool(), pView);
1760 break;
1762 case ToolbarId::Draw_Graf_Toolbox:
1763 pShell = new ::sd::GraphicObjectBar(&mrViewShell, pView);
1764 break;
1766 case ToolbarId::Draw_Media_Toolbox:
1767 pShell = new ::sd::MediaObjectBar(&mrViewShell, pView);
1768 break;
1770 case ToolbarId::Draw_Table_Toolbox:
1771 pShell = ::sd::ui::table::CreateTableObjectBar( mrViewShell, pView );
1772 break;
1774 case ToolbarId::Svx_Extrusion_Bar:
1775 pShell = new svx::ExtrusionBar(
1776 &mrViewShell.GetViewShellBase());
1777 break;
1779 case ToolbarId::Svx_Fontwork_Bar:
1780 pShell = new svx::FontworkBar(
1781 &mrViewShell.GetViewShellBase());
1782 break;
1784 default:
1785 pShell = nullptr;
1786 break;
1789 return pShell;
1792 void ViewShellObjectBarFactory::ReleaseShell (SfxShell* pShell)
1794 delete pShell;
1797 } // end of anonymous namespace
1799 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */