/// <summary> /// Destruct the previously created views. /// </summary> public void Destruct() { // Unhook from events _buttonSpec.ButtonSpecPropertyChanged -= new PropertyChangedEventHandler(OnPropertyChanged); // Remove buttonspec/view association _buttonSpec.SetView(null); // Remove all view element resources _viewCenter.Dispose(); }
/// <summary> /// Initialize a new instance of the ButtonSpecView class. /// </summary> /// <param name="redirector">Palette redirector.</param> /// <param name="paletteMetric">Source for metric values.</param> /// <param name="metricPadding">Padding metric for border padding.</param> /// <param name="manager">Reference to owning manager.</param> /// <param name="buttonSpec">Access</param> public ButtonSpecView(PaletteRedirect redirector, IPaletteMetric paletteMetric, PaletteMetricPadding metricPadding, ButtonSpecManagerBase manager, ButtonSpec buttonSpec) { Debug.Assert(redirector != null); Debug.Assert(manager != null); Debug.Assert(buttonSpec != null); // Remember references _redirector = redirector; Manager = manager; ButtonSpec = buttonSpec; _finishDelegate = OnFinishDelegate; // Create delegate for paint notifications NeedPaintHandler needPaint = OnNeedPaint; // Intercept calls from the button for color remapping and instead use // the button spec defined map and the container foreground color RemapPalette = Manager.CreateButtonSpecRemap(redirector, buttonSpec); // Use a redirector to get button values directly from palette _palette = new PaletteTripleRedirect(RemapPalette, PaletteBackStyle.ButtonButtonSpec, PaletteBorderStyle.ButtonButtonSpec, PaletteContentStyle.ButtonButtonSpec, needPaint); // Create the view for displaying a button ViewButton = new ViewDrawButton(_palette, _palette, _palette, _palette, paletteMetric, this, VisualOrientation.Top, false); // Associate the view with the source component (for design time support) if (buttonSpec.AllowComponent) { ViewButton.Component = buttonSpec; } // Use a view center to place button in centre of given space ViewCenter = new ViewLayoutCenter(paletteMetric, metricPadding, VisualOrientation.Top) { ViewButton }; // Create a controller for managing button behavior ButtonSpecViewControllers controllers = CreateController(ViewButton, needPaint, OnClick); ViewButton.MouseController = controllers.MouseController; ViewButton.SourceController = controllers.SourceController; ViewButton.KeyController = controllers.KeyController; // We need notifying whenever a button specification property changes ButtonSpec.ButtonSpecPropertyChanged += OnPropertyChanged; // Associate the button spec with the view that is drawing it ButtonSpec.SetView(ViewButton); // Finally update view with current button spec settings UpdateButtonStyle(); UpdateVisible(); UpdateEnabled(); UpdateChecked(); }
/// <summary> /// Initialize a new instance of the ButtonSpecView class. /// </summary> /// <param name="redirector">Palette redirector.</param> /// <param name="paletteMetric">Source for metric values.</param> /// <param name="metricPadding">Padding metric for border padding.</param> /// <param name="manager">Reference to owning manager.</param> /// <param name="buttonSpec">Access</param> public ButtonSpecView(PaletteRedirect redirector, IPaletteMetric paletteMetric, PaletteMetricPadding metricPadding, ButtonSpecManagerBase manager, ButtonSpec buttonSpec) { Debug.Assert(redirector != null); Debug.Assert(manager != null); Debug.Assert(buttonSpec != null); // Remember references _redirector = redirector; _manager = manager; _buttonSpec = buttonSpec; _finishDelegate = new EventHandler(OnFinishDelegate); // Create delegate for paint notifications NeedPaintHandler needPaint = new NeedPaintHandler(OnNeedPaint); // Intercept calls from the button for color remapping and instead use // the button spec defined map and the container foreground color _remapPalette = _manager.CreateButtonSpecRemap(redirector, buttonSpec); // Use a redirector to get button values directly from palette _palette = new PaletteTripleRedirect(_remapPalette, PaletteBackStyle.ButtonButtonSpec, PaletteBorderStyle.ButtonButtonSpec, PaletteContentStyle.ButtonButtonSpec, needPaint); // Create the view for displaying a button _viewButton = new ViewDrawButton(_palette, _palette, _palette, _palette, paletteMetric, this, VisualOrientation.Top, false); // Associate the view with the source component (for design time support) if (buttonSpec.AllowComponent) _viewButton.Component = buttonSpec; // Use a view center to place button in centre of given space _viewCenter = new ViewLayoutCenter(paletteMetric, metricPadding, VisualOrientation.Top); _viewCenter.Add(_viewButton); // Create a controller for managing button behavior ButtonSpecViewControllers controllers = CreateController(_viewButton, needPaint, new MouseEventHandler(OnClick)); _viewButton.MouseController = controllers.MouseController; _viewButton.SourceController = controllers.SourceController; _viewButton.KeyController = controllers.KeyController; // We need notifying whenever a button specification property changes _buttonSpec.ButtonSpecPropertyChanged += new PropertyChangedEventHandler(OnPropertyChanged); // Associate the button spec with the view that is drawing it _buttonSpec.SetView(_viewButton); // Finally update view with current button spec settings UpdateButtonStyle(); UpdateVisible(); UpdateEnabled(); UpdateChecked(); }