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

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

[Dotgnu-libs-commits] CVS: xsharp/Xsharp/XWindows Control.cs,NONE,1.1 Co


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-libs-commits] CVS: xsharp/Xsharp/XWindows Control.cs,NONE,1.1 ControlEvents.cs,NONE,1.1
Date: Sun, 29 Sep 2002 01:02:50 -0400

Update of /cvsroot/dotgnu-libs/xsharp/Xsharp/XWindows
In directory subversions:/tmp/cvs-serv13334/Xsharp/XWindows

Added Files:
        Control.cs ControlEvents.cs 
Log Message:


Add the "Control" class, which provides a simpler interface for
implementing controls as subclasses.


--- NEW FILE ---
/*
 * Control.cs - Input-output widget that is easier to inherit for controls.
 *
 * 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
 */

namespace XWindows
{

using System;

/// <summary>
/// <para>The <see cref="T:XWindows.Control"/> class inherits from
/// <see cref="T:XWindows.InputOutputWidget"/> and converts the common
/// events into virtual method calls.  This makes it easier to implement
/// program controls in subclasses.</para>
/// </summary>
public abstract class Control : InputOutputWidget
{
        /// <summary>
        /// <para>Constructs a new <see cref="T:XWindows.Control"/>
        /// instance underneath a specified parent widget.</para>
        /// </summary>
        ///
        /// <param name="parent">
        /// <para>The parent of the new widget.</para>
        /// </param>
        ///
        /// <param name="x">
        /// <para>The X co-ordinate of the top-left corner of
        /// the new widget.</para>
        /// </param>
        ///
        /// <param name="y">
        /// <para>The Y co-ordinate of the top-left corner of
        /// the new widget.</para>
        /// </param>
        ///
        /// <param name="width">
        /// <para>The width of the new widget.</para>
        /// </param>
        ///
        /// <param name="height">
        /// <para>The height of the new widget.</para>
        /// </param>
        ///
        /// <param name="events">
        /// <para>The events that the subclass is interested in.</para>
        /// </param>
        ///
        /// <exception cref="T:System.ArgumentNullException">
        /// <para>Raised if <paramref name="parent"/> is <see langword="null"/>.
        /// </para>
        /// </exception>
        ///
        /// <exception cref="T:XWindows.XException">
        /// <para>Raised if <paramref name="x"/>, <paramref name="y"/>,
        /// <paramref name="width"/>, or <paramref name="height"/> are
        /// out of range.</para>
        /// </exception>
        ///
        /// <exception cref="T.XWindows.XInvalidOperationException">
        /// <para>Raised if <paramref name="parent"/> is disposed, the
        /// root window, or an input-only window.</para>
        /// </exception>
        protected Control(Widget parent, int x, int y, int width, int height,
                                      ControlEvents events)
                        : base(parent, x, y, width, height)
                        {
                                // Redirect the events to virtual methods in 
this class.
                                Resized += new ResizedEventHandler(OnResize);
                                Paint += new PaintEventHandler(OnPaint);
                                if((events & ControlEvents.SensitivityChanged) 
!= 0)
                                {
                                        SensitivityChanged += new 
SensitivityChangedEventHandler
                                                (OnSensitivityChanged);
                                }
                                if((events & ControlEvents.SelectButton) != 0)
                                {
                                        SelectPress +=
                                                new 
ButtonPressEventHandler(OnSelectPress);
                                        SelectRelease +=
                                                new 
ButtonReleaseEventHandler(OnSelectRelease);
                                }
                                if((events & ControlEvents.SelectDoubleClick) 
!= 0)
                                {
                                        SelectDoubleClick +=
                                                new 
ButtonPressEventHandler(OnSelectDoubleClick);
                                }
                                if((events & ControlEvents.MenuButton) != 0)
                                {
                                        MenuPress +=
                                                new 
ButtonPressEventHandler(OnMenuPress);
                                        MenuRelease +=
                                                new 
ButtonReleaseEventHandler(OnMenuRelease);
                                }
                                if((events & ControlEvents.MenuDoubleClick) != 
0)
                                {
                                        MenuDoubleClick +=
                                                new 
ButtonPressEventHandler(OnMenuDoubleClick);
                                }
                                if((events & ControlEvents.PointerMotion) != 0)
                                {
                                        PointerMotion +=
                                                new 
PointerMotionEventHandler(OnPointerMotion);
                                }
                                if((events & ControlEvents.KeyPress) != 0)
                                {
                                        KeyPress += new 
KeyPressEventHandler(OnKeyPress);
                                }
                                if((events & ControlEvents.EnterLeave) != 0)
                                {
                                        Enter += new 
CrossingEventHandler(OnEnter);
                                        Leave += new 
CrossingEventHandler(OnLeave);
                                }
                                if((events & ControlEvents.FocusChange) != 0)
                                {
                                        FocusIn += new 
FocusChangeEventHandler(OnFocusIn);
                                        FocusOut += new 
FocusChangeEventHandler(OnFocusOut);
                                }
                        }

        /// <summary>
        /// <para>Handle a resize event on this control.</para>
        /// </summary>
        ///
        /// <param name="widget">
        /// <para>The widget that was resized (always <see langword="this"/>).
        /// </para>
        /// </param>
        ///
        /// <param name="width">
        /// <para>The new width for the widget.</para>
        /// </param>
        ///
        /// <param name="height">
        /// <para>The new height for the widget.</para>
        /// </param>
        protected virtual void OnResize(Widget widget, int width, int height)
                        {
                                // Force a repaint on the control.
                                Draw();
                        }

        /// <summary>
        /// <para>Handle a paint event or <c>Draw</c> request
        /// on this control.</para>
        /// </summary>
        ///
        /// <param name="widget">
        /// <para>The widget that to be painted (always <see langword="this"/>).
        /// </para>
        /// </param>
        ///
        /// <param name="canvas">
        /// <para>The canvas to paint with.</para>
        /// </param>
        protected virtual void OnPaint(Widget widget, Canvas canvas)
                        {
                                // Nothing to do here.
                        }

        /// <summary>
        /// <para>Handle a sensitivity change on this control.</para>
        /// </summary>
        ///
        /// <param name="widget">
        /// <para>The widget that was changed (always <see langword="this"/>).
        /// </para>
        /// </param>
        protected virtual void OnSensitivityChanged(Widget widget)
                        {
                                // Nothing to do here.
                        }

        // Bring the focus to this control in response to a button event.
        private void BringFocus()
                        {
                                if(Focusable && FullSensitive)
                                {
                                        RequestFocus();
                                }
                        }

        /// <summary>
        /// <para>Handle a button press on the "Select" button.</para>
        /// </summary>
        ///
        /// <param name="widget">
        /// <para>The widget that received the event
        /// (always <see langword="this"/>).</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>
        protected virtual void OnSelectPress(Widget widget, int x, int y,
                                                                                
 ButtonName button,
                                                                                
 ModifierMask modifiers)
                        {
                                BringFocus();
                        }

        /// <summary>
        /// <para>Handle a button release on the "Select" button.</para>
        /// </summary>
        ///
        /// <param name="widget">
        /// <para>The widget that received the event
        /// (always <see langword="this"/>).</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>
        protected virtual void OnSelectRelease(Widget widget, int x, int y,
                                                                                
   ButtonName button,
                                                                                
   ModifierMask modifiers)
                        {
                                // Nothing to do here.
                        }

        /// <summary>
        /// <para>Handle a button double-click on the "Select" button.</para>
        /// </summary>
        ///
        /// <param name="widget">
        /// <para>The widget that received the event
        /// (always <see langword="this"/>).</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>
        protected virtual void OnSelectDoubleClick(Widget widget, int x, int y,
                                                                                
           ButtonName button,
                                                                                
           ModifierMask modifiers)
                        {
                                BringFocus();
                        }

        /// <summary>
        /// <para>Handle a button press on the "Menu" button.</para>
        /// </summary>
        ///
        /// <param name="widget">
        /// <para>The widget that received the event
        /// (always <see langword="this"/>).</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>
        protected virtual void OnMenuPress(Widget widget, int x, int y,
                                                                           
ButtonName button,
                                                                           
ModifierMask modifiers)
                        {
                                BringFocus();
                        }

        /// <summary>
        /// <para>Handle a button release on the "Menu" button.</para>
        /// </summary>
        ///
        /// <param name="widget">
        /// <para>The widget that received the event
        /// (always <see langword="this"/>).</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>
        protected virtual void OnMenuRelease(Widget widget, int x, int y,
                                                                                
 ButtonName button,
                                                                                
 ModifierMask modifiers)
                        {
                                // Nothing to do here.
                        }

        /// <summary>
        /// <para>Handle a button double-click on the "Menu" button.</para>
        /// </summary>
        ///
        /// <param name="widget">
        /// <para>The widget that received the event
        /// (always <see langword="this"/>).</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>
        protected virtual void OnMenuDoubleClick(Widget widget, int x, int y,
                                                                                
         ButtonName button,
                                                                                
         ModifierMask modifiers)
                        {
                                BringFocus();
                        }

        /// <summary>
        /// <para>Handle a pointer motion event.</para>
        /// </summary>
        ///
        /// <param name="widget">
        /// <para>The widget that received the event
        /// (always <see langword="this"/>).</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="modifiers">
        /// <para>Button and shift flags that were active.</para>
        /// </param>
        protected virtual void OnPointerMotion(Widget widget, int x, int y,
                                                                                
   ModifierMask modifiers)
                        {
                                // Nothing to do here.
                        }

        /// <summary>
        /// <para>Handle a key press event within this control.</para>
        /// </summary>
        ///
        /// <param name="widget">
        /// <para>The widget that received the event
        /// (always <see langword="this"/>).</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>
        ///
        /// <returns>
        /// <para>Returns <see langword="true"/> if the key has been processed
        /// and it should not be passed further up the focus tree.  Returns
        /// <see langword="false"/> if the key should be passed further up
        /// the focus tree.</para>
        /// </returns>
        ///
        /// <remarks>The <paramref name="key"/> parameter indicates the X11
        /// symbol that corresponds to the key, which allows cursor control
        /// and function keys to be easily distinguished.  The
        /// <paramref name="str"/> is primarily of use to text
        /// input widgets.</remarks>
        protected virtual bool OnKeyPress(Widget widget, KeyName key,
                                                                      
ModifierMask modifiers, String str)
                        {
                                // Nothing to do here.
                                return false;
                        }

