コード例 #1
0
        public void Advise(System.Runtime.InteropServices.ComTypes.IDataObject dataObject, ref System.Runtime.InteropServices.ComTypes.FORMATETC fetc, System.Runtime.InteropServices.ComTypes.ADVF advf, System.Runtime.InteropServices.ComTypes.IAdviseSink advise, out int pdwConnection)
        {
            int con = -1;

            System.Runtime.InteropServices.ComTypes.FORMATETC etc = fetc;

            Invoke("Advise", () => _dataAdviseHolder.Advise(dataObject, ref etc, advf, advise, out con));
            if (!(-1 != con))
            {
                throw new InvalidOperationException(nameof(con) + " should be != -1");
            }

            ComDebug.ReportInfo("ManagedDataAdviseHolder giving out con={0}", con);
            pdwConnection = con;
        }
コード例 #2
0
ファイル: OleObjectBase.cs プロジェクト: olesar/Altaxo
 /// <summary>
 /// Notifies a container when an embedded object's window is about to become invisible.
 /// The container uses this information to remove the shading when the object is not visible any more.
 /// </summary>
 public virtual void SendAdvise_HideWindow()
 {
     ComDebug.ReportInfo("{0}.SendAdvise.HideWindow -> Calling IOleClientSite.OnShowWindow(false)", GetType().Name);
     try
     {
         if (null != _clientSite)
         {
             _clientSite.OnShowWindow(false);
         }
     }
     catch (Exception ex)
     {
         ComDebug.ReportError("{0}.SendAdvise.HideWindow -> Exception while calling _clientSite.OnShowWindow(false), Details: {0}", GetType().Name, ex.Message);
     }
 }
コード例 #3
0
        public int GetExtent(int dwDrawAspect, tagSIZEL pSizel)
        {
            ComDebug.ReportInfo("{0}.IOleObject.GetExtent", GetType().Name);
            if ((dwDrawAspect & (int)DVASPECT.DVASPECT_CONTENT) == 0)
            {
                return(ComReturnValue.E_FAIL);
            }

            var renderingOptions = EmbeddedGraphDocumentRenderingHelper.GetRenderingOptions(_document);

            var docSize_pt = _document.Size * renderingOptions.OutputScalingFactor;

            pSizel = new tagSIZEL((int)(docSize_pt.X * PointsToHimetric), (int)(docSize_pt.Y * PointsToHimetric));

            return(ComReturnValue.NOERROR);
        }
コード例 #4
0
 /// <summary>Invokes on the invokable thread.</summary>
 /// <param name="actionName">For debugging purposes.</param>
 /// <param name="action">The action to invoke.</param>
 private void Invoke(string actionName, Action action)
 {
     if (0 == _invokeCount) // no reentrancy
     {
         _previousActionName = actionName;
         ++_invokeCount;
         ComDebug.ReportInfo("OleAdviseThread {0}", actionName);
         _invokeableThread.Invoke(action);
         --_invokeCount;
     }
     else // Invoke was called before and is has not finished up to now
     {
         ComDebug.ReportWarning("ManagedOleAdviseHolder.Invoke: because a previous action ({0}) is still running, the action ({1}) is invoked asynchronously now.", _previousActionName, actionName);
         _invokeableThread.InvokeAsync(action);
     }
 }
コード例 #5
0
        public GraphDocumentLinkedComObject(GraphDocument graphDocument, ProjectFileComObject fileComObject, ComManager comManager)
            : base(comManager)
        {
            ComDebug.ReportInfo("{0} constructor.", GetType().Name);

            _dataAdviseHolder = new ManagedDataAdviseHolder();
            _oleAdviseHolder  = new ManagedOleAdviseHolderFM();

            Document = graphDocument;

            if (null != fileComObject)
            {
                fileComObject.FileMonikerChanged += EhFileMonikerChanged;
                EhFileMonikerChanged(fileComObject.FileMoniker);
            }
        }
コード例 #6
0
ファイル: ComStreamWrapper.cs プロジェクト: olesar/Altaxo
        public override void Close()
        {
            if (null != _istream)
            {
                //_istream.Commit(0);
                if (_isStreamOwner)
                {
                    Marshal.ReleaseComObject(_istream);
                    ComDebug.ReportInfo("ComStreamWrapper.Close: istream released");

                    ReportDebugStream("StreamWrapper.Close");
                }
                _istream = null;
            }
            base.Close();
        }
コード例 #7
0
ファイル: ComManager.cs プロジェクト: olesar/Altaxo
        private void InternalStopLocalServer()
        {
            ComDebug.ReportInfo("Stop local server");

            if (null != _embeddedComObject)
            {
                _embeddedComObject.Dispose();
                _embeddedComObject = null;
            }

            foreach (var co in _linkedDocumentsComObjects.Values)
            {
                co.Dispose();
            }
            _linkedDocumentsComObjects.Clear();

            if (null != _fileComObject)
            {
                _fileComObject.Dispose();
                _fileComObject = null;
            }

            if (null != _classFactoryOfDocumentComObject)
            {
                _classFactoryOfDocumentComObject.RevokeClassObject();
                ComDebug.ReportInfo("{0}.StopLocalServer:{1} Revoked.", GetType().Name, _classFactoryOfDocumentComObject.GetType().Name);
                _classFactoryOfDocumentComObject = null;
            }

            if (null != _classFactoryOfFileComObject)
            {
                _classFactoryOfFileComObject.RevokeClassObject();
                ComDebug.ReportInfo("{0}.StopLocalServer:{1} Revoked.", GetType().Name, _classFactoryOfFileComObject.GetType().Name);
                _classFactoryOfFileComObject = null;
            }

            if (null != _garbageCollector)
            {
                // Now stop the Garbage Collector thread.
                _garbageCollector.StopThread();
                _garbageCollector.WaitForThreadToStop();
                _garbageCollector = null;
                ComDebug.ReportInfo("StopLocalServer: GarbageCollector thread stopped.");
            }

            IsActive = false;
        }
コード例 #8
0
ファイル: ComManager.cs プロジェクト: olesar/Altaxo
        public void StartLocalServer()
        {
            IsActive = true;

            ComDebug.ReportInfo("Starting local server");

            // if we are in 64 bit mode, make sure that the PreferredServerBitness flag is set in the registry

            {
                // Register the FileComObject
                _classFactoryOfFileComObject = new ClassFactory_ProjectFileComObject(this)
                {
                    ClassContext = (uint)(CLSCTX.CLSCTX_LOCAL_SERVER),
                    ClassId      = Marshal.GenerateGuidForType(typeof(ProjectFileComObject)),
                    Flags        = (uint)REGCLS.REGCLS_SINGLEUSE | (uint)REGCLS.REGCLS_SUSPENDED
                };
                _classFactoryOfFileComObject.RegisterClassObject();
                ComDebug.ReportInfo("{0}.StartLocalServer Registered: {1}", GetType().Name, _classFactoryOfFileComObject.GetType().Name);
            }

            if (ApplicationWasStartedWithEmbeddingArg)
            {
                // Register the SimpleCOMObjectClassFactory.
                _classFactoryOfDocumentComObject = new ClassFactory_GraphDocumentEmbeddedComObject(this)
                {
                    ClassContext = (uint)(CLSCTX.CLSCTX_LOCAL_SERVER),
                    ClassId      = Marshal.GenerateGuidForType(typeof(GraphDocumentEmbeddedComObject)),
                    Flags        = (uint)REGCLS.REGCLS_SINGLEUSE | (uint)REGCLS.REGCLS_SUSPENDED
                };
                _classFactoryOfDocumentComObject.RegisterClassObject();
                ComDebug.ReportInfo("{0}.StartLocalServer Registered: {1}", GetType().Name, _classFactoryOfDocumentComObject.GetType().Name);
            }

            ClassFactoryBase.ResumeClassObjects();

            // Start up the garbage collection thread.
            _garbageCollector = new GarbageCollector(1000);
            var GarbageCollectionThread = new Thread(new ThreadStart(_garbageCollector.GCWatch))
            {
                // Set the name of the thread object.
                Name         = "GarbCollThread",
                IsBackground = true
            };

            // Start the thread.
            GarbageCollectionThread.Start();
        }
