dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/System.Windows.Forms Control.cs,1.17


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/System.Windows.Forms Control.cs,1.17,1.18 Form.cs,1.11,1.12 Message.cs,1.1,1.2 Win32Constants.cs,1.1,1.2
Date: Sun, 22 Jun 2003 21:04:23 -0400

Update of /cvsroot/dotgnu-pnet/pnetlib/System.Windows.Forms
In directory subversions:/tmp/cvs-serv2600/System.Windows.Forms

Modified Files:
        Control.cs Form.cs Message.cs Win32Constants.cs 
Log Message:


Implement key event dispatching.


Index: Control.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Windows.Forms/Control.cs,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -r1.17 -r1.18
*** Control.cs  22 Jun 2003 04:07:52 -0000      1.17
--- Control.cs  23 Jun 2003 01:04:21 -0000      1.18
***************
*** 71,74 ****
--- 71,75 ----
        private AccessibleObject accessibilityObject;
  #endif
+       private static Keys currentModifiers;
  
        // Constructors.
***************
*** 1175,1185 ****
  
        // Get the global state of the modifier keys.
-       [TODO]
        public static Keys ModifierKeys
                        {
                                get
                                {
!                                       // TODO
!                                       return Keys.None;
                                }
                        }
--- 1176,1184 ----
  
        // Get the global state of the modifier keys.
        public static Keys ModifierKeys
                        {
                                get
                                {
!                                       return (currentModifiers & 
Keys.Modifiers);
                                }
                        }
***************
*** 1640,1656 ****
  
        // Determine if a character is recognized by a control as an input char.
-       [TODO]
        protected virtual bool IsInputChar(char c)
                        {
!                               // TODO
!                               return false;
                        }
  
        // Determine if a key is recognized by a control as an input key.
-       [TODO]
        protected virtual bool IsInputKey(Keys keyData)
                        {
!                               // TODO
!                               return false;
                        }
  
--- 1639,1667 ----
  
        // Determine if a character is recognized by a control as an input char.
        protected virtual bool IsInputChar(char c)
                        {
!                               // By default, pass the request up to our 
parent.
!                               if(parent != null)
!                               {
!                                       return parent.IsInputChar(c);
!                               }
!                               else
!                               {
!                                       return true;
!                               }
                        }
  
        // Determine if a key is recognized by a control as an input key.
        protected virtual bool IsInputKey(Keys keyData)
                        {
!                               // By default, pass the request up to our 
parent.
!                               if(parent != null)
!                               {
!                                       return parent.IsInputKey(keyData);
!                               }
!                               else
!                               {
!                                       return true;
!                               }
                        }
  
***************
*** 1892,1939 ****
  
        // Process a dialog character.
-       [TODO]
        protected virtual bool ProcessDialogChar(char charCode)
                        {
!                               // TODO
!                               return false;
                        }
  
        // Process a dialog key.
-       [TODO]
        protected virtual bool ProcessDialogKey(Keys keyData)
                        {
!                               // TODO
!                               return false;
                        }
  
!       // Process a key event.
!       [TODO]
        protected virtual bool ProcessKeyEventArgs(ref Message msg)
                        {
!                               // TODO
!                               return false;
                        }
  
        // Process a keyboard message.
-       [TODO]
        protected internal virtual bool ProcessKeyMessage(ref Message msg)
                        {
!                               // TODO
!                               return false;
                        }
  
        // Preview a keyboard message.
-       [TODO]
        protected virtual bool ProcessKeyPreview(ref Message msg)
                        {
!                               // TODO
!                               return false;
                        }
  
        // Process a key mnemonic.
-       [TODO]
        protected virtual bool ProcessMnemonic(char charCode)
                        {
!                               // TODO
                                return false;
                        }
--- 1903,1998 ----
  
        // Process a dialog character.
        protected virtual bool ProcessDialogChar(char charCode)
                        {
!                               // By default, pass the message up to our 
parent.
!                               if(parent != null)
!                               {
!                                       return 
parent.ProcessDialogChar(charCode);
!                               }
!                               else
!                               {
!                                       return false;
!                               }
                        }
  
        // Process a dialog key.
        protected virtual bool ProcessDialogKey(Keys keyData)
                        {
!                               // By default, pass the message up to our 
parent.
!                               if(parent != null)
!                               {
!                                       return parent.ProcessDialogKey(keyData);
!                               }
!                               else
!                               {
!                                       return false;
!                               }
                        }
  
!       // Process a key event by turning it into its EventArgs form.
        protected virtual bool ProcessKeyEventArgs(ref Message msg)
                        {
!                               int msgNum = msg.Msg;
!                               KeyEventArgs args1;
!                               KeyPressEventArgs args2;
!                               if(msgNum == Win32Constants.WM_KEYDOWN)
!                               {
!                                       args1 = new KeyEventArgs(msg.key);
!                                       OnKeyDown(args1);
!                                       return args1.Handled;
!                               }
!                               else if(msgNum == Win32Constants.WM_KEYUP)
!                               {
!                                       args1 = new KeyEventArgs(msg.key);
!                                       OnKeyUp(args1);
!                                       return args1.Handled;
!                               }
!                               else if(msgNum == Win32Constants.WM_CHAR)
!                               {
!                                       args2 = new 
KeyPressEventArgs((char)(msg.key));
!                                       OnKeyPress(args2);
!                                       return args2.Handled;
!                               }
!                               else
!                               {
!                                       return false;
!                               }
                        }
  
        // Process a keyboard message.
        protected internal virtual bool ProcessKeyMessage(ref Message msg)
                        {
!                               // If we have a parent, then let it preview the 
event first.
!                               if(parent != null)
!                               {
!                                       if(parent.ProcessKeyPreview(ref msg))
!                                       {
!                                               return true;
!                                       }
!                               }
! 
!                               // Turn the event into its EventArgs form and 
dispatch it.
!                               return ProcessKeyEventArgs(ref msg);
                        }
  
        // Preview a keyboard message.
        protected virtual bool ProcessKeyPreview(ref Message msg)
                        {
!                               // By default, pass the message up to our 
parent.
!                               if(parent != null)
!                               {
!                                       return parent.ProcessKeyPreview(ref 
msg);
!                               }
!                               else
!                               {
!                                       return false;
!                               }
                        }
  
        // Process a key mnemonic.
        protected virtual bool ProcessMnemonic(char charCode)
                        {
!                               // By default, controls don't have mnemonics.
!                               // Overridden by subclasses that need mnemonics.
                                return false;
                        }
***************
*** 2344,2347 ****
--- 2403,2432 ----
                        }
  
+       // Pre-process a message before it is dispatched by the event loop.
+       public virtual bool PreProcessMessage(ref Message msg)
+                       {
+                               // Handle dialog and command keys.
+                               int msgNum = msg.Msg;
+                               if(msgNum == Win32Constants.WM_KEYDOWN)
+                               {
+                                       if(ProcessCmdKey(ref msg, msg.key))
+                                       {
+                                               return true;
+                                       }
+                                       if(!IsInputKey(msg.key))
+                                       {
+                                               return 
ProcessDialogKey(msg.key);
+                                       }
+                               }
+                               else if(msgNum == Win32Constants.WM_CHAR)
+                               {
+                                       if(!IsInputChar((char)(msg.key)))
+                                       {
+                                               return 
ProcessDialogChar((char)(msg.key));
+                                       }
+                               }
+                               return false;
+                       }
+ 
  #if !CONFIG_COMPACT_FORMS
  
***************
*** 2352,2362 ****
                        }
  
-       // Pre-process a message before it is dispatched by the event loop.
-       public virtual bool PreProcessMessage(ref Message msg)
-                       {
-                               // Window procedures are not used in this 
implementation.
-                               return false;
-                       }
- 
        // Process a message.
        protected virtual void WndProc(ref Message m)
--- 2437,2440 ----
***************
*** 4292,4310 ****
  
        // Toolkit event that is emitted for a key down event.
!       void IToolkitEventSink.ToolkitKeyDown(ToolkitKeys key)
                        {
!                               OnKeyDown(new KeyEventArgs((Keys)key));
                        }
  
        // Toolkit event that is emitted for a key up event.
!       void IToolkitEventSink.ToolkitKeyUp(ToolkitKeys key)
                        {
!                               OnKeyUp(new KeyEventArgs((Keys)key));
                        }
  
        // Toolkit event that is emitted for a key character event.
!       void IToolkitEventSink.ToolkitKeyChar(char charCode)
                        {
!                               OnKeyPress(new KeyPressEventArgs(charCode));
                        }
  
--- 4370,4414 ----
  
        // Toolkit event that is emitted for a key down event.
!       bool IToolkitEventSink.ToolkitKeyDown(ToolkitKeys key)
                        {
!                               // Create a fake key message and dispatch it.
!                               currentModifiers = (Keys)key;
!                               Message m = Message.CreateKeyMessage
!                                       (Win32Constants.WM_KEYDOWN, (Keys)key);
!                               if(PreProcessMessage(ref m))
!                               {
!                                       // The key was dispatched as a dialog 
or command key.
!                                       return true;
!                               }
!                               return ProcessKeyMessage(ref m);
                        }
  
        // Toolkit event that is emitted for a key up event.
!       bool IToolkitEventSink.ToolkitKeyUp(ToolkitKeys key)
                        {
!                               // Create a fake key message and dispatch it.
!                               currentModifiers = (Keys)key;
!                               Message m = Message.CreateKeyMessage
!                                       (Win32Constants.WM_KEYUP, (Keys)key);
!                               if(PreProcessMessage(ref m))
!                               {
!                                       // The key was dispatched as a dialog 
or command key.
!                                       return true;
!                               }
!                               return ProcessKeyMessage(ref m);
                        }
  
        // Toolkit event that is emitted for a key character event.
!       bool IToolkitEventSink.ToolkitKeyChar(char charCode)
                        {
!                               // Create a fake key character message and 
dispatch it.
!                               Message m = Message.CreateKeyMessage
!                                       (Win32Constants.WM_CHAR, 
(Keys)(int)charCode);
!                               if(PreProcessMessage(ref m))
!                               {
!                                       // The key was dispatched as a dialog 
or command key.
!                                       return true;
!                               }
!                               return ProcessKeyMessage(ref m);
                        }
  
