示例#1
0
        public int Close(tagOLECLOSE dwSaveOption)
        {
            ComDebug.ReportInfo("{0}.IOleObject.Close {1}", GetType().Name, dwSaveOption);
            try
            {
                bool save = false, cancelled = false;

                switch (dwSaveOption)
                {
                case tagOLECLOSE.OLECLOSE_SAVEIFDIRTY:
                    save = true;
                    break;

                case tagOLECLOSE.OLECLOSE_PROMPTSAVE:
                    _comManager.InvokeGuiThread(
                        new Action(() =>
                    {
                        // If asked to prompt, do so only if dirty: if we get a YES, save as
                        // usual and close.  On NO, just close.  On CANCEL, return
                        // OLE_E_PROMPTSAVECANCELLED.
                        var r = System.Windows.MessageBox.Show("Save?", "Box", System.Windows.MessageBoxButton.YesNoCancel);
                        switch (r)
                        {
                        case System.Windows.MessageBoxResult.Yes:
                            save = true;
                            break;

                        case System.Windows.MessageBoxResult.Cancel:
                            cancelled = true;
                            break;
                        }
                    }));
                    break;

                case tagOLECLOSE.OLECLOSE_NOSAVE:
                    break;

                default:
                    ComDebug.ReportError("{0}.IOleObject.Close called with unknown parameter: {1}", GetType().Name, dwSaveOption);
                    break;
                }

                if (cancelled)
                {
                    ComDebug.ReportInfo("{0}.IOleObject.Close -> OLE_E_PROMPTSAVECANCELLED", GetType().Name);
                    return(ComReturnValue.OLE_E_PROMPTSAVECANCELLED);
                }

                if (save)
                {
                    SendAdvise_SaveObject();
                    SendAdvise_Saved();
                }

                // Regardless of whether the form has been shown we must
                // do all the normal shutdown actions.  (e.g. WinWord 2007)
                ComDebug.ReportInfo("{0}.IOleObject.Close -> BeginInvoke MainWindow.Close", GetType().Name);
                _comManager.ApplicationAdapter.BeginClosingApplication();
                return(ComReturnValue.NOERROR);
            }
            catch (Exception e)
            {
                ComDebug.ReportError("{0}.IOleObject.Close threw an exception: {1}", GetType().Name, e);
                throw;
            }
            // }
        }
		public int Close(tagOLECLOSE dwSaveOption)
		{
			ComDebug.ReportInfo("{0}.IOleObject.Close {1}", this.GetType().Name, dwSaveOption);
			try
			{
				bool save = false, cancelled = false;

				switch (dwSaveOption)
				{
					case tagOLECLOSE.OLECLOSE_SAVEIFDIRTY:
						save = true;
						break;

					case tagOLECLOSE.OLECLOSE_PROMPTSAVE:
						_comManager.InvokeGuiThread(
							 new Action(() =>
						 {
							 // If asked to prompt, do so only if dirty: if we get a YES, save as
							 // usual and close.  On NO, just close.  On CANCEL, return
							 // OLE_E_PROMPTSAVECANCELLED.
							 var r = System.Windows.MessageBox.Show("Save?", "Box", System.Windows.MessageBoxButton.YesNoCancel);
							 switch (r)
							 {
								 case System.Windows.MessageBoxResult.Yes:
									 save = true;
									 break;

								 case System.Windows.MessageBoxResult.Cancel:
									 cancelled = true;
									 break;
							 }
						 }));
						break;

					case tagOLECLOSE.OLECLOSE_NOSAVE:
						break;

					default:
						ComDebug.ReportError("{0}.IOleObject.Close called with unknown parameter: {1}", this.GetType().Name, dwSaveOption);
						break;
				}

				if (cancelled)
				{
					ComDebug.ReportInfo("{0}.IOleObject.Close -> OLE_E_PROMPTSAVECANCELLED", this.GetType().Name);
					return ComReturnValue.OLE_E_PROMPTSAVECANCELLED;
				}

				if (save)
				{
					SendAdvise_SaveObject();
					SendAdvise_Saved();
				}

				// Regardless of whether the form has been shown we must
				// do all the normal shutdown actions.  (e.g. WinWord 2007)
				ComDebug.ReportInfo("{0}.IOleObject.Close -> BeginInvoke MainWindow.Close", this.GetType().Name);
				_comManager.ApplicationAdapter.BeginClosingApplication();
				return ComReturnValue.NOERROR;
			}
			catch (Exception e)
			{
				ComDebug.ReportError("{0}.IOleObject.Close threw an exception: {1}", this.GetType().Name, e);
				throw;
			}
			// }
		}