using DevComponents.DotNetBar.Rendering; using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.Design; using System.Drawing; namespace DevComponents.DotNetBar.Design { public class ListBoxAdvDesigner : BarBaseControlDesigner { public ListBoxAdvDesigner() { this.EnableItemDragDrop = true; } public override void Initialize(IComponent component) { base.Initialize(component); if (component == null || component.Site == null || !component.Site.DesignMode) return; #if !TRIAL IDesignerHost dh = this.GetService(typeof(IDesignerHost)) as IDesignerHost; if (dh != null) dh.LoadComplete += new EventHandler(dh_LoadComplete); #endif } #if FRAMEWORK20 public override void InitializeNewComponent(IDictionary defaultValues) { base.InitializeNewComponent(defaultValues); SetDesignTimeDefaults(); } #else public override void OnSetComponentDefaults() { SetDesignTimeDefaults(); base.OnSetComponentDefaults(); } #endif protected virtual void SetDesignTimeDefaults() { ListBoxAdv panel = this.Control as ListBoxAdv; panel.BackgroundStyle.Class = ElementStyleClassKeys.ListBoxAdvKey; panel.AutoScroll = true; #if !TRIAL string key = GetLicenseKey(); panel.LicenseKey = key; #endif } public override DesignerVerbCollection Verbs { get { Bar bar = this.Control as Bar; DesignerVerb[] verbs = null; verbs = new DesignerVerb[] { new DesignerVerb("Add ListBoxItem", new EventHandler(CreateListBoxItem)) }; return new DesignerVerbCollection(verbs); } } protected virtual void CreateListBoxItem(object sender, EventArgs e) { OnSubItemsChanging(); CreateListBoxItem(this.GetDefaultNewItemContainer()); OnSubItemsChanged(); } protected virtual void CreateListBoxItem(BaseItem parent) { if (parent == null) return; ListBoxAdv listBox = this.Control as ListBoxAdv; IDesignerHost dh = (IDesignerHost)GetService(typeof(IDesignerHost)); if (dh != null) { DesignerTransaction trans = dh.CreateTransaction("Adding new item"); try { m_CreatingItem = true; ListBoxItem item = dh.CreateComponent(typeof(ListBoxItem)) as ListBoxItem; if (item == null) return; IComponentChangeService cc = this.GetService(typeof(IComponentChangeService)) as IComponentChangeService; if (listBox != null && cc != null) cc.OnComponentChanging(listBox, TypeDescriptor.GetProperties(typeof(ListBoxAdv))["Items"]); item.Text = string.Format("Item {0}", parent.SubItems.Count + 1); listBox.Items.Add(item); this.RecalcLayout(); if (listBox != null && cc != null) cc.OnComponentChanged(listBox, TypeDescriptor.GetProperties(typeof(ListBoxAdv))["Items"], null, null); OnitemCreated(item); } catch { trans.Cancel(); } finally { if (!trans.Canceled) trans.Commit(); m_CreatingItem = false; } } } protected override bool GetHitTest(Point pt) { ListBoxAdv panel = this.Control as ListBoxAdv; if (panel != null && panel.IsHandleCreated && panel.AutoScroll) { Point p = panel.PointToClient(pt); if (panel.VScrollBar != null && panel.VScrollBar.Bounds.Contains(p)) return true; if (panel.HScrollBar != null && panel.HScrollBar.Bounds.Contains(p)) return true; } return base.GetHitTest(pt); } #region Licensing Stuff #if !TRIAL protected string GetLicenseKey() { string key = ""; Microsoft.Win32.RegistryKey regkey = Microsoft.Win32.Registry.LocalMachine; regkey = regkey.OpenSubKey("Software\\DevComponents\\Licenses", false); if (regkey != null) { object keyValue = regkey.GetValue("DevComponents.DotNetBar.DotNetBarManager2"); if (keyValue != null) key = keyValue.ToString(); } return key; } private void dh_LoadComplete(object sender, EventArgs e) { IDesignerHost dh = this.GetService(typeof(IDesignerHost)) as IDesignerHost; if (dh != null) dh.LoadComplete -= new EventHandler(dh_LoadComplete); string key = GetLicenseKey(); ItemPanel bar = this.Control as ItemPanel; if (key != "" && bar != null && bar.LicenseKey == "" && bar.LicenseKey != key) TypeDescriptor.GetProperties(bar)["LicenseKey"].SetValue(bar, key); } #endif #endregion } }