Beispiel #1
0
        // ProcessArguments() will process the command-line arguments
        // of this application.
        // If the return value is true, we carry
        // on and start this application.
        // If the return value is false, we terminate
        // this application immediately.
        public bool ProcessStartupArguments(params string[] args)
        {
            bool bRet = true;

            if (args.Length > 0)
            {
                switch (args[0].ToLower())
                {
                case "-embedding":
                    ApplicationWasStartedWithEmbeddingArg = true;
                    break;

                case "-register":
                case "/register":
                    RegisterApplicationForCom();
                    break;

                case "-unregister":
                case "/unregister":
                    UnregisterApplicationForCom();
                    break;

                default:
                    ComDebug.ReportError("Unknown argument: " + args[0] + "\nValid are : -register, -unregister and -embedding");
                    break;
                }
            }

            ComDebug.ReportInfo("{0}.ProcessArguments Embedding={1} IsRunning64bit={2}", GetType().Name, ApplicationWasStartedWithEmbeddingArg, System.Environment.Is64BitProcess);

            return(bRet);
        }
Beispiel #2
0
        /// <summary>
        /// Makes the main window of the application visible to the user.
        /// </summary>
        public void ShowMainWindow()
        {
            InvokeGuiThread(() =>
            {
                ComDebug.ReportInfo("Make main window visible");

                var mainWindow = System.Windows.Application.Current.MainWindow;

                mainWindow.Visibility    = System.Windows.Visibility.Visible;
                mainWindow.ShowInTaskbar = true;
                mainWindow.BringIntoView();

                // how to bring a window to the front ?
                // see http://stackoverflow.com/questions/257587/bring-a-window-to-the-front-in-wpf

                if (!mainWindow.IsVisible)
                {
                    mainWindow.Show();
                }

                if (mainWindow.WindowState == System.Windows.WindowState.Minimized)
                {
                    mainWindow.WindowState = System.Windows.WindowState.Normal;
                }

                mainWindow.Activate();
                mainWindow.Topmost = true;  // important
                mainWindow.Topmost = false; // important
                mainWindow.Focus();         // important

                ComDebug.ReportInfo("Make main window visible - done!");
            });
        }
Beispiel #3
0
        public void Dispose()
        {
            if (_isDocumentDirty)
            {
                ComDebug.ReportInfo("{0}.Dispose Step 0 : Document is dirty -> Advise DataChanged", GetType().Name);
                SendAdvise_DataChanged(); // update the image of the graph before we close
            }

            ComDebug.ReportInfo("{0}.Dispose Step 1 : SaveObject", GetType().Name);

            SendAdvise_SaveObject();

            ComDebug.ReportInfo("{0}.Dispose Step 2 : Calling SendAdvise.HideWindow", GetType().Name);

            SendAdvise_HideWindow();

            ComDebug.ReportInfo("{0}.Dispose Step 3 : Calling SendAdvise.Closed", GetType().Name);

            SendAdvise_Closed();

            ComDebug.ReportInfo("{0}.Dispose Step 4 : ROTUnregister(ref _documentMonikerRotCookie)", GetType().Name);

            if (0 != _documentMonikerRotCookie)
            {
                RunningObjectTableHelper.ROTUnregister(ref _documentMonikerRotCookie);
                _documentMoniker = null;
            }

            // Disconnect the container.
            ComDebug.ReportInfo("{0}.Dispose Step 5 : Disconnecting this object", GetType().Name);

            Ole32Func.CoDisconnectObject(this, 0);

            ComDebug.ReportInfo("{0}.Dispose completed.", GetType().Name);
        }
Beispiel #4
0
        private void EhCurrentProjectInstanceChanged(object sender, Altaxo.Main.ProjectEventArgs e)
        {
            if (e?.ProjectEventKind == Main.ProjectEventKind.ProjectRenamed)
            {
                EhCurrentProjectFileNameChanged(e.NewName);
            }

            if (object.ReferenceEquals(Current.Project, _currentProject))
            {
                return;
            }

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

            if (null != _currentProject && null != _currentProject.GraphDocumentCollection)
            {
                _currentProject.GraphDocumentCollection.CollectionChanged -= EhGraphDocumentRenamed;
            }

            _currentProject = Current.Project;

            if (null != _currentProject)
            {
                _currentProject.GraphDocumentCollection.CollectionChanged += EhGraphDocumentRenamed;
                EhCurrentProjectFileNameChanged(Current.IProjectService.CurrentProjectFileName);
            }
        }
        public ReferenceCountedObjectBase(ComManager comManager)
        {
            _comManager = comManager;
            _comManager.InterlockedIncrementObjectsCount();

            ComDebug.ReportInfo("{0}.Constructor, NumberOfObjectsInUse={1}", GetType().Name, _comManager.ObjectsCount);
        }
Beispiel #6
0
        public void Dispose()
        {
            if (_isDocumentDirty)
            {
                ComDebug.ReportInfo("{0}.Dispose Step 0 : Document is dirty -> Advise DataChanged", GetType().Name);
                SendAdvise_DataChanged(); // update the image of the graph before we close
            }

            ComDebug.ReportInfo("{0}.Dispose Step 1 : SaveObject", GetType().Name);

            SendAdvise_SaveObject(); // make an advise to save the mini-project into the container application

            ComDebug.ReportInfo("{0}.Dispose Step 2 : Calling SendAdvise.HideWindow", GetType().Name);

            SendAdvise_HideWindow();

            ComDebug.ReportInfo("{0}.Dispose Step 3 : Calling SendAdvise.Closed", GetType().Name);

            SendAdvise_Closed();

            // if we had a document moniker, we should unregister it here
            // but since this is an embedded object,we have no document moniker

            // Disconnect the container.
            ComDebug.ReportInfo("{0}.Dispose Step 4 : Disconnecting this object", GetType().Name);

            Ole32Func.CoDisconnectObject(this, 0);

            ComDebug.ReportInfo("{0}.Dispose completed.", GetType().Name);
        }
Beispiel #7
0
        public int EnumAdvise(out System.Runtime.InteropServices.ComTypes.IEnumSTATDATA e)
        {
            ComDebug.ReportInfo("{0}.IOleObject.EnumAdvise", GetType().Name);

            e = _oleAdviseHolder.EnumAdvise();
            return(ComReturnValue.NOERROR);
        }
Beispiel #8
0
        public int DAdvise(ref FORMATETC pFormatetc, ADVF advf, IAdviseSink adviseSink, out int connection)
        {
            if (null == DataAdviseHolder)
            {
                ComDebug.ReportInfo("{0}.IDataObject.DAdvise -> not implemented!", GetType().Name);
                connection = 0;
                return(ComReturnValue.E_NOTIMPL);
            }
            else
            {
                ComDebug.ReportInfo("{0}.IDataObject.DAdvise {1}, {2}", GetType().Name, DataObjectHelper.FormatEtcToString(pFormatetc), advf);

                try
                {
                    if (pFormatetc.cfFormat != 0)               // if a special format is required
                    {
                        int res = QueryGetData(ref pFormatetc); // ask the render helper for availability of that format
                        if (res != ComReturnValue.S_OK)         // if the required format is not available
                        {
                            connection = 0;                     //  return an invalid connection cookie
                            return(res);                        // and the error
                        }
                    }
                    FORMATETC etc = pFormatetc;
                    DataAdviseHolder.Advise((IDataObject)this, ref etc, advf, adviseSink, out var conn);
                    connection = conn;
                    return(ComReturnValue.NOERROR);
                }
                catch (Exception e)
                {
                    ComDebug.ReportError("{0}.IDataObject.DAdvise exception: {1}", GetType().Name, e);
                    throw;
                }
            }
        }
