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