Exemple #1
0
        /// <summary>
        /// <para>Constructs a new <see cref="T:Xsharp.InputOnlyWidget"/>
        /// 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>
        ///
        /// <exception cref="T:System.ArgumentNullException">
        /// <para>Raised if <paramref name="parent"/> is <see langword="null"/>.
        /// </para>
        /// </exception>
        ///
        /// <exception cref="T:Xsharp.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.Xsharp.XInvalidOperationException">
        /// <para>Raised if <paramref name="parent"/> is disposed or the
        /// root window.</para>
        /// </exception>
        public InputOnlyWidget(Widget parent, int x, int y, int width, int height)
            : base(GetDisplay(parent, false), GetScreen(parent),
                   DrawableKind.InputOnlyWidget, parent)
        {
            bool ok = false;

            try
            {
                // Validate the position and size.
                if (x < -32768 || x > 32767 ||
                    y < -32768 || y > 32767)
                {
                    throw new XException(S._("X_InvalidPosition"));
                }
                if (width < 1 || width > 32767 ||
                    height < 1 || height > 32767 ||
                    !ValidateSize(width, height))
                {
                    throw new XException(S._("X_InvalidSize"));
                }

                // Set the initial position and size of the widget.
                this.x         = x;
                this.y         = y;
                this.width     = width;
                this.height    = height;
                this.focusable = true;

                // Lock down the display and create the window handle.
                try
                {
                    IntPtr  display = dpy.Lock();
                    XWindow pwindow = parent.GetWidgetHandle();
                    XWindow window  = Xlib.XCreateWindow
                                          (display, pwindow,
                                          x, y, (uint)width, (uint)height, (uint)0,
                                          0 /* depth */, 2 /* InputOnly */,
                                          screen.DefaultVisual,
                                          (uint)0, IntPtr.Zero);
                    SetWidgetHandle(window);
                    if (parent.AutoMapChildren)
                    {
                        Xlib.XMapWindow(display, window);
                        mapped = true;
                    }
                }
                finally
                {
                    dpy.Unlock();
                }

                // Push the widget down to the default layer.
                layer = 0x7FFFFFFF;
                Layer = 0;
                ok    = true;

                // Select for mouse events.
                SelectInput(EventMask.ButtonPressMask |
                            EventMask.ButtonReleaseMask |
                            EventMask.EnterWindowMask |
                            EventMask.LeaveWindowMask |
                            EventMask.PointerMotionMask);
            }
            finally
            {
                if (!ok)
                {
                    // Creation failed, so detach ourselves from
                    // the parent's widget tree.
                    Detach(false);
                }
            }
        }
Exemple #2
0
        // Internal constructor that is used by the "InputOutputWidget" subclass.
        internal InputOnlyWidget(Widget parent, int x, int y,
                                 int width, int height, Color background,
                                 bool rootAllowed, bool overrideRedirect)
            : base(GetDisplay(parent, rootAllowed), GetScreen(parent),
                   DrawableKind.Widget, parent)
        {
            bool ok = false;

            try
            {
                // Validate the position and size.
                if (x < -32768 || x > 32767 ||
                    y < -32768 || y > 32767)
                {
                    throw new XException(S._("X_InvalidPosition"));
                }
                if (width < 1 || width > 32767 ||
                    height < 1 || height > 32767 ||
                    !ValidateSize(width, height))
                {
                    throw new XException(S._("X_InvalidSize"));
                }

                // Set the initial position and size of the widget.
                this.x         = x;
                this.y         = y;
                this.width     = width;
                this.height    = height;
                this.focusable = true;

                // Lock down the display and create the window handle.
                try
                {
                    IntPtr  display            = dpy.Lock();
                    XWindow pwindow            = parent.GetWidgetHandle();
                    XSetWindowAttributes attrs = new XSetWindowAttributes();
                    attrs.override_redirect = overrideRedirect;
                    XWindow window = Xlib.XCreateWindow
                                         (display, pwindow,
                                         x, y, (uint)width, (uint)height, (uint)0,
                                         screen.DefaultDepth, 1 /* InputOutput */,
                                         screen.DefaultVisual,
                                         (uint)(CreateWindowMask.CWOverrideRedirect),
                                         ref attrs);
                    SetWidgetHandle(window);
                    if (background.Index == StandardColor.Inherit)
                    {
                        Xlib.XSetWindowBackgroundPixmap
                            (display, window, XPixmap.ParentRelative);
                    }
                    else
                    {
                        Xlib.XSetWindowBackground(display, window,
                                                  ToPixel(background));
                    }
                    if (parent.AutoMapChildren)
                    {
                        Xlib.XMapWindow(display, window);
                        mapped = true;
                    }
                }
                finally
                {
                    dpy.Unlock();
                }

                // Push the widget down to the default layer.
                layer = 0x7FFFFFFF;
                Layer = 0;
                ok    = true;

                // Select for mouse events.
                SelectInput(EventMask.ButtonPressMask |
                            EventMask.ButtonReleaseMask |
                            EventMask.EnterWindowMask |
                            EventMask.LeaveWindowMask |
                            EventMask.PointerMotionMask);
            }
            finally
            {
                if (!ok)
                {
                    // Creation failed, so detach ourselves from
                    // the parent's widget tree.
                    Detach(false);
                }
            }
        }