summaryrefslogtreecommitdiffstats
path: root/khexedit/lib/kbufferranges.h
blob: 6b293b249fca79b5b1f8ae0fd69d908f20853531 (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 tqrepaint can take its info from here
  *
  * @author Friedrich W. H.  Kossebau
  */
class KBufferRanges
{
  public:
    KBufferRanges( KBufferLayout *L );
    ~KBufferRanges();

  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;
    KSelection Selection;
    /** memories first selected word on wordwise selection */
    KSection FirstWordSelection;

    KCoordRangeList ChangedRanges;

    KBufferLayout *Layout;
};


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

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

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

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

}

#endif