summaryrefslogtreecommitdiffstats
path: root/khexedit/lib/kbufferranges.h
blob: 622ff4a8acb2521f77311a6348c0ef79d62abdfd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/***************************************************************************
                          kbufferranges.h  -  description
                             -------------------
    begin                : Sun Jun 22 2003
    copyright            : (C) 2003 by Friedrich W. H. Kossebau
    email                : Friedrich.W.H@Kossebau.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This library is free software; you can redistribute it and/or         *
 *   modify it under the terms of the GNU Library General Public           *
 *   License version 2 as published by the Free Software Foundation.       *
 *                                                                         *
 ***************************************************************************/


#ifndef KHE_KBUFFERRANGES_H
#define KHE_KBUFFERRANGES_H

// lib specific
#include "kbufferlayout.h"
#include "kselection.h"
#include "ksectionlist.h"
#include "kcoordrangelist.h"

namespace KHE
{

/** a class to control all the ranges like marking and selections
  * holds also all modified ranges and merges them so a repaint can take its info from here
  *
  * @author Friedrich W. H.  Kossebau
  */
class TDEBufferRanges
{
  public:
    TDEBufferRanges( TDEBufferLayout *L );
    ~TDEBufferRanges();

  public: // modifcation access
    void setMarking( KSection M );
    void setSelectionStart( int StartIndex );
    void setSelectionEnd( int StartIndex );
    void setSelection( KSection S );
    /** */
    void setFirstWordSelection( KSection S );
    /** */
    void ensureWordSelectionForward( bool Forward );

    /** removes marking and returns true if something changed */
    void removeMarking();
    /** removes selection with id and returns true if something changed */
    void removeSelection( int id = 0 );
    /** removes all but the standard selection and returns true if something changed */
    void removeFurtherSelections();

    void addChangedRange( KSection S );
    void addChangedRange( int SI, int EI );
    void addChangedRange( const KCoordRange &NewRange );
    void resetChangedRanges();

    void setModified( bool M = true );
    /** removes all ranges */
    void reset();

  public: // value access
    int noOfSelections() const;
    int selectionStart() const;
    int selectionEnd() const;
    KSection selection() const;
    KSection firstWordSelection() const;
    int selectionLength() const;
    bool isModified() const;

  public: // calculated logic access
    bool hasSelection() const;
    bool hasMarking() const;
    bool selectionStarted() const;
    bool selectionJustStarted() const;
    bool hasFirstWordSelection() const;
    bool selectionIncludes( int Index ) const;
    bool markingIncludes( int Index ) const;
    // TODO: next three are deprecated
    bool overlapsSelection( int FirstIndex, int LastIndex, int *SI, int *EI ) const;
    bool overlapsMarking( int FirstIndex, int LastIndex, int *SI, int *EI ) const;
//    bool overlapsChanges( int FirstIndex, int LastIndex, int *SI, int *EI ) const;
//    bool overlapsChanges( KSection Indizes, KSection *ChangedRange ) const;
    bool overlapsChanges( const KCoordRange &Range, KCoordRange *ChangedRange ) const;
    const KSection *firstOverlappingSelection( KSection Range ) const;
    const KSection *overlappingMarking( KSection Range ) const;


  protected:
    /** true if something changed */
    bool Modified;

    KSection Marking;
    TDESelection Selection;
    /** memories first selected word on wordwise selection */
    KSection FirstWordSelection;

    KCoordRangeList ChangedRanges;

    TDEBufferLayout *Layout;
};


inline int TDEBufferRanges::noOfSelections()  const { return 1; }

inline int TDEBufferRanges::selectionStart()  const { return Selection.start(); }
inline int TDEBufferRanges::selectionEnd()    const { return Selection.end(); }
inline KSection TDEBufferRanges::selection()  const { return Selection; }
inline KSection TDEBufferRanges::firstWordSelection()  const { return FirstWordSelection; }
inline int TDEBufferRanges::selectionLength() const { return Selection.width(); }
inline bool TDEBufferRanges::isModified()     const { return Modified; }

inline bool TDEBufferRanges::hasSelection()             const { return Selection.isValid(); }
inline bool TDEBufferRanges::selectionStarted()         const { return Selection.started(); }
inline bool TDEBufferRanges::selectionJustStarted()     const { return Selection.justStarted(); }
inline bool TDEBufferRanges::hasFirstWordSelection()    const { return FirstWordSelection.isValid(); }
inline bool TDEBufferRanges::hasMarking()               const { return Marking.isValid(); }
inline bool TDEBufferRanges::selectionIncludes( int Index ) const { return Selection.includes( Index ); }
inline bool TDEBufferRanges::markingIncludes( int Index )   const { return Marking.includes( Index ); }

inline void TDEBufferRanges::setModified( bool M )           { Modified = M; }

}

#endif