public DrawingTopLevelWindow(Widget parent, String name,
						 		 int x, int y, int width, int height)
			: base(parent, name, x, y, width, height)
			{
				this.toolkit = ((IToolkitWindow)(parent.Parent)).Toolkit;
				this.AutoMapChildren = false;
			}
Пример #2
0
	// Constructor.
	internal Screen(Display dpy, int number, IntPtr screen)
			{
				// Copy parameters in from the create process.
				this.dpy = dpy;
				this.number = number;
				this.screen = screen;

				// Create the root window instance for this screen.
				rootWindow = new Xsharp.RootWindow
					(dpy, this, Xlib.XRootWindowOfScreen(screen));

				// Get the default root visual for this screen.
				visual = Xlib.XDefaultVisualOfScreen(screen);

				// Create a "Colormap" object for the default colormap.
				defaultColormap = new Colormap
					(dpy, this, Xlib.XDefaultColormapOfScreen(screen));

				// Create the GC cache.
				defaultGCs = new IntPtr [GCCacheSize];
				bitmapGCs = new IntPtr [GCCacheSize];

				// Initialize the standard colors.
				InitStandardColors();

				// Create the placeholder window for parent-less widgets.
				placeholder = new PlaceholderWindow(rootWindow);

				// Create the grab window for managing popup window events.
				grabWindow = new GrabWindow(rootWindow);
			}
Пример #3
0
	// Constructor.
	internal Widget(Display dpy, Screen screen,
					DrawableKind kind, Widget parent)
			: base(dpy, screen, kind)
			{
				// Set the initial widget properties.
				cursor = null;
				autoMapChildren = true;
				sensitive = true;

				// Insert this widget into the widget tree under its parent.
				this.parent = parent;
				this.topChild = null;
				this.nextAbove = null;
				if(parent != null)
				{
					ancestorSensitive =
						(parent.sensitive && parent.ancestorSensitive);
					nextBelow = parent.topChild;
					if(parent.topChild != null)
					{
						parent.topChild.nextAbove = this;
					}
					parent.topChild = this;
				}
				else
				{
					ancestorSensitive = true;
					nextBelow = null;
				}
				this.eventMask = 0;
			}
	// Constructor.
	public PlaceholderWindow(Widget parent)
			: base(parent, 0, 0, 1, 1,
			       new Color(StandardColor.Foreground),
			       new Color(StandardColor.Background),
				   true, true)
			{
				autoMapChildren = false;
			}
	// Constructor.
	internal OverrideWindow(Widget parent, int x, int y, int width, int height)
			: base(parent, x, y, width, height,
				   new Color(StandardColor.Foreground),
				   new Color(StandardColor.Background),
				   true, true)
			{
				// Nothing to do here.
			}
	// Constructor.
	public DrawingMdiClient
				(IToolkit toolkit, Widget parent,
				 int x, int y, int width, int height, IToolkitEventSink sink)
			: base(parent, x, y, width, height)
			{
				this.sink = sink;
				this.toolkit = toolkit;
				this.AutoMapChildren = false;
			}
Пример #7
0
	// Constructor.
	public GrabWindow(Widget parent)
			: base(parent, -1, -1, 1, 1)
			{
				// Create the initial list of popup windows.
				list = new PopupWindow [0];

				// The grab window is always mapped, but just off-screen
				// so that it isn't visible to the user.
				Map();
			}
	// Constructor.
	public DrawingToolkit()
			{
				// Create an Xsharp application instance.
				app = new Xsharp.Application(null, null);

				// Register the additional fonts that we required.
				RegisterFonts();

				// Get the placeholder widget for the screen.
				placeholder = app.Display.DefaultScreenOfDisplay.Placeholder;

				// Track changes to RESOURCE_MANAGER on the root window.
				app.Display.DefaultScreenOfDisplay.RootWindow.ResourcesChanged
					+= new EventHandler(ResourcesChanged);

				// And then load the initial state.
				LoadResources();
			}
	/// <summary>
	/// <para>Constructs a new <see cref="T:Xsharp.MdiClientWidget"/>
	/// 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, the
	/// root window, or an input-only window.</para>
	/// </exception>
	public MdiClientWidget(Widget parent, int x, int y, int width, int height)
			: base(parent, x, y, width, height,
			       new Color(StandardColor.Foreground),
				   new Color(StandardColor.BottomShadow))
			{
				AutoMapChildren = false;
				Focusable = false;
				TopLevel.mdiClient = this;
				cascadeOffset = 0;

				// Create the button widgets for displaying window controls
				// in the menu area of the top-level window.
				minimize = new CaptionButtonWidget
					(parent, 0, 0, 14, 14, this,
					 CaptionWidget.CaptionFlags.HasMinimize);
				restore = new CaptionButtonWidget
					(parent, 0, 0, 14, 14, this,
					 CaptionWidget.CaptionFlags.HasRestore);
				close = new CaptionButtonWidget
					(parent, 0, 0, 14, 14, this,
					 CaptionWidget.CaptionFlags.HasClose);
			}
	/// <summary>
	/// <para>Method that is called when the keyboard focus leaves
	/// this widget.</para>
	/// </summary>
	///
	/// <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 other)
			{
				// Nothing to do in this class.
			}
	/// <summary>
	/// <para>Method that is called when the mouse pointer leaves
	/// this widget.</para>
	/// </summary>
	///
	/// <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 child, int x, int y,
								   ModifierMask modifiers,
								   CrossingMode mode,
								   CrossingDetail detail)
			{
				// Nothing to do in this class.
			}
	// Get the screen associated with a parent widget.
	private static Screen GetScreen(Widget parent)
			{
				if(parent != null)
				{
					return parent.Screen;
				}
				else
				{
					return null;
				}
			}
	// Get the display associated with a parent widget, and also
	// validate the widget.
	private static Display GetDisplay(Widget parent, bool rootAllowed)
			{
				if(parent == null)
				{
					throw new ArgumentNullException("parent");
				}
				if(!rootAllowed && parent is RootWindow)
				{
					throw new XInvalidOperationException
						(S._("X_NonRootParent"));
				}
				return parent.Display;
			}
	// 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);
					}
				}
			}
		// Constructor.
		public CaptionButtonWidget(Widget parent, int x, int y,
								   int width, int height, MdiClientWidget mdi,
								   CaptionWidget.CaptionFlags flags)
				: base(parent, x, y, width, height)
				{
					this.mdi = mdi;
					this.flags = flags;
					this.pressed = false;
					this.Layer = 10;
				}
	/// <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);
					}
				}
			}
	/// <summary>
	/// <para>Constructs a new <see cref="T:Xsharp.EmbeddedApplication"/>
	/// instance.</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 window.</para>
	/// </param>
	///
	/// <param name="height">
	/// <para>The height of the new window.</para>
	/// </param>
	///
	/// <param name="program">
	/// <para>The name of the program to execute.</para>
	/// </param>
	///
	/// <param name="args">
	/// <para>The command-line arguments to pass to the program.</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, the
	/// root window, or an input-only window.</para>
	/// </exception>
	public EmbeddedApplication(Widget parent, int x, int y,
							   int width, int height,
							   String program, String args)
			: base(parent, x, y, width, height)
			{
				this.program = program;
				this.args = args;
				SelectInput(EventMask.SubstructureNotifyMask);
			}
	// Internal constructor that is used by "TopLevelWindow" and
	// "OverrideWindow".
	internal InputOutputWidget(Widget parent, int x, int y,
							   int width, int height,
							   Color foreground, Color background,
							   bool rootAllowed, bool overrideRedirect)
			: base(parent, x, y, width, height, background,
				   rootAllowed, overrideRedirect)
			{
				this.foreground = foreground;
				this.background = background;
				SelectInput(EventMask.ExposureMask);
			}
Пример #19
0
	/// <summary>
	/// <para>Reparenting is disabled for the root window.</para>
	/// </summary>
	public override void Reparent(Widget newParent, int x, int y)
			{
				throw new XInvalidOperationException
					(S._("X_NonRootOperation"));
			}
