1
/* This file is part of the KDE libraries
2
Copyright (C) 2002-2007 Hamish Rodda <rodda@kde.org>
3
Copyright (C) 2002 John Firebaugh <jfirebaugh@kde.org>
4
Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org>
5
Copyright (C) 2002 Christoph Cullmann <cullmann@kde.org>
6
Copyright (C) 2007 Mirko Stocker <me@misto.ch>
9
KWriteView : Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
11
This library is free software; you can redistribute it and/or
12
modify it under the terms of the GNU Library General Public
13
License version 2 as published by the Free Software Foundation.
15
This library is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
Library General Public License for more details.
20
You should have received a copy of the GNU Library General Public License
21
along with this library; see the file COPYING.LIB. If not, write to
22
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23
Boston, MA 02110-1301, USA.
26
#ifndef _KATE_VIEW_INTERNAL_
27
#define _KATE_VIEW_INTERNAL_
29
#include <ktexteditor/attribute.h>
31
#include "katetextcursor.h"
32
#include "katelinelayout.h"
33
#include "katetextline.h"
34
#include "katedocument.h"
36
#include "katerenderer.h"
38
#include <QtCore/QPoint>
39
#include <QtCore/QTimer>
40
#include <QtGui/QDrag>
41
#include <QtGui/QWidget>
42
#include <QtCore/QSet>
43
#include <QtCore/QPointer>
45
namespace KTextEditor {
52
class KateTextAnimation;
54
class KateViInputModeManager;
58
class KateViewInternal : public QWidget
62
friend class KateView;
63
friend class KateIconBorder;
64
friend class KateScrollBar;
65
friend class CalculatingCursor;
66
friend class BoundedCursor;
67
friend class WrappingCursor;
68
friend class KateViModeBase;
79
KateViewInternal ( KateView *view );
81
KateView *view() const { return m_view; }
86
void editEnd (int editTagLineStart, int editTagLineEnd, bool tagFrom);
88
void editSetCursor (const KTextEditor::Cursor &cursor);
91
uint editSessionNumber;
93
KTextEditor::Cursor editOldCursor;
94
KTextEditor::Range editOldSelection;
97
//BEGIN TAG & CLEAR & UPDATE STUFF
99
bool tagLine (const KTextEditor::Cursor& virtualCursor);
101
bool tagLines (int start, int end, bool realLines = false);
102
// cursors not const references as they are manipulated within
103
bool tagLines (KTextEditor::Cursor start, KTextEditor::Cursor end, bool realCursors = false);
105
bool tagRange(const KTextEditor::Range& range, bool realCursors);
115
// Updates the view and requests a redraw.
116
void updateView (bool changed = false, int viewLinesScrolled = 0);
119
// Actually performs the updating, but doesn't call update().
120
void doUpdateView(bool changed = false, int viewLinesScrolled = 0);
121
void makeVisible (const KTextEditor::Cursor& c, int endCol, bool force = false, bool center = false, bool calledExternally = false);
124
// Start Position is a virtual cursor
125
KTextEditor::Cursor startPos() const { return m_startPos; }
126
int startLine () const { return m_startPos.line(); }
127
int startX () const { return m_startX; }
129
KTextEditor::Cursor endPos () const;
130
int endLine () const;
132
KateTextLayout yToKateTextLayout(int y) const;
134
void prepareForDynWrapChange();
135
void dynWrapChanged();
138
void slotIncFontSizes();
139
void slotDecFontSizes();
142
void scrollLines(int line); // connected to the sliderMoved of the m_lineScroll
143
void scrollViewLines(int offset);
144
void scrollAction(int action);
145
void scrollNextPage();
146
void scrollPrevPage();
147
void scrollPrevLine();
148
void scrollNextLine();
149
void scrollColumns (int x); // connected to the valueChanged of the m_columnScroll
150
void viewSelectionChanged ();
154
void doSmartNewline();
159
void doDeletePrevWord();
160
void doDeleteNextWord();
163
* Set the caret's style.
164
* The caret can be a box or a line; see the documentation
165
* of KateRenderer::caretStyles for other options.
166
* @param style the caret style
167
* @param repaint whether to update the caret instantly.
168
* This also resets the caret's timer.
170
void setCaretStyle( KateRenderer::caretStyles style, bool repaint = false );
171
void cursorPrevChar(bool sel=false);
172
void cursorNextChar(bool sel=false);
173
void wordPrev(bool sel=false);
174
void wordNext(bool sel=false);
175
void home(bool sel=false);
176
void end(bool sel=false);
177
void cursorUp(bool sel=false);
178
void cursorDown(bool sel=false);
179
void cursorToMatchingBracket(bool sel=false);
182
void topOfView(bool sel=false);
183
void bottomOfView(bool sel=false);
184
void pageUp(bool sel=false, bool half=false);
185
void pageDown(bool sel=false, bool half=false);
186
void top(bool sel=false);
187
void bottom(bool sel=false);
188
void top_home(bool sel=false);
189
void bottom_end(bool sel=false);
191
KTextEditor::Cursor getCursor() const { return m_cursor; }
192
KTextEditor::Cursor getMouse() const { return m_mouse; }
194
QPoint cursorToCoordinate(const KTextEditor::Cursor& cursor, bool realCursor = true, bool includeBorder = true) const;
195
// by default, works on coordinates of the whole widget, eg. offsetted by the border
196
KTextEditor::Cursor coordinatesToCursor(const QPoint& coord, bool includeBorder = true) const;
197
QPoint cursorCoordinates(bool includeBorder = true) const;
198
KTextEditor::Cursor findMatchingBracket();
200
// EVENT HANDLING STUFF - IMPORTANT
202
void fixDropEvent(QDropEvent *event);
204
virtual void hideEvent(QHideEvent* e);
205
virtual void paintEvent(QPaintEvent *e);
206
virtual bool eventFilter( QObject *obj, QEvent *e );
207
virtual void keyPressEvent( QKeyEvent* );
208
virtual void keyReleaseEvent( QKeyEvent* );
209
virtual void resizeEvent( QResizeEvent* );
210
virtual void mousePressEvent( QMouseEvent* );
211
virtual void mouseDoubleClickEvent( QMouseEvent* );
212
virtual void mouseReleaseEvent( QMouseEvent* );
213
virtual void mouseMoveEvent( QMouseEvent* );
214
virtual void leaveEvent( QEvent* );
215
virtual void dragEnterEvent( QDragEnterEvent* );
216
virtual void dragMoveEvent( QDragMoveEvent* );
217
virtual void dropEvent( QDropEvent* );
218
virtual void showEvent ( QShowEvent *);
219
virtual void wheelEvent(QWheelEvent* e);
220
virtual void focusInEvent (QFocusEvent *);
221
virtual void focusOutEvent (QFocusEvent *);
222
virtual void inputMethodEvent(QInputMethodEvent* e);
224
void contextMenuEvent ( QContextMenuEvent * e );
227
void tripleClickTimeout();
230
// emitted when KateViewInternal is not handling its own URI drops
231
void dropEventPass(QDropEvent*);
234
void slotRegionVisibilityChanged();
235
void slotRegionBeginEndAddedRemoved(unsigned int);
238
void moveChar( Bias bias, bool sel );
239
void moveEdge( Bias bias, bool sel );
240
KTextEditor::Cursor maxStartPos(bool changed = false);
241
void scrollPos(KTextEditor::Cursor& c, bool force = false, bool calledExternally = false);
242
void scrollLines( int lines, bool sel );
244
int linesDisplayed() const;
246
int lineToY(int viewLine) const;
248
void updateSelection( const KTextEditor::Cursor&, bool keepSel );
249
void setSelection( const KTextEditor::Range& );
250
void moveCursorToSelectionEdge();
251
void updateCursor( const KTextEditor::Cursor& newCursor, bool force = false, bool center = false, bool calledExternally = false );
252
void updateBracketMarks();
256
void placeCursor( const QPoint& p, bool keepSelection = false, bool updateSelection = true );
257
bool isTargetSelected( const QPoint& p );
258
//Returns whether the given range affects the area currently visible in the view
259
bool rangeAffectsView(const KTextEditor::Range& range, bool realCursors) const;
263
KateRenderer* renderer() const;
266
class KateIconBorder *m_leftBorder;
273
Qt::CursorShape m_mouseCursor;
275
Kate::TextCursor m_cursor;
276
KTextEditor::Cursor m_mouse;
277
KTextEditor::Cursor m_displayCursor;
279
bool m_possibleTripleClick;
281
//Whether the current completion-item was expanded while the last press of ALT
282
bool m_completionItemExpanded;
285
// Bracket mark and corresponding decorative ranges
286
KTextEditor::MovingRange *m_bm, *m_bmStart, *m_bmEnd;
287
KTextEditor::MovingCursor * m_bmLastFlashPos;
288
void updateBracketMarkAttributes();
290
enum DragState { diNone, diPending, diDragging };
299
// line scrollbar + first visible (virtual) line in the current view
301
KateScrollBar *m_lineScroll;
304
// These are now cursors to account for word-wrap.
305
// Start Position is a virtual cursor
306
Kate::TextCursor m_startPos;
307
//Count of lines that are visible behind m_startPos.
308
//This does not respect dynamic word wrap, so take it as an approximation.
309
uint m_visibleLineCount;
311
// This is set to false on resize or scroll (other than that called by makeVisible),
312
// so that makeVisible is again called when a key is pressed and the cursor is in the same spot
314
bool m_shiftKeyPressed;
316
// How many lines to should be kept visible above/below the cursor when possible
317
void setAutoCenterLines(int viewLines, bool updateView = true);
318
int m_autoCenterLines;
319
int m_minLinesVisible;
322
// column scrollbar + x position
324
QScrollBar *m_columnScroll;
327
// has selection changed while your mouse or shift key is pressed
328
bool m_selChangedByUser;
329
KTextEditor::Cursor m_selectAnchor;
331
enum SelectionMode { Default=0, Mouse, Word, Line }; ///< for drag selection.
332
uint m_selectionMode;
333
// when drag selecting after double/triple click, keep the initial selected
334
// word/line independent of direction.
335
// They get set in the event of a double click, and is used with mouse move + leftbutton
336
KTextEditor::Range m_selectionCached;
338
// maximal length of textlines visible from given startLine
339
int maxLen(int startLine);
341
// are we allowed to scroll columns?
342
bool columnScrollingPossible ();
344
// returns the maximum X value / col value a cursor can take for a specific line range
345
int lineMaxCursorX(const KateTextLayout& line);
346
int lineMaxCol(const KateTextLayout& line);
348
class KateLayoutCache* cache() const;
349
KateLayoutCache* m_layoutCache;
351
// convenience methods
352
KateTextLayout currentLayout() const;
353
KateTextLayout previousLayout() const;
354
KateTextLayout nextLayout() const;
356
// find the cursor offset by (offset) view lines from a cursor.
357
// when keepX is true, the column position will be calculated based on the x
358
// position of the specified cursor.
359
KTextEditor::Cursor viewLineOffset(const KTextEditor::Cursor& virtualCursor, int offset, bool keepX = false);
361
KTextEditor::Cursor toRealCursor(const KTextEditor::Cursor& virtualCursor) const;
362
KTextEditor::Cursor toVirtualCursor(const KTextEditor::Cursor& realCursor) const;
364
// These variable holds the most recent maximum real & visible column number
368
int m_wrapChangeViewLine;
369
KTextEditor::Cursor m_cachedMaxStartPos;
372
// implementation details for KTextEditor::FlashTextInterface
375
void flashChar(const KTextEditor::Cursor & pos, KTextEditor::Attribute::Ptr attribute);
377
QPointer<KateTextAnimation> m_textAnimation;
381
void startDragScroll();
382
void stopDragScroll();
386
QTimer m_dragScrollTimer;
387
QTimer m_scrollTimer;
388
QTimer m_cursorTimer;
389
QTimer m_textHintTimer;
391
static const int s_scrollTime = 30;
392
static const int s_scrollMargin = 16;
395
void scrollTimeout ();
396
void cursorTimeout ();
397
void textHintTimeout ();
401
void enableTextHints(int timeout);
402
void disableTextHints();
405
bool m_textHintEnabled;
406
int m_textHintTimeout;
407
QPoint m_textHintPos;
413
virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
416
KTextEditor::MovingRange *m_imPreeditRange;
417
QList<KTextEditor::MovingRange *> m_imPreeditRangeChildren;
424
inline KateDocument *doc() { return m_view->doc(); }
425
inline KateDocument *doc() const { return m_view->doc(); }
430
bool m_viInputModeStealKeys;
431
bool m_viRelLineNumbers;
434
* returns the current vi mode
436
ViMode getCurrentViMode();
439
* an instance of KateViInputModeManager. used for interacting with the vi input mode when
442
KateViInputModeManager* m_viInputModeManager;
445
* @return a pointer to a KateViInputModeManager
447
KateViInputModeManager* getViInputModeManager();
450
* @return a pointer to a new KateViInputModeManager
452
KateViInputModeManager* resetViInputModeManager();
457
// kate: space-indent on; indent-width 2; replace-tabs on;