// Constructor. internal Widget(Display dpy, Screen screen, DrawableKind kind, Widget parent) : base(dpy, screen, kind) { // Set the initial widget properties. cursor = null; autoMapChildren = true; sensitive = true; // Insert this widget into the widget tree under its parent. this.parent = parent; this.topChild = null; this.nextAbove = null; if(parent != null) { ancestorSensitive = (parent.sensitive && parent.ancestorSensitive); nextBelow = parent.topChild; if(parent.topChild != null) { parent.topChild.nextAbove = this; } parent.topChild = this; } else { ancestorSensitive = true; nextBelow = null; } this.eventMask = 0; }
// Modify the cursor on a widget. internal static void ModifyCursor (Widget widget, ToolkitCursorType cursorType, Frame frame) { if (cursorType == ToolkitCursorType.InheritParent) { // Change the cursor back to the same value as the parent. widget.Cursor = null; } else if (cursorType == ToolkitCursorType.Default) { // Set the default cursor to something matching X. widget.Cursor = new Cursor(CursorType.XC_left_ptr); } else { // Create a cursor based on the supplied image. if (frame != null && /* irgnore pixel format ! * frame.PixelFormat == DotGNU.Images.PixelFormat.Format1bppIndexed * && */ frame.Mask != null) { if (cursorType != ToolkitCursorType.UserDefined) { lock (typeof(DrawingWindow)) { if (cursors == null) { cursors = new Xsharp.Cursor [32]; } Xsharp.Cursor curs = cursors[(int)cursorType]; if (curs == null) { cursors[(int)cursorType] = curs = new Xsharp.Cursor (widget.Screen, frame); } widget.Cursor = curs; } } else { widget.Cursor = new Xsharp.Cursor (widget.Screen, frame); } return; } // Last ditch attempt - use the nearest X11 cursor. CursorType type; switch (cursorType) { case ToolkitCursorType.AppStarting: type = CursorType.XC_watch; break; case ToolkitCursorType.Arrow: case ToolkitCursorType.Default: type = CursorType.XC_left_ptr; break; case ToolkitCursorType.Cross: type = CursorType.XC_crosshair; break; case ToolkitCursorType.IBeam: type = CursorType.XC_xterm; break; case ToolkitCursorType.No: type = CursorType.XC_X_cursor; break; case ToolkitCursorType.SizeAll: type = CursorType.XC_fleur; break; case ToolkitCursorType.SizeNS: case ToolkitCursorType.VSplit: type = CursorType.XC_sb_v_double_arrow; break; case ToolkitCursorType.SizeWE: case ToolkitCursorType.HSplit: type = CursorType.XC_sb_h_double_arrow; break; case ToolkitCursorType.UpArrow: type = CursorType.XC_sb_up_arrow; break; case ToolkitCursorType.WaitCursor: type = CursorType.XC_watch; break; case ToolkitCursorType.Help: type = CursorType.XC_question_arrow; break; case ToolkitCursorType.Hand: type = CursorType.XC_hand2; break; case ToolkitCursorType.SizeNWSE: case ToolkitCursorType.SizeNESW: case ToolkitCursorType.NoMove2D: case ToolkitCursorType.NoMoveHoriz: case ToolkitCursorType.NoMoveVert: case ToolkitCursorType.PanEast: case ToolkitCursorType.PanNE: case ToolkitCursorType.PanNorth: case ToolkitCursorType.PanNW: case ToolkitCursorType.PanSE: case ToolkitCursorType.PanSouth: case ToolkitCursorType.PanSW: case ToolkitCursorType.PanWest: case ToolkitCursorType.UserDefined: default: type = CursorType.XC_circle; break; } widget.Cursor = new Cursor(type); } }
// Perform a hit test and set the cursor to the appropriate value. private HitTest SetCursor(int x, int y) { HitTest test = PerformHitTest(x, y); CursorType cursor; switch(test) { case HitTest.TopLeft: cursor = CursorType.XC_top_left_corner; break; case HitTest.TopRight: cursor = CursorType.XC_top_right_corner; break; case HitTest.BottomLeft: cursor = CursorType.XC_bottom_left_corner; break; case HitTest.BottomRight: cursor = CursorType.XC_bottom_right_corner; break; case HitTest.Top: cursor = CursorType.XC_top_side; break; case HitTest.Bottom: cursor = CursorType.XC_bottom_side; break; case HitTest.Left: cursor = CursorType.XC_left_side; break; case HitTest.Right: cursor = CursorType.XC_right_side; break; default: cursor = CursorType.XC_inherit_parent; break; } Cursor = new Cursor(cursor); return test; }
// Modify the cursor on a widget. internal static void ModifyCursor (Widget widget, ToolkitCursorType cursorType, Frame frame) { if(cursorType == ToolkitCursorType.InheritParent) { // Change the cursor back to the same value as the parent. widget.Cursor = null; } else if(cursorType == ToolkitCursorType.Default) { // Set the default cursor to something matching X. widget.Cursor = new Cursor(CursorType.XC_left_ptr); } else { // Create a cursor based on the supplied image. if(frame != null && /* irgnore pixel format ! frame.PixelFormat == DotGNU.Images.PixelFormat.Format1bppIndexed && */ frame.Mask != null) { if(cursorType != ToolkitCursorType.UserDefined) { lock(typeof(DrawingWindow)) { if(cursors == null) { cursors = new Xsharp.Cursor [32]; } Xsharp.Cursor curs = cursors[(int)cursorType]; if(curs == null) { cursors[(int)cursorType] = curs = new Xsharp.Cursor (widget.Screen, frame); } widget.Cursor = curs; } } else { widget.Cursor = new Xsharp.Cursor (widget.Screen, frame); } return; } // Last ditch attempt - use the nearest X11 cursor. CursorType type; switch(cursorType) { case ToolkitCursorType.AppStarting: type = CursorType.XC_watch; break; case ToolkitCursorType.Arrow: case ToolkitCursorType.Default: type = CursorType.XC_left_ptr; break; case ToolkitCursorType.Cross: type = CursorType.XC_crosshair; break; case ToolkitCursorType.IBeam: type = CursorType.XC_xterm; break; case ToolkitCursorType.No: type = CursorType.XC_X_cursor; break; case ToolkitCursorType.SizeAll: type = CursorType.XC_fleur; break; case ToolkitCursorType.SizeNS: case ToolkitCursorType.VSplit: type = CursorType.XC_sb_v_double_arrow; break; case ToolkitCursorType.SizeWE: case ToolkitCursorType.HSplit: type = CursorType.XC_sb_h_double_arrow; break; case ToolkitCursorType.UpArrow: type = CursorType.XC_sb_up_arrow; break; case ToolkitCursorType.WaitCursor: type = CursorType.XC_watch; break; case ToolkitCursorType.Help: type = CursorType.XC_question_arrow; break; case ToolkitCursorType.Hand: type = CursorType.XC_hand2; break; case ToolkitCursorType.SizeNWSE: case ToolkitCursorType.SizeNESW: case ToolkitCursorType.NoMove2D: case ToolkitCursorType.NoMoveHoriz: case ToolkitCursorType.NoMoveVert: case ToolkitCursorType.PanEast: case ToolkitCursorType.PanNE: case ToolkitCursorType.PanNorth: case ToolkitCursorType.PanNW: case ToolkitCursorType.PanSE: case ToolkitCursorType.PanSouth: case ToolkitCursorType.PanSW: case ToolkitCursorType.PanWest: case ToolkitCursorType.UserDefined: default: type = CursorType.XC_circle; break; } widget.Cursor = new Cursor(type); } }