~ubuntu-branches/ubuntu/raring/geany/raring-proposed

« back to all changes in this revision

Viewing changes to scintilla/Decoration.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Damián Viano
  • Date: 2008-05-02 11:37:45 UTC
  • mfrom: (1.2.1 upstream) (9 hardy)
  • mto: (3.2.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: james.westby@ubuntu.com-20080502113745-xzp4g6dmovrpoj17
Tags: 0.14-1
New upstream release (Closes: #478126)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** @file Decoration.cxx
 
2
 ** Visual elements added over text.
 
3
 **/
 
4
// Copyright 1998-2007 by Neil Hodgson <neilh@scintilla.org>
 
5
// The License.txt file describes the conditions under which this software may be distributed.
 
6
 
 
7
#include <stdio.h>
 
8
#include <string.h>
 
9
#include <stdlib.h>
 
10
#include <stdarg.h>
 
11
 
 
12
#include "Platform.h"
 
13
 
 
14
#include "Scintilla.h"
 
15
#include "SplitVector.h"
 
16
#include "Partitioning.h"
 
17
#include "RunStyles.h"
 
18
#include "Decoration.h"
 
19
 
 
20
#ifdef SCI_NAMESPACE
 
21
using namespace Scintilla;
 
22
#endif
 
23
 
 
24
Decoration::Decoration(int indicator_) : next(0), indicator(indicator_) {
 
25
}
 
26
 
 
27
Decoration::~Decoration() {
 
28
}
 
29
 
 
30
bool Decoration::Empty() {
 
31
        return rs.starts->Partitions() == 1;
 
32
}
 
33
 
 
34
DecorationList::DecorationList() : currentIndicator(0), currentValue(1), current(0),
 
35
        lengthDocument(0), root(0), clickNotified(false) {
 
36
}
 
37
 
 
38
DecorationList::~DecorationList() {
 
39
        Decoration *deco = root;
 
40
        while (deco) {
 
41
                Decoration *decoNext = deco->next;
 
42
                delete deco;
 
43
                deco = decoNext;
 
44
        }
 
45
        root = 0;
 
46
        current = 0;
 
47
}
 
48
 
 
49
Decoration *DecorationList::DecorationFromIndicator(int indicator) {
 
50
        for (Decoration *deco=root; deco; deco = deco->next) {
 
51
                if (deco->indicator == indicator) {
 
52
                        return deco;
 
53
                }
 
54
        }
 
55
        return 0;
 
56
}
 
57
 
 
58
Decoration *DecorationList::Create(int indicator, int length) {
 
59
        currentIndicator = indicator;
 
60
        Decoration *decoNew = new Decoration(indicator);
 
61
        decoNew->rs.InsertSpace(0, length);
 
62
 
 
63
        Decoration *decoPrev = 0;
 
64
        Decoration *deco = root;
 
65
 
 
66
        while (deco && (deco->indicator < indicator)) {
 
67
                decoPrev = deco;
 
68
                deco = deco->next;
 
69
        }
 
70
        if (decoPrev == 0) {
 
71
                decoNew->next = root;
 
72
                root = decoNew;
 
73
        } else {
 
74
                decoNew->next = deco;
 
75
                decoPrev->next = decoNew;
 
76
        }
 
77
        return decoNew;
 
78
}
 
79
 
 
80
void DecorationList::Delete(int indicator) {
 
81
        Decoration *decoToDelete = 0;
 
82
        if (root) {
 
83
                if (root->indicator == indicator) {
 
84
                        decoToDelete = root;
 
85
                        root = root->next;
 
86
                } else {
 
87
                        Decoration *deco=root;
 
88
                        while (deco->next && !decoToDelete) {
 
89
                                if (deco->next && deco->next->indicator == indicator) {
 
90
                                        decoToDelete = deco->next;
 
91
                                        deco->next = decoToDelete->next;
 
92
                                } else {
 
93
                                        deco = deco->next;
 
94
                                }
 
95
                        }
 
96
                }
 
97
        }
 
98
        if (decoToDelete) {
 
99
                delete decoToDelete;
 
100
                current = 0;
 
101
        }
 
102
}
 
103
 
 
104
void DecorationList::SetCurrentIndicator(int indicator) {
 
105
        currentIndicator = indicator;
 
106
        current = DecorationFromIndicator(indicator);
 
107
        currentValue = 1;
 
108
}
 
109
 
 
110
void DecorationList::SetCurrentValue(int value) {
 
111
        currentValue = value ? value : 1;
 
112
}
 
113
 
 
114
bool DecorationList::FillRange(int &position, int value, int &fillLength) {
 
115
        if (!current) {
 
116
                current = DecorationFromIndicator(currentIndicator);
 
117
                if (!current) {
 
118
                        current = Create(currentIndicator, lengthDocument);
 
119
                }
 
120
        }
 
121
        bool changed = current->rs.FillRange(position, value, fillLength);
 
122
        if (current->Empty()) {
 
123
                Delete(currentIndicator);
 
124
        }
 
125
        return changed;
 
126
}
 
127
 
 
128
void DecorationList::InsertSpace(int position, int insertLength) {
 
129
        lengthDocument += insertLength;
 
130
        for (Decoration *deco=root; deco; deco = deco->next) {
 
131
                deco->rs.InsertSpace(position, insertLength);
 
132
        }
 
133
}
 
134
 
 
135
void DecorationList::DeleteRange(int position, int deleteLength) {
 
136
        lengthDocument -= deleteLength;
 
137
        Decoration *deco;
 
138
        for (deco=root; deco; deco = deco->next) {
 
139
                deco->rs.DeleteRange(position, deleteLength);
 
140
        }
 
141
        DeleteAnyEmpty();
 
142
}
 
143
 
 
144
void DecorationList::DeleteAnyEmpty() {
 
145
        Decoration *deco = root;
 
146
        while (deco) {
 
147
                if (deco->Empty()) {
 
148
                        Delete(deco->indicator);
 
149
                        deco = root;
 
150
                } else {
 
151
                        deco = deco->next;
 
152
                }
 
153
        }
 
154
}
 
155
 
 
156
int DecorationList::AllOnFor(int position) {
 
157
        int mask = 0;
 
158
        for (Decoration *deco=root; deco; deco = deco->next) {
 
159
                if (deco->rs.ValueAt(position)) {
 
160
                        mask |= 1 << deco->indicator;
 
161
                }
 
162
        }
 
163
        return mask;
 
164
}
 
165
 
 
166
int DecorationList::ValueAt(int indicator, int position) {
 
167
        Decoration *deco = DecorationFromIndicator(indicator);
 
168
        if (deco) {
 
169
                return deco->rs.ValueAt(position);
 
170
        }
 
171
        return 0;
 
172
}
 
173
 
 
174
int DecorationList::Start(int indicator, int position) {
 
175
        Decoration *deco = DecorationFromIndicator(indicator);
 
176
        if (deco) {
 
177
                return deco->rs.StartRun(position);
 
178
        }
 
179
        return 0;
 
180
}
 
181
 
 
182
int DecorationList::End(int indicator, int position) {
 
183
        Decoration *deco = DecorationFromIndicator(indicator);
 
184
        if (deco) {
 
185
                return deco->rs.EndRun(position);
 
186
        }
 
187
        return 0;
 
188
}