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 placeCursor( const QPoint& p, bool keepSelection = false, bool updateSelection = true ); 00264 bool isTargetSelected( const QPoint& p ); 00265 00266 void doDrag(); 00267 00268 KateView *m_view; 00269 KateDocument* m_doc; 00270 class KateIconBorder *leftBorder; 00271 00272 int mouseX; 00273 int mouseY; 00274 int scrollX; 00275 int scrollY; 00276 00277 KateSuperCursor cursor; 00278 KateTextCursor displayCursor; 00279 int cXPos; 00280 00281 bool possibleTripleClick; 00282 00283 // Bracket mark 00284 KateTextRange bm; 00285 00286 enum DragState { diNone, diPending, diDragging }; 00287 00288 struct _dragInfo { 00289 DragState state; 00290 QPoint start; 00291 QTextDrag* dragObject; 00292 } dragInfo; 00293 00294 uint iconBorderHeight; 00295 00296 // 00297 // line scrollbar + first visible (virtual) line in the current view 00298 // 00299 KateScrollBar *m_lineScroll; 00300 QWidget* m_dummy; 00301 QVBoxLayout* m_lineLayout; 00302 QHBoxLayout* m_colLayout; 00303 00304 // These are now cursors to account for word-wrap. 00305 KateTextCursor m_startPos; 00306 KateTextCursor m_oldStartPos; 00307 00308 // This is set to false on resize or scroll (other than that called by makeVisible), 00309 // so that makeVisible is again called when a key is pressed and the cursor is in the same spot 00310 bool m_madeVisible; 00311 bool m_shiftKeyPressed; 00312 00313 // How many lines to should be kept visible above/below the cursor when possible 00314 void setAutoCenterLines(int viewLines, bool updateView = true); 00315 int m_autoCenterLines; 00316 int m_minLinesVisible; 00317 00318 // 00319 // column scrollbar + x position 00320 // 00321 QScrollBar *m_columnScroll; 00322 bool m_columnScrollDisplayed; 00323 int m_startX; 00324 int m_oldStartX; 00325 00326 // has selection changed while your mouse or shift key is pressed 00327 bool m_selChangedByUser; 00328 KateTextCursor selectAnchor; 00329 00330 enum SelectionMode { Default=0, Word, Line }; 00331 uint m_selectionMode; 00332 // when drag selecting after double/triple click, keep the initial selected 00333 // word/line independant of direction. 00334 // They get set in the event of a double click, and is used with mouse move + leftbutton 00335 KateTextCursor selStartCached; 00336 KateTextCursor selEndCached; 00337 00338 // 00339 // lines Ranges, mostly useful to speedup + dyn. word wrap 00340 // 00341 QMemArray<KateLineRange> lineRanges; 00342 00343 // Used to determine if the scrollbar will appear/disappear in non-wrapped mode 00344 bool scrollbarVisible(uint startLine); 00345 int maxLen(uint startLine); 00346 00347 // returns the maximum X value / col value a cursor can take for a specific line range 00348 int lineMaxCursorX(const KateLineRange& range); 00349 int lineMaxCol(const KateLineRange& range); 00350 00351 // get the values for a specific range. 00352 // specify lastLine to get the next line of a range. 00353 KateLineRange range(int realLine, const KateLineRange* previous = 0L); 00354 00355 KateLineRange currentRange(); 00356 KateLineRange previousRange(); 00357 KateLineRange nextRange(); 00358 00359 // Finds the lineRange currently occupied by the cursor. 00360 KateLineRange range(const KateTextCursor& realCursor); 00361 00362 // Returns the lineRange of the specified realLine + viewLine. 00363 KateLineRange range(uint realLine, int viewLine); 00364 00365 // find the view line of cursor c (0 = same line, 1 = down one, etc.) 00366 uint viewLine(const KateTextCursor& realCursor); 00367 00368 // find the view line of the cursor, relative to the display (0 = top line of view, 1 = second line, etc.) 00369 // if limitToVisible is true, only lines which are currently visible will be searched for, and -1 returned if the line is not visible. 00370 int displayViewLine(const KateTextCursor& virtualCursor, bool limitToVisible = false); 00371 00372 // find the index of the last view line for a specific line 00373 uint lastViewLine(uint realLine); 00374 00375 // count the number of view lines for a real line 00376 uint viewLineCount(uint realLine); 00377 00378 // find the cursor offset by (offset) view lines from a cursor. 00379 // when keepX is true, the column position will be calculated based on the x 00380 // position of the specified cursor. 00381 KateTextCursor viewLineOffset(const KateTextCursor& virtualCursor, int offset, bool keepX = false); 00382 00383 // These variable holds the most recent maximum real & visible column number 00384 bool m_preserveMaxX; 00385 int m_currentMaxX; 00386 00387 bool m_usePlainLines; // accept non-highlighted lines if this is set 00388 KateTextLine::Ptr textLine(int realLine); 00389 00390 bool m_updatingView; 00391 int m_wrapChangeViewLine; 00392 KateTextCursor m_cachedMaxStartPos; 00393 00394 private slots: 00395 void doDragScroll(); 00396 void startDragScroll(); 00397 void stopDragScroll(); 00398 00399 private: 00400 // Timers 00401 QTimer m_dragScrollTimer; 00402 QTimer m_scrollTimer; 00403 QTimer m_cursorTimer; 00404 QTimer m_textHintTimer; 00405 00406 static const int scrollTime = 30; 00407 static const int scrollMargin = 16; 00408 00409 // needed to stop the column scroll bar from hiding / unhiding during a dragScroll. 00410 bool m_suppressColumnScrollBar; 00411 00412 private slots: 00413 void scrollTimeout (); 00414 void cursorTimeout (); 00415 void textHintTimeout (); 00416 00417 //TextHint 00418 public: 00419 void enableTextHints(int timeout); 00420 void disableTextHints(); 00421 00422 private: 00423 bool m_textHintEnabled; 00424 int m_textHintTimeout; 00425 int m_textHintMouseX; 00426 int m_textHintMouseY; 00427 00428 int m_imPreeditStartLine; 00429 int m_imPreeditStart; 00430 int m_imPreeditLength; 00431 }; 00432 00433 #endif 00434 00435 // 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.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Sep 29 09:45:09 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003