/// <summary> /// Sets the ExpandedImage property for a TreeNode (Key|Index). /// </summary> /// <param name="nItem">The TreeNode to set.</param> /// <param name="value">The new value to set.</param> public static void SetTreeNodeExpandedImageProperty(TreeNode nItem, object value) { TreeView treeView = nItem.TreeView; if ((value is string) || (value is Int32)) { if (CheckForProperty(treeView, NewPropertiesEnum.ExpandedImage)) { ValidateImageIndex(treeView, value); Dictionary <TreeNode, object> treeNodeExpandedImageList = (Dictionary <TreeNode, object>)NewProperties[treeView][NewPropertiesEnum.ExpandedImage]; if (!treeNodeExpandedImageList.ContainsKey(nItem)) { treeNodeExpandedImageList.Add(nItem, value); } else { treeNodeExpandedImageList[nItem] = value; } if (!EventsPatched.ContainsKey(treeView)) { CorrectEventsForTreeView(treeView); } CheckExpandedImageForTreeNode(nItem); } return; } throw new InvalidCastException("Invalid property value"); }
/// <summary> /// Patches the events for a specific button. /// </summary> /// <param name="btn">The button to patch.</param> private static void CorretEventsForButton(Button btn) { if (EventsPatched.ContainsKey(btn)) { throw new InvalidOperationException("Events for this button has been previously patched: '" + btn.Name + "'"); } EventsPatched.Add(btn, new Dictionary <string, List <Delegate> >()); foreach (string eventName in EventsToCorrect.Keys) { EventInfo eventInfo = btn.GetType().GetEvent(eventName); if (eventInfo == null) { throw new InvalidOperationException("Event info for event '" + eventName + "' could not be found"); } EventsPatched[btn].Add(eventName, new List <Delegate>()); Delegate[] eventDelegates = ContainerHelper.GetEventSubscribers(btn, eventName); if (eventDelegates != null) { foreach (Delegate del in eventDelegates) { EventsPatched[btn][eventName].Add(del); eventInfo.RemoveEventHandler(btn, del); } } eventInfo.AddEventHandler(btn, EventsToCorrect[eventName]); } }
/// <summary> /// Static - Sets the value of the property Style. /// </summary> /// <param name="designMode">To indicate if the operation is done in design mode.</param> /// <param name="button">The button to set the property.</param> /// <param name="style">The style to set.</param> public static void SetStyleProperty(bool designMode, Button button, int style) { if (OnMouseDown.Contains(button)) { SetStylePendingList.Enqueue(new KeyValuePair <Button, int>(button, style)); return; } Styles[button] = (style == 0) ? 0 : 1; if (designMode) { return; } button.Paint -= Button_Paint; if ((Styles[button] == 0) && (button.Image != null)) { UpPictures[button] = button.Image; button.Image = null; } else if ((Styles[button] == 1) && UpPictures.ContainsKey(button)) { button.Image = UpPictures[button]; } button.Paint += Button_Paint; }
public void CanFindOutIfContainsAKey() { WeakDictionary <object, object> dict = new WeakDictionary <object, object>(); dict.Add("foo", null); Assert.IsTrue(dict.ContainsKey("foo")); Assert.IsFalse(dict.ContainsKey("foo2")); }
/// <summary> /// Checks if a TreeView is controlled by the newProperties Dictionary. /// </summary> /// <param name="tView">The TreeView.</param> private static void CheckNewProperties(TreeView tView) { if (!newProperties.ContainsKey(tView)) { newProperties[tView] = new Dictionary <newPropertiesEnum, object>(); tView.Disposed += new EventHandler(TreeView_Disposed); } }
/// <summary> /// Checks if a TreeView is controlled by the newProperties Dictionary. /// </summary> /// <param name="treeView">The TreeView.</param> private static void CheckNewProperties(TreeView treeView) { if (!NewProperties.ContainsKey(treeView)) { NewProperties[treeView] = new Dictionary <NewPropertiesEnum, object>(); treeView.Disposed += TreeView_Disposed; } }
private static void AddListenerToCache(object aListener, EventObject aEvent) { if (!_listenerDict.ContainsKey(aListener)) { _listenerDict.Add(aListener, new List <EventObject>()); } if (!_listenerDict[aListener].Contains(aEvent)) { _listenerDict[aListener].Add(aEvent); } }
/// <summary> /// Checks if the btn is controlled by the newProperties Dictionary. /// </summary> /// <param name="btn">The button</param> private static void CheckNewProperties(Button btn) { if (!NewProperties.ContainsKey(btn)) { NewProperties[btn] = new Dictionary <NewPropertiesEnum, object>(); } }
internal void OnChildGroupRenderSizeChanged(RibbonGroup group, double originalWidth) { if (!_changedWidthGroups.ContainsKey(group)) { _changedWidthGroups[group] = originalWidth; } if (!_processGroupWidthChangeQueued) { _processGroupWidthChangeQueued = true; Dispatcher.BeginInvoke( (Action) delegate() { if (_changedWidthGroups.Count > 0) { foreach (RibbonGroup invalidGroup in _changedWidthGroups.Keys) { double originalRenderWidth = _changedWidthGroups[invalidGroup]; if (!DoubleUtil.AreClose(originalRenderWidth, invalidGroup.ActualWidth)) { // Reset the next increase group's cached data // if there was a real change in any groups width. ResetNextIncreaseGroupCache(); InvalidateMeasure(); break; } } } _changedWidthGroups.Clear(); _processGroupWidthChangeQueued = false; }, DispatcherPriority.Input, null); } }
/// <summary> /// Static - Gets the down picture bound to this button. /// </summary> /// <param name="button">The button bound to the down picture.</param> /// <returns>The image bound for down picture of this button.</returns> public static Image GetDownPictureProperty(Button button) { if (!DownPictures.ContainsKey(button)) { return(null); } return(DownPictures[button]); }
/// <summary> /// Static - Gets the property MaskColor for the button. /// </summary> /// <param name="button">The button.</param> /// <returns>The current MaskColor for this button.</returns> public static Color GetMaskColorProperty(Button button) { if (!MaskColor.ContainsKey(button)) { MaskColor.Add(button, Color.Silver); } return(MaskColor[button]); }
/// <summary> /// Static - Gets the disabled picture bound to this button. /// </summary> /// <param name="button">The button bound to the disabled picture.</param> /// <returns>The image bound for disable picture of this button.</returns> public static Image GetDisabledPictureProperty(Button button) { if (!DisabledPictures.ContainsKey(button)) { return(null); } else { return(DisabledPictures[button]); } }
/// <summary> /// Static - Gets the current value of the property Style. /// </summary> /// <param name="button">The button to get the property.</param> /// <returns>The current value.</returns> public static int GetStyleProperty(Button button) { if (!Styles.ContainsKey(button)) { return(0); } return(Styles[button]); }
private void ObjectInvariants() { Contract.Invariant(childrenRoot != null); Contract.Invariant(dataToVisual != null); // only two options - visible and single child (childrenRoot) or invisible and no children. Contract.Invariant( (IsVisible && Children.Count == 1 && Children[0] == childrenRoot) ^ (!IsVisible && Children.Count == 0)); // itemsView != null ==> the count of items and models is the same. Contract.Invariant(itemsView == null || itemsView.Cast <object>().Count() == childrenRoot.Children.Count); // itemsView != null ==> for all items we have a mapping to the item's model in the dictionary. Contract.Invariant(itemsView == null || Contract.ForAll(itemsView.Cast <object>(), item => dataToVisual.ContainsKey(item))); // for all items in data->model mapping, the model actually exists in the group children Contract.Invariant(Contract.ForAll(dataToVisual, item => childrenRoot.Children.Contains(item.Value))); // itemsView == null ==> both data-model mapping and group children have no items. Contract.Invariant(itemsView != null || (dataToVisual.Count == 0 && childrenRoot.Children.Count == 0)); }
/************************************************************************************* * PUBLIC: Listener logic *************************************************************************************/ public static void AddEventListener(string aEvent, object aDispatcher, object aListener, Action <EventObject> aMethod, int aPriority = 1) { if (aDispatcher == null || aListener == null) { return; } if (!_eventObjDict.ContainsKey(aDispatcher)) //If the dispatcher has never been registered, create a entry for it. { RegistertDispatcher(aDispatcher); } if (!IsDispatcherEventRelationRegistered(aDispatcher, aEvent)) //If this event has never been registered for that dispatcher create a new EventObject to manage it. { RegistertDispatcherEventRelation(aDispatcher, aEvent); } EventObject eventObj = _eventObjDict[aDispatcher][aEvent]; eventObj.RegisterEventListener(aListener, aMethod, aPriority); AddListenerToCache(aListener, eventObj); }
/// <summary> /// Sets the SelectionMode for a control. /// </summary> /// <param name="lstBox">The control to set the SelectionMode.</param> /// <param name="mode">The selection mode to set.</param> public void SetSelectionMode(ListBox lstBox, SelectionMode mode) { lstBox.SelectionMode = mode; if ((mode == SelectionMode.MultiExtended) || (mode == SelectionMode.MultiSimple)) { if (!_SelectedIndexList.ContainsKey(lstBox)) { _SelectedIndexList.Add(lstBox, 0); lstBox.DrawMode = DrawMode.OwnerDrawFixed; lstBox.DrawItem += ListBox_DrawItem; } } else { if (_SelectedIndexList.ContainsKey(lstBox)) { _SelectedIndexList.Remove(lstBox); lstBox.DrawMode = DrawMode.Normal; lstBox.DrawItem -= ListBox_DrawItem; } } }
/// <summary> /// Sets the SelectionMode for a control. /// </summary> /// <param name="lstBox">The control to set the SelectionMode.</param> /// <param name="mode">The selection mode to set.</param> public void SetSelectionMode(System.Windows.Forms.ListBox lstBox, System.Windows.Forms.SelectionMode mode) { lstBox.SelectionMode = mode; if ((mode == System.Windows.Forms.SelectionMode.MultiExtended) || (mode == System.Windows.Forms.SelectionMode.MultiSimple)) { if (!selectedIndexList.ContainsKey(lstBox)) { selectedIndexList.Add(lstBox, 0); lstBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed; lstBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(ListBox_DrawItem); } } else { if (selectedIndexList.ContainsKey(lstBox)) { selectedIndexList.Remove(lstBox); lstBox.DrawMode = DrawMode.Normal; lstBox.DrawItem -= new System.Windows.Forms.DrawItemEventHandler(ListBox_DrawItem); } } }
public bool ContainsKey(WeakDictionary <object, int, object> d, Tuple <object, int> k) { return(d.ContainsKey(k.Item1, k.Item2)); }
public bool ContainsKey(WeakDictionary <int, object> d, int k) { return(d.ContainsKey(k)); }