Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/sd/source/ui/inc/DrawViewShell.hxx
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
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/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
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 .
18
 */
19
20
#pragma once
21
22
#include <memory>
23
#include "ViewShell.hxx"
24
#include "tools/AsynchronousCall.hxx"
25
#include "TabControl.hxx"
26
#include <glob.hxx>
27
#include <pres.hxx>
28
#include <unotools/caserotate.hxx>
29
#include <unotools/options.hxx>
30
#include <sddllapi.h>
31
#include <viewopt.hxx>
32
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; }
37
38
class Outliner;
39
class SdPage;
40
class SdStyleSheet;
41
class SdrExternalToolEdit;
42
class TabBar;
43
class SdrObject;
44
class SdrPageView;
45
class TransferableDataHelper;
46
class TransferableClipboardListener;
47
class AbstractSvxNameDialog;
48
class SdrLayer;
49
class SvxClipboardFormatItem;
50
struct ESelection;
51
class AbstractSvxObjectNameDialog;
52
53
namespace sd {
54
55
class DrawView;
56
class LayerTabBar;
57
class Ruler;
58
class AnnotationManager;
59
class ViewOverlayManager;
60
61
template <typename MIN_T, typename T, typename MAX_T>
62
constexpr bool CHECK_RANGE(MIN_T nMin, T nValue, MAX_T nMax)
63
0
{
64
0
    return nValue >= nMin && nValue <= nMax;
65
0
}
Unexecuted instantiation: bool sd::CHECK_RANGE<AutoLayout, AutoLayout, AutoLayout>(AutoLayout, AutoLayout, AutoLayout)
Unexecuted instantiation: bool sd::CHECK_RANGE<int, unsigned short, int>(int, unsigned short, int)
Unexecuted instantiation: bool sd::CHECK_RANGE<int, int, unsigned short>(int, int, unsigned short)
Unexecuted instantiation: bool sd::CHECK_RANGE<com::sun::star::drawing::FillStyle, com::sun::star::drawing::FillStyle, com::sun::star::drawing::FillStyle>(com::sun::star::drawing::FillStyle, com::sun::star::drawing::FillStyle, com::sun::star::drawing::FillStyle)
Unexecuted instantiation: bool sd::CHECK_RANGE<int, int, int>(int, int, int)
66
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).
72
*/
73
class SAL_DLLPUBLIC_RTTI DrawViewShell
74
    : public ViewShell,
75
      public SfxListener,
76
      public utl::ConfigurationListener
77
{
78
public:
79
    SFX_DECL_INTERFACE(SD_IF_SDDRAWVIEWSHELL)
80
81
private:
82
    /// SfxInterface initializer.
83
    static void InitInterface_Impl();
84
85
public:
86
    /** Create a new stackable shell that may take some information
87
        (e.g. the frame view) from the given previous shell.
88
        @param ePageKind
89
            This parameter gives the initial page kind that the new shell
90
            will show.
91
        @param pFrameView
92
            The frame view that makes it possible to pass information from
93
            one view shell to the next.
94
    */
95
    DrawViewShell (
96
        ViewShellBase& rViewShellBase,
97
        vcl::Window* pParentWindow,
98
        PageKind ePageKind,
99
        FrameView* pFrameView);
100
101
    virtual ~DrawViewShell() override;
102
103
    virtual void Init (bool bIsMainViewShell) override;
104
105
    virtual void Shutdown() override;
106
107
    void PrePaint() override;
108
    virtual void Paint(const ::tools::Rectangle& rRect, ::sd::Window* pWin) override;
109
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
113
        sliders.
114
    */
115
    virtual void    ArrangeGUIElements() override;
116
117
    void            HidePage();
118
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
0
    bool            IsMouseButtonDown() const { return mbMouseButtonDown; }
125
0
    bool            IsMouseSelecting() const { return mbMouseSelecting; }
126
127
    virtual void    Resize() override;
128
129
    void            ShowMousePosInfo(const ::tools::Rectangle& rRect, ::sd::Window const * pWin);
130
131
    virtual void    ChangeEditMode (EditMode eMode, bool bIsLayerModeActive);
132
133
    virtual void    SetZoom( ::tools::Long nZoom ) override;
134
    virtual void    SetZoomRect( const ::tools::Rectangle& rZoomRect ) override;
135
136
    void            InsertURLField(const OUString& rURL, const OUString& rText, const OUString& rTarget, OUString const& rAltText);
137
    void            InsertURLButton(const OUString& rURL, const OUString& rText, const OUString& rTarget,
138
                                    const Point* pPos);
139
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;
148
149
    //If we are editing a PresObjKind::Outline return the Outliner and fill rSel
150
    //with the current selection
151
    ::Outliner*     GetOutlinerForMasterPageOutlineTextObj(ESelection &rSel);
152
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>
162
    */
163
    void            GetModeSwitchingMenuState (SfxItemSet &rSet);
164
    void            GetAttrState(SfxItemSet& rSet);
165
    void            GetSnapItemState(SfxItemSet& rSet);
166
167
    void            SetPageProperties (SfxRequest& rReq);
168
    void            GetPageProperties(SfxItemSet& rSet);
169
    void            GetMarginProperties(SfxItemSet& rSet);
170
171
    void            GetState (SfxItemSet& rSet);
172
    void            Execute (SfxRequest& rReq);
173
174
    void            ExecStatusBar(SfxRequest& rReq);
175
    void            GetStatusBarState(SfxItemSet& rSet);
176
177
    void            ExecOptionsBar(SfxRequest& rReq);
178
    void            GetOptionsBarState(SfxItemSet& rSet);
179
180
    void            ExecRuler(SfxRequest& rReq);
181
    void            GetRulerState(SfxItemSet& rSet);
182
183
    void            ExecFormText(SfxRequest& rReq);
184
    void            GetFormTextState(SfxItemSet& rSet);
185
186
    void            ExecAnimationWin(SfxRequest& rReq);
187
    void            GetAnimationWinState(SfxItemSet& rSet);
188
189
    void            ExecNavigatorWin(SfxRequest& rReq);
190
    void            GetNavigatorWinState(SfxItemSet& rSet);
191
192
    void            ExecutePropPanelAttr (SfxRequest const & rReq);
193
    void            GetStatePropPanelAttr(SfxItemSet& rSet);
194
195
    void            ExecEffectWin(SfxRequest& rReq);
196
197
    void            Update3DWindow();
198
    void            AssignFrom3DWindow();
199
200
    void            ExecGallery(SfxRequest const & rReq);
201
202
    void            ExecBmpMask( SfxRequest const & rReq );
203
    void            GetBmpMaskState( SfxItemSet& rSet );
204
205
    void            ExecIMap( SfxRequest const & rReq );
206
    void            GetIMapState( SfxItemSet& rSet );
207
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);
214
215
    void            AttrExec (SfxRequest& rReq);
