コード例 #1
0
        /// <summary>
        ///     Explains a list of namables and shows the associated textbox
        /// </summary>
        /// <param name="namable">The namable to explain</param>
        /// <param name="location">
        ///     The location where the explain box should be displayed. If empty is displayed, the location is
        ///     computed based on the combo box location
        /// </param>
        /// <param name="sensibleToMouseMove">Indicates that the explain box should be closed when the mouse moves</param>
        private void ExplainAndShow(INamable namable, Point location, bool sensibleToMouseMove)
        {
            explainRichTextBox.Text = "";
            if (namable != null)
            {
                TextualExplanation explanation    = new TextualExplanation();
                ITextualExplain    textualExplain = namable as ITextualExplain;
                if (textualExplain != null)
                {
                    textualExplain.GetExplain(explanation, false);
                }

                explainRichTextBox.Text = explanation.Text;
                explainRichTextBox.ProcessAllLines();

                if (location == Point.Empty)
                {
                    if (SelectionComboBox.DroppedDown)
                    {
                        explainRichTextBox.Location = new Point(
                            SelectionComboBox.Location.X + SelectionComboBox.Size.Width,
                            SelectionComboBox.Location.Y + SelectionComboBox.Size.Height
                            );
                    }
                    else
                    {
                        explainRichTextBox.Location = new Point(
                            SelectionComboBox.Location.X,
                            SelectionComboBox.Location.Y + SelectionComboBox.Size.Height
                            );
                    }
                }
                else
                {
                    explainRichTextBox.Location = new Point(
                        Math.Min(location.X, EditionTextBox.Size.Width - explainRichTextBox.Size.Width),
                        Math.Min(location.Y, EditionTextBox.Size.Height - explainRichTextBox.Size.Height));
                }

                ConsiderMouseMoveToCloseExplanation = sensibleToMouseMove;

                explainRichTextBox.Size = new Size(400, 200);
                if (explainRichTextBox.Size.Width >= Size.Width * 0.8)
                {
                    explainRichTextBox.Size = new Size((int)(Size.Width * 0.8), explainRichTextBox.Size.Height);
                }
                if (explainRichTextBox.Size.Height >= Size.Height * 0.8)
                {
                    explainRichTextBox.Size = new Size(explainRichTextBox.Size.Width, (int)(Size.Height * 0.8));
                }

                explainRichTextBox.Show();
                EditionTextBox.SendToBack();
            }
        }
コード例 #2
0
        /// <summary>
        ///     Displays the combo box if required and updates the edotor's text
        /// </summary>
        private void DisplayComboBox()
        {
            int index = EditionTextBox.SelectionStart - 1;

            string prefix = CurrentPrefix(index).Trim();

            index = Math.Max(0, index - prefix.Length);
            SortedSet <ObjectReference> allChoices = AllChoices(index, prefix);

            if (prefix.Length <= EditionTextBox.SelectionStart)
            {
                // It seems that selection start and length may be lost when losing the focus.
                // Store them to be able to reapply them
                _selectionStart  = EditionTextBox.SelectionStart - prefix.Length;
                _selectionLength = prefix.Length;
                EditionTextBox.Select(_selectionStart, _selectionLength);
                if (allChoices.Count == 1)
                {
                    EditionTextBox.SelectedText = allChoices.First().DisplayName;
                }
                else if (allChoices.Count > 1)
                {
                    SelectionComboBox.Items.Clear();
                    foreach (ObjectReference choice in allChoices)
                    {
                        SelectionComboBox.Items.Add(choice);
                    }
                    if (prefix.Length > 0)
                    {
                        SelectionComboBox.Text = prefix;
                    }
                    else
                    {
                        SelectionComboBox.Text = allChoices.First().DisplayName;
                    }

                    // Try to compute the combo box location
                    // TODO : Hypothesis. The first displayed line is the first line of the text
                    int    line     = 1;
                    string lineData = "";
                    for (int i = 0; i < EditionTextBox.SelectionStart; i++)
                    {
                        switch (EditionTextBox.Text[i])
                        {
                        case '\n':
                            line    += 1;
                            lineData = "";
                            break;

                        default:
                            lineData += EditionTextBox.Text[i];
                            break;
                        }
                    }

                    SizeF size             = CreateGraphics().MeasureString(lineData, EditionTextBox.Font);
                    int   x                = Math.Min((int)size.Width, Location.X + Size.Width - SelectionComboBox.Width);
                    int   y                = (line - 1) * EditionTextBox.Font.Height + 5;
                    Point comboBoxLocation = new Point(x, y);
                    SelectionComboBox.Location = comboBoxLocation;
                    PendingSelection           = true;
                    EditionTextBox.SendToBack();
                    SelectionComboBox.Show();
                    SelectionComboBox.Focus();
                }
            }
        }