diff options
Diffstat (limited to 'scintilla/src')
30 files changed, 625 insertions, 983 deletions
diff --git a/scintilla/src/CallTip.cxx b/scintilla/src/CallTip.cxx index d574a6d..d285a83 100644 --- a/scintilla/src/CallTip.cxx +++ b/scintilla/src/CallTip.cxx @@ -7,12 +7,14 @@ #include <stdlib.h>
#include <string.h>
+#include <stdio.h>
+
+#include <string>
#include "Platform.h"
#include "Scintilla.h"
#include "CallTip.h"
-#include <stdio.h>
#ifdef SCI_NAMESPACE
using namespace Scintilla;
@@ -22,7 +24,6 @@ CallTip::CallTip() { wCallTip = 0;
inCallTipMode = false;
posStartCallTip = 0;
- val = 0;
rectUp = PRectangle(0,0,0,0);
rectDown = PRectangle(0,0,0,0);
lineHeight = 1;
@@ -56,8 +57,6 @@ CallTip::CallTip() { CallTip::~CallTip() {
font.Release();
wCallTip.Destroy();
- delete []val;
- val = 0;
}
// Although this test includes 0, we should never see a \0 character.
@@ -176,17 +175,17 @@ int CallTip::PaintContents(Surface *surfaceWindow, bool draw) { // Draw the definition in three parts: before highlight, highlighted, after highlight
int ytext = rcClient.top + ascent + 1;
rcClient.bottom = ytext + surfaceWindow->Descent(font) + 1;
- char *chunkVal = val;
+ const char *chunkVal = val.c_str();
bool moreChunks = true;
int maxWidth = 0;
while (moreChunks) {
- char *chunkEnd = strchr(chunkVal, '\n');
+ const char *chunkEnd = strchr(chunkVal, '\n');
if (chunkEnd == NULL) {
chunkEnd = chunkVal + strlen(chunkVal);
moreChunks = false;
}
- int chunkOffset = chunkVal - val;
+ int chunkOffset = chunkVal - val.c_str();
int chunkLength = chunkEnd - chunkVal;
int chunkEndOffset = chunkOffset + chunkLength;
int thisStartHighlight = Platform::Maximum(startHighlight, chunkOffset);
@@ -215,7 +214,7 @@ int CallTip::PaintContents(Surface *surfaceWindow, bool draw) { }
void CallTip::PaintCT(Surface *surfaceWindow) {
- if (!val)
+ if (val.empty())
return;
PRectangle rcClientPos = wCallTip.GetClientPosition();
PRectangle rcClientSize(0, 0, rcClientPos.right - rcClientPos.left,
@@ -253,10 +252,7 @@ PRectangle CallTip::CallTipStart(int pos, Point pt, int textHeight, const char * int codePage_, int characterSet,
int technology, Window &wParent) {
clickPlace = 0;
- delete []val;
- val = 0;
- val = new char[strlen(defn) + 1];
- strcpy(val, defn);
+ val = defn;
codePage = codePage_;
Surface *surfaceMeasure = Surface::Allocate(technology);
if (!surfaceMeasure)
@@ -275,7 +271,7 @@ PRectangle CallTip::CallTipStart(int pos, Point pt, int textHeight, const char * // Only support \n here - simply means container must avoid \r!
int numLines = 1;
const char *newline;
- const char *look = val;
+ const char *look = val.c_str();
rectUp = PRectangle(0,0,0,0);
rectDown = PRectangle(0,0,0,0);
offsetMain = insetX; // changed to right edge of any arrows
diff --git a/scintilla/src/CallTip.h b/scintilla/src/CallTip.h index 85b837f..fca69d1 100644 --- a/scintilla/src/CallTip.h +++ b/scintilla/src/CallTip.h @@ -17,7 +17,7 @@ namespace Scintilla { class CallTip {
int startHighlight; // character offset to start and...
int endHighlight; // ...end of highlighted text
- char *val;
+ std::string val;
Font font;
PRectangle rectUp; // rectangle of last up angle in the tip
PRectangle rectDown; // rectangle of last down arrow in the tip
diff --git a/scintilla/src/CellBuffer.cxx b/scintilla/src/CellBuffer.cxx index 7c1b42c..95e2a80 100644 --- a/scintilla/src/CellBuffer.cxx +++ b/scintilla/src/CellBuffer.cxx @@ -10,6 +10,8 @@ #include <stdlib.h>
#include <stdarg.h>
+#include <algorithm>
+
#include "Platform.h"
#include "Scintilla.h"
@@ -81,11 +83,15 @@ Action::~Action() { Destroy();
}
-void Action::Create(actionType at_, int position_, char *data_, int lenData_, bool mayCoalesce_) {
+void Action::Create(actionType at_, int position_, const char *data_, int lenData_, bool mayCoalesce_) {
delete []data;
+ data = NULL;
position = position_;
at = at_;
- data = data_;
+ if (lenData_) {
+ data = new char[lenData_];
+ memcpy(data, data_, lenData_);
+ }
lenData = lenData_;
mayCoalesce = mayCoalesce_;
}
@@ -162,7 +168,7 @@ void UndoHistory::EnsureUndoRoom() { }
}
-void UndoHistory::AppendAction(actionType at, int position, char *data, int lengthData,
+void UndoHistory::AppendAction(actionType at, int position, const char *data, int lengthData,
bool &startSequence, bool mayCoalesce) {
EnsureUndoRoom();
//Platform::DebugPrintf("%% %d action %d %d %d\n", at, position, lengthData, currentAction);
@@ -393,11 +399,7 @@ const char *CellBuffer::InsertString(int position, const char *s, int insertLeng if (collectingUndo) {
// Save into the undo/redo stack, but only the characters - not the formatting
// This takes up about half load time
- data = new char[insertLength];
- for (int i = 0; i < insertLength; i++) {
- data[i] = s[i];
- }
- uh.AppendAction(insertAction, position, data, insertLength, startSequence);
+ uh.AppendAction(insertAction, position, s, insertLength, startSequence);
}
BasicInsertString(position, s, insertLength);
@@ -439,10 +441,8 @@ const char *CellBuffer::DeleteChars(int position, int deleteLength, bool &startS if (!readOnly) {
if (collectingUndo) {
// Save into the undo/redo stack, but only the characters - not the formatting
- data = new char[deleteLength];
- for (int i = 0; i < deleteLength; i++) {
- data[i] = substance.ValueAt(position + i);
- }
+ // The gap would be moved to position anyway for the deletion so this doesn't cost extra
+ const char *data = substance.RangePointer(position, deleteLength);
uh.AppendAction(removeAction, position, data, deleteLength, startSequence);
}
diff --git a/scintilla/src/CellBuffer.h b/scintilla/src/CellBuffer.h index 86b94cb..394b89a 100644 --- a/scintilla/src/CellBuffer.h +++ b/scintilla/src/CellBuffer.h @@ -80,7 +80,7 @@ public: Action();
~Action();
- void Create(actionType at_, int position_=0, char *data_=0, int lenData_=0, bool mayCoalesce_=true);
+ void Create(actionType at_, int position_=0, const char *data_=0, int lenData_=0, bool mayCoalesce_=true);
void Destroy();
void Grab(Action *source);
};
@@ -105,7 +105,7 @@ public: UndoHistory();
~UndoHistory();
- void AppendAction(actionType at, int position, char *data, int length, bool &startSequence, bool mayCoalesce=true);
+ void AppendAction(actionType at, int position, const char *data, int length, bool &startSequence, bool mayCoalesce=true);
void BeginUndoAction();
void EndUndoAction();
diff --git a/scintilla/src/ContractionState.cxx b/scintilla/src/ContractionState.cxx index 938e16f..ac8939e 100644 --- a/scintilla/src/ContractionState.cxx +++ b/scintilla/src/ContractionState.cxx @@ -7,6 +7,8 @@ #include <string.h>
+#include <algorithm>
+
#include "Platform.h"
#include "SplitVector.h"
diff --git a/scintilla/src/Decoration.cxx b/scintilla/src/Decoration.cxx index 4ed0b46..1ad03e4 100644 --- a/scintilla/src/Decoration.cxx +++ b/scintilla/src/Decoration.cxx @@ -9,6 +9,8 @@ #include <stdlib.h>
#include <stdarg.h>
+#include <algorithm>
+
#include "Platform.h"
#include "Scintilla.h"
diff --git a/scintilla/src/Document.cxx b/scintilla/src/Document.cxx index 38b931c..33a7c79 100644 --- a/scintilla/src/Document.cxx +++ b/scintilla/src/Document.cxx @@ -13,6 +13,7 @@ #include <string>
#include <vector>
+#include <algorithm>
#include "Platform.h"
@@ -102,8 +103,6 @@ Document::Document() { useTabs = true;
tabIndents = true;
backspaceUnindents = false;
- watchers = 0;
- lenWatchers = 0;
matchesValid = false;
regex = 0;
@@ -122,16 +121,13 @@ Document::Document() { }
Document::~Document() {
- for (int i = 0; i < lenWatchers; i++) {
- watchers[i].watcher->NotifyDeleted(this, watchers[i].userData);
+ for (std::vector<WatcherWithUserData>::iterator it = watchers.begin(); it != watchers.end(); ++it) {
+ it->watcher->NotifyDeleted(this, it->userData);
}
- delete []watchers;
for (int j=0; j<ldSize; j++) {
delete perLineData[j];
perLineData[j] = 0;
}
- watchers = 0;
- lenWatchers = 0;
delete regex;
regex = 0;
delete pli;
@@ -309,9 +305,9 @@ int SCI_METHOD Document::LineEnd(int line) const { }
void SCI_METHOD Document::SetErrorStatus(int status) {
- // Tell the watchers the lexer has changed.
- for (int i = 0; i < lenWatchers; i++) {
- watchers[i].watcher->NotifyErrorOccurred(this, watchers[i].userData, status);
+ // Tell the watchers an error has occurred.
+ for (std::vector<WatcherWithUserData>::iterator it = watchers.begin(); it != watchers.end(); ++it) {
+ it->watcher->NotifyErrorOccurred(this, it->userData, status);
}
}
@@ -420,7 +416,7 @@ void Document::GetHighlightDelimiters(HighlightDelimiter &highlightDelimiter, in int lookLine = line;
int lookLineLevel = level;
int lookLineLevelNum = lookLineLevel & SC_FOLDLEVELNUMBERMASK;
- while ((lookLine > 0) && ((lookLineLevel & SC_FOLDLEVELWHITEFLAG) ||
+ while ((lookLine > 0) && ((lookLineLevel & SC_FOLDLEVELWHITEFLAG) ||
((lookLineLevel & SC_FOLDLEVELHEADERFLAG) && (lookLineLevelNum >= (GetLevel(lookLine + 1) & SC_FOLDLEVELNUMBERMASK))))) {
lookLineLevel = GetLevel(--lookLine);
lookLineLevelNum = lookLineLevel & SC_FOLDLEVELNUMBERMASK;
@@ -453,8 +449,8 @@ void Document::GetHighlightDelimiters(HighlightDelimiter &highlightDelimiter, in }
}
if (firstChangeableLineBefore == -1) {
- for (lookLine = line - 1, lookLineLevel = GetLevel(lookLine), lookLineLevelNum = lookLineLevel & SC_FOLDLEVELNUMBERMASK;
- lookLine >= beginFoldBlock;
+ for (lookLine = line - 1, lookLineLevel = GetLevel(lookLine), lookLineLevelNum = lookLineLevel & SC_FOLDLEVELNUMBERMASK;
+ lookLine >= beginFoldBlock;
lookLineLevel = GetLevel(--lookLine), lookLineLevelNum = lookLineLevel & SC_FOLDLEVELNUMBERMASK) {
if ((lookLineLevel & SC_FOLDLEVELWHITEFLAG) || (lookLineLevelNum > (level & SC_FOLDLEVELNUMBERMASK))) {
firstChangeableLineBefore = lookLine;
@@ -466,8 +462,8 @@ void Document::GetHighlightDelimiters(HighlightDelimiter &highlightDelimiter, in firstChangeableLineBefore = beginFoldBlock - 1;
int firstChangeableLineAfter = -1;
- for (lookLine = line + 1, lookLineLevel = GetLevel(lookLine), lookLineLevelNum = lookLineLevel & SC_FOLDLEVELNUMBERMASK;
- lookLine <= endFoldBlock;
+ for (lookLine = line + 1, lookLineLevel = GetLevel(lookLine), lookLineLevelNum = lookLineLevel & SC_FOLDLEVELNUMBERMASK;
+ lookLine <= endFoldBlock;
lookLineLevel = GetLevel(++lookLine), lookLineLevelNum = lookLineLevel & SC_FOLDLEVELNUMBERMASK) {
if ((lookLineLevel & SC_FOLDLEVELHEADERFLAG) && (lookLineLevelNum < (GetLevel(lookLine + 1) & SC_FOLDLEVELNUMBERMASK))) {
firstChangeableLineAfter = lookLine;
@@ -715,7 +711,7 @@ bool SCI_METHOD Document::IsDBCSLeadByte(char ch) const { // Shift_jis
return ((uch >= 0x81) && (uch <= 0x9F)) ||
((uch >= 0xE0) && (uch <= 0xFC));
- // Lead bytes F0 to FC may be a Microsoft addition.
+ // Lead bytes F0 to FC may be a Microsoft addition.
case 936:
// GBK
return (uch >= 0x81) && (uch <= 0xFE);
@@ -892,7 +888,7 @@ void * SCI_METHOD Document::ConvertToDocument() { int Document::Undo() {
int newPos = -1;
CheckReadOnly();
- if (enteredModification == 0) {
+ if ((enteredModification == 0) && (cb.IsCollectingUndo())) {
enteredModification++;
if (!cb.IsReadOnly()) {
bool startSavePoint = cb.IsSavePoint();
@@ -977,7 +973,7 @@ int Document::Undo() { int Document::Redo() {
int newPos = -1;
CheckReadOnly();
- if (enteredModification == 0) {
+ if ((enteredModification == 0) && (cb.IsCollectingUndo())) {
enteredModification++;
if (!cb.IsReadOnly()) {
bool startSavePoint = cb.IsSavePoint();
@@ -1050,11 +1046,6 @@ bool Document::InsertCString(int position, const char *s) { return InsertString(position, s, static_cast<int>(s ? strlen(s) : 0));
}
-void Document::ChangeChar(int pos, char ch) {
- DeleteChars(pos, 1);
- InsertChar(pos, ch);
-}
-
void Document::DelChar(int pos) {
DeleteChars(pos, LenChar(pos));
}
@@ -1212,32 +1203,25 @@ void Document::Indent(bool forwards, int lineBottom, int lineTop) { // Convert line endings for a piece of text to a particular mode.
// Stop at len or when a NUL is found.
-// Caller must delete the returned pointer.
-char *Document::TransformLineEnds(int *pLenOut, const char *s, size_t len, int eolModeWanted) {
- char *dest = new char[2 * len + 1];
- const char *sptr = s;
- char *dptr = dest;
- for (size_t i = 0; (i < len) && (*sptr != '\0'); i++) {
- if (*sptr == '\n' || *sptr == '\r') {
+std::string Document::TransformLineEnds(const char *s, size_t len, int eolModeWanted) {
+ std::string dest;
+ for (size_t i = 0; (i < len) && (s[i]); i++) {
+ if (s[i] == '\n' || s[i] == '\r') {
if (eolModeWanted == SC_EOL_CR) {
- *dptr++ = '\r';
+ dest.push_back('\r');
} else if (eolModeWanted == SC_EOL_LF) {
- *dptr++ = '\n';
+ dest.push_back('\n');
} else { // eolModeWanted == SC_EOL_CRLF
- *dptr++ = '\r';
- *dptr++ = '\n';
+ dest.push_back('\r');
+ dest.push_back('\n');
}
- if ((*sptr == '\r') && (i+1 < len) && (*(sptr+1) == '\n')) {
+ if ((s[i] == '\r') && (i+1 < len) && (s[i+1] == '\n')) {
i++;
- sptr++;
}
- sptr++;
} else {
- *dptr++ = *sptr++;
+ dest.push_back(s[i]);
}
}
- *dptr++ = '\0';
- *pLenOut = (dptr - dest) - 1;
return dest;
}
@@ -1667,25 +1651,6 @@ int Document::LinesTotal() const { return cb.Lines();
}
-void Document::ChangeCase(Range r, bool makeUpperCase) {
- for (int pos = r.start; pos < r.end;) {
- int len = LenChar(pos);
- if (len == 1) {
- char ch = CharAt(pos);
- if (makeUpperCase) {
- if (IsLowerCase(ch)) {
- ChangeChar(pos, static_cast<char>(MakeUpperCase(ch)));
- }
- } else {
- if (IsUpperCase(ch)) {
- ChangeChar(pos, static_cast<char>(MakeLowerCase(ch)));
- }
- }
- }
- pos += len;
- }
-}
-
void Document::SetDefaultCharClasses(bool includeWordClass) {
charClass.SetDefaultCharClasses(includeWordClass);
}
@@ -1763,8 +1728,9 @@ void Document::EnsureStyledTo(int pos) { pli->Colourise(endStyledTo, pos);
} else {
// Ask the watchers to style, and stop as soon as one responds.
- for (int i = 0; pos > GetEndStyled() && i < lenWatchers; i++) {
- watchers[i].watcher->NotifyStyleNeeded(this, watchers[i].userData, pos);
+ for (std::vector<WatcherWithUserData>::iterator it = watchers.begin();
+ (pos > GetEndStyled()) && (it != watchers.end()); ++it) {
+ it->watcher->NotifyStyleNeeded(this, it->userData, pos);
}
}
}
@@ -1772,8 +1738,8 @@ void Document::EnsureStyledTo(int pos) { void Document::LexerChanged() {
// Tell the watchers the lexer has changed.
- for (int i = 0; i < lenWatchers; i++) {
- watchers[i].watcher->NotifyLexerChanged(this, watchers[i].userData);
+ for (std::vector<WatcherWithUserData>::iterator it = watchers.begin(); it != watchers.end(); ++it) {
+ it->watcher->NotifyLexerChanged(this, it->userData);
}
}
@@ -1821,10 +1787,6 @@ void Document::MarginSetStyles(int line, const unsigned char *styles) { NotifyModified(DocModification(SC_MOD_CHANGEMARGIN, LineStart(line), 0, 0, 0, line));
}
-int Document::MarginLength(int line) const {
- return static_cast<LineAnnotation *>(perLineData[ldMargin])->Length(line);
-}
-
void Document::MarginClearAll() {
int maxEditorLine = LinesTotal();
for (int l=0; l<maxEditorLine; l++)
@@ -1833,10 +1795,6 @@ void Document::MarginClearAll() { static_cast<LineAnnotation *>(perLineData[ldMargin])->ClearAll();
}
-bool Document::AnnotationAny() const {
- return static_cast<LineAnnotation *>(perLineData[ldAnnotation])->AnySet();
-}
-
StyledText Document::AnnotationStyledText(int line) {
LineAnnotation *pla = static_cast<LineAnnotation *>(perLineData[ldAnnotation]);
return StyledText(pla->Length(line), pla->Text(line),
@@ -1866,10 +1824,6 @@ void Document::AnnotationSetStyles(int line, const unsigned char *styles) { }
}
-int Document::AnnotationLength(int line) const {
- return static_cast<LineAnnotation *>(perLineData[ldAnnotation])->Length(line);
-}
-
int Document::AnnotationLines(int line) const {
return static_cast<LineAnnotation *>(perLineData[ldAnnotation])->Lines(line);
}
@@ -1895,54 +1849,34 @@ void SCI_METHOD Document::DecorationFillRange(int position, int value, int fillL }
bool Document::AddWatcher(DocWatcher *watcher, void *userData) {
- for (int i = 0; i < lenWatchers; i++) {
- if ((watchers[i].watcher == watcher) &&
- (watchers[i].userData == userData))
- return false;
- }
- WatcherWithUserData *pwNew = new WatcherWithUserData[lenWatchers + 1];
- for (int j = 0; j < lenWatchers; j++)
- pwNew[j] = watchers[j];
- pwNew[lenWatchers].watcher = watcher;
- pwNew[lenWatchers].userData = userData;
- delete []watchers;
- watchers = pwNew;
- lenWatchers++;
+ WatcherWithUserData wwud(watcher, userData);
+ std::vector<WatcherWithUserData>::iterator it =
+ std::find(watchers.begin(), watchers.end(), wwud);
+ if (it != watchers.end())
+ return false;
+ watchers.push_back(wwud);
return true;
}
bool Document::RemoveWatcher(DocWatcher *watcher, void *userData) {
- for (int i = 0; i < lenWatchers; i++) {
- if ((watchers[i].watcher == watcher) &&
- (watchers[i].userData == userData)) {
- if (lenWatchers == 1) {
- delete []watchers;
- watchers = 0;
- lenWatchers = 0;
- } else {
- WatcherWithUserData *pwNew = new WatcherWithUserData[lenWatchers];
- for (int j = 0; j < lenWatchers - 1; j++) {
- pwNew[j] = (j < i) ? watchers[j] : watchers[j + 1];
- }
- delete []watchers;
- watchers = pwNew;
- lenWatchers--;
- }
- return true;
- }
+ std::vector<WatcherWithUserData>::iterator it =
+ std::find(watchers.begin(), watchers.end(), WatcherWithUserData(watcher, userData));
+ if (it != watchers.end()) {
+ watchers.erase(it);
+ return true;
}
return false;
}
void Document::NotifyModifyAttempt() {
- for (int i = 0; i < lenWatchers; i++) {
- watchers[i].watcher->NotifyModifyAttempt(this, watchers[i].userData);
+ for (std::vector<WatcherWithUserData>::iterator it = watchers.begin(); it != watchers.end(); ++it) {
+ it->watcher->NotifyModifyAttempt(this, it->userData);
}
}
void Document::NotifySavePoint(bool atSavePoint) {
- for (int i = 0; i < lenWatchers; i++) {
- watchers[i].watcher->NotifySavePoint(this, watchers[i].userData, atSavePoint);
+ for (std::vector<WatcherWithUserData>::iterator it = watchers.begin(); it != watchers.end(); ++it) {
+ it->watcher->NotifySavePoint(this, it->userData, atSavePoint);
}
}
@@ -1952,8 +1886,8 @@ void Document::NotifyModified(DocModification mh) { } else if (mh.modificationType & SC_MOD_DELETETEXT) {
decorations.DeleteRange(mh.position, mh.length);
}
- for (int i = 0; i < lenWatchers; i++) {
- watchers[i].watcher->NotifyModified(this, mh, watchers[i].userData);
+ for (std::vector<WatcherWithUserData>::iterator it = watchers.begin(); it != watchers.end(); ++it) {
+ it->watcher->NotifyModified(this, mh, it->userData);
}
}
@@ -2127,10 +2061,9 @@ int Document::BraceMatch(int position, int /*maxReStyle*/) { */
class BuiltinRegex : public RegexSearchBase {
public:
- BuiltinRegex(CharClassify *charClassTable) : search(charClassTable), substituted(NULL) {}
+ BuiltinRegex(CharClassify *charClassTable) : search(charClassTable) {}
virtual ~BuiltinRegex() {
- delete substituted;
}
virtual long FindText(Document *doc, int minPos, int maxPos, const char *s,
@@ -2141,7 +2074,7 @@ public: private:
RESearch search;
- char *substituted;
+ std::string substituted;
};
// Define a way for the Regular Expression code to access the document
@@ -2236,6 +2169,8 @@ long BuiltinRegex::FindText(Document *doc, int minPos, int maxPos, const char *s int success = search.Execute(di, startOfLine, endOfLine);
if (success) {
pos = search.bopat[0];
+ // Ensure only whole characters selected
+ search.eopat[0] = doc->MovePositionOutsideChar(search.eopat[0], 1, false);
lenRet = search.eopat[0] - search.bopat[0];
// There can be only one start of a line, so no need to look for last match in line
if ((increment == -1) && (s[0] != '^')) {
@@ -2261,86 +2196,55 @@ long BuiltinRegex::FindText(Document *doc, int minPos, int maxPos, const char *s }
const char *BuiltinRegex::SubstituteByPosition(Document *doc, const char *text, int *length) {
- delete []substituted;
- substituted = 0;
+ substituted.clear();
DocumentIndexer di(doc, doc->Length());
- if (!search.GrabMatches(di))
- return 0;
- unsigned int lenResult = 0;
- for (int i = 0; i < *length; i++) {
- if (text[i] == '\\') {
- if (text[i + 1] >= '0' && text[i + 1] <= '9') {
- unsigned int patNum = text[i + 1] - '0';
- lenResult += search.eopat[patNum] - search.bopat[patNum];
- i++;
- } else {
- switch (text[i + 1]) {
- case 'a':
- case 'b':
- case 'f':
- case 'n':
- case 'r':
- case 't':
- case 'v':
- case '\\':
- i++;
- }
- lenResult++;
- }
- } else {
- lenResult++;
- }
- }
- substituted = new char[lenResult + 1];
- char *o = substituted;
+ search.GrabMatches(di);
for (int j = 0; j < *length; j++) {
if (text[j] == '\\') {
if (text[j + 1] >= '0' && text[j + 1] <= '9') {
unsigned int patNum = text[j + 1] - '0';
unsigned int len = search.eopat[patNum] - search.bopat[patNum];
- if (search.pat[patNum]) // Will be null if try for a match that did not occur
- memcpy(o, search.pat[patNum], len);
- o += len;
+ if (!search.pat[patNum].empty()) // Will be null if try for a match that did not occur
+ substituted.append(search.pat[patNum].c_str(), len);
j++;
} else {
j++;
switch (text[j]) {
case 'a':
- *o++ = '\a';
+ substituted.push_back('\a');
break;
case 'b':
- *o++ = '\b';
+ substituted.push_back('\b');
break;
case 'f':
- *o++ = '\f';
+ substituted.push_back('\f');
break;
case 'n':
- *o++ = '\n';
+ substituted.push_back('\n');
break;
case 'r':
- *o++ = '\r';
+ substituted.push_back('\r');
break;
case 't':
- *o++ = '\t';
+ substituted.push_back('\t');
break;
case 'v':
- *o++ = '\v';
+ substituted.push_back('\v');
break;
case '\\':
- *o++ = '\\';
+ substituted.push_back('\\');
break;
default:
- *o++ = '\\';
+ substituted.push_back('\\');
j--;
}
}
} else {
- *o++ = text[j];
+ substituted.push_back(text[j]);
}
}
- *o = '\0';
- *length = lenResult;
- return substituted;
+ *length = static_cast<int>(substituted.length());
+ return substituted.c_str();
}
#ifndef SCI_OWNREGEX
diff --git a/scintilla/src/Document.h b/scintilla/src/Document.h index 1c6a02a..00cd1e6 100644 --- a/scintilla/src/Document.h +++ b/scintilla/src/Document.h @@ -198,17 +198,17 @@ class Document : PerLine, public IDocumentWithLineEnd, public ILoader { public:
/** Used to pair watcher pointer with user data. */
- class WatcherWithUserData {
- public:
+ struct WatcherWithUserData {
DocWatcher *watcher;
void *userData;
- WatcherWithUserData() {
- watcher = 0;
- userData = 0;
+ WatcherWithUserData(DocWatcher *watcher_=0, void *userData_=0) :
+ watcher(watcher_), userData(userData_) {
+ }
+ bool operator==(const WatcherWithUserData &other) {
+ return (watcher == other.watcher) && (userData == other.userData);
}
};
- enum charClassification { ccSpace, ccNewLine, ccWord, ccPunctuation };
private:
int refCount;
CellBuffer cb;
@@ -221,8 +221,7 @@ private: int enteredStyling;
int enteredReadOnlyCount;
- WatcherWithUserData *watchers;
- int lenWatchers;
+ std::vector<WatcherWithUserData> watchers;
// ldSize is not real data - it is for dimensions and loops
enum lineData { ldMarkers, ldLevels, ldState, ldMargin, ldAnnotation, ldSize };
@@ -316,14 +315,13 @@ public: int CountCharacters(int startPos, int endPos);
int FindColumn(int line, int column);
void Indent(bool forwards, int lineBottom, int lineTop);
- static char *TransformLineEnds(int *pLenOut, const char *s, size_t len, int eolModeWanted);
+ static std::string TransformLineEnds(const char *s, size_t len, int eolModeWanted);
void ConvertLineEnds(int eolModeSet);
void SetReadOnly(bool set) { cb.SetReadOnly(set); }
bool IsReadOnly() { return cb.IsReadOnly(); }
bool InsertChar(int pos, char ch);
bool InsertCString(int position, const char *s);
- void ChangeChar(int pos, char ch);
void DelChar(int pos);
void DelCharBack(int pos);
@@ -371,8 +369,6 @@ public: const char *SubstituteByPosition(const char *text, int *length);
int LinesTotal() const;
- void ChangeCase(Range r, bool makeUpperCase);
-
void SetDefaultCharClasses(bool includeWordClass);
void SetCharClasses(const unsigned char *chars, CharClassify::cc newCharClass);
int GetCharsOfClass(CharClassify::cc charClass, unsigned char *buffer);
@@ -399,22 +395,17 @@ public: void MarginSetStyle(int line, int style);
void MarginSetStyles(int line, const unsigned char *styles);
void MarginSetText(int line, const char *text);
- int MarginLength(int line) const;
void MarginClearAll();
- bool AnnotationAny() const;
StyledText AnnotationStyledText(int line);
void AnnotationSetText(int line, const char *text);
void AnnotationSetStyle(int line, int style);
void AnnotationSetStyles(int line, const unsigned char *styles);
- int AnnotationLength(int line) const;
int AnnotationLines(int line) const;
void AnnotationClearAll();
bool AddWatcher(DocWatcher *watcher, void *userData);
bool RemoveWatcher(DocWatcher *watcher, void *userData);
- const WatcherWithUserData *GetWatchers() const { return watchers; }
- int GetLenWatchers() const { return lenWatchers; }
CharClassify::cc WordCharClass(unsigned char ch);
bool IsWordPartSeparator(char ch);
diff --git a/scintilla/src/Editor.cxx b/scintilla/src/Editor.cxx index ff05228..2f5cb46 100644 --- a/scintilla/src/Editor.cxx +++ b/scintilla/src/Editor.cxx @@ -106,7 +106,7 @@ Editor::Editor() { stylesValid = false;
technology = SC_TECHNOLOGY_DEFAULT;
scaleRGBAImage = 100;
-
+
printMagnification = 0;
printColourMode = SC_PRINT_NORMAL;
printWrapState = eWrapWord;
@@ -149,7 +149,7 @@ Editor::Editor() { caretYPolicy = CARET_EVEN;
caretYSlop = 0;
-
+
visiblePolicy = 0;
visibleSlop = 0;
@@ -208,6 +208,7 @@ Editor::Editor() { recordingMacro = false;
foldFlags = 0;
+ foldAutomatic = 0;
wrapState = eWrapNone;
wrapWidth = LineLayout::wrapWidthInfinite;
@@ -1246,6 +1247,9 @@ Editor::XYScrollPosition Editor::XYScrollToMakeVisible(const SelectionRange rang const Point ptBottomCaret(pt.x, pt.y + vs.lineHeight - 1);
XYScrollPosition newXY(xOffset, topLine);
+ if (rcClient.Empty()) {
+ return newXY;
+ }
// Vertical positioning
if ((options & xysVertical) && (pt.y < rcClient.top || ptBottomCaret.y >= rcClient.bottom || (caretYPolicy & CARET_STRICT) != 0)) {
@@ -1764,7 +1768,7 @@ static int WidthStyledText(Surface *surface, ViewStyle &vs, int styleOffset, size_t endSegment = start;
while ((endSegment+1 < len) && (static_cast<size_t>(styles[endSegment+1]) == style))
endSegment++;
- width += surface->WidthText(vs.styles[style+styleOffset].font, text + start,
+ width += surface->WidthText(vs.styles[style+styleOffset].font, text + start,
static_cast<int>(endSegment - start + 1));
start = endSegment + 1;
}
@@ -2286,7 +2290,7 @@ void Editor::LayoutLine(int line, Surface *surface, ViewStyle &vstyle, LineLayou if (vstyle.styles[ll->styles[charInLine]].visible) {
if (isControl) {
if (ll->chars[charInLine] == '\t') {
- ll->positions[charInLine + 1] =
+ ll->positions[charInLine + 1] =
((static_cast<int>((startsegx + 2) / tabWidth) + 1) * tabWidth) - startsegx;
} else if (controlCharSymbol < 32) {
if (ctrlCharWidth[ll->chars[charInLine]] == 0) {
@@ -3850,7 +3854,7 @@ long Editor::FormatRange(bool draw, Sci_RangeToFormat *pfr) { vsPrint.braceBadLightIndicatorSet = false;
// Set colours for printing according to users settings
- for (size_t sty = 0; sty < vsPrint.stylesSize; sty++) {
+ for (size_t sty = 0; sty < vsPrint.styles.size(); sty++) {
if (printColourMode == SC_PRINT_INVERTLIGHT) {
vsPrint.styles[sty].fore = InvertedLight(vsPrint.styles[sty].fore);
vsPrint.styles[sty].back = InvertedLight(vsPrint.styles[sty].back);
@@ -4443,7 +4447,7 @@ void Editor::DelCharBack(bool allowLineStartDeletion) { void Editor::NotifyFocus(bool) {}
void Editor::SetCtrlID(int identifier) {
- ctrlID = identifier;
+ ctrlID = identifier;
}
void Editor::NotifyStyleToNeeded(int endStyleNeeded) {
@@ -4563,11 +4567,32 @@ bool Editor::NotifyMarginClick(Point pt, bool shift, bool ctrl, bool alt) { x += vs.ms[margin].width;
}
if ((marginClicked >= 0) && vs.ms[marginClicked].sensitive) {
+ int position = pdoc->LineStart(LineFromLocation(pt));
+ if ((vs.ms[marginClicked].mask & SC_MASK_FOLDERS) && (foldAutomatic & SC_AUTOMATICFOLD_CLICK)) {
+ int lineClick = pdoc->LineFromPosition(position);
+ if (shift && ctrl) {
+ FoldAll(SC_FOLDACTION_TOGGLE);
+ } else {
+ int levelClick = pdoc->GetLevel(lineClick);
+ if (levelClick & SC_FOLDLEVELHEADERFLAG) {
+ if (shift) {
+ // Ensure all children visible
+ FoldExpand(lineClick, SC_FOLDACTION_EXPAND, levelClick);
+ } else if (ctrl) {
+ FoldExpand(lineClick, SC_FOLDACTION_TOGGLE, levelClick);
+ } else {
+ // Toggle this line
+ FoldLine(lineClick, SC_FOLDACTION_TOGGLE);
+ }
+ }
+ }
+ return true;
+ }
SCNotification scn = {0};
scn.nmhdr.code = SCN_MARGINCLICK;
scn.modifiers = (shift ? SCI_SHIFT : 0) | (ctrl ? SCI_CTRL : 0) |
(alt ? SCI_ALT : 0);
- scn.position = pdoc->LineStart(LineFromLocation(pt));
+ scn.position = position;
scn.margin = marginClicked;
NotifyParent(scn);
return true;
@@ -4706,11 +4731,11 @@ void Editor::NotifyModified(Document *, DocModification mh, void *) { insertingNewLine = true;
}
if (insertingNewLine && (mh.position != pdoc->LineStart(lineOfPos)))
- NotifyNeedShown(mh.position, pdoc->LineStart(lineOfPos+1) - mh.position);
+ NeedShown(mh.position, pdoc->LineStart(lineOfPos+1) - mh.position);
else
- NotifyNeedShown(mh.position, 0);
+ NeedShown(mh.position, 0);
} else if (mh.modificationType & SC_MOD_BEFOREDELETE) {
- NotifyNeedShown(mh.position, mh.length);
+ NeedShown(mh.position, mh.length);
}
}
if (mh.linesAdded != 0) {
@@ -4767,6 +4792,9 @@ void Editor::NotifyModified(Document *, DocModification mh, void *) { }
}
}
+ if ((mh.modificationType & SC_MOD_CHANGEFOLD) && (foldAutomatic & SC_AUTOMATICFOLD_CHANGE)) {
+ FoldChanged(mh.line, mh.foldLevelNow, mh.foldLevelPrev);
+ }
// NOW pay the piper WRT "deferred" visual updates
if (IsLastStep(mh)) {
@@ -4989,10 +5017,9 @@ void Editor::ChangeCaseOfSelection(int caseMapping) { SelectionRange current = sel.Range(r);
SelectionRange currentNoVS = current;
currentNoVS.ClearVirtualSpace();
- char *text = CopyRange(currentNoVS.Start().Position(), currentNoVS.End().Position());
size_t rangeBytes = currentNoVS.Length();
if (rangeBytes > 0) {
- std::string sText(text, rangeBytes);
+ std::string sText = RangeText(currentNoVS.Start().Position(), currentNoVS.End().Position());
std::string sMapped = CaseMapString(sText, caseMapping);
@@ -5015,7 +5042,6 @@ void Editor::ChangeCaseOfSelection(int caseMapping) { sel.Range(r) = current;
}
}
- delete []text;
}
}
@@ -5027,17 +5053,15 @@ void Editor::LineTranspose() { int endPrev = pdoc->LineEnd(line - 1);
int start = pdoc->LineStart(line);
int end = pdoc->LineEnd(line);
- char *line1 = CopyRange(startPrev, endPrev);
+ std::string line1 = RangeText(startPrev, endPrev);
int len1 = endPrev - startPrev;
- char *line2 = CopyRange(start, end);
+ std::string line2 = RangeText(start, end);
int len2 = end - start;
pdoc->DeleteChars(start, len2);
pdoc->DeleteChars(startPrev, len1);
- pdoc->InsertString(startPrev, line2, len2);
- pdoc->InsertString(start - len1 + len2, line1, len1);
+ pdoc->InsertString(startPrev, line2.c_str(), len2);
+ pdoc->InsertString(start - len1 + len2, line1.c_str(), len1);
MovePositionTo(SelectionPosition(start - len1 + len2));
- delete []line1;
- delete []line2;
}
}
@@ -5060,11 +5084,10 @@ void Editor::Duplicate(bool forLine) { start = SelectionPosition(pdoc->LineStart(line));
end = SelectionPosition(pdoc->LineEnd(line));
}
- char *text = CopyRange(start.Position(), end.Position());
+ std::string text = RangeText(start.Position(), end.Position());
if (forLine)
pdoc->InsertString(end.Position(), eol, eolLen);
- pdoc->InsertString(end.Position() + eolLen, text, SelectionRange(end, start).Length());
- delete []text;
+ pdoc->InsertString(end.Position() + eolLen, text.c_str(), SelectionRange(end, start).Length());
}
if (sel.Count() && sel.IsRectangular()) {
SelectionPosition last = sel.Last();
@@ -5992,19 +6015,6 @@ static bool Close(Point pt1, Point pt2) { return true;
}
-char *Editor::CopyRange(int start, int end) {
- char *text = 0;
- if (start < end) {
- int len = end - start;
- text = new char[len + 1];
- for (int i = 0; i < len; i++) {
- text[i] = pdoc->CharAt(start + i);
- }
- text[len] = '\0';
- }
- return text;
-}
-
std::string Editor::RangeText(int start, int end) const {
if (start < end) {
int len = end - start;
@@ -6024,21 +6034,13 @@ void Editor::CopySelectionRange(SelectionText *ss, bool allowLineCopy) { int start = pdoc->LineStart(currentLine);
int end = pdoc->LineEnd(currentLine);
- char *text = CopyRange(start, end);
- size_t textLen = text ? strlen(text) : 0;
- // include room for \r\n\0
- textLen += 3;
- char *textWithEndl = new char[textLen];
- textWithEndl[0] = '\0';
- if (text)
- strcat(textWithEndl, text);
+ std::string text = RangeText(start, end);
if (pdoc->eolMode != SC_EOL_LF)
- strcat(textWithEndl, "\r");
+ text.append("\r");
if (pdoc->eolMode != SC_EOL_CR)
- strcat(textWithEndl, "\n");
- ss->Set(textWithEndl, static_cast<int>(strlen(textWithEndl) + 1),
+ text.append("\n");
+ ss->Copy(text.c_str(), static_cast<int>(text.length() + 1),
pdoc->dbcsCodePage, vs.styles[STYLE_DEFAULT].characterSet, false, true);
- delete []text;
}
} else {
int delimiterLength = 0;
@@ -6050,7 +6052,7 @@ void Editor::CopySelectionRange(SelectionText *ss, bool allowLineCopy) { }
}
size_t size = sel.Length() + delimiterLength * sel.Count();
- char *text = new char[size + 1];
+ std::string text(size+1, '\0');
int j = 0;
std::vector<SelectionRange> rangesInOrder = sel.RangesCopy();
if (sel.selType == Selection::selRectangle)
@@ -6072,7 +6074,7 @@ void Editor::CopySelectionRange(SelectionText *ss, bool allowLineCopy) { }
}
text[size] = '\0';
- ss->Set(text, static_cast<int>(size + 1), pdoc->dbcsCodePage,
+ ss->Copy(&text[0], static_cast<int>(size + 1), pdoc->dbcsCodePage,
vs.styles[STYLE_DEFAULT].characterSet, sel.IsRectangular(), sel.selType == Selection::selLines);
}
}
@@ -6081,7 +6083,8 @@ void Editor::CopyRangeToClipboard(int start, int end) { start = pdoc->ClampPositionIntoDocument(start);
end = pdoc->ClampPositionIntoDocument(end);
SelectionText selectedText;
- selectedText.Set(CopyRange(start, end), end - start + 1,
+ std::string text = RangeText(start, end);
+ selectedText.Copy(text.c_str(), end - start + 1,
pdoc->dbcsCodePage, vs.styles[STYLE_DEFAULT].characterSet, false, false);
CopyToClipboard(selectedText);
}
@@ -6366,7 +6369,7 @@ void Editor::ButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, b if (inSelMargin) {
// Inside margin selection type should be either selSubLine or selWholeLine.
if (selectionType == selSubLine) {
- // If it is selSubLine, we're inside a *double* click and word wrap is enabled,
+ // If it is selSubLine, we're inside a *double* click and word wrap is enabled,
// so we switch to selWholeLine in order to select whole line.
selectionType = selWholeLine;
} else if (selectionType != selSubLine && selectionType != selWholeLine) {
@@ -6378,7 +6381,7 @@ void Editor::ButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, b selectionType = selWord;
doubleClick = true;
} else if (selectionType == selWord) {
- // Since we ended up here, we're inside a *triple* click, which should always select
+ // Since we ended up here, we're inside a *triple* click, which should always select
// whole line irregardless of word wrap being enabled or not.
selectionType = selWholeLine;
} else {
@@ -6443,7 +6446,7 @@ void Editor::ButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, b lineAnchorPos = sel.MainAnchor() - 1;
else
lineAnchorPos = sel.MainAnchor();
- // Reset selection type if there is an empty selection.
+ // Reset selection type if there is an empty selection.
// This ensures that we don't end up stuck in previous selection mode, which is no longer valid.
// Otherwise, if there's a non empty selection, reset selection type only if it differs from selSubLine and selWholeLine.
// This ensures that we continue selecting in the same selection mode.
@@ -6979,34 +6982,42 @@ void Editor::SetAnnotationVisible(int visible) { /**
* Recursively expand a fold, making lines visible except where they have an unexpanded parent.
*/
-void Editor::Expand(int &line, bool doExpand) {
+int Editor::ExpandLine(int line) {
int lineMaxSubord = pdoc->GetLastChild(line);
line++;
while (line <= lineMaxSubord) {
- if (doExpand)
- cs.SetVisible(line, line, true);
+ cs.SetVisible(line, line, true);
int level = pdoc->GetLevel(line);
if (level & SC_FOLDLEVELHEADERFLAG) {
- if (doExpand && cs.GetExpanded(line)) {
- Expand(line, true);
+ if (cs.GetExpanded(line)) {
+ line = ExpandLine(line);
} else {
- Expand(line, false);
+ line = pdoc->GetLastChild(line);
}
- } else {
- line++;
}
+ line++;
+ }
+ return lineMaxSubord;
+}
+
+void Editor::SetFoldExpanded(int lineDoc, bool expanded) {
+ if (cs.SetExpanded(lineDoc, expanded)) {
+ RedrawSelMargin();
}
}
-void Editor::ToggleContraction(int line) {
+void Editor::FoldLine(int line, int action) {
if (line >= 0) {
- if ((pdoc->GetLevel(line) & SC_FOLDLEVELHEADERFLAG) == 0) {
- line = pdoc->GetFoldParent(line);
- if (line < 0)
- return;
+ if (action == SC_FOLDACTION_TOGGLE) {
+ if ((pdoc->GetLevel(line) & SC_FOLDLEVELHEADERFLAG) == 0) {
+ line = pdoc->GetFoldParent(line);
+ if (line < 0)
+ return;
+ }
+ action = (cs.GetExpanded(line)) ? SC_FOLDACTION_CONTRACT : SC_FOLDACTION_EXPAND;
}
- if (cs.GetExpanded(line)) {
+ if (action == SC_FOLDACTION_CONTRACT) {
int lineMaxSubord = pdoc->GetLastChild(line);
if (lineMaxSubord > line) {
cs.SetExpanded(line, 0);
@@ -7017,9 +7028,6 @@ void Editor::ToggleContraction(int line) { // This does not re-expand the fold
EnsureCaretVisible();
}
-
- SetScrollBars();
- Redraw();
}
} else {
@@ -7028,11 +7036,35 @@ void Editor::ToggleContraction(int line) { GoToLine(line);
}
cs.SetExpanded(line, 1);
- Expand(line, true);
- SetScrollBars();
- Redraw();
+ ExpandLine(line);
+ }
+
+ SetScrollBars();
+ Redraw();
+ }
+}
+
+void Editor::FoldExpand(int line, int action, int level) {
+ bool expanding = action == SC_FOLDACTION_EXPAND;
+ if (action == SC_FOLDACTION_TOGGLE) {
+ expanding = !cs.GetExpanded(line);
+ }
+ SetFoldExpanded(line, expanding);
+ if (expanding && (cs.HiddenLines() == 0))
+ // Nothing to do
+ return;
+ int lineMaxSubord = pdoc->GetLastChild(line, level & SC_FOLDLEVELNUMBERMASK);
+ line++;
+ cs.SetVisible(line, lineMaxSubord, expanding);
+ while (line <= lineMaxSubord) {
+ int levelLine = pdoc->GetLevel(line);
+ if (levelLine & SC_FOLDLEVELHEADERFLAG) {
+ SetFoldExpanded(line, expanding);
}
+ line++;
}
+ SetScrollBars();
+ Redraw();
}
int Editor::ContractedFoldNext(int lineStart) {
@@ -7058,7 +7090,7 @@ void Editor::EnsureLineVisible(int lineDoc, bool enforcePolicy) { WrapLines(true, -1);
if (!cs.GetVisible(lineDoc)) {
- // Back up to find a non-blank line
+ // Back up to find a non-blank line
int lookLine = lineDoc;
int lookLineLevel = pdoc->GetLevel(lookLine);
while ((lookLine > 0) && (lookLineLevel & SC_FOLDLEVELWHITEFLAG)) {
@@ -7066,7 +7098,7 @@ void Editor::EnsureLineVisible(int lineDoc, bool enforcePolicy) { }
int lineParent = pdoc->GetFoldParent(lookLine);
if (lineParent < 0) {
- // Backed up to a top level line, so try to find parent of initial line
+ // Backed up to a top level line, so try to find parent of initial line
lineParent = pdoc->GetFoldParent(lineDoc);
}
if (lineParent >= 0) {
@@ -7074,7 +7106,7 @@ void Editor::EnsureLineVisible(int lineDoc, bool enforcePolicy) { EnsureLineVisible(lineParent, enforcePolicy);
if (!cs.GetExpanded(lineParent)) {
cs.SetExpanded(lineParent, 1);
- Expand(lineParent, true);
+ ExpandLine(lineParent);
}
}
SetScrollBars();
@@ -7103,6 +7135,89 @@ void Editor::EnsureLineVisible(int lineDoc, bool enforcePolicy) { }
}
+void Editor::FoldAll(int action) {
+ pdoc->EnsureStyledTo(pdoc->Length());
+ int maxLine = pdoc->LinesTotal();
+ bool expanding = action == SC_FOLDACTION_EXPAND;
+ if (action == SC_FOLDACTION_TOGGLE) {
+ // Discover current state
+ for (int lineSeek = 0; lineSeek < maxLine; lineSeek++) {
+ if (pdoc->GetLevel(lineSeek) & SC_FOLDLEVELHEADERFLAG) {
+ expanding = !cs.GetExpanded(lineSeek);
+ break;
+ }
+ }
+ }
+ if (expanding) {
+ cs.SetVisible(0, maxLine, true);
+ for (int line = 0; line < maxLine; line++) {
+ int levelLine = pdoc->GetLevel(line);
+ if (levelLine & SC_FOLDLEVELHEADERFLAG) {
+ SetFoldExpanded(line, true);
+ }
+ }
+ } else {
+ for (int line = 0; line < maxLine; line++) {
+ int level = pdoc->GetLevel(line);
+ if ((level & SC_FOLDLEVELHEADERFLAG) &&
+ (SC_FOLDLEVELBASE == (level & SC_FOLDLEVELNUMBERMASK))) {
+ SetFoldExpanded(line, false);
+ int lineMaxSubord = pdoc->GetLastChild(line, -1);
+ if (lineMaxSubord > line) {
+ cs.SetVisible(line + 1, lineMaxSubord, false);
+ }
+ }
+ }
+ }
+ SetScrollBars();
+ Redraw();
+}
+
+void Editor::FoldChanged(int line, int levelNow, int levelPrev) {
+ if (levelNow & SC_FOLDLEVELHEADERFLAG) {
+ if (!(levelPrev & SC_FOLDLEVELHEADERFLAG)) {
+ // Adding a fold point.
+ if (cs.SetExpanded(line, true)) {
+ RedrawSelMargin();
+ }
+ FoldExpand(line, SC_FOLDACTION_EXPAND, levelPrev);
+ }
+ } else if (levelPrev & SC_FOLDLEVELHEADERFLAG) {
+ if (!cs.GetExpanded(line)) {
+ // Removing the fold from one that has been contracted so should expand
+ // otherwise lines are left invisible with no way to make them visible
+ if (cs.SetExpanded(line, true)) {
+ RedrawSelMargin();
+ }
+ FoldExpand(line, SC_FOLDACTION_EXPAND, levelPrev);
+ }
+ }
+ if (!(levelNow & SC_FOLDLEVELWHITEFLAG) &&
+ ((levelPrev & SC_FOLDLEVELNUMBERMASK) > (levelNow & SC_FOLDLEVELNUMBERMASK))) {
+ if (cs.HiddenLines()) {
+ // See if should still be hidden
+ int parentLine = pdoc->GetFoldParent(line);
+ if ((parentLine < 0) || (cs.GetExpanded(parentLine) && cs.GetVisible(parentLine))) {
+ cs.SetVisible(line, line, true);
+ SetScrollBars();
+ Redraw();
+ }
+ }
+ }
+}
+
+void Editor::NeedShown(int pos, int len) {
+ if (foldAutomatic & SC_AUTOMATICFOLD_SHOW) {
+ int lineStart = pdoc->LineFromPosition(pos);
+ int lineEnd = pdoc->LineFromPosition(pos+len);
+ for (int line = lineStart; line <= lineEnd; line++) {
+ EnsureLineVisible(line, false);
+ }
+ } else {
+ NotifyNeedShown(pos, len);
+ }
+}
+
int Editor::GetTag(char *tagValue, int tagNumber) {
const char *text = 0;
int length = 0;
@@ -7165,18 +7280,17 @@ int Editor::WrapCount(int line) { void Editor::AddStyledText(char *buffer, int appendLength) {
// The buffer consists of alternating character bytes and style bytes
int textLength = appendLength / 2;
- char *text = new char[textLength];
+ std::string text(textLength, '\0');
int i;
for (i = 0; i < textLength; i++) {
text[i] = buffer[i*2];
}
- pdoc->InsertString(CurrentPosition(), text, textLength);
+ pdoc->InsertString(CurrentPosition(), text.c_str(), textLength);
for (i = 0; i < textLength; i++) {
text[i] = buffer[i*2+1];
}
pdoc->StartStyling(CurrentPosition(), static_cast<char>(0xff));
- pdoc->SetStyles(textLength, text);
- delete []text;
+ pdoc->SetStyles(textLength, text.c_str());
SetEmptySelection(sel.MainCaret() + textLength);
}
@@ -7924,10 +8038,10 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { case SCI_GETLINEENDTYPESALLOWED:
return pdoc->GetLineEndTypesAllowed();
-
+
case SCI_GETLINEENDTYPESACTIVE:
return pdoc->GetLineEndTypesActive();
-
+
case SCI_STARTSTYLING:
pdoc->StartStyling(wParam, static_cast<char>(lParam));
break;
@@ -8140,7 +8254,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { break;
case SCI_TEXTWIDTH:
- PLATFORM_ASSERT(wParam < vs.stylesSize);
+ PLATFORM_ASSERT(wParam < vs.styles.size());
PLATFORM_ASSERT(lParam);
return TextWidth(wParam, CharPtrFromSPtr(lParam));
@@ -8309,7 +8423,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { case SCI_MARKERGET:
return pdoc->GetMark(wParam);
- case SCI_MARKERNEXT:
+ case SCI_MARKERNEXT:
return pdoc->MarkerNext(wParam, lParam);
case SCI_MARKERPREVIOUS: {
@@ -8550,21 +8664,42 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { return cs.HiddenLines() ? 0 : 1;
case SCI_SETFOLDEXPANDED:
- if (cs.SetExpanded(wParam, lParam != 0)) {
- RedrawSelMargin();
- }
+ SetFoldExpanded(wParam, lParam != 0);
break;
case SCI_GETFOLDEXPANDED:
return cs.GetExpanded(wParam);
+ case SCI_SETAUTOMATICFOLD:
+ foldAutomatic = wParam;
+ break;
+
+ case SCI_GETAUTOMATICFOLD:
+ return foldAutomatic;
+
case SCI_SETFOLDFLAGS:
foldFlags = wParam;
Redraw();
break;
case SCI_TOGGLEFOLD:
- ToggleContraction(wParam);
+ FoldLine(wParam, SC_FOLDACTION_TOGGLE);
+ break;
+
+ case SCI_FOLDLINE:
+ FoldLine(wParam, lParam);
+ break;
+
+ case SCI_FOLDCHILDREN:
+ FoldExpand(wParam, lParam, pdoc->GetLevel(wParam));
+ break;
+
+ case SCI_FOLDALL:
+ FoldAll(wParam);
+ break;
+
+ case SCI_EXPANDCHILDREN:
+ FoldExpand(wParam, SC_FOLDACTION_EXPAND, lParam);
break;
case SCI_CONTRACTEDFOLDNEXT:
@@ -8578,7 +8713,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { EnsureLineVisible(wParam, true);
break;
- case SCI_SCROLLRANGE:
+ case SCI_SCROLLRANGE:
ScrollRange(SelectionRange(lParam, wParam));
break;
@@ -8951,9 +9086,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { case SCI_CREATEDOCUMENT: {
Document *doc = new Document();
- if (doc) {
- doc->AddRef();
- }
+ doc->AddRef();
return reinterpret_cast<sptr_t>(doc);
}
@@ -8967,11 +9100,9 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { case SCI_CREATELOADER: {
Document *doc = new Document();
- if (doc) {
- doc->AddRef();
- doc->Allocate(wParam);
- doc->SetUndoCollection(false);
- }
+ doc->AddRef();
+ doc->Allocate(wParam);
+ doc->SetUndoCollection(false);
return reinterpret_cast<sptr_t>(static_cast<ILoader *>(doc));
}
@@ -9516,18 +9647,18 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { case SCI_CHANGELEXERSTATE:
pdoc->ChangeLexerState(wParam, lParam);
break;
-
+
case SCI_SETIDENTIFIER:
SetCtrlID(wParam);
break;
-
+
case SCI_GETIDENTIFIER:
return GetCtrlID();
case SCI_SETTECHNOLOGY:
// No action by default
break;
-
+
case SCI_GETTECHNOLOGY:
return technology;
diff --git a/scintilla/src/Editor.h b/scintilla/src/Editor.h index a6f0355..a31ac03 100644 --- a/scintilla/src/Editor.h +++ b/scintilla/src/Editor.h @@ -91,20 +91,13 @@ public: Free();
}
void Free() {
- Set(0, 0, 0, 0, false, false);
- }
- void Set(char *s_, int len_, int codePage_, int characterSet_, bool rectangular_, bool lineCopy_) {
delete []s;
- s = s_;
- if (s)
- len = len_;
- else
- len = 0;
- codePage = codePage_;
- characterSet = characterSet_;
- rectangular = rectangular_;
- lineCopy = lineCopy_;
- FixSelectionForClipboard();
+ s = 0;
+ len = 0;
+ rectangular = false;
+ lineCopy = false;
+ codePage = 0;
+ characterSet = 0;
}
void Copy(const char *s_, int len_, int codePage_, int characterSet_, bool rectangular_, bool lineCopy_) {
delete []s;
@@ -274,6 +267,7 @@ protected: // ScintillaBase subclass needs access to much of Editor bool recordingMacro;
int foldFlags;
+ int foldAutomatic;
ContractionState cs;
// Hotspot support
@@ -522,7 +516,6 @@ protected: // ScintillaBase subclass needs access to much of Editor void GoToLine(int lineNo);
virtual void CopyToClipboard(const SelectionText &selectedText) = 0;
- char *CopyRange(int start, int end);
std::string RangeText(int start, int end) const;
void CopySelectionRange(SelectionText *ss, bool allowLineCopy=false);
void CopyRangeToClipboard(int start, int end);
@@ -565,14 +558,20 @@ protected: // ScintillaBase subclass needs access to much of Editor void SetBraceHighlight(Position pos0, Position pos1, int matchStyle);
void SetAnnotationHeights(int start, int end);
- void SetDocPointer(Document *document);
+ virtual void SetDocPointer(Document *document);
void SetAnnotationVisible(int visible);
- void Expand(int &line, bool doExpand);
- void ToggleContraction(int line);
+ int ExpandLine(int line);
+ void SetFoldExpanded(int lineDoc, bool expanded);
+ void FoldLine(int line, int action);
+ void FoldExpand(int line, int action, int level);
int ContractedFoldNext(int lineStart);
void EnsureLineVisible(int lineDoc, bool enforcePolicy);
+ void FoldChanged(int line, int levelNow, int levelPrev);
+ void NeedShown(int pos, int len);
+ void FoldAll(int action);
+
int GetTag(char *tagValue, int tagNumber);
int ReplaceTarget(bool replacePatterns, const char *text, int length=-1);
diff --git a/scintilla/src/Indicator.cxx b/scintilla/src/Indicator.cxx index 20e7f6e..0127320 100644 --- a/scintilla/src/Indicator.cxx +++ b/scintilla/src/Indicator.cxx @@ -152,6 +152,9 @@ void Indicator::Draw(Surface *surface, const PRectangle &rc, const PRectangle &r surface->FillRectangle(rcDot, fore);
x += 2;
}
+ } else if (style == INDIC_COMPOSITIONTHICK) {
+ PRectangle rcComposition(rc.left+1, rcLine.bottom-2, rc.right-1, rcLine.bottom);
+ surface->FillRectangle(rcComposition, fore);
} else { // Either INDIC_PLAIN or unknown
surface->MoveTo(rc.left, ymid);
surface->LineTo(rc.right, ymid);
diff --git a/scintilla/src/KeyMap.cxx b/scintilla/src/KeyMap.cxx index a659a77..74e7a2d 100644 --- a/scintilla/src/KeyMap.cxx +++ b/scintilla/src/KeyMap.cxx @@ -5,6 +5,10 @@ // Copyright 1998-2003 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.
+#include <stdlib.h>
+
+#include <vector>
+
#include "Platform.h"
#include "Scintilla.h"
@@ -15,7 +19,7 @@ using namespace Scintilla;
#endif
-KeyMap::KeyMap() : kmap(0), len(0), alloc(0) {
+KeyMap::KeyMap() {
for (int i = 0; MapDefault[i].key; i++) {
AssignCmdKey(MapDefault[i].key,
MapDefault[i].modifiers,
@@ -28,37 +32,25 @@ KeyMap::~KeyMap() { }
void KeyMap::Clear() {
- delete []kmap;
- kmap = 0;
- len = 0;
- alloc = 0;
+ kmap.clear();
}
void KeyMap::AssignCmdKey(int key, int modifiers, unsigned int msg) {
- if ((len+1) >= alloc) {
- KeyToCommand *ktcNew = new KeyToCommand[alloc + 5];
- if (!ktcNew)
- return;
- for (int k = 0; k < len; k++)
- ktcNew[k] = kmap[k];
- alloc += 5;
- delete []kmap;
- kmap = ktcNew;
- }
- for (int keyIndex = 0; keyIndex < len; keyIndex++) {
+ for (size_t keyIndex = 0; keyIndex < kmap.size(); keyIndex++) {
if ((key == kmap[keyIndex].key) && (modifiers == kmap[keyIndex].modifiers)) {
kmap[keyIndex].msg = msg;
return;
}
}
- kmap[len].key = key;
- kmap[len].modifiers = modifiers;
- kmap[len].msg = msg;
- len++;
+ KeyToCommand ktc;
+ ktc.key = key;
+ ktc.modifiers = modifiers;
+ ktc.msg = msg;
+ kmap.push_back(ktc);
}
unsigned int KeyMap::Find(int key, int modifiers) {
- for (int i = 0; i < len; i++) {
+ for (size_t i = 0; i < kmap.size(); i++) {
if ((key == kmap[i].key) && (modifiers == kmap[i].modifiers)) {
return kmap[i].msg;
}
diff --git a/scintilla/src/KeyMap.h b/scintilla/src/KeyMap.h index 6584b29..2b7ebe6 100644 --- a/scintilla/src/KeyMap.h +++ b/scintilla/src/KeyMap.h @@ -32,9 +32,7 @@ public: /**
*/
class KeyMap {
- KeyToCommand *kmap;
- int len;
- int alloc;
+ std::vector<KeyToCommand> kmap;
static const KeyToCommand MapDefault[];
public:
diff --git a/scintilla/src/PerLine.cxx b/scintilla/src/PerLine.cxx index 0d8c1c6..1154022 100644 --- a/scintilla/src/PerLine.cxx +++ b/scintilla/src/PerLine.cxx @@ -7,6 +7,8 @@ #include <string.h>
+#include <algorithm>
+
#include "Platform.h"
#include "Scintilla.h"
@@ -43,17 +45,6 @@ int MarkerHandleSet::Length() const { return c;
}
-int MarkerHandleSet::NumberFromHandle(int handle) const {
- MarkerHandleNumber *mhn = root;
- while (mhn) {
- if (mhn->handle == handle) {
- return mhn->number;
- }
- mhn = mhn->next;
- }
- return - 1;
-}
-
int MarkerHandleSet::MarkValue() const {
unsigned int m = 0;
MarkerHandleNumber *mhn = root;
@@ -77,8 +68,6 @@ bool MarkerHandleSet::Contains(int handle) const { bool MarkerHandleSet::InsertHandle(int handle, int markerNum) {
MarkerHandleNumber *mhn = new MarkerHandleNumber;
- if (!mhn)
- return false;
mhn->handle = handle;
mhn->number = markerNum;
mhn->next = root;
@@ -209,8 +198,6 @@ int LineMarkers::AddMark(int line, int markerNum, int lines) { if (!markers[line]) {
// Need new structure to hold marker handle
markers[line] = new MarkerHandleSet();
- if (!markers[line])
- return -1;
}
markers[line]->InsertHandle(handleCurrent, markerNum);
@@ -389,10 +376,6 @@ void LineAnnotation::RemoveLine(int line) { }
}
-bool LineAnnotation::AnySet() const {
- return annotations.Length() > 0;
-}
-
bool LineAnnotation::MultipleStyles(int line) const {
if (annotations.Length() && (line >= 0) && (line < annotations.Length()) && annotations[line])
return reinterpret_cast<AnnotationHeader *>(annotations[line])->style == IndividualStyles;
diff --git a/scintilla/src/PerLine.h b/scintilla/src/PerLine.h index ad85eb1..c314612 100644 --- a/scintilla/src/PerLine.h +++ b/scintilla/src/PerLine.h @@ -32,7 +32,6 @@ public: MarkerHandleSet();
~MarkerHandleSet();
int Length() const;
- int NumberFromHandle(int handle) const;
int MarkValue() const; ///< Bit set of marker numbers.
bool Contains(int handle) const;
bool InsertHandle(int handle, int markerNum);
@@ -101,7 +100,6 @@ public: virtual void InsertLine(int line);
virtual void RemoveLine(int line);
- bool AnySet() const;
bool MultipleStyles(int line) const;
int Style(int line);
const char *Text(int line) const;
diff --git a/scintilla/src/PositionCache.cxx b/scintilla/src/PositionCache.cxx index b6f8144..387ed54 100644 --- a/scintilla/src/PositionCache.cxx +++ b/scintilla/src/PositionCache.cxx @@ -207,7 +207,7 @@ int LineLayout::EndLineStyle() const { }
LineLayoutCache::LineLayoutCache() :
- level(0), length(0), size(0), cache(0),
+ level(0),
allInvalidated(false), styleClock(-1), useCount(0) {
Allocate(0);
}
@@ -216,24 +216,15 @@ LineLayoutCache::~LineLayoutCache() { Deallocate();
}
-void LineLayoutCache::Allocate(int length_) {
- PLATFORM_ASSERT(cache == NULL);
+void LineLayoutCache::Allocate(size_t length_) {
+ PLATFORM_ASSERT(cache.empty());
allInvalidated = false;
- length = length_;
- size = length;
- if (size > 1) {
- size = (size / 16 + 1) * 16;
- }
- if (size > 0) {
- cache = new LineLayout * [size];
- }
- for (int i = 0; i < size; i++)
- cache[i] = 0;
+ cache.resize(length_);
}
void LineLayoutCache::AllocateForLevel(int linesOnScreen, int linesInDoc) {
PLATFORM_ASSERT(useCount == 0);
- int lengthForLevel = 0;
+ size_t lengthForLevel = 0;
if (level == llcCaret) {
lengthForLevel = 1;
} else if (level == llcPage) {
@@ -241,35 +232,31 @@ void LineLayoutCache::AllocateForLevel(int linesOnScreen, int linesInDoc) { } else if (level == llcDocument) {
lengthForLevel = linesInDoc;
}
- if (lengthForLevel > size) {
+ if (lengthForLevel > cache.size()) {
Deallocate();
Allocate(lengthForLevel);
} else {
- if (lengthForLevel < length) {
- for (int i = lengthForLevel; i < length; i++) {
+ if (lengthForLevel < cache.size()) {
+ for (size_t i = lengthForLevel; i < cache.size(); i++) {
delete cache[i];
cache[i] = 0;
}
}
- length = lengthForLevel;
+ cache.resize(lengthForLevel);
}
- PLATFORM_ASSERT(length == lengthForLevel);
- PLATFORM_ASSERT(cache != NULL || length == 0);
+ PLATFORM_ASSERT(cache.size() == lengthForLevel);
}
void LineLayoutCache::Deallocate() {
PLATFORM_ASSERT(useCount == 0);
- for (int i = 0; i < length; i++)
+ for (size_t i = 0; i < cache.size(); i++)
delete cache[i];
- delete []cache;
- cache = 0;
- length = 0;
- size = 0;
+ cache.clear();
}
void LineLayoutCache::Invalidate(LineLayout::validLevel validity_) {
- if (cache && !allInvalidated) {
- for (int i = 0; i < length; i++) {
+ if (!cache.empty() && !allInvalidated) {
+ for (size_t i = 0; i < cache.size(); i++) {
if (cache[i]) {
cache[i]->Invalidate(validity_);
}
@@ -303,15 +290,15 @@ LineLayout *LineLayoutCache::Retrieve(int lineNumber, int lineCaret, int maxChar } else if (level == llcPage) {
if (lineNumber == lineCaret) {
pos = 0;
- } else if (length > 1) {
- pos = 1 + (lineNumber % (length - 1));
+ } else if (cache.size() > 1) {
+ pos = 1 + (lineNumber % (cache.size() - 1));
}
} else if (level == llcDocument) {
pos = lineNumber;
}
if (pos >= 0) {
PLATFORM_ASSERT(useCount == 0);
- if (cache && (pos < length)) {
+ if (!cache.empty() && (pos < static_cast<int>(cache.size()))) {
if (cache[pos]) {
if ((cache[pos]->lineNumber != lineNumber) ||
(cache[pos]->maxLineLength < maxChars)) {
@@ -322,12 +309,10 @@ LineLayout *LineLayoutCache::Retrieve(int lineNumber, int lineCaret, int maxChar if (!cache[pos]) {
cache[pos] = new LineLayout(maxChars);
}
- if (cache[pos]) {
- cache[pos]->lineNumber = lineNumber;
- cache[pos]->inCache = true;
- ret = cache[pos];
- useCount++;
- }
+ cache[pos]->lineNumber = lineNumber;
+ cache[pos]->inCache = true;
+ ret = cache[pos];
+ useCount++;
}
}
@@ -351,33 +336,18 @@ void LineLayoutCache::Dispose(LineLayout *ll) { }
void BreakFinder::Insert(int val) {
- // Expand if needed
- if (saeLen >= saeSize) {
- saeSize *= 2;
- int *selAndEdgeNew = new int[saeSize];
- for (unsigned int j = 0; j<saeLen; j++) {
- selAndEdgeNew[j] = selAndEdge[j];
- }
- delete []selAndEdge;
- selAndEdge = selAndEdgeNew;
- }
-
if (val >= nextBreak) {
- for (unsigned int j = 0; j<saeLen; j++) {
- if (val == selAndEdge[j]) {
+ for (std::vector<int>::iterator it = selAndEdge.begin(); it != selAndEdge.end(); ++it) {
+ if (val == *it) {
return;
}
- if (val < selAndEdge[j]) {
- for (unsigned int k = saeLen; k>j; k--) {
- selAndEdge[k] = selAndEdge[k-1];
- }
- saeLen++;
- selAndEdge[j] = val;
+ if (val <*it) {
+ selAndEdge.insert(it, 1, val);
return;
}
}
// Not less than any so append
- selAndEdge[saeLen++] = val;
+ selAndEdge.push_back(val);
}
}
@@ -399,17 +369,11 @@ BreakFinder::BreakFinder(LineLayout *ll_, int lineStart_, int lineEnd_, int posL lineEnd(lineEnd_),
posLineStart(posLineStart_),
nextBreak(lineStart_),
- saeSize(0),
- saeLen(0),
saeCurrentPos(0),
saeNext(0),
subBreak(-1),
pdoc(pdoc_) {
- saeSize = 8;
- selAndEdge = new int[saeSize];
- for (unsigned int j=0; j < saeSize; j++) {
- selAndEdge[j] = 0;
- }
+ selAndEdge.resize(1);
// Search for first visible break
// First find the first visible character
@@ -447,11 +411,10 @@ BreakFinder::BreakFinder(LineLayout *ll_, int lineStart_, int lineEnd_, int posL Insert(pos);
}
}
- saeNext = (saeLen > 0) ? selAndEdge[0] : -1;
+ saeNext = (!selAndEdge.empty()) ? selAndEdge[0] : -1;
}
BreakFinder::~BreakFinder() {
- delete []selAndEdge;
}
int BreakFinder::First() const {
@@ -467,7 +430,7 @@ int BreakFinder::Next() { IsControlCharacter(ll->chars[nextBreak]) || IsControlCharacter(ll->chars[nextBreak + 1])) {
if (nextBreak == saeNext) {
saeCurrentPos++;
- saeNext = (saeLen > saeCurrentPos) ? selAndEdge[saeCurrentPos] : -1;
+ saeNext = (saeCurrentPos < selAndEdge.size()) ? selAndEdge[saeCurrentPos] : -1;
}
nextBreak++;
if ((nextBreak - prev) < lengthStartSubdivision) {
@@ -509,7 +472,7 @@ void PositionCacheEntry::Set(unsigned int styleNumber_, const char *s_, len = len_;
clock = clock_;
if (s_ && positions_) {
- positions = new XYPOSITION[len + (len + 1) / 2];
+ positions = new XYPOSITION[len + (len / 4) + 1];
for (unsigned int i=0; i<len; i++) {
positions[i] = static_cast<XYPOSITION>(positions_[i]);
}
@@ -566,20 +529,18 @@ void PositionCacheEntry::ResetClock() { }
PositionCache::PositionCache() {
- size = 0x400;
clock = 1;
- pces = new PositionCacheEntry[size];
+ pces.resize(0x400);
allClear = true;
}
PositionCache::~PositionCache() {
Clear();
- delete []pces;
}
void PositionCache::Clear() {
if (!allClear) {
- for (size_t i=0; i<size; i++) {
+ for (size_t i=0; i<pces.size(); i++) {
pces[i].Clear();
}
}
@@ -589,9 +550,7 @@ void PositionCache::Clear() { void PositionCache::SetSize(size_t size_) {
Clear();
- delete []pces;
- size = size_;
- pces = new PositionCacheEntry[size];
+ pces.resize(size_);
}
void PositionCache::MeasureWidths(Surface *surface, ViewStyle &vstyle, unsigned int styleNumber,
@@ -599,17 +558,17 @@ void PositionCache::MeasureWidths(Surface *surface, ViewStyle &vstyle, unsigned allClear = false;
int probe = -1;
- if ((size > 0) && (len < 30)) {
+ if ((!pces.empty()) && (len < 30)) {
// Only store short strings in the cache so it doesn't churn with
// long comments with only a single comment.
// Two way associative: try two probe positions.
int hashValue = PositionCacheEntry::Hash(styleNumber, s, len);
- probe = static_cast<int>(hashValue % size);
+ probe = static_cast<int>(hashValue % pces.size());
if (pces[probe].Retrieve(styleNumber, s, len, positions)) {
return;
}
- int probe2 = static_cast<int>((hashValue * 37) % size);
+ int probe2 = static_cast<int>((hashValue * 37) % pces.size());
if (pces[probe2].Retrieve(styleNumber, s, len, positions)) {
return;
}
@@ -639,7 +598,7 @@ void PositionCache::MeasureWidths(Surface *surface, ViewStyle &vstyle, unsigned if (clock > 60000) {
// Since there are only 16 bits for the clock, wrap it round and
// reset all cache entries so none get stuck with a high clock.
- for (size_t i=0; i<size; i++) {
+ for (size_t i=0; i<pces.size(); i++) {
pces[i].ResetClock();
}
clock = 2;
diff --git a/scintilla/src/PositionCache.h b/scintilla/src/PositionCache.h index 1b909fd..50913f4 100644 --- a/scintilla/src/PositionCache.h +++ b/scintilla/src/PositionCache.h @@ -73,13 +73,11 @@ public: */
class LineLayoutCache {
int level;
- int length;
- int size;
- LineLayout **cache;
+ std::vector<LineLayout *>cache;
bool allInvalidated;
int styleClock;
int useCount;
- void Allocate(int length_);
+ void Allocate(size_t length_);
void AllocateForLevel(int linesOnScreen, int linesInDoc);
public:
LineLayoutCache();
@@ -122,9 +120,7 @@ class BreakFinder { int lineEnd;
int posLineStart;
int nextBreak;
- int *selAndEdge;
- unsigned int saeSize;
- unsigned int saeLen;
+ std::vector<int> selAndEdge;
unsigned int saeCurrentPos;
int saeNext;
int subBreak;
@@ -146,8 +142,7 @@ public: };
class PositionCache {
- PositionCacheEntry *pces;
- size_t size;
+ std::vector<PositionCacheEntry> pces;
unsigned int clock;
bool allClear;
// Private so PositionCache objects can not be copied
@@ -157,7 +152,7 @@ public: ~PositionCache();
void Clear();
void SetSize(size_t size_);
- size_t GetSize() const { return size; }
+ size_t GetSize() const { return pces.size(); }
void MeasureWidths(Surface *surface, ViewStyle &vstyle, unsigned int styleNumber,
const char *s, unsigned int len, XYPOSITION *positions, Document *pdoc);
};
diff --git a/scintilla/src/RESearch.cxx b/scintilla/src/RESearch.cxx index d3da8fb..be8166b 100644 --- a/scintilla/src/RESearch.cxx +++ b/scintilla/src/RESearch.cxx @@ -43,10 +43,6 @@ *
* int RESearch::Execute(characterIndexer &ci, int lp, int endp)
*
- * RESearch::Substitute: substitute the matched portions in a new string.
- *
- * int RESearch::Substitute(CharacterIndexer &ci, char *src, char *dst)
- *
* re_fail: failure routine for RESearch::Execute. (no longer used)
*
* void re_fail(char *msg, char op)
@@ -206,6 +202,8 @@ #include <stdlib.h>
+#include <string>
+
#include "CharClassify.h"
#include "RESearch.h"
@@ -269,36 +267,29 @@ void RESearch::Init() { sta = NOP; /* status of lastpat */
bol = 0;
for (int i = 0; i < MAXTAG; i++)
- pat[i] = 0;
+ pat[i].clear();
for (int j = 0; j < BITBLK; j++)
bittab[j] = 0;
}
void RESearch::Clear() {
for (int i = 0; i < MAXTAG; i++) {
- delete []pat[i];
- pat[i] = 0;
+ pat[i].clear();
bopat[i] = NOTFOUND;
eopat[i] = NOTFOUND;
}
}
-bool RESearch::GrabMatches(CharacterIndexer &ci) {
- bool success = true;
+void RESearch::GrabMatches(CharacterIndexer &ci) {
for (unsigned int i = 0; i < MAXTAG; i++) {
if ((bopat[i] != NOTFOUND) && (eopat[i] != NOTFOUND)) {
unsigned int len = eopat[i] - bopat[i];
- pat[i] = new char[len + 1];
- if (pat[i]) {
- for (unsigned int j = 0; j < len; j++)
- pat[i][j] = ci.CharAt(bopat[i] + j);
- pat[i][len] = '\0';
- } else {
- success = false;
- }
+ pat[i] = std::string(len+1, '\0');
+ for (unsigned int j = 0; j < len; j++)
+ pat[i][j] = ci.CharAt(bopat[i] + j);
+ pat[i][len] = '\0';
}
}
- return success;
}
void RESearch::ChSet(unsigned char c) {
@@ -967,52 +958,4 @@ int RESearch::PMatch(CharacterIndexer &ci, int lp, int endp, char *ap) { return lp;
}
-/*
- * RESearch::Substitute:
- * substitute the matched portions of the src in dst.
- *
- * & substitute the entire matched pattern.
- *
- * \digit substitute a subpattern, with the given tag number.
- * Tags are numbered from 1 to 9. If the particular
- * tagged subpattern does not exist, null is substituted.
- */
-int RESearch::Substitute(CharacterIndexer &ci, char *src, char *dst) {
- unsigned char c;
- int pin;
- int bp;
- int ep;
-
- if (!*src || !bopat[0])
- return 0;
-
- while ((c = *src++) != 0) {
- switch (c) {
-
- case '&':
- pin = 0;
- break;
-
- case '\\':
- c = *src++;
- if (c >= '0' && c <= '9') {
- pin = c - '0';
- break;
- }
-
- default:
- *dst++ = c;
- continue;
- }
-
- if ((bp = bopat[pin]) != 0 && (ep = eopat[pin]) != 0) {
- while (ci.CharAt(bp) && bp < ep)
- *dst++ = ci.CharAt(bp++);
- if (bp < ep)
- return 0;
- }
- }
- *dst = '\0';
- return 1;
-}
diff --git a/scintilla/src/RESearch.h b/scintilla/src/RESearch.h index e2f8d50..bf31b24 100644 --- a/scintilla/src/RESearch.h +++ b/scintilla/src/RESearch.h @@ -33,10 +33,9 @@ class RESearch { public:
RESearch(CharClassify *charClassTable);
~RESearch();
- bool GrabMatches(CharacterIndexer &ci);
+ void GrabMatches(CharacterIndexer &ci);
const char *Compile(const char *pattern, int length, bool caseSensitive, bool posix);
int Execute(CharacterIndexer &ci, int lp, int endp);
- int Substitute(CharacterIndexer &ci, char *src, char *dst);
enum { MAXTAG=10 };
enum { MAXNFA=2048 };
@@ -44,7 +43,7 @@ public: int bopat[MAXTAG];
int eopat[MAXTAG];
- char *pat[MAXTAG];
+ std::string pat[MAXTAG];
private:
void Init();
diff --git a/scintilla/src/RunStyles.cxx b/scintilla/src/RunStyles.cxx index 29ce08f..c8698a2 100644 --- a/scintilla/src/RunStyles.cxx +++ b/scintilla/src/RunStyles.cxx @@ -9,6 +9,8 @@ #include <stdlib.h>
#include <stdarg.h>
+#include <stdexcept>
+
#include "Platform.h"
#include "Scintilla.h"
@@ -113,7 +115,13 @@ int RunStyles::EndRun(int position) { }
bool RunStyles::FillRange(int &position, int value, int &fillLength) {
+ if (fillLength <= 0) {
+ return false;
+ }
int end = position + fillLength;
+ if (end > Length()) {
+ return false;
+ }
int runEnd = RunFromPosition(end);
if (styles->ValueAt(runEnd) == value) {
// End already has value so trim range.
@@ -249,3 +257,31 @@ int RunStyles::Find(int value, int start) const { }
return -1;
}
+
+void RunStyles::Check() {
+ if (Length() < 0) {
+ throw std::runtime_error("RunStyles: Length can not be negative.");
+ }
+ if (starts->Partitions() < 1) {
+ throw std::runtime_error("RunStyles: Must always have 1 or more partitions.");
+ }
+ if (starts->Partitions() != styles->Length()-1) {
+ throw std::runtime_error("RunStyles: Partitions and styles different lengths.");
+ }
+ int start=0;
+ while (start < Length()) {
+ int end = EndRun(start);
+ if (start >= end) {
+ throw std::runtime_error("RunStyles: Partition is 0 length.");
+ }
+ start = end;
+ }
+ if (styles->ValueAt(styles->Length()-1) != 0) {
+ throw std::runtime_error("RunStyles: Unused style at end changed.");
+ }
+ for (int j=1; j<styles->Length()-1; j++) {
+ if (styles->ValueAt(j) == styles->ValueAt(j-1)) {
+ throw std::runtime_error("RunStyles: Style of a partition same as previous.");
+ }
+ }
+}
diff --git a/scintilla/src/RunStyles.h b/scintilla/src/RunStyles.h index 25f9752..0191d9a 100644 --- a/scintilla/src/RunStyles.h +++ b/scintilla/src/RunStyles.h @@ -43,6 +43,8 @@ public: bool AllSame() const;
bool AllSameAs(int value) const;
int Find(int value, int start) const;
+
+ void Check();
};
#ifdef SCI_NAMESPACE
diff --git a/scintilla/src/SVector.h b/scintilla/src/SVector.h deleted file mode 100644 index 7d1a8a8..0000000 --- a/scintilla/src/SVector.h +++ /dev/null @@ -1,123 +0,0 @@ -// Scintilla source code edit control
-/** @file SVector.h
- ** A simple expandable vector.
- **/
-// Copyright 1998-2001 by Neil Hodgson <neilh@hare.net.au>
-// The License.txt file describes the conditions under which this software may be distributed.
-
-#ifndef SVECTOR_H
-#define SVECTOR_H
-
-#ifdef SCI_NAMESPACE
-namespace Scintilla {
-#endif
-
-/**
- * A simple expandable integer vector.
- * Storage not allocated for elements until an element is used.
- * This makes it very lightweight unless used so is a good match for optional features.
- */
-class SVector {
- enum { allocSize = 4000 };
-
- int *v; ///< The vector
- unsigned int size; ///< Number of elements allocated
- unsigned int len; ///< Number of elements used in vector
-
- /** Internally allocate more elements than the user wants
- * to avoid thrashing the memory allocator. */
- void SizeTo(int newSize) {
- if (newSize < allocSize)
- newSize += allocSize;
- else
- newSize = (newSize * 3) / 2;
- int *newv = new int[newSize];
- size = newSize;
- unsigned int i=0;
- for (; i<len; i++) {
- newv[i] = v[i];
- }
- for (; i<size; i++) {
- newv[i] = 0;
- }
- delete []v;
- v = newv;
- }
-
-public:
- SVector() {
- v = 0;
- len = 0;
- size = 0;
- }
- ~SVector() {
- Free();
- }
- /// Constructor from another vector.
- SVector(const SVector &other) {
- v = 0;
- len = 0;
- size = 0;
- if (other.Length() > 0) {
- SizeTo(other.Length());
- for (int i=0; i<other.Length(); i++)
- v[i] = other.v[i];
- len = other.Length();
- }
- }
- /// Copy constructor.
- SVector &operator=(const SVector &other) {
- if (this != &other) {
- delete []v;
- v = 0;
- len = 0;
- size = 0;
- if (other.Length() > 0) {
- SizeTo(other.Length());
- for (int i=0; i<other.Length(); i++)
- v[i] = other.v[i];
- len = other.Length();
- }
- }
- return *this;
- }
- /** @brief Accessor.
- * Allows to access values from the list, and grows it if accessing
- * outside the current bounds. The returned value in this case is 0. */
- int &operator[](unsigned int i) {
- if (i >= len) {
- if (i >= size) {
- SizeTo(i);
- }
- len = i+1;
- }
- return v[i];
- }
- /// Reset vector.
- void Free() {
- delete []v;
- v = 0;
- size = 0;
- len = 0;
- }
- /** @brief Grow vector size.
- * Doesn't allow a vector to be shrinked. */
- void SetLength(unsigned int newLength) {
- if (newLength > len) {
- if (newLength >= size) {
- SizeTo(newLength);
- }
- }
- len = newLength;
- }
- /// Get the current length (number of used elements) of the vector.
- int Length() const {
- return len;
- }
-};
-
-#ifdef SCI_NAMESPACE
-}
-#endif
-
-#endif
diff --git a/scintilla/src/Selection.cxx b/scintilla/src/Selection.cxx index 7192a2a..a708a53 100644 --- a/scintilla/src/Selection.cxx +++ b/scintilla/src/Selection.cxx @@ -20,14 +20,18 @@ using namespace Scintilla; #endif
void SelectionPosition::MoveForInsertDelete(bool insertion, int startChange, int length) {
- if (position == startChange) {
- virtualSpace = 0;
- }
if (insertion) {
- if (position > startChange) {
+ if (position == startChange) {
+ int virtualLengthRemove = std::min(length, virtualSpace);
+ virtualSpace -= virtualLengthRemove;
+ position += virtualLengthRemove;
+ } else if (position > startChange) {
position += length;
}
} else {
+ if (position == startChange) {
+ virtualSpace = 0;
+ }
if (position > startChange) {
int endDeletion = startChange + length;
if (position > endDeletion) {
diff --git a/scintilla/src/SplitVector.h b/scintilla/src/SplitVector.h index c64358e..5b8876c 100644 --- a/scintilla/src/SplitVector.h +++ b/scintilla/src/SplitVector.h @@ -174,8 +174,7 @@ public: }
RoomFor(insertLength);
GapTo(position);
- for (int i = 0; i < insertLength; i++)
- body[part1Length + i] = v;
+ std::fill(&body[part1Length], &body[part1Length + insertLength], v);
lengthBody += insertLength;
part1Length += insertLength;
gapLength -= insertLength;
diff --git a/scintilla/src/Style.cxx b/scintilla/src/Style.cxx index 9587d14..e12bdd1 100644 --- a/scintilla/src/Style.cxx +++ b/scintilla/src/Style.cxx @@ -21,7 +21,7 @@ FontAlias::FontAlias() { FontAlias::~FontAlias() {
SetID(0);
- // ~Font will not release the actual font resource sine it is now 0
+ // ~Font will not release the actual font resource since it is now 0
}
void FontAlias::MakeAlias(Font &fontOrigin) {
@@ -32,12 +32,29 @@ void FontAlias::ClearFont() { SetID(0);
}
-bool FontSpecification::EqualTo(const FontSpecification &other) const {
- return weight == other.weight &&
+bool FontSpecification::operator==(const FontSpecification &other) const {
+ return fontName == other.fontName &&
+ weight == other.weight &&
italic == other.italic &&
size == other.size &&
characterSet == other.characterSet &&
- fontName == other.fontName;
+ extraFontFlag == other.extraFontFlag;
+}
+
+bool FontSpecification::operator<(const FontSpecification &other) const {
+ if (fontName != other.fontName)
+ return fontName < other.fontName;
+ if (weight != other.weight)
+ return weight < other.weight;
+ if (italic != other.italic)
+ return italic == false;
+ if (size != other.size)
+ return size < other.size;
+ if (characterSet != other.characterSet)
+ return characterSet < other.characterSet;
+ if (extraFontFlag != other.extraFontFlag)
+ return extraFontFlag < other.extraFontFlag;
+ return false;
}
FontMeasurements::FontMeasurements() {
@@ -68,6 +85,7 @@ Style::Style(const Style &source) : FontSpecification(), FontMeasurements() { weight = source.weight;
italic = source.italic;
size = source.size;
+ fontName = source.fontName;
eolFilled = source.eolFilled;
underline = source.underline;
caseForce = source.caseForce;
@@ -91,6 +109,7 @@ Style &Style::operator=(const Style &source) { weight = source.weight;
italic = source.italic;
size = source.size;
+ fontName = source.fontName;
eolFilled = source.eolFilled;
underline = source.underline;
caseForce = source.caseForce;
diff --git a/scintilla/src/Style.h b/scintilla/src/Style.h index 5b7d3f3..5f520e7 100644 --- a/scintilla/src/Style.h +++ b/scintilla/src/Style.h @@ -27,7 +27,8 @@ struct FontSpecification { characterSet(0),
extraFontFlag(0) {
}
- bool EqualTo(const FontSpecification &other) const;
+ bool operator==(const FontSpecification &other) const;
+ bool operator<(const FontSpecification &other) const;
};
// Just like Font but only has a copy of the FontID so should not delete it
@@ -77,7 +78,7 @@ public: const char *fontName_, int characterSet_,
int weight_, bool italic_, bool eolFilled_,
bool underline_, ecaseForced caseForce_,
- bool visible_, bool changeable_, bool hotspot_);
+ bool visible_, bool changeable_, bool hotspot_);
void ClearTo(const Style &source);
void Copy(Font &font_, const FontMeasurements &fm_);
bool IsProtected() const { return !(changeable && visible);}
diff --git a/scintilla/src/ViewStyle.cxx b/scintilla/src/ViewStyle.cxx index e1eafcc..7661821 100644 --- a/scintilla/src/ViewStyle.cxx +++ b/scintilla/src/ViewStyle.cxx @@ -33,100 +33,52 @@ MarginStyle::MarginStyle() : // A list of the fontnames - avoids wasting space in each style
FontNames::FontNames() {
- size = 8;
- names = new char *[size];
- max = 0;
}
FontNames::~FontNames() {
Clear();
- delete []names;
- names = 0;
}
void FontNames::Clear() {
- for (int i=0; i<max; i++) {
- delete []names[i];
- }
- max = 0;
+ names.clear();
}
const char *FontNames::Save(const char *name) {
if (!name)
return 0;
- for (int i=0; i<max; i++) {
- if (strcmp(names[i], name) == 0) {
- return names[i];
- }
- }
- if (max >= size) {
- // Grow array
- int sizeNew = size * 2;
- char **namesNew = new char *[sizeNew];
- for (int j=0; j<max; j++) {
- namesNew[j] = names[j];
+
+ for (std::vector<char *>::const_iterator it=names.begin(); it != names.end(); ++it) {
+ if (strcmp(*it, name) == 0) {
+ return *it;
}
- delete []names;
- names = namesNew;
- size = sizeNew;
}
- names[max] = new char[strlen(name) + 1];
- strcpy(names[max], name);
- max++;
- return names[max-1];
+ char *nameSave = new char[strlen(name) + 1];
+ strcpy(nameSave, name);
+ names.push_back(nameSave);
+ return nameSave;
}
-FontRealised::FontRealised(const FontSpecification &fs) {
- frNext = NULL;
- (FontSpecification &)(*this) = fs;
+FontRealised::FontRealised() {
}
FontRealised::~FontRealised() {
font.Release();
- delete frNext;
- frNext = 0;
}
-void FontRealised::Realise(Surface &surface, int zoomLevel, int technology) {
- PLATFORM_ASSERT(fontName);
- sizeZoomed = size + zoomLevel * SC_FONT_SIZE_MULTIPLIER;
+void FontRealised::Realise(Surface &surface, int zoomLevel, int technology, const FontSpecification &fs) {
+ PLATFORM_ASSERT(fs.fontName);
+ sizeZoomed = fs.size + zoomLevel * SC_FONT_SIZE_MULTIPLIER;
if (sizeZoomed <= 2 * SC_FONT_SIZE_MULTIPLIER) // Hangs if sizeZoomed <= 1
sizeZoomed = 2 * SC_FONT_SIZE_MULTIPLIER;
float deviceHeight = surface.DeviceHeightFont(sizeZoomed);
- FontParameters fp(fontName, deviceHeight / SC_FONT_SIZE_MULTIPLIER, weight, italic, extraFontFlag, technology, characterSet);
+ FontParameters fp(fs.fontName, deviceHeight / SC_FONT_SIZE_MULTIPLIER, fs.weight, fs.italic, fs.extraFontFlag, technology, fs.characterSet);
font.Create(fp);
ascent = surface.Ascent(font);
descent = surface.Descent(font);
aveCharWidth = surface.AverageCharWidth(font);
spaceWidth = surface.WidthChar(font, ' ');
- if (frNext) {
- frNext->Realise(surface, zoomLevel, technology);
- }
-}
-
-FontRealised *FontRealised::Find(const FontSpecification &fs) {
- if (!fs.fontName)
- return this;
- FontRealised *fr = this;
- while (fr) {
- if (fr->EqualTo(fs))
- return fr;
- fr = fr->frNext;
- }
- return 0;
-}
-
-void FontRealised::FindMaxAscentDescent(unsigned int &maxAscent, unsigned int &maxDescent) {
- FontRealised *fr = this;
- while (fr) {
- if (maxAscent < fr->ascent)
- maxAscent = fr->ascent;
- if (maxDescent < fr->descent)
- maxDescent = fr->descent;
- fr = fr->frNext;
- }
}
ViewStyle::ViewStyle() {
@@ -134,9 +86,8 @@ ViewStyle::ViewStyle() { }
ViewStyle::ViewStyle(const ViewStyle &source) {
- frFirst = NULL;
- Init(source.stylesSize);
- for (unsigned int sty=0; sty<source.stylesSize; sty++) {
+ Init(source.styles.size());
+ for (unsigned int sty=0; sty<source.styles.size(); sty++) {
styles[sty] = source.styles[sty];
// Can't just copy fontname as its lifetime is relative to its owning ViewStyle
styles[sty].fontName = fontNames.Save(source.styles[sty].fontName);
@@ -218,16 +169,14 @@ ViewStyle::ViewStyle(const ViewStyle &source) { }
ViewStyle::~ViewStyle() {
- delete []styles;
- styles = NULL;
- delete frFirst;
- frFirst = NULL;
+ styles.clear();
+ for (FontMap::iterator it = fonts.begin(); it != fonts.end(); ++it) {
+ delete it->second;
+ }
+ fonts.clear();
}
void ViewStyle::Init(size_t stylesSize_) {
- frFirst = NULL;
- stylesSize = 0;
- styles = NULL;
AllocStyles(stylesSize_);
nextExtendedStyle = 256;
fontNames.Clear();
@@ -334,52 +283,42 @@ void ViewStyle::Init(size_t stylesSize_) { braceBadLightIndicator = 0;
}
-void ViewStyle::CreateFont(const FontSpecification &fs) {
- if (fs.fontName) {
- for (FontRealised *cur=frFirst; cur; cur=cur->frNext) {
- if (cur->EqualTo(fs))
- return;
- if (!cur->frNext) {
- cur->frNext = new FontRealised(fs);
- return;
- }
- }
- frFirst = new FontRealised(fs);
+void ViewStyle::Refresh(Surface &surface) {
+ for (FontMap::iterator it = fonts.begin(); it != fonts.end(); ++it) {
+ delete it->second;
}
-}
+ fonts.clear();
-void ViewStyle::Refresh(Surface &surface) {
- delete frFirst;
- frFirst = NULL;
selbar = Platform::Chrome();
selbarlight = Platform::ChromeHighlight();
- for (unsigned int i=0; i<stylesSize; i++) {
+ for (unsigned int i=0; i<styles.size(); i++) {
styles[i].extraFontFlag = extraFontFlag;
}
CreateFont(styles[STYLE_DEFAULT]);
- for (unsigned int j=0; j<stylesSize; j++) {
+ for (unsigned int j=0; j<styles.size(); j++) {
CreateFont(styles[j]);
}
- assert(frFirst);
- frFirst->Realise(surface, zoomLevel, technology);
+ for (FontMap::iterator it = fonts.begin(); it != fonts.end(); ++it) {
+ it->second->Realise(surface, zoomLevel, technology, it->first);
+ }
- for (unsigned int k=0; k<stylesSize; k++) {
- FontRealised *fr = frFirst->Find(styles[k]);
+ for (unsigned int k=0; k<styles.size(); k++) {
+ FontRealised *fr = Find(styles[k]);
styles[k].Copy(fr->font, *fr);
}
maxAscent = 1;
maxDescent = 1;
- frFirst->FindMaxAscentDescent(maxAscent, maxDescent);
+ FindMaxAscentDescent(maxAscent, maxDescent);
maxAscent += extraAscent;
maxDescent += extraDescent;
lineHeight = maxAscent + maxDescent;
someStylesProtected = false;
someStylesForceCase = false;
- for (unsigned int l=0; l<stylesSize; l++) {
+ for (unsigned int l=0; l<styles.size(); l++) {
if (styles[l].IsProtected()) {
someStylesProtected = true;
}
@@ -401,25 +340,6 @@ void ViewStyle::Refresh(Surface &surface) { textStart = marginInside ? fixedColumnWidth : leftMarginWidth;
}
-void ViewStyle::AllocStyles(size_t sizeNew) {
- Style *stylesNew = new Style[sizeNew];
- size_t i=0;
- for (; i<stylesSize; i++) {
- stylesNew[i] = styles[i];
- stylesNew[i].fontName = styles[i].fontName;
- }
- if (stylesSize > STYLE_DEFAULT) {
- for (; i<sizeNew; i++) {
- if (i != STYLE_DEFAULT) {
- stylesNew[i].ClearTo(styles[STYLE_DEFAULT]);
- }
- }
- }
- delete []styles;
- styles = stylesNew;
- stylesSize = sizeNew;
-}
-
void ViewStyle::ReleaseAllExtendedStyles() {
nextExtendedStyle = 256;
}
@@ -431,11 +351,8 @@ int ViewStyle::AllocateExtendedStyles(int numberStyles) { }
void ViewStyle::EnsureStyle(size_t index) {
- if (index >= stylesSize) {
- size_t sizeNew = stylesSize * 2;
- while (sizeNew <= index)
- sizeNew *= 2;
- AllocStyles(sizeNew);
+ if (index >= styles.size()) {
+ AllocStyles(index+1);
}
}
@@ -449,7 +366,7 @@ void ViewStyle::ResetDefaultStyle() { void ViewStyle::ClearStyles() {
// Reset all styles to be like the default style
- for (unsigned int i=0; i<stylesSize; i++) {
+ for (unsigned int i=0; i<styles.size(); i++) {
if (i != STYLE_DEFAULT) {
styles[i].ClearTo(styles[STYLE_DEFAULT]);
}
@@ -470,7 +387,7 @@ bool ViewStyle::ProtectionActive() const { }
bool ViewStyle::ValidStyle(size_t styleIndex) const {
- return styleIndex < stylesSize;
+ return styleIndex < styles.size();
}
void ViewStyle::CalcLargestMarkerHeight() {
@@ -488,3 +405,44 @@ void ViewStyle::CalcLargestMarkerHeight() { }
}
}
+
+void ViewStyle::AllocStyles(size_t sizeNew) {
+ size_t i=styles.size();
+ styles.resize(sizeNew);
+ if (styles.size() > STYLE_DEFAULT) {
+ for (; i<sizeNew; i++) {
+ if (i != STYLE_DEFAULT) {
+ styles[i].ClearTo(styles[STYLE_DEFAULT]);
+ }
+ }
+ }
+}
+
+void ViewStyle::CreateFont(const FontSpecification &fs) {
+ if (fs.fontName) {
+ FontMap::iterator it = fonts.find(fs);
+ if (it == fonts.end()) {
+ fonts[fs] = new FontRealised();
+ }
+ }
+}
+
+FontRealised *ViewStyle::Find(const FontSpecification &fs) {
+ if (!fs.fontName) // Invalid specification so return arbitrary object
+ return fonts.begin()->second;
+ FontMap::iterator it = fonts.find(fs);
+ if (it != fonts.end()) {
+ // Should always reach here since map was just set for all styles
+ return it->second;
+ }
+ return 0;
+}
+
+void ViewStyle::FindMaxAscentDescent(unsigned int &maxAscent, unsigned int &maxDescent) {
+ for (FontMap::const_iterator it = fonts.begin(); it != fonts.end(); ++it) {
+ if (maxAscent < it->second->ascent)
+ maxAscent = it->second->ascent;
+ if (maxDescent < it->second->descent)
+ maxDescent = it->second->descent;
+ }
+}
diff --git a/scintilla/src/ViewStyle.h b/scintilla/src/ViewStyle.h index 1830ae8..2288a64 100644 --- a/scintilla/src/ViewStyle.h +++ b/scintilla/src/ViewStyle.h @@ -28,9 +28,7 @@ public: */
class FontNames {
private:
- char **names;
- int size;
- int max;
+ std::vector<char *> names;
// Private so FontNames objects can not be copied
FontNames(const FontNames &);
@@ -41,32 +39,30 @@ public: const char *Save(const char *name);
};
-class FontRealised : public FontSpecification, public FontMeasurements {
+class FontRealised : public FontMeasurements {
// Private so FontRealised objects can not be copied
FontRealised(const FontRealised &);
FontRealised &operator=(const FontRealised &);
public:
Font font;
- FontRealised *frNext;
- FontRealised(const FontSpecification &fs);
+ FontRealised();
virtual ~FontRealised();
- void Realise(Surface &surface, int zoomLevel, int technology);
- FontRealised *Find(const FontSpecification &fs);
- void FindMaxAscentDescent(unsigned int &maxAscent, unsigned int &maxDescent);
+ void Realise(Surface &surface, int zoomLevel, int technology, const FontSpecification &fs);
};
enum IndentView {ivNone, ivReal, ivLookForward, ivLookBoth};
enum WhiteSpaceVisibility {wsInvisible=0, wsVisibleAlways=1, wsVisibleAfterIndent=2};
+typedef std::map<FontSpecification, FontRealised *> FontMap;
+
/**
*/
class ViewStyle {
-public:
FontNames fontNames;
- FontRealised *frFirst;
- size_t stylesSize;
- Style *styles;
+ FontMap fonts;
+public:
+ std::vector<Style> styles;
size_t nextExtendedStyle;
LineMarker markers[MARKER_MAX + 1];
int largestMarkerHeight;
@@ -143,9 +139,7 @@ public: ViewStyle(const ViewStyle &source);
~ViewStyle();
void Init(size_t stylesSize_=64);
- void CreateFont(const FontSpecification &fs);
void Refresh(Surface &surface);
- void AllocStyles(size_t sizeNew);
void ReleaseAllExtendedStyles();
int AllocateExtendedStyles(int numberStyles);
void EnsureStyle(size_t index);
@@ -155,6 +149,13 @@ public: bool ProtectionActive() const;
bool ValidStyle(size_t styleIndex) const;
void CalcLargestMarkerHeight();
+private:
+ void AllocStyles(size_t sizeNew);
+ void CreateFont(const FontSpecification &fs);
+ FontRealised *Find(const FontSpecification &fs);
+ void FindMaxAscentDescent(unsigned int &maxAscent, unsigned int &maxDescent);
+ // Private so can only be copied through copy constructor which ensures font names initialised correctly
+ ViewStyle &operator=(const ViewStyle &);
};
#ifdef SCI_NAMESPACE
diff --git a/scintilla/src/XPM.cxx b/scintilla/src/XPM.cxx index 02b2f32..59fa2c2 100644 --- a/scintilla/src/XPM.cxx +++ b/scintilla/src/XPM.cxx @@ -41,12 +41,8 @@ static size_t MeasureLength(const char *s) { return i;
}
-ColourDesired XPM::ColourDesiredFromCode(int ch) const {
- return *colourCodeTable[ch];
-}
-
ColourDesired XPM::ColourFromCode(int ch) const {
- return *colourCodeTable[ch];
+ return colourCodeTable[ch];
}
void XPM::FillRun(Surface *surface, int code, int startX, int y, int x) {
@@ -56,13 +52,11 @@ void XPM::FillRun(Surface *surface, int code, int startX, int y, int x) { }
}
-XPM::XPM(const char *textForm) :
- data(0), codes(0), colours(0), lines(0) {
+XPM::XPM(const char *textForm) {
Init(textForm);
}
-XPM::XPM(const char *const *linesForm) :
- data(0), codes(0), colours(0), lines(0) {
+XPM::XPM(const char *const *linesForm) {
Init(linesForm);
}
@@ -76,10 +70,9 @@ void XPM::Init(const char *textForm) { // if memcmp implemented strangely. Must be 4 bytes at least at destination.
if ((0 == memcmp(textForm, "/* X", 4)) && (0 == memcmp(textForm, "/* XPM */", 9))) {
// Build the lines form out of the text form
- const char **linesForm = LinesFormFromTextForm(textForm);
- if (linesForm != 0) {
- Init(linesForm);
- delete []linesForm;
+ std::vector<const char *> linesForm = LinesFormFromTextForm(textForm);
+ if (!linesForm.empty()) {
+ Init(&linesForm[0]);
}
} else {
// It is really in line form
@@ -92,18 +85,17 @@ void XPM::Init(const char *const *linesForm) { height = 1;
width = 1;
nColours = 1;
- data = NULL;
+ pixels.clear();
codeTransparent = ' ';
- codes = NULL;
- colours = NULL;
- lines = NULL;
if (!linesForm)
return;
+ std::fill(colourCodeTable, colourCodeTable+256, 0);
const char *line0 = linesForm[0];
width = atoi(line0);
line0 = NextField(line0);
height = atoi(line0);
+ pixels.resize(width*height);
line0 = NextField(line0);
nColours = atoi(line0);
line0 = NextField(line0);
@@ -111,56 +103,33 @@ void XPM::Init(const char *const *linesForm) { // Only one char per pixel is supported
return;
}
- codes = new char[nColours];
- colours = new ColourDesired[nColours];
-
- int strings = 1+height+nColours;
- lines = new char *[strings];
- size_t allocation = 0;
- for (int i=0; i<strings; i++) {
- allocation += MeasureLength(linesForm[i]) + 1;
- }
- data = new char[allocation];
- char *nextBit = data;
- for (int j=0; j<strings; j++) {
- lines[j] = nextBit;
- size_t len = MeasureLength(linesForm[j]);
- memcpy(nextBit, linesForm[j], len);
- nextBit += len;
- *nextBit++ = '\0';
- }
-
- for (int code=0; code<256; code++) {
- colourCodeTable[code] = 0;
- }
for (int c=0; c<nColours; c++) {
const char *colourDef = linesForm[c+1];
- codes[c] = colourDef[0];
+ int code = static_cast<unsigned char>(colourDef[0]);
colourDef += 4;
+ ColourDesired colour(0xff, 0xff, 0xff);
if (*colourDef == '#') {
- colours[c].Set(colourDef);
+ colour.Set(colourDef);
} else {
- colours[c] = ColourDesired(0xff, 0xff, 0xff);
- codeTransparent = codes[c];
+ codeTransparent = code;
}
- colourCodeTable[static_cast<unsigned char>(codes[c])] = &(colours[c]);
+ colourCodeTable[code] = colour;
+ }
+
+ for (int y=0; y<height; y++) {
+ const char *lform = linesForm[y+nColours+1];
+ size_t len = MeasureLength(lform);
+ for (size_t x = 0; x<len; x++)
+ pixels[y * width + x] = static_cast<unsigned char>(lform[x]);
}
}
void XPM::Clear() {
- delete []data;
- data = 0;
- delete []codes;
- codes = 0;
- delete []colours;
- colours = 0;
- delete []lines;
- lines = 0;
}
void XPM::Draw(Surface *surface, PRectangle &rc) {
- if (!data || !codes || !colours || !lines) {
+ if (pixels.empty()) {
return;
}
// Centre the pixmap
@@ -170,7 +139,7 @@ void XPM::Draw(Surface *surface, PRectangle &rc) { int prevCode = 0;
int xStartRun = 0;
for (int x=0; x<width; x++) {
- int code = lines[y+nColours+1][x];
+ int code = pixels[y * width + x];
if (code != prevCode) {
FillRun(surface, prevCode, startX + xStartRun, startY + y, startX + x);
xStartRun = x;
@@ -182,23 +151,23 @@ void XPM::Draw(Surface *surface, PRectangle &rc) { }
void XPM::PixelAt(int x, int y, ColourDesired &colour, bool &transparent) const {
- if (!data || !codes || !colours || !lines || (x<0) || (x >= width) || (y<0) || (y >= height)) {
+ if (pixels.empty() || (x<0) || (x >= width) || (y<0) || (y >= height)) {
colour = 0;
transparent = true;
return;
}
- int code = lines[y+nColours+1][x];
+ int code = pixels[y * width + x];
transparent = code == codeTransparent;
if (transparent) {
colour = 0;
} else {
- colour = ColourDesiredFromCode(code).AsLong();
+ colour = ColourFromCode(code).AsLong();
}
}
-const char **XPM::LinesFormFromTextForm(const char *textForm) {
+std::vector<const char *> XPM::LinesFormFromTextForm(const char *textForm) {
// Build the lines form out of the text form
- const char **linesForm = 0;
+ std::vector<const char *> linesForm;
int countQuotes = 0;
int strings=1;
int j=0;
@@ -214,111 +183,23 @@ const char **XPM::LinesFormFromTextForm(const char *textForm) { line0 = NextField(line0);
// Add 1 line for each colour
strings += atoi(line0);
- linesForm = new const char *[strings];
- if (linesForm == 0) {
- break; // Memory error!
- }
}
if (countQuotes / 2 >= strings) {
break; // Bad height or number of colors!
}
if ((countQuotes & 1) == 0) {
- linesForm[countQuotes / 2] = textForm + j + 1;
+ linesForm.push_back(textForm + j + 1);
}
countQuotes++;
}
}
if (textForm[j] == '\0' || countQuotes / 2 > strings) {
// Malformed XPM! Height + number of colors too high or too low
- delete []linesForm;
- linesForm = 0;
+ linesForm.clear();
}
return linesForm;
}
-// In future, may want to minimize search time by sorting and using a binary search.
-
-XPMSet::XPMSet() : set(0), len(0), maximum(0), height(-1), width(-1) {
-}
-
-XPMSet::~XPMSet() {
- Clear();
-}
-
-void XPMSet::Clear() {
- for (int i = 0; i < len; i++) {
- delete set[i];
- }
- delete []set;
- set = 0;
- len = 0;
- maximum = 0;
- height = -1;
- width = -1;
-}
-
-void XPMSet::Add(int ident, const char *textForm) {
- // Invalidate cached dimensions
- height = -1;
- width = -1;
-
- // Replace if this id already present
- for (int i = 0; i < len; i++) {
- if (set[i]->GetId() == ident) {
- set[i]->Init(textForm);
- return;
- }
- }
-
- // Not present, so add to end
- XPM *pxpm = new XPM(textForm);
- if (pxpm) {
- pxpm->SetId(ident);
- if (len == maximum) {
- maximum += 64;
- XPM **setNew = new XPM *[maximum];
- for (int i = 0; i < len; i++) {
- setNew[i] = set[i];
- }
- delete []set;
- set = setNew;
- }
- set[len] = pxpm;
- len++;
- }
-}
-
-XPM *XPMSet::Get(int ident) {
- for (int i = 0; i < len; i++) {
- if (set[i]->GetId() == ident) {
- return set[i];
- }
- }
- return 0;
-}
-
-int XPMSet::GetHeight() {
- if (height < 0) {
- for (int i = 0; i < len; i++) {
- if (height < set[i]->GetHeight()) {
- height = set[i]->GetHeight();
- }
- }
- }
- return (height > 0) ? height : 0;
-}
-
-int XPMSet::GetWidth() {
- if (width < 0) {
- for (int i = 0; i < len; i++) {
- if (width < set[i]->GetWidth()) {
- width = set[i]->GetWidth();
- }
- }
- }
- return (width > 0) ? width : 0;
-}
-
RGBAImage::RGBAImage(int width_, int height_, float scale_, const unsigned char *pixels_) :
height(height_), width(width_), scale(scale_) {
if (pixels_) {
diff --git a/scintilla/src/XPM.h b/scintilla/src/XPM.h index 9ecb1d5..ddac02e 100644 --- a/scintilla/src/XPM.h +++ b/scintilla/src/XPM.h @@ -1,6 +1,6 @@ // Scintilla source code edit control
/** @file XPM.h
- ** Define a class that holds data in the X Pixmap (XPM) format.
+ ** Define a classes to hold image data in the X Pixmap (XPM) and RGBA formats.
**/
// Copyright 1998-2003 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.
@@ -16,19 +16,14 @@ namespace Scintilla { * Hold a pixmap in XPM format.
*/
class XPM {
- int pid; // Assigned by container
int height;
int width;
int nColours;
- char *data;
+ std::vector<unsigned char> pixels;
+ ColourDesired colourCodeTable[256];
char codeTransparent;
- char *codes;
- ColourDesired *colours;
- ColourDesired ColourDesiredFromCode(int ch) const;
ColourDesired ColourFromCode(int ch) const;
void FillRun(Surface *surface, int code, int startX, int y, int x);
- char **lines;
- ColourDesired *colourCodeTable[256];
public:
XPM(const char *textForm);
XPM(const char *const *linesForm);
@@ -38,41 +33,15 @@ public: void Clear();
/// Decompose image into runs and use FillRectangle for each run
void Draw(Surface *surface, PRectangle &rc);
- char **InLinesForm() { return lines; }
- void SetId(int pid_) { pid = pid_; }
- int GetId() const { return pid; }
int GetHeight() const { return height; }
int GetWidth() const { return width; }
void PixelAt(int x, int y, ColourDesired &colour, bool &transparent) const;
- static const char **LinesFormFromTextForm(const char *textForm);
+private:
+ static std::vector<const char *>LinesFormFromTextForm(const char *textForm);
};
/**
- * A collection of pixmaps indexed by integer id.
- */
-class XPMSet {
- XPM **set; ///< The stored XPMs.
- int len; ///< Current number of XPMs.
- int maximum; ///< Current maximum number of XPMs, increased by steps if reached.
- int height; ///< Memorize largest height of the set.
- int width; ///< Memorize largest width of the set.
-public:
- XPMSet();
- ~XPMSet();
- /// Remove all XPMs.
- void Clear();
- /// Add a XPM.
- void Add(int ident, const char *textForm);
- /// Get XPM by id.
- XPM *Get(int ident);
- /// Give the largest height of the set.
- int GetHeight();
- /// Give the largest width of the set.
- int GetWidth();
-};
-
-/**
- * An translucent image stoed as a sequence of RGBA bytes.
+ * A translucent image stored as a sequence of RGBA bytes.
*/
class RGBAImage {
// Private so RGBAImage objects can not be copied
|