1 // Scintilla source code edit control 
   2 // Document.h - text document that handles notifications, DBCS, styling, words and end of line 
   3 // Copyright 1998-2000 by Neil Hodgson <neilh@scintilla.org> 
   4 // The License.txt file describes the conditions under which this software may be distributed. 
   9 // A Position is a position within a document between two characters or at the beginning or end. 
  10 // Sometimes used as a character index where it identifies the character after the position. 
  12 const Position invalidPosition 
= -1; 
  14 // The range class represents a range of text in a document. 
  15 // The two values are not sorted as one end may be more significant than the other 
  16 // as is the case for the selection where the end position is the position of the caret. 
  17 // If either position is invalidPosition then the range is invalid and most operations will fail. 
  23         Range(Position pos
=0) :  
  24                 start(pos
), end(pos
) { 
  26         Range(Position start_
, Position end_
) :  
  27                 start(start_
), end(end_
) { 
  31                 return (start 
!= invalidPosition
) && (end 
!= invalidPosition
); 
  34         bool Contains(Position pos
) const { 
  36                         return (pos 
>= start 
&& pos 
<= end
); 
  38                         return (pos 
<= start 
&& pos 
>= end
); 
  42         bool Contains(Range other
) const { 
  43                 return Contains(other
.start
) && Contains(other
.end
); 
  46         bool Overlaps(Range other
) const { 
  48                 Contains(other
.start
) || 
  49                 Contains(other
.end
) || 
  50                 other
.Contains(start
) || 
  56 class DocModification
; 
  61         // Used to pair watcher pointer with user data 
  62         class WatcherWithUserData 
{ 
  66                 WatcherWithUserData() { 
  81         WatcherWithUserData 
*watchers
; 
  98         int LineFromPosition(int pos
); 
  99         int ClampPositionIntoDocument(int pos
); 
 100         bool IsCrLf(int pos
); 
 101         int MovePositionOutsideChar(int pos
, int moveDir
, bool checkLineEnd
=true); 
 103         // Gateways to modifying document 
 104         void DeleteChars(int pos
, int len
); 
 105         void InsertStyledString(int position
, char *s
, int insertLength
); 
 108         bool CanUndo() { return cb
.CanUndo(); } 
 109         bool CanRedo() { return cb
.CanRedo(); } 
 110         void DeleteUndoHistory() { cb
.DeleteUndoHistory(); } 
 111         undoCollectionType 
SetUndoCollection(undoCollectionType collectUndo
) { 
 112                 return cb
.SetUndoCollection(collectUndo
); 
 114         void AppendUndoStartAction() { cb
.AppendUndoStartAction(); } 
 115         void BeginUndoAction() { cb
.BeginUndoAction(); } 
 116         void EndUndoAction() { cb
.EndUndoAction(); } 
 118         bool IsSavePoint() { return cb
.IsSavePoint(); } 
 119         void Indent(bool forwards
, int lineBottom
, int lineTop
); 
 120         void ConvertLineEnds(int eolModeSet
); 
 121         void SetReadOnly(bool set
) { cb
.SetReadOnly(set
); } 
 123         void InsertChar(int pos
, char ch
); 
 124         void InsertString(int position
, const char *s
); 
 125         void InsertString(int position
, const char *s
, int insertLength
); 
 126         void DelChar(int pos
); 
 127         int DelCharBack(int pos
); 
 129         char CharAt(int position
) { return cb
.CharAt(position
); } 
 130         void GetCharRange(char *buffer
, int position
, int lengthRetrieve
) { 
 131                 cb
.GetCharRange(buffer
, position
, lengthRetrieve
); 
 133         char StyleAt(int position
) { return cb
.StyleAt(position
); } 
 134         int GetMark(int line
) { return cb
.GetMark(line
); } 
 135         int AddMark(int line
, int markerNum
) { return cb
.AddMark(line
, markerNum
); } 
 136         void DeleteMark(int line
, int markerNum
) { cb
.DeleteMark(line
, markerNum
); } 
 137         void DeleteMarkFromHandle(int markerHandle
) { cb
.DeleteMarkFromHandle(markerHandle
); } 
 138         void DeleteAllMarks(int markerNum
) { cb
.DeleteAllMarks(markerNum
); } 
 139         int LineFromHandle(int markerHandle
) { return cb
.LineFromHandle(markerHandle
); } 
 140         int LineStart(int line
); 
 141         int LineEndPosition(int position
); 
 142         int VCHomePosition(int position
); 
 144         int SetLevel(int line
, int level
); 
 145         int GetLevel(int line
) { return cb
.GetLevel(line
); } 
 146         int GetLastChild(int lineParent
, int level
=-1); 
 147         int GetFoldParent(int line
); 
 149         void Indent(bool forwards
); 
 150         int ExtendWordSelect(int pos
, int delta
); 
 151         int NextWordStart(int pos
, int delta
); 
 152         int Length() { return cb
.Length(); } 
 153         long FindText(int minPos
, int maxPos
, const char *s
, bool caseSensitive
, bool word
); 
 154         long FindText(WORD iMessage
,WPARAM wParam
,LPARAM lParam
); 
 157         void SetWordChars(unsigned char *chars
); 
 158         void SetStylingBits(int bits
); 
 159         void StartStyling(int position
, char mask
); 
 160         void SetStyleFor(int length
, char style
); 
 161         void SetStyles(int length
, char *styles
); 
 162         int GetEndStyled() { return endStyled
; } 
 164         int SetLineState(int line
, int state
) { return cb
.SetLineState(line
, state
); } 
 165         int GetLineState(int line
) { return cb
.GetLineState(line
); } 
 166         int GetMaxLineState() { return cb
.GetMaxLineState(); } 
 168         bool AddWatcher(DocWatcher 
*watcher
, void *userData
); 
 169         bool RemoveWatcher(DocWatcher 
*watcher
, void *userData
); 
 170         const WatcherWithUserData 
*GetWatchers() const { return watchers
; } 
 171         int GetLenWatchers() const { return lenWatchers
; } 
 174         bool IsDBCS(int pos
); 
 175         bool IsWordChar(unsigned char ch
); 
 176         bool IsWordAt(int start
, int end
); 
 177         void ModifiedAt(int pos
); 
 179         void NotifyModifyAttempt(); 
 180         void NotifySavePoint(bool atSavePoint
); 
 181         void NotifyModified(DocModification mh
); 
 184 // To optimise processing of document modifications by DocWatchers, a hint is passed indicating the  
 185 // scope of the change. 
 186 // If the DocWatcher is a document view then this can be used to optimise screen updating. 
 187 class DocModification 
{ 
 189         int modificationType
; 
 192         int linesAdded
; // Negative if lines deleted 
 193         const char *text
;       // Only valid for changes to text, not for changes to style 
 198         DocModification(int modificationType_
, int position_
=0, int length_
=0,  
 199                 int linesAdded_
=0, const char *text_
=0) : 
 200                 modificationType(modificationType_
), 
 203                 linesAdded(linesAdded_
), 
 210 // A class that wants to receive notifications from a Document must be derived from DocWatcher  
 211 // and implement the notification methods. It can then be added to the watcher list with AddWatcher. 
 214         virtual ~DocWatcher() {} 
 216         virtual void NotifyModifyAttempt(Document 
*doc
, void *userData
) = 0; 
 217         virtual void NotifySavePoint(Document 
*doc
, void *userData
, bool atSavePoint
) = 0; 
 218         virtual void NotifyModified(Document 
*doc
, DocModification mh
, void *userData
) = 0; 
 219         virtual void NotifyDeleted(Document 
*doc
, void *userData
) = 0;