1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef INCLUDED_SLIDESHOW_SHAPEATTRIBUTELAYER_HXX
29 #define INCLUDED_SLIDESHOW_SHAPEATTRIBUTELAYER_HXX
30 
31 #include <com/sun/star/drawing/FillStyle.hpp>
32 #include <com/sun/star/drawing/LineStyle.hpp>
33 #include <com/sun/star/awt/FontSlant.hpp>
34 
35 #include <basegfx/vector/b2dsize.hxx>
36 #include <basegfx/point/b2dpoint.hxx>
37 #include <basegfx/range/b2drectangle.hxx>
38 #include <basegfx/polygon/b2dpolypolygon.hxx>
39 
40 #include "state.hxx"
41 #include "rgbcolor.hxx"
42 
43 #include <stack>
44 #include <boost/shared_ptr.hpp>
45 
46 
47 namespace slideshow
48 {
49     namespace internal
50     {
51         class ShapeAttributeLayer;
52 
53         typedef ::boost::shared_ptr< ShapeAttributeLayer > ShapeAttributeLayerSharedPtr;
54 
55         /** Encapsulates all modifiable attributes of a shape.
56 
57         	This class holds all modifiable attributes of a shape, and
58         	at the same time provides means to layer attributes on top
59         	of each other..
60 
61             And yes, there's a reason why we even pass bools and ints
62             by const reference. Namely, that makes the set* methods
63             differ only in the value type, which greatly reduces
64             template variability (e.g. in AnimationFactory).
65          */
66         class ShapeAttributeLayer
67         {
68         public:
69             /** Create a ShapeAttributeLayer instance, with all
70                 attributes set to default.
71 
72                 Furthermore, this constructor gets a pointer to a
73                 child layer, which is used as the fallback (or the
74                 base value) for all attributes
75 
76                 @param rChildLayer
77                 Layer below this one
78 
79                 @attention
80                 This method is only supposed to be called from Shape objects
81              */
82             explicit ShapeAttributeLayer( const ShapeAttributeLayerSharedPtr& rChildLayer );
83 
84             // Children management methods
85             //------------------------------------------------------------------
86 
87             /** Revoke the given layer.
88 
89             	This method revokes the given layer from this object
90             	or one of the children. That is, if this object does
91             	have children, and the given layer is no direct child,
92             	it is recursively passed to the children for removal.
93 
94                 @return true, if removal was successful.
95 
96                 @attention
97                 This method is only supposed to be called from Shape objects
98              */
99             bool revokeChildLayer( const ShapeAttributeLayerSharedPtr& rChildLayer );
100 
101             /** Query the child layer of this object.
102 
103                 @attention
104                 This method is only supposed to be called from Shape objects
105              */
106             ShapeAttributeLayerSharedPtr getChildLayer() const;
107 
108             /** Set the additive mode for possible child attributes
109 
110             	This method sets the additive mode for child
111             	attributes. That is the way underlying attribute
112             	layers are combined with this one (i.e. to overrule
113             	lower layers, or how to combine the values). The
114             	default is
115             	::com::sun::star::animations::AnimationAdditiveMode::BASE,
116             	which means, take the value of the underlying layers,
117             	or from the model shape itself.
118 
119                 @param nMode
120                 Must be one of
121                 ::com::sun::star::animations::AnimationAdditiveMode.
122              */
123             void setAdditiveMode( sal_Int16 nMode );
124 
125             // Attribute methods
126             //------------------------------------------------------------------
127 
128             /** Query whether the width attribute is valid.
129              */
130             bool isWidthValid() const;
131             /** Query the current width of the shape
132              */
133             double getWidth() const;
134             /** Set the new width of the shape
135 
136 				@param rNewWidth
137                 A negative width mirrors the shape.
138              */
139             void setWidth( const double& rNewWidth );
140 
141             /** Query whether the height attribute is valid.
142              */
143             bool isHeightValid() const;
144             /** Query the current height of the shape
145              */
146             double getHeight() const;
147             /** Set the new height of the shape
148 
149 				@param rNewHeight
150                 A negative height mirrors the shape.
151              */
152             void setHeight( const double& rNewHeight );
153 
154             /** Set the new size of the shape
155 
156 				@param rNewSize
157                 A negative size mirrors the shape.
158              */
159             void setSize( const ::basegfx::B2DSize& rNewSize );
160 
161             /** Query whether the x position attribute is valid
162              */
163             bool isPosXValid() const;
164             /** Query the current x position of the shape.
165 
166             	The current x position of the shape is always relative
167             	to the <em>center</em> of the shape (in contrast to
168             	the Shape::getBounds() and Shape::getUpdateArea()
169             	methods).
170              */
171             double getPosX() const;
172             /** Set the new x position of the shape
173 
174             	The current x position of the shape is always relative
175             	to the <em>center</em> of the shape (in contrast to
176             	the Shape::getBounds() and Shape::getUpdateArea()
177             	methods).
178              */
179             void setPosX( const double& rNewX );
180 
181             /** Query whether the y position attribute is valid
182              */
183             bool isPosYValid() const;
184             /** Query the current y position of the shape
185 
186             	The current y position of the shape is always relative
187             	to the <em>center</em> of the shape (in contrast to
188             	the Shape::getBounds() and Shape::getUpdateArea()
189             	methods).
190              */
191             double getPosY() const;
192             /** Set the new y position of the shape
193 
194             	The current y position of the shape is always relative
195             	to the <em>center</em> of the shape (in contrast to
196             	the Shape::getBounds() and Shape::getUpdateArea()
197             	methods).
198              */
199             void setPosY( const double& rNewY );
200 
201             /** Set the new position of the shape
202 
203             	The current position of the shape is always relative
204             	to the <em>center</em> of the shape (in contrast to
205             	the Shape::getBounds() and Shape::getUpdateArea()
206             	methods).
207              */
208             void setPosition( const ::basegfx::B2DPoint& rNewPos );
209 
210             /** Query whether the rotation angle attribute is valid
211              */
212             bool isRotationAngleValid() const;
213             /** Query the current rotation angle of the shape
214 
215             	@return the rotation angle in degrees.
216              */
217             double getRotationAngle() const;
218             /** Set the new rotation angle of the shape
219 
220             	@param rNewAngle
221                 New rotation angle in degrees.
222              */
223             void setRotationAngle( const double& rNewAngle );
224 
225             /** Query whether the shear x angle attribute is valid
226              */
227             bool isShearXAngleValid() const;
228             /** Query the current shear angle at the x axis of the shape
229 
230             	@return the shear angle in degrees.
231              */
232             double getShearXAngle() const;
233             /** Set the new shear angle at the x axis of the shape
234 
235             	@param rNewAngle
236                 New shear angle in radians.
237              */
238             void setShearXAngle( const double& rNewAngle );
239 
240             /** Query whether the shear y angle attribute is valid
241              */
242             bool isShearYAngleValid() const;
243             /** Query the current shear angle at the y axis of the shape
244 
245             	@return the shear angle in degrees.
246              */
247             double getShearYAngle() const;
248             /** Set the new shear angle at the y axis of the shape
249 
250             	@param rNewAngle
251                 New shear angle in radians.
252              */
253             void setShearYAngle( const double& rNewAngle );
254 
255             /** Query whether the alpha attribute is valid
256              */
257             bool isAlphaValid() const;
258             /** Query the current alpha value of the shape
259              */
260             double getAlpha() const;
261             /** Set the new alpha value of the shape
262 
263             	@param rNewValue
264                 New alpha value, must be in the [0,1] range
265              */
266             void setAlpha( const double& rNewValue );
267 
268             /** Query whether the clip attribute is valid
269              */
270             bool isClipValid() const;
271             /** Query the current clip polygon of the shape
272              */
273             ::basegfx::B2DPolyPolygon getClip() const;
274             /** Set the new clip polygon of the shape
275 
276             	@param rNewClip
277                 New clip polygon, is interpreted in shape view coordinates, but
278                 relative to the shape (i.e. the origin of the shape coincides
279                 with the origin of the clip polygon).
280              */
281             void setClip( const ::basegfx::B2DPolyPolygon& rNewClip );
282 
283             /** Query whether the dim color attribute is valid
284 
285             	The dim color globally 'dims' the shape towards that
286             	color
287              */
288             bool isDimColorValid() const;
289             /** Get the dim color for the whole shape.
290              */
291             RGBColor getDimColor() const;
292             /** Set the dim color globally for the whole shape.
293              */
294             void setDimColor( const RGBColor& nNewColor );
295 
296             /** Query whether the fill color attribute is valid
297              */
298             bool isFillColorValid() const;
299             /** Get the fill color for the whole shape.
300 
301             	If there's no unique fill color, the color from the
302             	first filled polygon is returned.
303              */
304             RGBColor getFillColor() const;
305             /** Set the fill color globally for the whole shape.
306              */
307             void setFillColor( const RGBColor& nNewColor );
308 
309             /** Query whether the line color attribute is valid
310              */
311             bool isLineColorValid() const;
312             /** Get the line color for the whole shape.
313 
314             	If there's no unique line color, the color from the
315             	first line is returned.
316              */
317             RGBColor  getLineColor() const;
318             /** Set the line color globally for the whole shape.
319              */
320             void setLineColor( const RGBColor& nNewColor );
321 
322             /** Query whether the fill mode attribute is valid
323              */
324             bool isFillStyleValid() const;
325             /** Get the current fill mode for polygon fillings.
326 
327 				@returns the current style
328              */
329             sal_Int16 getFillStyle() const;
330             /** Changes polygon fillings.
331              */
332             void setFillStyle( const sal_Int16& rStyle );
333 
334             /** Query whether the line mode attribute is valid
335              */
336             bool isLineStyleValid() const;
337             /** Get the current line mode for line drawing.
338 
339 				@returns the current line style
340              */
341             sal_Int16 getLineStyle() const;
342             /** Set line style for the whole shape
343              */
344             void setLineStyle( const sal_Int16& rStyle );
345 
346             /** Query whether the visibility state attribute is valid
347              */
348             bool isVisibilityValid() const;
349             /** Get the current shape visibility.
350 
351 				@returns true for visible, false for invisible.
352              */
353             bool getVisibility() const;
354             /** Set the shape visibility
355              */
356             void setVisibility( const bool& bVisible );
357 
358             /** Query whether the char color attribute is valid
359              */
360             bool isCharColorValid() const;
361             /** Get the text color for the whole shape.
362 
363             	If there's no unique text color, the color from the
364             	first text drawn is returned.
365              */
366             RGBColor getCharColor() const;
367             /** Set the text color globally for the whole shape.
368              */
369             void setCharColor( const RGBColor& nNewColor );
370 
371             /** Query whether the char rotation angle attribute is valid
372              */
373             bool isCharRotationAngleValid() const;
374             /** Query the current text rotation angle of the shape
375 
376             	@return the text rotation angle in degrees.
377              */
378             double getCharRotationAngle() const;
379             /** Set the new text rotation angle of the shape
380 
381             	@param rNewAngle
382                 New text rotation angle in degrees.
383              */
384             void setCharRotationAngle( const double& rNewAngle );
385 
386             /** Query whether the char weight attribute is valid
387              */
388             bool isCharWeightValid() const;
389             /** Get the current char weight value for the whole shape.
390 
391 				@returns the value for the char weight. The value must
392 				be out of the ::com::sun::star::awt::FontWeight
393 				constant group.
394              */
395             double getCharWeight() const;
396             /** Set the char weight globally for the whole shape.
397 
398             	The value must be out of the
399             	::com::sun::star::awt::FontWeight constant group.
400              */
401             void setCharWeight( const double& rStyle );
402 
403             /** Query whether the underline mode attribute is valid
404              */
405             bool isUnderlineModeValid() const;
406             /** Get the current text underline status for the whole shape.
407 
408             	If there is no unique underline status, false is returned.
409 
410 				@returns true for underlined text, false for normal.
411              */
412             sal_Int16 getUnderlineMode() const;
413             /** Set the underline status globally for the whole shape
414              */
415             void setUnderlineMode( const sal_Int16& bUnderline );
416 
417             /** Query whether the font family attribute is valid
418              */
419             bool isFontFamilyValid() const;
420             /** Get the current text font family for the whole shape.
421 
422             	If there is no unique font family, the font family of
423             	the first text of the shape is returned.
424              */
425             ::rtl::OUString getFontFamily() const;
426             /** Set the text font family name globally for the whole shape
427              */
428             void setFontFamily( const ::rtl::OUString& rName );
429 
430             /** Query whether the italic mode attribute is valid
431              */
432             bool isCharPostureValid() const;
433             /** Get the current text italic style for the whole shape.
434 
435 				@returns the italic style. The value returned is one
436 				of the ::com::sun::star::awt::FontSlant enums
437              */
438             sal_Int16 getCharPosture() const;
439             /** Set the italic style globally for the whole shape.
440 
441             	The value must be one of the
442             	::com::sun::star::awt::FontSlant enums.
443             */
444             void setCharPosture( const sal_Int16& rStyle );
445 
446             /** Query whether the char scaling attribute is valid
447              */
448             bool isCharScaleValid() const;
449             /** Query the current char scaling attribute globally for
450                 the shape.
451 
452                 The char scaling changes the scale of the whole shape
453                 text (uniformely, i.e. both in x and in y direction).
454              */
455             double getCharScale() const;
456             /** Set the new char scale globally for the shape
457 
458             	@param rNewScale
459                 New char scale
460              */
461             void setCharScale( const double& rNewScale );
462 
463             // State change query methods
464             // ==========================
465 
466             State::StateId getTransformationState() const;
467             State::StateId getClipState() const;
468             State::StateId getAlphaState() const;
469             State::StateId getPositionState() const;
470             State::StateId getContentState() const;
471             State::StateId getVisibilityState() const;
472 
473         private:
474             // default copy/assignment operator is okay
475             // ShapeAttributeLayer(const ShapeAttributeLayer&);
476             // ShapeAttributeLayer& operator=( const ShapeAttributeLayer& );
477 
478             bool haveChild() const { return mpChild; }
479             void updateStateIds();
480 
481             template< typename T > T calcValue( const T& 				   rCurrValue,
482                                                 bool						   bThisInstanceValid,
483                                                 bool (ShapeAttributeLayer::*pIsValid)() const,
484                                                 T 	(ShapeAttributeLayer::*pGetValue)() const ) const;
485 
486             ShapeAttributeLayerSharedPtr				mpChild; // may be NULL
487 
488             ::basegfx::B2DSize 							maSize;
489             ::basegfx::B2DPoint							maPosition;
490             ::basegfx::B2DPolyPolygon					maClip;
491 
492             ::rtl::OUString								maFontFamily;
493 
494             double										mnRotationAngle;
495             double 										mnShearXAngle;
496             double										mnShearYAngle;
497             double										mnAlpha;
498             double										mnCharRotationAngle;
499             double										mnCharScale;
500             double										mnCharWeight;
501 
502             ::com::sun::star::drawing::FillStyle		meFillStyle;
503             ::com::sun::star::drawing::LineStyle		meLineStyle;
504             ::com::sun::star::awt::FontSlant			meCharPosture;
505             sal_Int16									mnUnderlineMode;
506 
507             RGBColor									maDimColor;
508             RGBColor									maFillColor;
509             RGBColor									maLineColor;
510             RGBColor									maCharColor;
511 
512             State::StateId 								mnTransformationState;
513             State::StateId 								mnClipState;
514             State::StateId 								mnAlphaState;
515             State::StateId 								mnPositionState;
516             State::StateId 								mnContentState;
517             State::StateId 								mnVisibilityState;
518 
519             sal_Int16									mnAdditiveMode;
520 
521             bool										mbVisibility 			: 1;
522 
523             bool										mbWidthValid 			: 1;
524             bool										mbHeightValid 			: 1;
525             bool										mbPosXValid 			: 1;
526             bool										mbPosYValid 			: 1;
527             bool										mbClipValid				: 1;
528 
529             bool										mbFontFamilyValid 		: 1;
530 
531             bool										mbRotationAngleValid	: 1;
532             bool										mbShearXAngleValid		: 1;
533             bool										mbShearYAngleValid		: 1;
534 
535             bool										mbAlphaValid			: 1;
536 
537             bool										mbCharRotationAngleValid: 1;
538             bool										mbCharScaleValid		: 1;
539 
540             bool										mbDimColorValid			: 1;
541             bool										mbFillColorValid		: 1;
542             bool										mbLineColorValid		: 1;
543             bool										mbCharColorValid		: 1;
544 
545             bool										mbFillStyleValid		: 1;
546             bool										mbLineStyleValid		: 1;
547             bool										mbCharWeightValid		: 1;
548             bool										mbUnderlineModeValid	: 1;
549             bool										mbCharPostureValid		: 1;
550             bool										mbVisibilityValid		: 1;
551         };
552 
553     }
554 }
555 
556 #endif /* INCLUDED_SLIDESHOW_SHAPEATTRIBUTELAYER_HXX */
557