Example #1
0
        public HRESULT GetValue(ref PropertyKey key, out PropVariant value)
        {
            if (key == RibbonProperties.Label)
            {
                if ((style.Title == null) || (style.Title.Trim() == string.Empty))
                {
                    value = PropVariant.Empty;
                }
                else
                {
                    value = PropVariant.FromObject(style.Title);
                }
                return HRESULT.S_OK;
            }

            if (key == RibbonProperties.CategoryID)
            {
                if (categoryId.HasValue)
                {
                    value = PropVariant.FromObject(categoryId.Value);
                }
                else
                {
                    value = PropVariant.Empty;
                }
                return HRESULT.S_OK;
            }

            if (key == RibbonProperties.ItemImage)
            {
                if (itemImage != null)
                {
                    value = new PropVariant();
                    value.SetIUnknown(itemImage);
                }
                else
                {
                    value = PropVariant.Empty;
                }
                return HRESULT.S_OK;
            }

            Debug.WriteLine("Class {0} does not support property: {1}.", GetType().ToString(), RibbonProperties.GetPropertyKeyName(ref key));

            value = PropVariant.Empty;
            return HRESULT.E_NOTIMPL;
        }
        public HRESULT GetValue(ref PropertyKey key, out PropVariant value)
        {
            if (key == RibbonProperties.CommandID)
            {
                if (_commandID.HasValue)
                {
                    value = PropVariant.FromObject(_commandID.Value);
                }
                else
                {
                    value = PropVariant.Empty;
                }
                return HRESULT.S_OK;
            }

            if (key == RibbonProperties.CommandType)
            {
                if (_commandType.HasValue)
                {
                    value = PropVariant.FromObject((uint)_commandType.Value);
                }
                else
                {
                    value = PropVariant.Empty;
                }
                return HRESULT.S_OK;
            }

            if (key == RibbonProperties.CategoryID)
            {
                if (_categoryID.HasValue)
                {
                    value = PropVariant.FromObject(_categoryID.Value);
                }
                else
                {
                    value = PropVariant.Empty;
                }
                return HRESULT.S_OK;
            }

            Debug.WriteLine(string.Format("Class {0} does not support property: {1}.", GetType(), RibbonProperties.GetPropertyKeyName(ref key)));

            value = PropVariant.Empty;
            return HRESULT.E_NOTIMPL;
        }
        public HRESULT GetValue(ref PropertyKey key, out PropVariant value)
        {
            if (key == RibbonProperties.Label)
            {
                if ((_label == null) || (_label.Trim() == string.Empty))
                {
                    value = PropVariant.Empty;
                }
                else
                {
                    value = PropVariant.FromObject(_label);
                }
                return HRESULT.S_OK;
            }

            if (key == RibbonProperties.LabelDescription)
            {
                if ((_labelDescription == null) || (_labelDescription.Trim() == string.Empty))
                {
                    value = PropVariant.Empty;
                }
                else
                {
                    value = PropVariant.FromObject(_labelDescription);
                }
                return HRESULT.S_OK;
            }

            if (key == RibbonProperties.Pinned)
            {
                if (_pinned.HasValue)
                {
                    value = PropVariant.FromObject(_pinned.Value);
                }
                else
                {
                    value = PropVariant.Empty;
                }
                return HRESULT.S_OK;
            }

            Debug.WriteLine(string.Format("Class {0} does not support property: {1}.", GetType().ToString(), RibbonProperties.GetPropertyKeyName(ref key)));

            value = PropVariant.Empty;
            return HRESULT.E_NOTIMPL;
        }
        /// <summary>
        /// Handles IUICommandHandler.UpdateProperty function for the supported properties
        /// </summary>
        /// <param name="key">The Property Key to update</param>
        /// <param name="currentValue">A pointer to the current value for key. This parameter can be NULL</param>
        /// <param name="newValue">When this method returns, contains a pointer to the new value for key</param>
        /// <returns>Returns S_OK if successful, or an error value otherwise</returns>
        public override HRESULT UpdateProperty(ref PropertyKey key, PropVariantRef currentValue, ref PropVariant newValue)
        {
            if (key == RibbonProperties.ContextAvailable)
            {
                if (_contextAvailable.HasValue)
                {
                    newValue.SetUInt((uint)_contextAvailable.Value);
                }
            }

            return HRESULT.S_OK;
        }
        /// <summary>
        /// Handles IUICommandHandler.UpdateProperty function for the supported properties
        /// </summary>
        /// <param name="key">The Property Key to update</param>
        /// <param name="currentValue">A pointer to the current value for key. This parameter can be NULL</param>
        /// <param name="newValue">When this method returns, contains a pointer to the new value for key</param>
        /// <returns>Returns S_OK if successful, or an error value otherwise</returns>
        public override HRESULT UpdateProperty(ref PropertyKey key, PropVariantRef currentValue, ref PropVariant newValue)
        {
            if (key == RibbonProperties.StringValue)
            {
                if (_stringValue != null)
                {
                    newValue.SetString(_stringValue);
                }
            }

            return HRESULT.S_OK;
        }
