summaryrefslogtreecommitdiff
path: root/noncore/apps/tinykate/libkate/document/katedocument.h
Unidiff
Diffstat (limited to 'noncore/apps/tinykate/libkate/document/katedocument.h') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/tinykate/libkate/document/katedocument.h14
1 files changed, 7 insertions, 7 deletions
diff --git a/noncore/apps/tinykate/libkate/document/katedocument.h b/noncore/apps/tinykate/libkate/document/katedocument.h
index 9d8ec6a..969be87 100644
--- a/noncore/apps/tinykate/libkate/document/katedocument.h
+++ b/noncore/apps/tinykate/libkate/document/katedocument.h
@@ -1,127 +1,127 @@
1/*************************************************************************** 1/***************************************************************************
2 katedocument.h - description 2 katedocument.h - description
3 ------------------- 3 -------------------
4 begin : Mon Jan 15 2001 4 begin : Mon Jan 15 2001
5 copyright : (C) 2001 by Christoph "Crossfire" Cullmann 5 copyright : (C) 2001 by Christoph "Crossfire" Cullmann
6 (C) 2002 by Joseph Wenninger 6 (C) 2002 by Joseph Wenninger
7 email : crossfire@babylon2k.de 7 email : crossfire@babylon2k.de
8 jowenn@kde.org 8 jowenn@kde.org
9 9
10***************************************************************************/ 10***************************************************************************/
11 11
12/*************************************************************************** 12/***************************************************************************
13 * * 13 * *
14 * This program is free software; you can redistribute it and/or modify * 14 * This program is free software; you can redistribute it and/or modify *
15 * it under the terms of the GNU General Public License as published by * 15 * it under the terms of the GNU General Public License as published by *
16 * the Free Software Foundation; either version 2 of the License, or * 16 * the Free Software Foundation; either version 2 of the License, or *
17 * (at your option) any later version. * 17 * (at your option) any later version. *
18 * * 18 * *
19 ***************************************************************************/ 19 ***************************************************************************/
20 20
21/* 21/*
22 Copyright (C) 1998, 1999 Jochen Wilhelmy 22 Copyright (C) 1998, 1999 Jochen Wilhelmy
23 digisnap@cs.tu-berlin.de 23 digisnap@cs.tu-berlin.de
24 24
25 This library is free software; you can redistribute it and/or 25 This library is free software; you can redistribute it and/or
26 modify it under the terms of the GNU Library General Public 26 modify it under the terms of the GNU Library General Public
27 License as published by the Free Software Foundation; either 27 License as published by the Free Software Foundation; either
28 version 2 of the License, or (at your option) any later version. 28 version 2 of the License, or (at your option) any later version.
29 29
30 This library is distributed in the hope that it will be useful, 30 This library is distributed in the hope that it will be useful,
31 but WITHOUT ANY WARRANTY; without even the implied warranty of 31 but WITHOUT ANY WARRANTY; without even the implied warranty of
32 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 32 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
33 Library General Public License for more details. 33 Library General Public License for more details.
34 34
35 You should have received a copy of the GNU Library General Public License 35 You should have received a copy of the GNU Library General Public License
36 along with this library; see the file COPYING.LIB. If not, write to 36 along with this library; see the file COPYING.LIB. If not, write to
37 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 37 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
38 Boston, MA 02111-1307, USA. 38 Boston, MA 02111-1307, USA.
39*/ 39*/
40 40
41#ifndef kate_document_h 41#ifndef kate_document_h
42#define kate_document_h 42#define kate_document_h
43 43
44 44
45#include <qobject.h> 45#include <qobject.h>
46#include <qlist.h> 46#include <qlist.h>
47#include <qcolor.h> 47#include <qcolor.h>
48#include <qfont.h> 48#include <qfont.h>
49#include <qfontmetrics.h> 49#include <qfontmetrics.h>
50#include <qdatetime.h> 50#include <qdatetime.h>
51#include <qfileinfo.h> 51#include <qfileinfo.h>
52 52
53#include "../view/kateview.h" 53#include "../view/kateview.h"
54#include "katehighlight.h" 54#include "katehighlight.h"
55#include "katebuffer.h" 55#include "katebuffer.h"
56#include "katetextline.h" 56#include "katetextline.h"
57 57
58 58
59#include <qptrdict.h> 59#include <qptrdict.h>
60 60
61class KateCmd; 61class KateCmd;
62 62
63class CachedFontMetrics : public QFontMetrics { 63class CachedFontMetrics : public QFontMetrics {
64private: 64private:
65 short *warray[256]; 65 short *warray[256];
66public: 66public:
67 CachedFontMetrics(const QFont& f) : QFontMetrics(f) { 67 CachedFontMetrics(const QFont& f) : QFontMetrics(f) {
68 for (int i=0; i<256; i++) warray[i]=0; 68 for (int i=0; i<256; i++) warray[i]=0;
69 } 69 }
70 ~CachedFontMetrics() { 70 ~CachedFontMetrics() {
71 for (int i=0; i<256; i++) 71 for (int i=0; i<256; i++)
72 if (warray[i]) delete[] warray[i]; 72 if (warray[i]) delete[] warray[i];
73 } 73 }
74 int width(QChar c) { 74 int width(QChar c) {
75 uchar cell=c.cell(); 75 uchar cell=c.cell();
76 uchar row=c.row(); 76 uchar row=c.row();
77 short *wa=warray[row]; 77 short *wa=warray[row];
78 if (!wa) { 78 if (!wa) {
79 // qDebug("create row: %d",row); 79 // odebug << "create row: " << row << oendl;
80 wa=warray[row]=new short[256]; 80 wa=warray[row]=new short[256];
81 for (int i=0; i<256; i++) wa[i]=-1; 81 for (int i=0; i<256; i++) wa[i]=-1;
82 } 82 }
83 if (wa[cell]<0) wa[cell]=(short) QFontMetrics::width(c); 83 if (wa[cell]<0) wa[cell]=(short) QFontMetrics::width(c);
84 return (int)wa[cell]; 84 return (int)wa[cell];
85 } 85 }
86 int width(QString s) { return QFontMetrics::width(s); } 86 int width(QString s) { return QFontMetrics::width(s); }
87}; 87};
88 88
89class Attribute { 89class Attribute {
90 public: 90 public:
91 Attribute() { ; }; 91 Attribute() { ; };
92 92
93 QColor col; 93 QColor col;
94 QColor selCol; 94 QColor selCol;
95 bool bold; 95 bool bold;
96 bool italic; 96 bool italic;
97}; 97};
98 98
99class KateAction { 99class KateAction {
100 public: 100 public:
101 enum Action {replace, wordWrap, wordUnWrap, newLine, delLine, 101 enum Action {replace, wordWrap, wordUnWrap, newLine, delLine,
102 insLine, killLine};//, doubleLine, removeLine}; 102 insLine, killLine};//, doubleLine, removeLine};
103 103
104 KateAction(Action, PointStruc &cursor, int len = 0, 104 KateAction(Action, PointStruc &cursor, int len = 0,
105 const QString &text = QString::null); 105 const QString &text = QString::null);
106 106
107 Action action; 107 Action action;
108 PointStruc cursor; 108 PointStruc cursor;
109 int len; 109 int len;
110 QString text; 110 QString text;
111 KateAction *next; 111 KateAction *next;
112}; 112};
113 113
114class KateActionGroup { 114class KateActionGroup {
115 public: 115 public:
116 // the undo group types 116 // the undo group types
117 enum { ugNone, // 117 enum { ugNone, //
118 ugPaste, // paste 118 ugPaste, // paste
119 ugDelBlock, // delete/replace selected text 119 ugDelBlock, // delete/replace selected text
120 ugIndent, // indent 120 ugIndent, // indent
121 ugUnindent, // unindent 121 ugUnindent, // unindent
122 ugComment, // comment 122 ugComment, // comment
123 ugUncomment, // uncomment 123 ugUncomment, // uncomment
124 ugReplace, // text search/replace 124 ugReplace, // text search/replace
125 ugSpell, // spell check 125 ugSpell, // spell check
126 ugInsChar, // char type/deleting 126 ugInsChar, // char type/deleting
127 ugDelChar, // '' '' 127 ugDelChar, // '' ''
@@ -134,97 +134,97 @@ class KateActionGroup {
134 void insertAction(KateAction *); 134 void insertAction(KateAction *);
135 135
136 static const char * typeName(int type); 136 static const char * typeName(int type);
137 137
138 PointStruc start; 138 PointStruc start;
139 PointStruc end; 139 PointStruc end;
140 KateAction *action; 140 KateAction *action;
141 int undoType; 141 int undoType;
142}; 142};
143 143
144/** 144/**
145 The text document. It contains the textlines, controls the 145 The text document. It contains the textlines, controls the
146 document changing operations and does undo/redo. WARNING: do not change 146 document changing operations and does undo/redo. WARNING: do not change
147 the text contents directly in methods where this is not explicitly 147 the text contents directly in methods where this is not explicitly
148 permitted. All changes have to be made with some basic operations, 148 permitted. All changes have to be made with some basic operations,
149 which are recorded by the undo/redo system. 149 which are recorded by the undo/redo system.
150 @see TextLine 150 @see TextLine
151 @author Jochen Wilhelmy 151 @author Jochen Wilhelmy
152*/ 152*/
153class KateDocument: public Kate::Document 153class KateDocument: public Kate::Document
154{ 154{
155 Q_OBJECT 155 Q_OBJECT
156 friend class KateViewInternal; 156 friend class KateViewInternal;
157 friend class KateView; 157 friend class KateView;
158 friend class KateIconBorder; 158 friend class KateIconBorder;
159 159
160 public: 160 public:
161 KateDocument(bool bSingleViewMode=false, bool bBrowserView=false, QWidget *parentWidget = 0, const char *widgetName = 0, QObject * = 0, const char * = 0); 161 KateDocument(bool bSingleViewMode=false, bool bBrowserView=false, QWidget *parentWidget = 0, const char *widgetName = 0, QObject * = 0, const char * = 0);
162 ~KateDocument(); 162 ~KateDocument();
163 163
164 protected: 164 protected:
165 QFont myFont, myFontBold, myFontItalic, myFontBI; 165 QFont myFont, myFontBold, myFontItalic, myFontBI;
166 CachedFontMetrics myFontMetrics, myFontMetricsBold, myFontMetricsItalic, myFontMetricsBI; 166 CachedFontMetrics myFontMetrics, myFontMetricsBold, myFontMetricsItalic, myFontMetricsBI;
167 167
168 public: 168 public:
169 void setFont (QFont font); 169 void setFont (QFont font);
170 QFont getFont () { return myFont; }; 170 QFont getFont () { return myFont; };
171 CachedFontMetrics getFontMetrics () { return myFontMetrics; }; 171 CachedFontMetrics getFontMetrics () { return myFontMetrics; };
172 172
173 virtual bool saveFile(); 173 virtual bool saveFile();
174 174
175 virtual KTextEditor::View *createView( QWidget *parent, const char *name ); 175 virtual KTextEditor::View *createView( QWidget *parent, const char *name );
176 virtual QString textLine( int line ) const; 176 virtual QString textLine( int line ) const;
177 177
178 virtual void insertLine( const QString &s, int line = -1 ); 178 virtual void insertLine( const QString &s, int line = -1 );
179 179
180 void insert_Line(const QString& s,int line=-1, bool update=true); 180 void insert_Line(const QString& s,int line=-1, bool update=true);
181 void remove_Line(int line,bool update=true); 181 void remove_Line(int line,bool update=true);
182 void replaceLine(const QString& s,int line=-1); 182 void replaceLine(const QString& s,int line=-1);
183 virtual void insertAt( const QString &s, int line, int col, bool mark = FALSE ); 183 virtual void insertAt( const QString &s, int line, int col, bool mark = FALSE );
184 virtual void removeLine( int line ); 184 virtual void removeLine( int line );
185 virtual int length() const; 185 virtual int length() const;
186 186
187 virtual void setSelection( int row_from, int col_from, int row_to, int col_t ); 187 virtual void setSelection( int row_from, int col_from, int row_to, int col_t );
188 virtual bool hasSelection() const; 188 virtual bool hasSelection() const;
189 virtual QString selection() const; 189 virtual QString selection() const;
190 190
191 // only to make part work, don't change it ! 191 // only to make part work, don't change it !
192 bool m_bSingleViewMode; 192 bool m_bSingleViewMode;
193 193
194// public interface 194// public interface
195 /** 195 /**
196 * gets the number of lines 196 * gets the number of lines
197 */ 197 */
198 virtual int numLines() const; 198 virtual int numLines() const;
199 199
200 /** 200 /**
201 * gets the last line number (numLines() -1) 201 * gets the last line number (numLines() -1)
202 */ 202 */
203 int lastLine() const {return numLines()-1;} 203 int lastLine() const {return numLines()-1;}
204 204
205 /** 205 /**
206 gets the given line 206 gets the given line
207 @return the TextLine object at the given line 207 @return the TextLine object at the given line
208 @see TextLine 208 @see TextLine
209 */ 209 */
210 TextLine::Ptr getTextLine(int line) const; 210 TextLine::Ptr getTextLine(int line) const;
211 211
212 /** 212 /**
213 get the length in pixels of the given line 213 get the length in pixels of the given line
214 */ 214 */
215 int textLength(int line); 215 int textLength(int line);
216 216
217 void setTabWidth(int); 217 void setTabWidth(int);
218 int tabWidth() {return tabChars;} 218 int tabWidth() {return tabChars;}
219 void setReadOnly(bool); 219 void setReadOnly(bool);
220 bool isReadOnly() const; 220 bool isReadOnly() const;
221 void setNewDoc( bool ); 221 void setNewDoc( bool );
222 bool isNewDoc() const; 222 bool isNewDoc() const;
223 virtual void setReadWrite( bool ){}; 223 virtual void setReadWrite( bool ){};
224 virtual bool isReadWrite() const {return true;} 224 virtual bool isReadWrite() const {return true;}
225 virtual void setModified(bool); 225 virtual void setModified(bool);
226 virtual bool isModified() const; 226 virtual bool isModified() const;
227 void setSingleSelection(bool ss) {m_singleSelection = ss;} 227 void setSingleSelection(bool ss) {m_singleSelection = ss;}
228 bool singleSelection() {return m_singleSelection;} 228 bool singleSelection() {return m_singleSelection;}
229 229
230 void readConfig(); 230 void readConfig();
@@ -489,82 +489,82 @@ class KateDocument: public Kate::Document
489 QString encoding() { return myEncoding; }; 489 QString encoding() { return myEncoding; };
490 490
491 void setWordWrap (bool on); 491 void setWordWrap (bool on);
492 bool wordWrap () { return myWordWrap; }; 492 bool wordWrap () { return myWordWrap; };
493 493
494 void setWordWrapAt (uint col); 494 void setWordWrapAt (uint col);
495 uint wordWrapAt () { return myWordWrapAt; }; 495 uint wordWrapAt () { return myWordWrapAt; };
496 496
497 signals: 497 signals:
498 void modStateChanged (KateDocument *doc); 498 void modStateChanged (KateDocument *doc);
499 void nameChanged (KateDocument *doc); 499 void nameChanged (KateDocument *doc);
500 500
501 public: 501 public:
502 QList<Kate::Mark> marks (); 502 QList<Kate::Mark> marks ();
503 503
504 public slots: 504 public slots:
505 // clear buffer/filename - update the views 505 // clear buffer/filename - update the views
506 void flush (); 506 void flush ();
507 507
508 signals: 508 signals:
509 /** 509 /**
510 The file has been saved (perhaps the name has changed). The main window 510 The file has been saved (perhaps the name has changed). The main window
511 can use this to change its caption 511 can use this to change its caption
512 */ 512 */
513 void fileNameChanged (); 513 void fileNameChanged ();
514 514
515 public: 515 public:
516 //end of line settings 516 //end of line settings
517 enum Eol_settings {eolUnix=0,eolDos=1,eolMacintosh=2}; 517 enum Eol_settings {eolUnix=0,eolDos=1,eolMacintosh=2};
518 518
519 // for the DCOP interface 519 // for the DCOP interface
520 public: 520 public:
521 void open (const QString &name=0); 521 void open (const QString &name=0);
522 522
523 public: 523 public:
524 // wrap the text of the document at the column col 524 // wrap the text of the document at the column col
525 void wrapText (uint col); 525 void wrapText (uint col);
526 526
527 public slots: 527 public slots:
528 void applyWordWrap (); 528 void applyWordWrap ();
529 529
530 private: 530 private:
531 531
532 class KateDocPrivate 532 class KateDocPrivate
533 { 533 {
534 public: 534 public:
535 bool hlSetByUser; 535 bool hlSetByUser;
536 }; 536 };
537 537
538 538
539// BCI: Add a real d-pointer in the next BIC release 539// BCI: Add a real d-pointer in the next BIC release
540static QPtrDict<KateDocPrivate>* d_ptr; 540static QPtrDict<KateDocPrivate>* d_ptr;
541static void cleanup_d_ptr() 541static void cleanup_d_ptr()
542 { 542 {
543 delete d_ptr; 543 delete d_ptr;
544 } 544 }
545 545
546KateDocPrivate* d( const KateDocument* foo ) 546KateDocPrivate* d( const KateDocument* foo )
547 { 547 {
548 if ( !d_ptr ) { 548 if ( !d_ptr ) {
549 d_ptr = new QPtrDict<KateDocPrivate>; 549 d_ptr = new QPtrDict<KateDocPrivate>;
550 //qAddPostRoutine( cleanup_d_ptr ); 550 //qAddPostRoutine( cleanup_d_ptr );
551 } 551 }
552 KateDocPrivate* ret = d_ptr->find( (void*) foo ); 552 KateDocPrivate* ret = d_ptr->find( (void*) foo );
553 if ( ! ret ) { 553 if ( ! ret ) {
554 ret = new KateDocPrivate; 554 ret = new KateDocPrivate;
555 d_ptr->replace( (void*) foo, ret ); 555 d_ptr->replace( (void*) foo, ret );
556 } 556 }
557 return ret; 557 return ret;
558 } 558 }
559 559
560void delete_d( const KateDocument* foo ) 560void delete_d( const KateDocument* foo )
561 { 561 {
562 if ( d_ptr ) 562 if ( d_ptr )
563 d_ptr->remove( (void*) foo ); 563 d_ptr->remove( (void*) foo );
564 } 564 }
565 565
566}; 566};
567 567
568#endif 568#endif
569 569
570 570