home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / qt3_emx.zip / include / qtextedit.h < prev    next >
C/C++ Source or Header  |  2001-10-11  |  14KB  |  445 lines

  1. /****************************************************************************
  2. ** $Id:  qt/qtextedit.h   3.0.0   edited Sep 21 17:17 $
  3. **
  4. ** Definition of the QTextEdit class
  5. **
  6. ** Created : 990101
  7. **
  8. ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
  9. **
  10. ** This file is part of the widgets module of the Qt GUI Toolkit.
  11. **
  12. ** This file may be distributed under the terms of the Q Public License
  13. ** as defined by Trolltech AS of Norway and appearing in the file
  14. ** LICENSE.QPL included in the packaging of this file.
  15. **
  16. ** This file may be distributed and/or modified under the terms of the
  17. ** GNU General Public License version 2 as published by the Free Software
  18. ** Foundation and appearing in the file LICENSE.GPL included in the
  19. ** packaging of this file.
  20. **
  21. ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
  22. ** licenses may use this file in accordance with the Qt Commercial License
  23. ** Agreement provided with the Software.
  24. **
  25. ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  26. ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  27. **
  28. ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
  29. **   information about Qt Commercial License Agreements.
  30. ** See http://www.trolltech.com/qpl/ for QPL licensing information.
  31. ** See http://www.trolltech.com/gpl/ for GPL licensing information.
  32. **
  33. ** Contact info@trolltech.com if any conditions of this licensing are
  34. ** not clear to you.
  35. **
  36. **********************************************************************/
  37.  
  38. #ifndef QTEXTEDIT_H
  39. #define QTEXTEDIT_H
  40.  
  41. #ifndef QT_H
  42. #include "qscrollview.h"
  43. #include "qstylesheet.h"
  44. #include "qptrvector.h"
  45. #include "qvaluelist.h"
  46. #endif // QT_H
  47.  
  48. #ifndef QT_NO_TEXTEDIT
  49. class QPainter;
  50. class QTextDocument;
  51. class QTextCursor;
  52. class QKeyEvent;
  53. class QResizeEvent;
  54. class QMouseEvent;
  55. class QTimer;
  56. class QTextString;
  57. class QTextCommand;
  58. class QTextParag;
  59. class QTextFormat;
  60. class QFont;
  61. class QColor;
  62. class QTextEdit;
  63. class QTextBrowser;
  64. class QTextString;
  65. struct QUndoRedoInfoPrivate;
  66. class QPopupMenu;
  67. class QTextEditPrivate;
  68.  
  69. class Q_EXPORT QTextEdit : public QScrollView
  70. {
  71.     friend class QTextBrowser;
  72.  
  73.     Q_OBJECT
  74.     Q_ENUMS( WordWrap WrapPolicy )
  75.     Q_PROPERTY( TextFormat textFormat READ textFormat WRITE setTextFormat )
  76.     Q_PROPERTY( QString text READ text WRITE setText )
  77.     Q_PROPERTY( QBrush paper READ paper WRITE setPaper )
  78.     Q_PROPERTY( bool linkUnderline READ linkUnderline WRITE setLinkUnderline )
  79.     Q_PROPERTY( QString documentTitle READ documentTitle )
  80.     Q_PROPERTY( int length READ length )
  81.     Q_PROPERTY( WordWrap wordWrap READ wordWrap WRITE setWordWrap )
  82.     Q_PROPERTY( int wrapColumnOrWidth READ wrapColumnOrWidth WRITE setWrapColumnOrWidth )
  83.     Q_PROPERTY( WrapPolicy wrapPolicy READ wrapPolicy WRITE setWrapPolicy )
  84.     Q_PROPERTY( bool hasSelectedText READ hasSelectedText )
  85.     Q_PROPERTY( QString selectedText READ selectedText )
  86.     Q_PROPERTY( int undoDepth READ undoDepth WRITE setUndoDepth )
  87.     Q_PROPERTY( bool overwriteMode READ isOverwriteMode WRITE setOverwriteMode )
  88.     Q_PROPERTY( bool modified READ isModified WRITE setModified DESIGNABLE false )
  89.     Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly )
  90.     Q_PROPERTY( bool undoRedoEnabled READ isUndoRedoEnabled WRITE setUndoRedoEnabled )
  91.  
  92. public:
  93.     enum WordWrap {
  94.     NoWrap,
  95.     WidgetWidth,
  96.     FixedPixelWidth,
  97.     FixedColumnWidth
  98.     };
  99.  
  100.     enum WrapPolicy {
  101.     AtWordBoundary,
  102.     Anywhere,
  103.     AtWhiteSpace = AtWordBoundary // deprecated, don't use
  104.     };
  105.  
  106.     enum KeyboardAction {
  107.     ActionBackspace,
  108.     ActionDelete,
  109.     ActionReturn,
  110.     ActionKill
  111.     };
  112.  
  113.     enum CursorAction {
  114.     MoveBackward,
  115.     MoveForward,
  116.     MoveWordBackward,
  117.     MoveWordForward,
  118.     MoveUp,
  119.     MoveDown,
  120.     MoveLineStart,
  121.     MoveLineEnd,
  122.     MoveHome,
  123.     MoveEnd,
  124.     MovePgUp,
  125.     MovePgDown
  126.     };
  127.  
  128.     enum VerticalAlignment {
  129.     AlignNormal,
  130.     AlignSuperScript,
  131.     AlignSubScript
  132.     };
  133.  
  134.     QTextEdit( const QString& text, const QString& context = QString::null,
  135.            QWidget* parent=0, const char* name=0);
  136.     QTextEdit( QWidget* parent=0, const char* name=0 );
  137.     virtual ~QTextEdit();
  138.     void setPalette( const QPalette & );
  139.  
  140.     QString text() const;
  141.     QString text( int para ) const;
  142.     TextFormat textFormat() const;
  143.     QString context() const;
  144.     QString documentTitle() const;
  145.  
  146.     void getSelection( int *paraFrom, int *indexFrom,
  147.             int *paraTo, int *indexTo, int selNum = 0 ) const;
  148.     virtual bool find( const QString &expr, bool cs, bool wo, bool forward = TRUE,
  149.                int *para = 0, int *index = 0 );
  150.  
  151.     int paragraphs() const;
  152.     int lines() const;
  153.     int linesOfParagraph( int para ) const;
  154.     int lineOfChar( int para, int chr );
  155.     int length() const;
  156.     QRect paragraphRect( int para ) const;
  157.     int paragraphAt( const QPoint &pos ) const;
  158.     int charAt( const QPoint &pos, int *para ) const;
  159.     int paragraphLength( int para ) const;
  160.  
  161.     QStyleSheet* styleSheet() const;
  162.     QMimeSourceFactory* mimeSourceFactory() const;
  163.  
  164.     QBrush paper() const;
  165.     bool linkUnderline() const;
  166.  
  167.     int heightForWidth( int w ) const;
  168.  
  169.     bool hasSelectedText() const;
  170.     QString selectedText() const;
  171.     bool isUndoAvailable() const;
  172.     bool isRedoAvailable() const;
  173.  
  174.     WordWrap wordWrap() const;
  175.     int wrapColumnOrWidth() const;
  176.     WrapPolicy wrapPolicy() const;
  177.  
  178.     int tabStopWidth() const;
  179.  
  180.     QString anchorAt( const QPoint& pos );
  181.  
  182.     QSize sizeHint() const;
  183.  
  184.     bool isReadOnly() const { return readonly; }
  185.  
  186.     void getCursorPosition( int *parag, int *index ) const;
  187.  
  188.     bool isModified() const;
  189.     bool italic() const;
  190.     bool bold() const;
  191.     bool underline() const;
  192.     QString family() const;
  193.     int pointSize() const;
  194.     QColor color() const;
  195.     QFont font() const;
  196.     int alignment() const;
  197.     int undoDepth() const;
  198.     virtual bool getFormat( int para, int index, QFont *font, QColor *color, VerticalAlignment *verticalAlignment );
  199.     virtual bool getParagraphFormat( int para, QFont *font, QColor *color,
  200.                      VerticalAlignment *verticalAlignment, int *alignment,
  201.                      QStyleSheetItem::DisplayMode *displayMode,
  202.                      QStyleSheetItem::ListStyle *listStyle,
  203.                      int *listDepth );
  204.     bool isOverwriteMode() const { return overWrite; }
  205.     QColor paragraphBackgroundColor( int para ) const;
  206.  
  207.     bool isUndoRedoEnabled() const;
  208.     bool eventFilter( QObject *o, QEvent *e );
  209.  
  210. public slots:
  211.     void setEnabled( bool );
  212.     virtual void setMimeSourceFactory( QMimeSourceFactory* factory );
  213.     virtual void setStyleSheet( QStyleSheet* styleSheet );
  214.     virtual void scrollToAnchor( const QString& name );
  215.     virtual void setPaper( const QBrush& pap );
  216.     virtual void setLinkUnderline( bool );
  217.  
  218.     virtual void setWordWrap( WordWrap mode );
  219.     virtual void setWrapColumnOrWidth( int );
  220.     virtual void setWrapPolicy( WrapPolicy policy );
  221.  
  222.     virtual void copy();
  223.     virtual void append( const QString& text );
  224.  
  225.     void setText( const QString &txt ) { setText( txt, QString::null ); }
  226.     virtual void setText( const QString &txt, const QString &context );
  227.     virtual void setTextFormat( TextFormat f );
  228.  
  229.     virtual void selectAll( bool select = TRUE );
  230.     virtual void setTabStopWidth( int ts );
  231.     virtual void zoomIn( int range );
  232.     virtual void zoomIn() { zoomIn( 1 ); }
  233.     virtual void zoomOut( int range );
  234.     virtual void zoomOut() { zoomOut( 1 ); }
  235.     virtual void zoomTo( int size );
  236.  
  237.     virtual void sync();
  238.     virtual void setReadOnly( bool b );
  239.  
  240.     virtual void undo();
  241.     virtual void redo();
  242.     virtual void cut();
  243.     virtual void paste();
  244. #ifndef QT_NO_CLIPBOARD
  245.     virtual void pasteSubType( const QCString &subtype );
  246. #endif
  247.     virtual void clear();
  248.     virtual void del();
  249.     virtual void indent();
  250.     virtual void setItalic( bool b );
  251.     virtual void setBold( bool b );
  252.     virtual void setUnderline( bool b );
  253.     virtual void setFamily( const QString &f );
  254.     virtual void setPointSize( int s );
  255.     virtual void setColor( const QColor &c );
  256.     virtual void setFont( const QFont &f );
  257.     virtual void setVerticalAlignment( VerticalAlignment a );
  258.     virtual void setAlignment( int a );
  259.     virtual void setParagType( QStyleSheetItem::DisplayMode dm, QStyleSheetItem::ListStyle listStyle );
  260.     virtual void setCursorPosition( int parag, int index );
  261.     virtual void setSelection( int parag_from, int index_from, int parag_to, int index_to, int selNum = 0 );
  262.     virtual void setSelectionAttributes( int selNum, const QColor &back, bool invertText );
  263.     virtual void setModified( bool m );
  264.     virtual void resetFormat();
  265.     virtual void setUndoDepth( int d );
  266.     virtual void setFormat( QTextFormat *f, int flags );
  267.     virtual void ensureCursorVisible();
  268.     virtual void placeCursor( const QPoint &pos, QTextCursor *c = 0 );
  269.     virtual void moveCursor( CursorAction action, bool select );
  270.     virtual void doKeyboardAction( KeyboardAction action );
  271.     virtual void removeSelectedText( int selNum = 0 );
  272.     virtual void removeSelection( int selNum = 0 );
  273.     virtual void setCurrentFont( const QFont &f );
  274.     virtual void setOverwriteMode( bool b ) { overWrite = b; }
  275.  
  276.     virtual void scrollToBottom();
  277.  
  278.     virtual void insert( const QString &text, bool indent = FALSE, bool checkNewLine = TRUE, bool removeSelected = TRUE );
  279.     virtual void insertAt( const QString &text, int para, int index );
  280.     virtual void removeParagraph( int para );
  281.     virtual void insertParagraph( const QString &text, int para );
  282.  
  283.     virtual void setParagraphBackgroundColor( int para, const QColor &bg );
  284.     virtual void clearParagraphBackground( int para );
  285.  
  286.     virtual void setUndoRedoEnabled( bool b );
  287.  
  288. signals:
  289.     void textChanged();
  290.     void selectionChanged();
  291.     void copyAvailable( bool );
  292.     void undoAvailable( bool yes );
  293.     void redoAvailable( bool yes );
  294.     void currentFontChanged( const QFont &f );
  295.     void currentColorChanged( const QColor &c );
  296.     void currentAlignmentChanged( int a );
  297.     void currentVerticalAlignmentChanged( VerticalAlignment a );
  298.     void cursorPositionChanged( QTextCursor *c );
  299.     void cursorPositionChanged( int para, int pos );
  300.     void returnPressed();
  301.     void modificationChanged( bool m );
  302.  
  303. protected:
  304.     void repaintChanged();
  305.     void updateStyles();
  306.     void drawContents( QPainter *p, int cx, int cy, int cw, int ch );
  307.     bool event( QEvent *e );
  308.     void keyPressEvent( QKeyEvent *e );
  309.     void resizeEvent( QResizeEvent *e );
  310.     void viewportResizeEvent( QResizeEvent* );
  311.     void contentsMousePressEvent( QMouseEvent *e );
  312.     void contentsMouseMoveEvent( QMouseEvent *e );
  313.     void contentsMouseReleaseEvent( QMouseEvent *e );
  314.     void contentsMouseDoubleClickEvent( QMouseEvent *e );
  315.     void contentsWheelEvent( QWheelEvent *e );
  316.     void imStartEvent( QIMEvent * );
  317.     void imComposeEvent( QIMEvent * );
  318.     void imEndEvent( QIMEvent * );
  319. #ifndef QT_NO_DRAGANDDROP
  320.     void contentsDragEnterEvent( QDragEnterEvent *e );
  321.     void contentsDragMoveEvent( QDragMoveEvent *e );
  322.     void contentsDragLeaveEvent( QDragLeaveEvent *e );
  323.     void contentsDropEvent( QDropEvent *e );
  324. #endif
  325.     void contentsContextMenuEvent( QContextMenuEvent *e );
  326.     bool focusNextPrevChild( bool next );
  327.     QTextDocument *document() const;
  328.     QTextCursor *textCursor() const;
  329.     void setDocument( QTextDocument *doc );
  330.     virtual QPopupMenu *createPopupMenu( const QPoint& pos );
  331.     virtual QPopupMenu *createPopupMenu();
  332.     void drawCursor( bool visible );
  333.  
  334.     void windowActivationChange( bool );
  335.  
  336. protected slots:
  337.     virtual void doChangeInterval();
  338.  
  339. private slots:
  340.     void formatMore();
  341.     void doResize();
  342.     void doAutoScroll();
  343.     void blinkCursor();
  344.     void setModified();
  345.     void startDrag();
  346.     void documentWidthChanged( int w );
  347.  
  348. private:
  349.     struct Q_EXPORT UndoRedoInfo {
  350.     enum Type { Invalid, Insert, Delete, Backspace, Return, RemoveSelected, Format, Alignment, ParagType };
  351.  
  352.     UndoRedoInfo( QTextDocument *dc );
  353.     ~UndoRedoInfo();
  354.     void clear();
  355.     bool valid() const;
  356.  
  357.     QUndoRedoInfoPrivate *d;
  358.     int id;
  359.     int index;
  360.     int eid;
  361.     int eindex;
  362.     QTextFormat *format;
  363.     int flags;
  364.     Type type;
  365.     QTextDocument *doc;
  366.     QMemArray<int> oldAligns;
  367.     int newAlign;
  368.     bool list;
  369.     QStyleSheetItem::ListStyle listStyle;
  370.     QValueList< QPtrVector<QStyleSheetItem> > oldStyles;
  371.     QValueList<QStyleSheetItem::ListStyle> oldListStyles;
  372.     };
  373.  
  374. private:
  375.     void drawContents( QPainter * );
  376.     virtual bool linksEnabled() const { return FALSE; }
  377.     void init();
  378.     void checkUndoRedoInfo( UndoRedoInfo::Type t );
  379.     void updateCurrentFormat();
  380.     bool handleReadOnlyKeyEvent( QKeyEvent *e );
  381.     void makeParagVisible( QTextParag *p );
  382. #ifndef QT_NO_MIME
  383.     QCString pickSpecial(QMimeSource* ms, bool always_ask, const QPoint&);
  384. #endif
  385. #ifndef QT_NO_MIMECLIPBOARD
  386.     void pasteSpecial(const QPoint&);
  387. #endif
  388.     void setFontInternal( const QFont &f );
  389.  
  390.     virtual void emitHighlighted( const QString & ) {}
  391.     virtual void emitLinkClicked( const QString & ) {}
  392.  
  393.     void readFormats( QTextCursor &c1, QTextCursor &c2, int oldLen, QTextString &text, bool fillStyles = FALSE );
  394.     void clearUndoRedo();
  395.     void paintDocument( bool drawAll, QPainter *p, int cx = -1, int cy = -1, int cw = -1, int ch = -1 );
  396.     void moveCursor( CursorAction action );
  397.  
  398. private:
  399.     QTextDocument *doc;
  400.     QTextCursor *cursor;
  401.     QTimer *formatTimer, *scrollTimer, *changeIntervalTimer, *blinkTimer, *dragStartTimer;
  402.     QTextParag *lastFormatted;
  403.     int interval;
  404.     UndoRedoInfo undoRedoInfo;
  405.     QTextFormat *currentFormat;
  406.     int currentAlignment;
  407.     QPoint oldMousePos, mousePos;
  408.     QPoint dragStartPos;
  409.     QString onLink;
  410.     WordWrap wrapMode;
  411.     WrapPolicy wPolicy;
  412.     int wrapWidth;
  413.     QString pressedLink;
  414.     QTextEditPrivate *d;
  415.     bool inDoubleClick : 1;
  416.     bool mousePressed : 1;
  417.     bool cursorVisible : 1;
  418.     bool blinkCursorVisible : 1;
  419.     bool readOnly : 1;
  420.     bool modified : 1;
  421.     bool mightStartDrag : 1;
  422.     bool inDnD : 1;
  423.     bool readonly : 1;
  424.     bool undoEnabled : 1;
  425.     bool overWrite : 1;
  426. };
  427.  
  428. inline QTextDocument *QTextEdit::document() const
  429. {
  430.     return doc;
  431. }
  432.  
  433. inline QTextCursor *QTextEdit::textCursor() const
  434. {
  435.     return cursor;
  436. }
  437.  
  438. inline void QTextEdit::setCurrentFont( const QFont &f )
  439. {
  440.     QTextEdit::setFontInternal( f );
  441. }
  442.  
  443. #endif //QT_NO_TEXTEDIT
  444. #endif //QTEXTVIEW_H
  445.