00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
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
00079
00080
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
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);
00117 void scrollViewLines(int offset);
00118 void scrollNextPage();
00119 void scrollPrevPage();
00120 void scrollPrevLine();
00121 void scrollNextLine();
00122 void scrollColumns (int x);
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
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
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 moveWord( 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 QPoint& p, bool keepSelection = false, bool updateSelection = true );
00212 bool isTargetSelected( const QPoint& 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 Qt::CursorShape m_mouseCursor;
00226
00227 KateSuperCursor cursor;
00228 KateTextCursor displayCursor;
00229 int cXPos;
00230
00231 bool possibleTripleClick;
00232
00233
00234 KateBracketRange bm;
00235
00236 enum DragState { diNone, diPending, diDragging };
00237
00238 struct _dragInfo {
00239 DragState state;
00240 QPoint start;
00241 QTextDrag* dragObject;
00242 } dragInfo;
00243
00244 uint iconBorderHeight;
00245
00246
00247
00248
00249 KateScrollBar *m_lineScroll;
00250 QWidget* m_dummy;
00251 QVBoxLayout* m_lineLayout;
00252 QHBoxLayout* m_colLayout;
00253
00254
00255 KateSuperCursor m_startPos;
00256
00257
00258
00259 bool m_madeVisible;
00260 bool m_shiftKeyPressed;
00261
00262
00263 void setAutoCenterLines(int viewLines, bool updateView = true);
00264 int m_autoCenterLines;
00265 int m_minLinesVisible;
00266
00267
00268
00269
00270 QScrollBar *m_columnScroll;
00271 int m_startX;
00272 int m_oldStartX;
00273
00274
00275 bool m_selChangedByUser;
00276 KateTextCursor selectAnchor;
00277
00278 enum SelectionMode { Default=0, Word, Line };
00279 uint m_selectionMode;
00280
00281
00282
00283 KateTextCursor selStartCached;
00284 KateTextCursor selEndCached;
00285
00286
00287
00288
00289 QMemArray<KateLineRange> lineRanges;
00290
00291
00292 int maxLen(uint startLine);
00293
00294
00295 bool columnScrollingPossible ();
00296
00297
00298 int lineMaxCursorX(const KateLineRange& range);
00299 int lineMaxCol(const KateLineRange& range);
00300
00301
00302
00303 KateLineRange range(int realLine, const KateLineRange* previous = 0L);
00304
00305 KateLineRange currentRange();
00306 KateLineRange previousRange();
00307 KateLineRange nextRange();
00308
00309
00310 KateLineRange range(const KateTextCursor& realCursor);
00311
00312
00313 KateLineRange range(uint realLine, int viewLine);
00314
00315
00316 uint viewLine(const KateTextCursor& realCursor);
00317
00318
00319
00320 int displayViewLine(const KateTextCursor& virtualCursor, bool limitToVisible = false);
00321
00322
00323 uint lastViewLine(uint realLine);
00324
00325
00326 uint viewLineCount(uint realLine);
00327
00328
00329
00330
00331 KateTextCursor viewLineOffset(const KateTextCursor& virtualCursor, int offset, bool keepX = false);
00332
00333
00334 bool m_preserveMaxX;
00335 int m_currentMaxX;
00336
00337 bool m_usePlainLines;
00338
00339 inline KateTextLine::Ptr textLine( int realLine )
00340 {
00341 if (m_usePlainLines)
00342 return m_doc->plainKateTextLine(realLine);
00343 else
00344 return m_doc->kateTextLine(realLine);
00345 }
00346
00347 bool m_updatingView;
00348 int m_wrapChangeViewLine;
00349 KateTextCursor m_cachedMaxStartPos;
00350
00351 private slots:
00352 void doDragScroll();
00353 void startDragScroll();
00354 void stopDragScroll();
00355
00356 private:
00357
00358 QTimer m_dragScrollTimer;
00359 QTimer m_scrollTimer;
00360 QTimer m_cursorTimer;
00361 QTimer m_textHintTimer;
00362
00363 static const int scrollTime = 30;
00364 static const int scrollMargin = 16;
00365
00366
00367
00368 bool m_maximizeLineScroll;
00369
00370 private slots:
00371 void scrollTimeout ();
00372 void cursorTimeout ();
00373 void textHintTimeout ();
00374
00375
00376 public:
00377 void enableTextHints(int timeout);
00378 void disableTextHints();
00379
00380 private:
00381 bool m_textHintEnabled;
00382 int m_textHintTimeout;
00383 int m_textHintMouseX;
00384 int m_textHintMouseY;
00385
00389 protected:
00390 void imStartEvent( QIMEvent *e );
00391 void imComposeEvent( QIMEvent *e );
00392 void imEndEvent( QIMEvent *e );
00393
00394 private:
00395 int m_imPreeditStartLine;
00396 int m_imPreeditStart;
00397 int m_imPreeditLength;
00398 int m_imPreeditSelStart;
00399 };
00400
00401 #endif
00402
00403