1 /*
2 This file is part of the Okteta Gui library, made within the KDE community.
3
4 SPDX-FileCopyrightText: 2003, 2008-2009 Friedrich W. H. Kossebau <kossebau@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7 */
8
9 #ifndef OKTETA_BYTEARRAYTABLERANGES_HPP
10 #define OKTETA_BYTEARRAYTABLERANGES_HPP
11
12 // lib
13 #include "oktetagui_export.hpp"
14 #include "selection.hpp"
15 #include "coordrangelist.hpp"
16 // Okteta core
17 #include <Okteta/AddressRange>
18 // Qt
19 #include <QScopedPointer>
20
21 namespace Okteta {
22 class ArrayChangeMetricsList;
23 class ByteArrayTableLayout;
24 class ByteArrayTableRangesPrivate;
25
26 /** a class to control all the ranges like marking and selections
27 * holds also all modified ranges and merges them so a repaint can take its info from here
28 *
29 * @author Friedrich W. H. Kossebau
30 */
31 // TODO: split info about ranges from info about dirty ranges into a second class
32 class OKTETAGUI_EXPORT ByteArrayTableRanges
33 {
34 public:
35 explicit ByteArrayTableRanges(ByteArrayTableLayout* layout);
36 ByteArrayTableRanges() = delete;
37
38 ~ByteArrayTableRanges();
39
40 public: // modifcation access
41 void setMarking(const AddressRange& marking);
42 void setSelectionStart(Address startIndex);
43 void setSelectionEnd(Address startIndex);
44 void setSelection(const AddressRange& selection);
45 /** */
46 void setFirstWordSelection(const AddressRange& selection);
47 /** */
48 void ensureWordSelectionForward(bool Forward);
49
50 /** removes selection with id and returns it */
51 AddressRange removeSelection(int id = 0);
52 /** removes all but the standard selection and returns true if something changed */
53 void removeFurtherSelections();
54
55 /** assumes all added lines to overlap */
56 void addChangedOffsetLines(const LineRange& changesLines);
57
58 void addChangedRange(const AddressRange& range);
59 void addChangedRange(Address start, Address end);
60 void addChangedRange(const CoordRange& range);
61 void adaptToChanges(const ArrayChangeMetricsList& changeList, Size oldLength);
62 void resetChangedRanges();
63
64 void takeHasSelectionChanged(bool* hasSelectionChanged, bool* selectionChanged);
65 void setModified(bool M = true);
66 /** removes all ranges */
67 void reset();
68
69 public: // value access
70 int noOfSelections() const;
71 Address selectionStart() const;
72 Address selectionEnd() const;
73 AddressRange selection() const;
74 AddressRange firstWordSelection() const;
75 Size selectionLength() const;
76 AddressRange marking() const;
77 bool isModified() const;
78 LineRange changedOffsetLines() const;
79
80 public: // calculated logic access
81 bool hasSelection() const;
82 bool hasMarking() const;
83 bool selectionStarted() const;
84 bool selectionJustStarted() const;
85 bool hasFirstWordSelection() const;
86 bool selectionIncludes(Address index) const;
87 bool markingIncludes(Address index) const;
88 // TODO: next three are deprecated
89 bool overlapsSelection(Address FirstIndex, Address LastIndex, Address* SI, Address* EI) const;
90 bool overlapsMarking(Address FirstIndex, Address LastIndex, Address* SI, Address* EI) const;
91 // bool overlapsChanges( int FirstIndex, int LastIndex, int *SI, int *EI ) const;
92 // bool overlapsChanges( AddressRange Indizes, AddressRange *ChangedRange ) const;
93 bool overlapsChanges(const CoordRange& range, CoordRange* ChangedRange) const;
94 const AddressRange* firstOverlappingSelection(const AddressRange& range) const;
95 const AddressRange* overlappingMarking(const AddressRange& range) const;
96
97 private:
98 /** true if something changed */
99 bool mModified = false;
100
101 AddressRange mMarking;
102 Selection mSelection;
103 /** memories first selected word on wordwise selection */
104 AddressRange FirstWordSelection;
105
106 /** lines that were added or removed */
107 LineRange mChangedOffsetLines;
108
109 CoordRangeList ChangedRanges;
110
111 const QScopedPointer<ByteArrayTableRangesPrivate> d_ptr;
112 Q_DECLARE_PRIVATE(ByteArrayTableRanges)
113 };
114
noOfSelections() const115 inline int ByteArrayTableRanges::noOfSelections() const { return 1; }
116
selectionStart() const117 inline Address ByteArrayTableRanges::selectionStart() const { return mSelection.start(); }
selectionEnd() const118 inline Address ByteArrayTableRanges::selectionEnd() const { return mSelection.end(); }
selection() const119 inline AddressRange ByteArrayTableRanges::selection() const { return mSelection.range(); }
firstWordSelection() const120 inline AddressRange ByteArrayTableRanges::firstWordSelection() const { return FirstWordSelection; }
selectionLength() const121 inline Size ByteArrayTableRanges::selectionLength() const { return mSelection.range().width(); }
marking() const122 inline AddressRange ByteArrayTableRanges::marking() const { return mMarking; }
isModified() const123 inline bool ByteArrayTableRanges::isModified() const { return mModified; }
changedOffsetLines() const124 inline LineRange ByteArrayTableRanges::changedOffsetLines() const { return mChangedOffsetLines; }
125
hasSelection() const126 inline bool ByteArrayTableRanges::hasSelection() const { return mSelection.isValid(); }
selectionStarted() const127 inline bool ByteArrayTableRanges::selectionStarted() const { return mSelection.started(); }
selectionJustStarted() const128 inline bool ByteArrayTableRanges::selectionJustStarted() const { return mSelection.justStarted(); }
hasFirstWordSelection() const129 inline bool ByteArrayTableRanges::hasFirstWordSelection() const { return FirstWordSelection.isValid(); }
hasMarking() const130 inline bool ByteArrayTableRanges::hasMarking() const { return mMarking.isValid(); }
selectionIncludes(Address index) const131 inline bool ByteArrayTableRanges::selectionIncludes(Address index) const { return mSelection.range().includes(index); }
markingIncludes(Address index) const132 inline bool ByteArrayTableRanges::markingIncludes(Address index) const { return mMarking.includes(index); }
133
setModified(bool M)134 inline void ByteArrayTableRanges::setModified(bool M) { mModified = M; }
135
136 }
137
138 #endif
139