示例#1
0
        /// <summary> Register a "delete window action" to application context, translate the "delete
        /// window action", add/overwrite the shell widget's translation table and set windows manager
        /// protocol hook for the shell widget. </summary>
        /// <param name="appContext">  The application's context to register the action to.
        /// <see cref="System.IntPtr"/> </param>
        /// <param name="deleteWindowAction"> The action to register to the application's context.
        /// <see cref="XtActionProc"/> </param>
        /// <remarks> This must be done *** AFTER *** XtRealizeWidget (). </remarks>
        public void RegisterDeleteWindowAction(IntPtr appContext, XtActionProc deleteWindowAction)
        {
            try
            {
                // Register (instance method) action procedure to runtime action marshaller
                // and let it map the signal to the (global static) action procedure.
                IntPtr deleteWindowActionPtr = ActionMarshaler.Add(_shell,
                                                                   X11.XEventName.ClientMessage, deleteWindowAction);

                // Create an actions record, to provide the application's context
                // with a "action-name" to "action-procedure" translation.
                XtActionsRec[] actionProcs = new XtActionsRec[] {
                    new XtActionsRec(X11Utils.StringToSByteArray(XtWmShell.DELETE_WINDOW_ACTION_NAME + "\0"),
                                     deleteWindowActionPtr)
                };

                // Register the actions record to the application's context.
                Xtlib.XtAppAddActions(appContext, actionProcs, (XCardinal)1);

                // Create a compiled translation table, to provide the widget with
                // a "message" to "action-name" translation.
                IntPtr translationTable = Xtlib.XtParseTranslationTable("<Message>WM_PROTOCOLS: " +
                                                                        XtWmShell.DELETE_WINDOW_ACTION_NAME + "()");

                // Merge new translations to the widget, overriding existing ones.
                Xtlib.XtOverrideTranslations(_shell, translationTable);

                /// The delete message from the windows manager. Closing an app via window
                /// title functionality doesn't generate a window message - it only generates a
                /// window manager message, thot must be routed to the window (message loop).
                IntPtr wmDeleteMessage = IntPtr.Zero;

                // Hook the closing event from windows manager.
                // Must be done *** AFTER *** XtRealizeWidget () to determine display and window!
                wmDeleteMessage = X11lib.XInternAtom(Xtlib.XtDisplay(_shell), "WM_DELETE_WINDOW", false);
                if (X11lib.XSetWMProtocols(Xtlib.XtDisplay(_shell), Xtlib.XtWindow(_shell),
                                           ref wmDeleteMessage, (X11.TInt) 1) == 0)
                {
                    Console.WriteLine(CLASS_NAME + "::RegisterDeleteWindowAction () " +
                                      "WARNING: Failed to register 'WM_DELETE_WINDOW' event.");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }
        /// <summary> Initialize local ressources for all constructors. </summary>
        /// <param name="assignedPosition"> The position of the top left top corner assigned by the window manager (for shell widgets) or geometry management (by non-shell widgets). Passed as reference to avoid structure copy constructor calls. <see cref="TPoint"/> </param>
        public void InitializeTransientShellResources(ref TPoint offset)
        {
            /* Get the colors black and white. */
            TPixel black = X11lib.XBlackPixel(_display, _screenNumber);                 /* get color black */
            TPixel white = X11lib.XWhitePixel(_display, _screenNumber);                 /* get color white */

            /* Once the display is initialized, create the window.
             * It will have the foreground white and background black */

            _window = X11lib.XCreateSimpleWindow(_display, X11lib.XDefaultRootWindow(_display), (TInt)offset.X, (TInt)offset.Y, (TUint)_assignedSize.Width, (TUint)_assignedSize.Height, 0, 0, black);
            if (_window == IntPtr.Zero)
            {
                Console.WriteLine(CLASS_NAME + "::InitializeTransientShellResources () ERROR. Can not create transient shell.");
                return;
            }

            X11lib.XSelectInput(_display, _window,
                                EventMask.StructureNotifyMask | EventMask.ExposureMask |
                                EventMask.ButtonPressMask | EventMask.ButtonReleaseMask |
                                EventMask.EnterWindowMask | EventMask.LeaveWindowMask |
                                EventMask.PointerMotionMask | EventMask.FocusChangeMask |
                                EventMask.KeyPressMask | EventMask.KeyReleaseMask |
                                EventMask.SubstructureNotifyMask);

            _hasOwnWindow = true;

            /* Hook the closing event from windows manager. */
            _wmDeleteMessage = X11lib.XInternAtom(_display, "WM_DELETE_WINDOW", false);
            if (X11lib.XSetWMProtocols(_display, _window, ref _wmDeleteMessage, (X11.TInt) 1) == 0)
            {
                Console.WriteLine(CLASS_NAME + "::InitializeTransientShellResources () WARNING: Failed to register 'WM_DELETE_WINDOW' event.");
            }

            X11lib.XSetTransientForHint(_display, _window, Parent.Window);

            /* Recreate the foreground Graphics Context with. */
            if (_gc != IntPtr.Zero)
            {
                if (XrwApplicationSettings.VERBOSE_OUTPUT_TO_CONSOLE)
                {
                    Console.WriteLine(CLASS_NAME + "::InitializeTransientShellResources () Replace the foreground GC.");
                }
                X11lib.XFreeGC(_display, _gc);
                _gc = IntPtr.Zero;
            }
            _gc = X11lib.XCreateGC(_display, _window, 0, IntPtr.Zero);
            X11lib.XSetForeground(_display, _gc, white);
        }