+2005-12-18 Peter Dennis Bartok <pbartok@novell.com>
+
+ * Control.cs:
+ - Reworked Controls.Add(), Controls.Remove() and set_Parent() to
+ cause events to be sent in the same order as MS does.
+ - Added ChangeParent() method to trigger various OnXXXChanged events
+ that need to be fired when a parent changes (This is a reworking
+ of the patch from r54254, with the X11 errors fixed)
+ - Removed SuspendLayout()/ResumeLayout() calls from Controls.Clear()
+ since on MS we get OnLayoutChanged events when calling Clear()
+ - Changed Enabled property to consider parent state as well, if a
+ parent is not enabled, the control will not be either
+ - Changed Parent property to simply call Controls.Add() since that
+ now does all the work required, this way we avoid code duplication
+ - Threw in a few OnBindingsContextChanged calls to try and match
+ when MS sends them. We seem to send a few too many, though.
+ - Added call to CreateControl when adding the control to a parent.
+ We were never calling CreateControl. Still needs some work, in
+ some places we treat HandleCreated and ControlCreated as equal,
+ which is wrong
+ - Removed obsolete commented out code from UpdateZOrder()
+
2005-12-18 Alexander Olk <alex.olk@googlemail.com>
* ThemeClearlooks.cs: Updated TrackBar drawing.
internal string name; // for object naming
// State
- private bool create_handled; // true if OnCreateControl has been sent
+ internal bool is_created; // true if OnCreateControl has been sent
internal bool has_focus; // true if control has focus
internal bool is_visible; // true if control is visible
internal bool is_entered; // is the mouse inside the control?
if (value == null)
return;
- if (Contains (value))
+ if (Contains (value)) {
+ owner.PerformLayout();
return;
+ }
if (value.tab_index == -1) {
int end;
value.tab_index = use;
}
+ if (value.parent != null) {
+ value.parent.Controls.Remove(value);
+ }
+
all_controls = null;
list.Add (value);
- value.Parent = owner;
+
+ value.ChangeParent(owner);
+
+ value.InitLayout();
+
owner.UpdateZOrder();
+ owner.PerformLayout(value, "Parent");
owner.OnControlAdded(new ControlEventArgs(value));
}
impl_list = new ArrayList ();
all_controls = null;
impl_list.Add (control);
- control.Parent = owner;
+ control.ChangeParent (owner);
owner.UpdateZOrder ();
+ owner.PerformLayout (control, "Parent");
+ owner.OnControlAdded (new ControlEventArgs (control));
}
public virtual void AddRange (Control[] controls)
public virtual void Clear ()
{
- owner.SuspendLayout();
all_controls = null;
- for (int i = 0; i < list.Count; i++) {
- owner.OnControlRemoved(new ControlEventArgs((Control)list[i]));
+
+ // MS sends remove events in reverse order
+ while (list.Count > 0) {
+ RemoveAt(list.Count - 1);
}
- list.Clear();
- owner.ResumeLayout();
}
internal virtual void ClearImplicit ()
public virtual void Remove(Control value) {
all_controls = null;
+ owner.PerformLayout(value, "Parent");
owner.OnControlRemoved(new ControlEventArgs(value));
list.Remove(value);
- value.parent = null;
+
+ value.ChangeParent(null);
+
owner.UpdateZOrder();
}
{
if (impl_list != null) {
all_controls = null;
+ owner.PerformLayout (control, "Parent");
+ owner.OnControlRemoved (new ControlEventArgs (control));
impl_list.Remove (control);
}
- control.Parent = null;
+ control.ChangeParent (null);
owner.UpdateZOrder ();
}
anchor_style = AnchorStyles.Top | AnchorStyles.Left;
- create_handled = false;
+ is_created = false;
is_visible = true;
is_captured = false;
is_disposed = false;
binding.Check (binding_context);
}
}
+
+
+ private void ChangeParent(Control new_parent) {
+ bool pre_enabled;
+ bool pre_visible;
+ Font pre_font;
+ Color pre_fore_color;
+ Color pre_back_color;
+ RightToLeft pre_rtl;
+
+ // These properties are inherited from our parent
+ // Get them pre parent-change and then send events
+ // if they are changed after we have our new parent
+ pre_enabled = Enabled;
+ pre_visible = Visible;
+ pre_font = Font;
+ pre_fore_color = ForeColor;
+ pre_back_color = BackColor;
+ pre_rtl = RightToLeft;
+ // MS doesn't seem to send a CursorChangedEvent
+
+ parent = new_parent;
+
+ if (IsHandleCreated && (new_parent != null) && new_parent.IsHandleCreated) {
+ XplatUI.SetParent(Handle, new_parent.Handle);
+ }
+
+ OnParentChanged(EventArgs.Empty);
+
+ if (pre_enabled != Enabled) {
+ OnEnabledChanged(EventArgs.Empty);
+ }
+
+ if (pre_visible != Visible) {
+ OnVisibleChanged(EventArgs.Empty);
+ }
+
+ if (pre_font != Font) {
+ OnFontChanged(EventArgs.Empty);
+ }
+
+ if (pre_fore_color != ForeColor) {
+ OnForeColorChanged(EventArgs.Empty);
+ }
+
+ if (pre_back_color != BackColor) {
+ OnBackColorChanged(EventArgs.Empty);
+ }
+
+ if (pre_rtl != RightToLeft) {
+ // MS sneaks a OnCreateControl and OnHandleCreated in here, I guess
+ // because when RTL changes they have to recreate the win32 control
+ // We don't really need that (until someone runs into compatibility issues)
+ OnRightToLeftChanged(EventArgs.Empty);
+ }
+
+ if ((new_parent != null) && new_parent.Created && !Created) {
+ CreateControl();
+ }
+
+ if (binding_context == null) { // seem to be sent whenever it's null?
+ OnBindingContextChanged(EventArgs.Empty);
+ }
+ }
#endregion // Private & Internal Methods
#region Public Static Properties
cursor = value;
pt = Cursor.Position;
- Console.WriteLine ("{0} {1} {2}", bounds, pt, bounds.Contains (pt));
+ //Console.WriteLine ("{0} {1} {2}", bounds, pt, bounds.Contains (pt));
if (bounds.Contains(pt)) {
if (GetChildAtPoint(pt) == null) {
if (cursor != null) {
[Localizable(true)]
public bool Enabled {
get {
- return is_enabled;
+ if (!is_enabled) {
+ return false;
+ }
+
+ if (parent != null) {
+ return parent.Enabled;
+ }
+
+ return true;
}
set {
return;
}
- parent=value;
-
- if (!parent.Controls.AllContains (this)) {
- Console.WriteLine ("Adding child: " + this);
- parent.Controls.Add(this);
- }
-
- if (IsHandleCreated) {
- XplatUI.SetParent(Handle, value.Handle);
- }
-
- OnParentChanged(EventArgs.Empty);
- InitLayout();
+ value.Controls.Add(this);
}
}
}
CreateHandle();
}
- if (!create_handled) {
- create_handled = true;
- OnCreateControl();
+ if (!is_created) {
+ is_created = true;
}
Control [] controls = child_controls.GetAllControls ();
for (int i=0; i<controls.Length; i++) {
controls [i].CreateControl ();
}
+
+ if (binding_context == null) { // seem to be sent whenever it's null?
+ OnBindingContextChanged(EventArgs.Empty);
+ }
+
+ OnCreateControl();
}
public Graphics CreateGraphics() {
[EditorBrowsable(EditorBrowsableState.Advanced)]
protected void UpdateZOrder() {
Control [] controls;
-#if not
- Control ctl;
-
- if (parent == null) {
- return;
- }
-
- ctl = parent;
-
- controls = ctl.child_controls.GetAllControls ();
- for (int i = 1; i < controls.Length; i++ ) {
- XplatUI.SetZOrder(controls[i].window.Handle, controls[i-1].window.Handle, false, false);
- }
-#else
if (!IsHandleCreated) {
return;
}
for (int i = 1; i < controls.Length; i++ ) {
XplatUI.SetZOrder(controls[i].Handle, controls[i-1].Handle, false, false);
}
-#endif
}
protected virtual void WndProc(ref Message m) {