00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
#ifndef __KATE_TEXTLINE_H__
00024
#define __KATE_TEXTLINE_H__
00025
00026
#include <ksharedptr.h>
00027
00028
#include <qmemarray.h>
00029
#include <qstring.h>
00030
00031
class KateRenderer;
00032
class QTextStream;
00033
00041 class KateTextLine :
public KShared
00042 {
00043
public:
00047 typedef KSharedPtr<KateTextLine> Ptr;
00048
00049
public:
00053 enum Flags
00054 {
00055 flagNoOtherData = 0x1,
00056 flagHlContinue = 0x2,
00057 flagAutoWrapped = 0x4,
00058 flagFoldingColumnsOutdated=0x8
00059 };
00060
00061
public:
00067
KateTextLine ();
00068
00072
~KateTextLine ();
00073
00077
public:
00081 inline void setFoldingColumnsOutdated(
bool set) {
if (set) m_flags |= KateTextLine::flagFoldingColumnsOutdated;
else m_flags&=
00082 (~
KateTextLine::flagFoldingColumnsOutdated);}
00083
00088 inline bool foldingColumnsOutdated() {
return m_flags & KateTextLine::flagFoldingColumnsOutdated; }
00089
00090
00095 inline uint
length()
const {
return m_text.
length(); }
00096
00101 inline bool hlLineContinue ()
const {
return m_flags & KateTextLine::flagHlContinue; }
00102
00107 inline bool isAutoWrapped ()
const {
return m_flags & KateTextLine::flagAutoWrapped; }
00108
00113
int firstChar() const;
00114
00119
int lastChar() const;
00120
00127
int nextNonSpaceChar(uint pos) const;
00128
00135
int previousNonSpaceChar(uint pos) const;
00136
00143 inline
QChar getChar (uint pos)
const {
return m_text[pos]; }
00144
00149 inline const QChar *
text()
const {
return m_text.
unicode(); }
00150
00165 inline uchar *
attributes ()
const {
return m_attributes.
data(); }
00166
00171 inline const QString&
string()
const {
return m_text; }
00172
00179 inline QString string(uint startCol, uint length)
const
00180
{
return m_text.
mid(startCol, length); }
00181
00194
void stringAsHtml(uint startCol, uint length,
KateRenderer *renderer,
QTextStream *outputStream)
const;
00195
00205 void stringAsHtml(
KateRenderer *renderer,
QTextStream *outputStream)
const
00206
{ stringAsHtml(0,m_text.
length(),renderer, outputStream);}
00207
00212
const QChar *
firstNonSpace() const;
00213
00219 uint indentDepth (uint tabwidth) const;
00220
00228
int cursorX(uint pos, uint tabChars) const;
00229
00235 uint lengthWithTabs (uint tabChars) const;
00236
00243
bool stringAtPos(uint pos, const
QString& match) const;
00244
00250
bool startingWith(const
QString& match) const;
00251
00257
bool endingWith(const
QString& match) const;
00258
00269
bool searchText (uint startCol, const
QString &text,
00270 uint *foundAtCol, uint *matchLen,
00271
bool casesensitive = true,
00272
bool backwards = false);
00273
00283
bool searchText (uint startCol, const
QRegExp ®exp,
00284 uint *foundAtCol, uint *matchLen,
00285
bool backwards = false);
00286
00295 inline uchar attribute (uint pos)
const
00296
{
00297
if (pos < m_attributes.
size())
return m_attributes[pos];
00298
return 0;
00299 }
00300
00305 inline const QMemArray<short> &
ctxArray ()
const {
return m_ctx; };
00306
00311 inline const QMemArray<uint> &
foldingListArray ()
const {
return m_foldingList; };
00312
00317 inline const QMemArray<unsigned short> &
indentationDepthArray ()
const {
return m_indentationDepth; };
00318
00326
void insertText (uint pos, uint insLen,
const QChar *insText, uchar *insAttribs = 0);
00327
00333
void removeText (uint pos, uint delLen);
00334
00339
void truncate(uint newLen);
00340
00345 inline void setHlLineContinue (
bool cont)
00346 {
00347
if (cont) m_flags = m_flags | KateTextLine::flagHlContinue;
00348
else m_flags = m_flags & ~ KateTextLine::flagHlContinue;
00349 }
00350
00355 inline void setAutoWrapped (
bool wrapped)
00356 {
00357
if (wrapped) m_flags = m_flags | KateTextLine::flagAutoWrapped;
00358
else m_flags = m_flags & ~ KateTextLine::flagAutoWrapped;
00359 }
00360
00365 inline void setContext (
QMemArray<short> &val) { m_ctx.
assign (val); }
00366
00371 inline void setFoldingList (
QMemArray<uint> &val) { m_foldingList.
assign (val); m_foldingList.
detach(); }
00372
00377 inline void setIndentationDepth (
QMemArray<unsigned short> &val) { m_indentationDepth.
assign (val); }
00378
00382
public:
00388 inline uint
dumpSize (
bool withHighlighting)
const
00389
{
00390
return ( 1
00391 +
sizeof(uint)
00392 + (m_text.
length() *
sizeof(
QChar))
00393 + ( withHighlighting ?
00394 ( (3 *
sizeof(uint))
00395 + (m_text.
length() *
sizeof(uchar))
00396 + (m_ctx.
size() *
sizeof(
short))
00397 + (m_foldingList.
size() *
sizeof(uint))
00398 + (m_indentationDepth.
size() *
sizeof(
unsigned short))
00399 ) : 0
00400 )
00401 );
00402 }
00403
00411
char *dump (
char *buf,
bool withHighlighting)
const;
00412
00419
char *restore (
char *buf);
00420
00424
private:
00428
QString m_text;
00429
00435
QMemArray<uchar> m_attributes;
00436
00440
QMemArray<short> m_ctx;
00441
00445
QMemArray<uint> m_foldingList;
00446
00450
QMemArray<unsigned short> m_indentationDepth;
00451
00455 uchar m_flags;
00456 };
00457
00458
#endif
00459
00460