[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-libs-commits] CVS: xsharp/Xsharp/XWindows KeyName.cs,NONE,1.1 Ev
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-libs-commits] CVS: xsharp/Xsharp/XWindows KeyName.cs,NONE,1.1 EventHandlers.cs,1.1.1.1,1.2 InputOnlyWidget.cs,1.1.1.1,1.2 InputOutputWidget.cs,1.1.1.1,1.2 Xlib.cs.in,1.1.1.1,1.2 |
Date: |
Fri, 27 Sep 2002 01:54:16 -0400 |
Update of /cvsroot/dotgnu-libs/xsharp/Xsharp/XWindows
In directory subversions:/tmp/cvs-serv32199/Xsharp/XWindows
Modified Files:
EventHandlers.cs InputOnlyWidget.cs InputOutputWidget.cs
Xlib.cs.in
Added Files:
KeyName.cs
Log Message:
Handle button and key events.
--- NEW FILE ---
/*
* KeyName.cs - Key name codes.
*
* This file is part of the X# library.
* Copyright (C) 2002 Southern Storm Software, Pty Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
[...1704 lines suppressed...]
XK_combining_acute = 0x1ef3,
XK_combining_hook = 0x1efe,
XK_combining_belowdot = 0x1eff,
XK_EcuSign = 0x20a0,
XK_ColonSign = 0x20a1,
XK_CruzeiroSign = 0x20a2,
XK_FFrancSign = 0x20a3,
XK_LiraSign = 0x20a4,
XK_MillSign = 0x20a5,
XK_NairaSign = 0x20a6,
XK_PesetaSign = 0x20a7,
XK_RupeeSign = 0x20a8,
XK_WonSign = 0x20a9,
XK_NewSheqelSign = 0x20aa,
XK_DongSign = 0x20ab,
XK_EuroSign = 0x20ac
} // enum KeyName
} // namespace XWindows
Index: EventHandlers.cs
===================================================================
RCS file: /cvsroot/dotgnu-libs/xsharp/Xsharp/XWindows/EventHandlers.cs,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** EventHandlers.cs 26 Sep 2002 10:32:41 -0000 1.1.1.1
--- EventHandlers.cs 27 Sep 2002 05:54:12 -0000 1.2
***************
*** 124,126 ****
--- 124,230 ----
public delegate bool ClosedEventHandler(Widget widget);
+ /// <summary>
+ /// <para>The <see cref="T:XWindows.ButtonPressEventHandler"/> delegate is
+ /// used to process button press events.</para>
+ /// </summary>
+ ///
+ /// <param name="widget">
+ /// <para>The widget that received the event.</para>
+ /// </param>
+ ///
+ /// <param name="x">
+ /// <para>The X co-ordinate of the pointer position.</para>
+ /// </param>
+ ///
+ /// <param name="y">
+ /// <para>The Y co-ordinate of the pointer position.</para>
+ /// </param>
+ ///
+ /// <param name="button">
+ /// <para>The button that was pressed.</para>
+ /// </param>
+ ///
+ /// <param name="modifiers">
+ /// <para>Other button and shift flags that were active.</para>
+ /// </param>
+ public delegate void ButtonPressEventHandler(Widget widget, int x, int y,
+
ButtonName button,
+
ModifierMask modifiers);
+
+ /// <summary>
+ /// <para>The <see cref="T:XWindows.ButtonReleaseEventHandler"/> delegate is
+ /// used to process button release events.</para>
+ /// </summary>
+ ///
+ /// <param name="widget">
+ /// <para>The widget that received the event.</para>
+ /// </param>
+ ///
+ /// <param name="x">
+ /// <para>The X co-ordinate of the pointer position.</para>
+ /// </param>
+ ///
+ /// <param name="y">
+ /// <para>The Y co-ordinate of the pointer position.</para>
+ /// </param>
+ ///
+ /// <param name="button">
+ /// <para>The button that was released.</para>
+ /// </param>
+ ///
+ /// <param name="modifiers">
+ /// <para>Other button and shift flags that were active.</para>
+ /// </param>
+ public delegate void ButtonReleaseEventHandler(Widget widget, int x, int y,
+
ButtonName button,
+
ModifierMask modifiers);
+
+ /// <summary>
+ /// <para>The <see cref="T:XWindows.KeyPressEventHandler"/> delegate is
+ /// used to process key press events.</para>
+ /// </summary>
+ ///
+ /// <param name="widget">
+ /// <para>The widget that received the event.</para>
+ /// </param>
+ ///
+ /// <param name="key">
+ /// <para>The key code.</para>
+ /// </param>
+ ///
+ /// <param name="modifiers">
+ /// <para>Other button and shift flags that were active.</para>
+ /// </param>
+ ///
+ /// <param name="str">
+ /// <para>The translated string that corresponds to the key, or
+ /// <see langword="null"/> if the key does not have a translation.</para>
+ /// </param>
+ ///
+ /// <remarks>The <paramref name="key"/> parameter indicates the X11
+ /// symbol that corresponds to the key, which allows cursor constrol
+ /// and function keys to be easily distinguished. The <paramref name="str"/>
+ /// is primarily of use to text input widgets.</remarks>
+ public delegate void KeyPressEventHandler(Widget widget, KeyName key,
+
ModifierMask modifiers, String str);
+
+ /// <summary>
+ /// <para>The <see cref="T:XWindows.KeyReleaseEventHandler"/> delegate is
+ /// used to process key release events.</para>
+ /// </summary>
+ ///
+ /// <param name="widget">
+ /// <para>The widget that received the event.</para>
+ /// </param>
+ ///
+ /// <param name="key">
+ /// <para>The key code.</para>
+ /// </param>
+ ///
+ /// <param name="modifiers">
+ /// <para>Other button and shift flags that were active.</para>
+ /// </param>
+ public delegate void KeyReleaseEventHandler(Widget widget, KeyName key,
+
ModifierMask modifiers);
+
} // namespace XWindows
Index: InputOnlyWidget.cs
===================================================================
RCS file: /cvsroot/dotgnu-libs/xsharp/Xsharp/XWindows/InputOnlyWidget.cs,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** InputOnlyWidget.cs 26 Sep 2002 10:32:42 -0000 1.1.1.1
--- InputOnlyWidget.cs 27 Sep 2002 05:54:12 -0000 1.2
***************
*** 24,28 ****
--- 24,30 ----
using System;
+ using System.Runtime.InteropServices;
using XWindows.Types;
+ using XWindows.Events;
/// <summary>
***************
*** 33,36 ****
--- 35,41 ----
public class InputOnlyWidget : Widget
{
+ // Internal state.
+ private InputEventHandlers handlers;
+
/// <summary>
/// <para>Constructs a new <see cref="T:XWindows.InputOnlyWidget"/>
***************
*** 229,232 ****
--- 234,767 ----
}
}
+
+ // Get the input handler list.
+ private InputEventHandlers GetHandlers()
+ {
+ if(handlers == null)
+ {
+ handlers = new InputEventHandlers();
+ }
+ return handlers;
+ }
+
+ /// <summary>
+ /// <para>Event that is raised when any mouse button is pressed
+ /// while the pointer is inside this widget.</para>
+ /// </summary>
+ public event ButtonPressEventHandler ButtonPress
+ {
+ add
+ {
+ lock(this)
+ {
+ InputEventHandlers handlers =
GetHandlers();
+
SelectInput(EventMask.ButtonPressMask);
+ handlers.press += value;
+ }
+ }
+ remove
+ {
+ lock(this)
+ {
+ if(handlers != null)
+ {
+ handlers.press -= value;
+
handlers.DeselectButtonPress(this);
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// <para>Event that is raised when any mouse button is released
+ /// while the pointer is inside this widget.</para>
+ /// </summary>
+ public event ButtonReleaseEventHandler ButtonRelease
+ {
+ add
+ {
+ lock(this)
+ {
+ InputEventHandlers handlers =
GetHandlers();
+
SelectInput(EventMask.ButtonReleaseMask);
+ handlers.release += value;
+ }
+ }
+ remove
+ {
+ lock(this)
+ {
+ if(handlers != null)
+ {
+ handlers.release -=
value;
+
handlers.DeselectButtonRelease(this);
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// <para>Event that is raised when any mouse button is double-clicked
+ /// while the pointer is inside this widget.</para>
+ /// </summary>
+ public event ButtonPressEventHandler ButtonDoubleClick
+ {
+ add
+ {
+ lock(this)
+ {
+ InputEventHandlers handlers =
GetHandlers();
+
SelectInput(EventMask.ButtonPressMask);
+ handlers.doubleClick += value;
+ }
+ }
+ remove
+ {
+ lock(this)
+ {
+ if(handlers != null)
+ {
+ handlers.doubleClick -=
value;
+
handlers.DeselectButtonPress(this);
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// <para>Event that is raised when the "Select" mouse button is pressed
+ /// while the pointer is inside this widget. Usually this is the
+ /// "Left" mouse button.</para>
+ /// </summary>
+ public event ButtonPressEventHandler SelectPress
+ {
+ add
+ {
+ lock(this)
+ {
+ InputEventHandlers handlers =
GetHandlers();
+
SelectInput(EventMask.ButtonPressMask);
+ handlers.selectPress += value;
+ }
+ }
+ remove
+ {
+ lock(this)
+ {
+ if(handlers != null)
+ {
+ handlers.selectPress -=
value;
+
handlers.DeselectButtonPress(this);
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// <para>Event that is raised when the "Select" mouse button is
released
+ /// while the pointer is inside this widget. Usually this is the
+ /// "Left" mouse button.</para>
+ /// </summary>
+ public event ButtonReleaseEventHandler SelectRelease
+ {
+ add
+ {
+ lock(this)
+ {
+ InputEventHandlers handlers =
GetHandlers();
+
SelectInput(EventMask.ButtonReleaseMask);
+ handlers.selectRelease += value;
+ }
+ }
+ remove
+ {
+ lock(this)
+ {
+ if(handlers != null)
+ {
+ handlers.selectRelease
-= value;
+
handlers.DeselectButtonRelease(this);
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// <para>Event that is raised when the "Select" mouse button is
+ /// double-clicked while the pointer is inside this widget.</para>
+ /// </summary>
+ public event ButtonPressEventHandler SelectDoubleClick
+ {
+ add
+ {
+ lock(this)
+ {
+ InputEventHandlers handlers =
GetHandlers();
+
SelectInput(EventMask.ButtonPressMask);
+ handlers.selectDoubleClick +=
value;
+ }
+ }
+ remove
+ {
+ lock(this)
+ {
+ if(handlers != null)
+ {
+
handlers.selectDoubleClick -= value;
+
handlers.DeselectButtonPress(this);
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// <para>Event that is raised when the "Menu" mouse button is pressed
+ /// while the pointer is inside this widget. Usually this is the
+ /// "Right" mouse button.</para>
+ /// </summary>
+ public event ButtonPressEventHandler MenuPress
+ {
+ add
+ {
+ lock(this)
+ {
+ InputEventHandlers handlers =
GetHandlers();
+
SelectInput(EventMask.ButtonPressMask);
+ handlers.menuPress += value;
+ }
+ }
+ remove
+ {
+ lock(this)
+ {
+ if(handlers != null)
+ {
+ handlers.menuPress -=
value;
+
handlers.DeselectButtonPress(this);
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// <para>Event that is raised when the "Menu" mouse button is released
+ /// while the pointer is inside this widget. Usually this is the
+ /// "Right" mouse button.</para>
+ /// </summary>
+ public event ButtonReleaseEventHandler MenuRelease
+ {
+ add
+ {
+ lock(this)
+ {
+ InputEventHandlers handlers =
GetHandlers();
+
SelectInput(EventMask.ButtonReleaseMask);
+ handlers.menuRelease += value;
+ }
+ }
+ remove
+ {
+ lock(this)
+ {
+ if(handlers != null)
+ {
+ handlers.menuRelease -=
value;
+
handlers.DeselectButtonRelease(this);
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// <para>Event that is raised when the "Menu" mouse button is
+ /// double-clicked while the pointer is inside this widget.</para>
+ /// </summary>
+ public event ButtonPressEventHandler MenuDoubleClick
+ {
+ add
+ {
+ lock(this)
+ {
+ InputEventHandlers handlers =
GetHandlers();
+
SelectInput(EventMask.ButtonPressMask);
+ handlers.menuDoubleClick +=
value;
+ }
+ }
+ remove
+ {
+ lock(this)
+ {
+ if(handlers != null)
+ {
+
handlers.menuDoubleClick -= value;
+
handlers.DeselectButtonPress(this);
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// <para>Event that is raised if a key is pressed when this
+ /// widget has the focus.</para>
+ /// </summary>
+ public event KeyPressEventHandler KeyPress
+ {
+ add
+ {
+ lock(this)
+ {
+ InputEventHandlers handlers =
GetHandlers();
+ handlers.keyPress += value;
+ }
+ }
+ remove
+ {
+ lock(this)
+ {
+ if(handlers != null)
+ {
+ handlers.keyPress -=
value;
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// <para>Event that is raised if a key is released when this
+ /// widget has the focus.</para>
+ /// </summary>
+ public event KeyReleaseEventHandler KeyRelease
+ {
+ add
+ {
+ lock(this)
+ {
+ InputEventHandlers handlers =
GetHandlers();
+ handlers.keyRelease += value;
+ }
+ }
+ remove
+ {
+ lock(this)
+ {
+ if(handlers != null)
+ {
+ handlers.keyRelease -=
value;
+ }
+ }
+ }
+ }
+
+ // Dispatch an event to this widget.
+ internal override void DispatchEvent(ref XEvent xevent)
+ {
+ lock(this)
+ {
+ if(handlers != null)
+ {
+ handlers.DispatchEvent(this,
ref xevent);
+ }
+ }
+ }
+
+ // Input event handling class. This is created only if the
+ // user selects for input events, to avoid wasting memory if
+ // no button/key events are desired on a particular widget.
+ private class InputEventHandlers
+ {
+ public ButtonPressEventHandler press;
+ public ButtonReleaseEventHandler release;
+ public ButtonPressEventHandler doubleClick;
+ public ButtonPressEventHandler selectPress;
+ public ButtonReleaseEventHandler selectRelease;
+ public ButtonPressEventHandler selectDoubleClick;
+ public ButtonPressEventHandler menuPress;
+ public ButtonReleaseEventHandler menuRelease;
+ public ButtonPressEventHandler menuDoubleClick;
+ public Xlib.Time lastClickTime;
+ public ButtonName lastClickButton;
+ public KeyPressEventHandler keyPress;
+ public KeyReleaseEventHandler keyRelease;
+ public IntPtr keyBuffer;
+
+ ~InputEventHandlers()
+ {
+ if(keyBuffer != IntPtr.Zero)
+ {
+ Marshal.FreeHGlobal(keyBuffer);
+ }
+ }
+
+ // Dispatch an event to the widget that owns this handler list.
+ public void DispatchEvent(Widget widget, ref XEvent xevent)
+ {
+ ButtonName button;
+ Xlib.Time time;
+
+ switch(xevent.type)
+ {
+ case EventType.ButtonPress:
+ {
+ // Process generic
button events.
+ button =
xevent.xbutton.button;
+ time =
xevent.xbutton.time;
+ if(doubleClick != null
&&
+ lastClickButton ==
button &&
+ lastClickTime !=
Xlib.Time.CurrentTime &&
+ (time -
lastClickTime) < 500)
+ {
+
doubleClick(widget, xevent.xbutton.x,
+
xevent.xbutton.y, button,
+
xevent.xbutton.state);
+ time =
Xlib.Time.CurrentTime;
+ }
+ else if(press != null)
+ {
+ press(widget,
xevent.xbutton.x,
+
xevent.xbutton.y, button,
+
xevent.xbutton.state);
+ }
+
+ // Process button
events for specific buttons.
+ if(button ==
ButtonName.Button1)
+ {
+
if(selectDoubleClick != null &&
+
lastClickButton == button &&
+
lastClickTime != Xlib.Time.CurrentTime &&
+ (time -
lastClickTime) < 500)
+ {
+
selectDoubleClick(widget, xevent.xbutton.x,
+
xevent.xbutton.y, button,
+
xevent.xbutton.state);
+ time =
Xlib.Time.CurrentTime;
+ }
+ else
if(selectPress != null)
+ {
+
selectPress(widget, xevent.xbutton.x,
+
xevent.xbutton.y, button,
+
xevent.xbutton.state);
+ }
+ }
+ else
+ {
+
if(menuDoubleClick != null &&
+
lastClickButton == button &&
+
lastClickTime != Xlib.Time.CurrentTime &&
+ (time -
lastClickTime) < 500)
+ {
+
menuDoubleClick(widget, xevent.xbutton.x,
+
xevent.xbutton.y, button,
+
xevent.xbutton.state);
+ time =
Xlib.Time.CurrentTime;
+ }
+ else
if(menuPress != null)
+ {
+
menuPress(widget, xevent.xbutton.x,
+
xevent.xbutton.y, button,
+
xevent.xbutton.state);
+ }
+ }
+ lastClickTime = time;
+ lastClickButton =
button;
+ }
+ break;
+
+ case EventType.ButtonRelease:
+ {
+ // Dispatch a button
release event.
+ button =
xevent.xbutton.button;
+ if(release != null)
+ {
+ release(widget,
xevent.xbutton.x,
+
xevent.xbutton.y, button,
+
xevent.xbutton.state);
+ }
+ if(button ==
ButtonName.Button1 &&
+ selectRelease !=
null)
+ {
+
selectRelease(widget, xevent.xbutton.x,
+
xevent.xbutton.y, button,
+
xevent.xbutton.state);
+ }
+ else if(button !=
ButtonName.Button1 &&
+
menuRelease != null)
+ {
+
menuRelease(widget, xevent.xbutton.x,
+
xevent.xbutton.y, button,
+
xevent.xbutton.state);
+ }
+ }
+ break;
+
+ case EventType.KeyPress:
+ {
+ // Dispatch a key press
event.
+ if(keyPress != null)
+ {
+ if(keyBuffer ==
IntPtr.Zero)
+ {
+
keyBuffer = Marshal.AllocHGlobal(32);
+ }
+ Xlib.KeySym
keysym = 0;
+ int len =
Xlib.XLookupString
+ (ref
xevent.xkey, keyBuffer, 32,
+ ref
keysym, IntPtr.Zero);
+ if(len > 0)
+ {
+
keyPress(widget, (KeyName)keysym,
+
xevent.xkey.state,
+
Marshal.PtrToStringAnsi
+
(keyBuffer, len));
+ }
+ else
+ {
+
keyPress(widget, (KeyName)keysym,
+
xevent.xkey.state, null);
+ }
+ }
+ }
+ break;
+
+ case EventType.KeyRelease:
+ {
+ // Dispatch a key
release event.
+ if(keyRelease != null)
+ {
+
keyRelease(widget, (KeyName)
+
Xlib.XLookupKeysym
+
(ref xevent.xkey, 0),
+
xevent.xkey.state);
+ }
+ }
+ break;
+ }
+ }
+
+ // Deselect ButtonPress events if nothing else is interested in
them.
+ public void DeselectButtonPress(Widget widget)
+ {
+ if(((Object)press) == null &&
+ ((Object)doubleClick) == null &&
+ ((Object)selectPress) == null &&
+ ((Object)selectDoubleClick) == null
&&
+ ((Object)menuPress) == null &&
+ ((Object)menuDoubleClick) == null)
+ {
+
widget.DeselectInput(EventMask.ButtonPressMask);
+ }
+ }
+
+ // Deselect ButtonRelease events if nothing else is interested
in them.
+ public void DeselectButtonRelease(Widget widget)
+ {
+ if(((Object)release) == null &&
+ ((Object)selectRelease) == null &&
+ ((Object)menuRelease) == null)
+ {
+
widget.DeselectInput(EventMask.ButtonReleaseMask);
+ }
+ }
+
+ } // class InputEventHandlers
} // class InputOnlyWidget
Index: InputOutputWidget.cs
===================================================================
RCS file: /cvsroot/dotgnu-libs/xsharp/Xsharp/XWindows/InputOutputWidget.cs,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** InputOutputWidget.cs 26 Sep 2002 10:32:42 -0000 1.1.1.1
--- InputOutputWidget.cs 27 Sep 2002 05:54:12 -0000 1.2
***************
*** 314,318 ****
}
! /// Dispatch an event to this widget.
internal override void DispatchEvent(ref XEvent xevent)
{
--- 314,318 ----
}
! // Dispatch an event to this widget.
internal override void DispatchEvent(ref XEvent xevent)
{
***************
*** 353,356 ****
--- 353,357 ----
break;
}
+ base.DispatchEvent(ref xevent);
}
Index: Xlib.cs.in
===================================================================
RCS file: /cvsroot/dotgnu-libs/xsharp/Xsharp/XWindows/Xlib.cs.in,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** Xlib.cs.in 26 Sep 2002 10:32:44 -0000 1.1.1.1
--- Xlib.cs.in 27 Sep 2002 05:54:12 -0000 1.2
***************
*** 385,388 ****
--- 385,399 ----
(IntPtr display, Xlib.Colormap colormap, ref XColor
xcolor);
+ // Declare key-related external functions.
+
+ [DllImport("X11")]
+ extern public static @X_int@ XLookupString
+ (ref XKeyEvent xevent, IntPtr buffer, @X_int@
bytes_buffer,
+ ref KeySym keysym_return, IntPtr status_in_out);
+
+ [DllImport("X11")]
+ extern public static KeySym XLookupKeysym
+ (ref XKeyEvent xevent, int index);
+
} // class Xlib
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-libs-commits] CVS: xsharp/Xsharp/XWindows KeyName.cs,NONE,1.1 EventHandlers.cs,1.1.1.1,1.2 InputOnlyWidget.cs,1.1.1.1,1.2 InputOutputWidget.cs,1.1.1.1,1.2 Xlib.cs.in,1.1.1.1,1.2,
Rhys Weatherley <address@hidden> <=