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 #include "katedocument.h"
00032 
00033 #include <qscrollbar.h>
00034 #include <qpoint.h>
00035 #include <qtimer.h>
00036 #include <qintdict.h>
00037 
00038 class KateView;
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 contextMenuEvent ( QContextMenuEvent * e );
00230 
00231     void imStartEvent( QIMEvent *e );
00232     void imComposeEvent( QIMEvent *e );
00233     void imEndEvent( QIMEvent *e );
00234 
00235   private slots:
00236     void tripleClickTimeout();
00237 
00238   signals:
00239     // emitted when KateViewInternal is not handling its own URI drops
00240     void dropEventPass(QDropEvent*);
00241 
00242   private slots:
00243     void slotRegionVisibilityChangedAt(unsigned int);
00244     void slotRegionBeginEndAddedRemoved(unsigned int);
00245     void slotCodeFoldingChanged();
00246 
00247   private:
00248     void moveChar( Bias bias, bool sel );
00249     void moveWord( Bias bias, bool sel );
00250     void moveEdge( Bias bias, bool sel );
00251     KateTextCursor maxStartPos(bool changed = false);
00252     void scrollPos(KateTextCursor& c, bool force = false, bool calledExternally = false);
00253     void scrollLines( int lines, bool sel );
00254 
00255     uint linesDisplayed() const;
00256 
00257     int lineToY(uint viewLine) const;
00258 
00259     void updateSelection( const KateTextCursor&, bool keepSel );
00260     void updateCursor( const KateTextCursor& newCursor, bool force = false, bool center = false, bool calledExternally = false );
00261     void updateBracketMarks();
00262 
00263     void paintCursor();
00264 
00265     void updateMicroFocusHint();
00266 
00267     void placeCursor( const QPoint& p, bool keepSelection = false, bool updateSelection = true );
00268     bool isTargetSelected( const QPoint& p );
00269 
00270     void doDrag();
00271 
00272     KateView *m_view;
00273     KateDocument* m_doc;
00274     class KateIconBorder *leftBorder;
00275 
00276     int mouseX;
00277     int mouseY;
00278     int scrollX;
00279     int scrollY;
00280 
00281     Qt::CursorShape m_mouseCursor;
00282 
00283     KateSuperCursor cursor;
00284     KateTextCursor displayCursor;
00285     int cXPos;
00286 
00287     bool possibleTripleClick;
00288 
00289     // Bracket mark
00290     KateTextRange bm;
00291 
00292     enum DragState { diNone, diPending, diDragging };
00293 
00294     struct _dragInfo {
00295       DragState    state;
00296       QPoint       start;
00297       QTextDrag*   dragObject;
00298     } dragInfo;
00299 
00300     uint iconBorderHeight;
00301 
00302     //
00303     // line scrollbar + first visible (virtual) line in the current view
00304     //
00305     KateScrollBar *m_lineScroll;
00306     QWidget* m_dummy;
00307     QVBoxLayout* m_lineLayout;
00308     QHBoxLayout* m_colLayout;
00309 
00310     // These are now cursors to account for word-wrap.
00311     KateSuperCursor m_startPos;
00312 
00313     // This is set to false on resize or scroll (other than that called by makeVisible),
00314     // so that makeVisible is again called when a key is pressed and the cursor is in the same spot
00315     bool m_madeVisible;
00316     bool m_shiftKeyPressed;
00317 
00318     // How many lines to should be kept visible above/below the cursor when possible
00319     void setAutoCenterLines(int viewLines, bool updateView = true);
00320     int m_autoCenterLines;
00321     int m_minLinesVisible;
00322 
00323     //
00324     // column scrollbar + x position
00325     //
00326     QScrollBar *m_columnScroll;
00327     bool m_columnScrollDisplayed;
00328     int m_startX;
00329     int m_oldStartX;
00330 
00331     // has selection changed while your mouse or shift key is pressed
00332     bool m_selChangedByUser;
00333     KateTextCursor selectAnchor;
00334 
00335     enum SelectionMode { Default=0, Word, Line }; 
00336     uint m_selectionMode;
00337     // when drag selecting after double/triple click, keep the initial selected
00338     // word/line independant of direction.
00339     // They get set in the event of a double click, and is used with mouse move + leftbutton
00340     KateTextCursor selStartCached;
00341     KateTextCursor selEndCached;
00342 
00343     //
00344     // lines Ranges, mostly useful to speedup + dyn. word wrap
00345     //
00346     QMemArray<KateLineRange> lineRanges;
00347 
00348     // Used to determine if the scrollbar will appear/disappear in non-wrapped mode
00349     bool scrollbarVisible(uint startLine);
00350     int maxLen(uint startLine);
00351 
00352     // returns the maximum X value / col value a cursor can take for a specific line range
00353     int lineMaxCursorX(const KateLineRange& range);
00354     int lineMaxCol(const KateLineRange& range);
00355 
00356     // get the values for a specific range.
00357     // specify lastLine to get the next line of a range.
00358     KateLineRange range(int realLine, const KateLineRange* previous = 0L);
00359 
00360     KateLineRange currentRange();
00361     KateLineRange previousRange();
00362     KateLineRange nextRange();
00363 
00364     // Finds the lineRange currently occupied by the cursor.
00365     KateLineRange range(const KateTextCursor& realCursor);
00366 
00367     // Returns the lineRange of the specified realLine + viewLine.
00368     KateLineRange range(uint realLine, int viewLine);
00369 
00370     // find the view line of cursor c (0 = same line, 1 = down one, etc.)
00371     uint viewLine(const KateTextCursor& realCursor);
00372 
00373     // find the view line of the cursor, relative to the display (0 = top line of view, 1 = second line, etc.)
00374     // if limitToVisible is true, only lines which are currently visible will be searched for, and -1 returned if the line is not visible.
00375     int displayViewLine(const KateTextCursor& virtualCursor, bool limitToVisible = false);
00376 
00377     // find the index of the last view line for a specific line
00378     uint lastViewLine(uint realLine);
00379 
00380     // count the number of view lines for a real line
00381     uint viewLineCount(uint realLine);
00382 
00383     // find the cursor offset by (offset) view lines from a cursor.
00384     // when keepX is true, the column position will be calculated based on the x
00385     // position of the specified cursor.
00386     KateTextCursor viewLineOffset(const KateTextCursor& virtualCursor, int offset, bool keepX = false);
00387 
00388     // These variable holds the most recent maximum real & visible column number
00389     bool m_preserveMaxX;
00390     int m_currentMaxX;
00391 
00392     bool m_usePlainLines; // accept non-highlighted lines if this is set
00393 
00394     inline KateTextLine::Ptr textLine( int realLine )
00395     {
00396       if (m_usePlainLines)
00397         return m_doc->plainKateTextLine(realLine);
00398       else
00399         return m_doc->kateTextLine(realLine);
00400     }
00401 
00402     bool m_updatingView;
00403     int m_wrapChangeViewLine;
00404     KateTextCursor m_cachedMaxStartPos;
00405 
00406   private slots:
00407     void doDragScroll();
00408     void startDragScroll();
00409     void stopDragScroll();
00410 
00411   private:
00412     // Timers
00413     QTimer m_dragScrollTimer;
00414     QTimer m_scrollTimer;
00415     QTimer m_cursorTimer;
00416     QTimer m_textHintTimer;
00417 
00418     static const int scrollTime = 30;
00419     static const int scrollMargin = 16;
00420 
00421     // needed to stop the column scroll bar from hiding / unhiding during a dragScroll.
00422     bool m_suppressColumnScrollBar;
00423 
00424   private slots:
00425     void scrollTimeout ();
00426     void cursorTimeout ();
00427     void textHintTimeout ();
00428 
00429   //TextHint
00430  public:
00431    void enableTextHints(int timeout);
00432    void disableTextHints();
00433 
00434  private:
00435    bool m_textHintEnabled;
00436    int m_textHintTimeout;
00437    int m_textHintMouseX;
00438    int m_textHintMouseY;
00439 
00440    int m_imPreeditStartLine;
00441    int m_imPreeditStart;
00442    int m_imPreeditLength;
00443    int m_imPreeditSelStart;
00444 };
00445 
00446 #endif
00447 
00448 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE Logo
This file is part of the documentation for kate Library Version 3.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Feb 8 06:26:25 2006 by doxygen 1.4.4 written by Dimitri van Heesch, © 1997-2003