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, 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.º 3
0
 public PubStory(Pub.Story basedOnStory)
 {
     m_aStoryBasedOn = basedOnStory;
     m_nOffset       = 0; // not sure if needed
 }