Coverage Report

Created: 2026-11-06 11:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sd/source/ui/inc/Window.hxx
Line
Count
Source
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 <tools/gen.hxx>
23
#include <tools/long.hxx>
24
#include <vcl/DocWindow.hxx>
25
#include <vcl/transfer.hxx>
26
27
class OutlinerView;
28
29
namespace sd
30
{
31
class ViewShell;
32
33
/** An SdWindow contains the actual working area of ViewShell.
34
35
    <p>The zoom factor used by this class controls how much the page and the
36
    shapes on it are scaled down (<100%) or up (>100%) when displayed on the
37
    output device represented by the <type>OutputDevice</type>base class.  A
38
    zoom factor of 100% would result (with a correctly set DPI value for an
39
    output device) in a one to one mapping of the internal coordinates that
40
    are stored in 100th of mm.  The zoom factor is stored in the map mode
41
    member of the <type>OutputDevice</type> base class.  It is calculated to
42
    be an integer percent value.
43
*/
44
class Window : public vcl::DocWindow, public ::DropTargetHelper
45
{
46
public:
47
    Window(vcl::Window* pParent);
48
    virtual ~Window() override;
49
    virtual void dispose() override;
50
51
    void SetViewShell(ViewShell* pViewSh);
52
    ViewShell* GetViewShell();
53
54
    /** Set the zoom factor to the specified value and center the display
55
        area around the zoom center.
56
        @param nZoom
57
            The zoom factor is given as integral percent value.
58
    */
59
    void SetZoomIntegral(::tools::Long nZoom);
60
61
    /** This internally used method performs the actual adaptation of the
62
        window's map mode to the specified zoom factor.
63
        @param nZoom
64
            The zoom factor is given as integral percent value.
65
        @return
66
            When the given zoom factor lies outside the valid range enclosed
67
            by the minimal zoom factor previously calculated by
68
            <member>CalcMinZoom</member> and a constant upper value it is
69
            forced into that interval.  Therefore the returned value is a
70
            valid zoom factor.
71
    */
72
    ::tools::Long SetZoomFactor(::tools::Long nZoom);
73
74
    /** This method is called when the whole page shall be displayed in the
75
        window.  Position and zoom factor are set so that the given
76
        rectangle is displayed as large as possible in the window while at
77
        the same time maintaining the rectangle's aspect ratio and adding a
78
        small space at all its four sides (about 3% of width and height).
79
        The map mode is adapted accordingly.
80
        @param rZoomRect
81
            The rectangle is expected to be given relative to the upper left
82
            corner of the window in logical coordinates (100th of mm).
83
        @return
84
            The new zoom factor is returned as integral percent value.
85
    */
86
    ::tools::Long SetZoomRect(const ::tools::Rectangle& rZoomRect);
87
88
    ::tools::Long GetZoomForRect(const ::tools::Rectangle& rZoomRect);
89
90
    void SetMinZoomAutoCalc(bool bAuto);
91
92
    /** Calculate the minimal zoom factor as the value at which the
93
        application area would completely fill the window.  All values set
94
        manually or programmatically are set to this value if they are
95
        smaller.  If the currently used zoom factor is smaller than the minimal zoom
96
        factor than set the minimal zoom factor as the new current zoom
97
        factor.
98
99
        <p>This calculation is performed only when the
100
        <member>bMinZoomAutoCalc</member> is set (to <TRUE/>).</p>
101
    */
102
    void CalcMinZoom();
103
    void SetMinZoom(::tools::Long nMin);
104
0
    ::tools::Long GetMinZoom() const { return mnMinZoom; }
105
    void SetMaxZoom(::tools::Long nMax);
106
0
    ::tools::Long GetMaxZoom() const { return mnMaxZoom; }
107
108
    ::tools::Long GetZoom() const;
109
110
0
    const Point& GetWinViewPos() const { return maWinPos; }
111
0
    const Point& GetViewOrigin() const { return maViewOrigin; }
112
0
    const Size& GetViewSize() const { return maViewSize; }
113
    void SetWinViewPos(const Point& rPnt);
114
    void SetViewOrigin(const Point& rPnt);
115
    void SetViewSize(const Size& rSize);
116
    void SetCenterAllowed(bool bIsAllowed);
117
118
    /** Calculate origin of the map mode according to the size of the view
119
        and window (its size in model coordinates; that takes the zoom
120
        factor into account), and the bCenterAllowed flag.  When it is not
121
        set then nothing is changed.  When in any direction the window is
122
        larger than the view or the value of aWinPos in this direction is -1
123
        then the window is centered in this direction.
124
        */
125
    void UpdateMapOrigin(bool bInvalidate = true);
126
127
    void UpdateMapMode();
128
129
    double GetVisibleX() const; // interface for ScrollBars
130
    double GetVisibleY() const;
131
    void SetVisibleXY(double fX, double fY);
132
    double GetVisibleWidth() const;
133
    double GetVisibleHeight() const;
134
    Point GetVisibleCenter();
135
    double GetScrlLineWidth() const;
136
    double GetScrlLineHeight() const;
137
    double GetScrlPageWidth() const;
138
    double GetScrlPageHeight() const;
139
    void GrabFocus();
140
    virtual void DataChanged(const DataChangedEvent& rDCEvt) override;
141
142
    // DropTargetHelper
143
    virtual sal_Int8 AcceptDrop(const AcceptDropEvent& rEvt) override;
144
    virtual sal_Int8 ExecuteDrop(const ExecuteDropEvent& rEvt) override;
145
146
    /** The DropScroll() method is used by AcceptDrop() to scroll the
147
        content of the window while dragging and dropping.  With this method
148
        you can control whether DropScroll() shall be used.
149
    */
150
    void SetUseDropScroll(bool bUseDropScroll);
151
    void DropScroll(const Point& rMousePos);
152
    virtual void KeyInput(const KeyEvent& rKEvt) override;
153
154
private:
155
    OutlinerView* GetOutlinerView() const;
156
157
protected:
158
    Point maWinPos;
159
    Point maViewOrigin;
160
    Size maViewSize;
161
    Size maPrevSize; // contains previous window size in logical coords
162
    sal_uInt16 mnMinZoom;
163
    sal_uInt16 mnMaxZoom;
164
165
    /** This flag tells whether to re-calculate the minimal zoom factor
166
        depending on the current zoom factor.  Its default value is now false.
167
    */
168
    bool mbMinZoomAutoCalc;
169
    bool mbCenterAllowed;
170
    ::tools::Long mnTicks;
171
172
    ViewShell* mpViewShell;
173
    bool mbUseDropScroll;
174
175
    virtual void Resize() override;
176
    virtual void PrePaint(vcl::RenderContext& rRenderContext) override;
177
    virtual void Paint(vcl::RenderContext& rRenderContext,
178
                       const ::tools::Rectangle& rRect) override;
179
    virtual void MouseMove(const MouseEvent& rMEvt) override;
180
    virtual void MouseButtonUp(const MouseEvent& rMEvt) override;
181
    virtual void MouseButtonDown(const MouseEvent& rMEvt) override;
182
    virtual void Command(const CommandEvent& rCEvt) override;
183
    virtual void RequestHelp(const HelpEvent& rEvt) override;
184
    virtual void LoseFocus() override;
185
    virtual bool EventNotify(NotifyEvent& rNEvt) override;
186
187
    /** Create an accessibility object that makes this window accessible.
188
189
        @return
190
            The returned reference is empty if an accessible object could
191
            not be created.
192
    */
193
    rtl::Reference<comphelper::OAccessible> CreateAccessible() override;
194
195
    OUString GetSurroundingText() const override;
196
    Selection GetSurroundingTextSelection() const override;
197
    bool DeleteSurroundingText(const Selection& rSelection) override;
198
199
    /// @see Window::LogicInvalidate().
200
    void LogicInvalidate(const ::tools::Rectangle* pRectangle) override;
201
202
    FactoryFunction GetUITestFactory() const override;
203
};
204
205
} // end of namespace sd
206
207
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */