1+ #include < text-editor/editor.hpp>
2+ #include < iostream>
3+
4+ Editor::Editor (){
5+ scintilla.setParent (this );
6+ // configure margins
7+ turbo::call (scintilla, SCI_SETMARGINS, 0 , 0 );
8+
9+ // Indentation
10+ turbo::call (scintilla, SCI_SETUSETABS, false , 0U );
11+ turbo::call (scintilla, SCI_SETINDENT, 4 , 0U );
12+ turbo::call (scintilla, SCI_SETTABWIDTH, 4 , 0U );
13+ turbo::call (scintilla, SCI_SETTABINDENTS, true , 0U );
14+ turbo::call (scintilla, SCI_SETBACKSPACEUNINDENTS, true , 0U );
15+ }
16+
17+ void Editor::setSize (const TPoint& size){
18+ this ->size = size;
19+ }
20+
21+ void Editor::paint (TDrawSurface& surface, TRect area){
22+ turbo::paint (scintilla, surface, area);
23+ }
24+
25+ void Editor::handleEvent (TEvent& event){
26+ if (event.what == evKeyboard){
27+ turbo::handleKeyDown (scintilla, event.keyDown );
28+ }
29+ // TODO: handle mouse events
30+ }
31+
32+ void Editor::addObserver (EditorObserver* observer){
33+ observers.insert (observer);
34+ }
35+
36+ void Editor::removeObserver (EditorObserver* observer){
37+ observers.erase (observer);
38+ }
39+
40+ TPoint Editor::getEditorSize (){
41+ return size;
42+ }
43+
44+ void Editor::invalidate (TRect area){
45+ // may be useful later for understanding scintilla events
46+ std::cerr << " invalidate " << area.a .x << " " << area.a .y << " " << area.b .x << " " << area.b .y << " \n " ;
47+ updateAll ();
48+ }
49+
50+ void Editor::handleNotification (const SCNotification &scn){
51+ std::cerr << " handleNotification\n " ;
52+ // updateAll();
53+ }
54+
55+ void Editor::setVerticalScrollPos (int delta, int limit){
56+ std::cerr << " setVerticalScrollPos " << delta << " " << limit << " \n " ;
57+ updateAll ();
58+ }
59+
60+ void Editor::setHorizontalScrollPos (int delta, int limit){
61+ std::cerr << " setHorizontalScrollPos " << delta << " " << limit << " \n " ;
62+ updateAll ();
63+ }
64+
65+ void Editor::updateAll (){
66+ for (auto observer : observers)observer->editorUpdate ();
67+ }
0 commit comments