OSDN Git Service

Commit DialogBox compile Okay
[tortoisegit/TortoiseGitJp.git] / ext / scintilla / src / Document.h
diff --git a/ext/scintilla/src/Document.h b/ext/scintilla/src/Document.h
new file mode 100644 (file)
index 0000000..e861ba4
--- /dev/null
@@ -0,0 +1,333 @@
+// Scintilla source code edit control\r
+/** @file Document.h\r
+ ** Text document that handles notifications, DBCS, styling, words and end of line.\r
+ **/\r
+// Copyright 1998-2003 by Neil Hodgson <neilh@scintilla.org>\r
+// The License.txt file describes the conditions under which this software may be distributed.\r
+\r
+#ifndef DOCUMENT_H\r
+#define DOCUMENT_H\r
+\r
+#ifdef SCI_NAMESPACE\r
+namespace Scintilla {\r
+#endif\r
+\r
+/**\r
+ * A Position is a position within a document between two characters or at the beginning or end.\r
+ * Sometimes used as a character index where it identifies the character after the position.\r
+ */\r
+typedef int Position;\r
+const Position invalidPosition = -1;\r
+\r
+/**\r
+ * The range class represents a range of text in a document.\r
+ * The two values are not sorted as one end may be more significant than the other\r
+ * as is the case for the selection where the end position is the position of the caret.\r
+ * If either position is invalidPosition then the range is invalid and most operations will fail.\r
+ */\r
+class Range {\r
+public:\r
+       Position start;\r
+       Position end;\r
+\r
+       Range(Position pos=0) :\r
+               start(pos), end(pos) {\r
+       };\r
+       Range(Position start_, Position end_) :\r
+               start(start_), end(end_) {\r
+       };\r
+\r
+       bool Valid() const {\r
+               return (start != invalidPosition) && (end != invalidPosition);\r
+       }\r
+\r
+       // Is the position within the range?\r
+       bool Contains(Position pos) const {\r
+               if (start < end) {\r
+                       return (pos >= start && pos <= end);\r
+               } else {\r
+                       return (pos <= start && pos >= end);\r
+               }\r
+       }\r
+\r
+       // Is the character after pos within the range?\r
+       bool ContainsCharacter(Position pos) const {\r
+               if (start < end) {\r
+                       return (pos >= start && pos < end);\r
+               } else {\r
+                       return (pos < start && pos >= end);\r
+               }\r
+       }\r
+\r
+       bool Contains(Range other) const {\r
+               return Contains(other.start) && Contains(other.end);\r
+       }\r
+\r
+       bool Overlaps(Range other) const {\r
+               return\r
+               Contains(other.start) ||\r
+               Contains(other.end) ||\r
+               other.Contains(start) ||\r
+               other.Contains(end);\r
+       }\r
+};\r
+\r
+class DocWatcher;\r
+class DocModification;\r
+class Document;\r
+\r
+/**\r
+ * Interface class for regular expression searching\r
+ */\r
+class RegexSearchBase {\r
+public:\r
+       virtual ~RegexSearchBase(){}\r
+\r
+       virtual long FindText(Document* doc, int minPos, int maxPos, const char *s,\r
+                        bool caseSensitive, bool word, bool wordStart, int flags, int *length) = 0;\r
+\r
+       ///@return String with the substitutions, must remain valid until the next call or destruction\r
+       virtual const char *SubstituteByPosition(Document* doc, const char *text, int *length) = 0;\r
+};\r
+\r
+/// Factory function for RegexSearchBase\r
+extern RegexSearchBase* CreateRegexSearch(CharClassify *charClassTable);\r
+\r
+/**\r
+ */\r
+class Document {\r
+\r
+public:\r
+       /** Used to pair watcher pointer with user data. */\r
+       class WatcherWithUserData {\r
+       public:\r
+               DocWatcher *watcher;\r
+               void *userData;\r
+               WatcherWithUserData() {\r
+                       watcher = 0;\r
+                       userData = 0;\r
+               }\r
+       };\r
+\r
+       enum charClassification { ccSpace, ccNewLine, ccWord, ccPunctuation };\r
+\r
+private:\r
+       int refCount;\r
+       CellBuffer cb;\r
+       CharClassify charClass;\r
+       char stylingMask;\r
+       int endStyled;\r
+       int styleClock;\r
+       int enteredModification;\r
+       int enteredStyling;\r
+       int enteredReadOnlyCount;\r
+\r
+       WatcherWithUserData *watchers;\r
+       int lenWatchers;\r
+\r
+       bool matchesValid;\r
+       RegexSearchBase* regex;\r
+\r
+public:\r
+       int stylingBits;\r
+       int stylingBitsMask;\r
+\r
+       int eolMode;\r
+       /// Can also be SC_CP_UTF8 to enable UTF-8 mode\r
+       int dbcsCodePage;\r
+       int tabInChars;\r
+       int indentInChars;\r
+       int actualIndentInChars;\r
+       bool useTabs;\r
+       bool tabIndents;\r
+       bool backspaceUnindents;\r
+\r
+       DecorationList decorations;\r
+\r
+       Document();\r
+       virtual ~Document();\r
+\r
+       int AddRef();\r
+       int Release();\r
+\r
+       int LineFromPosition(int pos);\r
+       int ClampPositionIntoDocument(int pos);\r
+       bool IsCrLf(int pos);\r
+       int LenChar(int pos);\r
+       bool InGoodUTF8(int pos, int &start, int &end);\r
+       int MovePositionOutsideChar(int pos, int moveDir, bool checkLineEnd=true);\r
+\r
+       // Gateways to modifying document\r
+       void ModifiedAt(int pos);\r
+       void CheckReadOnly();\r
+       bool DeleteChars(int pos, int len);\r
+       bool InsertString(int position, const char *s, int insertLength);\r
+       int Undo();\r
+       int Redo();\r
+       bool CanUndo() { return cb.CanUndo(); }\r
+       bool CanRedo() { return cb.CanRedo(); }\r
+       void DeleteUndoHistory() { cb.DeleteUndoHistory(); }\r
+       bool SetUndoCollection(bool collectUndo) {\r
+               return cb.SetUndoCollection(collectUndo);\r
+       }\r
+       bool IsCollectingUndo() { return cb.IsCollectingUndo(); }\r
+       void BeginUndoAction() { cb.BeginUndoAction(); }\r
+       void EndUndoAction() { cb.EndUndoAction(); }\r
+       void SetSavePoint();\r
+       bool IsSavePoint() { return cb.IsSavePoint(); }\r
+       const char *BufferPointer() { return cb.BufferPointer(); }\r
+\r
+       int GetLineIndentation(int line);\r
+       void SetLineIndentation(int line, int indent);\r
+       int GetLineIndentPosition(int line) const;\r
+       int GetColumn(int position);\r
+       int FindColumn(int line, int column);\r
+       void Indent(bool forwards, int lineBottom, int lineTop);\r
+       static char *TransformLineEnds(int *pLenOut, const char *s, size_t len, int eolMode);\r
+       void ConvertLineEnds(int eolModeSet);\r
+       void SetReadOnly(bool set) { cb.SetReadOnly(set); }\r
+       bool IsReadOnly() { return cb.IsReadOnly(); }\r
+\r
+       bool InsertChar(int pos, char ch);\r
+       bool InsertCString(int position, const char *s);\r
+       void ChangeChar(int pos, char ch);\r
+       void DelChar(int pos);\r
+       void DelCharBack(int pos);\r
+\r
+       char CharAt(int position) { return cb.CharAt(position); }\r
+       void GetCharRange(char *buffer, int position, int lengthRetrieve) {\r
+               cb.GetCharRange(buffer, position, lengthRetrieve);\r
+       }\r
+       char StyleAt(int position) { return cb.StyleAt(position); }\r
+       int GetMark(int line) { return cb.GetMark(line); }\r
+       int AddMark(int line, int markerNum);\r
+       void AddMarkSet(int line, int valueSet);\r
+       void DeleteMark(int line, int markerNum);\r
+       void DeleteMarkFromHandle(int markerHandle);\r
+       void DeleteAllMarks(int markerNum);\r
+       int LineFromHandle(int markerHandle) { return cb.LineFromHandle(markerHandle); }\r
+       int LineStart(int line) const;\r
+       int LineEnd(int line) const;\r
+       int LineEndPosition(int position);\r
+       int VCHomePosition(int position);\r
+\r
+       int SetLevel(int line, int level);\r
+       int GetLevel(int line) { return cb.GetLevel(line); }\r
+       void ClearLevels() { cb.ClearLevels(); }\r
+       int GetLastChild(int lineParent, int level=-1);\r
+       int GetFoldParent(int line);\r
+\r
+       void Indent(bool forwards);\r
+       int ExtendWordSelect(int pos, int delta, bool onlyWordCharacters=false);\r
+       int NextWordStart(int pos, int delta);\r
+       int NextWordEnd(int pos, int delta);\r
+       int Length() const { return cb.Length(); }\r
+       void Allocate(int newSize) { cb.Allocate(newSize); }\r
+       long FindText(int minPos, int maxPos, const char *s,\r
+               bool caseSensitive, bool word, bool wordStart, bool regExp, int flags, int *length);\r
+       long FindText(int iMessage, unsigned long wParam, long lParam);\r
+       const char *SubstituteByPosition(const char *text, int *length);\r
+       int LinesTotal() const;\r
+\r
+       void ChangeCase(Range r, bool makeUpperCase);\r
+\r
+       void SetDefaultCharClasses(bool includeWordClass);\r
+       void SetCharClasses(const unsigned char *chars, CharClassify::cc newCharClass);\r
+       void SetStylingBits(int bits);\r
+       void StartStyling(int position, char mask);\r
+       bool SetStyleFor(int length, char style);\r
+       bool SetStyles(int length, char *styles);\r
+       int GetEndStyled() { return endStyled; }\r
+       void EnsureStyledTo(int pos);\r
+       int GetStyleClock() { return styleClock; }\r
+       void IncrementStyleClock();\r
+       void DecorationFillRange(int position, int value, int fillLength);\r
+\r
+       int SetLineState(int line, int state);\r
+       int GetLineState(int line) { return cb.GetLineState(line); }\r
+       int GetMaxLineState() { return cb.GetMaxLineState(); }\r
+\r
+       bool AddWatcher(DocWatcher *watcher, void *userData);\r
+       bool RemoveWatcher(DocWatcher *watcher, void *userData);\r
+       const WatcherWithUserData *GetWatchers() const { return watchers; }\r
+       int GetLenWatchers() const { return lenWatchers; }\r
+\r
+       bool IsWordPartSeparator(char ch);\r
+       int WordPartLeft(int pos);\r
+       int WordPartRight(int pos);\r
+       int ExtendStyleRange(int pos, int delta, bool singleLine = false);\r
+       bool IsWhiteLine(int line) const;\r
+       int ParaUp(int pos);\r
+       int ParaDown(int pos);\r
+       int IndentSize() { return actualIndentInChars; }\r
+       int BraceMatch(int position, int maxReStyle);\r
+\r
+private:\r
+       CharClassify::cc WordCharClass(unsigned char ch);\r
+       bool IsWordStartAt(int pos);\r
+       bool IsWordEndAt(int pos);\r
+       bool IsWordAt(int start, int end);\r
+\r
+       void NotifyModifyAttempt();\r
+       void NotifySavePoint(bool atSavePoint);\r
+       void NotifyModified(DocModification mh);\r
+};\r
+\r
+/**\r
+ * To optimise processing of document modifications by DocWatchers, a hint is passed indicating the\r
+ * scope of the change.\r
+ * If the DocWatcher is a document view then this can be used to optimise screen updating.\r
+ */\r
+class DocModification {\r
+public:\r
+       int modificationType;\r
+       int position;\r
+       int length;\r
+       int linesAdded; /**< Negative if lines deleted. */\r
+       const char *text;       /**< Only valid for changes to text, not for changes to style. */\r
+       int line;\r
+       int foldLevelNow;\r
+       int foldLevelPrev;\r
+\r
+       DocModification(int modificationType_, int position_=0, int length_=0,\r
+               int linesAdded_=0, const char *text_=0, int line_=0) :\r
+               modificationType(modificationType_),\r
+               position(position_),\r
+               length(length_),\r
+               linesAdded(linesAdded_),\r
+               text(text_),\r
+               line(line_),\r
+               foldLevelNow(0),\r
+               foldLevelPrev(0) {}\r
+\r
+       DocModification(int modificationType_, const Action &act, int linesAdded_=0) :\r
+               modificationType(modificationType_),\r
+               position(act.position),\r
+               length(act.lenData),\r
+               linesAdded(linesAdded_),\r
+               text(act.data),\r
+               line(0),\r
+               foldLevelNow(0),\r
+               foldLevelPrev(0) {}\r
+};\r
+\r
+/**\r
+ * A class that wants to receive notifications from a Document must be derived from DocWatcher\r
+ * and implement the notification methods. It can then be added to the watcher list with AddWatcher.\r
+ */\r
+class DocWatcher {\r
+public:\r
+       virtual ~DocWatcher() {}\r
+\r
+       virtual void NotifyModifyAttempt(Document *doc, void *userData) = 0;\r
+       virtual void NotifySavePoint(Document *doc, void *userData, bool atSavePoint) = 0;\r
+       virtual void NotifyModified(Document *doc, DocModification mh, void *userData) = 0;\r
+       virtual void NotifyDeleted(Document *doc, void *userData) = 0;\r
+       virtual void NotifyStyleNeeded(Document *doc, void *userData, int endPos) = 0;\r
+};\r
+\r
+#ifdef SCI_NAMESPACE\r
+}\r
+#endif\r
+\r
+#endif\r