TDE core libraries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

kateviewinternal.h 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. /* This file is part of the KDE libraries
  2. Copyright (C) 2002 John Firebaugh <jfirebaugh@kde.org>
  3. Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org>
  4. Copyright (C) 2002 Christoph Cullmann <cullmann@kde.org>
  5. Based on:
  6. KWriteView : Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
  7. This library is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU Library General Public
  9. License version 2 as published by the Free Software Foundation.
  10. This library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. Library General Public License for more details.
  14. You should have received a copy of the GNU Library General Public License
  15. along with this library; see the file COPYING.LIB. If not, write to
  16. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17. Boston, MA 02110-1301, USA.
  18. */
  19. #ifndef _KATE_VIEW_INTERNAL_
  20. #define _KATE_VIEW_INTERNAL_
  21. #include "katecursor.h"
  22. #include "katesupercursor.h"
  23. #include "katelinerange.h"
  24. #include "katetextline.h"
  25. #include "katedocument.h"
  26. #include <tqpoint.h>
  27. #include <tqtimer.h>
  28. #include <tqintdict.h>
  29. #include <tqdragobject.h>
  30. class KateView;
  31. class KateIconBorder;
  32. class KateScrollBar;
  33. class TQHBoxLayout;
  34. class TQVBoxLayout;
  35. class TQScrollBar;
  36. enum Bias
  37. {
  38. left_b = -1,
  39. none = 0,
  40. right_b = 1
  41. };
  42. class KateViewInternal : public TQWidget
  43. {
  44. Q_OBJECT
  45. friend class KateView;
  46. friend class KateIconBorder;
  47. friend class KateScrollBar;
  48. friend class CalculatingCursor;
  49. friend class BoundedCursor;
  50. friend class WrappingCursor;
  51. public:
  52. KateViewInternal ( KateView *view, KateDocument *doc );
  53. ~KateViewInternal ();
  54. //BEGIN EDIT STUFF
  55. public:
  56. void editStart ();
  57. void editEnd (int editTagLineStart, int editTagLineEnd, bool tagFrom);
  58. void editSetCursor (const KateTextCursor &cursor);
  59. private:
  60. uint editSessionNumber;
  61. bool editIsRunning;
  62. KateTextCursor editOldCursor;
  63. //END
  64. //BEGIN TAG & CLEAR & UPDATE STUFF
  65. public:
  66. bool tagLine (const KateTextCursor& virtualCursor);
  67. bool tagLines (int start, int end, bool realLines = false);
  68. bool tagLines (KateTextCursor start, KateTextCursor end, bool realCursors = false);
  69. void tagAll ();
  70. void clear ();
  71. //END
  72. private:
  73. void updateView (bool changed = false, int viewLinesScrolled = 0);
  74. void makeVisible (const KateTextCursor& c, uint endCol, bool force = false, bool center = false, bool calledExternally = false);
  75. public:
  76. inline const KateTextCursor& startPos() const { return m_startPos; }
  77. inline uint startLine () const { return m_startPos.line(); }
  78. inline uint startX () const { return m_startX; }
  79. KateTextCursor endPos () const;
  80. uint endLine () const;
  81. KateLineRange yToKateLineRange(uint y) const;
  82. void prepareForDynWrapChange();
  83. void dynWrapChanged();
  84. KateView *view () { return m_view; }
  85. public slots:
  86. void slotIncFontSizes();
  87. void slotDecFontSizes();
  88. private slots:
  89. void scrollLines(int line); // connected to the sliderMoved of the m_lineScroll
  90. void scrollViewLines(int offset);
  91. void scrollNextPage();
  92. void scrollPrevPage();
  93. void scrollPrevLine();
  94. void scrollNextLine();
  95. void scrollColumns (int x); // connected to the valueChanged of the m_columnScroll
  96. void viewSelectionChanged ();
  97. public:
  98. void doReturn();
  99. void doDelete();
  100. void doBackspace();
  101. void doTranspose();
  102. void doDeleteWordLeft();
  103. void doDeleteWordRight();
  104. void cursorLeft(bool sel=false);
  105. void cursorRight(bool sel=false);
  106. void wordLeft(bool sel=false);
  107. void wordRight(bool sel=false);
  108. void home(bool sel=false);
  109. void end(bool sel=false);
  110. void cursorUp(bool sel=false);
  111. void cursorDown(bool sel=false);
  112. void cursorToMatchingBracket(bool sel=false);
  113. void scrollUp();
  114. void scrollDown();
  115. void topOfView(bool sel=false);
  116. void bottomOfView(bool sel=false);
  117. void pageUp(bool sel=false);
  118. void pageDown(bool sel=false);
  119. void top(bool sel=false);
  120. void bottom(bool sel=false);
  121. void top_home(bool sel=false);
  122. void bottom_end(bool sel=false);
  123. inline const KateTextCursor& getCursor() { return cursor; }
  124. TQPoint cursorCoordinates();
  125. void paintText (int x, int y, int width, int height, bool paintOnlyDirty = false);
  126. // EVENT HANDLING STUFF - IMPORTANT
  127. protected:
  128. void paintEvent(TQPaintEvent *e);
  129. bool eventFilter( TQObject *obj, TQEvent *e );
  130. void keyPressEvent( TQKeyEvent* );
  131. void keyReleaseEvent( TQKeyEvent* );
  132. void resizeEvent( TQResizeEvent* );
  133. void mousePressEvent( TQMouseEvent* );
  134. void mouseDoubleClickEvent( TQMouseEvent* );
  135. void mouseReleaseEvent( TQMouseEvent* );
  136. void mouseMoveEvent( TQMouseEvent* );
  137. void dragEnterEvent( TQDragEnterEvent* );
  138. void dragMoveEvent( TQDragMoveEvent* );
  139. void dropEvent( TQDropEvent* );
  140. void showEvent ( TQShowEvent *);
  141. void wheelEvent(TQWheelEvent* e);
  142. void focusInEvent (TQFocusEvent *);
  143. void focusOutEvent (TQFocusEvent *);
  144. void contextMenuEvent ( TQContextMenuEvent * e );
  145. private slots:
  146. void tripleClickTimeout();
  147. signals:
  148. // emitted when KateViewInternal is not handling its own URI drops
  149. void dropEventPass(TQDropEvent*);
  150. private slots:
  151. void slotRegionVisibilityChangedAt(unsigned int);
  152. void slotRegionBeginEndAddedRemoved(unsigned int);
  153. void slotCodeFoldingChanged();
  154. private:
  155. void moveChar( Bias bias, bool sel );
  156. void moveEdge( Bias bias, bool sel );
  157. KateTextCursor maxStartPos(bool changed = false);
  158. void scrollPos(KateTextCursor& c, bool force = false, bool calledExternally = false);
  159. void scrollLines( int lines, bool sel );
  160. uint linesDisplayed() const;
  161. int lineToY(uint viewLine) const;
  162. void updateSelection( const KateTextCursor&, bool keepSel );
  163. void updateCursor( const KateTextCursor& newCursor, bool force = false, bool center = false, bool calledExternally = false );
  164. void updateBracketMarks();
  165. void paintCursor();
  166. void updateMicroFocusHint();
  167. void placeCursor( const TQPoint& p, bool keepSelection = false, bool updateSelection = true );
  168. bool isTargetSelected( const TQPoint& p );
  169. void doDrag();
  170. KateView *m_view;
  171. KateDocument* m_doc;
  172. class KateIconBorder *leftBorder;
  173. int mouseX;
  174. int mouseY;
  175. int scrollX;
  176. int scrollY;
  177. TQt::tqCursorShape m_mouseCursor;
  178. KateSuperCursor cursor;
  179. KateTextCursor displayCursor;
  180. int cXPos;
  181. bool possibleTripleClick;
  182. // Bracket mark
  183. KateBracketRange bm;
  184. enum DragState { diNone, diPending, diDragging };
  185. struct _dragInfo {
  186. DragState state;
  187. TQPoint start;
  188. TQTextDrag* dragObject;
  189. } dragInfo;
  190. uint iconBorderHeight;
  191. //
  192. // line scrollbar + first visible (virtual) line in the current view
  193. //
  194. KateScrollBar *m_lineScroll;
  195. TQWidget* m_dummy;
  196. TQVBoxLayout* m_lineLayout;
  197. TQHBoxLayout* m_colLayout;
  198. // These are now cursors to account for word-wrap.
  199. KateSuperCursor m_startPos;
  200. // This is set to false on resize or scroll (other than that called by makeVisible),
  201. // so that makeVisible is again called when a key is pressed and the cursor is in the same spot
  202. bool m_madeVisible;
  203. bool m_shiftKeyPressed;
  204. // How many lines to should be kept visible above/below the cursor when possible
  205. void setAutoCenterLines(int viewLines, bool updateView = true);
  206. int m_autoCenterLines;
  207. int m_minLinesVisible;
  208. //
  209. // column scrollbar + x position
  210. //
  211. TQScrollBar *m_columnScroll;
  212. int m_startX;
  213. // has selection changed while your mouse or shift key is pressed
  214. bool m_selChangedByUser;
  215. KateTextCursor selectAnchor;
  216. enum SelectionMode { Default=0, Word, Line, Mouse }; ///< for drag selection. @since 2.3
  217. uint m_selectionMode;
  218. // when drag selecting after double/triple click, keep the initial selected
  219. // word/line independant of direction.
  220. // They get set in the event of a double click, and is used with mouse move + leftbutton
  221. KateTextCursor selStartCached;
  222. KateTextCursor selEndCached;
  223. //
  224. // lines Ranges, mostly useful to speedup + dyn. word wrap
  225. //
  226. TQMemArray<KateLineRange> lineRanges;
  227. // maximal lenght of textlines visible from given startLine
  228. int maxLen(uint startLine);
  229. // are we allowed to scroll columns?
  230. bool columnScrollingPossible ();
  231. // returns the maximum X value / col value a cursor can take for a specific line range
  232. int lineMaxCursorX(const KateLineRange& range);
  233. int lineMaxCol(const KateLineRange& range);
  234. // get the values for a specific range.
  235. // specify lastLine to get the next line of a range.
  236. KateLineRange range(int realLine, const KateLineRange* previous = 0L);
  237. KateLineRange currentRange();
  238. KateLineRange previousRange();
  239. KateLineRange nextRange();
  240. // Finds the lineRange currently occupied by the cursor.
  241. KateLineRange range(const KateTextCursor& realCursor);
  242. // Returns the lineRange of the specified realLine + viewLine.
  243. KateLineRange range(uint realLine, int viewLine);
  244. // find the view line of cursor c (0 = same line, 1 = down one, etc.)
  245. uint viewLine(const KateTextCursor& realCursor);
  246. // find the view line of the cursor, relative to the display (0 = top line of view, 1 = second line, etc.)
  247. // if limitToVisible is true, only lines which are currently visible will be searched for, and -1 returned if the line is not visible.
  248. int displayViewLine(const KateTextCursor& virtualCursor, bool limitToVisible = false);
  249. // find the index of the last view line for a specific line
  250. uint lastViewLine(uint realLine);
  251. // count the number of view lines for a real line
  252. uint viewLineCount(uint realLine);
  253. // find the cursor offset by (offset) view lines from a cursor.
  254. // when keepX is true, the column position will be calculated based on the x
  255. // position of the specified cursor.
  256. KateTextCursor viewLineOffset(const KateTextCursor& virtualCursor, int offset, bool keepX = false);
  257. // These variable holds the most recent maximum real & visible column number
  258. bool m_preserveMaxX;
  259. int m_currentMaxX;
  260. bool m_usePlainLines; // accept non-highlighted lines if this is set
  261. inline KateTextLine::Ptr textLine( int realLine )
  262. {
  263. if (m_usePlainLines)
  264. return m_doc->plainKateTextLine(realLine);
  265. else
  266. return m_doc->kateTextLine(realLine);
  267. }
  268. bool m_updatingView;
  269. int m_wrapChangeViewLine;
  270. KateTextCursor m_cachedMaxStartPos;
  271. private slots:
  272. void doDragScroll();
  273. void startDragScroll();
  274. void stopDragScroll();
  275. private:
  276. // Timers
  277. TQTimer m_dragScrollTimer;
  278. TQTimer m_scrollTimer;
  279. TQTimer m_cursorTimer;
  280. TQTimer m_textHintTimer;
  281. static const int scrollTime = 30;
  282. static const int scrollMargin = 16;
  283. private slots:
  284. void scrollTimeout ();
  285. void cursorTimeout ();
  286. void textHintTimeout ();
  287. //TextHint
  288. public:
  289. void enableTextHints(int timeout);
  290. void disableTextHints();
  291. private:
  292. bool m_textHintEnabled;
  293. int m_textHintTimeout;
  294. int m_textHintMouseX;
  295. int m_textHintMouseY;
  296. /**
  297. * IM input stuff
  298. */
  299. protected:
  300. void imStartEvent( TQIMEvent *e );
  301. void imComposeEvent( TQIMEvent *e );
  302. void imEndEvent( TQIMEvent *e );
  303. private:
  304. int m_imPreeditStartLine;
  305. int m_imPreeditStart;
  306. int m_imPreeditLength;
  307. int m_imPreeditSelStart;
  308. };
  309. #endif
  310. // kate: space-indent on; indent-width 2; replace-tabs on;