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 #ifndef INCLUDED_SW_SOURCE_UIBASE_INC_FRMMGR_HXX
20 #define INCLUDED_SW_SOURCE_UIBASE_INC_FRMMGR_HXX
21 
22 #include <swtypes.hxx>
23 #include <editeng/boxitem.hxx>
24 #include <editeng/shaditem.hxx>
25 #include <tools/gen.hxx>
26 #include <fmtfsize.hxx>
27 #include <fmtornt.hxx>
28 #include <fmtanchr.hxx>
29 #include <swdllapi.h>
30 
31 class   SwWrtShell;
32 struct  SvxSwFrameValidation;
33 struct  SwPosition;
34 
35 class   SwFormatCol;
36 class SvGlobalName;
37 
38 const SwTwips   DFLT_WIDTH      = MM50 * 4;
39 const SwTwips   DFLT_HEIGHT     = MM50;
40 
41 enum class Frmmgr_Type
42 {
43     NONE    = 0x00,
44     TEXT    = 0x01,
45     GRF     = 0x02,
46     OLE     = 0x04,
47     ENVELP  = 0x10
48 };
49 
50 class SW_DLLPUBLIC SwFlyFrameAttrMgr
51 {
52     SfxItemSet  m_aSet;
53     Point       m_aAbsPos;
54     SwWrtShell* m_pOwnSh;
55 
56     bool    m_bAbsPos,
57             m_bNewFrame;
58     bool    m_bIsInVertical;
59     // #mongolianlayout#
60     bool    m_bIsInVerticalL2R;
61 
62     // internal calculation for borders
63     SAL_DLLPRIVATE SwTwips           CalcTopSpace();
64     SAL_DLLPRIVATE SwTwips           CalcBottomSpace();
65     SAL_DLLPRIVATE SwTwips           CalcLeftSpace();
66     SAL_DLLPRIVATE SwTwips           CalcRightSpace();
67 
68     SAL_DLLPRIVATE void UpdateFlyFrame_(); // post-treatment after insert or update
69 
70 public:
71     SwFlyFrameAttrMgr( bool bNew, SwWrtShell* pSh, Frmmgr_Type nType, const SvGlobalName* pName );
72 
73     //CopyCtor for dialogs to check the metrics
74     SwFlyFrameAttrMgr( bool bNew, SwWrtShell *pSh, const SfxItemSet &rSet );
75 
76     void                SetAnchor(RndStdIds eId);
77     inline RndStdIds    GetAnchor()  const;
78 
79     void                SetHorzOrientation(sal_Int16 eOrient);
80     void                SetVertOrientation(sal_Int16 eOrient);
81 
82     // absolute position
83     void                SetAbsPos(const Point& rLPoint);
84 
85     // anchor's relative position
86     void                SetPos(const Point& rLPoint);
87     inline Point        GetPos() const;
88 
89     // size
90     void                SetSize(const Size& rLSize);
91     inline const Size&  GetSize() const;
92 
93     void                SetHeightSizeType(SwFrameSize eType);
94 
95     // rotation
96     void                SetRotation(Degree10 nOld, Degree10 nNew, const Size& rUnrotatedSize);
97 
98     // space to content
99     void                SetLRSpace( tools::Long nLeft,
100                                     tools::Long nRight );
101     void                SetULSpace( tools::Long nTop,
102                                     tools::Long nBottom );
103 
104     void                SetCol( const SwFormatCol &rCol);
105 
106     // change and query attributes
107     void                UpdateAttrMgr();
108     void                UpdateFlyFrame();
109 
110     // create new frame
111     void                InsertFlyFrame();
112     void                InsertFlyFrame(RndStdIds      eAnchorType,
113                                    const Point    &rPos,
114                                    const Size     &rSize);
115 
116     // check and change metrics
117     void                ValidateMetrics(SvxSwFrameValidation& rVal,
118                             const SwPosition* pToCharContentPos,
119                             bool bOnlyPercentRefValue = false);
120 
121     void                DelAttr(sal_uInt16 nId);
122 
123     // reach out the set
GetAttrSet() const124     const SfxItemSet &GetAttrSet() const { return m_aSet; }
GetAttrSet()125     SfxItemSet &GetAttrSet()       { return m_aSet; }
126     void                     SetAttrSet(const SfxItemSet& rSet);
127 
128     inline const SwFormatVertOrient &GetVertOrient() const;
129     inline const SwFormatHoriOrient &GetHoriOrient() const;
130     inline const SvxShadowItem   &GetShadow() const;
131     inline const SvxBoxItem      &GetBox() const;
132     inline const SwFormatFrameSize    &GetFrameSize() const;
133 
CalcWidthBorder()134     tools::Long CalcWidthBorder()  { return CalcLeftSpace()+CalcRightSpace(); }
CalcHeightBorder()135     tools::Long CalcHeightBorder() { return CalcTopSpace()+CalcBottomSpace(); }
136 };
137 
GetSize() const138 inline const Size& SwFlyFrameAttrMgr::GetSize() const
139 {
140     return m_aSet.Get(RES_FRM_SIZE).GetSize();
141 }
142 
GetVertOrient() const143 inline const SwFormatVertOrient &SwFlyFrameAttrMgr::GetVertOrient() const
144 {
145     return m_aSet.Get(RES_VERT_ORIENT);
146 }
GetHoriOrient() const147 inline const SwFormatHoriOrient &SwFlyFrameAttrMgr::GetHoriOrient() const
148 {
149     return m_aSet.Get(RES_HORI_ORIENT);
150 }
GetFrameSize() const151 inline const SwFormatFrameSize& SwFlyFrameAttrMgr::GetFrameSize() const
152 {
153     return m_aSet.Get(RES_FRM_SIZE);
154 }
GetShadow() const155 inline const SvxShadowItem &SwFlyFrameAttrMgr::GetShadow() const
156 {
157     return m_aSet.Get(RES_SHADOW);
158 }
GetBox() const159 inline const SvxBoxItem &SwFlyFrameAttrMgr::GetBox() const
160 {
161     return m_aSet.Get(RES_BOX);
162 }
GetPos() const163 inline Point SwFlyFrameAttrMgr::GetPos() const
164 {
165     return Point( GetHoriOrient().GetPos(), GetVertOrient().GetPos() );
166 }
GetAnchor() const167 inline RndStdIds SwFlyFrameAttrMgr::GetAnchor()  const
168 {
169     return m_aSet.Get(RES_ANCHOR).GetAnchorId();
170 }
171 
172 #endif
173 
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
175