Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /************************************************************************* *
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2008 by Sun Microsystems, Inc.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <AnchorOverlayObject.hxx>
30 : : #include <SidebarWindowsConsts.hxx>
31 : :
32 : : #include <swrect.hxx>
33 : : #include <view.hxx>
34 : : #include <svx/sdrpaintwindow.hxx>
35 : : #include <svx/svdview.hxx>
36 : : #include <svx/sdr/overlay/overlaymanager.hxx>
37 : :
38 : : #include <sw_primitivetypes2d.hxx>
39 : : #include <drawinglayer/primitive2d/primitivetools2d.hxx>
40 : : #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
41 : : #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
42 : : #include <drawinglayer/primitive2d/shadowprimitive2d.hxx>
43 : :
44 : : namespace sw { namespace sidebarwindows {
45 : :
46 : : //////////////////////////////////////////////////////////////////////////////
47 : : // helper class: Primitive for discrete visualisation
48 : :
49 [ + - ][ + - ]: 102 : class AnchorPrimitive : public drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D
[ + - ][ - + ]
50 : : {
51 : : private:
52 : : basegfx::B2DPolygon maTriangle;
53 : : basegfx::B2DPolygon maLine;
54 : : basegfx::B2DPolygon maLineTop;
55 : : const AnchorState maAnchorState;
56 : : basegfx::BColor maColor;
57 : :
58 : : // discrete line width
59 : : double mfLogicLineWidth;
60 : :
61 : : // bitfield
62 : : bool mbShadow : 1;
63 : : bool mbLineSolid : 1;
64 : :
65 : : protected:
66 : : virtual drawinglayer::primitive2d::Primitive2DSequence create2DDecomposition(
67 : : const drawinglayer::geometry::ViewInformation2D& rViewInformation) const;
68 : :
69 : : public:
70 : 54 : AnchorPrimitive( const basegfx::B2DPolygon& rTriangle,
71 : : const basegfx::B2DPolygon& rLine,
72 : : const basegfx::B2DPolygon& rLineTop,
73 : : AnchorState aAnchorState,
74 : : const basegfx::BColor& rColor,
75 : : double fLogicLineWidth,
76 : : bool bShadow,
77 : : bool bLineSolid )
78 : : : drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D(),
79 : : maTriangle(rTriangle),
80 : : maLine(rLine),
81 : : maLineTop(rLineTop),
82 : : maAnchorState(aAnchorState),
83 : : maColor(rColor),
84 : : mfLogicLineWidth(fLogicLineWidth),
85 : : mbShadow(bShadow),
86 [ + - ][ + - ]: 54 : mbLineSolid(bLineSolid)
[ + - ]
87 : 54 : {}
88 : :
89 : : // data access
90 : 54 : const basegfx::B2DPolygon& getTriangle() const { return maTriangle; }
91 : 36 : const basegfx::B2DPolygon& getLine() const { return maLine; }
92 : 36 : const basegfx::B2DPolygon& getLineTop() const { return maLineTop; }
93 : 0 : AnchorState getAnchorState() const { return maAnchorState; }
94 : 126 : const basegfx::BColor& getColor() const { return maColor; }
95 : 72 : double getLogicLineWidth() const { return mfLogicLineWidth; }
96 : 54 : bool getShadow() const { return mbShadow; }
97 : 36 : bool getLineSolid() const { return mbLineSolid; }
98 : :
99 : : virtual bool operator==( const drawinglayer::primitive2d::BasePrimitive2D& rPrimitive ) const;
100 : :
101 : : DeclPrimitrive2DIDBlock()
102 : : };
103 : :
104 : 54 : drawinglayer::primitive2d::Primitive2DSequence AnchorPrimitive::create2DDecomposition(
105 : : const drawinglayer::geometry::ViewInformation2D& /*rViewInformation*/) const
106 : : {
107 : 54 : drawinglayer::primitive2d::Primitive2DSequence aRetval;
108 : :
109 [ - + ][ # # ]: 54 : if ( AS_TRI == maAnchorState ||
[ + + ]
110 : : AS_ALL == maAnchorState ||
111 : : AS_START == maAnchorState )
112 : : {
113 : : // create triangle
114 : : const drawinglayer::primitive2d::Primitive2DReference aTriangle(
115 : : new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
116 : 54 : basegfx::B2DPolyPolygon(getTriangle()),
117 [ + - ][ + - ]: 54 : getColor()));
[ + - ][ + - ]
[ + - ]
118 : :
119 [ + - ]: 54 : drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, aTriangle);
120 : : }
121 : :
122 [ + + ][ - + ]: 54 : if ( AS_ALL == maAnchorState ||
123 : : AS_START == maAnchorState )
124 : : {
125 : : // create line start
126 : : const drawinglayer::attribute::LineAttribute aLineAttribute(
127 : 36 : getColor(),
128 [ - + ][ + - ]: 72 : getLogicLineWidth() / (basegfx::fTools::equalZero(getDiscreteUnit()) ? 1.0 : getDiscreteUnit()));
129 : :
130 [ - + ]: 36 : if(getLineSolid())
131 : : {
132 : : const drawinglayer::primitive2d::Primitive2DReference aSolidLine(
133 : : new drawinglayer::primitive2d::PolygonStrokePrimitive2D(
134 : : getLine(),
135 [ # # ][ # # ]: 0 : aLineAttribute));
[ # # ]
136 : :
137 [ # # ]: 0 : drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, aSolidLine);
138 : : }
139 : : else
140 : : {
141 [ + - ]: 36 : ::std::vector< double > aDotDashArray;
142 : 36 : const double fDistance(3.0 * 15.0);
143 : 36 : const double fDashLen(5.0 * 15.0);
144 : :
145 [ + - ]: 36 : aDotDashArray.push_back(fDashLen);
146 [ + - ]: 36 : aDotDashArray.push_back(fDistance);
147 : :
148 : : const drawinglayer::attribute::StrokeAttribute aStrokeAttribute(
149 : : aDotDashArray,
150 [ + - ]: 36 : fDistance + fDashLen);
151 : :
152 : : const drawinglayer::primitive2d::Primitive2DReference aStrokedLine(
153 : : new drawinglayer::primitive2d::PolygonStrokePrimitive2D(
154 : : getLine(),
155 : : aLineAttribute,
156 [ + - ][ + - ]: 36 : aStrokeAttribute));
[ + - ]
157 : :
158 [ + - ][ + - ]: 36 : drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, aStrokedLine);
159 [ + - ]: 36 : }
160 : : }
161 : :
162 [ + - ][ - + ]: 54 : if(aRetval.hasElements() && getShadow())
[ - + ]
163 : : {
164 : : // shadow is only for triangle and line start, and in upper left
165 : : // and lower right direction, in different colors
166 : 0 : const double fColorChange(20.0 / 255.0);
167 : 0 : const basegfx::B3DTuple aColorChange(fColorChange, fColorChange, fColorChange);
168 : 0 : basegfx::BColor aLighterColor(getColor() + aColorChange);
169 : 0 : basegfx::BColor aDarkerColor(getColor() - aColorChange);
170 : :
171 [ # # ]: 0 : aLighterColor.clamp();
172 [ # # ]: 0 : aDarkerColor.clamp();
173 : :
174 : : // create shadow sequence
175 [ # # ]: 0 : drawinglayer::primitive2d::Primitive2DSequence aShadows(2);
176 [ # # ]: 0 : basegfx::B2DHomMatrix aTransform;
177 : :
178 [ # # ]: 0 : aTransform.set(0, 2, -getDiscreteUnit());
179 [ # # ]: 0 : aTransform.set(1, 2, -getDiscreteUnit());
180 : :
181 [ # # ]: 0 : aShadows[0] = drawinglayer::primitive2d::Primitive2DReference(
182 : : new drawinglayer::primitive2d::ShadowPrimitive2D(
183 : : aTransform,
184 : : aLighterColor,
185 [ # # ][ # # ]: 0 : aRetval));
[ # # ][ # # ]
186 : :
187 [ # # ]: 0 : aTransform.set(0, 2, getDiscreteUnit());
188 [ # # ]: 0 : aTransform.set(1, 2, getDiscreteUnit());
189 : :
190 [ # # ]: 0 : aShadows[1] = drawinglayer::primitive2d::Primitive2DReference(
191 : : new drawinglayer::primitive2d::ShadowPrimitive2D(
192 : : aTransform,
193 : : aDarkerColor,
194 [ # # ][ # # ]: 0 : aRetval));
[ # # ][ # # ]
195 : :
196 : : // add shadow before geometry to make it be proccessed first
197 [ # # ]: 0 : const drawinglayer::primitive2d::Primitive2DSequence aTemporary(aRetval);
198 : :
199 [ # # ]: 0 : aRetval = aShadows;
200 [ # # ][ # # ]: 0 : drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(aRetval, aTemporary);
[ # # ][ # # ]
201 : : }
202 : :
203 [ + + ][ - + ]: 54 : if ( AS_ALL == maAnchorState ||
204 : : AS_END == maAnchorState )
205 : : {
206 : : // LineTop has to be created, too, but uses no shadow, so add after
207 : : // the other parts are created
208 : : const drawinglayer::attribute::LineAttribute aLineAttribute(
209 : 36 : getColor(),
210 [ - + ][ + - ]: 72 : getLogicLineWidth() / (basegfx::fTools::equalZero(getDiscreteUnit()) ? 1.0 : getDiscreteUnit()));
211 : :
212 : : const drawinglayer::primitive2d::Primitive2DReference aLineTop(
213 : : new drawinglayer::primitive2d::PolygonStrokePrimitive2D(
214 : : getLineTop(),
215 [ + - ][ + - ]: 36 : aLineAttribute));
[ + - ]
216 : :
217 [ + - ][ + - ]: 36 : drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, aLineTop);
218 : : }
219 : :
220 : 54 : return aRetval;
221 : : }
222 : :
223 : 0 : bool AnchorPrimitive::operator==( const drawinglayer::primitive2d::BasePrimitive2D& rPrimitive ) const
224 : : {
225 [ # # ]: 0 : if(drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D::operator==(rPrimitive))
226 : : {
227 : 0 : const AnchorPrimitive& rCompare = static_cast< const AnchorPrimitive& >(rPrimitive);
228 : :
229 : 0 : return (getTriangle() == rCompare.getTriangle()
230 : 0 : && getLine() == rCompare.getLine()
231 : 0 : && getLineTop() == rCompare.getLineTop()
232 : 0 : && getAnchorState() == rCompare.getAnchorState()
233 : 0 : && getColor() == rCompare.getColor()
234 : 0 : && getLogicLineWidth() == rCompare.getLogicLineWidth()
235 : 0 : && getShadow() == rCompare.getShadow()
236 [ # # ][ # # : 0 : && getLineSolid() == rCompare.getLineSolid());
# # # # #
# # # # #
# # ]
237 : : }
238 : :
239 : 0 : return false;
240 : : }
241 : :
242 : 6 : ImplPrimitrive2DIDBlock(AnchorPrimitive, PRIMITIVE2D_ID_SWSIDEBARANCHORPRIMITIVE)
243 : :
244 : : /****** AnchorOverlayObject ***********************************************************/
245 : 18 : /*static*/ AnchorOverlayObject* AnchorOverlayObject::CreateAnchorOverlayObject(
246 : : SwView& rDocView,
247 : : const SwRect& aAnchorRect,
248 : : const long& aPageBorder,
249 : : const Point& aLineStart,
250 : : const Point& aLineEnd,
251 : : const Color& aColorAnchor )
252 : : {
253 : 18 : AnchorOverlayObject* pAnchorOverlayObject( 0 );
254 [ + - ]: 18 : if ( rDocView.GetDrawView() )
255 : : {
256 : 18 : SdrPaintWindow* pPaintWindow = rDocView.GetDrawView()->GetPaintWindow(0);
257 [ + - ]: 18 : if( pPaintWindow )
258 : : {
259 [ + - ]: 18 : rtl::Reference< ::sdr::overlay::OverlayManager > xOverlayManager = pPaintWindow->GetOverlayManager();
260 : :
261 [ + - ]: 18 : if ( xOverlayManager.is() )
262 : : {
263 : : pAnchorOverlayObject = new AnchorOverlayObject(
264 : 18 : basegfx::B2DPoint( aAnchorRect.Left() , aAnchorRect.Bottom()-5*15),
265 : 18 : basegfx::B2DPoint( aAnchorRect.Left()-5*15 , aAnchorRect.Bottom()+5*15),
266 : 18 : basegfx::B2DPoint( aAnchorRect.Left()+5*15 , aAnchorRect.Bottom()+5*15),
267 : 18 : basegfx::B2DPoint( aAnchorRect.Left(), aAnchorRect.Bottom()+2*15),
268 : 18 : basegfx::B2DPoint( aPageBorder ,aAnchorRect.Bottom()+2*15),
269 : 18 : basegfx::B2DPoint( aLineStart.X(),aLineStart.Y()),
270 : 18 : basegfx::B2DPoint( aLineEnd.X(),aLineEnd.Y()) ,
271 : : aColorAnchor,
272 : : false,
273 [ + - ][ + - ]: 126 : false);
274 [ + - ]: 18 : xOverlayManager->add(*pAnchorOverlayObject);
275 [ + - ]: 18 : }
276 : : }
277 : : }
278 : :
279 : 18 : return pAnchorOverlayObject;
280 : : }
281 : :
282 : 15 : /*static*/ void AnchorOverlayObject::DestroyAnchorOverlayObject( AnchorOverlayObject* pAnchor )
283 : : {
284 [ + - ]: 15 : if ( pAnchor )
285 : : {
286 [ + - ]: 15 : if ( pAnchor->getOverlayManager() )
287 : : {
288 : : // remove this object from the chain
289 : 15 : pAnchor->getOverlayManager()->remove(*pAnchor);
290 : : }
291 [ + - ]: 15 : delete pAnchor;
292 : : }
293 : 15 : }
294 : :
295 : 18 : AnchorOverlayObject::AnchorOverlayObject( const basegfx::B2DPoint& rBasePos,
296 : : const basegfx::B2DPoint& rSecondPos,
297 : : const basegfx::B2DPoint& rThirdPos,
298 : : const basegfx::B2DPoint& rFourthPos,
299 : : const basegfx::B2DPoint& rFifthPos,
300 : : const basegfx::B2DPoint& rSixthPos,
301 : : const basegfx::B2DPoint& rSeventhPos,
302 : : const Color aBaseColor,
303 : : const bool bShadowedEffect,
304 : : const bool bLineSolid)
305 : : : OverlayObjectWithBasePosition( rBasePos, aBaseColor )
306 : : , maSecondPosition(rSecondPos)
307 : : , maThirdPosition(rThirdPos)
308 : : , maFourthPosition(rFourthPos)
309 : : , maFifthPosition(rFifthPos)
310 : : , maSixthPosition(rSixthPos)
311 : : , maSeventhPosition(rSeventhPos)
312 : : , maTriangle()
313 : : , maLine()
314 : : , maLineTop()
315 : : , mHeight(0)
316 : : , mAnchorState(AS_ALL)
317 : : , mbShadowedEffect(bShadowedEffect)
318 [ + - ][ + - ]: 18 : , mbLineSolid(bLineSolid)
[ + - ]
319 : : {
320 : 18 : }
321 : :
322 [ + - ][ + - ]: 15 : AnchorOverlayObject::~AnchorOverlayObject()
[ + - ]
323 : : {
324 [ - + ]: 30 : }
325 : :
326 : 54 : void AnchorOverlayObject::implEnsureGeometry()
327 : : {
328 [ + + ]: 54 : if(!maTriangle.count())
329 : : {
330 : 18 : maTriangle.append(getBasePosition());
331 : 18 : maTriangle.append(GetSecondPosition());
332 : 18 : maTriangle.append(GetThirdPosition());
333 : 18 : maTriangle.setClosed(true);
334 : : }
335 : :
336 [ + + ]: 54 : if(!maLine.count())
337 : : {
338 : 18 : maLine.append(GetFourthPosition());
339 : 18 : maLine.append(GetFifthPosition());
340 : 18 : maLine.append(GetSixthPosition());
341 : : }
342 : :
343 [ + + ]: 54 : if(!maLineTop.count())
344 : : {
345 : 18 : maLineTop.append(GetSixthPosition());
346 : 18 : maLineTop.append(GetSeventhPosition());
347 : : }
348 : 54 : }
349 : :
350 : 0 : void AnchorOverlayObject::implResetGeometry()
351 : : {
352 : 0 : maTriangle.clear();
353 : 0 : maLine.clear();
354 : 0 : maLineTop.clear();
355 : 0 : }
356 : :
357 : 54 : drawinglayer::primitive2d::Primitive2DSequence AnchorOverlayObject::createOverlayObjectPrimitive2DSequence()
358 : : {
359 [ + - ]: 54 : implEnsureGeometry();
360 : :
361 : : const drawinglayer::primitive2d::Primitive2DReference aReference(
362 : : new AnchorPrimitive( maTriangle,
363 : : maLine,
364 : : maLineTop,
365 : : GetAnchorState(),
366 : 54 : getBaseColor().getBColor(),
367 : : ANCHORLINE_WIDTH * 15.0,
368 : 54 : getShadowedEffect(),
369 [ + - ][ + - ]: 108 : getLineSolid()) );
[ + - ]
370 : :
371 [ + - ]: 54 : return drawinglayer::primitive2d::Primitive2DSequence(&aReference, 1);
372 : : }
373 : :
374 : 0 : void AnchorOverlayObject::SetAllPosition( const basegfx::B2DPoint& rPoint1,
375 : : const basegfx::B2DPoint& rPoint2,
376 : : const basegfx::B2DPoint& rPoint3,
377 : : const basegfx::B2DPoint& rPoint4,
378 : : const basegfx::B2DPoint& rPoint5,
379 : : const basegfx::B2DPoint& rPoint6,
380 : : const basegfx::B2DPoint& rPoint7)
381 : : {
382 [ # # # # : 0 : if ( rPoint1 != getBasePosition() ||
# # # # #
# # # #
# ][ # # ]
383 : 0 : rPoint2 != GetSecondPosition() ||
384 : 0 : rPoint3 != GetThirdPosition() ||
385 : 0 : rPoint4 != GetFourthPosition() ||
386 : 0 : rPoint5 != GetFifthPosition() ||
387 : 0 : rPoint6 != GetSixthPosition() ||
388 : 0 : rPoint7 != GetSeventhPosition() )
389 : : {
390 : 0 : maBasePosition = rPoint1;
391 : 0 : maSecondPosition = rPoint2;
392 : 0 : maThirdPosition = rPoint3;
393 : 0 : maFourthPosition = rPoint4;
394 : 0 : maFifthPosition = rPoint5;
395 : 0 : maSixthPosition = rPoint6;
396 : 0 : maSeventhPosition = rPoint7;
397 : :
398 : 0 : implResetGeometry();
399 : 0 : objectChange();
400 : : }
401 : 0 : }
402 : :
403 : 0 : void AnchorOverlayObject::SetSixthPosition(const basegfx::B2DPoint& rNew)
404 : : {
405 [ # # ]: 0 : if(rNew != maSixthPosition)
406 : : {
407 : 0 : maSixthPosition = rNew;
408 : 0 : implResetGeometry();
409 : 0 : objectChange();
410 : : }
411 : 0 : }
412 : :
413 : 0 : void AnchorOverlayObject::SetSeventhPosition(const basegfx::B2DPoint& rNew)
414 : : {
415 [ # # ]: 0 : if(rNew != maSeventhPosition)
416 : : {
417 : 0 : maSeventhPosition = rNew;
418 : 0 : implResetGeometry();
419 : 0 : objectChange();
420 : : }
421 : 0 : }
422 : :
423 : 0 : void AnchorOverlayObject::SetTriPosition(const basegfx::B2DPoint& rPoint1,const basegfx::B2DPoint& rPoint2,const basegfx::B2DPoint& rPoint3,
424 : : const basegfx::B2DPoint& rPoint4,const basegfx::B2DPoint& rPoint5)
425 : : {
426 [ # # # # : 0 : if(rPoint1 != getBasePosition()
# # # # #
# ][ # # ]
427 : 0 : || rPoint2 != GetSecondPosition()
428 : 0 : || rPoint3 != GetThirdPosition()
429 : 0 : || rPoint4 != GetFourthPosition()
430 : 0 : || rPoint5 != GetFifthPosition())
431 : : {
432 : 0 : maBasePosition = rPoint1;
433 : 0 : maSecondPosition = rPoint2;
434 : 0 : maThirdPosition = rPoint3;
435 : 0 : maFourthPosition = rPoint4;
436 : 0 : maFifthPosition = rPoint5;
437 : :
438 : 0 : implResetGeometry();
439 : 0 : objectChange();
440 : : }
441 : 0 : }
442 : :
443 : 0 : void AnchorOverlayObject::setLineSolid( const bool bNew )
444 : : {
445 [ # # ]: 0 : if ( bNew != getLineSolid() )
446 : : {
447 : 0 : mbLineSolid = bNew;
448 : 0 : objectChange();
449 : : }
450 : 0 : }
451 : :
452 : 96 : void AnchorOverlayObject::SetAnchorState( const AnchorState aState)
453 : : {
454 [ + + ]: 96 : if ( mAnchorState != aState)
455 : : {
456 : 36 : mAnchorState = aState;
457 : 36 : objectChange();
458 : : }
459 : 96 : }
460 : :
461 : : } } // end of namespace sw::annotation
462 : :
463 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|