update this directory to include the handle branch changes, as well as the SendParent...
[mono-project.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms.X11Internal / XplatUIX11-new.cs
blobd40a555bb64a386daec4d885189de7cd84ac69b0
1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
8 //
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 //
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004-2006 Novell, Inc.
22 // Authors:
23 // Peter Bartok pbartok@novell.com
24 // Chris Toshok toshok@ximian.com
28 // NOTE:
29 // This driver understands the following environment variables: (Set the var to enable feature)
31 // MONO_XEXCEPTIONS = throw an exception when a X11 error is encountered;
32 // by default a message is displayed but execution continues
34 // MONO_XSYNC = perform all X11 commands synchronous; this is slower but
35 // helps in debugging errors
38 // NOT COMPLETE
40 // define to log Window handles and relationships to stdout
41 #undef DriverDebug
43 // Extra detailed debug
44 #undef DriverDebugExtra
45 #undef DriverDebugParent
46 #undef DriverDebugCreate
47 #undef DriverDebugDestroy
48 #undef DriverDebugThreads
49 #undef DriverDebugXEmbed
51 using System;
52 using System.ComponentModel;
53 using System.Collections;
54 using System.Diagnostics;
55 using System.Drawing;
56 using System.Drawing.Drawing2D;
57 using System.Drawing.Imaging;
58 using System.IO;
59 using System.Net;
60 using System.Net.Sockets;
61 using System.Reflection;
62 using System.Runtime.InteropServices;
63 using System.Text;
64 using System.Threading;
65 using System.Windows.Forms;
67 /// X11 Version
68 namespace System.Windows.Forms.X11Internal {
69 internal class XplatUIX11_new : XplatUIDriver {
70 #region Local Variables
71 // General
72 static volatile XplatUIX11_new Instance;
73 static readonly object lockobj = new object ();
74 static int RefCount;
75 static bool themes_enabled;
77 static Hashtable MessageQueues; // Holds our thread-specific X11ThreadQueues
79 X11Display display;
81 #endregion // Local Variables
82 #region Constructors
83 private XplatUIX11_new() {
84 // Handle singleton stuff first
85 RefCount = 0;
87 // Now regular initialization
88 MessageQueues = Hashtable.Synchronized (new Hashtable(7));
89 if (Xlib.XInitThreads() == 0) {
90 Console.WriteLine ("Failed XInitThreads. The X11 event loop will not function properly");
94 private void InitializeDisplay ()
96 display = new X11Display (Xlib.XOpenDisplay(IntPtr.Zero));
98 Graphics.FromHdcInternal (display.Handle);
101 ~XplatUIX11_new() {
102 // Remove our display handle from S.D
103 Graphics.FromHdcInternal (IntPtr.Zero);
106 #endregion // Constructors
108 #region Singleton Specific Code
109 public static XplatUIX11_new GetInstance() {
110 lock (lockobj) {
111 if (Instance == null) {
112 Instance = new XplatUIX11_new ();
114 Instance.InitializeDisplay ();
116 RefCount++;
118 return Instance;
121 public int Reference {
122 get {
123 return RefCount;
126 #endregion
128 #region Internal Methods
129 internal static void Where() {
130 Console.WriteLine("Here: {0}\n", GetInstance().display.WhereString());
133 #endregion // Internal Methods
135 #region Private Methods
137 internal X11ThreadQueue ThreadQueue (Thread thread)
139 X11ThreadQueue queue;
141 queue = (X11ThreadQueue)MessageQueues[thread];
142 if (queue == null) {
143 queue = new X11ThreadQueue(thread);
144 MessageQueues[thread] = queue;
147 return queue;
149 #endregion // Private Methods
152 #region Public Properties
153 internal override int Caption {
154 get { return 19; }
157 internal override Size CursorSize {
158 get { return display.CursorSize; }
161 internal override bool DragFullWindows {
162 get { return true; }
165 internal override Size DragSize {
166 get { return new Size(4, 4); }
169 internal override Size FrameBorderSize {
170 get { return new Size (4, 4); }
173 internal override Size IconSize {
174 get { return display.IconSize; }
177 internal override int KeyboardSpeed {
178 get { return display.KeyboardSpeed; }
181 internal override int KeyboardDelay {
182 get { return display.KeyboardSpeed; }
185 internal override Size MaxWindowTrackSize {
186 get { return new Size (WorkingArea.Width, WorkingArea.Height); }
189 internal override Size MinimizedWindowSize {
190 get { return new Size(1, 1); }
193 internal override Size MinimizedWindowSpacingSize {
194 get { return new Size(1, 1); }
197 internal override Size MinimumWindowSize {
198 get { return new Size(1, 1); }
201 internal override Size MinWindowTrackSize {
202 get { return new Size(1, 1); }
205 internal override Keys ModifierKeys {
206 get { return display.ModifierKeys; }
209 internal override Size SmallIconSize {
210 get { return display.SmallIconSize; }
213 internal override int MouseButtonCount {
214 get { return 3; /* FIXME - should detect this somehow.. */}
217 internal override bool MouseButtonsSwapped {
218 get { return false; /*FIXME - how to detect? */}
221 internal override Size MouseHoverSize {
222 get { return new Size (1, 1); }
225 internal override int MouseHoverTime {
226 get { return display.MouseHoverTime; }
229 internal override bool MouseWheelPresent {
230 get { return true; /* FIXME - how to detect? */ }
233 internal override Rectangle VirtualScreen {
234 get { return WorkingArea; }
237 internal override Rectangle WorkingArea {
238 get { return display.WorkingArea; }
241 internal override bool ThemesEnabled {
242 get { return XplatUIX11_new.themes_enabled; }
246 #endregion // Public properties
248 #region Public Static Methods
249 internal override IntPtr InitializeDriver()
251 lock (this) {
252 if (display == null)
253 display = new X11Display (Xlib.XOpenDisplay(IntPtr.Zero));
255 return IntPtr.Zero;
258 internal override void ShutdownDriver(IntPtr token)
260 lock (this) {
261 if (display != null) {
262 display.Close ();
263 display = null;
268 internal override void EnableThemes()
270 themes_enabled = true;
273 internal override void Activate (IntPtr handle)
275 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
277 if (hwnd != null)
278 hwnd.Activate ();
281 internal override void AudibleAlert()
283 display.AudibleAlert ();
287 internal override void CaretVisible (IntPtr handle, bool visible)
289 display.CaretVisible (handle, visible);
292 // XXX this implementation should probably be shared between all non-win32 backends
293 internal override bool CalculateWindowRect (ref Rectangle ClientRect, int Style, int ExStyle, Menu menu, out Rectangle WindowRect)
295 FormBorderStyle border_style;
296 TitleStyle title_style;
297 bool border_static;
298 int caption_height;
299 int tool_caption_height;
301 // XXX this method should be static on Hwnd, not X11Hwnd
302 X11Hwnd.DeriveStyles (Style, ExStyle, out border_style, out border_static, out title_style,
303 out caption_height, out tool_caption_height);
305 WindowRect = Hwnd.GetWindowRectangle(border_style, border_static, menu, title_style,
306 caption_height, tool_caption_height,
307 ClientRect);
308 return true;
311 internal override void ClientToScreen (IntPtr handle, ref int x, ref int y)
313 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
315 if (hwnd != null)
316 hwnd.ClientToScreen (ref x, ref y);
319 internal override int[] ClipboardAvailableFormats (IntPtr handle)
321 return display.ClipboardAvailableFormats (handle);
324 internal override void ClipboardClose (IntPtr handle)
326 display.ClipboardClose (handle);
329 internal override int ClipboardGetID (IntPtr handle, string format)
331 return display.ClipboardGetID (handle, format);
334 internal override IntPtr ClipboardOpen (bool primary_selection)
336 return display.ClipboardOpen (primary_selection);
339 internal override object ClipboardRetrieve (IntPtr handle, int type, XplatUI.ClipboardToObject converter)
341 return display.ClipboardRetrieve (handle, type, converter);
344 internal override void ClipboardStore (IntPtr handle, object obj, int type, XplatUI.ObjectToClipboard converter)
346 display.ClipboardStore (handle, obj, type, converter);
349 internal override void CreateCaret (IntPtr handle, int width, int height)
351 display.CreateCaret (handle, width, height);
354 internal override IntPtr CreateWindow (CreateParams cp)
356 X11Hwnd hwnd = new X11Hwnd (display);
358 hwnd.CreateWindow (cp);
360 return hwnd.Handle;
363 internal override IntPtr CreateWindow (IntPtr Parent, int X, int Y, int Width, int Height)
365 CreateParams create_params = new CreateParams();
367 create_params.Caption = "";
368 create_params.X = X;
369 create_params.Y = Y;
370 create_params.Width = Width;
371 create_params.Height = Height;
373 create_params.ClassName = XplatUI.DefaultClassName;
374 create_params.ClassStyle = 0;
375 create_params.ExStyle = 0;
376 create_params.Parent = IntPtr.Zero;
377 create_params.Param = 0;
379 return CreateWindow (create_params);
382 internal override IntPtr DefineCursor (Bitmap bitmap, Bitmap mask, Color cursor_pixel, Color mask_pixel, int xHotSpot, int yHotSpot)
384 return display.DefineCursor (bitmap, mask, cursor_pixel, mask_pixel, xHotSpot, yHotSpot);
387 internal override IntPtr DefineStdCursor (StdCursor id)
389 return display.DefineStdCursor (id);
392 internal override IntPtr DefWndProc(ref Message msg)
394 X11Hwnd hwnd = (X11Hwnd)Hwnd.GetObjectFromWindow(msg.HWnd);
396 if (hwnd == null)
397 return IntPtr.Zero;
399 return hwnd.DefWndProc (ref msg);
402 internal override void DestroyCaret (IntPtr handle)
404 display.DestroyCaret (handle);
407 internal override void DestroyCursor(IntPtr cursor)
409 display.DestroyCursor (cursor);
412 internal override void DestroyWindow (IntPtr handle) {
413 X11Hwnd hwnd;
415 hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
417 if (hwnd == null) {
418 #if DriverDebug || DriverDebugDestroy
419 Console.WriteLine("window {0:X} already destroyed", handle.ToInt32());
420 #endif
421 return;
424 #if DriverDebug || DriverDebugDestroy
425 Console.WriteLine("Destroying window {0}", XplatUI.Window(hwnd.ClientWindow));
426 #endif
428 display.DestroyWindow (hwnd);
431 internal override IntPtr DispatchMessage(ref MSG msg)
433 return display.DispatchMessage (ref msg);
436 internal override void DrawReversibleLine (Point start, Point end, Color backColor)
438 display.DrawReversibleLine (start, end, backColor);
441 internal override void FillReversibleRectangle (Rectangle rectangle, Color backColor)
443 display.FillReversibleRectangle (rectangle, backColor);
446 internal override void DrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style)
448 display.DrawReversibleFrame (rectangle, backColor, style);
451 internal override void DrawReversibleRectangle (IntPtr handle, Rectangle rect, int line_width)
453 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
455 if (hwnd != null)
456 hwnd.DrawReversibleRectangle (rect, line_width);
459 internal override void DoEvents ()
461 X11ThreadQueue queue = ThreadQueue (Thread.CurrentThread);
462 display.DoEvents (queue);
465 internal override void EnableWindow (IntPtr handle, bool Enable)
467 Hwnd hwnd;
469 hwnd = Hwnd.ObjectFromHandle(handle);
470 if (hwnd != null)
471 hwnd.Enabled = Enable;
474 internal override void EndLoop (Thread thread)
476 // This is where we one day will shut down the loop for the thread
480 internal override IntPtr GetActive()
482 X11Hwnd hwnd = display.GetActiveWindow ();
484 return (hwnd == null) ? IntPtr.Zero : hwnd.Handle;
487 internal override Region GetClipRegion (IntPtr handle)
489 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
491 return (hwnd == null) ? null : hwnd.GetClipRegion ();
494 internal override void GetCursorInfo(IntPtr cursor, out int width, out int height, out int hotspot_x, out int hotspot_y)
496 width = 20;
497 height = 20;
498 hotspot_x = 0;
499 hotspot_y = 0;
502 internal override void GetDisplaySize(out Size size)
504 display.GetDisplaySize (out size);
507 internal override SizeF GetAutoScaleSize (Font font)
509 return display.GetAutoScaleSize (font);
512 // XXX this should be someplace shareable by all non-win32 backends.. like in Hwnd itself.
513 // maybe a Hwnd.ParentHandle property
514 internal override IntPtr GetParent (IntPtr handle)
516 Hwnd hwnd;
518 hwnd = Hwnd.ObjectFromHandle(handle);
519 if (hwnd != null && hwnd.parent != null) {
520 return hwnd.parent.Handle;
522 return IntPtr.Zero;
525 internal override void GetCursorPos (IntPtr handle, out int x, out int y)
527 display.GetCursorPos ((X11Hwnd)Hwnd.ObjectFromHandle(handle),
528 out x, out y);
531 internal override IntPtr GetFocus()
533 return display.GetFocus ();
536 // XXX this should be shared amongst non-win32 backends
537 internal override bool GetFontMetrics (Graphics g, Font font, out int ascent, out int descent)
539 return Xlib.GetFontMetrics(g.GetHdc(), font.ToHfont(), out ascent, out descent);
543 // XXX this should be shared amongst non-win32 backends
544 internal override Point GetMenuOrigin (IntPtr handle)
546 Hwnd hwnd;
548 hwnd = Hwnd.ObjectFromHandle(handle);
550 if (hwnd != null)
551 return hwnd.MenuOrigin;
553 return Point.Empty;
556 internal override bool GetMessage (object queue_id, ref MSG msg, IntPtr handle, int wFilterMin, int wFilterMax)
558 return display.GetMessage (queue_id, ref msg, handle, wFilterMin, wFilterMax);
561 internal override bool GetText (IntPtr handle, out string text)
563 X11Hwnd hwnd = (X11Hwnd) Hwnd.ObjectFromHandle(handle);
565 text = "";
566 return hwnd != null && hwnd.GetText (out text);
569 internal override void GetWindowPos (IntPtr handle, bool is_toplevel,
570 out int x, out int y,
571 out int width, out int height,
572 out int client_width, out int client_height)
574 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
576 if (hwnd != null) {
577 hwnd.GetPosition (is_toplevel, out x, out y, out width, out height, out client_width, out client_height);
579 else {
580 // Should we throw an exception or fail silently?
581 // throw new ArgumentException("Called with an invalid window handle", "handle");
583 x = 0;
584 y = 0;
585 width = 0;
586 height = 0;
587 client_width = 0;
588 client_height = 0;
592 internal override FormWindowState GetWindowState (IntPtr handle)
594 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
596 if (hwnd == null)
597 return FormWindowState.Normal; // XXX should we throw an exception here? probably
599 return hwnd.GetWindowState ();
602 internal override void GrabInfo (out IntPtr handle, out bool GrabConfined, out Rectangle GrabArea)
604 display.GrabInfo (out handle, out GrabConfined, out GrabArea);
607 internal override void GrabWindow (IntPtr handle, IntPtr confine_to_handle)
609 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
610 X11Hwnd confine_to_hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(confine_to_handle);
612 display.GrabWindow (hwnd, confine_to_hwnd);
615 internal override void UngrabWindow (IntPtr handle)
617 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
619 display.UngrabWindow (hwnd);
622 internal override void HandleException(Exception e) {
623 StackTrace st = new StackTrace(e, true);
624 Console.WriteLine("Exception '{0}'", e.Message+st.ToString());
625 Console.WriteLine("{0}{1}", e.Message, st.ToString());
628 internal override void Invalidate (IntPtr handle, Rectangle rc, bool clear)
630 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
632 hwnd.Invalidate (rc, clear);
635 internal override void InvalidateNC (IntPtr handle)
637 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
639 hwnd.InvalidateNC ();
642 internal override bool IsEnabled(IntPtr handle)
644 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle (handle);
646 return hwnd != null && hwnd.Enabled;
649 internal override bool IsVisible(IntPtr handle)
651 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle (handle);
653 return hwnd != null && hwnd.Visible;
656 internal override void KillTimer (Timer timer)
658 X11ThreadQueue queue = (X11ThreadQueue) MessageQueues [timer.thread];
660 if (queue == null) {
661 // This isn't really an error, MS doesn't start the timer if
662 // it has no assosciated queue
663 return;
665 queue.KillTimer (timer);
668 internal override void MenuToScreen (IntPtr handle, ref int x, ref int y)
670 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
672 if (hwnd != null)
673 hwnd.MenuToScreen (ref x, ref y);
676 internal override void OverrideCursor (IntPtr cursor)
678 display.OverrideCursor = cursor;
681 internal override PaintEventArgs PaintEventStart (IntPtr handle, bool client)
683 return display.PaintEventStart (handle, client);
686 internal override void PaintEventEnd (IntPtr handle, bool client)
688 display.PaintEventEnd (handle, client);
692 internal override bool PeekMessage (object queue_id, ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags)
694 return display.PeekMessage (queue_id, ref msg, hWnd, wFilterMin, wFilterMax, flags);
697 internal override bool PostMessage (IntPtr handle, Msg message, IntPtr wparam, IntPtr lparam)
699 return display.PostMessage (handle, message, wparam, lparam);
702 internal override void PostQuitMessage(int exitCode)
704 display.PostMessage (display.FosterParent.Handle, Msg.WM_QUIT, IntPtr.Zero, IntPtr.Zero);
705 display.Flush ();
708 [MonoTODO]
709 internal override void RequestAdditionalWM_NCMessages (IntPtr handle, bool hover, bool leave)
711 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
713 if (hwnd != null)
714 hwnd.RequestAdditionalWM_NCMessages (hover, leave);
717 internal override void RequestNCRecalc (IntPtr handle)
719 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
721 if (hwnd != null)
722 hwnd.RequestNCRecalc ();
725 internal override void ResetMouseHover (IntPtr handle)
727 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
729 display.ResetMouseHover (hwnd);
732 internal override void ScreenToClient(IntPtr handle, ref int x, ref int y)
734 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
736 if (hwnd != null)
737 hwnd.ScreenToClient (ref x, ref y);
740 internal override void ScreenToMenu (IntPtr handle, ref int x, ref int y)
742 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
744 if (hwnd != null)
745 hwnd.ScreenToMenu (ref x, ref y);
748 internal override void ScrollWindow (IntPtr handle, Rectangle area, int XAmount, int YAmount, bool with_children)
750 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
752 if (hwnd != null)
753 hwnd.ScrollWindow (area, XAmount, YAmount, with_children);
756 internal override void ScrollWindow(IntPtr handle, int XAmount, int YAmount, bool with_children)
758 X11Hwnd hwnd = (X11Hwnd)Hwnd.GetObjectFromWindow(handle);
760 if (hwnd != null) {
761 Rectangle rect;
763 rect = hwnd.ClientRect;
764 rect.X = 0;
765 rect.Y = 0;
766 hwnd.ScrollWindow (rect, XAmount, YAmount, with_children);
770 internal override void SendAsyncMethod (AsyncMethodData method)
772 display.SendAsyncMethod (method);
775 // XXX this is likely shareable amongst other backends
776 internal override IntPtr SendMessage (IntPtr handle, Msg message, IntPtr wParam, IntPtr lParam)
778 return display.SendMessage (handle, message, wParam, lParam);
781 internal override int SendInput(IntPtr handle, Queue keys) {
782 return display.SendInput(handle, keys);
786 internal override void SetAllowDrop (IntPtr handle, bool value)
788 // We allow drop on all windows
791 internal override DragDropEffects StartDrag (IntPtr handle, object data,
792 DragDropEffects allowed_effects)
794 return display.StartDrag (handle, data, allowed_effects);
797 internal override void SetBorderStyle (IntPtr handle, FormBorderStyle border_style)
799 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
801 if (hwnd != null)
802 hwnd.SetBorderStyle (border_style);
805 internal override void SetCaretPos (IntPtr handle, int x, int y)
807 display.SetCaretPos (handle, x, y);
810 internal override void SetClipRegion (IntPtr handle, Region region)
812 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
814 if (hwnd != null)
815 hwnd.SetClipRegion (region);
818 internal override void SetCursor (IntPtr handle, IntPtr cursor)
820 display.SetCursor (handle, cursor);
823 internal override void SetCursorPos (IntPtr handle, int x, int y)
825 if (handle == IntPtr.Zero) {
826 display.SetCursorPos (x, y);
828 else {
829 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
831 hwnd.SetCursorPos (x, y);
835 internal override void SetFocus (IntPtr handle)
837 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
839 display.SetFocus (hwnd);
842 internal override void SetIcon(IntPtr handle, Icon icon)
844 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);;
846 if (hwnd != null)
847 hwnd.SetIcon (icon);
850 internal override void SetMenu(IntPtr handle, Menu menu)
852 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
854 hwnd.SetMenu (menu);
857 internal override void SetModal(IntPtr handle, bool Modal)
859 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
861 if (hwnd != null)
862 display.SetModal (hwnd, Modal);
865 internal override IntPtr SetParent(IntPtr handle, IntPtr parent)
867 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
868 X11Hwnd parent_hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(parent);
870 if (hwnd != null)
871 hwnd.SetParent (parent_hwnd);
873 return IntPtr.Zero;
876 internal override void SetTimer (Timer timer)
878 X11ThreadQueue queue = (X11ThreadQueue) MessageQueues [timer.thread];
880 if (queue == null) {
881 // This isn't really an error, MS doesn't start the timer if
882 // it has no assosciated queue
883 return;
885 queue.SetTimer (timer);
888 internal override bool SetTopmost(IntPtr handle, IntPtr handle_owner, bool enabled)
890 X11Hwnd hwnd;
892 hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
894 if (hwnd == null)
895 return false;
897 X11Hwnd hwnd_owner = (X11Hwnd)Hwnd.ObjectFromHandle(handle_owner);
899 return hwnd.SetTopmost (hwnd_owner, enabled);
902 internal override bool SetVisible (IntPtr handle, bool visible, bool activate)
904 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
906 return hwnd != null && hwnd.SetVisible (visible, activate);
909 internal override void SetWindowMinMax (IntPtr handle, Rectangle maximized, Size min, Size max)
911 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
913 if (hwnd == null)
914 return;
916 hwnd.SetMinMax (maximized, min, max);
919 internal override void SetWindowPos (IntPtr handle, int x, int y, int width, int height)
921 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
923 if (hwnd != null)
924 hwnd.SetPosition (x, y, width, height);
927 internal override void SetWindowState (IntPtr handle, FormWindowState state)
929 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
931 if (hwnd != null)
932 hwnd.SetWindowState (state);
935 internal override void SetWindowStyle (IntPtr handle, CreateParams cp)
937 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
939 if (hwnd != null) {
940 hwnd.SetHwndStyles (cp);
941 hwnd.SetWMStyles (cp);
945 internal override double GetWindowTransparency (IntPtr handle)
947 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
949 if (hwnd != null)
950 return hwnd.GetWindowTransparency ();
951 else
952 return 0.0;
955 internal override void SetWindowTransparency (IntPtr handle, double transparency, Color key)
957 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
959 if (hwnd != null)
960 hwnd.SetWindowTransparency (transparency, key);
963 internal override bool SetZOrder (IntPtr handle, IntPtr after_handle, bool top, bool bottom)
965 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
967 if (hwnd == null || !hwnd.mapped)
968 return false;
970 X11Hwnd after_hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(after_handle);
972 return hwnd.SetZOrder (after_hwnd, top, bottom);
975 internal override void ShowCursor (bool show)
977 display.ShowCursor (show);
980 internal override object StartLoop(Thread thread)
982 return (object) ThreadQueue(thread);
985 internal override TransparencySupport SupportsTransparency()
987 return display.SupportsTransparency ();
990 internal override bool SystrayAdd (IntPtr handle, string tip, Icon icon, out ToolTip tt)
992 return display.SystrayAdd (handle, tip, icon, out tt);
995 internal override bool SystrayChange (IntPtr handle, string tip, Icon icon, ref ToolTip tt)
997 return display.SystrayChange (handle, tip, icon, ref tt);
1000 internal override void SystrayRemove (IntPtr handle, ref ToolTip tt)
1002 display.SystrayRemove (handle, ref tt);
1005 internal override bool Text (IntPtr handle, string text)
1007 X11Hwnd hwnd = (X11Hwnd) Hwnd.ObjectFromHandle(handle);
1009 if (hwnd != null)
1010 hwnd.Text = text;
1012 return true;
1015 internal override bool TranslateMessage (ref MSG msg)
1017 return display.TranslateMessage (ref msg);
1020 internal override void UpdateWindow (IntPtr handle)
1022 X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
1024 if (hwnd != null)
1025 hwnd.Update ();
1028 internal override void CreateOffscreenDrawable (IntPtr handle,
1029 int width, int height,
1030 out object offscreen_drawable)
1032 display.CreateOffscreenDrawable (handle, width, height,
1033 out offscreen_drawable);
1036 internal override void DestroyOffscreenDrawable (object offscreen_drawable)
1038 display.DestroyOffscreenDrawable (offscreen_drawable);
1041 internal override Graphics GetOffscreenGraphics (object offscreen_drawable)
1043 return display.GetOffscreenGraphics (offscreen_drawable);
1046 internal override void BlitFromOffscreen (IntPtr dest_handle,
1047 Graphics dest_dc,
1048 object offscreen_drawable,
1049 Graphics offscreen_dc,
1050 Rectangle r)
1052 display.BlitFromOffscreen (dest_handle, dest_dc, offscreen_drawable, offscreen_dc, r);
1055 #endregion // Public Static Methods
1057 #region Events
1058 internal override event EventHandler Idle {
1059 add {
1060 Console.WriteLine ("adding idle handler for thread {0}", Thread.CurrentThread.GetHashCode());
1061 X11ThreadQueue queue = ThreadQueue(Thread.CurrentThread);
1062 queue.Idle += value;
1064 remove {
1065 X11ThreadQueue queue = ThreadQueue(Thread.CurrentThread);
1066 queue.Idle += value;
1069 #endregion // Events