        /// <summary>
        /// <para>Handle a window enter event on this control.</para>
        /// </summary>
        ///
        /// <param name="widget">
        /// <para>The widget that received the event
        /// (always <see langword="this"/>).</para>
        /// </param>
        ///
        /// <param name="child">
        /// <para>The child widget that contained the previous or final
        /// position, or <see langword="null"/> if no applicable child
        /// widget.</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="modifiers">
        /// <para>Button and shift flags that were active.</para>
        /// </param>
        ///
        /// <param name="mode">
        /// <para>The notification mode value from the event.</para>
        /// </param>
        ///
        /// <param name="detail">
        /// <para>The notification detail value from the event.</para>
        /// </param>
        protected virtual void OnEnter(Widget widget, Widget child,
                                                                   int x, int y,
                                                                   ModifierMask 
modifiers,
                                                                   CrossingMode 
mode,
                                                                   
CrossingDetail detail)
                        {
                                // Nothing to do here.
                        }

        /// <summary>
        /// <para>Handle a window leave event on this control.</para>
        /// </summary>
        ///
        /// <param name="widget">
        /// <para>The widget that received the event
        /// (always <see langword="this"/>).</para>
        /// </param>
        ///
        /// <param name="child">
        /// <para>The child widget that contained the previous or final
        /// position, or <see langword="null"/> if no applicable child
        /// widget.</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="modifiers">
        /// <para>Button and shift flags that were active.</para>
        /// </param>
        ///
        /// <param name="mode">
        /// <para>The notification mode value from the event.</para>
        /// </param>
        ///
        /// <param name="detail">
        /// <para>The notification detail value from the event.</para>
        /// </param>
        protected virtual void OnLeave(Widget widget, Widget child,
                                                                   int x, int y,
                                                                   ModifierMask 
modifiers,
                                                                   CrossingMode 
mode,
                                                                   
CrossingDetail detail)
                        {
                                // Nothing to do here.
                        }

        /// <summary>
        /// <para>Handle a focus in event on this control.</para>
        /// </summary>
        ///
        /// <param name="widget">
        /// <para>The widget that received the event
        /// (always <see langword="this"/>).</para>
        /// </param>
        ///
        /// <param name="other">
        /// <para>The previous widget within the same top-level window that had
        /// the focus, or <see langword="null"/> if the focus is entering the
        /// top-level window from outside.</para>
        /// </param>
        protected virtual void OnFocusIn(Widget widget, Widget other)
                        {
                                // Nothing to do here.
                        }

        /// <summary>
        /// <para>Handle a focus out event on this control.</para>
        /// </summary>
        ///
        /// <param name="widget">
        /// <para>The widget that received the event
        /// (always <see langword="this"/>).</para>
        /// </param>
        ///
        /// <param name="other">
        /// <para>The new widget within the same top-level window that will 
receive
        /// the focus, or <see langword="null"/> if the focus is leaving the
        /// top-level window.</para>
        /// </param>
        protected virtual void OnFocusOut(Widget widget, Widget other)
                        {
                                // Nothing to do here.
                        }

        /// <summary>
        /// <para>Flush pending <c>Expose</c> events on this control.</para>
        /// </summary>
        protected void FlushExpose()
                        {
                                try
                                {
                                        dpy.Lock();
                                        Expose();
                                        RemovePendingExpose();
                                }
                                finally
                                {
                                        dpy.Unlock();
                                }
                        }

        /// <summary>
        /// <para>Clear the control and redraw it using the
        /// <c>OnPaint</c> method.</para>
        /// </summary>
        protected void Draw()
                        {
                                if(IsMapped && AncestorsMapped)
                                {
                                        FlushExpose();
                                        Canvas canvas = new Canvas(this);
                                        canvas.Clear(0, 0, width, height);
                                        OnPaint(this, canvas);
                                        canvas.Dispose();
                                }
                        }

} // class Control

} // namespace XWindows

--- NEW FILE ---
/*
 * ControlEvents.cs - Events that are desired by a control.
 *
 * 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
 */

namespace XWindows
{

using System;

/// <summary>
/// <para>The <see cref="T:XWindows.ControlEvents"/> enumeration specifies
/// events that are desired by a subclass of <see cref="T:XWindows.Control"/>.
/// </para>
/// </summary>
public enum ControlEvents
{

        SensitivityChanged      = (1<<0),
        SelectButton            = (1<<1),
        SelectDoubleClick   = (1<<2),
        MenuButton                      = (1<<3),
        MenuDoubleClick     = (1<<4),
        PointerMotion           = (1<<5),
        KeyPress                        = (1<<6),
        EnterLeave                      = (1<<7),
        FocusChange                     = (1<<8)

} // enum ControlEvents

} // namespace XWindows





reply via email to

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