~ubuntu-branches/ubuntu/wily/geany/wily

« back to all changes in this revision

Viewing changes to scintilla/src/CellBuffer.h

  • Committer: Package Import Robot
  • Author(s): Chow Loong Jin
  • Date: 2011-12-10 07:43:26 UTC
  • mfrom: (3.3.7 sid)
  • Revision ID: package-import@ubuntu.com-20111210074326-s8yqbew5i20h33tf
Tags: 0.21-1ubuntu1
* Merge from Debian Unstable, remaining changes:
  - debian/patches/20_use_evince_viewer.patch:
     + use evince as viewer for pdf and dvi files
  - debian/patches/20_use_x_terminal_emulator.patch:
     + use x-terminal-emulator as terminal
  - debian/control
     + Add breaks on geany-plugins-common << 0.20
* Also fixes bugs:
  - Filter for MATLAB/Octave files filters everythign (LP: 885505)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Scintilla source code edit control
 
2
/** @file CellBuffer.h
 
3
 ** Manages the text of the document.
 
4
 **/
 
5
// Copyright 1998-2004 by Neil Hodgson <neilh@scintilla.org>
 
6
// The License.txt file describes the conditions under which this software may be distributed.
 
7
 
 
8
#ifndef CELLBUFFER_H
 
9
#define CELLBUFFER_H
 
10
 
 
11
#ifdef SCI_NAMESPACE
 