コード例 #9
0
        public override void InternalCreateInstance(IntPtr pUnkOuter, ref Guid riid, out IntPtr ppvObject)
        {
            ComDebug.ReportInfo("{0}.CreateInstance(), requesting interface {1}", GetType().Name, riid);

            if (riid == Marshal.GenerateGuidForType(typeof(System.Runtime.InteropServices.ComTypes.IDataObject)) ||
                riid == InterfaceGuid.IID_IDispatch ||
                riid == InterfaceGuid.IID_IUnknown)
            {
                var documentComObject = _comManager.GetNewEmbeddedGraphDocumentComObject();

                ppvObject = Marshal.GetComInterfaceForObject(documentComObject, typeof(System.Runtime.InteropServices.ComTypes.IDataObject));
            }
            else
            {
                throw new COMException("No interface", unchecked ((int)0x80004002));
            }
        }
コード例 #10
0
        private IntPtr RenderBitmapAsDropFile(TYMED tymed)
        {
            ComDebug.ReportInfo("GraphDocumentDataObject.BitmapAsDropFile");

            if (!(tymed == TYMED.TYMED_HGLOBAL))
            {
                throw new ArgumentException(nameof(tymed) + " is not TYMED_HGLOBAL");
            }

            EnsureDropFileCreated();

            if (!string.IsNullOrEmpty(_graphDocumentDropdownFileName))
            {
                return(DataObjectHelper.RenderFiles(new string[] { _graphDocumentDropdownFileName }));
            }
            return(IntPtr.Zero);
        }
コード例 #11
0
        public override void InternalCreateInstance(IntPtr pUnkOuter, ref Guid riid, out IntPtr ppvObject)
        {
            ComDebug.ReportInfo("{0}.CreateInstance(), requesting interface {1}", GetType().Name, riid);

            if (riid == Marshal.GenerateGuidForType(typeof(System.Runtime.InteropServices.ComTypes.IPersistFile)) ||
                riid == Marshal.GenerateGuidForType(typeof(IOleItemContainer)) ||
                riid == InterfaceGuid.IID_IDispatch ||
                riid == InterfaceGuid.IID_IUnknown)
            {
                // notify the ComManager that we are about to enter linked object mode.
                _comManager.EnterLinkedObjectMode();
                ppvObject = Marshal.GetComInterfaceForObject(_comManager.FileComObject, typeof(System.Runtime.InteropServices.ComTypes.IPersistFile));
            }
            else
            {
                throw new COMException("No interface", unchecked ((int)0x80004002));
            }
        }
コード例 #12
0
        private IntPtr RenderBitmapDIBV5(TYMED tymed)
        {
            ComDebug.ReportInfo("GraphDocumentDataObject.RenderBitmapDIBV5");

            if (!(tymed == TYMED.TYMED_HGLOBAL))
            {
                throw new ArgumentException(nameof(tymed) + " is not TYMED_HGLOBAL");
            }

            if (null != _graphDocumentBitmapImage)
            {
                return(DataObjectHelper.RenderDIBV5BitmapToHGLOBAL(_graphDocumentBitmapImage));
            }
            else
            {
                throw new InvalidProgramException("Please report this exception to the author of the program and describe the steps to reproduce the exception");
            }
        }
コード例 #13
0
 public void GetDataHere(ref System.Runtime.InteropServices.ComTypes.FORMATETC format, ref System.Runtime.InteropServices.ComTypes.STGMEDIUM medium)
 {
     ComDebug.ReportInfo("{0}.IDataObject.GetDataHere({1})", GetType().Name, DataObjectHelper.ClipboardFormatName(format.cfFormat));
     // Allows containers to duplicate this into their own storage.
     try
     {
         if (InternalGetDataHere(ref format, ref medium))
         {
             return; // data could be provided
         }
     }
     catch (Exception e)
     {
         ComDebug.ReportError("{0}.IDataObject.GetDataHere threw an exception: {1}", GetType().Name, e);
         throw;
     }
     Marshal.ThrowExceptionForHR(ComReturnValue.DATA_E_FORMATETC);
 }
コード例 #14
0
        public int QueryGetData(ref FORMATETC format)
        {
            ComDebug.ReportInfo("{0}.IDataObject.QueryGetData, tymed={1}, aspect={2}", GetType().Name, format.tymed, format.dwAspect);

            int ret;

            // We only support CONTENT aspect
            if ((DVASPECT.DVASPECT_CONTENT & format.dwAspect) == 0)
            {
                ret = ComReturnValue.DV_E_DVASPECT;
            }
            else
            {
                ret = ComReturnValue.DV_E_TYMED;

                // Try to locate the data
                // TODO: The ret, if not S_OK, is only relevant to the last item
                foreach (var rendering in Renderings)
                {
                    if ((rendering.format.tymed & format.tymed) > 0)
                    {
                        if (rendering.format.cfFormat == format.cfFormat)
                        {
                            // Found it, return S_OK;
                            ret = ComReturnValue.S_OK;
                            break;
                        }
                        else
                        {
                            // Found the medium type, but wrong format
                            ret = ComReturnValue.DV_E_FORMATETC;
                        }
                    }
                    else
                    {
                        // Mismatch on medium type
                        ret = ComReturnValue.DV_E_TYMED;
                    }
                }
            }

            ComDebug.ReportInfo("{0}.IDataObject.QueryGetData is returning 0x{1:X}", GetType().Name, ret);
            return(ret);
        }
コード例 #15
0
        public void GetData(ref FORMATETC format, out STGMEDIUM medium)
        {
            ComDebug.ReportInfo("{0}.IDataObject.GetData({1})", GetType().Name, DataObjectHelper.FormatEtcToString(format));

            try
            {
                // Locate the data
                foreach (var rendering in Renderings)
                {
                    if ((rendering.format.tymed & format.tymed) > 0 &&
                        rendering.format.dwAspect == format.dwAspect &&
                        rendering.format.cfFormat == format.cfFormat &&
                        rendering.renderer != null)
                    {
                        // Found it. Return a copy of the data.

                        medium = new STGMEDIUM
                        {
                            tymed = rendering.format.tymed & format.tymed
                        };
                        medium.unionmember = rendering.renderer(medium.tymed);
                        if (medium.tymed == TYMED.TYMED_ISTORAGE || medium.tymed == TYMED.TYMED_ISTREAM)
                        {
                            medium.pUnkForRelease = Marshal.GetObjectForIUnknown(medium.unionmember);
                        }
                        else
                        {
                            medium.pUnkForRelease = null;
                        }
                        return;
                    }
                }
            }
            catch (Exception e)
            {
                ComDebug.ReportError("{0}.IDataObject.GetData threw an exception {1}", GetType().Name, e);
                throw;
            }

            ComDebug.ReportInfo("{0}.IDataObject.GetData, no data delivered!", GetType().Name);
            medium = new STGMEDIUM();
            // Marshal.ThrowExceptionForHR(ComReturnValue.DV_E_FORMATETC);
        }
コード例 #16
0
        public void Advise(IAdviseSink pAdvise, out int pdwConnection)
        {
            int conn = -1;

            Invoke("Advise", () =>
            {
                ComDebug.ReportInfo("ManagedOleAdviseHolder.Advise (before calling Advise)", conn);
                _oleAdviseHolder.Advise(pAdvise, out conn);
                ComDebug.ReportInfo("ManagedOleAdviseHolder.Advise has given out cookie={0}", conn);
            }
                   );

            if (!(-1 != conn))
            {
                throw new InvalidOperationException(nameof(conn) + " should be != -1");
            }

            pdwConnection = conn;
        }
コード例 #17
0
        public IEnumFORMATETC EnumFormatEtc(DATADIR direction)
        {
            ComDebug.ReportInfo("{0}.IDataObject.EnumFormatEtc", GetType().Name);
            try
            {
                // We only support GET
                if (DATADIR.DATADIR_GET == direction)
                {
                    return(new EnumFormatEtc(new List <FORMATETC>(Renderings.Select(x => x.format))));
                }
            }
            catch (Exception e)
            {
                ComDebug.ReportError("{0}.IDataObject.EnumFormatEtc exception: {1}", GetType().Name, e);
                throw;
            }

            throw new NotImplementedException("Can not use registry here because a return value is not supported");
        }
コード例 #18
0
        public int SetExtent(int dwDrawAspect, tagSIZEL pSizel)
        {
            ComDebug.ReportInfo("{0}.IOleObject.SetExtent({1}x{2}) -> not supported.", GetType().Name, pSizel.cx, pSizel.cy);

            /*
             *                if ((dwDrawAspect & (int)DVASPECT.DVASPECT_CONTENT) != 0)
             *                {
             *                        try
             *                        {
             *                                _document.Size = new Graph.PointD2D(pSizel.cx / PointsToHimetric, pSizel.cy / PointsToHimetric);
             *                                return ComReturnValue.S_OK;
             *                        }
             *                        catch (Exception e)
             *                        {
             *                                Debug.ReportError("{0}.SetExtent threw an exception: {1}", this.GetType().Name, e);
             *                        }
             *                }
             */
            return(ComReturnValue.E_FAIL);
        }
コード例 #19
0
ファイル: ComManager.cs プロジェクト: olesar/Altaxo
        public GraphDocumentLinkedComObject GetDocumentsComObjectForGraphDocument(GraphDocument doc)
        {
            if (null == doc)
            {
                throw new ArgumentNullException();
            }

            ComDebug.ReportInfo("{0}.GetDocumentsComObjectForGraphDocument Name={1}", GetType().Name, doc.Name);

            if (null != doc && _linkedDocumentsComObjects.ContainsKey(doc))
            {
                return(_linkedDocumentsComObjects[doc]);
            }

            // else we must create a new DocumentComObject
            var newComObject = new GraphDocumentLinkedComObject(doc, _fileComObject, this);

            _linkedDocumentsComObjects.Add(doc, newComObject);
            return(newComObject);
        }
コード例 #20
0
        private void EhCurrentProjectFileNameChanged(string fileName)
        {
            // see Brockschmidt, Inside Ole 2nd ed., page 996

            // make sure that if we have a valid file name, then the ComManager should be Active in order that this Com object is made public
            if (!string.IsNullOrEmpty(fileName) && !_comManager.IsActive)
            {
                ComDebug.ReportInfo("{0}.EhCurrentProjectFileNameChanged StartLocalServer because we have a valid file name. FileName: {1}", GetType().Name, fileName);
                _comManager.StartLocalServer();
            }

            ComDebug.ReportInfo("{0}.EhCurrentProjectFileNameChanged", GetType().Name);

            RunningObjectTableHelper.ROTUnregister(ref _fileWithWildCardItemMonikerRotCookie);
            _fileWithWildCardItemMoniker = null;
            RunningObjectTableHelper.ROTUnregister(ref _fileMonikerRotCookie);
            _fileMoniker = null;

            if (!string.IsNullOrEmpty(fileName))
            {
                Ole32Func.CreateFileMoniker(fileName, out _fileMoniker);
                if (null != _fileMoniker)
                {
                    RunningObjectTableHelper.ROTRegisterAsRunning(_fileMoniker, this, ref _fileMonikerRotCookie, typeof(IPersistFile));

                    // Notify all other item Com objects of the new _fileMoniker
                    if (null != FileMonikerChanged)
                    {
                        FileMonikerChanged(_fileMoniker);
                    }

                    // now register also a file moniker with a wild card item, that handles all items that are not open in the moment
                    Ole32Func.CreateItemMoniker("!", "\\", out var wildCardItemMoniker);
                    if (null != wildCardItemMoniker)
                    {
                        _fileMoniker.ComposeWith(wildCardItemMoniker, false, out _fileWithWildCardItemMoniker);
                        RunningObjectTableHelper.ROTRegisterAsRunning(_fileWithWildCardItemMoniker, this, ref _fileWithWildCardItemMonikerRotCookie, typeof(IOleItemContainer));
                    }
                }
            }
        }
コード例 #21
0
 public void DUnadvise(int connection)
 {
     if (null == DataAdviseHolder)
     {
         ComDebug.ReportInfo("{0}.IDataObject.DUnadvise connection={1} -> not implemented!", GetType().Name, connection);
         return;
     }
     else
     {
         ComDebug.ReportInfo("{0}.IDataObject.DUnadvise connection={1}", GetType().Name, connection);
         try
         {
             DataAdviseHolder.Unadvise(connection);
         }
         catch (Exception e)
         {
             ComDebug.ReportError("{0}.IDataObject.DUnadvise exception {1}", GetType().Name, e);
             throw;
         }
     }
 }
コード例 #22
0
        private IntPtr RenderBitmapDIB(TYMED tymed)
        {
            ComDebug.ReportInfo("GraphDocumentDataObject.RenderBitmapDIB");

            if (!(tymed == TYMED.TYMED_HGLOBAL))
            {
                throw new ArgumentException(nameof(tymed) + " is not TYMED_HGLOBAL");
            }

            if (null != _graphDocumentBitmapImage)
            {
                using (var convertedBitmap = GraphDocumentExportActions.ConvertBitmapToPixelFormat(_graphDocumentBitmapImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb, _graphExportOptions.BackgroundColorForFormatsWithoutAlphaChannel))
                {
                    return(DataObjectHelper.RenderDIBBitmapToHGLOBAL(convertedBitmap));
                }
            }
            else
            {
                throw new InvalidProgramException("Please report this exception to the author of the program and describe the steps to reproduce the exception");
            }
        }
