katetextline.h
/* This file is part of the KDE libraries
Copyright (C) 2001-2003 Christoph Cullmann <cullmann@kde.org>
Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org>
Based on:
KateTextLine : Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef __KATE_TEXTLINE_H__
#define __KATE_TEXTLINE_H__
#include <ksharedptr.h>
#include <qmemarray.h>
#include <qstring.h>
class KateRenderer;
class QTextStream;
class KateTextLine : public KShared
{
public:
typedef KSharedPtr<KateTextLine> Ptr;
public:
enum Flags
{
flagNoOtherData = 1, // ONLY INTERNAL USE, NEVER EVER SET THAT !!!!
flagHlContinue = 2,
flagAutoWrapped = 4,
flagFoldingColumnsOutdated = 8,
flagNoIndentationBasedFolding = 16,
flagNoIndentationBasedFoldingAtStart = 32
};
public:
KateTextLine ();
~KateTextLine ();
public:
inline void setFoldingColumnsOutdated(bool set) { if (set) m_flags |= KateTextLine::flagFoldingColumnsOutdated; else m_flags&=
(~KateTextLine::flagFoldingColumnsOutdated);}
inline bool foldingColumnsOutdated() { return m_flags & KateTextLine::flagFoldingColumnsOutdated; }
inline uint length() const { return m_text.length(); }
inline bool hlLineContinue () const { return m_flags & KateTextLine::flagHlContinue; }
inline bool isAutoWrapped () const { return m_flags & KateTextLine::flagAutoWrapped; }
int firstChar() const;
int lastChar() const;
int nextNonSpaceChar(uint pos) const;
int previousNonSpaceChar(uint pos) const;
inline QChar getChar (uint pos) const { return m_text[pos]; }
inline const QChar *text() const { return m_text.unicode(); }
inline uchar *attributes () const { return m_attributes.data(); }
inline const QString& string() const { return m_text; }
inline QString string(uint startCol, uint length) const
{ return m_text.mid(startCol, length); }
const QChar *firstNonSpace() const;
uint indentDepth (uint tabwidth) const;
int cursorX(uint pos, uint tabChars) const;
uint lengthWithTabs (uint tabChars) const;
bool stringAtPos(uint pos, const QString& match) const;
bool startingWith(const QString& match) const;
bool endingWith(const QString& match) const;
bool searchText (uint startCol, const QString &text,
uint *foundAtCol, uint *matchLen,
bool casesensitive = true,
bool backwards = false);
bool searchText (uint startCol, const QRegExp &regexp,
uint *foundAtCol, uint *matchLen,
bool backwards = false);
inline uchar attribute (uint pos) const
{
if (pos < m_attributes.size()) return m_attributes[pos];
return 0;
}
inline const QMemArray<short> &ctxArray () const { return m_ctx; };
inline const bool noIndentBasedFolding() const { return m_flags & KateTextLine::flagNoIndentationBasedFolding; };
inline const bool noIndentBasedFoldingAtStart() const { return m_flags & KateTextLine::flagNoIndentationBasedFoldingAtStart; };
inline const QMemArray<uint> &foldingListArray () const { return m_foldingList; };
inline const QMemArray<unsigned short> &indentationDepthArray () const { return m_indentationDepth; };
void insertText (uint pos, uint insLen, const QChar *insText, uchar *insAttribs = 0);
void removeText (uint pos, uint delLen);
void truncate(uint newLen);
inline void setHlLineContinue (bool cont)
{
if (cont) m_flags = m_flags | KateTextLine::flagHlContinue;
else m_flags = m_flags & ~ KateTextLine::flagHlContinue;
}
inline void setAutoWrapped (bool wrapped)
{
if (wrapped) m_flags = m_flags | KateTextLine::flagAutoWrapped;
else m_flags = m_flags & ~ KateTextLine::flagAutoWrapped;
}
inline void setContext (QMemArray<short> &val) { m_ctx.assign (val); }
inline void setNoIndentBasedFolding(bool val)
{
if (val) m_flags = m_flags | KateTextLine::flagNoIndentationBasedFolding;
else m_flags = m_flags & ~ KateTextLine::flagNoIndentationBasedFolding;
}
inline void setNoIndentBasedFoldingAtStart(bool val)
{
if (val) m_flags = m_flags | KateTextLine::flagNoIndentationBasedFoldingAtStart;
else m_flags = m_flags & ~ KateTextLine::flagNoIndentationBasedFoldingAtStart;
}
inline void setFoldingList (QMemArray<uint> &val) { m_foldingList.assign (val); m_foldingList.detach(); }
inline void setIndentationDepth (QMemArray<unsigned short> &val) { m_indentationDepth.assign (val); }
public:
inline uint dumpSize (bool withHighlighting) const
{
return ( 1
+ sizeof(uint)
+ (m_text.length() * sizeof(QChar))
+ ( withHighlighting ?
( (3 * sizeof(uint))
+ (m_text.length() * sizeof(uchar))
+ (m_ctx.size() * sizeof(short))
+ (m_foldingList.size() * sizeof(uint))
+ (m_indentationDepth.size() * sizeof(unsigned short))
) : 0
)
);
}
char *dump (char *buf, bool withHighlighting) const;
char *restore (char *buf);
private:
QString m_text;
QMemArray<uchar> m_attributes;
QMemArray<short> m_ctx;
QMemArray<uint> m_foldingList;
QMemArray<unsigned short> m_indentationDepth;
uchar m_flags;
};
#endif
// kate: space-indent on; indent-width 2; replace-tabs on;
KSharedPtr
KateTextLine::cursorX
int cursorX(uint pos, uint tabChars) const
Returns the x position of the cursor at the given position, which depends on the number of tab charac...
Definition: katetextline.cpp:237
KateTextLine::hlLineContinue
bool hlLineContinue() const
has the line the hl continue flag set
Definition: katetextline.h:103
KateTextLine::dump
char * dump(char *buf, bool withHighlighting) const
Dumps the line to *buf and counts buff dumpSize bytes up as return value.
Definition: katetextline.cpp:335
KateTextLine::string
QString string(uint startCol, uint length) const
Gets a substring.
Definition: katetextline.h:181
KateTextLine::setNoIndentBasedFolding
void setNoIndentBasedFolding(bool val)
sets if for the next line indent based folding should be disabled
Definition: katetextline.h:351
KateTextLine::searchText
bool searchText(uint startCol, const QString &text, uint *foundAtCol, uint *matchLen, bool casesensitive=true, bool backwards=false)
search given string
Definition: katetextline.cpp:273
KateTextLine::length
uint length() const
Returns the length.
Definition: katetextline.h:97
KateTextLine::lengthWithTabs
uint lengthWithTabs(uint tabChars) const
Returns the text length with tabs calced in.
Definition: katetextline.cpp:256
KateTextLine::removeText
void removeText(uint pos, uint delLen)
remove text at given position
Definition: katetextline.cpp:76
KateTextLine::startingWith
bool startingWith(const QString &match) const
Is the line starting with the given string.
Definition: katetextline.cpp:202
KateTextLine::setFoldingColumnsOutdated
void setFoldingColumnsOutdated(bool set)
Methods to get data.
Definition: katetextline.h:83
KateTextLine::setAutoWrapped
void setAutoWrapped(bool wrapped)
auto-wrapped
Definition: katetextline.h:336
KateTextLine::restore
char * restore(char *buf)
Restores the line from *buf and counts buff dumpSize bytes up as return value.
Definition: katetextline.cpp:383
KateTextLine::nextNonSpaceChar
int nextNonSpaceChar(uint pos) const
Find the position of the next char that is not a space.
Definition: katetextline.cpp:110
KateTextLine::setFoldingList
void setFoldingList(QMemArray< uint > &val)
update folding list
Definition: katetextline.h:367
KateRenderer
Handles all of the work of rendering the text (used for the views and printing)
Definition: katerenderer.h:42
KateTextLine::lastChar
int lastChar() const
Returns the position of the last non-whitespace character.
Definition: katetextline.cpp:147
KateTextLine::endingWith
bool endingWith(const QString &match) const
Is the line ending with the given string.
Definition: katetextline.cpp:219
KateTextLine::indentationDepthArray
const QMemArray< unsigned short > & indentationDepthArray() const
indentation stack
Definition: katetextline.h:298
KateTextLine::previousNonSpaceChar
int previousNonSpaceChar(uint pos) const
Find the position of the previous char that is not a space.
Definition: katetextline.cpp:124
KateTextLine::setIndentationDepth
void setIndentationDepth(QMemArray< unsigned short > &val)
update indentation stack
Definition: katetextline.h:373
KateTextLine::insertText
void insertText(uint pos, uint insLen, const QChar *insText, uchar *insAttribs=0)
insert text into line
Definition: katetextline.cpp:39
KateTextLine::stringAtPos
bool stringAtPos(uint pos, const QString &match) const
Can we find the given string at the given position.
Definition: katetextline.cpp:180
KateTextLine::isAutoWrapped
bool isAutoWrapped() const
was this line automagically wrapped
Definition: katetextline.h:109
KateTextLine::string
const QString & string() const
Gets a QString.
Definition: katetextline.h:173
KateTextLine::KateTextLine
KateTextLine()
Constructor Creates an empty text line with given attribute and syntax highlight context.
Definition: katetextline.cpp:30
KateTextLine::attribute
uchar attribute(uint pos) const
Gets the attribute at the given position use KRenderer::attributes to get the KTextAttribute for this...
Definition: katetextline.h:271
KateTextLine::foldingListArray
const QMemArray< uint > & foldingListArray() const
folding list
Definition: katetextline.h:292
KateTextLine::foldingColumnsOutdated
bool foldingColumnsOutdated()
folding columns outdated ?
Definition: katetextline.h:90
KateTextLine::Ptr
KSharedPtr< KateTextLine > Ptr
Define a Shared-Pointer type.
Definition: katetextline.h:47
KateTextLine::Flags
Flags
Used Flags.
Definition: katetextline.h:53
KateTextLine::noIndentBasedFolding
const bool noIndentBasedFolding() const
Definition: katetextline.h:286
KateTextLine::setHlLineContinue
void setHlLineContinue(bool cont)
set hl continue flag
Definition: katetextline.h:326
KateTextLine::attributes
uchar * attributes() const
Highlighting array The size of this is string().length()
Definition: katetextline.h:167
KateTextLine
The KateTextLine represents a line of text.
Definition: katetextline.h:41
KateTextLine::setContext
void setContext(QMemArray< short > &val)
Sets the syntax highlight context number.
Definition: katetextline.h:346
KateTextLine::firstChar
int firstChar() const
Returns the position of the first non-whitespace character.
Definition: katetextline.cpp:142
KateTextLine::ctxArray
const QMemArray< short > & ctxArray() const
context stack
Definition: katetextline.h:281
KateTextLine::dumpSize
uint dumpSize(bool withHighlighting) const
Methodes for dump/restore of the line in the buffer.
Definition: katetextline.h:384
KateTextLine::getChar
QChar getChar(uint pos) const
Gets the char at the given position.
Definition: katetextline.h:145
KateTextLine::~KateTextLine
~KateTextLine()
Destructor.
Definition: katetextline.cpp:35
KateTextLine::text
const QChar * text() const
Gets the text as a unicode representation.
Definition: katetextline.h:151
KateTextLine::truncate
void truncate(uint newLen)
Truncates the textline to the new length.
Definition: katetextline.cpp:101
KateTextLine::firstNonSpace
const QChar * firstNonSpace() const
Gets a null terminated pointer to first non space char.
Definition: katetextline.cpp:152
KateTextLine::indentDepth
uint indentDepth(uint tabwidth) const
indentation depth of this line
Definition: katetextline.cpp:158
KShared

KDE Home | KDE Accessibility Home | Description of Access Keys