]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/modules/lseditor/tdefs.h
code cleanup
[wxWidgets.git] / utils / wxPython / modules / lseditor / tdefs.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: No names yet.
3 // Purpose: Contrib. demo
4 // Author: Aleksandras Gluchovas
5 // Modified by:
6 // Created: 03/04/1999
7 // RCS-ID: $Id$
8 // Copyright: (c) Aleskandars Gluchovas
9 // Licence: GNU General Public License
10 /////////////////////////////////////////////////////////////////////////////
11 //
12 // This program is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation; either version 2 of the License, or
15 // (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 /////////////////////////////////////////////////////////////////////////////
26
27
28
29 #ifndef __TDEFS_G__
30 #define __TDEFS_G__
31
32 // should be compiled with wxSTL-v.1.2 (or higher)
33
34 #include "wxstldefs.h"
35
36 #if defined( wxUSE_TEMPLATE_STL )
37 #include <vector>
38 #include <list>
39 #else
40 #include "wxstlvec.h"
41 #include "wxstllst.h"
42 #endif
43
44 #include "wx/window.h"
45 #include "wx/scrolbar.h"
46
47 #include "sourcepainter.h"
48
49 #define NPOS ((size_t)(-1))
50
51 class wxTextEditorModel;
52 class wxTextEditorView;
53
54 /*
55 * class represents column-row position in the source text,
56 * may refere to the column past the end-of-line,
57 * but should not point past the last-line in the text
58 */
59
60 class TPosition
61 {
62 public:
63 size_t mRow;
64 size_t mCol;
65
66 inline TPosition() : mRow(0), mCol(0) {}
67
68 inline TPosition( size_t row, size_t col )
69
70 : mRow( row ), mCol( col ) {}
71
72 inline bool operator>( const TPosition& rhs ) const
73 {
74 if ( mRow == rhs.mRow ) return mCol > rhs.mCol;
75 else
76 return mRow > rhs.mRow;
77 }
78
79 inline bool operator<( const TPosition& rhs ) const
80 {
81 if ( mRow == rhs.mRow ) return mCol < rhs.mCol;
82 else
83 return mRow < rhs.mRow;
84 }
85 };
86
87 class TRange
88 {
89 public:
90 TPosition mFrom;
91 TPosition mTill;
92
93 TRange() {}
94 TRange( const TPosition& from, const TPosition& till )
95 : mFrom( from ), mTill( till )
96 {}
97 };
98
99 inline bool operator==( const TPosition& lhs, const TPosition& rhs )
100 {
101 return lhs.mRow == rhs.mRow && lhs.mCol == rhs.mCol;
102 }
103
104 // FOR NOW:: bigger ones...
105
106 #define MAX_BLOCK_LEN (1024*164)
107 #define BALANCED_BLOCK_LEN (1024*152)
108 #define FILLED_BLOCK_LEN (1024*148)
109
110 // FOR NOW::
111 #define T_ASSERT( x ) if ( !(x) ) throw;
112
113 // to speed up debug v. :
114
115 #define is_eol_char( ch ) ( ch == (char)10 )
116 #define is_DOS_eol_char( ch ) ( ch == (char)13 )
117
118 // the target-platfrom eol-marking is selected when
119 // new text document is created or auto-detection
120 // failed to determine the text-format (e.g. no EOLs found at all)
121
122 #if defined(__WINDOWS__) || defined(__WXMSW__)
123
124 #define IS_UNIX_TEXT_BY_DEFAULT FALSE
125 #else
126 #define IS_UNIX_TEXT_BY_DEFAULT TRUE
127 #endif
128
129 //inline bool is_eol_char( char ch ) { return ch == 10 && ch == 13 ; }
130
131 /*
132 * Class contains single fragment of the source text, which
133 * may grow or shrink in the process of editing. Blocks always
134 * start at the begining of the line and end at eol, i.e. lines
135 * are not broken among blocks
136 */
137
138 class TBlock
139 {
140 public:
141 char mBuf[MAX_BLOCK_LEN];
142 size_t mTextLen;
143 size_t mRowCount;
144
145 TBlock() : mTextLen(0), mRowCount(0) { mBuf[0] = '\0'; }
146
147 void RecalcBlockProperties();
148
149 bool operator==( const TBlock& blk ) const { return this == &blk; }
150
151 bool operator!=( const TBlock& blk ) const { return this != &blk; }
152
153 bool operator<( const TBlock& blk ) const { return TRUE; }
154
155 bool operator>( const TBlock& blk ) const { return FALSE; }
156 };
157
158 /*
159 * captures info about mutable command
160 */
161
162 class TCommand
163 {
164 public:
165
166 TCommand() : mType(-1) {}
167 TCommand( int type ) : mType( type ) {}
168 ~TCommand() {}
169
170 int mType;
171 char* mData;
172 size_t mDataLen;
173
174 TRange mRange;
175
176 // positions of cursor before and after executions of this command
177 TPosition mPrePos;
178 TPosition mPostPos;
179
180 };
181
182 enum TEXT_EDITOR_COMMAND
183 {
184 TCMD_INSERT,
185 TCMD_DELETE
186 };
187
188 enum TEXT_CHANGE_TYPE
189 {
190 CT_MODIFIED,
191 CT_DELETED,
192 CT_INSERTED
193 };
194
195 class wxTextEditorView;
196
197 // STL-list is used for managing blocks, since it's alg. collects
198 // removed elements into a free-list, from which they
199 // can be reclaimed later, that way heap-fragmentation may be reduced
200
201 #if defined( wxUSE_TEMPLATE_STL )
202 typedef list<TBlock> TBlockListT;
203 typedef vector<TCommand*> TCommandListT;
204 typedef vector<wxTextEditorView*> TextViewListT;
205 #else
206 typedef WXSTL_LIST( TBlock ) TBlockListT;
207
208 typedef TCommand* TCommandPtrT;
209 typedef WXSTL_VECTOR_SHALLOW_COPY( TCommandPtrT ) TCommandListT;
210
211 typedef wxTextEditorView* TextViewPtrT;
212 typedef WXSTL_VECTOR_SHALLOW_COPY( TextViewPtrT ) TextViewListT;
213 #endif
214
215 typedef TBlockListT::iterator TBlockIteratorT;
216
217
218 /*
219 * class shields the higher-level operations from direct access
220 * to blocks of fragmented in-memory buffers
221 */
222
223 class TTextIterator
224 {
225 public:
226 TBlockIteratorT mBlockIter;
227 TBlockIteratorT mEndOfListIter;
228 TPosition mPos;
229
230 size_t mActualRow;
231 size_t mFirstRowInBlock;
232
233 char* mpCurRowStart;
234 bool mIsEof;
235
236 public:
237 TTextIterator();
238
239 char GetChar();
240 bool IsEol();
241 bool IsEof();
242 bool IsLastLine();
243 int GetDistFromEol();
244
245 void NextChar();
246 void PreviousChar();
247 void NextWord();
248 void PreviousWord();
249 void ToEndOfLine();
250 void ToStartOfLine();
251
252 bool IsInLastBlock();
253
254 // accesors
255
256 size_t GetLineLen();
257 TPosition GetPosition();
258
259 char* GetClosestPos();
260 char* GotoClosestPos();
261
262 inline char* GetBlockStart() { return (*mBlockIter).mBuf; }
263 inline char* GetBlockEnd() { return (*mBlockIter).mBuf + (*mBlockIter).mTextLen; }
264
265 bool DetectUnixText();
266
267 // adjust this member to add specific separators,
268 // the default value is : ",.()[]\t\\+-*/|=<>:;\t\n~?!%"
269
270 static string mSeparators;
271
272 static bool IsSeparator( char ch );
273 };
274
275 class wxTextEditorModel;
276
277 class TTextChangeListenerBase
278 {
279 public:
280 virtual void OnTextChanged( wxTextEditorModel* pModel, size_t atRow, size_t nRows, TEXT_CHANGE_TYPE ct ) = 0;
281 };
282
283 class TCppJavaHighlightListener : public TTextChangeListenerBase
284 {
285 protected:
286 wxTextEditorModel* mpModel; // is set up temporarely
287
288 enum { IN_COMMENT_STATE, OUT_OF_COMMENT_STATE };
289
290 public:
291 virtual void OnTextChanged( wxTextEditorModel* pModel, size_t atRow, size_t nRows, TEXT_CHANGE_TYPE ct );
292 };
293
294
295 /*
296 * Base class for user-defined "bookmarks" within the source-text, bookmarks
297 * are automatically repositioned or deleted as the text is edited. Class
298 * can be subclassed to add pin-specific data (e.g. breakpoint information)
299 */
300
301 class TPinBase
302 {
303 public:
304 int mTypeCode;
305 size_t mRow;
306
307 public:
308 TPinBase()
309 : mTypeCode(-1), mRow(NPOS) {}
310
311 TPinBase( int typeCode, size_t row )
312 : mTypeCode( typeCode ), mRow( row ) {}
313
314 size_t GetRow() { return mRow; }
315 int GetTypeCode() { return mTypeCode; }
316
317 virtual ~TPinBase() {}
318 };
319
320 // "recommened" type-code ranges for custom pins
321
322 #define HIHGLIGHTING_PINS_TC_STARRT 50
323 #define OTHER_PINS_TC_START 100
324
325 inline bool operator<( const TPinBase& lhs, TPinBase& rhs )
326
327 { return lhs.mRow < rhs.mRow; }
328
329 #if defined( wxUSE_TEMPLATE_STL )
330
331 typedef vector<TPinBase*> PinListT;
332 typedef vector<TTextChangeListenerBase*> ChangeListenerListT;
333 #else
334 typedef TPinBase* TPinBasePtrT;
335 typedef WXSTL_VECTOR_SHALLOW_COPY( TPinBasePtrT ) PinListT;
336
337 typedef TTextChangeListenerBase* TTextChangeListenerBasePtrT;
338 typedef WXSTL_VECTOR_SHALLOW_COPY( TTextChangeListenerBasePtrT ) ChangeListenerListT;
339 #endif
340
341 /* OLD STUFF::
342
343 struct TPinBaseCompareFunctor
344 {
345 inline int operator()(const TPinBasePtrT* x, const TPinBasePtrT*& y ) const
346 {
347 return x->mLine < y->mLine;
348 }
349 };
350
351 typedef WXSTL_MULTIMAP( TPinBasePtrT, TPinBasePtrT, TPinBaseCompareFunctor ) PinMapT;
352 typedef PinMapT::iterator PinIteratorT;
353 */
354
355 /*
356 * Class manages access and manpulation of in-memory text. Can
357 * be accessed by multiple views, only one of which can be active
358 * at a time.
359 */
360
361 class wxTextEditorModel
362 {
363 protected:
364 TBlockListT mBlocks;
365
366 TCommandListT mCommands;
367 size_t mCurCommand;
368
369 TextViewListT mViews;
370 wxTextEditorView* mpActiveView;
371
372 PinListT mPins;
373 bool mIsUnixText;
374
375 ChangeListenerListT mChangeListeners;
376
377 public:
378 /*** public properties ***/
379
380 bool mTextChanged;
381 size_t mChangedFromRow;
382 size_t mChangedTillRow;
383
384 bool mWasChanged; // TRUE, if any content has been changed
385
386 TPosition mCursorPos;
387
388 TPosition mPrevSelectionStart;
389 TPosition mPrevSelectionEnd;
390 TPosition mPrevCursorPos;
391
392 TPosition mSelectionStart;
393 TPosition mSelectionEnd;
394 size_t mRowsPerPage;
395
396 bool mIsReadOnly; // default: FALSE
397 bool mIsModified;
398 bool mInsertMode; // default: TRUE
399 bool mAutoIndentMode; // default: TRUE
400 bool mSmartIndentMode; // default: TRUE
401
402 bool mIsSelectionEditMode; // default: TRUE
403 size_t mTabSize; // default: 4
404
405 StrListT mSearchExprList;
406 string mLastFindExpr;
407
408 bool mCheckPointDestroyed;
409 size_t mCheckPointCmdNo;
410
411 protected:
412
413 size_t GetLineCountInRange( char* from, char* till );
414
415 // two lowest-level operations
416 void DoInsertText ( const TPosition& pos, char* text, size_t len, TRange& actualRange );
417 void DoDeleteRange( const TPosition& from, const TPosition& till, TRange& actualRange );
418
419 void DoExecuteNewCommand( TCommand& cmd );
420
421 void DoReexecuteCommand( TCommand& cmd );
422 void DoUnexecuteCommand( TCommand& cmd );
423
424
425 void ExecuteCommand( TCommand* pCmd );
426
427 // to methods enabling grouping of undo-able commands
428 bool CanPrependCommand( TCommand* pCmd );
429 void PrependCommand( TCommand* pCmd );
430
431 void SetPostPos( const TPosition& pos );
432
433 void UndoImpl();
434 void RedoImpl();
435
436 void StartBatch();
437 void FinishBatch();
438
439 void CheckSelection();
440 void TrackSelection();
441
442 void NotifyView();
443 void NotifyAllViews();
444
445 void NotifyTextChanged( size_t atRow, size_t nRows, TEXT_CHANGE_TYPE ct );
446 void NotifyTextChanged( TPosition from, TPosition till, TEXT_CHANGE_TYPE ct );
447
448 void ArrangePositions( TPosition& upper, TPosition& lower );
449 void ArrangePositions( size_t& upper, size_t& lower );
450
451 void MergeChange( size_t fromRow, size_t nRows );
452
453 void PrepreForCommand();
454
455 size_t TextToScrColumn( const TPosition& pos );
456 size_t ScrToTextColumn( TPosition pos );
457
458 void DoMoveCursor( int rows, int cols );
459
460 public:
461 wxTextEditorModel();
462 virtual ~wxTextEditorModel();
463
464 // utilities
465
466 char* AllocCharacters( size_t n );
467 char* AllocCharacters( size_t n, const char* srcBuf );
468 void FreeCharacters( char* buf );
469
470 void DeleteSelection();
471 TTextIterator CreateIterator( const TPosition& pos );
472
473 void DeleteRange( const TPosition& from, const TPosition& till );
474 void InsertText( const TPosition& pos, const char* text, size_t len );
475 void GetTextFromRange( const TPosition& from, const TPosition& till, char** text, size_t& textLen );
476 void LoadTextFromFile( const wxString& fname );
477 void SaveTextToFile( const wxString& fname );
478 void ResetSelection();
479 void ClearUndoBuffer();
480
481
482 void DeleteAllText();
483 void GetAllText( char** text, size_t& textLen );
484
485 void SetSelectionEditMode( bool editIsOn );
486
487 /*** user-level commands ***/
488
489 // mutable (undoable) commands
490
491 void OnInsertChar( char ch );
492 void OnDelete();
493 void OnDeleteBack();
494 void OnDeleteLine();
495
496 void OnShiftSelectionIndent( bool left );
497
498 // clipboard functions
499
500 void OnCopy();
501 void OnPaste();
502 void OnCut();
503 bool CanCopy();
504 bool CanPaste();
505
506 // undo-redo
507
508 bool CanUndo();
509 bool CanRedo();
510 void OnUndo();
511 void OnRedo();
512
513 // imutable commands
514
515 void OnMoveLeft();
516 void OnMoveRight();
517 void OnMoveUp();
518 void OnMoveDown();
519
520 void OnWordLeft();
521 void OnWordRight();
522
523 void OnMoveToPosition( const TPosition& pos );
524
525 void OnEndOfLine();
526 void OnStartOfLine();
527 void OnPageUp();
528 void OnPageDown();
529 void OnSlideUp();
530 void OnSlideDown();
531 void OnStartOfText();
532 void OnEndOfText();
533
534 void OnSelectWord();
535 void OnSelectAll();
536
537 // bookmarks
538
539 void OnToggleBookmark();
540 void OnNextBookmark();
541 void OnPreviousBookmark();
542
543 // search
544
545 bool OnFind();
546 bool OnFindNext();
547 bool OnFindPrevious();
548 void OnGotoLine( int line, int col );
549 void OnGotoLine();
550
551 // status
552
553 bool IsReadOnly();
554 bool IsModified();
555 bool IsInsertMode();
556
557 // check-pointin
558
559 void SetCheckpoint();
560 bool CheckpointModified();
561
562 // accessors
563
564 TPosition GetStartOfSelection();
565 TPosition GetEndOfSelection();
566 TPosition GetCursor();
567
568 size_t GetTotalRowCount();
569 bool SelectionIsEmpty();
570 bool IsLastLine( const TPosition& pos );
571
572 bool IsUnixText() { return mIsUnixText; }
573
574 void GetSelection( char** text, size_t& textLen );
575
576 void SetStartOfSelection( const TPosition& pos );
577 void SetEndOfSelection( const TPosition& pos );
578 void SetCursor( const TPosition& pos );
579
580 void AddView( wxTextEditorView* pView );
581 void RemoveView( wxTextEditorView* pView );
582 void SetActiveView( wxTextEditorView* pView );
583 wxTextEditorView* GetActiveView();
584
585 void SetRowsPerPage( size_t n );
586
587 void AddPin( TPinBase* pPin );
588 PinListT& GetPins();
589
590 // returns NPOS, if non
591 size_t FindFirstPinInRange( size_t fromRow, size_t tillRow );
592 size_t FindNextPinFrom( size_t fromRow );
593 size_t FindPreviousPinFrom( size_t fromRow );
594
595 size_t GetPinNoAt( size_t row, int pinTypeCode );
596 TPinBase* GetPinAt( size_t row, int pinTypeCode );
597 void RemovePinAt( size_t row, int pinTypeCode );
598
599 void AddChangeListener( TTextChangeListenerBase* pListener );
600 };
601
602 class TCursorTimer;
603 class wxTextEditorView;
604
605 class TPinPainterBase : public wxObject
606 {
607 public:
608 int mPinTypeCode;
609
610 public:
611 TPinPainterBase( int pinTc ) : mPinTypeCode( pinTc ) {}
612 TPinPainterBase() : mPinTypeCode( -1 ) {}
613
614 inline int GetPinTypeCode() { return mPinTypeCode; }
615
616 virtual void DrawPin( TPinBase* pPin, wxTextEditorView& view, wxDC& dc,
617 const wxPoint& pos, const wxSize& dim ) = 0;
618 };
619
620 /*
621 * a couple very common ping objects/painters
622 */
623
624 #define BOOKMARK_PIN_TC (OTHER_PINS_TC_START)
625 #define BRKPOINT_PIN_TC (BOOKMARK_PIN_TC + 1)
626
627 class TBookmarkPainter : public TPinPainterBase
628 {
629 protected:
630 wxBrush mBkBrush;
631
632 public:
633 TBookmarkPainter();
634
635 virtual void DrawPin( TPinBase* pPin, wxTextEditorView& view, wxDC& dc,
636 const wxPoint& pos, const wxSize& dim );
637 };
638
639 class TBookmarkPin : public TPinBase
640 {
641 public:
642 TBookmarkPin( size_t row )
643 : TPinBase( BOOKMARK_PIN_TC, row )
644 {}
645
646 static int GetPinTypeCode() { return BOOKMARK_PIN_TC; }
647 };
648
649 class TBreakpointPainter : public TPinPainterBase
650 {
651 protected:
652 wxBrush mBkBrush;
653
654 public:
655 TBreakpointPainter();
656
657 virtual void DrawPin( TPinBase* pPin, wxTextEditorView& view, wxDC& dc,
658 const wxPoint& pos, const wxSize& dim );
659 };
660
661 class TBreakpointPin : public TPinBase
662 {
663 public:
664 TBreakpointPin( size_t row )
665 : TPinBase( BRKPOINT_PIN_TC, row )
666 {}
667
668 static int GetPinTypeCode() { return BRKPOINT_PIN_TC; }
669 };
670
671
672 #if defined( wxUSE_TEMPLATE_STL )
673 typedef vector<TPinPainterBase*> PinPainterListT;
674 #else
675 typedef TPinPainterBase* TPinPainterBasePtrT;
676 typedef WXSTL_VECTOR_SHALLOW_COPY( TPinPainterBasePtrT ) PinPainterListT;
677 #endif
678
679 /*
680 * Class displays graphical view of data contained in wxTextModel
681 */
682
683 class wxTextEditorView : public wxScrolledWindow
684 {
685 protected:
686
687 wxTextEditorModel* mpModel;
688 TPosition mSelectionStart;
689 TPosition mSelectionEnd;
690 TPosition mCursorPos;
691
692 TPosition mLastViewStart;
693 size_t mLastRowsTotal;
694
695 size_t mRowsPerPage;
696 size_t mColsPerPage;
697
698 static char* mpLineBuffer;
699 static size_t mpLineBufferLen;
700
701 bool mFullRefreshPending;
702 bool mAdjustScrollPending;
703
704 wxFont mFont;
705
706 bool mScrollingOn; // default: TRUE
707 bool mCursorOn; // default: TRUE;
708
709 bool mLTMode; // line-tracking mode
710 // (when the whole line is coloured,
711 // instead of showing blinking cursor position)
712
713 wxColour mLTColour; // fill-colour for LT-mode
714
715 bool mDragStarted;
716 char* mpDraggedText;
717
718 bool mOwnsModel;
719
720 wxString mFragment; // reused heap-buffer
721 // for coloured fragments
722 SourcePainter* mpPainter;
723 PinPainterListT mPinPainters;
724 TTextIterator mCashedIter;
725
726 static TCursorTimer* mpTimer;
727
728 public: /*** public properties ***/
729
730 int mLeftMargin; // default: 20
731 int mRightMargin; // default: 0
732 int mTopMargin; // default: 0
733 int mBottomMargin; // default: 0
734 int mMaxColumns; // default: 500
735
736 TPosition mPagePos;
737
738 // color-scheme properties
739
740 wxColour mNormalTextCol;
741 wxColour mIndentifierTextCol;
742 wxColour mReservedWordTextCol;
743 wxColour mCommentTextCol;
744
745 wxColour mNormalBkCol;
746 wxColour mSelectionFgCol;
747 wxColour mSelectionBkCol;
748
749 wxBrush mNormalBkBrush;
750 wxBrush mSelectedBkBrush;
751
752 // accessed by timer
753
754 TPosition mCursorScrPos;
755 wxSize mCharDim;
756
757 protected:
758
759 char* GetLineBuffer( size_t len );
760
761 virtual void PaintDecorations( size_t fromRow, size_t tillRow, wxDC& dc, TTextIterator& iter );
762 virtual void PaintRows( size_t fromRow, size_t tillRow, wxDC& dc );
763
764 void ObtainFontProperties();
765
766 bool IsActiveView();
767 void SetTextDefaults();
768 void RecalcPagingInfo();
769
770 TPinPainterBase* FindPainterForPin( TPinBase& pin );
771
772 public:
773 wxTextEditorView( wxWindow* parent, wxWindowID id = -1,
774 wxTextEditorModel* pModel = NULL,
775 int wndStyle = wxSUNKEN_BORDER,
776 bool ownsModel = TRUE );
777 ~wxTextEditorView();
778
779 /*** setup methods ***/
780
781 void SetModel( wxTextEditorModel* pModel );
782
783 // sets custom syntax-higlighting implementation
784 void SetSourcePainter( SourcePainter* pPainter );
785 void AddPinPainter( TPinPainterBase* pPainter );
786
787 void SetDefaultFont( const wxFont& font );
788 wxFont& GetDefaultFont();
789
790 wxSize GetCharacterSize() { return mCharDim; }
791
792 size_t GetRowsPerPage() { return mRowsPerPage; }
793 void SetRowsPerPage( size_t n );
794 void SetMaxColumns( size_t n );
795
796 void SetLineTrackingMode( bool on, const wxColour& col = wxColour(255,255,0) );
797
798 void EnableCursor( bool enable );
799 void EnableScrollbars( bool enable );
800
801 void SetColours( const wxColour& normalBkCol,
802 const wxColour& selectedBkCol,
803 const wxColour& selectedTextCol );
804
805 void SetHeighlightingColours( const wxColour& normalTextCol,
806 const wxColour& identifierTextCol,
807 const wxColour& reservedWordTextCol,
808 const wxColour& commentTextCol );
809
810 void SetMargins( int top, int left, int bottom, int right );
811
812 // notifications from editor-model:
813
814 void OnModelChanged();
815 void ScrollView( int rows, int cols );
816
817 // accessors
818
819 void Activate();
820 void Deactivate();
821
822 // event handlers
823
824 #if (( wxVERSION_NUMBER < 2100 ) || (( wxVERSION_NUMBER == 2100 ) && (wxBETA_NUMBER <= 4)))
825 void OnScroll( wxScrollEvent& event );
826 #else
827 void OnScroll( wxScrollWinEvent& event );
828 #endif
829 void OnPaint ( wxPaintEvent& event );
830 void OnSize ( wxSizeEvent& event );
831 void OnEraseBackground( wxEraseEvent& event );
832
833 void OnLButtonDown( wxMouseEvent& event );
834 void OnLButtonUp ( wxMouseEvent& event );
835 void OnMotion ( wxMouseEvent& event );
836 void OnDblClick ( wxMouseEvent& event );
837
838 void OnSetFocus( wxFocusEvent& event );
839 void OnKillFocus( wxFocusEvent& event );
840
841 // requests editor to keep cursor blinking, even when
842 // the window has lost it's focus
843
844 void HoldCursor( bool hold );
845
846 // FOR NOW:: hard-coded key-bindings
847
848 void OnChar( wxKeyEvent& event );
849 void OnKeyDown( wxKeyEvent& event );
850
851 // utilities
852
853 virtual void SyncViewPortPosition();
854 virtual void SyncScrollbars();
855 virtual void PositionCursor();
856
857 void TextPosToScreenPos( const TPosition& txtPos, TPosition& scrPos );
858 void ScreenPosToTextPos( const TPosition& scrPos, TPosition& txtPos );
859 void ScreenPosToPixels ( const TPosition& scrPos, int& x, int& y );
860 void PixelsToScrPos ( int x, int y, int& scrRow, int& scrCol );
861 void PixelsToTextPos ( int x, int y, TPosition& textPos );
862
863 bool IsClipboardCmd( wxKeyEvent& key );
864
865 TPosition GetPagePos() { return mPagePos; }
866
867 DECLARE_EVENT_TABLE()
868 };
869
870 // TODO:: mutex class should be used to avoid race on updates
871
872 class TCursorTimer : public wxTimer
873 {
874 protected:
875 wxTextEditorView* mpView;
876 volatile bool mIsLocked;
877 volatile bool mIsShown;
878 volatile bool mStarted;
879 wxBrush mBrush;
880 bool mMissOneTick;
881
882 int mBlinkInterval; // default: 500mills
883 protected:
884
885 void DrawCursor();
886
887 public:
888
889 TCursorTimer();
890
891 virtual void Notify();
892
893 void SetView( wxTextEditorView* pView );
894 wxTextEditorView* GetView();
895 void HideCursor( bool forceHide = FALSE );
896 void ShowCursor( bool forceShow = FALSE );
897
898 void SetIsShown( bool isShown );
899 void Lock();
900 void Unlock();
901 };
902
903 #endif // __TDEFS_G__