Exemple #1
0
        //
        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;
            _listbox = new CustomWidgets.ListBox(300, 200);
            _listbox.SetLocation(0, 40);
            _listbox.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(_listbox);
            //------------------------------------
            BuildSampleCountryList();
        }
        protected override void OnStart(AppHost host)
        {
            var listbox = new LayoutFarm.CustomWidgets.ListBox(300, 400);

            listbox.SetLocation(10, 10);
            listbox.BackColor = KnownColors.FromKnownColor(KnownColor.LightGray);
            //add list view to viewport
            host.AddChild(listbox);
            //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;
                listbox.AddItem(listItem);
            }
        }
Exemple #3
0
        void UpdateSuggestionList()
        {
            //find suggestion words
            _currentLocalText = null;
            _listbox.ClearItems();
            TextEditing.Run currentSpan = _textbox.CurrentTextSpan;
            if (currentSpan == null)
            {
                _listbox.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.TextSplitBounds selectBounds = _textSplitBoundsList[splitBoundIndex];
            _currentLocalText = GetString(textBuffer, selectBounds);


            char firstChar = _currentLocalText[0];

            if (_words.TryGetValue(firstChar, out List <string> keywords))
            {
                int j             = keywords.Count;
                int listViewWidth = _listbox.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 = KnownColors.LightGray;
                        item.Tag       = item.Text = keywords[i];
                        _listbox.AddItem(item);
                    }
                }
            }
            if (_listbox.ItemCount > 0)
            {
                _listbox.Visible = true;
                //TODO: implement selectedIndex suggestion hint here ***
                _listbox.SelectedIndex = 0;
                //move listview under caret position
                var caretPos = _textbox.CaretPosition;
                //temp fixed
                //TODO: review here
                _listbox.SetLocation(_textbox.Left + caretPos.X, _textbox.Top + caretPos.Y + 20);
                _listbox.EnsureSelectedItemVisible();
            }
            else
            {
                _listbox.Visible = false;
            }

            //-------------------------------------------------------------------------
        }