// John Sohn jsohn@columbus.rr.com
//
-// COMPLETE
-
#undef DebugRecreate
#undef DebugFocus
Dispose ();
}
}
+
+ [ListBindable (false)]
#if NET_2_0
[ComVisible (false)]
+ public class ControlCollection : Layout.ArrangedElementCollection, IList, ICollection, ICloneable, IEnumerable {
#else
[DesignerSerializer("System.Windows.Forms.Design.ControlCollectionCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
-#endif
- [ListBindable(false)]
public class ControlCollection : IList, ICollection, ICloneable, IEnumerable {
+#endif
#region ControlCollection Local Variables
+#if !NET_2_0
ArrayList list;
+#endif
ArrayList impl_list;
Control[] all_controls;
Control owner;
#region ControlCollection Public Constructor
public ControlCollection(Control owner) {
this.owner=owner;
+#if !NET_2_0
this.list=new ArrayList();
+#endif
}
#endregion
}
+#if !NET_2_0
public int Count {
get { return list.Count; }
}
+#endif
#if NET_2_0
bool IList.IsReadOnly
}
}
+#if NET_2_0
+ public Control Owner { get { return this.owner; } }
+
+ public virtual Control this[string key] {
+ get {
+ int index = IndexOfKey (key);
+
+ if (index >= 0)
+ return this[index];
+
+ return null;
+ }
+ }
+
+ new
+#endif
public virtual Control this[int index] {
get {
if (index < 0 || index >= list.Count) {
}
return (Control)list[index];
}
+
+
}
#endregion // ControlCollection Public Instance Properties
- #region ControlCollection Private Instance Methods
+ #region ControlCollection Instance Methods
public virtual void Add (Control value)
{
if (value == null)
}
}
+#if NET_2_0
+ new
+#endif
public virtual void Clear ()
{
all_controls = null;
return Contains (value) || ImplicitContains (value);
}
+#if NET_2_0
+ public virtual bool ContainsKey (string key)
+ {
+ return IndexOfKey (key) >= 0;
+ }
+#endif
+
void ICollection.CopyTo (Array array, int index)
{
CopyTo (array, index);
}
- internal void CopyTo (Array array, int index)
+#if !NET_2_0
+ public void CopyTo (Array array, int index)
{
list.CopyTo(array, index);
}
-#if !NET_2_0
public override bool Equals (object other)
{
if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
}
#endif
+#if NET_2_0
+ // LAMESPEC: MSDN says AE, MS implementation throws ANE
+ public Control[] Find (string key, bool searchAllChildren)
+ {
+ if (string.IsNullOrEmpty (key))
+ throw new ArgumentNullException ("key");
+
+ ArrayList al = new ArrayList ();
+
+ foreach (Control c in list) {
+ if (c.Name.Equals (key, StringComparison.CurrentCultureIgnoreCase))
+ al.Add (c);
+
+ if (searchAllChildren)
+ al.AddRange (c.Controls.Find (key, true));
+ }
+
+ return (Control[])al.ToArray (typeof (Control));
+ }
+#endif
+
public int GetChildIndex(Control child) {
return GetChildIndex(child, false);
}
}
#if NET_2_0
- public virtual IEnumerator
+ public override IEnumerator
#else
public IEnumerator
#endif
return list.IndexOf(control);
}
+#if NET_2_0
+ public virtual int IndexOfKey (string key)
+ {
+ if (string.IsNullOrEmpty (key))
+ return -1;
+
+ for (int i = 0; i < list.Count; i++)
+ if (((Control)list[i]).Name.Equals (key, StringComparison.CurrentCultureIgnoreCase))
+ return i;
+
+ return -1;
+ }
+#endif
+
public virtual void Remove(Control value)
{
if (value == null)
owner.UpdateChildrenZOrder ();
}
+#if NET_2_0
+ new
+#endif
public void RemoveAt(int index)
{
if (index < 0 || index >= list.Count) {
}
#if NET_2_0
+ public virtual void RemoveByKey (string key)
+ {
+ int index = IndexOfKey (key);
+
+ if (index >= 0)
+ RemoveAt (index);
+ }
+
public virtual void
#else
public void
tab_stop = true;
ime_mode = ImeMode.Inherit;
- layout_engine = this.LayoutEngine;
- if (layout_engine == null)
- layout_engine = new Layout.DefaultLayout ();
#if NET_2_0
backgroundimage_layout = ImageLayout.Tile;
use_compatible_text_rendering = Application.use_compatible_text_rendering;
child_controls = CreateControlsInstance();
client_size = new Size(DefaultSize.Width, DefaultSize.Height);
client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
- XplatUI.CalculateWindowRect(ref client_rect, CreateParams.Style, CreateParams.ExStyle, null, out bounds);
+ bounds.Size = SizeFromClientSize (client_size);
+
if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) == 0) {
bounds.X=-1;
bounds.Y=-1;
border_style = value;
if (IsHandleCreated) {
- XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
- Refresh();
+ XplatUI.SetBorderStyle (window.Handle, (FormBorderStyle)border_style);
+ RecreateHandle ();
+ Refresh ();
}
}
}
}
container = GetContainerControl();
- if (container != null) {
+ if (container != null && (Control)container != control) {
container.ActiveControl = control;
}
if (control.IsHandleCreated) {
anchor_style=value;
- if (parent != null) {
+ UpdateDistances ();
+
+ if (parent != null)
parent.PerformLayout(this, "Anchor");
- }
}
}
[DefaultValue (false)]
[MonoTODO("This method currently does nothing")]
public virtual bool AutoSize {
- get {
- //Console.Error.WriteLine("Unimplemented: Control::get_AutoSize()");
- return auto_size;
- }
+ get { return auto_size; }
set {
- auto_size = value;
+ if (this.auto_size != value) {
+ auto_size = value;
+ OnAutoSizeChanged (EventArgs.Empty);
+ }
}
}
return minimum_size;
}
set {
- minimum_size = value;
+ if (minimum_size != value) {
+ minimum_size = value;
+ PerformLayout ();
+ }
}
}
#endif // NET_2_0
if (value != backgroundimage_layout) {
backgroundimage_layout = value;
Invalidate ();
+ OnBackgroundImageLayoutChanged (EventArgs.Empty);
}
}
set {
this.SetClientSizeCore(value.Width, value.Height);
+#if NET_2_0
+ this.OnClientSizeChanged (EventArgs.Empty);
+#endif
}
}
}
}
- internal bool ContainerSelected {
- get { return container_selected; }
- set { container_selected = value; }
- }
+ internal bool ContainerSelected {
+ get { return container_selected; }
+ set { container_selected = value; }
+ }
[EditorBrowsable(EditorBrowsableState.Advanced)]
[Browsable(false)]
}
set {
+ if (this.is_enabled != value) {
+ bool old_value = is_enabled;
- bool old_value = is_enabled;
-
- is_enabled = value;
- if (old_value != value && !value && this.has_focus)
- SelectNextControl(this, true, true, true, true);
+ is_enabled = value;
+ if (old_value != value && !value && this.has_focus)
+ SelectNextControl(this, true, true, true, true);
- OnEnabledChanged (EventArgs.Empty);
+ OnEnabledChanged (EventArgs.Empty);
+ }
}
}
font = value;
Invalidate();
OnFontChanged (EventArgs.Empty);
+ PerformLayout ();
}
}
public virtual
#endif
Layout.LayoutEngine LayoutEngine {
- get { return new Layout.DefaultLayout (); }
- }
+ get {
+ if (layout_engine == null)
+ layout_engine = new Layout.DefaultLayout ();
+ return layout_engine;
+ }
+ }
[EditorBrowsable(EditorBrowsableState.Always)]
[Browsable(false)]
[Localizable (true)]
public Padding Margin {
get { return this.margin; }
- set { this.margin = value; }
+ set {
+ if (this.margin != value) {
+ this.margin = value;
+ OnMarginChanged (EventArgs.Empty);
+ }
+ }
}
#endif
}
set {
- padding = value;
- OnPaddingChanged (EventArgs.Empty);
+ if (padding != value) {
+ padding = value;
+ OnPaddingChanged (EventArgs.Empty);
+ PerformLayout ();
+ }
}
}
#endif
}
set {
- if (value != null && IsHandleCreated) {
- XplatUI.SetClipRegion(Handle, value);
+ if (clip_region != value) {
+ if (value != null && IsHandleCreated)
+ XplatUI.SetClipRegion(Handle, value);
+
+ clip_region = value;
+#if NET_2_0
+ OnRegionChanged (EventArgs.Empty);
+#endif
}
- clip_region = value;
}
}
if (value != right_to_left) {
right_to_left = value;
OnRightToLeftChanged(EventArgs.Empty);
+ PerformLayout ();
}
}
}
}
}
+#if NET_2_0
+ protected virtual Cursor DefaultCursor { get { return Cursors.Default; } }
+#endif
+
protected virtual ImeMode DefaultImeMode {
get {
return ImeMode.Inherit;
protected virtual Padding DefaultMargin {
get { return new Padding (3); }
}
+
+ protected virtual Size DefaultMaximumSize { get { return new Size (); } }
+ protected virtual Size DefaultMinimumSize { get { return new Size (); } }
+ protected virtual Padding DefaultPadding { get { return new Padding (); } }
#endif
protected virtual Size DefaultSize {
if (!IsHandleCreated)
return;
- NotifyInvalidate(rc);
+ if (rc.Width > 0 && rc.Height > 0) {
- XplatUI.Invalidate(Handle, rc, false);
+ NotifyInvalidate(rc);
- if (invalidateChildren) {
- Control [] controls = child_controls.GetAllControls ();
- for (int i=0; i<controls.Length; i++)
- controls [i].Invalidate ();
+ XplatUI.Invalidate(Handle, rc, false);
+
+ if (invalidateChildren) {
+ Control [] controls = child_controls.GetAllControls ();
+ for (int i=0; i<controls.Length; i++)
+ controls [i].Invalidate ();
+ }
}
OnInvalidated(new InvalidateEventArgs(rc));
}
// Perform all Dock and Anchor calculations
try {
- layout_engine.Layout(this, levent);
-
- // Let everyone know
OnLayout(levent);
}
IContainerControl container;
container = GetContainerControl();
- if (container != null)
- container.ActiveControl = this;
+ if (container != null && (Control)container != this)
+ if (!this.Parent.ContainerSelected)
+ container.ActiveControl = this;
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
protected virtual void SetClientSizeCore(int x, int y) {
- // Calculate the actual window size from the client size (it usually stays the same or grows)
- Rectangle ClientRect;
- Rectangle WindowRect;
- CreateParams cp;
-
- ClientRect = new Rectangle(0, 0, x, y);
- cp = this.CreateParams;
-
- if (XplatUI.CalculateWindowRect(ref ClientRect, cp.Style, cp.ExStyle, null, out WindowRect)==false) {
- return;
- }
-
- SetBounds(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
+ Size NewSize = SizeFromClientSize (new Size (x, y));
+
+ if (NewSize != Size.Empty)
+ SetBounds (bounds.X, bounds.Y, NewSize.Width, NewSize.Height, BoundsSpecified.Size);
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
protected void SetTopLevel(bool value) {
if ((GetTopLevel() != value) && (parent != null)) {
- throw new Exception();
+ throw new ArgumentException ("Cannot change toplevel style of a parented control.");
}
if (this is Form) {
}
} else {
if (Visible) {
- Visible = false;
+ Visible = false;
}
}
}
if (parent != null) {
parent.PerformLayout(this, "visible");
} else {
- PerformLayout(this, "visible");
+ if (is_visible)
+ PerformLayout(this, "visible");
}
}
}
-
+
+#if NET_2_0
+ protected
+#else
+ internal
+#endif
+ virtual Size SizeFromClientSize (Size clientSize)
+ {
+ Rectangle ClientRect;
+ Rectangle WindowRect;
+ CreateParams cp;
+
+ ClientRect = new Rectangle (0, 0, clientSize.Width, clientSize.Height);
+ cp = this.CreateParams;
+
+ if (XplatUI.CalculateWindowRect (ref ClientRect, cp.Style, cp.ExStyle, null, out WindowRect))
+ return new Size (WindowRect.Width, WindowRect.Height);
+
+ return Size.Empty;
+ }
+
[EditorBrowsable(EditorBrowsableState.Advanced)]
protected void UpdateBounds() {
int x;
if (resized) {
OnSizeChanged(EventArgs.Empty);
+#if NET_2_0
+ OnClientSizeChanged (EventArgs.Empty);
+#endif
}
}
}
case Msg.WM_SETFOCUS: {
- if (!has_focus) {
- this.has_focus = true;
+ if (!has_focus) {
if (this.Parent != null && this.Parent.ContainerSelected)
return;
- OnGotFocusInternal (EventArgs.Empty);
+ this.has_focus = true;
+ OnGotFocusInternal (EventArgs.Empty);
}
return;
}
#endregion // Public Instance Methods
#region OnXXX methods
- [EditorBrowsable(EditorBrowsableState.Advanced)]
+#if NET_2_0
+ protected virtual void OnAutoSizeChanged (EventArgs e)
+ {
+ EventHandler eh = (EventHandler)(Events[AutoSizeChangedEvent]);
+ if (eh != null)
+ eh (this, e);
+ }
+#endif
+
+ [EditorBrowsable (EditorBrowsableState.Advanced)]
protected virtual void OnBackColorChanged(EventArgs e) {
EventHandler eh = (EventHandler)(Events [BackColorChangedEvent]);
if (eh != null)
for (int i=0; i<child_controls.Count; i++) child_controls[i].OnParentBackgroundImageChanged(e);
}
+#if NET_2_0
+ [EditorBrowsable (EditorBrowsableState.Advanced)]
+ protected virtual void OnBackgroundImageLayoutChanged (EventArgs e)
+ {
+ EventHandler eh = (EventHandler)(Events[BackgroundImageLayoutChangedEvent]);
+ if (eh != null)
+ eh (this, e);
+ }
+#endif
+
[EditorBrowsable(EditorBrowsableState.Advanced)]
protected virtual void OnBindingContextChanged(EventArgs e) {
CheckDataBindings ();
eh (this, e);
}
+#if NET_2_0
+ [EditorBrowsable (EditorBrowsableState.Advanced)]
+ protected virtual void OnClientSizeChanged (EventArgs e)
+ {
+ EventHandler eh = (EventHandler)(Events[ClientSizeChangedEvent]);
+ if (eh != null)
+ eh (this, e);
+ }
+#endif
+
[EditorBrowsable(EditorBrowsableState.Advanced)]
protected virtual void OnContextMenuChanged(EventArgs e) {
EventHandler eh = (EventHandler)(Events [ContextMenuChangedEvent]);
LayoutEventHandler eh = (LayoutEventHandler)(Events [LayoutEvent]);
if (eh != null)
eh (this, levent);
+
+ LayoutEngine.Layout (this, levent);
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
}
#if NET_2_0
+ protected virtual void OnMarginChanged (EventArgs e)
+ {
+ EventHandler eh = (EventHandler)(Events[MarginChangedEvent]);
+ if (eh != null)
+ eh (this, e);
+ }
+
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected virtual void OnMouseCaptureChanged (EventArgs e)
{
eh (this, e);
}
+#if NET_2_0
+ [EditorBrowsable (EditorBrowsableState.Advanced)]
+ protected virtual void OnRegionChanged (EventArgs e)
+ {
+ EventHandler eh = (EventHandler)(Events[RegionChangedEvent]);
+ if (eh != null)
+ eh (this, e);
+ }
+#endif
+
[EditorBrowsable(EditorBrowsableState.Advanced)]
protected virtual void OnResize(EventArgs e) {
PerformLayout(this, "Bounds");