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 moveEdge( Bias bias, bool sel ); 00194 KateTextCursor maxStartPos(bool changed = false); 00195 void scrollPos(KateTextCursor& c, bool force = false, bool calledExternally = false); 00196 void scrollLines( int lines, bool sel ); 00197 00198 uint linesDisplayed() const; 00199 00200 int lineToY(uint viewLine) const; 00201 00202 void updateSelection( const KateTextCursor&, bool keepSel ); 00203 void updateCursor( const KateTextCursor& newCursor, bool force = false, bool center = false, bool calledExternally = false ); 00204 void updateBracketMarks(); 00205 00206 void paintCursor(); 00207 00208 void updateMicroFocusHint(); 00209 00210 void placeCursor( const QPoint& p, bool keepSelection = false, bool updateSelection = true ); 00211 bool isTargetSelected( const QPoint& p ); 00212 00213 void doDrag(); 00214 00215 KateView *m_view; 00216 KateDocument* m_doc; 00217 class KateIconBorder *leftBorder; 00218 00219 int mouseX; 00220 int mouseY; 00221 int scrollX; 00222 int scrollY; 00223 00224 Qt::CursorShape m_mouseCursor; 00225 00226 KateSuperCursor cursor; 00227 KateTextCursor displayCursor; 00228 int cXPos; 00229 00230 bool possibleTripleClick; 00231 00232 // Bracket mark 00233 KateBracketRange bm; 00234 00235 enum DragState { diNone, diPending, diDragging }; 00236 00237 struct _dragInfo { 00238 DragState state; 00239 QPoint start; 00240 QTextDrag* dragObject; 00241 } dragInfo; 00242 00243 uint iconBorderHeight; 00244 00245 // 00246 // line scrollbar + first visible (virtual) line in the current view 00247 // 00248 KateScrollBar *m_lineScroll; 00249 QWidget* m_dummy; 00250 QVBoxLayout* m_lineLayout; 00251 QHBoxLayout* m_colLayout; 00252 00253 // These are now cursors to account for word-wrap. 00254 KateSuperCursor m_startPos; 00255 00256 // This is set to false on resize or scroll (other than that called by makeVisible), 00257 // so that makeVisible is again called when a key is pressed and the cursor is in the same spot 00258 bool m_madeVisible; 00259 bool m_shiftKeyPressed; 00260 00261 // How many lines to should be kept visible above/below the cursor when possible 00262 void setAutoCenterLines(int viewLines, bool updateView = true); 00263 int m_autoCenterLines; 00264 int m_minLinesVisible; 00265 00266 // 00267 // column scrollbar + x position 00268 // 00269 QScrollBar *m_columnScroll; 00270 int m_startX; 00271 00272 // has selection changed while your mouse or shift key is pressed 00273 bool m_selChangedByUser; 00274 KateTextCursor selectAnchor; 00275 00276 enum SelectionMode { Default=0, Word, Line, Mouse }; 00277 uint m_selectionMode; 00278 // when drag selecting after double/triple click, keep the initial selected 00279 // word/line independant of direction. 00280 // They get set in the event of a double click, and is used with mouse move + leftbutton 00281 KateTextCursor selStartCached; 00282 KateTextCursor selEndCached; 00283 00284 // 00285 // lines Ranges, mostly useful to speedup + dyn. word wrap 00286 // 00287 QMemArray<KateLineRange> lineRanges; 00288 00289 // maximal lenght of textlines visible from given startLine 00290 int maxLen(uint startLine); 00291 00292 // are we allowed to scroll columns? 00293 bool columnScrollingPossible (); 00294 00295 // returns the maximum X value / col value a cursor can take for a specific line range 00296 int lineMaxCursorX(const KateLineRange& range); 00297 int lineMaxCol(const KateLineRange& range); 00298 00299 // get the values for a specific range. 00300 // specify lastLine to get the next line of a range. 00301 KateLineRange range(int realLine, const KateLineRange* previous = 0L); 00302 00303 KateLineRange currentRange(); 00304 KateLineRange previousRange(); 00305 KateLineRange nextRange(); 00306 00307 // Finds the lineRange currently occupied by the cursor. 00308 KateLineRange range(const KateTextCursor& realCursor); 00309 00310 // Returns the lineRange of the specified realLine + viewLine. 00311 KateLineRange range(uint realLine, int viewLine); 00312 00313 // find the view line of cursor c (0 = same line, 1 = down one, etc.) 00314 uint viewLine(const KateTextCursor& realCursor); 00315 00316 // find the view line of the cursor, relative to the display (0 = top line of view, 1 = second line, etc.) 00317 // if limitToVisible is true, only lines which are currently visible will be searched for, and -1 returned if the line is not visible. 00318 int displayViewLine(const KateTextCursor& virtualCursor, bool limitToVisible = false); 00319 00320 // find the index of the last view line for a specific line 00321 uint lastViewLine(uint realLine); 00322 00323 // count the number of view lines for a real line 00324 uint viewLineCount(uint realLine); 00325 00326 // find the cursor offset by (offset) view lines from a cursor. 00327 // when keepX is true, the column position will be calculated based on the x 00328 // position of the specified cursor. 00329 KateTextCursor viewLineOffset(const KateTextCursor& virtualCursor, int offset, bool keepX = false); 00330 00331 // These variable holds the most recent maximum real & visible column number 00332 bool m_preserveMaxX; 00333 int m_currentMaxX; 00334 00335 bool m_usePlainLines; // accept non-highlighted lines if this is set 00336 00337 inline KateTextLine::Ptr textLine( int realLine ) 00338 { 00339 if (m_usePlainLines) 00340 return m_doc->plainKateTextLine(realLine); 00341 else 00342 return m_doc->kateTextLine(realLine); 00343 } 00344 00345 bool m_updatingView; 00346 int m_wrapChangeViewLine; 00347 KateTextCursor m_cachedMaxStartPos; 00348 00349 private slots: 00350 void doDragScroll(); 00351 void startDragScroll(); 00352 void stopDragScroll(); 00353 00354 private: 00355 // Timers 00356 QTimer m_dragScrollTimer; 00357 QTimer m_scrollTimer; 00358 QTimer m_cursorTimer; 00359 QTimer m_textHintTimer; 00360 00361 static const int scrollTime = 30; 00362 static const int scrollMargin = 16; 00363 00364 private slots: 00365 void scrollTimeout (); 00366 void cursorTimeout (); 00367 void textHintTimeout (); 00368 00369 //TextHint 00370 public: 00371 void enableTextHints(int timeout); 00372 void disableTextHints(); 00373 00374 private: 00375 bool m_textHintEnabled; 00376 int m_textHintTimeout; 00377 int m_textHintMouseX; 00378 int m_textHintMouseY; 00379 00383 protected: 00384 void imStartEvent( QIMEvent *e ); 00385 void imComposeEvent( QIMEvent *e ); 00386 void imEndEvent( QIMEvent *e ); 00387 00388 private: 00389 int m_imPreeditStartLine; 00390 int m_imPreeditStart; 00391 int m_imPreeditLength; 00392 int m_imPreeditSelStart; 00393 }; 00394 00395 #endif 00396 00397 // kate: space-indent on; indent-width 2; replace-tabs on;