Beispiel #9
0
        private IntPtr RenderWindowsMetafilePict(TYMED tymed)
        {
            ComDebug.ReportInfo("GraphDocumentDataObject.RenderWindowsMetafilePict");

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

            if (null != _graphDocumentBitmapImage)
            {
                using (var rgbBitmap = GraphDocumentExportActions.ConvertBitmapToPixelFormat(_graphDocumentBitmapImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb, _graphExportOptions.BackgroundColorForFormatsWithoutAlphaChannel))
                {
                    var scaledDocSize = _graphDocumentSize * _graphExportOptions.OutputScalingFactor;

                    using (var enhancedMetafile = GraphDocumentExportActions.RenderAsEnhancedMetafileBitmapFormat(rgbBitmap, scaledDocSize))
                    {
                        var hEmf = enhancedMetafile.GetHenhmetafile();
                        return(DataObjectHelper.ConvertEnhancedMetafileToWindowsMetafilePict(hEmf, scaledDocSize.X, scaledDocSize.Y));
                    }
                }
            }
            else
            {
                throw new InvalidProgramException("Please report this exception to the author of the program and describe the steps to reproduce the exception");
            }
        }
Beispiel #10
0
        // AttemptToTerminateServer() will check to see if
        // the objects count and the server lock count has
        // both dropped to zero.
        // If so, we post a WM_QUIT message to the main thread's
        // message loop. This will cause the message loop to
        // exit and hence the termination of this application.
        public void AttemptToTerminateServer()
        {
            lock (this)
            {
                // Get the most up-to-date values of these critical data.
                int iObjsInUse   = ObjectsCount;
                int iServerLocks = ServerLockCount;

                {
                    // Print out these info for debug purposes.
                    var sb = new StringBuilder("");
                    sb.AppendFormat("NumberOfObjectsInUse : {0}. NumberOfServerLocks : {1}", iObjsInUse, iServerLocks);
                    ComDebug.ReportInfo(sb.ToString());
                }

                if ((iObjsInUse > 0) || (iServerLocks > 0))
                {
                    ComDebug.ReportInfo("There are still referenced objects or the server lock count is non-zero.");
                }
                else
                {
                    var wParam = new UIntPtr(0);
                    var lParam = new IntPtr(0);

                    // Stop the program now

                    ApplicationAdapter.BeginClosingApplication();
                }
            }
        }
Beispiel #11
0
 /// <summary>
 /// Asks a container to display its object to the user. This method ensures that the container itself is visible and not minimized.
 /// </summary>
 /// <remarks>
 /// <para>After a link client binds to a link source, it commonly calls IOleObject::DoVerb on the link source, usually
 /// requesting the source to perform some action requiring that it display itself to the user. As part of its implementation
 /// of IOleObject::DoVerb, the link source can call ShowObject, which forces the client to show the link source as best it can.
 /// If the link source's container is itself an embedded object, it will recursively invoke ShowObject on its own container.</para>
 /// <para>Having called the ShowObject method, a link source has no guarantee of being appropriately displayed because its container
 /// may not be able to do so at the time of the call. The ShowObject method does not guarantee visibility, only that the container will do the best it can.</para>
 /// </remarks>
 public virtual void SendAdvise_ShowObject()
 {
     ComDebug.ReportInfo("{0}.SendAdvise.ShowObject -> Calling IOleClientSite.ShowObject()", GetType().Name);
     if (null != _clientSite)
     {
         _clientSite.ShowObject();
     }
 }
Beispiel #12
0
 /// <summary>
 /// Notifies a container when an embedded object's window is about to become visible.
 /// The container uses this information to shade the object's client site when the object is displayed in a window.
 /// A shaded object, having received this notification, knows that it already has an open window and therefore can respond to being double-clicked by bringing this window quickly to the top, instead of launching its application in order to obtain a new one.
 /// </summary>
 public virtual void SendAdvise_ShowWindow()
 {
     ComDebug.ReportInfo("{0}.SendAdvise.ShowWindow -> Calling IOleClientSite.OnShowWindow(true)", GetType().Name);
     if (null != _clientSite)
     {
         _clientSite.OnShowWindow(true);
     }
 }
Beispiel #13
0
        public int GetCanonicalFormatEtc(ref FORMATETC formatIn, out FORMATETC formatOut)
        {
            ComDebug.ReportInfo("{0}.IDataObject.GetCanonicalFormatEtc {1}", GetType().Name, DataObjectHelper.FormatEtcToString(formatIn));

            formatOut = default(FORMATETC);

            return(ComReturnValue.DATA_S_SAMEFORMATETC);
        }
Beispiel #14
0
        public int GetMiscStatus(int dwAspect, out int misc)
        {
            misc = GraphDocumentDataObject.MiscStatus(dwAspect);

            ComDebug.ReportInfo("{0}.IOleObject.GetMiscStatus -> returning 0x{1:X}", GetType().Name, misc);

            return(ComReturnValue.S_OK);
        }
Beispiel #15
0
 public virtual void SendAdvise_DataChanged()
 {
     if (null != DataAdviseHolder)
     {
         ComDebug.ReportInfo("{0}.SendAdvise.DataChanged -> Calling _dataAdviseHolder.SendOnDataChange()", GetType().Name);
         DataAdviseHolder.SendOnDataChange((IDataObject)this, 0, 0);
     }
 }
Beispiel #16
0
        public GraphDocumentEmbeddedComObject(ComManager comManager)
            : base(comManager)
        {
            ComDebug.ReportInfo("{0} constructor.", GetType().Name);

            _dataAdviseHolder = new ManagedDataAdviseHolder();
            _oleAdviseHolder  = new ManagedOleAdviseHolderFM();
        }
Beispiel #17
0
        public void WaitForThreadToStop()
        {
            ComDebug.ReportInfo("WaitForThreadToStop().");
            _eventThreadEnded.WaitOne();
            _eventThreadEnded.Reset();

            ComDebug.ReportInfo("WaitForThreadToStop() exiting.");
        }
Beispiel #18
0
        public int IsRunning(string pszItem)
        {
            bool isRunning = _currentProject.GraphDocumentCollection.TryGetValue(pszItem, out var doc);

            ComDebug.ReportInfo("{0}.IsRunning item={1}, result={2}", GetType().Name, pszItem, isRunning);

            return(isRunning ? ComReturnValue.NOERROR : ComReturnValue.S_FALSE);
        }
 public void SendOnClose()
 {
     ComDebug.ReportInfo("{0}.SendOnClose calling (for all sinks) IAdviseSink.OnClose()", GetType().Name);
     foreach (var sink in new List <IAdviseSink>(_advises.Where(x => null != x))) // new List is neccessary because the original list might be modified during the operation
     {
         sink.OnClose();
     }
 }
Beispiel #20
0
        public static IntPtr RenderLinkedObjectDescriptor(TYMED tymed)
        {
            ComDebug.ReportInfo("GraphDocumentDataObject.RenderLinkedObjectDescriptor");

            // Brockschmidt, Inside Ole 2nd ed. page 991
            if (!(tymed == TYMED.TYMED_HGLOBAL))
            {
                throw new ArgumentException(nameof(tymed) + " is not TYMED_HGLOBAL");
            }
            // Fill in the basic information.
            var od = new OBJECTDESCRIPTOR
            {
                // According to the documentation this is used just to find an icon.
                clsid        = typeof(GraphDocumentLinkedComObject).GUID,
                dwDrawAspect = DVASPECT.DVASPECT_CONTENT,
                sizelcx      = 0, // zero in imitation of Word/Excel, but could be box.Extent.cx;
                sizelcy      = 0, // zero in imitation of Word/Excel, but could be box.Extent.cy;
                pointlx      = 0,
                pointly      = 0
            };

            od.dwStatus = MiscStatus((int)od.dwDrawAspect);

            // Descriptive strings to tack on after the struct.
            string name        = GraphDocumentLinkedComObject.USER_TYPE;
            int    name_size   = (name.Length + 1) * sizeof(char);
            string source      = "Altaxo";
            int    source_size = (source.Length + 1) * sizeof(char);
            int    od_size     = Marshal.SizeOf(typeof(OBJECTDESCRIPTOR));

            od.dwFullUserTypeName = od_size;
            od.dwSrcOfCopy        = od_size + name_size;
            int full_size = od_size + name_size + source_size;

            od.cbSize = full_size;

            // To avoid 'unsafe', we will arrange the strings in a byte array.
            byte[]   strings = new byte[full_size];
            Encoding unicode = Encoding.Unicode;

            Array.Copy(unicode.GetBytes(name), 0, strings, od.dwFullUserTypeName, name.Length * sizeof(char));
            Array.Copy(unicode.GetBytes(source), 0, strings, od.dwSrcOfCopy, source.Length * sizeof(char));

            // Combine the strings and the struct into a single block of mem.
            IntPtr hod = Kernel32Func.GlobalAlloc(GlobalAllocFlags.GHND, full_size);

            if (!(hod != IntPtr.Zero))
            {
                throw new InvalidOperationException("GlobalAlloc operation was not successful");
            }
            IntPtr buf = Kernel32Func.GlobalLock(hod);

            Marshal.Copy(strings, 0, buf, full_size);
            Marshal.StructureToPtr(od, buf, false);

            Kernel32Func.GlobalUnlock(hod);
            return(hod);
        }
 public void SendOnClose()
 {
     Invoke("SendOnClose", () =>
     {
         ComDebug.ReportInfo("ManagedOleAdviseHolder.SendOnClose");
         _oleAdviseHolder.SendOnClose();
     }
            );
 }
