1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
23 #include "ViewShell.hxx"
24 #include "tools/AsynchronousCall.hxx"
25 #include "TabControl.hxx"
28 #include <unotools/caserotate.hxx>
29 #include <unotools/options.hxx>
31 #include <viewopt.hxx>
33 namespace svx::sidebar
{ class SelectionChangeHandler
; }
34 namespace com::sun::star::lang
{ class XEventListener
; }
35 namespace com::sun::star::scanner
{ class XScannerManager2
; }
36 namespace com::sun::star::presentation
{ class XSlideShow
; }
41 class SdrExternalToolEdit
;
45 class TransferableDataHelper
;
46 class TransferableClipboardListener
;
47 class AbstractSvxNameDialog
;
49 class SvxClipboardFormatItem
;
51 class AbstractSvxObjectNameDialog
;
58 class AnnotationManager
;
59 class ViewOverlayManager
;
61 template <typename MIN_T
, typename T
, typename MAX_T
>
62 constexpr bool CHECK_RANGE(MIN_T nMin
, T nValue
, MAX_T nMax
)
64 return nValue
>= nMin
&& nValue
<= nMax
;
67 /** Base class of the stacked shells that provide graphical views to
68 Draw and Impress documents and editing functionality. In contrast
69 to this other stacked shells are responsible for showing an
70 overview over several slides or a textual
71 overview over the text in an Impress document (OutlineViewShell).
73 class SAL_DLLPUBLIC_RTTI DrawViewShell
76 public utl::ConfigurationListener
79 SFX_DECL_INTERFACE(SD_IF_SDDRAWVIEWSHELL
)
82 /// SfxInterface initializer.
83 static void InitInterface_Impl();
86 /** Create a new stackable shell that may take some information
87 (e.g. the frame view) from the given previous shell.
89 This parameter gives the initial page kind that the new shell
92 The frame view that makes it possible to pass information from
93 one view shell to the next.
96 ViewShellBase
& rViewShellBase
,
97 vcl::Window
* pParentWindow
,
99 FrameView
* pFrameView
);
101 virtual ~DrawViewShell() override
;
103 virtual void Init (bool bIsMainViewShell
) override
;
105 virtual void Shutdown() override
;
107 void PrePaint() override
;
108 virtual void Paint(const ::tools::Rectangle
& rRect
, ::sd::Window
* pWin
) override
;
110 /** Arrange and resize the GUI elements like rulers, sliders, and
111 buttons as well as the actual document view according to the size of
112 the enclosing window and current sizes of buttons, rulers, and
115 virtual void ArrangeGUIElements() override
;
119 virtual bool KeyInput(const KeyEvent
& rKEvt
, ::sd::Window
* pWin
) override
;
120 virtual void MouseMove(const MouseEvent
& rMEvt
, ::sd::Window
* pWin
) override
;
121 virtual void MouseButtonUp(const MouseEvent
& rMEvt
, ::sd::Window
* pWin
) override
;
122 virtual void MouseButtonDown(const MouseEvent
& rMEvt
, ::sd::Window
* pWin
) override
;
123 virtual void Command(const CommandEvent
& rCEvt
, ::sd::Window
* pWin
) override
;
124 bool IsMouseButtonDown() const { return mbMouseButtonDown
; }
125 bool IsMouseSelecting() const { return mbMouseSelecting
; }
127 virtual void Resize() override
;
129 void ShowMousePosInfo(const ::tools::Rectangle
& rRect
, ::sd::Window
const * pWin
);
131 virtual void ChangeEditMode (EditMode eMode
, bool bIsLayerModeActive
);
133 virtual void SetZoom( ::tools::Long nZoom
) override
;
134 virtual void SetZoomRect( const ::tools::Rectangle
& rZoomRect
) override
;
136 void InsertURLField(const OUString
& rURL
, const OUString
& rText
, const OUString
& rTarget
);
137 void InsertURLButton(const OUString
& rURL
, const OUString
& rText
, const OUString
& rTarget
,
140 void SelectionHasChanged();
141 void ModelHasChanged();
142 virtual void Activate(bool bIsMDIActivate
) override
;
143 virtual void Deactivate(bool IsMDIActivate
) override
;
144 virtual void UIActivating( SfxInPlaceClient
* ) override
;
145 virtual void UIDeactivated( SfxInPlaceClient
* ) override
;
146 OUString
GetSelectionText( bool bCompleteWords
);
147 bool HasSelection( bool bText
) const;
149 //If we are editing a PresObjKind::Outline return the Outliner and fill rSel
150 //with the current selection
151 ::Outliner
* GetOutlinerForMasterPageOutlineTextObj(ESelection
&rSel
);
153 void ExecCtrl(SfxRequest
& rReq
);
154 void GetCtrlState(SfxItemSet
& rSet
);
155 void GetDrawAttrState(SfxItemSet
& rSet
);
156 void GetMenuState(SfxItemSet
& rSet
);
157 void GetTableMenuState(SfxItemSet
& rSet
);
158 /** Set the items of the given item set that are related to
159 switching the editing mode to the correct values.
160 <p>This function also sets the states of the mode buttons
161 (those at the upper right corner) accordingly.</p>
163 void GetModeSwitchingMenuState (SfxItemSet
&rSet
);
164 void GetAttrState(SfxItemSet
& rSet
);
165 void GetSnapItemState(SfxItemSet
& rSet
);
167 void SetPageProperties (SfxRequest
& rReq
);
168 void GetPageProperties(SfxItemSet
& rSet
);
169 void GetMarginProperties(SfxItemSet
& rSet
);
171 void GetState (SfxItemSet
& rSet
);
172 void Execute (SfxRequest
& rReq
);
174 void ExecStatusBar(SfxRequest
& rReq
);
175 void GetStatusBarState(SfxItemSet
& rSet
);
177 void ExecOptionsBar(SfxRequest
& rReq
);
178 void GetOptionsBarState(SfxItemSet
& rSet
);
180 void ExecRuler(SfxRequest
& rReq
);
181 void GetRulerState(SfxItemSet
& rSet
);
183 void ExecFormText(SfxRequest
& rReq
);
184 void GetFormTextState(SfxItemSet
& rSet
);
186 void ExecAnimationWin(SfxRequest
& rReq
);
187 void GetAnimationWinState(SfxItemSet
& rSet
);
189 void ExecNavigatorWin(SfxRequest
& rReq
);
190 void GetNavigatorWinState(SfxItemSet
& rSet
);
192 void ExecutePropPanelAttr (SfxRequest
const & rReq
);
193 void GetStatePropPanelAttr(SfxItemSet
& rSet
);
195 void ExecEffectWin(SfxRequest
& rReq
);
197 void Update3DWindow();
198 void AssignFrom3DWindow();
200 void ExecGallery(SfxRequest
const & rReq
);
202 void ExecBmpMask( SfxRequest
const & rReq
);
203 void GetBmpMaskState( SfxItemSet
& rSet
);
205 void ExecIMap( SfxRequest
const & rReq
);
206 void GetIMapState( SfxItemSet
& rSet
);
208 void FuTemporary(SfxRequest
& rReq
);
209 void FuPermanent(SfxRequest
& rReq
);
210 void FuSupport(SfxRequest
& rReq
);
211 void FuDeleteSelectedObjects();
212 void FuSupportRotate(SfxRequest
const & rReq
);
213 void FuTable(SfxRequest
& rReq
);
215 void AttrExec (SfxRequest
& rReq
);
216 void AttrState (SfxItemSet
& rSet
);
218 void ExecGoToNextPage (SfxRequest
& rReq
);
219 void GetStateGoToNextPage (SfxItemSet
& rSet
);
221 void ExecGoToPreviousPage (SfxRequest
& rReq
);
222 void GetStateGoToPreviousPage (SfxItemSet
& rSet
);
224 void ExecGoToFirstPage (SfxRequest
& rReq
);
225 void GetStateGoToFirstPage (SfxItemSet
& rSet
);
227 void ExecGoToLastPage (SfxRequest
& rReq
);
228 void GetStateGoToLastPage (SfxItemSet
& rSet
);
230 void ExecGoToPage (SfxRequest
& rReq
);
231 void GetStateGoToPage (SfxItemSet
& rSet
);
233 SD_DLLPUBLIC
void ExecChar(SfxRequest
& rReq
);
235 void ExecuteAnnotation (SfxRequest
const & rRequest
);
236 void GetAnnotationState (SfxItemSet
& rItemSet
);
238 AnnotationManager
* getAnnotationManagerPtr() { return mpAnnotationManager
.get(); }
240 void StartRulerDrag (const Ruler
& rRuler
, const MouseEvent
& rMEvt
);
242 virtual bool PrepareClose( bool bUI
= true ) override
;
244 PageKind
GetPageKind() const { return mePageKind
; }
245 void SetPageKind( PageKind ePageKind
) { mePageKind
= ePageKind
; }
246 const Point
& GetMousePos() const { return maMousePos
; }
248 EditMode
GetEditMode() const { return meEditMode
; }
249 virtual SdPage
* GetActualPage() override
{ return mpActualPage
; }
251 /// inherited from sd::ViewShell
252 virtual SdPage
* getCurrentPage() const override
;
254 void ResetActualPage();
255 void ResetActualLayer();
256 SD_DLLPUBLIC
bool SwitchPage(sal_uInt16 nPage
, bool bAllowChangeFocus
= true);
257 bool IsSwitchPageAllowed() const;
260 * Mark the desired page as selected (1), deselected (0), toggle (2).
261 * nPage refers to the page in question.
263 bool SelectPage(sal_uInt16 nPage
, sal_uInt16 nSelect
);
264 bool IsSelected(sal_uInt16 nPage
);
266 void GotoBookmark(std::u16string_view rBookmark
);
267 //Realize multi-selection of objects, If object is marked, the
268 //corresponding entry is set true, else the corresponding entry is set
270 void FreshNavigatrTree();
271 void MakeVisible(const ::tools::Rectangle
& rRect
, vcl::Window
& rWin
);
273 virtual void ReadFrameViewData(FrameView
* pView
) override
;
274 virtual void WriteFrameViewData() override
;
276 virtual ErrCode
DoVerb(sal_Int32 nVerb
) override
;
277 virtual bool ActivateObject(SdrOle2Obj
* pObj
, sal_Int32 nVerb
) override
;
279 void SetZoomOnPage( bool bZoom
) { mbZoomOnPage
= bZoom
; }
280 bool IsZoomOnPage() const { return mbZoomOnPage
; }
281 static void CheckLineTo (SfxRequest
& rReq
);
282 void SetChildWindowState( SfxItemSet
& rSet
);
284 void UpdateIMapDlg( SdrObject
* pObj
);
288 bool IsInputLocked() const { return mnLockCount
> 0; }
290 sal_uInt16
GetCurPagePos() const { return maTabControl
->GetCurPagePos(); }
292 /** Show controls of the UI or hide them, depending on the given flag.
293 Do not call this method directly. Call the method at ViewShellBase
296 virtual void ShowUIControls (bool bVisible
) override
;
300 bool IsLayerModeActive() const { return mbIsLayerModeActive
;}
302 virtual sal_Int8
AcceptDrop( const AcceptDropEvent
& rEvt
, DropTargetHelper
& rTargetHelper
,
303 ::sd::Window
* pTargetWindow
, sal_uInt16 nPage
, SdrLayerID nLayer
) override
;
304 virtual sal_Int8
ExecuteDrop( const ExecuteDropEvent
& rEvt
, DropTargetHelper
& rTargetHelper
,
305 ::sd::Window
* pTargetWindow
, sal_uInt16 nPage
, SdrLayerID nLayer
) override
;
307 virtual void WriteUserDataSequence ( css::uno::Sequence
< css::beans::PropertyValue
>& ) override
;
308 virtual void ReadUserDataSequence ( const css::uno::Sequence
< css::beans::PropertyValue
>& ) override
;
310 virtual void VisAreaChanged(const ::tools::Rectangle
& rRect
) override
;
312 /** Create an accessible object representing the specified window.
314 The returned object makes the document displayed in this window
317 Returns an <type>AccessibleDrawDocumentView</type> object.
319 virtual css::uno::Reference
<css::accessibility::XAccessible
>
320 CreateAccessibleDocumentView (::sd::Window
* pWindow
) override
;
322 /** Return the number of layers managed by the layer tab control. This
323 will usually differ from the number of layers managed by the layer
326 The number of layers managed by the layer tab control. The
327 returned value is independent of whether the layer mode is
328 currently active and the tab control is visible.
330 int GetTabLayerCount() const;
332 /** Return the numerical id of the currently active layer as seen by the
335 The returned id is a number between zero (inclusive) and the
336 number of layers as returned by the
337 <member>GetTabLayerCount</member> method (exclusive).
339 int GetActiveTabLayerIndex() const;
341 /** Set the active layer at the layer tab control and update the control
342 accordingly to reflect the change on screen.
344 The id is expected to be a number between zero (inclusive) and
345 the number of layers as returned by the
346 <member>GetTabLayerCount</member> method (exclusive). Note that
347 Invalid values are ignored. No exception is thrown in that case.
349 void SetActiveTabLayerIndex (int nId
);
351 /** Return a pointer to the tab control for pages.
353 TabControl
& GetPageTabControl() { return *maTabControl
; }
355 /** Return a pointer to the tab control for layers.
357 SD_DLLPUBLIC LayerTabBar
* GetLayerTabControl(); // export for unit test
359 /** Renames the given slide using an SvxNameDialog
361 @param nPageId the index of the page in the SdTabControl.
362 @param rName the new name of the slide.
364 @return false, if the new name is invalid for some reason.
366 <p>Implemented in <code>drviews8.cxx</code>.</p>
368 bool RenameSlide( sal_uInt16 nPageId
, const OUString
& rName
);
370 /** modifies the given layer with the given values */
371 void ModifyLayer( SdrLayer
* pLayer
, const OUString
& rLayerName
, const OUString
& rLayerTitle
, const OUString
& rLayerDesc
, bool bIsVisible
, bool bIsLocked
, bool bIsPrintable
);
373 virtual css::uno::Reference
<css::drawing::XDrawSubController
> CreateSubController() override
;
375 DrawView
* GetDrawView() const { return mpDrawView
.get(); }
377 /** Relocation to a new parent window is not supported for DrawViewShell
378 objects so this method always returns <FALSE/>.
380 virtual bool RelocateToParentWindow (vcl::Window
* pParentWindow
) override
;
382 OUString
const & GetSidebarContextName() const;
384 bool IsInSwitchPage() const { return mbIsInSwitchPage
; }
386 const SdViewOptions
& GetViewOptions() const;
387 void SetViewOptions(const SdViewOptions
& rOptions
);
388 //move this method to ViewShell.
389 //void NotifyAccUpdate();
391 const css::uno::Reference
<css::presentation::XSlideShow
> & getXSlideShowInstance();
392 void destroyXSlideShowInstance();
395 DECL_DLLPRIVATE_LINK( ClipboardChanged
, TransferableDataHelper
*, void );
396 DECL_DLLPRIVATE_LINK( TabSplitHdl
, TabBar
*, void );
397 DECL_DLLPRIVATE_LINK( NameObjectHdl
, AbstractSvxObjectNameDialog
&, bool );
398 DECL_DLLPRIVATE_LINK( RenameSlideHdl
, AbstractSvxNameDialog
&, bool );
400 void DeleteActualPage();
401 void DeleteActualLayer();
403 virtual VclPtr
<SvxRuler
> CreateHRuler(::sd::Window
* pWin
) override
;
404 virtual VclPtr
<SvxRuler
> CreateVRuler(::sd::Window
* pWin
) override
;
405 virtual void UpdateHRuler() override
;
406 virtual void UpdateVRuler() override
;
407 virtual void SetZoomFactor(const Fraction
& rZoomX
, const Fraction
& rZoomY
) override
;
409 void SetupPage( Size
const &rSize
, ::tools::Long nLeft
, ::tools::Long nRight
, ::tools::Long nUpper
, ::tools::Long nLower
,
410 bool bSize
, bool bMargin
, bool bScaleAll
);
412 void GetMenuStateSel(SfxItemSet
& rSet
);
415 DrawViewShell(const DrawViewShell
&) = delete;
416 DrawViewShell
& operator=(const DrawViewShell
&) = delete;
418 void Construct (DrawDocShell
* pDocSh
, PageKind ePageKind
);
422 /** Depending on the given request create a new page or duplicate an
423 existing one. See ViewShell::CreateOrDuplicatePage() for more
426 virtual SdPage
* CreateOrDuplicatePage (
427 SfxRequest
& rRequest
,
430 const sal_Int32 nInsertPosition
= -1) override
;
432 void DuplicateSelectedSlides (SfxRequest
& rRequest
);
434 virtual void Notify (SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
436 /** Stop a running slide show.
438 void StopSlideShow();
440 /** Show the context menu for snap lines and points. Because snap lines
441 can not be selected the index of the snap line/point for which the
442 popup menu is opened has to be passed to the processing slot
443 handlers. This can be done only by manually showing the popup menu.
445 The parent for the context menu.
447 The location at which to display the context menu.
449 The page view is used to access the help lines.
450 @param nSnapLineIndex
451 Index of the snap line or snap point for which to show the
454 void ShowSnapLineContextMenu(weld::Window
* pParent
, const ::tools::Rectangle
& rRect
,
455 SdrPageView
& rPageView
, const sal_uInt16 nSnapLineIndex
);
457 using ViewShell::Notify
;
459 virtual void ConfigurationChanged( utl::ConfigurationBroadcaster
* pCb
, ConfigurationHints
) override
;
461 void ConfigureAppBackgroundColor( svtools::ColorConfig
* pColorConfig
= nullptr );
463 /// return true if "Edit Hyperlink" in context menu should be disabled
464 bool ShouldDisableEditHyperlink() const;
467 std::unique_ptr
<DrawView
> mpDrawView
;
468 SdPage
* mpActualPage
;
469 ::tools::Rectangle maMarkRect
;
471 VclPtr
<TabControl
> maTabControl
;
476 sal_uLong mnLockCount
;
478 static bool mbPipette
;
479 /** Prevents grabbing focus while loading - see tdf#83773 that introduced
480 the grabbing, and tdf#150773 that needs grabbing disabled on loading
482 bool mbFirstTimeActivation
= true;
483 /** This flag controls whether the layer mode is active, i.e. the layer
486 bool mbIsLayerModeActive
;
487 /** This item contains the clipboard formats of the current clipboard
488 content that are supported both by that content and by the
491 ::std::unique_ptr
<SvxClipboardFormatItem
> mpCurrentClipboardFormats
;
492 /** On some occasions it is necessary to make SwitchPage calls
495 tools::AsynchronousCall maAsynchronousSwitchPageCall
;
496 /** This flag is used to prevent nested calls to SwitchPage().
498 bool mbIsInSwitchPage
;
499 RotateTransliteration m_aRotateCase
;
500 /** Listen for selection changes and broadcast context changes for the sidebar.
502 ::rtl::Reference
<svx::sidebar::SelectionChangeHandler
> mpSelectionChangeHandler
;
503 css::uno::Reference
< css::scanner::XScannerManager2
> mxScannerManager
;
504 css::uno::Reference
< css::lang::XEventListener
> mxScannerListener
;
505 rtl::Reference
<TransferableClipboardListener
> mxClipEvtLstnr
;
506 bool mbPastePossible
;
507 bool mbMouseButtonDown
;
508 bool mbMouseSelecting
;
509 std::unique_ptr
<AnnotationManager
> mpAnnotationManager
;
510 std::unique_ptr
<ViewOverlayManager
> mpViewOverlayManager
;
511 std::vector
<std::unique_ptr
<SdrExternalToolEdit
>> m_ExternalEdits
;
513 css::uno::Reference
<css::presentation::XSlideShow
> mxSlideShow
;
516 /// Merge the background properties together and deposit the result in rMergeAttr
517 void MergePageBackgroundFilling(SdPage
*pPage
, SdStyleSheet
*pStyleSheet
, bool bMasterPage
, SfxItemSet
& rMergedAttr
);
519 } // end of namespace sd
521 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */