protected override void OnSizeAllocated(Gdk.Rectangle allocation)
        {
            Console.WriteLine (allocation.Width + " " + allocation.Height);
            base.OnSizeAllocated (allocation);

            if(requestedWidth != allocation.Width || requiredHeight != allocation.Height)
            {
                int width = -1;
                candidateCombinaison = null;

                foreach(VariantsCombinaison combi in combinaisons)
                {
                    //combi.HeightRequest = allocation.Height;

                    Requisition req = combi.SizeRequest ();

                    if(req.Width <= allocation.Width && req.Width > width)
                    {
                        candidateCombinaison = combi;
                        width = req.Width;
                    }
                }
            }

            Select (candidateCombinaison);

            if(candidateCombinaison != null)
            {
                candidateCombinaison.SizeAllocate (allocation);
            }
        }
        public VariantsCombinaisonTest()
            : base(WindowType.Toplevel)
        {
            AddEvents ((int)(Gdk.EventMask.ButtonPressMask | Gdk.EventMask.ButtonReleaseMask | Gdk.EventMask.PointerMotionMask));
            Title = "Ribbons Sample";
            AppPaintable = true;

            VariantsCombinaisonSwitcher switcher = new VariantsCombinaisonSwitcher ();

            RibbonGroup group0 = CreateGroup0 ();
            RibbonGroup group1 = CreateGroup1 ();
            RibbonGroup group2 = CreateGroup2 ();
            DropdownRibbonGroup dgroup0 = CreateDropdownGroup0 ();
            dgroup0.Group = group0;
            DropdownRibbonGroup dgroup1 = CreateDropdownGroup1 ();
            dgroup1.Group = group1;
            DropdownRibbonGroup dgroup2 = CreateDropdownGroup2 ();
            dgroup2.Group = group2;

            VariantsCombinaison combi0 = new VariantsCombinaison ();
            combi0.Append (group0);
            combi0.Append (group1);
            combi0.Append (group2);
            switcher.AddCombinaison (combi0);

            VariantsCombinaison combi1 = new VariantsCombinaison ();
            combi1.Append (group0);
            combi1.Append (group1);
            combi1.Append (dgroup2);
            switcher.AddCombinaison (combi1);

            VariantsCombinaison combi2 = new VariantsCombinaison ();
            combi2.Append (dgroup0);
            combi2.Append (dgroup1);
            combi2.Append (dgroup2);
            switcher.AddCombinaison (combi2);

            Add (switcher);

            ScreenChanged += Window_OnScreenChanged;
            Window_OnScreenChanged (this, null);
            ExposeEvent += Window_OnExpose;
            DeleteEvent += Window_OnDelete;

            this.Resize (200, 200);
            this.ShowAll ();
        }
