Exemplo n.º 1
0
		protected bool ProcessParagraphs(OfficeDocumentProcessor aWordProcessor, Word.Paragraphs aParagraphs)
		{
			foreach (Word.Paragraph aParagraph in aParagraphs)
			{
				// get the Range object for this paragraph
				Word.Range aParagraphRange = aParagraph.Range;

				// if we're picking up where we left off and we're not there yet...
				int nCharIndex = 0;
				if (aWordProcessor.AreLeftOvers)
				{
					if (aWordProcessor.LeftOvers.Start > aParagraphRange.End)
						continue;   // skip to the next paragraph

					nCharIndex = aWordProcessor.LeftOvers.StartIndex;
					aWordProcessor.LeftOvers = null; // turn off "left overs"
				}

				WordRange aThisParagraph = new WordRange(aParagraphRange);
				if (!ProcessRangeAsWords(aWordProcessor, aThisParagraph, nCharIndex))
					return false;
			}

			return true;
		}
Exemplo n.º 2
0
        void WordByWord_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
        {
            if (!HookDocumentClose(Application.ActiveDocument))
            {
                return;
            }

            Application.System.Cursor = Word.WdCursorType.wdCursorWait;

            try
            {
                WordDocument doc = new WordDocument(Application.ActiveDocument, OfficeTextDocument.ProcessingType.eWordByWord);

                if (m_aWordByWordProcessor == null)
                {
                    m_aWordByWordProcessor = new OfficeDocumentProcessor(new SILConverterProcessorForm());
                }

                if (doc.ProcessWordByWord(m_aWordByWordProcessor))
                {
                    m_aWordByWordProcessor = null;
                }
            }
            catch (Exception ex)
            {
                DisplayException(ex);
            }

            Application.System.Cursor = Word.WdCursorType.wdCursorNormal;
        }