12
namespace Scintilla {
 
13
#endif
 
14
 
 
15
// Interface to per-line data that wants to see each line insertion and deletion
 
16
class PerLine {
 
17
public:
 
18
        virtual ~PerLine() {}
 
19
        virtual void Init()=0;
 
20
        virtual void InsertLine(int)=0;
 
21
        virtual void RemoveLine(int)=0;
 
22
};
 
23
 
 
24
/**
 
25
 * The line vector contains information about each of the lines in a cell buffer.
 
26
 */
 
27
class LineVector {
 
28
 
 
29
        Partitioning starts;
 
30
        PerLine *perLine;
 
31
 
 
32
public:
 
33
 
 
34
        LineVector();
 
35
        ~LineVector();
 
36
        void Init();
 
37
        void SetPerLine(PerLine *pl);
 
38
 
 
39
        void InsertText(int line, int delta);
 
40
        void InsertLine(int line, int position, bool lineStart);
 
41
        void SetLineStart(int line, int position);
 
42
        void RemoveLine(int line);
 
43
        int Lines() const {
 
44
                return starts.Partitions();
 
45
        }
 
46
        int LineFromPosition(int pos) const;
 
47
        int LineStart(int line) const {
 
48
                return starts.PositionFromPartition(line);
 
49
        }
 
50
 
 
51
        int MarkValue(int line);
 
52
        int AddMark(int line, int marker);
 
53
        void MergeMarkers(int pos);
 
54
        void DeleteMark(int line, int markerNum, bool all);
 
55
        void DeleteMarkFromHandle(int markerHandle);
 
56
        int LineFromHandle(int markerHandle);
 
57
 
 
58
        void ClearLevels();
 
59
        int SetLevel(int line, int level);
 
60
        int GetLevel(int line);
 
61
 
 
62
        int SetLineState(int line, int state);
 
63
        int GetLineState(int line);
 
64
        int GetMaxLineState();
 
65
 
 
66
};
 
67
 
 
68
enum actionType { insertAction, removeAction, startAction, containerAction };
 
69
 
 
70
/**
 
71
 * Actions are used to store all the information required to perform one undo/redo step.
 
72
 */
 
73
class Action {
 
74
public:
 
75
        actionType at;
 
76
        int position;
 
77
        char *data;
 
78
        int lenData;
 
79
        bool mayCoalesce;
 
80
 
 
81
        Action();
 
82
        ~Action();
 
83
        void Create(actionType at_, int position_=0, char *data_=0, int lenData_=0, bool mayCoalesce_=true);
 
84
        void Destroy();
 
85
        void Grab(Action *source);
 
86
};
 
87
 
 
88
/**
 
89
 *
 
90
 */
 
91
class UndoHistory {
 
92
        Action *actions;
 
93
        int lenActions;
 
94
        int maxAction;
 
95
        int currentAction;
 
96
        int undoSequenceDepth;
 
97
        int savePoint;
 
98
 
 
99
        void EnsureUndoRoom();
 
100
 
 
101
public:
 
102
        UndoHistory();
 
103
        ~UndoHistory();
 
104
 
 
105
        void AppendAction(actionType at, int position, char *data, int length, bool &startSequence, bool mayCoalesce=true);
 
106
 
 
107
        void BeginUndoAction();
 
108
        void EndUndoAction();
 
109
        void DropUndoSequence();
 
110
        void DeleteUndoHistory();
 
111
 
 
112
        /// The save point is a marker in the undo stack where the container has stated that
 
113
        /// the buffer was saved. Undo and redo can move over the save point.
 
114
        void SetSavePoint();
 
115
        bool IsSavePoint() const;
 
116
 
 
117
        /// To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
 
118
        /// called that many times. Similarly for redo.
 
119
        bool CanUndo() const;
 
120
        int StartUndo();
 
121
        const Action &GetUndoStep() const;
 
122
        void CompletedUndoStep();
 
123
        bool CanRedo() const;
 
124
        int StartRedo();
 
125
        const Action &GetRedoStep() const;
 
126
        void CompletedRedoStep();
 
127
};
 
128
 
 
129
/**
 
130
 * Holder for an expandable array of characters that supports undo and line markers.
 
131
 * Based on article "Data Structures in a Bit-Mapped Text Editor"
 
132
 * by Wilfred J. Hansen, Byte January 1987, page 183.
 
133
 */
 
134
class CellBuffer {
 
135
private:
 
136
        SplitVector<char> substance;
 
137
        SplitVector<char> style;
 
138
        bool readOnly;
 
139
 
 
140
        bool collectingUndo;
 
141
        UndoHistory uh;
 
142
 
 
143
        LineVector lv;
 
144
 
 
145
        /// Actions without undo
 
146
        void BasicInsertString(int position, const char *s, int insertLength);
 
147
        void BasicDeleteChars(int position, int deleteLength);
 
148
 
 
149
public:
 
150
 
 
151
        CellBuffer();
 
152
        ~CellBuffer();
 
153
 
 
154
        /// Retrieving positions outside the range of the buffer works and returns 0
 
155
        char CharAt(int position) const;
 
156
        void GetCharRange(char *buffer, int position, int lengthRetrieve) const;
 
157
        char StyleAt(int position) const;
 
158
        void GetStyleRange(unsigned char *buffer, int position, int lengthRetrieve) const;
 
159
        const char *BufferPointer();
 
160
 
 
161
        int Length() const;
 
162
        void Allocate(int newSize);
 
163
        void SetPerLine(PerLine *pl);
 
164
        int Lines() const;
 
165
        int LineStart(int line) const;
 
166
        int LineFromPosition(int pos) const { return lv.LineFromPosition(pos); }
 
167
        void InsertLine(int line, int position, bool lineStart);
 
168
        void RemoveLine(int line);
 
169
        const char *InsertString(int position, const char *s, int insertLength, bool &startSequence);
 
170
 
 
171
        /// Setting styles for positions outside the range of the buffer is safe and has no effect.
 
172
        /// @return true if the style of a character is changed.
 
173
        bool SetStyleAt(int position, char styleValue, char mask='\377');
 
174
        bool SetStyleFor(int position, int length, char styleValue, char mask);
 
175
 
 
176
        const char *DeleteChars(int position, int deleteLength, bool &startSequence);
 
177
 
 
178
        bool IsReadOnly() const;
 
179
        void SetReadOnly(bool set);
 
180
 
 
181
        /// The save point is a marker in the undo stack where the container has stated that
 
182
        /// the buffer was saved. Undo and redo can move over the save point.
 
183
        void SetSavePoint();
 
184
        bool IsSavePoint();
 
185
 
 
186
        bool SetUndoCollection(bool collectUndo);
 
187
        bool IsCollectingUndo() const;
 
188
        void BeginUndoAction();
 
189
        void EndUndoAction();
 
190
        void AddUndoAction(int token, bool mayCoalesce);
 
191
        void DeleteUndoHistory();
 
192
 
 
193
        /// To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
 
194
        /// called that many times. Similarly for redo.
 
195
        bool CanUndo();
 
196
        int StartUndo();
 
197
        const Action &GetUndoStep() const;
 
198
        void PerformUndoStep();
 
199
        bool CanRedo();
 
200
        int StartRedo();
 
201
        const Action &GetRedoStep() const;
 
202
        void PerformRedoStep();
 
203
};
 
204
 
 
205
#ifdef SCI_NAMESPACE
 
206
}
 
207
#endif
 
208
 
 
209
#endif