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 .
22 #include <tools/gen.hxx>
23 #include <tools/long.hxx>
24 #include <vcl/DocWindow.hxx>
25 #include <vcl/transfer.hxx>
33 /** An SdWindow contains the actual working area of ViewShell.
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.
44 class Window
: public vcl::DocWindow
, public ::DropTargetHelper
47 Window(vcl::Window
* pParent
);
48 virtual ~Window() override
;
49 virtual void dispose() override
;
51 void SetViewShell(ViewShell
* pViewSh
);
52 ViewShell
* GetViewShell();
54 /** Set the zoom factor to the specified value and center the display
55 area around the zoom center.
57 The zoom factor is given as integral percent value.
59 void SetZoomIntegral(::tools::Long nZoom
);
61 /** This internally used method performs the actual adaptation of the
62 window's map mode to the specified zoom factor.
64 The zoom factor is given as integral percent value.
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
72 ::tools::Long
SetZoomFactor(::tools::Long nZoom
);
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.
81 The rectangle is expected to be given relative to the upper left
82 corner of the window in logical coordinates (100th of mm).
84 The new zoom factor is returned as integral percent value.
86 ::tools::Long
SetZoomRect(const ::tools::Rectangle
& rZoomRect
);
88 ::tools::Long
GetZoomForRect(const ::tools::Rectangle
& rZoomRect
);
90 void SetMinZoomAutoCalc(bool bAuto
);
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
99 <p>This calculation is performed only when the
100 <member>bMinZoomAutoCalc</member> is set (to <TRUE/>).</p>
103 void SetMinZoom(::tools::Long nMin
);
104 ::tools::Long
GetMinZoom() const { return mnMinZoom
; }
105 void SetMaxZoom(::tools::Long nMax
);
106 ::tools::Long
GetMaxZoom() const { return mnMaxZoom
; }
108 ::tools::Long
GetZoom() const;
110 const Point
& GetWinViewPos() const { return maWinPos
; }
111 const Point
& GetViewOrigin() const { return maViewOrigin
; }
112 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
);
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.
125 void UpdateMapOrigin(bool bInvalidate
= true);
127 void UpdateMapMode();
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;
140 virtual void DataChanged(const DataChangedEvent
& rDCEvt
) override
;
143 virtual sal_Int8
AcceptDrop(const AcceptDropEvent
& rEvt
) override
;
144 virtual sal_Int8
ExecuteDrop(const ExecuteDropEvent
& rEvt
) override
;
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.
150 void SetUseDropScroll(bool bUseDropScroll
);
151 void DropScroll(const Point
& rMousePos
);
152 virtual void KeyInput(const KeyEvent
& rKEvt
) override
;
155 OutlinerView
* GetOutlinerView() const;
161 Size maPrevSize
; // contains previous window size in logical coords
162 sal_uInt16 mnMinZoom
;
163 sal_uInt16 mnMaxZoom
;
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.
168 bool mbMinZoomAutoCalc
;
169 bool mbCenterAllowed
;
170 ::tools::Long mnTicks
;
172 ViewShell
* mpViewShell
;
173 bool mbUseDropScroll
;
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
;
187 /** Create an accessibility object that makes this window accessible.
190 The returned reference is empty if an accessible object could
193 virtual css::uno::Reference
<css::accessibility::XAccessible
> CreateAccessible() override
;
195 OUString
GetSurroundingText() const override
;
196 Selection
GetSurroundingTextSelection() const override
;
197 bool DeleteSurroundingText(const Selection
& rSelection
) override
;
199 /// @see Window::LogicInvalidate().
200 void LogicInvalidate(const ::tools::Rectangle
* pRectangle
) override
;
202 FactoryFunction
GetUITestFactory() const override
;
205 } // end of namespace sd
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */