1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <sal/config.h>
24 #include <string_view>
26 #include <swtypes.hxx>
29 #include <o3tl/enumarray.hxx>
32 class SwFormatVertOrient
;
34 class SwFieldPortion
: public SwExpandPortion
36 friend class SwTextFormatter
;
38 OUString m_aExpand
; // The expanded field
39 std::unique_ptr
<SwFont
> m_pFont
; // For multi-line fields
40 TextFrameIndex m_nNextOffset
; // Offset of the follow in the original string
41 TextFrameIndex m_nNextScriptChg
;
42 TextFrameIndex m_nFieldLen
; //< Length of field text, 1 for normal fields, any number for input fields
43 // TODO ^ do we need this as member or is base class len enough?
44 sal_uInt16 m_nViewWidth
; // Screen width for empty fields
45 bool m_bFollow
: 1; // 2nd or later part of a field
46 bool m_bLeft
: 1; // Used by SwNumberPortion
47 bool m_bHide
: 1; // Used by SwNumberPortion
48 bool m_bCenter
: 1; // Used by SwNumberPortion
49 bool m_bHasFollow
: 1; // Continues on the next line
50 bool m_bAnimated
: 1; // Used by SwGrfNumPortion
51 bool m_bNoPaint
: 1; // Used by SwGrfNumPortion
52 bool m_bReplace
: 1; // Used by SwGrfNumPortion
53 bool m_bNoLength
: 1; // HACK for meta suffix (no CH_TXTATR)
54 bool m_bContentControl
= false;
56 void SetFont( std::unique_ptr
<SwFont
> pNew
) { m_pFont
= std::move(pNew
); }
57 bool IsNoLength() const { return m_bNoLength
; }
58 void SetNoLength() { m_bNoLength
= true; }
61 SwFieldPortion( const SwFieldPortion
& rField
);
62 SwFieldPortion(OUString aExpand
, std::unique_ptr
<SwFont
> pFnt
= nullptr, TextFrameIndex nLen
= TextFrameIndex(1));
63 virtual ~SwFieldPortion() override
;
65 void TakeNextOffset( const SwFieldPortion
* pField
);
66 void CheckScript( const SwTextSizeInfo
&rInf
);
67 bool HasFont() const { return nullptr != m_pFont
; }
68 // #i89179# - made public
69 const SwFont
*GetFont() const { return m_pFont
.get(); }
71 const OUString
& GetExp() const { return m_aExpand
; }
72 virtual bool GetExpText( const SwTextSizeInfo
&rInf
, OUString
&rText
) const override
;
73 virtual bool Format( SwTextFormatInfo
&rInf
) override
;
74 virtual void Paint( const SwTextPaintInfo
&rInf
) const override
;
76 // Empty fields are also allowed
77 virtual SwLinePortion
*Compress() override
;
79 virtual sal_uInt16
GetViewWidth( const SwTextSizeInfo
&rInf
) const override
;
81 bool IsFollow() const { return m_bFollow
; }
82 void SetFollow( bool bNew
) { m_bFollow
= bNew
; }
84 bool IsLeft() const { return m_bLeft
; }
85 void SetLeft( bool bNew
) { m_bLeft
= bNew
; }
87 bool IsHide() const { return m_bHide
; }
88 void SetHide( bool bNew
) { m_bHide
= bNew
; }
90 bool IsCenter() const { return m_bCenter
; }
91 void SetCenter( bool bNew
) { m_bCenter
= bNew
; }
93 bool HasFollow() const { return m_bHasFollow
; }
94 void SetHasFollow( bool bNew
) { m_bHasFollow
= bNew
; }
96 TextFrameIndex
GetNextOffset() const { return m_nNextOffset
; }
97 void SetNextOffset(TextFrameIndex nNew
) { m_nNextOffset
= nNew
; }
99 TextFrameIndex
GetFieldLen() const { return m_nFieldLen
; }
101 // Field cloner for SplitGlue
102 virtual SwFieldPortion
*Clone( const OUString
&rExpand
) const;
104 // Extra GetTextSize because of pFnt
105 virtual SwPosSize
GetTextSize( const SwTextSizeInfo
&rInfo
) const override
;
107 // Accessibility: pass information about this portion to the PortionHandler
108 virtual void HandlePortion( SwPortionHandler
& rPH
) const override
;
110 void SetContentControl(bool bContentControl
) { m_bContentControl
= bContentControl
; }
112 void dumpAsXml(xmlTextWriterPtr pWriter
, const OUString
& rText
,
113 TextFrameIndex
& nOffset
) const override
;
117 * Distinguish only for painting/hide
119 class SwHiddenPortion
: public SwFieldPortion
122 SwHiddenPortion( const OUString
&rExpand
, std::unique_ptr
<SwFont
> pFntL
= nullptr )
123 : SwFieldPortion( rExpand
, std::move(pFntL
) )
124 { SetLen(TextFrameIndex(1)); SetWhichPor( PortionType::Hidden
); }
125 virtual void Paint( const SwTextPaintInfo
&rInf
) const override
;
126 virtual bool GetExpText( const SwTextSizeInfo
&rInf
, OUString
&rText
) const override
;
128 // Field cloner for SplitGlue
129 virtual SwFieldPortion
*Clone( const OUString
&rExpand
) const override
;
132 class SwNumberPortion
: public SwFieldPortion
135 sal_uInt16 m_nFixWidth
; // See Glues
136 sal_uInt16 m_nMinDist
; // Minimal distance to the text
137 bool mbLabelAlignmentPosAndSpaceModeActive
;
140 SwNumberPortion( const OUString
&rExpand
,
141 std::unique_ptr
<SwFont
> pFnt
,
144 const sal_uInt16 nMinDst
,
145 const bool bLabelAlignmentPosAndSpaceModeActive
);
146 virtual void Paint( const SwTextPaintInfo
&rInf
) const override
;
147 virtual TextFrameIndex
GetModelPositionForViewPoint(sal_uInt16 nOfst
) const override
;
148 virtual bool Format( SwTextFormatInfo
&rInf
) override
;
150 // Field cloner for SplitGlue
151 virtual SwFieldPortion
*Clone( const OUString
&rExpand
) const override
;
152 virtual void FormatEOL( SwTextFormatInfo
&rInf
) override
;
155 class SwBulletPortion
: public SwNumberPortion
158 SwBulletPortion( const sal_UCS4 cCh
,
159 std::u16string_view rBulletFollowedBy
,
160 std::unique_ptr
<SwFont
> pFnt
,
163 const sal_uInt16 nMinDst
,
164 const bool bLabelAlignmentPosAndSpaceModeActive
);
167 class SwGrfNumPortion
: public SwNumberPortion
169 std::unique_ptr
<SvxBrushItem
> m_pBrush
;
170 tools::Long m_nId
; // For StopAnimation
171 SwTwips m_nYPos
; // _Always_ contains the current RelPos
172 SwTwips m_nGrfHeight
;
175 SwGrfNumPortion( const OUString
& rGraphicFollowedBy
,
176 const SvxBrushItem
* pGrfBrush
,
177 OUString
const & referer
,
178 const SwFormatVertOrient
* pGrfOrient
,
179 const Size
& rGrfSize
,
182 const sal_uInt16 nMinDst
,
183 const bool bLabelAlignmentPosAndSpaceModeActive
);
184 virtual ~SwGrfNumPortion() override
;
185 virtual void Paint( const SwTextPaintInfo
&rInf
) const override
;
186 virtual bool Format( SwTextFormatInfo
&rInf
) override
;
188 void SetBase( tools::Long nLnAscent
, tools::Long nLnDescent
,
189 tools::Long nFlyAscent
, tools::Long nFlyDescent
);
191 void StopAnimation( const OutputDevice
* pOut
);
193 bool IsAnimated() const { return m_bAnimated
; }
194 void SetAnimated( bool bNew
) { m_bAnimated
= bNew
; }
195 void SetRelPos( SwTwips nNew
) { m_nYPos
= nNew
; }
196 void SetId( tools::Long nNew
) const
197 { const_cast<SwGrfNumPortion
*>(this)->m_nId
= nNew
; }
198 SwTwips
GetRelPos() const { return m_nYPos
; }
199 SwTwips
GetGrfHeight() const { return m_nGrfHeight
; }
200 sal_Int16
GetOrient() const { return m_eOrient
; }
204 * Used in for asian layout specialities to display up to six characters
205 * in 2 rows and 2-3 columns.
207 * A.. A.. A.B A.B A.B.C A.B.C
208 * ... ..B .C. C.D .D.E. D.E.F
211 class SwCombinedPortion
: public SwFieldPortion
213 sal_uInt16 m_aPos
[6]; // up to six X positions
214 o3tl::enumarray
<SwFontScript
,sal_uInt16
> m_aWidth
; // one width for every scripttype
215 SwFontScript m_aScrType
[6]; // scripttype of every character
216 sal_uInt16 m_nUpPos
; // the Y position of the upper baseline
217 sal_uInt16 m_nLowPos
; // the Y position of the lower baseline
218 sal_uInt8 m_nProportion
; // relative font height
220 explicit SwCombinedPortion( const OUString
&rExpand
);
221 virtual void Paint( const SwTextPaintInfo
&rInf
) const override
;
222 virtual bool Format( SwTextFormatInfo
&rInf
) override
;
223 virtual sal_uInt16
GetViewWidth( const SwTextSizeInfo
&rInf
) const override
;
226 namespace sw::mark
{ class IFieldmark
; }
228 class SwFieldFormDropDownPortion
: public SwFieldPortion
231 explicit SwFieldFormDropDownPortion(sw::mark::IFieldmark
*pFieldMark
, const OUString
&rExpand
)
232 : SwFieldPortion(rExpand
)
233 , m_pFieldMark(pFieldMark
)
236 // Field cloner for SplitGlue
237 virtual SwFieldPortion
*Clone( const OUString
&rExpand
) const override
;
239 virtual void Paint( const SwTextPaintInfo
&rInf
) const override
;
242 sw::mark::IFieldmark
* m_pFieldMark
;
245 class SwFieldFormDatePortion
: public SwFieldPortion
248 explicit SwFieldFormDatePortion(sw::mark::IFieldmark
*pFieldMark
, bool bStart
)
250 , m_pFieldMark(pFieldMark
)
254 // Field cloner for SplitGlue
255 virtual SwFieldPortion
*Clone( const OUString
&rExpand
) const override
;
257 virtual void Paint( const SwTextPaintInfo
&rInf
) const override
;
260 sw::mark::IFieldmark
* m_pFieldMark
;
264 class SwJumpFieldPortion final
: public SwFieldPortion
267 explicit SwJumpFieldPortion(OUString aExpand
, OUString aHelp
, std::unique_ptr
<SwFont
> pFont
,
269 : SwFieldPortion(std::move(aExpand
), std::move(pFont
))
271 , m_sHelp(std::move(aHelp
))
274 virtual SwFieldPortion
* Clone(const OUString
& rExpand
) const override
;
276 virtual void Paint(const SwTextPaintInfo
& rInf
) const override
;
279 sal_uInt32 m_nFormat
; // SwJumpEditFormat from SwField::GetFormat()
282 bool DescribePDFControl(const SwTextPaintInfo
& rInf
) const;
285 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */