Selection Handles drawn with wrong color

Hi,

I'm having a problem where my selection handles are getting drawn with the incorrect color.
I'd like for the handles to always display using the View's PimarySelectionColor for the primary in the selection and all other GoObjects should be drawn with the SecondarySelection color. This is mostly achieved by setting the NoFocusSelection color to the PrimarySelectionColor.
In my application, I occasionally need to have things redrawn in a GoView which does not have focus. For example, I have a top level window in my application with a property sheet where I can change behavior in the GoSelection of a nonfocused GoView. Changes are for things like othogonal to non-orthogonal for links (and have them redrawn), etc.
The view which does not have focus will create the selection handles inside of CreateResizeHandle(). If the selection instance isn't Focused, then all handles get drawn with the NoFocusSelection color (in my case all are drawn in the PrimarySelectionColor) which is undesirable. I've changed the Focused conditional code to the following and all seems to be fine:
if (this.Focused || view.NoFocusSelectionColor == view.PrimarySelectionColor)
{
if (this.Primary != null && this.Primary.SelectionObject == obj)
{
selColor = view.PrimarySelectionColor; } else { selColor = view.SecondarySelectionColor; } } else { selColor = view.NoFocusSelectionColor; }
Can you see a better way to resolve this issue?
Thanks!

That looks good. Here’s the complete code, for someone who does not have source code:

[code] public class SpecialSelection : GoSelection {
public SpecialSelection(GoView view) : base(view) {}

public override IGoHandle CreateBoundingHandle(GoObject obj, GoObject selectedObj) {
  IGoHandle handle = obj.CreateBoundingHandle();
  if (handle == null) return null;
  handle.SelectedObject = selectedObj;
  GoObject hobj = handle.GoObject;
  if (hobj == null) return null;
  hobj.Selectable = false;

  GoShape hshape = hobj as GoShape;
  if (hshape != null) {
    Color selColor = Color.LightGray;
    GoView view = this.View;
    if (view != null) {
      if (this.Focused || view.NoFocusSelectionColor == view.PrimarySelectionColor) {
        if (this.Primary != null &&
            this.Primary.SelectionObject == obj) {
          selColor = view.PrimarySelectionColor;
        } else {
          selColor = view.SecondarySelectionColor;
        }
      } else {
        selColor = view.NoFocusSelectionColor;
      }
    }
    float viewWidth = view.BoundingHandlePenWidth;
    float selWidth = (viewWidth == 0 ? 0 : viewWidth);
    if (myBoundingHandlePen == null ||
        GetPenColor(myBoundingHandlePen, selColor) != selColor ||
        GetPenWidth(myBoundingHandlePen) != selWidth) {
      myBoundingHandlePen = new Pen(selColor, selWidth);
    }
    hshape.Pen = myBoundingHandlePen;
    hshape.Brush = null;
  }

  AddHandle(obj, handle);
  return handle;
}

public override IGoHandle CreateResizeHandle(GoObject obj, GoObject selectedObj, PointF loc, int handleid, bool filled) {
  IGoHandle handle = obj.CreateResizeHandle(handleid);
  if (handle == null) return null;
  handle.HandleID = handleid;
  handle.SelectedObject = selectedObj;
  GoObject hobj = handle.GoObject;
  if (hobj == null) return null;
  GoView view = this.View;
  SizeF size = hobj.Size;
  if (size.Width <= 0 || size.Height <= 0) {
    if (view != null) {
      size = view.ResizeHandleSize;
    } else {
      size = new SizeF(6, 6);
    }
  }
  hobj.Bounds = new RectangleF(loc.X - size.Width/2, loc.Y - size.Height/2, size.Width, size.Height);
  if (handleid == GoObject.NoHandle) {
    hobj.Selectable = false;
  } else {
    hobj.Selectable = true;
  }

  GoShape hshape = hobj as GoShape;
  if (hshape != null) {
    Color selColor = Color.LightGray;
    if (view != null) {
      if (this.Focused || view.NoFocusSelectionColor == view.PrimarySelectionColor) {
        if (this.Primary != null &&
          this.Primary.SelectionObject == obj) {
          selColor = view.PrimarySelectionColor;
        } else {
          selColor = view.SecondarySelectionColor;
        }
      } else {
        selColor = view.NoFocusSelectionColor;
      }
    }
    if (filled) {
      float viewWidth = view.ResizeHandlePenWidth;
      float selWidth = (viewWidth == 0 ? 0 : viewWidth);
      if (myResizeHandlePen == null ||
          GetPenColor(myResizeHandlePen, myResizeHandlePenColor) != myResizeHandlePenColor ||
          GetPenWidth(myResizeHandlePen) != selWidth) {
        myResizeHandlePen = new Pen(myResizeHandlePenColor, selWidth);
      }
      hshape.Pen = myResizeHandlePen;
      if (myResizeHandleBrush == null ||
          myResizeHandleBrush.Color != selColor) {
        myResizeHandleBrush = new SolidBrush(selColor);
      }
      hshape.Brush = myResizeHandleBrush;
    } else {
      float viewWidth = view.ResizeHandlePenWidth;
      float selWidth = (viewWidth == 0 ? 0 : (viewWidth+1));
      if (myResizeHandlePen == null ||
          GetPenColor(myResizeHandlePen, selColor) != selColor ||
          GetPenWidth(myResizeHandlePen) != selWidth) {
        myResizeHandlePen = new Pen(selColor, selWidth);
      }
      hshape.Pen = myResizeHandlePen;
      hshape.Brush = null;
    }
  }

  AddHandle(obj, handle);
  return handle;
}

[NonSerialized]
private Pen myBoundingHandlePen;
[NonSerialized]
private Pen myResizeHandlePen;
private Color myResizeHandlePenColor = Color.Black;
[NonSerialized]
private SolidBrush myResizeHandleBrush;

internal static Color GetPenColor(Pen p, Color def) {
  if (p == null) return def;
  try {
    return p.Color;
  } catch (Exception) {
    return def;
  }
}

internal static float GetPenWidth(Pen pen) {
  if (pen == null) return 0;
  try {
    return pen.Width;
  } catch (Exception) {
    return 1;
  }
}

}

public class SpecialView : GoView {
public SpecialView() {
public override GoSelection CreateSelection() {
return new SpecialSelection(this);
}
}[/code]