// ############################################################################### // ### 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> Minimal initializing constructor. Use this constructor only for *** shell classes *** only! </summary> /// <param name="display">The display pointer, that specifies the connection to the X server. <see cref="IntPtr"/> </param> protected XrwWmShell(IntPtr display) : base(display, X11lib.XDefaultScreen(display), /* Select the current screen to display on. */ X11lib.XDefaultRootWindow(display)) /* Select display's root window as parent window. */ { ; }
/// <summary> Hide the widget and unmap the window (if any). </summary> public override void Hide() { _shown = false; X11lib.XUnmapWindow(_display, _window); X11lib.XFlush(_display); }
/// <summary> Initialize local ressources for all constructors. </summary> private void InitializeSmeRessources() { _focusedColorPixel = X11lib.XAllocParsedColorByName(_display, _screenNumber, XrwTheme.FocusedColor); Enter += HandleEnterDefault; Leave += HandleLeaveDefault; }
/// <summary> Redraw the widget. </summary> protected override void Redraw() { if (_assignedSize.Width < 1 || _assignedSize.Height < 1) { return; } TRectangle completeArea = new TRectangle(_assignedPosition, _assignedSize); // Background. // -- (windowless) // Outer border. if ((int)_borderWidth > 0) { X11lib.XSetForeground(_display, _gc, _borderColorPixel); base.DrawBorder(_display, _window, _gc, completeArea, _borderWidth); } TRectangle clientArea = ClientArea(); // Frame. if (_frameType != TFrameTypeExt.None) { base.DrawFrame(_display, _window, _gc, clientArea, _frameType, _darkShadowColorPixel, _lightShadowColorPixel); } RedrawContent(); }
// ############################################################################### // ### M E T H O D S // ############################################################################### #region XrwRectObj overrides /// <summary> Show the widget and map the window (if any). </summary> public override void Show() { _shown = true; X11lib.XMapWindow(_display, _window); X11lib.XFlush(_display); }
/// <summary> Measure the text using the default font of indicated graphics context. </summary> /// <param name="display"> The display pointer, that specifies the connection to the X server. <see cref="IntPtr"/> </param> /// <param name="gc"> The crapchics context to use for measuring. <see cref="IntPtr"/> </param> /// <param name="text"> The text to measure. <see cref="X11.TChar[]"/> </param> /// <returns> The measured size of the indicated text. <see cref="TSize"/> </returns> public virtual TSize MeasureTextLine(IntPtr display, IntPtr gc, X11.TChar[] text) { TSize result = new TSize(5, 5); if (display == IntPtr.Zero) { Console.WriteLine(CLASS_NAME + "::MeasureTextLine () ERROR: Argument null: display"); return(result); } if (gc == IntPtr.Zero) { Console.WriteLine(CLASS_NAME + "::MeasureTextLine () ERROR: Argument null: gc"); return(result); } TInt gcID = X11lib.XGContextFromGC(gc); if (gcID != 0) { TInt direction = 0; TInt fontAscent = 0; TInt fontDescent = 0; X11lib.XCharStruct xCharStruct = new X11lib.XCharStruct(); X11lib.XQueryTextExtents(display, gcID, text, (X11.TInt)text.Length, ref direction, ref fontAscent, ref fontDescent, ref xCharStruct); result.Width = (int)xCharStruct.width; result.Height = (int)fontAscent + (int)fontDescent; } else { Console.WriteLine(CLASS_NAME + "::MeasureTextLine () ERROR: Cannot investigate default font ressource ID of underlaying graphics context."); } return(result); }
/// <summary> Draw text with current font of indicated graphics context. </summary> /// <param name="display"> The display pointer, that specifies the connection to the X server. <see cref="IntPtr"/> </param> /// <param name="window"> The window to draw on. <see cref="IntPtr"/> </param> /// <param name="gc"> The graphics context to use for drawing. <see cref="IntPtr"/> </param> /// <param name="text"> The tyt to draw. <see cref="X11.TChar[]"/> </param> /// <param name="area"> The area to draw within. <see cref="Rectangle"/> </param> /// <param name="horzAlign"> The horizontal alignment (0.5F is centered). <see cref="XFloat"/> </param> /// <param name="vertAlign"> The vertical alignment (0.5F is centered). <see cref="XFloat"/> </param> public virtual void DrawTextLine(IntPtr display, IntPtr window, IntPtr gc, X11.TChar[] text, X11.TRectangle area, float horzAlign, float vertAlign) { if (display == IntPtr.Zero) { Console.WriteLine(CLASS_NAME + "::DrawTextLine () ERROR: Argument null: display"); return; } if (window == IntPtr.Zero) { Console.WriteLine(CLASS_NAME + "::DrawTextLine () ERROR: Argument null: window"); return; } if (gc == IntPtr.Zero) { Console.WriteLine(CLASS_NAME + "::DrawTextLine () ERROR: Argument null: gc"); return; } if (horzAlign < 0.0F || horzAlign > 1.0F) { Console.WriteLine(CLASS_NAME + "::DrawTextLine () ERROR: Argument out of range (0.0 ... 1.0): horzAlign"); if (horzAlign < 0.0F) { horzAlign = 0.0F; } if (horzAlign > 1.0F) { horzAlign = 1.0F; } } if (vertAlign < 0.0F || vertAlign > 1.0F) { Console.WriteLine(CLASS_NAME + "::DrawTextLine () ERROR: Argument out of range (0.0 ... 1.0): vertAlign"); if (vertAlign < 0.0F) { vertAlign = 0.0F; } if (vertAlign > 1.0F) { vertAlign = 1.0F; } } TSize textMeasure = MeasureTextLine(display, gc, text); int textX = (int)((area.Width - textMeasure.Width) * horzAlign); if (textX < _borderWidth + 2) { textX = _borderWidth + 2; } if (textX > area.Width - textMeasure.Width - _borderWidth - 2) { textX = area.Width - textMeasure.Width - _borderWidth - 2; } int textY = (int)((area.Height - textMeasure.Height) * vertAlign) + (int)(textMeasure.Height * 0.85F); X11lib.XDrawString(display, window, gc, (TInt)((int)area.Left + (int)textX), (TInt)((int)area.Top + (int)textY), text, (X11.TInt)text.Length); }
// ############################################################################### // ### M E T H O D S // ############################################################################### #region XrwRectObj overrides /// <summary> Show the widget and map the window (if any). </summary> /// <remarks> Adds the override shell to her application schell's children, if not already done. </remarks> public override void Show() { _shown = true; X11lib.XMapWindow(_display, _window); X11lib.XFlush(_display); X11lib.XSetInputFocus(_display, _window, X11lib.TRevertTo.RevertToParent, (TInt)0); }
// ############################################################################### // ### 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> Hidden initializing constructor. </summary> /// <param name="display">The display pointer, that specifies the connection to the X server. <see cref="IntPtr"/> </param> /// <param name="screenNumber"> The appropriate screen number on the host server. <see cref="System.Int32"/> </param> /// <param name="parentWindow"> The X11 *** parent *** window for X11 calls. This widget has no X11 *** own *** window. <see cref="IntPtr"/> </param> protected XrwBox(IntPtr display, X11.TInt screenNumber, IntPtr parentWindow) : base(display, screenNumber, parentWindow) { _expandToAvailableWidth = true; _borderColorPixel = X11lib.XAllocParsedColorByName(_display, _screenNumber, XrwTheme.OuterBorderColor); _backgroundColorPixel = X11lib.XAllocParsedColorByName(_display, _screenNumber, XrwTheme.BackGroundColor); }
public static IntPtr[] FindWindows(IntPtr display, string title) { List <IntPtr> windows = new List <IntPtr>(); return(FindChildWindows(display, X11lib.XDefaultRootWindow(display), title, ref windows)); }
/// <summary> Redraw the widget. </summary> protected override void Redraw() { if (_assignedSize.Width < 1 || _assignedSize.Height < 1) { return; } TRectangle completeArea = new TRectangle(_assignedPosition, _assignedSize); // Background. if (_focused) { X11lib.XSetForeground(_display, _gc, _focusedColorPixel); } else { X11lib.XSetForeground(_display, _gc, _backgroundColorPixel); } base.DrawBackground(_display, _window, _gc, completeArea); // Outer border. if ((int)_borderWidth > 0) { X11lib.XSetForeground(_display, _gc, _borderColorPixel); base.DrawBorder(_display, _window, _gc, completeArea, _borderWidth); } TRectangle clientArea = ClientArea(); // Frame. if (_frameType != TFrameTypeExt.None) { bool _pressed = false; TFrameTypeExt frameType = _frameType; if (_pressed == true && frameType == TFrameTypeExt.Raised) { frameType = TFrameTypeExt.Sunken; } else if (_pressed == true && frameType == TFrameTypeExt.Sunken) { frameType = TFrameTypeExt.Raised; } else if (_pressed == true && frameType == TFrameTypeExt.Chiseled) { frameType = TFrameTypeExt.Ledged; } else if (_pressed == true && frameType == TFrameTypeExt.Ledged) { frameType = TFrameTypeExt.Chiseled; } base.DrawFrame(_display, _window, _gc, clientArea, frameType, _darkShadowColorPixel, _lightShadowColorPixel); } base.RedrawContent(); }
//**************************************************************************** //See: https://stackoverflow.com/questions/42449050/cant-get-a-window-handle //**************************************************************************** private static IntPtr[] FindChildWindows(IntPtr display, IntPtr window, string title, ref List <IntPtr> windows) { IntPtr rootWindow; IntPtr parentWindow; IntPtr[] childWindows = new IntPtr[0]; int childWindowsLength; X11lib.XQueryTree(display, window, out rootWindow, out parentWindow, out childWindows, out childWindowsLength); childWindows = new IntPtr[childWindowsLength]; X11lib.XQueryTree(display, window, out rootWindow, out parentWindow, out childWindows, out childWindowsLength); string windowFetchedTitle; X11lib.XFetchName(display, window, out windowFetchedTitle); if (title == windowFetchedTitle && !windows.Contains(window)) { windows.Add(window); } for (int childWindowsIndexer = 0; childWindowsIndexer < childWindows.Length; childWindowsIndexer++) { IntPtr childWindow = childWindows[childWindowsIndexer]; string childWindowFetchedTitle; X11lib.XFetchName(display, childWindow, out childWindowFetchedTitle); if (title == childWindowFetchedTitle && !windows.Contains(childWindow)) { windows.Add(childWindow); } FindChildWindows(display, childWindow, title, ref windows); } windows.TrimExcess(); return(windows.ToArray()); }
// ############################################################################### // ### M E T H O D S // ############################################################################### #region Methods /// <summary> Get the window attributes of the underlaying X11 window. </summary> /// <param name="windowAttributes"> The structure containing the determined window attributes. <see cref="X11lib.XWindowAttributes"/> </param> /// <returns> True on success, or false on any error. <see cref="System.Boolean"/> </returns> public bool GetWindowAttributes(ref X11lib.XWindowAttributes windowAttributes) { if (X11lib.XGetWindowAttributes(_display, _window, ref windowAttributes) != (TInt)0) { return(true); } else { return(false); } }
/// <summary> Dispose by parent. </summary> public override void DisposeByParent() { // Free shared ressources. if (_gc != IntPtr.Zero) { X11lib.XFreeGC(_display, _gc); _gc = IntPtr.Zero; } base.DisposeByParent(); }
/// <summary> Initialize local ressources for all constructors. </summary> private void InitializeXrwVisibleRectObjRessources() { _gc = X11lib.XCreateGC(_display, _window, 0, IntPtr.Zero); if (_gc == IntPtr.Zero) { throw new OperationCanceledException("Failed to create graphics context."); } _backgroundColorPixel = X11lib.XAllocParsedColorByName(_display, _screenNumber, XrwTheme.BackGroundColor); _darkShadowColorPixel = X11lib.XAllocParsedColorByName(_display, _screenNumber, XrwTheme.DarkShadowColor); _lightShadowColorPixel = X11lib.XAllocParsedColorByName(_display, _screenNumber, XrwTheme.LightShadowColor); }
/// <summary> Hide the widget and unmap the window (if any). </summary> public override void Hide() { _shown = false; for (int cntChildren = _children.Count - 1; cntChildren >= 0; cntChildren--) { _children[cntChildren].Hide(); } X11lib.XUnmapWindow(_display, _window); X11lib.XFlush(_display); }
/// <summary> Initialize local ressources for all constructors. </summary> private void InitializeCommandRessources() { _frameWidth = XrwTheme.InteractingFrameWidth; _frameType = (TFrameTypeExt)XrwTheme.InteractingFrameType; _focusedColorPixel = X11lib.XAllocParsedColorByName(_display, _screenNumber, XrwTheme.FocusedColor); Enter += this.HandleEnterDefault; Leave += this.HandleLeaveDefault; ButtonPress += this.HandleButtonPressDefault; ButtonRelease += this.HandleButtonReleaseDefault; }
/// <summary> Redraw the widget. </summary> protected virtual void RedrawContent() { if (_assignedSize.Width < 1 || _assignedSize.Height < 1) { return; } TRectangle clientArea = ClientArea(); clientArea.X += _frameWidth; clientArea.Width -= _frameWidth * 2; clientArea.Y += _frameWidth; clientArea.Height -= _frameWidth * 2; // Content. X11lib.XSetForeground(_display, _gc, _textColorPixel); if (_leftBitmap != null) { int vertAlignOffset = (int)((clientArea.Height - _leftBitmap.Height - _space * 2) * _leftBitmapVertAlign); _leftBitmap.Draw(_window, _gc, (TInt)(clientArea.X + _leftMargin), (TInt)(clientArea.Y + _space + vertAlignOffset)); clientArea.X += _leftBitmap.Width + _leftMargin + _space; clientArea.Width -= _leftBitmap.Width + _leftMargin + _space; } else { clientArea.X += _leftMargin; clientArea.Width -= _leftMargin; } if (_rightBitmap != null) { int vertAlignOffset = (int)((clientArea.Height - _rightBitmap.Height - _space * 2) * _rightBitmapVertAlign); _rightBitmap.Draw(_window, _gc, (TInt)(clientArea.Right - _rightBitmap.Width - _rightMargin), (TInt)(clientArea.Y + _space + vertAlignOffset)); clientArea.Width -= _rightBitmap.Width + _space + _rightMargin; } else { clientArea.Width -= _rightMargin; } clientArea.Y += _space; clientArea.Height -= _space * 2; /* DEBUG START */ // X11lib.XDrawLine (_display, _window, _gc, (TInt)clientArea.X, (TInt)clientArea.Y, (TInt)clientArea.Right, (TInt)clientArea.Bottom); /* DEBUG END */ clientArea.X += 2; /* No idea why, but it must be done! */ base.DrawTextLines(_lines, clientArea, _horzTextAlign, _vertTextAlign); }
// ############################################################################### // ### M E T H O D S // ############################################################################### #region Methods /// <summary> Alloc a color from the default colormap of the display's default screen. </summary> /// <param name="colorname"> The color to alloc. <see cref="System.String"/> </param> /// <returns> The color pixel on success, or the white pixel otherwise. <see cref="X11.TColor"/> </returns> public TColor AllocColorFromDefaultColormap(string colorname) { IntPtr display = Xtlib.XtDisplay(_shell); if (display == IntPtr.Zero) { return(TColor.FallbackWhite); } TInt scrnID = X11lib.XDefaultScreen(display); return(X11lib.XAllocClosestNamedColor(display, X11lib.XDefaultColormap(display, scrnID), colorname)); }
// ############################################################################### // ### 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); }
/// <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); }
/// <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> Set the assigned position and size, calculated by the geometry management. </summary> /// <param name="rectObj"> The rectangle object to set the assigned position and size for. <see cref="XrwRectObj"/> </param> /// <param name="position"> The assigned position to set. <see cref="TPoint"/> </param> /// <param name="size"> The assigned position to set. <see cref="TSize"/> </param> public static void SetAssignedGeometry(XrwRectObj rectObj, TPoint position, TSize size) { if (rectObj == null) { Console.WriteLine("GeometryManagerAccess::SetAssignedGeometry () ERROR: Argument null: rectObj"); return; } // Fixed size always has priority! if (rectObj.IsFixedWidth == true) { size.Width = rectObj.FixedSize.Width; } if (rectObj.IsFixedWidth == true) { size.Height = rectObj.FixedSize.Height; } rectObj._assignedSize = size; if (rectObj.HasOwnWindow && (rectObj is XrwVisibleRectObj)) { // Transfer the geometry to the underlaying window. XrwVisibleRectObj visibleRect = rectObj as XrwVisibleRectObj; if (visibleRect.Display != IntPtr.Zero && visibleRect.Window != IntPtr.Zero) { // This call causes a ConfigureNotify event. X11lib.XMoveResizeWindow(visibleRect.Display, visibleRect.Window, (TInt)position.X, (TInt)position.Y, (TUint)size.Width, (TUint)size.Height); visibleRect._assignedPosition = new TPoint(0, 0); } else { throw new AccessViolationException("XrwVisibleRectObj or inherited widget without display or window."); } } else { rectObj._assignedPosition = position; } // Child should be prevented from overwriting parent's border. size.Width -= 2 * rectObj.BorderWidth; size.Height -= 2 * rectObj.BorderWidth; rectObj.CalculateChildLayout(position, size); }
/// <summary> Initialize an *** own *** window. </summary> /// <remarks> Use thei initialization from XrwCore +++ inheridet +++ classes, that should act as a widget, not as a gadget. </remarks> protected void InitializeOwnWindow() { // Create a *** own *** window and exchange the *** parent *** window against it. _window = X11lib.XCreateSimpleWindow(_display, _window, (TInt)_assignedPosition.X, (TInt)_assignedPosition.Y, (TUint)_fixedSize.Width, (TUint)_fixedSize.Height, 0, 0, _backgroundColorPixel); if (_window == IntPtr.Zero) { Console.WriteLine(CLASS_NAME + "::InitializeOwnWindow () ERROR. Can not create transient shell."); throw new OperationCanceledException("Failed to create own window."); } X11lib.XSelectInput(_display, _window, EventMask.ExposureMask | EventMask.ButtonPressMask | EventMask.ButtonReleaseMask | EventMask.EnterWindowMask | EventMask.LeaveWindowMask | EventMask.PointerMotionMask | EventMask.FocusChangeMask | EventMask.KeyPressMask | EventMask.KeyReleaseMask | EventMask.SubstructureNotifyMask); _hasOwnWindow = true; }
/// <summary> Draw the border. </summary> /// <param name="display"> The display pointer, that specifies the connection to the X server. <see cref="IntPtr"/> </param> /// <param name="window"> The window to draw on. <see cref="IntPtr"/> </param> /// <param name="gc"> The graphics context to use for drawing. <see cref="IntPtr"/> </param> /// <param name="borderArea"> The area to draw the border on. <see cref="TRectangle"/> </param> /// <param name="borderWidth"> The width of the border. <see cref="System.Int32"/> </param> public virtual void DrawBorder(IntPtr display, IntPtr window, IntPtr gc, TRectangle borderArea, int borderWidth) { if (display == IntPtr.Zero) { Console.WriteLine(CLASS_NAME + "::DrawOuterBorder () ERROR: Argument null: display"); return; } if (window == IntPtr.Zero) { Console.WriteLine(CLASS_NAME + "::DrawOuterBorder () ERROR: Argument null: window"); return; } if (gc == IntPtr.Zero) { Console.WriteLine(CLASS_NAME + "::DrawOuterBorder () ERROR: Argument null: gc"); return; } if (borderWidth <= 0) { return; } for (int counter = 0; counter < (int)borderWidth; counter++) { // Top: L ==> R X11lib.XDrawLine(display, window, gc, (X11.TInt)(borderArea.Left + counter), (X11.TInt)(borderArea.Top + counter), (X11.TInt)((int)borderArea.Right - counter - 1), (X11.TInt)(borderArea.Top + counter)); // Right: T ==> B X11lib.XDrawLine(display, window, gc, (X11.TInt)((int)borderArea.Right - counter - 1), (X11.TInt)(borderArea.Top + counter), (X11.TInt)((int)borderArea.Right - counter - 1), (X11.TInt)((int)borderArea.Bottom - counter - 1)); // Bottom: R ==> L X11lib.XDrawLine(display, window, gc, (X11.TInt)((int)borderArea.Right - counter - 1), (X11.TInt)((int)borderArea.Bottom - counter - 1), (X11.TInt)(borderArea.Left + counter), (X11.TInt)((int)borderArea.Bottom - counter - 1)); // Left: B ==> T X11lib.XDrawLine(display, window, gc, (X11.TInt)(borderArea.Left + counter), (X11.TInt)((int)borderArea.Bottom - counter - 1), (X11.TInt)(borderArea.Left + counter), (X11.TInt)(borderArea.Top + counter)); // Fix X11lib drawing problems (not drawn pixel at bottom right corner). X11lib.XDrawPoint(display, window, gc, (X11.TInt)((int)borderArea.Right - (int)counter - 1), (X11.TInt)(borderArea.Bottom - (int)counter - 1)); } }
/// <summary> Draw the background. </summary> /// <param name="display"> The display pointer, that specifies the connection to the X server. <see cref="IntPtr"/> </param> /// <param name="window"> The window to draw on. <see cref="IntPtr"/> </param> /// <param name="gc"> The graphics context to use for drawing. <see cref="IntPtr"/> </param> /// <param name="backgroundArea"> The area to draw the background on. <see cref="TRectangle"/> </param> public virtual void DrawBackground(IntPtr display, IntPtr window, IntPtr gc, TRectangle backgroundArea) { if (display == IntPtr.Zero) { Console.WriteLine(CLASS_NAME + "::DrawBackground () ERROR: Argument null: display"); return; } if (window == IntPtr.Zero) { Console.WriteLine(CLASS_NAME + "::DrawBackground () ERROR: Argument null: window"); return; } if (gc == IntPtr.Zero) { Console.WriteLine(CLASS_NAME + "::DrawBackground () ERROR: Argument null: gc"); return; } X11lib.XFillRectangle(display, window, gc, (TInt)backgroundArea.X, (TInt)backgroundArea.Y, (TUint)backgroundArea.Width, (TUint)backgroundArea.Height); }
// ############################################################################### // ### 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); }
/// <summary> Set the shell icon for a WM shell. </summary> /// <param name="application"> The WM shell to set the icon for. <see cref="XrwWmShell"/> </param> /// <param name="iconPath"> The path (relative, if applicable) to the icon to set. <see cref="System.String"/> </param> /// <returns> Returns true on success, or false otherwise. <see cref="System.Boolean"/> </returns> public static bool SetWmShellIcon(XrwWmShell application, string iconPath) { bool result = false; if (application == null) { Console.WriteLine(CLASS_NAME + "::SetWmShellIcon() ERROR: Paramerter 'application' null."); return(result); } if (string.IsNullOrEmpty(iconPath)) { Console.WriteLine(CLASS_NAME + "::SetWmShellIcon() ERROR: Paramerter 'iconPath' null or empty."); return(result); } using (X11Graphic appIcon = new X11Graphic(application.Display, application.Screen, iconPath)) { IntPtr appGraphicPixMap = appIcon.CreateIndependentGraphicPixmap(application.Display, application.Window); IntPtr appMaskPixMap = appIcon.CreateIndependentMaskPixmap(application.Display, application.Window); if (appGraphicPixMap != IntPtr.Zero && appMaskPixMap != IntPtr.Zero) { X11lib.XWMHints wmHints = X11lib.XAllocWMHints(); wmHints.flags = X11lib.XWMHintMask.IconPixmapHint | X11lib.XWMHintMask.IconPositionHint | X11lib.XWMHintMask.IconMaskHint; wmHints.icon_pixmap = appGraphicPixMap; wmHints.icon_mask = appMaskPixMap; wmHints.icon_x = 0; wmHints.icon_y = 0; X11lib.XSetWMHints(application.Display, application.Window, ref wmHints); result = true; } else { Console.WriteLine(CLASS_NAME + "::SetWmShellIcon () ERROR: Can not create application icon."); } } return(result); }
/// <summary> Redraw the widget. </summary> protected virtual void Redraw() { if (_assignedSize.Width < 1 || _assignedSize.Height < 1) { return; } TRectangle completeArea = new TRectangle(_assignedPosition, _assignedSize); X11lib.XSetForeground(_display, _gc, _backgroundColorPixel); base.DrawBackground(_display, _window, _gc, completeArea); if ((int)_borderWidth > 0) { X11lib.XSetForeground(_display, _gc, _borderColorPixel); base.DrawBorder(_display, _window, _gc, new TRectangle(_assignedPosition, _assignedSize), _borderWidth); } if (_frameType != TFrameTypeExt.None && _frameWidth > 0) { base.DrawFrame(_display, _window, _gc, this.ClientArea(), _frameType, _darkShadowColorPixel, _lightShadowColorPixel); } }
/// <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 InitializeOverrideShellResources(ref TPoint assignedPosition) { TInt depth = X11lib.XDefaultDepth(_display, _screenNumber); X11lib.WindowAttributeMask mask = X11lib.WindowAttributeMask.CWOverrideRedirect | X11lib.WindowAttributeMask.CWSaveUnder; X11lib.XSetWindowAttributes attributes = new X11lib.XSetWindowAttributes(); attributes.override_redirect = (TBoolean)1; attributes.save_under = (TBoolean)1; _window = X11lib.XCreateWindow(_display, X11lib.XDefaultRootWindow(_display), (TInt)assignedPosition.X, (TInt)assignedPosition.Y, (TUint)_assignedSize.Width, (TUint)_assignedSize.Height, 0, depth, (TUint)X11lib.WindowClass.InputOutput, IntPtr.Zero, mask, ref attributes); if (_window == IntPtr.Zero) { Console.WriteLine(CLASS_NAME + "::InitializeOverrideShellResources () ERROR. Can not create menu shell."); return; } _hasOwnWindow = true; X11lib.XSelectInput(_display, _window, EventMask.ExposureMask | EventMask.ButtonPressMask | EventMask.ButtonReleaseMask | EventMask.EnterWindowMask | EventMask.LeaveWindowMask | EventMask.PointerMotionMask | EventMask.FocusChangeMask | EventMask.KeyPressMask | EventMask.KeyReleaseMask | EventMask.SubstructureNotifyMask); /* Create the foreground Graphics Context. */ if (_gc != IntPtr.Zero) { if (XrwApplicationSettings.VERBOSE_OUTPUT_TO_CONSOLE) { Console.WriteLine(CLASS_NAME + "::InitializeOverrideShellResources () Replace the foreground GC."); } X11lib.XFreeGC(_display, _gc); _gc = IntPtr.Zero; } _gc = X11lib.XCreateGC(_display, _window, 0, IntPtr.Zero); }