Esempio n. 1
0
        // ###############################################################################
        // ### M E T H O D S
        // ###############################################################################

        #region Methods

        /// <summary> Load the icon from indicated path and set it as shell icon. </summary>
        /// <returns> <c>true</c>, if icon was set, <c>false</c> otherwise. </returns>
        /// <param name='iconPath'> The icon path. </param>
        public bool SetShellIcon(string iconPath)
        {
            bool result = false;

            if (_shell == IntPtr.Zero)
            {
                Console.WriteLine(CLASS_NAME + "::SetShellIcon() ERROR: Member attribute '_shell' null.");
                return(result);
            }
            if (string.IsNullOrEmpty(iconPath))
            {
                Console.WriteLine(CLASS_NAME + "::SetShellIcon() ERROR: Paramerter 'iconPath' null or empty.");
                return(result);
            }

            IntPtr display      = Xtlib.XtDisplay(_shell);
            IntPtr window       = Xtlib.XtWindow(_shell);
            TInt   screenNumber = Xtlib.XDefaultScreen(display);

            using (X11Graphic appIcon = new X11Graphic(display, (int)screenNumber, IntPtr.Zero, X11lib.XDefaultDepth(display, screenNumber), iconPath))
            {
                _appIconPixMap = appIcon.CreateIndependentGraphicPixmap(display, window);
                _appMaskPixMap = appIcon.CreateIndependentMaskPixmap(display, window);
                if (_appIconPixMap != IntPtr.Zero && _appMaskPixMap != IntPtr.Zero)
                {
                    X11lib.XWMHints wmHints = new X11lib.XWMHints();
                    IntPtr          wmAddr  = X11lib.XAllocWMHints(ref wmHints);

                    wmHints.flags = X11lib.XWMHintMask.IconPixmapHint |
                                    X11lib.XWMHintMask.IconPositionHint |
                                    X11lib.XWMHintMask.IconMaskHint;
                    wmHints.icon_pixmap = _appIconPixMap;
                    wmHints.icon_mask   = _appMaskPixMap;
                    wmHints.icon_x      = 0;
                    wmHints.icon_y      = 0;

                    X11lib.XSetWMHints(display, window, ref wmHints);
                    X11lib.XFree(wmAddr);

                    result = true;
                }
                else
                {
                    Console.WriteLine(CLASS_NAME + "::SetShellIcon () ERROR: Can not create application icon.");
                }
            }

            return(result);
        }
Esempio n. 2
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);
            }
        }
