btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / kits / interface / textview_support / TextGapBuffer.h
blobea96b0dab49f817c8b2d9e4546fe91706e6d3d75
1 /*
2 * Copyright 2001-2006, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Marc Flerackers (mflerackers@androme.be)
7 */
8 #ifndef __TEXTGAPBUFFER_H
9 #define __TEXTGAPBUFFER_H
12 #include <SupportDefs.h>
13 #include <TextView.h>
16 class BFile;
19 namespace BPrivate {
22 class TextGapBuffer {
23 public:
24 TextGapBuffer();
25 ~TextGapBuffer();
27 void InsertText(const char* inText, int32 inNumItems,
28 int32 inAtIndex);
29 bool InsertText(BFile* file, int32 fileOffset,
30 int32 amount, int32 atIndex);
31 void RemoveRange(int32 start, int32 end);
33 bool FindChar(char inChar, int32 fromIndex,
34 int32* ioDelta);
36 const char* Text();
37 const char* RealText();
38 int32 Length() const;
40 const char* GetString(int32 fromOffset, int32* numBytes);
41 void GetString(int32 offset, int32 length,
42 char* buffer);
44 char RealCharAt(int32 offset) const;
46 bool PasswordMode() const;
47 void SetPasswordMode(bool);
49 private:
50 void _MoveGapTo(int32 toIndex);
51 void _EnlargeGapTo(int32 inCount);
52 void _ShrinkGapTo(int32 inCount);
54 int32 fItemCount; // logical count
55 char* fBuffer; // allocated memory
56 int32 fBufferCount; // physical count
57 int32 fGapIndex; // gap position
58 int32 fGapCount; // gap count
59 char* fScratchBuffer; // for GetString
60 int32 fScratchSize; // scratch size
61 bool fPasswordMode;
65 inline int32
66 TextGapBuffer::Length() const
68 return fItemCount;
72 inline char
73 TextGapBuffer::RealCharAt(int32 index) const
75 if (index < 0 || index >= fItemCount) {
76 if (index != fItemCount)
77 debugger("RealCharAt: invalid index supplied");
78 return 0;
81 return index < fGapIndex ? fBuffer[index] : fBuffer[index + fGapCount];
85 } // namespace BPrivate
88 #endif //__TEXTGAPBUFFER_H