216
    void            AttrState (SfxItemSet& rSet);
217
218
    void            ExecGoToNextPage (SfxRequest& rReq);
219
    void            GetStateGoToNextPage (SfxItemSet& rSet);
220
221
    void            ExecGoToPreviousPage (SfxRequest& rReq);
222
    void            GetStateGoToPreviousPage (SfxItemSet& rSet);
223
224
    void            ExecGoToFirstPage (SfxRequest& rReq);
225
    void            GetStateGoToFirstPage (SfxItemSet& rSet);
226
227
    void            ExecGoToLastPage (SfxRequest& rReq);
228
    void            GetStateGoToLastPage (SfxItemSet& rSet);
229
230
    void            ExecGoToPage (SfxRequest& rReq);
231
    void            GetStateGoToPage (SfxItemSet& rSet);
232
233
    SD_DLLPUBLIC void ExecChar(SfxRequest& rReq);
234
235
    void            ExecuteAnnotation (SfxRequest const & rRequest);
236
    void            GetAnnotationState (SfxItemSet& rItemSet);
237
238
0
    AnnotationManager* getAnnotationManagerPtr() { return mpAnnotationManager.get(); }
239
240
    void            StartRulerDrag (const Ruler& rRuler, const MouseEvent& rMEvt);
241
242
    virtual bool    PrepareClose( bool bUI = true ) override;
243
244
0
    PageKind        GetPageKind() const { return mePageKind; }
245
0
    void            SetPageKind( PageKind ePageKind ) { mePageKind = ePageKind; }
246
0
    const Point&    GetMousePos() const { return maMousePos; }
247
248
0
    EditMode        GetEditMode() const { return meEditMode; }
249
0
    virtual SdPage* GetActualPage() override { return mpActualPage; }
250
251
    /// inherited from sd::ViewShell
252
    virtual SdPage* getCurrentPage() const override;
253
254
    void            ResetActualPage();
255
    void            ResetActualLayer();
256
    SD_DLLPUBLIC bool SwitchPage(sal_uInt16 nPage, bool bAllowChangeFocus = true,
257
                                 bool bUpdateScrollbars = true);
258
    bool            IsSwitchPageAllowed() const;
259
260
    /**
261
     * Mark the desired page as selected (1), deselected (0), toggle (2).
262
     * nPage refers to the page in question.
263
     */
264
    bool            SelectPage(sal_uInt16 nPage, sal_uInt16 nSelect);
265
    bool            IsSelected(sal_uInt16 nPage);
266
267
    void            GotoBookmark(std::u16string_view rBookmark);
268
    //Realize multi-selection of objects, If object is marked, the