Beispiel #22
0
        private void EhDocumentChanged(object sender, EventArgs e)
        {
            ComDebug.ReportInfo("{0}.EhDocumentChanged", GetType().Name);
            _isDocumentDirty = true;

            // see Brockschmidt Inside Ole 2nd edition, page 909
            // we must send IDataAdviseHolder:SendOnDataChange
            SendAdvise_DataChanged();
        }
Beispiel #23
0
        public void InitNew(IStorage pstg)
        {
            ComDebug.ReportInfo("{0}.IPersistStorage.InitNew", GetType().Name);

            Document = Current.ProjectService.CreateNewGraph().Doc;

            // We don't need an IStorage except at Load/Save.
            _isDocumentDirty = true; // but we set the document dirty flag thus it is saved
        }
 public void Unadvise(int dwConnection)
 {
     Invoke("Unadvise", () =>
     {
         ComDebug.ReportInfo("ManagedOleAdviseHolder.Unadvise, cookie={0}", dwConnection);
         _oleAdviseHolder.Unadvise(dwConnection);
     }
            );
 }
 public void SendOnRename(IMoniker pmk)
 {
     Invoke("SendOnRename()", () =>
     {
         ComDebug.ReportInfo("ManagedOleAdviseHolder.SendOnRename");
         _oleAdviseHolder.SendOnRename(pmk);
     }
            );
 }
Beispiel #26
0
 public void EnterEmbeddedObjectMode()
 {
     if (null != _classFactoryOfFileComObject)
     {
         _classFactoryOfFileComObject.RevokeClassObject();
         ComDebug.ReportInfo("{0}.EnterEmbeddedObjectMode Revoked: {1}", GetType().Name, _classFactoryOfFileComObject.GetType().Name);
         _classFactoryOfFileComObject = null;
     }
 }
 public void SendOnSave()
 {
     ComDebug.ReportInfo("{0}.SendOnSave calling (for all sinks) IAdviseSink.OnSave()", GetType().Name);
     // note we don't have an IOleAdviseHolder for this, we use a list of sinks
     foreach (var sink in _advises.Where(x => null != x))
     {
         sink.OnSave();
     }
 }
