// Internal constructor, that can create a top-level window on either
	// the root window or underneath an MDI client parent.
	public TopLevelWindow(Widget parent, String name,
						  int x, int y, int width, int height)
			: base(parent, x, y, width, height,
			       new Color(StandardColor.Foreground),
			       new Color(StandardColor.Background),
				   true, false)
			{
				// Check the parent.
				if(!(parent is RootWindow) && !(parent is CaptionWidget))
				{
					throw new XInvalidOperationException();
				}

				// Initialize this object's state.
				this.name = ((name != null) ? name : String.Empty);
				this.iconic = false;
				this.maximized = false;
				this.hasPrimaryFocus = false;
				this.reparented = false;
				this.sticky = false;
				this.shaded = false;
				this.hidden = false;
				this.fullScreen = false;
				this.keyBuffer = IntPtr.Zero;
				this.focusWidget = this;
				this.defaultFocus = null;
				this.decorations = MotifDecorations.All;
				this.functions = MotifFunctions.All;
				this.inputType = MotifInputType.Normal;
				this.transientFor = null;
				this.resizeTimer = null;
				this.expectedWidth = -1;
				this.expectedHeight = -1;

				// Top-level widgets receive all key and focus events.
				SelectInput(EventMask.KeyPressMask |
							EventMask.KeyReleaseMask |
							EventMask.FocusChangeMask |
							EventMask.StructureNotifyMask |
							EventMask.PropertyChangeMask);

				// We don't use WM properties if the parent is a CaptionWidget.
				if(parent is CaptionWidget)
				{
					return;
				}

				// Set the initial WM properties.
				try
				{
					// Lock down the display and get the window handle.
					IntPtr display = dpy.Lock();
					XWindow handle = GetWidgetHandle();

					// Make this the group leader if we don't have one yet.
					bool isFirst = false;
					if(dpy.groupLeader == XWindow.Zero)
					{
						dpy.groupLeader = handle;
						isFirst = true;
					}

					// Set the WM_CLASS hint.
					Application app = Application.Primary;
					if(app != null)
					{
						XClassHint classHint = new XClassHint();
						classHint.res_name = app.ResourceName;
						classHint.res_class = app.ResourceClass;
						Xlib.XSetClassHint(display, handle, ref classHint);
						classHint.Free();
					}

					// Set the title bar and icon names.
					SetWindowName(display, handle, this.name);

					// Ask for "WM_DELETE_WINDOW" and "WM_TAKE_FOCUS".
					SetProtocols(display, handle);

					// Set the window hints.
					if(isFirst && app != null && app.StartIconic)
					{
						// The user supplied "-iconic" on the command-line.
						iconic = true;
					}
					SetWMHints(display, handle);

					// Set some other string properties.
					String cultureName = CultureInfo.CurrentCulture.Name;
					if(cultureName == null || (cultureName.Length == 0))
					{
						cultureName = "en_US";
					}
					else
					{
						cultureName = cultureName.Replace("-", "_");
					}
					SetTextProperty(display, handle, "WM_LOCALE_NAME",
									cultureName);
					String hostname = Application.Hostname;
					if(hostname != null)
					{
						SetTextProperty(display, handle,
										"WM_CLIENT_MACHINE", hostname);
					}
					if(isFirst)
					{
						String[] args = Environment.GetCommandLineArgs();
						if(args != null && args.Length > 0)
						{
							// We put "ilrun" at the start of the command,
							// because the command needs to be in a form
							// that can be directly executed by fork/exec,
							// and IL binaries normally aren't in this form.
							String[] newArgs = new String [args.Length + 1];
							newArgs[0] = "ilrun";
							Array.Copy(args, 0, newArgs, 1, args.Length);
							SetTextProperty(display, handle,
											"WM_COMMAND", newArgs);
						}
					}

				#if CONFIG_EXTENDED_DIAGNOSTICS
					// Put the process ID on the window.
					int pid = Process.GetCurrentProcess().Id;
					if(pid != -1 && pid != 0)
					{
						Xlib.XChangeProperty
							(display, handle,
							 Xlib.XInternAtom(display, "_NET_WM_PID",
							 				  XBool.False),
							 Xlib.XInternAtom(display, "CARDINAL",
							 				  XBool.False),
							 32, 0 /* PropModeReplace */,
							 new Xlib.Xlong [] {(Xlib.Xlong)(pid)}, 1);
					}
				#endif
				}
				finally
				{
					dpy.Unlock();
				}
			}
	// Determine if the child window has a particular Motif function.
	private bool HasFunction(MotifFunctions function)
			{
				if((child.Functions & MotifFunctions.All) != 0)
				{
					return ((child.Functions & function) == 0);
				}
				else
				{
					return ((child.Functions & function) != 0);
				}
			}
Exemplo n.º 3
0
        // Change the set of supported window decorations and functions.
        void IToolkitTopLevelWindow.SetWindowFlags(ToolkitWindowFlags flags)
        {
            // Set the default hint flags.
            MotifDecorations decorations = 0;
            MotifFunctions   functions   = 0;
            MotifInputType   inputType   = MotifInputType.Normal;
            OtherHints       otherHints  = OtherHints.None;

            // Alter decorations according to the window flags.
            if ((flags & ToolkitWindowFlags.Close) != 0)
            {
                functions |= MotifFunctions.Close;
            }
            if ((flags & ToolkitWindowFlags.Minimize) != 0)
            {
                decorations |= MotifDecorations.Minimize;
                functions   |= MotifFunctions.Minimize;
            }
            if ((flags & ToolkitWindowFlags.Caption) != 0)
            {
                decorations |= MotifDecorations.Title;
            }
            if ((flags & ToolkitWindowFlags.Border) != 0)
            {
                decorations |= MotifDecorations.Border;
            }
            if ((flags & ToolkitWindowFlags.ResizeHandles) != 0)
            {
                decorations |= MotifDecorations.ResizeHandles;
            }
            if ((flags & ToolkitWindowFlags.Menu) != 0)
            {
                decorations |= MotifDecorations.Menu;
            }
            if ((flags & ToolkitWindowFlags.Resize) != 0)
            {
                decorations |= MotifDecorations.Maximize |
                               MotifDecorations.ResizeHandles;
                functions |= MotifFunctions.Maximize |
                             MotifFunctions.Resize;
            }
            if ((flags & ToolkitWindowFlags.Move) != 0)
            {
                functions |= MotifFunctions.Move;
            }
            if ((flags & ToolkitWindowFlags.Modal) != 0)
            {
                inputType = MotifInputType.ApplicationModal;
            }
            if ((flags & ToolkitWindowFlags.ToolWindow) != 0)
            {
                otherHints |= OtherHints.ToolWindow;
            }
            else if ((flags & ToolkitWindowFlags.Dialog) != 0)
            {
                otherHints |= OtherHints.Dialog;
            }
            if ((flags & ToolkitWindowFlags.ShowInTaskbar) == 0)
            {
                otherHints |= OtherHints.HideFromTaskBar;
            }
            if ((flags & ToolkitWindowFlags.Help) != 0)
            {
                otherHints |= OtherHints.HelpButton;
            }
            if ((flags & ToolkitWindowFlags.TopMost) != 0)
            {
                otherHints |= OtherHints.TopMost;
            }

            // Remove the "transient for" hint if we are changing a
            // modal form back into a regular form.
            if (InputType == MotifInputType.ApplicationModal &&
                inputType == MotifInputType.Normal)
            {
                RemoveTransientFor();
            }

            // Send the Motif flags to the window manager.
            Decorations = decorations;
            Functions   = functions;
            InputType   = inputType;
            OtherHints  = otherHints;
        }