1 #include <CtrlLib/CtrlLib.h> 2 3 using namespace Upp; 4 5 struct MyApp : TopWindow { 6 LineEdit editor; 7 ArrayCtrl list; 8 Splitter splitter; 9 int dosel = 0; 10 11 MyApp(); 12 }; 13 MyApp()14MyApp::MyApp() 15 { 16 Add(splitter.SizePos()); 17 splitter.Horz(list, editor); 18 list.AddRowNumColumn().ConvertBy([=](const Value& v)->Value { 19 int ii = v; 20 if(ii >= editor.GetLineCount()) 21 return Null; 22 return AsString(ii) << " " << FormatIntRoman(ii, true); 23 }); 24 list.NoHeader().NoGrid().HideSb(); 25 list.NoWantFocus(); 26 27 String text; 28 for(int i = 0; i < 1000; i++) 29 text << "Line " << AsString(i) << "\n"; 30 editor <<= text; 31 32 int cy = editor.GetFontSize().cy; 33 list.SetLineCy(cy); 34 35 editor.WhenAction = editor.WhenScroll = [=] { 36 list.SetVirtualCount(editor.GetLineCount() + 2); // unfortunately, we need 2 more lines to cover LineEdit end of text 37 list.ScrollTo(editor.GetScrollPos().y * cy); 38 }; 39 editor.WhenSel = [=] { 40 if(dosel) // avoid infinite recursion 41 return; 42 dosel++; 43 list.SetCursor(editor.GetCursorLine()); 44 list.WhenAction(); 45 dosel--; 46 }; 47 48 list.WhenScroll = [=] { 49 editor.SetScrollPos(Point(0, list.GetScroll() / cy)); 50 }; 51 list.WhenSel = [=] { 52 if(dosel) // avoid infinite recursion 53 return; 54 dosel++; 55 int i = list.GetCursor(); 56 if(i >= 0 && i <= editor.GetLength()) { 57 editor.SetCursor(editor.GetPos(i)); 58 editor.WhenAction(); 59 } 60 dosel--; 61 }; 62 63 editor.WhenAction(); // set initial scroll position in the list 64 editor.WhenSel(); // set initial cursor position in the list 65 } 66 67 GUI_APP_MAIN 68 { 69 MyApp().Run(); 70 } 71