void ProcDefBlock_FormalParamAdded(object sender, IProcDefBit newBit) { ProcDefBlock b = (ProcDefBlock)sender; ProcDefView v = (ProcDefView)ViewFromBlock(b); DataType type = DataType.Invalid; if (newBit is VarDefBlock) { VarDefBlock vb = (VarDefBlock)newBit; type = (vb).Type; int height = ArgBitTextHeight(newBit); EditableVarDefView vv = new EditableVarDefView(vb, MakeTextBitBitmap(vb.Name, height), varb_parts, textMetrics, textFont); blockViews[vb] = vv; vb.TextChanged += new VarDefBlockTextChangedEvent(ProcDef_FormalParamTextChanged); v.AddFormalBit(vv, type); } else { ProcDefTextBit pb = (ProcDefTextBit)newBit; pb.TextChanged += new ProcDefTextBitTextChangedEvent(ProcDefTextBit_TextChanged); EditableLabelView lv = new EditableLabelView(MakeTextBitBitmap(pb.Text, ArgBitTextHeight(pb)), (ProcDefTextBit)newBit); blockViews[pb] = lv; v.AddFormalBit(lv, DataType.Invalid); } }
void ProcDef_FormalParamTextChanged(object sender, string newText) { VarDefBlock b = (VarDefBlock)sender; EditableVarDefView v = (EditableVarDefView)ViewFromBlock(b); int height = ArgBitTextHeight(b); Bitmap bmp = MakeTextBitBitmap(newText, height); }
public void AddArg(DataType type) { string argName = MakeArgName(type); VarDefBlock v = new VarDefBlock(argName, type); v.ParentRelationship = new ParentRelationship(ParentRelationshipType.FormalParameter, model, model.Bits.Count); model.AddBit(v); }
private IBlockView ViewFromProcDefBlock(ProcDefBlock b) { List <IBlockView> subContent = new List <IBlockView>(); int i = 0; int n = b.Bits.Count; BitArray trueArgs = new BitArray(n); DataType[] argTypes = new DataType[n]; // slow: Repeats instanceof test twice for all bits; once for height and once to add to subContent int height = b.Bits.Count == 0?1: b.Bits.Max(bb => ArgBitTextHeight(bb)); foreach (IProcDefBit bit in b.Bits) { if (bit is VarDefBlock) { VarDefBlock vb = (VarDefBlock)bit; EditableVarDefView vv = new EditableVarDefView(vb, MakeTextBitBitmap(vb.Name, height), varb_parts, textMetrics, textFont); blockViews[vb] = vv; subContent.Add(vv); trueArgs[i] = true; argTypes[i] = vb.Type; vb.TextChanged += new VarDefBlockTextChangedEvent(ProcDef_FormalParamTextChanged); } else { ProcDefTextBit ptb = (ProcDefTextBit)bit; EditableLabelView ev = new EditableLabelView( MakeTextBitBitmap(ptb.Text, height), ptb); blockViews[ptb] = ev; subContent.Add(ev); argTypes[i] = DataType.Invalid; trueArgs[i] = false; ptb.TextChanged += new ProcDefTextBitTextChangedEvent(ProcDefTextBit_TextChanged); } ++i; } Bitmap[] defineTextView = RenderTextBits(new string[] { "define" }); ContentView innerContent = new ContentView(subContent.ToArray(), argTypes, trueArgs, sb_parts); ContentView outerContent = new ContentView(new IBlockView[] { new LabelView(defineTextView[0]), innerContent }, new DataType[] { DataType.Invalid }, new BitArray(new bool[] { false, true }), pdb_parts); ProcDefView pdb = new ProcDefView(b, outerContent, innerContent); b.FormalParamAdded += new ProcDefBitAddedEvent(ProcDefBlock_FormalParamAdded); b.FormalParamRemoved += new ProcDefBitRemovedEvent(ProcDefBlock_FormalParamRemoved); b.FormalParamChanged += new ProcDefBitChangedEvent(ProcDefBlock_FormalParamChanged); return(pdb); }
public EditableVarDefView(VarDefBlock model, Bitmap bitmap, Nine abc, Graphics textMetrics, Font textFont) { this._model = model; this.Changed += delegate(object source) { }; // todo: So much in common with TextView; consider abstracting into common implementation this.abc = abc; this.bitmap = bitmap; this.textMetrics = textMetrics; this.textFont = textFont; }
internal string[] GetArgNames() { List <string> ret = new List <string>(); foreach (IProcDefBit bit in Bits) { if (bit is VarDefBlock) { VarDefBlock vdb = bit as VarDefBlock; ret.Add(vdb.Name); } } return(ret.ToArray()); }
internal DataType[] GetArgTypes() { List <DataType> ret = new List <DataType>(); foreach (IProcDefBit bit in Bits) { if (bit is VarDefBlock) { VarDefBlock vdb = bit as VarDefBlock; ret.Add(vdb.Type); } } return(ret.ToArray()); }
internal VarDefBlock GetArg(string varName) { foreach (IProcDefBit bit in Bits) { if (bit is VarDefBlock) { VarDefBlock vdb = bit as VarDefBlock; if (vdb.Name == varName) { return(vdb); } } } throw new ArgumentException(string.Format("ProcDefBlock.GetArg(): Variable {0} not an argument", varName)); }
private IBlock ToVarAccess(JToken json) { string varName = json[1].ToString(); if (currentProcDef == null) { throw new InvalidOperationException(string.Format("Variable {0} used outside of proc definition", varName)); } if (!currentProcDef.GetArgNames().Contains(varName)) { throw new InvalidOperationException(string.Format("Variable {0} undefined", varName)); } VarDefBlock vdb = currentProcDef.GetArg(varName); VarAccessBlock b = new VarAccessBlock(vdb); return(b); }
public VarAccessBlock(VarDefBlock declaration) { this._declaration = declaration; }