Hello,
public GoView EditorView
{
get
{
return _editorView;
}
set
{
_editorView = value;
}
}
{
box1.Position = new PointF(50, 50);
box1.Text = "Test";
_editorView.Document.Add(box1);
t.Show();
{
public TestView()
{
GoView myView = new GoView();
myView.Dock = DockStyle.Fill;
this.Controls.Add(myView);
box1.Position = new PointF(50, 50);
box1.Text = "Test";
myView.Document.Add(box1);
}
}
class ISwEditBox2 : GoGroup {
// a ISwEditBox2 initially has just an "empty" box shape, shown by a GoRoundedRectangle,
// and a label (a GoText)
public ISwEditBox2()
{
this.Initializing = true;
myBorder = new GoRoundedRectangle();
myBorder.Selectable = false;
if (myBorderPen == null)
{
Pen p = new Pen(Color.Blue, 2);
//p.DashStyle = DashStyle.Dash;
myBorderPen = p;
}
myBorder.Pen = myBorderPen;
myBorder.Size = new SizeF(100,100);
Add(myBorder);
myLabel = new GoText();
//myLabel.Bordered = true;
myLabel.Text = "KB";
myLabel.Selectable = false;
myLabel.Editable = true;
Add(myLabel);
this.Initializing = false;
LayoutChildren(myBorder);
}
protected override void CopyChildren(GoGroup newgroup, GoCopyDictionary env) {
base.CopyChildren(newgroup, env);
ISwEditBox2 newobj = (ISwEditBox2)newgroup;
newobj.myBorder = (GoShape)env[myBorder];
newobj.myLabel = (GoText)env[myLabel];
}
public override void Remove(GoObject obj) {
base.Remove(obj);
if (obj == myBorder)
myBorder = null;
else if (obj == myLabel)
myLabel = null;
}
// This might return null, if there are no other objects besides the Border.
public RectangleF ComputeBorder() {
RectangleF rect = RectangleF.Empty;
bool first = true;
foreach (GoObject obj in this) {
if (obj == this.Border) continue;
if (obj == this.myLabel) continue;
if (first) {
first = false;
rect = obj.Bounds;
} else {
// add the object's bounding rect to this one
rect = RectangleF.Union(rect, obj.Bounds);
}
}
if (!first) {
// leave some room as a margin
rect.Inflate(4, 4);
}
return rect;
}
public override void LayoutChildren(GoObject childchanged) {
if (this.Initializing) return;
GoObject border = this.Border;
GoObject label = this.myLabel;
if (childchanged == border && border != null && label != null) {
RectangleF rect = border.Bounds;
label.SetSpotLocation(BottomLeft, new PointF(rect.X, rect.Y-2));
} else if (!this.AllowDragInOut) {
// compute the minimum rectangle needed to enclose the children except for the Border
RectangleF rect = ComputeBorder();
if (rect != RectangleF.Empty) {
// but don't have the box shrink to minimum size continuously
rect = RectangleF.Union(rect, border.Bounds);
border.Bounds = rect;
if (label != null) {
this.myLabel.SetSpotLocation(BottomLeft, new PointF(rect.X, rect.Y - 2));
}
}
}
}
// When this property is false, there should not be a BackgroundSelectionDropped event
// handler, and this node will not support reparenting of its children -- the border
// will always surround its children.
public bool AllowDragInOut {
get { return true; }
}
if (this.AllowDragInOut) {
// add all selected objects to this ISwEditBox2
view.Selection.AddRange(AddCollection(view.Selection, true));
// update the border to include all selected objects in case the selection crosses the border
GoObject border = this.Border;
if (border != null) {
RectangleF rect = ComputeBorder();
if (rect != RectangleF.Empty) {
// but don't have the box shrink to minimum size continuously
rect = RectangleF.Union(rect, border.Bounds);
border.Bounds = rect;
}
}
return true;
} else {
return false;
}
}
// this ensures that the border surrounds all of the children.
public override void DoResize(GoView view, RectangleF origRect, PointF newPoint, int whichHandle, GoInputState evttype, SizeF min, SizeF max) {
// compute rectangle for normal resizing
RectangleF newRect = ComputeResize(origRect, newPoint, whichHandle, min, max, true);
// account for the height of the Label
newRect.Y += this.myLabel.Height + 2;
newRect.Height -= this.myLabel.Height + 2;
// compute rectangle required by the child objects
RectangleF minRect = ComputeBorder();
if (minRect != RectangleF.Empty) {
newRect = RectangleF.Union(newRect, minRect);
}
// update the bounding rect of the Border
this.Border.Bounds = newRect;
}
get { return myBorder; }
}
{
get { return myLabel.Text; }
set { myLabel.Text = value;}
}
private GoText myLabel = null;
}