Rectangle explicit_bounds; // explicitly set bounds
internal object creator_thread; // thread that created the control
internal ControlNativeWindow window; // object for native window handle
+ private IWindowTarget window_target;
string name; // for object naming
// State
BindingContext binding_context;
RightToLeft right_to_left; // drawing direction for control
ContextMenu context_menu; // Context menu associated with the control
+ internal bool use_compatible_text_rendering;
// double buffering
DoubleBuffer backbuffer;
ControlBindingsCollection data_bindings;
#if NET_2_0
- internal bool use_compatible_text_rendering;
static bool verify_thread_handle;
Padding padding;
ImageLayout backgroundimage_layout;
}
}
+ protected override void OnHandleChange()
+ {
+ this.owner.WindowTarget.OnHandleChange(this.owner.Handle);
+ }
+
static internal Control ControlFromHandle(IntPtr hWnd) {
ControlNativeWindow window;
}
protected override void WndProc(ref Message m) {
- owner.WndProc(ref m);
+ owner.WindowTarget.OnMessage(ref m);
+ }
+ }
+
+ private class ControlWindowTarget : IWindowTarget
+ {
+ private Control control;
+
+ public ControlWindowTarget(Control control)
+ {
+ this.control = control;
+ }
+
+ public void OnHandleChange(IntPtr newHandle)
+ {
+ }
+
+ public void OnMessage(ref Message m)
+ {
+ control.WndProc(ref m);
}
}
#endregion
#region Public Classes
[ComVisible(true)]
public class ControlAccessibleObject : AccessibleObject {
- Control owner;
+ IntPtr handle;
#region ControlAccessibleObject Constructors
public ControlAccessibleObject(Control ownerControl)
: base (ownerControl)
{
- this.owner = ownerControl;
+ if (ownerControl == null)
+ throw new ArgumentNullException ("owner");
+
+ handle = ownerControl.Handle;
}
#endregion // ControlAccessibleObject Constructors
public IntPtr Handle {
get {
- return owner.Handle;
+ return handle;
}
set {
public Control Owner {
get {
- return owner;
+ return base.owner;
}
}
return base.GetHelpTopic (out FileName);
}
- [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
+ [MonoTODO ("Implement this")]
public void NotifyClients(AccessibleEvents accEvent) {
throw new NotImplementedException();
}
- [MonoTODO("Implement this and tie it into Control.AccessibilityNotifyClients")]
+ [MonoTODO ("Implement this")]
public void NotifyClients(AccessibleEvents accEvent, int childID) {
- throw new NotImplementedException();
}
public override string ToString() {
private Control parent;
private bool pending_disposal;
- public DoubleBuffer (Control parent)
- {
+ public DoubleBuffer (Control parent) {
this.parent = parent;
real_graphics = new Stack ();
int width = parent.Width;
Invalidate ();
}
- public void Blit (PaintEventArgs pe)
- {
+ public void Blit (PaintEventArgs pe) {
Graphics buffered_graphics;
buffered_graphics = XplatUI.GetOffscreenGraphics (back_buffer);
XplatUI.BlitFromOffscreen (parent.Handle, pe.Graphics, back_buffer, buffered_graphics, pe.ClipRectangle);
buffered_graphics.Dispose ();
}
- public void Start (PaintEventArgs pe)
- {
+ public void Start (PaintEventArgs pe) {
// We need to get the graphics for every paint.
real_graphics.Push(pe.SetGraphics (XplatUI.GetOffscreenGraphics (back_buffer)));
}
- public void End (PaintEventArgs pe)
- {
+ public void End (PaintEventArgs pe) {
Graphics buffered_graphics;
buffered_graphics = pe.SetGraphics ((Graphics) real_graphics.Pop ());
buffered_graphics.Dispose ();
}
- public void Invalidate ()
- {
+ public void Invalidate () {
if (InvalidRegion != null)
InvalidRegion.Dispose ();
InvalidRegion = new Region (parent.ClientRectangle);
}
- public void Dispose ()
- {
+ public void Dispose () {
if (real_graphics.Count > 0) {
pending_disposal = true;
return;
}
#region IDisposable Members
- void IDisposable.Dispose ()
- {
+ void IDisposable.Dispose () {
Dispose ();
}
#endregion
- ~DoubleBuffer ()
- {
+ ~DoubleBuffer () {
Dispose ();
}
}
#endregion // ControlCollection Public Instance Properties
#region ControlCollection Instance Methods
- public virtual void Add (Control value)
- {
+ public virtual void Add (Control value) {
if (value == null)
return;
- bool owner_permits_toplevels = (owner is MdiClient) || (owner is Form && ((Form)owner).IsMdiContainer);
- bool child_is_toplevel = ((Control)value).GetTopLevel();
- bool child_is_mdichild = (value is Form && ((Form)value).IsMdiChild);
+ Form form_value = value as Form;
+ Form form_owner = owner as Form;
+ bool owner_permits_toplevels = (owner is MdiClient) || (form_owner != null && form_owner.IsMdiContainer);
+ bool child_is_toplevel = value.GetTopLevel();
+ bool child_is_mdichild = form_value != null && form_value.IsMdiChild;
if (child_is_toplevel && !(owner_permits_toplevels && child_is_mdichild))
throw new ArgumentException("Cannot add a top level control to a control.", "value");
+ if (child_is_mdichild && form_value.MdiParent != null && form_value.MdiParent != owner && form_value.MdiParent != owner.Parent) {
+ throw new ArgumentException ("Form cannot be added to the Controls collection that has a valid MDI parent.", "value");
+ }
+
if (Contains (value)) {
owner.PerformLayout();
return;
value.InitLayout();
- owner.UpdateChildrenZOrder();
+ if (owner.Visible)
+ owner.UpdateChildrenZOrder();
owner.PerformLayout(value, "Parent");
owner.OnControlAdded(new ControlEventArgs(value));
}
- internal void AddToList (Control c)
- {
+ internal void AddToList (Control c) {
all_controls = null;
list.Add (c);
}
- internal virtual void AddImplicit (Control control)
- {
+ internal virtual void AddImplicit (Control control) {
if (impl_list == null)
impl_list = new ArrayList ();
- if (AllContains (control))
+ if (AllContains (control)) {
+ owner.PerformLayout ();
return;
+ }
+
+ if (control.parent != null) {
+ control.parent.Controls.Remove(control);
+ }
all_controls = null;
impl_list.Add (control);
control.ChangeParent (owner);
control.InitLayout ();
- owner.UpdateChildrenZOrder ();
- owner.PerformLayout (control, "Parent");
- owner.OnControlAdded (new ControlEventArgs (control));
+ if (owner.Visible)
+ owner.UpdateChildrenZOrder ();
+
+ // If we are adding a new control that isn't
+ // visible, don't trigger a layout
+ if (control.VisibleInternal)
+ owner.PerformLayout (control, "Parent");
}
#if NET_2_0
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
#endif
- public virtual void AddRange (Control[] controls)
- {
+ public virtual void AddRange (Control[] controls) {
if (controls == null)
throw new ArgumentNullException ("controls");
}
}
- internal virtual void AddRangeImplicit (Control [] controls)
- {
+ internal virtual void AddRangeImplicit (Control [] controls) {
if (controls == null)
throw new ArgumentNullException ("controls");
#if NET_2_0
new
#endif
- public virtual void Clear ()
- {
+ public virtual void Clear () {
all_controls = null;
// MS sends remove events in reverse order
}
}
- internal virtual void ClearImplicit ()
- {
+ internal virtual void ClearImplicit () {
if (impl_list == null)
return;
all_controls = null;
impl_list.Clear ();
}
- public bool Contains (Control value)
- {
+ public bool Contains (Control value) {
for (int i = list.Count; i > 0; ) {
i--;
return false;
}
- internal bool ImplicitContains (Control value)
- {
+ internal bool ImplicitContains (Control value) {
if (impl_list == null)
return false;
return false;
}
- internal bool AllContains (Control value)
- {
+ internal bool AllContains (Control value) {
return Contains (value) || ImplicitContains (value);
}
}
#endif
- void ICollection.CopyTo (Array array, int index)
- {
+ void ICollection.CopyTo (Array array, int index) {
CopyTo (array, index);
}
#if !NET_2_0
- public void CopyTo (Array array, int index)
- {
+ public void CopyTo (Array array, int index) {
list.CopyTo(array, index);
}
- public override bool Equals (object other)
- {
+ public override bool Equals (object other) {
if (other is ControlCollection && (((ControlCollection)other).owner==this.owner)) {
return(true);
} else {
#else
public IEnumerator
#endif
- GetEnumerator ()
- {
+ GetEnumerator () {
return list.GetEnumerator();
}
- internal IEnumerator GetAllEnumerator ()
- {
+ internal IEnumerator GetAllEnumerator () {
Control [] res = GetAllControls ();
return res.GetEnumerator ();
}
- internal Control [] GetAllControls ()
- {
+ internal Control [] GetAllControls () {
if (all_controls != null)
return all_controls;
}
#if !NET_2_0
- public override int GetHashCode()
- {
+ public override int GetHashCode() {
return base.GetHashCode();
}
#endif
- public int IndexOf(Control control)
- {
+ public int IndexOf(Control control) {
return list.IndexOf(control);
}
}
#endif
- public virtual void Remove(Control value)
- {
+ public virtual void Remove(Control value) {
if (value == null)
return;
owner.UpdateChildrenZOrder();
}
- internal virtual void RemoveImplicit (Control control)
- {
+ internal virtual void RemoveImplicit (Control control) {
if (impl_list != null) {
all_controls = null;
owner.PerformLayout (control, "Parent");
#if NET_2_0
new
#endif
- public void RemoveAt(int index)
- {
+ public void RemoveAt(int index) {
if (index < 0 || index >= list.Count) {
throw new ArgumentOutOfRangeException("index", index, "ControlCollection does not have that many controls");
}
if (index >= 0)
RemoveAt (index);
}
-
+#endif
+
+#if NET_2_0
public virtual void
#else
public void
#endif
- SetChildIndex(Control child, int newIndex)
- {
+ SetChildIndex(Control child, int newIndex) {
if (child == null)
throw new ArgumentNullException ("child");
#endregion // ControlCollection Class
#region Public Constructors
- public Control()
+ public Control ()
{
layout_type = LayoutType.Anchor;
anchor_style = AnchorStyles.Top | AnchorStyles.Left;
dist_bottom = 0;
tab_stop = true;
ime_mode = ImeMode.Inherit;
+ use_compatible_text_rendering = true;
#if NET_2_0
backgroundimage_layout = ImageLayout.Tile;
text = string.Empty;
name = string.Empty;
+ window_target = new ControlWindowTarget(this);
window = new ControlNativeWindow(this);
child_controls = CreateControlsInstance();
client_size = new Size(DefaultSize.Width, DefaultSize.Height);
client_rect = new Rectangle(0, 0, DefaultSize.Width, DefaultSize.Height);
- bounds.Size = SizeFromClientSize (client_size);
+ bounds.Size = InternalSizeFromClientSize (client_size);
explicit_bounds = bounds;
}
- public Control(Control parent, string text) : this() {
+ public Control (Control parent, string text) : this()
+ {
Text=text;
Parent=parent;
}
- public Control(Control parent, string text, int left, int top, int width, int height) : this() {
+ public Control (Control parent, string text, int left, int top, int width, int height) : this()
+ {
Parent=parent;
bounds.X=left;
bounds.Y=top;
Text=text;
}
- public Control(string text) : this() {
+ public Control (string text) : this()
+ {
Text=text;
}
- public Control(string text, int left, int top, int width, int height) : this() {
+ public Control (string text, int left, int top, int width, int height) : this()
+ {
bounds.X=left;
bounds.Y=top;
bounds.Width=width;
private delegate void RemoveDelegate(object c);
- protected override void Dispose(bool disposing) {
+ protected override void Dispose (bool disposing)
+ {
if (!is_disposed && disposing) {
Capture = false;
}
if (this.InvokeRequired) {
- if (Application.MessageLoop) {
- this.BeginInvokeInternal(new MethodInvoker(DestroyHandle), null, true);
+ if (Application.MessageLoop && IsHandleCreated) {
+ this.BeginInvokeInternal(new MethodInvoker(DestroyHandle), null);
}
} else {
DestroyHandle();
#endregion // Public Constructors
#region Internal Properties
+ // Control is currently selected, like Focused, except maintains state
+ // when Form loses focus
+ internal bool InternalSelected {
+ get {
+ IContainerControl container;
+
+ container = GetContainerControl();
+
+ if (container != null && container.ActiveControl == this)
+ return true;
+
+ return false;
+ }
+ }
+
+ // Mouse is currently within the control's bounds
+ internal bool Entered {
+ get { return this.is_entered; }
+ }
+
internal bool VisibleInternal {
get { return is_visible; }
}
}
}
}
+
+ internal Size InternalClientSize { set { this.client_size = value; } }
+ internal virtual bool ActivateOnShow { get { return true; } }
#endregion // Internal Properties
#region Private & Internal Methods
}
#endif
- internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args, bool disposing) {
+ internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args) {
+ return BeginInvokeInternal (method, args, FindControlToInvokeOn ());
+ }
+
+ internal IAsyncResult BeginInvokeInternal (Delegate method, object [] args, Control control) {
AsyncMethodResult result;
AsyncMethodData data;
- if (!disposing) {
- Control p = this;
- do {
- if (!p.IsHandleCreated) {
- throw new InvalidOperationException("Cannot call Invoke or InvokeAsync on a control until the window handle is created");
- }
- p = p.parent;
- } while (p != null);
- }
-
result = new AsyncMethodResult ();
data = new AsyncMethodData ();
- data.Handle = window.Handle;
+ data.Handle = control.Handle;
data.Method = method;
data.Args = args;
data.Result = result;
}
- internal void PointToClient (ref int x, ref int y)
- {
+ internal void PointToClient (ref int x, ref int y) {
XplatUI.ScreenToClient (Handle, ref x, ref y);
}
- internal void PointToScreen (ref int x, ref int y)
- {
+ internal void PointToScreen (ref int x, ref int y) {
XplatUI.ClientToScreen (Handle, ref x, ref y);
}
return bmp_g;
}
}
-
- private void InvalidateBackBuffer ()
+
+ private Control FindControlToInvokeOn ()
{
+ Control p = this;
+ do {
+ if (p.IsHandleCreated)
+ break;
+ p = p.parent;
+ } while (p != null);
+
+ if (p == null || !p.IsHandleCreated)
+ throw new InvalidOperationException ("Cannot call Invoke or BeginInvoke on a control until the window handle is created");
+
+ return p;
+ }
+
+ private void InvalidateBackBuffer () {
if (backbuffer != null)
backbuffer.Invalidate ();
}
- private DoubleBuffer GetBackBuffer ()
- {
+ private DoubleBuffer GetBackBuffer () {
if (backbuffer == null)
backbuffer = new DoubleBuffer (this);
return backbuffer;
}
- private void DisposeBackBuffer ()
- {
+ private void DisposeBackBuffer () {
if (backbuffer != null) {
backbuffer.Dispose ();
backbuffer = null;
}
// This method exists so controls overriding OnPaintBackground can have default background painting done
- internal virtual void PaintControlBackground (PaintEventArgs pevent)
- {
+ internal virtual void PaintControlBackground (PaintEventArgs pevent) {
if (GetStyle(ControlStyles.SupportsTransparentBackColor) && (BackColor.A != 0xff)) {
if (parent != null) {
PaintEventArgs parent_pe;
DrawBackgroundImage (pevent.Graphics);
}
- void DrawBackgroundImage (Graphics g)
- {
+ void DrawBackgroundImage (Graphics g) {
#if NET_2_0
Rectangle drawing_rectangle = new Rectangle ();
g.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (BackColor), ClientRectangle);
#endif
}
- internal virtual void DndEnter (DragEventArgs e)
- {
+ internal virtual void DndEnter (DragEventArgs e) {
try {
OnDragEnter (e);
} catch { }
}
- internal virtual void DndOver (DragEventArgs e)
- {
+ internal virtual void DndOver (DragEventArgs e) {
try {
OnDragOver (e);
} catch { }
}
- internal virtual void DndDrop (DragEventArgs e)
- {
+ internal virtual void DndDrop (DragEventArgs e) {
try {
OnDragDrop (e);
} catch (Exception exc) {
}
}
- internal virtual void DndLeave (EventArgs e)
- {
+ internal virtual void DndLeave (EventArgs e) {
try {
OnDragLeave (e);
} catch { }
}
- internal virtual void DndFeedback(GiveFeedbackEventArgs e)
- {
+ internal virtual void DndFeedback(GiveFeedbackEventArgs e) {
try {
OnGiveFeedback(e);
} catch { }
}
- internal virtual void DndContinueDrag(QueryContinueDragEventArgs e)
- {
+ internal virtual void DndContinueDrag(QueryContinueDragEventArgs e) {
try {
OnQueryContinueDrag(e);
} catch { }
}
- internal virtual void FireEnter ()
- {
+ internal virtual void FireEnter () {
OnEnter (EventArgs.Empty);
}
- internal virtual void FireLeave ()
- {
+ internal virtual void FireLeave () {
OnLeave (EventArgs.Empty);
}
- internal virtual void FireValidating (CancelEventArgs ce)
- {
+ internal virtual void FireValidating (CancelEventArgs ce) {
OnValidating (ce);
}
- internal virtual void FireValidated ()
- {
+ internal virtual void FireValidated () {
OnValidated (EventArgs.Empty);
}
OnClick(EventArgs.Empty);
#else
OnDoubleClick(me);
+ OnMouseDoubleClick (me);
} else {
OnClick(me);
OnMouseClick (me);
}
}
- internal void CaptureWithConfine (Control ConfineWindow)
- {
+ internal void CaptureWithConfine (Control ConfineWindow) {
if (this.IsHandleCreated && !is_captured) {
is_captured = true;
XplatUI.GrabWindow (this.window.Handle, ConfineWindow.Handle);
}
}
- private void CheckDataBindings ()
- {
+ private void CheckDataBindings () {
if (data_bindings == null)
return;
parent = new_parent;
- if (IsHandleCreated)
+ if (IsHandleCreated) {
XplatUI.SetParent(Handle,
(new_parent == null || !new_parent.IsHandleCreated) ? IntPtr.Zero : new_parent.Handle);
+ if (this is Form ) {
+ ((Form) this).ChangingParent (new_parent);
+ }
+ }
OnParentChanged(EventArgs.Empty);
}
}
+ // Sometimes we need to do this calculation without it being virtual (constructor)
+ internal Size InternalSizeFromClientSize (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;
+ }
+
private void UpdateDistances() {
if (parent != null) {
- if (bounds.Width > 0)
+ if (bounds.Width >= 0)
dist_right = parent.ClientSize.Width - bounds.X - bounds.Width;
- if (bounds.Height > 0)
+ if (bounds.Height >= 0)
dist_bottom = parent.ClientSize.Height - bounds.Y - bounds.Height;
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public string AccessibleDefaultActionDescription {
get {
- return AccessibilityObject.default_action;
+ if (accessibility_object != null)
+ return accessibility_object.default_action;
+ else
+ return null;
}
set {
- AccessibilityObject.default_action=value;
+ if (accessibility_object != null)
+ accessibility_object.default_action = value;
}
}
[MWFCategory("Accessibility")]
public string AccessibleDescription {
get {
- return AccessibilityObject.description;
+ if (accessibility_object != null)
+ return accessibility_object.description;
+ else
+ return null;
}
set {
- AccessibilityObject.description=value;
+ if (accessibility_object != null)
+ accessibility_object.description = value;
}
}
[MWFCategory("Accessibility")]
public string AccessibleName {
get {
- return AccessibilityObject.Name;
+ if (accessibility_object != null)
+ return accessibility_object.Name;
+ else
+ return null;
}
set {
- AccessibilityObject.Name=value;
+ if (accessibility_object != null)
+ accessibility_object.Name = value;
}
}
[MWFDescription("Role of the control"), MWFCategory("Accessibility")]
public AccessibleRole AccessibleRole {
get {
- return AccessibilityObject.role;
+ if (accessibility_object != null)
+ return accessibility_object.role;
+ else
+ return AccessibleRole.Default;
}
set {
- AccessibilityObject.role=value;
+ if (accessibility_object != null)
+ accessibility_object.role = value;
}
}
if (value != is_captured) {
if (value) {
is_captured = true;
- XplatUI.GrabWindow(this.Handle, IntPtr.Zero);
+ XplatUI.GrabWindow(Handle, IntPtr.Zero);
} else {
- XplatUI.UngrabWindow(this.Handle);
+ if (IsHandleCreated)
+ XplatUI.UngrabWindow(Handle);
is_captured = false;
}
}
}
}
- internal virtual ContextMenu GetContextMenuInternal ()
- {
+ internal virtual ContextMenu GetContextMenuInternal () {
return context_menu;
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool IsHandleCreated {
get {
- if ((window != null) && (window.Handle != IntPtr.Zero)) {
- Hwnd hwnd = Hwnd.ObjectFromHandle (window.Handle);
- if (hwnd != null && !hwnd.zombie)
- return true;
- }
+ if (window == null || window.Handle == IntPtr.Zero)
+ return false;
- return false;
+ Hwnd hwnd = Hwnd.ObjectFromHandle (window.Handle);
+ if (hwnd != null && hwnd.zombie)
+ return false;
+
+ return true;
}
}
// set.
if (attrs != null && attrs.Length > 0)
a = (AssemblyProductAttribute) attrs [0];
+ if (a == null) {
+ return GetType ().Namespace;
+ }
return a.Product;
}
}
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public IWindowTarget WindowTarget {
- get {
- return null;
- }
-
- set {
- ; // MS Internal
- }
+ get { return window_target; }
+ set { window_target = value; }
}
#endregion // Public Instance Properties
create_params.ClassName = XplatUI.DefaultClassName;
- create_params.ClassStyle = 0;
+ create_params.ClassStyle = (int)(XplatUIWin32.ClassStyle.CS_OWNDC | XplatUIWin32.ClassStyle.CS_DBLCLKS);
create_params.ExStyle = 0;
create_params.Param = 0;
}
switch (border_style) {
- case BorderStyle.FixedSingle:
- create_params.Style |= (int) WindowStyles.WS_BORDER;
- break;
- case BorderStyle.Fixed3D:
- create_params.ExStyle |= (int) WindowExStyles.WS_EX_CLIENTEDGE;
- break;
+ case BorderStyle.FixedSingle:
+ create_params.Style |= (int) WindowStyles.WS_BORDER;
+ break;
+ case BorderStyle.Fixed3D:
+ create_params.ExStyle |= (int) WindowExStyles.WS_EX_CLIENTEDGE;
+ break;
}
return create_params;
object [] prms = null;
if (method is EventHandler)
prms = new object [] { this, EventArgs.Empty };
- return BeginInvokeInternal(method, prms, false);
+ return BeginInvokeInternal(method, prms);
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
- public IAsyncResult BeginInvoke (Delegate method, object[] args) {
- return BeginInvokeInternal (method, args, false);
+#if NET_2_0
+ public IAsyncResult BeginInvoke (Delegate method, params object[] args)
+#else
+ public IAsyncResult BeginInvoke (Delegate method, object[] args)
+#endif
+ {
+ return BeginInvokeInternal (method, args);
}
public void BringToFront() {
if (parent != null) {
parent.child_controls.SetChildIndex(this, 0);
- parent.Refresh();
- } else {
+ }
+ else if (IsHandleCreated) {
XplatUI.SetZOrder(Handle, IntPtr.Zero, false, false);
}
}
return false;
}
- public void CreateControl ()
- {
+ public void CreateControl () {
if (is_disposed) {
throw new ObjectDisposedException(GetType().FullName.ToString());
}
return;
}
+ if (!is_visible) {
+ return;
+ }
+
if (!IsHandleCreated) {
CreateHandle();
}
if (!is_created) {
is_created = true;
- }
-
- Control [] controls = child_controls.GetAllControls ();
- for (int i=0; i<controls.Length; i++) {
- if (controls [i].is_visible)
- controls [i].CreateControl ();
- }
- UpdateChildrenZOrder();
+ if (binding_context == null) { // seem to be sent whenever it's null?
+ OnBindingContextChanged(EventArgs.Empty);
+ }
- if (binding_context == null) { // seem to be sent whenever it's null?
- OnBindingContextChanged(EventArgs.Empty);
+ OnCreateControl();
}
-
- OnCreateControl();
}
public Graphics CreateGraphics() {
}
public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects) {
- return XplatUI.StartDrag(this.window.Handle, data, allowedEffects);
+ if (IsHandleCreated)
+ return XplatUI.StartDrag(Handle, data, allowedEffects);
+ else
+ return DragDropEffects.None;
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
[EditorBrowsable (EditorBrowsableState.Advanced)]
#endif
public bool Focus() {
- if (CanFocus && IsHandleCreated && !has_focus && !is_focusing) {
+ return FocusInternal (false);
+ }
+
+ internal virtual bool FocusInternal (bool skip_check) {
+ if (skip_check || (CanFocus && IsHandleCreated && !has_focus && !is_focusing)) {
is_focusing = true;
Select(this);
is_focusing = false;
return has_focus;
}
- internal void FocusInternal ()
- {
- is_focusing = true;
- Select(this);
- is_focusing = false;
- }
-
public Control GetChildAtPoint(Point pt) {
+ // MS's version causes the handle to be created. The stack trace shows that get_Handle is called here, but
+ // we'll just call CreateHandle instead.
+ CreateHandle ();
+
// Microsoft's version of this function doesn't seem to work, so I can't check
// if we only consider children or also grandchildren, etc.
// I'm gonna say 'children only'
return Invoke(method, prms);
}
-
+#if NET_2_0
+ public object Invoke (Delegate method, params object [] args) {
+#else
public object Invoke (Delegate method, object[] args) {
+#endif
+ Control control = FindControlToInvokeOn ();
+
if (!this.InvokeRequired) {
return method.DynamicInvoke(args);
}
- IAsyncResult result = BeginInvoke (method, args);
- return EndInvoke(result);
- }
-
- internal object InvokeInternal (Delegate method, bool disposing) {
- return InvokeInternal(method, null, disposing);
- }
-
- internal object InvokeInternal (Delegate method, object[] args, bool disposing) {
- if (!this.InvokeRequired) {
- return method.DynamicInvoke(args);
- }
-
- IAsyncResult result = BeginInvokeInternal (method, args, disposing);
+ IAsyncResult result = BeginInvokeInternal (method, args, control);
return EndInvoke(result);
}
PerformLayout(null, null);
}
- internal void SetImplicitBounds (int x, int y, int width, int height)
- {
+ internal void SetImplicitBounds (int x, int y, int width, int height) {
Rectangle saved_bounds = explicit_bounds;
SetBounds (x, y, width, height);
explicit_bounds = saved_bounds;
}
public virtual void Refresh() {
- if (IsHandleCreated) {
+ if (IsHandleCreated && Visible) {
Invalidate();
XplatUI.UpdateWindow(window.Handle);
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetBindings() {
- data_bindings.Clear();
+ if (data_bindings != null)
+ data_bindings.Clear();
}
[EditorBrowsable(EditorBrowsableState.Never)]
#if DebugFocus
private void printTree(Control c, string t) {
foreach(Control i in c.child_controls) {
- Console.WriteLine("{2}{0}.TabIndex={1}", i, i.tab_index, t);
- printTree(i, t+"\t");
+ Console.WriteLine ("{2}{0}.TabIndex={1}", i, i.tab_index, t);
+ printTree (i, t+"\t");
}
}
#endif
}
SetBoundsCore(x, y, width, height, specified);
- if (parent != null) {
+ if (parent != null)
parent.PerformLayout(this, "Bounds");
- }
}
- public void Show ()
- {
- if (!is_created) {
- this.CreateControl();
- }
-
- this.Visible=true;
+ public void Show () {
+ this.Visible = true;
}
public void SuspendLayout() {
#region Protected Instance Methods
[EditorBrowsable(EditorBrowsableState.Advanced)]
- [MonoTODO("Implement this and tie it into Control.ControlAccessibleObject.NotifyClients")]
protected void AccessibilityNotifyClients(AccessibleEvents accEvent, int childID) {
- throw new NotImplementedException();
+ // turns out this method causes handle
+ // creation in 1.1. at first I thought this
+ // would be accomplished just by using
+ // get_AccessibilityObject, which would route
+ // through CreateAccessibilityInstance, which
+ // calls CreateControl. This isn't the case,
+ // though (as overriding
+ // CreateAccessibilityInstance and adding a
+ // CWL shows nothing. So we fudge it and put
+ // a CreateHandle here.
+
+#if ONLY_1_1
+ CreateHandle ();
+#endif
+
+ if (accessibility_object != null && accessibility_object is ControlAccessibleObject)
+ ((ControlAccessibleObject)accessibility_object).NotifyClients (accEvent, childID);
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
protected virtual AccessibleObject CreateAccessibilityInstance() {
+ CreateControl ();
return new Control.ControlAccessibleObject(this);
}
return;
}
- window.CreateHandle(CreateParams);
+ CreateParams create_params = CreateParams;
+ window.CreateHandle(create_params);
if (window.Handle != IntPtr.Zero) {
creator_thread = Thread.CurrentThread;
XplatUI.EnableWindow(window.Handle, is_enabled);
- XplatUI.SetVisible(window.Handle, is_visible, true);
if (clip_region != null) {
- XplatUI.SetClipRegion(Handle, clip_region);
+ XplatUI.SetClipRegion(window.Handle, clip_region);
}
// Set our handle with our parent
XplatUI.SetParent(window.Handle, parent.Handle);
}
- // Set our handle as parent for our children
- Control [] children;
-
- children = child_controls.GetAllControls ();
- for (int i = 0; i < children.Length; i++ ) {
- if (!children[i].RecreatingHandle)
- XplatUI.SetParent(children[i].Handle, window.Handle);
- }
-
UpdateStyles();
- XplatUI.SetAllowDrop (Handle, allow_drop);
+ XplatUI.SetAllowDrop (window.Handle, allow_drop);
// Find out where the window manager placed us
if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) != 0) {
XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
}
UpdateBounds();
-
- OnHandleCreated(EventArgs.Empty);
}
}
#if NET_2_0
protected virtual AccessibleObject GetAccessibilityObjectById (int objectId)
{
- throw new NotImplementedException ();
+ // XXX need to implement this.
+ return null;
}
#endif
}
protected virtual bool IsInputChar (char charCode) {
+ // XXX on MS.NET this method causes the handle to be created..
+ CreateHandle ();
+
return true;
}
return false;
}
- protected virtual bool ProcessKeyEventArgs (ref Message msg)
- {
+ protected virtual bool ProcessKeyEventArgs (ref Message msg) {
KeyEventArgs key_event;
switch (msg.Msg) {
// MS Internal
}
- private void SetIsRecreating ()
- {
+ private void SetIsRecreating () {
is_recreating=true;
foreach (Control c in Controls.GetAllControls()) {
[EditorBrowsable(EditorBrowsableState.Advanced)]
protected void RecreateHandle() {
+ if (!IsHandleCreated)
+ return;
+
#if DebugRecreate
Console.WriteLine("Recreating control {0}", XplatUI.Window(window.Handle));
#endif
container = GetContainerControl();
if (container != null && (Control)container != this)
- container.ActiveControl = this;
+ container.ActiveControl = this;
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
protected virtual void SetClientSizeCore(int x, int y) {
- Size NewSize = SizeFromClientSize (new Size (x, y));
+ Size NewSize = InternalSizeFromClientSize (new Size (x, y));
if (NewSize != Size.Empty)
SetBounds (bounds.X, bounds.Y, NewSize.Width, NewSize.Height, BoundsSpecified.Size);
}
if (this is Form) {
- if (value == true) {
- if (!Visible) {
- Visible = true;
- }
- } else {
- if (Visible) {
- Visible = false;
- }
+ if (IsHandleCreated && value != Visible) {
+ Visible = value;
}
+ } else {
+ // XXX MS.NET causes handle to be created here
+ CreateHandle ();
}
is_toplevel = value;
}
protected virtual void SetVisibleCore(bool value) {
- if (value!=is_visible) {
- is_visible=value;
+ if (value != is_visible) {
+ is_visible = value;
- if (value && ((window.Handle == IntPtr.Zero) || !is_created)) {
+ if (is_visible && ((window.Handle == IntPtr.Zero) || !is_created)) {
CreateControl();
}
if (IsHandleCreated) {
- XplatUI.SetVisible(Handle, value, true);
+ XplatUI.SetVisible(Handle, is_visible, true);
// Explicitly move Toplevel windows to where we want them;
// apparently moving unmapped toplevel windows doesn't work
if (is_visible && (this is Form)) {
XplatUI.SetWindowPos(window.Handle, bounds.X, bounds.Y, bounds.Width, bounds.Height);
}
}
-
- OnVisibleChanged(EventArgs.Empty);
-
- if (value == false && parent != null && Focused) {
- Control container;
-
- // Need to start at parent, GetContainerControl might return ourselves if we're a container
- container = (Control)parent.GetContainerControl();
- if (container != null) {
- container.SelectNextControl(this, true, true, true, true);
- }
- }
-
- if (parent != null) {
- parent.PerformLayout(this, "visible");
- } else {
- if (is_visible)
- PerformLayout(this, "visible");
+ else {
+ OnVisibleChanged(EventArgs.Empty);
}
}
}
#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;
+ virtual Size SizeFromClientSize (Size clientSize) {
+ return InternalSizeFromClientSize (clientSize);
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
protected void UpdateBounds() {
+ if (!IsHandleCreated)
+ return;
+
int x;
int y;
int width;
int client_width;
int client_height;
- if (!IsHandleCreated) {
- CreateHandle();
- }
-
XplatUI.GetWindowPos(this.Handle, this is Form, out x, out y, out width, out height, out client_width, out client_height);
UpdateBounds(x, y, width, height, client_width, client_height);
if (moved) {
OnLocationChanged(EventArgs.Empty);
- if (!background_color.IsEmpty && background_color.A < byte.MaxValue)
+ if (!background_color.IsEmpty && background_color.A < byte.MaxValue)
Invalidate ();
}
// Override this if there is a control that shall always remain on
// top of other controls (such as scrollbars). If there are several
// of these controls, the bottom-most should be returned.
- internal virtual IntPtr AfterTopMostControl ()
- {
+ internal virtual IntPtr AfterTopMostControl () {
return IntPtr.Zero;
}
- private void UpdateChildrenZOrder() {
+ // internal because we need to call it from ScrollableControl.OnVisibleChanged
+ internal void UpdateChildrenZOrder() {
Control [] controls;
if (!IsHandleCreated) {
return;
}
+ // XXX This code is severely broken. It leaks
+ // the "zero_sized" abstraction out of the X11
+ // backend and into Control.cs. It'll work on
+ // windows simply by virtue of windows never
+ // setting that field to true.
+ //
+ // basically what we need to guard against is
+ // calling XplatUI.SetZOrder on an hwnd that
+ // corresponds to an unmapped X window.
controls = child_controls.GetAllControls ();
- for (int i = 1; i < controls.Length; i++ ) {
- XplatUI.SetZOrder(controls[i].Handle, controls[i-1].Handle, false, false);
+
+ ArrayList children_to_order = new ArrayList ();
+
+ for (int i = 0; i < controls.Length; i ++) {
+ if (!controls[i].IsHandleCreated || !controls[i].VisibleInternal)
+ continue;
+
+ Hwnd hwnd = Hwnd.ObjectFromHandle (controls[i].Handle);
+ if (hwnd.zero_sized)
+ continue;
+
+ children_to_order.Add (controls[i]);
+ }
+
+ for (int i = 1; i < children_to_order.Count; i ++) {
+ Control upper = (Control)children_to_order[i-1];
+ Control lower = (Control)children_to_order[i];
+
+ XplatUI.SetZOrder(lower.Handle, upper.Handle, false, false);
}
}
}
switch((Msg)m.Msg) {
- case Msg.WM_DESTROY: {
- OnHandleDestroyed(EventArgs.Empty);
-#if DebugRecreate
- IntPtr handle = window.Handle;
-#endif
- window.InvalidateHandle();
+ case Msg.WM_DESTROY: {
+ WmDestroy(ref m);
+ return;
+ }
- if (is_recreating) {
-#if DebugRecreate
- Console.WriteLine ("Creating handle for {0:X}", handle.ToInt32());
-#endif
- CreateHandle();
-#if DebugRecreate
- Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
-#endif
- is_recreating = false;
+ case Msg.WM_WINDOWPOSCHANGED: {
+ WmWindowPosChanged(ref m);
+ return;
}
- return;
- }
- case Msg.WM_WINDOWPOSCHANGED: {
- if (Visible) {
- Rectangle save_bounds = explicit_bounds;
- UpdateBounds();
- explicit_bounds = save_bounds;
- if (GetStyle(ControlStyles.ResizeRedraw)) {
- Invalidate();
- }
+ // Nice description of what should happen when handling WM_PAINT
+ // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
+ // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
+ case Msg.WM_PAINT: {
+ WmPaint (ref m);
+ return;
+ }
+
+ // The DefWndProc will never have to handle this, we always paint the background in managed code
+ // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
+ // here but it just makes things more complicated...
+ case Msg.WM_ERASEBKGND: {
+ WmEraseBackground (ref m);
+ return;
}
- return;
- }
- // Nice description of what should happen when handling WM_PAINT
- // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
- // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
- case Msg.WM_PAINT: {
- PaintEventArgs paint_event;
+ case Msg.WM_LBUTTONUP: {
+ WmLButtonUp (ref m);
+ return;
+ }
+
+ case Msg.WM_LBUTTONDOWN: {
+ WmLButtonDown (ref m);
+ return;
+ }
- paint_event = XplatUI.PaintEventStart(Handle, true);
+ case Msg.WM_LBUTTONDBLCLK: {
+ WmLButtonDblClick (ref m);
+ return;
+ }
- if (paint_event == null) {
+ case Msg.WM_MBUTTONUP: {
+ WmMButtonUp (ref m);
return;
}
- DoubleBuffer current_buffer = null;
- if (UseDoubleBuffering) {
- current_buffer = GetBackBuffer ();
- if (!current_buffer.InvalidRegion.IsVisible (paint_event.ClipRectangle)) {
- // Just blit the previous image
- current_buffer.Blit (paint_event);
- XplatUI.PaintEventEnd (Handle, true);
- return;
- }
- current_buffer.Start (paint_event);
+
+ case Msg.WM_MBUTTONDOWN: {
+ WmMButtonDown (ref m);
+ return;
}
-
- if (!GetStyle(ControlStyles.Opaque)) {
- OnPaintBackground(paint_event);
+
+ case Msg.WM_MBUTTONDBLCLK: {
+ WmMButtonDblClick (ref m);
+ return;
}
- // Button-derived controls choose to ignore their Opaque style, give them a chance to draw their background anyways
- OnPaintBackgroundInternal(paint_event);
+ case Msg.WM_RBUTTONUP: {
+ WmRButtonUp (ref m);
+ return;
+ }
+
+ case Msg.WM_RBUTTONDOWN: {
+ WmRButtonDown (ref m);
+ return;
+ }
- OnPaintInternal(paint_event);
- if (!paint_event.Handled) {
- OnPaint(paint_event);
+ case Msg.WM_RBUTTONDBLCLK: {
+ WmRButtonDblClick (ref m);
+ return;
}
- if (current_buffer != null) {
- current_buffer.End (paint_event);
+ case Msg.WM_CONTEXTMENU: {
+ WmContextMenu (ref m);
+ return;
}
+ case Msg.WM_MOUSEWHEEL: {
+ WmMouseWheel (ref m);
+ return;
+ }
- XplatUI.PaintEventEnd(Handle, true);
- return;
- }
-
- case Msg.WM_ERASEBKGND: {
- // The DefWndProc will never have to handle this, we always paint the background in managed code
- // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
- // here but it just makes things more complicated...
- m.Result = (IntPtr)1;
- return;
- }
+ case Msg.WM_MOUSEMOVE: {
+ WmMouseMove (ref m);
+ return;
+ }
- case Msg.WM_LBUTTONUP: {
- MouseEventArgs me;
+ case Msg.WM_SHOWWINDOW: {
+ WmShowWindow (ref m);
+ return;
+ }
- me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
- mouse_clicks,
- LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
- 0);
+ case Msg.WM_CREATE: {
+ WmCreate (ref m);
+ return;
+ }
- HandleClick(mouse_clicks, me);
- OnMouseUp (me);
+ case Msg.WM_MOUSE_ENTER: {
+ WmMouseEnter (ref m);
+ return;
+ }
- if (InternalCapture) {
- InternalCapture = false;
+ case Msg.WM_MOUSELEAVE: {
+ WmMouseLeave (ref m);
+ return;
}
- if (mouse_clicks > 1) {
- mouse_clicks = 1;
+ case Msg.WM_MOUSEHOVER: {
+ WmMouseHover (ref m);
+ return;
+ }
+
+ case Msg.WM_SYSKEYUP: {
+ WmSysKeyUp (ref m);
+ return;
+ }
+
+ case Msg.WM_SYSKEYDOWN:
+ case Msg.WM_KEYDOWN:
+ case Msg.WM_KEYUP:
+ case Msg.WM_SYSCHAR:
+ case Msg.WM_CHAR: {
+ WmKeys (ref m);
+ return;
+ }
+
+ case Msg.WM_HELP: {
+ WmHelp (ref m);
+ return;
+ }
+
+ case Msg.WM_KILLFOCUS: {
+ WmKillFocus (ref m);
+ return;
+ }
+
+ case Msg.WM_SETFOCUS: {
+ WmSetFocus (ref m);
+ return;
}
- return;
- }
- case Msg.WM_LBUTTONDOWN: {
- if (CanSelect) {
- Select (true, true);
- }
- InternalCapture = true;
- OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
- mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
- 0));
-
- return;
- }
+ case Msg.WM_SYSCOLORCHANGE: {
+ WmSysColorChange (ref m);
+ return;
+ }
- case Msg.WM_LBUTTONDBLCLK: {
- InternalCapture = true;
- mouse_clicks++;
- OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
- mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
- 0));
- return;
+ case Msg.WM_SETCURSOR: {
+ WmSetCursor (ref m);
+ return;
+ }
+
+ case Msg.WM_CAPTURECHANGED: {
+ WmCaptureChanged (ref m);
+ return;
+ }
+
+ default:
+ DefWndProc(ref m);
+ return;
}
+ }
+ #endregion // Public Instance Methods
- case Msg.WM_MBUTTONUP: {
- MouseEventArgs me;
+ #region WM methods
+
+ private void WmDestroy (ref Message m) {
+ OnHandleDestroyed(EventArgs.Empty);
+#if DebugRecreate
+ IntPtr handle = window.Handle;
+#endif
+ window.InvalidateHandle();
- me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
- mouse_clicks,
- LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
- 0);
+ if (is_recreating) {
+#if DebugRecreate
+ Console.WriteLine ("Creating handle for {0:X}", handle.ToInt32());
+#endif
+ CreateHandle();
+#if DebugRecreate
+ Console.WriteLine (" + new handle = {0:X}", Handle.ToInt32());
+#endif
+ is_recreating = false;
+ }
+ }
- HandleClick(mouse_clicks, me);
- OnMouseUp (me);
- if (InternalCapture) {
- InternalCapture = false;
- }
- if (mouse_clicks > 1) {
- mouse_clicks = 1;
+ private void WmWindowPosChanged (ref Message m) {
+ if (Visible) {
+ Rectangle save_bounds = explicit_bounds;
+ UpdateBounds();
+ explicit_bounds = save_bounds;
+ if (GetStyle(ControlStyles.ResizeRedraw)) {
+ Invalidate();
}
- return;
}
-
- case Msg.WM_MBUTTONDOWN: {
- InternalCapture = true;
- OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
- mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
- 0));
+ }
+
+
+ // Nice description of what should happen when handling WM_PAINT
+ // can be found here: http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html
+ // and here http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/
+ private void WmPaint (ref Message m) {
+ PaintEventArgs paint_event;
+
+ IntPtr handle = Handle;
+
+ paint_event = XplatUI.PaintEventStart (handle, true);
+
+ if (paint_event == null)
return;
+
+ DoubleBuffer current_buffer = null;
+ if (UseDoubleBuffering) {
+ current_buffer = GetBackBuffer ();
+ if (!current_buffer.InvalidRegion.IsVisible (paint_event.ClipRectangle)) {
+ // Just blit the previous image
+ current_buffer.Blit (paint_event);
+ XplatUI.PaintEventEnd (handle, true);
+ return;
+ }
+ current_buffer.Start (paint_event);
+ }
+
+ if (!GetStyle(ControlStyles.Opaque)) {
+ OnPaintBackground (paint_event);
}
- case Msg.WM_MBUTTONDBLCLK: {
- InternalCapture = true;
- mouse_clicks++;
- OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
- mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
- 0));
- return;
+ // Button-derived controls choose to ignore their Opaque style, give them a chance to draw their background anyways
+ OnPaintBackgroundInternal (paint_event);
+
+ OnPaintInternal(paint_event);
+ if (!paint_event.Handled) {
+ OnPaint (paint_event);
}
- case Msg.WM_RBUTTONUP: {
- MouseEventArgs me;
- Point pt;
+ if (current_buffer != null) {
+ current_buffer.End (paint_event);
+ }
- pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
- pt = PointToScreen(pt);
- XplatUI.SendMessage(m.HWnd, Msg.WM_CONTEXTMENU, m.HWnd, (IntPtr)(pt.X + (pt.Y << 16)));
+ XplatUI.PaintEventEnd (handle, true);
+ }
- me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
- mouse_clicks,
- LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
- 0);
+ private void WmEraseBackground (ref Message m) {
+ // The DefWndProc will never have to handle this, we always paint the background in managed code
+ // In theory this code would look at ControlStyles.AllPaintingInWmPaint and and call OnPaintBackground
+ // here but it just makes things more complicated...
+ m.Result = (IntPtr)1;
+ }
- HandleClick(mouse_clicks, me);
- OnMouseUp (me);
+ private void WmLButtonUp (ref Message m) {
+ MouseEventArgs me;
- if (InternalCapture) {
- InternalCapture = false;
- }
+ me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Left,
+ mouse_clicks,
+ LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
+ 0);
- if (mouse_clicks > 1) {
- mouse_clicks = 1;
- }
- return;
+ HandleClick(mouse_clicks, me);
+ OnMouseUp (me);
+
+ if (InternalCapture) {
+ InternalCapture = false;
+ }
+
+ if (mouse_clicks > 1) {
+ mouse_clicks = 1;
}
+ }
- case Msg.WM_RBUTTONDOWN: {
- InternalCapture = true;
- OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
- mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
- 0));
- return;
+ private void WmLButtonDown (ref Message m) {
+ if (CanSelect) {
+ Select (true, true);
}
+ InternalCapture = true;
+ OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
+ mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
+ 0));
+ }
- case Msg.WM_RBUTTONDBLCLK: {
- InternalCapture = true;
- mouse_clicks++;
- OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
- mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
- 0));
- return;
+ private void WmLButtonDblClick (ref Message m) {
+ InternalCapture = true;
+ mouse_clicks++;
+ OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
+ mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
+ 0));
+ }
+
+ private void WmMButtonUp (ref Message m) {
+ MouseEventArgs me;
+
+ me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Middle,
+ mouse_clicks,
+ LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
+ 0);
+
+ HandleClick(mouse_clicks, me);
+ OnMouseUp (me);
+ if (InternalCapture) {
+ InternalCapture = false;
}
+ if (mouse_clicks > 1) {
+ mouse_clicks = 1;
+ }
+ }
+
+ private void WmMButtonDown (ref Message m) {
+ InternalCapture = true;
+ OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
+ mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
+ 0));
+ }
- case Msg.WM_CONTEXTMENU: {
- if (context_menu != null) {
- Point pt;
+ private void WmMButtonDblClick (ref Message m) {
+ InternalCapture = true;
+ mouse_clicks++;
+ OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
+ mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
+ 0));
+ }
- pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
+ private void WmRButtonUp (ref Message m) {
+ MouseEventArgs me;
+ Point pt;
- if (pt.X == -1 || pt.Y == -1) {
- pt.X = (this.Width / 2) + this.Left;
- pt.Y = (this.Height / 2) + this.Top;
- pt = this.PointToScreen (pt);
- }
+ pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
+ pt = PointToScreen(pt);
+
+ XplatUI.SendMessage(m.HWnd, Msg.WM_CONTEXTMENU, m.HWnd, (IntPtr)(pt.X + (pt.Y << 16)));
+
+ me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right,
+ mouse_clicks,
+ LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
+ 0);
+
+ HandleClick(mouse_clicks, me);
+ OnMouseUp (me);
+
+ if (InternalCapture) {
+ InternalCapture = false;
+ }
+
+ if (mouse_clicks > 1) {
+ mouse_clicks = 1;
+ }
+ }
- context_menu.Show (this, PointToClient (pt));
- return;
+ private void WmRButtonDown (ref Message m) {
+ InternalCapture = true;
+ OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
+ mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
+ 0));
+ }
+
+ private void WmRButtonDblClick (ref Message m) {
+ InternalCapture = true;
+ mouse_clicks++;
+ OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
+ mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
+ 0));
+ }
+
+ private void WmContextMenu (ref Message m) {
+ if (context_menu != null) {
+ Point pt;
+
+ pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
+
+ if (pt.X == -1 || pt.Y == -1) {
+ pt.X = (this.Width / 2) + this.Left;
+ pt.Y = (this.Height / 2) + this.Top;
+ pt = this.PointToScreen (pt);
}
+
+ context_menu.Show (this, PointToClient (pt));
+ return;
+ }
#if NET_2_0
// If there isn't a regular context menu, show the Strip version
return;
}
#endif
- DefWndProc(ref m);
- return;
- }
-
- case Msg.WM_MOUSEWHEEL: {
- DefWndProc(ref m);
- OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
- mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
- HighOrder(m.WParam.ToInt32())));
- return;
- }
+ DefWndProc(ref m);
+ }
+ private void WmCreate (ref Message m) {
+ OnHandleCreated(EventArgs.Empty);
+ }
- case Msg.WM_MOUSEMOVE: {
- OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
- mouse_clicks,
- LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
- 0));
- return;
- }
+ private void WmMouseWheel (ref Message m) {
+ DefWndProc(ref m);
+ OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
+ mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
+ HighOrder(m.WParam.ToInt32())));
+ }
- case Msg.WM_MOUSE_ENTER: {
- if (is_entered) {
- return;
- }
- is_entered = true;
- OnMouseEnter(EventArgs.Empty);
- return;
- }
- case Msg.WM_MOUSE_LEAVE: {
- is_entered=false;
- OnMouseLeave(EventArgs.Empty);
- return;
- }
+ private void WmMouseMove (ref Message m) {
+ OnMouseMove (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
+ mouse_clicks,
+ LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()),
+ 0));
+ }
- case Msg.WM_MOUSEHOVER: {
- OnMouseHover(EventArgs.Empty);
+ private void WmMouseEnter (ref Message m) {
+ if (is_entered) {
return;
}
+ is_entered = true;
+ OnMouseEnter(EventArgs.Empty);
+ }
- case Msg.WM_SYSKEYUP: {
- if (ProcessKeyMessage(ref m)) {
- m.Result = IntPtr.Zero;
- return;
- }
+ private void WmMouseLeave (ref Message m) {
+ is_entered=false;
+ OnMouseLeave(EventArgs.Empty);
+ }
- if ((m.WParam.ToInt32() & (int)Keys.KeyCode) == (int)Keys.Menu) {
- Form form;
+ private void WmMouseHover (ref Message m) {
+ OnMouseHover(EventArgs.Empty);
+ }
- form = FindForm();
- if (form != null && form.ActiveMenu != null) {
- form.ActiveMenu.ProcessCmdKey(ref m, (Keys)m.WParam.ToInt32());
+ private void WmShowWindow (ref Message m) {
+ if (m.WParam.ToInt32() != 0) {
+ CreateControl ();
+ /* if we're being shown, make sure our child controls all have their handles created */
+ Control [] controls = child_controls.GetAllControls ();
+ for (int i=0; i<controls.Length; i++) {
+ if (controls [i].is_visible) {
+ controls [i].CreateControl ();
+ XplatUI.SetParent(controls[i].Handle, window.Handle);
}
}
-
- DefWndProc (ref m);
- return;
}
+ else {
+ if (parent != null && Focused) {
+ Control container;
- case Msg.WM_SYSKEYDOWN:
- case Msg.WM_KEYDOWN:
- case Msg.WM_KEYUP:
- case Msg.WM_SYSCHAR:
- case Msg.WM_CHAR: {
- if (ProcessKeyMessage(ref m)) {
- m.Result = IntPtr.Zero;
- return;
+ // Need to start at parent, GetContainerControl might return ourselves if we're a container
+ container = (Control)parent.GetContainerControl();
+ if (container != null) {
+ container.SelectNextControl(this, true, true, true, true);
+ }
}
- DefWndProc (ref m);
- return;
}
- case Msg.WM_HELP: {
- Point mouse_pos;
- if (m.LParam != IntPtr.Zero) {
- HELPINFO hi;
-
- hi = new HELPINFO();
+ if (is_toplevel || (this is Form && ((Form) this).IsMdiChild)) /* XXX make sure this works for mdi forms */
+ OnVisibleChanged(EventArgs.Empty);
+ }
- hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
- mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
- } else {
- mouse_pos = Control.MousePosition;
- }
- OnHelpRequested(new HelpEventArgs(mouse_pos));
- m.Result = (IntPtr)1;
+ private void WmSysKeyUp (ref Message m) {
+ if (ProcessKeyMessage(ref m)) {
+ m.Result = IntPtr.Zero;
return;
}
- case Msg.WM_KILLFOCUS: {
- this.has_focus = false;
- OnLostFocus (EventArgs.Empty);
- return;
- }
+ if ((m.WParam.ToInt32() & (int)Keys.KeyCode) == (int)Keys.Menu) {
+ Form form;
- case Msg.WM_SETFOCUS: {
- if (!has_focus) {
- this.has_focus = true;
- OnGotFocus (EventArgs.Empty);
+ form = FindForm();
+ if (form != null && form.ActiveMenu != null) {
+ form.ActiveMenu.ProcessCmdKey(ref m, (Keys)m.WParam.ToInt32());
}
- return;
}
-
- case Msg.WM_SYSCOLORCHANGE: {
- ThemeEngine.Current.ResetDefaults();
- OnSystemColorsChanged(EventArgs.Empty);
+
+ DefWndProc (ref m);
+ }
+
+ private void WmKeys (ref Message m) {
+ if (ProcessKeyMessage(ref m)) {
+ m.Result = IntPtr.Zero;
return;
}
+ DefWndProc (ref m);
+ }
- case Msg.WM_SETCURSOR: {
- if ((cursor == null) || ((HitTest)(m.LParam.ToInt32() & 0xffff) != HitTest.HTCLIENT)) {
- DefWndProc(ref m);
- return;
- }
+ private void WmHelp (ref Message m) {
+ Point mouse_pos;
+ if (m.LParam != IntPtr.Zero) {
+ HELPINFO hi;
- XplatUI.SetCursor(window.Handle, cursor.handle);
- m.Result = (IntPtr)1;
+ hi = new HELPINFO();
- return;
+ hi = (HELPINFO) Marshal.PtrToStructure (m.LParam, typeof (HELPINFO));
+ mouse_pos = new Point(hi.MousePos.x, hi.MousePos.y);
+ } else {
+ mouse_pos = Control.MousePosition;
}
+ OnHelpRequested(new HelpEventArgs(mouse_pos));
+ m.Result = (IntPtr)1;
+ }
- case Msg.WM_CAPTURECHANGED: {
- is_captured = false;
- OnMouseCaptureChanged (EventArgs.Empty);
- m.Result = (IntPtr) 0;
- return;
+ private void WmKillFocus (ref Message m) {
+ this.has_focus = false;
+ OnLostFocus (EventArgs.Empty);
+ }
+
+ private void WmSetFocus (ref Message m) {
+ if (!has_focus) {
+ this.has_focus = true;
+ OnGotFocus (EventArgs.Empty);
}
+ }
+
+ private void WmSysColorChange (ref Message m) {
+ ThemeEngine.Current.ResetDefaults();
+ OnSystemColorsChanged(EventArgs.Empty);
+ }
- default:
+ private void WmSetCursor (ref Message m) {
+ if ((cursor == null) || ((HitTest)(m.LParam.ToInt32() & 0xffff) != HitTest.HTCLIENT)) {
DefWndProc(ref m);
return;
}
+
+ XplatUI.SetCursor(window.Handle, cursor.handle);
+ m.Result = (IntPtr)1;
+ }
+
+ private void WmCaptureChanged (ref Message m) {
+ is_captured = false;
+ OnMouseCaptureChanged (EventArgs.Empty);
+ m.Result = (IntPtr) 0;
}
- #endregion // Public Instance Methods
+
+
+ #endregion
#region OnXXX methods
#if NET_2_0
eh (this, e);
}
- internal void RaiseHelpRequested (HelpEventArgs hevent)
- {
+ internal void RaiseHelpRequested (HelpEventArgs hevent) {
OnHelpRequested (hevent);
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
protected virtual void OnVisibleChanged(EventArgs e) {
- if ((parent != null) && !Created && Visible) {
- if (!is_disposed) {
- CreateControl();
- PerformLayout();
- }
- }
-
EventHandler eh = (EventHandler)(Events [VisibleChangedEvent]);
if (eh != null)
eh (this, e);