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