1*cdf0e10cSrcweir /************************************************************************* *
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2008 by Sun Microsystems, Inc.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * $RCSfile: postit.cxx,v $
10*cdf0e10cSrcweir  * $Revision: 1.8.42.11 $
11*cdf0e10cSrcweir  *
12*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
13*cdf0e10cSrcweir  *
14*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
15*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
16*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
17*cdf0e10cSrcweir  *
18*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
19*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
22*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
23*cdf0e10cSrcweir  *
24*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
25*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
26*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
27*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
28*cdf0e10cSrcweir  *
29*cdf0e10cSrcweir  ************************************************************************/
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include "precompiled_sw.hxx"
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include <ShadowOverlayObject.hxx>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include <view.hxx>
37*cdf0e10cSrcweir #include <svx/sdrpaintwindow.hxx>
38*cdf0e10cSrcweir #include <svx/svdview.hxx>
39*cdf0e10cSrcweir #include <svx/sdr/overlay/overlaymanager.hxx>
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir #include <sw_primitivetypes2d.hxx>
42*cdf0e10cSrcweir #include <drawinglayer/primitive2d/primitivetools2d.hxx>
43*cdf0e10cSrcweir #include <drawinglayer/primitive2d/fillgradientprimitive2d.hxx>
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir namespace sw { namespace sidebarwindows {
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
48*cdf0e10cSrcweir // helper SwPostItShadowPrimitive
49*cdf0e10cSrcweir //
50*cdf0e10cSrcweir // Used to allow view-dependent primitive definition. For that purpose, the
51*cdf0e10cSrcweir // initially created primitive (this one) always has to be view-independent,
52*cdf0e10cSrcweir // but the decomposition is made view-dependent. Very simple primitive which
53*cdf0e10cSrcweir // just remembers the discrete data and applies it at decomposition time.
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir class ShadowPrimitive : public drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D
56*cdf0e10cSrcweir {
57*cdf0e10cSrcweir private:
58*cdf0e10cSrcweir     basegfx::B2DPoint           maBasePosition;
59*cdf0e10cSrcweir     basegfx::B2DPoint           maSecondPosition;
60*cdf0e10cSrcweir     ShadowState                 maShadowState;
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir protected:
63*cdf0e10cSrcweir     virtual drawinglayer::primitive2d::Primitive2DSequence create2DDecomposition(
64*cdf0e10cSrcweir         const drawinglayer::geometry::ViewInformation2D& rViewInformation) const;
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir public:
67*cdf0e10cSrcweir     ShadowPrimitive(
68*cdf0e10cSrcweir         const basegfx::B2DPoint& rBasePosition,
69*cdf0e10cSrcweir         const basegfx::B2DPoint& rSecondPosition,
70*cdf0e10cSrcweir         ShadowState aShadowState)
71*cdf0e10cSrcweir     :   drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D(),
72*cdf0e10cSrcweir         maBasePosition(rBasePosition),
73*cdf0e10cSrcweir         maSecondPosition(rSecondPosition),
74*cdf0e10cSrcweir         maShadowState(aShadowState)
75*cdf0e10cSrcweir     {}
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir     // data access
78*cdf0e10cSrcweir     const basegfx::B2DPoint& getBasePosition() const { return maBasePosition; }
79*cdf0e10cSrcweir     const basegfx::B2DPoint& getSecondPosition() const { return maSecondPosition; }
80*cdf0e10cSrcweir     ShadowState getShadowState() const { return maShadowState; }
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir     virtual bool operator==( const drawinglayer::primitive2d::BasePrimitive2D& rPrimitive ) const;
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir     DeclPrimitrive2DIDBlock()
85*cdf0e10cSrcweir };
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir drawinglayer::primitive2d::Primitive2DSequence ShadowPrimitive::create2DDecomposition(
88*cdf0e10cSrcweir     const drawinglayer::geometry::ViewInformation2D& /*rViewInformation*/) const
89*cdf0e10cSrcweir {
90*cdf0e10cSrcweir     // get logic sizes in object coordinate system
91*cdf0e10cSrcweir     drawinglayer::primitive2d::Primitive2DSequence xRetval;
92*cdf0e10cSrcweir     basegfx::B2DRange aRange(getBasePosition());
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir     switch(maShadowState)
95*cdf0e10cSrcweir     {
96*cdf0e10cSrcweir         case SS_NORMAL:
97*cdf0e10cSrcweir         {
98*cdf0e10cSrcweir             aRange.expand(basegfx::B2DTuple(getSecondPosition().getX(), getSecondPosition().getY() + (2.0 * getDiscreteUnit())));
99*cdf0e10cSrcweir             const ::drawinglayer::attribute::FillGradientAttribute aFillGradientAttribute(
100*cdf0e10cSrcweir                 drawinglayer::attribute::GRADIENTSTYLE_LINEAR,
101*cdf0e10cSrcweir                 0.0,
102*cdf0e10cSrcweir                 0.5,
103*cdf0e10cSrcweir                 0.5,
104*cdf0e10cSrcweir                 1800.0 * F_PI1800,
105*cdf0e10cSrcweir                 basegfx::BColor(230.0/255.0,230.0/255.0,230.0/255.0),
106*cdf0e10cSrcweir                 basegfx::BColor(180.0/255.0,180.0/255.0,180.0/255.0),
107*cdf0e10cSrcweir                 2);
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir             const drawinglayer::primitive2d::Primitive2DReference xReference(
110*cdf0e10cSrcweir                 new drawinglayer::primitive2d::FillGradientPrimitive2D(
111*cdf0e10cSrcweir                     aRange,
112*cdf0e10cSrcweir                     aFillGradientAttribute));
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir             xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
115*cdf0e10cSrcweir             break;
116*cdf0e10cSrcweir         }
117*cdf0e10cSrcweir         case SS_VIEW:
118*cdf0e10cSrcweir         {
119*cdf0e10cSrcweir             aRange.expand(basegfx::B2DTuple(getSecondPosition().getX(), getSecondPosition().getY() + (4.0 * getDiscreteUnit())));
120*cdf0e10cSrcweir             const drawinglayer::attribute::FillGradientAttribute aFillGradientAttribute(
121*cdf0e10cSrcweir                 drawinglayer::attribute::GRADIENTSTYLE_LINEAR,
122*cdf0e10cSrcweir                 0.0,
123*cdf0e10cSrcweir                 0.5,
124*cdf0e10cSrcweir                 0.5,
125*cdf0e10cSrcweir                 1800.0 * F_PI1800,
126*cdf0e10cSrcweir                 basegfx::BColor(230.0/255.0,230.0/255.0,230.0/255.0),
127*cdf0e10cSrcweir                 basegfx::BColor(180.0/255.0,180.0/255.0,180.0/255.0),
128*cdf0e10cSrcweir                 4);
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir             const drawinglayer::primitive2d::Primitive2DReference xReference(
131*cdf0e10cSrcweir                 new drawinglayer::primitive2d::FillGradientPrimitive2D(
132*cdf0e10cSrcweir                     aRange,
133*cdf0e10cSrcweir                     aFillGradientAttribute));
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir             xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
136*cdf0e10cSrcweir             break;
137*cdf0e10cSrcweir         }
138*cdf0e10cSrcweir         case SS_EDIT:
139*cdf0e10cSrcweir         {
140*cdf0e10cSrcweir             aRange.expand(basegfx::B2DTuple(getSecondPosition().getX(), getSecondPosition().getY() + (4.0 * getDiscreteUnit())));
141*cdf0e10cSrcweir             const drawinglayer::attribute::FillGradientAttribute aFillGradientAttribute(
142*cdf0e10cSrcweir                 drawinglayer::attribute::GRADIENTSTYLE_LINEAR,
143*cdf0e10cSrcweir                 0.0,
144*cdf0e10cSrcweir                 0.5,
145*cdf0e10cSrcweir                 0.5,
146*cdf0e10cSrcweir                 1800.0 * F_PI1800,
147*cdf0e10cSrcweir                 basegfx::BColor(230.0/255.0,230.0/255.0,230.0/255.0),
148*cdf0e10cSrcweir                 basegfx::BColor(83.0/255.0,83.0/255.0,83.0/255.0),
149*cdf0e10cSrcweir                 4);
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir             const drawinglayer::primitive2d::Primitive2DReference xReference(
152*cdf0e10cSrcweir                 new drawinglayer::primitive2d::FillGradientPrimitive2D(
153*cdf0e10cSrcweir                     aRange,
154*cdf0e10cSrcweir                     aFillGradientAttribute));
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir             xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
157*cdf0e10cSrcweir             break;
158*cdf0e10cSrcweir         }
159*cdf0e10cSrcweir         default:
160*cdf0e10cSrcweir         {
161*cdf0e10cSrcweir             break;
162*cdf0e10cSrcweir         }
163*cdf0e10cSrcweir     }
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir     return xRetval;
166*cdf0e10cSrcweir }
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir bool ShadowPrimitive::operator==( const drawinglayer::primitive2d::BasePrimitive2D& rPrimitive ) const
169*cdf0e10cSrcweir {
170*cdf0e10cSrcweir     if(drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D::operator==(rPrimitive))
171*cdf0e10cSrcweir     {
172*cdf0e10cSrcweir         const ShadowPrimitive& rCompare = static_cast< const ShadowPrimitive& >(rPrimitive);
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir         return (getBasePosition() == rCompare.getBasePosition()
175*cdf0e10cSrcweir             && getSecondPosition() == rCompare.getSecondPosition()
176*cdf0e10cSrcweir             && getShadowState() == rCompare.getShadowState());
177*cdf0e10cSrcweir     }
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir     return false;
180*cdf0e10cSrcweir }
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir ImplPrimitrive2DIDBlock(ShadowPrimitive, PRIMITIVE2D_ID_SWSIDEBARSHADOWPRIMITIVE)
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir /****** ShadowOverlayObject  **************************************************/
185*cdf0e10cSrcweir /* static */ ShadowOverlayObject* ShadowOverlayObject::CreateShadowOverlayObject( SwView& rDocView )
186*cdf0e10cSrcweir {
187*cdf0e10cSrcweir     ShadowOverlayObject* pShadowOverlayObject( 0 );
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir     if ( rDocView.GetDrawView() )
190*cdf0e10cSrcweir     {
191*cdf0e10cSrcweir         SdrPaintWindow* pPaintWindow = rDocView.GetDrawView()->GetPaintWindow(0);
192*cdf0e10cSrcweir         if( pPaintWindow )
193*cdf0e10cSrcweir         {
194*cdf0e10cSrcweir             sdr::overlay::OverlayManager* pOverlayManager = pPaintWindow->GetOverlayManager();
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir             if ( pOverlayManager )
197*cdf0e10cSrcweir             {
198*cdf0e10cSrcweir                 pShadowOverlayObject = new ShadowOverlayObject( basegfx::B2DPoint(0,0),
199*cdf0e10cSrcweir                                                                 basegfx::B2DPoint(0,0),
200*cdf0e10cSrcweir                                                                 Color(0,0,0),
201*cdf0e10cSrcweir                                                                 SS_NORMAL );
202*cdf0e10cSrcweir                 pOverlayManager->add(*pShadowOverlayObject);
203*cdf0e10cSrcweir             }
204*cdf0e10cSrcweir         }
205*cdf0e10cSrcweir     }
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir     return pShadowOverlayObject;
208*cdf0e10cSrcweir }
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir /* static */ void ShadowOverlayObject::DestroyShadowOverlayObject( ShadowOverlayObject* pShadow )
211*cdf0e10cSrcweir {
212*cdf0e10cSrcweir     if ( pShadow )
213*cdf0e10cSrcweir     {
214*cdf0e10cSrcweir         if ( pShadow->getOverlayManager() )
215*cdf0e10cSrcweir         {
216*cdf0e10cSrcweir             pShadow->getOverlayManager()->remove(*pShadow);
217*cdf0e10cSrcweir         }
218*cdf0e10cSrcweir         delete pShadow;
219*cdf0e10cSrcweir     }
220*cdf0e10cSrcweir }
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir ShadowOverlayObject::ShadowOverlayObject( const basegfx::B2DPoint& rBasePos,
223*cdf0e10cSrcweir                                           const basegfx::B2DPoint& rSecondPosition,
224*cdf0e10cSrcweir                                           Color aBaseColor,
225*cdf0e10cSrcweir                                           ShadowState aState )
226*cdf0e10cSrcweir     : OverlayObjectWithBasePosition(rBasePos, aBaseColor)
227*cdf0e10cSrcweir     , maSecondPosition(rSecondPosition)
228*cdf0e10cSrcweir     , mShadowState(aState)
229*cdf0e10cSrcweir {
230*cdf0e10cSrcweir }
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir ShadowOverlayObject::~ShadowOverlayObject()
233*cdf0e10cSrcweir {
234*cdf0e10cSrcweir }
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir drawinglayer::primitive2d::Primitive2DSequence ShadowOverlayObject::createOverlayObjectPrimitive2DSequence()
237*cdf0e10cSrcweir {
238*cdf0e10cSrcweir     const drawinglayer::primitive2d::Primitive2DReference aReference(
239*cdf0e10cSrcweir         new ShadowPrimitive( getBasePosition(),
240*cdf0e10cSrcweir                              GetSecondPosition(),
241*cdf0e10cSrcweir                              GetShadowState() ) );
242*cdf0e10cSrcweir     return drawinglayer::primitive2d::Primitive2DSequence(&aReference, 1);
243*cdf0e10cSrcweir }
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir void ShadowOverlayObject::SetShadowState(ShadowState aState)
246*cdf0e10cSrcweir {
247*cdf0e10cSrcweir     if (mShadowState != aState)
248*cdf0e10cSrcweir     {
249*cdf0e10cSrcweir         mShadowState = aState;
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir         objectChange();
252*cdf0e10cSrcweir     }
253*cdf0e10cSrcweir }
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir void ShadowOverlayObject::SetPosition( const basegfx::B2DPoint& rPoint1,
256*cdf0e10cSrcweir                                        const basegfx::B2DPoint& rPoint2)
257*cdf0e10cSrcweir {
258*cdf0e10cSrcweir     if(!rPoint1.equal(getBasePosition()) || !rPoint2.equal(GetSecondPosition()))
259*cdf0e10cSrcweir     {
260*cdf0e10cSrcweir         maBasePosition = rPoint1;
261*cdf0e10cSrcweir         maSecondPosition = rPoint2;
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir         objectChange();
264*cdf0e10cSrcweir     }
265*cdf0e10cSrcweir }
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir } } // end of namespace sw::sidebarwindows
268*cdf0e10cSrcweir 
269