コード例 #23
0
        public IntPtr GetObject(string pszItem, int dwSpeedNeeded, IBindCtx pbc, ref Guid riid)
        {
            // Brockschmidt, Inside Ole 2nd ed. page 1003

            pszItem = DataObjectHelper.MonikerNameStringToNormalString(pszItem);

            ComDebug.ReportInfo("{0}.GetObject {1}, Requesting Interface : {2}", GetType().Name, pszItem, riid);

            bool isRunning = _currentProject.GraphDocumentCollection.TryGetValue(pszItem, out var doc);

            if (((int)BINDSPEED.BINDSPEED_IMMEDIATE == dwSpeedNeeded || (int)BINDSPEED.BINDSPEED_MODERATE == dwSpeedNeeded) && !isRunning)
            {
                throw Marshal.GetExceptionForHR(ComReturnValue.MK_E_EXCEEDEDDEADLINE);
            }

            if (null == doc) // in this application we can do nothing but to return intptr.Zero
            {
                return(IntPtr.Zero);
            }

            if (riid == Marshal.GenerateGuidForType(typeof(System.Runtime.InteropServices.ComTypes.IDataObject)) ||
                riid == Marshal.GenerateGuidForType(typeof(IOleObject)) ||
                riid == InterfaceGuid.IID_IDispatch ||
                riid == InterfaceGuid.IID_IUnknown)
            {
                var    documentComObject = _comManager.GetDocumentsComObjectForGraphDocument(doc);
                IntPtr ppvObject         = Marshal.GetComInterfaceForObject(documentComObject, typeof(System.Runtime.InteropServices.ComTypes.IDataObject));

                var action = new Action(() => Current.IProjectService.ShowDocumentView(doc));
                Current.Dispatcher.InvokeAndForget(action);

                return(ppvObject);
            }
            else
            {
                throw new COMException("No interface", unchecked ((int)0x80004002));
            }
        }
