kate Library API Documentation

kateviewinternal.h

00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2002 John Firebaugh <jfirebaugh@kde.org>
00003    Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org>
00004    Copyright (C) 2002 Christoph Cullmann <cullmann@kde.org>
00005 
00006    Based on:
00007      KWriteView : Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
00008 
00009    This library is free software; you can redistribute it and/or
00010    modify it under the terms of the GNU Library General Public
00011    License version 2 as published by the Free Software Foundation.
00012 
00013    This library is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016    Library General Public License for more details.
00017 
00018    You should have received a copy of the GNU Library General Public License
00019    along with this library; see the file COPYING.LIB.  If not, write to
00020    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00021    Boston, MA 02111-1307, USA.
00022 */
00023 
00024 #ifndef _KATE_VIEW_INTERNAL_
00025 #define _KATE_VIEW_INTERNAL_
00026 
00027 #include "katecursor.h"
00028 #include "katesupercursor.h"
00029 #include "katelinerange.h"
00030 #include "katetextline.h"
00031 
00032 #include <qscrollbar.h>
00033 #include <qpoint.h>
00034 #include <qtimer.h>
00035 #include <qintdict.h>
00036 
00037 class KateView;
00038 class KateDocument;
00039 class KateIconBorder;
00040 
00041 class QHBoxLayout;
00042 class QVBoxLayout;
00043 
00044 enum Bias
00045 {
00046     left  = -1,
00047     none  =  0,
00048     right =  1
00049 };
00050 
00058 class KateScrollBar : public QScrollBar
00059 {
00060   Q_OBJECT
00061 
00062   public:
00063     KateScrollBar(Orientation orientation, class KateViewInternal *parent, const char* name = 0L);
00064 
00065     inline bool showMarks() { return m_showMarks; };
00066     inline void setShowMarks(bool b) { m_showMarks = b; update(); };
00067 
00068   signals:
00069     void sliderMMBMoved(int value);
00070 
00071   protected:
00072     virtual void mousePressEvent(QMouseEvent* e);
00073     virtual void mouseReleaseEvent(QMouseEvent* e);
00074     virtual void mouseMoveEvent (QMouseEvent* e);
00075     virtual void paintEvent(QPaintEvent *);
00076     virtual void resizeEvent(QResizeEvent *);
00077     virtual void styleChange(QStyle &oldStyle);
00078     virtual void valueChange();
00079     virtual void rangeChange();
00080 
00081   protected slots:
00082     void sliderMaybeMoved(int value);
00083     void marksChanged();
00084 
00085   private:
00086     void redrawMarks();
00087     void recomputeMarksPositions(bool forceFullUpdate = false);
00088     void watchScrollBarSize();
00089 
00090   bool m_middleMouseDown;
00091 
00092     KateView *m_view;
00093     KateDocument *m_doc;
00094     class KateViewInternal *m_viewInternal;
00095 
00096     int m_topMargin;
00097     int m_bottomMargin;
00098     uint m_savVisibleLines;
00099 
00100     QIntDict<QColor> m_lines;
00101 
00102     bool m_showMarks;
00103 };
00104 
00105 class KateViewInternal : public QWidget
00106 {
00107     Q_OBJECT
00108 
00109     friend class KateView;
00110     friend class KateIconBorder;
00111     friend class KateScrollBar;
00112     friend class CalculatingCursor;
00113     friend class BoundedCursor;
00114     friend class WrappingCursor;
00115 
00116   public:
00117     KateViewInternal ( KateView *view, KateDocument *doc );
00118     ~KateViewInternal ();
00119 
00120   // BEGIN EDIT STUFF
00121   public:
00122     void editStart ();
00123     void editEnd (int editTagLineStart, int editTagLineEnd, bool tagFrom);
00124 
00125     void editSetCursor (const KateTextCursor &cursor);
00126 
00127   private:
00128     uint editSessionNumber;
00129     bool editIsRunning;
00130     KateTextCursor editOldCursor;
00131   // END
00132 
00133   // BEGIN TAG & CLEAR & UPDATE STUFF
00134   public:
00135     bool tagLine (const KateTextCursor& virtualCursor);
00136 
00137     bool tagLines (int start, int end, bool realLines = false);
00138     bool tagLines (KateTextCursor start, KateTextCursor end, bool realCursors = false);
00139 
00140     void tagAll ();
00141 
00142     void clear ();
00143   // END
00144 
00145   private:
00146     void updateView (bool changed = false, int viewLinesScrolled = 0);
00147     void makeVisible (const KateTextCursor& c, uint endCol, bool force = false, bool center = false, bool calledExternally = false);
00148 
00149   public:
00150     inline const KateTextCursor& startPos() const { return m_startPos; }
00151     inline uint startLine () const { return m_startPos.line(); }
00152     inline uint startX () const { return m_startX; }
00153 
00154     KateTextCursor endPos () const;
00155     uint endLine () const;
00156 
00157     KateLineRange yToKateLineRange(uint y) const;
00158 
00159     void prepareForDynWrapChange();
00160     void dynWrapChanged();
00161 
00162   public slots:
00163     void slotIncFontSizes();
00164     void slotDecFontSizes();
00165 
00166   private slots:
00167     void scrollLines(int line); // connected to the sliderMoved of the m_lineScroll
00168     void scrollViewLines(int offset);
00169     void scrollNextPage();
00170     void scrollPrevPage();
00171     void scrollPrevLine();
00172     void scrollNextLine();
00173     void scrollColumns (int x); // connected to the valueChanged of the m_columnScroll
00174     void docSelectionChanged ();
00175 
00176   public:
00177     void doReturn();
00178     void doDelete();
00179     void doBackspace();
00180     void doPaste();
00181     void doTranspose();
00182     void doDeleteWordLeft();
00183     void doDeleteWordRight();
00184 
00185     void cursorLeft(bool sel=false);
00186     void cursorRight(bool sel=false);
00187     void wordLeft(bool sel=false);
00188     void wordRight(bool sel=false);
00189     void home(bool sel=false);
00190     void end(bool sel=false);
00191     void cursorUp(bool sel=false);
00192     void cursorDown(bool sel=false);
00193     void cursorToMatchingBracket(bool sel=false);
00194     void scrollUp();
00195     void scrollDown();
00196     void topOfView(bool sel=false);
00197     void bottomOfView(bool sel=false);
00198     void pageUp(bool sel=false);
00199     void pageDown(bool sel=false);
00200     void top(bool sel=false);
00201     void bottom(bool sel=false);
00202     void top_home(bool sel=false);
00203     void bottom_end(bool sel=false);
00204 
00205     inline const KateTextCursor& getCursor() { return cursor; }
00206     QPoint cursorCoordinates();
00207 
00208     void paintText (int x, int y, int width, int height, bool paintOnlyDirty = false);
00209 
00210   // EVENT HANDLING STUFF - IMPORTANT
00211   protected:
00212     void paintEvent(QPaintEvent *e);
00213     bool eventFilter( QObject *obj, QEvent *e );
00214     void keyPressEvent( QKeyEvent* );
00215     void keyReleaseEvent( QKeyEvent* );
00216     void resizeEvent( QResizeEvent* );
00217     void mousePressEvent(       QMouseEvent* );
00218     void mouseDoubleClickEvent( QMouseEvent* );
00219     void mouseReleaseEvent(     QMouseEvent* );
00220     void mouseMoveEvent(        QMouseEvent* );
00221     void dragEnterEvent( QDragEnterEvent* );
00222     void dragMoveEvent( QDragMoveEvent* );
00223     void dropEvent( QDropEvent* );
00224     void showEvent ( QShowEvent *);
00225     void wheelEvent(QWheelEvent* e);
00226     void focusInEvent (QFocusEvent *);
00227     void focusOutEvent (QFocusEvent *);
00228 
00229     void imStartEvent( QIMEvent *e );
00230     void imComposeEvent( QIMEvent *e );
00231     void imEndEvent( QIMEvent *e );
00232 
00233   private slots:
00234     void tripleClickTimeout();
00235 
00236   signals:
00237     // emitted when KateViewInternal is not handling its own URI drops
00238     void dropEventPass(QDropEvent*);
00239 
00240   private slots:
00241     void slotRegionVisibilityChangedAt(unsigned int);
00242     void slotRegionBeginEndAddedRemoved(unsigned int);
00243     void slotCodeFoldingChanged();
00244 
00245   private:
00246     void moveChar( Bias bias, bool sel );
00247     void moveWord( Bias bias, bool sel );
00248     void moveEdge( Bias bias, bool sel );
00249     KateTextCursor maxStartPos(bool changed = false);
00250     void scrollPos(KateTextCursor& c, bool force = false, bool calledExternally = false);
00251     void scrollLines( int lines, bool sel );
00252 
00253     uint linesDisplayed() const;
00254 
00255     int lineToY(uint viewLine) const;
00256 
00257     void updateSelection( const KateTextCursor&, bool keepSel );
00258     void updateCursor( const KateTextCursor& newCursor, bool force = false, bool center = false, bool calledExternally = false );
00259     void updateBracketMarks();
00260 
00261     void paintCursor();
00262 
00263     void updateMicroFocusHint();
00264 
00265     void placeCursor( const QPoint& p, bool keepSelection = false, bool updateSelection = true );
00266     bool isTargetSelected( const QPoint& p );
00267 
00268     void doDrag();
00269 
00270     KateView *m_view;
00271     KateDocument* m_doc;
00272     class KateIconBorder *leftBorder;
00273 
00274     int mouseX;
00275     int mouseY;
00276     int scrollX;
00277     int scrollY;
00278 
00279     KateSuperCursor cursor;
00280     KateTextCursor displayCursor;
00281     int cXPos;
00282 
00283     bool possibleTripleClick;
00284 
00285     // Bracket mark
00286     KateTextRange bm;
00287 
00288     enum DragState { diNone, diPending, diDragging };
00289 
00290     struct _dragInfo {
00291       DragState    state;
00292       QPoint       start;
00293       QTextDrag*   dragObject;
00294     } dragInfo;
00295 
00296     uint iconBorderHeight;
00297 
00298     //
00299     // line scrollbar + first visible (virtual) line in the current view
00300     //
00301     KateScrollBar *m_lineScroll;
00302     QWidget* m_dummy;
00303     QVBoxLayout* m_lineLayout;
00304     QHBoxLayout* m_colLayout;
00305 
00306     // These are now cursors to account for word-wrap.
00307     KateTextCursor m_startPos;
00308     KateTextCursor m_oldStartPos;
00309 
00310     // This is set to false on resize or scroll (other than that called by makeVisible),
00311     // so that makeVisible is again called when a key is pressed and the cursor is in the same spot
00312     bool m_madeVisible;
00313     bool m_shiftKeyPressed;
00314 
00315     // How many lines to should be kept visible above/below the cursor when possible
00316     void setAutoCenterLines(int viewLines, bool updateView = true);
00317     int m_autoCenterLines;
00318     int m_minLinesVisible;
00319 
00320     //
00321     // column scrollbar + x position
00322     //
00323     QScrollBar *m_columnScroll;
00324     bool m_columnScrollDisplayed;
00325     int m_startX;
00326     int m_oldStartX;
00327 
00328     // has selection changed while your mouse or shift key is pressed
00329     bool m_selChangedByUser;
00330     KateTextCursor selectAnchor;
00331 
00332     enum SelectionMode { Default=0, Word, Line }; 
00333     uint m_selectionMode;
00334     // when drag selecting after double/triple click, keep the initial selected
00335     // word/line independant of direction.
00336     // They get set in the event of a double click, and is used with mouse move + leftbutton
00337     KateTextCursor selStartCached;
00338     KateTextCursor selEndCached;
00339 
00340     //
00341     // lines Ranges, mostly useful to speedup + dyn. word wrap
00342     //
00343     QMemArray<KateLineRange> lineRanges;
00344 
00345     // Used to determine if the scrollbar will appear/disappear in non-wrapped mode
00346     bool scrollbarVisible(uint startLine);
00347     int maxLen(uint startLine);
00348 
00349     // returns the maximum X value / col value a cursor can take for a specific line range
00350     int lineMaxCursorX(const KateLineRange& range);
00351     int lineMaxCol(const KateLineRange& range);
00352 
00353     // get the values for a specific range.
00354     // specify lastLine to get the next line of a range.
00355     KateLineRange range(int realLine, const KateLineRange* previous = 0L);
00356 
00357     KateLineRange currentRange();
00358     KateLineRange previousRange();
00359     KateLineRange nextRange();
00360 
00361     // Finds the lineRange currently occupied by the cursor.
00362     KateLineRange range(const KateTextCursor& realCursor);
00363 
00364     // Returns the lineRange of the specified realLine + viewLine.
00365     KateLineRange range(uint realLine, int viewLine);
00366 
00367     // find the view line of cursor c (0 = same line, 1 = down one, etc.)
00368     uint viewLine(const KateTextCursor& realCursor);
00369 
00370     // find the view line of the cursor, relative to the display (0 = top line of view, 1 = second line, etc.)
00371     // if limitToVisible is true, only lines which are currently visible will be searched for, and -1 returned if the line is not visible.
00372     int displayViewLine(const KateTextCursor& virtualCursor, bool limitToVisible = false);
00373 
00374     // find the index of the last view line for a specific line
00375     uint lastViewLine(uint realLine);
00376 
00377     // count the number of view lines for a real line
00378     uint viewLineCount(uint realLine);
00379 
00380     // find the cursor offset by (offset) view lines from a cursor.
00381     // when keepX is true, the column position will be calculated based on the x
00382     // position of the specified cursor.
00383     KateTextCursor viewLineOffset(const KateTextCursor& virtualCursor, int offset, bool keepX = false);
00384 
00385     // These variable holds the most recent maximum real & visible column number
00386     bool m_preserveMaxX;
00387     int m_currentMaxX;
00388 
00389     bool m_usePlainLines; // accept non-highlighted lines if this is set
00390     KateTextLine::Ptr textLine(int realLine);
00391 
00392     bool m_updatingView;
00393     int m_wrapChangeViewLine;
00394     KateTextCursor m_cachedMaxStartPos;
00395 
00396   private slots:
00397     void doDragScroll();
00398     void startDragScroll();
00399     void stopDragScroll();
00400 
00401   private:
00402     // Timers
00403     QTimer m_dragScrollTimer;
00404     QTimer m_scrollTimer;
00405     QTimer m_cursorTimer;
00406     QTimer m_textHintTimer;
00407 
00408     static const int scrollTime = 30;
00409     static const int scrollMargin = 16;
00410 
00411     // needed to stop the column scroll bar from hiding / unhiding during a dragScroll.
00412     bool m_suppressColumnScrollBar;
00413 
00414   private slots:
00415     void scrollTimeout ();
00416     void cursorTimeout ();
00417     void textHintTimeout ();
00418 
00419   //TextHint
00420  public:
00421    void enableTextHints(int timeout);
00422    void disableTextHints();
00423 
00424  private:
00425    bool m_textHintEnabled;
00426    int m_textHintTimeout;
00427    int m_textHintMouseX;
00428    int m_textHintMouseY;
00429 
00430    int m_imPreeditStartLine;
00431    int m_imPreeditStart;
00432    int m_imPreeditLength;
00433    int m_imPreeditSelStart;
00434 };
00435 
00436 #endif
00437 
00438 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE Logo
This file is part of the documentation for kate Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun Jan 15 13:35:11 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003