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 
00036 class KateView;
00037 class KateDocument;
00038 class KateIconBorder;
00039 
00040 class QHBoxLayout;
00041 class QVBoxLayout;
00042 
00043 enum Bias
00044 {
00045     left  = -1,
00046     none  =  0,
00047     right =  1
00048 };
00049 
00055 class KateScrollBar : public QScrollBar
00056 {
00057   Q_OBJECT
00058 
00059   public:
00060     KateScrollBar(Orientation orientation, QWidget* parent, const char* name = 0L);
00061 
00062   signals:
00063     void sliderMMBMoved(int value);
00064 
00065   protected:
00066     virtual void mousePressEvent(QMouseEvent* e);
00067     virtual void mouseReleaseEvent(QMouseEvent* e);
00068 
00069   protected slots:
00070     void sliderMaybeMoved(int value);
00071 
00072   private:
00073   bool m_middleMouseDown;
00074 };
00075 
00076 class KateViewInternal : public QWidget
00077 {
00078     Q_OBJECT
00079 
00080     friend class KateView;
00081     friend class KateIconBorder;
00082     friend class CalculatingCursor;
00083     friend class BoundedCursor;
00084     friend class WrappingCursor;
00085 
00086   public:
00087     KateViewInternal ( KateView *view, KateDocument *doc );
00088     ~KateViewInternal ();
00089 
00090   // BEGIN EDIT STUFF
00091   public:
00092     void editStart ();
00093     void editEnd (int editTagLineStart, int editTagLineEnd, bool tagFrom);
00094 
00095     void editSetCursor (const KateTextCursor &cursor);
00096 
00097   private:
00098     uint editSessionNumber;
00099     bool editIsRunning;
00100     KateTextCursor editOldCursor;
00101   // END
00102 
00103   // BEGIN TAG & CLEAR & UPDATE STUFF
00104   public:
00105     bool tagLine (const KateTextCursor& virtualCursor);
00106 
00107     bool tagLines (int start, int end, bool realLines = false);
00108     bool tagLines (KateTextCursor start, KateTextCursor end, bool realCursors = false);
00109 
00110     void tagAll ();
00111 
00112     void clear ();
00113   // END
00114 
00115   private:
00116     void updateView (bool changed = false, int viewLinesScrolled = 0);
00117     void makeVisible (const KateTextCursor& c, uint endCol, bool force = false, bool center = false, bool calledExternally = false);
00118 
00119   public:
00120     inline const KateTextCursor& startPos() const { return m_startPos; }
00121     inline uint startLine () const { return m_startPos.line(); }
00122     inline uint startX () const { return m_startX; }
00123 
00124     KateTextCursor endPos () const;
00125     uint endLine () const;
00126 
00127     LineRange yToLineRange(uint y) const;
00128 
00129     void prepareForDynWrapChange();
00130     void dynWrapChanged();
00131 
00132   public slots:
00133     void slotIncFontSizes();
00134     void slotDecFontSizes();
00135 
00136   private slots:
00137     void scrollLines(int line); // connected to the sliderMoved of the m_lineScroll
00138     void scrollViewLines(int offset);
00139     void scrollNextPage();
00140     void scrollPrevPage();
00141     void scrollPrevLine();
00142     void scrollNextLine();
00143     void scrollColumns (int x); // connected to the valueChanged of the m_columnScroll
00144     void docSelectionChanged ();
00145 
00146   public:
00147     void doReturn();
00148     void doDelete();
00149     void doBackspace();
00150     void doPaste();
00151     void doTranspose();
00152     void doDeleteWordLeft();
00153     void doDeleteWordRight();
00154 
00155     void cursorLeft(bool sel=false);
00156     void cursorRight(bool sel=false);
00157     void wordLeft(bool sel=false);
00158     void wordRight(bool sel=false);
00159     void home(bool sel=false);
00160     void end(bool sel=false);
00161     void cursorUp(bool sel=false);
00162     void cursorDown(bool sel=false);
00163     void cursorToMatchingBracket(bool sel=false);
00164     void scrollUp();
00165     void scrollDown();
00166     void topOfView(bool sel=false);
00167     void bottomOfView(bool sel=false);
00168     void pageUp(bool sel=false);
00169     void pageDown(bool sel=false);
00170     void top(bool sel=false);
00171     void bottom(bool sel=false);
00172     void top_home(bool sel=false);
00173     void bottom_end(bool sel=false);
00174 
00175     inline const KateTextCursor& getCursor() { return cursor; }
00176     QPoint cursorCoordinates();
00177 
00178     void paintText (int x, int y, int width, int height, bool paintOnlyDirty = false);
00179 
00180   // EVENT HANDLING STUFF - IMPORTANT
00181   protected:
00182     void paintEvent(QPaintEvent *e);
00183     bool eventFilter( QObject *obj, QEvent *e );
00184     void keyPressEvent( QKeyEvent* );
00185     void keyReleaseEvent( QKeyEvent* );
00186     void resizeEvent( QResizeEvent* );
00187     void mousePressEvent(       QMouseEvent* );
00188     void mouseDoubleClickEvent( QMouseEvent* );
00189     void mouseReleaseEvent(     QMouseEvent* );
00190     void mouseMoveEvent(        QMouseEvent* );
00191     void dragEnterEvent( QDragEnterEvent* );
00192     void dragMoveEvent( QDragMoveEvent* );
00193     void dropEvent( QDropEvent* );
00194     void showEvent ( QShowEvent *);
00195     void wheelEvent(QWheelEvent* e);
00196     void focusInEvent (QFocusEvent *);
00197     void focusOutEvent (QFocusEvent *);
00198 
00199     void imStartEvent( QIMEvent *e );
00200     void imComposeEvent( QIMEvent *e );
00201     void imEndEvent( QIMEvent *e );
00202 
00203   private slots:
00204     void tripleClickTimeout();
00205 
00206   signals:
00207     // emitted when KateViewInternal is not handling its own URI drops
00208     void dropEventPass(QDropEvent*);
00209 
00210   private slots:
00211     void slotRegionVisibilityChangedAt(unsigned int);
00212     void slotRegionBeginEndAddedRemoved(unsigned int);
00213     void slotCodeFoldingChanged();
00214 
00215   private:
00216     void moveChar( Bias bias, bool sel );
00217     void moveWord( Bias bias, bool sel );
00218     void moveEdge( Bias bias, bool sel );
00219     KateTextCursor maxStartPos(bool changed = false);
00220     void scrollPos(KateTextCursor& c, bool force = false, bool calledExternally = false);
00221     void scrollLines( int lines, bool sel );
00222 
00223     uint linesDisplayed() const;
00224 
00225     int lineToY(uint viewLine) const;
00226 
00227     void updateSelection( const KateTextCursor&, bool keepSel );
00228     void updateCursor( const KateTextCursor& newCursor, bool force = false, bool center = false, bool calledExternally = false );
00229     void updateBracketMarks();
00230 
00231     void paintCursor();
00232 
00233     void placeCursor( const QPoint& p, bool keepSelection = false, bool updateSelection = true );
00234     bool isTargetSelected( const QPoint& p );
00235 
00236     void doDrag();
00237 
00238     KateView *m_view;
00239     KateDocument* m_doc;
00240     class KateIconBorder *leftBorder;
00241 
00242     int mouseX;
00243     int mouseY;
00244     int scrollX;
00245     int scrollY;
00246 
00247     KateSuperCursor cursor;
00248     KateTextCursor displayCursor;
00249     int cXPos;
00250 
00251     bool possibleTripleClick;
00252 
00253     // Bracket mark
00254     KateTextRange bm;
00255 
00256     enum DragState { diNone, diPending, diDragging };
00257 
00258     struct _dragInfo {
00259       DragState    state;
00260       QPoint       start;
00261       QTextDrag*   dragObject;
00262     } dragInfo;
00263 
00264     uint iconBorderHeight;
00265 
00266     //
00267     // line scrollbar + first visible (virtual) line in the current view
00268     //
00269     QScrollBar *m_lineScroll;
00270     QWidget* m_dummy;
00271     QVBoxLayout* m_lineLayout;
00272     QHBoxLayout* m_colLayout;
00273 
00274     // These are now cursors to account for word-wrap.
00275     KateTextCursor m_startPos;
00276     KateTextCursor m_oldStartPos;
00277 
00278     // This is set to false on resize or scroll (other than that called by makeVisible),
00279     // so that makeVisible is again called when a key is pressed and the cursor is in the same spot
00280     bool m_madeVisible;
00281     bool m_shiftKeyPressed;
00282 
00283     // How many lines to should be kept visible above/below the cursor when possible
00284     void setAutoCenterLines(int viewLines, bool updateView = true);
00285     int m_autoCenterLines;
00286     int m_minLinesVisible;
00287 
00288     //
00289     // column scrollbar + x position
00290     //
00291     QScrollBar *m_columnScroll;
00292     bool m_columnScrollDisplayed;
00293     int m_startX;
00294     int m_oldStartX;
00295 
00296     // has selection changed while your mouse or shift key is pressed
00297     bool m_selChangedByUser;
00298     KateTextCursor selectAnchor;
00299 
00300     //
00301     // lines Ranges, mostly useful to speedup + dyn. word wrap
00302     //
00303     QMemArray<LineRange> lineRanges;
00304 
00305     // Used to determine if the scrollbar will appear/disappear in non-wrapped mode
00306     bool scrollbarVisible(uint startLine);
00307     int maxLen(uint startLine);
00308 
00309     // returns the maximum X value / col value a cursor can take for a specific line range
00310     int lineMaxCursorX(const LineRange& range);
00311     int lineMaxCol(const LineRange& range);
00312 
00313     // get the values for a specific range.
00314     // specify lastLine to get the next line of a range.
00315     LineRange range(int realLine, const LineRange* previous = 0L);
00316 
00317     LineRange currentRange();
00318     LineRange previousRange();
00319     LineRange nextRange();
00320 
00321     // Finds the lineRange currently occupied by the cursor.
00322     LineRange range(const KateTextCursor& realCursor);
00323 
00324     // Returns the lineRange of the specified realLine + viewLine.
00325     LineRange range(uint realLine, int viewLine);
00326 
00327     // find the view line of cursor c (0 = same line, 1 = down one, etc.)
00328     uint viewLine(const KateTextCursor& realCursor);
00329 
00330     // find the view line of the cursor, relative to the display (0 = top line of view, 1 = second line, etc.)
00331     // if limitToVisible is true, only lines which are currently visible will be searched for, and -1 returned if the line is not visible.
00332     int displayViewLine(const KateTextCursor& virtualCursor, bool limitToVisible = false);
00333 
00334     // find the index of the last view line for a specific line
00335     uint lastViewLine(uint realLine);
00336 
00337     // count the number of view lines for a real line
00338     uint viewLineCount(uint realLine);
00339 
00340     // find the cursor offset by (offset) view lines from a cursor.
00341     // when keepX is true, the column position will be calculated based on the x
00342     // position of the specified cursor.
00343     KateTextCursor viewLineOffset(const KateTextCursor& virtualCursor, int offset, bool keepX = false);
00344 
00345     // These variable holds the most recent maximum real & visible column number
00346     bool m_preserveMaxX;
00347     int m_currentMaxX;
00348 
00349     bool m_usePlainLines; // accept non-highlighted lines if this is set
00350     TextLine::Ptr textLine(int realLine);
00351 
00352     bool m_updatingView;
00353     int m_wrapChangeViewLine;
00354     KateTextCursor m_cachedMaxStartPos;
00355 
00356   private slots:
00357     void doDragScroll();
00358     void startDragScroll();
00359     void stopDragScroll();
00360 
00361   private:
00362     // Timers
00363     QTimer m_dragScrollTimer;
00364     QTimer m_scrollTimer;
00365     QTimer m_cursorTimer;
00366     QTimer m_textHintTimer;
00367 
00368     static const int scrollTime = 30;
00369     static const int scrollMargin = 16;
00370 
00371     // needed to stop the column scroll bar from hiding / unhiding during a dragScroll.
00372     bool m_suppressColumnScrollBar;
00373 
00374   private slots:
00375     void scrollTimeout ();
00376     void cursorTimeout ();
00377     void textHintTimeout ();
00378 
00379   //TextHint
00380  public:
00381    void enableTextHints(int timeout);
00382    void disableTextHints();
00383 
00384  private:
00385    bool m_textHintEnabled;
00386    int m_textHintTimeout;
00387    int m_textHintMouseX;
00388    int m_textHintMouseY;
00389 
00390    int m_imPreeditStartLine;
00391    int m_imPreeditStart;
00392    int m_imPreeditLength;
00393 };
00394 
00395 #endif
KDE Logo
This file is part of the documentation for kate Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Apr 21 18:45:19 2004 by doxygen 1.3.6-20040222 written by Dimitri van Heesch, © 1997-2003