LibreOffice Module sw (master) 1
ShadowOverlayObject.cxx
Go to the documentation of this file.
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
21
22#include <view.hxx>
24#include <svx/svdview.hxx>
26
30
31namespace sw::sidebarwindows {
32
33// helper SwPostItShadowPrimitive
34
35namespace {
36
37// Used to allow view-dependent primitive definition. For that purpose, the
38// initially created primitive (this one) always has to be view-independent,
39// but the decomposition is made view-dependent. Very simple primitive which
40// just remembers the discrete data and applies it at decomposition time.
42{
43private:
47
48protected:
49 virtual void create2DDecomposition(
51 const drawinglayer::geometry::ViewInformation2D& rViewInformation) const override;
52
53public:
54 ShadowPrimitive(
55 const basegfx::B2DPoint& rBasePosition,
56 const basegfx::B2DPoint& rSecondPosition,
57 ShadowState aShadowState)
58 : maBasePosition(rBasePosition),
59 maSecondPosition(rSecondPosition),
60 maShadowState(aShadowState)
61 {}
62
63 // data access
64 const basegfx::B2DPoint& getSecondPosition() const { return maSecondPosition; }
65
66 virtual bool operator==( const drawinglayer::primitive2d::BasePrimitive2D& rPrimitive ) const override;
67
68 virtual sal_uInt32 getPrimitive2DID() const override;
69};
70
71}
72
73void ShadowPrimitive::create2DDecomposition(
75 const drawinglayer::geometry::ViewInformation2D& /*rViewInformation*/) const
76{
77 // get logic sizes in object coordinate system
79
80 switch(maShadowState)
81 {
82 case SS_NORMAL:
83 {
84 aRange.expand(basegfx::B2DTuple(getSecondPosition().getX(), getSecondPosition().getY() + (2.0 * getDiscreteUnit())));
87 0.0,
88 0.5,
89 0.5,
90 M_PI,
91 basegfx::BColor(230.0/255.0,230.0/255.0,230.0/255.0),
92 basegfx::BColor(180.0/255.0,180.0/255.0,180.0/255.0));
93
94 rContainer.push_back(
96 aRange,
97 std::move(aFillGradientAttribute)));
98 break;
99 }
100 case SS_VIEW:
101 {
102 aRange.expand(basegfx::B2DTuple(getSecondPosition().getX(), getSecondPosition().getY() + (4.0 * getDiscreteUnit())));
105 0.0,
106 0.5,
107 0.5,
108 M_PI,
109 basegfx::BColor(230.0/255.0,230.0/255.0,230.0/255.0),
110 basegfx::BColor(180.0/255.0,180.0/255.0,180.0/255.0));
111
112 rContainer.push_back(
114 aRange,
115 std::move(aFillGradientAttribute)));
116 break;
117 }
118 case SS_EDIT:
119 {
120 aRange.expand(basegfx::B2DTuple(getSecondPosition().getX(), getSecondPosition().getY() + (4.0 * getDiscreteUnit())));
123 0.0,
124 0.5,
125 0.5,
126 M_PI,
127 basegfx::BColor(230.0/255.0,230.0/255.0,230.0/255.0),
128 basegfx::BColor(83.0/255.0,83.0/255.0,83.0/255.0));
129
130 rContainer.push_back(
132 aRange,
133 std::move(aFillGradientAttribute)));
134 break;
135 }
136 default:
137 {
138 break;
139 }
140 }
141}
142
143bool ShadowPrimitive::operator==( const drawinglayer::primitive2d::BasePrimitive2D& rPrimitive ) const
144{
145 if(drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D::operator==(rPrimitive))
146 {
147 const ShadowPrimitive& rCompare = static_cast< const ShadowPrimitive& >(rPrimitive);
148
149 return (maBasePosition == rCompare.maBasePosition
150 && getSecondPosition() == rCompare.getSecondPosition()
151 && maShadowState == rCompare.maShadowState);
152 }
153
154 return false;
155}
156
157sal_uInt32 ShadowPrimitive::getPrimitive2DID() const
158{
160}
161
162/* static */ std::unique_ptr<ShadowOverlayObject> ShadowOverlayObject::CreateShadowOverlayObject( SwView const & rDocView )
163{
164 std::unique_ptr<ShadowOverlayObject> pShadowOverlayObject;
165
166 if ( rDocView.GetDrawView() )
167 {
168 SdrPaintWindow* pPaintWindow = rDocView.GetDrawView()->GetPaintWindow(0);
169 if( pPaintWindow )
170 {
171 const rtl::Reference< sdr::overlay::OverlayManager >& xOverlayManager = pPaintWindow->GetOverlayManager();
172
173 if ( xOverlayManager.is() )
174 {
175 pShadowOverlayObject.reset( new ShadowOverlayObject( basegfx::B2DPoint(0,0),
177 Color(0,0,0) ) );
178 xOverlayManager->add(*pShadowOverlayObject);
179 }
180 }
181 }
182
183 return pShadowOverlayObject;
184}
185
187 const basegfx::B2DPoint& rSecondPosition,
188 Color aBaseColor )
189 : OverlayObjectWithBasePosition(rBasePos, aBaseColor)
190 , maSecondPosition(rSecondPosition)
191 , mShadowState(SS_NORMAL)
192{
193}
194
196{
197 if ( getOverlayManager() )
198 {
199 getOverlayManager()->remove(*this);
200 }
201}
202
204{
206 new ShadowPrimitive( getBasePosition(),
208 GetShadowState() ) );
210}
211
213{
214 if (mShadowState != aState)
215 {
216 mShadowState = aState;
217
218 objectChange();
219 }
220}
221
223 const basegfx::B2DPoint& rPoint2)
224{
225 if(!rPoint1.equal(getBasePosition()) || !rPoint2.equal(maSecondPosition))
226 {
227 maBasePosition = rPoint1;
228 maSecondPosition = rPoint2;
229
230 objectChange();
231 }
232}
233
234} // end of namespace sw::sidebarwindows
235
236/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ShadowState maShadowState
basegfx::B2DPoint maBasePosition
basegfx::B2DPoint maSecondPosition
SdrPaintWindow * GetPaintWindow(sal_uInt32 nIndex) const
rtl::Reference< sdr::overlay::OverlayManager > const & GetOverlayManager() const
Definition: view.hxx:146
virtual SdrView * GetDrawView() const override
Definition: viewdraw.cxx:621
bool equal(const Tuple2D< TYPE > &rTup) const
void remove(OverlayObject &rOverlayObject)
const basegfx::B2DPoint & getBasePosition() const
OverlayManager * getOverlayManager() const
ShadowOverlayObject(const basegfx::B2DPoint &rBasePos, const basegfx::B2DPoint &rSecondPosition, Color aBaseColor)
virtual drawinglayer::primitive2d::Primitive2DContainer createOverlayObjectPrimitive2DSequence() override
static std::unique_ptr< ShadowOverlayObject > CreateShadowOverlayObject(SwView const &rDocView)
void SetPosition(const basegfx::B2DPoint &rPoint1, const basegfx::B2DPoint &rPoint2)
#define PRIMITIVE2D_ID_SWSIDEBARSHADOWPRIMITIVE
bool operator==(const XclFontData &rLeft, const XclFontData &rRight)