269
    //corresponding entry is set true, else the corresponding entry is set
270
    //false.
271
    void            FreshNavigatrTree();
272
    void            MakeVisible(const ::tools::Rectangle& rRect, vcl::Window& rWin);
273
274
    virtual void    ReadFrameViewData(FrameView* pView) override;
275
    virtual void    WriteFrameViewData() override;
276
277
    virtual ErrCode DoVerb(sal_Int32 nVerb) override;
278
    virtual bool    ActivateObject(SdrOle2Obj* pObj, sal_Int32 nVerb) override;
279
280
0
    void            SetZoomOnPage( bool bZoom ) { mbZoomOnPage = bZoom; }
281
0
    bool            IsZoomOnPage() const { return mbZoomOnPage; }
282
    static void     CheckLineTo (SfxRequest& rReq);
283
    void            SetChildWindowState( SfxItemSet& rSet );
284
285
    void            UpdateIMapDlg( SdrObject* pObj );
286
287
    void            LockInput();
288
    void            UnlockInput();
289
0
    bool            IsInputLocked() const { return mnLockCount > 0; }
290
291
0
    sal_uInt16      GetCurPagePos() const { return maTabControl->GetCurPagePos(); }
292
293
    /** Show controls of the UI or hide them, depending on the given flag.
294
        Do not call this method directly.  Call the method at ViewShellBase
295
        instead.
296
    */
297
    virtual void    ShowUIControls (bool bVisible) override;
298
299
    void            ScannerEvent();
300
301
0
    bool            IsLayerModeActive() const { return mbIsLayerModeActive;}
302
303
    virtual sal_Int8    AcceptDrop( const AcceptDropEvent& rEvt, DropTargetHelper& rTargetHelper,
304
                                    ::sd::Window* pTargetWindow, sal_uInt16 nPage, SdrLayerID nLayer ) override;
305
    virtual sal_Int8    ExecuteDrop( const ExecuteDropEvent& rEvt, DropTargetHelper& rTargetHelper,
306
                                    ::sd::Window* pTargetWindow, sal_uInt16 nPage, SdrLayerID nLayer ) override;
307
308
    virtual void    WriteUserDataSequence ( css::uno::Sequence < css::beans::PropertyValue >& ) override;
309
    virtual void    ReadUserDataSequence ( const css::uno::Sequence < css::beans::PropertyValue >& ) override;
310
311
    virtual void    VisAreaChanged(const ::tools::Rectangle& rRect) override;
312
313
    /** Create an accessible object representing the specified window.
314
        @param pWindow
315
            The returned object makes the document displayed in this window
316
            accessible.
317
        @return
318
            Returns an <type>AccessibleDrawDocumentView</type> object.
319
   */
320
    virtual rtl::Reference<comphelper::OAccessible>
321
    CreateAccessibleDocumentView(::sd::Window* pWindow) override;
322
323
    /** Return the number of layers managed by the layer tab control.  This
324
        will usually differ from the number of layers managed by the layer
325
        administrator.
326
        @return
327
            The number of layers managed by the layer tab control.  The
328
            returned value is independent of whether the layer mode is
329
            currently active and the tab control is visible.
330
    */
331
    int GetTabLayerCount() const;
332
333
    /** Return the numerical id of the currently active layer as seen by the
334
        layer tab control.
335
        @return
336
            The returned id is a number between zero (inclusive) and the
337
            number of layers as returned by the
338
            <member>GetTabLayerCount</member> method (exclusive).
339
    */
340
    int GetActiveTabLayerIndex() const;
341
342
    /** Set the active layer at the layer tab control and update the control
343
        accordingly to reflect the change on screen.
344
        @param nId
345
            The id is expected to be a number between zero (inclusive) and
346
            the number of layers as returned by the
347
            <member>GetTabLayerCount</member> method (exclusive). Note that
348
            Invalid values are ignored. No exception is thrown in that case.
349
    */
350
    void SetActiveTabLayerIndex (int nId);
351
352
    /** Return a pointer to the tab control for pages.
353
    */
354
0
    TabControl& GetPageTabControl() { return *maTabControl; }
355
356
    /** Return a pointer to the tab control for layers.
357
    */
358
    SD_DLLPUBLIC LayerTabBar* GetLayerTabControl(); // export for unit test
359
360
    /** Renames the given slide using an SvxNameDialog
361
362
        @param nPageId the index of the page in the SdTabControl.
363
        @param rName the new name of the slide.
364
365
        @return false, if the new name is invalid for some reason.
366
367
        <p>Implemented in <code>drviews8.cxx</code>.</p>
368
     */
369
    bool RenameSlide( sal_uInt16 nPageId, const OUString & rName );
370
371
    /** modifies the given layer with the given values */
372
    void ModifyLayer( SdrLayer* pLayer, const OUString& rLayerName, const OUString& rLayerTitle, const OUString& rLayerDesc, bool bIsVisible, bool bIsLocked, bool bIsPrintable );
373
374
    virtual css::uno::Reference<css::drawing::XDrawSubController> CreateSubController() override;
375
376
0
    DrawView*   GetDrawView() const { return mpDrawView.get(); }
377
378
    /** Relocation to a new parent window is not supported for DrawViewShell
379
        objects so this method always returns <FALSE/>.
380
    */
381
    virtual bool RelocateToParentWindow (vcl::Window* pParentWindow) override;
382
383
    OUString const & GetSidebarContextName() const;
384
385
0
    bool IsInSwitchPage() const { return mbIsInSwitchPage; }
386
387
    const SdViewOptions& GetViewOptions() const;
388
    void SetViewOptions(const SdViewOptions& rOptions);
389
    //move this method to ViewShell.
390
    //void  NotifyAccUpdate();
391
392
    void destroyXSlideShowInstance();
393
394
protected:
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 );
399
400
    void            DeleteActualPage();
401
    void            DeleteActualLayer();
402
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;
408
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 );
411
412
    void            GetMenuStateSel(SfxItemSet& rSet);
413
414
private:
415
    DrawViewShell(const DrawViewShell&) = delete;
416
    DrawViewShell& operator=(const DrawViewShell&) = delete;
417
418
    void Construct (DrawDocShell* pDocSh, PageKind ePageKind);
419
420
    void ImplDestroy();
421
422
    /** Depending on the given request create a new page or duplicate an
423
        existing one.  See ViewShell::CreateOrDuplicatePage() for more
424
        information.
425
    */
426
    virtual SdPage* CreateOrDuplicatePage (
427
        SfxRequest& rRequest,
428
        PageKind ePageKind,
429
        SdPage* pPage,
430
        const sal_Int32 nInsertPosition = -1) override;
431
432
    void DuplicateSelectedSlides (SfxRequest& rRequest);
433
434
    virtual void Notify (SfxBroadcaster& rBC, const SfxHint& rHint) override;
435
436
    /** Stop a running slide show.
437
    */
438
    void StopSlideShow();
439
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.
444
        @param pParent
445
            The parent for the context menu.
446
        @param rRect
447
            The location at which to display the context menu.
448
        @param rPageView
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
452
            context menu.
453
    */
454
    void ShowSnapLineContextMenu(weld::Window* pParent, const ::tools::Rectangle& rRect,
455
        SdrPageView& rPageView, const sal_uInt16 nSnapLineIndex);
456
457
    using ViewShell::Notify;
458
459
    virtual void ConfigurationChanged( utl::ConfigurationBroadcaster* pCb, ConfigurationHints ) override;
460
461
    void ConfigureAppBackgroundColor( svtools::ColorConfig* pColorConfig = nullptr );
462
463
    /// return true if "Edit Hyperlink" in context menu should be disabled
464
    bool ShouldDisableEditHyperlink() const;
465
466
private:
467
    std::unique_ptr<DrawView> mpDrawView;
468
    SdPage*             mpActualPage;
469
    ::tools::Rectangle           maMarkRect;
470
    Point               maMousePos;
471
    VclPtr<TabControl>  maTabControl;
472
    EditMode            meEditMode;
473
    PageKind            mePageKind;
474
    bool                mbZoomOnPage;
475
    bool                mbIsRulerDrag;
476
    sal_uLong           mnLockCount;
477
    bool                mbReadOnly;
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
481
    */
482
    bool mbFirstTimeActivation = true;
483
    /** This flag controls whether the layer mode is active, i.e. the layer
484
        dialog is visible.
485
    */
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
489
        DrawViewShell.
490
    */
491
    ::std::unique_ptr<SvxClipboardFormatItem> mpCurrentClipboardFormats;
492
    /** On some occasions it is necessary to make SwitchPage calls
493
        asynchronously.
494
    */
495
    tools::AsynchronousCall maAsynchronousSwitchPageCall;
496
    /** This flag is used to prevent nested calls to SwitchPage().
497
    */
498
    bool mbIsInSwitchPage;
499
    RotateTransliteration m_aRotateCase;
500
    /** Listen for selection changes and broadcast context changes for the sidebar.
501
    */
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;
512
513
    css::uno::Reference<css::presentation::XSlideShow> mxSlideShow;
514
};
515
516
/// Merge the background properties together and deposit the result in rMergeAttr
517
SD_DLLPUBLIC void MergePageBackgroundFilling(SdPage *pPage, SdStyleSheet *pStyleSheet, bool bMasterPage, SfxItemSet& rMergedAttr);
518
519
} // end of namespace sd
520
521
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */