2 // System.Windows.Forms.Control.cs
\r
5 // stubbed out by Jaak Simm (jaaksimm@firm.ee)
\r
6 // Dennis Hayes (dennish@rayetk.com)
\r
7 // WINELib implementation started by John Sohn (jsohn@columbus.rr.com)
\r
9 // (C) Ximian, Inc., 2002
\r
12 using System.ComponentModel;
\r
13 using System.Drawing;
\r
14 using System.Collections;
\r
15 using System.Threading;
\r
18 namespace System.Windows.Forms {
\r
21 /// Defines the base class for controls, which are components with
\r
22 /// visual representation.
\r
25 public class Control : Component , ISynchronizeInvoke, IWin32Window {
\r
28 // Helper NativeWindow class to dispatch messages back
\r
29 // to the Control class
\r
30 protected class ControlNativeWindow : NativeWindow {
\r
32 private Control control;
\r
34 public ControlNativeWindow (Control control) : base() {
\r
35 this.control = control;
\r
38 protected override void WndProc (ref Message m) {
\r
39 //Console.WriteLine ("Control WndProc Message HWnd {0}, Msg {1}", m.HWnd, m.Msg);
\r
40 // Do not call default WndProc here
\r
41 // let the control decide what to do
\r
42 // base.WndProc (ref m);
\r
43 control.WndProc (ref m);
\r
47 // FIXME: not sure if dervied classes should have access
\r
48 protected ControlNativeWindow window;
\r
49 private ControlCollection childControls;
\r
50 private Control parent;
\r
51 static private Hashtable controlsCollection = new Hashtable ();
\r
54 // it seems these are stored in case the window is not created,
\r
55 // corresponding properties (below) need to check if window
\r
56 // is created or not and react accordingly
\r
57 string accessibleDefaultActionDescription;
\r
58 string accessibleDescription;
\r
59 string accessibleName;
\r
60 AccessibleRole accessibleRole;
\r
62 AnchorStyles anchor;
\r
64 Image backgroundImage;
\r
65 //BindingContext bindingContext;
\r
67 bool causesValidation;
\r
68 //ContextMenu contextMenu;
\r
75 // Point location; // using bounds to store location
\r
78 RightToLeft rightToLeft;
\r
83 protected bool mouseIsInside_;
\r
84 bool recreatingHandle;
\r
86 // BeginInvoke() etc. helpers
\r
87 static int InvokeMessage = Win32.RegisterWindowMessage("mono_control_invoke_helper");
\r
89 // CHECKME: This variable is used to determine whether current thread
\r
90 // was used to create Control Handle. It take some space but saves a call
\r
91 // to unmanaged code in ISynchronizeInvoke.IsInvokeRequired.
\r
92 private int CreatorThreadId_ = 0;
\r
94 private Queue InvokeQueue_ = new Queue();
\r
96 internal class ControlInvokeHelper : IAsyncResult {
\r
97 private Delegate Method_ = null;
\r
98 private object[] MethodArgs_ = null;
\r
99 private object MethodResult_ = null;
\r
100 private ManualResetEvent AsyncWaitHandle_ = new ManualResetEvent(false);
\r
101 private bool CompletedSynchronously_ = false;
\r
102 private bool IsCompleted_ = false;
\r
104 public ControlInvokeHelper( Delegate method, object[] args) {
\r
106 MethodArgs_ = args;
\r
109 // IAsyncResult interface
\r
110 object IAsyncResult.AsyncState {
\r
112 if( MethodArgs_ != null && MethodArgs_.Length != 0) {
\r
113 return MethodArgs_[MethodArgs_.Length - 1];
\r
119 WaitHandle IAsyncResult.AsyncWaitHandle {
\r
121 return AsyncWaitHandle_;
\r
125 bool IAsyncResult.CompletedSynchronously {
\r
127 return CompletedSynchronously_;
\r
131 bool IAsyncResult.IsCompleted {
\r
133 return IsCompleted_;
\r
137 internal bool CompletedSynchronously {
\r
139 CompletedSynchronously_ = value;
\r
143 internal object MethodResult {
\r
145 return MethodResult_;
\r
149 internal void ExecuteMethod() {
\r
150 object result = Method_.DynamicInvoke(MethodArgs_);
\r
152 MethodResult_ = result;
\r
153 IsCompleted_ = true;
\r
155 AsyncWaitHandle_.Set();
\r
159 // --- Constructors ---
\r
161 //Compact Framework //only Control()
\r
164 CreateControlsInstance ();
\r
166 accessibleDefaultActionDescription = null;
\r
167 accessibleDescription = null;
\r
168 accessibleName = null;
\r
169 accessibleRole = AccessibleRole.Default;
\r
171 anchor = AnchorStyles.Top | AnchorStyles.Left;
\r
172 backColor = Control.DefaultBackColor;
\r
173 backgroundImage = null;
\r
174 bounds = new Rectangle();
\r
175 // bindingContext = null;
\r
176 causesValidation = true;
\r
177 // contextMenu = null;
\r
178 dock = DockStyle.None;
\r
180 // font = Control.DefaultFont;
\r
181 foreColor = Control.DefaultForeColor;
\r
182 imeMode = ImeMode.Inherit;
\r
183 isAccessible = false;
\r
184 // location = new Point (0,0); should be from OS
\r
187 rightToLeft = RightToLeft.Inherit;
\r
192 mouseIsInside_ = false;
\r
193 recreatingHandle = false;
\r
194 // Do not create Handle here, only in CreateHandle
\r
195 // CreateHandle();//sets window handle. FIXME: No it does not
\r
198 // according to docs, the constructors do not create
\r
199 // the (HWND) window
\r
200 public Control (string text) : this()
\r
203 // SetWindowTextA (Handle, text);
\r
206 public Control (Control parent, string text) : this (text)
\r
209 // SetParent (Handle, parent.Handle);
\r
212 public Control (string text, int left, int top,
\r
213 int width, int height) : this(text)
\r
219 //SetWindowPos (Handle, (IntPtr) 0, left, top,
\r
220 // width, height, 0);
\r
223 public Control (Control parent,string text,int left, int top,
\r
224 int width,int height) : this (parent, text)
\r
230 // SetWindowPos (Handle, (IntPtr) 0, left, top,
\r
231 // width, height, 0);
\r
234 // for internal use only, create a control class
\r
235 // for an existing, created HWND
\r
236 private Control (IntPtr existingHandle)
\r
238 window = (ControlNativeWindow) NativeWindow.FromHandle (
\r
242 // --- Properties ---
\r
243 // Properties only supporting .NET framework, not stubbed out:
\r
244 // - protected bool RenderRightToLeft {get;}
\r
245 // - public IWindowTarget WindowTarget {get; set;}
\r
247 //public AccessibleObject AccessibilityObject {
\r
249 // throw new NotImplementedException ();
\r
253 public string AccessibleDefaultActionDescription {
\r
255 return accessibleDefaultActionDescription;
\r
258 accessibleDefaultActionDescription = value;
\r
262 public string AccessibleDescription {
\r
264 return accessibleDescription;
\r
267 accessibleDescription=value;
\r
271 public string AccessibleName {
\r
273 return accessibleName;
\r
276 accessibleName=value;
\r
280 public AccessibleRole AccessibleRole {
\r
282 return accessibleRole;
\r
285 accessibleRole=value;
\r
289 public virtual bool AllowDrop {
\r
298 public virtual AnchorStyles Anchor {
\r
307 //Compact Framework
\r
308 public virtual Color BackColor {
\r
317 public virtual Image BackgroundImage {
\r
319 return backgroundImage;
\r
322 backgroundImage = value;
\r
323 // FIXME: force redraw
\r
328 public virtual BindingContext BindingContext {
\r
330 //return bindingContext;
\r
331 throw new NotImplementedException ();
\r
334 //bindingContext=value;
\r
335 throw new NotImplementedException ();
\r
339 //Compact Framework
\r
340 public int Bottom {
\r
342 return Top + Height;
\r
346 //Compact Framework
\r
347 public Rectangle Bounds {
\r
349 if (IsHandleCreated) {
\r
350 RECT rect = new RECT();
\r
351 Win32.GetWindowRect (Handle, ref rect);
\r
352 return new Rectangle ((int) rect.left,
\r
355 (int) rect.bottom);
\r
356 } else return bounds;
\r
359 SetBounds(value.Left, value.Top, value.Width, value.Height);
\r
363 public bool CanFocus {
\r
365 if (IsHandleCreated && Visible && Enabled)
\r
372 public bool CanSelect {
\r
374 // if (ControlStyles.Selectable &&
\r
375 // isContainedInAnotherControl &&
\r
376 // parentIsVisiable && isVisialbe &&
\r
377 // parentIsEnabled && isEnabled) {
\r
382 throw new NotImplementedException ();
\r
386 //Compact Framework
\r
387 public bool Capture {
\r
389 if (IsHandleCreated) {
\r
390 IntPtr captured = Win32.GetCapture ();
\r
391 if (Handle == captured)
\r
397 if (IsHandleCreated) {
\r
399 Win32.SetCapture (Handle);
\r
401 IntPtr captured = Win32.GetCapture ();
\r
403 // if this window is in capture state
\r
405 if (Handle == captured)
\r
406 Win32.ReleaseCapture ();
\r
412 public bool CausesValidation {
\r
414 return causesValidation;
\r
417 causesValidation=value;
\r
421 //Compact Framework
\r
422 public Rectangle ClientRectangle {
\r
424 if (IsHandleCreated) {
\r
425 RECT rect = new RECT();
\r
426 Win32.GetClientRect (Handle, ref rect);
\r
427 return new Rectangle ((int) rect.left,
\r
430 (int) rect.bottom);
\r
433 // FIXME: is the correct return value for
\r
434 // window who's handle is not created
\r
435 return new Rectangle (0, 0, 0, 0);
\r
439 //Compact Framework
\r
441 public Size ClientSize {
\r
443 if (IsHandleCreated) {
\r
444 RECT rect = new RECT();
\r
445 Win32.GetClientRect (Handle, ref rect);
\r
448 (int) rect.bottom);
\r
450 // FIXME: is the correct return value for
\r
451 // window who's handle is not created
\r
452 return new Size (0, 0);
\r
455 // FIXME: Is this good default style ?
\r
456 SetClientSize(value, (int)(WindowStyles.WS_CHILD | WindowStyles.WS_BORDER), false);
\r
461 public string CompanyName {
\r
463 //Better than throwing an execption
\r
464 return "Company Name";
\r
468 internal void SetClientSize(Size value, int styleIfNoWindow, bool menuIfNoWindow) {
\r
469 RECT rc = new RECT();
\r
470 rc.left = rc.top = 0;
\r
471 rc.right = value.Width;
\r
472 rc.bottom = value.Height;
\r
474 if( Handle != IntPtr.Zero){
\r
475 int style = Win32.GetWindowLong( Handle, GetWindowLongFlag.GWL_STYLE).ToInt32();
\r
476 int menuExists = 0;
\r
477 if( (style & (int)WindowStyles.WS_CHILD) == 0 ){
\r
478 menuExists = Win32.GetMenu(Handle) != IntPtr.Zero ? 1 : 0;
\r
480 Win32.AdjustWindowRect( ref rc, style, menuExists);
\r
481 Win32.SetWindowPos( Handle, SetWindowPosZOrder.HWND_TOP, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
\r
482 SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOZORDER);
\r
485 Win32.AdjustWindowRect( ref rc, styleIfNoWindow, menuIfNoWindow ? 1 : 0);
\r
487 Size = new Size(rc.right - rc.left, rc.bottom - rc.top);
\r
490 public bool ContainsFocus {
\r
492 if (IsHandleCreated) {
\r
493 IntPtr focusedWindow = Win32.GetFocus();
\r
494 if (focusedWindow == Handle)
\r
501 //Compact Framework
\r
503 public virtual ContextMenu ContextMenu {
\r
505 //return contextMenu;
\r
506 throw new NotImplementedException ();
\r
509 //contextMenu=value;
\r
510 throw new NotImplementedException ();
\r
514 public ControlCollection Controls {
\r
515 get { return childControls; }
\r
518 public bool Created {
\r
520 if (Handle != (IntPtr) 0)
\r
526 protected virtual CreateParams CreateParams {
\r
528 CreateParams createParams = new CreateParams ();
\r
529 createParams.Caption = Text;
\r
530 createParams.ClassName = "CONTROL";
\r
531 createParams.X = Left;
\r
532 createParams.Y = Top;
\r
533 createParams.Width = Width;
\r
534 createParams.Height = Height;
\r
535 createParams.ClassStyle = 0;
\r
536 createParams.ExStyle = 0;
\r
537 createParams.Param = 0;
\r
539 if (parent != null)
\r
540 createParams.Parent = parent.Handle;
\r
542 createParams.Parent = (IntPtr) 0;
\r
544 createParams.Style = (int) WindowStyles.WS_OVERLAPPEDWINDOW;
\r
546 return createParams;
\r
550 internal protected IntPtr ControlRealWndProc = IntPtr.Zero;
\r
551 internal protected bool SubClassWndProc_ = false;
\r
553 // This function lets Windows or/and default Windows control process message
\r
554 // Classes have to call it if they do not handle message in WndProc or
\r
555 // default handling is needed.
\r
556 protected void CallControlWndProc( ref Message msg) {
\r
557 if( ControlRealWndProc != IntPtr.Zero) {
\r
558 msg.Result = (IntPtr)Win32.CallWindowProc(ControlRealWndProc, msg.HWnd, (int)msg.Msg, msg.WParam.ToInt32(), msg.LParam.ToInt32());
\r
561 DefWndProc(ref msg);
\r
565 // Subclass only native Windows controls. Those classes have to set SubClassWndProc_ to true in contructor
\r
566 private void SubclassWindow() {
\r
567 if( IsHandleCreated && SubClassWndProc_) {
\r
568 ControlRealWndProc = Win32.SetWindowLong( Handle, GetWindowLongFlag.GWL_WNDPROC, NativeWindow.GetWindowProc());
\r
572 private void UnsubclassWindow() {
\r
573 if( IsHandleCreated) {
\r
574 Win32.SetWindowLong( Handle, GetWindowLongFlag.GWL_WNDPROC, ControlRealWndProc.ToInt32());
\r
578 protected virtual void OnWmCommand (ref Message m) {
\r
579 if( m.LParam.ToInt32() != 0) {
\r
580 if( m.LParam != Handle) {
\r
581 // Control notification
\r
582 System.Console.WriteLine("Control notification Code {0} Id = Hwnd {1}", m.HiWordWParam, m.LParam.ToInt32());
\r
583 Control.ReflectMessage(m.LParam, ref m);
\r
586 // Unhandled Control reflection
\r
587 // Derived class didn't handle WM_COMMAND or called base.WndProc in WM_COMMAND handler
\r
588 // CHECKME: Shall we notify user in debug build, throw an exception or just ignore this case ?
\r
594 public virtual Cursor Cursor {
\r
596 throw new NotImplementedException ();
\r
599 throw new NotImplementedException ();
\r
603 //Compact Framework
\r
605 // waiting for BindingContext; should be stubbed now
\r
606 public ControlBindingsCollection DataBindings {
\r
608 throw new NotImplementedException ();
\r
612 public static Color DefaultBackColor {
\r
614 // FIXME: use GetSystemMetrics?
\r
615 return SystemColors.Control;
\r
616 //throw new NotImplementedException ();
\r
621 // FIXME: use GetSystemMetrics?
\r
622 public static Font DefaultFont {
\r
623 // FIXME: get current system font from GenericSansSerif
\r
624 // call ArgumentException not called
\r
626 // throw new NotImplementedException ();
\r
627 // return (FontFamily.GenericSansSerif);
\r
628 return Font.FromHfont(Win32.GetStockObject(GSO_.DEFAULT_GUI_FONT));
\r
632 public static Color DefaultForeColor {
\r
634 return SystemColors.ControlText;
\r
638 protected virtual ImeMode DefaultImeMode {
\r
640 return ImeMode.Inherit;
\r
644 protected virtual Size DefaultSize {
\r
646 //Default label size, this should be correct.
\r
647 return new Size(100,23);
\r
651 public virtual Rectangle DisplayRectangle {
\r
653 return ClientRectangle;
\r
658 public bool Disposing {
\r
660 throw new NotImplementedException ();
\r
664 public virtual DockStyle Dock {
\r
673 //Compact Framework
\r
674 public virtual bool Enabled {
\r
677 //return Win32.IsWindowEnabled (Handle);
\r
680 if( enabled != value) {
\r
681 Win32.EnableWindow (Handle, value);
\r
683 // FIXME: Disable/enable all children here
\r
689 //Compact Framework
\r
690 public virtual bool Focused {
\r
692 return ContainsFocus;
\r
696 //Compact Framework
\r
697 public virtual Font Font {
\r
699 Font result = font;
\r
700 if( result == null) {
\r
701 if( Parent != null) {
\r
702 result = Parent.Font;
\r
704 if( result == null) {
\r
705 result = Control.DefaultFont;
\r
712 if( IsHandleCreated) {
\r
713 Win32.SendMessage(Handle, Msg.WM_SETFONT, Font.ToHfont().ToInt32(), 1);
\r
719 protected int FontHeight {
\r
721 throw new NotImplementedException ();
\r
724 throw new NotImplementedException ();
\r
728 //Compact Framework
\r
729 public virtual Color ForeColor {
\r
738 public bool HasChildren {
\r
740 if (childControls.Count >0)
\r
746 //Compact Framework
\r
747 public int Height {
\r
749 if (IsHandleCreated) {
\r
750 // FIXME: GetWindowPos
\r
752 return bounds.Height;
\r
755 //bounds.Height = value;
\r
756 if (IsHandleCreated) {
\r
757 // FIXME: SetWindowPos
\r
759 SetBounds(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
\r
763 public ImeMode ImeMode {
\r
773 public bool IsAccessible {
\r
776 return isAccessible;
\r
777 } // default is false
\r
779 isAccessible=value;
\r
783 public bool IsDisposed {
\r
785 if (Handle == (IntPtr) 0)
\r
791 public bool IsHandleCreated {
\r
793 if (Handle != (IntPtr) 0)
\r
799 //Compact Framework
\r
802 if (IsHandleCreated) {
\r
803 // FIXME: GetWindowPos
\r
805 } else return bounds.X;
\r
808 if (IsHandleCreated) {
\r
809 // FIXME: SetWindowPos
\r
811 SetBounds(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
\r
815 //Compact Framework
\r
816 public Point Location {
\r
819 return new Point (Top, Left);
\r
822 if (IsHandleCreated) {
\r
823 // FIXME: SetWindowPos
\r
825 SetBounds(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
\r
830 public static Keys ModifierKeys {
\r
832 throw new NotImplementedException ();
\r
836 //Compact Framework
\r
838 public static MouseButtons MouseButtons {
\r
840 // FIXME: use GetAsycKeyState?
\r
841 throw new NotImplementedException ();
\r
845 //Compact Framework
\r
846 public static Point MousePosition {
\r
848 POINT point = new POINT();
\r
849 Win32.GetCursorPos (ref point);
\r
850 return new Point ( (int) point.x, (int) point.y);
\r
854 public string Name {
\r
864 //Compact Framework
\r
865 public Control Parent {
\r
868 //IntPtr parent = GetParent (Handle);
\r
869 //return FromHandle (parent);
\r
872 if( parent != value) {
\r
873 Console.WriteLine ("setting parent");
\r
876 Console.WriteLine ("add ourself to the parents control");
\r
877 // add ourself to the parents control
\r
878 parent.Controls.Add (this);
\r
880 Console.WriteLine ("SetParent");
\r
881 if (IsHandleCreated) {
\r
882 Console.WriteLine ("Handle created");
\r
883 Win32.SetParent (Handle, value.Handle);
\r
886 else if( parent.IsHandleCreated){
\r
887 // CHECKME: Now control is responsible for creating his window
\r
888 // when added to Form, may be things must be reversed.
\r
897 public string ProductName {
\r
900 return "Product Name";
\r
905 public string ProductVersion {
\r
908 return "Product Version";
\r
913 public bool RecreatingHandle {
\r
915 return recreatingHandle;
\r
919 public Region Region {
\r
930 protected bool ResizeRedraw {
\r
932 throw new NotImplementedException ();
\r
935 throw new NotImplementedException ();
\r
939 //Compact Framework
\r
942 return Left + Width;
\r
947 public virtual RightToLeft RightToLeft {
\r
950 return rightToLeft;
\r
958 protected virtual bool ShowFocusCues {
\r
960 throw new NotImplementedException ();
\r
965 protected bool ShowKeyboardCues {
\r
967 throw new NotImplementedException ();
\r
972 public override ISite Site {
\r
974 throw new NotImplementedException ();
\r
977 throw new NotImplementedException ();
\r
981 //Compact Framework
\r
983 //FIXME: should we return client size or someother size???
\r
985 if( IsHandleCreated) {
\r
986 RECT WindowRectangle;
\r
987 WindowRectangle = new RECT();
\r
988 if(!Win32.GetWindowRect(Handle,ref WindowRectangle)){
\r
989 //throw new Exception("couild not retreve Control Size");
\r
991 // CHECKME: Here we can also update internal variables
\r
992 return new Size(WindowRectangle.right - WindowRectangle.left,
\r
993 WindowRectangle.bottom - WindowRectangle.top);
\r
996 return new Size(Width, Height);
\r
1000 if( IsHandleCreated) {
\r
1002 Win32.SetWindowPos(Handle, SetWindowPosZOrder.HWND_TOP, 0, 0, value.Width, value.Height,
\r
1003 SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOMOVE |
\r
1004 SetWindowPosFlags.SWP_NOZORDER);// Activating might be a good idea?? | SetWindowPosFlags.SWP_NOACTIVATE);
\r
1007 SetBounds(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
\r
1011 internal int tabindex;//for debug/test only. remove
\r
1013 public int TabIndex {
\r
1022 public bool TabStop {
\r
1033 public object Tag {
\r
1042 //Compact Framework
\r
1043 public virtual string Text {
\r
1045 // CHECKME: if we really need to provide back current text of real window
\r
1046 // or just our copy in text member.
\r
1047 if (IsHandleCreated) {
\r
1048 int len = Win32.GetWindowTextLengthA (Handle);
\r
1049 // FIXME: len is doubled due to some strange behaviour.(of GetWindowText function ?)
\r
1050 // instead of 10 characters we can get only 9, even if sb.Capacity is 10.
\r
1051 StringBuilder sb = new StringBuilder(len * 2 /*Win32.GetWindowTextLengthA (Handle)*/);
\r
1052 Win32.GetWindowText (Handle, sb, sb.Capacity);
\r
1053 return sb.ToString();
\r
1062 if (IsHandleCreated)
\r
1063 Win32.SetWindowTextA (Handle, value);
\r
1067 //Compact Framework
\r
1070 if (IsHandleCreated) {
\r
1071 // FIXME: GetWindowPos
\r
1073 } else return bounds.Top;
\r
1076 if (IsHandleCreated) {
\r
1077 // FIXME: SetWindowPos
\r
1079 SetBounds(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
\r
1084 public Control TopLevelControl {
\r
1086 throw new NotImplementedException ();
\r
1090 //Compact Framework
\r
1091 public bool Visible {
\r
1093 throw new NotImplementedException ();
\r
1097 Win32.ShowWindow (
\r
1098 Handle, ShowWindowStyles.SW_SHOW);
\r
1100 Win32.ShowWindow (
\r
1101 Handle, ShowWindowStyles.SW_HIDE);
\r
1105 //Compact Framework
\r
1106 public int Width {
\r
1108 if (IsHandleCreated) {
\r
1109 // FIXME: GetWindowPos
\r
1111 return bounds.Width;
\r
1114 if (IsHandleCreated) {
\r
1115 // FIXME: SetWindowPos
\r
1117 SetBounds(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
\r
1121 /// --- methods ---
\r
1122 /// internal .NET framework supporting methods, not stubbed out:
\r
1123 /// - protected virtual void NotifyInvalidate(Rectangle invalidatedArea)
\r
1124 /// - protected void RaiseDragEvent(object key,DragEventArgs e);
\r
1125 /// - protected void RaiseKeyEvent(object key,KeyEventArgs e);
\r
1126 /// - protected void RaiseMouseEvent(object key,MouseEventArgs e);
\r
1127 /// - protected void RaisePaintEvent(object key,PaintEventArgs e);
\r
1128 /// - protected void ResetMouseEventArgs();
\r
1131 protected void AccessibilityNotifyClients (
\r
1132 AccessibleEvents accEvent,int childID)
\r
1134 throw new NotImplementedException ();
\r
1137 //Compact Framework
\r
1139 public void BringToFront ()
\r
1144 public bool Contains (Control ctl)
\r
1146 return childControls.Contains (ctl);
\r
1149 public void CreateControl ()
\r
1152 OnCreateControl();
\r
1156 protected virtual AccessibleObject CreateAccessibilityInstance() {
\r
1157 throw new NotImplementedException ();
\r
1160 protected virtual ControlCollection CreateControlsInstance ()
\r
1162 childControls = new ControlCollection (this);
\r
1163 return childControls;
\r
1166 //Compact Framework
\r
1168 public Graphics CreateGraphics ()
\r
1170 return Graphics.FromHwnd(Handle);
\r
1173 protected virtual void CreateHandle ()
\r
1175 if( !IsHandleCreated) {
\r
1176 if( window == null) {
\r
1177 window = new ControlNativeWindow (this);
\r
1179 if( window != null) {
\r
1180 CreateParams createParams = CreateParams;
\r
1182 createParams.Style |= (int)WindowStyles.WS_DISABLED;
\r
1184 window.CreateHandle (createParams);
\r
1186 if( Handle != IntPtr.Zero) {
\r
1187 if( controlsCollection[Handle] == null) {
\r
1188 controlsCollection.Add(Handle, this);
\r
1192 CreatorThreadId_ = Win32.GetCurrentThreadId();
\r
1194 OnHandleCreated (new EventArgs());
\r
1199 protected virtual void DefWndProc (ref Message m)
\r
1201 window.DefWndProc(ref m);
\r
1204 protected virtual void DestroyHandle ()
\r
1206 if( Handle != IntPtr.Zero) {
\r
1207 controlsCollection.Remove(Handle);
\r
1209 if( window != null) {
\r
1210 window.DestroyHandle ();
\r
1214 protected override void Dispose (bool disposing)
\r
1217 base.Dispose(disposing);
\r
1221 public DragDropEffects DoDragDrop (
\r
1222 object data, DragDropEffects allowedEffects)
\r
1224 throw new NotImplementedException ();
\r
1227 //public object EndInvoke(IAsyncResult asyncResult):
\r
1228 //look under ISynchronizeInvoke methods
\r
1231 public Form FindForm ()
\r
1233 throw new NotImplementedException ();
\r
1236 //Compact Framework
\r
1237 public bool Focus ()
\r
1239 if (Win32.SetFocus (Handle) != (IntPtr) 0)
\r
1245 public static Control FromChildHandle (IntPtr handle)
\r
1247 Control control = null;
\r
1248 IntPtr controlHwnd = handle;
\r
1249 while( controlHwnd != IntPtr.Zero) {
\r
1250 control = controlsCollection[controlHwnd] as Control;
\r
1251 if( control != null) break;
\r
1252 controlHwnd = Win32.GetParent(controlHwnd);
\r
1257 public static Control FromHandle (IntPtr handle)
\r
1259 // FIXME: Here we have to check, whether control already exists
\r
1260 //Control control = new Control (handle);
\r
1261 Control control = controlsCollection[handle] as Control;
\r
1266 public Control GetChildAtPoint (Point pt)
\r
1268 throw new NotImplementedException ();
\r
1272 //public IContainerControl GetContainerControl ()
\r
1274 // throw new NotImplementedException ();
\r
1278 public Control GetNextControl (Control ctl, bool forward)
\r
1280 throw new NotImplementedException ();
\r
1284 protected bool GetStyle (ControlStyles flag)
\r
1286 throw new NotImplementedException ();
\r
1290 protected bool GetTopLevel ()
\r
1292 throw new NotImplementedException ();
\r
1295 //Compact Framework
\r
1296 public void Hide ()
\r
1298 if (IsHandleCreated)
\r
1299 Win32.ShowWindow (Handle, ShowWindowStyles.SW_HIDE);
\r
1303 protected virtual void InitLayout ()
\r
1308 //Compact Framework
\r
1309 public void Invalidate ()
\r
1311 if (IsHandleCreated) {
\r
1312 Win32.InvalidateRect(Handle, IntPtr.Zero, 1);
\r
1317 public void Invalidate (bool invalidateChildren)
\r
1322 //Compact Framework
\r
1323 public void Invalidate (Rectangle rc)
\r
1325 if (IsHandleCreated) {
\r
1326 RECT rect = new RECT();
\r
1327 rect.left = rc.Left;
\r
1328 rect.top = rc.Top;
\r
1329 rect.right = rc.Right;
\r
1330 rect.bottom = rc.Bottom;
\r
1331 Win32.InvalidateRect (Handle, ref rect, true);
\r
1336 public void Invalidate(Region region)
\r
1342 public void Invalidate (Rectangle rc, bool invalidateChildren)
\r
1348 public void Invalidate(Region region,bool invalidateChildren)
\r
1354 protected void InvokeGotFocus (Control toInvoke, EventArgs e)
\r
1360 protected void InvokeLostFocus (Control toInvoke, EventArgs e)
\r
1366 protected void InvokeOnClick (Control toInvoke, EventArgs e)
\r
1372 protected void InvokePaint (Control c, PaintEventArgs e)
\r
1378 protected void InvokePaintBackground (
\r
1379 Control c,PaintEventArgs e)
\r
1385 protected virtual bool IsInputChar (char charCode)
\r
1387 throw new NotImplementedException ();
\r
1391 protected virtual bool IsInputKey (Keys keyData)
\r
1393 throw new NotImplementedException ();
\r
1397 public static bool IsMnemonic (char charCode,string text)
\r
1399 throw new NotImplementedException ();
\r
1402 // methods used with events:
\r
1403 protected virtual void OnBackColorChanged (EventArgs e)
\r
1405 if (BackColorChanged != null)
\r
1406 BackColorChanged (this, e);
\r
1409 protected virtual void OnBackgroundImageChanged (EventArgs e)
\r
1411 if (BackgroundImageChanged != null)
\r
1412 BackgroundImageChanged (this, e);
\r
1415 protected virtual void OnBindingContextChanged (EventArgs e)
\r
1417 if (BindingContextChanged != null)
\r
1418 BindingContextChanged (this, e);
\r
1421 protected virtual void OnCausesValidationChanged (EventArgs e)
\r
1423 if (CausesValidationChanged != null)
\r
1424 CausesValidationChanged (this, e);
\r
1427 protected virtual void OnChangeUICues(UICuesEventArgs e)
\r
1429 if (ChangeUICues != null)
\r
1430 ChangeUICues (this, e);
\r
1433 //Compact Framework
\r
1434 protected virtual void OnClick (EventArgs e)
\r
1436 if (Click != null)
\r
1441 protected virtual void OnContextMenuChanged (EventArgs e)
\r
1443 if (ContextMenuChanged != null)
\r
1444 ContextMenuChanged (this, e);
\r
1447 protected virtual void OnControlAdded (ControlEventArgs e)
\r
1449 if (ControlAdded != null)
\r
1450 ControlAdded (this, e);
\r
1453 protected virtual void OnControlRemoved (ControlEventArgs e)
\r
1455 if (ControlRemoved != null)
\r
1456 ControlRemoved (this, e);
\r
1459 protected virtual void OnCreateControl ()
\r
1464 protected virtual void OnCursorChanged (EventArgs e)
\r
1466 if (CursorChanged != null)
\r
1467 CursorChanged (this, e);
\r
1470 protected virtual void OnDockChanged (EventArgs e)
\r
1472 if (DockChanged != null)
\r
1473 DockChanged (this, e);
\r
1476 protected virtual void OnDoubleClick (EventArgs e)
\r
1478 if (DoubleClick != null)
\r
1479 DoubleClick (this, e);
\r
1482 protected virtual void OnDragDrop (DragEventArgs e)
\r
1484 if (DragDrop != null)
\r
1485 DragDrop (this, e);
\r
1488 protected virtual void OnDragEnter (DragEventArgs e)
\r
1490 if (DragEnter != null)
\r
1491 DragEnter (this, e);
\r
1494 protected virtual void OnDragLeave (EventArgs e)
\r
1496 if (DragLeave != null)
\r
1497 DragLeave (this, e);
\r
1500 protected virtual void OnDragOver (DragEventArgs e)
\r
1502 if (DragOver != null)
\r
1503 DragOver (this, e);
\r
1506 //Compact Framework
\r
1507 protected virtual void OnEnabledChanged (EventArgs e)
\r
1509 if (EnabledChanged != null)
\r
1510 EnabledChanged (this, e);
\r
1513 protected virtual void OnEnter (EventArgs e)
\r
1515 if (Enter != null)
\r
1519 protected virtual void OnFontChanged (EventArgs e)
\r
1521 if (FontChanged != null)
\r
1522 FontChanged (this, e);
\r
1525 protected virtual void OnForeColorChanged (EventArgs e)
\r
1527 if (ForeColorChanged != null)
\r
1528 ForeColorChanged (this, e);
\r
1531 protected virtual void OnGiveFeedback (GiveFeedbackEventArgs e)
\r
1533 if (GiveFeedback != null)
\r
1534 GiveFeedback (this, e);
\r
1537 //Compact Framework
\r
1538 protected virtual void OnGotFocus (EventArgs e)
\r
1540 if (GotFocus != null)
\r
1541 GotFocus (this, e);
\r
1544 protected virtual void OnHandleCreated (EventArgs e)
\r
1546 Console.WriteLine ("OnHandleCreated");
\r
1548 //if( font != null) {
\r
1549 // Win32.SendMessage( Handle, Msg.WM_SETFONT, font.ToHfont().ToInt32(), 0);
\r
1551 Win32.SendMessage( Handle, Msg.WM_SETFONT, Font.ToHfont().ToInt32(), 0);
\r
1552 Win32.SetWindowText( Handle, text);
\r
1554 if (HandleCreated != null)
\r
1555 HandleCreated (this, e);
\r
1557 // create all child windows
\r
1558 IEnumerator cw = childControls.GetEnumerator();
\r
1560 while (cw.MoveNext()) {
\r
1561 Console.WriteLine ("Adding Control");
\r
1562 Control control = (Control) cw.Current;
\r
1563 control.CreateControl ();
\r
1568 protected virtual void OnHandleDestroyed (EventArgs e)
\r
1570 if( Handle != IntPtr.Zero) {
\r
1571 controlsCollection.Remove(Handle);
\r
1574 if (HandleDestroyed != null) {
\r
1575 HandleDestroyed (this, e);
\r
1579 protected virtual void OnHelpRequested (HelpEventArgs e)
\r
1581 if (HelpRequested != null)
\r
1582 HelpRequested (this, e);
\r
1585 protected virtual void OnImeModeChanged (EventArgs e)
\r
1587 if (ImeModeChanged != null)
\r
1588 ImeModeChanged (this, e);
\r
1591 protected virtual void OnInvalidated (InvalidateEventArgs e)
\r
1593 if (Invalidated != null)
\r
1594 Invalidated (this, e);
\r
1597 //Compact Framework
\r
1598 protected virtual void OnKeyDown (KeyEventArgs e)
\r
1600 if (KeyDown != null)
\r
1601 KeyDown (this, e);
\r
1604 //Compact Framework
\r
1605 protected virtual void OnKeyPress (KeyPressEventArgs e)
\r
1607 if (KeyPress != null)
\r
1608 KeyPress (this, e);
\r
1611 //Compact Framework
\r
1612 protected virtual void OnKeyUp (KeyEventArgs e)
\r
1614 if (KeyUp != null)
\r
1619 protected virtual void OnLayout (LayoutEventArgs e)
\r
1621 if (Layout != null)
\r
1625 protected virtual void OnLeave (EventArgs e)
\r
1627 if (Leave != null)
\r
1631 protected virtual void OnLocationChanged (EventArgs e)
\r
1633 if (LocationChanged != null)
\r
1634 LocationChanged (this, e);
\r
1637 //Compact Framework
\r
1638 protected virtual void OnLostFocus (EventArgs e)
\r
1640 if (LostFocus != null)
\r
1641 LostFocus (this, e);
\r
1644 //Compact Framework
\r
1645 protected virtual void OnMouseDown (MouseEventArgs e)
\r
1647 if (MouseDown != null)
\r
1648 MouseDown (this, e);
\r
1651 protected virtual void OnMouseEnter (EventArgs e)
\r
1653 //System.Console.WriteLine("OnMouseEnter");
\r
1654 if (MouseEnter != null)
\r
1655 MouseEnter (this, e);
\r
1658 protected virtual void OnMouseHover (EventArgs e)
\r
1660 if (MouseHover != null)
\r
1661 MouseHover (this, e);
\r
1664 protected virtual void OnMouseLeave (EventArgs e)
\r
1666 //System.Console.WriteLine("OnMouseLeave");
\r
1668 mouseIsInside_ = false;
\r
1669 if (MouseLeave != null)
\r
1670 MouseLeave (this, e);
\r
1673 //Compact Framework
\r
1674 protected virtual void OnMouseMove (MouseEventArgs e)
\r
1676 // If enter and mouse pressed - do not process
\r
1677 if( ((e.Button & MouseButtons.Left) != 0) && !mouseIsInside_) return;
\r
1679 if( !mouseIsInside_) {
\r
1680 TRACKMOUSEEVENT tme = new TRACKMOUSEEVENT();
\r
1682 tme.hWnd = Handle;
\r
1683 tme.dwFlags = (int)TrackerEventFlags.TME_LEAVE;
\r
1684 tme.dwHoverTime = 0;
\r
1686 bool result = Win32.TrackMouseEvent(ref tme);
\r
1688 System.Console.WriteLine("{0}",Win32.FormatMessage(Win32.GetLastError()));
\r
1692 POINT pt = new POINT();
\r
1695 Win32.ClientToScreen(Handle, ref pt);
\r
1696 IntPtr wndUnderMouse = Win32.WindowFromPoint(pt);
\r
1698 if( wndUnderMouse != Handle) {
\r
1699 // we are outside of the window
\r
1700 if( mouseIsInside_) {
\r
1701 OnMouseLeave(new EventArgs());
\r
1702 mouseIsInside_ = false;
\r
1706 if( !mouseIsInside_) {
\r
1707 mouseIsInside_ = true;
\r
1708 OnMouseEnter(new EventArgs());
\r
1711 if (MouseMove != null)
\r
1712 MouseMove (this, e);
\r
1715 //Compact Framework
\r
1716 protected virtual void OnMouseUp (MouseEventArgs e)
\r
1718 if (MouseUp != null)
\r
1719 MouseUp (this, e);
\r
1722 protected virtual void OnMouseWheel (MouseEventArgs e)
\r
1724 if (MouseWheel != null)
\r
1725 MouseWheel (this, e);
\r
1728 protected virtual void OnMove (EventArgs e)
\r
1734 protected virtual void OnNotifyMessage (Message m)
\r
1739 //Compact Framework
\r
1740 protected virtual void OnPaint (PaintEventArgs e)
\r
1742 if (Paint != null)
\r
1746 //Compact Framework
\r
1747 protected virtual void OnPaintBackground (PaintEventArgs e)
\r
1752 protected virtual void OnParentBackColorChanged (EventArgs e)
\r
1754 if (BackColorChanged != null)
\r
1755 BackColorChanged (this, e);
\r
1758 protected virtual void OnParentBackgroundImageChanged (
\r
1761 if (BackgroundImageChanged != null)
\r
1762 BackgroundImageChanged (this, e);
\r
1765 protected virtual void OnParentBindingContextChanged (
\r
1768 if (BindingContextChanged != null)
\r
1769 BindingContextChanged (this, e);
\r
1772 //Compact Framework
\r
1773 protected virtual void OnParentChanged (EventArgs e)
\r
1775 if (ParentChanged != null)
\r
1776 ParentChanged (this, e);
\r
1779 protected virtual void OnParentEnabledChanged (EventArgs e)
\r
1781 if (EnabledChanged != null)
\r
1782 EnabledChanged (this, e);
\r
1785 protected virtual void OnParentFontChanged (EventArgs e)
\r
1787 if (FontChanged != null)
\r
1788 FontChanged (this, e);
\r
1791 protected virtual void OnParentForeColorChanged (EventArgs e)
\r
1793 if (ForeColorChanged != null)
\r
1794 ForeColorChanged (this, e);
\r
1797 protected virtual void OnParentRightToLeftChanged (
\r
1800 if (RightToLeftChanged != null)
\r
1801 RightToLeftChanged (this, e);
\r
1804 protected virtual void OnParentVisibleChanged (EventArgs e)
\r
1806 if (VisibleChanged != null)
\r
1807 VisibleChanged (this, e);
\r
1810 protected virtual void OnQueryContinueDrag (
\r
1811 QueryContinueDragEventArgs e)
\r
1813 if (QueryContinueDrag != null)
\r
1814 QueryContinueDrag (this, e);
\r
1817 //Compact Framework
\r
1818 protected virtual void OnResize (EventArgs e)
\r
1820 if (Resize != null)
\r
1824 protected virtual void OnRightToLeftChanged (EventArgs e)
\r
1826 if (RightToLeftChanged != null)
\r
1827 RightToLeftChanged (this, e);
\r
1830 protected virtual void OnSizeChanged (EventArgs e)
\r
1832 if (SizeChanged != null)
\r
1833 SizeChanged (this, e);
\r
1836 protected virtual void OnStyleChanged (EventArgs e)
\r
1838 if (StyleChanged != null)
\r
1839 StyleChanged (this, e);
\r
1842 protected virtual void OnSystemColorsChanged (EventArgs e)
\r
1844 if (SystemColorsChanged != null)
\r
1845 SystemColorsChanged (this, e);
\r
1848 protected virtual void OnTabIndexChanged (EventArgs e)
\r
1850 if (TabIndexChanged != null)
\r
1851 TabIndexChanged (this, e);
\r
1854 protected virtual void OnTabStopChanged (EventArgs e)
\r
1856 if (TabStopChanged != null)
\r
1857 TabStopChanged (this, e);
\r
1860 //Compact Framework
\r
1861 protected virtual void OnTextChanged (EventArgs e)
\r
1863 if (TextChanged != null)
\r
1864 TextChanged (this, e);
\r
1867 //[MonoTODO] // this doesn't seem to be documented
\r
1868 // protected virtual void OnTextAlignChanged (EventArgs e) {
\r
1869 // TextAlignChanged (this, e);
\r
1872 protected virtual void OnValidated (EventArgs e)
\r
1874 if (Validated != null)
\r
1875 Validated (this, e);
\r
1879 // CancelEventArgs not ready
\r
1880 //protected virtual void OnValidating(CancelEventArgs e)
\r
1882 // throw new NotImplementedException ();
\r
1886 protected virtual void OnVisibleChanged (EventArgs e)
\r
1888 if (VisibleChanged != null)
\r
1889 VisibleChanged (this, e);
\r
1891 // --- end of methods for events ---
\r
1895 public void PerformLayout ()
\r
1901 public void PerformLayout (Control affectedControl,
\r
1902 string affectedProperty)
\r
1907 //Compact Framework
\r
1909 public Point PointToClient (Point p)
\r
1911 throw new NotImplementedException ();
\r
1914 //Compact Framework
\r
1916 public Point PointToScreen (Point p)
\r
1918 throw new NotImplementedException ();
\r
1922 public virtual bool PreProcessMessage (ref Message msg)
\r
1924 throw new NotImplementedException ();
\r
1928 protected virtual bool ProcessCmdKey (ref Message msg,
\r
1931 throw new NotImplementedException ();
\r
1935 protected virtual bool ProcessDialogChar (char charCode)
\r
1937 throw new NotImplementedException ();
\r
1941 protected virtual bool ProcessDialogKey (Keys keyData)
\r
1943 throw new NotImplementedException ();
\r
1947 protected virtual bool ProcessKeyEventArgs (ref Message m)
\r
1949 throw new NotImplementedException ();
\r
1953 protected internal virtual bool ProcessKeyMessage (
\r
1956 throw new NotImplementedException ();
\r
1960 protected virtual bool ProcessKeyPreview (ref Message m)
\r
1962 throw new NotImplementedException ();
\r
1966 protected virtual bool ProcessMnemonic (char charCode)
\r
1968 throw new NotImplementedException ();
\r
1971 // used when properties/values of Control
\r
1972 // are big enough to warrant recreating the HWND
\r
1973 protected void RecreateHandle()
\r
1975 recreatingHandle = true;
\r
1976 if( IsHandleCreated) {
\r
1980 recreatingHandle = false;
\r
1983 //Compact Framework
\r
1985 public Rectangle RectangleToClient (Rectangle r)
\r
1987 // FIXME: What to return if Handle is not created yet ?
\r
1988 RECT rect = new RECT();
\r
1989 rect.left = r.Left;
\r
1991 rect.right = r.Right;
\r
1992 rect.bottom = r.Bottom;
\r
1993 Win32.ScreenToClient(Handle,ref rect);
\r
1994 return new Rectangle( rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
\r
1997 //Compact Framework
\r
1999 public Rectangle RectangleToScreen (Rectangle r)
\r
2001 // FIXME: What to return if Handle is not created yet ?
\r
2002 RECT rect = new RECT();
\r
2003 rect.left = r.Left;
\r
2005 rect.right = r.Right;
\r
2006 rect.bottom = r.Bottom;
\r
2007 Win32.ClientToScreen(Handle,ref rect);
\r
2008 return new Rectangle( rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
\r
2012 protected static bool ReflectMessage (IntPtr hWnd, ref Message m) {
\r
2013 bool result = false;
\r
2014 Control cntrl = Control.FromHandle( hWnd);
\r
2015 if( cntrl != null) {
\r
2016 cntrl.WndProc(ref m);
\r
2022 //Compact Framework
\r
2023 public virtual void Refresh ()
\r
2025 //RECT rect = (RECT) null;
\r
2026 //InvalidateRect (Handle, ref rect, true);
\r
2027 Win32.UpdateWindow (Handle);
\r
2031 public virtual void ResetBackColor ()
\r
2037 public void ResetBindings ()
\r
2043 public virtual void ResetFont ()
\r
2049 public virtual void ResetForeColor ()
\r
2055 public void ResetImeMode ()
\r
2061 public virtual void ResetRightToLeft ()
\r
2067 public virtual void ResetText ()
\r
2073 public void ResumeLayout ()
\r
2079 public void ResumeLayout (bool performLayout)
\r
2085 protected ContentAlignment RtlTranslateAlignment (
\r
2086 ContentAlignment align)
\r
2088 throw new NotImplementedException ();
\r
2092 protected HorizontalAlignment RtlTranslateAlignment (
\r
2093 HorizontalAlignment align)
\r
2095 throw new NotImplementedException ();
\r
2099 protected LeftRightAlignment RtlTranslateAlignment (
\r
2100 LeftRightAlignment align)
\r
2102 throw new NotImplementedException ();
\r
2106 protected ContentAlignment RtlTranslateContent (
\r
2107 ContentAlignment align)
\r
2109 throw new NotImplementedException ();
\r
2113 protected HorizontalAlignment RtlTranslateHorizontal (
\r
2114 HorizontalAlignment align)
\r
2116 throw new NotImplementedException ();
\r
2120 protected LeftRightAlignment RtlTranslateLeftRight (
\r
2121 LeftRightAlignment align)
\r
2123 throw new NotImplementedException ();
\r
2127 public void Scale (float ratio)
\r
2133 public void Scale (float dx,float dy)
\r
2139 protected virtual void ScaleCore (float dx, float dy)
\r
2145 public void Select ()
\r
2151 protected virtual void Select (bool directed,bool forward)
\r
2157 public bool SelectNextControl (Control ctl, bool forward,
\r
2158 bool tabStopOnly,
\r
2159 bool nested, bool wrap)
\r
2161 throw new NotImplementedException ();
\r
2164 //Compact Framework
\r
2166 public void SendToBack ()
\r
2172 public void SetBounds (int x, int y, int width, int height)
\r
2174 SetBounds(x, y, width, height, BoundsSpecified.All);
\r
2178 public void SetBounds (int x, int y, int width, int height, BoundsSpecified specified)
\r
2180 SetBoundsCore( x, y, width, height, specified);
\r
2184 protected virtual void SetBoundsCore ( int x, int y, int width, int height, BoundsSpecified specified)
\r
2186 if( IsHandleCreated) {
\r
2187 // SetWindowPosFlags flags = SetWindowPosFlags.SWP_NOOWNERZORDER | SetWindowPosFlags.SWP_NOZORDER |
\r
2188 // SetWindowPosFlags.SWP_FRAMECHANGED | SetWindowPosFlags.SWP_DRAWFRAME;
\r
2189 SetWindowPosFlags flags = SetWindowPosFlags.SWP_NOZORDER |
\r
2190 SetWindowPosFlags.SWP_FRAMECHANGED | SetWindowPosFlags.SWP_DRAWFRAME;
\r
2191 Win32.SetWindowPos( Handle, SetWindowPosZOrder.HWND_NOTOPMOST, x, y, width, height, flags);
\r
2192 RECT rect = new RECT();
\r
2193 Win32.GetWindowRect (Handle, ref rect);
\r
2194 if( Parent != null) {
\r
2195 Win32.ScreenToClient(Parent.Handle, ref rect);
\r
2197 bounds = new Rectangle (rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
\r
2200 if( (specified & BoundsSpecified.X) != 0) {
\r
2203 if( (specified & BoundsSpecified.Y) != 0) {
\r
2206 if( (specified & BoundsSpecified.Width) != 0) {
\r
2207 bounds.Width = width;
\r
2209 if( (specified & BoundsSpecified.Height) != 0) {
\r
2210 bounds.Height = height;
\r
2216 protected virtual void SetClientSizeCore (int x, int y)
\r
2222 protected void SetStyle (ControlStyles flag, bool value)
\r
2227 protected void SetTopLevel (bool value)
\r
2230 // FIXME: verify on whether this is supposed
\r
2231 // to activate/deactive the window
\r
2232 Win32.SetWindowPos (Handle,
\r
2233 SetWindowPosZOrder.HWND_NOTOPMOST,
\r
2236 // FIXME: this does not make sense but
\r
2237 // the docs say the window is hidden
\r
2238 Win32.ShowWindow (Handle, ShowWindowStyles.SW_HIDE);
\r
2242 protected virtual void SetVisibleCore (bool value)
\r
2247 //Compact Framework
\r
2248 public void Show ()
\r
2250 Win32.ShowWindow (Handle, ShowWindowStyles.SW_SHOW);
\r
2254 public void SuspendLayout ()
\r
2259 //Compact Framework
\r
2260 public void Update ()
\r
2262 Win32.UpdateWindow (Handle);
\r
2266 protected void UpdateBounds ()
\r
2272 protected void UpdateBounds (int x, int y, int width, int height)
\r
2278 protected void UpdateBounds (
\r
2279 int x, int y, int width, int height, int clientWidth,
\r
2286 protected void UpdateStyles ()
\r
2292 protected void UpdateZOrder ()
\r
2298 internal MouseEventArgs Msg2MouseEventArgs( ref Message msg) {
\r
2299 MouseButtons mb = MouseButtons.None;
\r
2300 KeyStatusFlags keyIndicator = (KeyStatusFlags)msg.WParam.ToInt32();
\r
2301 if( (keyIndicator & KeyStatusFlags.MK_LBUTTON) != 0) {
\r
2302 mb |= MouseButtons.Left;
\r
2304 if( (keyIndicator & KeyStatusFlags.MK_RBUTTON) != 0) {
\r
2305 mb |= MouseButtons.Right;
\r
2307 if( (keyIndicator & KeyStatusFlags.MK_MBUTTON) != 0) {
\r
2308 mb |= MouseButtons.Middle;
\r
2310 if( (keyIndicator & KeyStatusFlags.MK_XBUTTON1) != 0) {
\r
2311 mb |= MouseButtons.XButton1;
\r
2313 if( (keyIndicator & KeyStatusFlags.MK_XBUTTON2) != 0) {
\r
2314 mb |= MouseButtons.XButton2;
\r
2317 return new MouseEventArgs( mb, (mb != MouseButtons.None) ? 1: 0, msg.LoWordLParam, msg.HiWordLParam, 0);
\r
2320 // WndProc - calls appriate On... function for the give
\r
2323 // These On... functions do not appear to be called by
\r
2326 // background color/image handled by WinForms
\r
2327 // OnBackColorChanged
\r
2328 // OnBackgroundImageChanged
\r
2329 // OnForeColorChanged
\r
2330 // OnPaintBackground
\r
2332 // controls are added/removed by WinForms
\r
2334 // OnControlRemoved
\r
2335 // OnCreateControl
\r
2337 // OnBindingContextChanged
\r
2338 // OnCausesValidationChanged
\r
2340 // OnContextMenuChanged
\r
2341 // OnRightToLeftChanged
\r
2345 // OnCursorChanged
\r
2346 // OnTextAlignChanged
\r
2349 // OnTabIndexChanged
\r
2350 // OnTabStopChanged
\r
2351 // OnLocationChanged
\r
2353 // FIXME: may be one of the WM_IME_ messages
\r
2354 // OnImeModeChanged
\r
2356 // InvalidateRect is called by no Invalidate message exists
\r
2359 // these messages ARE not called by WNDPROC according to docs
\r
2360 // OnParentBackColorChanged
\r
2361 // OnParentBackgroundImageChanged
\r
2362 // OnParentBindingContextChanged
\r
2363 // OnParentChanged
\r
2364 // OnParentEnabledChanged
\r
2365 // OnParentFontChanged
\r
2366 // OnParentForeColorChanged
\r
2367 // OnParentRightToLeftChanged
\r
2368 // OnParentVisibleChanged
\r
2370 protected virtual void WndProc(ref Message m)
\r
2372 EventArgs eventArgs = new EventArgs ();
\r
2373 // FIXME: paintEventArgs is not being created properly
\r
2374 // FIXME: Graphics does not have a public constructor, you must get one from .NET
\r
2375 //PaintEventArgs paintEventArgs = new PaintEventArgs (
\r
2376 // new Graphics(), new Rectangle());
\r
2378 if( (uint)m.Msg == Control.InvokeMessage) {
\r
2379 ControlInvokeHelper helper = null;
\r
2380 lock( InvokeQueue_.SyncRoot) {
\r
2381 if( InvokeQueue_.Count > 0) {
\r
2382 helper = (ControlInvokeHelper)InvokeQueue_.Dequeue();
\r
2385 if( helper != null) {
\r
2386 helper.ExecuteMethod();
\r
2390 else if( m.Msg == Msg.WM_COMMAND) {
\r
2392 m.Result = (IntPtr)1;
\r
2393 OnWmCommand (ref m);
\r
2394 if( m.Result != IntPtr.Zero) {
\r
2395 CallControlWndProc (ref m);
\r
2401 case Msg.WM_CREATE:
\r
2402 Console.WriteLine ("WM_CREATE");
\r
2403 OnHandleCreated (eventArgs);
\r
2405 case Msg.WM_LBUTTONDBLCLK:
\r
2406 OnDoubleClick (eventArgs);
\r
2407 CallControlWndProc(ref m);
\r
2413 // OnQueryContinueDrag
\r
2414 case Msg.WM_ENABLE:
\r
2415 OnEnabledChanged (eventArgs);
\r
2416 CallControlWndProc(ref m);
\r
2418 case Msg.WM_SETFOCUS:
\r
2419 OnEnter (eventArgs);
\r
2420 OnGotFocus (eventArgs);
\r
2421 CallControlWndProc(ref m);
\r
2423 case Msg.WM_FONTCHANGE:
\r
2424 OnFontChanged (eventArgs);
\r
2425 CallControlWndProc(ref m);
\r
2427 case Msg.WM_DESTROY:
\r
2428 OnHandleDestroyed (eventArgs);
\r
2429 CallControlWndProc(ref m);
\r
2433 //OnHelpRequested (eventArgs);
\r
2434 CallControlWndProc(ref m);
\r
2436 case Msg.WM_KEYDOWN:
\r
2438 // OnKeyDown (eventArgs);
\r
2439 CallControlWndProc(ref m);
\r
2443 // OnKeyPress (eventArgs);
\r
2444 CallControlWndProc(ref m);
\r
2446 case Msg.WM_KEYUP:
\r
2448 OnKeyUp ( new KeyEventArgs ( (Keys)m.WParam.ToInt32() ) );
\r
2449 CallControlWndProc(ref m);
\r
2451 case Msg.WM_KILLFOCUS:
\r
2452 OnLeave (eventArgs);
\r
2453 OnLostFocus (eventArgs);
\r
2454 CallControlWndProc(ref m);
\r
2456 case Msg.WM_MOUSEACTIVATE:
\r
2457 //OnMouseEnter (eventArgs);
\r
2458 CallControlWndProc(ref m);
\r
2460 case Msg.WM_MOUSEHOVER: // called by TrackMouseEvent
\r
2461 OnMouseHover (eventArgs);
\r
2462 CallControlWndProc(ref m);
\r
2464 case Msg.WM_MOUSELEAVE: // called by TrackMouseEvent
\r
2465 OnMouseLeave (eventArgs);
\r
2466 CallControlWndProc(ref m);
\r
2468 case Msg.WM_MOUSEMOVE:
\r
2470 OnMouseMove (Msg2MouseEventArgs(ref m));
\r
2471 CallControlWndProc(ref m);
\r
2473 case Msg.WM_LBUTTONDOWN:
\r
2475 //OnMouseDown (eventArgs);
\r
2476 CallControlWndProc(ref m);
\r
2478 case Msg.WM_LBUTTONUP:
\r
2480 //OnMouseUp (eventArgs);
\r
2481 CallControlWndProc(ref m);
\r
2483 case Msg.WM_MOUSEWHEEL:
\r
2485 //OnMouseWheel (eventArgs);
\r
2486 CallControlWndProc(ref m);
\r
2489 OnMove (eventArgs);
\r
2490 CallControlWndProc(ref m);
\r
2492 case Msg.WM_NOTIFY:
\r
2493 // FIXME: get NM_CLICKED msg from pnmh
\r
2494 // OnClick (eventArgs);
\r
2495 //OnNotifyMessage (eventArgs);
\r
2496 CallControlWndProc(ref m);
\r
2498 case Msg.WM_PAINT:
\r
2499 if( ControlRealWndProc != IntPtr.Zero) {
\r
2500 CallControlWndProc(ref m);
\r
2503 PAINTSTRUCT ps = new PAINTSTRUCT();
\r
2504 IntPtr hdc = Win32.BeginPaint( Handle, ref ps);
\r
2505 Rectangle rc = new Rectangle();
\r
2506 rc.X = ps.rcPaint.left;
\r
2507 rc.Y = ps.rcPaint.top;
\r
2508 rc.Width = ps.rcPaint.right - ps.rcPaint.left;
\r
2509 rc.Height = ps.rcPaint.bottom - ps.rcPaint.top;
\r
2510 PaintEventArgs paintEventArgs = new PaintEventArgs( Graphics.FromHdc(hdc), rc);
\r
2511 OnPaint (paintEventArgs);
\r
2512 paintEventArgs.Dispose();
\r
2513 Win32.EndPaint(Handle, ref ps);
\r
2517 OnResize (eventArgs);
\r
2518 OnSizeChanged (eventArgs);
\r
2519 CallControlWndProc(ref m);
\r
2521 case Msg.WM_STYLECHANGED:
\r
2522 OnStyleChanged (eventArgs);
\r
2523 CallControlWndProc(ref m);
\r
2525 case Msg.WM_SYSCOLORCHANGE:
\r
2526 OnSystemColorsChanged (eventArgs);
\r
2527 CallControlWndProc(ref m);
\r
2529 case Msg.WM_SETTEXT:
\r
2530 OnTextChanged (eventArgs);
\r
2531 CallControlWndProc(ref m);
\r
2533 case Msg.WM_SHOWWINDOW:
\r
2534 OnVisibleChanged (eventArgs);
\r
2535 CallControlWndProc(ref m);
\r
2537 case Msg.WM_CTLCOLORLISTBOX:
\r
2538 Win32.SetTextColor( m.WParam, Win32.RGB(ForeColor));
\r
2539 //Win32.SetBkColor( m.WParam, 0x00FF00);
\r
2540 //m.Result = Win32.GetStockObject(GSO_.LTGRAY_BRUSH);
\r
2542 case Msg.WM_MEASUREITEM:
\r
2543 ReflectMessage( m.WParam, ref m);
\r
2545 case Msg.WM_DRAWITEM:
\r
2546 Control.ReflectMessage( m.WParam, ref m);
\r
2549 CallControlWndProc(ref m);
\r
2551 if( ControlRealWndProc != IntPtr.Zero) {
\r
2552 CallControlWndProc(ref m);
\r
2555 DefWndProc (ref m);
\r
2562 /// --- Control: events ---
\r
2563 public event EventHandler BackColorChanged;
\r
2564 public event EventHandler BackgroundImageChanged;
\r
2565 public event EventHandler BindingContextChanged;
\r
2566 public event EventHandler CausesValidationChanged;
\r
2567 public event UICuesEventHandler ChangeUICues;
\r
2569 //Compact Framework
\r
2570 public event EventHandler Click;
\r
2572 public event EventHandler ContextMenuChanged;
\r
2573 public event ControlEventHandler ControlAdded;
\r
2574 public event ControlEventHandler ControlRemoved;
\r
2575 public event EventHandler CursorChanged;
\r
2576 public event EventHandler DockChanged;
\r
2577 public event EventHandler DoubleClick;
\r
2578 public event DragEventHandler DragDrop;
\r
2579 public event DragEventHandler DragEnter;
\r
2580 public event EventHandler DragLeave;
\r
2581 public event DragEventHandler DragOver;
\r
2583 //Compact Framework
\r
2584 public event EventHandler EnabledChanged;
\r
2586 public event EventHandler Enter;
\r
2587 public event EventHandler FontChanged;
\r
2588 public event EventHandler ForeColorChanged;
\r
2589 public event GiveFeedbackEventHandler GiveFeedback;
\r
2591 //Compact Framework
\r
2592 public event EventHandler GotFocus;
\r
2594 public event EventHandler HandleCreated;
\r
2595 public event EventHandler HandleDestroyed;
\r
2596 public event HelpEventHandler HelpRequested;
\r
2597 public event EventHandler ImeModeChanged;
\r
2598 public event InvalidateEventHandler Invalidated;
\r
2600 //Compact Framework
\r
2601 public event KeyEventHandler KeyDown;
\r
2603 //Compact Framework
\r
2604 public event KeyPressEventHandler KeyPress;
\r
2606 //Compact Framework
\r
2607 public event KeyEventHandler KeyUp;
\r
2609 public event LayoutEventHandler Layout;
\r
2610 public event EventHandler Leave;
\r
2611 public event EventHandler LocationChanged;
\r
2613 //Compact Framework
\r
2614 public event EventHandler LostFocus;
\r
2616 //Compact Framework
\r
2617 public event MouseEventHandler MouseDown;
\r
2619 public event EventHandler MouseEnter;
\r
2620 public event EventHandler MouseHover;
\r
2621 public event EventHandler MouseLeave;
\r
2623 //Compact Framework
\r
2624 public event MouseEventHandler MouseMove;
\r
2626 //Compact Framework
\r
2627 public event MouseEventHandler MouseUp;
\r
2629 public event MouseEventHandler MouseWheel;
\r
2630 public event EventHandler Move;
\r
2632 //Compact Framework
\r
2633 public event PaintEventHandler Paint;
\r
2635 //Compact Framework
\r
2636 public event EventHandler ParentChanged;
\r
2638 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
\r
2639 public event QueryContinueDragEventHandler QueryContinueDrag;
\r
2641 //Compact Framework
\r
2642 public event EventHandler Resize;
\r
2644 public event EventHandler RightToLeftChanged;
\r
2645 public event EventHandler SizeChanged;
\r
2646 public event EventHandler StyleChanged;
\r
2647 public event EventHandler SystemColorsChanged;
\r
2648 public event EventHandler TabIndexChanged;
\r
2649 public event EventHandler TabStopChanged;
\r
2651 //Compact Framework
\r
2652 public event EventHandler TextChanged;
\r
2654 public event EventHandler Validated;
\r
2656 // CancelEventHandler not yet defined
\r
2657 //public event CancelEventHandler Validating {
\r
2659 public event EventHandler VisibleChanged;
\r
2661 /// --- IWin32Window properties
\r
2662 public IntPtr Handle {
\r
2664 if (window != null)
\r
2665 return window.Handle;
\r
2666 return (IntPtr) 0;
\r
2670 /// --- ISynchronizeInvoke properties ---
\r
2672 public bool InvokeRequired {
\r
2674 return CreatorThreadId_ != Win32.GetCurrentThreadId();
\r
2678 private IAsyncResult DoInvoke( Delegate method, object[] args) {
\r
2679 IAsyncResult result = null;
\r
2680 ControlInvokeHelper helper = new ControlInvokeHelper(method, args);
\r
2681 if( InvokeRequired) {
\r
2683 lock( InvokeQueue_.SyncRoot) {
\r
2684 InvokeQueue_.Enqueue(helper);
\r
2686 Win32.PostMessage(Handle, Control.InvokeMessage, 0, 0);
\r
2691 helper.CompletedSynchronously = true;
\r
2692 helper.ExecuteMethod();
\r
2698 /// --- ISynchronizeInvoke methods ---
\r
2700 public IAsyncResult BeginInvoke (Delegate method)
\r
2702 return DoInvoke( method, null);
\r
2706 public IAsyncResult BeginInvoke (Delegate method, object[] args)
\r
2708 return DoInvoke( method, args);
\r
2712 public object EndInvoke (IAsyncResult asyncResult)
\r
2714 object result = null;
\r
2715 ControlInvokeHelper helper = asyncResult as ControlInvokeHelper;
\r
2716 if( helper != null) {
\r
2717 if( !asyncResult.CompletedSynchronously) {
\r
2718 asyncResult.AsyncWaitHandle.WaitOne();
\r
2720 result = helper.MethodResult;
\r
2725 //Compact Framework
\r
2727 public object Invoke (Delegate method)
\r
2729 return Invoke( method, null);
\r
2733 public object Invoke (Delegate method, object[] args)
\r
2735 IAsyncResult result = BeginInvoke(method, args);
\r
2736 return EndInvoke(result);
\r
2739 /// sub-class: Control.ControlAccessibleObject
\r
2741 /// Provides information about a control that can be used by an accessibility application.
\r
2743 public class ControlAccessibleObject : AccessibleObject {
\r
2744 // AccessibleObject not ready to be base class
\r
2745 /// --- ControlAccessibleObject.constructor ---
\r
2747 public ControlAccessibleObject (Control ownerControl)
\r
2749 throw new NotImplementedException ();
\r
2753 /// --- ControlAccessibleObject Properties ---
\r
2755 public override string DefaultAction {
\r
2758 return base.DefaultAction;
\r
2763 public override string Description {
\r
2766 return base.Description;
\r
2771 public IntPtr Handle {
\r
2773 throw new NotImplementedException ();
\r
2781 public override string Help {
\r
2789 public override string KeyboardShortcut {
\r
2792 return base.KeyboardShortcut;
\r
2797 public override string Name {
\r
2804 base.Name = value;
\r
2809 public Control Owner {
\r
2811 throw new NotImplementedException ();
\r
2816 public override AccessibleRole Role {
\r
2823 /// --- ControlAccessibleObject Methods ---
\r
2825 public override int GetHelpTopic(out string fileName)
\r
2828 return base.GetHelpTopic(out fileName);
\r
2832 public void NotifyClients (AccessibleEvents accEvent)
\r
2838 public void NotifyClients (AccessibleEvents accEvent,
\r
2845 public override string ToString ()
\r
2848 return base.ToString();
\r
2852 /// sub-class: Control.ControlCollection
\r
2854 /// Represents a collection of Control objects
\r
2856 public class ControlCollection : IList, ICollection, IEnumerable, ICloneable {
\r
2858 private ArrayList collection = new ArrayList ();
\r
2859 private Control owner;
\r
2861 /// --- ControlCollection.constructor ---
\r
2862 public ControlCollection (Control owner)
\r
2864 this.owner = owner;
\r
2867 /// --- ControlCollection Properties ---
\r
2868 public int Count {
\r
2870 return collection.Count;
\r
2874 public bool IsReadOnly {
\r
2876 return collection.IsReadOnly;
\r
2880 public virtual Control this [int index] {
\r
2882 return (Control) collection[index];
\r
2886 public virtual void Add (Control value)
\r
2888 if( !Contains(value)) {
\r
2889 value.parent = owner;
\r
2890 collection.Add (value);
\r
2894 public virtual void AddRange (Control[] controls)
\r
2896 for(int i = 0; i < controls.Length; i++) {
\r
2901 public virtual void Clear ()
\r
2903 collection.Clear ();
\r
2906 public bool Contains (Control control)
\r
2908 return collection.Contains (control);
\r
2911 public void CopyTo (Array dest,int index)
\r
2913 collection.CopyTo (dest, index);
\r
2917 public override bool Equals (object obj)
\r
2920 return base.Equals(obj);
\r
2924 public int GetChildIndex (Control child)
\r
2926 throw new NotImplementedException ();
\r
2929 public IEnumerator GetEnumerator ()
\r
2931 return collection.GetEnumerator ();
\r
2935 public override int GetHashCode ()
\r
2938 return base.GetHashCode();
\r
2941 public int IndexOf (Control control)
\r
2943 return collection.IndexOf (control);
\r
2946 public virtual void Remove (Control value)
\r
2948 collection.Remove (value);
\r
2951 public void RemoveAt (int index)
\r
2953 collection.RemoveAt (index);
\r
2957 public void SetChildIndex (Control child,int newIndex)
\r
2962 /// --- ControlCollection.IClonable methods ---
\r
2964 object ICloneable.Clone ()
\r
2966 throw new NotImplementedException ();
\r
2969 /// --- ControlCollection.IList properties ---
\r
2970 bool IList.IsFixedSize {
\r
2972 return collection.IsFixedSize;
\r
2976 object IList.this [int index] {
\r
2978 return collection[index];
\r
2981 collection[index] = value;
\r
2985 object ICollection.SyncRoot {
\r
2987 return collection.SyncRoot;
\r
2991 bool ICollection.IsSynchronized {
\r
2993 return collection.IsSynchronized;
\r
2997 /// --- ControlCollection.IList methods ---
\r
2998 int IList.Add (object control)
\r
3000 return collection.Add (control);
\r
3003 bool IList.Contains (object control)
\r
3005 return collection.Contains (control);
\r
3008 int IList.IndexOf (object control)
\r
3010 return collection.IndexOf (control);
\r
3013 void IList.Insert (int index,object value)
\r
3015 collection.Insert (index, value);
\r
3018 void IList.Remove (object control)
\r
3020 collection.Remove (control);
\r
3022 } // --- end of Control.ControlCollection ---
\r