示例#1
0
文件: Ribbon.cs 项目: nangs/RibbonLib
        /// <summary>
        /// Initalize ribbon framework
        /// </summary>
        /// <param name="form">Form where ribbon should reside</param>
        /// <param name="resourceName">Identifier of the ribbon resource</param>
        /// <param name="hInstance">Pointer to HINSTANCE of module where we can find ribbon resource</param>
        void InitFramework(string resourceName, IntPtr hInstance)
        {
            // create ribbon framework object
            Framework        = CreateRibbonFramework();
            _imageFromBitmap = CreateImageFromBitmapFactory();

            // create ribbon application object
            _application = new RibbonUIApplication(this, this);

            // init ribbon framework
            HRESULT hr = Framework.Initialize(this.WindowHandle, _application);

            if (NativeMethods.Failed(hr))
            {
                Marshal.ThrowExceptionForHR((int)hr);
            }

            // load ribbon ui
            hr = Framework.LoadUI(hInstance, resourceName);


            if (NativeMethods.Failed(hr))
            {
                Marshal.ThrowExceptionForHR((int)hr);
            }
        }
示例#2
0
        /// <summary>
        /// Initialize ribbon framework
        /// </summary>
        /// <param name="resourceName">Identifier of the ribbon resource</param>
        /// <param name="hInstance">Pointer to HINSTANCE of module where we can find ribbon resource</param>
        void InitFramework(string resourceName, IntPtr hInstance)
        {
            // create ribbon framework object
            Framework        = CreateRibbonFramework();
            _imageFromBitmap = CreateImageFromBitmapFactory();

            // create ribbon application object
            _application = new RibbonUIApplication(this, this);

            // init ribbon framework
            HRESULT hr = Framework.Initialize(this.WindowHandle, _application);

            if (NativeMethods.Failed(hr))
            {
                Marshal.ThrowExceptionForHR((int)hr);
            }

            // load ribbon ui
            hr = Framework.LoadUI(hInstance, resourceName);

            if (!(Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor <= 1 || Environment.OSVersion.Version.Major < 6))
            {
                IUIEventingManager eventingManager = Framework as IUIEventingManager;
                if (eventingManager != null)
                {
                    EventLogger = new EventLogger(eventingManager);
                }
            }

            if (NativeMethods.Failed(hr))
            {
                Marshal.ThrowExceptionForHR((int)hr);
            }
        }
示例#3
0
文件: Ribbon.cs 项目: nangs/RibbonLib
        /// <summary>
        /// Destroy ribbon framework
        /// </summary>
        void DestroyFramework()
        {
            if (Initalized)
            {
                // destroy ribbon framework
                Framework.Destroy();
                Marshal.ReleaseComObject(Framework);

                // remove reference to framework object
                Framework = null;
            }

            // Unregister event handlers
            RegisterForm(null);

            if (_loadedDllHandle != IntPtr.Zero)
            {
                // free dynamic library
                NativeMethods.FreeLibrary(_loadedDllHandle);
                _loadedDllHandle = IntPtr.Zero;
            }

            if (_imageFromBitmap != null)
            {
                // remove reference to imageFromBitmap object
                _imageFromBitmap = null;
            }

            if (_application != null)
            {
                // remove reference to application object
                _application = null;
            }

            // remove references to ribbon controls
            _mapRibbonControls.Clear();

            if (!string.IsNullOrEmpty(_tempDllFilename))
            {
                try
                {
                    File.Delete(_tempDllFilename);
                    _tempDllFilename = null;
                }
                catch { }
            }
        }
        private void InitializeRibbon()
        {

            IUIFramework framework = (IUIFramework)Activator.CreateInstance<Framework>();

            Trace.Assert(framework != null, "Failed to create IUIFramework.");

            ribbonControl = new RibbonControl(_htmlEditor.IHtmlEditorComponentContext, _htmlEditor);

            int initializeResult = framework.Initialize(_mainFrameWindow.Handle, this);
            Trace.Assert(initializeResult == HRESULT.S_OK, "Ribbon framework failed to initialize: " + initializeResult);

            _framework = framework;

            string nativeResourceDLL = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\OpenLiveWriter.Ribbon.dll";
            IntPtr hMod = Kernel32.LoadLibrary(nativeResourceDLL);

            using (new QuickTimer("IUIRibbonFramework::LoadUI"))
            {
                int loadResult = _framework.LoadUI(hMod, "RIBBON_RIBBON");
                Trace.Assert(loadResult == HRESULT.S_OK, "Ribbon failed to load: " + loadResult);
            }

            _framework.SetModes(mode);

            CommandManager.Invalidate(CommandId.MRUList);
            CommandManager.Invalidate(CommandId.OpenDraftSplit);
            CommandManager.Invalidate(CommandId.OpenPostSplit);

            ApplicationDiagnostics.TestModeChanged += OnTestModeChanged;
            TestMode = ApplicationDiagnostics.TestMode;
        }
示例#5
0
        public void FlushPendingInvalidations(IUIFramework framework)
        {
            Debug.Assert(!_flushing, "Flushing while already flushing!?!");
            _flushing = true;

            try
            {
                Debug.Assert(pendingInvalidations.Count < _keys.Length, "Need to increase the size of MAX_PENDING_INVALIDATIONS.");
                pendingInvalidations.Keys.CopyTo(_keys, 0);

                for (int i = 0; i < pendingInvalidations.Count; i++)
                {
                    PropertyKey key = _keys[i];
                    if (pendingInvalidations[key] == InvalidationState.Pending)
                    {
                        int result = framework.InvalidateUICommand((uint)CommandId,
                                                      PropertyKeyExtensions.GetCommandInvalidationFlags(key),
                                                      key.ToPointer());
                        pendingInvalidations[key] = result == 0 ? InvalidationState.WaitingForUpdateProperty : InvalidationState.Error;
                    }
                }
            }
            catch (Exception)
            {
                pendingInvalidations.Clear();
                throw;
            }
            finally
            {
                _flushing = false;
            }
        }