Example #6
0
        /// <summary>
        /// Get the name of a given PropertyKey
        /// </summary>
        /// <param name="propertyKey">PropertyKey</param>
        /// <returns>Name of the PropertyKey</returns>
        /// <remarks>This function is used for debugging.</remarks>
        public static string GetPropertyKeyName(ref PropertyKey propertyKey)
        {
            FieldInfo[] fields = typeof(RibbonProperties).GetFields();

            foreach (FieldInfo field in fields)
            {
                if (field.FieldType == typeof(PropertyKey))
                {
                    PropertyKey currentPropertyKey = (PropertyKey)field.GetValue(null);
                    if (currentPropertyKey.FormatId == propertyKey.FormatId)
                    {
                        return field.Name;
                    }
                }
            }

            return string.Empty;
        }
Example #7
0
 public static PropertyKeyRef From(PropertyKey value)
 {
     PropertyKeyRef obj = new PropertyKeyRef();
     obj.PropertyKey = value;
     return obj;
 }
        /// <summary>
        /// Handles IUICommandHandler.UpdateProperty function for the supported properties
        /// </summary>
        /// <param name="key">The Property Key to update</param>
        /// <param name="currentValue">A pointer to the current value for key. This parameter can be NULL</param>
        /// <param name="newValue">When this method returns, contains a pointer to the new value for key</param>
        /// <returns>Returns S_OK if successful, or an error value otherwise</returns>
        public override HRESULT UpdateProperty(ref PropertyKey key, PropVariantRef currentValue, ref PropVariant newValue)
        {
            if (key == RibbonProperties.AutomaticColorLabel)
            {
                if (_automaticColorLabel != null)
                {
                    newValue.SetString(_automaticColorLabel);
                }
            }
            else if (key == RibbonProperties.Color)
            {
                if (_color.HasValue)
                {
                    newValue.SetUInt((uint)ColorTranslator.ToWin32(_color.Value));
                }
            }
            else if (key == RibbonProperties.ColorType)
            {
                if (_colorType.HasValue)
                {
                    newValue.SetUInt((uint)_colorType.Value);
                }
            }
            else if (key == RibbonProperties.MoreColorsLabel)
            {
                if (_moreColorsLabel != null)
                {
                    newValue.SetString(_moreColorsLabel);
                }
            }
            else if (key == RibbonProperties.NoColorLabel)
            {
                if (_noColorLabel != null)
                {
                    newValue.SetString(_noColorLabel);
                }
            }
            else if (key == RibbonProperties.RecentColorsCategoryLabel)
            {
                if (_recentColorsCategoryLabel != null)
                {
                    newValue.SetString(_recentColorsCategoryLabel);
                }
            }
            else if (key == RibbonProperties.StandardColors)
            {
                if (_standardColors != null)
                {
                    int[] intStandardColors = Array.ConvertAll<Color, int>(_standardColors, new Converter<Color, int>(ColorTranslator.ToWin32));
                    uint[] uintStandardColors = Array.ConvertAll<int, uint>(intStandardColors, new Converter<int, uint>(Convert.ToUInt32));
                    newValue.SetUIntVector(uintStandardColors);
                }
            }
            else if (key == RibbonProperties.StandardColorsCategoryLabel)
            {
                if (_standardColorsCategoryLabel != null)
                {
                    newValue.SetString(_standardColorsCategoryLabel);
                }
            }
            else if (key == RibbonProperties.StandardColorsTooltips)
            {
                if (_standardColorsTooltips != null)
                {
                    newValue.SetStringVector(_standardColorsTooltips);
                }
            }
            else if (key == RibbonProperties.ThemeColors)
            {
                if (_themeColors != null)
                {
                    int[] intThemeColors = Array.ConvertAll<Color, int>(_themeColors, new Converter<Color, int>(ColorTranslator.ToWin32));
                    uint[] uintThemeColors = Array.ConvertAll<int, uint>(intThemeColors, new Converter<int, uint>(Convert.ToUInt32));
                    newValue.SetUIntVector(uintThemeColors);
                }
            }
            else if (key == RibbonProperties.ThemeColorsCategoryLabel)
            {
                if (_themeColorsCategoryLabel != null)
                {
                    newValue.SetString(_themeColorsCategoryLabel);
                }
            }
            else if (key == RibbonProperties.ThemeColorsTooltips)
            {
                if (_themeColorsTooltips != null)
                {
                    newValue.SetStringVector(_themeColorsTooltips);
                }
            }

            return HRESULT.S_OK;
        }
        /// <summary>
        /// Handles IUICommandHandler.UpdateProperty function for the supported properties
        /// </summary>
        /// <param name="key">The Property Key to update</param>
        /// <param name="currentValue">A pointer to the current value for key. This parameter can be NULL</param>
        /// <param name="newValue">When this method returns, contains a pointer to the new value for key</param>
        /// <returns>Returns S_OK if successful, or an error value otherwise</returns>
        public override HRESULT UpdateProperty(ref PropertyKey key, PropVariantRef currentValue, ref PropVariant newValue)
        {
            if (key == RibbonProperties.RecentItems)
            {
                if (_recentItems != null)
                {
                    newValue.SetSafeArray(_recentItems.ToArray());
                }
            }

            return HRESULT.S_OK;
        }
