~ubuntu-branches/ubuntu/raring/codeblocks/raring-proposed

« back to all changes in this revision

Viewing changes to src/sdk/wxscintilla/src/scintilla/src/Selection.h

  • Committer: Bazaar Package Importer
  • Author(s): Cosme Domínguez Díaz
  • Date: 2010-08-09 04:38:38 UTC
  • mfrom: (1.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20100809043838-a59ygguym4eg0jgw
Tags: 10.05-0ubuntu1
* New upstream release. Closes (LP: #322350)
 - Switch to dpkg-source 3.0 (quilt) format
 - Remove unneeded README.source
 - Add debian/get-source-orig script that removes all
   Windows prebuilt binaries
* Bump Standards-Version to 3.9.1
 - Stop shipping *.la files
* debian/control
 - Add cdbs package as Build-Depend
 - Add libbz2-dev and zlib1g-dev packages as
   Build-Depends (needed by libhelp_plugin.so)
 - Remove dpatch package of Build-Depends
 - Add codeblocks-contrib-debug package
 - Split architecture-independent files of codeblocks
   package in codeblocks-common package
* debian/rules
 - Switch to CDBS rules system
 - Add parallel build support
 - Add a call to debian/get-source-orig script
 - Use lzma compression (saves 23,5 MB of free space)
* debian/patches
 - Refresh 01_codeblocks_plugin_path
 - Add 02_no_Makefiles_in_debian_dir to remove any link
   in codeblocks build system to deleted Makefiles of debian directory
 - Drop 02_ftbfs_gcc44 and 03_ftbfs_glib221 (merged in upstream)
* debian/watch
 - Update to use the new host (berlios.de)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Scintilla source code edit control
 
2
/** @file Selection.h
 
3
 ** Classes maintaining the selection.
 
4
 **/
 
5
// Copyright 2009 by Neil Hodgson <neilh@scintilla.org>
 
6
// The License.txt file describes the conditions under which this software may be distributed.
 
7
 
 
8
#ifndef SELECTION_H
 
9
#define SELECTION_H
 
10
 
 
11
/* C::B begin */
 
12
#include <vector>
 
13
/* C::B end */
 
14
 
 
15
#ifdef SCI_NAMESPACE
 
16
namespace Scintilla {
 
17
#endif
 
18
 
 
19
class SelectionPosition {
 
20
        int position;
 
21
        int virtualSpace;
 
22
public:
 
23
        explicit SelectionPosition(int position_=INVALID_POSITION, int virtualSpace_=0) : position(position_), virtualSpace(virtualSpace_) {
 
24
                PLATFORM_ASSERT(virtualSpace < 800000);
 
25
                if (virtualSpace < 0)
 
26
                        virtualSpace = 0;
 
27
        }
 
28
        void Reset() {
 
29
                position = 0;
 
30
                virtualSpace = 0;
 
31
        }
 
32
        void MoveForInsertDelete(bool insertion, int startChange, int length);
 
33
        bool operator ==(const SelectionPosition &other) const {
 
34
                return position == other.position && virtualSpace == other.virtualSpace;
 
35
        }
 
36
        bool operator <(const SelectionPosition &other) const;
 
37
        bool operator >(const SelectionPosition &other) const;
 
38
        bool operator <=(const SelectionPosition &other) const;
 
39
        bool operator >=(const SelectionPosition &other) const;
 
40
        int Position() const {
 
41
                return position;
 
42
        }
 
43
        void SetPosition(int position_) {
 
44
                position = position_;
 
45
                virtualSpace = 0;
 
46
        }
 
47
        int VirtualSpace() const {
 
48
                return virtualSpace;
 
49
        }
 
50
        void SetVirtualSpace(int virtualSpace_) {
 
51
                PLATFORM_ASSERT(virtualSpace_ < 800000);
 
52
                if (virtualSpace_ >= 0)
 
53
                        virtualSpace = virtualSpace_;
 
54
        }
 
55
        void Add(int increment) {
 
56
                position = position + increment;
 
57
        }
 
58
        bool IsValid() const {
 
59
                return position >= 0;
 
60
        }
 
61
};
 
62
 
 
63
// Ordered range to make drawing simpler
 
64
struct SelectionSegment {       
 
65
        SelectionPosition start;
 
66
        SelectionPosition end;
 
67
        SelectionSegment() {
 
68
        }
 
69
        SelectionSegment(SelectionPosition a, SelectionPosition b) {
 
70
                if (a < b) {
 
71
                        start = a;
 
72
                        end = b;
 
73
                } else {
 
74
                        start = b;
 
75
                        end = a;
 
76
                }
 
77
        }
 
78
        bool Empty() const {
 
79
                return start == end;
 
80
        }
 
81
        void Extend(SelectionPosition p) {
 
82
                if (start > p)
 
83
                        start = p;
 
84
                if (end < p)
 
85
                        end = p;
 
86
        }
 
87
};
 
88
 
 
89
struct SelectionRange {
 
90
        SelectionPosition caret;
 
91
        SelectionPosition anchor;
 
92
 
 
93
        SelectionRange() {
 
94
        }
 
95
        SelectionRange(SelectionPosition single) : caret(single), anchor(single) {
 
96
        }
 
97
        SelectionRange(int single) : caret(single), anchor(single) {
 
98
        }
 
99
        SelectionRange(SelectionPosition caret_, SelectionPosition anchor_) : caret(caret_), anchor(anchor_) {
 
100
        }
 
101
        SelectionRange(int caret_, int anchor_) : caret(caret_), anchor(anchor_) {
 
102
        }
 
103
        bool Empty() const {
 
104
                return anchor == caret;
 
105
        }
 
106
        int Length() const;
 
107
        // int Width() const;   // Like Length but takes virtual space into account
 
108
        bool operator ==(const SelectionRange &other) const {
 
109
                return caret == other.caret && anchor == other.anchor;
 
110
        }
 
111
        bool operator <(const SelectionRange &other) const {
 
112
                return caret < other.caret || ((caret == other.caret) && (anchor < other.anchor));
 
113
        }
 
114
        void Reset() {
 
115
                anchor.Reset();
 
116
                caret.Reset();
 
117
        }
 
118
        void ClearVirtualSpace() {
 
119
                anchor.SetVirtualSpace(0);
 
120
                caret.SetVirtualSpace(0);
 
121
        }
 
122
        bool Contains(int pos) const;
 
123
        bool Contains(SelectionPosition sp) const;
 
124
        bool ContainsCharacter(int posCharacter) const;
 
125
        SelectionSegment Intersect(SelectionSegment check) const;
 
126
        SelectionPosition Start() const {
 
127
                return (anchor < caret) ? anchor : caret;
 
128
        }
 
129
        SelectionPosition End() const {
 
130
                return (anchor < caret) ? caret : anchor;
 
131
        }
 
132
        bool Trim(SelectionRange range);
 
133
        // If range is all virtual collapse to start of virtual space
 
134
        void MinimizeVirtualSpace();
 
135
};
 
136
 
 
137
class Selection {
 
138
        std::vector<SelectionRange> ranges;
 
139
        std::vector<SelectionRange> rangesSaved;
 
140
        SelectionRange rangeRectangular;
 
141
        size_t mainRange;
 
142
        bool moveExtends;
 
143
        bool tentativeMain;
 
144
public:
 
145
        enum selTypes { noSel, selStream, selRectangle, selLines, selThin };
 
146
        selTypes selType;
 
147
 
 
148
        Selection();
 
149
        ~Selection();
 
150
        bool IsRectangular() const;
 
151
        int MainCaret() const;
 
152
        int MainAnchor() const;
 
153
        SelectionRange &Rectangular();
 
154
        SelectionSegment Limits() const;
 
155
        // This is for when you want to move the caret in response to a 
 
156
        // user direction command - for rectangular selections, use the range
 
157
        // that covers all selected text otherwise return the main selection.
 
158
        SelectionSegment LimitsForRectangularElseMain() const;
 
159
        size_t Count() const;
 
160
        size_t Main() const;
 
161
        void SetMain(size_t r);
 
162
        SelectionRange &Range(size_t r);
 
163
        SelectionRange &RangeMain();
 
164
        bool MoveExtends() const;
 
165
        void SetMoveExtends(bool moveExtends_);
 
166
        bool Empty() const;
 
167
        SelectionPosition Last() const;
 
168
        int Length() const;
 
169
        void MovePositions(bool insertion, int startChange, int length);
 
170
        void TrimSelection(SelectionRange range);
 
171
        void SetSelection(SelectionRange range);
 
172
        void AddSelection(SelectionRange range);
 
173
        void TentativeSelection(SelectionRange range);
 
174
        void CommitTentative();
 
175
        int CharacterInSelection(int posCharacter) const;
 
176
        int InSelectionForEOL(int pos) const;
 
177
        int VirtualSpaceFor(int pos) const;
 
178
        void Clear();
 
179
        void RemoveDuplicates();
 
180
        void RotateMain();
 
181
        bool Tentative() const { return tentativeMain; }
 
182
        std::vector<SelectionRange> RangesCopy() const {
 
183
                return ranges;
 
184
        }
 
185
};
 
186
 
 
187
#ifdef SCI_NAMESPACE
 
188
}
 
189
#endif
 
190
 
 
191
#endif