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
|
/**********************************************************************
**
** Implementation of TQMultiLineEdit widget class
**
** Created : 961005
**
** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
**
** 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.
**
**********************************************************************/
#include "tqmultilineedit.h"
#ifndef TQT_NO_MULTILINEEDIT
#include "tqpainter.h"
#include "tqscrollbar.h"
#include "tqcursor.h"
#include "tqclipboard.h"
#include "tqpixmap.h"
#include "tqregexp.h"
#include "ntqapplication.h"
#include "tqdragobject.h"
#include "tqpopupmenu.h"
#include "tqtimer.h"
#include "tqdict.h"
#include "../kernel/tqrichtext_p.h"
/*!
\class TQMultiLineEdit tqmultilineedit.h
\obsolete
\brief The TQMultiLineEdit widget is a simple editor for inputting text.
\ingroup advanced
The TQMultiLineEdit was a simple editor widget in former TQt versions. TQt
3.0 includes a new richtext engine which obsoletes TQMultiLineEdit. It is
still included for compatibility reasons. It is now a subclass of
\l TQTextEdit, and provides enough of the old TQMultiLineEdit API to keep old
applications working.
If you implement something new with TQMultiLineEdit, we suggest using
\l TQTextEdit instead and call TQTextEdit::setTextFormat(TQt::PlainText).
Although most of the old TQMultiLineEdit API is still available, there is
a few difference. The old TQMultiLineEdit operated on lines, not on
paragraphs. As lines change all the time during wordwrap, the new
richtext engine uses paragraphs as basic elements in the data structure.
All functions (numLines(), textLine(), etc.) that operated on lines, now
operate on paragraphs. Further, getString() has been removed completely.
It revealed too much of the internal data structure.
Applications which made normal and reasonable use of TQMultiLineEdit
should still work without problems. Some odd usage will require some
porting. In these cases, it may be better to use \l TQTextEdit now.
<img src=qmlined-m.png> <img src=qmlined-w.png>
\sa TQTextEdit
*/
/*!
\fn bool TQMultiLineEdit::autoUpdate() const
\obsolete
*/
/*!
\fn virtual void TQMultiLineEdit::setAutoUpdate( bool )
\obsolete
*/
/*!
\fn int TQMultiLineEdit::totalWidth() const
\obsolete
*/
/*!
\fn int TQMultiLineEdit::totalHeight() const
\obsolete
*/
/*!
\fn int TQMultiLineEdit::maxLines() const
\obsolete
*/
/*!
\fn void TQMultiLineEdit::setMaxLines( int )
\obsolete
*/
/*!
\fn void TQMultiLineEdit::deselect()
\obsolete
*/
class TQMultiLineEditData
{
};
/*!
Constructs a new, empty, TQMultiLineEdit with parent \a parent called
\a name.
*/
TQMultiLineEdit::TQMultiLineEdit( TQWidget *parent , const char *name )
: TQTextEdit( parent, name )
{
d = new TQMultiLineEditData;
setTextFormat( TQt::PlainText );
}
/*! \property TQMultiLineEdit::numLines
\brief the number of paragraphs in the editor
The count includes any empty paragraph at top and bottom, so for an
empty editor this method returns 1.
*/
int TQMultiLineEdit::numLines() const
{
return document()->lastParagraph()->paragId() + 1;
}
/*! \property TQMultiLineEdit::atEnd
\brief whether the cursor is placed at the end of the text
\sa atBeginning
*/
bool TQMultiLineEdit::atEnd() const
{
return textCursor()->paragraph() == document()->lastParagraph() && textCursor()->atParagEnd();
}
/*! \property TQMultiLineEdit::atBeginning
\brief whether the cursor is placed at the beginning of the text
\sa atEnd
*/
bool TQMultiLineEdit::atBeginning() const
{
return textCursor()->paragraph() == document()->firstParagraph() && textCursor()->atParagStart();
}
/*! Returns the number of characters at paragraph number \a row. If
\a row is out of range, -1 is returned.
*/
int TQMultiLineEdit::lineLength( int row ) const
{
if ( row < 0 || row > numLines() )
return -1;
return document()->paragAt( row )->length() - 1;
}
/*! \reimp */
TQMultiLineEdit::~TQMultiLineEdit()
{
delete d;
}
/*!
If there is selected text, sets \a line1, \a col1, \a line2 and \a col2
to the start and end of the selected region and returns TRUE. Returns
FALSE if there is no selected text.
*/
bool TQMultiLineEdit::getMarkedRegion( int *line1, int *col1,
int *line2, int *col2 ) const
{
int p1,c1, p2, c2;
getSelection( &p1, &c1, &p2, &c2 );
if ( p1 == -1 && c1 == -1 && p2 == -1 && c2 == -1 )
return FALSE;
if ( line1 )
*line1 = p1;
if ( col1 )
*col1 = c1;
if ( line2 )
*line2 = p2;
if ( col2 )
*col2 = c2;
return TRUE;
}
/*!
Returns TRUE if there is selected text.
*/
bool TQMultiLineEdit::hasMarkedText() const
{
return hasSelectedText();
}
/*!
Returns a copy of the selected text.
*/
TQString TQMultiLineEdit::markedText() const
{
return selectedText();
}
/*!
Moves the cursor one page down. If \a mark is TRUE, the text
is selected.
*/
void TQMultiLineEdit::pageDown( bool mark )
{
moveCursor( MoveDown, mark );
}
/*!
Moves the cursor one page up. If \a mark is TRUE, the text
is selected.
*/
void TQMultiLineEdit::pageUp( bool mark )
{
moveCursor( MovePgUp, mark );
}
/*! Inserts \a txt at paragraph number \a line. If \a line is less
than zero, or larger than the number of paragraphs, the new text is
put at the end. If \a txt contains newline characters, several
paragraphs are inserted.
The cursor position is not changed.
*/
void TQMultiLineEdit::insertLine( const TQString &txt, int line )
{
insertParagraph( txt, line );
}
/*! Deletes the paragraph at paragraph number \a paragraph. If \a
paragraph is less than zero or larger than the number of paragraphs,
nothing is deleted.
*/
void TQMultiLineEdit::removeLine( int paragraph )
{
removeParagraph( paragraph );
}
/*! Inserts \a str at the current cursor position and selects the
text if \a mark is TRUE.
*/
void TQMultiLineEdit::insertAndMark( const TQString& str, bool mark )
{
insert( str );
if ( mark )
document()->setSelectionEnd( TQTextDocument::Standard, *textCursor() );
}
/*! Splits the paragraph at the current cursor position.
*/
void TQMultiLineEdit::newLine()
{
insert( "\n" );
}
/*! Deletes the character on the left side of the text cursor and
moves the cursor one position to the left. If a text has been selected
by the user (e.g. by clicking and dragging) the cursor is put at the
beginning of the selected text and the selected text is removed. \sa
del()
*/
void TQMultiLineEdit::backspace()
{
if ( document()->hasSelection( TQTextDocument::Standard ) ) {
removeSelectedText();
return;
}
if ( !textCursor()->paragraph()->prev() &&
textCursor()->atParagStart() )
return;
doKeyboardAction( ActionBackspace );
}
/*! Moves the text cursor to the left end of the line. If \a mark is
TRUE, text is selected toward the first position. If it is FALSE and the
cursor is moved, all selected text is unselected.
\sa end()
*/
void TQMultiLineEdit::home( bool mark )
{
moveCursor( MoveLineStart, mark );
}
/*! Moves the text cursor to the right end of the line. If \a mark is
TRUE, text is selected toward the last position. If it is FALSE and the
cursor is moved, all selected text is unselected.
\sa home()
*/
void TQMultiLineEdit::end( bool mark )
{
moveCursor( MoveLineEnd, mark );
}
/*!
\fn void TQMultiLineEdit::setCursorPosition( int line, int col )
\reimp
*/
/*! Sets the cursor position to character number \a col in paragraph
number \a line. The parameters are adjusted to lie within the legal
range.
If \a mark is FALSE, the selection is cleared. otherwise it is extended.
*/
void TQMultiLineEdit::setCursorPosition( int line, int col, bool mark )
{
if ( !mark )
selectAll( FALSE );
TQTextEdit::setCursorPosition( line, col );
if ( mark )
document()->setSelectionEnd( TQTextDocument::Standard, *textCursor() );
}
/*! Returns the top center point where the cursor is drawn.
*/
TQPoint TQMultiLineEdit::cursorPoint() const
{
return TQPoint( textCursor()->x(), textCursor()->y() + textCursor()->paragraph()->rect().y() );
}
/*! \property TQMultiLineEdit::alignment
\brief The editor's paragraph alignment
Sets the alignment to flag, which must be \c AlignLeft, \c
AlignHCenter or \c AlignRight.
If flag is an illegal flag nothing happens.
\sa TQt::AlignmentFlags
*/
void TQMultiLineEdit::setAlignment( int flag )
{
if ( flag == AlignCenter )
flag = AlignHCenter;
if ( flag != AlignLeft && flag != AlignRight && flag != AlignHCenter )
return;
TQTextParagraph *p = document()->firstParagraph();
while ( p ) {
p->setAlignment( flag );
p = p->next();
}
}
int TQMultiLineEdit::alignment() const
{
return document()->firstParagraph()->alignment();
}
void TQMultiLineEdit::setEdited( bool e )
{
setModified( e );
}
/*! \property TQMultiLineEdit::edited
\brief whether the document has been edited by the user
This is the same as TQTextEdit's "modifed" property.
\sa TQTextEdit::modified
*/
bool TQMultiLineEdit::edited() const
{
return isModified();
}
/*! Moves the cursor one word to the right. If \a mark is TRUE, the text
is selected.
\sa cursorWordBackward()
*/
void TQMultiLineEdit::cursorWordForward( bool mark )
{
moveCursor( MoveWordForward, mark );
}
/*! Moves the cursor one word to the left. If \a mark is TRUE, the
text is selected.
\sa cursorWordForward()
*/
void TQMultiLineEdit::cursorWordBackward( bool mark )
{
moveCursor( MoveWordBackward, mark );
}
/*!
\fn TQMultiLineEdit::insertAt( const TQString &s, int line, int col )
\reimp
*/
/*! Inserts string \a s at paragraph number \a line, after character
number \a col in the paragraph. If \a s contains newline
characters, new lines are inserted.
If \a mark is TRUE the inserted string will be selected.
The cursor position is adjusted.
*/
void TQMultiLineEdit::insertAt( const TQString &s, int line, int col, bool mark )
{
TQTextEdit::insertAt( s, line, col );
if ( mark )
setSelection( line, col, line, col + s.length() );
}
// ### reggie - is this documentation correct?
/*! Deletes text from the current cursor position to the end of the
line. (Note that this function still operates on lines, not paragraphs.)
*/
void TQMultiLineEdit::killLine()
{
doKeyboardAction( ActionKill );
}
/*! Moves the cursor one character to the left. If \a mark is TRUE,
the text is selected.
The \a wrap parameter is currently ignored.
\sa cursorRight() cursorUp() cursorDown()
*/
void TQMultiLineEdit::cursorLeft( bool mark, bool )
{
moveCursor( MoveBackward, mark );
}
/*! Moves the cursor one character to the right. If \a mark is TRUE,
the text is selected.
The \a wrap parameter is currently ignored.
\sa cursorLeft() cursorUp() cursorDown()
*/
void TQMultiLineEdit::cursorRight( bool mark, bool )
{
moveCursor( MoveForward, mark );
}
/*! Moves the cursor up one line. If \a mark is TRUE, the text is
selected.
\sa cursorDown() cursorLeft() cursorRight()
*/
void TQMultiLineEdit::cursorUp( bool mark )
{
moveCursor( MoveUp, mark );
}
/*!
Moves the cursor one line down. If \a mark is TRUE, the text
is selected.
\sa cursorUp() cursorLeft() cursorRight()
*/
void TQMultiLineEdit::cursorDown( bool mark )
{
moveCursor( MoveDown, mark );
}
/*! Returns the text at line number \a line (possibly the empty
string), or a \link TQString::operator!() null string\endlink if \a
line is invalid.
*/
TQString TQMultiLineEdit::textLine( int line ) const
{
if ( line < 0 || line >= numLines() )
return TQString::null;
TQString str = document()->paragAt( line )->string()->toString();
str.truncate( str.length() - 1 );
return str;
}
#endif
|