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 
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  2);
95 
96  rContainer.push_back(
98  aRange,
99  aFillGradientAttribute));
100  break;
101  }
102  case SS_VIEW:
103  {
104  aRange.expand(basegfx::B2DTuple(getSecondPosition().getX(), getSecondPosition().getY() + (4.0 * getDiscreteUnit())));
105  const drawinglayer::attribute::FillGradientAttribute aFillGradientAttribute(
107  0.0,
108  0.5,
109  0.5,
110  F_PI,
111  basegfx::BColor(230.0/255.0,230.0/255.0,230.0/255.0),
112  basegfx::BColor(180.0/255.0,180.0/255.0,180.0/255.0),
113  4);
114 
115  rContainer.push_back(
117  aRange,
118  aFillGradientAttribute));
119  break;
120  }
121  case SS_EDIT:
122  {
123  aRange.expand(basegfx::B2DTuple(getSecondPosition().getX(), getSecondPosition().getY() + (4.0 * getDiscreteUnit())));
124  const drawinglayer::attribute::FillGradientAttribute aFillGradientAttribute(
126  0.0,
127  0.5,
128  0.5,
129  F_PI,
130  basegfx::BColor(230.0/255.0,230.0/255.0,230.0/255.0),
131  basegfx::BColor(83.0/255.0,83.0/255.0,83.0/255.0),
132  4);
133 
134  rContainer.push_back(
136  aRange,
137  aFillGradientAttribute));
138  break;
139  }
140  default:
141  {
142  break;
143  }
144  }
145 }
146 
147 bool ShadowPrimitive::operator==( const drawinglayer::primitive2d::BasePrimitive2D& rPrimitive ) const
148 {
149  if(drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D::operator==(rPrimitive))
150  {
151  const ShadowPrimitive& rCompare = static_cast< const ShadowPrimitive& >(rPrimitive);
152 
153  return (maBasePosition == rCompare.maBasePosition
154  && getSecondPosition() == rCompare.getSecondPosition()
155  && maShadowState == rCompare.maShadowState);
156  }
157 
158  return false;
159 }
160 
162 
163 /* static */ std::unique_ptr<ShadowOverlayObject> ShadowOverlayObject::CreateShadowOverlayObject( SwView const & rDocView )
164 {
165  std::unique_ptr<ShadowOverlayObject> pShadowOverlayObject;
166 
167  if ( rDocView.GetDrawView() )
168  {
169  SdrPaintWindow* pPaintWindow = rDocView.GetDrawView()->GetPaintWindow(0);
170  if( pPaintWindow )
171  {
172  const rtl::Reference< sdr::overlay::OverlayManager >& xOverlayManager = pPaintWindow->GetOverlayManager();
173 
174  if ( xOverlayManager.is() )
175  {
176  pShadowOverlayObject.reset( new ShadowOverlayObject( basegfx::B2DPoint(0,0),
177  basegfx::B2DPoint(0,0),
178  Color(0,0,0) ) );
179  xOverlayManager->add(*pShadowOverlayObject);
180  }
181  }
182  }
183 
184  return pShadowOverlayObject;
185 }
186 
188  const basegfx::B2DPoint& rSecondPosition,
189  Color aBaseColor )
190  : OverlayObjectWithBasePosition(rBasePos, aBaseColor)
191  , maSecondPosition(rSecondPosition)
192  , mShadowState(SS_NORMAL)
193 {
194 }
195 
197 {
198  if ( getOverlayManager() )
199  {
200  getOverlayManager()->remove(*this);
201  }
202 }
203 
205 {
207  new ShadowPrimitive( getBasePosition(),
209  GetShadowState() ) );
211 }
212 
214 {
215  if (mShadowState != aState)
216  {
217  mShadowState = aState;
218 
219  objectChange();
220  }
221 }
222 
224  const basegfx::B2DPoint& rPoint2)
225 {
226  if(!rPoint1.equal(getBasePosition()) || !rPoint2.equal(maSecondPosition))
227  {
228  maBasePosition = rPoint1;
229  maSecondPosition = rPoint2;
230 
231  objectChange();
232  }
233 }
234 
235 } // end of namespace sw::sidebarwindows
236 
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
rtl::Reference< sdr::overlay::OverlayManager > const & GetOverlayManager() const
#define DeclPrimitive2DIDBlock()
ShadowOverlayObject(const basegfx::B2DPoint &rBasePos, const basegfx::B2DPoint &rSecondPosition, Color aBaseColor)
ShadowState const maShadowState
basegfx::B2DPoint const maBasePosition
bool equal(const B2DTuple &rTup) const
OverlayManager * getOverlayManager() const
void remove(OverlayObject &rOverlayObject)
virtual drawinglayer::primitive2d::Primitive2DContainer createOverlayObjectPrimitive2DSequence() override
basegfx::B2DPoint const maSecondPosition
const basegfx::B2DPoint & getBasePosition() const
css::uno::Reference< css::graphic::XPrimitive2D > Primitive2DReference
#define PRIMITIVE2D_ID_SWSIDEBARSHADOWPRIMITIVE
void SetPosition(const basegfx::B2DPoint &rPoint1, const basegfx::B2DPoint &rPoint2)
bool operator==(const ScCsvLayoutData &rData1, const ScCsvLayoutData &rData2)
Definition: view.hxx:146
ImplPrimitive2DIDBlock(AnchorPrimitive, PRIMITIVE2D_ID_SWSIDEBARANCHORPRIMITIVE) std