home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 3.iso / dist / fw_qt3.idb / usr / freeware / Qt / include / qtextedit.h.z / qtextedit.h
Encoding:
C/C++ Source or Header  |  2002-04-08  |  14.3 KB  |  452 lines

  1. /****************************************************************************
  2. ** $Id:  qt/qtextedit.h   3.0.3   edited Mar 12 10:09 $
  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.     Q_PROPERTY( int tabStopWidth READ tabStopWidth WRITE setTabStopWidth )
  92.  
  93. public:
  94.     enum WordWrap {
  95.     NoWrap,
  96.     WidgetWidth,
  97.     FixedPixelWidth,
  98.     FixedColumnWidth
  99.     };
  100.  
  101.     enum WrapPolicy {
  102.     AtWordBoundary,
  103.     Anywhere,
  104.     AtWhiteSpace = AtWordBoundary // deprecated, don't use
  105.     };
  106.  
  107.     enum KeyboardAction {
  108.     ActionBackspace,
  109.     ActionDelete,
  110.     ActionReturn,
  111.     ActionKill
  112.     };
  113.  
  114.     enum CursorAction {
  115.     MoveBackward,
  116.     MoveForward,
  117.     MoveWordBackward,
  118.     MoveWordForward,
  119.     MoveUp,
  120.     MoveDown,
  121.     MoveLineStart,
  122.     MoveLineEnd,
  123.     MoveHome,
  124.     MoveEnd,
  125.     MovePgUp,
  126.     MovePgDown
  127.     };
  128.  
  129.     enum VerticalAlignment {
  130.     AlignNormal,
  131.     AlignSuperScript,
  132.     AlignSubScript
  133.     };
  134.  
  135.     QTextEdit( const QString& text, const QString& context = QString::null,
  136.            QWidget* parent=0, const char* name=0);
  137.     QTextEdit( QWidget* parent=0, const char* name=0 );
  138.     virtual ~QTextEdit();
  139.     void setPalette( const QPalette & );
  140.  
  141.     QString text() const;
  142.     QString text( int para ) const;
  143.     TextFormat textFormat() const;
  144.     QString context() const;
  145.     QString documentTitle() const;
  146.  
  147.     void getSelection( int *paraFrom, int *indexFrom,
  148.             int *paraTo, int *indexTo, int selNum = 0 ) const;
  149.     virtual bool find( const QString &expr, bool cs, bool wo, bool forward = TRUE,
  150.                int *para = 0, int *index = 0 );
  151.  
  152.     int paragraphs() const;
  153.     int lines() const;
  154.     int linesOfParagraph( int para ) const;
  155.     int lineOfChar( int para, int chr );
  156.     int length() const;
  157.     QRect paragraphRect( int para ) const;
  158.     int paragraphAt( const QPoint &pos ) const;
  159.     int charAt( const QPoint &pos, int *para ) const;
  160.     int paragraphLength( int para ) const;
  161.  
  162.     QStyleSheet* styleSheet() const;
  163.     QMimeSourceFactory* mimeSourceFactory() const;
  164.  
  165.     QBrush paper() const;
  166.     bool linkUnderline() const;
  167.  
  168.     int heightForWidth( int w ) const;
  169.  
  170.     bool hasSelectedText() const;
  171.     QString selectedText() const;
  172.     bool isUndoAvailable() const;
  173.     bool isRedoAvailable() const;
  174.  
  175.     WordWrap wordWrap() const;
  176.     int wrapColumnOrWidth() const;
  177.     WrapPolicy wrapPolicy() const;
  178.  
  179.     int tabStopWidth() const;
  180.  
  181.     QString anchorAt( const QPoint& pos );
  182.  
  183.     QSize sizeHint() const;
  184.  
  185.     bool isReadOnly() const { return readonly; }
  186.  
  187.     void getCursorPosition( int *parag, int *index ) const;
  188.  
  189.     bool isModified() const;
  190.     bool italic() const;
  191.     bool bold() const;
  192.     bool underline() const;
  193.     QString family() const;
  194.     int pointSize() const;
  195.     QColor color() const;
  196.     QFont font() const;
  197.     int alignment() const;
  198.     int undoDepth() const;
  199.     virtual bool getFormat( int para, int index, QFont *font, QColor *color, VerticalAlignment *verticalAlignment );
  200.     virtual bool getParagraphFormat( int para, QFont *font, QColor *color,
  201.                      VerticalAlignment *verticalAlignment, int *alignment,
  202.                      QStyleSheetItem::DisplayMode *displayMode,
  203.                      QStyleSheetItem::ListStyle *listStyle,
  204.                      int *listDepth );
  205.     bool isOverwriteMode() const { return overWrite; }
  206.     QColor paragraphBackgroundColor( int para ) const;
  207.  
  208.     bool isUndoRedoEnabled() const;
  209.     bool eventFilter( QObject *o, QEvent *e );
  210.  
  211. public slots:
  212.     void setEnabled( bool );
  213.     virtual void setMimeSourceFactory( QMimeSourceFactory* factory );
  214.     virtual void setStyleSheet( QStyleSheet* styleSheet );
  215.     virtual void scrollToAnchor( const QString& name );
  216.     virtual void setPaper( const QBrush& pap );
  217.     virtual void setLinkUnderline( bool );
  218.  
  219.     virtual void setWordWrap( WordWrap mode );
  220.     virtual void setWrapColumnOrWidth( int );
  221.     virtual void setWrapPolicy( WrapPolicy policy );
  222.  
  223.     virtual void copy();
  224.     virtual void append( const QString& text );
  225.  
  226.     void setText( const QString &txt ) { setText( txt, QString::null ); }
  227.     virtual void setText( const QString &txt, const QString &context );
  228.     virtual void setTextFormat( TextFormat f );
  229.  
  230.     virtual void selectAll( bool select = TRUE );
  231.     virtual void setTabStopWidth( int ts );
  232.     virtual void zoomIn( int range );
  233.     virtual void zoomIn() { zoomIn( 1 ); }
  234.     virtual void zoomOut( int range );
  235.     virtual void zoomOut() { zoomOut( 1 ); }
  236.     virtual void zoomTo( int size );
  237.  
  238.     virtual void sync();
  239.     virtual void setReadOnly( bool b );
  240.  
  241.     virtual void undo();
  242.     virtual void redo();
  243.     virtual void cut();
  244.     virtual void paste();
  245. #ifndef QT_NO_CLIPBOARD
  246.     virtual void pasteSubType( const QCString &subtype );
  247. #endif
  248.     virtual void clear();
  249.     virtual void del();
  250.     virtual void indent();
  251.     virtual void setItalic( bool b );
  252.     virtual void setBold( bool b );
  253.     virtual void setUnderline( bool b );
  254.     virtual void setFamily( const QString &f );
  255.     virtual void setPointSize( int s );
  256.     virtual void setColor( const QColor &c );
  257.     virtual void setFont( const QFont &f );
  258.     virtual void setVerticalAlignment( VerticalAlignment a );
  259.     virtual void setAlignment( int a );
  260.     virtual void setParagType( QStyleSheetItem::DisplayMode dm, QStyleSheetItem::ListStyle listStyle );
  261.     virtual void setCursorPosition( int parag, int index );
  262.     virtual void setSelection( int parag_from, int index_from, int parag_to, int index_to, int selNum = 0 );
  263.     virtual void setSelectionAttributes( int selNum, const QColor &back, bool invertText );
  264.     virtual void setModified( bool m );
  265.     virtual void resetFormat();
  266.     virtual void setUndoDepth( int d );
  267.     virtual void setFormat( QTextFormat *f, int flags );
  268.     virtual void ensureCursorVisible();
  269.     virtual void placeCursor( const QPoint &pos, QTextCursor *c = 0 );
  270.     virtual void moveCursor( CursorAction action, bool select );
  271.     virtual void doKeyboardAction( KeyboardAction action );
  272.     virtual void removeSelectedText( int selNum = 0 );
  273.     virtual void removeSelection( int selNum = 0 );
  274.     virtual void setCurrentFont( const QFont &f );
  275.     virtual void setOverwriteMode( bool b ) { overWrite = b; }
  276.  
  277.     virtual void scrollToBottom();
  278.  
  279.     virtual void insert( const QString &text, bool indent = FALSE, bool checkNewLine = TRUE, bool removeSelected = TRUE );
  280.     virtual void insertAt( const QString &text, int para, int index );
  281.     virtual void removeParagraph( int para );
  282.     virtual void insertParagraph( const QString &text, int para );
  283.  
  284.     virtual void setParagraphBackgroundColor( int para, const QColor &bg );
  285.     virtual void clearParagraphBackground( int para );
  286.  
  287.     virtual void setUndoRedoEnabled( bool b );
  288.  
  289. signals:
  290.     void textChanged();
  291.     void selectionChanged();
  292.     void copyAvailable( bool );
  293.     void undoAvailable( bool yes );
  294.     void redoAvailable( bool yes );
  295.     void currentFontChanged( const QFont &f );
  296.     void currentColorChanged( const QColor &c );
  297.     void currentAlignmentChanged( int a );
  298.     void currentVerticalAlignmentChanged( VerticalAlignment a );
  299.     void cursorPositionChanged( QTextCursor *c );
  300.     void cursorPositionChanged( int para, int pos );
  301.     void returnPressed();
  302.     void modificationChanged( bool m );
  303.  
  304. protected:
  305.     void repaintChanged();
  306.     void updateStyles();
  307.     void drawContents( QPainter *p, int cx, int cy, int cw, int ch );
  308.     bool event( QEvent *e );
  309.     void keyPressEvent( QKeyEvent *e );
  310.     void resizeEvent( QResizeEvent *e );
  311.     void viewportResizeEvent( QResizeEvent* );
  312.     void contentsMousePressEvent( QMouseEvent *e );
  313.     void contentsMouseMoveEvent( QMouseEvent *e );
  314.     void contentsMouseReleaseEvent( QMouseEvent *e );
  315.     void contentsMouseDoubleClickEvent( QMouseEvent *e );
  316. #ifndef QT_NO_WHEELEVENT
  317.     void contentsWheelEvent( QWheelEvent *e );
  318. #endif
  319.     void imStartEvent( QIMEvent * );
  320.     void imComposeEvent( QIMEvent * );
  321.     void imEndEvent( QIMEvent * );
  322. #ifndef QT_NO_DRAGANDDROP
  323.     void contentsDragEnterEvent( QDragEnterEvent *e );
  324.     void contentsDragMoveEvent( QDragMoveEvent *e );
  325.     void contentsDragLeaveEvent( QDragLeaveEvent *e );
  326.     void contentsDropEvent( QDropEvent *e );
  327. #endif
  328.     void contentsContextMenuEvent( QContextMenuEvent *e );
  329.     bool focusNextPrevChild( bool next );
  330.     QTextDocument *document() const;
  331.     QTextCursor *textCursor() const;
  332.     void setDocument( QTextDocument *doc );
  333.     virtual QPopupMenu *createPopupMenu( const QPoint& pos );
  334.     virtual QPopupMenu *createPopupMenu();
  335.     void drawCursor( bool visible );
  336.  
  337.     void windowActivationChange( bool );
  338.  
  339. protected slots:
  340.     virtual void doChangeInterval();
  341.  
  342. private slots:
  343.     void formatMore();
  344.     void doResize();
  345.     void doAutoScroll();
  346.     void blinkCursor();
  347.     void setModified();
  348.     void startDrag();
  349.     void documentWidthChanged( int w );
  350.     void clipboardChanged();
  351.  
  352. private:
  353.     struct Q_EXPORT UndoRedoInfo {
  354.     enum Type { Invalid, Insert, Delete, Backspace, Return, RemoveSelected, Format, Alignment, ParagType };
  355.  
  356.     UndoRedoInfo( QTextDocument *dc );
  357.     ~UndoRedoInfo();
  358.     void clear();
  359.     bool valid() const;
  360.  
  361.     QUndoRedoInfoPrivate *d;
  362.     int id;
  363.     int index;
  364.     int eid;
  365.     int eindex;
  366.     QTextFormat *format;
  367.     int flags;
  368.     Type type;
  369.     QTextDocument *doc;
  370.     QMemArray<int> oldAligns;
  371.     int newAlign;
  372.     bool list;
  373.     QStyleSheetItem::ListStyle listStyle;
  374.     QValueList< QPtrVector<QStyleSheetItem> > oldStyles;
  375.     QValueList<QStyleSheetItem::ListStyle> oldListStyles;
  376.     };
  377.  
  378. private:
  379.     void updateCursor( const QPoint & pos );
  380.     void drawContents( QPainter * );
  381.     virtual bool linksEnabled() const { return FALSE; }
  382.     void init();
  383.     void checkUndoRedoInfo( UndoRedoInfo::Type t );
  384.     void updateCurrentFormat();
  385.     bool handleReadOnlyKeyEvent( QKeyEvent *e );
  386.     void makeParagVisible( QTextParag *p );
  387. #ifndef QT_NO_MIME
  388.     QCString pickSpecial(QMimeSource* ms, bool always_ask, const QPoint&);
  389. #endif
  390. #ifndef QT_NO_MIMECLIPBOARD
  391.     void pasteSpecial(const QPoint&);
  392. #endif
  393.     void setFontInternal( const QFont &f );
  394.  
  395.     virtual void emitHighlighted( const QString & ) {}
  396.     virtual void emitLinkClicked( const QString & ) {}
  397.  
  398.     void readFormats( QTextCursor &c1, QTextCursor &c2, int oldLen, QTextString &text, bool fillStyles = FALSE );
  399.     void clearUndoRedo();
  400.     void paintDocument( bool drawAll, QPainter *p, int cx = -1, int cy = -1, int cw = -1, int ch = -1 );
  401.     void moveCursor( CursorAction action );
  402.     void ensureFormatted( QTextParag *p );
  403.     void placeCursor( const QPoint &pos, QTextCursor *c, bool link );
  404.  
  405. private:
  406.     QTextDocument *doc;
  407.     QTextCursor *cursor;
  408.     QTimer *formatTimer, *scrollTimer, *changeIntervalTimer, *blinkTimer, *dragStartTimer;
  409.     QTextParag *lastFormatted;
  410.     int interval;
  411.     UndoRedoInfo undoRedoInfo;
  412.     QTextFormat *currentFormat;
  413.     int currentAlignment;
  414.     QPoint oldMousePos, mousePos;
  415.     QPoint dragStartPos;
  416.     QString onLink;
  417.     WordWrap wrapMode;
  418.     WrapPolicy wPolicy;
  419.     int wrapWidth;
  420.     QString pressedLink;
  421.     QTextEditPrivate *d;
  422.     bool inDoubleClick : 1;
  423.     bool mousePressed : 1;
  424.     bool cursorVisible : 1;
  425.     bool blinkCursorVisible : 1;
  426.     bool readOnly : 1;
  427.     bool modified : 1;
  428.     bool mightStartDrag : 1;
  429.     bool inDnD : 1;
  430.     bool readonly : 1;
  431.     bool undoEnabled : 1;
  432.     bool overWrite : 1;
  433. };
  434.  
  435. inline QTextDocument *QTextEdit::document() const
  436. {
  437.     return doc;
  438. }
  439.  
  440. inline QTextCursor *QTextEdit::textCursor() const
  441. {
  442.     return cursor;
  443. }
  444.  
  445. inline void QTextEdit::setCurrentFont( const QFont &f )
  446. {
  447.     QTextEdit::setFontInternal( f );
  448. }
  449.  
  450. #endif //QT_NO_TEXTEDIT
  451. #endif //QTEXTVIEW_H
  452.