示例#1
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 Prepend(ApplicationMenuItem i)
 {
     Insert (i, 0);
 }
 public void Append(ApplicationMenuItem i)
 {
     Insert (i, -1);
 }
        public void Insert(ApplicationMenuItem i, int ItemIndex)
        {
            i.Parent = this;
            i.Visible = true;

            if(ItemIndex == -1)
                items.Add (i);
            else
                items.Insert (ItemIndex, i);
        }
示例#5
0
        internal void DrawApplicationMenuItem(Context cr, Rectangle bodyAllocation, MenuItemState state, double roundSize, double lineWidth, double arrowSize, double arrowPadding, bool drawSeparator, ApplicationMenuItem widget)
        {
            double lineWidth05 = lineWidth / 2;
            double lineWidth15 = lineWidth05 * 3;
            double separatorX = bodyAllocation.X + bodyAllocation.Width - 2 * lineWidth - arrowSize - 2 * arrowPadding;

            cr.LineWidth = lineWidth;

            if(state != MenuItemState.Default)
            {
                LinearGradient bodyPattern, innerBorderPattern;
                Color borderColor;

                bodyPattern = new LinearGradient (bodyAllocation.X, bodyAllocation.Y, bodyAllocation.X, bodyAllocation.Y + bodyAllocation.Height);
                bodyPattern.AddColorStopRgb (0.0, new Color (1, 0.996, 0.890));
                bodyPattern.AddColorStopRgb (0.37, new Color (1, 0.906, 0.592));
                bodyPattern.AddColorStopRgb (0.43, new Color (1, 0.843, 0.314));
                bodyPattern.AddColorStopRgb (1.0, new Color (1, 0.906, 0.588));

                innerBorderPattern = new LinearGradient (bodyAllocation.X, bodyAllocation.Y, bodyAllocation.X + bodyAllocation.Width, bodyAllocation.Y + bodyAllocation.Height);
                innerBorderPattern.AddColorStop (0.0, new Color (1, 1, 0.969, 1));
                innerBorderPattern.AddColorStop (1.0, new Color (1, 1, 0.969, 0));

                borderColor = new Color (0.824, 0.753, 0.553);

                double x0 = bodyAllocation.X + lineWidth05, y0 = bodyAllocation.Y + lineWidth05;
                double x1 = bodyAllocation.X + bodyAllocation.Width - lineWidth05, y1 = bodyAllocation.Y + bodyAllocation.Height - lineWidth05;

                cr.MoveTo (x0 + roundSize, y0);
                cr.Arc (x1 - roundSize, y0 + roundSize, roundSize, 1.5*Math.PI, 0);
                cr.Arc (x1 - roundSize, y1 - roundSize, roundSize, 0, 0.5*Math.PI);
                cr.Arc (x0 + roundSize, y1 - roundSize, roundSize, 0.5*Math.PI, Math.PI);
                cr.Arc (x0 + roundSize, y0 + roundSize, roundSize, Math.PI, 1.5*Math.PI);

                cr.Pattern = bodyPattern;
                cr.Fill ();
                bodyPattern.Destroy ();

                if(state == MenuItemState.HilightAction)
                {
                    cr.Color = new Color (1, 1, 1, 0.7);
                    cr.MoveTo (x0 + roundSize, y0);
                    cr.LineTo (separatorX, y0);
                    cr.LineTo (separatorX, y1);
                    cr.Arc (x0 + roundSize, y1 - roundSize, roundSize, 0.5*Math.PI, Math.PI);
                    cr.Arc (x0 + roundSize, y0 + roundSize, roundSize, Math.PI, 1.5*Math.PI);
                    cr.Fill ();
                }
                else if(state == MenuItemState.HilightMenu)
                {
                    cr.Color = new Color (1, 1, 1, 0.7);
                    cr.MoveTo (separatorX, y0);
                    cr.Arc (x1 - roundSize, y0 + roundSize, roundSize, 1.5*Math.PI, 0);
                    cr.Arc (x1 - roundSize, y1 - roundSize, roundSize, 0, 0.5*Math.PI);
                    cr.LineTo (separatorX, y1);
                    cr.LineTo (separatorX, y0);
                    cr.Fill ();
                }

                x0 = bodyAllocation.X + lineWidth15; y0 = bodyAllocation.Y + lineWidth15;
                x1 = bodyAllocation.X + bodyAllocation.Width - lineWidth15; y1 = bodyAllocation.Y + bodyAllocation.Height - lineWidth15;

                double roundSizeMinusLineWidth = roundSize - lineWidth;

                x0 -= lineWidth;

                cr.MoveTo (x0 + roundSizeMinusLineWidth, y0);
                cr.Arc (x1 - roundSizeMinusLineWidth, y0 + roundSizeMinusLineWidth, roundSizeMinusLineWidth, 1.5*Math.PI, 0);
                cr.Arc (x1 - roundSizeMinusLineWidth, y1 - roundSizeMinusLineWidth, roundSizeMinusLineWidth, 0, 0.5*Math.PI);
                cr.Arc (x0 + roundSizeMinusLineWidth, y1 - roundSizeMinusLineWidth, roundSizeMinusLineWidth, 0.5*Math.PI, Math.PI);
                cr.Arc (x0 + roundSizeMinusLineWidth, y0 + roundSizeMinusLineWidth, roundSizeMinusLineWidth, Math.PI, 1.5*Math.PI);

                x0 += lineWidth;

                cr.Pattern = innerBorderPattern;
                cr.Stroke ();
                innerBorderPattern.Destroy ();

                x0 = bodyAllocation.X + lineWidth05; y0 = bodyAllocation.Y + lineWidth05;
                x1 = bodyAllocation.X + bodyAllocation.Width - lineWidth05; y1 = bodyAllocation.Y + bodyAllocation.Height - lineWidth05;

                cr.MoveTo (x0 + roundSize, y0);
                cr.Arc (x1 - roundSize, y0 + roundSize, roundSize, 1.5*Math.PI, 0);
                cr.Arc (x1 - roundSize, y1 - roundSize, roundSize, 0, 0.5*Math.PI);
                cr.Arc (x0 + roundSize, y1 - roundSize, roundSize, 0.5*Math.PI, Math.PI);

                cr.Color = borderColor;
                cr.Stroke ();
            }

            if(arrowSize > 0)
            {
                double x, y;

                x = separatorX;
                y = bodyAllocation.Y + (bodyAllocation.Height - arrowSize) / 2.0;

                if(drawSeparator)
                {
                    double top = bodyAllocation.Y + 2 * lineWidth, bottom = bodyAllocation.Y + bodyAllocation.Height - 2 * lineWidth;
                    cr.MoveTo (x - lineWidth / 2, top);
                    cr.LineTo (x - lineWidth / 2, bottom);
                    cr.Color = new Color (0, 0, 0, 0.1);
                    cr.Stroke ();

                    cr.MoveTo (x + lineWidth / 2, top);
                    cr.LineTo (x + lineWidth / 2, bottom);
                    cr.Color = new Color (1, 1, 1, 0.6);
                    cr.Stroke ();
                }

                x += arrowSize / 4.0 + lineWidth / 2.0;

                cr.MoveTo (x, y);
                cr.LineTo (x, y + arrowSize);
                cr.LineTo (x + arrowSize / 2.0, y + arrowSize / 2.0);
                cr.LineTo (x, y);
                cr.Color = new Color (0, 0, 0);
                cr.Fill ();
            }
        }