TQt conversion of scintilla for Qt3
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Accessor.h 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Scintilla source code edit control
  2. /** @file Accessor.h
  3. ** Rapid easy access to contents of a Scintilla.
  4. **/
  5. // Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org>
  6. // The License.txt file describes the conditions under which this software may be distributed.
  7. enum { wsSpace = 1, wsTab = 2, wsSpaceTab = 4, wsInconsistent=8};
  8. class Accessor;
  9. typedef bool (*PFNIsCommentLeader)(Accessor &styler, int pos, int len);
  10. /**
  11. * Interface to data in a Scintilla.
  12. */
  13. class Accessor {
  14. protected:
  15. enum {extremePosition=0x7FFFFFFF};
  16. /** @a bufferSize is a trade off between time taken to copy the characters
  17. * and retrieval overhead.
  18. * @a slopSize positions the buffer before the desired position
  19. * in case there is some backtracking. */
  20. enum {bufferSize=4000, slopSize=bufferSize/8};
  21. char buf[bufferSize+1];
  22. int startPos;
  23. int endPos;
  24. int codePage;
  25. virtual bool InternalIsLeadByte(char ch)=0;
  26. virtual void Fill(int position)=0;
  27. public:
  28. Accessor() : startPos(extremePosition), endPos(0), codePage(0) {}
  29. virtual ~Accessor() {}
  30. char operator[](int position) {
  31. if (position < startPos || position >= endPos) {
  32. Fill(position);
  33. }
  34. return buf[position - startPos];
  35. }
  36. /** Safe version of operator[], returning a defined value for invalid position. */
  37. char SafeGetCharAt(int position, char chDefault=' ') {
  38. if (position < startPos || position >= endPos) {
  39. Fill(position);
  40. if (position < startPos || position >= endPos) {
  41. // Position is outside range of document
  42. return chDefault;
  43. }
  44. }
  45. return buf[position - startPos];
  46. }
  47. bool IsLeadByte(char ch) {
  48. return codePage && InternalIsLeadByte(ch);
  49. }
  50. void SetCodePage(int codePage_) { codePage = codePage_; }
  51. virtual bool Match(int pos, const char *s)=0;
  52. virtual char StyleAt(int position)=0;
  53. virtual int GetLine(int position)=0;
  54. virtual int LineStart(int line)=0;
  55. virtual int LevelAt(int line)=0;
  56. virtual int Length()=0;
  57. virtual void Flush()=0;
  58. virtual int GetLineState(int line)=0;
  59. virtual int SetLineState(int line, int state)=0;
  60. virtual int GetPropertyInt(const char *key, int defaultValue=0)=0;
  61. virtual char *GetProperties()=0;
  62. // Style setting
  63. virtual void StartAt(unsigned int start, char chMask=31)=0;
  64. virtual void SetFlags(char chFlags_, char chWhile_)=0;
  65. virtual unsigned int GetStartSegment()=0;
  66. virtual void StartSegment(unsigned int pos)=0;
  67. virtual void ColourTo(unsigned int pos, int chAttr)=0;
  68. virtual void SetLevel(int line, int level)=0;
  69. virtual int IndentAmount(int line, int *flags, PFNIsCommentLeader pfnIsCommentLeader = 0)=0;
  70. };