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 #pragma once
20 
21 #include "possiz.hxx"
22 #include <txttypes.hxx>
23 #include <TextFrameIndex.hxx>
24 #include <rtl/ustring.hxx>
25 
26 class SwTextSizeInfo;
27 class SwTextPaintInfo;
28 class SwTextFormatInfo;
29 class SwPortionHandler;
30 
31 /// Portion groups
32 /// @see enum PortionType in txttypes.hxx
33 #define PORGRP_TXT      0x8000
34 #define PORGRP_EXP      0x4000
35 #define PORGRP_FLD      0x2000
36 #define PORGRP_HYPH     0x1000
37 #define PORGRP_NUMBER   0x0800
38 #define PORGRP_GLUE     0x0400
39 #define PORGRP_FIX      0x0200
40 #define PORGRP_TAB      0x0100
41 // Small special groups
42 #define PORGRP_FIXMARG  0x0040
43 //#define PORGRP_?  0x0020
44 #define PORGRP_TABNOTLFT 0x0010
45 #define PORGRP_TOXREF   0x0008
46 
47 /// Base class for anything that can be part of a line in the Writer layout.
48 /// Typically owned by SwLineLayout.
49 class SAL_DLLPUBLIC_RTTI SwLinePortion: public SwPosSize
50 {
51 protected:
52     // Here we have areas with different attributes
53     SwLinePortion *mpNextPortion;
54     // Count of chars and spaces on the line
55     TextFrameIndex mnLineLength;
56     sal_uInt16 mnAscent;      // Maximum ascender
57 
58     SwLinePortion();
59 private:
60     PortionType mnWhichPor;       // Who's who?
61     bool m_bJoinBorderWithPrev;
62     bool m_bJoinBorderWithNext;
63 
64     void Truncate_();
65 
66 public:
67     explicit inline SwLinePortion(const SwLinePortion &rPortion);
68            virtual ~SwLinePortion();
69 
70     // Access methods
GetNextPortion() const71     SwLinePortion *GetNextPortion() const { return mpNextPortion; }
72     inline SwLinePortion &operator=(const SwLinePortion &rPortion);
GetLen() const73     TextFrameIndex GetLen() const { return mnLineLength; }
SetLen(TextFrameIndex const nLen)74     void SetLen(TextFrameIndex const nLen) { mnLineLength = nLen; }
SetNextPortion(SwLinePortion * pNew)75     void SetNextPortion( SwLinePortion *pNew ){ mpNextPortion = pNew; }
GetAscent()76     sal_uInt16 &GetAscent() { return mnAscent; }
GetAscent() const77     sal_uInt16 GetAscent() const { return mnAscent; }
SetAscent(const sal_uInt16 nNewAsc)78     void SetAscent( const sal_uInt16 nNewAsc ) { mnAscent = nNewAsc; }
PrtWidth(sal_uInt16 nNewWidth)79     void  PrtWidth( sal_uInt16 nNewWidth ) { Width( nNewWidth ); }
PrtWidth() const80     sal_uInt16 PrtWidth() const { return Width(); }
AddPrtWidth(const sal_uInt16 nNew)81     void AddPrtWidth( const sal_uInt16 nNew ) { Width( Width() + nNew ); }
SubPrtWidth(const sal_uInt16 nNew)82     void SubPrtWidth( const sal_uInt16 nNew ) { Width( Width() - nNew ); }
83 
84     // Insert methods
85     virtual SwLinePortion *Insert( SwLinePortion *pPortion );
86     virtual SwLinePortion *Append( SwLinePortion *pPortion );
87             SwLinePortion *Cut( SwLinePortion *pVictim );
88     inline  void Truncate();
89 
90     // Returns 0, if there's no payload
91     virtual SwLinePortion *Compress();
92 
SetWhichPor(const PortionType nNew)93     void SetWhichPor( const PortionType nNew )    { mnWhichPor = nNew; }
GetWhichPor() const94     PortionType GetWhichPor( ) const        { return mnWhichPor; }
95 
96 // Group queries
InTextGrp() const97     bool InTextGrp() const { return (sal_uInt16(mnWhichPor) & PORGRP_TXT) != 0; }
InGlueGrp() const98     bool InGlueGrp() const { return (sal_uInt16(mnWhichPor) & PORGRP_GLUE) != 0; }
InTabGrp() const99     bool InTabGrp() const { return (sal_uInt16(mnWhichPor) & PORGRP_TAB) != 0; }
InHyphGrp() const100     bool InHyphGrp() const { return (sal_uInt16(mnWhichPor) & PORGRP_HYPH) != 0; }
InNumberGrp() const101     bool InNumberGrp() const { return (sal_uInt16(mnWhichPor) & PORGRP_NUMBER) != 0; }
InFixGrp() const102     bool InFixGrp() const { return (sal_uInt16(mnWhichPor) & PORGRP_FIX) != 0; }
InFieldGrp() const103     bool InFieldGrp() const { return (sal_uInt16(mnWhichPor) & PORGRP_FLD) != 0; }
InToxRefGrp() const104     bool InToxRefGrp() const { return (sal_uInt16(mnWhichPor) & PORGRP_TOXREF) != 0; }
InToxRefOrFieldGrp() const105     bool InToxRefOrFieldGrp() const { return (sal_uInt16(mnWhichPor) & ( PORGRP_FLD | PORGRP_TOXREF )) != 0; }
InExpGrp() const106     bool InExpGrp() const { return (sal_uInt16(mnWhichPor) & PORGRP_EXP) != 0; }
InFixMargGrp() const107     bool InFixMargGrp() const { return (sal_uInt16(mnWhichPor) & PORGRP_FIXMARG) != 0; }
InSpaceGrp() const108     bool InSpaceGrp() const { return InTextGrp() || IsMultiPortion(); }
109 // Individual queries
IsGrfNumPortion() const110     bool IsGrfNumPortion() const { return mnWhichPor == PortionType::GrfNum; }
IsFlyCntPortion() const111     bool IsFlyCntPortion() const { return mnWhichPor == PortionType::FlyCnt; }
IsBlankPortion() const112     bool IsBlankPortion() const { return mnWhichPor == PortionType::Blank; }
IsBreakPortion() const113     bool IsBreakPortion() const { return mnWhichPor == PortionType::Break; }
IsErgoSumPortion() const114     bool IsErgoSumPortion() const { return mnWhichPor == PortionType::ErgoSum; }
IsQuoVadisPortion() const115     bool IsQuoVadisPortion() const { return mnWhichPor == PortionType::QuoVadis; }
IsTabLeftPortion() const116     bool IsTabLeftPortion() const { return mnWhichPor == PortionType::TabLeft; }
IsTabRightPortion() const117     bool IsTabRightPortion() const { return mnWhichPor == PortionType::TabRight; }
IsTabCenterPortion() const118     bool IsTabCenterPortion() const { return mnWhichPor == PortionType::TabCenter; }
IsTabDecimalPortion() const119     bool IsTabDecimalPortion() const { return mnWhichPor == PortionType::TabDecimal; }
IsFootnoteNumPortion() const120     bool IsFootnoteNumPortion() const { return mnWhichPor == PortionType::FootnoteNum; }
IsFootnotePortion() const121     bool IsFootnotePortion() const { return mnWhichPor == PortionType::Footnote; }
IsDropPortion() const122     bool IsDropPortion() const { return mnWhichPor == PortionType::Drop; }
IsLayPortion() const123     bool IsLayPortion() const { return mnWhichPor == PortionType::Lay; }
IsParaPortion() const124     bool IsParaPortion() const { return mnWhichPor == PortionType::Para; }
IsMarginPortion() const125     bool IsMarginPortion() const { return mnWhichPor == PortionType::Margin; }
IsFlyPortion() const126     bool IsFlyPortion() const { return mnWhichPor == PortionType::Fly; }
IsHolePortion() const127     bool IsHolePortion() const { return mnWhichPor == PortionType::Hole; }
IsSoftHyphPortion() const128     bool IsSoftHyphPortion() const { return mnWhichPor == PortionType::SoftHyphen; }
IsPostItsPortion() const129     bool IsPostItsPortion() const { return mnWhichPor == PortionType::PostIts; }
IsCombinedPortion() const130     bool IsCombinedPortion() const { return mnWhichPor == PortionType::Combined; }
IsTextPortion() const131     bool IsTextPortion() const { return mnWhichPor == PortionType::Text; }
IsHangingPortion() const132     bool IsHangingPortion() const { return mnWhichPor == PortionType::Hanging; }
IsKernPortion() const133     bool IsKernPortion() const { return mnWhichPor == PortionType::Kern; }
IsArrowPortion() const134     bool IsArrowPortion() const { return mnWhichPor == PortionType::Arrow; }
IsMultiPortion() const135     bool IsMultiPortion() const { return mnWhichPor == PortionType::Multi; }
IsNumberPortion() const136     bool IsNumberPortion() const { return mnWhichPor == PortionType::Number; } // #i23726#
IsControlCharPortion() const137     bool IsControlCharPortion() const { return mnWhichPor == PortionType::ControlChar || mnWhichPor == PortionType::Bookmark; }
138 
139     // Positioning
140     SwLinePortion *FindPrevPortion( const SwLinePortion *pRoot );
141     SwLinePortion *FindLastPortion();
142 
143     /// the parameter is actually SwTwips apparently?
144     virtual TextFrameIndex GetModelPositionForViewPoint(sal_uInt16 nOfst) const;
145     virtual SwPosSize GetTextSize( const SwTextSizeInfo &rInfo ) const;
146     void CalcTextSize( const SwTextSizeInfo &rInfo );
147 
148     // Output
149     virtual void Paint( const SwTextPaintInfo &rInf ) const = 0;
150     void PrePaint( const SwTextPaintInfo &rInf, const SwLinePortion *pLast ) const;
151 
152     virtual bool Format( SwTextFormatInfo &rInf );
153     // Is called for the line's last portion
154     virtual void FormatEOL( SwTextFormatInfo &rInf );
155             void Move( SwTextPaintInfo &rInf );
156 
157     // For SwTextSlot
158     virtual bool GetExpText( const SwTextSizeInfo &rInf, OUString &rText ) const;
159 
160     // For SwFieldPortion, SwSoftHyphPortion
161     virtual sal_uInt16 GetViewWidth( const SwTextSizeInfo &rInf ) const;
162 
163     // for text- and multi-portions
164     virtual tools::Long CalcSpacing( tools::Long nSpaceAdd, const SwTextSizeInfo &rInf ) const;
165 
166     // Accessibility: pass information about this portion to the PortionHandler
167     virtual void HandlePortion( SwPortionHandler& rPH ) const;
168 
GetJoinBorderWithPrev() const169     bool GetJoinBorderWithPrev() const { return m_bJoinBorderWithPrev; }
GetJoinBorderWithNext() const170     bool GetJoinBorderWithNext() const { return m_bJoinBorderWithNext; }
SetJoinBorderWithPrev(const bool bJoinPrev)171     void SetJoinBorderWithPrev( const bool bJoinPrev ) { m_bJoinBorderWithPrev = bJoinPrev; }
SetJoinBorderWithNext(const bool bJoinNext)172     void SetJoinBorderWithNext( const bool bJoinNext ) { m_bJoinBorderWithNext = bJoinNext; }
173 };
174 
operator =(const SwLinePortion & rPortion)175 inline SwLinePortion &SwLinePortion::operator=(const SwLinePortion &rPortion)
176 {
177     *static_cast<SwPosSize*>(this) = rPortion;
178     mnLineLength = rPortion.mnLineLength;
179     mnAscent = rPortion.mnAscent;
180     mnWhichPor = rPortion.mnWhichPor;
181     m_bJoinBorderWithPrev = rPortion.m_bJoinBorderWithPrev;
182     m_bJoinBorderWithNext = rPortion.m_bJoinBorderWithNext;
183     return *this;
184 }
185 
SwLinePortion(const SwLinePortion & rPortion)186 inline SwLinePortion::SwLinePortion(const SwLinePortion &rPortion) :
187     SwPosSize( rPortion ),
188     mpNextPortion( nullptr ),
189     mnLineLength( rPortion.mnLineLength ),
190     mnAscent( rPortion.mnAscent ),
191     mnWhichPor( rPortion.mnWhichPor ),
192     m_bJoinBorderWithPrev( rPortion.m_bJoinBorderWithPrev ),
193     m_bJoinBorderWithNext( rPortion.m_bJoinBorderWithNext )
194 {
195 }
196 
Truncate()197 inline void SwLinePortion::Truncate()
198 {
199     if ( mpNextPortion )
200         Truncate_();
201 }
202 
203 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
204