Пример #1
0
        public WindowResizeTest()
        {
            t = new Timer();

            dpy     = new XDisplay(IntPtr.Zero);
            s       = new XScreen(dpy);
            ev      = new XEvent(dpy);
            pointer = new XPointer(dpy);
            gc      = new XGC(dpy);

            //XShape shape = new XShape(dpy);
            //shape.Query();
            //Console.WriteLine("Shape Event Type Number = {0}", shape.Type.ToString());

            //atom = new XAtom (dpy, "_MAJYK_HINT", false);

            // Used to test the XPM function that reads a pixmap from a char**
//      pix_data = new string[] {
//            "16 16 16 1",
//            "   c None",
//            ". c #323232",
//            "+  c #535353",
//            "@  c #4A8A8E",
//            "#  c #DEE2E2",
//            "$  c #7E827A",
//            "%  c #8A9292",
//            "&  c #D6D6D6",
//            "*  c #36767E",
//            "=  c #9E9E9E",
//            "-  c #FAFAFA",
//            ";  c #B2B2B2",
//            ">  c #DEEEEA",
//            ",  c #464646",
//            "'  c #5EA2A2",
//            ")  c #52969A",
//            "                ",
//            "                ",
//            " --#>>>>>>#-#-; ",
//            " -&%')))))=&=&+ ",
//            " >;$@*****=;%;+ ",
//            " &$$$$$$$$$$$$, ",
//            " &;;;;;;;;;;;;+ ",
//            " &;;;;;;;;;;;;+ ",
//            " #;;;;;;;;;;;;+ ",
//            " &;;;;;;;;;;;;+ ",
//            " #;;;;;;;;;;;;+ ",
//            " #;;;;;;;;;;;;+ ",
//            " &;;;;;;;;;;;;+ ",
//            " $............. ",
//            "                ",
//            "                "
//      };

            bg_color     = new XColor(dpy, "#AAAAAA");
            handle_color = new XColor(dpy, "#FF0000");

            //bg_color = new XColor(dpy, Color.FromArgb(200, 200, 200));
            //handle_color = new XColor(dpy, Color.FromArgb(0, 255, 0));

            main_win = new XWindow(dpy, new Rectangle(5, 5, 640, 480), 0, s.BlackPixel(), s.WhitePixel());

            main_win.Name = "Window Resize Test";
            main_win.SelectInput(XEventMask.KeyPressMask | XEventMask.ExposureMask);

            resize_main_win         = new XWindow(dpy, main_win, new Rectangle(resize_win_x, resize_win_y, resize_win_width, resize_win_height), 1, s.BlackPixel(), bg_color.Pixel);
            resize_top_left_win     = new XWindow(dpy, resize_main_win, new Rectangle(0, 0, resize_handle_width, resize_handle_height), 1, s.BlackPixel(), handle_color.Pixel);
            resize_top_right_win    = new XWindow(dpy, resize_main_win, new Rectangle(0, 0, resize_handle_width, resize_handle_height), 1, s.BlackPixel(), handle_color.Pixel);
            resize_bottom_left_win  = new XWindow(dpy, resize_main_win, new Rectangle(0, 0, resize_handle_width, resize_handle_height), 1, s.BlackPixel(), handle_color.Pixel);
            resize_bottom_right_win = new XWindow(dpy, resize_main_win, new Rectangle(0, 0, resize_handle_width, resize_handle_height), 1, s.BlackPixel(), handle_color.Pixel);

            //string foo="MAJYK!";
            //resize_main_win.ChangeProperty(atom, atom, 8, PropMode.PropModeReplace, Marshal.StringToHGlobalAnsi(foo), foo.Length);

            //int return_type=0;
            //int actual_format=0;
            //int nitems=0;
            //int bytes_return=0;
            //IntPtr data = IntPtr.Zero;

            //resize_main_win.GetProperty(atom, 0, 2, false, atom, out return_type, out actual_format, out nitems, out bytes_return, out data);

            //string z = Marshal.PtrToStringAnsi(data);
            //Console.WriteLine("nitems = {0}, z = {1}", nitems, z);

            //pix = new XPixmap (dpy);

            //if (pix.ReadPixmapFromData (resize_main_win, pix_data)) {
            //  resize_main_win.SetBackgroundPixmap (pix);

            //  Console.WriteLine ("pixmap w = {0} | h = {1}", pix.Width.ToString (), pix.Height.ToString ());
            //}

            resize_main_win.SetBackgroundColor(Color.Gray);

            // Test TransientFor
            //resize_main_win.SetTransientForHint(main_win);
            //Window foo = resize_main_win.GetTransientForHint();
            //Console.WriteLine("resize_main_win = {0} | foo.transient_for = {1} | main_win = {2}", resize_main_win.ID.ToString(), foo.ID.ToString(), main_win.ID.ToString());

            XEventMask mask = XEventMask.ButtonPressMask | XEventMask.ButtonReleaseMask;

            resize_main_win.SelectInput(mask);
            resize_top_left_win.SelectInput(mask);
            resize_top_right_win.SelectInput(mask);
            resize_bottom_left_win.SelectInput(mask);
            resize_bottom_right_win.SelectInput(mask);

            PlaceHandles();

            resize_main_win.MapSubwindows();
            main_win.MapSubwindows();
            main_win.Map();

            ev.KeyPressHandlerEvent      += new KeyPressHandler(HandleKeyPress);
            ev.MotionNotifyHandlerEvent  += new MotionNotifyHandler(HandleMotionNotify);
            ev.ButtonPressHandlerEvent   += new ButtonPressHandler(HandleButtonPress);
            ev.ButtonReleaseHandlerEvent += new ButtonReleaseHandler(HandleButtonRelease);
            ev.ExposeHandlerEvent        += new ExposeHandler(HandleExpose);

            t.Interval = 1000;
            t.Enabled  = true;
            t.Elapsed += new ElapsedEventHandler(UpdateClock);
            t.Start();

            ev.Loop();
        }