diff --git a/sample/GtkDemo/DemoEntryCompletion.cs b/sample/GtkDemo/DemoEntryCompletion.cs new file mode 100644 index 000000000..d407c6c36 --- /dev/null +++ b/sample/GtkDemo/DemoEntryCompletion.cs @@ -0,0 +1,42 @@ +using System; +using Gtk; + +namespace GtkDemo +{ + public class DemoEntryCompletion : Dialog + { + public DemoEntryCompletion () : base ("Demo Entry Completion", null, DialogFlags.DestroyWithParent) + { + this.BorderWidth = 10; + + Label label = new Label ("Completion demo, try writing total or gnome for example."); + label.UseMarkup = true; + this.VBox.PackStart (label, false, true, 0); + + Entry entry = new Entry (); + // FIXME: no way to set model + //entry.Completion = new EntryCompletion (); + //entry.SetModel (CreateCompletionModel ()); + this.VBox.PackStart (entry, false, true, 0); + + this.AddButton (Stock.Close, ResponseType.Close); + + this.ShowAll (); + this.Run (); + this.Hide (); + this.Destroy (); + } + + TreeModel CreateCompletionModel () + { + ListStore store = new ListStore (typeof (string)); + + store.AppendValues ("GNOME"); + store.AppendValues ("total"); + store.AppendValues ("totally"); + + return store; + } + } +} + diff --git a/sample/GtkDemo/DemoExpander.cs b/sample/GtkDemo/DemoExpander.cs new file mode 100644 index 000000000..2ef683c18 --- /dev/null +++ b/sample/GtkDemo/DemoExpander.cs @@ -0,0 +1,26 @@ +using System; +using Gtk; + +namespace GtkDemo +{ + public class DemoExpander : Gtk.Dialog + { + public DemoExpander () : base ("Demo Expander", null, DialogFlags.DestroyWithParent) + { + this.BorderWidth = 10; + this.VBox.PackStart (new Label ("Expander demo. Click on the triangle for details."), false, true, 3); + + Expander expander = new Expander ("Details"); + expander.Add (new Label ("Details can be shown or hidden.")); + this.VBox.PackStart (expander, false, true, 3); + + this.AddButton (Stock.Close, ResponseType.Close); + + this.ShowAll (); + this.Run (); + this.Hide (); + this.Destroy (); + } + } +} + diff --git a/sample/GtkDemo/DemoItemFactory.cs b/sample/GtkDemo/DemoItemFactory.cs deleted file mode 100644 index c119c1743..000000000 --- a/sample/GtkDemo/DemoItemFactory.cs +++ /dev/null @@ -1,42 +0,0 @@ -// -// DemoItemFactoryDemo.cs - port of item_factory from gtk-demo -// -// Author: Daniel Kornhauser -// -// Copyright (C) 2003, Ximian Inc. - -/* Item Factory - * - * The GtkItemFactory object allows the easy creation of menus - * from an array of descriptions of menu items. - */ - -// TODO: - unfinished - -using System; -using System.IO; - -using Gtk; -using Gdk; - -namespace GtkDemo -{ - public class DemoItemFactory : Gtk.Window - { - public DemoItemFactory () : base ("Demo Item Factory") - { - this.DeleteEvent += new DeleteEventHandler (WindowDelete); - Gtk.AccelGroup accelGroup = new Gtk.AccelGroup (); - //STUCK OUCH !!!! - - this.ShowAll (); - } - - private void WindowDelete (object o, DeleteEventArgs args) - { - this.Hide (); - this.Destroy (); - args.RetVal = true; - } - } -} diff --git a/sample/GtkDemo/DemoMain.cs b/sample/GtkDemo/DemoMain.cs index b25904132..4600d804f 100644 --- a/sample/GtkDemo/DemoMain.cs +++ b/sample/GtkDemo/DemoMain.cs @@ -153,9 +153,9 @@ namespace GtkDemo private TreeStore FillTree () { - // title, filename, italic + // title, filename, italic store = new TreeStore (typeof (string), typeof (string), typeof (bool)); - TreeIter parent; + TreeIter parent; store.AppendValues ("Application Window", "DemoApplicationWindow.cs", false); store.AppendValues ("Button Boxes", "DemoButtonBox.cs", false); @@ -163,20 +163,22 @@ namespace GtkDemo store.AppendValues ("Color Selector", "DemoColorSelection.cs", false); store.AppendValues ("Dialog and Message Boxes", "DemoDialog.cs", false); store.AppendValues ("Drawing Area", "DemoDrawingArea.cs", false); + store.AppendValues ("Entry Completion", "DemoEntryCompletion.cs", false); + store.AppendValues ("Expander", "DemoExpander.cs", false); store.AppendValues ("Images", "DemoImages.cs", false); - store.AppendValues ("Item Factory (5% complete)", "DemoItemFactory.cs", false); store.AppendValues ("Menus", "DemoMenus.cs", false); store.AppendValues ("Paned Widget", "DemoPanes.cs", false); store.AppendValues ("Pixbuf", "DemoPixbuf.cs", false); store.AppendValues ("Size Groups", "DemoSizeGroup.cs", false); store.AppendValues ("Stock Item and Icon Browser (10% complete)", "DemoStockBrowser.cs", false); parent = store.AppendValues ("Text Widget"); - store.AppendValues (parent, "HyperText (50%)", "DemoHyperText.cs", false); - store.AppendValues (parent, "Multiple Views", "DemoTextView.cs", false); + store.AppendValues (parent, "HyperText (50%)", "DemoHyperText.cs", false); + store.AppendValues (parent, "Multiple Views", "DemoTextView.cs", false); parent = store.AppendValues ("Tree View"); - store.AppendValues (parent, "Editable Cells", "DemoEditableCells.cs", false); - store.AppendValues (parent, "List Store", "DemoListStore.cs", false); - store.AppendValues (parent, "Tree Store", "DemoTreeStore.cs", false); + store.AppendValues (parent, "Editable Cells", "DemoEditableCells.cs", false); + store.AppendValues (parent, "List Store", "DemoListStore.cs", false); + store.AppendValues (parent, "Tree Store", "DemoTreeStore.cs", false); + store.AppendValues ("UIManager", "DemoUIManager.cs", false); return store; } @@ -222,47 +224,53 @@ namespace GtkDemo new DemoDrawingArea (); break; case "6": - new DemoImages (); + new DemoEntryCompletion (); break; case "7": - new DemoItemFactory (); + new DemoExpander (); break; case "8": - new DemoMenus (); + new DemoImages (); break; case "9": - new DemoPanes (); + new DemoMenus (); break; case "10": - new DemoPixbuf (); + new DemoPanes (); break; case "11": - new DemoSizeGroup (); + new DemoPixbuf (); break; case "12": - new DemoStockBrowser (); + new DemoSizeGroup (); break; case "13": - ToggleRow (args.Path); - break; - case "13:0": - new DemoHyperText (); - break; - case "13:1": - new DemoTextView (); + new DemoStockBrowser (); break; case "14": ToggleRow (args.Path); - break; + break; case "14:0": - new DemoEditableCells (); + new DemoHyperText (); break; case "14:1": + new DemoTextView (); + break; + case "15": + ToggleRow (args.Path); + break; + case "15:0": + new DemoEditableCells (); + break; + case "15:1": new DemoListStore (); break; - case "14:2": + case "15:2": new DemoTreeStore (); break; + case "16": + new DemoUIManager (); + break; default: break; } diff --git a/sample/GtkDemo/DemoUIManager.cs b/sample/GtkDemo/DemoUIManager.cs new file mode 100644 index 000000000..3ceb6ea52 --- /dev/null +++ b/sample/GtkDemo/DemoUIManager.cs @@ -0,0 +1,140 @@ +using System; +using Gtk; + +namespace GtkDemo +{ + public class DemoUIManager : Window + { + VBox vbox; + + const string uiInfo = + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + public DemoUIManager () : base ("Demo UIManager") + { + this.SetDefaultSize (400, 300); + this.DeleteEvent += new DeleteEventHandler (WindowDelete); + + vbox = new VBox (false, 0); + this.Add (vbox); + + AddActions (); + + Button close = new Button (Stock.Close); + close.Clicked += new EventHandler (OnCloseClicked); + vbox.PackEnd (close, false, true, 0); + + vbox.PackEnd (new Label ("test"), true, true, 0); + + this.ShowAll (); + } + + void AddActions () + { + 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", new EventHandler (OnActionActivated)), + new ActionEntry ("Green", null, "_Green", "G", "Grass", new EventHandler (OnActionActivated)), + new ActionEntry ("Blue", null, "_Blue", "B", "Sky", new EventHandler (OnActionActivated)) + }; + + ActionEntry[] shapeActions = new ActionEntry[] + { + new ActionEntry ("Square", null, "_Square", "S", "Square", new EventHandler (OnActionActivated)), + new ActionEntry ("Rectangle", null, "_Rectangle", "R", "Rectangle", new EventHandler (OnActionActivated)), + new ActionEntry ("Oval", null, "_Oval", "O", "Oval", new EventHandler (OnActionActivated)) + }; + + 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 void OnActionActivated (object sender, EventArgs a) + { + Action action = sender as Action; + Console.WriteLine ("** Message: Action \"{0}\" activated", action.Name); + } + + private void WindowDelete (object o, DeleteEventArgs args) + { + this.Hide (); + this.Destroy (); + args.RetVal = true; + } + + void OnCloseClicked (object sender, EventArgs a) + { + this.Hide (); + this.Destroy (); + } + + void OnAddWidget (object sender, AddWidgetArgs a) + { + a.Widget.Show (); + vbox.PackStart (a.Widget, false, true, 0); + } + } +} + diff --git a/sample/GtkDemo/Makefile.am b/sample/GtkDemo/Makefile.am index f39adb65c..e1d52df32 100644 --- a/sample/GtkDemo/Makefile.am +++ b/sample/GtkDemo/Makefile.am @@ -6,25 +6,27 @@ noinst_SCRIPTS = $(TARGETS) EXTRA_DIST = $(sources) $(image_names) -sources = \ +sources = \ DemoApplicationWindow.cs \ DemoButtonBox.cs \ - DemoColorSelection.cs \ + DemoColorSelection.cs \ DemoDialog.cs \ DemoDrawingArea.cs \ - DemoEditableCells.cs \ + DemoEditableCells.cs \ + DemoEntryCompletion.cs \ + DemoExpander.cs \ DemoHyperText.cs \ DemoImages.cs \ - DemoItemFactory.cs \ DemoListStore.cs \ - DemoMain.cs \ + DemoMain.cs \ DemoMenus.cs \ DemoPanes.cs \ DemoPixbuf.cs \ DemoSizeGroup.cs \ DemoStockBrowser.cs \ - DemoTextView.cs \ - DemoTreeStore.cs + DemoTextView.cs \ + DemoTreeStore.cs \ + DemoUIManager.cs images = \ images/gnome-foot.png,gnome-foot.png \ diff --git a/sample/GtkDemo/TODO b/sample/GtkDemo/TODO index 4f85cfad9..ead77d693 100644 --- a/sample/GtkDemo/TODO +++ b/sample/GtkDemo/TODO @@ -5,7 +5,7 @@ DemoMain - syntax highlighting DemoIconFactory - - almost everything + - I think this is removed > gtk2.4 DemoImages - improve the Progressive Image loading and error handling @@ -19,3 +19,6 @@ DemoStockBrowser DemoHyperText - finish +DemoEntryCompletion + - set the model +