Example #10
0
        /// <summary>
        /// Handles IUICommandHandler.UpdateProperty function for this ribbon control
        /// </summary>
        /// <param name="key">The Property Key to update</param>
        /// <param name="currentValue">A pointer to the current value for key. This parameter can be NULL</param>
        /// <param name="newValue">When this method returns, contains a pointer to the new value for key</param>
        /// <returns>Returns S_OK if successful, or an error value otherwise</returns>
        public virtual HRESULT UpdateProperty(ref PropertyKey key, PropVariantRef currentValue, ref PropVariant newValue)
        {
            // check if property is registered with this ribbon control
            if (_mapProperties.ContainsKey(key))
            {
                // find property provider
                IPropertiesProvider propertiesProvider = _mapProperties[key];

                // delegates execution to property provider
                return propertiesProvider.UpdateProperty(ref key, currentValue, ref newValue);
            }

            Debug.WriteLine(string.Format("Class {0} does not support property: {1}.", GetType(), RibbonProperties.GetPropertyKeyName(ref key)));
            return HRESULT.S_OK;
        }
        /// <summary>
        /// Handles IUICommandHandler.UpdateProperty function for the supported properties
        /// </summary>
        /// <param name="key">The Property Key to update</param>
        /// <param name="currentValue">A pointer to the current value for key. This parameter can be NULL</param>
        /// <param name="newValue">When this method returns, contains a pointer to the new value for key</param>
        /// <returns>Returns S_OK if successful, or an error value otherwise</returns>
        public override HRESULT UpdateProperty(ref PropertyKey key, PropVariantRef currentValue, ref PropVariant newValue)
        {
            if (key == RibbonProperties.FontProperties)
            {
                if (currentValue != null)
                {
                    // get current font properties
                    IPropertyStore fontProperties = (IPropertyStore)currentValue.PropVariant.Value;

                    // set family
                    if ( (_family == null) || (_family.Trim() == string.Empty) )
                    {
                        PropVariant propFamily = PropVariant.Empty;
                        fontProperties.SetValue(ref RibbonProperties.FontProperties_Family, ref propFamily);
                    }
                    else
                    {
                        PropVariant propFamily = PropVariant.FromObject(_family);
                        fontProperties.SetValue(ref RibbonProperties.FontProperties_Family, ref propFamily);
                    }

                    // set size
                    if (_size.HasValue)
                    {
                        PropVariant propSize = PropVariant.FromObject(_size.Value);
                        fontProperties.SetValue(ref RibbonProperties.FontProperties_Size, ref propSize);
                    }

                    // set bold
                    if (_bold.HasValue)
                    {
                        PropVariant propBold = PropVariant.FromObject((uint)_bold.Value);
                        fontProperties.SetValue(ref RibbonProperties.FontProperties_Bold, ref propBold);
                    }

                    // set italic
                    if (_italic.HasValue)
                    {
                        PropVariant propItalic = PropVariant.FromObject((uint)_italic.Value);
                        fontProperties.SetValue(ref RibbonProperties.FontProperties_Italic, ref propItalic);
                    }

                    // set underline
                    if (_underline.HasValue)
                    {
                        PropVariant propUnderline = PropVariant.FromObject((uint)_underline.Value);
                        fontProperties.SetValue(ref RibbonProperties.FontProperties_Underline, ref propUnderline);
                    }

                    // set strikethrough
                    if (_strikethrough.HasValue)
                    {
                        PropVariant propStrikethrough = PropVariant.FromObject((uint)_strikethrough.Value);
                        fontProperties.SetValue(ref RibbonProperties.FontProperties_Strikethrough, ref propStrikethrough);
                    }

                    // set foregroundColor
                    if (_foregroundColor.HasValue)
                    {
                        PropVariant propForegroundColor = PropVariant.FromObject((uint)ColorTranslator.ToWin32(_foregroundColor.Value));
                        fontProperties.SetValue(ref RibbonProperties.FontProperties_ForegroundColor, ref propForegroundColor);
                    }

                    // set foregroundColorType
                    if (_foregroundColorType.HasValue)
                    {
                        PropVariant propForegroundColorType = PropVariant.FromObject((uint)_foregroundColorType.Value);
                        fontProperties.SetValue(ref RibbonProperties.FontProperties_ForegroundColorType, ref propForegroundColorType);
                    }

                    // set backgroundColor
                    if (_backgroundColor.HasValue)
                    {
                        PropVariant propBackgroundColor = PropVariant.FromObject((uint)ColorTranslator.ToWin32(_backgroundColor.Value));
                        fontProperties.SetValue(ref RibbonProperties.FontProperties_BackgroundColor, ref propBackgroundColor);
                    }

                    // set backgroundColorType
                    if (_backgroundColorType.HasValue)
                    {
                        PropVariant propBackgroundColorType = PropVariant.FromObject((uint)_backgroundColorType.Value);
                        fontProperties.SetValue(ref RibbonProperties.FontProperties_BackgroundColorType, ref propBackgroundColorType);
                    }

                    // set verticalPositioning
                    if (_verticalPositioning.HasValue)
                    {
                        PropVariant propVerticalPositioning = PropVariant.FromObject((uint)_verticalPositioning.Value);
                        fontProperties.SetValue(ref RibbonProperties.FontProperties_VerticalPositioning, ref propVerticalPositioning);
                    }

                    // set new font properties
                    newValue.SetIUnknown(fontProperties);
                }
            }

            return HRESULT.S_OK;
        }
        /// <summary>
        /// Handles IUICommandHandler.UpdateProperty function for the supported properties
        /// </summary>
        /// <param name="key">The Property Key to update</param>
        /// <param name="currentValue">A pointer to the current value for key. This parameter can be NULL</param>
        /// <param name="newValue">When this method returns, contains a pointer to the new value for key</param>
        /// <returns>Returns S_OK if successful, or an error value otherwise</returns>
        public override HRESULT UpdateProperty(ref PropertyKey key, PropVariantRef currentValue, ref PropVariant newValue)
        {
            if (key == RibbonProperties.Categories)
            {
                if (CategoriesReady != null)
                {
                    CategoriesReady(_sender, EventArgs.Empty);
                }
            }
            else if (key == RibbonProperties.ItemsSource)
            {
                if (ItemsSourceReady != null)
                {
                    ItemsSourceReady(_sender, EventArgs.Empty);
                }
            }
            else if (key == RibbonProperties.SelectedItem)
            {
                if (_selectedItem.HasValue)
                {
                    newValue.SetUInt(_selectedItem.Value);
                }
            }

            return HRESULT.S_OK;
        }
