1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24
25 #include "precompiled_sw.hxx"
26
27 #include <ShadowOverlayObject.hxx>
28
29 #include <view.hxx>
30 #include <svx/sdrpaintwindow.hxx>
31 #include <svx/svdview.hxx>
32 #include <svx/sdr/overlay/overlaymanager.hxx>
33
34 #include <sw_primitivetypes2d.hxx>
35 #include <drawinglayer/primitive2d/primitivetools2d.hxx>
36 #include <drawinglayer/primitive2d/fillgradientprimitive2d.hxx>
37
38 namespace sw { namespace sidebarwindows {
39
40 //////////////////////////////////////////////////////////////////////////////
41 // helper SwPostItShadowPrimitive
42 //
43 // Used to allow view-dependent primitive definition. For that purpose, the
44 // initially created primitive (this one) always has to be view-independent,
45 // but the decomposition is made view-dependent. Very simple primitive which
46 // just remembers the discrete data and applies it at decomposition time.
47
48 class ShadowPrimitive : public drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D
49 {
50 private:
51 basegfx::B2DPoint maBasePosition;
52 basegfx::B2DPoint maSecondPosition;
53 ShadowState maShadowState;
54
55 protected:
56 virtual drawinglayer::primitive2d::Primitive2DSequence create2DDecomposition(
57 const drawinglayer::geometry::ViewInformation2D& rViewInformation) const;
58
59 public:
ShadowPrimitive(const basegfx::B2DPoint & rBasePosition,const basegfx::B2DPoint & rSecondPosition,ShadowState aShadowState)60 ShadowPrimitive(
61 const basegfx::B2DPoint& rBasePosition,
62 const basegfx::B2DPoint& rSecondPosition,
63 ShadowState aShadowState)
64 : drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D(),
65 maBasePosition(rBasePosition),
66 maSecondPosition(rSecondPosition),
67 maShadowState(aShadowState)
68 {}
69
70 // data access
getBasePosition() const71 const basegfx::B2DPoint& getBasePosition() const { return maBasePosition; }
getSecondPosition() const72 const basegfx::B2DPoint& getSecondPosition() const { return maSecondPosition; }
getShadowState() const73 ShadowState getShadowState() const { return maShadowState; }
74
75 virtual bool operator==( const drawinglayer::primitive2d::BasePrimitive2D& rPrimitive ) const;
76
77 DeclPrimitrive2DIDBlock()
78 };
79
create2DDecomposition(const drawinglayer::geometry::ViewInformation2D &) const80 drawinglayer::primitive2d::Primitive2DSequence ShadowPrimitive::create2DDecomposition(
81 const drawinglayer::geometry::ViewInformation2D& /*rViewInformation*/) const
82 {
83 // get logic sizes in object coordinate system
84 drawinglayer::primitive2d::Primitive2DSequence xRetval;
85 basegfx::B2DRange aRange(getBasePosition());
86
87 switch(maShadowState)
88 {
89 case SS_NORMAL:
90 {
91 aRange.expand(basegfx::B2DTuple(getSecondPosition().getX(), getSecondPosition().getY() + (2.0 * getDiscreteUnit())));
92 const ::drawinglayer::attribute::FillGradientAttribute aFillGradientAttribute(
93 drawinglayer::attribute::GRADIENTSTYLE_LINEAR,
94 0.0,
95 0.5,
96 0.5,
97 1800.0 * F_PI1800,
98 basegfx::BColor(230.0/255.0,230.0/255.0,230.0/255.0),
99 basegfx::BColor(180.0/255.0,180.0/255.0,180.0/255.0),
100 2);
101
102 const drawinglayer::primitive2d::Primitive2DReference xReference(
103 new drawinglayer::primitive2d::FillGradientPrimitive2D(
104 aRange,
105 aFillGradientAttribute));
106
107 xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
108 break;
109 }
110 case SS_VIEW:
111 {
112 aRange.expand(basegfx::B2DTuple(getSecondPosition().getX(), getSecondPosition().getY() + (4.0 * getDiscreteUnit())));
113 const drawinglayer::attribute::FillGradientAttribute aFillGradientAttribute(
114 drawinglayer::attribute::GRADIENTSTYLE_LINEAR,
115 0.0,
116 0.5,
117 0.5,
118 1800.0 * F_PI1800,
119 basegfx::BColor(230.0/255.0,230.0/255.0,230.0/255.0),
120 basegfx::BColor(180.0/255.0,180.0/255.0,180.0/255.0),
121 4);
122
123 const drawinglayer::primitive2d::Primitive2DReference xReference(
124 new drawinglayer::primitive2d::FillGradientPrimitive2D(
125 aRange,
126 aFillGradientAttribute));
127
128 xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
129 break;
130 }
131 case SS_EDIT:
132 {
133 aRange.expand(basegfx::B2DTuple(getSecondPosition().getX(), getSecondPosition().getY() + (4.0 * getDiscreteUnit())));
134 const drawinglayer::attribute::FillGradientAttribute aFillGradientAttribute(
135 drawinglayer::attribute::GRADIENTSTYLE_LINEAR,
136 0.0,
137 0.5,
138 0.5,
139 1800.0 * F_PI1800,
140 basegfx::BColor(230.0/255.0,230.0/255.0,230.0/255.0),
141 basegfx::BColor(83.0/255.0,83.0/255.0,83.0/255.0),
142 4);
143
144 const drawinglayer::primitive2d::Primitive2DReference xReference(
145 new drawinglayer::primitive2d::FillGradientPrimitive2D(
146 aRange,
147 aFillGradientAttribute));
148
149 xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
150 break;
151 }
152 default:
153 {
154 break;
155 }
156 }
157
158 return xRetval;
159 }
160
operator ==(const drawinglayer::primitive2d::BasePrimitive2D & rPrimitive) const161 bool ShadowPrimitive::operator==( const drawinglayer::primitive2d::BasePrimitive2D& rPrimitive ) const
162 {
163 if(drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D::operator==(rPrimitive))
164 {
165 const ShadowPrimitive& rCompare = static_cast< const ShadowPrimitive& >(rPrimitive);
166
167 return (getBasePosition() == rCompare.getBasePosition()
168 && getSecondPosition() == rCompare.getSecondPosition()
169 && getShadowState() == rCompare.getShadowState());
170 }
171
172 return false;
173 }
174
ImplPrimitrive2DIDBlock(ShadowPrimitive,PRIMITIVE2D_ID_SWSIDEBARSHADOWPRIMITIVE)175 ImplPrimitrive2DIDBlock(ShadowPrimitive, PRIMITIVE2D_ID_SWSIDEBARSHADOWPRIMITIVE)
176
177 /****** ShadowOverlayObject **************************************************/
178 /* static */ ShadowOverlayObject* ShadowOverlayObject::CreateShadowOverlayObject( SwView& rDocView )
179 {
180 ShadowOverlayObject* pShadowOverlayObject( 0 );
181
182 if ( rDocView.GetDrawView() )
183 {
184 SdrPaintWindow* pPaintWindow = rDocView.GetDrawView()->GetPaintWindow(0);
185 if( pPaintWindow )
186 {
187 sdr::overlay::OverlayManager* pOverlayManager = pPaintWindow->GetOverlayManager();
188
189 if ( pOverlayManager )
190 {
191 pShadowOverlayObject = new ShadowOverlayObject( basegfx::B2DPoint(0,0),
192 basegfx::B2DPoint(0,0),
193 Color(0,0,0),
194 SS_NORMAL );
195 pOverlayManager->add(*pShadowOverlayObject);
196 }
197 }
198 }
199
200 return pShadowOverlayObject;
201 }
202
DestroyShadowOverlayObject(ShadowOverlayObject * pShadow)203 /* static */ void ShadowOverlayObject::DestroyShadowOverlayObject( ShadowOverlayObject* pShadow )
204 {
205 if ( pShadow )
206 {
207 if ( pShadow->getOverlayManager() )
208 {
209 pShadow->getOverlayManager()->remove(*pShadow);
210 }
211 delete pShadow;
212 }
213 }
214
ShadowOverlayObject(const basegfx::B2DPoint & rBasePos,const basegfx::B2DPoint & rSecondPosition,Color aBaseColor,ShadowState aState)215 ShadowOverlayObject::ShadowOverlayObject( const basegfx::B2DPoint& rBasePos,
216 const basegfx::B2DPoint& rSecondPosition,
217 Color aBaseColor,
218 ShadowState aState )
219 : OverlayObjectWithBasePosition(rBasePos, aBaseColor)
220 , maSecondPosition(rSecondPosition)
221 , mShadowState(aState)
222 {
223 }
224
~ShadowOverlayObject()225 ShadowOverlayObject::~ShadowOverlayObject()
226 {
227 }
228
createOverlayObjectPrimitive2DSequence()229 drawinglayer::primitive2d::Primitive2DSequence ShadowOverlayObject::createOverlayObjectPrimitive2DSequence()
230 {
231 const drawinglayer::primitive2d::Primitive2DReference aReference(
232 new ShadowPrimitive( getBasePosition(),
233 GetSecondPosition(),
234 GetShadowState() ) );
235 return drawinglayer::primitive2d::Primitive2DSequence(&aReference, 1);
236 }
237
SetShadowState(ShadowState aState)238 void ShadowOverlayObject::SetShadowState(ShadowState aState)
239 {
240 if (mShadowState != aState)
241 {
242 mShadowState = aState;
243
244 objectChange();
245 }
246 }
247
SetPosition(const basegfx::B2DPoint & rPoint1,const basegfx::B2DPoint & rPoint2)248 void ShadowOverlayObject::SetPosition( const basegfx::B2DPoint& rPoint1,
249 const basegfx::B2DPoint& rPoint2)
250 {
251 if(!rPoint1.equal(getBasePosition()) || !rPoint2.equal(GetSecondPosition()))
252 {
253 maBasePosition = rPoint1;
254 maSecondPosition = rPoint2;
255
256 objectChange();
257 }
258 }
259
260 } } // end of namespace sw::sidebarwindows
261
262