katerenderer.h
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2003 Hamish Rodda <rodda@kde.org> 00003 Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> 00004 Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org> 00005 Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License version 2 as published by the Free Software Foundation. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #ifndef __KATE_RENDERER_H__ 00023 #define __KATE_RENDERER_H__ 00024 00025 #include "katecursor.h" 00026 #include "kateattribute.h" 00027 #include "katetextline.h" 00028 00029 #include <tqfont.h> 00030 #include <tqfontmetrics.h> 00031 00032 class KateDocument; 00033 class KateView; 00034 class KateLineRange; 00035 class KateRendererConfig; 00036 00042 class KateRenderer 00043 { 00044 public: 00048 enum caretStyles { 00049 Insert, 00050 Replace 00051 }; 00052 00058 KateRenderer(KateDocument* doc, KateView *view = 0); 00059 00063 ~KateRenderer(); 00064 00069 void updateAttributes (); 00070 00075 inline bool drawCaret() const { return m_drawCaret; } 00076 00081 void setDrawCaret(bool drawCaret); 00082 00087 inline KateRenderer::caretStyles caretStyle() const { return m_caretStyle; } 00088 00093 void setCaretStyle(KateRenderer::caretStyles style); 00094 00100 inline bool showTabs() const { return m_showTabs; } 00101 00106 void setShowTabs(bool showTabs); 00107 00112 void setTabWidth(int tabWidth); 00113 00118 bool showIndentLines() const; 00119 00124 void setShowIndentLines(bool showLines); 00125 00130 void setIndentWidth(int indentWidth); 00131 00136 inline bool showSelections() const { return m_showSelections; } 00137 00143 void setShowSelections(bool showSelections); 00144 00148 void increaseFontSizes(); 00149 void decreaseFontSizes(); 00150 const TQFont* currentFont(); 00151 const TQFontMetrics* currentFontMetrics(); 00152 00157 bool isPrinterFriendly() const; 00158 00164 void setPrinterFriendly(bool printerFriendly); 00165 00170 // Width calculators 00171 uint spaceWidth(); 00172 uint textWidth(const KateTextLine::Ptr &, int cursorCol); 00173 uint textWidth(const KateTextLine::Ptr &textLine, uint startcol, uint maxwidth, bool *needWrap, int *endX = 0); 00174 uint textWidth(const KateTextCursor &cursor); 00175 00176 // Cursor constrainer 00177 uint textWidth(KateTextCursor &cursor, int xPos, uint startCol = 0); 00178 00179 // Column calculators 00188 uint textPos(uint line, int xPos, uint startCol = 0, bool nearest=true); 00192 uint textPos(const KateTextLine::Ptr &, int xPos, uint startCol = 0, bool nearest=true); 00193 00194 // Font height 00195 uint fontHeight(); 00196 00197 // Document height 00198 uint documentHeight(); 00199 00200 // Selection boundaries 00201 bool getSelectionBounds(uint line, uint lineLength, uint &start, uint &end); 00202 00210 void paintTextLine(TQPainter& paint, const KateLineRange* range, int xStart, int xEnd, const KateTextCursor* cursor = 0L, const KateBracketRange* bracketmark = 0L); 00211 00221 bool paintTextLineBackground(TQPainter& paint, int line, bool isCurrentLine, int xStart, int xEnd); 00222 00230 KateAttribute* attribute(uint pos); 00231 00232 private: 00238 void paintWhitespaceMarker(TQPainter &paint, uint x, uint y); 00239 00241 void paintIndentMarker(TQPainter &paint, uint x, uint y); 00242 00243 KateDocument* m_doc; 00244 KateView *m_view; 00245 00246 // cache of config values 00247 int m_tabWidth; 00248 int m_indentWidth; 00249 uint m_schema; 00250 00251 // some internal flags 00252 KateRenderer::caretStyles m_caretStyle; 00253 bool m_drawCaret; 00254 bool m_showSelections; 00255 bool m_showTabs; 00256 bool m_printerFriendly; 00257 00258 TQMemArray<KateAttribute> *m_attributes; 00259 00263 public: 00264 inline KateRendererConfig *config () { return m_config; }; 00265 00266 void updateConfig (); 00267 00268 private: 00269 KateRendererConfig *m_config; 00270 }; 00271 00272 #endif