Example #13
0
        /// <summary>
        /// Handles IUICommandHandler.UpdateProperty function for the supported properties
        /// </summary>
        /// <param name="key">The Property Key to update</param>
        /// <param name="currentValue">A pointer to the current value for key. This parameter can be NULL</param>
        /// <param name="newValue">When this method returns, contains a pointer to the new value for key</param>
        /// <returns>Returns S_OK if successful, or an error value otherwise</returns>
        public override HRESULT UpdateProperty(ref PropertyKey key, PropVariantRef currentValue, ref PropVariant newValue)
        {
            if (key == RibbonProperties.DecimalValue)
            {
            }
            else if (key == RibbonProperties.Increment)
            {
                if (_increment.HasValue)
                {
                    newValue.SetDecimal(_increment.Value);
                }
            }
            else if (key == RibbonProperties.MaxValue)
            {
                if (_maxValue.HasValue)
                {
                    newValue.SetDecimal(_maxValue.Value);
                }
            }
            else if (key == RibbonProperties.MinValue)
            {
                if (_minValue.HasValue)
                {
                    newValue.SetDecimal(_minValue.Value);
                }
            }
            else if (key == RibbonProperties.DecimalPlaces)
            {
                if (_decimalPlaces.HasValue)
                {
                    newValue.SetUInt(_decimalPlaces.Value);
                }
            }
            else if (key == RibbonProperties.FormatString)
            {
                if (_formatString != null)
                {
                    newValue.SetString(_formatString);
                }
            }

            return HRESULT.S_OK;
        }
        /// <summary>
        /// Handles IUICommandHandler.UpdateProperty function for the supported properties
        /// </summary>
        /// <param name="key">The Property Key to update</param>
        /// <param name="currentValue">A pointer to the current value for key. This parameter can be NULL</param>
        /// <param name="newValue">When this method returns, contains a pointer to the new value for key</param>
        /// <returns>Returns S_OK if successful, or an error value otherwise</returns>
        public override HRESULT UpdateProperty(ref PropertyKey key, PropVariantRef currentValue, ref PropVariant newValue)
        {
            if (key == RibbonProperties.BooleanValue)
            {
                if (_booleanValue.HasValue)
                {
                    newValue.SetBool(_booleanValue.Value);
                }
            }

            return HRESULT.S_OK;
        }
