示例#1
0
 public ValidateForm(AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl visioControl, string vuiFileName, BackgroundWorker backgroundWorkerPathMaker)
 {
     this.vuiFileName = vuiFileName;
     this.backgroundWorkerPathMaker = backgroundWorkerPathMaker;
     this.visioControl = visioControl;
     InitializeComponent();
 }
示例#2
0
        public static Document OpenStencil(
            AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl drawingControl,
            string stencilPath)
        {
            if (drawingControl == null)
            {
                throw new ArgumentNullException("drawingControl");
            }

            // The drawing control object must be valid.
            if (drawingControl.Window == null || drawingControl.Window.Application == null)
            {
                // Throw a meaningful error.
                throw new ArgumentNullException("drawingControl");
            }
            Document targetStencil = null;

            Documents targetDocuments;

            targetDocuments = (Documents)drawingControl.Window.Application.Documents;

            // Open the stencil file invisibly.
            // A COMException will be thrown if the open fails.
            // If the stencil is currently open Visio will return a
            // reference to the open stencil.
            targetStencil = targetDocuments.OpenEx(stencilPath,
                                                   (short)VisOpenSaveArgs.visOpenRO |
                                                   (short)VisOpenSaveArgs.visOpenHidden |
                                                   (short)VisOpenSaveArgs.visOpenMinimized |
                                                   (short)VisOpenSaveArgs.visOpenNoWorkspace);

            return(targetStencil);
        }
示例#3
0
 public ValidateForm(AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl visioControl, string vuiFileName, BackgroundWorker backgroundWorkerPathMaker)
 {
     this.vuiFileName = vuiFileName;
     this.backgroundWorkerPathMaker = backgroundWorkerPathMaker;
     this.visioControl = visioControl;
     InitializeComponent();
 }
示例#4
0
        public static IVShape GetClickedShape(
            AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl drawingControl,
            double clickLocationX,
            double clickLocationY)
        {
            const double Tolerance = .0001;

            return(GetClickedShape(
                       drawingControl, clickLocationX, clickLocationY, Tolerance));
        }
示例#5
0
 static public string getCurrentFileDirectory(AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl visioControl)
 {
     if (visioControl.Src.Contains(Strings.VisioTemplateFileSuffix))
     {
         return(Environment.GetFolderPath(Environment.SpecialFolder.Personal));
     }
     else
     {
         return(System.IO.Path.GetDirectoryName(visioControl.Src));
     }
 }
        public ValidateResultsForm(string results, AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl visioControlIn, string formName)
        {
            InitializeComponent();
            UISpecResults_Load(results);
            this.BringToFront();
            visioControl = visioControlIn;
            this.results = results;

            //Close any open UI Spec results form
            CloseAllForms(formName);
        }
        public ValidateResultsForm(string results, AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl visioControlIn, string formName)
        {
            InitializeComponent();
            UISpecResults_Load(results);
            this.BringToFront();
            visioControl = visioControlIn;
            this.results = results;

            //Close any open UI Spec results form
            CloseAllForms(formName);
        }
示例#8
0
        public static System.Drawing.Point MapVisioToWindows(
            AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl drawingControl,
            double visioX,
            double visioY)
        {
            // The drawing control object must be valid.
            if (drawingControl == null)
            {
                // Throw a meaningful error.
                throw new ArgumentNullException("drawingControl");
            }

            int    windowsX = 0;
            int    windowsY = 0;
            double visioLeft;
            double visioTop;
            double visioWidth;
            double visioHeight;
            int    pixelLeft;
            int    pixelTop;
            int    pixelWidth;
            int    pixelHeight;
            Window referenceWindow;

            referenceWindow = (Window)drawingControl.Window;
            if (referenceWindow == null)
            {
                return(System.Drawing.Point.Empty);
            }
            // Get the window coordinates in Visio units.
            referenceWindow.GetViewRect(out visioLeft, out visioTop,
                                        out visioWidth, out visioHeight);

            // Get the window coordinates in pixels.
            referenceWindow.GetWindowRect(out pixelLeft, out pixelTop,
                                          out pixelWidth, out pixelHeight);

            // Convert the X coordinate by using pixels per inch from the
            // width values.
            windowsX = (int)(pixelLeft +
                             ((pixelWidth / visioWidth) * (visioX - visioLeft)));

            // Convert the Y coordinate by using pixels per inch from the
            // height values and transform from a top-left origin (windows
            // coordinates) to a bottom-left origin (Visio coordinates).
            windowsY = (int)(pixelTop +
                             ((pixelHeight / visioHeight) * (visioTop - visioY)));

            return(new System.Drawing.Point(windowsX, windowsY));
        }
示例#9
0
        public static IVShape GetClickedShape(
            AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl drawingControl,
            double clickLocationX,
            double clickLocationY,
            double tolerance)
        {
            if (drawingControl == null)
            {
                return(null);
            }

            // The drawing control object must be valid.
            if (drawingControl.Window == null)
            {
                // do nothing...and nothing can be done as well.
                return(null);
            }

            IVShape foundShape = null;

            Page currentPage;

            currentPage = drawingControl.Window.PageAsObj;

            // Use the spatial search method to return a list of
            // shapes at the location.
            Selection foundShapes = currentPage.get_SpatialSearch(
                clickLocationX, clickLocationY,
                (short)VisSpatialRelationCodes.visSpatialContainedIn,
                tolerance,
                (short)VisSpatialRelationFlags.visSpatialFrontToBack);

            if (foundShapes.Count > 0)
            {
                // The selection collection of shapes is 1-based, so
                // the first shape is at index 1.
                foundShape = foundShapes[1];
            }

            return(foundShape);
        }
示例#10
0
        public static Master GetMaster(
            AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl drawingControl,
            string stencilPath,
            string masterNameU)
        {
            // The drawing control object must be valid.
            if (drawingControl == null)
            {
                // Throw a meaningful error.
                throw new ArgumentNullException("drawingControl");
            }

            Master targetMaster = null;

            Document targetDocument;
            Masters  targetMasters;

            targetDocument = OpenStencil(drawingControl, stencilPath);
            targetMasters  = targetDocument.Masters;
            targetMaster   = targetMasters.get_ItemU(masterNameU);

            return(targetMaster);
        }
示例#11
0
        internal static void ExportDesignNotes(AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl visioControl)
        {
            string targetFilename;
            string currentFileName;

            if (saveFileDialog == null)
            {
                saveFileDialog             = new SaveFileDialog();
                saveFileDialog.Title       = Common.GetResourceString(Strings.SavePromptsTitleRes);
                saveFileDialog.Filter      = Common.GetResourceString(Strings.SavePromptsFilterRes);
                saveFileDialog.FilterIndex = 1;

                // Excel will ask about overwriting and I can't find a way to bypass that - so
                // skip it here and let excel do it on wb.close
                saveFileDialog.OverwritePrompt = false;
            }

            saveFileDialog.InitialDirectory = PathMaker.getCurrentFileDirectory(visioControl);

            targetFilename          = visioControl.Src;
            currentFileName         = System.IO.Path.GetFileName(targetFilename);
            saveFileDialog.FileName = Common.StripExtensionFileName(currentFileName) + "_DesignNotes.xlsx";

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                targetFilename = saveFileDialog.FileName;
            }
            else
            {
                return;
            }

            Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();

            if (excelApp == null)
            {
                Common.ErrorMessage("Couldn't start Excel - make sure it's installed");
                return;
            }
            excelApp.Visible = false;

            Workbook  wb = excelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
            Worksheet ws = (Worksheet)wb.Worksheets[1];

            if (ws == null)
            {
                Common.ErrorMessage("Excel worksheet couldn't be created.");
                return;
            }

            DocTitleShadow shadow  = PathMaker.LookupDocTitleShadow();
            string         client  = "";
            string         project = "";

            if (shadow != null)
            {
                client  = shadow.GetClientName();
                project = shadow.GetProjectName();
            }

            ws.Cells[1, 1].Value = "Client: " + client;
            ws.Cells[2, 1].Value = "Project: " + project;
            ws.Cells[3, 1].Value = "Date: " + DateTime.Now.ToString(Strings.DateColumnFormatString);

            ws.Cells[1, 1].Font.Bold = true;
            ws.Cells[2, 1].Font.Bold = true;
            ws.Cells[3, 1].Font.Bold = true;

            ws.Columns["A:A"].ColumnWidth = 6;
            ws.Columns["B:B"].ColumnWidth = 40;
            ws.Columns["C:C"].ColumnWidth = 100;
            ws.Columns["D:D"].ColumnWidth = 16;

            ((Range)ws.Columns["C:C"]).EntireColumn.WrapText = true;

            ws.Cells[5, 1].Value = "Count";
            ws.Cells[5, 2].Value = "State Name";
            ws.Cells[5, 3].Value = "Design Notes";
            ws.Cells[5, 4].Value = "Last Updated";

            ws.Cells[5, 1].Font.Bold = true;
            ws.Cells[5, 2].Font.Bold = true;
            ws.Cells[5, 3].Font.Bold = true;
            ws.Cells[5, 4].Font.Bold = true;

            ws.Cells[5, 4].HorizontalAlignment    = XlHAlign.xlHAlignLeft;
            ws.Columns["D:D"].HorizontalAlignment = XlHAlign.xlHAlignLeft;

            DesignNotesList designNotesList = Common.GetDesignNotesList();

            char[] delimiterChars = { '@' };
            //raw text looks like this... "design notes have been updated again@@02/18/2014"
            //splitting inot two parts for XLS writing

            int row   = 6;
            int count = 1;

            if (designNotesList.GetDesignNotes().Count >= 1)
            {
                foreach (DesignNotesList.DesignNoteContent designNote in designNotesList.GetDesignNotes())
                {
                    ws.Cells[row, 1] = count;
                    ws.Cells[row, 2] = designNote.StateId;

                    //string wording = Common.StripBracketLabels(designNote.Wording);
                    string[] notes = Common.StripBracketLabels(designNote.Wording).Split(delimiterChars);

                    if (notes[0].Length > 0)
                    {
                        ws.Cells[row, 3] = notes[0];
                        string lastUpdated = notes[2];
                        ws.Cells[row, 4] = lastUpdated;
                        ws.Rows[row].VerticalAlignment       = XlVAlign.xlVAlignCenter;
                        ws.Cells[row, 1].HorizontalAlignment = XlHAlign.xlHAlignCenter;
                    }
                    row++;
                    count++;
                }

                try
                {
                    wb.SaveAs(targetFilename);
                }
                catch
                {
                    Common.ErrorMessage("Excel worksheet couldn't be created.");
                }
            }
            else
            {
                Common.ErrorMessage("Excel worksheet generation skipped - no Design Notes found in VUI file.");
            }
            excelApp.Quit();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
            excelApp = null;
        }
示例#12
0
        internal static void ExportPromptList(DateTime?onOrAfterDate, bool hyperLinks, AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl visioControl)
        {
            string targetFilename;
            string currentFileName;

            if (saveFileDialog == null)
            {
                saveFileDialog             = new SaveFileDialog();
                saveFileDialog.Title       = Common.GetResourceString(Strings.SavePromptsTitleRes);
                saveFileDialog.Filter      = Common.GetResourceString(Strings.SavePromptsFilterRes);
                saveFileDialog.FilterIndex = 1;

                // Excel will ask about overwriting and I can't find a way to bypass that - so
                // skip it here and let excel do it on wb.close
                saveFileDialog.OverwritePrompt = false;
            }

            saveFileDialog.InitialDirectory = PathMaker.getCurrentFileDirectory(visioControl);

            targetFilename          = visioControl.Src;
            currentFileName         = System.IO.Path.GetFileName(targetFilename);
            saveFileDialog.FileName = Common.StripExtensionFileName(currentFileName) + "_Prompts.xlsx";

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                targetFilename = saveFileDialog.FileName;
            }
            else
            {
                return;
            }

            Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();

            if (excelApp == null)
            {
                Common.ErrorMessage("Couldn't start Excel - make sure it's installed");
                return;
            }
            excelApp.Visible = false;

            Workbook  wb = excelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
            Worksheet ws = (Worksheet)wb.Worksheets[1];

            if (ws == null)
            {
                Common.ErrorMessage("Excel worksheet couldn't be created.");
                return;
            }

            DocTitleShadow shadow  = PathMaker.LookupDocTitleShadow();
            string         client  = "";
            string         project = "";

            if (shadow != null)
            {
                client  = shadow.GetClientName();
                project = shadow.GetProjectName();
            }

            ws.Cells[1, 1].Value          = "Client: " + client;
            ws.Cells[2, 1].Value          = "Project: " + project;
            ws.Cells[3, 1].Value          = "Date: " + DateTime.Now.ToString(Strings.DateColumnFormatString);
            ws.Columns["A:A"].ColumnWidth = 8;
            ws.Columns["B:C"].ColumnWidth = 30;
            ws.Columns["D:E"].ColumnWidth = 50;

            ((Range)ws.Columns["C:E"]).EntireColumn.WrapText = true;

            ws.Cells[5, 1].Value = "Count";
            ws.Cells[5, 2].Value = "Prompt ID";
            ws.Cells[5, 3].Value = "Duplicate IDs";
            ws.Cells[5, 4].Value = "Prompt Wording";
            ws.Cells[5, 5].Value = "Notes";

            ws.Cells[5, 1].Font.Bold = true;
            ws.Cells[5, 2].Font.Bold = true;
            ws.Cells[5, 3].Font.Bold = true;
            ws.Cells[5, 4].Font.Bold = true;
            ws.Cells[5, 5].Font.Bold = true;

            PromptRecordingList recordingList = Common.GetPromptRecordingList(onOrAfterDate);

            List <string> duplicateIdList = recordingList.GetDuplicatePromptIds();

            if (duplicateIdList.Count > 0)
            {
                string list        = String.Empty;
                int    lineCounter = 1;
                foreach (string s in duplicateIdList)
                {
                    list += s;
                    list += ", ";
                    if (list.Length > (lineCounter * 60))
                    {
                        list += "\n";
                        lineCounter++;
                    }
                }
                list = list.Substring(0, list.Length - 2);

                Common.ErrorMessage("Warning: multiple copies of prompt ids in the design.\n" +
                                    "Management and testing of each is NOT handled by the tools.\n" +
                                    "You are responsible for reviewing and testing that each is correct.\n" +
                                    "Recommended that you fix the prompt numbers and let the tools handle it.\n" +
                                    "\n" +
                                    "Duplicates:\n" +
                                    list);
            }

            int row   = 7;
            int count = 1;

            foreach (PromptRecordingList.PromptRecording recording in recordingList.GetPromptRecordings())
            {
                ws.Cells[row, 1] = count;
                ws.Cells[row, 2] = recording.PromptId;
                ws.Cells[row, 3] = MakeDuplicateString(recording.GetDuplicateIds());
                string wording = Common.StripBracketLabels(recording.Wording);
                ws.Cells[row, 4] = wording;

                // if the whole wording is the label, there are no []s
                string label = Common.MakeLabelName(recording.Wording);
                if (label.Length != wording.Length)
                {
                    ws.Cells[row, 5] = Common.MakeLabelName(recording.Wording);
                }

                if (hyperLinks)
                {
                    string recordingFile = Common.GetResourceString(Strings.PromptRecordingLocationRes);
                    recordingFile += "\\" + recording.PromptId + ".wav";
                    ws.Hyperlinks.Add(ws.Cells[row, 2], recordingFile);
                }

                row++;
                count++;
            }

            try {
                wb.SaveAs(targetFilename);
            }
            catch {
            }
            excelApp.Quit();;
            System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
            excelApp = null;
        }
示例#13
0
        internal static string ExportFastPathXML(AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl visioControl, bool useTmpFile)
        {
            DocTitleShadow docTitleShadow = PathMaker.LookupDocTitleShadow();

            if (docTitleShadow == null)
            {
                Common.ErrorMessage("Missing Document Title shape");
                return(null);
            }
            StartShadow startShadow = PathMaker.LookupStartShadow();

            if (startShadow == null)
            {
                Common.ErrorMessage("Missing Start shape");
                return(null);
            }

            changeLogShadow = PathMaker.LookupChangeLogShadow();
            if (changeLogShadow == null)
            {
                Common.ErrorMessage("Missing Change Log shape");
                return(null);
            }

            if (saveFileDialog == null)
            {
                saveFileDialog             = new SaveFileDialog();
                saveFileDialog.Title       = Common.GetResourceString(Strings.SaveFastPathXMLTitleRes);
                saveFileDialog.Filter      = Common.GetResourceString(Strings.SaveFastPathXMLFilterRes);
                saveFileDialog.FilterIndex = 1;
            }

            saveFileDialog.InitialDirectory = PathMaker.getCurrentFileDirectory(visioControl);
            saveFileDialog.RestoreDirectory = true;

            targetFilename          = visioControl.Src;
            currentFileName         = System.IO.Path.GetFileName(targetFilename);
            saveFileDialog.FileName = Common.StripExtensionFileName(currentFileName) + ".xml";

            if (!useTmpFile)
            {
                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    targetFilename = saveFileDialog.FileName;
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                targetFilename = saveFileDialog.FileName + ".tmp";
            }

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.XmlResolver = null;
            xmlDoc.LoadXml(xmlStrings.Header);
            xmlDoc.DocumentElement.SetAttribute(xmlStrings.Project, docTitleShadow.GetProjectName());
            xmlDoc.DocumentElement.SetAttribute(xmlStrings.Client, docTitleShadow.GetClientName());
            xmlDoc.DocumentElement.SetAttribute(xmlStrings.LastModified, changeLogShadow.GetLastLogChangeDate());
            xmlDoc.DocumentElement.SetAttribute(xmlStrings.Version, changeLogShadow.GetLastChangeVersion());

            AddStartElement(xmlDoc, startShadow);

            List <Shadow> shadowList = PathMaker.LookupAllShadows();
            // sorting them here helps the Missed statements in PathRunner come out in order
            string stateSortOrder = startShadow.GetDefaultSetting(Strings.DefaultSettingsStateSortOrder);

            if (stateSortOrder.Equals(Strings.StateSortOrderAlphaNumerical))
            {
                shadowList.Sort(Common.StateIdShadowSorterAlphaNumerical);
            }
            else if (stateSortOrder.Equals(Strings.StateSortOrderNumericalOnly))
            {
                shadowList.Sort(Common.StateIdShadowSorterNumericalAlpha);
            }
            else
            {
                Common.StateIdShadowSorterVisioHeuristic(shadowList, visioControl.Document, startShadow);
            }

            foreach (Shadow shadow in shadowList)
            {
                switch (shadow.GetShapeType())
                {
                case ShapeTypes.Interaction:
                    AddInteractionElement(xmlDoc, shadow as InteractionShadow);
                    break;

                case ShapeTypes.Play:
                    AddPlayElement(xmlDoc, shadow as PlayShadow);
                    break;

                case ShapeTypes.Decision:
                    AddDecisionElement(xmlDoc, shadow as DecisionShadow);
                    break;

                case ShapeTypes.Data:
                    AddDataElement(xmlDoc, shadow as DataShadow);
                    break;

                case ShapeTypes.SubDialog:
                    AddSubDialogElement(xmlDoc, shadow as SubDialogShadow);
                    break;

                default:
                    break;
                }
            }

            xmlDoc.Save(targetFilename);
            return(targetFilename);
        }
示例#14
0
 internal static string ExportFastPathXML(AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl visioControl)
 {
     return(ExportFastPathXML(visioControl, false));
 }
示例#15
0
        public DialogResult SaveDrawing(AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl visioControl, bool promptFirst, bool saveAs)
        {
            if (visioControl == null)
            {
                return(DialogResult.Cancel);
            }

            if (visioControl.Document.Saved && !saveAs)
            {
                return(DialogResult.Ignore);
            }

            DialogResult result          = DialogResult.No;
            string       targetFilename  = string.Empty;
            string       currentFileName = string.Empty;
            Document     targetDocument;

            targetFilename  = visioControl.Src;
            targetDocument  = (Document)visioControl.Document;
            currentFileName = System.IO.Path.GetFileName(targetFilename);
            // Prompt to save changes.
            if (promptFirst == true)
            {
                string prompt = string.Empty;
                string title  = string.Empty;

                title = Common.GetResourceString(Strings.SaveDialogTitleRes);

                if (targetFilename == null)
                {
                    return(DialogResult.Cancel);
                }

                // Save changes to the existing drawing.
                if ((saveAs || targetFilename.Length > 0) && (!targetFilename.Contains(Strings.VisioTemplateFileSuffix)))
                {
                    prompt  = Common.GetResourceString(Strings.SavePromptRes);
                    prompt += Environment.NewLine;
                    prompt += targetFilename;
                }
                else
                {
                    // Save changes as new drawing.
                    prompt = Common.GetResourceString(Strings.SaveAsPromptRes);
                }
                result = MessageBox.Show(prompt, title, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
            }
            else
            {
                result = DialogResult.Yes;
            }

            // Display a file browse dialog to select path and filename.
            if ((DialogResult.Yes == result) && (saveAs || targetFilename.Length == 0 || targetFilename.Contains(Strings.VisioTemplateFileSuffix)))
            {
                // Set up the save file dialog and let the user specify the
                // name to save the document to.
                if (saveFileDialog == null)
                {
                    saveFileDialog             = new SaveFileDialog();
                    saveFileDialog.Title       = Common.GetResourceString(Strings.SaveDialogTitleRes);
                    saveFileDialog.Filter      = Common.GetResourceString(Strings.SaveDialogFilterRes);
                    saveFileDialog.FilterIndex = 1;
                }

                saveFileDialog.InitialDirectory = getCurrentFileDirectory();

                if (targetFilename.Contains(Strings.VisioTemplateFileSuffix))
                {
                    saveFileDialog.FileName = Strings.DefaultFileName;
                }
                else
                {
                    saveFileDialog.FileName = Common.StripExtensionFileName(currentFileName) + Strings.DefaultCopyFileNameSuffix;
                }

                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    targetFilename = saveFileDialog.FileName;
                }
                else
                {
                    targetFilename = string.Empty;
                }
            }
            // Save the document to the filename specified by
            // the end user in the save file dialog, or the existing file name.
            if ((DialogResult.Yes == result) && (targetFilename.Length > 0))
            {
                if (targetDocument != null)
                {
                    targetDocument.SaveAs(targetFilename);
                }

                // without these garbage collection calls in here, we get an access violation...
                GC.Collect();
                GC.WaitForPendingFinalizers();

                if (!visioControl.Src.Equals(targetFilename))
                {
                    visioControl.Src = targetFilename;
                    OnSrcDocumentChange();
                }
                visioControl.Document.Saved = true;
            }
            return(result);
        }
示例#16
0
        public static DialogResult SaveDrawing(
            AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl drawingControl,
            bool promptFirst)
        {
            if (drawingControl == null)
            {
                return(DialogResult.Cancel);
            }


            SaveFileDialog saveFileDialog = null;
            DialogResult   result         = DialogResult.No;
            string         targetFilename = string.Empty;
            Document       targetDocument;

            try {
                targetFilename = drawingControl.Src;
                targetDocument = (Document)drawingControl.Document;

                // Prompt to save changes.
                if (promptFirst == true)
                {
                    string prompt = string.Empty;
                    string title  = string.Empty;

                    title = Utility.GetResourceString(Strings.SaveDialogTitle);

                    if (targetFilename == null)
                    {
                        return(DialogResult.Cancel);
                    }

                    // Save changes to the existing drawing.
                    if (targetFilename.Length > 0)
                    {
                        prompt  = Utility.GetResourceString(Strings.SavePrompt);
                        prompt += Environment.NewLine;
                        prompt += targetFilename;
                    }
                    else
                    {
                        // Save changes as new drawing.
                        prompt = Utility.GetResourceString(Strings.SaveAsPrompt);
                    }
                    result = Utility.RtlAwareMessageBoxShow(null, prompt, title,
                                                            MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question,
                                                            drawingControl.Window.Application.AlertResponse);
                }
                else
                {
                    result = DialogResult.Yes;
                }

                // Display a file browse dialog to select path and filename.
                if ((DialogResult.Yes == result) && (targetFilename.Length == 0))
                {
                    // Set up the save file dialog and let the user specify the
                    // name to save the document to.
                    saveFileDialog       = new SaveFileDialog();
                    saveFileDialog.Title =
                        Utility.GetResourceString(Strings.SaveDialogTitle);
                    saveFileDialog.Filter =
                        Utility.GetResourceString(Strings.SaveDialogFilter);
                    saveFileDialog.FilterIndex      = 1;
                    saveFileDialog.InitialDirectory =
                        System.Windows.Forms.Application.StartupPath;

                    if (saveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        targetFilename = saveFileDialog.FileName;
                    }
                }
                // Save the document to the filename specified by
                // the end user in the save file dialog, or the existing file name.
                if ((DialogResult.Yes == result) && (targetFilename.Length > 0))
                {
                    if (targetDocument != null)
                    {
                        targetDocument.SaveAs(targetFilename);
                    }
                    drawingControl.Src            = targetFilename;
                    drawingControl.Document.Saved = true;
                }
            }
            finally {
                // Make sure the dialog is cleaned up.
                if (saveFileDialog != null)
                {
                    saveFileDialog.Dispose();
                }
            }
            return(result);
        }