protected override void OnStartDemo(SampleViewport viewport) { textbox = new LayoutFarm.CustomWidgets.TextBox(400, 300, true); textbox.SetLocation(20, 20); var style1 = new Text.TextSpanStyle(); style1.FontInfo = new PixelFarm.Drawing.RequestFont("tahoma", 10); style1.FontColor = new PixelFarm.Drawing.Color(0, 0, 0); textbox.DefaultSpanStyle = style1; var textSplitter = new LayoutFarm.CustomWidgets.ContentTextSplitter(); textbox.TextSplitter = textSplitter; listView = new CustomWidgets.ListView(300, 200); listView.SetLocation(0, 40); listView.Visible = false; //------------------------------------ //create special text surface listener var textSurfaceListener = new LayoutFarm.Text.TextSurfaceEventListener(); textSurfaceListener.CharacterAdded += (s, e) => UpdateSuggestionList(); textSurfaceListener.CharacterRemoved += (s, e) => UpdateSuggestionList(); textSurfaceListener.PreviewArrowKeyDown += new EventHandler <Text.TextDomEventArgs>(textSurfaceListener_PreviewArrowKeyDown); textSurfaceListener.PreviewEnterKeyDown += new EventHandler <Text.TextDomEventArgs>(textSurfaceListener_PreviewEnterKeyDown); textbox.TextEventListener = textSurfaceListener; //------------------------------------ viewport.AddContent(textbox); viewport.AddContent(listView); //------------------------------------ BuildSampleCountryList(); }
protected override void OnStart(AppHost host) { var listview = new LayoutFarm.CustomWidgets.ListView(300, 400); listview.SetLocation(10, 10); listview.BackColor = KnownColors.FromKnownColor(KnownColor.LightGray); //add list view to viewport host.AddChild(listview); //add RequestFont listItemFont = new RequestFont("tahoma", 18); for (int i = 0; i < 10; ++i) { var listItem = new LayoutFarm.CustomWidgets.ListItem(400, 20); if ((i % 2) == 0) { listItem.BackColor = KnownColors.FromKnownColor(KnownColor.OrangeRed); } else { listItem.BackColor = KnownColors.FromKnownColor(KnownColor.Orange); } listItem.SetFont(listItemFont); listItem.Text = "A" + i; listview.AddItem(listItem); } }
protected override void OnStartDemo(SampleViewport viewport) { textbox = new LayoutFarm.CustomWidgets.TextBox(400, 30, false); textbox.SetLocation(20, 20); var textSplitter = new Composers.ContentTextSplitter(); textbox.TextSplitter = textSplitter; listView = new CustomWidgets.ListView(300, 200); listView.SetLocation(0, 40); listView.Visible = false; //------------------------------------ //create special text surface listener var textSurfaceListener = new LayoutFarm.Text.TextSurfaceEventListener(); textSurfaceListener.CharacterAdded += (s, e) => UpdateSuggestionList(); textSurfaceListener.CharacterRemoved += (s, e) => UpdateSuggestionList(); textSurfaceListener.PreviewArrowKeyDown += new EventHandler <Text.TextDomEventArgs>(textSurfaceListener_PreviewArrowKeyDown); textSurfaceListener.PreviewEnterKeyDown += new EventHandler <Text.TextDomEventArgs>(textSurfaceListener_PreviewEnterKeyDown); textbox.TextEventListener = textSurfaceListener; //------------------------------------ viewport.AddContent(textbox); viewport.AddContent(listView); //------------------------------------ BuildSampleCountryList(); }
// protected override void OnStart(AppHost host) { _textbox = new LayoutFarm.CustomWidgets.TextBox(400, 30, false); _textbox.SetLocation(20, 20); var style2 = new TextEditing.TextSpanStyle(); style2.ReqFont = new PixelFarm.Drawing.RequestFont("tahoma", 14); style2.FontColor = new PixelFarm.Drawing.Color(0, 0, 0); _textbox.DefaultSpanStyle = style2; var textSplitter = new LayoutFarm.CustomWidgets.ContentTextSplitter(); _textbox.TextSplitter = textSplitter; _listView = new CustomWidgets.ListView(300, 200); _listView.SetLocation(0, 40); _listView.Visible = false; //------------------------------------ //create special text surface listener var textSurfaceListener = new LayoutFarm.TextEditing.TextSurfaceEventListener(); textSurfaceListener.CharacterAdded += (s, e) => UpdateSuggestionList(); textSurfaceListener.CharacterRemoved += (s, e) => UpdateSuggestionList(); textSurfaceListener.PreviewArrowKeyDown += new EventHandler <TextEditing.TextDomEventArgs>(textSurfaceListener_PreviewArrowKeyDown); textSurfaceListener.PreviewEnterKeyDown += new EventHandler <TextEditing.TextDomEventArgs>(textSurfaceListener_PreviewEnterKeyDown); _textbox.TextEventListener = textSurfaceListener; //------------------------------------ host.AddChild(_textbox); host.AddChild(_listView); //------------------------------------ BuildSampleCountryList(); }
protected override void OnStartDemo(SampleViewport viewport) { var listview = new LayoutFarm.CustomWidgets.ListView(300, 400); listview.SetLocation(10, 10); listview.BackColor = KnownColors.FromKnownColor(KnownColor.LightGray); viewport.AddContent(listview); //add for (int i = 0; i < 10; ++i) { var listItem = new LayoutFarm.CustomWidgets.ListItem(400, 20); if ((i % 2) == 0) { listItem.BackColor = KnownColors.FromKnownColor(KnownColor.OrangeRed); } else { listItem.BackColor = KnownColors.FromKnownColor(KnownColor.Orange); } listview.AddItem(listItem); } }
protected override void OnStartDemo(SampleViewport viewport) { textbox = new LayoutFarm.CustomWidgets.TextBox(400, 300, true); textbox.SetLocation(20, 20); var textSplitter = new LayoutFarm.CustomWidgets.ContentTextSplitter(); textbox.TextSplitter = textSplitter; listView = new CustomWidgets.ListView(300, 200); listView.SetLocation(0, 40); listView.Visible = false; //------------------------------------ //create special text surface listener var textSurfaceListener = new LayoutFarm.Text.TextSurfaceEventListener(); textSurfaceListener.CharacterAdded += (s, e) => UpdateSuggestionList(); textSurfaceListener.CharacterRemoved += (s, e) => UpdateSuggestionList(); textSurfaceListener.PreviewArrowKeyDown += new EventHandler<Text.TextDomEventArgs>(textSurfaceListener_PreviewArrowKeyDown); textSurfaceListener.PreviewEnterKeyDown += new EventHandler<Text.TextDomEventArgs>(textSurfaceListener_PreviewEnterKeyDown); textbox.TextEventListener = textSurfaceListener; //------------------------------------ viewport.AddContent(textbox); viewport.AddContent(listView); //------------------------------------ BuildSampleCountryList(); }
void UpdateSuggestionList() { //find suggestion words this.currentLocalText = null; listView.ClearItems(); Text.EditableRun currentSpan = textbox.CurrentTextSpan; if (currentSpan == null) { listView.Visible = false; return; } //------------------------------------------------------------------------- //sample parse ... //In this example all country name start with Captial letter so ... //try to get underlining text //int startAt, len; //textbox.FindCurrentUnderlyingWord(out startAt, out len); string currentTextSpanText = currentSpan.GetText().ToUpper(); //analyze content char[] textBuffer = currentTextSpanText.ToCharArray(); _textSplitBoundsList.Clear(); _textSplitBoundsList.AddRange(textbox.TextSplitter.ParseWordContent(textBuffer, 0, textBuffer.Length)); //get last part of splited text int m = _textSplitBoundsList.Count; if (m < 1) { return; } int splitBoundIndex = GetProperSplitBoundIndex(_textSplitBoundsList, textbox.CurrentLineCharIndex); if (splitBoundIndex < 0) { return; } //find current split bounds Composers.TextSplitBound selectBounds = _textSplitBoundsList[splitBoundIndex]; this.currentLocalText = GetString(textBuffer, selectBounds); char firstChar = currentLocalText[0]; List <string> keywords; if (words.TryGetValue(firstChar, out keywords)) { int j = keywords.Count; int listViewWidth = listView.Width; for (int i = 0; i < j; ++i) { string choice = keywords[i].ToUpper(); if (StringStartsWithChars(choice, currentLocalText)) { CustomWidgets.ListItem item = new CustomWidgets.ListItem(listViewWidth, 17); item.BackColor = Color.LightGray; item.Tag = item.Text = keywords[i]; listView.AddItem(item); } } } if (listView.ItemCount > 0) { listView.Visible = true; //TODO: implement selectedIndex suggestion hint here *** listView.SelectedIndex = 0; //move listview under caret position var caretPos = textbox.CaretPosition; //temp fixed //TODO: review here listView.SetLocation(textbox.Left + caretPos.X, textbox.Top + caretPos.Y + 20); listView.EnsureSelectedItemVisible(); } else { listView.Visible = false; } //------------------------------------------------------------------------- }
void UpdateSuggestionList() { //find suggestion words this.currentLocalText = null; listView.ClearItems(); if (textbox.CurrentTextSpan == null) { listView.Visible = false; return; } //------------------------------------------------------------------------- //sample parse ... //In this example all country name start with Captial letter so ... string currentTextSpanText = textbox.CurrentTextSpan.Text.ToUpper(); //analyze content var textBuffer = currentTextSpanText.ToCharArray(); var results = new List <LayoutFarm.Composers.TextSplitBound>(); results.AddRange(textbox.TextSplitter.ParseWordContent(textBuffer, 0, textBuffer.Length)); //get last part of splited text int m = results.Count; if (m < 1) { return; } Composers.TextSplitBound lastSplitPart = results[m - 1]; this.currentLocalText = GetString(textBuffer, lastSplitPart); //char firstChar = currentTextSpanText[0]; char firstChar = currentLocalText[0]; List <string> keywords; if (words.TryGetValue(firstChar, out keywords)) { int j = keywords.Count; int listViewWidth = listView.Width; for (int i = 0; i < j; ++i) { string choice = keywords[i].ToUpper(); if (choice.StartsWith(currentLocalText)) { CustomWidgets.ListItem item = new CustomWidgets.ListItem(listViewWidth, 17); item.BackColor = Color.LightGray; item.Tag = item.Text = keywords[i]; listView.AddItem(item); } } } if (listView.ItemCount > 0) { listView.Visible = true; //TODO: implement selectedIndex suggestion hint here *** listView.SelectedIndex = 0; //move listview under caret position var caretPos = textbox.CaretPosition; //temp fixed //TODO: review here listView.SetLocation(textbox.Left + caretPos.X, textbox.Top + caretPos.Y + 20); } else { listView.Visible = false; } //------------------------------------------------------------------------- }