Esempio n. 3
0
        // ###############################################################################
        // ### A T T R I B U T E S
        // ###############################################################################

        #region Attributes

        #endregion

        // ###############################################################################
        // ### C O N S T R U C T I O N   A N D   I N I T I A L I Z A T I O N
        // ###############################################################################

        #region Construction

        /// <summary> The initializing constructor. </summary>
        /// <param name="toplevelShell"> The toplevel shell that owns the underlaying transient popup shell of this dialog. <see cref="XtApplicationShell"/> </param>
        /// <param name="toplevelShell"> The shell caption. <see cref="System.String"/> </param>
        public XtGrabExclusiveAthenaDialog(XtApplicationShell toplevelShell, string caption)
            : base(toplevelShell, caption)
        {
            if (toplevelShell == null)
            {
                throw new ArgumentNullException("toplevelShell");
            }

            // The dialog widget needs the final size of all child widgets during layout calculation to prevent child widget overlapping. Or in other words:
            // Child widget overlapping will happen, if XtNicon is set after dialog widget's layout calculation, because XtMakeResizeRequest () can't be called.

            // Currently the dialog widget isn't realized and therefor it hasn't a window. That's why we use the toplevel shell's window instead.
            IntPtr logo = IntPtr.Zero;

            if (!(Xtlib.XtIsRealized(toplevelShell.Shell) == (TBoolean)0))
            {
                IntPtr display = Xtlib.XtDisplay(toplevelShell.Shell);
                IntPtr window  = Xtlib.XtWindow(toplevelShell.Shell);
                logo = X11lib.XCreateBitmapFromData(display, window, XtResources.BIG_EXCLAMATION_ICON_BITS,
                                                    XtResources.BIG_ICON_WIDTH, XtResources.BIG_ICON_HEIGHT);
            }
            Arg[] formArgs = { new Arg(XtNames.XtNlabel, X11.X11Utils.StringToSByteArray("Enter data string:\0")),
                               new Arg(XtNames.XtNvalue, X11.X11Utils.StringToSByteArray("\0")),
                               new Arg(XtNames.XtNicon,  (XtArgVal)logo) };
            _dialogForm = Xtlib.XtCreateManagedWidget(DIALOG_RESOURCE_NAME,
                                                      Xtlib.XawDialogWidgetClass(), _shell,
                                                      formArgs, (XCardinal)3);

            Arg[] okArgs = { new Arg(XtNames.XtNlabel, X11.X11Utils.StringToSByteArray("OK\0")) };
            _okCommand = Xtlib.XtCreateManagedWidget(_okCmdName,
                                                     Xtlib.XawCommandWidgetClass(), _dialogForm,
                                                     okArgs, (XCardinal)1);
            Xtlib.XtAddCallback(_okCommand, XtNames.XtNcallback, CallBackMarshaler.Add(_okCommand, this.DialogOk), IntPtr.Zero);

            Arg[] cancelArgs = { new Arg(XtNames.XtNlabel, X11.X11Utils.StringToSByteArray("Cancel\0")) };
            _cancelCommand = Xtlib.XtCreateManagedWidget(_cancelCmdName,
                                                         Xtlib.XawCommandWidgetClass(), _dialogForm,
                                                         cancelArgs, (XCardinal)1);
            Xtlib.XtAddCallback(_cancelCommand, XtNames.XtNcallback, CallBackMarshaler.Add(_cancelCommand, this.DialogCancel), IntPtr.Zero);
        }
        // ###############################################################################
        // ### A T T R I B U T E S
        // ###############################################################################

        #region Attributes

        #endregion

        // ###############################################################################
        // ### C O N S T R U C T I O N   A N D   I N I T I A L I Z A T I O N
        // ###############################################################################

        #region Construction

        public XtGrabExclusiveMessageBox(XtApplicationShell toplevelShell, string message, string caption, DialogIcon icontype)
            : base(toplevelShell, caption)
        {
            if (toplevelShell == null)
            {
                throw new ArgumentNullException("toplevelShell");
            }

            Arg[] formArgs = { new Arg(XtNames.XtNbackground, (XtArgVal)toplevelShell.AllocColorFromDefaultColormap(X11ColorNames.Gray80).P) };
            _dialogForm = Xtlib.XtCreateManagedWidget(DIALOG_RESOURCE_NAME,
                                                      Xtlib.XawFormWidgetClass(), _shell,
                                                      formArgs, (XCardinal)1);

            // The dialog widget needs the final size of all child widgets during layout calculation to prevent child widget overlapping. Or in other words:
            // Child widget overlapping will happen, if XtNicon is set after dialog widget's layout calculation, because XtMakeResizeRequest () can't be called.

            // Currently the dialog widget isn't realized and therefor it hasn't a window. That's why we use the toplevel shell's window instead.
            IntPtr logo = IntPtr.Zero;

            if (!(Xtlib.XtIsRealized(toplevelShell.Shell) == (TBoolean)0) && icontype != XtDialog.DialogIcon.None)
            {
                IntPtr display = Xtlib.XtDisplay(toplevelShell.Shell);
                IntPtr window  = Xtlib.XtWindow(toplevelShell.Shell);
                if (icontype == DialogIcon.Information)
                {
                    logo = X11lib.XCreateBitmapFromData(display, window, XtResources.BIG_INFORMATION_ICON_BITS,
                                                        XtResources.BIG_ICON_WIDTH, XtResources.BIG_ICON_HEIGHT);
                }
                else if (icontype == DialogIcon.Question)
                {
                    logo = X11lib.XCreateBitmapFromData(display, window, XtResources.BIG_QUESTION_ICON_BITS,
                                                        XtResources.BIG_ICON_WIDTH, XtResources.BIG_ICON_HEIGHT);
                }
                else if (icontype == DialogIcon.Exclamation)
                {
                    logo = X11lib.XCreateBitmapFromData(display, window, XtResources.BIG_EXCLAMATION_ICON_BITS,
                                                        XtResources.BIG_ICON_WIDTH, XtResources.BIG_ICON_HEIGHT);
                }
                else                 // if (icontype == DialogIcon.Stop)
                {
                    logo = X11lib.XCreateBitmapFromData(display, window, XtResources.BIG_STOP_ICON_BITS,
                                                        XtResources.BIG_ICON_WIDTH, XtResources.BIG_ICON_HEIGHT);
                }
            }
            Arg[] msgArgs = { new Arg(XtNames.XtNlabel,       X11.X11Utils.StringToSByteArray(message + "\0")),
                              new Arg(XtNames.XtNbackground,  (XtArgVal)toplevelShell.AllocColorFromDefaultColormap(X11ColorNames.Gray80).P),
                              new Arg(XtNames.XtNborderWidth, (XtArgVal)0),
                              new Arg(XtNames.XtNleftBitmap,  (XtArgVal)logo) };
            _messageLabel = Xtlib.XtCreateManagedWidget(_msgLblName,
                                                        Xtlib.XawLabelWidgetClass(), _dialogForm,
                                                        msgArgs, (XCardinal)4);

            Arg[] okArgs = { new Arg(XtNames.XtNlabel,    X11.X11Utils.StringToSByteArray("Yes\0")),
                             new Arg(XtNames.XtNfromVert, _messageLabel) };
            _okCommand = Xtlib.XtCreateManagedWidget(_okCmdName,
                                                     Xtlib.XawCommandWidgetClass(), _dialogForm,
                                                     okArgs, (XCardinal)2);
            Xtlib.XtAddCallback(_okCommand, XtNames.XtNcallback, CallBackMarshaler.Add(_okCommand, this.DialogOk), IntPtr.Zero);

            Arg[] cancelArgs = { new Arg(XtNames.XtNlabel,     X11.X11Utils.StringToSByteArray("No\0")),
                                 new Arg(XtNames.XtNfromVert,  _messageLabel),
                                 new Arg(XtNames.XtNfromHoriz, _okCommand) };
            _cancelCommand = Xtlib.XtCreateManagedWidget(_cancelCmdName,
                                                         Xtlib.XawCommandWidgetClass(), _dialogForm,
                                                         cancelArgs, (XCardinal)3);
            Xtlib.XtAddCallback(_cancelCommand, XtNames.XtNcallback, CallBackMarshaler.Add(_cancelCommand, this.DialogCancel), IntPtr.Zero);
        }