File indexing completed on 2024-04-21 05:53:09

0001 /*
0002     This file is part of the Okteta Gui library, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2003, 2008-2009, 2021 Friedrich W. H. Kossebau <kossebau@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #ifndef OKTETA_BYTEARRAYTABLERANGES_HPP
0010 #define OKTETA_BYTEARRAYTABLERANGES_HPP
0011 
0012 // lib
0013 #include "oktetagui_export.hpp"
0014 #include "selection.hpp"
0015 #include "coordrangelist.hpp"
0016 // Okteta core
0017 #include <Okteta/AddressRange>
0018 
0019 namespace Okteta {
0020 class ArrayChangeMetricsList;
0021 class ByteArrayTableLayout;
0022 
0023 /** a class to control all the ranges like marking and selections
0024  * holds also all modified ranges and merges them so a repaint can take its info from here
0025  *
0026  * @author Friedrich W. H.  Kossebau
0027  */
0028 // TODO: split info about ranges from info about dirty ranges into a second class
0029 class OKTETAGUI_EXPORT ByteArrayTableRanges
0030 {
0031 public:
0032     explicit ByteArrayTableRanges(ByteArrayTableLayout* layout);
0033     ByteArrayTableRanges(const ByteArrayTableRanges&) = delete;
0034 
0035     ~ByteArrayTableRanges();
0036 
0037     ByteArrayTableRanges& operator=(const ByteArrayTableRanges&) = delete;
0038 
0039 public: // modifcation access
0040     void setMarking(const AddressRange& marking);
0041     void setSelectionStart(Address startIndex);
0042     void setSelectionEnd(Address endIndex);
0043     void setSelection(const AddressRange& selection);
0044     /** */
0045     void setFirstWordSelection(const AddressRange& selection);
0046     /** */
0047     void ensureWordSelectionForward(bool Forward);
0048 
0049     /** removes selection with id and returns it */
0050     AddressRange removeSelection(int id = 0);
0051     /** removes all but the standard selection and returns true if something changed */
0052     void removeFurtherSelections();
0053 
0054     /** assumes all added lines to overlap */
0055     void addChangedOffsetLines(const LineRange& changedLines);
0056 
0057     void addChangedRange(const AddressRange& range);
0058     void addChangedRange(Address start, Address end);
0059     void addChangedRange(const CoordRange& range);
0060     void adaptToChanges(const ArrayChangeMetricsList& changeList, Size oldLength);
0061     void resetChangedRanges();
0062 
0063     void takeHasSelectionChanged(bool* hasSelectionChanged, bool* selectionChanged);
0064     void setModified(bool M = true);
0065     /** removes all ranges */
0066     void reset();
0067 
0068 public: // value access
0069     int noOfSelections() const;
0070     Address selectionStart() const;
0071     Address selectionEnd() const;
0072     AddressRange selection() const;
0073     AddressRange firstWordSelection() const;
0074     Size selectionLength() const;
0075     AddressRange marking() const;
0076     bool isModified() const;
0077     LineRange changedOffsetLines() const;
0078 
0079 public: // calculated logic access
0080     bool hasSelection() const;
0081     bool hasMarking() const;
0082     bool selectionStarted() const;
0083     bool selectionJustStarted() const;
0084     bool hasFirstWordSelection() const;
0085     bool selectionIncludes(Address index) const;
0086     bool markingIncludes(Address index) const;
0087     // TODO: next three are deprecated
0088     bool overlapsSelection(Address FirstIndex, Address LastIndex, Address* startIndex, Address* endIndex) const;
0089     bool overlapsMarking(Address FirstIndex, Address LastIndex, Address* startIndex, Address* endIndex) const;
0090 //    bool overlapsChanges( int FirstIndex, int LastIndex, int *SI, int *EI ) const;
0091 //    bool overlapsChanges( AddressRange Indizes, AddressRange *ChangedRange ) const;
0092     bool overlapsChanges(const CoordRange& range, CoordRange* ChangedRange) const;
0093     const AddressRange* firstOverlappingSelection(const AddressRange& range) const;
0094     const AddressRange* overlappingMarking(const AddressRange& range) const;
0095 
0096 private:
0097     /** true if something changed */
0098     bool mModified = false;
0099 
0100     AddressRange mMarking;
0101     Selection mSelection;
0102     /** memories first selected word on wordwise selection */
0103     AddressRange FirstWordSelection;
0104 
0105     /** lines that were added or removed */
0106     LineRange mChangedOffsetLines;
0107 
0108     CoordRangeList ChangedRanges;
0109     Selection mPreviousSelection;
0110 
0111     ByteArrayTableLayout* const mLayout;
0112 };
0113 
0114 inline int ByteArrayTableRanges::noOfSelections()  const { return 1; }
0115 
0116 inline Address ByteArrayTableRanges::selectionStart()  const { return mSelection.start(); }
0117 inline Address ByteArrayTableRanges::selectionEnd()    const { return mSelection.end(); }
0118 inline AddressRange ByteArrayTableRanges::selection()  const { return mSelection.range(); }
0119 inline AddressRange ByteArrayTableRanges::firstWordSelection()  const { return FirstWordSelection; }
0120 inline Size ByteArrayTableRanges::selectionLength()    const { return mSelection.range().width(); }
0121 inline AddressRange ByteArrayTableRanges::marking()    const { return mMarking; }
0122 inline bool ByteArrayTableRanges::isModified()         const { return mModified; }
0123 inline LineRange ByteArrayTableRanges::changedOffsetLines() const { return mChangedOffsetLines; }
0124 
0125 inline bool ByteArrayTableRanges::hasSelection()             const { return mSelection.isValid(); }
0126 inline bool ByteArrayTableRanges::selectionStarted()         const { return mSelection.started(); }
0127 inline bool ByteArrayTableRanges::selectionJustStarted()     const { return mSelection.justStarted(); }
0128 inline bool ByteArrayTableRanges::hasFirstWordSelection()    const { return FirstWordSelection.isValid(); }
0129 inline bool ByteArrayTableRanges::hasMarking()               const { return mMarking.isValid(); }
0130 inline bool ByteArrayTableRanges::selectionIncludes(Address index) const { return mSelection.range().includes(index); }
0131 inline bool ByteArrayTableRanges::markingIncludes(Address index)   const { return mMarking.includes(index); }
0132 
0133 inline void ByteArrayTableRanges::setModified(bool M)           { mModified = M; }
0134 
0135 }
0136 
0137 #endif