Пример #3
0
        public MainWindow()
            : base(WindowType.Toplevel)
        {
            AddEvents ((int)(Gdk.EventMask.ButtonPressMask | Gdk.EventMask.ButtonReleaseMask | Gdk.EventMask.PointerMotionMask));

            VBox master = new VBox ();
            master.AddEvents ((int)(Gdk.EventMask.ButtonPressMask | Gdk.EventMask.ButtonReleaseMask | Gdk.EventMask.PointerMotionMask));

            Title = "Ribbons Sample";
            AppPaintable = true;

            VariantsCombinaisonSwitcher page0 = new VariantsCombinaisonSwitcher ();

            RibbonGroup group0 = CreateGroup0 ();
            RibbonGroup group1 = CreateGroup1 ();
            RibbonGroup group2 = CreateGroup2 ();
            DropdownRibbonGroup dgroup0 = CreateDropdownGroup0 ();
            dgroup0.Group = group0;
            DropdownRibbonGroup dgroup1 = CreateDropdownGroup1 ();
            dgroup1.Group = group1;
            DropdownRibbonGroup dgroup2 = CreateDropdownGroup2 ();
            dgroup2.Group = group2;

            VariantsCombinaison combi0 = new VariantsCombinaison ();
            combi0.Append (group0);
            combi0.Append (group1);
            combi0.Append (group2);
            page0.AddCombinaison (combi0);

            VariantsCombinaison combi1 = new VariantsCombinaison ();
            combi1.Append (group0);
            combi1.Append (group1);
            combi1.Append (dgroup2);
            page0.AddCombinaison (combi1);

            VariantsCombinaison combi2 = new VariantsCombinaison ();
            combi2.Append (dgroup0);
            combi2.Append (dgroup1);
            combi2.Append (dgroup2);
            page0.AddCombinaison (combi2);

            HBox page1 = new HBox (false, 2);
            RibbonGroup group10 = new RibbonGroup ();
            group10.Label = "Welcome on the second page";
            page1.PackStart (group10, false, false, 0);

            HBox page2 = new HBox (false, 2);

            Label pageLabel0 = new Label ("Page 1");
            pageLabel1 = new Label ("Page 2");
            Label pageLabel2 = new Label ("Page 3");

            Ribbons.Button shortcuts = new Ribbons.Button ("Menu");
            shortcuts.Child.ModifyFg (Gtk.StateType.Normal, new Gdk.Color(255, 255, 255));

            Menu mainMenu = new Menu ();
            MenuItem mainMenu_quit = new MenuItem ("Quit");
            mainMenu_quit.Activated += delegate (object Sender, EventArgs e)
            {
                Application.Quit ();
            };
            mainMenu.Append (mainMenu_quit);

            shortcuts.Clicked += delegate (object Sender, EventArgs e)
            {
                mainMenu.Popup ();
                mainMenu.ShowAll ();
            };

            QuickAccessToolbar qat = new QuickAccessToolbar ();
            Ribbons.Button qatNew, qatSave;
            qat.Append (qatNew = Ribbons.Button.FromStockIcon (Gtk.Stock.New, false));
            qat.Append (qatSave = Ribbons.Button.FromStockIcon (Gtk.Stock.Save, false));

            ribbon = new Ribbon ();
            ribbon.ApplicationButton = new ApplicationButton ();
            ribbon.QuickAccessToolbar = qat;
            //ribbon.Shortcuts = shortcuts;
            ribbon.AppendPage (page0, pageLabel0);
            ribbon.AppendPage (page1, pageLabel1);
            ribbon.AppendPage (page2, pageLabel2);
            pageLabel1.AddEvents ((int)(Gdk.EventMask.ButtonPressMask | Gdk.EventMask.ButtonReleaseMask | Gdk.EventMask.PointerMotionMask));
            pageLabel1.ButtonPressEvent += delegate (object sender, ButtonPressEventArgs e)
            {
                Console.WriteLine("label1 press");
            };
            pageLabel1.EnterNotifyEvent += delegate (object sender, EnterNotifyEventArgs e)
            {
                Console.WriteLine("label1 enter");
            };
            pageLabel1.LeaveNotifyEvent += delegate (object sender, LeaveNotifyEventArgs e)
            {
                Console.WriteLine("label1 leave");
            };

            ApplicationMenu appMenu = ribbon.ApplicationButton.Menu;
            TextView mnu = new TextView ();
            appMenu.DefaultMenu = mnu;
            mnu.Buffer.InsertAtCursor ("Default");
            ApplicationMenuItem mi = new ApplicationMenuItem ("Test 1");
            mnu = new TextView ();
            mi.Menu = mnu;
            mnu.Buffer.InsertAtCursor ("Test 1");
            appMenu.Append (mi);
            mi = new ApplicationMenuItem ("Test 2");
            appMenu.Append (mi);
            mi = new ApplicationMenuItem ("Test 3");
            appMenu.Append (mi);

            appMenu.OptionsButton = new Ribbons.Button ("Options");
            appMenu.ExitButton = new Ribbons.Button ("Exit");

            TextView txt = new TextView ();

            master.PackStart (ribbon, false, false, 0);
            master.PackStart (txt, true, true, 0);

            Add (master);

            ribbon.ApplicationButton.KeyTip = new KeyTip (appMenu, "A");
            qat.AddKeyTip (new KeyTip (qatNew, "B"));
            qat.AddKeyTip (new KeyTip (qatSave, "C"));
            ribbon.AddTabKeyTip (new KeyTip (pageLabel0, "D"));
            ribbon.AddTabKeyTip (new KeyTip (pageLabel1, "E"));
            ribbon.AddTabKeyTip (new KeyTip (pageLabel2, "F"));

            ScreenChanged += Window_OnScreenChanged;
            Window_OnScreenChanged (this, null);
            ExposeEvent += Window_OnExpose;
            DeleteEvent += Window_OnDelete;

            this.Resize (200, 200);
            this.ShowAll ();
        }
 public void RemoveCombinaison(VariantsCombinaison Combinaison)
 {
     combinaisons.Remove (Combinaison);
 }
 public void AddCombinaison(VariantsCombinaison Combinaison)
 {
     combinaisons.Add (Combinaison);
 }
        private void Select(VariantsCombinaison combi)
        {
            Console.WriteLine ("Select: " + combi);
            if(selectedCombinaison != combi)
            {
                if(selectedCombinaison != null)
                {
                    selectedCombinaison.Unparent ();
                }

                if(combi != null)
                {
                    combi.Parent = this;
                }

                selectedCombinaison = combi;
            }
        }
        protected override void OnSizeRequested(ref Requisition requisition)
        {
            Console.WriteLine ("TEST");
            base.OnSizeRequested (ref requisition);

            /*combinaisons[0].HeightRequest = HeightRequest;
            requisition = combinaisons[0].SizeRequest ();
            requiredHeight = requisition.Height;
            requestedWidth = requisition.Width;
            candidateCombinaison = combinaisons[0];
            return;*/

            candidateCombinaison = null;
            requiredHeight = HeightRequest;

            if(WidthRequest == -1)
            {
                int width = int.MaxValue;

                foreach(VariantsCombinaison combi in combinaisons)
                {
                    //combi.HeightRequest = HeightRequest;

                    Requisition req = combi.SizeRequest ();

                    if(req.Width < width)
                    {
                        candidateCombinaison = combi;
                        width = req.Width;
                        requiredHeight = req.Height;
                    }
                }

                requestedWidth = requisition.Width = width;
            }
            else if(HeightRequest == -1)
            {
                int width = -1;

                foreach(VariantsCombinaison combi in combinaisons)
                {
                    combi.HeightRequest = -1;

                    Requisition req = combi.SizeRequest ();

                    if((req.Width <= WidthRequest && req.Width > width) || (width > WidthRequest && req.Width < width))
                    {
                        candidateCombinaison = combi;
                        width = req.Width;
                        requiredHeight = req.Height;
                    }
                }

                requestedWidth = requisition.Width = WidthRequest;
            }

            if(HeightRequest == -1) requisition.Height = requiredHeight;
            else requisition.Height = HeightRequest;

            Console.WriteLine ("Switcher req: " + requisition.Width + " " + requisition.Height);
        }