crashtesting: assert on reimport of docx export of ooo102874-2.doc
[LibreOffice.git] / slideshow / source / inc / shapeattributelayer.hxx
blobb97722fee20c1e56219c2ea2efedb6f569b9e1d1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SLIDESHOW_SOURCE_INC_SHAPEATTRIBUTELAYER_HXX
21 #define INCLUDED_SLIDESHOW_SOURCE_INC_SHAPEATTRIBUTELAYER_HXX
23 #include <com/sun/star/drawing/FillStyle.hpp>
24 #include <com/sun/star/drawing/LineStyle.hpp>
25 #include <com/sun/star/awt/FontSlant.hpp>
27 #include <basegfx/vector/b2dsize.hxx>
28 #include <basegfx/point/b2dpoint.hxx>
29 #include <basegfx/polygon/b2dpolypolygon.hxx>
31 #include "rgbcolor.hxx"
33 #include <memory>
36 namespace slideshow::internal
39 /** This interface represents a stateful object.
41 The state ID returned by the getStateId() method
42 abstractly encodes the object's state. When this ID
43 changes, clients can assume that the object's state has
44 changed.
46 class State final
48 public:
50 /// Abstract, numerically encoded state ID
51 typedef ::std::size_t StateId;
54 class ShapeAttributeLayer;
56 typedef ::std::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
62 of each other...
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
71 public:
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
79 @param rChildLayer
80 Layer below this one
82 @attention
83 This method is only supposed to be called from Shape objects
85 explicit ShapeAttributeLayer( const ShapeAttributeLayerSharedPtr& rChildLayer );
87 // Children management methods
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.
99 @attention
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.
106 @attention
107 This method is only supposed to be called from Shape objects
109 const 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
117 default is
118 css::animations::AnimationAdditiveMode::BASE,
119 which means, take the value of the underlying layers,
120 or from the model shape itself.
122 @param nMode
123 Must be one of
124 css::animations::AnimationAdditiveMode.
126 void setAdditiveMode( sal_Int16 nMode );
128 // Attribute methods
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
139 @param rNewWidth
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
152 @param rNewHeight
153 A negative height mirrors the shape.
155 void setHeight( const double& rNewHeight );
157 /** Set the new size of the shape
159 @param rNewSize
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()
172 methods).
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()
180 methods).
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()
192 methods).
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()
200 methods).
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()
209 methods).
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
223 @param rNewAngle
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 radians.
235 double getShearXAngle() const;
236 /** Set the new shear angle at the x axis of the shape
238 @param rNewAngle
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 radians.
250 double getShearYAngle() const;
251 /** Set the new shear angle at the y axis of the shape
253 @param rNewAngle
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
266 @param rNewValue
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
279 @param rNewClip
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
289 color
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 weight attribute is valid
376 bool isCharWeightValid() const;
377 /** Get the current char weight value for the whole shape.
379 @returns the value for the char weight. The value must
380 be out of the css::awt::FontWeight
381 constant group.
383 double getCharWeight() const;
384 /** Set the char weight globally for the whole shape.
386 The value must be out of the
387 css::awt::FontWeight constant group.
389 void setCharWeight( const double& rStyle );
391 /** Query whether the underline mode attribute is valid
393 bool isUnderlineModeValid() const;
394 /** Get the current text underline status for the whole shape.
396 If there is no unique underline status, false is returned.
398 @returns true for underlined text, false for normal.
400 sal_Int16 getUnderlineMode() const;
401 /** Set the underline status globally for the whole shape
403 void setUnderlineMode( const sal_Int16& bUnderline );
405 /** Query whether the font family attribute is valid
407 bool isFontFamilyValid() const;
408 /** Get the current text font family for the whole shape.
410 If there is no unique font family, the font family of
411 the first text of the shape is returned.
413 OUString getFontFamily() const;
414 /** Set the text font family name globally for the whole shape
416 void setFontFamily( const OUString& rName );
418 /** Query whether the italic mode attribute is valid
420 bool isCharPostureValid() const;
421 /** Get the current text italic style for the whole shape.
423 @returns the italic style. The value returned is one
424 of the css::awt::FontSlant enums
426 sal_Int16 getCharPosture() const;
427 /** Set the italic style globally for the whole shape.
429 The value must be one of the
430 css::awt::FontSlant enums.
432 void setCharPosture( const sal_Int16& rStyle );
434 /** Query whether the char scaling attribute is valid
436 bool isCharScaleValid() const;
437 /** Query the current char scaling attribute globally for
438 the shape.
440 The char scaling changes the scale of the whole shape
441 text (uniformly, i.e. both in x and in y direction).
443 double getCharScale() const;
444 /** Set the new char scale globally for the shape
446 @param rNewScale
447 New char scale
449 void setCharScale( const double& rNewScale );
451 // State change query methods
454 State::StateId getTransformationState() const;
455 State::StateId getClipState() const;
456 State::StateId getAlphaState() const;
457 State::StateId getPositionState() const;
458 State::StateId getContentState() const;
459 State::StateId getVisibilityState() const;
461 private:
462 // default copy/assignment operator is okay
463 // ShapeAttributeLayer(const ShapeAttributeLayer&);
464 // ShapeAttributeLayer& operator=( const ShapeAttributeLayer& );
466 bool haveChild() const { return static_cast< bool >(mpChild); }
467 void updateStateIds();
469 template< typename T > T calcValue( const T& rCurrValue,
470 bool bThisInstanceValid,
471 bool (ShapeAttributeLayer::*pIsValid)() const,
472 T (ShapeAttributeLayer::*pGetValue)() const ) const;
474 ShapeAttributeLayerSharedPtr mpChild; // may be NULL
476 ::basegfx::B2DSize maSize;
477 ::basegfx::B2DPoint maPosition;
478 ::basegfx::B2DPolyPolygon maClip;
480 OUString maFontFamily;
482 double mnRotationAngle;
483 double mnShearXAngle;
484 double mnShearYAngle;
485 double mnAlpha;
486 double mnCharScale;
487 double mnCharWeight;
489 css::drawing::FillStyle meFillStyle;
490 css::drawing::LineStyle meLineStyle;
491 css::awt::FontSlant meCharPosture;
492 sal_Int16 mnUnderlineMode;
494 RGBColor maDimColor;
495 RGBColor maFillColor;
496 RGBColor maLineColor;
497 RGBColor maCharColor;
499 State::StateId mnTransformationState;
500 State::StateId mnClipState;
501 State::StateId mnAlphaState;
502 State::StateId mnPositionState;
503 State::StateId mnContentState;
504 State::StateId mnVisibilityState;
506 sal_Int16 mnAdditiveMode;
508 bool mbVisibility : 1;
510 bool mbWidthValid : 1;
511 bool mbHeightValid : 1;
512 bool mbPosXValid : 1;
513 bool mbPosYValid : 1;
514 bool mbClipValid : 1;
516 bool mbFontFamilyValid : 1;
518 bool mbRotationAngleValid : 1;
519 bool mbShearXAngleValid : 1;
520 bool mbShearYAngleValid : 1;
522 bool mbAlphaValid : 1;
524 bool mbCharScaleValid : 1;
526 bool mbDimColorValid : 1;
527 bool mbFillColorValid : 1;
528 bool mbLineColorValid : 1;
529 bool mbCharColorValid : 1;
531 bool mbFillStyleValid : 1;
532 bool mbLineStyleValid : 1;
533 bool mbCharWeightValid : 1;
534 bool mbUnderlineModeValid : 1;
535 bool mbCharPostureValid : 1;
536 bool mbVisibilityValid : 1;
541 #endif // INCLUDED_SLIDESHOW_SOURCE_INC_SHAPEATTRIBUTELAYER_HXX
543 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */