1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117
|
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2004-2006 Novell, Inc.
//
// Authors:
// Peter Bartok pbartok@novell.com
// Chris Toshok toshok@ximian.com
//
//
// NOTE:
// This driver understands the following environment variables: (Set the var to enable feature)
//
// MONO_XEXCEPTIONS = throw an exception when a X11 error is encountered;
// by default a message is displayed but execution continues
//
// MONO_XSYNC = perform all X11 commands synchronous; this is slower but
// helps in debugging errors
//
// NOT COMPLETE
// define to log Window handles and relationships to stdout
#undef DriverDebug
// Extra detailed debug
#undef DriverDebugExtra
#undef DriverDebugParent
#undef DriverDebugCreate
#undef DriverDebugDestroy
#undef DriverDebugThreads
#undef DriverDebugXEmbed
using System;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows.Forms;
/// X11 Version
namespace System.Windows.Forms.X11Internal {
internal class XplatUIX11_new : XplatUIDriver {
#region Local Variables
// General
static volatile XplatUIX11_new Instance;
static readonly object lockobj = new object ();
static int RefCount;
static bool themes_enabled;
static Hashtable MessageQueues; // Holds our thread-specific X11ThreadQueues
X11Display display;
#endregion // Local Variables
#region Constructors
private XplatUIX11_new() {
// Handle singleton stuff first
RefCount = 0;
// Now regular initialization
MessageQueues = Hashtable.Synchronized (new Hashtable(7));
if (Xlib.XInitThreads() == 0) {
Console.WriteLine ("Failed XInitThreads. The X11 event loop will not function properly");
}
}
private void InitializeDisplay ()
{
display = new X11Display (Xlib.XOpenDisplay(IntPtr.Zero));
Graphics.FromHdcInternal (display.Handle);
}
~XplatUIX11_new() {
// Remove our display handle from S.D
Graphics.FromHdcInternal (IntPtr.Zero);
}
#endregion // Constructors
#region Singleton Specific Code
public static XplatUIX11_new GetInstance() {
lock (lockobj) {
if (Instance == null) {
Instance = new XplatUIX11_new ();
Instance.InitializeDisplay ();
}
RefCount++;
}
return Instance;
}
public int Reference {
get {
return RefCount;
}
}
#endregion
#region Internal Methods
internal static void Where() {
Console.WriteLine("Here: {0}\n", GetInstance().display.WhereString());
}
#endregion // Internal Methods
#region Private Methods
internal X11ThreadQueue ThreadQueue (Thread thread)
{
X11ThreadQueue queue;
queue = (X11ThreadQueue)MessageQueues[thread];
if (queue == null) {
queue = new X11ThreadQueue(thread);
MessageQueues[thread] = queue;
}
return queue;
}
#endregion // Private Methods
#region Public Properties
internal override int CaptionHeight {
get { return 19; }
}
internal override Size CursorSize {
get { return display.CursorSize; }
}
internal override bool DragFullWindows {
get { return true; }
}
internal override Size DragSize {
get { return new Size(4, 4); }
}
internal override Size FrameBorderSize {
get { return new Size (4, 4); }
}
internal override Size IconSize {
get { return display.IconSize; }
}
internal override int KeyboardSpeed {
get { return display.KeyboardSpeed; }
}
internal override int KeyboardDelay {
get { return display.KeyboardSpeed; }
}
internal override Size MaxWindowTrackSize {
get { return new Size (WorkingArea.Width, WorkingArea.Height); }
}
internal override bool MenuAccessKeysUnderlined {
get {
return false;
}
}
internal override Size MinimizedWindowSize {
get { return new Size(1, 1); }
}
internal override Size MinimizedWindowSpacingSize {
get { return new Size(1, 1); }
}
internal override Size MinimumWindowSize {
get { return new Size(1, 1); }
}
internal override Size MinWindowTrackSize {
get { return new Size(1, 1); }
}
internal override Keys ModifierKeys {
get { return display.ModifierKeys; }
}
internal override Size SmallIconSize {
get { return display.SmallIconSize; }
}
internal override int MouseButtonCount {
get { return 3; /* FIXME - should detect this somehow.. */}
}
internal override bool MouseButtonsSwapped {
get { return false; /*FIXME - how to detect? */}
}
internal override Size MouseHoverSize {
get { return new Size (1, 1); }
}
internal override int MouseHoverTime {
get { return display.MouseHoverTime; }
}
internal override bool MouseWheelPresent {
get { return true; /* FIXME - how to detect? */ }
}
internal override Rectangle VirtualScreen {
get { return display.VirtualScreen; }
}
internal override Rectangle WorkingArea {
get { return display.WorkingArea; }
}
internal override bool ThemesEnabled {
get { return XplatUIX11_new.themes_enabled; }
}
#endregion // Public properties
#region Public Static Methods
internal override void RaiseIdle (EventArgs e)
{
X11ThreadQueue queue = ThreadQueue (Thread.CurrentThread);
queue.OnIdle (e);
}
internal override IntPtr InitializeDriver ()
{
lock (this) {
if (display == null)
display = new X11Display (Xlib.XOpenDisplay(IntPtr.Zero));
}
return IntPtr.Zero;
}
internal override void ShutdownDriver(IntPtr token)
{
lock (this) {
if (display != null) {
display.Close ();
display = null;
}
}
}
internal override void EnableThemes()
{
themes_enabled = true;
}
internal override void Activate (IntPtr handle)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
if (hwnd != null)
hwnd.Activate ();
}
internal override void AudibleAlert()
{
display.AudibleAlert ();
}
internal override void CaretVisible (IntPtr handle, bool visible)
{
display.CaretVisible (handle, visible);
}
// XXX this implementation should probably be shared between all non-win32 backends
internal override bool CalculateWindowRect (ref Rectangle ClientRect, CreateParams cp, Menu menu, out Rectangle WindowRect)
{
WindowRect = Hwnd.GetWindowRectangle (cp, menu, ClientRect);
return true;
}
internal override void ClientToScreen (IntPtr handle, ref int x, ref int y)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
if (hwnd != null)
hwnd.ClientToScreen (ref x, ref y);
}
internal override int[] ClipboardAvailableFormats (IntPtr handle)
{
return display.ClipboardAvailableFormats (handle);
}
internal override void ClipboardClose (IntPtr handle)
{
display.ClipboardClose (handle);
}
internal override int ClipboardGetID (IntPtr handle, string format)
{
return display.ClipboardGetID (handle, format);
}
internal override IntPtr ClipboardOpen (bool primary_selection)
{
return display.ClipboardOpen (primary_selection);
}
internal override object ClipboardRetrieve (IntPtr handle, int type, XplatUI.ClipboardToObject converter)
{
return display.ClipboardRetrieve (handle, type, converter);
}
internal override void ClipboardStore (IntPtr handle, object obj, int type, XplatUI.ObjectToClipboard converter)
{
display.ClipboardStore (handle, obj, type, converter);
}
internal override void CreateCaret (IntPtr handle, int width, int height)
{
display.CreateCaret (handle, width, height);
}
internal override IntPtr CreateWindow (CreateParams cp)
{
X11Hwnd hwnd = new X11Hwnd (display);
hwnd.CreateWindow (cp);
return hwnd.Handle;
}
internal override IntPtr CreateWindow (IntPtr Parent, int X, int Y, int Width, int Height)
{
CreateParams create_params = new CreateParams();
create_params.Caption = "";
create_params.X = X;
create_params.Y = Y;
create_params.Width = Width;
create_params.Height = Height;
create_params.ClassName = XplatUI.DefaultClassName;
create_params.ClassStyle = 0;
create_params.ExStyle = 0;
create_params.Parent = IntPtr.Zero;
create_params.Param = 0;
return CreateWindow (create_params);
}
internal override IntPtr DefineCursor (Bitmap bitmap, Bitmap mask, Color cursor_pixel, Color mask_pixel, int xHotSpot, int yHotSpot)
{
return display.DefineCursor (bitmap, mask, cursor_pixel, mask_pixel, xHotSpot, yHotSpot);
}
internal override Bitmap DefineStdCursorBitmap (StdCursor id)
{
return display.DefineStdCursorBitmap (id);
}
internal override IntPtr DefineStdCursor (StdCursor id)
{
return display.DefineStdCursor (id);
}
internal override IntPtr DefWndProc(ref Message msg)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.GetObjectFromWindow(msg.HWnd);
if (hwnd == null)
return IntPtr.Zero;
return hwnd.DefWndProc (ref msg);
}
internal override void DestroyCaret (IntPtr handle)
{
display.DestroyCaret (handle);
}
internal override void DestroyCursor(IntPtr cursor)
{
display.DestroyCursor (cursor);
}
internal override void DestroyWindow (IntPtr handle) {
X11Hwnd hwnd;
hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
if (hwnd == null) {
#if DriverDebug || DriverDebugDestroy
Console.WriteLine("window {0:X} already destroyed", handle.ToInt32());
#endif
return;
}
#if DriverDebug || DriverDebugDestroy
Console.WriteLine("Destroying window {0}", XplatUI.Window(hwnd.ClientWindow));
#endif
display.DestroyWindow (hwnd);
}
internal override IntPtr DispatchMessage(ref MSG msg)
{
return display.DispatchMessage (ref msg);
}
internal override void DrawReversibleLine (Point start, Point end, Color backColor)
{
display.DrawReversibleLine (start, end, backColor);
}
internal override void FillReversibleRectangle (Rectangle rectangle, Color backColor)
{
display.FillReversibleRectangle (rectangle, backColor);
}
internal override void DrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style)
{
display.DrawReversibleFrame (rectangle, backColor, style);
}
internal override void DrawReversibleRectangle (IntPtr handle, Rectangle rect, int line_width)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
if (hwnd != null)
hwnd.DrawReversibleRectangle (rect, line_width);
}
internal override void DoEvents ()
{
X11ThreadQueue queue = ThreadQueue (Thread.CurrentThread);
display.DoEvents (queue);
}
internal override void EnableWindow (IntPtr handle, bool Enable)
{
Hwnd hwnd;
hwnd = Hwnd.ObjectFromHandle(handle);
if (hwnd != null)
hwnd.Enabled = Enable;
}
internal override void EndLoop (Thread thread)
{
// This is where we one day will shut down the loop for the thread
}
internal override IntPtr GetActive()
{
X11Hwnd hwnd = display.GetActiveWindow ();
return (hwnd == null) ? IntPtr.Zero : hwnd.Handle;
}
internal override Region GetClipRegion (IntPtr handle)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
return (hwnd == null) ? null : hwnd.GetClipRegion ();
}
internal override void GetCursorInfo(IntPtr cursor, out int width, out int height, out int hotspot_x, out int hotspot_y)
{
width = 20;
height = 20;
hotspot_x = 0;
hotspot_y = 0;
}
internal override void GetDisplaySize(out Size size)
{
display.GetDisplaySize (out size);
}
internal override SizeF GetAutoScaleSize (Font font)
{
return display.GetAutoScaleSize (font);
}
// XXX this should be someplace shareable by all non-win32 backends.. like in Hwnd itself.
// maybe a Hwnd.ParentHandle property
internal override IntPtr GetParent (IntPtr handle)
{
Hwnd hwnd;
hwnd = Hwnd.ObjectFromHandle(handle);
if (hwnd != null && hwnd.parent != null) {
return hwnd.parent.Handle;
}
return IntPtr.Zero;
}
// This is a nop on win32 and x11
internal override IntPtr GetPreviousWindow(IntPtr handle) {
return handle;
}
internal override void GetCursorPos (IntPtr handle, out int x, out int y)
{
display.GetCursorPos ((X11Hwnd)Hwnd.ObjectFromHandle(handle),
out x, out y);
}
internal override IntPtr GetFocus()
{
return display.GetFocus ();
}
// XXX this should be shared amongst non-win32 backends
internal override bool GetFontMetrics (Graphics g, Font font, out int ascent, out int descent)
{
FontFamily ff = font.FontFamily;
ascent = ff.GetCellAscent (font.Style);
descent = ff.GetCellDescent (font.Style);
return true;
}
// XXX this should be shared amongst non-win32 backends
internal override Point GetMenuOrigin (IntPtr handle)
{
Hwnd hwnd;
hwnd = Hwnd.ObjectFromHandle(handle);
if (hwnd != null)
return hwnd.MenuOrigin;
return Point.Empty;
}
internal override bool GetMessage (object queue_id, ref MSG msg, IntPtr handle, int wFilterMin, int wFilterMax)
{
return display.GetMessage (queue_id, ref msg, handle, wFilterMin, wFilterMax);
}
internal override bool GetText (IntPtr handle, out string text)
{
X11Hwnd hwnd = (X11Hwnd) Hwnd.ObjectFromHandle(handle);
text = "";
return hwnd != null && hwnd.GetText (out text);
}
internal override void GetWindowPos (IntPtr handle, bool is_toplevel,
out int x, out int y,
out int width, out int height,
out int client_width, out int client_height)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
if (hwnd != null) {
hwnd.GetPosition (is_toplevel, out x, out y, out width, out height, out client_width, out client_height);
}
else {
// Should we throw an exception or fail silently?
// throw new ArgumentException("Called with an invalid window handle", "handle");
x = 0;
y = 0;
width = 0;
height = 0;
client_width = 0;
client_height = 0;
}
}
internal override FormWindowState GetWindowState (IntPtr handle)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
if (hwnd == null)
return FormWindowState.Normal; // XXX should we throw an exception here? probably
return hwnd.GetWindowState ();
}
internal override void GrabInfo (out IntPtr handle, out bool GrabConfined, out Rectangle GrabArea)
{
display.GrabInfo (out handle, out GrabConfined, out GrabArea);
}
internal override void GrabWindow (IntPtr handle, IntPtr confine_to_handle)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
X11Hwnd confine_to_hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(confine_to_handle);
display.GrabWindow (hwnd, confine_to_hwnd);
}
internal override void UngrabWindow (IntPtr handle)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
display.UngrabWindow (hwnd);
}
internal override void HandleException(Exception e) {
StackTrace st = new StackTrace(e, true);
Console.WriteLine("Exception '{0}'", e.Message+st.ToString());
Console.WriteLine("{0}{1}", e.Message, st.ToString());
}
internal override void Invalidate (IntPtr handle, Rectangle rc, bool clear)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
hwnd.Invalidate (rc, clear);
}
internal override void InvalidateNC (IntPtr handle)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
hwnd.InvalidateNC ();
}
internal override bool IsEnabled(IntPtr handle)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle (handle);
return hwnd != null && hwnd.Enabled;
}
internal override bool IsVisible(IntPtr handle)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle (handle);
return hwnd != null && hwnd.Visible;
}
internal override void KillTimer (Timer timer)
{
X11ThreadQueue queue = (X11ThreadQueue) MessageQueues [timer.thread];
if (queue == null) {
// This isn't really an error, MS doesn't start the timer if
// it has no assosciated queue
return;
}
queue.KillTimer (timer);
}
internal override void MenuToScreen (IntPtr handle, ref int x, ref int y)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
if (hwnd != null)
hwnd.MenuToScreen (ref x, ref y);
}
internal override void OverrideCursor (IntPtr cursor)
{
display.OverrideCursor = cursor;
}
internal override PaintEventArgs PaintEventStart (ref Message m, IntPtr handle, bool client)
{
return display.PaintEventStart (ref m, handle, client);
}
internal override void PaintEventEnd (ref Message m, IntPtr handle, bool client)
{
display.PaintEventEnd (ref m, handle, client);
}
internal override bool PeekMessage (object queue_id, ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags)
{
return display.PeekMessage (queue_id, ref msg, hWnd, wFilterMin, wFilterMax, flags);
}
internal override bool PostMessage (IntPtr handle, Msg message, IntPtr wparam, IntPtr lparam)
{
return display.PostMessage (handle, message, wparam, lparam);
}
internal override void PostQuitMessage(int exitCode)
{
display.PostMessage (display.FosterParent.Handle, Msg.WM_QUIT, IntPtr.Zero, IntPtr.Zero);
display.Flush ();
}
[MonoTODO]
internal override void RequestAdditionalWM_NCMessages (IntPtr handle, bool hover, bool leave)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
if (hwnd != null)
hwnd.RequestAdditionalWM_NCMessages (hover, leave);
}
internal override void RequestNCRecalc (IntPtr handle)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
if (hwnd != null)
hwnd.RequestNCRecalc ();
}
internal override void ResetMouseHover (IntPtr handle)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
display.ResetMouseHover (hwnd);
}
internal override void ScreenToClient(IntPtr handle, ref int x, ref int y)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
if (hwnd != null)
hwnd.ScreenToClient (ref x, ref y);
}
internal override void ScreenToMenu (IntPtr handle, ref int x, ref int y)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
if (hwnd != null)
hwnd.ScreenToMenu (ref x, ref y);
}
internal override void ScrollWindow (IntPtr handle, Rectangle area, int XAmount, int YAmount, bool with_children)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
if (hwnd != null)
hwnd.ScrollWindow (area, XAmount, YAmount, with_children);
}
internal override void ScrollWindow(IntPtr handle, int XAmount, int YAmount, bool with_children)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.GetObjectFromWindow(handle);
if (hwnd != null) {
Rectangle rect;
rect = hwnd.ClientRect;
rect.X = 0;
rect.Y = 0;
hwnd.ScrollWindow (rect, XAmount, YAmount, with_children);
}
}
internal override void SendAsyncMethod (AsyncMethodData method)
{
display.SendAsyncMethod (method);
}
// XXX this is likely shareable amongst other backends
internal override IntPtr SendMessage (IntPtr handle, Msg message, IntPtr wParam, IntPtr lParam)
{
return display.SendMessage (handle, message, wParam, lParam);
}
internal override int SendInput(IntPtr handle, Queue keys) {
return display.SendInput(handle, keys);
}
internal override void SetAllowDrop (IntPtr handle, bool value)
{
// We allow drop on all windows
}
internal override DragDropEffects StartDrag (IntPtr handle, object data,
DragDropEffects allowed_effects)
{
return display.StartDrag (handle, data, allowed_effects);
}
internal override void SetBorderStyle (IntPtr handle, FormBorderStyle border_style)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
if (hwnd != null)
hwnd.SetBorderStyle (border_style);
}
internal override void SetCaretPos (IntPtr handle, int x, int y)
{
display.SetCaretPos (handle, x, y);
}
internal override void SetClipRegion (IntPtr handle, Region region)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
if (hwnd != null)
hwnd.SetClipRegion (region);
}
internal override void SetCursor (IntPtr handle, IntPtr cursor)
{
display.SetCursor (handle, cursor);
}
internal override void SetCursorPos (IntPtr handle, int x, int y)
{
if (handle == IntPtr.Zero) {
display.SetCursorPos (x, y);
}
else {
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
hwnd.SetCursorPos (x, y);
}
}
internal override void SetFocus (IntPtr handle)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
display.SetFocus (hwnd);
}
internal override void SetIcon(IntPtr handle, Icon icon)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);;
if (hwnd != null)
hwnd.SetIcon (icon);
}
internal override void SetMenu(IntPtr handle, Menu menu)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
hwnd.SetMenu (menu);
}
internal override void SetModal(IntPtr handle, bool Modal)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
if (hwnd != null)
display.SetModal (hwnd, Modal);
}
internal override IntPtr SetParent(IntPtr handle, IntPtr parent)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
X11Hwnd parent_hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(parent);
if (hwnd != null)
hwnd.SetParent (parent_hwnd);
return IntPtr.Zero;
}
internal override void SetTimer (Timer timer)
{
X11ThreadQueue queue = (X11ThreadQueue) MessageQueues [timer.thread];
if (queue == null) {
// This isn't really an error, MS doesn't start the timer if
// it has no assosciated queue
return;
}
queue.SetTimer (timer);
}
internal override bool SetTopmost(IntPtr handle, bool enabled)
{
X11Hwnd hwnd = (X11Hwnd) Hwnd.ObjectFromHandle (handle);
if (hwnd == null)
return false;
return hwnd.SetTopmost (enabled);
}
internal override bool SetOwner(IntPtr handle, IntPtr handle_owner)
{
X11Hwnd hwnd;
hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
if (hwnd == null)
return false;
X11Hwnd hwnd_owner = (X11Hwnd)Hwnd.ObjectFromHandle(handle_owner);
return hwnd.SetOwner (hwnd_owner);
}
internal override bool SetVisible (IntPtr handle, bool visible, bool activate)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
return hwnd != null && hwnd.SetVisible (visible, activate);
}
internal override void SetWindowMinMax (IntPtr handle, Rectangle maximized, Size min, Size max)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
if (hwnd == null)
return;
hwnd.SetMinMax (maximized, min, max);
}
internal override void SetWindowPos (IntPtr handle, int x, int y, int width, int height)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
if (hwnd != null)
hwnd.SetPosition (x, y, width, height);
}
internal override void SetWindowState (IntPtr handle, FormWindowState state)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
if (hwnd != null)
hwnd.SetWindowState (state);
}
internal override void SetWindowStyle (IntPtr handle, CreateParams cp)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
if (hwnd != null) {
hwnd.SetHwndStyles (cp);
hwnd.SetWMStyles (cp);
}
}
internal override double GetWindowTransparency (IntPtr handle)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
if (hwnd != null)
return hwnd.GetWindowTransparency ();
else
return 0.0;
}
internal override void SetWindowTransparency (IntPtr handle, double transparency, Color key)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
if (hwnd != null)
hwnd.SetWindowTransparency (transparency, key);
}
internal override bool SetZOrder (IntPtr handle, IntPtr after_handle, bool top, bool bottom)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
if (hwnd == null || !hwnd.mapped)
return false;
X11Hwnd after_hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(after_handle);
return hwnd.SetZOrder (after_hwnd, top, bottom);
}
internal override void ShowCursor (bool show)
{
display.ShowCursor (show);
}
internal override object StartLoop(Thread thread)
{
return (object) ThreadQueue(thread);
}
internal override TransparencySupport SupportsTransparency()
{
return display.SupportsTransparency ();
}
internal override bool SystrayAdd (IntPtr handle, string tip, Icon icon, out ToolTip tt)
{
return display.SystrayAdd (handle, tip, icon, out tt);
}
internal override bool SystrayChange (IntPtr handle, string tip, Icon icon, ref ToolTip tt)
{
return display.SystrayChange (handle, tip, icon, ref tt);
}
internal override void SystrayRemove (IntPtr handle, ref ToolTip tt)
{
display.SystrayRemove (handle, ref tt);
}
#if NET_2_0
NotifyIcon.BalloonWindow balloon_window;
internal override void SystrayBalloon(IntPtr handle, int timeout, string title, string text, ToolTipIcon icon)
{
Control control = Control.FromHandle(handle);
if (control == null)
return;
if (balloon_window != null) {
balloon_window.Close ();
balloon_window.Dispose ();
}
balloon_window = new NotifyIcon.BalloonWindow (handle);
balloon_window.Title = title;
balloon_window.Text = text;
balloon_window.Timeout = timeout;
balloon_window.Show ();
SendMessage(handle, Msg.WM_USER, IntPtr.Zero, (IntPtr) Msg.NIN_BALLOONSHOW);
}
#endif
internal override bool Text (IntPtr handle, string text)
{
X11Hwnd hwnd = (X11Hwnd) Hwnd.ObjectFromHandle(handle);
if (hwnd != null)
hwnd.Text = text;
return true;
}
internal override bool TranslateMessage (ref MSG msg)
{
return display.TranslateMessage (ref msg);
}
internal override void UpdateWindow (IntPtr handle)
{
X11Hwnd hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(handle);
if (hwnd != null)
hwnd.Update ();
}
internal override void CreateOffscreenDrawable (IntPtr handle,
int width, int height,
out object offscreen_drawable)
{
display.CreateOffscreenDrawable (handle, width, height,
out offscreen_drawable);
}
internal override void DestroyOffscreenDrawable (object offscreen_drawable)
{
display.DestroyOffscreenDrawable (offscreen_drawable);
}
internal override Graphics GetOffscreenGraphics (object offscreen_drawable)
{
return display.GetOffscreenGraphics (offscreen_drawable);
}
internal override void BlitFromOffscreen (IntPtr dest_handle,
Graphics dest_dc,
object offscreen_drawable,
Graphics offscreen_dc,
Rectangle r)
{
display.BlitFromOffscreen (dest_handle, dest_dc, offscreen_drawable, offscreen_dc, r);
}
#endregion // Public Static Methods
#region Events
internal override event EventHandler Idle {
add {
Console.WriteLine ("adding idle handler for thread {0}", Thread.CurrentThread.GetHashCode());
X11ThreadQueue queue = ThreadQueue(Thread.CurrentThread);
queue.Idle += value;
}
remove {
X11ThreadQueue queue = ThreadQueue(Thread.CurrentThread);
queue.Idle += value;
}
}
#endregion // Events
}
}
|