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