cid#1640468 Dereference after null check
[LibreOffice.git] / sw / inc / fmtfsize.hxx
blobab9c69c992e854dc96f81f7f6c2273aa7cdbe065
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 .
19 #ifndef INCLUDED_SW_INC_FMTFSIZE_HXX
20 #define INCLUDED_SW_INC_FMTFSIZE_HXX
22 #include <sal/config.h>
24 #include <editeng/sizeitem.hxx>
25 #include <svl/poolitem.hxx>
26 #include "swdllapi.h"
27 #include "hintids.hxx"
28 #include "swtypes.hxx"
29 #include "format.hxx"
31 class IntlWrapper;
33 //Frame size.
35 enum class SwFrameSize
37 Variable, ///< Frame is variable in Var-direction.
38 Fixed, ///< Frame cannot be moved in Var-direction.
39 Minimum /**< Value in Var-direction gives minimum
40 (can be exceeded but not be less). */
43 /**
44 * Describes the size of a Writer frame, for example a table, table row, table cell, TextFrame,
45 * page, etc.
47 * The height and width can be either relative or absolute, see SwFrameSize.
49 * If the size is relative, then the "relation" decides what 100% means, e.g. it may be relative to
50 * the page size of the parent frame size.
52 class SW_DLLPUBLIC SwFormatFrameSize final : public SvxSizeItem
54 SwFrameSize m_eFrameHeightType;
55 SwFrameSize m_eFrameWidthType;
56 sal_uInt8 m_nWidthPercent;
57 sal_Int16 m_eWidthPercentRelation;
58 sal_uInt8 m_nHeightPercent;
59 sal_Int16 m_eHeightPercentRelation;
61 // For tables: width can be given in percent.
63 // For frames: height and/or width may be given in percent.
64 // If only one of these percentage values is given, the value 0xFF
65 // used instead of the missing percentage value indicates this side
66 // being proportional to the given one.
67 // The calculation in this case is based upon the values in Size.
68 // Percentages are always related to the environment in which
69 // the object is placed (PrtArea) and to the screen width
70 // minus borders in BrowseView if the environment is the page.
72 void ScaleMetrics(tools::Long lMult, tools::Long lDiv) override;
73 bool HasMetrics() const override;
75 public:
76 DECLARE_ITEM_TYPE_FUNCTION(SwFormatFrameSize)
77 SwFormatFrameSize( SwFrameSize eSize = SwFrameSize::Variable,
78 SwTwips nWidth = 0, SwTwips nHeight = 0 );
80 virtual bool operator==( const SfxPoolItem& ) const override;
81 virtual size_t hashCode() const override;
82 virtual SwFormatFrameSize* Clone( SfxItemPool *pPool = nullptr ) const override;
83 virtual bool GetPresentation( SfxItemPresentation ePres,
84 MapUnit eCoreMetric,
85 MapUnit ePresMetric,
86 OUString &rText,
87 const IntlWrapper& rIntl ) const override;
88 virtual bool QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const override;
89 virtual bool PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId ) override;
91 SwFrameSize GetHeightSizeType() const { return m_eFrameHeightType; }
92 void SetHeightSizeType( SwFrameSize eSize )
93 { ASSERT_CHANGE_REFCOUNTED_ITEM; m_eFrameHeightType = eSize; }
95 SwFrameSize GetWidthSizeType() const { return m_eFrameWidthType; }
96 void SetWidthSizeType( SwFrameSize eSize )
97 { ASSERT_CHANGE_REFCOUNTED_ITEM; m_eFrameWidthType = eSize; }
99 enum PercentFlags { SYNCED = 0xff };
100 //0xff is reserved to indicate height is synced to width
101 sal_uInt8 GetHeightPercent() const{ return m_nHeightPercent; }
102 sal_Int16 GetHeightPercentRelation() const { return m_eHeightPercentRelation; }
103 //0xff is reserved to indicate width is synced to height
104 sal_uInt8 GetWidthPercent() const { return m_nWidthPercent; }
105 sal_Int16 GetWidthPercentRelation() const { return m_eWidthPercentRelation; }
106 void SetHeightPercent( sal_uInt8 n )
107 { ASSERT_CHANGE_REFCOUNTED_ITEM; m_nHeightPercent = n; }
108 void SetHeightPercentRelation ( sal_Int16 n )
109 { ASSERT_CHANGE_REFCOUNTED_ITEM; m_eHeightPercentRelation = n; }
110 void SetWidthPercent ( sal_uInt8 n )
111 { ASSERT_CHANGE_REFCOUNTED_ITEM; m_nWidthPercent = n; }
112 void SetWidthPercentRelation ( sal_Int16 n )
113 { ASSERT_CHANGE_REFCOUNTED_ITEM; m_eWidthPercentRelation = n; }
115 void dumpAsXml(xmlTextWriterPtr pWriter) const override;
117 protected:
118 virtual ItemInstanceManager* getItemInstanceManager() const override;
121 inline const SwFormatFrameSize &SwAttrSet::GetFrameSize(bool bInP) const
122 { return Get( RES_FRM_SIZE,bInP); }
124 inline const SwFormatFrameSize &SwFormat::GetFrameSize(bool bInP) const
125 { return m_aSet.GetFrameSize(bInP); }
127 #endif
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */