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
21
22#include <view.hxx>
24#include <svx/svdview.hxx>
26
31
32namespace sw::sidebarwindows {
33
34// helper SwPostItShadowPrimitive
35
36namespace {
37
38// Used to allow view-dependent primitive definition. For that purpose, the
39// initially created primitive (this one) always has to be view-independent,
40// but the decomposition is made view-dependent. Very simple primitive which
41// just remembers the discrete data and applies it at decomposition time.
43{
44private:
48
49protected:
50 virtual void create2DDecomposition(
52 const drawinglayer::geometry::ViewInformation2D& rViewInformation) const override;
53
54public:
55 ShadowPrimitive(
56 const basegfx::B2DPoint& rBasePosition,
57 const basegfx::B2DPoint& rSecondPosition,
58 ShadowState aShadowState)
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
74void 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
88 css::awt::GradientStyle_LINEAR,
89 0.0,
90 0.5,
91 0.5,
92 M_PI,
94 basegfx::BColor(230.0/255.0,230.0/255.0,230.0/255.0),
95 basegfx::BColor(180.0/255.0,180.0/255.0,180.0/255.0)));
96
97 rContainer.push_back(
99 aRange,
100 std::move(aFillGradientAttribute)));
101 break;
102 }
103 case SS_VIEW:
104 {
105 aRange.expand(basegfx::B2DTuple(getSecondPosition().getX(), getSecondPosition().getY() + (4.0 * getDiscreteUnit())));
107 css::awt::GradientStyle_LINEAR,
108 0.0,
109 0.5,
110 0.5,
111 M_PI,
113 basegfx::BColor(230.0/255.0,230.0/255.0,230.0/255.0),
114 basegfx::BColor(180.0/255.0,180.0/255.0,180.0/255.0)));
115
116 rContainer.push_back(
118 aRange,
119 std::move(aFillGradientAttribute)));
120 break;
121 }
122 case SS_EDIT:
123 {
124 aRange.expand(basegfx::B2DTuple(getSecondPosition().getX(), getSecondPosition().getY() + (4.0 * getDiscreteUnit())));
126 css::awt::GradientStyle_LINEAR,
127 0.0,
128 0.5,
129 0.5,
130 M_PI,
132 basegfx::BColor(230.0/255.0,230.0/255.0,230.0/255.0),
133 basegfx::BColor(83.0/255.0,83.0/255.0,83.0/255.0)));
134
135 rContainer.push_back(
137 aRange,
138 std::move(aFillGradientAttribute)));
139 break;
140 }
141 default:
142 {
143 break;
144 }
145 }
146}
147
148bool ShadowPrimitive::operator==( const drawinglayer::primitive2d::BasePrimitive2D& rPrimitive ) const
149{
150 if(drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D::operator==(rPrimitive))
151 {
152 const ShadowPrimitive& rCompare = static_cast< const ShadowPrimitive& >(rPrimitive);
153
154 return (maBasePosition == rCompare.maBasePosition
155 && getSecondPosition() == rCompare.getSecondPosition()
156 && maShadowState == rCompare.maShadowState);
157 }
158
159 return false;
160}
161
162sal_uInt32 ShadowPrimitive::getPrimitive2DID() const
163{
165}
166
167/* static */ std::unique_ptr<ShadowOverlayObject> ShadowOverlayObject::CreateShadowOverlayObject( SwView const & rDocView )
168{
169 std::unique_ptr<ShadowOverlayObject> pShadowOverlayObject;
170
171 if ( rDocView.GetDrawView() )
172 {
173 SdrPaintWindow* pPaintWindow = rDocView.GetDrawView()->GetPaintWindow(0);
174 if( pPaintWindow )
175 {
176 const rtl::Reference< sdr::overlay::OverlayManager >& xOverlayManager = pPaintWindow->GetOverlayManager();
177
178 if ( xOverlayManager.is() )
179 {
180 pShadowOverlayObject.reset( new ShadowOverlayObject( basegfx::B2DPoint(0,0),
182 Color(0,0,0) ) );
183 xOverlayManager->add(*pShadowOverlayObject);
184 }
185 }
186 }
187
188 return pShadowOverlayObject;
189}
190
192 const basegfx::B2DPoint& rSecondPosition,
193 Color aBaseColor )
194 : OverlayObjectWithBasePosition(rBasePos, aBaseColor)
195 , maSecondPosition(rSecondPosition)
196 , mShadowState(SS_NORMAL)
197{
198}
199
201{
202 if ( getOverlayManager() )
203 {
204 getOverlayManager()->remove(*this);
205 }
206}
207
209{
211 new ShadowPrimitive( getBasePosition(),
213 GetShadowState() ) );
215}
216
218{
219 if (mShadowState != aState)
220 {
221 mShadowState = aState;
222
223 objectChange();
224 }
225}
226
228 const basegfx::B2DPoint& rPoint2)
229{
230 if(!rPoint1.equal(getBasePosition()) || !rPoint2.equal(maSecondPosition))
231 {
232 maBasePosition = rPoint1;
233 maSecondPosition = rPoint2;
234
235 objectChange();
236 }
237}
238
239} // end of namespace sw::sidebarwindows
240
241/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ShadowState maShadowState
basegfx::B2DPoint maBasePosition
basegfx::B2DPoint maSecondPosition
SdrPaintWindow * GetPaintWindow(sal_uInt32 nIndex) const
rtl::Reference< sdr::overlay::OverlayManager > const & GetOverlayManager() const
Definition: view.hxx:146
virtual SdrView * GetDrawView() const override
Definition: viewdraw.cxx:621
bool equal(const Tuple2D< TYPE > &rTup) const
void remove(OverlayObject &rOverlayObject)
const basegfx::B2DPoint & getBasePosition() const
OverlayManager * getOverlayManager() const
ShadowOverlayObject(const basegfx::B2DPoint &rBasePos, const basegfx::B2DPoint &rSecondPosition, Color aBaseColor)
virtual drawinglayer::primitive2d::Primitive2DContainer createOverlayObjectPrimitive2DSequence() override
static std::unique_ptr< ShadowOverlayObject > CreateShadowOverlayObject(SwView const &rDocView)
void SetPosition(const basegfx::B2DPoint &rPoint1, const basegfx::B2DPoint &rPoint2)
#define PRIMITIVE2D_ID_SWSIDEBARSHADOWPRIMITIVE
bool operator==(const XclFontData &rLeft, const XclFontData &rRight)