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 <tqpoint.h> 00034 #include <tqtimer.h> 00035 #include <tqintdict.h> 00036 #include <tqdragobject.h> 00037 00038 class KateView; 00039 class KateIconBorder; 00040 class KateScrollBar; 00041 00042 class TQHBoxLayout; 00043 class TQVBoxLayout; 00044 class TQScrollBar; 00045 00046 enum Bias 00047 { 00048 left_b = -1, 00049 none = 0, 00050 right_b = 1 00051 }; 00052 00053 class KateViewInternal : public TQWidget 00054 { 00055 Q_OBJECT 00056 00057 friend class KateView; 00058 friend class KateIconBorder; 00059 friend class KateScrollBar; 00060 friend class CalculatingCursor; 00061 friend class BoundedCursor; 00062 friend class WrappingCursor; 00063 00064 public: 00065 KateViewInternal ( KateView *view, KateDocument *doc ); 00066 ~KateViewInternal (); 00067 00068 //BEGIN EDIT STUFF 00069 public: 00070 void editStart (); 00071 void editEnd (int editTagLineStart, int editTagLineEnd, bool tagFrom); 00072 00073 void editSetCursor (const KateTextCursor &cursor); 00074 00075 private: 00076 uint editSessionNumber; 00077 bool editIsRunning; 00078 KateTextCursor editOldCursor; 00079 //END 00080 00081 //BEGIN TAG & CLEAR & UPDATE STUFF 00082 public: 00083 bool tagLine (const KateTextCursor& virtualCursor); 00084 00085 bool tagLines (int start, int end, bool realLines = false); 00086 bool tagLines (KateTextCursor start, KateTextCursor end, bool realCursors = false); 00087 00088 void tagAll (); 00089 00090 void clear (); 00091 //END 00092 00093 private: 00094 void updateView (bool changed = false, int viewLinesScrolled = 0); 00095 void makeVisible (const KateTextCursor& c, uint endCol, bool force = false, bool center = false, bool calledExternally = false); 00096 00097 public: 00098 inline const KateTextCursor& startPos() const { return m_startPos; } 00099 inline uint startLine () const { return m_startPos.line(); } 00100 inline uint startX () const { return m_startX; } 00101 00102 KateTextCursor endPos () const; 00103 uint endLine () const; 00104 00105 KateLineRange yToKateLineRange(uint y) const; 00106 00107 void prepareForDynWrapChange(); 00108 void dynWrapChanged(); 00109 00110 KateView *view () { return m_view; } 00111 00112 public slots: 00113 void slotIncFontSizes(); 00114 void slotDecFontSizes(); 00115 00116 private slots: 00117 void scrollLines(int line); // connected to the sliderMoved of the m_lineScroll 00118 void scrollViewLines(int offset); 00119 void scrollNextPage(); 00120 void scrollPrevPage(); 00121 void scrollPrevLine(); 00122 void scrollNextLine(); 00123 void scrollColumns (int x); // connected to the valueChanged of the m_columnScroll 00124 void viewSelectionChanged (); 00125 00126 public: 00127 void doReturn(); 00128 void doDelete(); 00129 void doBackspace(); 00130 void doTranspose(); 00131 void doDeleteWordLeft(); 00132 void doDeleteWordRight(); 00133 00134 void cursorLeft(bool sel=false); 00135 void cursorRight(bool sel=false); 00136 void wordLeft(bool sel=false); 00137 void wordRight(bool sel=false); 00138 void home(bool sel=false); 00139 void end(bool sel=false); 00140 void cursorUp(bool sel=false); 00141 void cursorDown(bool sel=false); 00142 void cursorToMatchingBracket(bool sel=false); 00143 void scrollUp(); 00144 void scrollDown(); 00145 void topOfView(bool sel=false); 00146 void bottomOfView(bool sel=false); 00147 void pageUp(bool sel=false); 00148 void pageDown(bool sel=false); 00149 void top(bool sel=false); 00150 void bottom(bool sel=false); 00151 void top_home(bool sel=false); 00152 void bottom_end(bool sel=false); 00153 00154 inline const KateTextCursor& getCursor() { return cursor; } 00155 TQPoint cursorCoordinates(); 00156 00157 void paintText (int x, int y, int width, int height, bool paintOnlyDirty = false); 00158 00159 // EVENT HANDLING STUFF - IMPORTANT 00160 protected: 00161 void paintEvent(TQPaintEvent *e); 00162 bool eventFilter( TQObject *obj, TQEvent *e ); 00163 void keyPressEvent( TQKeyEvent* ); 00164 void keyReleaseEvent( TQKeyEvent* ); 00165 void resizeEvent( TQResizeEvent* ); 00166 void mousePressEvent( TQMouseEvent* ); 00167 void mouseDoubleClickEvent( TQMouseEvent* ); 00168 void mouseReleaseEvent( TQMouseEvent* ); 00169 void mouseMoveEvent( TQMouseEvent* ); 00170 void dragEnterEvent( TQDragEnterEvent* ); 00171 void dragMoveEvent( TQDragMoveEvent* ); 00172 void dropEvent( TQDropEvent* ); 00173 void showEvent ( TQShowEvent *); 00174 void wheelEvent(TQWheelEvent* e); 00175 void focusInEvent (TQFocusEvent *); 00176 void focusOutEvent (TQFocusEvent *); 00177 00178 void contextMenuEvent ( TQContextMenuEvent * e ); 00179 00180 private slots: 00181 void tripleClickTimeout(); 00182 00183 signals: 00184 // emitted when KateViewInternal is not handling its own URI drops 00185 void dropEventPass(TQDropEvent*); 00186 00187 private slots: 00188 void slotRegionVisibilityChangedAt(unsigned int); 00189 void slotRegionBeginEndAddedRemoved(unsigned int); 00190 void slotCodeFoldingChanged(); 00191 00192 private: 00193 void moveChar( 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 TQPoint& p, bool keepSelection = false, bool updateSelection = true ); 00212 bool isTargetSelected( const TQPoint& 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 TQt::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 TQPoint start; 00241 TQTextDrag* 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 TQWidget* m_dummy; 00251 TQVBoxLayout* m_lineLayout; 00252 TQHBoxLayout* 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 TQScrollBar *m_columnScroll; 00271 int m_startX; 00272 00273 // has selection changed while your mouse or shift key is pressed 00274 bool m_selChangedByUser; 00275 KateTextCursor selectAnchor; 00276 00277 enum SelectionMode { Default=0, Word, Line, Mouse }; 00278 uint m_selectionMode; 00279 // when drag selecting after double/triple click, keep the initial selected 00280 // word/line independant of direction. 00281 // They get set in the event of a double click, and is used with mouse move + leftbutton 00282 KateTextCursor selStartCached; 00283 KateTextCursor selEndCached; 00284 00285 // 00286 // lines Ranges, mostly useful to speedup + dyn. word wrap 00287 // 00288 TQMemArray<KateLineRange> lineRanges; 00289 00290 // maximal length of textlines visible from given startLine 00291 int maxLen(uint startLine); 00292 00293 // are we allowed to scroll columns? 00294 bool columnScrollingPossible (); 00295 00296 // returns the maximum X value / col value a cursor can take for a specific line range 00297 int lineMaxCursorX(const KateLineRange& range); 00298 int lineMaxCol(const KateLineRange& range); 00299 00300 // get the values for a specific range. 00301 // specify lastLine to get the next line of a range. 00302 KateLineRange range(int realLine, const KateLineRange* previous = 0L); 00303 00304 KateLineRange currentRange(); 00305 KateLineRange previousRange(); 00306 KateLineRange nextRange(); 00307 00308 // Finds the lineRange currently occupied by the cursor. 00309 KateLineRange range(const KateTextCursor& realCursor); 00310 00311 // Returns the lineRange of the specified realLine + viewLine. 00312 KateLineRange range(uint realLine, int viewLine); 00313 00314 // find the view line of cursor c (0 = same line, 1 = down one, etc.) 00315 uint viewLine(const KateTextCursor& realCursor); 00316 00317 // find the view line of the cursor, relative to the display (0 = top line of view, 1 = second line, etc.) 00318 // if limitToVisible is true, only lines which are currently visible will be searched for, and -1 returned if the line is not visible. 00319 int displayViewLine(const KateTextCursor& virtualCursor, bool limitToVisible = false); 00320 00321 // find the index of the last view line for a specific line 00322 uint lastViewLine(uint realLine); 00323 00324 // count the number of view lines for a real line 00325 uint viewLineCount(uint realLine); 00326 00327 // find the cursor offset by (offset) view lines from a cursor. 00328 // when keepX is true, the column position will be calculated based on the x 00329 // position of the specified cursor. 00330 KateTextCursor viewLineOffset(const KateTextCursor& virtualCursor, int offset, bool keepX = false); 00331 00332 // These variable holds the most recent maximum real & visible column number 00333 bool m_preserveMaxX; 00334 int m_currentMaxX; 00335 00336 bool m_usePlainLines; // accept non-highlighted lines if this is set 00337 00338 inline KateTextLine::Ptr textLine( int realLine ) 00339 { 00340 if (m_usePlainLines) 00341 return m_doc->plainKateTextLine(realLine); 00342 else 00343 return m_doc->kateTextLine(realLine); 00344 } 00345 00346 bool m_updatingView; 00347 int m_wrapChangeViewLine; 00348 KateTextCursor m_cachedMaxStartPos; 00349 00350 private slots: 00351 void doDragScroll(); 00352 void startDragScroll(); 00353 void stopDragScroll(); 00354 00355 private: 00356 // Timers 00357 TQTimer m_dragScrollTimer; 00358 TQTimer m_scrollTimer; 00359 TQTimer m_cursorTimer; 00360 TQTimer m_textHintTimer; 00361 00362 static const int scrollTime = 30; 00363 static const int scrollMargin = 16; 00364 00365 private slots: 00366 void scrollTimeout (); 00367 void cursorTimeout (); 00368 void textHintTimeout (); 00369 00370 //TextHint 00371 public: 00372 void enableTextHints(int timeout); 00373 void disableTextHints(); 00374 00375 private: 00376 bool m_textHintEnabled; 00377 int m_textHintTimeout; 00378 int m_textHintMouseX; 00379 int m_textHintMouseY; 00380 00384 protected: 00385 void imStartEvent( TQIMEvent *e ); 00386 void imComposeEvent( TQIMEvent *e ); 00387 void imEndEvent( TQIMEvent *e ); 00388 00389 private: 00390 int m_imPreeditStartLine; 00391 int m_imPreeditStart; 00392 int m_imPreeditLength; 00393 int m_imPreeditSelStart; 00394 }; 00395 00396 #endif 00397 00398 // kate: space-indent on; indent-width 2; replace-tabs on;