示例#1
0
        // ###############################################################################
        // ### M E T H O D S
        // ###############################################################################

        #region Methods

        #endregion

        #region Event handler

        /// <summary> Handle the ButtonPress event. </summary>
        /// <param name="source"> The widget, the ButtonPress event is assigned to. <see cref="XrwRectObj"/> </param>
        /// <param name="e"> The event data. <see cref="XawButtonEvent"/> </param>
        /// <remarks> Set XawButtonEvent. Set result to nonzero to stop further event processing. </remarks>
        private new void HandleButtonPressDefault(XrwRectObj source, XrwButtonEvent e)
        {
            if (_menu != null)
            {
                // Set position and size.
                TPoint position = new TPoint(20, 20);
                X11lib.XWindowAttributes menuButtonAttributes = new X11lib.XWindowAttributes();
                if (this.GetWindowAttributes(ref menuButtonAttributes) == true)
                {
                    position.X = (int)menuButtonAttributes.x;
                    position.Y = (int)menuButtonAttributes.y + (int)menuButtonAttributes.height;
                }
                else
                {
                    Console.WriteLine(CLASS_NAME + "::HandleButtonPress () ERROR: Unable to determine window attributes.");
                }

                XrwObject parent = this.Parent;
                while (parent != null && (parent is XrwVisibleRectObj))
                {
                    if (parent is XrwWmShell)
                    {
                        position.X += (parent as XrwWmShell).AssignedPosition.X;
                        position.Y += (parent as XrwWmShell).AssignedPosition.Y;
                    }
                    else if (parent.HasOwnWindow)
                    {
                        if ((parent as XrwVisibleRectObj).GetWindowAttributes(ref menuButtonAttributes) == true)
                        {
                            position.X += (int)menuButtonAttributes.x;
                            position.Y += (int)menuButtonAttributes.y;
                        }
                        else
                        {
                            Console.WriteLine(CLASS_NAME + "::HandleButtonPress () ERROR: Unable to determine parent window attributes.");
                        }
                    }
                    else
                    {
                        // Windowless widgets positions must not be added!
                    }
                    parent = (parent as XrwVisibleRectObj).Parent;
                }

                TSize size = _menu.AssignedSize;
                _menu.MoveResize(ref position, ref size);

                // Register menu shell to her application shell for integrating into their event loop.
                XrwApplicationShell appShell = _menu.ApplicationShell;
                if (appShell != null)
                {
                    if (!appShell.HasChild(_menu))
                    {
                        appShell.AddChild(_menu);
                    }
                }
                else
                {
                    Console.WriteLine(CLASS_NAME + "::HandleButtonPress () ERROR. Can not investigate menu's application shell.");
                }

                _menu.Show();
            }
            else
            {
                Console.WriteLine(CLASS_NAME + "::HandleButtonPress () ERROR: No menu registered.");
            }
            e.Result = 1;
        }