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::sidebarwindows {
32 
33 // helper SwPostItShadowPrimitive
34 
35 namespace {
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 {
43 private:
47 
48 protected:
49  virtual void create2DDecomposition(
51  const drawinglayer::geometry::ViewInformation2D& rViewInformation) const override;
52 
53 public:
54  ShadowPrimitive(
55  const basegfx::B2DPoint& rBasePosition,
56  const basegfx::B2DPoint& rSecondPosition,
57  ShadowState aShadowState)
58  : drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D(),
59  maBasePosition(rBasePosition),
60  maSecondPosition(rSecondPosition),
61  maShadowState(aShadowState)
62  {}
63 
64  // data access
65  const basegfx::B2DPoint& getSecondPosition() const { return maSecondPosition; }
66 
67  virtual bool operator==( const drawinglayer::primitive2d::BasePrimitive2D& rPrimitive ) const override;
68 
69  virtual sal_uInt32 getPrimitive2DID() const override;
70 };
71 
72 }
73 
74 void ShadowPrimitive::create2DDecomposition(
76  const drawinglayer::geometry::ViewInformation2D& /*rViewInformation*/) const
77 {
78  // get logic sizes in object coordinate system
80 
81  switch(maShadowState)
82  {
83  case SS_NORMAL:
84  {
85  aRange.expand(basegfx::B2DTuple(getSecondPosition().getX(), getSecondPosition().getY() + (2.0 * getDiscreteUnit())));
86  const ::drawinglayer::attribute::FillGradientAttribute aFillGradientAttribute(
88  0.0,
89  0.5,
90  0.5,
91  F_PI,
92  basegfx::BColor(230.0/255.0,230.0/255.0,230.0/255.0),
93  basegfx::BColor(180.0/255.0,180.0/255.0,180.0/255.0));
94 
95  rContainer.push_back(
97  aRange,
98  aFillGradientAttribute));
99  break;
100  }
101  case SS_VIEW:
102  {
103  aRange.expand(basegfx::B2DTuple(getSecondPosition().getX(), getSecondPosition().getY() + (4.0 * getDiscreteUnit())));
104  const drawinglayer::attribute::FillGradientAttribute aFillGradientAttribute(
106  0.0,
107  0.5,
108  0.5,
109  F_PI,
110  basegfx::BColor(230.0/255.0,230.0/255.0,230.0/255.0),
111  basegfx::BColor(180.0/255.0,180.0/255.0,180.0/255.0));
112 
113  rContainer.push_back(
115  aRange,
116  aFillGradientAttribute));
117  break;
118  }
119  case SS_EDIT:
120  {
121  aRange.expand(basegfx::B2DTuple(getSecondPosition().getX(), getSecondPosition().getY() + (4.0 * getDiscreteUnit())));
122  const drawinglayer::attribute::FillGradientAttribute aFillGradientAttribute(
124  0.0,
125  0.5,
126  0.5,
127  F_PI,
128  basegfx::BColor(230.0/255.0,230.0/255.0,230.0/255.0),
129  basegfx::BColor(83.0/255.0,83.0/255.0,83.0/255.0));
130 
131  rContainer.push_back(
133  aRange,
134  aFillGradientAttribute));
135  break;
136  }
137  default:
138  {
139  break;
140  }
141  }
142 }
143 
144 bool ShadowPrimitive::operator==( const drawinglayer::primitive2d::BasePrimitive2D& rPrimitive ) const
145 {
146  if(drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D::operator==(rPrimitive))
147  {
148  const ShadowPrimitive& rCompare = static_cast< const ShadowPrimitive& >(rPrimitive);
149 
150  return (maBasePosition == rCompare.maBasePosition
151  && getSecondPosition() == rCompare.getSecondPosition()
152  && maShadowState == rCompare.maShadowState);
153  }
154 
155  return false;
156 }
157 
159 
160 /* static */ std::unique_ptr<ShadowOverlayObject> ShadowOverlayObject::CreateShadowOverlayObject( SwView const & rDocView )
161 {
162  std::unique_ptr<ShadowOverlayObject> pShadowOverlayObject;
163 
164  if ( rDocView.GetDrawView() )
165  {
166  SdrPaintWindow* pPaintWindow = rDocView.GetDrawView()->GetPaintWindow(0);
167  if( pPaintWindow )
168  {
169  const rtl::Reference< sdr::overlay::OverlayManager >& xOverlayManager = pPaintWindow->GetOverlayManager();
170 
171  if ( xOverlayManager.is() )
172  {
173  pShadowOverlayObject.reset( new ShadowOverlayObject( basegfx::B2DPoint(0,0),
174  basegfx::B2DPoint(0,0),
175  Color(0,0,0) ) );
176  xOverlayManager->add(*pShadowOverlayObject);
177  }
178  }
179  }
180 
181  return pShadowOverlayObject;
182 }
183 
185  const basegfx::B2DPoint& rSecondPosition,
186  Color aBaseColor )
187  : OverlayObjectWithBasePosition(rBasePos, aBaseColor)
188  , maSecondPosition(rSecondPosition)
189  , mShadowState(SS_NORMAL)
190 {
191 }
192 
194 {
195  if ( getOverlayManager() )
196  {
197  getOverlayManager()->remove(*this);
198  }
199 }
200 
202 {
204  new ShadowPrimitive( getBasePosition(),
206  GetShadowState() ) );
208 }
209 
211 {
212  if (mShadowState != aState)
213  {
214  mShadowState = aState;
215 
216  objectChange();
217  }
218 }
219 
221  const basegfx::B2DPoint& rPoint2)
222 {
223  if(!rPoint1.equal(getBasePosition()) || !rPoint2.equal(maSecondPosition))
224  {
225  maBasePosition = rPoint1;
226  maSecondPosition = rPoint2;
227 
228  objectChange();
229  }
230 }
231 
232 } // end of namespace sw::sidebarwindows
233 
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
rtl::Reference< sdr::overlay::OverlayManager > const & GetOverlayManager() const
ShadowOverlayObject(const basegfx::B2DPoint &rBasePos, const basegfx::B2DPoint &rSecondPosition, Color aBaseColor)
bool equal(const B2DTuple &rTup) const
ShadowState maShadowState
OverlayManager * getOverlayManager() const
void remove(OverlayObject &rOverlayObject)
virtual drawinglayer::primitive2d::Primitive2DContainer createOverlayObjectPrimitive2DSequence() override
const basegfx::B2DPoint & getBasePosition() const
css::uno::Reference< css::graphic::XPrimitive2D > Primitive2DReference
basegfx::B2DPoint maSecondPosition
#define PRIMITIVE2D_ID_SWSIDEBARSHADOWPRIMITIVE
void SetPosition(const basegfx::B2DPoint &rPoint1, const basegfx::B2DPoint &rPoint2)
basegfx::B2DPoint maBasePosition
bool operator==(const ScCsvLayoutData &rData1, const ScCsvLayoutData &rData2)
Definition: view.hxx:144
ImplPrimitive2DIDBlock(AnchorPrimitive, PRIMITIVE2D_ID_SWSIDEBARANCHORPRIMITIVE) std