1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
|
/****************************************************************************
**
** Definition of the TQTextEdit class
**
** Created : 990101
**
** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
**
** This file is part of the widgets module of the TQt GUI Toolkit.
**
** This file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free
** Software Foundation and appearing in the files LICENSE.GPL2
** and LICENSE.GPL3 included in the packaging of this file.
** Alternatively you may (at your option) use any later version
** of the GNU General Public License if such license has been
** publicly approved by Trolltech ASA (or its successors, if any)
** and the KDE Free TQt Foundation.
**
** Please review the following information to ensure GNU General
** Public Licensing requirements will be met:
** http://trolltech.com/products/qt/licenses/licensing/opensource/.
** If you are unsure which license is appropriate for your use, please
** review the following information:
** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
** or contact the sales department at sales@trolltech.com.
**
** This file may be used under the terms of the Q Public License as
** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
** included in the packaging of this file. Licensees holding valid TQt
** Commercial licenses may use this file in accordance with the TQt
** Commercial License Agreement provided with the Software.
**
** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
** herein.
**
**********************************************************************/
#ifndef TQTEXTEDIT_H
#define TQTEXTEDIT_H
#ifndef TQT_H
#include "tqscrollview.h"
#include "tqstylesheet.h"
#include "tqptrvector.h"
#include "tqvaluelist.h"
#include "tqptrlist.h"
#include "tqdragobject.h"
#endif // TQT_H
#ifndef TQT_NO_TEXTEDIT
// uncomment below to enable optimization mode - also uncomment the
// optimDoAutoScroll() private slot since tqmoc ignores #ifdefs..
#define TQT_TEXTEDIT_OPTIMIZATION
class TQPainter;
class TQTextDocument;
class TQTextCursor;
class TQKeyEvent;
class TQResizeEvent;
class TQMouseEvent;
class TQTimer;
class TQTextString;
class TQTextCommand;
class TQTextParagraph;
class TQTextFormat;
class TQFont;
class TQColor;
class TQTextEdit;
class TQTextBrowser;
class TQTextString;
struct TQUndoRedoInfoPrivate;
class TQPopupMenu;
class TQTextEditPrivate;
class TQSyntaxHighlighter;
#ifdef TQT_TEXTEDIT_OPTIMIZATION
class TQTextEditOptimPrivate
{
public:
// Note: no left-tag has any value for leftTag or tqparent, and
// no right-tag has any formatting flags set.
enum TagType { Color = 0, Format = 1 };
struct Tag {
TagType type:2;
bool bold:1;
bool italic:1;
bool underline:1;
int line;
int index;
Tag * leftTag; // ptr to left-tag in a left-right tag pair
Tag * tqparent; // ptr to tqparent left-tag in a nested tag
Tag * prev;
Tag * next;
TQString tag;
};
TQTextEditOptimPrivate()
{
len = numLines = maxLineWidth = 0;
selStart.line = selStart.index = -1;
selEnd.line = selEnd.index = -1;
search.line = search.index = 0;
tags = lastTag = 0;
}
void clearTags()
{
Tag * itr = tags;
while ( tags ) {
itr = tags;
tags = tags->next;
delete itr;
}
tags = lastTag = 0;
tagIndex.clear();
}
~TQTextEditOptimPrivate()
{
clearTags();
}
int len;
int numLines;
int maxLineWidth;
struct Selection {
int line;
int index;
};
Selection selStart, selEnd, search;
Tag * tags, * lastTag;
TQMap<int, TQString> lines;
TQMap<int, Tag *> tagIndex;
};
#endif
class TQ_EXPORT TQTextEdit : public TQScrollView
{
friend class TQTextBrowser;
friend class TQSyntaxHighlighter;
Q_OBJECT
TQ_OBJECT
Q_ENUMS( WordWrap WrapPolicy )
Q_ENUMS( AutoFormatting )
Q_PROPERTY( TextFormat textFormat READ textFormat WRITE setTextFormat )
Q_PROPERTY( TQString text READ text WRITE setText )
Q_PROPERTY( TQBrush paper READ paper WRITE setPaper )
Q_PROPERTY( bool linkUnderline READ linkUnderline WRITE setLinkUnderline )
Q_PROPERTY( TQString documentTitle READ documentTitle )
Q_PROPERTY( int length READ length )
Q_PROPERTY( WordWrap wordWrap READ wordWrap WRITE setWordWrap )
Q_PROPERTY( int wrapColumnOrWidth READ wrapColumnOrWidth WRITE setWrapColumnOrWidth )
Q_PROPERTY( WrapPolicy wrapPolicy READ wrapPolicy WRITE setWrapPolicy )
Q_PROPERTY( bool hasSelectedText READ hasSelectedText )
Q_PROPERTY( TQString selectedText READ selectedText )
Q_PROPERTY( int undoDepth READ undoDepth WRITE setUndoDepth )
Q_PROPERTY( bool overwriteMode READ isOverwriteMode WRITE setOverwriteMode )
Q_PROPERTY( bool modified READ isModified WRITE setModified DESIGNABLE false )
Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly )
Q_PROPERTY( bool undoRedoEnabled READ isUndoRedoEnabled WRITE setUndoRedoEnabled )
Q_PROPERTY( int tabStopWidth READ tabStopWidth WRITE setTabStopWidth )
Q_PROPERTY( bool tabChangesFocus READ tabChangesFocus WRITE setTabChangesFocus )
Q_PROPERTY( AutoFormatting autoFormatting READ autoFormattingProp WRITE setAutoFormattingProp )
public:
enum WordWrap {
NoWrap,
WidgetWidth,
FixedPixelWidth,
FixedColumnWidth
};
enum WrapPolicy {
AtWordBoundary,
AtWhiteSpace = AtWordBoundary, // AtWhiteSpace is deprecated
Anywhere,
AtWordOrDocumentBoundary
};
enum AutoFormatting {
AutoNone = 0,
AutoBulletList = 0x00000001,
AutoAll = 0xffffffff
};
enum KeyboardAction {
ActionBackspace,
ActionDelete,
ActionReturn,
ActionKill,
ActionWordBackspace,
ActionWordDelete
};
enum CursorAction {
MoveBackward,
MoveForward,
MoveWordBackward,
MoveWordForward,
MoveUp,
MoveDown,
MoveLineStart,
MoveLineEnd,
MoveHome,
MoveEnd,
MovePgUp,
MovePgDown
};
enum VerticalAlignment {
AlignNormal,
AlignSuperScript,
AlignSubScript
};
enum TextInsertionFlags {
RedoIndentation = 0x0001,
CheckNewLines = 0x0002,
RemoveSelected = 0x0004,
AsIMCompositionText = 0x0008, // internal use
WithIMSelection = 0x0010 // internal use
};
TQTextEdit( const TQString& text, const TQString& context = TQString::null,
TQWidget* tqparent=0, const char* name=0);
TQTextEdit( TQWidget* tqparent=0, const char* name=0 );
virtual ~TQTextEdit();
void setPalette( const TQPalette & );
TQString text() const;
TQString text( int para ) const;
TQt::TextFormat textFormat() const;
TQString context() const;
TQString documentTitle() const;
void getSelection( int *paraFrom, int *indexFrom,
int *paraTo, int *indexTo, int selNum = 0 ) const;
virtual bool tqfind( const TQString &expr, bool cs, bool wo, bool forward = TRUE,
int *para = 0, int *index = 0 );
int paragraphs() const;
int lines() const;
int linesOfParagraph( int para ) const;
int lineOfChar( int para, int chr );
int length() const;
TQRect paragraphRect( int para ) const;
int paragraphAt( const TQPoint &pos ) const;
int charAt( const TQPoint &pos, int *para ) const;
int paragraphLength( int para ) const;
TQStyleSheet* styleSheet() const;
#ifndef TQT_NO_MIME
TQMimeSourceFactory* mimeSourceFactory() const;
#endif
TQBrush paper() const;
bool linkUnderline() const;
int heightForWidth( int w ) const;
bool hasSelectedText() const;
TQString selectedText() const;
bool isUndoAvailable() const;
bool isRedoAvailable() const;
WordWrap wordWrap() const;
int wrapColumnOrWidth() const;
WrapPolicy wrapPolicy() const;
int tabStopWidth() const;
TQString anchorAt( const TQPoint& pos );
TQString anchorAt( const TQPoint& pos, Qt::AnchorAttribute a );
TQSize tqsizeHint() const;
bool isReadOnly() const { return readonly; }
void getCursorPosition( int *parag, int *index ) const;
bool isModified() const;
bool italic() const;
bool bold() const;
bool underline() const;
TQString family() const;
int pointSize() const;
TQColor color() const;
TQFont font() const;
TQFont currentFont() const;
int tqalignment() const;
int undoDepth() const;
// do not use, will go away
virtual bool getFormat( int para, int index, TQFont *font, TQColor *color, VerticalAlignment *verticalAlignment );
// do not use, will go away
virtual bool getParagraphFormat( int para, TQFont *font, TQColor *color,
VerticalAlignment *verticalAlignment, int *tqalignment,
TQStyleSheetItem::DisplayMode *displayMode,
TQStyleSheetItem::ListStyle *listStyle,
int *listDepth );
bool isOverwriteMode() const { return overWrite; }
TQColor paragraphBackgroundColor( int para ) const;
bool isUndoRedoEnabled() const;
bool eventFilter( TQObject *o, TQEvent *e );
bool tabChangesFocus() const;
void setAutoFormatting( uint features );
uint autoFormatting() const;
inline void setAutoFormattingProp( AutoFormatting features ) { setAutoFormatting((uint)features); }
inline AutoFormatting autoFormattingProp() const { return (AutoFormatting)autoFormatting(); }
TQSyntaxHighlighter *syntaxHighlighter() const;
public Q_SLOTS:
void setEnabled( bool );
#ifndef TQT_NO_MIME
virtual void setMimeSourceFactory( TQMimeSourceFactory* factory );
#endif
virtual void setStyleSheet( TQStyleSheet* styleSheet );
virtual void scrollToAnchor( const TQString& name );
virtual void setPaper( const TQBrush& pap );
virtual void setLinkUnderline( bool );
virtual void setWordWrap( WordWrap mode );
virtual void setWrapColumnOrWidth( int );
virtual void setWrapPolicy( WrapPolicy policy );
virtual void copy();
virtual void append( const TQString& text );
void setText( const TQString &txt ) { setText( txt, TQString::null ); }
virtual void setText( const TQString &txt, const TQString &context );
virtual void setTextFormat( TQt::TextFormat f );
virtual void selectAll( bool select = TRUE );
virtual void setTabStopWidth( int ts );
virtual void zoomIn( int range );
virtual void zoomIn() { zoomIn( 1 ); }
virtual void zoomOut( int range );
virtual void zoomOut() { zoomOut( 1 ); }
virtual void zoomTo( int size );
virtual void sync();
virtual void setReadOnly( bool b );
virtual void undo();
virtual void redo();
virtual void cut();
virtual void paste();
#ifndef TQT_NO_CLIPBOARD
virtual void pasteSubType( const TQCString &subtype );
#endif
virtual void clear();
virtual void del();
virtual void indent();
virtual void setItalic( bool b );
virtual void setBold( bool b );
virtual void setUnderline( bool b );
virtual void setFamily( const TQString &f );
virtual void setPointSize( int s );
virtual void setColor( const TQColor &c );
virtual void setFont( const TQFont &f );
virtual void setVerticalAlignment( VerticalAlignment a );
virtual void tqsetAlignment( int a );
// do not use, will go away
virtual void setParagType( TQStyleSheetItem::DisplayMode dm, TQStyleSheetItem::ListStyle listStyle );
virtual void setCursorPosition( int parag, int index );
virtual void setSelection( int parag_from, int index_from, int parag_to, int index_to, int selNum = 0 );
virtual void setSelectionAttributes( int selNum, const TQColor &back, bool invertText );
virtual void setModified( bool m );
virtual void resetFormat();
virtual void setUndoDepth( int d );
virtual void setFormat( TQTextFormat *f, int flags );
virtual void ensureCursorVisible();
virtual void placeCursor( const TQPoint &pos, TQTextCursor *c = 0 );
virtual void moveCursor( CursorAction action, bool select );
virtual void doKeyboardAction( KeyboardAction action );
virtual void removeSelectedText( int selNum = 0 );
virtual void removeSelection( int selNum = 0 );
virtual void setCurrentFont( const TQFont &f );
virtual void setOverwriteMode( bool b ) { overWrite = b; }
virtual void scrollToBottom();
void insert( const TQString &text, uint insertionFlags = CheckNewLines | RemoveSelected ); // ## virtual in 4.0
// obsolete
virtual void insert( const TQString &text, bool, bool = TRUE, bool = TRUE );
virtual void insertAt( const TQString &text, int para, int index );
virtual void removeParagraph( int para );
virtual void insertParagraph( const TQString &text, int para );
virtual void setParagraphBackgroundColor( int para, const TQColor &bg );
virtual void clearParagraphBackground( int para );
virtual void setUndoRedoEnabled( bool b );
void setTabChangesFocus( bool b ); // ### make virtual in 4.0
#ifdef TQT_TEXTEDIT_OPTIMIZATION
void polish();
void setMaxLogLines( int numLines );
int maxLogLines();
#endif
Q_SIGNALS:
void textChanged();
void selectionChanged();
void copyAvailable( bool );
void undoAvailable( bool yes );
void redoAvailable( bool yes );
void currentFontChanged( const TQFont &f );
void currentColorChanged( const TQColor &c );
void currentAlignmentChanged( int a );
void currentVerticalAlignmentChanged( VerticalAlignment a );
void cursorPositionChanged( TQTextCursor *c );
void cursorPositionChanged( int para, int pos );
void returnPressed();
void modificationChanged( bool m );
void clicked( int parag, int index );
void doubleClicked( int parag, int index );
protected:
void repaintChanged();
void updateStyles();
void drawContents( TQPainter *p, int cx, int cy, int cw, int ch );
bool event( TQEvent *e );
void keyPressEvent( TQKeyEvent *e );
void resizeEvent( TQResizeEvent *e );
void viewportResizeEvent( TQResizeEvent* );
void contentsMousePressEvent( TQMouseEvent *e );
void contentsMouseMoveEvent( TQMouseEvent *e );
void contentsMouseReleaseEvent( TQMouseEvent *e );
void contentsMouseDoubleClickEvent( TQMouseEvent *e );
#ifndef TQT_NO_WHEELEVENT
void contentsWheelEvent( TQWheelEvent *e );
#endif
void imStartEvent( TQIMEvent * );
void imComposeEvent( TQIMEvent * );
void imEndEvent( TQIMEvent * );
#ifndef TQT_NO_DRAGANDDROP
void contentsDragEnterEvent( TQDragEnterEvent *e );
void contentsDragMoveEvent( TQDragMoveEvent *e );
void contentsDragLeaveEvent( TQDragLeaveEvent *e );
void contentsDropEvent( TQDropEvent *e );
#endif
void contentsContextMenuEvent( TQContextMenuEvent *e );
bool sendMouseEventToInputContext( TQMouseEvent *e );
bool focusNextPrevChild( bool next );
TQTextDocument *document() const;
TQTextCursor *textCursor() const;
void setDocument( TQTextDocument *doc );
virtual TQPopupMenu *createPopupMenu( const TQPoint& pos );
virtual TQPopupMenu *createPopupMenu();
void drawCursor( bool visible );
void windowActivationChange( bool );
protected Q_SLOTS:
virtual void doChangeInterval();
void sliderReleased(); // ### make virtual in 4.0
#if (TQT_VERSION >= 0x040000)
#error "Some functions need to be changed to virtual for TQt 4.0"
#endif
private Q_SLOTS:
void formatMore();
void doResize();
void autoScrollTimerDone();
void blinkCursor();
void setModified();
void startDrag();
void documentWidthChanged( int w );
void clipboardChanged();
private:
struct TQ_EXPORT UndoRedoInfo {
enum Type { Invalid, Insert, Delete, Backspace, Return, RemoveSelected, Format, Style, IME };
UndoRedoInfo( TQTextDocument *dc );
~UndoRedoInfo();
void clear();
bool valid() const;
TQUndoRedoInfoPrivate *d;
int id;
int index;
int eid;
int eindex;
TQTextFormat *format;
int flags;
Type type;
TQTextDocument *doc;
TQByteArray styleInformation;
};
private:
void updateCursor( const TQPoint & pos );
void handleMouseMove( const TQPoint& pos );
void drawContents( TQPainter * );
virtual bool linksEnabled() const { return FALSE; }
void init();
void checkUndoRedoInfo( UndoRedoInfo::Type t );
void updateCurrentFormat();
bool handleReadOnlyKeyEvent( TQKeyEvent *e );
void makeParagVisible( TQTextParagraph *p );
void normalCopy();
void copyToClipboard();
#ifndef TQT_NO_MIME
TQCString pickSpecial(TQMimeSource* ms, bool always_ask, const TQPoint&);
TQTextDrag *dragObject( TQWidget *tqparent = 0 ) const;
#endif
#ifndef TQT_NO_MIMECLIPBOARD
void pasteSpecial(const TQPoint&);
#endif
void setFontInternal( const TQFont &f );
virtual void emitHighlighted( const TQString & ) {}
virtual void emitLinkClicked( const TQString & ) {}
void readFormats( TQTextCursor &c1, TQTextCursor &c2, TQTextString &text, bool fillStyles = FALSE );
void clearUndoRedo();
void paintDocument( bool drawAll, TQPainter *p, int cx = -1, int cy = -1, int cw = -1, int ch = -1 );
void moveCursor( CursorAction action );
void ensureFormatted( TQTextParagraph *p );
void placeCursor( const TQPoint &pos, TQTextCursor *c, bool link );
void updateMicroFocusHint();
#ifdef TQT_TEXTEDIT_OPTIMIZATION
bool checkOptimMode();
TQString optimText() const;
void optimSetText( const TQString &str );
void optimAppend( const TQString &str );
void optimInsert( const TQString &str, int line, int index );
void optimDrawContents( TQPainter * p, int cx, int cy, int cw, int ch );
void optimMousePressEvent( TQMouseEvent * e );
void optimMouseReleaseEvent( TQMouseEvent * e );
void optimMouseMoveEvent( TQMouseEvent * e );
int optimCharIndex( const TQString &str, int mx ) const;
void optimSelectAll();
void optimRemoveSelection();
void optimSetSelection( int startLine, int startIdx, int endLine,
int endIdx );
bool optimHasSelection() const;
TQString optimSelectedText() const;
bool optimFind( const TQString & str, bool, bool, bool, int *, int * );
void optimParseTags( TQString * str, int lineNo = -1, int indexOffset = 0 );
TQTextEditOptimPrivate::Tag * optimPreviousLeftTag( int line );
void optimSetTextFormat( TQTextDocument *, TQTextCursor *, TQTextFormat * f,
int, int, TQTextEditOptimPrivate::Tag * t );
TQTextEditOptimPrivate::Tag * optimAppendTag( int index, const TQString & tag );
TQTextEditOptimPrivate::Tag * optimInsertTag( int line, int index, const TQString & tag );
void optimCheckLimit( const TQString& str );
bool optimHasBoldMetrics( int line );
private Q_SLOTS:
void optimDoAutoScroll();
#endif // TQT_TEXTEDIT_OPTIMIZATION
private:
#ifndef TQT_NO_CLIPBOARD
void pasteSubType( const TQCString &subtype, TQMimeSource *m );
#endif
private:
TQTextDocument *doc;
TQTextCursor *cursor;
TQTimer *formatTimer, *scrollTimer, *changeIntervalTimer, *blinkTimer, *dragStartTimer;
TQTextParagraph *lastFormatted;
int interval;
UndoRedoInfo undoRedoInfo;
TQTextFormat *currentFormat;
int currentAlignment;
TQPoint oldMousePos, mousePos;
TQPoint dragStartPos;
TQString onLink;
WordWrap wrapMode;
WrapPolicy wPolicy;
int wrapWidth;
TQString pressedLink;
TQTextEditPrivate *d;
bool inDoubleClick : 1;
bool mousePressed : 1;
bool cursorVisible : 1;
bool blinkCursorVisible : 1;
bool readOnly : 1;
bool modified : 1;
bool mightStartDrag : 1;
bool inDnD : 1;
bool readonly : 1;
bool undoEnabled : 1;
bool overWrite : 1;
private: // Disabled copy constructor and operator=
#if defined(TQ_DISABLE_COPY)
TQTextEdit( const TQTextEdit & );
TQTextEdit &operator=( const TQTextEdit & );
#endif
};
inline TQTextDocument *TQTextEdit::document() const
{
return doc;
}
inline TQTextCursor *TQTextEdit::textCursor() const
{
return cursor;
}
inline void TQTextEdit::setCurrentFont( const TQFont &f )
{
TQTextEdit::setFontInternal( f );
}
#endif //TQT_NO_TEXTEDIT
#endif //TQTEXTVIEW_H
|