Beispiel #28
0
        public GraphDocumentDataObject(GraphDocumentBase graphDocument, ProjectFileComObject fileComObject, ComManager comManager)
            : base(comManager)
        {
            ComDebug.ReportInfo("{0} constructor.", GetType().Name);
            _dataAdviseHolder = new ManagedDataAdviseHolder();

            _graphDocumentName = graphDocument.Name;
            _graphDocumentSize = graphDocument.Size;

            _graphExportOptions = graphDocument.GetPropertyValue(ClipboardRenderingOptions.PropertyKeyClipboardRenderingOptions, () => new ClipboardRenderingOptions()).Clone();
            var embeddedRenderingOptions = graphDocument.GetPropertyValue(EmbeddedObjectRenderingOptions.PropertyKeyEmbeddedObjectRenderingOptions, () => null);

            if (null != embeddedRenderingOptions)
            {
                _graphExportOptions.CopyFrom(embeddedRenderingOptions); // merge embedded rendering options
            }
            if ((_graphExportOptions.RenderEnhancedMetafile && _graphExportOptions.RenderEnhancedMetafileAsVectorFormat) ||
                (_graphExportOptions.RenderDropFile && _graphExportOptions.DropFileImageFormat == System.Drawing.Imaging.ImageFormat.Emf)
                )
            {
                if (graphDocument is Altaxo.Graph.Gdi.GraphDocument)
                {
                    _graphDocumentMetafileImage = GraphDocumentExportActions.RenderAsEnhancedMetafileVectorFormat((Altaxo.Graph.Gdi.GraphDocument)graphDocument, _graphExportOptions);
                }
            }

            if (null == _graphDocumentMetafileImage ||
                _graphExportOptions.RenderBitmap ||
                _graphExportOptions.RenderWindowsMetafile ||
                (_graphExportOptions.RenderEnhancedMetafile && !_graphExportOptions.RenderEnhancedMetafileAsVectorFormat) ||
                _graphExportOptions.RenderDropFile)
            {
                if (graphDocument is Altaxo.Graph.Gdi.GraphDocument)
                {
                    _graphDocumentBitmapImage = GraphDocumentExportActions.RenderAsBitmap((Altaxo.Graph.Gdi.GraphDocument)graphDocument, _graphExportOptions.BackgroundBrush, System.Drawing.Imaging.PixelFormat.Format32bppArgb, _graphExportOptions.SourceDpiResolution, _graphExportOptions.SourceDpiResolution / _graphExportOptions.OutputScalingFactor);
                }
                else if (graphDocument is Altaxo.Graph.Graph3D.GraphDocument)
                {
                    _graphDocumentBitmapImage = Altaxo.Graph.Graph3D.GraphDocumentExportActions.RenderAsBitmap((Altaxo.Graph.Graph3D.GraphDocument)graphDocument, _graphExportOptions.BackgroundBrush, System.Drawing.Imaging.PixelFormat.Format32bppArgb, _graphExportOptions.SourceDpiResolution, _graphExportOptions.SourceDpiResolution / _graphExportOptions.OutputScalingFactor);
                }
                else
                {
                    throw new NotImplementedException();
                }
            }

            if (_graphExportOptions.RenderEmbeddedObject)
            {
                var miniProjectBuilder = new Altaxo.Graph.Procedures.MiniProjectBuilder();
                _altaxoMiniProject = miniProjectBuilder.GetMiniProject(graphDocument, true);
            }
            else
            {
                _altaxoMiniProject = null;
            }
        }
Beispiel #29
0
        public static void SaveMonikerToStream(IMoniker moniker, IStream strm)
        {
            ComDebug.ReportInfo("SaveMonikerToStream:{0}", GetDisplayName(moniker));
            int hr = Ole32Func.OleSaveToStream((IPersistStream)moniker, strm);

            if (!(hr == ComReturnValue.S_OK))
            {
                throw new InvalidOperationException("The COM operation was not successful");
            }
        }
Beispiel #30
0
        private IntPtr RenderAsDIBBitmap(TYMED tymed)
        {
            ComDebug.ReportInfo("{0}.RenderAsDIBBitmap", GetType().Name);
            if (!(tymed == TYMED.TYMED_HGLOBAL))
            {
                throw new ArgumentException(nameof(tymed) + " is not TYMED_HGLOBAL");
            }

            return(EmbeddedGraphDocumentRenderingHelper.RenderAsDIBBitmap_TYMED_HGLOBAL(tymed, _document));
        }