summaryrefslogtreecommitdiff
path: root/noncore/apps/tinykate/libkate/ktexteditor/ktexteditor.h
authorjowenn <jowenn>2002-11-10 21:08:01 (UTC)
committer jowenn <jowenn>2002-11-10 21:08:01 (UTC)
commite97a6da57804aa14907dec327fbae71bff9b383e (patch) (unidiff)
tree15f6ee292dba24bdda72f5c72f6d2224c3516763 /noncore/apps/tinykate/libkate/ktexteditor/ktexteditor.h
parent7c012ee8cd16d8befacc6f6750711443fac0fd5e (diff)
downloadopie-e97a6da57804aa14907dec327fbae71bff9b383e.zip
opie-e97a6da57804aa14907dec327fbae71bff9b383e.tar.gz
opie-e97a6da57804aa14907dec327fbae71bff9b383e.tar.bz2
import of tiny kate. (saving not possible yet)
Diffstat (limited to 'noncore/apps/tinykate/libkate/ktexteditor/ktexteditor.h') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/tinykate/libkate/ktexteditor/ktexteditor.h239
1 files changed, 239 insertions, 0 deletions
diff --git a/noncore/apps/tinykate/libkate/ktexteditor/ktexteditor.h b/noncore/apps/tinykate/libkate/ktexteditor/ktexteditor.h
new file mode 100644
index 0000000..595b5d3
--- a/dev/null
+++ b/noncore/apps/tinykate/libkate/ktexteditor/ktexteditor.h
@@ -0,0 +1,239 @@
1/* This file is part of the KDE project
2 Copyright (C) 2000 Simon Hausmann <hausmann@kde.org>
3 Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#ifndef __ktexteditor_h__
22#define __ktexteditor_h__
23
24#include <qwidget.h>
25#include <qlist.h>
26
27/**
28 * This is the kparts interface classes for text editors.
29 * The text editors use the Document/View model that allows multiple views into
30 * one file (Document)
31 *
32 * Line numbers passed via this interface must begin at line number zero (0).
33 *
34 * TODO: See documentation at http://??????? for information on how to use kparts in
35 * general. A simple (but sufficient) implementation is shown below.
36 *
37 * <pre>
38 * QHBoxLayout *layout = new QHBoxLayout(this);
39 * QSplitter *fixme = new QSplitter(this);
40 *
41 * KTrader::OfferList offers = KTrader::self()->query( "KTextEditor/Document" );
42 * assert( offers.count() >= 1 );
43 * KService::Ptr service = *offers.begin();
44 * KLibFactory *factory = KLibLoader::self()->factory( service->library() );
45 * assert( factory );
46 * m_part = static_cast<KTextEditor::Document *>(
47 * factory->create( this, 0, "KTextEditor::Document" ) );
48 * assert( m_part );
49 * m_part->createView( fixme, 0 );
50 * layout->addWidget(fixme);
51 * m_part->setText( "" );
52 * </pre>
53 *
54 * You may also be able to use a dynamic_cast for the document part above
55 * (depending on compliation of the library used)
56 *
57 */
58
59namespace KTextEditor
60{
61
62class Document;
63
64/**
65 * The View class encapsulates a single view into the document.
66 */
67
68class View : public QWidget
69{
70 Q_OBJECT
71
72public:
73 /**
74 * Create a new view to the given document. The document must be non-null.
75 */
76 View( Document *doc, QWidget *parent, const char *name = 0 );
77 virtual ~View();
78
79 /**
80 * Acessor to the parent Document.
81 */
82 virtual Document *document() const; // XXX fix when renaming KXMLGUIClient::document
83
84 virtual void setCursorPosition( int line, int col, bool mark = false ) = 0;
85 virtual void getCursorPosition( int *line, int *col ) = 0;
86
87 /**
88 * Inserts text at the current cursor position into the document
89 */
90 virtual void insertText( const QString &text, bool mark = false );
91
92 /**
93 * Overwrite mode is where the char under the cursor is replaced with the
94 * char typed by the user
95 */
96 virtual bool isOverwriteMode() const = 0;
97
98 /**
99 * You should reimplement this method.
100 * If the internal popupmenu property is enabled, then the implementation
101 * is free to handle/use/implement/show a context popupmenu ( see also
102 * KContextMenuManager class in kdeui ). If disabled, then the
103 * implementation should emit the @ref contextPopupMenu signal.
104 */
105 virtual void setInternalContextMenuEnabled( bool b );
106 virtual bool internalContextMenuEnabled() const;
107
108public slots:
109 virtual void setOverwriteMode( bool b ) = 0;
110
111signals:
112 /**
113 * Connect here when you want to implement a custom popup menu.
114 */
115 void contextPopupMenu( const QPoint &p );
116
117 /**
118 * Connect here if you want to track the scrolling within the editor. This
119 * allows you to add specialised borders that displays extra data about
120 * particular lines such as breakpoints etc.
121 */
122 void scrollValueChanged( int value );
123
124private:
125 class ViewPrivate;
126 ViewPrivate *d;
127};
128
129class Document : public QObject
130{
131 Q_OBJECT
132public:
133 Document( QObject *parent = 0, const char *name = 0 );
134 virtual ~Document();
135
136 /**
137 * Create a view that will display the document data. You can create as many
138 * views as you like. When the user modifies data in one view then all other
139 * views will be updated as well.
140 */
141 virtual View *createView( QWidget *parent, const char *name = 0 ) = 0;
142
143 /*
144 * Accessor to the list of views.
145 */
146 virtual QList<View> views() const;
147
148 /**
149 * @return All the text from the requested line.
150 */
151 virtual QString textLine( int line ) const = 0;
152
153 virtual void setSelection( int row_from, int col_from, int row_to, int col_t ) = 0;
154 virtual bool hasSelection() const = 0;
155 virtual QString selection() const = 0;
156
157 /**
158 * @return The current number of lines in the document
159 */
160 virtual int numLines() const = 0;
161
162 /**
163 * Insert line(s) at the given line number. If the line number is -1
164 * (the default) then the line is added to end of the document
165 */
166 virtual void insertLine( const QString &s, int line = -1 ) = 0;
167
168 /**
169 * Add the line(s) into the document at the given line and column.
170 */
171 virtual void insertAt( const QString &s, int line, int col, bool mark = FALSE ) = 0;
172
173 virtual void removeLine( int line ) = 0;
174
175 /**
176 * @return the complete document as a single QString
177 */
178 virtual QString text() const = 0;
179
180 /**
181 * @return the number of characters in the document
182 */
183 virtual int length() const = 0;
184
185public slots:
186 /**
187 * Set the given text into the view.
188 * Warning: This will overwrite any data currently held in this view.
189 */
190 virtual void setText( const QString &t ) = 0;
191
192signals:
193
194 /**
195 * When the user changes the text then this signal is emitted
196 * TODO: - explain why and what type of change trigger this?
197 */
198 void textChanged();
199
200 /**
201 */
202 void deleted( int startLine, int endLine );
203
204 /**
205 */
206 void inserted( int startLine, int endLine );
207
208protected:
209 /**
210 * Call this method in your document implementation whenever you created a new
211 * view.
212 * (like in @ref createView )
213 */
214 virtual void addView( View *view );
215
216 /**
217 * Call this method in your document implementation whenever you delete a view.
218 */
219 virtual void removeView( View *view );
220
221 QList<View> m_views;
222
223private slots:
224
225 /**
226 * The view emits a destroyed() signal which is connected to this slot
227 * and removed from our internal list. Note: The view* is obtained from
228 * the QObject::sender() method.
229 */
230 void slotViewDestroyed();
231
232private:
233 class DocumentPrivate;
234 DocumentPrivate *d;
235};
236
237};
238
239#endif