Completed
Last Updated: 23 Oct 2013 06:13 by ADMIN
ADMIN
Georgi I. Georgiev
Created on: 23 Oct 2013 06:13
Category: Editors
Type: Bug Report
0
FIX. RadSpellChecker - Dialogs do not show on top when the form has TopMost set to true
To reproduce:
Add a RadSpellChecker and a RichTextBox, set the spell checker to check the RichTextBox on some button click. Set the main form's TopMost property to true. Start the form, you will notice that sometimes the dialog for spellchecking and the complete messagebox show behind the main form.

Workaround:
public class MyRadSpellChecker : RadSpellChecker
{
    private FormSettings formSettingsForCurrentSpellCheckIteration = new FormSettings();

    public MyRadSpellChecker()
        {
        }

    protected override void CheckAllAtOnce(IControlSpellChecker spellChecker)
    {
        Form spellCheckerParentForm = this.GetSpellCheckerParentForm(spellChecker);
        RadDocument editingElementContentToRadDocument = spellChecker.GetContentAsDocument();
        editingElementContentToRadDocument.Measure(RadDocument.MAX_DOCUMENT_SIZE);

        IControlSpellChecker richTextBoxSpellChecker = this.GetControlSpellChecker(typeof(RadRichTextBox));

        SpellCheckAllAtOnceForm checkAllAtOnceWindow = new SpellCheckAllAtOnceForm(editingElementContentToRadDocument,
                                                                                   richTextBoxSpellChecker,
                                                                                   spellChecker);

        if (!checkAllAtOnceWindow.HasErrors)
        {
            this.ShowSpellCheckingCompleteDialog(spellCheckerParentForm);
            return;
        }

        this.CopyFormSettings(this.FormSettings, checkAllAtOnceWindow);

        SpellingFormShowingEventArgs args = new SpellingFormShowingEventArgs(checkAllAtOnceWindow, spellChecker);
        this.OnSpellingFormShowing(args);

        if (args.Cancel)
        {
            return;
        }

        Form form = args.SpellingForm;
        form.ShowDialog(spellCheckerParentForm);
    }

    private void CopyFormSettings(FormSettings from, RadForm to)
        {
            to.Location = from.Location;
            to.StartPosition = from.StartPosition;
            ThemeResolutionService.ApplyThemeToControlTree(to, from.ThemeName);
        }

    private void ShowSpellCheckingCompleteDialog(Form parentForm = null)
        {
            if (this.EnableCompleteMessageBox)
            {
                string themeName = RadMessageBox.ThemeName;
                RadMessageBox.ThemeName = this.ThemeName;
                string title = RadSpellCheckerLocalizationProvider.CurrentProvider.GetLocalizedString(RadSpellCheckerStringId.Title);
                string complete = RadSpellCheckerLocalizationProvider.CurrentProvider.GetLocalizedString(RadSpellCheckerStringId.Complete);
                RadMessageBox.Show(parentForm, complete, title, MessageBoxButtons.OK);
                RadMessageBox.ThemeName = themeName;
            }
        }

    protected override void CheckWordByWord(IControlSpellChecker spellChecker)
    {
        this.CopyWindowSettings(this.FormSettings, this.formSettingsForCurrentSpellCheckIteration);
        DialogResult result = DialogResult.None;

        do
        {
            result = this.ShowWindowForNextError(spellChecker);
        }
        while (result != DialogResult.None && result == DialogResult.OK);
    }

    private void CopyWindowSettings(FormSettings from, FormSettings to)
    {
        to.Location = from.Location;
        to.StartPosition = from.StartPosition;
        to.ThemeName = from.ThemeName;
    }

    private DialogResult ShowWindowForNextError(IControlSpellChecker spellChecker)
    {
        Form spellCheckerParentForm = this.GetSpellCheckerParentForm(spellChecker);

        spellChecker.ResetFields();
        IWordInfo incorrectWordInfo = spellChecker.MoveToNextError();

        if (incorrectWordInfo == null)
        {
            this.ShowSpellCheckingCompleteDialog(spellCheckerParentForm);
            return DialogResult.None;
        }

        RadForm checkWordByWordWindow = new SpellCheckWordByWordForm(incorrectWordInfo.Word, spellChecker);

        this.CopyFormSettings(this.formSettingsForCurrentSpellCheckIteration, checkWordByWordWindow);

        SpellingFormShowingEventArgs args = new SpellingFormShowingEventArgs(checkWordByWordWindow, spellChecker);
        this.OnSpellingFormShowing(args);

        if (args.Cancel)
        {
            return DialogResult.None;
        }

        checkWordByWordWindow = args.SpellingForm;
        spellChecker.CurrentControl.Focus();
        return checkWordByWordWindow.ShowDialog(spellCheckerParentForm);
    }

    private Form GetSpellCheckerParentForm(IControlSpellChecker spellChecker)
    {
        if (spellChecker != null && spellChecker.CurrentControl != null)
        {
            return spellChecker.CurrentControl.FindForm();
        }

        return null;       
    }
}
0 comments