diff --git a/sample/GtkDemo/DemoApplicationWindow.cs b/sample/GtkDemo/DemoApplicationWindow.cs index 134425ecf..1ef4f781a 100644 --- a/sample/GtkDemo/DemoApplicationWindow.cs +++ b/sample/GtkDemo/DemoApplicationWindow.cs @@ -2,6 +2,7 @@ // ApplicationWindow.cs, port of appwindow.c from gtk-demo // // Author: Daniel Kornhauser +// John Luke // // Copyright (C) 2003, Ximian Inc. @@ -11,10 +12,7 @@ * Demonstrates a typical application window, with menubar, toolbar, statusbar. */ -// : - Is this necesary? /* Set up item factory to go away with the window */ - using System; - using Gtk; namespace GtkDemo @@ -27,82 +25,119 @@ namespace GtkDemo int row, column, count = 0; Statusbar statusbar; + VBox vbox; - // static ItemFactoryEntry items[] = { new ItemFactoryEntry ("/_File", null, 0, 0, "" )}; + const string uiInfo = + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + ""; public DemoApplicationWindow () : base ("Demo Application Window") { this.SetDefaultSize (400, 300); this.DeleteEvent += new DeleteEventHandler (WindowDelete); - VBox vbox = new VBox (false, 0); + vbox = new VBox (false, 0); this.Add (vbox); - // Create the menubar + AddActions (); - AccelGroup accelGroup = new AccelGroup (); - this.AddAccelGroup (accelGroup); - - MenuBar menubar = CreateMenu (); - vbox.PackStart (menubar, false, false, 0); - - Toolbar toolbar = CreateToolbar (); - vbox.PackStart (toolbar, false, false, 0); - - TextView textview = new TextView (); - textview.Buffer.MarkSet += new MarkSetHandler (OnMarkSet); - vbox.PackStart (textview, true, true, 0); - statusbar = new Statusbar (); UpdateStatus (); + vbox.PackEnd (statusbar, false, false, 0); - vbox.PackStart (statusbar, false, false, 0); + TextView textview = new TextView (); + textview.Buffer.MarkSet += new MarkSetHandler (OnMarkSet); + vbox.PackEnd (textview, true, true, 0); - //ItemFactory itemFactory = new ItemFactory (typeof (MenuBar),"
", accelGroup); - - // static ItemFactoryEntry items[] = { new ItemFactoryEntry ("/_File", null, 0, 0, "" )}; - - - - // Set up item factory to go away with the window - // Is this necesary ? - - // create menu items - //STUCK : Didn't find any examples of ItemFactory - this.ShowAll (); } - - private MenuBar CreateMenu () + + void AddActions () { - MenuBar menubar = new MenuBar (); - MenuItem file = new MenuItem ("File"); - menubar.Append (file); - return menubar; + ActionEntry[] actions = new ActionEntry[] + { + new ActionEntry ("FileMenu", null, "_File", null, null, null), + new ActionEntry ("PreferencesMenu", null, "_Preferences", null, null, null), + new ActionEntry ("ColorMenu", null, "_Color", null, null, null), + new ActionEntry ("ShapeMenu", null, "_Shape", null, null, null), + new ActionEntry ("HelpMenu", null, "_Help", null, null, null), + new ActionEntry ("New", Stock.New, "_New", "N", "Create a new file", new EventHandler (OnActionActivated)), + new ActionEntry ("Open", Stock.Open, "_Open", "O", "Open a file", new EventHandler (OnActionActivated)), + new ActionEntry ("Save", Stock.Save, "_Save", "S", "Save current file", new EventHandler (OnActionActivated)), + new ActionEntry ("SaveAs", Stock.SaveAs, "Save _As", null, "Save to a file", new EventHandler (OnActionActivated)), + new ActionEntry ("Quit", Stock.Quit, "_Quit", "Q", "Quit", new EventHandler (OnActionActivated)), + new ActionEntry ("About", null, "_About", "A", "About", new EventHandler (OnActionActivated)), + new ActionEntry ("Logo", "demo-gtk-logo", "Gtk#", null, "Gtk#", new EventHandler (OnActionActivated)) + }; + + ToggleActionEntry[] toggleActions = new ToggleActionEntry[] + { + new ToggleActionEntry ("Bold", Stock.Bold, "_Bold", "B", "Bold", new EventHandler (OnActionActivated), false) + }; + + ActionEntry[] colorActions = new ActionEntry[] + { + new ActionEntry ("Red", null, "_Red", "R", "Blood", null), + new ActionEntry ("Green", null, "_Green", "G", "Grass", null), + new ActionEntry ("Blue", null, "_Blue", "B", "Sky", null) + }; + + ActionEntry[] shapeActions = new ActionEntry[] + { + new ActionEntry ("Square", null, "_Square", "S", "Square", null), + new ActionEntry ("Rectangle", null, "_Rectangle", "R", "Rectangle", null), + new ActionEntry ("Oval", null, "_Oval", "O", "Oval", null) + }; + + ActionGroup group = new ActionGroup ("group"); + group.Add (actions); + group.Add (toggleActions); + group.Add (colorActions); + group.Add (shapeActions); + + UIManager uim = new UIManager (); + uim.InsertActionGroup (group, (int) uim.NewMergeId ()); + uim.AddWidget += new AddWidgetHandler (OnAddWidget); + uim.AddUiFromString (uiInfo); } - private Toolbar CreateToolbar () + private void OnActionActivated (object sender, EventArgs a) { - Toolbar toolbar = new Toolbar (); - - Button open = new Button (Stock.Open); - open.Clicked += new EventHandler (OnToolbarClicked); - toolbar.AppendWidget (open, "Open", "Open"); - - Button quit = new Button (Stock.Quit); - quit.Clicked += new EventHandler (OnToolbarClicked); - toolbar.AppendWidget (quit, "Quit", "Quit"); - - Button gtk = new Button ("Gtk#"); - gtk.Clicked += new EventHandler (OnToolbarClicked); - toolbar.AppendWidget (gtk, "Gtk#", "Gtk#"); - - return toolbar; - } - - private void OnToolbarClicked (object o, EventArgs args) - { - using (MessageDialog md = new MessageDialog (this, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Close, "You selected a toolbar button.")) { + Action action = sender as Action; + + using (MessageDialog md = new MessageDialog (this, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Close, String.Format ("You activated action: {0}", action.Name))) { md.Run (); md.Hide (); } @@ -129,5 +164,12 @@ namespace GtkDemo statusbar.Pop (ctx); statusbar.Push (ctx, String.Format (fmt, row, column, count)); } + + void OnAddWidget (object sender, AddWidgetArgs a) + { + a.Widget.Show (); + vbox.PackStart (a.Widget, false, true, 0); + } } } + diff --git a/sample/GtkDemo/DemoMain.cs b/sample/GtkDemo/DemoMain.cs index bc76878a1..b25904132 100644 --- a/sample/GtkDemo/DemoMain.cs +++ b/sample/GtkDemo/DemoMain.cs @@ -157,7 +157,7 @@ namespace GtkDemo store = new TreeStore (typeof (string), typeof (string), typeof (bool)); TreeIter parent; - store.AppendValues ("Application Window (75% complete)", "DemoApplicationWindow.cs", false); + store.AppendValues ("Application Window", "DemoApplicationWindow.cs", false); store.AppendValues ("Button Boxes", "DemoButtonBox.cs", false); store.AppendValues ("Change Display (0%)", "DemoChangeDisplay.cs", false); store.AppendValues ("Color Selector", "DemoColorSelection.cs", false); diff --git a/sample/GtkDemo/DemoSizeGroup.cs b/sample/GtkDemo/DemoSizeGroup.cs index 9c3b3c549..38297fad0 100644 --- a/sample/GtkDemo/DemoSizeGroup.cs +++ b/sample/GtkDemo/DemoSizeGroup.cs @@ -85,22 +85,15 @@ namespace GtkDemo } // Convenience function to create an option menu holding a number of strings - private OptionMenu CreateOptionMenu (string [] strings) + private ComboBox CreateOptionMenu (string [] strings) { - Menu menu = new Menu (); - MenuItem menuItem; + ComboBox combo = ComboBox.NewText (); foreach (string str in strings) - { - menuItem = new MenuItem (str); - menuItem.Show (); - menu.Append (menuItem); - } + combo.AppendText (str); - OptionMenu optionMenu = new OptionMenu (); - optionMenu.Menu = menu; - - return optionMenu; + combo.Active = 0; + return combo; } private void AddRow (Table table, uint row, SizeGroup sizeGroup, string labelText, string [] options) @@ -113,10 +106,10 @@ namespace GtkDemo AttachOptions.Expand, AttachOptions.Fill, 0, 0); - OptionMenu optionMenu = CreateOptionMenu (options); + ComboBox combo = CreateOptionMenu (options); - sizeGroup.AddWidget (optionMenu); - table.Attach (optionMenu, + sizeGroup.AddWidget (combo); + table.Attach (combo, 1, 2, row, row + 1, AttachOptions.Expand, AttachOptions.Expand, 0, 0); diff --git a/sample/GtkDemo/DemoTextView.cs b/sample/GtkDemo/DemoTextView.cs index f1e6d50c7..a141a0a6b 100644 --- a/sample/GtkDemo/DemoTextView.cs +++ b/sample/GtkDemo/DemoTextView.cs @@ -79,21 +79,17 @@ namespace GtkDemo textView.AddChildAtAnchor (button, buttonAnchor); button.ShowAll (); - OptionMenu option = new OptionMenu (); - Menu menu = new Menu (); - MenuItem menuItem = new MenuItem ("Option 1"); - menu.Append (menuItem); - menuItem = new MenuItem ("Option 2"); - menu.Append (menuItem); - menuItem = new MenuItem ("Option 3"); - menu.Append (menuItem); - option.Menu = menu; - textView.AddChildAtAnchor (option, menuAnchor); - menu.ShowAll (); + ComboBox combo = ComboBox.NewText (); + combo.AppendText ("Option 1"); + combo.AppendText ("Option 2"); + combo.AppendText ("Option 3"); + combo.Active = 0; - HScale scale = new HScale (null); + textView.AddChildAtAnchor (combo, menuAnchor); + + HScale scale = new HScale (null); scale.SetRange (0,100); - scale.SetSizeRequest (70, -1); + scale.SetSizeRequest (70, -1); textView.AddChildAtAnchor (scale, scaleAnchor); scale.ShowAll (); diff --git a/sample/GtkDemo/TODO b/sample/GtkDemo/TODO index 2d4955a3d..4f85cfad9 100644 --- a/sample/GtkDemo/TODO +++ b/sample/GtkDemo/TODO @@ -4,9 +4,6 @@ General DemoMain - syntax highlighting -DemoApplicationWindow - - ItemFactory stuff - DemoIconFactory - almost everything @@ -19,9 +16,6 @@ DemoStockBrowser - missing stockitems for some reason - remove duplication in ListStore, and use DataFunc's -DemoTextView - - small issue with international text - DemoHyperText - finish