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 ProcDefBlock_FormalParamChanged(object sender, int index, IProcDefBit newBit) { IBlockView v = ViewFromBlock((VarDefBlock)newBit); ProcDefView parent = (ProcDefView)ViewFromBlock((IBlock)sender); parent.SetFormalBit(index, v); }
void ProcDefBlock_FormalParamRemoved(object sender, IProcDefBit bit) { ProcDefBlock b = (ProcDefBlock)sender; ProcDefView v = (ProcDefView)ViewFromBlock(b); IBlockView bitView = ViewFromBlock((IBlock)bit); v.RemoveFormalBit(bitView); }
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 EditProcDefController NewProcDef(Func <TextBox> textBoxMaker, Button eraseButton) { ProcDefBlock block = new ProcDefBlock(); ProcDefView view = (ProcDefView)viewFactory.ViewFromBlock(block); EditProcDefController controller = new EditProcDefController(view, block, viewFactory, textBoxMaker, eraseButton); return(controller); }
public EditProcDefController(ProcDefView view, ProcDefBlock model, BlockViewFactory factory, Func<TextBox> textBoxMaker, Button eraseButton) { this.view = view; this.view.Changed += new ViewChangedEvent(view_Changed); this.model = model; this.factory = factory; this.textBoxMaker = textBoxMaker; this.eraseButton = eraseButton; this.eraseButton.Hide(); this.eraseButton.Click += new EventHandler(eraseButton_Click); this.Changed += delegate(object sender) { }; State = EditState.Ready; // I wish the view was dynamically centered, but there's some mismatch // between a label's textbox and the place where the text is drawn // for now we hide it by not constantly moving the view // strangely, the mistmatch disappears (text is drawn in the right place) // when view.RelativePos is not moved anymore. hmm... // Point origin = size.Center(b.Size); Point origin = new Point(15, 15); view.RelativePos = origin; }
public EditProcDefController(ProcDefView view, ProcDefBlock model, BlockViewFactory factory, Func <TextBox> textBoxMaker, Button eraseButton) { this.view = view; this.view.Changed += new ViewChangedEvent(view_Changed); this.model = model; this.factory = factory; this.textBoxMaker = textBoxMaker; this.eraseButton = eraseButton; this.eraseButton.Hide(); this.eraseButton.Click += new EventHandler(eraseButton_Click); this.Changed += delegate(object sender) { }; State = EditState.Ready; // I wish the view was dynamically centered, but there's some mismatch // between a label's textbox and the place where the text is drawn // for now we hide it by not constantly moving the view // strangely, the mistmatch disappears (text is drawn in the right place) // when view.RelativePos is not moved anymore. hmm... // Point origin = size.Center(b.Size); Point origin = new Point(15, 15); view.RelativePos = origin; }
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; }