***************
*** 4314,4317 ****
--- 4418,4422 ----
                                 int clicks, int x, int y, int delta)
                        {
+                               currentModifiers = (Keys)modifiers;
                                OnMouseDown(new MouseEventArgs
                                        ((MouseButtons)buttons, clicks, x, y, 
delta));
***************
*** 4323,4326 ****
--- 4428,4432 ----
                                 int clicks, int x, int y, int delta)
                        {
+                               currentModifiers = (Keys)modifiers;
                                OnMouseUp(new MouseEventArgs
                                        ((MouseButtons)buttons, clicks, x, y, 
delta));
***************
*** 4332,4335 ****
--- 4438,4442 ----
                                 int clicks, int x, int y, int delta)
                        {
+                               currentModifiers = (Keys)modifiers;
                                OnMouseHover(new MouseEventArgs
                                        ((MouseButtons)buttons, clicks, x, y, 
delta));
***************
*** 4341,4344 ****
--- 4448,4452 ----
                                 int clicks, int x, int y, int delta)
                        {
+                               currentModifiers = (Keys)modifiers;
                                OnMouseMove(new MouseEventArgs
                                        ((MouseButtons)buttons, clicks, x, y, 
delta));
***************
*** 4350,4353 ****
--- 4458,4462 ----
                                 int clicks, int x, int y, int delta)
                        {
+                               currentModifiers = (Keys)modifiers;
                                OnMouseWheel(new MouseEventArgs
                                        ((MouseButtons)buttons, clicks, x, y, 
delta));

Index: Form.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Windows.Forms/Form.cs,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -r1.11 -r1.12
*** Form.cs     22 Jun 2003 04:07:52 -0000      1.11
--- Form.cs     23 Jun 2003 01:04:21 -0000      1.12
***************
*** 1148,1155 ****
  
        // Preview a keyboard message.
-       [TODO]
        protected override bool ProcessKeyPreview(ref Message msg)
                        {
!                               // TODO
                                return base.ProcessKeyPreview(ref msg);
                        }
--- 1148,1161 ----
  
        // Preview a keyboard message.
        protected override bool ProcessKeyPreview(ref Message msg)
                        {
!                               if(keyPreview)
!                               {
!                                       // The form wants first crack at the 
key message.
!                                       if(ProcessKeyEventArgs(ref msg))
!                                       {
!                                               return true;
!                                       }
!                               }
                                return base.ProcessKeyPreview(ref msg);
                        }

Index: Message.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Windows.Forms/Message.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** Message.cs  11 Jun 2003 07:07:19 -0000      1.1
--- Message.cs  23 Jun 2003 01:04:21 -0000      1.2
***************
*** 23,27 ****
  {
  
! #if !CONFIG_COMPACT_FORMS
  
  public struct Message
--- 23,28 ----
  {
  
! // Note: while "Message" is not a Compact Forms class, we need it
! // to do proper key event dispatching.
  
  public struct Message
***************
*** 33,36 ****
--- 34,38 ----
        private IntPtr lParam;
        private IntPtr result;
+       internal Keys key;
  
        // Get or set the message parameters.
***************
*** 101,104 ****
--- 103,120 ----
                                value.lParam = lparam;
                                value.result = IntPtr.Zero;
+                               value.key = Keys.None;
+                               return value;
+                       }
+ 
+       // Create a fake key message.
+       internal static Message CreateKeyMessage(int msg, Keys key)
+                       {
+                               Message value;
+                               value.hWnd = IntPtr.Zero;
+                               value.msg = msg;
+                               value.wParam = new IntPtr((int)(key & 
Keys.KeyCode));
+                               value.lParam = IntPtr.Zero;
+                               value.result = IntPtr.Zero;
+                               value.key = key;
                                return value;
                        }
***************
*** 148,153 ****
  
  }; // struct Message
- 
- #endif // !CONFIG_COMPACT_FORMS
  
  }; // namespace System.Windows.Forms
--- 164,167 ----

Index: Win32Constants.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Windows.Forms/Win32Constants.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** Win32Constants.cs   11 Jun 2003 07:07:19 -0000      1.1
--- Win32Constants.cs   23 Jun 2003 01:04:21 -0000      1.2
***************
*** 98,101 ****
--- 98,111 ----
        public const int WS_EX_WINDOWEDGE               = 0x00000100;
  
+       // Message codes.
+       public const int WM_KEYDOWN                             = 256;
+       public const int WM_KEYUP                               = 257;
+       public const int WM_CHAR                                = 258;
+       public const int WM_DEADCHAR                    = 259;
+       public const int WM_SYSKEYDOWN                  = 260;
+       public const int WM_SYSKEYUP                    = 261;
+       public const int WM_SYSCHAR                             = 262;
+       public const int WM_SYSDEADCHAR                 = 263;
+ 
  }; // class Win32Constants
  





reply via email to

[Prev in Thread] Current Thread [Next in Thread]