Exemplo n.º 1
0
        private Control AddTextBox(IWritingSystemDefinition writingSystem, MultiTextBase multiText)
        {
            Control control;

            if (writingSystem.IsVoice)
            {
                if (_serviceProvider == null)
                {
                    //no, better to just omit it.  throw new ConfigurationException("WeSay cannot handle yet audio in this task.");
                    return(null);
                }
                var ap = _serviceProvider.GetService(typeof(AudioPathProvider)) as AudioPathProvider;
                control = new WeSayAudioFieldBox(writingSystem, ap, _serviceProvider.GetService(typeof(Palaso.Reporting.ILogger)) as ILogger);
                control.SuspendLayout();
                ((WeSayAudioFieldBox)control).PlayOnly = (_visibility == CommonEnumerations.VisibilitySetting.ReadOnly);
            }
            else
            {
                IWeSayTextBox box = null;
                if (_serviceProvider != null)
                {
                    box = _serviceProvider.GetService(typeof(IWeSayTextBox)) as IWeSayTextBox;
                }
                else
                {
                    // Shouldn't get to this but just in case.
                    box = new WeSayTextBox();
                }
                box.Init(writingSystem, Name);

                control = (Control)box;
                control.SuspendLayout();
                box.ReadOnly               = (_visibility == CommonEnumerations.VisibilitySetting.ReadOnly);
                box.Multiline              = true;
                box.WordWrap               = true;
                box.MultiParagraph         = _isMultiParagraph;
                box.IsSpellCheckingEnabled = IsSpellCheckingEnabled;
                //box.Enabled = !box.ReadOnly;
                if (!box.ReadOnly && box is WeSayTextBox)
                {
                    Palaso.UI.WindowsForms.Keyboarding.KeyboardController.Register((Control)box);
                }
            }

            _inputBoxes.Add(control);

            string text = multiText.GetExactAlternative(writingSystem.Id);

            if (_isMultiParagraph)            //review... stuff was coming in with just \n, and the text box then didn't show the paragarph marks
            {
                text = text.Replace("\r\n", "\n");
                text = text.Replace("\n", "\r\n");
            }
            control.Name = Name.Replace("-mtc", "") + "_" + writingSystem.Id;
            //for automated tests to find this particular guy
            control.Text = text;

            if (control is IWeSayTextBox)
            {
                var spans = multiText.GetExactAlternativeSpans(writingSystem.Id);
                (control as IWeSayTextBox).Spans = spans;
            }

            control.TextChanged += OnTextOfSomeBoxChanged;
            control.KeyDown     += OnKeyDownInSomeBox;
            control.MouseWheel  += subControl_MouseWheel;

            control.ResumeLayout(false);
            return(control);
        }