Пример #20
0
	// Set this cursor on a widget.
	internal void SetCursor(Widget widget)
			{
				Display dpy = widget.dpy;
				try
				{
					IntPtr display = dpy.Lock();
					XWindow window = widget.GetWidgetHandle();
					if(source != null)
					{
						if(cursor == XCursor.Zero)
						{
							XColor foreground = new XColor();
							foreground.red = (ushort)0;
							foreground.green = (ushort)0;
							foreground.blue = (ushort)0;
							foreground.flags =
								(XColor.DoRed | XColor.DoGreen | XColor.DoBlue);
							XColor background = new XColor();
							background.red = (ushort)0xFFFF;
							background.green = (ushort)0xFFFF;
							background.blue = (ushort)0xFFFF;
							background.flags =
								(XColor.DoRed | XColor.DoGreen | XColor.DoBlue);
							if(reverse)
							{
								cursor = Xlib.XCreatePixmapCursor
									(display,
									 source.GetPixmapHandle(),
									 mask.GetPixmapHandle(),
									 ref background, ref foreground,
									 (uint)hotspotX, (uint)hotspotY);
							}
							else
							{
								cursor = Xlib.XCreatePixmapCursor
									(display,
									 source.GetPixmapHandle(),
									 mask.GetPixmapHandle(),
									 ref foreground, ref background,
									 (uint)hotspotX, (uint)hotspotY);
							}
						}
						Xlib.XDefineCursor(display, window, cursor);
					}
					else if(type == CursorType.XC_inherit_parent)
					{
						Xlib.XUndefineCursor(display, window);
					}
					else
					{
						Xlib.XDefineCursor
							(display, window, dpy.GetCursor(type));
					}
				}
				finally
				{
					dpy.Unlock();
				}
			}
	// Place a minimized window rectangle.
	internal void PlaceMinimizedRectangle(ref Rectangle rect, Widget placed)
			{
				// Create a region that consists of all minimized areas.
				Region region = new Region();
				Widget current = TopChild;
				while(current != null)
				{
					if(current is CaptionWidget && current.IsMapped &&
					   ((CaptionWidget)current).Child.IsIconic)
					{
						if(current != placed)
						{
							region.Union
								(current.x, current.y,
								 current.width, current.height);
						}
					}
					current = current.NextBelow;
				}

				// Place the minimized rectangle.
				int yplace = height - rect.height;
				int xplace = 0;
				for(;;)
				{
					// Move up to the next line if we've overflowed this one.
					if((xplace + rect.width) > width && width >= rect.width)
					{
						yplace -= rect.height;
						xplace = 0;
					}

					// Determine if the rectangle overlaps the region.
					// If it doesn't, then we have found the best location.
					rect.x = xplace;
					rect.y = yplace;
					if(!region.Overlaps(rect))
					{
						region.Dispose();
						return;
					}

					// Move on to the next candidate.
					xplace += rect.width;
				}
			}
	// Maximize all windows.
	internal void MaximizeAll(Widget dontNotify)
			{
				bool controls = HasControls();
				maximized = true;
				Widget current = TopChild;
				while(current != null)
				{
					if(current is CaptionWidget)
					{
						((CaptionWidget)current).MaximizeChild
							(current != dontNotify, controls);
					}
					current = current.NextBelow;
				}
				PositionControls();
			}
	// Dispatch a focus in event to this widget from the top-level window.
	internal void DispatchFocusIn(Widget oldWidget)
			{
				OnFocusIn(oldWidget);
			}
	// Override the focus enter event from Xsharp.
	protected override void OnFocusIn(Widget other)
			{
				if(sink != null)
				{
					sink.ToolkitFocusEnter();
				}
			}
	// Dispatch a focus out event to this widget from the top-level window.
	internal void DispatchFocusOut(Widget newWidget)
			{
				OnFocusOut(newWidget);
			}
	// Override the focus leave event from Xsharp.
	protected override void OnFocusOut(Widget other)
			{
				if(sink != null)
				{
					sink.ToolkitFocusLeave();
				}
			}
	/// <summary>
	/// <para>Constructs a new <see cref="T:Xsharp.InputOutputWidget"/>
	/// instance underneath a specified parent widget, with
	/// specified foreground and background colors.</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="foreground">
	/// <para>The foreground color for the widget.</para>
	/// </param>
	///
	/// <param name="background">
	/// <para>The background color for the 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, the
	/// root window, or an input-only window.</para>
	/// </exception>
	public InputOutputWidget(Widget parent, int x, int y,
							 int width, int height,
							 Color foreground, Color background)
			: base(parent, x, y, width, height, background, false, false)
			{
				this.foreground = foreground;
				this.background = background;
				SelectInput(EventMask.ExposureMask);
			}
	// Restore all windows from the maximized state.
	internal void RestoreAll(Widget dontNotify)
			{
				maximized = false;
				Widget current = TopChild;
				while(current != null)
				{
					if(current is CaptionWidget)
					{
						((CaptionWidget)current).RestoreChild
							(current != dontNotify);
					}
					current = current.NextBelow;
				}
				PositionControls();
			}
	/// <summary>
	/// <para>Constructs a new <see cref="T:Xsharp.InputOutputWidget"/>
	/// 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, the
	/// root window, or an input-only window.</para>
	/// </exception>
	public InputOutputWidget(Widget parent, int x, int y,
							 int width, int height)
			: base(parent, x, y, width, height,
			       new Color(StandardColor.Inherit), false, false)
			{
				foreground = new Color(StandardColor.Foreground);
				background = new Color(StandardColor.Inherit);
				SelectInput(EventMask.ExposureMask);
			}
	// Override the mouse leave event from Xsharp.
	protected override void OnLeave(Widget child, int x, int y,
								    ModifierMask modifiers,
								    CrossingMode mode,
								    CrossingDetail detail)
			{
				if(sink != null)
				{
					sink.ToolkitMouseLeave();
				}
			}