コード例 #24
0
ファイル: ClassFactoryBase.cs プロジェクト: olesar/Altaxo
        /// <summary>
        /// Registers the class factory.
        /// </summary>
        /// <returns></returns>
        public bool RegisterClassObject()
        {
            // Register the class factory
            int i = Ole32Func.CoRegisterClassObject
                    (
                ref _classId,
                this,
                ClassContext,
                Flags,
                out _cookie
                    );

            ComDebug.ReportInfo("{0}.RegisterClassObject, i={1}, _cookie={2}", GetType().Name, i, _cookie);

            if (i == 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #25
0
ファイル: ComStreamWrapper.cs プロジェクト: olesar/Altaxo
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="T:System.IO.Stream" /> and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            ComDebug.ReportInfo("ComStreamWrapper.Dispose({0})", disposing);
            ReportDebugStream("StreamWrapper.Dispose({0})\r\n", disposing);

            base.Dispose(disposing);

            Marshal.FreeCoTaskMem(_int64Ptr);
            _int64Ptr = IntPtr.Zero;

            Marshal.FreeCoTaskMem(_int32Ptr);
            _int32Ptr = IntPtr.Zero;

            if (null != _istream)
            {
                if (_isStreamOwner)
                {
                    Marshal.ReleaseComObject(_istream);
                    ComDebug.ReportInfo("ComStreamWrapper.Dispose: istream released");
                }
                _istream = null;
            }
        }
コード例 #26
0
        private IntPtr RenderEnhancedMetaFile(TYMED tymed)
        {
            ComDebug.ReportInfo("GraphDocumentDataObject.RenderEnhancedMetafile");

            if (!(tymed == TYMED.TYMED_ENHMF))
            {
                throw new ArgumentException(nameof(tymed) + " is not TYMED_TYMED_ENHMF");
            }

            if (null != _graphDocumentMetafileImage)
            {
                var mfCloned = (System.Drawing.Imaging.Metafile)_graphDocumentMetafileImage.Clone();
                return(mfCloned.GetHenhmetafile());
            }
            else if (null != _graphDocumentBitmapImage)
            {
                var scaledDocSize = _graphDocumentSize * _graphExportOptions.OutputScalingFactor;
                return(GraphDocumentExportActions.RenderAsEnhancedMetafileBitmapFormat(_graphDocumentBitmapImage, scaledDocSize).GetHenhmetafile());
            }
            else
            {
                throw new InvalidProgramException("Please report this exception to the author of the program and describe the steps to reproduce the exception");
            }
        }
コード例 #27
0
        public int SetExtent(int dwDrawAspect, tagSIZEL pSizel)
        {
            ComDebug.ReportInfo("{0}.IOleObject.SetExtent({1}x{2}) -> not supported.", GetType().Name, pSizel.cx, pSizel.cy);

            return(ComReturnValue.E_FAIL);
        }
コード例 #28
0
        public int DoVerb(int iVerb, IntPtr lpmsg, IOleClientSite pActiveSite, int lindex, IntPtr hwndParent, COMRECT lprcPosRect)
        {
            ComDebug.ReportInfo("{0}.IOleObject.DoVerb {1}", GetType().Name, iVerb);
            try
            {
                // I saw OLEIVERB_HIDE come in as 253.  Perhaps a unsigned
                // byte conversion happening somewhere.
                if (iVerb >= 250 && iVerb <= 255)
                {
                    int new_iverb = iVerb - 256;
                    ComDebug.ReportWarning("{0}.IOleObject.DoVerb -> Fixing iVerb: {1} -> {2}", GetType().Name, iVerb, new_iverb);
                    iVerb = new_iverb;
                }

                _lastVerb = iVerb;

                switch (iVerb)
                {
                case (int)OLEIVERB.OLEIVERB_HIDE:
                    ComDebug.ReportInfo("{0}.IOleObject.DoVerb OLEIVERB_HIDE", GetType().Name);
                    _comManager.ApplicationAdapter.HideMainWindow();
                    SendAdvise_HideWindow();
                    break;

                case (int)OLEIVERB.OLEIVERB_PRIMARY:
                case (int)OLEIVERB.OLEIVERB_SHOW:
                case (int)OLEIVERB.OLEIVERB_OPEN:

                    if ((int)OLEIVERB.OLEIVERB_PRIMARY == iVerb)
                    {
                        ComDebug.ReportInfo("{0}.IOleObject.DoVerb OLEIVERB_PRIMARY", GetType().Name);
                    }
                    if ((int)OLEIVERB.OLEIVERB_SHOW == iVerb)
                    {
                        ComDebug.ReportInfo("{0}.IOleObject.DoVerb OLEIVERB_SHOW", GetType().Name);
                    }
                    if ((int)OLEIVERB.OLEIVERB_OPEN == iVerb)
                    {
                        ComDebug.ReportInfo("{0}.IOleObject.DoVerb OLEIVERB_OPEN", GetType().Name);
                    }
                    _comManager.ApplicationAdapter.ShowMainWindow();
                    if (pActiveSite != null)
                    {
                        ComDebug.ReportInfo("{0}.IOleObject.DoVerb -> calling ClientSite.ShowObject()", GetType().Name);
                        try
                        {
                            pActiveSite.ShowObject();
                        }
                        catch (Exception ex)
                        {
                            ComDebug.ReportInfo("{0}.IOleObject.DoVerb pActiveSite.ShowObject caused an exception: {1}", GetType().Name, ex);
                        }

                        SendAdvise_ShowWindow();
                    }

                    return(ComReturnValue.NOERROR);

                default:
                    ComDebug.ReportError("{0}.IOleObject.DoVerb Unexpected verb: {1}", GetType().Name, iVerb);
                    return(ComReturnValue.OLEOBJ_S_INVALIDVERB);
                }
                ComDebug.ReportInfo("{0}.IOleObject.DoVerb -> returning NOERROR", GetType().Name);
                return(ComReturnValue.NOERROR);
            }
            catch (Exception e)
            {
                ComDebug.ReportError("{0}.IOleObject.DoVerb throw an exception. Details: {1}", GetType().Name, e);
                throw;
            }
        }
コード例 #29
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;
            }
            // }
        }
コード例 #30
0
 public int HandsOffStorage()
 {
     ComDebug.ReportInfo("{0}.IPersistStorage.HandsOffStorage", GetType().Name);
     return(ComReturnValue.S_OK);
 }