// 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);
					}
				}
			}
Пример #2
0
	extern public static XWindow XCreateWindow
			(IntPtr display, XWindow parent, int x, int y,
		     uint width, uint height, uint border_width,
			 int depth, int c_class, IntPtr visual,
			 uint value_mask, ref XSetWindowAttributes values);