Exemplo n.º 3
0
        void ConvertTableField_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
        {
            try
            {
                if (Application.Selection == null)
                {
                    throw new ApplicationException("First select the cells that you want to convert using a system converter");
                }

                ExcelDocument doc = new ExcelDocument(Application.Selection);
                if (m_aSelectionProcessor == null)
                {
                    string        strTitle = "Choose the converter for the selected areas/cells";
                    EncConverters aECs     = GetEncConverters;
                    if (aECs != null)
                    {
                        IEncConverter aIEC = aECs.AutoSelectWithTitle(ConvType.Unknown, strTitle);
                        FontConverter aFC  = new FontConverter(new DirectableEncConverter(aIEC));
                        m_aSelectionProcessor = new OfficeDocumentProcessor(aFC, new SILConverterProcessorForm());
                    }
                }

                if (m_aSelectionProcessor != null)
                {
                    if (doc.ProcessWordByWord(m_aSelectionProcessor))
                    {
                        m_aSelectionProcessor = null;
                    }
                }
            }
            catch (Exception ex)
            {
                DisplayException(ex);
            }
        }
        protected bool ProcessParagraphs(OfficeDocumentProcessor aWordProcessor, Word.Paragraphs aParagraphs)
        {
            foreach (Word.Paragraph aParagraph in aParagraphs)
            {
                // get the Range object for this paragraph
                Word.Range aParagraphRange = aParagraph.Range;

                // if we're picking up where we left off and we're not there yet...
                int nCharIndex = 0;
                if (aWordProcessor.AreLeftOvers)
                {
                    if (aWordProcessor.LeftOvers.Start > aParagraphRange.End)
                    {
                        continue;   // skip to the next paragraph
                    }
                    nCharIndex = aWordProcessor.LeftOvers.StartIndex;
                    aWordProcessor.LeftOvers = null; // turn off "left overs"
                }

                WordRange aThisParagraph = new WordRange(aParagraphRange);
                if (!ProcessRangeAsWords(aWordProcessor, aThisParagraph, nCharIndex))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 5
0
		void ConvertTableField_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
		{
			try
			{
				if (Application.Selection == null)
					throw new ApplicationException("First select the cells that you want to convert using a system converter");

				ExcelDocument doc = new ExcelDocument(Application.Selection);
				if (m_aSelectionProcessor == null)
				{
					string strTitle = "Choose the converter for the selected areas/cells";
					EncConverters aECs = GetEncConverters;
					if (aECs != null)
					{
						IEncConverter aIEC = aECs.AutoSelectWithTitle(ConvType.Unknown, strTitle);
						FontConverter aFC = new FontConverter(new DirectableEncConverter(aIEC));
						m_aSelectionProcessor = new OfficeDocumentProcessor(aFC, new SILConverterProcessorForm());
					}
				}

				if (m_aSelectionProcessor != null)
					if (doc.ProcessWordByWord(m_aSelectionProcessor))
						m_aSelectionProcessor = null;
			}
			catch (Exception ex)
			{
				DisplayException(ex);
			}
		}
Exemplo n.º 6
0
        void SelectionConvert_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
        {
            if (!HookDocumentClose(Application.ActiveDocument))
            {
                return;
            }

            try
            {
                WordSelectionDocument doc = new WordSelectionDocument(Application.ActiveDocument, OfficeTextDocument.ProcessingType.eWordByWord);
#if !QueryAllFonts
                // first get the fonts the user wants to process
                OfficeDocumentProcessor aSelectionProcessor = null;
                FontConvertersPicker    aFCsPicker          = new FontConvertersPicker(doc);
                if ((aFCsPicker.ShowDialog() == DialogResult.OK) && (aFCsPicker.SelectedFontConverters.Count > 0))
                {
                    FontConverters aFCs = aFCsPicker.SelectedFontConverters;
                    aSelectionProcessor = new OfficeDocumentProcessor(aFCs, new SILConverterProcessorForm());
                }
#else
                OfficeDocumentProcessor aSelectionProcessor = new OfficeDocumentProcessor((FontConverters)null, new SILConverterProcessorForm());
#endif
                if (aSelectionProcessor != null)
                {
                    doc.ProcessWordByWord(aSelectionProcessor);
                }
            }
            catch (Exception ex)
            {
                DisplayException(ex);
            }
        }
        public bool ProcessWholeParagraphs(OfficeDocumentProcessor aWordProcessor, Word.Paragraphs aParagraphs)
        {
            foreach (Word.Paragraph aParagraph in aParagraphs)
            {
                // get the Range object for this paragraph
                Word.Range aParagraphRange = aParagraph.Range;

                // if we're picking up where we left off and we're not there yet...
                int nCharIndex = 0;
                if (aWordProcessor.AreLeftOvers)
                {
                    if (aWordProcessor.LeftOvers.Start > aParagraphRange.End)
                    {
                        continue;   // skip to the next paragraph
                    }
                    nCharIndex = aWordProcessor.LeftOvers.StartIndex;
                    aWordProcessor.LeftOvers = null; // turn off "left overs"
                }

                WordRange aRunRange  = new WordRange(aParagraphRange);
                int       nEndIndex  = --aRunRange.EndIndex;
                int       nLastIndex = nCharIndex;

                // exclude the paragraph end and process it as a whole unit (we may have to do this multiple times
                bool bStop = false;
                while (!bStop && (nCharIndex < nEndIndex))
                {
                    aRunRange.StartIndex = nCharIndex;
                    if (aRunRange.EndIndex != nEndIndex)
                    {
                        aRunRange.EndIndex = nEndIndex;
                    }

                    nLastIndex = nCharIndex;

                    System.Diagnostics.Trace.WriteLine(String.Format("Start: {0}, End: {1}, text: {2}, length: {3}",
                                                                     aRunRange.Start, aRunRange.End, aRunRange.Text, aRunRange.Text.Length));

                    if (!aWordProcessor.Process(aRunRange, ref nCharIndex))
                    {
                        aWordProcessor.LeftOvers = aRunRange;
                        return(false);
                    }

                    if (nLastIndex == nCharIndex)
                    {
                        break;
                    }
                }
            }

            return(true);
        }
Exemplo n.º 8
0
        void ThisStoryConvert()
        {
            if (!HookDocumentClose(Application.ActiveDocument))
            {
                return;
            }

            try
            {
#if DEBUG
                string strPubPIOVer = Application.Version;
                MessageBox.Show(String.Format("MSPub PIA version: {0}", strPubPIOVer));
#endif
                PubStoryDocument doc = new PubStoryDocument(Application.ActiveDocument, OfficeTextDocument.ProcessingType.eWordByWord);

                // we want to process the file word by word and show differences between
                //  the Input and (once) Converted string
                if ((m_aThisStoryWordByWordFontProcessor == null) || (m_strLastStoryName != doc.StoryName))
                {
                    m_aThisStoryWordByWordFontProcessor = null; // just in case we came thru the latter OR case

                    // first get the fonts the user wants to process
                    FontConvertersPicker aFCsPicker = new FontConvertersPicker(doc);
                    if ((aFCsPicker.ShowDialog() == DialogResult.OK) && (aFCsPicker.SelectedFontConverters.Count > 0))
                    {
                        FontConverters aFCs = aFCsPicker.SelectedFontConverters;
                        m_aThisStoryWordByWordFontProcessor = GetDocumentProcessor(aFCs, new SILConverterProcessorForm());
                    }
                }

                if (m_aThisStoryWordByWordFontProcessor != null)
                {
                    if (doc.ProcessWordByWord(m_aThisStoryWordByWordFontProcessor))
                    {
                        m_aThisStoryWordByWordFontProcessor = null;
                        m_strLastStoryName = null;
                    }
                    else
                    {
                        m_strLastStoryName = doc.StoryName;
                    }
                }
            }
            catch (Exception ex)
            {
                DisplayException(ex);
                if ((m_aThisStoryWordByWordFontProcessor != null) && !m_aThisStoryWordByWordFontProcessor.AreLeftOvers)
                {
                    m_aThisStoryWordByWordFontProcessor = null;
                }
            }
        }
        protected bool ProcessParagraphs(OfficeDocumentProcessor aWordProcessor, PubParagraphs aPubParagraphs)
        {
            foreach (PubRange aParagraphRange in aPubParagraphs)
            {
                int nCharIndex = 0;
                if (!ProcessRangeAsWords(aWordProcessor, aParagraphRange, nCharIndex))
                {
                    return(false);
                }
            }

            return(true);
        }
        public bool ProcessParagraphsIsoFormat(OfficeDocumentProcessor aWordProcessor, Word.Paragraphs aParagraphs)
        {
            foreach (Word.Paragraph aParagraph in aParagraphs)
            {
                // get the Range object for this paragraph
                Word.Range aParagraphRange = aParagraph.Range;

                // if we're picking up where we left off and we're not there yet...
                int nCharIndex = 0;
                if (aWordProcessor.AreLeftOvers)
                {
                    if (aWordProcessor.LeftOvers.Start > aParagraphRange.End)
                    {
                        continue;                           // skip to the next paragraph
                    }
                    nCharIndex = aWordProcessor.LeftOvers.StartIndex;
                    aWordProcessor.LeftOvers = null;                     // turn off "left overs"
                }

                WordRange aRunRange   = new WordRange(aParagraphRange);
                int       nStartIndex = aRunRange.StartIndex;
                System.Diagnostics.Debug.Assert(nStartIndex == 0);

                // if we have mixed character formatting, then use a binary search algorithm to find
                //	the maximum run.
                if (MixedCharacterFormatting(aRunRange))
                {
                    int nWidth = aRunRange.EndIndex / 2;

                    do
                    {
                        aRunRange.EndIndex++;
                    } while (!MixedCharacterFormatting(aRunRange));

                    aRunRange.EndIndex--;                       // back up one
                }
                else
                {
                    // the whole paragraph seems to be iso formatted, so exclude the paragraph end and
                    // process it as a whole unit
                    aRunRange.EndIndex--;
                    if (!aWordProcessor.Process(aRunRange, ref nCharIndex))
                    {
                        aWordProcessor.LeftOvers = aRunRange;
                        return(false);
                    }
                }
            }

            return(true);
        }
Exemplo n.º 11
0
        public override bool ProcessWordByWord(OfficeDocumentProcessor aWordProcessor)
        {
            if (aWordProcessor.AreLeftOvers)
            {
                DialogResult res = MessageBox.Show("Click 'Yes' to restart where you left off, 'No' to start over at the top, and 'Cancel' to quit", Connect.cstrCaption, MessageBoxButtons.YesNoCancel);
                if (res == DialogResult.No)
                {
                    aWordProcessor.LeftOvers = null;
                }
                else if (res == DialogResult.Cancel)
                {
                    return(true);
                }
            }

            int nCharIndex = 0;             // don't care

            foreach (Excel.Range aArea in Document.Areas)
            {
                foreach (Excel.Range aColumn in aArea.Columns)
                {
                    if (aWordProcessor.AreLeftOvers && (aWordProcessor.LeftOvers.End > aColumn.Column))
                    {
                        continue;
                    }

                    foreach (Excel.Range aRow in aColumn.Rows)
                    {
                        if ((aWordProcessor.AreLeftOvers && (aWordProcessor.LeftOvers.Start > aRow.Row)) ||
                            (String.IsNullOrEmpty((string)aRow.Text)))
                        {
                            continue;
                        }

                        ExcelRange aCellRange = new ExcelRange(aRow);
                        aWordProcessor.LeftOvers = aCellRange;

                        if (!aWordProcessor.Process(aCellRange, ref nCharIndex))
                        {
                            return(false);
                        }
                    }

                    aWordProcessor.LeftOvers = null;
                }
            }

            return(true);
        }
        protected bool ProcessStory(OfficeDocumentProcessor aWordProcessor, Pub.Story aStory)
        {
            PubStory aPubStory = new PubStory(aStory);

            foreach (PubRange aParagraphRange in aPubStory.Paragraphs)
            {
                // if we're picking up where we left off and we're not there yet...
                int nCharIndex = 0;
                if (aWordProcessor.AreLeftOvers)
                {
                    if (aWordProcessor.LeftOvers.Start > aParagraphRange.End)
                    {
                        continue;   // skip to the next paragraph
                    }
                    nCharIndex = aWordProcessor.LeftOvers.StartIndex;
                    aWordProcessor.LeftOvers = null; // turn off "left overs"
                }

                if (!ProcessRangeAsWords(aWordProcessor, aParagraphRange, nCharIndex))
                {
                    return(false);
                }
            }

            // see if the user would like us to adjust the size to make it fit.
            if (!aWordProcessor.SuspendUI &&
                (aStory.HasTextFrame == Office.MsoTriState.msoTrue) &&
                (aStory.TextFrame.Overflowing == Office.MsoTriState.msoTrue))
            {
                if (MessageBox.Show("The story has overflowed the text frame. Would you like me to adjust the text size so it fits?", OfficeApp.cstrCaption, MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    try
                    {
                        aStory.TextFrame.AutoFitText = Pub.PbTextAutoFitType.pbTextAutoFitShrinkOnOverflow;
                    }
                    catch (Exception ex)
                    {
                        // this error is occasionally thrown when we try to do the auto fit... if it happens, just ignore it.
                        // (it's just to save the user from having to reformat)
                        if (ex.Message != "Error HRESULT E_FAIL has been returned from a call to a COM component.")
                        {
                            throw;
                        }
                    }
                }
            }

            return(true);
        }
        public override bool ProcessWordByWord(OfficeDocumentProcessor aWordProcessor)
        {
            // if multiple paragraphs...
            int            nCharIndex       = 0;
            WordParagraphs aParagraphRanges = new WordParagraphs(Document.Application.Selection);

            foreach (Word.Range aRange in aParagraphRanges)
            {
                WordRange aThisParagraph = new WordRange(aRange);
                if (!ProcessRangeAsWords(aWordProcessor, aThisParagraph, nCharIndex))
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 14
0
		public override bool ProcessWordByWord(OfficeDocumentProcessor aWordProcessor, ProcessingType eType)
		{
			if (aWordProcessor.AreLeftOvers)
			{
				DialogResult res = MessageBox.Show("Click 'Yes' to restart where you left off, 'No' to start over at the top, and 'Cancel' to quit", Connect.cstrCaption, MessageBoxButtons.YesNoCancel);
				if (res == DialogResult.No)
					aWordProcessor.LeftOvers = null;
				if (res == DialogResult.Cancel)
					return true;
			}

			if (eType == ProcessingType.eWordByWord)
				return ProcessParagraphs(aWordProcessor, Document.Paragraphs);
			else
				return ProcessParagraphsIsoFormat(aWordProcessor, Document.Paragraphs);
		}
Exemplo n.º 15
0
        public void DocumentClosed()
        {
            if (m_formFindReplace != null)
            {
                m_formFindReplace.Close();
            }
            m_formFindReplace = null;

            m_aWordByWordProcessor     = null;
            m_aWordByWordFontProcessor = null;

            m_aWordByWordSpellFixerProcessor     = null;
            m_aWordByWordFontSpellFixerProcessor = null;

            m_aRoundTripCheckWordProcessor     = null;
            m_aRoundTripCheckFontWordProcessor = null;
        }
        public override bool ProcessWordByWord(OfficeDocumentProcessor aWordProcessor, ProcessingType eType)
        {
            Pub.Stories aStories = Document.Stories;
            int         nStoryId = 1;

            if (aWordProcessor.AreLeftOvers)
            {
                DialogResult res = MessageBox.Show("Click 'Yes' to restart where you left off, 'No' to start over at the top, and 'Cancel' to quit", OfficeApp.cstrCaption, MessageBoxButtons.YesNoCancel);
                if (res == DialogResult.No)
                {
                    aWordProcessor.LeftOvers = null;
                }
                else if (res == DialogResult.Cancel)
                {
                    return(true);
                }
                else
                {
                    System.Diagnostics.Debug.Assert(res == DialogResult.Yes);
                    PubRange rngPub = (PubRange)aWordProcessor.LeftOvers;
                    nStoryId = rngPub.StoryID;
                }
            }

            for (; nStoryId <= aStories.Count; nStoryId++)
            {
                Pub.Story aStory = aStories[nStoryId];

                bool bResult = ProcessStory(aWordProcessor, aStory);

                if (aWordProcessor.AreLeftOvers)
                {
                    PubRange rngPub = (PubRange)aWordProcessor.LeftOvers;
                    rngPub.StoryID = nStoryId;  // remember which story we were doing when the user cancelled
                }

                if (!bResult)
                {
                    return(false);
                }

                aWordProcessor.ReplaceAll = false;  // stop after each story
            }

            return(true);
        }
Exemplo n.º 17
0
        void SpellFixerWordByWordFont_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
        {
            if (!HookDocumentClose(Application.ActiveDocument))
            {
                return;
            }

            Application.System.Cursor = Word.WdCursorType.wdCursorWait;
            try
            {
                WordDocument doc = new WordDocument(Application.ActiveDocument, OfficeTextDocument.ProcessingType.eWordByWord);

                // we want to process the file word by word and show differences between
                //  the Input and (once) Converted string
                if (m_aWordByWordFontSpellFixerProcessor == null)
                {
                    SpellFixerProcessorForm form = new SpellFixerProcessorForm(GetSpellFixer);

                    // next get the fonts the user wants to process
                    FontConvertersPicker aFCsPicker = new FontConvertersPicker(doc, GetSpellFixer.SpellFixerEncConverter);

                    if ((aFCsPicker.ShowDialog() == DialogResult.OK) && (aFCsPicker.SelectedFontConverters.Count > 0))
                    {
                        m_aWordByWordFontSpellFixerProcessor = new OfficeDocumentProcessor(aFCsPicker.SelectedFontConverters, form);
                    }
                    else
                    {
                        return;
                    }
                }

                if (m_aWordByWordFontSpellFixerProcessor != null)
                {
                    if (doc.ProcessWordByWord(m_aWordByWordFontSpellFixerProcessor))
                    {
                        m_aWordByWordFontSpellFixerProcessor = null;
                    }
                }
            }
            catch (Exception ex)
            {
                DisplayException(ex);
            }
            Application.System.Cursor = Word.WdCursorType.wdCursorNormal;
        }
Exemplo n.º 18
0
        void SelectionConvert_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
        {
            if (!HookDocumentClose(Application.ActiveDocument))
            {
                return;
            }

            try
            {
                WordSelectionDocument   doc = new WordSelectionDocument(Application.ActiveDocument, OfficeTextDocument.ProcessingType.eWordByWord);
                OfficeDocumentProcessor aSelectionProcessor = new OfficeDocumentProcessor((FontConverters)null, new SILConverterProcessorForm());
                doc.ProcessWordByWord(aSelectionProcessor);
            }
            catch (Exception ex)
            {
                DisplayException(ex);
            }
        }
Exemplo n.º 19
0
        protected void SelectionConvert()
        {
            if (Application.ActiveDocument == null)
            {
                return;
            }

            try
            {
                PubRangeDocument        doc = new PubRangeDocument(Application.ActiveDocument, OfficeTextDocument.ProcessingType.eWordByWord);
                OfficeDocumentProcessor aSelectionProcessor = GetDocumentProcessor((FontConverters)null, new SILConverterProcessorForm());

                doc.ProcessWordByWord(aSelectionProcessor);
            }
            catch (Exception ex)
            {
                DisplayException(ex);
            }
        }
        public override bool ProcessWordByWord(OfficeDocumentProcessor aWordProcessor)
        {
            if (Document.Selection.Type == Pub.PbSelectionType.pbSelectionNone)
            {
                throw new ApplicationException("Nothing selected!");
            }

            PubRange      aSelectionRange = (PubRange)SelectionRange;
            PubParagraphs aParagraphs     = aSelectionRange.Paragraphs;

            if (aParagraphs.Count > 1)
            {
                return(ProcessParagraphs(aWordProcessor, aParagraphs));
            }
            else
            {
                int nCharIndex = 0;
                return(aWordProcessor.Process(aSelectionRange, ref nCharIndex));
            }
        }
Exemplo n.º 21
0
        protected void WholeDocumentConvert()
        {
            if (!HookDocumentClose(Application.ActiveDocument))
            {
                return;
            }

            try
            {
                PubDocument doc = new PubDocument(Application.ActiveDocument, OfficeTextDocument.ProcessingType.eWordByWord);

                // we want to process the file word by word and show differences between
                //  the Input and (once) Converted string
                if (m_aWordByWordFontProcessor == null)
                {
                    // first get the fonts the user wants to process
                    FontConvertersPicker aFCsPicker = new FontConvertersPicker(doc);
                    if ((aFCsPicker.ShowDialog() == DialogResult.OK) && (aFCsPicker.SelectedFontConverters.Count > 0))
                    {
                        FontConverters aFCs = aFCsPicker.SelectedFontConverters;
                        m_aWordByWordFontProcessor = GetDocumentProcessor(aFCs, new SILConverterProcessorForm());
                    }
                }

                if (m_aWordByWordFontProcessor != null)
                {
                    if (doc.ProcessWordByWord(m_aWordByWordFontProcessor))
                    {
                        m_aWordByWordFontProcessor = null;
                    }
                }
            }
            catch (Exception ex)
            {
                DisplayException(ex);
                if ((m_aWordByWordFontProcessor != null) && !m_aWordByWordFontProcessor.AreLeftOvers)
                {
                    m_aWordByWordFontProcessor = null;
                }
            }
        }
Exemplo n.º 22
0
        public override bool ProcessWordByWord(OfficeDocumentProcessor aWordProcessor)
        {
            Document.MoveFirst(); // to avoid an error on the first 'Edit'
            int nDontCare = 0;    // don't care

            while (!Document.EOF)
            {
                dao.Fields aFields = Document.Fields;
                dao.Field  aField  = aFields[m_strFieldName];
                if (aField.Value != System.DBNull.Value)
                {
                    AccessRange aWordRange = new AccessRange(aField, this);

                    try
                    {
                        if (!aWordProcessor.Process(aWordRange, ref nDontCare))
                        {
                            return(false);
                        }
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                    finally
                    {
                        // this gets called whether we successfully process the word or not,
                        //  whether we're returning 'false' (in the try) or not, and whether we
                        //  have an exception or not... just exactly what we want, or MSAccess
                        //  process won't release when we exit.
                        OfficeApp.ReleaseComObject(aField);
                        OfficeApp.ReleaseComObject(aFields);
                    }
                }

                Document.MoveNext();
            }

            return(true);
        }
Exemplo n.º 23
0
		public override bool ProcessWordByWord(OfficeDocumentProcessor aWordProcessor, ProcessingType eType)
		{
			Pub.Stories aStories = Document.Stories;
			int nStoryId = 1;
			if (aWordProcessor.AreLeftOvers)
			{
				DialogResult res = MessageBox.Show("Click 'Yes' to restart where you left off, 'No' to start over at the top, and 'Cancel' to quit", Connect.cstrCaption, MessageBoxButtons.YesNoCancel);
				if (res == DialogResult.No)
					aWordProcessor.LeftOvers = null;
				else if (res == DialogResult.Cancel)
					return true;
				else
				{
					System.Diagnostics.Debug.Assert(res == DialogResult.Yes);
					PubRange rngPub = (PubRange)aWordProcessor.LeftOvers;
					nStoryId = rngPub.StoryID;
				}
			}

			for (; nStoryId <= aStories.Count; nStoryId++)
			{
				Pub.Story aStory = aStories[nStoryId];

				bool bResult = ProcessStory(aWordProcessor, aStory);

				if (aWordProcessor.AreLeftOvers)
				{
					PubRange rngPub = (PubRange)aWordProcessor.LeftOvers;
					rngPub.StoryID = nStoryId;  // remember which story we were doing when the user cancelled
				}

				if (!bResult)
					return false;

				aWordProcessor.ReplaceAll = false;  // stop after each story
			}

			return true;
		}
        public override bool ProcessWordByWord(OfficeDocumentProcessor aWordProcessor)
        {
            if (aWordProcessor.AreLeftOvers)
            {
                DialogResult res = MessageBox.Show("Click 'Yes' to restart where you left off, 'No' to start over at the top, and 'Cancel' to quit", OfficeApp.cstrCaption, MessageBoxButtons.YesNoCancel);
                if (res == DialogResult.No)
                {
                    aWordProcessor.LeftOvers = null;
                }
                if (res == DialogResult.Cancel)
                {
                    return(true);
                }
            }

            if (Document.Selection.Type == Pub.PbSelectionType.pbSelectionNone)
            {
                throw new ApplicationException("No story selected!");
            }

            return(ProcessStory(aWordProcessor, Document.Selection.TextRange.Story));
        }
Exemplo n.º 25
0
		public override bool ProcessWordByWord(OfficeDocumentProcessor aWordProcessor)
		{
			if (aWordProcessor.AreLeftOvers)
			{
				DialogResult res = MessageBox.Show("Click 'Yes' to restart where you left off, 'No' to start over at the top, and 'Cancel' to quit", Connect.cstrCaption, MessageBoxButtons.YesNoCancel);
				if (res == DialogResult.No)
					aWordProcessor.LeftOvers = null;
				else if (res == DialogResult.Cancel)
					return true;
			}

			int nCharIndex = 0; // don't care
			foreach (Excel.Range aArea in Document.Areas)
			{
				foreach (Excel.Range aColumn in aArea.Columns)
				{
					if (aWordProcessor.AreLeftOvers && (aWordProcessor.LeftOvers.End > aColumn.Column))
						continue;

					foreach (Excel.Range aRow in aColumn.Rows)
					{
						if(     (aWordProcessor.AreLeftOvers && (aWordProcessor.LeftOvers.Start > aRow.Row))
							||  (String.IsNullOrEmpty((string)aRow.Text)))
							continue;

						ExcelRange aCellRange = new ExcelRange(aRow);
						aWordProcessor.LeftOvers = aCellRange;

						if (!aWordProcessor.Process(aCellRange, ref nCharIndex))
							return false;
					}

					aWordProcessor.LeftOvers = null;
				}
			}

			return true;
		}
Exemplo n.º 26
0
		public override bool ProcessWordByWord(OfficeDocumentProcessor aWordProcessor)
		{
			Document.MoveFirst();   // to avoid an error on the first 'Edit'
			int nDontCare = 0; // don't care
			while (!Document.EOF)
			{
				dao.Fields aFields = Document.Fields;
				dao.Field aField = aFields[m_strFieldName];
				if (aField.Value != System.DBNull.Value)
				{
					AccessRange aWordRange = new AccessRange(aField, this);

					try
					{
						if (!aWordProcessor.Process(aWordRange, ref nDontCare))
							return false;
					}
					catch (Exception)
					{
						throw;
					}
					finally
					{
						// this gets called whether we successfully process the word or not,
						//  whether we're returning 'false' (in the try) or not, and whether we
						//  have an exception or not... just exactly what we want, or MSAccess
						//  process won't release when we exit.
						OfficeApp.ReleaseComObject(aField);
						OfficeApp.ReleaseComObject(aFields);
					}
				}

				Document.MoveNext();
			}

			return true;
		}
        public override bool ProcessWordByWord(OfficeDocumentProcessor aWordProcessor, ProcessingType eType)
        {
            if (aWordProcessor.AreLeftOvers)
            {
                DialogResult res = MessageBox.Show("Click 'Yes' to restart where you left off, 'No' to start over at the top, and 'Cancel' to quit", OfficeApp.cstrCaption, MessageBoxButtons.YesNoCancel);
                if (res == DialogResult.No)
                {
                    aWordProcessor.LeftOvers = null;
                }
                if (res == DialogResult.Cancel)
                {
                    return(true);
                }
            }

            if (eType == ProcessingType.eWordByWord)
            {
                return(ProcessParagraphs(aWordProcessor, Document.Paragraphs));
            }
            else
            {
                return(ProcessParagraphsIsoFormat(aWordProcessor, Document.Paragraphs));
            }
        }
Exemplo n.º 28
0
		public abstract bool ProcessWordByWord(OfficeDocumentProcessor aWordProcessor, ProcessingType eType);
Exemplo n.º 29
0
		protected bool ProcessWholeRange(OfficeDocumentProcessor aWordProcessor, OfficeRange aParagraphRange, int nCharIndex)
		{
			string strText = aParagraphRange.Text;
			int nLength = (strText != null) ? strText.Length : 0;

			while ((nCharIndex < nLength) && (strText.IndexOfAny(m_achParagraphTerminators, nCharIndex, 1) == -1))
			{
				// get a copy of the range to work with
				OfficeRange aWordRange = Duplicate(aParagraphRange);

				// skip past initial spaces
				while ((nCharIndex < nLength) && (strText.IndexOfAny(m_achWhiteSpace, nCharIndex, 1) != -1))
					nCharIndex++;

				// make sure we haven't hit the end of the paragraph (i.e. '\r') or range (beyond len)
				if (nCharIndex < nLength)
				{
					if (strText.IndexOfAny(m_achParagraphTerminators, nCharIndex, 1) == -1)
					{
						// set the start index
						aWordRange.StartIndex = nCharIndex;

						// run through the characters in the word (i.e. until, space, NL, etc)
						while ((nCharIndex < nLength) && (strText.IndexOfAny(m_achWordTerminators, nCharIndex, 1) == -1))
							nCharIndex++;

						// set the end of the range after the first space after the word (but not for NL)
						if (++nCharIndex >= nLength)
							--nCharIndex;

						aWordRange.EndIndex = nCharIndex;

						// make sure the word has text (sometimes it doesn't)
						if (aWordRange.Text == null)  // e.g. Figure "1" returns a null Text string
							// if it does, see if it's "First Character" has any text (which it does in this case)
							aWordRange.DealWithNullText();

						// finally check it.
						if (!aWordProcessor.Process(aWordRange, ref nCharIndex))
						{
							aWordProcessor.LeftOvers = aWordRange;
							return false;
						}
					}

					strText = aParagraphRange.Text; // incase of replace, we've changed it.
					nLength = (strText != null) ? strText.Length : 0;
				}
				else
					break;
			}

			return true;
		}
Exemplo n.º 30
0
		void Reset_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
		{
			m_aSelectionProcessor = null;
		}
Exemplo n.º 31
0
 public abstract bool ProcessWordByWord(OfficeDocumentProcessor aWordProcessor, ProcessingType eType);
Exemplo n.º 32
0
 public abstract bool ProcessWordByWord(OfficeDocumentProcessor aWordProcessor);
Exemplo n.º 33
0
		public bool ProcessWholeParagraphs(OfficeDocumentProcessor aWordProcessor, Word.Paragraphs aParagraphs)
		{
			foreach (Word.Paragraph aParagraph in aParagraphs)
			{
				// get the Range object for this paragraph
				Word.Range aParagraphRange = aParagraph.Range;

				// if we're picking up where we left off and we're not there yet...
				int nCharIndex = 0;
				if (aWordProcessor.AreLeftOvers)
				{
					if (aWordProcessor.LeftOvers.Start > aParagraphRange.End)
						continue;   // skip to the next paragraph

					nCharIndex = aWordProcessor.LeftOvers.StartIndex;
					aWordProcessor.LeftOvers = null; // turn off "left overs"
				}

				WordRange aRunRange = new WordRange(aParagraphRange);
				int nEndIndex = --aRunRange.EndIndex;
				int nLastIndex = nCharIndex;

				// exclude the paragraph end and process it as a whole unit (we may have to do this multiple times
				bool bStop = false;
				while (!bStop && (nCharIndex < nEndIndex))
				{
					aRunRange.StartIndex = nCharIndex;
					if (aRunRange.EndIndex != nEndIndex)
						aRunRange.EndIndex = nEndIndex;

					nLastIndex = nCharIndex;

					System.Diagnostics.Trace.WriteLine(String.Format("Start: {0}, End: {1}, text: {2}, length: {3}",
						aRunRange.Start, aRunRange.End, aRunRange.Text, aRunRange.Text.Length));

					if (!aWordProcessor.Process(aRunRange, ref nCharIndex))
					{
						aWordProcessor.LeftOvers = aRunRange;
						return false;
					}

					if (nLastIndex == nCharIndex)
						break;
				}
			}

			return true;
		}
Exemplo n.º 34
0
 void Reset_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
 {
     m_aWordByWordProcessor     = null;
     m_aWordByWordFontProcessor = null;
 }
Exemplo n.º 35
0
		protected bool ProcessParagraphs(OfficeDocumentProcessor aWordProcessor, PubParagraphs aPubParagraphs)
		{
			foreach (PubRange aParagraphRange in aPubParagraphs)
			{
				int nCharIndex = 0;
				if (!ProcessRangeAsWords(aWordProcessor, aParagraphRange, nCharIndex))
					return false;
			}

			return true;
		}
Exemplo n.º 36
0
		public override bool ProcessWordByWord(OfficeDocumentProcessor aWordProcessor)
		{
			if (aWordProcessor.AreLeftOvers)
			{
				DialogResult res = MessageBox.Show("Click 'Yes' to restart where you left off, 'No' to start over at the top, and 'Cancel' to quit", Connect.cstrCaption, MessageBoxButtons.YesNoCancel);
				if (res == DialogResult.No)
					aWordProcessor.LeftOvers = null;
				if (res == DialogResult.Cancel)
					return true;
			}

			if (Document.Selection.Type == Pub.PbSelectionType.pbSelectionNone)
				throw new ApplicationException("No story selected!");

			return ProcessStory(aWordProcessor, Document.Selection.TextRange.Story);
		}
Exemplo n.º 37
0
		void WholeDocumentConvert_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
		{
			if (!HookDocumentClose(Application.ActiveDocument))
				return;

			try
			{
				PubDocument doc = new PubDocument(Application.ActiveDocument, OfficeTextDocument.ProcessingType.eWordByWord);

				// we want to process the file word by word and show differences between
				//  the Input and (once) Converted string
				if (m_aWordByWordFontProcessor == null)
				{
					// first get the fonts the user wants to process
					FontConvertersPicker aFCsPicker = new FontConvertersPicker(doc);
					if ((aFCsPicker.ShowDialog() == DialogResult.OK) && (aFCsPicker.SelectedFontConverters.Count > 0))
					{
						FontConverters aFCs = aFCsPicker.SelectedFontConverters;
						m_aWordByWordFontProcessor = GetDocumentProcessor(aFCs, new SILConverterProcessorForm());
					}
				}

				if (m_aWordByWordFontProcessor != null)
					if (doc.ProcessWordByWord(m_aWordByWordFontProcessor))
						m_aWordByWordFontProcessor = null;
			}
			catch (Exception ex)
			{
				DisplayException(ex);
				if ((m_aWordByWordFontProcessor != null) && !m_aWordByWordFontProcessor.AreLeftOvers)
					m_aWordByWordFontProcessor = null;
			}
		}
Exemplo n.º 38
0
		void Reset()
		{
			m_aWordByWordFontProcessor = null;
			m_aThisStoryWordByWordFontProcessor = null;
		}
Exemplo n.º 39
0
		void ThisStoryConvert_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
		{
			if (!HookDocumentClose(Application.ActiveDocument))
				return;

			try
			{
#if DEBUG
				string strPubPIOVer = Application.Version;
				MessageBox.Show(String.Format("MSPub PIA version: {0}", strPubPIOVer));
#endif
				PubStoryDocument doc = new PubStoryDocument(Application.ActiveDocument, OfficeTextDocument.ProcessingType.eWordByWord);

				// we want to process the file word by word and show differences between
				//  the Input and (once) Converted string
				if ((m_aThisStoryWordByWordFontProcessor == null) || (m_strLastStoryName != doc.StoryName))
				{
					m_aThisStoryWordByWordFontProcessor = null; // just in case we came thru the latter OR case

					// first get the fonts the user wants to process
					FontConvertersPicker aFCsPicker = new FontConvertersPicker(doc);
					if ((aFCsPicker.ShowDialog() == DialogResult.OK) && (aFCsPicker.SelectedFontConverters.Count > 0))
					{
						FontConverters aFCs = aFCsPicker.SelectedFontConverters;
						m_aThisStoryWordByWordFontProcessor = GetDocumentProcessor(aFCs, new SILConverterProcessorForm());
					}
				}

				if (m_aThisStoryWordByWordFontProcessor != null)
				{
					if (doc.ProcessWordByWord(m_aThisStoryWordByWordFontProcessor))
					{
						m_aThisStoryWordByWordFontProcessor = null;
						m_strLastStoryName = null;
					}
					else
					{
						m_strLastStoryName = doc.StoryName;
					}
				}
			}
			catch (Exception ex)
			{
				DisplayException(ex);
				if ((m_aThisStoryWordByWordFontProcessor != null) && !m_aThisStoryWordByWordFontProcessor.AreLeftOvers)
					m_aThisStoryWordByWordFontProcessor = null;
			}
		}
Exemplo n.º 40
0
		public override bool ProcessWordByWord(OfficeDocumentProcessor aWordProcessor)
		{
			if (Document.Selection.Type == Pub.PbSelectionType.pbSelectionNone)
				throw new ApplicationException("Nothing selected!");

			PubRange aSelectionRange = (PubRange)SelectionRange;
			PubParagraphs aParagraphs = aSelectionRange.Paragraphs;
			if (aParagraphs.Count > 1)
				return ProcessParagraphs(aWordProcessor, aParagraphs);
			else
			{
				int nCharIndex = 0;
				return aWordProcessor.Process(aSelectionRange, ref nCharIndex);
			}
		}
Exemplo n.º 41
0
		public override bool ProcessWordByWord(OfficeDocumentProcessor aWordProcessor)
		{
			return ProcessWordByWord(aWordProcessor, m_eType);
		}
Exemplo n.º 42
0
		protected bool ProcessStory(OfficeDocumentProcessor aWordProcessor, Pub.Story aStory)
		{
			PubStory aPubStory = new PubStory(aStory);
			foreach (PubRange aParagraphRange in aPubStory.Paragraphs)
			{
				// if we're picking up where we left off and we're not there yet...
				int nCharIndex = 0;
				if (aWordProcessor.AreLeftOvers)
				{
					if (aWordProcessor.LeftOvers.Start > aParagraphRange.End)
						continue;   // skip to the next paragraph

					nCharIndex = aWordProcessor.LeftOvers.StartIndex;
					aWordProcessor.LeftOvers = null; // turn off "left overs"
				}

				if (!ProcessRangeAsWords(aWordProcessor, aParagraphRange, nCharIndex))
					return false;
			}

			// see if the user would like us to adjust the size to make it fit.
			if (    !aWordProcessor.SuspendUI
				&&  (aStory.HasTextFrame == Office.MsoTriState.msoTrue)
				&&  (aStory.TextFrame.Overflowing == Office.MsoTriState.msoTrue))
			{
				if (MessageBox.Show("The story has overflowed the text frame. Would you like me to adjust the text size so it fits?", Connect.cstrCaption, MessageBoxButtons.YesNo) == DialogResult.Yes)
				{
					try
					{
						aStory.TextFrame.AutoFitText = Pub.PbTextAutoFitType.pbTextAutoFitShrinkOnOverflow;
					}
					catch (Exception ex)
					{
						// this error is occasionally thrown when we try to do the auto fit... if it happens, just ignore it.
						// (it's just to save the user from having to reformat)
						if (ex.Message != "Error HRESULT E_FAIL has been returned from a call to a COM component.")
							throw;
					}
				}
			}

			return true;
		}
Exemplo n.º 43
0
		public abstract bool ProcessWordByWord(OfficeDocumentProcessor aWordProcessor);
Exemplo n.º 44
0
		void ConvertTableFieldDialog_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
		{
			dao.Database aDb = (dao.Database)Application.CurrentDb();
			if (aDb == null)
				return;

			dao.TableDefs aTableDefs = null;
			dao.TableDef aTableDef = null;
			dao.Recordset aRecordSet = null;
			try
			{
				aTableDefs = aDb.TableDefs;
				DbFieldSelect dlg = new DbFieldSelect(aTableDefs);
				if (dlg.ShowDialog() == DialogResult.OK)
				{
					aTableDef = aTableDefs[dlg.TableName];
					aRecordSet = aTableDef.OpenRecordset(dao.RecordsetTypeEnum.dbOpenTable, 0);
					// dao.RecordsetOptionEnum.);

					if (!aRecordSet.Updatable)
						throw new ApplicationException("Can't edit this table? Is it opened? If so, then close it and try again.");

					string strTitle = String.Format("Select the Converter for the {0}.{1} field", dlg.TableName, dlg.FieldName);
					EncConverters aECs = GetEncConverters;
					if (aECs != null)
					{
						IEncConverter aIEC = aECs.AutoSelectWithTitle(ConvType.Unknown, strTitle);
						FontConverter aFC = new FontConverter(new DirectableEncConverter(aIEC));
						OfficeDocumentProcessor aTableProcessor = new OfficeDocumentProcessor(aFC, new SILConverterProcessorForm());
						AccessDocument rsDoc = new AccessDocument(aRecordSet, dlg.FieldName);

						// do a transaction just in case we throw an exception trying to update and the user
						//  wants to rollback.
						aDb.BeginTrans();
						rsDoc.ProcessWordByWord(aTableProcessor);
						aDb.CommitTrans((int)dao.CommitTransOptionsEnum.dbForceOSFlush);
					}
				}
			}
			catch (Exception ex)
			{
				DisplayException(ex);
				if (ex.Message != Connect.cstrAbortMessage)
				{
					if (MessageBox.Show("Would you like to rollback the transaction?", Connect.cstrCaption, MessageBoxButtons.YesNo) == DialogResult.Yes)
						aDb.Rollback();
					else
						aDb.CommitTrans((int)dao.CommitTransOptionsEnum.dbForceOSFlush);
				}
			}
			finally
			{
				if( aRecordSet != null )
					aRecordSet.Close();
				ReleaseComObject(aRecordSet);
				ReleaseComObject(aTableDef);
				ReleaseComObject(aTableDefs);
				ReleaseComObject(aDb);
			}
		}
Exemplo n.º 45
0
 void SpellFixerReset_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
 {
     m_aSF = null;
     m_aWordByWordSpellFixerProcessor     = null;
     m_aWordByWordFontSpellFixerProcessor = null;
 }
Exemplo n.º 46
0
 void Reset()
 {
     m_aWordByWordFontProcessor          = null;
     m_aThisStoryWordByWordFontProcessor = null;
 }
Exemplo n.º 47
0
		public override bool ProcessWordByWord(OfficeDocumentProcessor aWordProcessor)
		{
			// if multiple paragraphs...
			int nCharIndex = 0;
			WordParagraphs aParagraphRanges = new WordParagraphs(Document.Application.Selection);
			foreach (Word.Range aRange in aParagraphRanges)
			{
				WordRange aThisParagraph = new WordRange(aRange);
				if (!ProcessRangeAsWords(aWordProcessor, aThisParagraph, nCharIndex))
					return false;
			}
			return true;
		}
Exemplo n.º 48
0
        void Reset_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
#endif
        {
            m_aSelectionProcessor = null;
        }
Exemplo n.º 49
0
 public override bool ProcessWordByWord(OfficeDocumentProcessor aWordProcessor)
 {
     return(ProcessWordByWord(aWordProcessor, m_eType));
 }
Exemplo n.º 50
0
        void ConvertTableFieldDialog_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
#endif
        {
#if DEBUG
            MessageBox.Show("ConvertTableFieldDialog_Click");
#endif
            dao.Database aDb = Application.CurrentDb();
            if (aDb == null)
            {
                return;
            }

            dao.TableDefs aTableDefs = null;
            dao.TableDef  aTableDef  = null;
            dao.Recordset aRecordSet = null;
            try
            {
                aTableDefs = aDb.TableDefs;
                DbFieldSelect dlg = new DbFieldSelect(aTableDefs);
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    aTableDef  = aTableDefs[dlg.TableName];
                    aRecordSet = aTableDef.OpenRecordset(dao.RecordsetTypeEnum.dbOpenTable, 0);
                    // dao.RecordsetOptionEnum.);

                    if (!aRecordSet.Updatable)
                    {
                        throw new ApplicationException("Can't edit this table? Is it opened? If so, then close it and try again.");
                    }

                    string        strTitle = String.Format("Select the Converter for the {0}.{1} field", dlg.TableName, dlg.FieldName);
                    EncConverters aECs     = GetEncConverters;
                    if (aECs != null)
                    {
                        IEncConverter           aIEC            = aECs.AutoSelectWithTitle(ConvType.Unknown, strTitle);
                        FontConverter           aFC             = new FontConverter(new DirectableEncConverter(aIEC));
                        OfficeDocumentProcessor aTableProcessor = new OfficeDocumentProcessor(aFC, new SILConverterProcessorForm());
                        AccessDocument          rsDoc           = new AccessDocument(aRecordSet, dlg.FieldName);

                        // do a transaction just in case we throw an exception trying to update and the user
                        //  wants to rollback.
                        aDb.BeginTrans();
                        rsDoc.ProcessWordByWord(aTableProcessor);
                        aDb.CommitTrans((int)dao.CommitTransOptionsEnum.dbForceOSFlush);
                    }
                }
            }
            catch (Exception ex)
            {
                DisplayException(ex);
                if (ex.Message != cstrAbortMessage)
                {
                    if (MessageBox.Show("Would you like to rollback the transaction?", OfficeApp.cstrCaption, MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        aDb.Rollback();
                    }
                    else
                    {
                        aDb.CommitTrans((int)dao.CommitTransOptionsEnum.dbForceOSFlush);
                    }
                }
            }
            finally
            {
                if (aRecordSet != null)
                {
                    aRecordSet.Close();
                }
                ReleaseComObject(aRecordSet);
                ReleaseComObject(aTableDef);
                ReleaseComObject(aTableDefs);
                ReleaseComObject(aDb);
            }
        }
Exemplo n.º 51
0
        protected bool ProcessWholeRange(OfficeDocumentProcessor aWordProcessor, OfficeRange aParagraphRange, int nCharIndex)
        {
            string strText = aParagraphRange.Text;
            int    nLength = (strText != null) ? strText.Length : 0;

            while ((nCharIndex < nLength) && (strText.IndexOfAny(m_achParagraphTerminators, nCharIndex, 1) == -1))
            {
                // get a copy of the range to work with
                OfficeRange aWordRange = Duplicate(aParagraphRange);

                // skip past initial spaces
                while ((nCharIndex < nLength) && (strText.IndexOfAny(m_achWhiteSpace, nCharIndex, 1) != -1))
                {
                    nCharIndex++;
                }

                // make sure we haven't hit the end of the paragraph (i.e. '\r') or range (beyond len)
                if (nCharIndex < nLength)
                {
                    if (strText.IndexOfAny(m_achParagraphTerminators, nCharIndex, 1) == -1)
                    {
                        // set the start index
                        aWordRange.StartIndex = nCharIndex;

                        // run through the characters in the word (i.e. until, space, NL, etc)
                        while ((nCharIndex < nLength) && (strText.IndexOfAny(m_achWordTerminators, nCharIndex, 1) == -1))
                        {
                            nCharIndex++;
                        }

                        // set the end of the range after the first space after the word (but not for NL)
                        if (++nCharIndex >= nLength)
                        {
                            --nCharIndex;
                        }

                        aWordRange.EndIndex = nCharIndex;

                        // make sure the word has text (sometimes it doesn't)
                        if (aWordRange.Text == null)                          // e.g. Figure "1" returns a null Text string
                        // if it does, see if it's "First Character" has any text (which it does in this case)
                        {
                            aWordRange.DealWithNullText();
                        }

                        // finally check it.
                        if (!aWordProcessor.Process(aWordRange, ref nCharIndex))
                        {
                            aWordProcessor.LeftOvers = aWordRange;
                            return(false);
                        }
                    }

                    strText = aParagraphRange.Text;                     // incase of replace, we've changed it.
                    nLength = (strText != null) ? strText.Length : 0;
                }
                else
                {
                    break;
                }
            }

            return(true);
        }
Exemplo n.º 52
0
		public bool ProcessParagraphsIsoFormat(OfficeDocumentProcessor aWordProcessor, Word.Paragraphs aParagraphs)
		{
			foreach (Word.Paragraph aParagraph in aParagraphs)
			{
				// get the Range object for this paragraph
				Word.Range aParagraphRange = aParagraph.Range;

				// if we're picking up where we left off and we're not there yet...
				int nCharIndex = 0;
				if (aWordProcessor.AreLeftOvers)
				{
					if (aWordProcessor.LeftOvers.Start > aParagraphRange.End)
						continue;   // skip to the next paragraph

					nCharIndex = aWordProcessor.LeftOvers.StartIndex;
					aWordProcessor.LeftOvers = null; // turn off "left overs"
				}

				WordRange aRunRange = new WordRange(aParagraphRange);
				int nStartIndex = aRunRange.StartIndex;
				System.Diagnostics.Debug.Assert(nStartIndex == 0);

				// if we have mixed character formatting, then use a binary search algorithm to find
				//	the maximum run.
				if (MixedCharacterFormatting(aRunRange))
				{
					int nWidth = aRunRange.EndIndex / 2;

					do
					{
						aRunRange.EndIndex++;

					} while (!MixedCharacterFormatting(aRunRange));

					aRunRange.EndIndex--;	// back up one
				}
				else
				{
					// the whole paragraph seems to be iso formatted, so exclude the paragraph end and
					// process it as a whole unit
					aRunRange.EndIndex--;
					if (!aWordProcessor.Process(aRunRange, ref nCharIndex))
					{
						aWordProcessor.LeftOvers = aRunRange;
						return false;
					}
				}
			}

			return true;
		}