Example #1
0
    public static void Main(string[] args)
    {
        Node n = null;

        if (args.Length == 0)
        {
            Console.WriteLine("Must specify the XML file with the data to load");
            return;
        }
        try {
            n = LoadNodes(args [0], "Size", "Foo");
        } catch {
            Console.WriteLine("Unable to load {0}", args [0]);
            throw;
        }

        Gtk.Application.Init();
        MoonlightRuntime.Init();

        Gtk.Window w = new Gtk.Window("Foo");
        var        v = new Gtk.VBox(false, 0);

        w.DeleteEvent += delegate {
            Gtk.Application.Quit();
        };

        w.SetSizeRequest(width, height);
        MoonlightHost h = new MoonlightHost();

        v.PackStart(h, true, true, 0);
        var back = new Gtk.Button("Back");

        v.PackStart(back, false, false, 0);
        w.Add(v);

        w.ShowAll();

        // Make it pretty, skip all levels that are just 1 element
        while (n.Children.Count == 1)
        {
            n = n.Children [0];
        }

        // Render
        TreemapRenderer r = new TreemapRenderer(n, "");

        r.KeyDown += delegate(object sender, KeyEventArgs e) {
            if (e.Key == Key.Back)
            {
                r.Back();
            }
        };

        back.Clicked += delegate {
            r.Back();
        };

        SetSize(r, width, height);

        h.Application.RootVisual = r;

        w.ResizeChecked += delegate(object sender, EventArgs e) {
            int new_width, new_heigth;
            w.GetSize(out new_width, out new_heigth);

            SetSize(r, new_width, new_heigth);;
        };

        Gtk.Application.Run();
    }
Example #2
0
    static int LoadXap(string file, List <string> args)
    {
        string [] test = { "" };

        if (sync)
        {
            test [0] = "--sync";
        }

        Application.Init("mopen", ref test);
        MoonlightRuntime.Init();
        window = new Gtk.Window(file);
        window.SetDefaultSize(400, 400);

        if (transparent)
        {
            CompositeHelper.SetRgbaColormap(window);
            window.AppPaintable = true;
            window.ExposeEvent += HandleExposeEvent;
        }

        if (desklet)
        {
            ConfigureDeskletWindow(window);
        }

        window.DeleteEvent += delegate {
            Application.Quit();
        };

        moon_host = new MoonlightHost();

        try {
            moon_host.LoadXap(file);
        } catch (Exception e) {
            Console.Error.WriteLine("mopen: Could not load xaml: {0}", e.Message);
            return(1);
        }

        System.Windows.Application app = moon_host.Application;
        FrameworkElement           top = (FrameworkElement)app.RootVisual;

        if (top is Moon.Windows.Desktop.Window)
        {
            var moonwindow = ((Moon.Windows.Desktop.Window)top);
            /* special window handling mode */
            moonwindow.IsActive = window.IsActive;

            Wnck.Screen.Default.ActiveWindowChanged += delegate {
                moonwindow.IsActive = window.IsActive;
            };

            moonwindow.PositionChanged += delegate {
                window.Move((int)moonwindow.Position.X, (int)moonwindow.Position.Y);
            };

            moonwindow.SizeChanged += delegate {
                window.Resize((int)moonwindow.Size.Width, (int)moonwindow.Size.Height);
            };

            moonwindow.WindowOpacityChanged += delegate {
                moon_host.QueueDraw();
            };

            if (!transparent)
            {
                CompositeHelper.SetRgbaColormap(window);
                window.AppPaintable = true;
                window.ExposeEvent += HandleExposeEvent;

                moon_host.AppPaintable = true;
                moon_host.Transparent  = true;
            }
        }

        if (parse_only)
        {
            return(0);
        }

        if (width == -1)
        {
            width = (int)top.Width;
        }
        if (height == -1)
        {
            height = (int)top.Height;
        }

        if (width > 0 && height > 0)
        {
            moon_host.SetSizeRequest(width, height);
            window.Resize(width, height);
        }

        if (transparent)
        {
            moon_host.AppPaintable = true;
            moon_host.Transparent  = true;
        }

        if (desklet)
        {
            top.MouseLeftButtonDown += new MouseButtonEventHandler(HandleMouseLeftButtonDown);
            top.MouseLeftButtonUp   += new MouseButtonEventHandler(HandleMouseLeftButtonUp);
            top.MouseMove           += new MouseEventHandler(HandleMouseMove);
        }

        window.Add(moon_host);

        window.ShowAll();

        if (story_names != null)
        {
            storyboards = new List <Storyboard> ();

            foreach (string story in story_names)
            {
                object     o  = top.FindName(story);
                Storyboard sb = o as Storyboard;

                if (sb == null)
                {
                    Console.Error.WriteLine("mopen: there is no Storyboard object named {0} in the XAML file", story);
                    return(1);
                }
                sb.Completed += delegate {
                    window.Title = String.Format("Storyboard {0} completed", current_storyboard - 1);
                };

                storyboards.Add(sb);
            }
            ;

            top.MouseLeftButtonUp += delegate {
                if (current_storyboard == storyboards.Count)
                {
                    current_storyboard = 0;
                }
                if (current_storyboard == storyboards.Count)
                {
                    return;
                }

                window.Title = String.Format("Storyboard {0} running", current_storyboard);
                storyboards [current_storyboard++].Begin();
            };
        }

        if (timeout > 0)
        {
            GLib.Timeout.Add((uint)(timeout * 1000), new TimeoutHandler(Quit));
        }

        Application.Run();
        return(0);
    }