1 // Copyright (c) 2014, Thomas Goyne <plorkyeran@aegisub.org> 2 // 3 // Permission to use, copy, modify, and distribute this software for any 4 // purpose with or without fee is hereby granted, provided that the above 5 // copyright notice and this permission notice appear in all copies. 6 // 7 // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 // 15 // Aegisub Project http://www.aegisub.org/ 16 17 #include <libaegisub/signal.h> 18 19 class wxStyledTextCtrl; 20 class wxStyledTextEvent; 21 22 class TextSelectionController { 23 int selection_start = 0; 24 int selection_end = 0; 25 int insertion_point = 0; 26 bool changing = false; 27 28 wxStyledTextCtrl *ctrl = nullptr; 29 30 void UpdateUI(wxStyledTextEvent &evt); 31 32 agi::signal::Signal<> AnnounceSelectionChanged; 33 34 public: 35 void SetSelection(int start, int end); 36 void SetInsertionPoint(int point); 37 GetSelectionStart()38 int GetSelectionStart() const { return selection_start; } GetSelectionEnd()39 int GetSelectionEnd() const { return selection_end; } GetInsertionPoint()40 int GetInsertionPoint() const { return insertion_point; } 41 42 void SetControl(wxStyledTextCtrl *ctrl); 43 ~TextSelectionController(); 44 45 DEFINE_SIGNAL_ADDERS(AnnounceSelectionChanged, AddSelectionListener) 46 }; 47