Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/source/edit/textdat2.hxx
Line
Count
Source
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
20
#pragma once
21
22
#include <tools/long.hxx>
23
24
#include <vcl/cursor.hxx>
25
#include <vcl/seleng.hxx>
26
27
#include <cstddef>
28
#include <limits>
29
#include <vector>
30
31
class TextLine;
32
class TextNode;
33
class TextView;
34
35
0
#define PORTIONKIND_TEXT        0
36
0
#define PORTIONKIND_TAB         1
37
38
0
#define DELMODE_SIMPLE          0
39
0
#define DELMODE_RESTOFWORD      1
40
0
#define DELMODE_RESTOFCONTENT   2
41
42
0
#define DEL_LEFT    1
43
0
#define DEL_RIGHT   2
44
0
#define TRAVEL_X_DONTKNOW   0xFFFF
45
#define MAXCHARSINPARA      0x3FFF-CHARPOSGROW
46
47
0
#define LINE_SEP    0x0A
48
49
class TETextPortion
50
{
51
private:
52
    tools::Long     nWidth;
53
    sal_Int32       nLen;
54
    sal_uInt8       nKind;
55
    bool            bRightToLeft;
56
57
public:
58
                TETextPortion( sal_Int32 nL )
59
0
                    : nWidth {-1}
60
0
                    , nLen {nL}
61
0
                    , nKind {PORTIONKIND_TEXT}
62
0
                    , bRightToLeft {false}
63
0
                {}
64
65
0
    sal_Int32&  GetLen()                        { return nLen; }
66
0
    sal_Int32  GetLen() const                   { return nLen; }
67
0
    tools::Long&           GetWidth()                  { return nWidth; }
68
0
    sal_uInt8&      GetKind()                   { return nKind; }
69
0
    void            SetRightToLeft(bool b)      { bRightToLeft = b; }
70
0
    bool            IsRightToLeft() const       { return bRightToLeft; }
71
};
72
73
class TETextPortionList
74
{
75
private:
76
    std::vector<TETextPortion> maPortions;
77
78
public:
79
    static constexpr auto npos = std::numeric_limits<std::size_t>::max();
80
81
    TETextPortionList();
82
    ~TETextPortionList();
83
84
    TETextPortion& operator[]( std::size_t nPos );
85
    std::vector<TETextPortion>::iterator begin();
86
    std::vector<TETextPortion>::const_iterator begin() const;
87
    std::vector<TETextPortion>::iterator end();
88
    std::vector<TETextPortion>::const_iterator end() const;
89
    bool empty() const;
90
    std::size_t size() const;
91
    std::vector<TETextPortion>::iterator erase( const std::vector<TETextPortion>::iterator& aIter );
92
    std::vector<TETextPortion>::iterator insert( const std::vector<TETextPortion>::iterator& aIter,
93
                                                  const TETextPortion& rTP );
94
    void push_back( const TETextPortion & aTP );
95
96
    void    Reset();
97
    std::size_t FindPortion( sal_Int32 nCharPos, sal_Int32& rPortionStart, bool bPreferStartingPortion = false );
98
    void    DeleteFromPortion( std::size_t nDelFrom );
99
};
100
101
struct TEWritingDirectionInfo
102
{
103
    bool         bLeftToRight;
104
    sal_Int32    nStartPos;
105
    sal_Int32    nEndPos;
106
    TEWritingDirectionInfo( bool LeftToRight, sal_Int32 Start, sal_Int32 End )
107
0
        : bLeftToRight {LeftToRight}
108
0
        , nStartPos {Start}
109
0
        , nEndPos {End}
110
0
    {}
111
};
112
113
class TEParaPortion
114
{
115
private:
116
    TextNode*               mpNode;
117
118
    std::vector<TextLine>   maLines;
119
    TETextPortionList       maTextPortions;
120
    std::vector<TEWritingDirectionInfo> maWritingDirectionInfos;
121
122
    sal_Int32               mnInvalidPosStart;
123
    sal_Int32               mnInvalidDiff;
124
125
    bool                    mbInvalid;
126
    bool                    mbSimple;   // only type linearly
127
128
public:
129
                        TEParaPortion( TextNode* pNode );
130
                        ~TEParaPortion();
131
132
    TEParaPortion( const TEParaPortion& ) = delete;
133
    void operator=( const TEParaPortion& ) = delete;
134
135
0
    bool                IsInvalid() const           { return mbInvalid; }
136
0
    bool                IsSimpleInvalid() const     { return mbSimple; }
137
0
    void                SetNotSimpleInvalid()       { mbSimple = false; }
138
0
    void                SetValid()                  { mbInvalid = false; mbSimple = true;}
139
140
    void                MarkInvalid( sal_Int32 nStart, sal_Int32 nDiff );
141
    void                MarkSelectionInvalid( sal_Int32 nStart );
142
143
0
    sal_Int32           GetInvalidPosStart() const  { return mnInvalidPosStart; }
144
0
    sal_Int32           GetInvalidDiff() const      { return mnInvalidDiff; }
145
146
0
    TextNode*           GetNode() const             { return mpNode; }
147
0
    std::vector<TextLine>& GetLines()               { return maLines; }
148
0
    TETextPortionList&  GetTextPortions()           { return maTextPortions; }
149
0
    std::vector<TEWritingDirectionInfo>& GetWritingDirectionInfos() { return maWritingDirectionInfos; }
150
151
    std::vector<TextLine>::size_type GetLineNumber( sal_Int32 nIndex, bool bInclEnd );
152
    void                CorrectValuesBehindLastFormattedLine( sal_uInt16 nLastFormattedLine );
153
};
154
155
class TEParaPortions
156
{
157
private:
158
    std::vector<std::unique_ptr<TEParaPortion>> mvData;
159
160
public:
161
0
                    TEParaPortions() : mvData() {}
162
                    ~TEParaPortions();
163
164
0
    sal_uInt32      Count() const { return static_cast<sal_uInt32>(mvData.size()); }
165
0
    TEParaPortion*  GetObject( sal_uInt32 nIndex ) { return mvData[nIndex].get(); }
166
0
    void            Insert( TEParaPortion* pObject, sal_uInt32 nPos ) { mvData.emplace( mvData.begin()+nPos, pObject ); }
167
0
    void            Remove( sal_uInt32 nPos ) { mvData.erase( mvData.begin()+nPos ); }
168
};
169
170
class TextSelFunctionSet: public FunctionSet
171
{
172
private:
173
    TextView*       mpView;
174
175
public:
176
                    TextSelFunctionSet( TextView* pView );
177
178
    virtual void    BeginDrag() override;
179
180
    virtual void    CreateAnchor() override;
181
182
    virtual void    SetCursorAtPoint( const Point& rPointPixel, bool bDontSelectAtCursor = false ) override;
183
184
    virtual bool    IsSelectionAtPoint( const Point& rPointPixel ) override;
185
    virtual void    DeselectAll() override;
186
187
    virtual void    DeselectAtPoint( const Point& ) override;
188
    virtual void    DestroyAnchor() override;
189
};
190
191
struct TextDDInfo
192
{
193
    vcl::Cursor     maCursor;
194
    TextPaM         maDropPos;
195
196
    bool            mbStarterOfDD;
197
    bool            mbVisCursor;
198
199
    TextDDInfo()
200
0
        : maCursor()
201
0
        , maDropPos()
202
0
        , mbStarterOfDD {false}
203
0
        , mbVisCursor {false}
204
0
    {
205
0
        maCursor.SetStyle( CURSOR_SHADOW );
206
0
    }
207
};
208
209
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */