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 
20 #include "ShadowOverlayObject.hxx"
21 
22 #include <view.hxx>
23 #include <svx/sdrpaintwindow.hxx>
24 #include <svx/svdview.hxx>
26 
27 #include <sw_primitivetypes2d.hxx>
30 
31 namespace sw { namespace sidebarwindows {
32 
33 // helper SwPostItShadowPrimitive
34 
35 // Used to allow view-dependent primitive definition. For that purpose, the
36 // initially created primitive (this one) always has to be view-independent,
37 // but the decomposition is made view-dependent. Very simple primitive which
38 // just remembers the discrete data and applies it at decomposition time.
40 {
41 private:
45 
46 protected:
47  virtual void create2DDecomposition(
49  const drawinglayer::geometry::ViewInformation2D& rViewInformation) const override;
50 
51 public:
53  const basegfx::B2DPoint& rBasePosition,
54  const basegfx::B2DPoint& rSecondPosition,
55  ShadowState aShadowState)
57  maBasePosition(rBasePosition),
58  maSecondPosition(rSecondPosition),
59  maShadowState(aShadowState)
60  {}
61 
62  // data access
64 
65  virtual bool operator==( const drawinglayer::primitive2d::BasePrimitive2D& rPrimitive ) const override;
66 
68 };
69 
72  const drawinglayer::geometry::ViewInformation2D& /*rViewInformation*/) const
73 {
74  // get logic sizes in object coordinate system
76 
77  switch(maShadowState)
78  {
79  case SS_NORMAL:
80  {
81  aRange.expand(basegfx::B2DTuple(getSecondPosition().getX(), getSecondPosition().getY() + (2.0 * getDiscreteUnit())));
82  const ::drawinglayer::attribute::FillGradientAttribute aFillGradientAttribute(
84  0.0,
85  0.5,
86  0.5,
87  F_PI,
88  basegfx::BColor(230.0/255.0,230.0/255.0,230.0/255.0),
89  basegfx::BColor(180.0/255.0,180.0/255.0,180.0/255.0),
90  2);
91 
92  rContainer.push_back(
94  aRange,
95  aFillGradientAttribute));
96  break;
97  }
98  case SS_VIEW:
99  {
100  aRange.expand(basegfx::B2DTuple(getSecondPosition().getX(), getSecondPosition().getY() + (4.0 * getDiscreteUnit())));
101  const drawinglayer::attribute::FillGradientAttribute aFillGradientAttribute(
103  0.0,
104  0.5,
105  0.5,
106  F_PI,
107  basegfx::BColor(230.0/255.0,230.0/255.0,230.0/255.0),
108  basegfx::BColor(180.0/255.0,180.0/255.0,180.0/255.0),
109  4);
110 
111  rContainer.push_back(
113  aRange,
114  aFillGradientAttribute));
115  break;
116  }
117  case SS_EDIT:
118  {
119  aRange.expand(basegfx::B2DTuple(getSecondPosition().getX(), getSecondPosition().getY() + (4.0 * getDiscreteUnit())));
120  const drawinglayer::attribute::FillGradientAttribute aFillGradientAttribute(
122  0.0,
123  0.5,
124  0.5,
125  F_PI,
126  basegfx::BColor(230.0/255.0,230.0/255.0,230.0/255.0),
127  basegfx::BColor(83.0/255.0,83.0/255.0,83.0/255.0),
128  4);
129 
130  rContainer.push_back(
132  aRange,
133  aFillGradientAttribute));
134  break;
135  }
136  default:
137  {
138  break;
139  }
140  }
141 }
142 
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 
158 
159 /* static */ std::unique_ptr<ShadowOverlayObject> ShadowOverlayObject::CreateShadowOverlayObject( SwView const & rDocView )
160 {
161  std::unique_ptr<ShadowOverlayObject> pShadowOverlayObject;
162 
163  if ( rDocView.GetDrawView() )
164  {
165  SdrPaintWindow* pPaintWindow = rDocView.GetDrawView()->GetPaintWindow(0);
166  if( pPaintWindow )
167  {
168  const rtl::Reference< sdr::overlay::OverlayManager >& xOverlayManager = pPaintWindow->GetOverlayManager();
169 
170  if ( xOverlayManager.is() )
171  {
172  pShadowOverlayObject.reset( new ShadowOverlayObject( basegfx::B2DPoint(0,0),
173  basegfx::B2DPoint(0,0),
174  Color(0,0,0) ) );
175  xOverlayManager->add(*pShadowOverlayObject);
176  }
177  }
178  }
179 
180  return pShadowOverlayObject;
181 }
182 
184  const basegfx::B2DPoint& rSecondPosition,
185  Color aBaseColor )
186  : OverlayObjectWithBasePosition(rBasePos, aBaseColor)
187  , maSecondPosition(rSecondPosition)
188  , mShadowState(SS_NORMAL)
189 {
190 }
191 
193 {
194  if ( getOverlayManager() )
195  {
196  getOverlayManager()->remove(*this);
197  }
198 }
199 
201 {
205  GetShadowState() ) );
207 }
208 
210 {
211  if (mShadowState != aState)
212  {
213  mShadowState = aState;
214 
215  objectChange();
216  }
217 }
218 
220  const basegfx::B2DPoint& rPoint2)
221 {
222  if(!rPoint1.equal(getBasePosition()) || !rPoint2.equal(maSecondPosition))
223  {
224  maBasePosition = rPoint1;
225  maSecondPosition = rPoint2;
226 
227  objectChange();
228  }
229 }
230 
231 } } // end of namespace sw::sidebarwindows
232 
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void expand(const B2DTuple &rTuple)
rtl::Reference< sdr::overlay::OverlayManager > const & GetOverlayManager() const
#define DeclPrimitive2DIDBlock()
ShadowOverlayObject(const basegfx::B2DPoint &rBasePos, const basegfx::B2DPoint &rSecondPosition, Color aBaseColor)
bool equal(const B2DTuple &rTup) const
Dialog to specify the properties of date form field.
virtual bool operator==(const drawinglayer::primitive2d::BasePrimitive2D &rPrimitive) const override
OverlayManager * getOverlayManager() const
ShadowPrimitive(const basegfx::B2DPoint &rBasePosition, const basegfx::B2DPoint &rSecondPosition, ShadowState aShadowState)
void remove(OverlayObject &rOverlayObject)
virtual void create2DDecomposition(drawinglayer::primitive2d::Primitive2DContainer &rContainer, const drawinglayer::geometry::ViewInformation2D &rViewInformation) const override
#define F_PI
virtual drawinglayer::primitive2d::Primitive2DContainer createOverlayObjectPrimitive2DSequence() override
const basegfx::B2DPoint & getBasePosition() const
const basegfx::B2DPoint & getSecondPosition() const
#define PRIMITIVE2D_ID_SWSIDEBARSHADOWPRIMITIVE
void SetPosition(const basegfx::B2DPoint &rPoint1, const basegfx::B2DPoint &rPoint2)
css::uno::Reference< css::graphic::XPrimitive2D > Primitive2DReference
Definition: view.hxx:146
ImplPrimitive2DIDBlock(AnchorPrimitive, PRIMITIVE2D_ID_SWSIDEBARANCHORPRIMITIVE) std