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_INC_CRSTATE_HXX
20 #define INCLUDED_SW_INC_CRSTATE_HXX
21 
22 #include <com/sun/star/text/HoriOrientation.hpp>
23 #include <tools/gen.hxx>
24 #include "swrect.hxx"
25 
26 #include <memory>
27 
28 enum SwFillMode
29 {
30     FILL_TAB,       ///< default, fill with tabs
31     FILL_TAB_SPACE, ///< fill with spaces and tabs
32     FILL_SPACE,     ///< fill with spaces
33     FILL_MARGIN,    ///< only align left, center, right
34     FILL_INDENT     ///< by left paragraph indention
35 };
36 
37 struct SwFillCursorPos
38 {
39     SwRect aCursor;           ///< position and size of the ShadowCursor
40     sal_uInt16 nParaCnt;        ///< number of paragraphs to insert
41     sal_uInt16 nTabCnt;         ///< number of tabs respectively size of indentation
42     sal_uInt16 nSpaceCnt;       ///< number of spaces to insert
43     sal_uInt16 nSpaceOnlyCnt;   ///< number of spaces to insert ("only spaces, no tabs" mode)
44     sal_uInt16 nColumnCnt;      ///< number of necessary column breaks
45     sal_Int16  eOrient;      ///< paragraph alignment
46     SwFillMode const eMode; ///< desired fill-up rule
SwFillCursorPosSwFillCursorPos47     SwFillCursorPos( SwFillMode eMd ) :
48         nParaCnt( 0 ), nTabCnt( 0 ), nSpaceCnt( 0 ), nSpaceOnlyCnt(0), nColumnCnt( 0 ),
49         eOrient( css::text::HoriOrientation::NONE ), eMode( eMd )
50     {}
51 };
52 
53 // Multiportion types: two lines, bidirectional, 270 degrees rotation,
54 //                     ruby portion and 90 degrees rotation
55 enum class MultiPortionType : sal_uInt8
56 {
57         TWOLINE  = 0,
58         BIDI     = 1,
59         ROT_270  = 3,
60         RUBY     = 4,
61         ROT_90   = 7,
62 };
63 
64 struct Sw2LinesPos
65 {
66     SwRect aLine;           ///< Position and size of the line
67     SwRect aPortion;        ///< Position and size of the multi portion
68     SwRect aPortion2;       ///< needed for nested multi portions
69     MultiPortionType nMultiType;  ///< Multiportion type
70 };
71 
72 /**
73  *  SwSpecialPos. This structure is used to pass some additional information
74  *  during the call of SwTextFrame::GetCharRect(). An SwSpecialPos defines a position
75  *  inside a portion which does not have a representation in the core string or
76  *  which is only represented by one position,  e.g., field portions,
77  *  number portions, ergo sum and quo vadis portions.
78  *
79  *  nCharOfst       - The offset inside the special portion. Fields and its
80  *                    follow fields are treated as one long special portion.
81  *  nLineOfst       - The number of lines between the beginning of the special
82  *                    portion and nCharOfst. A line offset required to be
83  *                    nCharOfst relative to the beginning of the line.
84  *  nExtendRange    - Setting this identifies portions which are in front or
85  *                    behind the core string (number portion, quo vadis)
86  *
87  *  Examples 1)
88  *
89  *      Get the position of the second character inside a number portion:
90  *          nCharOfst = 2; nLineOfst = 0; nExtendRange = SP_EXTEND_RANGE_BEFORE;
91  *          Call SwTextFrame:::GetCharRect with core string position 0.
92  *
93  *  Example 2)
94  *
95  *      Field A - Length = 5
96  *      Follow field B - Length = 9
97  *      Get the position of the third character in follow field B, core position
98  *      of field A is 33.
99  *          nCharOfst = 7; nLineOfst = 0; nExtendRange = SP_EXTEND_RANGE_NONE;
100  *          Call SwTextFrame:::GetCharRect with core string position 33.
101  */
102 
103 enum class SwSPExtendRange : sal_uInt8
104 {
105     NONE, BEFORE, BEHIND
106 };
107 
108 struct SwSpecialPos
109 {
110     sal_Int32 nCharOfst;
111     sal_uInt16 nLineOfst;
112     SwSPExtendRange nExtendRange;
113 
114     // #i27615#
SwSpecialPosSwSpecialPos115     SwSpecialPos() : nCharOfst(0), nLineOfst(0),
116                      nExtendRange(SwSPExtendRange::NONE)
117     {}
118 };
119 
120 // CursorTravelling-States (for GetCursorOfst)
121 enum CursorMoveState
122 {
123     MV_NONE,            ///< default
124     MV_UPDOWN,          ///< Cursor Up/Down
125     MV_RIGHTMARGIN,     ///< at right margin
126     MV_LEFTMARGIN,      ///< at left margin
127     MV_SETONLYTEXT,     ///< stay with the cursor inside text
128     MV_TBLSEL           ///< not in repeated headlines
129 };
130 
131 // struct for later extensions
132 struct SwCursorMoveState
133 {
134     SwFillCursorPos   *m_pFill;     ///< for automatic filling with tabs etc
135     std::unique_ptr<Sw2LinesPos> m_p2Lines;   ///< for selections inside/around 2line portions
136     SwSpecialPos*   m_pSpecialPos; ///< for positions inside fields
137     Point m_aRealHeight;          ///< contains then the position/height of the cursor
138     CursorMoveState m_eState;
139     sal_uInt8            m_nCursorBidiLevel;
140     bool m_bStop;
141     bool m_bRealHeight;           ///< should the real height be calculated?
142     bool m_bFieldInfo;            ///< should be fields recognized?
143     bool m_bPosCorr;              ///< Point had to be corrected
144     bool m_bFootnoteNoInfo;            ///< recognized footnote numbering
145     bool m_bExactOnly;            /**< let GetCursorOfst look for exact matches only,
146                                          i.e. never let it run into GetContentPos */
147     bool m_bFillRet;              ///< only used temporary in FillMode
148     bool m_bSetInReadOnly;        ///< ReadOnly areas may be entered
149     bool m_bRealWidth;            ///< Calculation of the width required
150     bool m_b2Lines;               ///< Check 2line portions and fill p2Lines
151     bool m_bNoScroll;             ///< No scrolling of undersized textframes
152     bool m_bPosMatchesBounds;         /**< GetCursorOfst should not return the next
153                                        position if screen position is inside second
154                                        have of bound rect */
155 
156     bool m_bContentCheck;           // #i43742# Cursor position over content?
157 
158     // #i27615#
159     /**
160        cursor in front of label
161      */
162     bool m_bInFrontOfLabel;
163     bool m_bInNumPortion;         ///< point is in number portion #i23726#
164     int m_nInNumPortionOffset;        ///< distance from number portion's start
165 
SwCursorMoveStateSwCursorMoveState166     SwCursorMoveState( CursorMoveState eSt = MV_NONE ) :
167         m_pFill( nullptr ),
168         m_pSpecialPos( nullptr ),
169         m_eState( eSt ),
170         m_nCursorBidiLevel( 0 ),
171         m_bStop( false ),
172         m_bRealHeight( false ),
173         m_bFieldInfo( false ),
174         m_bPosCorr( false ),
175         m_bFootnoteNoInfo( false ),
176         m_bExactOnly( false ),
177         m_bFillRet( false ),
178         m_bSetInReadOnly( false ),
179         m_bRealWidth( false ),
180         m_b2Lines( false ),
181         m_bNoScroll( false ),
182         m_bPosMatchesBounds( false ),
183         m_bContentCheck( false ), // #i43742#
184         m_bInFrontOfLabel( false ), // #i27615#
185         m_bInNumPortion(false), // #i26726#
186         m_nInNumPortionOffset(0) // #i26726#
187     {}
SwCursorMoveStateSwCursorMoveState188     SwCursorMoveState( SwFillCursorPos *pInitFill ) :
189         m_pFill( pInitFill ),
190         m_pSpecialPos( nullptr ),
191         m_eState( MV_SETONLYTEXT ),
192         m_nCursorBidiLevel( 0 ),
193         m_bStop( false ),
194         m_bRealHeight( false ),
195         m_bFieldInfo( false ),
196         m_bPosCorr( false ),
197         m_bFootnoteNoInfo( false ),
198         m_bExactOnly( false ),
199         m_bFillRet( false ),
200         m_bSetInReadOnly( false ),
201         m_bRealWidth( false ),
202         m_b2Lines( false ),
203         m_bNoScroll( false ),
204         m_bPosMatchesBounds( false ),
205         m_bContentCheck( false ), // #i43742#
206         m_bInFrontOfLabel( false ), // #i27615#
207         m_bInNumPortion(false), // #i23726#
208         m_nInNumPortionOffset(0) // #i23726#
209     {}
210 };
211 
212 #endif
213 
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
215