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 "porglue.hxx"
22 
23 class SwTabPortion : public SwFixPortion
24 {
25     const sal_uInt16 m_nTabPos;
26     const sal_Unicode m_cFill;
27     const bool m_bAutoTabStop;
28 
29     // Format() branches either into PreFormat() or PostFormat()
30     bool PreFormat( SwTextFormatInfo &rInf );
31 public:
32     SwTabPortion( const sal_uInt16 nTabPos, const sal_Unicode cFill, const bool bAutoTab = true );
33     virtual void Paint( const SwTextPaintInfo &rInf ) const override;
34     virtual bool Format( SwTextFormatInfo &rInf ) override;
35     virtual void FormatEOL( SwTextFormatInfo &rInf ) override;
36     bool PostFormat( SwTextFormatInfo &rInf );
IsFilled() const37     bool IsFilled() const { return 0 != m_cFill; }
GetTabPos() const38     sal_uInt16 GetTabPos() const { return m_nTabPos; }
39 
40     // Accessibility: pass information about this portion to the PortionHandler
41     virtual void HandlePortion( SwPortionHandler& rPH ) const override;
42 };
43 
44 class SwTabLeftPortion : public SwTabPortion
45 {
46 public:
SwTabLeftPortion(const sal_uInt16 nTabPosVal,const sal_Unicode cFillChar,bool bAutoTab)47     SwTabLeftPortion( const sal_uInt16 nTabPosVal, const sal_Unicode cFillChar, bool bAutoTab )
48          : SwTabPortion( nTabPosVal, cFillChar, bAutoTab )
49     { SetWhichPor( PortionType::TabLeft ); }
50 };
51 
52 class SwTabRightPortion : public SwTabPortion
53 {
54 public:
SwTabRightPortion(const sal_uInt16 nTabPosVal,const sal_Unicode cFillChar)55     SwTabRightPortion( const sal_uInt16 nTabPosVal, const sal_Unicode cFillChar )
56          : SwTabPortion( nTabPosVal, cFillChar )
57     { SetWhichPor( PortionType::TabRight ); }
58 };
59 
60 class SwTabCenterPortion : public SwTabPortion
61 {
62 public:
SwTabCenterPortion(const sal_uInt16 nTabPosVal,const sal_Unicode cFillChar)63     SwTabCenterPortion( const sal_uInt16 nTabPosVal, const sal_Unicode cFillChar )
64          : SwTabPortion( nTabPosVal, cFillChar )
65     { SetWhichPor( PortionType::TabCenter ); }
66 };
67 
68 class SwTabDecimalPortion : public SwTabPortion
69 {
70     const sal_Unicode mcTab;
71 
72     /*
73      * During text formatting, we already store the width of the portions
74      * following the tab stop up to the decimal position. This value is
75      * evaluated during pLastTab->FormatEOL. FME 2006-01-06 #127428#.
76      */
77     sal_uInt16 mnWidthOfPortionsUpTpDecimalPosition;
78 
79 public:
SwTabDecimalPortion(const sal_uInt16 nTabPosVal,const sal_Unicode cTab,const sal_Unicode cFillChar)80     SwTabDecimalPortion( const sal_uInt16 nTabPosVal, const sal_Unicode cTab,
81                                 const sal_Unicode cFillChar )
82          : SwTabPortion( nTabPosVal, cFillChar ),
83            mcTab(cTab),
84            mnWidthOfPortionsUpTpDecimalPosition( USHRT_MAX )
85     { SetWhichPor( PortionType::TabDecimal ); }
86 
GetTabDecimal() const87     sal_Unicode GetTabDecimal() const { return mcTab; }
88 
SetWidthOfPortionsUpToDecimalPosition(sal_uInt16 nNew)89     void SetWidthOfPortionsUpToDecimalPosition( sal_uInt16 nNew )
90     {
91         mnWidthOfPortionsUpTpDecimalPosition = nNew;
92     }
GetWidthOfPortionsUpToDecimalPosition() const93     sal_uInt16 GetWidthOfPortionsUpToDecimalPosition() const
94     {
95         return mnWidthOfPortionsUpTpDecimalPosition;
96     }
97 };
98 
99 class SwAutoTabDecimalPortion : public SwTabDecimalPortion
100 {
101 public:
SwAutoTabDecimalPortion(const sal_uInt16 nTabPosVal,const sal_Unicode cTab,const sal_Unicode cFillChar)102     SwAutoTabDecimalPortion( const sal_uInt16 nTabPosVal, const sal_Unicode cTab,
103                                     const sal_Unicode cFillChar )
104          : SwTabDecimalPortion( nTabPosVal, cTab, cFillChar )
105     {
106         SetLen(TextFrameIndex(0));
107     }
108     virtual void Paint( const SwTextPaintInfo &rInf ) const override;
109 };
110 
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
112