lib

KoTextView.h
1/* This file is part of the KDE project
2 Copyright (C) 2001-2006 David Faure <faure@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#ifndef kotextview_h
21#define kotextview_h
22
23#include <tqobject.h>
24#include <tqpoint.h>
25#include <tqcolor.h>
26#include <tqfont.h>
27#include <KoRuler.h> // for KoTabulatorList
28#include <KoTextObject.h> // for KoTextView
29#include <koffice_export.h>
30class KoBgSpellCheck;
31class KoTextObject;
32class KoTextDocument;
33class KoTextParag;
34class KoTextFormat;
35class KoParagCounter;
36class KCommand;
37class TQTimer;
38class TDEAction;
39class TDEInstance;
40class KDataToolInfo;
41class KoLinkVariable;
42class KoVariable;
43class KoTextViewIface;
44#include "KoRichText.h"
45class KoBorder;
46class KoParagStyle;
47
53class KOTEXT_EXPORT KoTextView : public TQObject, public KoTextFormatInterface
54{
55 TQ_OBJECT
56
57public:
62 KoTextView( KoTextObject *textobj );
63 virtual ~KoTextView();
64
65 void setBackSpeller( KoBgSpellCheck* backSpeller );
66
67 virtual KoTextViewIface* dcopObject();
68
71 void terminate( bool removeselection=true );
72
73 KoTextObject * textObject() const { return m_textobj; }
74 KoTextCursor * cursor() const { return m_cursor; }
75 void setCursor( const KoTextCursor& cursor ) { *m_cursor = cursor; };
76 KoTextDocument * textDocument() const;
77
80 bool isReadWrite() const { return m_bReadWrite; }
82 void setReadWrite( bool b ) { m_bReadWrite = b; }
83
84 virtual KoTextFormat * currentFormat() const { return m_currentFormat; }
85 void setCurrentFormat( KoTextFormat *fmt ) { m_currentFormat = fmt; }
86
90 virtual const KoParagLayout * currentParagLayoutFormat() const;
91
92 virtual bool rtl() const;
93
94 virtual KCommand *setChangeCaseOfTextCommand( KoChangeCaseDia::TypeOfCase _type );
95
96 virtual KCommand* setParagLayoutFormatCommand( KoParagLayout *newLayout, int flags, int marginIndex = -1 );
97
99 virtual KCommand* setFormatCommand( const KoTextFormat * newFormat, int flags, bool zoomFont = false );
100
101 // -- Paragraph settings --
102 KCommand * setCounterCommand( const KoParagCounter & counter );
103 KCommand * setAlignCommand( int align );
104 KCommand * setPageBreakingCommand( int pageBreaking );
105 KCommand * setLineSpacingCommand( double spacing, KoParagLayout::SpacingType _type );
106 KCommand * setBordersCommand( const KoBorder& leftBorder, const KoBorder& rightBorder, const KoBorder& bottomBorder, const KoBorder& topBorder );
107 KCommand * setJoinBordersCommand( bool join );
108 KCommand * setMarginCommand( TQStyleSheetItem::Margin m, double margin );
109 KCommand * setTabListCommand( const KoTabulatorList & tabList );
110 KCommand * setBackgroundColorCommand( const TQColor & color );
111 void applyStyle( const KoParagStyle * style );
112
113 void dragStarted();
114 void focusInEvent();
115 void focusOutEvent();
116 void handleKeyPressEvent( TQKeyEvent * e, TQWidget *, const TQPoint& );
117 void handleKeyReleaseEvent( TQKeyEvent * e );
118 void handleImStartEvent( TQIMEvent * e );
119 void handleImComposeEvent( TQIMEvent * e );
120 void handleImEndEvent( TQIMEvent * e );
121 // iPoint is in Layout Unit pixels
122 // return true if we add new parag with "insert direct cursor"
123 bool handleMousePressEvent( TQMouseEvent* e, const TQPoint& iPoint, bool canStartDrag = true, bool insertDirectCursor = false );
124 void handleMouseMoveEvent( TQMouseEvent* e, const TQPoint& iPoint );
125 void handleMouseReleaseEvent();
126 void handleMouseDoubleClickEvent( TQMouseEvent* e, const TQPoint& iPoint );
127 void handleMouseTripleClickEvent( TQMouseEvent* e, const TQPoint& /* Currently unused */ );
128 bool maybeStartDrag( TQMouseEvent* e );
129
130 KoTextCursor selectWordUnderCursor( const KoTextCursor& cursor, int selectionId = KoTextDocument::Standard );
131 KoTextCursor selectParagUnderCursor( const KoTextCursor& cursor, int selectionId = KoTextDocument::Standard, bool copyAndNotify = true );
132 void extendParagraphSelection( const TQPoint& iPoint );
133
134 TQString wordUnderCursor( const KoTextCursor& cursor );
135
137 TQPtrList<TDEAction> dataToolActionList( TDEInstance * instance, const TQString& word, bool & _singleWord );
138
139 void insertSoftHyphen();
140 void insertLineBreak();
141 void insertNonbreakingSpace();
142 void insertNonbreakingHyphen();
143 void increaseNumberingLevel( const KoStyleCollection* styleCollection );
144 void decreaseNumberingLevel( const KoStyleCollection* styleCollection );
145 void insertSpecialChar( TQChar _c, const TQString& font );
146 void changeCaseOfText( KoChangeCaseDia::TypeOfCase _type );
147
148 void addBookmarks( const TQString& );
149
150 //return a pointer to the variable under the cursor, if any
151 KoVariable *variable();
152 //return a pointer to the link variable under the cursor, if any
153 // (special case of variable())
154 KoLinkVariable *linkVariable();
155
159 KCommand *prepareDropMove( KoTextCursor dropCursor );
160
161 void removeComment();
162 void copyTextOfComment();
163
164 // This is in fact "from selection or cursor"
165 KoParagStyle * createStyleFromSelection( const TQString & name );
166 void updateStyleFromSelection( KoParagStyle* style );
167
168 TQString currentWordOrSelection() const;
169
170 virtual void removeToolTipCompletion() {}
171
172 // return true if we "insert direct cursor" and we insert new parag
173 bool placeCursor( const TQPoint &pos /* in internal coordinates */, bool insertDirectCursor=false );
174 void setOverwriteMode( bool overwriteMode );
175
176public slots:
180 virtual void updateUI( bool updateFormat, bool force = false );
181 virtual void ensureCursorVisible() = 0;
182 void showCurrentFormat();
183
184 // This allows KoTextObject to hide/show all the cursors before modifying anything
185 void hideCursor() { drawCursor( false ); }
186 void showCursor() { drawCursor( true ); }
187
189 void insertText( const TQString &text );
190 void newParagraph();
191
192 void copyLink();
193 void removeLink();
194 void completion();
195
196 void setCursor( KoTextCursor * _cursor ) { *m_cursor = *_cursor; }
197
198protected slots:
200 virtual void startDrag() = 0;
201 void slotToolActivated( const KDataToolInfo & info, const TQString & command );
202signals:
203 void copy();
204 void cut();
205 void paste();
206
207protected:
212 virtual void doAutoFormat( KoTextCursor* /*cursor*/, KoTextParag * /*parag*/,
213 int /*index*/, TQChar /*ch*/ ) { }
214
215 virtual bool doCompletion( KoTextCursor* , KoTextParag *, int ) { return false; }
216 virtual bool doToolTipCompletion( KoTextCursor* , KoTextParag *, int, int ) { return false; }
217 virtual void showToolTipBox( KoTextParag *, int , TQWidget *, const TQPoint& ) {}
218
219 virtual void textIncreaseIndent() {}
220 virtual bool textDecreaseIndent() { return true; }
221
222 //return true if we are a doubleSpace
223 virtual bool doIgnoreDoubleSpace(KoTextParag * /*parag*/,
224 int /*index*/,TQChar /*ch*/ ) { return false;}
225
227 virtual void showFormat( KoTextFormat *format ) = 0;
228
233 virtual void drawCursor( bool b );
234
236 virtual bool openLink( KoLinkVariable* linkVariable );
237
240 virtual bool pgUpKeyPressed() = 0;
243 virtual bool pgDownKeyPressed() = 0;
245 virtual void ctrlPgUpKeyPressed() { pgUpKeyPressed(); }
247 virtual void ctrlPgDownKeyPressed() { pgDownKeyPressed(); }
248
249 void deleteWordLeft();
250 void deleteWordRight();
251 bool insertParagraph( const TQPoint &pos );
252
253private slots:
254 void blinkCursor();
255 void tripleClickTimeout();
256 void afterTripleClickTimeout();
257protected:
258 KoTextViewIface *dcop;
259 public: // necessary to be public to allow script action in KoTextViewIface
260 enum CursorAction { // keep in sync with TQTextEdit
261 MoveBackward,
262 MoveForward,
263 MoveWordBackward,
264 MoveWordForward,
265 MoveUp,
266 MoveDown,
267 MoveLineStart,
268 MoveLineEnd,
269 MoveHome,
270 MoveEnd,
271 MovePgUp,
272 MovePgDown,
273 MoveParagUp, // libkotext-specific
274 MoveParagDown, // libkotext-specific
275 MoveViewportUp, // KWord-specific
276 MoveViewportDown // KWord-specific
277 };
278
279 void moveCursor( CursorAction action, bool select );
280 bool moveCursor( CursorAction action );
281
282private:
283 KoTextObject *m_textobj;
284 KoTextCursor *m_cursor;
285
286 // Store the index of the variable on which we last clicked, to position m_cursor
287 int m_variablePosition;
288 bool m_overwriteMode;
289
290 KoTextFormat *m_currentFormat;
291 TQTimer *blinkTimer, *dragStartTimer;
292 class KoTextViewPrivate;
293 KoTextViewPrivate *d;
294 TQPoint dragStartPos;
295 bool m_cursorVisible;
296 bool blinkCursorVisible;
297 bool inDoubleClick;
298 bool mightStartDrag;
299 bool m_bReadWrite;
300 bool possibleTripleClick;
301 bool afterTripleClick;
302
303 bool m_singleWord;
304 TQString m_wordUnderCursor;
305};
306
307#endif
This class represents a border - for anything, like paragraph, or frame.
Definition KoBorder.h:34
This is the structure associated with a paragraph (KoTextParag), to define the bullet or numbering of...
This class holds the paragraph-specific formatting information It's separated from KoTextParag so tha...
SpacingType
Line spacing values Assuming h is the height of the biggest char in the line, and v is the linespacin...
A paragraph style is a combination of a character style and paragraph-layout attributes,...
TODO rename to KoParagStyleCollection - or should char styles be part of it too?
The KoTextFormatInterface is a pure interface that allows access to the "current text format".
virtual KCommand * setFormatCommand(const KoTextFormat *format, int flags, bool zoomFont=false)=0
Interface for setting the modified format.
virtual const KoParagLayout * currentParagLayoutFormat() const =0
Interface for accessing the current parag layout.
virtual KCommand * setParagLayoutFormatCommand(KoParagLayout *newLayout, int flags, int marginIndex=-1)=0
Interface for changing the paragraph layout.
Each character (KoTextStringChar) points to a KoTextFormat that defines the formatting of that charac...
The KoTextObject is the high-level object that contains a KoTextDocument (the list of paragraphs),...
Object that is created to edit a KoTextObject.
Definition KoTextView.h:54
virtual void ctrlPgUpKeyPressed()
Reimplement this to handle CTRL+PageUp.
Definition KoTextView.h:245
void setReadWrite(bool b)
Call setReadWrite(false) to make the text view readonly.
Definition KoTextView.h:82
virtual KoTextFormat * currentFormat() const
Interface for accessing the current format.
Definition KoTextView.h:84
virtual void showFormat(KoTextFormat *format)=0
Show the settings of this format in the GUI.
bool isReadWrite() const
Return true if the view is allowed to modify the text object.
Definition KoTextView.h:80
virtual void ctrlPgDownKeyPressed()
Reimplement this to handle CTRL+PageDown.
Definition KoTextView.h:247
virtual bool pgDownKeyPressed()=0
Reimplement this to handle PageDown.
virtual bool pgUpKeyPressed()=0
Reimplement this to handle PageUp.
virtual void doAutoFormat(KoTextCursor *, KoTextParag *, int, TQChar)
Called when a character (ch) has been inserted into parag, at the given index.
Definition KoTextView.h:212
virtual void startDrag()=0
Start a drag.
A KoVariable is a custom item, i.e.
Definition KoVariable.h:364