Example #1
0
        /// <summary>
        /// Called when the state of a View changes
        /// </summary>
        /// <param name="viewId">The ID for the View. Only a value of 0 is valid.</param>
        /// <param name="typeID">The UI_VIEWTYPE hosted by the application.</param>
        /// <param name="view">A pointer to the View interface.</param>
        /// <param name="verb">The UI_VIEWVERB (or action) performed by the View.</param>
        /// <param name="uReasonCode">Not defined.</param>
        /// <returns>Returns S_OK if successful, or an error value otherwise.</returns>
        public HRESULT OnViewChanged(uint viewId, ViewType typeID, object view, ViewVerb verb, int uReasonCode)
        {
            HRESULT hr = HRESULT.E_FAIL;

            // Checks to see if the view that was changed was a Ribbon view.
            if (typeID == ViewType.Ribbon)
            {
                switch (verb)
                {
                // The view was newly created
                case ViewVerb.Create:
                    if (UIRibbon == null)
                    {
                        UIRibbon = view as IUIRibbon;
                    }
                    _ribbonControl.BeginInvoke(new MethodInvoker(_ribbonControl.OnViewCreated));
                    hr = HRESULT.S_OK;
                    break;

                // The view has been resized.  For the Ribbon view, the application should
                // call GetHeight to determine the height of the ribbon.
                case ViewVerb.Size:
                    uint uRibbonHeight;
                    // Call to the framework to determine the desired height of the Ribbon.
                    hr = UIRibbon.GetHeight(out uRibbonHeight);

                    if (NativeMethods.Failed(hr))
                    {
                        // error
                    }
                    else
                    {
                        _ribbonControl.Height = (int)uRibbonHeight;
                        _ribbonControl.BeginInvoke(new MethodInvoker(_ribbonControl.OnRibbonHeightChanged));
                    }
                    break;

                // The view was destroyed.
                case ViewVerb.Destroy:

                    _ribbonControl.Invoke(new MethodInvoker(_ribbonControl.OnViewDestroy));
                    UIRibbon = null;
                    hr       = HRESULT.S_OK;
                    break;

                default:
                    break;
                }
            }

            return(hr);
        }
        /// <summary>
        /// Called when the state of a View changes
        /// </summary>
        /// <param name="viewId">The ID for the View. Only a value of 0 is valid.</param>
        /// <param name="typeID">The UI_VIEWTYPE hosted by the application.</param>
        /// <param name="view">A pointer to the View interface.</param>
        /// <param name="verb">The UI_VIEWVERB (or action) performed by the View.</param>
        /// <param name="uReasonCode">Not defined.</param>
        /// <returns>Returns S_OK if successful, or an error value otherwise.</returns>
        public HRESULT OnViewChanged(uint viewId, ViewType typeID, object view, ViewVerb verb, int uReasonCode)
        {
            HRESULT hr = HRESULT.E_FAIL;

            // Checks to see if the view that was changed was a Ribbon view.
            if (typeID == ViewType.Ribbon)
            {
                switch (verb)
                {
                    // The view was newly created
                    case ViewVerb.Create:
                        if (UIRibbon == null)
                        {
                            UIRibbon = view as IUIRibbon;
                        }
                        _ribbonControl.BeginInvoke(new MethodInvoker(_ribbonControl.RaiseViewCreated));
                        hr = HRESULT.S_OK;
                        break;

                    // The view has been resized.  For the Ribbon view, the application should
                    // call GetHeight to determine the height of the ribbon.
                    case ViewVerb.Size:
                        uint uRibbonHeight;
                        // Call to the framework to determine the desired height of the Ribbon.
                        hr = UIRibbon.GetHeight(out uRibbonHeight);

                        if (NativeMethods.Failed(hr))
                        {
                            // error
                        }
                        else
                        {
                            _ribbonControl.Height = (int)uRibbonHeight;
                        }
                        break;

                    // The view was destroyed.
                    case ViewVerb.Destroy:

                        UIRibbon = null;
                        hr = HRESULT.S_OK;
                        break;

                    default:
                        break;
                }
            }

            return hr;
        }
        public int OnViewChanged(uint viewId, CommandTypeID typeID, object view, ViewVerb verb, int uReasonCode)
        {
            if (ribbon == null)
            {
                ribbon = view as IUIRibbon;
            }

            if (ribbon != null)
            {
                switch (verb)
                {
                    case ViewVerb.Create:
                        LoadRibbonSettings();
                        break;
                    case ViewVerb.Destroy:
                        break;
                    case ViewVerb.Error:
                        Trace.Fail("Ribbon error: " + uReasonCode);
                        break;
                    case ViewVerb.Size:
                        uint ribbonHeight;
                        if (ComHelper.SUCCEEDED(ribbon.GetHeight(out ribbonHeight)))
                        {
                            Debug.Assert(ribbonHeight >= 0);
                            OnSizeChanged(EventArgs.Empty);
                        }
                        break;
                    default:
                        Debug.Assert(false, "Unexpected ViewVerb!");
                        break;
                }
            }
            return HRESULT.S_OK;
        }