Beispiel #1
0
        public void StartSpellChecking()
        {
            Cursor.Current = Cursors.WaitCursor;

            Globals.ThisAddIn.SpellOn = true;
            ResetAllInitVariables();

            if (!tabControl.TabPages.Contains(tabPage1))
            {
                tabControl.TabPages.Add(tabPage1);
            }
            tabControl.SelectTab(tabPage1);

            m_Inspector = Globals.ThisAddIn.Application.ActiveInspector();
            m_Document  = m_Inspector.WordEditor;
            if (!m_Inspector.IsWordMail())
            {
                m_Document = m_Inspector.CurrentItem as Word.Document;
            }

            // get the cursor position in the document
            nCursorPos = m_Document.Application.Selection.Start;
            // get all shapes in the document
            oShapes = m_Document.Application.ActiveDocument.Shapes;

            Word.ShapeRange oShpRng = m_Document.Application.Selection.ShapeRange;
            if (oShpRng.Count > 0)
            {
                object     obj = 1;
                Word.Shape shp = oShpRng.get_Item(ref obj);
                bCheckNormalText = false;
                bCursorInShape   = true;

                for (int i = 1; i <= oShapes.Count; i++)
                {
                    obj         = i;
                    nShapeIndex = i;
                    Word.Shape oShp = oShapes.get_Item(ref obj);
                    if (oShp.Name == shp.Name)
                    {
                        break;
                    }
                }
            }
            RestartParagraph();
            SetSpellingState("Անտեսել");
        }
Beispiel #2
0
        private void RestartParagraph()
        {
            bHasPrevTextBoxLink = false;

////
//            // if restart-par, then change the paragraph in the original document
//            if (bRestartPar)
//            {
//                Word.Range rgPar = oPars[nParIndex].Range;
//                rgPar.Text = txtText.Text;
//            }

            if (bCheckNormalText)
            {
                // get all paragraphs of normal text area (including field regions)
                oPars     = Globals.ThisAddIn.Application.ActiveDocument.Paragraphs;
                nParCount = oPars.Count;

                Word.Paragraph CurPar  = oPars[nParIndex];
                int            nCurPos = Math.Max(CurPar.Range.Start, nCursorPos);

                // start with the range of the whole active document
                Object     oRS = null, oRE = null;
                Word.Range rg = Globals.ThisAddIn.Application.ActiveDocument.Range(ref oRS, ref oRE);
                rg.End = int.MaxValue;

                // search for the first armenian character starting from the current cursor position
                nCurPos = SearchForArmenianChar(rg, nCurPos);
                if (nParIndex > nParCount)
                {
                    bCheckNormalText = false;
                    if (oShapes.Count > 0)
                    {
                        nShapeIndex = 1;
                        RestartParagraph();
                    }
                    else
                    {
                        TerminateSpellCheck();
                    }
                    return;
                }
            }
            else
            {
                if (!bCursorInShape)
                {
                    nCursorPos = 0;
                }
                if (nShapeIndex > oShapes.Count)
                {
                    TerminateSpellCheck();
                    return;
                }
                object     obj = nShapeIndex;
                Word.Shape shp = oShapes.get_Item(ref obj);

                while (nShapeIndex <= oShapes.Count && !HasText(shp))
                {
                    obj = ++nShapeIndex;
                    if (nShapeIndex > oShapes.Count)
                    {
                        RestartParagraph();
                        return;
                    }
                    shp = oShapes.get_Item(ref obj);
                }
                Word.Range rg = null;
                if (nShapeIndex <= oShapes.Count && HasText(shp))
                {
                    rg        = shp.TextFrame.TextRange;
                    oPars     = rg.Paragraphs;
                    nParCount = oPars.Count;
                    if (shp.TextFrame.ContainingRange.Start < shp.TextFrame.TextRange.Start)
                    {
                        bHasPrevTextBoxLink = true;
                    }
                }
                else
                {
                    nShapeIndex++;
                    RestartParagraph();
                    return;
                }
                nParIndex = 1;

                Word.Range rgOffset = shp.TextFrame.TextRange;
                // search for the first armenian character in the shape object
                nCursorPos = SearchForArmenianChar(rgOffset, nCursorPos);
                if (nParIndex > nParCount)
                {
                    bCheckNormalText = false;
                    if (oShapes.Count > 0)
                    {
                        nShapeIndex++;
                        RestartParagraph();
                    }
                    else
                    {
                        TerminateSpellCheck();
                    }
                    return;
                }
            }

            if (!bRestartPar)
            {
                Word.Paragraph par = oPars[nParIndex];
                Word.Range     pRg = par.Range;
                nIParOffset = Math.Max(nCursorPos - pRg.Start, 0);
                pRg.End     = pRg.Start + nIParOffset;
                nParOffset  = 0;
                if (nIParOffset > 0 && pRg.Text != null)
                {
                    nParOffset += pRg.Text.Length;
                }
                CheckParagraph(par);
            }
            bRestartPar = false;
        }