Example #15
0
        /// <summary>
        /// Handles IUICommandHandler.UpdateProperty function for the supported properties
        /// </summary>
        /// <param name="key">The Property Key to update</param>
        /// <param name="currentValue">A pointer to the current value for key. This parameter can be NULL</param>
        /// <param name="newValue">When this method returns, contains a pointer to the new value for key</param>
        /// <returns>Returns S_OK if successful, or an error value otherwise</returns>
        public override HRESULT UpdateProperty(ref PropertyKey key, PropVariantRef currentValue, ref PropVariant newValue)
        {
            if (key == RibbonProperties.LargeImage)
            {
                if (_largeImage != null)
                {
                    newValue.SetIUnknown(_largeImage);
                }
            }
            else if (key == RibbonProperties.SmallImage)
            {
                if (_smallImage != null)
                {
                    newValue.SetIUnknown(_smallImage);
                }
            }
            else if (key == RibbonProperties.LargeHighContrastImage)
            {
                if (_largeHighContrastImage != null)
                {
                    newValue.SetIUnknown(_largeHighContrastImage);
                }
            }
            else if (key == RibbonProperties.SmallHighContrastImage)
            {
                if (_smallHighContrastImage != null)
                {
                    newValue.SetIUnknown(_smallHighContrastImage);
                }
            }

            return HRESULT.S_OK;
        }
Example #16
0
        /// <summary>
        /// Handles IUICommandHandler.UpdateProperty function for the supported properties
        /// </summary>
        /// <param name="key">The Property Key to update</param>
        /// <param name="currentValue">A pointer to the current value for key. This parameter can be NULL</param>
        /// <param name="newValue">When this method returns, contains a pointer to the new value for key</param>
        /// <returns>Returns S_OK if successful, or an error value otherwise</returns>
        public override HRESULT UpdateProperty(ref PropertyKey key, PropVariantRef currentValue, ref PropVariant newValue)
        {
            if (key == RibbonProperties.TooltipTitle)
            {
                if (_tooltipTitle != null)
                {
                    newValue.SetString(_tooltipTitle);
                }
            }
            else if (key == RibbonProperties.TooltipDescription)
            {
                if (_tooltipDescription != null)
                {
                    newValue.SetString(_tooltipDescription);
                }
            }

            return HRESULT.S_OK;
        }
        /// <summary>
        /// Implementation of IUICommandHandler.UpdateProperty
        /// Responds to property update requests from the Windows Ribbon (Ribbon) framework. 
        /// </summary>
        /// <param name="commandID">The ID for the Command, which is specified in the Markup resource file</param>
        /// <param name="key">The Property Key to update</param>
        /// <param name="currentValue">A pointer to the current value for key. This parameter can be NULL</param>
        /// <param name="newValue">When this method returns, contains a pointer to the new value for key</param>
        /// <returns>Returns S_OK if successful, or an error value otherwise</returns>
        /// <remarks>This method is used internally by the Ribbon class and should not be called by the user.</remarks>
        public virtual HRESULT UpdateProperty(uint commandID, ref PropertyKey key, PropVariantRef currentValue, ref PropVariant newValue)
        {
            #if DEBUG
            Debug.WriteLine(string.Format("UpdateProperty key: {0} for command {1}", RibbonProperties.GetPropertyKeyName(ref key), commandID));
            #endif

            if (_mapRibbonControls.ContainsKey(commandID))
            {
                return _mapRibbonControls[commandID].UpdateProperty(ref key, currentValue, ref newValue);
            }

            return HRESULT.S_OK;
        }
Example #18
0
        public HRESULT UpdateProperty(ref PropertyKey key, PropVariantRef currentValue, ref PropVariant newValue)
        {
            if (key == RibbonProperties.ItemsSource)
            {
                if (_itemsSource != null)
                {
                    IUICollection itemsSource = (IUICollection)currentValue.PropVariant.Value;

                    itemsSource.Clear();
                    uint count;
                    _itemsSource.GetCount(out count);
                    for (uint i = 0; i < count; ++i)
                    {
                        object item;
                        _itemsSource.GetItem(i, out item);
                        itemsSource.Add(item);
                    }
                }
            }
            return HRESULT.S_OK;
        }
Example #19
0
 /// <summary>
 /// Handles IUICommandHandler.UpdateProperty function for the supported properties
 /// </summary>
 /// <param name="key">The Property Key to update</param>
 /// <param name="currentValue">A pointer to the current value for key. This parameter can be NULL</param>
 /// <param name="newValue">When this method returns, contains a pointer to the new value for key</param>
 /// <returns>Returns S_OK if successful, or an error value otherwise</returns>
 public virtual HRESULT UpdateProperty(ref PropertyKey key, PropVariantRef currentValue, ref PropVariant newValue)
 {
     return HRESULT.S_OK;
 }