public static CodeExpression GetDrawItemExpression(DrawingControl dc) { if (dc != null) { DrawingItem di = dc.Item as DrawingItem; if (di != null) { DrawDataRepeater ddp = di.Container as DrawDataRepeater; if (ddp != null) { //((item type)<repeater name>[<drawing item name>]) TypeMappingAttribute tma = null; object[] vs = dc.GetType().GetCustomAttributes(typeof(TypeMappingAttribute), true); if (vs != null && vs.Length > 0) { tma = vs[0] as TypeMappingAttribute; } if (tma != null) { CodeFieldReferenceExpression repeater = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), ddp.Name); CodeIndexerExpression cie = new CodeIndexerExpression(repeater, new CodePrimitiveExpression(dc.Name)); CodeCastExpression cce = new CodeCastExpression(tma.MappedType, cie); return(cce); } } } } return(null); }
public override void OnLoadedFromXmlFile(DrawingItem obj, IDesignPane designPane, IDrawDesignControl designControl) { Point p0 = this.Location; this.Copy(obj); //contained objects are cloned in _items if (this.Page != null && this.Page.InDesignMode) { DrawGroupBox dgb = obj as DrawGroupBox; if (dgb != null) { IList <DrawingItem> lst = dgb.Items; //cloned in _items if (lst != null && designPane != null && designControl != null) { //for each object, create a designer control and assign it to the control Control ctrl = designControl as Control; //control corresponding to this object foreach (DrawingItem di in lst) { Type t = di.GetType(); object[] vs = t.GetCustomAttributes(typeof(TypeMappingAttribute), true); if (vs != null && vs.Length > 0) { TypeMappingAttribute tm = vs[0] as TypeMappingAttribute; if (tm != null) { //create designer control IComponent ic = designPane.CreateComponent(tm.MappedType, di.Name); IDrawDesignControl idc = ic as IDrawDesignControl; Control c = ic as Control; DrawingItem d0 = idc.Item; //auto-created object, should be deleted ctrl.Controls.Add(c); idc.Item = GetItemByID(di.DrawingId); //use cloned object for the new control c.Location = di.Location; if (_items != null) { //remove auto-created object d0 for (int i = 0; i < _items.Count; i++) { if (d0 == _items[i] || d0.DrawingId == _items[i].DrawingId) { _items.RemoveAt(i); break; } } } } } } } } } this.Location = p0; }
public static Type GetDrawingItemType(Type controlType) { if (controlType.GetInterface("IDrawDesignControl") != null) { Type ret = TypeMappingAttribute.GetMappedType(controlType); if (ret == null) { throw new ExceptionDrawing2D("DrawingControl type {0} does not have DrawingItemTypeAttribute", controlType.AssemblyQualifiedName); } return(ret); } else { return(controlType); } }
private void showDrawingBoard(object sender, EventArgs e) { MenuItem mi = sender as MenuItem; if (mi != null) { DrawingPage page = mi.Tag as DrawingPage; if (page != null) { IDesignerHost host = (IDesignerHost)this.GetService(typeof(IDesignerHost)); if (host != null) { HostSurface surface = host.GetService(typeof(DesignSurface)) as HostSurface; if (surface != null) { ClassPointer root = surface.Loader.GetRootId(); DrawingLayerCollection layers = page.ShowDrawingsEditor(); if (layers != null) { //layers0 is the existing layer collections DrawingLayerCollection layers0 = page.DrawingLayers; //for layers0 if a drawing object's guid does not exist in layers then //the object has been deleted List <DrawingItem> deleted = new List <DrawingItem>(); foreach (DrawingLayer l0 in layers0) { DrawingItem d = null; for (int i = 0; i < l0.Count; i++) { DrawingItem d0 = l0[i]; d = layers.GetDrawingItemById(d0.DrawingId); if (d != null) { d0.Copy(d); //not deleted //move and resize the IDrawDesignControl foreach (Control c in page.Controls) { IDrawDesignControl dc0 = c as IDrawDesignControl; if (dc0 != null) { if (dc0.Item == d0) { c.Location = d0.Location; c.Size = d0.Bounds.Size; break; } } } } else { deleted.Add(d0); //deleted } } } if (deleted.Count > 0) { //check to see if each deleted item has usages List <DrawingItem> ls = new List <DrawingItem>(); foreach (DrawingItem d0 in deleted) { for (int i = 0; i < page.Controls.Count; i++) { IDrawDesignControl dc = page.Controls[i] as IDrawDesignControl; if (dc != null) { if (dc.DrawingId == d0.DrawingId) { uint id = root.ObjectList.GetObjectID(dc); if (id == 0) { DesignUtil.WriteToOutputWindow("id not found on deleting component {0}", dc.Name); } else { List <ObjectTextID> list = root.GetComponentUsage(id); if (list.Count > 0) { dlgObjectUsage dlg = new dlgObjectUsage(); dlg.LoadData("Cannot delete this component. It is being used by the following objects", string.Format("Component - {0}", dc.Name), list); dlg.ShowDialog(); ls.Add(d0); } } break; } } } } if (ls.Count > 0) { foreach (DrawingItem d0 in ls) { deleted.Remove(d0); } } foreach (DrawingItem d0 in deleted) { for (int i = 0; i < page.Controls.Count; i++) { IDrawDesignControl dc = page.Controls[i] as IDrawDesignControl; if (dc != null) { if (dc.DrawingId == d0.DrawingId) { surface.Loader.DeleteComponent(page.Controls[i]); break; } } } } } //for a drawing object in layers if its guid does not exist in layers0 then //it is a new object //reset zorder according to the new layers List <Control> ctrls = new List <Control>(); foreach (DrawingLayer l in layers) { int zOrder = 0; foreach (DrawingItem d in l) { DrawingItem d0 = layers0.GetDrawingItemById(d.DrawingId); if (d0 == null) { //add a new drawing string name = d.Name + Guid.NewGuid().GetHashCode().ToString("x"); Type designerType = TypeMappingAttribute.GetMappedType(d.GetType()); if (designerType == null) { throw new DesignerException("Drawing type {0} does not have a designer", d.GetType()); } Control dc = (Control)surface.Loader.CreateComponent(designerType, name); IDrawDesignControl ddc = (IDrawDesignControl)dc; ddc.Item = d; dc.Location = d.Location; dc.Size = d.Bounds.Size; ctrls.Add(dc); ddc.ZOrder = zOrder; } else { for (int k = 0; k < page.Controls.Count; k++) { IDrawDesignControl dc = page.Controls[k] as IDrawDesignControl; if (dc != null) { if (dc.Item == d0) { dc.ZOrder = zOrder; break; } } } } zOrder += 10; } } if (ctrls.Count > 0) { page.Controls.AddRange(ctrls.ToArray()); } page.LoadData(layers, false); page.Refresh(); surface.SetModified(); surface.Loader.NotifyChanges(); } } } } } }
static StringCollection _s_baseProperties; //subclasses must use their own static variables public DrawingGroupBox() { Visible = true; _item = (DrawingItem)Activator.CreateInstance(TypeMappingAttribute.GetMappedType(this.GetType())); }
/// <summary> /// Constructs a representation of a PostgreSQL base data type. /// </summary> #pragma warning disable CA2222 // Do not decrease inherited member visibility internal PostgresBaseType(string ns, string name, uint oid, Type handlerType, TypeMappingAttribute mapping) #pragma warning restore CA2222 // Do not decrease inherited member visibility : base(ns, name, oid) { HandlerType = handlerType; NpgsqlDbType = mapping.NpgsqlDbType; _dbTypes = mapping.DbTypes; _clrTypes = mapping.ClrTypes; }