ITEM: Refactor ItemType
[LibreOffice.git] / sw / source / core / text / pordrop.hxx
blob6d36d8a3d462b35c25c53ba126bf3003b85b46f3
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 #pragma once
21 #include "portxt.hxx"
22 #include <swfont.hxx>
24 #include <memory>
26 class SwFont;
28 // DropCap cache, global variable initialized/destroyed in txtinit.cxx
29 // and used in txtdrop.cxx for initial calculation
31 class SwDropCapCache;
32 extern SwDropCapCache *pDropCapCache;
34 // A drop portion can consist of one or more parts in order to allow
35 // attribute changes inside them.
36 class SwDropPortionPart
38 std::unique_ptr<SwDropPortionPart> m_pFollow;
39 std::unique_ptr<SwFont> m_pFnt;
40 TextFrameIndex m_nLen;
41 SwTwips m_nWidth;
42 bool m_bJoinBorderWithNext;
43 bool m_bJoinBorderWithPrev;
45 public:
46 SwDropPortionPart( SwFont& rFont, const TextFrameIndex nL )
47 : m_pFnt( &rFont ), m_nLen( nL ), m_nWidth( 0 ), m_bJoinBorderWithNext(false), m_bJoinBorderWithPrev(false) {};
48 ~SwDropPortionPart();
50 SwDropPortionPart* GetFollow() const { return m_pFollow.get(); };
51 void SetFollow( std::unique_ptr<SwDropPortionPart> pNew ) { m_pFollow = std::move(pNew); };
52 SwFont& GetFont() const { return *m_pFnt; }
53 TextFrameIndex GetLen() const { return m_nLen; }
54 SwTwips GetWidth() const { return m_nWidth; }
55 void SetWidth(SwTwips nNew) { m_nWidth = nNew; }
57 bool GetJoinBorderWithPrev() const { return m_bJoinBorderWithPrev; }
58 bool GetJoinBorderWithNext() const { return m_bJoinBorderWithNext; }
59 void SetJoinBorderWithPrev( const bool bJoinPrev ) { m_bJoinBorderWithPrev = bJoinPrev; }
60 void SetJoinBorderWithNext( const bool bJoinNext ) { m_bJoinBorderWithNext = bJoinNext; }
63 /// Text portion for the Format -> Paragraph -> Drop Caps functionality.
64 class SwDropPortion : public SwTextPortion
66 friend class SwDropCapCache;
67 std::unique_ptr<SwDropPortionPart> m_pPart; // due to script/attribute changes
68 sal_uInt16 m_nLines; // Line count
69 SwTwips m_nDropHeight; // Height
70 SwTwips m_nDropDescent; // Distance to the next line
71 SwTwips m_nDistance; // Distance to the text
72 SwTwips m_nFix; // Fixed position
73 SwTwips m_nY; // Y Offset
75 bool FormatText( SwTextFormatInfo &rInf );
76 void PaintText( const SwTextPaintInfo &rInf ) const;
78 public:
79 SwDropPortion( const sal_uInt16 nLineCnt,
80 const SwTwips nDropHeight,
81 const SwTwips nDropDescent,
82 const SwTwips nDistance );
83 virtual ~SwDropPortion() override;
85 virtual void Paint( const SwTextPaintInfo &rInf ) const override;
86 void PaintDrop( const SwTextPaintInfo &rInf ) const;
87 virtual bool Format( SwTextFormatInfo &rInf ) override;
88 virtual SwPosSize GetTextSize( const SwTextSizeInfo &rInfo ) const override;
89 virtual TextFrameIndex GetModelPositionForViewPoint(SwTwips nOfst) const override;
91 sal_uInt16 GetLines() const { return m_nLines; }
92 SwTwips GetDistance() const { return m_nDistance; }
93 SwTwips GetDropHeight() const { return m_nDropHeight; }
94 SwTwips GetDropDescent() const { return m_nDropDescent; }
95 SwTwips GetDropLeft() const { return Width() + m_nFix; }
97 SwDropPortionPart* GetPart() const { return m_pPart.get(); }
98 void SetPart( std::unique_ptr<SwDropPortionPart> pNew ) { m_pPart = std::move(pNew); }
100 void SetY( short nNew ) { m_nY = nNew; }
102 SwFont* GetFnt() const { return m_pPart ? &m_pPart->GetFont() : nullptr; }
104 static void DeleteDropCapCache();
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */