1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: shapeattributelayer.hxx,v $
10 * $Revision: 1.8.30.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef INCLUDED_SLIDESHOW_SHAPEATTRIBUTELAYER_HXX
32 #define INCLUDED_SLIDESHOW_SHAPEATTRIBUTELAYER_HXX
34 #include <com/sun/star/drawing/FillStyle.hpp>
35 #include <com/sun/star/drawing/LineStyle.hpp>
36 #include <com/sun/star/awt/FontSlant.hpp>
38 #include <basegfx/vector/b2dsize.hxx>
39 #include <basegfx/point/b2dpoint.hxx>
40 #include <basegfx/range/b2drectangle.hxx>
41 #include <basegfx/polygon/b2dpolypolygon.hxx>
44 #include "rgbcolor.hxx"
47 #include <boost/shared_ptr.hpp>
54 class ShapeAttributeLayer
;
56 typedef ::boost::shared_ptr
< ShapeAttributeLayer
> ShapeAttributeLayerSharedPtr
;
58 /** Encapsulates all modifiable attributes of a shape.
60 This class holds all modifiable attributes of a shape, and
61 at the same time provides means to layer attributes on top
64 And yes, there's a reason why we even pass bools and ints
65 by const reference. Namely, that makes the set* methods
66 differ only in the value type, which greatly reduces
67 template variability (e.g. in AnimationFactory).
69 class ShapeAttributeLayer
72 /** Create a ShapeAttributeLayer instance, with all
73 attributes set to default.
75 Furthermore, this constructor gets a pointer to a
76 child layer, which is used as the fallback (or the
77 base value) for all attributes
83 This method is only supposed to be called from Shape objects
85 explicit ShapeAttributeLayer( const ShapeAttributeLayerSharedPtr
& rChildLayer
);
87 // Children management methods
88 //------------------------------------------------------------------
90 /** Revoke the given layer.
92 This method revokes the given layer from this object
93 or one of the children. That is, if this object does
94 have children, and the given layer is no direct child,
95 it is recursively passed to the children for removal.
97 @return true, if removal was successful.
100 This method is only supposed to be called from Shape objects
102 bool revokeChildLayer( const ShapeAttributeLayerSharedPtr
& rChildLayer
);
104 /** Query the child layer of this object.
107 This method is only supposed to be called from Shape objects
109 ShapeAttributeLayerSharedPtr
getChildLayer() const;
111 /** Set the additive mode for possible child attributes
113 This method sets the additive mode for child
114 attributes. That is the way underlying attribute
115 layers are combined with this one (i.e. to overrule
116 lower layers, or how to combine the values). The
118 ::com::sun::star::animations::AnimationAdditiveMode::BASE,
119 which means, take the value of the underlying layers,
120 or from the model shape itself.
124 ::com::sun::star::animations::AnimationAdditiveMode.
126 void setAdditiveMode( sal_Int16 nMode
);
129 //------------------------------------------------------------------
131 /** Query whether the width attribute is valid.
133 bool isWidthValid() const;
134 /** Query the current width of the shape
136 double getWidth() const;
137 /** Set the new width of the shape
140 A negative width mirrors the shape.
142 void setWidth( const double& rNewWidth
);
144 /** Query whether the height attribute is valid.
146 bool isHeightValid() const;
147 /** Query the current height of the shape
149 double getHeight() const;
150 /** Set the new height of the shape
153 A negative height mirrors the shape.
155 void setHeight( const double& rNewHeight
);
157 /** Set the new size of the shape
160 A negative size mirrors the shape.
162 void setSize( const ::basegfx::B2DSize
& rNewSize
);
164 /** Query whether the x position attribute is valid
166 bool isPosXValid() const;
167 /** Query the current x position of the shape.
169 The current x position of the shape is always relative
170 to the <em>center</em> of the shape (in contrast to
171 the Shape::getBounds() and Shape::getUpdateArea()
174 double getPosX() const;
175 /** Set the new x position of the shape
177 The current x position of the shape is always relative
178 to the <em>center</em> of the shape (in contrast to
179 the Shape::getBounds() and Shape::getUpdateArea()
182 void setPosX( const double& rNewX
);
184 /** Query whether the y position attribute is valid
186 bool isPosYValid() const;
187 /** Query the current y position of the shape
189 The current y position of the shape is always relative
190 to the <em>center</em> of the shape (in contrast to
191 the Shape::getBounds() and Shape::getUpdateArea()
194 double getPosY() const;
195 /** Set the new y position of the shape
197 The current y position of the shape is always relative
198 to the <em>center</em> of the shape (in contrast to
199 the Shape::getBounds() and Shape::getUpdateArea()
202 void setPosY( const double& rNewY
);
204 /** Set the new position of the shape
206 The current position of the shape is always relative
207 to the <em>center</em> of the shape (in contrast to
208 the Shape::getBounds() and Shape::getUpdateArea()
211 void setPosition( const ::basegfx::B2DPoint
& rNewPos
);
213 /** Query whether the rotation angle attribute is valid
215 bool isRotationAngleValid() const;
216 /** Query the current rotation angle of the shape
218 @return the rotation angle in degrees.
220 double getRotationAngle() const;
221 /** Set the new rotation angle of the shape
224 New rotation angle in degrees.
226 void setRotationAngle( const double& rNewAngle
);
228 /** Query whether the shear x angle attribute is valid
230 bool isShearXAngleValid() const;
231 /** Query the current shear angle at the x axis of the shape
233 @return the shear angle in degrees.
235 double getShearXAngle() const;
236 /** Set the new shear angle at the x axis of the shape
239 New shear angle in radians.
241 void setShearXAngle( const double& rNewAngle
);
243 /** Query whether the shear y angle attribute is valid
245 bool isShearYAngleValid() const;
246 /** Query the current shear angle at the y axis of the shape
248 @return the shear angle in degrees.
250 double getShearYAngle() const;
251 /** Set the new shear angle at the y axis of the shape
254 New shear angle in radians.
256 void setShearYAngle( const double& rNewAngle
);
258 /** Query whether the alpha attribute is valid
260 bool isAlphaValid() const;
261 /** Query the current alpha value of the shape
263 double getAlpha() const;
264 /** Set the new alpha value of the shape
267 New alpha value, must be in the [0,1] range
269 void setAlpha( const double& rNewValue
);
271 /** Query whether the clip attribute is valid
273 bool isClipValid() const;
274 /** Query the current clip polygon of the shape
276 ::basegfx::B2DPolyPolygon
getClip() const;
277 /** Set the new clip polygon of the shape
280 New clip polygon, is interpreted in shape view coordinates, but
281 relative to the shape (i.e. the origin of the shape coincides
282 with the origin of the clip polygon).
284 void setClip( const ::basegfx::B2DPolyPolygon
& rNewClip
);
286 /** Query whether the dim color attribute is valid
288 The dim color globally 'dims' the shape towards that
291 bool isDimColorValid() const;
292 /** Get the dim color for the whole shape.
294 RGBColor
getDimColor() const;
295 /** Set the dim color globally for the whole shape.
297 void setDimColor( const RGBColor
& nNewColor
);
299 /** Query whether the fill color attribute is valid
301 bool isFillColorValid() const;
302 /** Get the fill color for the whole shape.
304 If there's no unique fill color, the color from the
305 first filled polygon is returned.
307 RGBColor
getFillColor() const;
308 /** Set the fill color globally for the whole shape.
310 void setFillColor( const RGBColor
& nNewColor
);
312 /** Query whether the line color attribute is valid
314 bool isLineColorValid() const;
315 /** Get the line color for the whole shape.
317 If there's no unique line color, the color from the
318 first line is returned.
320 RGBColor
getLineColor() const;
321 /** Set the line color globally for the whole shape.
323 void setLineColor( const RGBColor
& nNewColor
);
325 /** Query whether the fill mode attribute is valid
327 bool isFillStyleValid() const;
328 /** Get the current fill mode for polygon fillings.
330 @returns the current style
332 sal_Int16
getFillStyle() const;
333 /** Changes polygon fillings.
335 void setFillStyle( const sal_Int16
& rStyle
);
337 /** Query whether the line mode attribute is valid
339 bool isLineStyleValid() const;
340 /** Get the current line mode for line drawing.
342 @returns the current line style
344 sal_Int16
getLineStyle() const;
345 /** Set line style for the whole shape
347 void setLineStyle( const sal_Int16
& rStyle
);
349 /** Query whether the visibility state attribute is valid
351 bool isVisibilityValid() const;
352 /** Get the current shape visibility.
354 @returns true for visible, false for invisible.
356 bool getVisibility() const;
357 /** Set the shape visibility
359 void setVisibility( const bool& bVisible
);
361 /** Query whether the char color attribute is valid
363 bool isCharColorValid() const;
364 /** Get the text color for the whole shape.
366 If there's no unique text color, the color from the
367 first text drawn is returned.
369 RGBColor
getCharColor() const;
370 /** Set the text color globally for the whole shape.
372 void setCharColor( const RGBColor
& nNewColor
);
374 /** Query whether the char rotation angle attribute is valid
376 bool isCharRotationAngleValid() const;
377 /** Query the current text rotation angle of the shape
379 @return the text rotation angle in degrees.
381 double getCharRotationAngle() const;
382 /** Set the new text rotation angle of the shape
385 New text rotation angle in degrees.
387 void setCharRotationAngle( const double& rNewAngle
);
389 /** Query whether the char weight attribute is valid
391 bool isCharWeightValid() const;
392 /** Get the current char weight value for the whole shape.
394 @returns the value for the char weight. The value must
395 be out of the ::com::sun::star::awt::FontWeight
398 double getCharWeight() const;
399 /** Set the char weight globally for the whole shape.
401 The value must be out of the
402 ::com::sun::star::awt::FontWeight constant group.
404 void setCharWeight( const double& rStyle
);
406 /** Query whether the underline mode attribute is valid
408 bool isUnderlineModeValid() const;
409 /** Get the current text underline status for the whole shape.
411 If there is no unique underline status, false is returned.
413 @returns true for underlined text, false for normal.
415 sal_Int16
getUnderlineMode() const;
416 /** Set the underline status globally for the whole shape
418 void setUnderlineMode( const sal_Int16
& bUnderline
);
420 /** Query whether the font family attribute is valid
422 bool isFontFamilyValid() const;
423 /** Get the current text font family for the whole shape.
425 If there is no unique font family, the font family of
426 the first text of the shape is returned.
428 ::rtl::OUString
getFontFamily() const;
429 /** Set the text font family name globally for the whole shape
431 void setFontFamily( const ::rtl::OUString
& rName
);
433 /** Query whether the italic mode attribute is valid
435 bool isCharPostureValid() const;
436 /** Get the current text italic style for the whole shape.
438 @returns the italic style. The value returned is one
439 of the ::com::sun::star::awt::FontSlant enums
441 sal_Int16
getCharPosture() const;
442 /** Set the italic style globally for the whole shape.
444 The value must be one of the
445 ::com::sun::star::awt::FontSlant enums.
447 void setCharPosture( const sal_Int16
& rStyle
);
449 /** Query whether the char scaling attribute is valid
451 bool isCharScaleValid() const;
452 /** Query the current char scaling attribute globally for
455 The char scaling changes the scale of the whole shape
456 text (uniformely, i.e. both in x and in y direction).
458 double getCharScale() const;
459 /** Set the new char scale globally for the shape
464 void setCharScale( const double& rNewScale
);
466 // State change query methods
467 // ==========================
469 State::StateId
getTransformationState() const;
470 State::StateId
getClipState() const;
471 State::StateId
getAlphaState() const;
472 State::StateId
getPositionState() const;
473 State::StateId
getContentState() const;
474 State::StateId
getVisibilityState() const;
477 // default copy/assignment operator is okay
478 // ShapeAttributeLayer(const ShapeAttributeLayer&);
479 // ShapeAttributeLayer& operator=( const ShapeAttributeLayer& );
481 bool haveChild() const { return mpChild
; }
482 void updateStateIds();
484 template< typename T
> T
calcValue( const T
& rCurrValue
,
485 bool bThisInstanceValid
,
486 bool (ShapeAttributeLayer::*pIsValid
)() const,
487 T (ShapeAttributeLayer::*pGetValue
)() const ) const;
489 ShapeAttributeLayerSharedPtr mpChild
; // may be NULL
491 ::basegfx::B2DSize maSize
;
492 ::basegfx::B2DPoint maPosition
;
493 ::basegfx::B2DPolyPolygon maClip
;
495 ::rtl::OUString maFontFamily
;
497 double mnRotationAngle
;
498 double mnShearXAngle
;
499 double mnShearYAngle
;
501 double mnCharRotationAngle
;
505 ::com::sun::star::drawing::FillStyle meFillStyle
;
506 ::com::sun::star::drawing::LineStyle meLineStyle
;
507 ::com::sun::star::awt::FontSlant meCharPosture
;
508 sal_Int16 mnUnderlineMode
;
511 RGBColor maFillColor
;
512 RGBColor maLineColor
;
513 RGBColor maCharColor
;
515 State::StateId mnTransformationState
;
516 State::StateId mnClipState
;
517 State::StateId mnAlphaState
;
518 State::StateId mnPositionState
;
519 State::StateId mnContentState
;
520 State::StateId mnVisibilityState
;
522 sal_Int16 mnAdditiveMode
;
524 bool mbVisibility
: 1;
526 bool mbWidthValid
: 1;
527 bool mbHeightValid
: 1;
528 bool mbPosXValid
: 1;
529 bool mbPosYValid
: 1;
530 bool mbClipValid
: 1;
532 bool mbFontFamilyValid
: 1;
534 bool mbRotationAngleValid
: 1;
535 bool mbShearXAngleValid
: 1;
536 bool mbShearYAngleValid
: 1;
538 bool mbAlphaValid
: 1;
540 bool mbCharRotationAngleValid
: 1;
541 bool mbCharScaleValid
: 1;
543 bool mbDimColorValid
: 1;
544 bool mbFillColorValid
: 1;
545 bool mbLineColorValid
: 1;
546 bool mbCharColorValid
: 1;
548 bool mbFillStyleValid
: 1;
549 bool mbLineStyleValid
: 1;
550 bool mbCharWeightValid
: 1;
551 bool mbUnderlineModeValid
: 1;
552 bool mbCharPostureValid
: 1;
553 bool mbVisibilityValid
: 1;
559 #endif /* INCLUDED_SLIDESHOW_SHAPEATTRIBUTELAYER_HXX */