From 246d4e16205608b11100e2bef8a3eb866460e8d0 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Fri, 1 Apr 2005 21:08:14 +0000 Subject: [PATCH] * samples/GtkDemo/*.cs: General fixup and cleanup; Remove some gratuitous differences from the C version. Make comment and indent style consistent. Don't use "this." where not needed. Override OnDeleteEvent rather than connecting one's own DeleteEvent signal. * sample/GtkDemo/DemoApplicationWindow.cs (static DemoApplicationWindow): register the Gtk logo icon with StockManager so it shows up correctly in the toolbar. (AddActions): Register the radio items as radio items so they work right. * sample/GtkDemo/DemoHyperText.cs (EventAfter): handle link-clicking from Widget.WidgetEventAfter (as in the C version), rather than ButtonRelease, now that WidgetEventAfter is wrapped. * sample/GtkDemo/DemoImages.cs (DemoImages): use Gtk.Image.LoadFromResource (particularly to make the animation work right). (OnDestroyed): handle clean up (remove the timeout, etc) * sample/GtkDemo/DemoMain.cs (LoadStream): Fix handling of blank lines and whitespace to match the C version. * sample/GtkDemo/DemoPixbuf.cs (Expose): Use System.Runtime.InteropServices.Marshal.Copy() to copy pixbuf.Pixels to pass to DrawRgbImageDithalign, to make this more like the C version (and probably faster?) (timeout): Remove the FIXME since it seems to work now * sample/GtkDemo/DemoStockBrowser.cs: Simplify a bunch. Use reflection to get the C# names of the stock icons rather than trying to correctly re-mangle the ids. Display the Label with the accelerator underlined. * sample/GtkDemo/DemoTextView.cs (AttachWidgets): use Gtk.Image.LoadFromResource, so the image is properly loaded as an animation, not a static image. Don't set the combobox's "Active" property (for consistency with the C version). (InsertText): Fix miscellaneous differences with the C version. Remove some leftover cruft from earlier workarounds for gtk# bugs. * sample/GtkDemo/DemoTreeStore.cs (AddColumns): Make this more like the C version so the checkboxes are sensitized and hidden correctly on a per-row basis. * sample/GtkDemo/DemoUIManager.cs: Make the radio menu items work. * sample/GtkDemo/README: * sample/GtkDemo/TODO: update svn path=/trunk/gtk-sharp/; revision=42481 --- ChangeLog | 52 ++++ sample/GtkDemo/DemoApplicationWindow.cs | 259 ++++++++++-------- sample/GtkDemo/DemoAttribute.cs | 6 +- sample/GtkDemo/DemoButtonBox.cs | 81 +++--- sample/GtkDemo/DemoClipboard.cs | 36 +-- sample/GtkDemo/DemoColorSelection.cs | 46 ++-- sample/GtkDemo/DemoDialog.cs | 72 +++-- sample/GtkDemo/DemoDrawingArea.cs | 256 ++++++++--------- sample/GtkDemo/DemoEditableCells.cs | 158 +++++------ sample/GtkDemo/DemoEntryCompletion.cs | 24 +- sample/GtkDemo/DemoExpander.cs | 16 +- sample/GtkDemo/DemoHyperText.cs | 176 ++++++------ sample/GtkDemo/DemoImages.cs | 101 +++---- sample/GtkDemo/DemoListStore.cs | 119 ++++---- sample/GtkDemo/DemoMain.cs | 202 +++++++------- sample/GtkDemo/DemoMenus.cs | 135 ++++----- sample/GtkDemo/DemoPanes.cs | 212 ++++++--------- sample/GtkDemo/DemoPixbuf.cs | 162 +++++------ sample/GtkDemo/DemoSizeGroup.cs | 71 ++--- sample/GtkDemo/DemoStockBrowser.cs | 347 +++++++++++------------- sample/GtkDemo/DemoTextView.cs | 314 ++++++++++----------- sample/GtkDemo/DemoTreeStore.cs | 305 ++++++++++----------- sample/GtkDemo/DemoUIManager.cs | 207 +++++++------- sample/GtkDemo/README | 13 +- sample/GtkDemo/TODO | 14 +- 25 files changed, 1608 insertions(+), 1776 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7fe84f67f..deaae30b7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,55 @@ +2005-04-01 Dan Winship + + * samples/GtkDemo/*.cs: General fixup and cleanup; Remove some + gratuitous differences from the C version. Make comment and indent + style consistent. Don't use "this." where not needed. Override + OnDeleteEvent rather than connecting one's own DeleteEvent signal. + + * sample/GtkDemo/DemoApplicationWindow.cs (static + DemoApplicationWindow): register the Gtk logo icon with + StockManager so it shows up correctly in the toolbar. + (AddActions): Register the radio items as radio items so they work + right. + + * sample/GtkDemo/DemoHyperText.cs (EventAfter): handle + link-clicking from Widget.WidgetEventAfter (as in the C version), + rather than ButtonRelease, now that WidgetEventAfter is wrapped. + + * sample/GtkDemo/DemoImages.cs (DemoImages): use + Gtk.Image.LoadFromResource (particularly to make the animation + work right). + (OnDestroyed): handle clean up (remove the timeout, etc) + + * sample/GtkDemo/DemoMain.cs (LoadStream): Fix handling of blank + lines and whitespace to match the C version. + + * sample/GtkDemo/DemoPixbuf.cs (Expose): Use + System.Runtime.InteropServices.Marshal.Copy() to copy + pixbuf.Pixels to pass to DrawRgbImageDithalign, to make this more + like the C version (and probably faster?) + (timeout): Remove the FIXME since it seems to work now + + * sample/GtkDemo/DemoStockBrowser.cs: Simplify a bunch. Use + reflection to get the C# names of the stock icons rather than + trying to correctly re-mangle the ids. Display the Label with the + accelerator underlined. + + * sample/GtkDemo/DemoTextView.cs (AttachWidgets): use + Gtk.Image.LoadFromResource, so the image is properly loaded as an + animation, not a static image. Don't set the combobox's "Active" + property (for consistency with the C version). + (InsertText): Fix miscellaneous differences with the C version. + Remove some leftover cruft from earlier workarounds for gtk# bugs. + + * sample/GtkDemo/DemoTreeStore.cs (AddColumns): Make this more + like the C version so the checkboxes are sensitized and hidden + correctly on a per-row basis. + + * sample/GtkDemo/DemoUIManager.cs: Make the radio menu items work. + + * sample/GtkDemo/README: + * sample/GtkDemo/TODO: update + 2005-04-01 Mike Kestner * gtk/TreeModelFilter.custom : manually implement SetVisibleFunc and diff --git a/sample/GtkDemo/DemoApplicationWindow.cs b/sample/GtkDemo/DemoApplicationWindow.cs index 6dee21e39..690206d9a 100644 --- a/sample/GtkDemo/DemoApplicationWindow.cs +++ b/sample/GtkDemo/DemoApplicationWindow.cs @@ -1,12 +1,3 @@ -// -// ApplicationWindow.cs, port of appwindow.c from gtk-demo -// -// Author: Daniel Kornhauser -// John Luke -// -// Copyright (C) 2003, Ximian Inc. - - /* Application main window * * Demonstrates a typical application window, with menubar, toolbar, statusbar. @@ -15,62 +6,70 @@ using System; using Gtk; -namespace GtkDemo +namespace GtkDemo { [Demo ("Application Window", "DemoApplicationWindow.cs")] public class DemoApplicationWindow : Window { - // for the statusbar - const int ctx = 1; - const string fmt = "Cursor at row {0} column {1} - {2} chars in document"; - int row, column, count = 0; - Statusbar statusbar; VBox vbox; - const string uiInfo = - "" + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - ""; - - public DemoApplicationWindow () : base ("Demo Application Window") + static DemoApplicationWindow () { - this.SetDefaultSize (400, 300); - this.DeleteEvent += new DeleteEventHandler (WindowDelete); + // Register our custom toolbar icons, for themability + + Gdk.Pixbuf pixbuf = Gdk.Pixbuf.LoadFromResource ("gtk-logo-rgb.gif"); + Gdk.Pixbuf transparent = pixbuf.AddAlpha (true, 0xff, 0xff, 0xff); + + IconFactory factory = new IconFactory (); + factory.Add ("demo-gtk-logo", new IconSet (transparent)); + factory.AddDefault (); + + StockManager.Add (new StockItem ("demo-gtk-logo", "_GTK#", 0, 0, null)); + } + + const string uiInfo = + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + public DemoApplicationWindow () : base ("Application Window") + { + SetDefaultSize (200, 200); vbox = new VBox (false, 0); - this.Add (vbox); + Add (vbox); AddActions (); @@ -78,80 +77,129 @@ namespace GtkDemo UpdateStatus (); vbox.PackEnd (statusbar, false, false, 0); - TextView textview = new TextView (); - textview.Buffer.MarkSet += new MarkSetHandler (OnMarkSet); - vbox.PackEnd (textview, true, true, 0); + ScrolledWindow sw = new ScrolledWindow (); + sw.SetPolicy (PolicyType.Automatic, PolicyType.Automatic); + sw.ShadowType = ShadowType.In; + vbox.PackEnd (sw, true, true, 0); - this.ShowAll (); + TextView textview = new TextView (); + textview.Buffer.MarkSet += new MarkSetHandler (MarkSet); + sw.Add (textview); + + textview.GrabFocus (); + + ShowAll (); + } + + enum Color { + Red, + Green, + Blue + } + + enum Shape { + Square, + Rectangle, + Oval } 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)) - }; + { + 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 (ActionActivated)), + new ActionEntry ("Open", Stock.Open, "_Open", "O", "Open a file", new EventHandler (ActionActivated)), + new ActionEntry ("Save", Stock.Save, "_Save", "S", "Save current file", new EventHandler (ActionActivated)), + new ActionEntry ("SaveAs", Stock.SaveAs, "Save _As", null, "Save to a file", new EventHandler (ActionActivated)), + new ActionEntry ("Quit", Stock.Quit, "_Quit", "Q", "Quit", new EventHandler (ActionActivated)), + new ActionEntry ("About", null, "_About", "A", "About", new EventHandler (ActionActivated)), + new ActionEntry ("Logo", "demo-gtk-logo", null, null, "Gtk#", new EventHandler (ActionActivated)) + }; ToggleActionEntry[] toggleActions = new ToggleActionEntry[] - { - new ToggleActionEntry ("Bold", Stock.Bold, "_Bold", "B", "Bold", new EventHandler (OnActionActivated), false) - }; + { + new ToggleActionEntry ("Bold", Stock.Bold, "_Bold", "B", "Bold", new EventHandler (ActionActivated), true) + }; - 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) - }; + RadioActionEntry[] colorActions = new RadioActionEntry[] + { + new RadioActionEntry ("Red", null, "_Red", "R", "Blood", (int)Color.Red), + new RadioActionEntry ("Green", null, "_Green", "G", "Grass", (int)Color.Green), + new RadioActionEntry ("Blue", null, "_Blue", "B", "Sky", (int)Color.Blue) + }; - 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) - }; + RadioActionEntry[] shapeActions = new RadioActionEntry[] + { + new RadioActionEntry ("Square", null, "_Square", "S", "Square", (int)Shape.Square), + new RadioActionEntry ("Rectangle", null, "_Rectangle", "R", "Rectangle", (int)Shape.Rectangle), + new RadioActionEntry ("Oval", null, "_Oval", "O", "Egg", (int)Shape.Oval) + }; - ActionGroup group = new ActionGroup ("group"); + ActionGroup group = new ActionGroup ("AppWindowActions"); group.Add (actions); group.Add (toggleActions); - group.Add (colorActions); - group.Add (shapeActions); + group.Add (colorActions, (int)Color.Red, new ChangedHandler (RadioActionActivated)); + group.Add (shapeActions, (int)Shape.Square, new ChangedHandler (RadioActionActivated)); UIManager uim = new UIManager (); - uim.InsertActionGroup (group, (int) uim.NewMergeId ()); - uim.AddWidget += new AddWidgetHandler (OnAddWidget); + uim.InsertActionGroup (group, 0); + uim.AddWidget += new AddWidgetHandler (AddWidget); uim.AddUiFromString (uiInfo); + + AddAccelGroup (uim.AccelGroup); } - - private void OnActionActivated (object sender, EventArgs a) + + private void ActionActivated (object sender, EventArgs a) { Action action = sender as Action; + MessageDialog md; - using (MessageDialog md = new MessageDialog (this, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Close, "You activated action: {0}", action.Name)) { + md = new MessageDialog (this, DialogFlags.DestroyWithParent, + MessageType.Info, ButtonsType.Close, + "You activated action: \"{0}\" of type \"{1}\"", + action.Name, action.GetType ()); + md.Run (); + md.Destroy (); + } + + private void RadioActionActivated (object sender, ChangedArgs args) + { + RadioAction action = args.Current; + MessageDialog md; + + if (action.Active) { + md = new MessageDialog (this, DialogFlags.DestroyWithParent, + MessageType.Info, ButtonsType.Close, + "You activated radio action: \"{0}\" of type \"{1}\".\nCurrent value: {2}", + action.Name, action.GetType (), + args.Current.Value); md.Run (); - md.Hide (); + md.Destroy (); } } - private void WindowDelete (object o, DeleteEventArgs args) + protected override bool OnDeleteEvent (Gdk.Event evt) { - this.Hide (); - this.Destroy (); - args.RetVal = true; + Destroy (); + return true; } - void OnMarkSet (object o, MarkSetArgs args) + protected override bool OnWindowStateEvent (Gdk.EventWindowState evt) + { + if ((evt.ChangedMask & (Gdk.WindowState.Maximized | Gdk.WindowState.Fullscreen)) != 0) + statusbar.HasResizeGrip = (evt.NewWindowState & (Gdk.WindowState.Maximized | Gdk.WindowState.Fullscreen)) == 0; + return false; + } + + const string fmt = "Cursor at row {0} column {1} - {2} chars in document"; + int row, column, count = 0; + + void MarkSet (object o, MarkSetArgs args) { TextIter iter = args.Location; row = iter.Line + 1; @@ -162,15 +210,14 @@ namespace GtkDemo void UpdateStatus () { - statusbar.Pop (ctx); - statusbar.Push (ctx, String.Format (fmt, row, column, count)); + statusbar.Pop (0); + statusbar.Push (0, String.Format (fmt, row, column, count)); } - void OnAddWidget (object sender, AddWidgetArgs a) + void AddWidget (object sender, AddWidgetArgs a) { a.Widget.Show (); vbox.PackStart (a.Widget, false, true, 0); } } } - diff --git a/sample/GtkDemo/DemoAttribute.cs b/sample/GtkDemo/DemoAttribute.cs index 20a6997ff..f431025e8 100644 --- a/sample/GtkDemo/DemoAttribute.cs +++ b/sample/GtkDemo/DemoAttribute.cs @@ -6,7 +6,7 @@ namespace GtkDemo public class DemoAttribute : Attribute { string label, filename, parent; - + public DemoAttribute (string label, string filename) : this (label, filename, null) { } @@ -27,9 +27,7 @@ namespace GtkDemo } public string Parent { - get { - return parent; - } + get { return parent; } } } } diff --git a/sample/GtkDemo/DemoButtonBox.cs b/sample/GtkDemo/DemoButtonBox.cs index 4c7a02e4e..99b0b7226 100644 --- a/sample/GtkDemo/DemoButtonBox.cs +++ b/sample/GtkDemo/DemoButtonBox.cs @@ -1,11 +1,3 @@ -// -// DemoButtonBox.cs, port of buttonbox.c from gtk-demo -// -// Author: Daniel Kornhauser -// -// Copyright (C) 2003, Ximian Inc. - - /* Button Boxes * * The Button Box widgets are used to arrange buttons with padding. @@ -14,86 +6,77 @@ using System; using Gtk; -namespace GtkDemo +namespace GtkDemo { [Demo ("Button Boxes", "DemoButtonBox.cs")] public class DemoButtonBox : Gtk.Window { public DemoButtonBox () : base ("Button Boxes") { - this.DeleteEvent += new DeleteEventHandler (WindowDelete); - this.BorderWidth = 10; + BorderWidth = 10; // Add Vertical Box VBox mainVbox = new VBox (false,0); - this.Add (mainVbox); + Add (mainVbox); // Add Horizontal Frame Frame horizontalFrame = new Frame ("Horizontal Button Boxes"); - mainVbox.PackStart (horizontalFrame); - VBox vbox = new VBox (false, 0) ; + mainVbox.PackStart (horizontalFrame, true, true, 10); + VBox vbox = new VBox (false, 0); vbox.BorderWidth = 10; horizontalFrame.Add (vbox); // Pack Buttons - vbox.PackStart(CreateButtonBox (true, "Spread (spacing 40)", 40, 85, 20, ButtonBoxStyle.Spread)); - vbox.PackStart(CreateButtonBox (true, "Edge (spacing 30)", 30, 85, 20, ButtonBoxStyle.Edge)); - vbox.PackStart(CreateButtonBox (true, "Start (spacing 20)", 20, 85, 20, ButtonBoxStyle.Start)); - vbox.PackStart(CreateButtonBox (true, "End (spacing 10)", 10, 85, 20, ButtonBoxStyle.End)); + vbox.PackStart (CreateButtonBox (true, "Spread", 40, ButtonBoxStyle.Spread), true, true, 0); + vbox.PackStart (CreateButtonBox (true, "Edge", 40, ButtonBoxStyle.Edge), true, true, 5); + vbox.PackStart (CreateButtonBox (true, "Start", 40, ButtonBoxStyle.Start), true, true, 5); + vbox.PackStart (CreateButtonBox (true, "End", 40, ButtonBoxStyle.End), true, true, 5); - // Add Vertical Frame + // Add Vertical Frame Frame verticalFrame = new Frame ("Vertical Button Boxes"); - mainVbox.PackStart (verticalFrame); + mainVbox.PackStart (verticalFrame, true, true, 10); HBox hbox = new HBox (false, 0); hbox.BorderWidth = 10; verticalFrame.Add (hbox); // Pack Buttons - hbox.PackStart(CreateButtonBox (false, "Spread (spacing 5)", 5, 85, 20, ButtonBoxStyle.Spread)); - hbox.PackStart(CreateButtonBox (false, "Edge (spacing 30)", 30, 85, 20, ButtonBoxStyle.Edge)); - hbox.PackStart(CreateButtonBox (false, "Start (spacing 20)", 20, 85, 20, ButtonBoxStyle.Start)); - hbox.PackStart(CreateButtonBox (false, "End (spacing 20)", 20, 85, 20, ButtonBoxStyle.End)); - - this.ShowAll (); + hbox.PackStart(CreateButtonBox (false, "Spread", 30, ButtonBoxStyle.Spread), true, true, 0); + hbox.PackStart(CreateButtonBox (false, "Edge", 30, ButtonBoxStyle.Edge), true, true, 5); + hbox.PackStart(CreateButtonBox (false, "Start", 30, ButtonBoxStyle.Start), true, true, 5); + hbox.PackStart(CreateButtonBox (false, "End", 30, ButtonBoxStyle.End), true, true, 5); + + ShowAll (); } // Create a Button Box with the specified parameters - private Frame CreateButtonBox (bool horizontal, string title, int spacing, int childW , int childH , ButtonBoxStyle layout) + private Frame CreateButtonBox (bool horizontal, string title, int spacing, ButtonBoxStyle layout) { Frame frame = new Frame (title); Gtk.ButtonBox bbox ; - - if (horizontal == true) - { + + if (horizontal) bbox = new Gtk.HButtonBox (); - } else - { - bbox = new Gtk.VButtonBox (); - } - + bbox = new Gtk.VButtonBox (); + bbox.BorderWidth = 5; frame.Add (bbox); - + // Set the appearance of the Button Box bbox.Layout = layout; - bbox.Spacing= spacing; - - Button buttonOk = new Button (Stock.Ok); - bbox.Add (buttonOk); - Button buttonCancel = new Button (Stock.Cancel); - bbox.Add (buttonCancel); - Button buttonHelp = new Button (Stock.Help); - bbox.Add (buttonHelp); - + bbox.Spacing = spacing; + + bbox.Add (new Button (Stock.Ok)); + bbox.Add (new Button (Stock.Cancel)); + bbox.Add (new Button (Stock.Help)); + return frame; } - private void WindowDelete (object o, DeleteEventArgs args) + protected override bool OnDeleteEvent (Gdk.Event evt) { - this.Hide (); - this.Destroy (); - args.RetVal = true; + Destroy (); + return true; } } } diff --git a/sample/GtkDemo/DemoClipboard.cs b/sample/GtkDemo/DemoClipboard.cs index 076168f0a..2936a70e2 100644 --- a/sample/GtkDemo/DemoClipboard.cs +++ b/sample/GtkDemo/DemoClipboard.cs @@ -2,11 +2,14 @@ * * GtkClipboard is used for clipboard handling. This demo shows how to * copy and paste text to and from the clipboard. + * + * This is actually from gtk+ 2.6's gtk-demo, but doesn't use any 2.6 + * functionality */ using System; using Gtk; -namespace GtkDemo +namespace GtkDemo { [Demo ("Clipboard", "DemoClipboard.cs")] public class DemoClipboard : Gtk.Window @@ -15,8 +18,6 @@ namespace GtkDemo public DemoClipboard () : base ("Demo Clipboard") { - this.DeleteEvent += new DeleteEventHandler (OnDelete); - VBox vbox = new VBox (); vbox.BorderWidth = 8; Label copyLabel = new Label ("\"Copy\" will copy the text\nin the entry to the clipboard"); @@ -26,9 +27,9 @@ namespace GtkDemo Label pasteLabel = new Label ("\"Paste\" will paste the text from the clipboard to the entry"); vbox.PackStart (pasteLabel, false, false, 0); vbox.PackStart (CreatePasteBox (), false, false, 0); - - this.Add (vbox); - this.ShowAll (); + + Add (vbox); + ShowAll (); } HBox CreateCopyBox () @@ -37,7 +38,7 @@ namespace GtkDemo hbox.BorderWidth = 8; copyEntry = new Entry (); Button copyButton = new Button (Stock.Copy); - copyButton.Clicked += new EventHandler (OnCopyClicked); + copyButton.Clicked += new EventHandler (CopyClicked); hbox.PackStart (copyEntry, true, true, 0); hbox.PackStart (copyButton, false, false, 0); return hbox; @@ -49,30 +50,33 @@ namespace GtkDemo hbox.BorderWidth = 8; pasteEntry = new Entry (); Button pasteButton = new Button (Stock.Paste); - pasteButton.Clicked += new EventHandler (OnPasteClicked); + pasteButton.Clicked += new EventHandler (PasteClicked); hbox.PackStart (pasteEntry, true, true, 0); hbox.PackStart (pasteButton, false, false, 0); return hbox; } - void OnCopyClicked (object sender, EventArgs a) + void CopyClicked (object obj, EventArgs args) { Clipboard clipboard = copyEntry.GetClipboard (Gdk.Selection.Clipboard); clipboard.SetText (copyEntry.Text); } - void OnPasteClicked (object sender, EventArgs a) + void PasteClicked (object obj, EventArgs args) { Clipboard clipboard = pasteEntry.GetClipboard (Gdk.Selection.Clipboard); - pasteEntry.Text = clipboard.WaitForText (); + clipboard.RequestText (new ClipboardTextReceivedFunc (PasteReceived)); } - void OnDelete (object sender, DeleteEventArgs a) + void PasteReceived (Clipboard clipboard, string text) { - this.Hide (); - this.Destroy (); - a.RetVal = true; + pasteEntry.Text = text; + } + + protected override bool OnDeleteEvent (Gdk.Event evt) + { + Destroy (); + return true; } } } - diff --git a/sample/GtkDemo/DemoColorSelection.cs b/sample/GtkDemo/DemoColorSelection.cs index 6d451d48e..1e8b90c87 100644 --- a/sample/GtkDemo/DemoColorSelection.cs +++ b/sample/GtkDemo/DemoColorSelection.cs @@ -1,10 +1,3 @@ -// -// DemoColorSelection.cs, port of colorsel.c from gtk-demo -// -// Author: Daniel Kornhauser -// -// Copyright (C) 2003, Ximian Inc. - /* Color Selector * * GtkColorSelection lets the user choose a color. GtkColorSelectionDialog is @@ -16,7 +9,7 @@ using System; using Gdk; using Gtk; -namespace GtkDemo +namespace GtkDemo { [Demo ("Color Selection", "DemoColorSelection.cs")] public class DemoColorSelection : Gtk.Window @@ -26,11 +19,10 @@ namespace GtkDemo public DemoColorSelection () : base ("Color Selection") { - this.DeleteEvent += new DeleteEventHandler (WindowDelete); - this.BorderWidth = 8; + BorderWidth = 8; VBox vbox = new VBox (false,8); vbox.BorderWidth = 8; - this.Add (vbox); + Add (vbox); // Create the color swatch area Frame frame = new Frame (); @@ -52,17 +44,16 @@ namespace GtkDemo alignment.Add (button); vbox.PackStart (alignment); - this.ShowAll (); - } - - private void WindowDelete (object o, DeleteEventArgs args) - { - this.Hide (); - this.Destroy (); - args.RetVal = true; + ShowAll (); } - - // Expose callback for the drawing area + + protected override bool OnDeleteEvent (Gdk.Event evt) + { + Destroy (); + return true; + } + + // Expose callback for the drawing area private void ExposeEventCallback (object o, ExposeEventArgs args) { EventExpose eventExpose = args.Event; @@ -70,22 +61,21 @@ namespace GtkDemo Rectangle area = eventExpose.Area; window.DrawRectangle (drawingArea.Style.BackgroundGC (StateType.Normal), - true, - area.X, area.Y, - area.Width, area.Height); + true, + area.X, area.Y, + area.Width, area.Height); args.RetVal = true; } - + private void ChangeColorCallback (object o, EventArgs args) { using (ColorSelectionDialog colorSelectionDialog = new ColorSelectionDialog ("Changing color")) { colorSelectionDialog.TransientFor = this; colorSelectionDialog.ColorSelection.PreviousColor = color; colorSelectionDialog.ColorSelection.CurrentColor = color; - colorSelectionDialog.ColorSelection.HasPalette = true; + colorSelectionDialog.ColorSelection.HasPalette = true; - if (colorSelectionDialog.Run () == (int) ResponseType.Ok) - { + if (colorSelectionDialog.Run () == (int) ResponseType.Ok) { Gdk.Color selected = colorSelectionDialog.ColorSelection.CurrentColor; drawingArea.ModifyBg (StateType.Normal, selected); } diff --git a/sample/GtkDemo/DemoDialog.cs b/sample/GtkDemo/DemoDialog.cs index e7114897c..3bc74bb27 100644 --- a/sample/GtkDemo/DemoDialog.cs +++ b/sample/GtkDemo/DemoDialog.cs @@ -1,10 +1,3 @@ -// -// DemoDialog.cs, port of dialog.c from gtk-demo -// -// Author Daniel Kornhauser -// -// Copyright (C) 2003, Ximian Inc. - /* Dialog and Message Boxes * * Dialog widgets are used to pop up a transient window for user feedback. @@ -13,7 +6,7 @@ using System; using Gtk; -namespace GtkDemo +namespace GtkDemo { [Demo ("Dialog and Message Boxes", "DemoDialog.cs")] public class DemoDialog : Gtk.Window @@ -23,23 +16,22 @@ namespace GtkDemo public DemoDialog () : base ("Dialogs") { - this.DeleteEvent += new DeleteEventHandler(WindowDelete); - this.BorderWidth = 8; + BorderWidth = 8; Frame frame = new Frame ("Dialogs"); - this.Add (frame); + Add (frame); VBox vbox = new VBox (false, 8); vbox.BorderWidth = 8; frame.Add (vbox); - // Standard message dialog + // Standard message dialog HBox hbox = new HBox (false,8); vbox.PackStart (hbox, false, false, 0); Button button = new Button ("_Message Dialog"); button.Clicked += new EventHandler (MessageDialogClicked); hbox.PackStart (button, false, false, 0); - vbox.PackStart (new HSeparator()); + vbox.PackStart (new HSeparator(), false, false, 0); // Interactive dialog hbox = new HBox (false, 8); @@ -54,39 +46,38 @@ namespace GtkDemo Table table = new Table (2, 2, false); table.RowSpacing = 4; table.ColumnSpacing = 4; - hbox.PackStart (table); + hbox.PackStart (table, false, false, 0); Label label = new Label ("_Entry1"); table.Attach (label, 0, 1, 0, 1); entry1 = new Entry (); table.Attach (entry1, 1, 2, 0, 1); label.MnemonicWidget = entry1; - + label = new Label ("E_ntry2"); table.Attach (label,0,1,1,2); entry2 = new Entry (); table.Attach (entry2, 1, 2, 1, 2); - label.MnemonicWidget = entry2; - - this.ShowAll (); + label.MnemonicWidget = entry2; + + ShowAll (); } - private void WindowDelete (object o, DeleteEventArgs args) + protected override bool OnDeleteEvent (Gdk.Event evt) { - this.Hide (); - this.Destroy (); - args.RetVal = true; + Destroy (); + return true; } private int i = 1; private void MessageDialogClicked (object o, EventArgs args) { - using (Dialog dialog = new MessageDialog (this, - DialogFlags.Modal | DialogFlags.DestroyWithParent, - MessageType.Info, - ButtonsType.Ok, - "This message box has been popped up the following\n number of times:\n\n {0:D} ", - i)) { + using (Dialog dialog = new MessageDialog (this, + DialogFlags.Modal | DialogFlags.DestroyWithParent, + MessageType.Info, + ButtonsType.Ok, + "This message box has been popped up the following\nnumber of times:\n\n {0}", + i)) { dialog.Run (); dialog.Hide (); } @@ -96,42 +87,47 @@ namespace GtkDemo private void InteractiveDialogClicked (object o, EventArgs args) { - Dialog dialog = new Dialog ("Interactive Dialog", this, DialogFlags.Modal | DialogFlags.DestroyWithParent, Gtk.Stock.Ok, ResponseType.Ok, "_Non-stock Button", ResponseType.Cancel); + Dialog dialog = new Dialog ("Interactive Dialog", this, + DialogFlags.Modal | DialogFlags.DestroyWithParent, + Gtk.Stock.Ok, ResponseType.Ok, + "_Non-stock Button", ResponseType.Cancel); HBox hbox = new HBox (false, 8); hbox.BorderWidth = 8; dialog.VBox.PackStart (hbox, false, false, 0); + Image stock = new Image (Stock.DialogQuestion, IconSize.Dialog); + hbox.PackStart (stock, false, false, 0); + Table table = new Table (2, 2, false); table.RowSpacing = 4; table.ColumnSpacing = 4; - hbox.PackStart (table, false, false, 0); + hbox.PackStart (table, true, true, 0); Label label = new Label ("_Entry1"); table.Attach (label, 0, 1, 0, 1); - Entry localEntry1 = new Entry(); + Entry localEntry1 = new Entry (); localEntry1.Text = entry1.Text; table.Attach (localEntry1, 1, 2, 0, 1); label.MnemonicWidget = localEntry1; label = new Label ("E_ntry2"); table.Attach (label, 0, 1, 1, 2); - Entry localEntry2 = new Entry(); + Entry localEntry2 = new Entry (); localEntry2.Text = entry2.Text; table.Attach (localEntry2, 1, 2, 1, 2); label.MnemonicWidget = localEntry2; - + hbox.ShowAll (); - + ResponseType response = (ResponseType) dialog.Run (); if (response == ResponseType.Ok) { entry1.Text = localEntry1.Text; entry2.Text = localEntry2.Text; - } - + } + dialog.Destroy (); } - } + } } - diff --git a/sample/GtkDemo/DemoDrawingArea.cs b/sample/GtkDemo/DemoDrawingArea.cs index d25818986..ea7721274 100644 --- a/sample/GtkDemo/DemoDrawingArea.cs +++ b/sample/GtkDemo/DemoDrawingArea.cs @@ -1,12 +1,3 @@ -// -// DemoDrawingArea.cs, port of drawingarea.c from gtk-demo -// -// Author: Daniel Kornhauser -// Rachel Hestilow -// -// Copyright (C) 2003, Ximian Inc. -// - /* Drawing Area * * GtkDrawingArea is a blank area where you can draw custom displays @@ -31,213 +22,196 @@ namespace GtkDemo [Demo ("Drawing Area", "DemoDrawingArea.cs")] public class DemoDrawingArea : Gtk.Window { - private static Pixmap pixmap = null; - private static DrawingArea drawingArea; - private static DrawingArea drawingArea1; + private Pixmap pixmap = null; public DemoDrawingArea () : base ("Drawing Area") { - this.DeleteEvent += new DeleteEventHandler (WindowDelete); - this.BorderWidth = 8; - + BorderWidth = 8; + VBox vbox = new VBox (false, 8); vbox.BorderWidth = 8; - this.Add (vbox); - + Add (vbox); + // Create the checkerboard area - Label label = new Label (); - label.Markup = "Checkerboard pattern"; + Label label = new Label ("Checkerboard pattern"); + label.UseMarkup = true; vbox.PackStart (label, false, false, 0); - + Frame frame = new Frame (); frame.ShadowType = ShadowType.In; vbox.PackStart (frame, true, true, 0); - drawingArea = new DrawingArea (); + DrawingArea da = new DrawingArea (); // set a minimum size - drawingArea.SetSizeRequest (100,100); - frame.Add (drawingArea); - drawingArea.ExposeEvent += new ExposeEventHandler (CheckerboardExpose); + da.SetSizeRequest (100,100); + frame.Add (da); + da.ExposeEvent += new ExposeEventHandler (CheckerboardExpose); // Create the scribble area - Label label1 = new Label ("Scribble area"); - label1.UseMarkup = true; - vbox.PackStart (label1, false, false, 0); - - Frame frame1 = new Frame (); - frame1.ShadowType = ShadowType.In; - vbox.PackStart (frame1, true, true, 0); + label = new Label ("Scribble area"); + label.UseMarkup = true; + vbox.PackStart (label, false, false, 0); + + frame = new Frame (); + frame.ShadowType = ShadowType.In; + vbox.PackStart (frame, true, true, 0); + + da = new DrawingArea (); + // set a minimum size + da.SetSizeRequest (100, 100); + frame.Add (da); - drawingArea1 = new DrawingArea (); - // set a minimun size - drawingArea1.SetSizeRequest (100, 100); - frame1.Add (drawingArea1); // Signals used to handle backing pixmap - drawingArea1.ExposeEvent += new ExposeEventHandler (ScribbleExpose); - drawingArea1.ConfigureEvent += new ConfigureEventHandler (ScribbleConfigure); + da.ExposeEvent += new ExposeEventHandler (ScribbleExpose); + da.ConfigureEvent += new ConfigureEventHandler (ScribbleConfigure); + // Event signals - drawingArea1.MotionNotifyEvent += new MotionNotifyEventHandler (ScribbleMotionNotify); - drawingArea1.ButtonPressEvent += new ButtonPressEventHandler (ScribbleButtonPress); + da.MotionNotifyEvent += new MotionNotifyEventHandler (ScribbleMotionNotify); + da.ButtonPressEvent += new ButtonPressEventHandler (ScribbleButtonPress); + // Ask to receive events the drawing area doesn't normally // subscribe to + da.Events |= EventMask.LeaveNotifyMask | EventMask.ButtonPressMask | + EventMask.PointerMotionMask | EventMask.PointerMotionHintMask; - drawingArea1.Events = EventMask.LeaveNotifyMask | EventMask.ButtonPressMask | - EventMask.PointerMotionMask | EventMask.PointerMotionHintMask; - - this.ShowAll (); + ShowAll (); } - - private void WindowDelete (object o, DeleteEventArgs args) + + protected override bool OnDeleteEvent (Gdk.Event evt) { - this.Hide (); - this.Destroy (); - args.RetVal = true; + Destroy (); + return true; } - - private void CheckerboardExpose (object o, ExposeEventArgs args) - { - // Defining the size of the Checks + private void CheckerboardExpose (object o, ExposeEventArgs args) + { const int CheckSize = 10; const int Spacing = 2; - // Defining the color of the Checks + DrawingArea da = o as DrawingArea; + + // It would be a bit more efficient to keep these + // GC's around instead of recreating on each expose, but + // this is the lazy/slow way. + Gdk.GC gc1 = new Gdk.GC (da.GdkWindow); + gc1.RgbFgColor = new Gdk.Color (117, 0, 117); + + Gdk.GC gc2 = new Gdk.GC (da.GdkWindow); + gc2.RgbFgColor = new Gdk.Color (255, 255, 255); + int i, j, xcount, ycount; - Gdk.GC gc, gc1, gc2; - Gdk.Color color = new Gdk.Color (); - EventExpose eventExpose = args.Event; - Gdk.Window window = eventExpose.Window; - gc1 = new Gdk.GC (window); + Gdk.Rectangle alloc = da.Allocation; - color.Red = 30000; - color.Green = 0; - color.Blue = 30000; - gc1.RgbFgColor = color; - - gc2 = new Gdk.GC (window); - color.Red = 65535; - color.Green = 65535; - color.Blue = 65535; - gc2.RgbFgColor = color; - - // Start redrawing the Checkerboard + // Start redrawing the Checkerboard xcount = 0; i = Spacing; - while (i < drawingArea.Allocation.Width){ + while (i < alloc.Width) { j = Spacing; - ycount = xcount % 2; //start with even/odd depending on row - while (j < drawingArea.Allocation.Height){ - gc = new Gdk.GC (window); - if (ycount % 2 != 0){ - gc = gc1;} - else{ - gc = gc2;} - window.DrawRectangle(gc, true, i, j, CheckSize, CheckSize); - + ycount = xcount % 2; // start with even/odd depending on row + while (j < alloc.Height) { + Gdk.GC gc; + if (ycount % 2 != 0) + gc = gc1; + else + gc = gc2; + da.GdkWindow.DrawRectangle (gc, true, i, j, + CheckSize, CheckSize); + j += CheckSize + Spacing; ++ycount; } i += CheckSize + Spacing; ++xcount; } + // return true because we've handled this event, so no // further processing is required. args.RetVal = true; } - + private void ScribbleExpose (object o, ExposeEventArgs args) { + Widget widget = o as Widget; + Gdk.Window window = widget.GdkWindow; + Rectangle area = args.Event.Area; + // We use the "ForegroundGC" for the widget since it already exists, // but honestly any GC would work. The only thing to worry about // is whether the GC has an inappropriate clip region set. - - EventExpose eventExpose = args.Event; - Gdk.Window window = eventExpose.Window; - Rectangle area = eventExpose.Area; - - window.DrawDrawable (drawingArea1.Style.ForegroundGC(StateType.Normal), - pixmap, - area.X, area.Y, - area.X, area.Y, - area.Width, area.Height); - args.RetVal = false; + window.DrawDrawable (widget.Style.ForegroundGC (StateType.Normal), + pixmap, + area.X, area.Y, + area.X, area.Y, + area.Width, area.Height); } - - // Create a new pixmap of the appropriate size to store our scribbles + + // Create a new pixmap of the appropriate size to store our scribbles private void ScribbleConfigure (object o, ConfigureEventArgs args) { - EventConfigure eventConfigure = args.Event; - Gdk.Window window = eventConfigure.Window; - Rectangle allocation = drawingArea1.Allocation; - pixmap = new Pixmap (window, - allocation.Width, - allocation.Height, - -1); + Widget widget = o as Widget; + Rectangle allocation = widget.Allocation; + + pixmap = new Pixmap (widget.GdkWindow, allocation.Width, allocation.Height, -1); + // Initialize the pixmap to white - pixmap.DrawRectangle (drawingArea1.Style.WhiteGC, true, 0, 0, - allocation.Width, allocation.Height); + pixmap.DrawRectangle (widget.Style.WhiteGC, true, 0, 0, + allocation.Width, allocation.Height); + // We've handled the configure event, no need for further processing. args.RetVal = true; } - + private void ScribbleMotionNotify (object o, MotionNotifyEventArgs args) { + // paranoia check, in case we haven't gotten a configure event + if (pixmap == null) + return; + // This call is very important; it requests the next motion event. - // If you don't call Window.GetPointer() you'll only get - // a single motion event. The reason is that we specified - // PointerMotionHintMask in drawingArea1.Events. - // If we hadn't specified that, we could just use ExposeEvent.x, ExposeEvent.y - // as the pointer location. But we'd also get deluged in events. - // By requesting the next event as we handle the current one, - // we avoid getting a huge number of events faster than we - // can cope. + // If you don't call Window.GetPointer() you'll only get a single + // motion event. The reason is that we specified PointerMotionHintMask + // in widget.Events. If we hadn't specified that, we could just use + // args.Event.X, args.Event.Y as the pointer location. But we'd also + // get deluged in events. By requesting the next event as we handle + // the current one, we avoid getting a huge number of events faster + // than we can cope. int x, y; ModifierType state; - EventMotion ev = args.Event; - Gdk.Window window = ev.Window; + args.Event.Window.GetPointer (out x, out y, out state); - if (ev.IsHint) { - ModifierType s; - window.GetPointer (out x, out y, out s); - state = s; - } else { - x = (int) ev.X; - y = (int) ev.Y; - state = (ModifierType) ev.State; - } + if ((state & ModifierType.Button1Mask) != 0) + DrawBrush (o as Widget, x, y); - if ((state & ModifierType.Button1Mask) != 0 && pixmap != null) - DrawBrush (x, y); // We've handled it, stop processing args.RetVal = true; } // Draw a rectangle on the screen - static void DrawBrush (double x, double y) + private void DrawBrush (Widget widget, double x, double y) { - Rectangle update_rect = new Rectangle (); - update_rect.X = (int) x - 3; - update_rect.Y = (int) y - 3; - update_rect.Width = 6; - update_rect.Height = 6; + Rectangle update_rect = new Rectangle ((int)x - 3, (int)y - 3, 6, 6); - //Paint to the pixmap, where we store our state - pixmap.DrawRectangle (drawingArea1.Style.BlackGC, true, - update_rect.X, update_rect.Y, - update_rect.Width, update_rect.Height); - drawingArea1.QueueDrawArea (update_rect.X, update_rect.Y, - update_rect.Width, update_rect.Height); + // Paint to the pixmap, where we store our state + pixmap.DrawRectangle (widget.Style.BlackGC, true, + update_rect.X, update_rect.Y, + update_rect.Width, update_rect.Height); + widget.GdkWindow.InvalidateRect (update_rect, false); } - + private void ScribbleButtonPress (object o, ButtonPressEventArgs args) { + // paranoia check, in case we haven't gotten a configure event + if (pixmap == null) + return; + EventButton ev = args.Event; - if (ev.Button == 1 && pixmap != null) - DrawBrush (ev.X, ev.Y); - //We've handled the event, stop processing + if (ev.Button == 1) + DrawBrush (o as Widget, ev.X, ev.Y); + + // We've handled the event, stop processing args.RetVal = true; } } diff --git a/sample/GtkDemo/DemoEditableCells.cs b/sample/GtkDemo/DemoEditableCells.cs index 815eea1c2..df88ee485 100644 --- a/sample/GtkDemo/DemoEditableCells.cs +++ b/sample/GtkDemo/DemoEditableCells.cs @@ -1,11 +1,3 @@ -// -// DemoEditableCells.cs, port of appwindow.c from gtk-demo -// -// Author: Daniel Kornhauser -// -// Copyright (C) 2003, Ximian Inc. - - /* Tree View/Editable Cells * * This demo demonstrates the use of editable cells in a Gtk.TreeView. If @@ -18,7 +10,7 @@ using System; using System.Collections; using Gtk; -namespace GtkDemo +namespace GtkDemo { [Demo ("Editable Cells", "DemoEditableCells.cs", "Tree View")] public class DemoEditableCells : Gtk.Window @@ -27,25 +19,29 @@ namespace GtkDemo private TreeView treeView; private ArrayList articles; - public DemoEditableCells () : base ("Color Selection") + public DemoEditableCells () : base ("Shopping list") { - this.SetDefaultSize (320, 200); - this.DeleteEvent += new DeleteEventHandler (WindowDelete); + SetDefaultSize (320, 200); + BorderWidth = 5; VBox vbox = new VBox (false, 5); - this.Add (vbox); - + Add (vbox); + vbox.PackStart (new Label ("Shopping list (you can edit the cells!)"), false, false, 0); - - ScrolledWindow scrolledWindow = new ScrolledWindow (null, null); - scrolledWindow.ShadowType = ShadowType.In; + + ScrolledWindow scrolledWindow = new ScrolledWindow (); + scrolledWindow.ShadowType = ShadowType.EtchedIn; scrolledWindow.SetPolicy (PolicyType.Automatic, PolicyType.Automatic); - vbox.PackStart (scrolledWindow); + vbox.PackStart (scrolledWindow, true, true, 0); + + // create model + store = CreateModel (); // create tree view - treeView = new TreeView (); - CreateModel (); - treeView.Model = store ; + treeView = new TreeView (store); + treeView.RulesHint = true; + treeView.Selection.Mode = SelectionMode.Single; + AddColumns (); scrolledWindow.Add (treeView); @@ -61,107 +57,106 @@ namespace GtkDemo button.Clicked += new EventHandler (RemoveItem); hbox.PackStart (button, true, true, 0); - this.ShowAll (); + ShowAll (); } - + private void AddColumns () { CellRendererText renderer; - + + // number column renderer = new CellRendererText (); renderer.Edited += new EditedHandler (NumberCellEdited); renderer.Editable = true; - // renderer.Data ("column", (int) Column.Number); - treeView.AppendColumn ("Number", renderer, - "text", (int) Column.Number); - + treeView.AppendColumn ("Number", renderer, + "text", (int) Column.Number); + // product column renderer = new CellRendererText (); renderer.Edited += new EditedHandler (TextCellEdited); renderer.Editable = true; - // renderer.Data ("column", (int) Column.Product); treeView.AppendColumn ("Product", renderer , - "text", (int) Column.Product); + "text", (int) Column.Product); } - private void CreateModel () + private ListStore CreateModel () { // create array articles = new ArrayList (); AddItems (); + // create list store - store = new ListStore (typeof (int), typeof (string), typeof (bool)); - + ListStore store = new ListStore (typeof (int), typeof (string), typeof (bool)); + // add items foreach (Item item in articles) - store.AppendValues (item.Number, item.Product, item.Editable); + store.AppendValues (item.Number, item.Product); + + return store; } private void AddItems () { Item foo; - foo = new Item (3, "bottles of coke", true); + foo = new Item (3, "bottles of coke"); articles.Add (foo); - foo = new Item (5, "packages of noodles", true); + foo = new Item (5, "packages of noodles"); articles.Add (foo); - foo = new Item (2, "packages of chocolate chip cookies", true); + foo = new Item (2, "packages of chocolate chip cookies"); articles.Add (foo); - foo = new Item (1, "can of vanilla ice cream", true); + foo = new Item (1, "can vanilla ice cream"); articles.Add (foo); - foo = new Item (6, "eggs", true); + foo = new Item (6, "eggs"); articles.Add (foo); } - - private void WindowDelete (object o, DeleteEventArgs args) + + protected override bool OnDeleteEvent (Gdk.Event evt) { - this.Hide (); - this.Destroy (); - args.RetVal = true; + Destroy (); + return true; } private void NumberCellEdited (object o, EditedArgs args) { - int i; - Item foo; + TreePath path = new TreePath (args.Path); + TreeIter iter; + store.GetIter (out iter, path); + int i = path.Indices[0]; - try - { - i = Convert.ToInt32 (args.Path); + Item foo; + try { foo = (Item) articles[i]; foo.Number = int.Parse (args.NewText); - } - catch (Exception e) - { - Console.WriteLine (e.ToString ()); + } catch (Exception e) { + Console.WriteLine (e); return; } - TreeIter iter; - store.GetIterFromString (out iter, args.Path); store.SetValue (iter, (int) Column.Number, foo.Number); } - private void TextCellEdited (object o, EditedArgs args) { - int i = int.Parse (args.Path); + TreePath path = new TreePath (args.Path); + TreeIter iter; + store.GetIter (out iter, path); + int i = path.Indices[0]; + Item foo = (Item) articles[i]; foo.Product = args.NewText; - TreeIter iter; - store.GetIterFromString (out iter, args.Path); store.SetValue (iter, (int) Column.Product, foo.Product); } private void AddItem (object o, EventArgs args) { - Item foo = new Item (0, "Description here", true); + Item foo = new Item (0, "Description here"); articles.Add (foo); - store.AppendValues (foo.Number, foo.Product, foo.Editable); + store.AppendValues (foo.Number, foo.Product); } private void RemoveItem (object o, EventArgs args) @@ -169,47 +164,38 @@ namespace GtkDemo TreeIter iter; TreeModel model; - if (treeView.Selection.GetSelected (out model, out iter)) - { - int position = int.Parse (store.GetPath (iter).ToString ()); + if (treeView.Selection.GetSelected (out model, out iter)) { + int position = store.GetPath (iter).Indices[0]; store.Remove (ref iter); articles.RemoveAt (position); } } } - - public enum Column + + enum Column { Number, - Product, - Editable, + Product }; - - public struct Item + + struct Item { public int Number { - get {return NumberItem;} - set {NumberItem = value;} + get { return number; } + set { number = value; } } public string Product { - get {return ProductItem;} - set {ProductItem = value;} - } - - public bool Editable { - get {return EditableItem;} - set {EditableItem = value;} + get { return product; } + set { product = value; } } - private int NumberItem; - private string ProductItem; - private bool EditableItem; + private int number; + private string product; - public Item (int number, string product, bool editable) + public Item (int number, string product) { - NumberItem = number; - ProductItem = product; - EditableItem = editable; + this.number = number; + this.product = product; } } } diff --git a/sample/GtkDemo/DemoEntryCompletion.cs b/sample/GtkDemo/DemoEntryCompletion.cs index 356a6ba8e..65cee5e52 100644 --- a/sample/GtkDemo/DemoEntryCompletion.cs +++ b/sample/GtkDemo/DemoEntryCompletion.cs @@ -7,32 +7,35 @@ using System; using Gtk; -namespace GtkDemo +namespace GtkDemo { [Demo ("Entry Completion", "DemoEntryCompletion.cs")] public class DemoEntryCompletion : Dialog { public DemoEntryCompletion () : base ("Demo Entry Completion", null, DialogFlags.DestroyWithParent) { - this.BorderWidth = 10; - this.Resizable = false; + Resizable = false; + + VBox vbox = new VBox (false, 5); + vbox.BorderWidth = 5; + this.VBox.PackStart (vbox, true, true, 0); Label label = new Label ("Completion demo, try writing total or gnome for example."); label.UseMarkup = true; - this.VBox.PackStart (label, false, true, 0); + vbox.PackStart (label, false, true, 0); Entry entry = new Entry (); + vbox.PackStart (entry, false, true, 0); + entry.Completion = new EntryCompletion (); entry.Completion.Model = CreateCompletionModel (); entry.Completion.TextColumn = 0; - this.VBox.PackStart (entry, false, true, 0); - this.AddButton (Stock.Close, ResponseType.Close); + AddButton (Stock.Close, ResponseType.Close); - this.ShowAll (); - this.Run (); - this.Hide (); - this.Destroy (); + ShowAll (); + Run (); + Destroy (); } TreeModel CreateCompletionModel () @@ -47,4 +50,3 @@ namespace GtkDemo } } } - diff --git a/sample/GtkDemo/DemoExpander.cs b/sample/GtkDemo/DemoExpander.cs index 4f7b8e9f7..192b369fd 100644 --- a/sample/GtkDemo/DemoExpander.cs +++ b/sample/GtkDemo/DemoExpander.cs @@ -7,18 +7,19 @@ using System; using Gtk; -namespace GtkDemo +namespace GtkDemo { [Demo ("Expander", "DemoExpander.cs")] public class DemoExpander : Gtk.Dialog { public DemoExpander () : base ("Demo Expander", null, DialogFlags.DestroyWithParent) { - this.Resizable = false; - this.BorderWidth = 10; + Resizable = false; + VBox vbox = new VBox (false, 5); this.VBox.PackStart (vbox, true, true, 0); vbox.BorderWidth = 5; + vbox.PackStart (new Label ("Expander demo. Click on the triangle for details."), false, false, 0); // Create the expander @@ -26,12 +27,11 @@ namespace GtkDemo expander.Add (new Label ("Details can be shown or hidden.")); vbox.PackStart (expander, false, false, 0); - this.AddButton (Stock.Close, ResponseType.Close); + AddButton (Stock.Close, ResponseType.Close); - this.ShowAll (); - this.Run (); - this.Hide (); - this.Destroy (); + ShowAll (); + Run (); + Destroy (); } } } diff --git a/sample/GtkDemo/DemoHyperText.cs b/sample/GtkDemo/DemoHyperText.cs index 20bcddd38..656f4de29 100644 --- a/sample/GtkDemo/DemoHyperText.cs +++ b/sample/GtkDemo/DemoHyperText.cs @@ -1,14 +1,8 @@ -// -// Author: John Luke -// ported from gtk-demo in GTK+ -// Demonstrates HyperLinks in the TextView -// - /* Text Widget/Hypertext * - * Usually, tags modify the appearance of text in the view, e.g. making it - * bold or colored or underlined. But tags are not restricted to appearance. - * They can also affect the behavior of mouse and key presses, as this demo + * Usually, tags modify the appearance of text in the view, e.g. making it + * bold or colored or underlined. But tags are not restricted to appearance. + * They can also affect the behavior of mouse and key presses, as this demo * shows. */ @@ -20,44 +14,30 @@ namespace GtkDemo [Demo ("Hyper Text", "DemoHyperText.cs", "Text Widget")] public class DemoHyperText : Gtk.Window { - // FIXME: useless counter - int uid = 0; bool hoveringOverLink = false; Gdk.Cursor handCursor, regularCursor; public DemoHyperText () : base ("HyperText") - { - this.DeleteEvent += new DeleteEventHandler (OnWindowDelete); - this.SetDefaultSize (450, 450); - CreateCursors (); - this.Add (CreateScrolledWindow ()); - this.ShowAll (); - } - - void CreateCursors () { handCursor = new Gdk.Cursor (Gdk.CursorType.Hand2); regularCursor = new Gdk.Cursor (Gdk.CursorType.Xterm); - } - ScrolledWindow CreateScrolledWindow () - { - ScrolledWindow sw = new ScrolledWindow (); - sw.Add (CreateTextView ()); - return sw; - } + SetDefaultSize (450, 450); - TextView CreateTextView () - { TextView view = new TextView (); view.WrapMode = WrapMode.Word; - view.KeyPressEvent += new KeyPressEventHandler (OnKeyPress); - view.MotionNotifyEvent += new MotionNotifyEventHandler (OnMotionNotify); - view.VisibilityNotifyEvent += new VisibilityNotifyEventHandler (OnVisibilityNotify); - view.ButtonReleaseEvent += new ButtonReleaseEventHandler (OnButtonRelease); + view.KeyPressEvent += new KeyPressEventHandler (KeyPress); + view.WidgetEventAfter += new WidgetEventAfterHandler (EventAfter); + view.MotionNotifyEvent += new MotionNotifyEventHandler (MotionNotify); + view.VisibilityNotifyEvent += new VisibilityNotifyEventHandler (VisibilityNotify); + + ScrolledWindow sw = new ScrolledWindow (); + sw.SetPolicy (Gtk.PolicyType.Automatic, Gtk.PolicyType.Automatic); + Add (sw); + sw.Add (view); ShowPage (view.Buffer, 1); - return view; + ShowAll (); } // Inserts a piece of text into the buffer, giving it the usual @@ -66,7 +46,7 @@ namespace GtkDemo // as a link. void InsertLink (TextBuffer buffer, ref TextIter iter, string text, int page) { - TextTag tag = new TextTag ("link" + uid++); + TextTag tag = new TextTag (null); tag.Foreground = "blue"; tag.Underline = Pango.Underline.Single; tag.PersistentData.Add ("page", page); @@ -79,29 +59,24 @@ namespace GtkDemo void ShowPage (TextBuffer buffer, int page) { buffer.Text = ""; - TextIter iter = buffer.GetIterAtOffset (0); + TextIter iter = buffer.StartIter; - if (page == 1) - { + if (page == 1) { buffer.Insert (ref iter, "Some text to show that simple "); InsertLink (buffer, ref iter, "hypertext", 3); buffer.Insert (ref iter, " can easily be realized with "); InsertLink (buffer, ref iter, "tags", 2); buffer.Insert (ref iter, "."); - } - else if (page == 2) - { - buffer.Insert (ref iter, - "A tag is an attribute that can be applied to some range of text. " + - "For example, a tag might be called \"bold\" and make the text inside " + - "the tag bold. However, the tag concept is more general than that; " + - "tags don't have to affect appearance. They can instead affect the " + - "behavior of mouse and key presses, \"lock\" a range of text so the " + - "user can't edit it, or countless other things.\n"); + } else if (page == 2) { + buffer.Insert (ref iter, + "A tag is an attribute that can be applied to some range of text. " + + "For example, a tag might be called \"bold\" and make the text inside " + + "the tag bold. However, the tag concept is more general than that; " + + "tags don't have to affect appearance. They can instead affect the " + + "behavior of mouse and key presses, \"lock\" a range of text so the " + + "user can't edit it, or countless other things.\n"); InsertLink (buffer, ref iter, "Go back", 1); - } - else if (page == 3) - { + } else if (page == 3) { TextTag tag = buffer.TagTable.Lookup ("bold"); if (tag == null) { tag = new TextTag ("bold"); @@ -110,26 +85,25 @@ namespace GtkDemo } buffer.InsertWithTags (ref iter, "hypertext:\n", tag); buffer.Insert (ref iter, - "machine-readable text that is not sequential but is organized" + - "so that related items of information are connected.\n"); + "machine-readable text that is not sequential but is organized " + + "so that related items of information are connected.\n"); InsertLink (buffer, ref iter, "Go back", 1); } } - // Looks at all tags covering the position of iter in the text view, + // Looks at all tags covering the position of iter in the text view, // and if one of them is a link, follow it by showing the page identified // by the data attached to it. void FollowIfLink (TextView view, TextIter iter) { - foreach (TextTag tag in iter.Tags) - { - int page = (int) tag.PersistentData ["page"]; - if (page != 0) - ShowPage (view.Buffer, page); + foreach (TextTag tag in iter.Tags) { + object page = tag.PersistentData ["page"]; + if (page is int) + ShowPage (view.Buffer, (int)page); } } - // Looks at all tags covering the position (x, y) in the text view, + // Looks at all tags covering the position (x, y) in the text view, // and if one of them is a link, change the cursor to the "hands" cursor // typically used by web browsers. void SetCursorIfAppropriate (TextView view, int x, int y) @@ -137,73 +111,82 @@ namespace GtkDemo bool hovering = false; TextIter iter = view.GetIterAtLocation (x, y); - foreach (TextTag tag in iter.Tags) - { - if (tag.PersistentData ["page"] != null && ((int) tag.PersistentData ["page"]) != 0) { + foreach (TextTag tag in iter.Tags) { + if (tag.PersistentData ["page"] is int) { hovering = true; break; } } - if (hovering != hoveringOverLink) - { + if (hovering != hoveringOverLink) { + Gdk.Window window = view.GetWindow (Gtk.TextWindowType.Text); + hoveringOverLink = hovering; if (hoveringOverLink) - view.GdkWindow.Cursor = handCursor; + window.Cursor = handCursor; else - view.GdkWindow.Cursor = regularCursor; + window.Cursor = regularCursor; } } - [GLib.ConnectBefore] - void OnButtonRelease (object sender, ButtonReleaseEventArgs a) + // Links can be activated by pressing Enter. + void KeyPress (object sender, KeyPressEventArgs args) { - if (a.Event.Button != 1) - return; + TextView view = sender as TextView; + + switch ((Gdk.Key) args.Event.KeyValue) { + case Gdk.Key.Return: + case Gdk.Key.KP_Enter: + TextIter iter = view.Buffer.GetIterAtMark (view.Buffer.InsertMark); + FollowIfLink (view, iter); + break; + default: + break; + } + } + + // Links can also be activated by clicking. + void EventAfter (object sender, WidgetEventAfterArgs args) + { + if (args.Event.Type != Gdk.EventType.ButtonRelease) + return; + + Gdk.EventButton evt = (Gdk.EventButton)args.Event; + + if (evt.Button != 1) + return; TextView view = sender as TextView; TextIter start, end, iter; int x, y; + // we shouldn't follow a link if the user has selected something view.Buffer.GetSelectionBounds (out start, out end); if (start.Offset != end.Offset) return; - view.WindowToBufferCoords (TextWindowType.Widget, (int) a.Event.X, (int) a.Event.Y, out x, out y); + view.WindowToBufferCoords (TextWindowType.Widget, (int) evt.X, (int) evt.Y, out x, out y); iter = view.GetIterAtLocation (x, y); FollowIfLink (view, iter); } - // Links can be activated by pressing Enter. - void OnKeyPress (object sender, KeyPressEventArgs a) - { - TextView view = sender as TextView; - - switch ((Gdk.Key) a.Event.KeyValue) { - case Gdk.Key.Return: - case Gdk.Key.KP_Enter: - TextIter iter = view.Buffer.GetIterAtMark (view.Buffer.InsertMark); - FollowIfLink (view, iter); - break; - default: - break; - } - } - - //Update the cursor image if the pointer moved. - void OnMotionNotify (object sender, MotionNotifyEventArgs a) + // Update the cursor image if the pointer moved. + void MotionNotify (object sender, MotionNotifyEventArgs args) { TextView view = sender as TextView; int x, y; + Gdk.ModifierType state; - view.WindowToBufferCoords (TextWindowType.Widget, (int) a.Event.X, (int) a.Event.Y, out x, out y); + view.WindowToBufferCoords (TextWindowType.Widget, (int) args.Event.X, (int) args.Event.Y, out x, out y); SetCursorIfAppropriate (view, x, y); + + view.GdkWindow.GetPointer (out x, out y, out state); } // Also update the cursor image if the window becomes visible // (e.g. when a window covering it got iconified). - void OnVisibilityNotify (object sender, VisibilityNotifyEventArgs a) + void VisibilityNotify (object sender, VisibilityNotifyEventArgs a) { TextView view = sender as TextView; int wx, wy, bx, by; @@ -211,15 +194,12 @@ namespace GtkDemo view.GetPointer (out wx, out wy); view.WindowToBufferCoords (TextWindowType.Widget, wx, wy, out bx, out by); SetCursorIfAppropriate (view, bx, by); - } - void OnWindowDelete (object sender, DeleteEventArgs a) + protected override bool OnDeleteEvent (Gdk.Event evt) { - this.Hide (); - this.Destroy (); - a.RetVal = true; + Destroy (); + return true; } } } - diff --git a/sample/GtkDemo/DemoImages.cs b/sample/GtkDemo/DemoImages.cs index 315010fcc..ede0cb39a 100644 --- a/sample/GtkDemo/DemoImages.cs +++ b/sample/GtkDemo/DemoImages.cs @@ -1,12 +1,3 @@ -// -// DemoImages.cs - port of images.c gtk-demo -// -// Author: Daniel Kornhauser -// -// Copyright (C) 2003, Ximian Inc. -// - - /* Images * * Gtk.Image is used to display an image; the image can be in a number of formats. @@ -36,19 +27,18 @@ namespace GtkDemo private VBox vbox; BinaryReader imageStream; - public DemoImages () : base ("images") + public DemoImages () : base ("Images") { - this.DeleteEvent += new DeleteEventHandler (WindowDelete); - this.BorderWidth = 8; - + BorderWidth = 8; + vbox = new VBox (false, 8); vbox.BorderWidth = 8; - this.Add (vbox); - + Add (vbox); + Gtk.Label label = new Gtk.Label ("Image loaded from a file"); label.UseMarkup = true; vbox.PackStart (label, false, false, 0); - + Gtk.Frame frame = new Gtk.Frame (); frame.ShadowType = ShadowType.In; @@ -57,14 +47,14 @@ namespace GtkDemo Alignment alignment = new Alignment (0.5f, 0.5f, 0f, 0f); alignment.Add (frame); vbox.PackStart (alignment, false, false, 0); - - Gtk.Image image = new Gtk.Image (Gdk.Pixbuf.LoadFromResource ("gtk-logo-rgb.gif")); - frame.Add (image); + + Gtk.Image image = Gtk.Image.LoadFromResource ("gtk-logo-rgb.gif"); + frame.Add (image); // Animation label = new Gtk.Label ("Animation loaded from a file"); label.UseMarkup = true; - vbox.PackStart (label); + vbox.PackStart (label, false, false, 0); frame = new Gtk.Frame (); frame.ShadowType = ShadowType.In; @@ -73,13 +63,13 @@ namespace GtkDemo alignment.Add (frame); vbox.PackStart (alignment, false, false, 0); - image = new Gtk.Image (Gdk.Pixbuf.LoadFromResource ("floppybuddy.gif")); + image = Gtk.Image.LoadFromResource ("floppybuddy.gif"); frame.Add (image); // Progressive label = new Gtk.Label ("Progressive image loading"); label.UseMarkup = true; - vbox.PackStart (label); + vbox.PackStart (label, false, false, 0); frame = new Gtk.Frame (); frame.ShadowType = ShadowType.In; @@ -90,54 +80,74 @@ namespace GtkDemo // Create an empty image for now; the progressive loader // will create the pixbuf and fill it in. - // progressiveImage = new Gtk.Image (); frame.Add (progressiveImage); StartProgressiveLoading (); - + // Sensitivity control Gtk.ToggleButton button = new Gtk.ToggleButton ("_Insensitive"); vbox.PackStart (button, false, false, 0); button.Toggled += new EventHandler (ToggleSensitivity); - this.ShowAll (); + ShowAll (); } - - private void WindowDelete (object o, DeleteEventArgs args) + + protected override void OnDestroyed () { - this.Hide (); - this.Destroy (); - args.RetVal = true; + if (timeout_id != 0) { + GLib.Source.Remove (timeout_id); + timeout_id = 0; + } + + if (pixbufLoader != null) { + pixbufLoader.Close (); + pixbufLoader = null; + } + + if (imageStream != null) { + imageStream.Close (); + imageStream = null; + } + } + + protected override bool OnDeleteEvent (Gdk.Event evt) + { + Destroy (); + return true; } private void ToggleSensitivity (object o, EventArgs args) { + ToggleButton toggle = o as ToggleButton; + Widget[] children = vbox.Children; - foreach (Widget widget in children) + foreach (Widget widget in children) { // don't disable our toggle - if (widget.GetType () != o.GetType () ) - widget.Sensitive = !widget.Sensitive; + if (widget != toggle) + widget.Sensitive = !toggle.Active; + } } private uint timeout_id; private void StartProgressiveLoading () { - /* This is obviously totally contrived (we slow down loading - * on purpose to show how incremental loading works). - * The real purpose of incremental loading is the case where - * you are reading data from a slow source such as the network. - * The timeout simply simulates a slow data source by inserting - * pauses in the reading process. - */ + // This is obviously totally contrived (we slow down loading + // on purpose to show how incremental loading works). + // The real purpose of incremental loading is the case where + // you are reading data from a slow source such as the network. + // The timeout simply simulates a slow data source by inserting + // pauses in the reading process. + timeout_id = GLib.Timeout.Add (150, new GLib.TimeoutHandler (ProgressiveTimeout)); } Gdk.PixbufLoader pixbufLoader; - // TODO: Decide if we want to perform crazy error handling - private bool ProgressiveTimeout () + // TODO: Decide if we want to perform the same crazy error handling + // gtk-demo does + private bool ProgressiveTimeout () { if (imageStream == null) { Stream stream = Assembly.GetExecutingAssembly ().GetManifestResourceStream ("alphatest.png"); @@ -151,21 +161,20 @@ namespace GtkDemo byte[] bytes = imageStream.ReadBytes (256); pixbufLoader.Write (bytes, (uint) bytes.Length); return true; // leave the timeout active - } - else { + } else { imageStream.Close (); return false; // removes the timeout } } - void ProgressivePreparedCallback (object obj, EventArgs args) + void ProgressivePreparedCallback (object obj, EventArgs args) { Gdk.Pixbuf pixbuf = pixbufLoader.Pixbuf; pixbuf.Fill (0xaaaaaaff); progressiveImage.FromPixbuf = pixbuf; } - void ProgressiveUpdatedCallback (object obj, AreaUpdatedArgs args) + void ProgressiveUpdatedCallback (object obj, AreaUpdatedArgs args) { progressiveImage.QueueDraw (); } diff --git a/sample/GtkDemo/DemoListStore.cs b/sample/GtkDemo/DemoListStore.cs index d914d7a98..8acc50c17 100644 --- a/sample/GtkDemo/DemoListStore.cs +++ b/sample/GtkDemo/DemoListStore.cs @@ -1,11 +1,4 @@ -// -// DemoListItem.cs, port of tree_store.c from gtk-demo -// -// Author: Daniel Kornhauser -// -// Copyright (C) 2003, Ximian Inc. - -/* List View/List Store +/* Tree View/List Store * * The Gtk.ListStore is used to store data in tree form, to be * used later on by a Gtk.ListView to display it. This demo builds @@ -19,7 +12,7 @@ using System.Collections; using Gtk; -namespace GtkDemo +namespace GtkDemo { [Demo ("List Store", "DemoListStore.cs", "Tree View")] public class DemoListStore : Gtk.Window @@ -28,40 +21,40 @@ namespace GtkDemo public DemoListStore () : base ("ListStore Demo") { - this.DeleteEvent += new DeleteEventHandler (WindowDelete); + BorderWidth = 8; VBox vbox = new VBox (false, 8); - vbox.BorderWidth = 8; - this.Add (vbox); + Add (vbox); - vbox.PackStart (new Label ("This is the bug list (note: not based on real data, it would be nice to have a nice ODBC interface to bugzilla or so, though)."), false, false, 0); + Label label = new Label ("This is the bug list (note: not based on real data, it would be nice to have a nice ODBC interface to bugzilla or so, though)."); + vbox.PackStart (label, false, false, 0); - ScrolledWindow scrolledWindow = new ScrolledWindow (); - scrolledWindow.ShadowType = ShadowType.EtchedIn; - scrolledWindow.SetPolicy (PolicyType.Automatic, PolicyType.Automatic); - vbox.PackStart (scrolledWindow, true, true, 0); - // create model - CreateModel (); + ScrolledWindow sw = new ScrolledWindow (); + sw.ShadowType = ShadowType.EtchedIn; + sw.SetPolicy (PolicyType.Automatic, PolicyType.Automatic); + vbox.PackStart (sw, true, true, 0); + + // create model + store = CreateModel (); // create tree view TreeView treeView = new TreeView (store); treeView.RulesHint = true; - treeView.SearchColumn = (int) ColumnNumber.Description; - AddColumns (treeView); - scrolledWindow.Add (treeView); + treeView.SearchColumn = (int) Column.Description; + sw.Add (treeView); - // finish & show - this.SetDefaultSize (650, 400); - this.ShowAll (); + AddColumns (treeView); + + // finish & show + SetDefaultSize (280, 250); + ShowAll (); } - private void ItemToggled (object o, ToggledArgs args) + private void FixedToggled (object o, ToggledArgs args) { Gtk.TreeIter iter; - if (store.GetIterFromString (out iter, args.Path)) - { + if (store.GetIterFromString (out iter, args.Path)) { bool val = (bool) store.GetValue (iter, 0); - Console.WriteLine ("toggled {0} with value {1}", args.Path, val); store.SetValue (iter, 0, !val); } } @@ -70,64 +63,62 @@ namespace GtkDemo { // column for fixed toggles CellRendererToggle rendererToggle = new CellRendererToggle (); - rendererToggle.Toggled += new ToggledHandler (ItemToggled); - TreeViewColumn column = new TreeViewColumn ("Fixed", rendererToggle, "active", 0); - rendererToggle.Active = true; - rendererToggle.Activatable = true; - rendererToggle.Visible = true; - // set this column to a fixed sizing (of 50 pixels) + rendererToggle.Toggled += new ToggledHandler (FixedToggled); + TreeViewColumn column = new TreeViewColumn ("Fixed?", rendererToggle, "active", Column.Fixed); + + // set this column to a fixed sizing (of 50 pixels) column.Sizing = TreeViewColumnSizing.Fixed; column.FixedWidth = 50; - treeView.AppendColumn (column); - // column for bug numbers + treeView.AppendColumn (column); + + // column for bug numbers CellRendererText rendererText = new CellRendererText (); - column = new TreeViewColumn ("Bug number", rendererText, "text", ColumnNumber.Number); - column.SortColumnId = (int) ColumnNumber.Number; - treeView.AppendColumn (column); + column = new TreeViewColumn ("Bug number", rendererText, "text", Column.Number); + column.SortColumnId = (int) Column.Number; + treeView.AppendColumn (column); + // column for severities rendererText = new CellRendererText (); - column = new TreeViewColumn ("Severity", rendererText, "text", ColumnNumber.Severity); - column.SortColumnId = (int) ColumnNumber.Severity; - treeView.AppendColumn(column); + column = new TreeViewColumn ("Severity", rendererText, "text", Column.Severity); + column.SortColumnId = (int) Column.Severity; + treeView.AppendColumn(column); + // column for description rendererText = new CellRendererText (); - column = new TreeViewColumn ("Description", rendererText, "text", ColumnNumber.Description); - column.SortColumnId = (int) ColumnNumber.Description; - treeView.AppendColumn (column); + column = new TreeViewColumn ("Description", rendererText, "text", Column.Description); + column.SortColumnId = (int) Column.Description; + treeView.AppendColumn (column); } - private void WindowDelete (object o, DeleteEventArgs args) + protected override bool OnDeleteEvent (Gdk.Event evt) { - this.Hide (); - this.Destroy (); - args.RetVal = true; + Destroy (); + return true; } - private void CreateModel () + private ListStore CreateModel () { - store = new ListStore ( - typeof(bool), - typeof(int), - typeof(string), - typeof(string)); + ListStore store = new ListStore (typeof(bool), + typeof(int), + typeof(string), + typeof(string)); foreach (Bug bug in bugs) { - store.AppendValues(bug.Fixed, + store.AppendValues (bug.Fixed, bug.Number, bug.Severity, bug.Description); } + return store; } - // FIXME: Instead of using number convert enum to array using - // GetValues and then get the Length Property - public enum ColumnNumber + private enum Column { Fixed, Number, Severity, - Description, + Description } private static Bug[] bugs = @@ -146,7 +137,7 @@ namespace GtkDemo new Bug ( true, 50939, "Normal", "Add shift clicking to GtkTextView" ), new Bug ( false, 6112, "Enhancement","netscape-like collapsable toolbars" ), new Bug ( false, 1, "Normal", "First bug :=)" ) - }; + }; } public class Bug @@ -155,9 +146,9 @@ namespace GtkDemo public int Number; public string Severity; public string Description; - + public Bug (bool status, int number, string severity, - string description) + string description) { Fixed = status; Number = number; diff --git a/sample/GtkDemo/DemoMain.cs b/sample/GtkDemo/DemoMain.cs index 1526f90b3..36a4e0745 100644 --- a/sample/GtkDemo/DemoMain.cs +++ b/sample/GtkDemo/DemoMain.cs @@ -1,10 +1,3 @@ -// -// DemoMain.cs, port of main.c from gtk-demo -// -// Author: Daniel Kornhauser -// -// Copyright (C) 2003, Ximian Inc. - using System; using System.Collections; using System.IO; @@ -14,14 +7,14 @@ using Gdk; using Gtk; using Pango; -namespace GtkDemo +namespace GtkDemo { public class DemoMain { private Gtk.Window window; private TextBuffer infoBuffer = new TextBuffer (null); private TextBuffer sourceBuffer = new TextBuffer (null); - private TreeView treeView; + private TreeView treeView; private TreeStore store; private TreeIter oldSelection = TreeIter.Zero; @@ -31,9 +24,9 @@ namespace GtkDemo new DemoMain (); Application.Run (); } - + public DemoMain () - { + { SetupDefaultIcon (); window = new Gtk.Window ("Gtk# Code Demos"); window.SetDefaultSize (600, 400); @@ -41,16 +34,16 @@ namespace GtkDemo HBox hbox = new HBox (false, 0); window.Add (hbox); - + treeView = CreateTree (); hbox.PackStart (treeView, false, false, 0); - + Notebook notebook = new Notebook (); hbox.PackStart (notebook, true, true, 0); notebook.AppendPage (CreateText (infoBuffer, false), new Label ("_Info")); TextTag heading = new TextTag ("heading"); - heading.Scale = heading.Scale * 2; + heading.Font = "Sans 18"; infoBuffer.TagTable.Add (heading); notebook.AppendPage (CreateText (sourceBuffer, true), new Label ("_Source")); @@ -61,17 +54,12 @@ namespace GtkDemo private void LoadFile (string filename) { Stream file = Assembly.GetExecutingAssembly ().GetManifestResourceStream (filename); - if (file != null) - { + if (file != null) { LoadStream (file); - } - else if (File.Exists (filename)) - { + } else if (File.Exists (filename)) { file = File.OpenRead (filename); LoadStream (file); - } - else - { + } else { infoBuffer.Text = String.Format ("{0} was not found.", filename); sourceBuffer.Text = String.Empty; } @@ -79,52 +67,64 @@ namespace GtkDemo Fontify (); } + private enum LoadState { + Title, + Info, + SkipWhitespace, + Body + }; + private void LoadStream (Stream file) { StreamReader sr = new StreamReader (file); - bool insideComment = false; - bool headingValid = true; + LoadState state = LoadState.Title; + bool inPara = false; infoBuffer.Text = ""; sourceBuffer.Text = ""; + TextIter infoIter = infoBuffer.EndIter; + TextIter sourceIter = sourceBuffer.EndIter; + // mostly broken comment parsing for splitting // out the special comments to display in the infobuffer + string line, trimmed; while (sr.Peek () != -1) { line = sr.ReadLine (); trimmed = line.Trim (); - if (headingValid && line.Trim ().StartsWith ("//")) - { - continue; - } - else if (headingValid && trimmed.StartsWith ("/*")) - { - TextIter iter = infoBuffer.EndIter; - infoBuffer.InsertWithTagsByName (ref iter, trimmed.Substring (2) + Environment.NewLine, "heading"); - infoBuffer.Insert (ref iter, Environment.NewLine); - insideComment = true; - } - else if (headingValid && trimmed.StartsWith ("*/")) - { - insideComment = false; - headingValid = false; - } - else - { - if (insideComment) - { - TextIter iter = infoBuffer.EndIter; - if (trimmed.StartsWith ("*")) - infoBuffer.Insert (ref iter, trimmed.Substring (1)); - else - infoBuffer.Insert (ref iter, trimmed); + + switch (state) { + case LoadState.Title: + if (trimmed.StartsWith ("/* ")) { + infoBuffer.InsertWithTagsByName (ref infoIter, trimmed.Substring (3), "heading"); + state = LoadState.Info; } - else - { - TextIter iter = sourceBuffer.EndIter; - sourceBuffer.Insert (ref iter, line + Environment.NewLine); + break; + + case LoadState.Info: + if (trimmed == "*") { + infoBuffer.Insert (ref infoIter, "\n"); + inPara = false; + } else if (trimmed.StartsWith ("* ")) { + if (inPara) + infoBuffer.Insert (ref infoIter, " "); + infoBuffer.Insert (ref infoIter, trimmed.Substring (2)); + inPara = true; + } else if (trimmed.StartsWith ("*/")) + state = LoadState.SkipWhitespace; + break; + + case LoadState.SkipWhitespace: + if (trimmed != "") { + state = LoadState.Body; + goto case LoadState.Body; } + break; + + case LoadState.Body: + sourceBuffer.Insert (ref sourceIter, line + "\n"); + break; } } sr.Close (); @@ -139,14 +139,13 @@ namespace GtkDemo private void SetupDefaultIcon () { Gdk.Pixbuf pixbuf = Gdk.Pixbuf.LoadFromResource ("gtk-logo-rgb.gif"); - - if (pixbuf != null) - { + + if (pixbuf != null) { // The gtk-logo-rgb icon has a white background // make it transparent instead Pixbuf transparent = pixbuf.AddAlpha (true, 0xff, 0xff, 0xff); - - Gtk.Window.DefaultIconList = new Gdk.Pixbuf [] {transparent}; + + Gtk.Window.DefaultIconList = new Gdk.Pixbuf [] { transparent }; } } @@ -159,9 +158,9 @@ namespace GtkDemo TreeViewColumn column = new TreeViewColumn ("Widget (double click for demo)", cr, "text", 0); column.AddAttribute (cr, "style" , 2); view.AppendColumn (column); - - view.Selection.Changed += new EventHandler (OnTreeChanged); - view.RowActivated += new RowActivatedHandler (OnRowActivated); + + view.Selection.Changed += new EventHandler (TreeChanged); + view.RowActivated += new RowActivatedHandler (RowActivated); view.ExpandAll (); view.SetSizeRequest (200, -1); view.Selection.Mode = Gtk.SelectionMode.Browse; @@ -173,77 +172,64 @@ namespace GtkDemo ScrolledWindow scrolledWindow = new ScrolledWindow (); scrolledWindow.SetPolicy (PolicyType.Automatic, PolicyType.Automatic); scrolledWindow.ShadowType = ShadowType.In; - + TextView textView = new TextView (buffer); textView.Editable = false; textView.CursorVisible = false; scrolledWindow.Add (textView); - if (IsSource) - { - FontDescription fontDescription = FontDescription.FromString ("Courier 12"); + if (IsSource) { + FontDescription fontDescription = FontDescription.FromString ("Courier 12"); textView.ModifyFont (fontDescription); textView.WrapMode = Gtk.WrapMode.None; - } - else - { + } else { // Make it a bit nicer for text textView.WrapMode = Gtk.WrapMode.Word; textView.PixelsAboveLines = 2; textView.PixelsBelowLines = 2; } - + return scrolledWindow; } - - private TreeStore FillTree () - { + + private TreeStore FillTree () + { // title, filename, italic - store = new TreeStore (typeof (string), typeof (System.Type), typeof (bool)); + store = new TreeStore (typeof (string), typeof (System.Type), typeof (bool)); Hashtable parents = new Hashtable (); TreeIter parent; - - Type[] types = Assembly.GetExecutingAssembly ().GetTypes (); - foreach (Type t in types) - { - if (t.IsDefined (typeof (DemoAttribute), false)) - { - object[] att = t.GetCustomAttributes (typeof (DemoAttribute), false); - foreach (DemoAttribute demo in att) - { - if (demo.Parent != null) - { - if (!parents.Contains (demo.Parent)) - parents.Add (demo.Parent, store.AppendValues (demo.Parent)); - parent = (TreeIter) parents[demo.Parent]; - store.AppendValues (parent, demo.Label, t, false); - } - else - { - store.AppendValues (demo.Label, t, false); - } + Type[] types = Assembly.GetExecutingAssembly ().GetTypes (); + foreach (Type t in types) { + object[] att = t.GetCustomAttributes (typeof (DemoAttribute), false); + foreach (DemoAttribute demo in att) { + if (demo.Parent != null) { + if (!parents.Contains (demo.Parent)) + parents.Add (demo.Parent, store.AppendValues (demo.Parent)); + + parent = (TreeIter) parents[demo.Parent]; + store.AppendValues (parent, demo.Label, t, false); + } else { + store.AppendValues (demo.Label, t, false); } } } store.SetSortColumnId (0, SortType.Ascending); - return store; - } - - private void OnTreeChanged (object o, EventArgs args) + return store; + } + + private void TreeChanged (object o, EventArgs args) { TreeIter iter; TreeModel model; - if (treeView.Selection.GetSelected (out model, out iter)) - { + if (treeView.Selection.GetSelected (out model, out iter)) { Type type = (Type) model.GetValue (iter, 1); - if (type != null) - { + if (type != null) { object[] atts = type.GetCustomAttributes (typeof (DemoAttribute), false); string file = ((DemoAttribute) atts[0]).Filename; - LoadFile (file); + LoadFile (file); } model.SetValue (iter, 2, true); @@ -251,19 +237,18 @@ namespace GtkDemo model.SetValue (oldSelection, 2, false); oldSelection = iter; } - } + } - private void OnRowActivated (object o, RowActivatedArgs args) - { + private void RowActivated (object o, RowActivatedArgs args) + { TreeIter iter; - if (treeView.Model.GetIter (out iter, args.Path)) - { + if (treeView.Model.GetIter (out iter, args.Path)) { Type type = (Type) treeView.Model.GetValue (iter, 1); if (type != null) Activator.CreateInstance (type); } - } + } private void WindowDelete (object o, DeleteEventArgs args) { @@ -272,4 +257,3 @@ namespace GtkDemo } } } - diff --git a/sample/GtkDemo/DemoMenus.cs b/sample/GtkDemo/DemoMenus.cs index f3447abec..60f8bcb95 100644 --- a/sample/GtkDemo/DemoMenus.cs +++ b/sample/GtkDemo/DemoMenus.cs @@ -1,45 +1,29 @@ -// -// TestMenus.cs -// -// Author: Duncan Mak (duncan@ximian.com) -// -// Copyright (C) 2002, Duncan Mak, Ximian Inc. -// - /* Menus * - * There are several widgets involved in displaying menus. The - * MenuBar widget is a horizontal menu bar, which normally appears - * at the top of an application. The Menu widget is the actual menu - * that pops up. Both MenuBar and Menu are subclasses of - * MenuShell; a MenuShell contains menu items - * (MenuItem). Each menu item contains text and/or images and can - * be selected by the user. + * There are several widgets involved in displaying menus. The MenuBar + * widget is a horizontal menu bar, which normally appears at the top + * of an application. The Menu widget is the actual menu that pops up. + * Both MenuBar and Menu are subclasses of MenuShell; a MenuShell + * contains menu items (MenuItem). Each menu item contains text and/or + * images and can be selected by the user. * * There are several kinds of menu item, including plain MenuItem, - * CheckMenuItem which can be checked/unchecked, RadioMenuItem - * which is a check menu item that's in a mutually exclusive group, - * SeparatorMenuItem which is a separator bar, TearoffMenuItem - * which allows a Menu to be torn off, and ImageMenuItem which - * can place a Image or other widget next to the menu text. + * CheckMenuItem which can be checked/unchecked, RadioMenuItem which + * is a check menu item that's in a mutually exclusive group, + * SeparatorMenuItem which is a separator bar, TearoffMenuItem which + * allows a Menu to be torn off, and ImageMenuItem which can place a + * Image or other widget next to the menu text. * - * A MenuItem can have a submenu, which is simply a Menu to pop - * up when the menu item is selected. Typically, all menu items in a menu bar - * have submenus. + * A MenuItem can have a submenu, which is simply a Menu to pop up + * when the menu item is selected. Typically, all menu items in a menu + * bar have submenus. * - * The OptionMenu widget is a button that pops up a Menu when clicked. - * It's used inside dialogs and such. + * UIManager provides a higher-level interface for creating menu bars + * and menus; while you can construct menus manually, most people + * don't do that. There's a separate demo for UIManager. * - * ItemFactory provides a higher-level interface for creating menu bars - * and menus; while you can construct menus manually, most people don't - * do that. There's a separate demo for ItemFactory. - * */ - -// TODO : window width is not exactly equal -// point on the right side - using System; using Gtk; @@ -49,102 +33,79 @@ namespace GtkDemo public class DemoMenus : Gtk.Window { public DemoMenus () : base ("Menus") - { - this.DeleteEvent += new DeleteEventHandler (WindowDelete); - + { AccelGroup accel_group = new AccelGroup (); - this.AddAccelGroup (accel_group); + AddAccelGroup (accel_group); VBox box1 = new VBox (false, 0); - this.Add (box1); + Add (box1); MenuBar menubar = new MenuBar (); - box1.PackStart (menubar, false, false, 0); - - Menu menu = Create_Menu (2, true); + box1.PackStart (menubar, false, true, 0); MenuItem menuitem = new MenuItem ("test\nline2"); - menuitem.Submenu = menu; + menuitem.Submenu = CreateMenu (2, true); menubar.Append (menuitem); MenuItem menuitem1 = new MenuItem ("foo"); - menuitem1.Submenu = Create_Menu (3, true); + menuitem1.Submenu = CreateMenu (3, true); menubar.Append (menuitem1); menuitem = new MenuItem ("bar"); - menuitem.Submenu = Create_Menu (4, true); + menuitem.Submenu = CreateMenu (4, true); menuitem.RightJustified = true; menubar.Append (menuitem); - - menubar = new MenuBar (); - box1.PackStart (menubar, false, true, 0); - + VBox box2 = new VBox (false, 10); box2.BorderWidth = 10; - box1.PackStart (box2, true, true, 0); - - box2 = new VBox (false, 10); - box2.BorderWidth = 10; box1.PackStart (box2, false, true, 0); - - Button close_button = new Button ("close"); - close_button.Clicked += new EventHandler (Close_Button); - box2.PackStart (close_button, true, true, 0); - - close_button.CanDefault = true; - close_button.GrabDefault (); - this.ShowAll (); - } + Button close = new Button ("close"); + close.Clicked += new EventHandler (CloseClicked); + box2.PackStart (close, true, true, 0); - private Menu Create_Menu (int depth, bool tearoff) + close.CanDefault = true; + close.GrabDefault (); + + ShowAll (); + } + + private Menu CreateMenu (int depth, bool tearoff) { if (depth < 1) return null; Menu menu = new Menu (); - MenuItem menuitem; - string label; GLib.SList group = new GLib.SList (IntPtr.Zero); - if (tearoff) - { - menuitem = new TearoffMenuItem (); + if (tearoff) { + TearoffMenuItem menuitem = new TearoffMenuItem (); menu.Append (menuitem); - menuitem.Show (); } - for (int i = 0, j = 1; i < 5; i++, j++) - { - label = String.Format ("item {0} - {1}", depth, j); - menuitem = new RadioMenuItem (group, label); - group = ((RadioMenuItem) menuitem).Group; - menuitem = new MenuItem (label); + for (int i = 0, j = 1; i < 5; i++, j++) { + RadioMenuItem menuitem = new RadioMenuItem (group, String.Format ("item {0} - {1}", depth, j)); + group = menuitem.Group; + menu.Append (menuitem); - if (i == 3) menuitem.Sensitive = false; - - Menu child = Create_Menu ((depth - 1), true); - if (child != null) - menuitem.Submenu = child; + menuitem.Submenu = CreateMenu ((depth - 1), true); } return menu; } - private void Close_Button (object o, EventArgs args) + private void CloseClicked (object o, EventArgs args) { - this.Hide (); - this.Destroy (); + Destroy (); } - - private void WindowDelete (object o, DeleteEventArgs args) + + protected override bool OnDeleteEvent (Gdk.Event evt) { - this.Hide (); - this.Destroy (); - args.RetVal = true; + Destroy (); + return true; } } } diff --git a/sample/GtkDemo/DemoPanes.cs b/sample/GtkDemo/DemoPanes.cs index 937ae7c11..66f972c73 100644 --- a/sample/GtkDemo/DemoPanes.cs +++ b/sample/GtkDemo/DemoPanes.cs @@ -1,12 +1,3 @@ -// -// DemoPanes.cs -// -// Author: Daniel Kornhauser -// -// Copyright (C) 2002, Daniel Kornhauser, Ximian Inc. -// - - /* Paned Widgets * * The HPaned and VPaned Widgets divide their content @@ -22,6 +13,7 @@ using System; +using System.Collections; using Gtk; namespace GtkDemo @@ -29,151 +21,119 @@ namespace GtkDemo [Demo ("Paned Widget", "DemoPanes.cs")] public class DemoPanes : Gtk.Window { - private VPaned vpaned; - private HPaned top; - private Frame left; - private Frame right; - private Frame bottom; - - private CheckButton resizeLeft; - private CheckButton shrinkLeft; - private CheckButton resizeRight; - private CheckButton shrinkRight; - private CheckButton resizeTop; - private CheckButton shrinkTop; - private CheckButton resizeBottom; - private CheckButton shrinkBottom; - private Button button; + Hashtable children = new Hashtable (); public DemoPanes () : base ("Panes") - { - this.DeleteEvent += new DeleteEventHandler (WindowDelete); - this.BorderWidth = 0; - + { VBox vbox = new VBox (false, 0); - this.Add (vbox); + Add (vbox); - vpaned = new VPaned (); + VPaned vpaned = new VPaned (); vbox.PackStart (vpaned, true, true, 0); vpaned.BorderWidth = 5; - top = new HPaned (); - vpaned.Add1 (top); + HPaned hpaned = new HPaned (); + vpaned.Add1 (hpaned); - left = new Frame (); - left.ShadowType = ShadowType.In; - left.SetSizeRequest (60, 60); - top.Add1 (left); - button = new Button ("_Hi there"); - left.Add (button); + Frame frame = new Frame (); + frame.ShadowType = ShadowType.In; + frame.SetSizeRequest (60, 60); + hpaned.Add1 (frame); - right = new Frame (); - right.ShadowType = ShadowType.In; - right.SetSizeRequest (80, 60); - top.Add2 (right); + Gtk.Button button = new Button ("_Hi there"); + frame.Add (button); - bottom = new Frame (); - bottom.ShadowType = ShadowType.In; - bottom.SetSizeRequest (80, 60); - vpaned.Add2 (bottom); + frame = new Frame (); + frame.ShadowType = ShadowType.In; + frame.SetSizeRequest (80, 60); + hpaned.Add2 (frame); - // Now create toggle buttons to control sizing + frame = new Frame (); + frame.ShadowType = ShadowType.In; + frame.SetSizeRequest (60, 80); + vpaned.Add2 (frame); - Frame frame = new Frame ("Horizonal"); + // Now create toggle buttons to control sizing + vbox.PackStart (CreatePaneOptions (hpaned, + "Horizontal", + "Left", + "Right"), + false, false, 0); + + vbox.PackStart (CreatePaneOptions (vpaned, + "Vertical", + "Top", + "Bottom"), + false, false, 0); + + ShowAll (); + } + + Frame CreatePaneOptions (Paned paned, string frameLabel, + string label1, string label2) + { + Frame frame = new Frame (frameLabel); frame.BorderWidth = 4; - vbox.PackStart (frame); Table table = new Table (3, 2, true); frame.Add (table); - Label label = new Label ("Left"); + Label label = new Label (label1); table.Attach (label, 0, 1, 0, 1); - resizeLeft = new CheckButton ("_Resize"); - table.Attach (resizeLeft, 0, 1, 1, 2); - resizeLeft.Toggled += new EventHandler (LeftCB); + CheckButton check = new CheckButton ("_Resize"); + table.Attach (check, 0, 1, 1, 2); + check.Toggled += new EventHandler (ToggleResize); + children[check] = paned.Child1; - shrinkLeft = new CheckButton ("_Shrink"); - table.Attach (shrinkLeft, 0, 1, 2, 3); - shrinkLeft.Active = true; - shrinkLeft.Toggled += new EventHandler (LeftCB); + check = new CheckButton ("_Shrink"); + table.Attach (check, 0, 1, 2, 3); + check.Active = true; + check.Toggled += new EventHandler (ToggleShrink); + children[check] = paned.Child1; - label = new Label ("Right"); + label = new Label (label2); table.Attach (label, 1, 2, 0, 1); - - resizeRight = new CheckButton ("_Resize"); - table.Attach (resizeRight, 1, 2, 1, 2); - resizeRight.Active = true; - resizeRight.Toggled += new EventHandler (RightCB); - shrinkRight = new CheckButton ("_Shrink"); - table.Attach (shrinkRight, 1, 2, 2, 3); - shrinkRight.Active = true; - shrinkRight.Toggled += new EventHandler (RightCB); + check = new CheckButton ("_Resize"); + table.Attach (check, 1, 2, 1, 2); + check.Active = true; + check.Toggled += new EventHandler (ToggleResize); + children[check] = paned.Child2; - frame = new Frame ("Vertical"); - frame.BorderWidth = 4; - vbox.PackStart (frame); - - table = new Table (3, 2, true); - frame.Add (table); - - label = new Label ("Top"); - table.Attach (label, 0, 1, 0, 1); - - resizeTop = new CheckButton ("_Resize"); - table.Attach (resizeTop, 0, 1, 1, 2); - resizeTop.Toggled += new EventHandler (TopCB); - - shrinkTop = new CheckButton ("_Shrink"); - table.Attach (shrinkTop, 0, 1, 2, 3); - shrinkTop.Active = true; - shrinkTop.Toggled += new EventHandler (TopCB); + check = new CheckButton ("_Shrink"); + table.Attach (check, 1, 2, 2, 3); + check.Active = true; + check.Toggled += new EventHandler (ToggleShrink); + children[check] = paned.Child2; - label = new Label ("Bottom"); - table.Attach (label, 1, 2, 0, 1); - - resizeBottom = new CheckButton ("_Resize"); - table.Attach (resizeBottom, 1, 2, 1, 2); - resizeBottom.Active = true; - resizeBottom.Toggled += new EventHandler (BottomCB); - - shrinkBottom = new CheckButton ("_Shrink"); - table.Attach (shrinkBottom, 1, 2, 2, 3); - shrinkBottom.Active = true; - shrinkBottom.Toggled += new EventHandler (BottomCB); - - this.ShowAll (); - } - - private void LeftCB (object o, EventArgs args) - { - top.Remove (left); - top.Pack1 (left, resizeLeft.Active, shrinkLeft.Active); - } - - private void RightCB (object o, EventArgs args) - { - top.Remove (right); - top.Pack2 (right, resizeRight.Active, shrinkRight.Active); + return frame; } - private void TopCB (object o, EventArgs args) - { - vpaned.Remove (top); - vpaned.Pack1 (top, resizeTop.Active, shrinkTop.Active); - } - - private void BottomCB (object o, EventArgs args) - { - vpaned.Remove (bottom); - vpaned.Pack2 (bottom, resizeBottom.Active, shrinkBottom.Active); - } - - private void WindowDelete (object o, DeleteEventArgs args) + private void ToggleResize (object obj, EventArgs args) { - this.Hide (); - this.Destroy (); + ToggleButton toggle = obj as ToggleButton; + Widget child = children[obj] as Widget; + Paned paned = child.Parent as Paned; + + Paned.PanedChild pc = paned[child] as Paned.PanedChild; + pc.Resize = toggle.Active; + } + + private void ToggleShrink (object obj, EventArgs args) + { + ToggleButton toggle = obj as ToggleButton; + Widget child = children[obj] as Widget; + Paned paned = child.Parent as Paned; + + Paned.PanedChild pc = paned[child] as Paned.PanedChild; + pc.Shrink = toggle.Active; + } + + protected override bool OnDeleteEvent (Gdk.Event evt) + { + Destroy (); + return true; } } } diff --git a/sample/GtkDemo/DemoPixbuf.cs b/sample/GtkDemo/DemoPixbuf.cs index a6f161ff8..eab0ec2f2 100644 --- a/sample/GtkDemo/DemoPixbuf.cs +++ b/sample/GtkDemo/DemoPixbuf.cs @@ -1,11 +1,3 @@ -// DemoPixbuf.cs: Pixbuf demonstration -// -// Gtk# port of pixbuf demo in gtk-demo app. -// -// Author: Yves Kurz -// -// 2003 Yves Kurz - /* Pixbufs * * A Pixbuf represents an image, normally in RGB or RGBA format. @@ -24,8 +16,9 @@ using Gdk; using Gtk; using System; +using System.Runtime.InteropServices; // for Marshal.Copy -namespace GtkDemo +namespace GtkDemo { [Demo ("Pixbuf", "DemoPixbuf.cs")] public class DemoPixbuf : Gtk.Window @@ -33,8 +26,8 @@ namespace GtkDemo const int FrameDelay = 50; const int CycleLen = 60; const string BackgroundName = "background.jpg"; - - string [] ImageNames = { + + static string[] ImageNames = { "apple-red.png", "gnome-applets.png", "gnome-calendar.png", @@ -44,33 +37,36 @@ namespace GtkDemo "gnome-gsame.png", "gnu-keys.png" }; - + + // background image + static Pixbuf background; + static int backWidth, backHeight; + + // images + static Pixbuf[] images; + // current frame Pixbuf frame; int frameNum; - - // background image - Pixbuf background; - int backWidth, backHeight; - - // images - Pixbuf[] images; // drawing area DrawingArea drawingArea; - // Loads the images for the demo - void LoadPixbuf () + uint timeoutId; + + static DemoPixbuf () { + // Load the images for the demo + background = Gdk.Pixbuf.LoadFromResource (BackgroundName); backWidth = background.Width; backHeight = background.Height; images = new Pixbuf[ImageNames.Length]; - + int i = 0; - foreach (string im in ImageNames) + foreach (string im in ImageNames) images[i++] = Gdk.Pixbuf.LoadFromResource (im); } @@ -78,17 +74,22 @@ namespace GtkDemo void Expose (object o, ExposeEventArgs args) { Widget widget = (Widget) o; + Gdk.Rectangle area = args.Event.Area; + byte[] pixels; + int rowstride; - frame.RenderToDrawableAlpha( - widget.GdkWindow, - 0, 0, - 0, 0, - backWidth, backHeight, - Gdk.PixbufAlphaMode.Full, 8, - RgbDither.Normal, - 100, 100); + rowstride = frame.Rowstride; + pixels = new byte[(frame.Height - area.Y) * rowstride]; + Marshal.Copy (frame.Pixels, pixels, rowstride * area.Y + area.X * 3, pixels.Length); + + widget.GdkWindow.DrawRgbImageDithalign (widget.Style.BlackGC, + area.X, area.Y, area.Width, area.Height, + Gdk.RgbDither.Normal, + pixels, rowstride, + area.X, area.Y); + args.RetVal = true; } - + // timeout handler to regenerate the frame bool timeout () { @@ -102,101 +103,74 @@ namespace GtkDemo double radius = Math.Min (xmid, ymid) / 2; for (int i = 0; i < images.Length; i++) { - double ang = 2 * Math.PI * i / images.Length - f * 2 * - Math.PI; + double ang = 2 * Math.PI * (double) i / images.Length - f * 2 * Math.PI; int iw = images[i].Width; int ih = images[i].Height; - double r = radius + (radius / 3) * Math.Sin (f * 2 * - Math.PI); + double r = radius + (radius / 3) * Math.Sin (f * 2 * Math.PI); int xpos = (int) Math.Floor (xmid + r * Math.Cos (ang) - - iw / 2 + 0.5); + iw / 2.0 + 0.5); int ypos = (int) Math.Floor (ymid + r * Math.Sin (ang) - - ih / 2 + 0.5); - - double k = (i % 2 == 1) ? Math.Sin (f * 2 * Math.PI) : + ih / 2.0 + 0.5); + + double k = (i % 2 == 1) ? Math.Sin (f * 2 * Math.PI) : Math.Cos (f * 2 * Math.PI); k = 2 * k * k; k = Math.Max (0.25, k); - Rectangle r1; /*, r2, dest*/ - - r1 = new Rectangle (xpos, ypos,(int) (iw * k), - (int) (ih * k)); - - /* FIXME: Why is that code not working (in the original gtk-demo it works + Rectangle r1, r2, dest; + r1 = new Rectangle (xpos, ypos, (int) (iw * k), (int) (ih * k)); r2 = new Rectangle (0, 0, backWidth, backHeight); - dest = new Rectangle (0, 0, 0, 0); - r1.Intersect (r2, dest); - - images[i].Composite (frame, dest.x, dest.y, dest.width, - dest.height, xpos, ypos, k, k, - InterpType.Nearest, (int) ((i % 2 == 1) - ? Math.Max (127, Math.Abs (255 * Math.Sin (f * - 2 * Math.PI))) - : Math.Max (127, Math.Abs (255 * Math.Cos (f * - 2 * Math.PI))))); - */ - images[i].Composite (frame, r1.X, r1.Y, r1.Width, - r1.Height, xpos, ypos, k, k, - InterpType.Nearest, (int) ((i % 2 == 1) - ? Math.Max (127, Math.Abs (255 * Math.Sin (f * - 2 * Math.PI))) - : Math.Max (127, Math.Abs (255 * Math.Cos (f * - 2 * Math.PI))))); + dest = Rectangle.Intersect (r1, r2); + if (!dest.IsEmpty) { + images[i].Composite (frame, dest.X, dest.Y, + dest.Width, dest.Height, + xpos, ypos, k, k, + InterpType.Nearest, + (int) ((i % 2 == 1) ? + Math.Max (127, Math.Abs (255 * Math.Sin (f * 2 * Math.PI))) : + Math.Max (127, Math.Abs (255 * Math.Cos (f * 2 * Math.PI))))); + } } drawingArea.QueueDraw (); frameNum++; - + return true; } - public DemoPixbuf () : base ("Gdk Pixbuf Demo") + public DemoPixbuf () : base ("Pixbufs") { - this.DeleteEvent += new DeleteEventHandler (OnWindowDelete); + Resizable = false; + SetSizeRequest (backWidth, backHeight); - try - { - LoadPixbuf (); - } catch (Exception e) - { - using (MessageDialog md = new MessageDialog (this, - DialogFlags.DestroyWithParent, - MessageType.Error, - ButtonsType.Close, - "Error: \n" + e.Message)) { - md.Run (); - md.Hide (); - } - - throw; - } - - frame = new Pixbuf (Colorspace.Rgb, true, 8, backWidth, - backHeight); + frame = new Pixbuf (Colorspace.Rgb, false, 8, backWidth, backHeight); drawingArea = new DrawingArea (); drawingArea.ExposeEvent += new ExposeEventHandler (Expose); Add (drawingArea); - GLib.Timeout.Add (FrameDelay, new GLib.TimeoutHandler(timeout)); + timeoutId = GLib.Timeout.Add (FrameDelay, new GLib.TimeoutHandler(timeout)); - this.SetDefaultSize (backWidth, backHeight); - // this.Resizable = false; ShowAll (); } - void OnWindowDelete (object obj, DeleteEventArgs args) + protected override void OnDestroyed () { - this.Hide (); - this.Destroy (); - args.RetVal = true; + if (timeoutId != 0) { + GLib.Source.Remove (timeoutId); + timeoutId = 0; + } + } + + protected override bool OnDeleteEvent (Gdk.Event evt) + { + Destroy (); + return true; } } } - diff --git a/sample/GtkDemo/DemoSizeGroup.cs b/sample/GtkDemo/DemoSizeGroup.cs index 1e33838ad..42776f2ee 100644 --- a/sample/GtkDemo/DemoSizeGroup.cs +++ b/sample/GtkDemo/DemoSizeGroup.cs @@ -1,18 +1,10 @@ -// -// DemoSizeGroup.cs -// -// Author: Duncan Mak (duncan@ximian.com) -// -// Copyright (C) 2002, Duncan Mak, Ximian Inc. -// - /* Size Groups * * SizeGroup provides a mechanism for grouping a number of * widgets together so they all request the same amount of space. - * This is typically useful when you want a column of widgets to + * This is typically useful when you want a column of widgets to * have the same size, but you can't use a Table widget. - * + * * Note that size groups only affect the amount of space requested, * not the size that the widgets finally receive. If you want the * widgets in a SizeGroup to actually be the same size, you need @@ -31,18 +23,22 @@ namespace GtkDemo { private SizeGroup sizeGroup; - public DemoSizeGroup () + static string [] colors = { "Red", "Green", "Blue" }; + static string [] dashes = { "Solid", "Dashed", "Dotted" }; + static string [] ends = { "Square", "Round", "Arrow" }; + + public DemoSizeGroup () : base ("SizeGroup", null, DialogFlags.DestroyWithParent, + Gtk.Stock.Close, Gtk.ResponseType.Close) { - this.Title = "Size groups"; - this.Resizable = false; - + Resizable = false; + VBox vbox = new VBox (false, 5); this.VBox.PackStart (vbox, true, true, 0); vbox.BorderWidth = 5; sizeGroup = new SizeGroup (SizeGroupMode.Horizontal); - //Create one frame holding color options + // Create one frame holding color options Frame frame = new Frame ("Color Options"); vbox.PackStart (frame, true, true, 0); @@ -52,10 +48,6 @@ namespace GtkDemo table.ColumnSpacing = 10; frame.Add (table); - string [] colors = {"Red", "Green", "Blue", }; - string [] dashes = {"Solid", "Dashed", "Dotted", }; - string [] ends = {"Square", "Round", "Arrow", }; - AddRow (table, 0, sizeGroup, "_Foreground", colors); AddRow (table, 1, sizeGroup, "_Background", colors); @@ -76,17 +68,13 @@ namespace GtkDemo CheckButton checkButton = new CheckButton ("_Enable grouping"); vbox.PackStart (checkButton, false, false, 0); checkButton.Active = true; - checkButton.Toggled += new EventHandler (ButtonToggleCb); + checkButton.Toggled += new EventHandler (ToggleGrouping); - Button CloseButton = new Button (Stock.Close); - this.AddActionWidget (CloseButton, ResponseType.Close); - this.Response += new ResponseHandler (ResponseCallback); - - this.ShowAll (); + ShowAll (); } - // Convenience function to create an option menu holding a number of strings - private ComboBox CreateOptionMenu (string [] strings) + // Convenience function to create a combo box holding a number of strings + private ComboBox CreateComboBox (string [] strings) { ComboBox combo = ComboBox.NewText (); @@ -104,29 +92,26 @@ namespace GtkDemo table.Attach (label, 0, 1, row, row + 1, - AttachOptions.Expand, AttachOptions.Fill, + AttachOptions.Expand | AttachOptions.Fill, 0, 0, 0); - ComboBox combo = CreateOptionMenu (options); + ComboBox combo = CreateComboBox (options); + label.MnemonicWidget = combo; sizeGroup.AddWidget (combo); table.Attach (combo, 1, 2, row, row + 1, - AttachOptions.Expand, AttachOptions.Expand, + 0, 0, 0, 0); } - private void ButtonToggleCb (object o, EventArgs args) + private void ToggleGrouping (object o, EventArgs args) { - ToggleGrouping ((ToggleButton) o, sizeGroup); - } + ToggleButton checkButton = (ToggleButton)o; - // SizeGroupMode.None is not generally useful, but is useful - // here to show the effect of SizeGroupMode.Horizontal by - // contrast - - private void ToggleGrouping (ToggleButton checkButton, SizeGroup sizeGroup) - { + // SizeGroupMode.None is not generally useful, but is useful + // here to show the effect of SizeGroupMode.Horizontal by + // contrast SizeGroupMode mode; if (checkButton.Active) @@ -137,13 +122,9 @@ namespace GtkDemo sizeGroup.Mode = mode; } - private void ResponseCallback (object obj, ResponseArgs args) + protected override void OnResponse (Gtk.ResponseType responseId) { - if ((args.ResponseId) == ResponseType.Close) { - this.Hide (); - this.Destroy (); - } + Destroy (); } - } } diff --git a/sample/GtkDemo/DemoStockBrowser.cs b/sample/GtkDemo/DemoStockBrowser.cs index 042f13160..9316fde19 100644 --- a/sample/GtkDemo/DemoStockBrowser.cs +++ b/sample/GtkDemo/DemoStockBrowser.cs @@ -1,10 +1,3 @@ -// -// StockBrowser.cs, port of stock_browser.c from gtk-demo -// -// Author: Daniel Kornhauser -// -// (C) 2003 Ximian, Inc. - /* Stock Item and Icon Browser * * This source code for this demo doesn't demonstrate anything @@ -15,214 +8,190 @@ using System; using System.Collections; +using System.Reflection; using Gtk; namespace GtkDemo -{ +{ [Demo ("Stock Item and Icon Browser", "DemoStockBrowser.cs")] public class DemoStockBrowser : Gtk.Window { - class StockInfo + enum Column { + Id, + Name, + Label, + Accel, + }; + + Label typeLabel, nameLabel, idLabel, accelLabel; + Image iconImage; + + public DemoStockBrowser () : base ("Stock Icons and Items") { - internal string Name; - internal string Label; - internal string Accel; - internal string ID; - internal Gdk.Pixbuf Icon; - } - - // in a real application this would be - // split into its own file - class StockFrame : Gtk.Frame - { - StockInfo info; - Label category; - Label name; - Label id; - Label label; - Image icon; - - internal StockFrame () : base ("Selected Item") - { - this.SetSizeRequest (200, -1); - // Icon and Item / Icon Only / ??? - category = new Label ("???"); - // icon / blank - icon = new Image (""); - // _Add / blank - label = new Label (); - label.UseUnderline = true; - // Gtk.Stock.Cancel - name = new Label (); - // gtk-stock-cancel - id = new Label (); - - VBox vbox = new VBox (false, 3); - vbox.PackStart (category, false, true, 0); - vbox.PackStart (icon, false, true, 0); - vbox.PackStart (label, false, true, 0); - vbox.PackStart (name, false, true, 0); - vbox.PackStart (id, false, true, 0); - - this.Add (vbox); - this.ShowAll (); - } - - internal StockInfo Info - { - get { return info; } - set { - info = value; - name.Text = info.Name; - label.Text = info.Label; - id.Text = info.ID; - icon.Pixbuf = info.Icon; - } - } - } - - StockFrame stockFrame; - - public DemoStockBrowser () : base ("Stock Item Browser Demo") - { - this.SetDefaultSize (600, 400); - this.DeleteEvent += new DeleteEventHandler (WindowDelete); - this.BorderWidth = 8; + SetDefaultSize (-1, 500); + BorderWidth = 8; HBox hbox = new HBox (false, 8); - this.Add (hbox); + Add (hbox); - ScrolledWindow scrolledWindow = new ScrolledWindow (null, null); - scrolledWindow.SetPolicy (PolicyType.Never, PolicyType.Automatic); - hbox.PackStart (scrolledWindow, true, true, 0); - - TreeView list = new TreeView (); - list.AppendColumn ("Icon", new CellRendererPixbuf (), "pixbuf", 0); - list.AppendColumn ("Name", new CellRendererText (), "text", 1); - list.AppendColumn ("Label", new CellRendererText (), "text", 2); - list.AppendColumn ("Accel", new CellRendererText (), "text", 3); - list.AppendColumn ("ID", new CellRendererText (), "text", 4); - list.Model = CreateStore (); + ScrolledWindow sw = new ScrolledWindow (); + sw.SetPolicy (PolicyType.Never, PolicyType.Automatic); + hbox.PackStart (sw, false, false, 0); - list.Selection.Changed += new EventHandler (OnSelectionChanged); - scrolledWindow.Add (list); - - stockFrame = new StockFrame (); - hbox.PackStart (stockFrame, false, false, 0); - - this.ShowAll (); - } + ListStore model = CreateModel (); - private ListStore CreateStore () + TreeView treeview = new TreeView (model); + sw.Add (treeview); + + TreeViewColumn column = new TreeViewColumn (); + column.Title = "Name"; + CellRenderer renderer = new CellRendererPixbuf (); + column.PackStart (renderer, false); + column.SetAttributes (renderer, "stock_id", Column.Id); + renderer = new CellRendererText (); + column.PackStart (renderer, true); + column.SetAttributes (renderer, "text", Column.Name); + + treeview.AppendColumn (column); + treeview.AppendColumn ("Label", new CellRendererText (), "text", Column.Label); + treeview.AppendColumn ("Accel", new CellRendererText (), "text", Column.Accel); + treeview.AppendColumn ("ID", new CellRendererText (), "text", Column.Id); + + Alignment align = new Alignment (0.5f, 0.0f, 0.0f, 0.0f); + hbox.PackEnd (align, false, false, 0); + + Frame frame = new Frame ("Selected Item"); + align.Add (frame); + + VBox vbox = new VBox (false, 8); + vbox.BorderWidth = 8; + frame.Add (vbox); + + typeLabel = new Label (); + vbox.PackStart (typeLabel, false, false, 0); + iconImage = new Gtk.Image (); + vbox.PackStart (iconImage, false, false, 0); + accelLabel = new Label (); + vbox.PackStart (accelLabel, false, false, 0); + nameLabel = new Label (); + vbox.PackStart (nameLabel, false, false, 0); + idLabel = new Label (); + vbox.PackStart (idLabel, false, false, 0); + + treeview.Selection.Mode = Gtk.SelectionMode.Single; + treeview.Selection.Changed += new EventHandler (SelectionChanged); + + ShowAll (); + } + + private ListStore CreateModel () { - // FIXME: tremendous duplication of info - // image, name, label, accel, id, StockInfo - ListStore store = new Gtk.ListStore (typeof (Gdk.Pixbuf), typeof(string), typeof(string), typeof(string), typeof (string), typeof (StockInfo)); + ListStore store = new Gtk.ListStore (typeof (string), typeof(string), typeof(string), typeof(string), typeof (string)); - string[] stock_ids = Gtk.Stock.ListIds (); + string[] stockIds = Gtk.Stock.ListIds (); + Array.Sort (stockIds); - foreach (string s in stock_ids) - { - Gtk.StockItem si; - si = Gtk.Stock.Lookup (s); - if (si.StockId != null) { - Gdk.Pixbuf icon = this.RenderIcon (s, IconSize.Menu, ""); - StockInfo info = new StockInfo (); - info.Icon = icon; - info.Name = GetCLSName (si.StockId); - info.Label = si.Label; - info.Accel = GetKeyName (si); - info.ID = si.StockId; - - // FIXME: si.Label needs to _AccelAware - store.AppendValues (icon, GetCLSName (si.StockId), si.Label, GetKeyName (si), si.StockId, info); - } - else { - //Console.WriteLine ("StockItem '{0}' could not be found.", s); - } + // Use reflection to get the list of C# names + Hashtable idToName = new Hashtable (); + foreach (PropertyInfo info in typeof (Gtk.Stock).GetProperties (BindingFlags.Public | BindingFlags.Static)) { + if (info.PropertyType == typeof (string)) + idToName[info.GetValue (null, null)] = "Gtk.Stock." + info.Name; } - + + foreach (string id in stockIds) { + Gtk.StockItem si; + string accel; + + si = Gtk.Stock.Lookup (id); + if (si.Keyval != 0) + accel = Accelerator.Name (si.Keyval, si.Modifier); + else + accel = ""; + + store.AppendValues (id, idToName[id], si.Label, accel); + } + return store; } - // changes 'gtk-stock-close' into 'Gtk.Stock.Close' - // should use StudlyCaps from gapi2xml.pl instead - string GetCLSName (string stockID) - { - string cls = ""; - if (stockID.StartsWith ("gtk-")) - cls = stockID.Substring (4, stockID.Length - 4); - - char[] split = cls.ToCharArray (); - bool raiseNext = false; - ArrayList tmp = new ArrayList (); - tmp.Add (char.ToUpper (split[0])); - - for (int i = 1; i < split.Length; i ++) - { - if (split[i] == '-') { - raiseNext = true; - continue; - } - - if (raiseNext) { - tmp.Add (char.ToUpper (split[i])); - raiseNext = false; - } - else { - tmp.Add (split[i]); - } - } - - split = new char[tmp.Count]; - int j = 0; - foreach (char c in tmp) - split[j++] = c; - - return "Gtk.Stock." + new string (split); - } - - // use si.Keyval and si.Modifier - // to produce a reasonable representation - // of the key binding - string GetKeyName (StockItem si) - { - string mod = ""; - string key = ""; - - switch (si.Modifier) { - // seems to be the only one used - case Gdk.ModifierType.ControlMask: - mod = ""; - break; - default: - break; - } - - if (si.Keyval > 0) - key = Gdk.Keyval.Name (si.Keyval); - - return String.Format ("{0} {1}", mod, key); - } - - void OnSelectionChanged (object o, EventArgs args) + void SelectionChanged (object o, EventArgs args) { + TreeSelection selection = (TreeSelection)o; TreeIter iter; TreeModel model; - if (((TreeSelection) o).GetSelected (out model, out iter)) - { - StockInfo info = (StockInfo) model.GetValue (iter, 5); - stockFrame.Info = info; + if (selection.GetSelected (out model, out iter)) { + string id = (string) model.GetValue (iter, (int)Column.Id); + string name = (string) model.GetValue (iter, (int)Column.Name); + string label = (string) model.GetValue (iter, (int)Column.Label); + string accel = (string) model.GetValue (iter, (int)Column.Accel); + + IconSize size = GetLargestSize (id); + bool icon = (size != IconSize.Invalid); + + if (icon && label != null) + typeLabel.Text = "Icon and Item"; + else if (icon) + typeLabel.Text = "Icon Only"; + else if (label != null) + typeLabel.Text = "Item Only"; + else + typeLabel.Text = "???????"; + + if (name != null) + nameLabel.Text = name; + else + nameLabel.Text = ""; + + idLabel.Text = id; + + if (label != null) + accelLabel.TextWithMnemonic = label + " " + accel; + else + accelLabel.Text = ""; + + if (icon) + iconImage.SetFromStock (id, size); + else + iconImage.Pixbuf = null; + } else { + typeLabel.Text = "No selected item"; + nameLabel.Text = ""; + idLabel.Text = ""; + accelLabel.Text = ""; + iconImage.Pixbuf = null; } } - - private void WindowDelete (object o, DeleteEventArgs args) + + // Finds the largest size at which the given image stock id is + // available. This would not be useful for a normal application + + private IconSize GetLargestSize (string stockId) { - this.Hide (); - this.Destroy (); - args.RetVal = true; + IconSet set = IconFactory.LookupDefault (stockId); + if (set == null) + return IconSize.Invalid; + + IconSize[] sizes = set.Sizes; + IconSize bestSize = IconSize.Invalid; + int bestPixels = 0; + + foreach (IconSize size in sizes) { + int width, height; + Gtk.Icon.SizeLookup (size, out width, out height); + if (width * height > bestPixels) { + bestSize = size; + bestPixels = width * height; + } + } + + return bestSize; + } + + protected override bool OnDeleteEvent (Gdk.Event evt) + { + Destroy (); + return true; } } } - diff --git a/sample/GtkDemo/DemoTextView.cs b/sample/GtkDemo/DemoTextView.cs index 0544a787e..b6afb851b 100644 --- a/sample/GtkDemo/DemoTextView.cs +++ b/sample/GtkDemo/DemoTextView.cs @@ -1,11 +1,4 @@ -// -// DemoTextView.cs, port of textview.c form gtk-demo -// -// Author: Daniel Kornhauser -// -// (C) 2003 Ximian, Inc. - -/* Text Widget +/* Text Widget/Multiple Views * * The Gtk.TextView widget displays a Gtk.TextBuffer. One Gtk.TextBuffer * can be displayed by multiple Gtk.TextViews. This demo has two views @@ -27,44 +20,39 @@ namespace GtkDemo TextView view1; TextView view2; - public DemoTextView () : base ("TextView Demo") - { - this.DeleteEvent += new DeleteEventHandler (WindowDelete); - this.SetDefaultSize (450,450); - this.BorderWidth = 6; + public DemoTextView () : base ("TextView") + { + SetDefaultSize (450,450); + BorderWidth = 0; VPaned vpaned = new VPaned (); vpaned.BorderWidth = 5; - this.Add (vpaned); + Add (vpaned); - /* For convenience, we just use the autocreated buffer from - * the first text view; you could also create the buffer - * by itself with new Gtk.TextBuffer (), then later create - * a view widget. - */ + // For convenience, we just use the autocreated buffer from + // the first text view; you could also create the buffer + // by itself, then later create a view widget. view1 = new TextView (); TextBuffer buffer = view1.Buffer; - view2 = new TextView(buffer); + view2 = new TextView (buffer); - ScrolledWindow scrolledWindow = new ScrolledWindow (); - scrolledWindow.SetPolicy (PolicyType.Automatic, Gtk.PolicyType.Automatic); - vpaned.Add1 (scrolledWindow); - scrolledWindow.Add (view1); + ScrolledWindow sw = new ScrolledWindow (); + sw.SetPolicy (PolicyType.Automatic, PolicyType.Automatic); + vpaned.Add1 (sw); + sw.Add (view1); - scrolledWindow = new Gtk.ScrolledWindow (); - scrolledWindow.SetPolicy (Gtk.PolicyType.Automatic, Gtk.PolicyType.Automatic); - vpaned.Add2 (scrolledWindow); - scrolledWindow.Add (view2); + sw = new ScrolledWindow (); + sw.SetPolicy (PolicyType.Automatic, PolicyType.Automatic); + vpaned.Add2 (sw); + sw.Add (view2); CreateTags (buffer); - InsertText(buffer); + InsertText (buffer); - AttachWidgets(view1); - AttachWidgets(view2); + AttachWidgets (view1); + AttachWidgets (view2); - vpaned.ShowAll(); - - this.ShowAll (); + ShowAll (); } private TextChildAnchor buttonAnchor; @@ -75,6 +63,9 @@ namespace GtkDemo private void AttachWidgets (TextView textView) { + // This is really different from the C version, but the + // C versions seems a little pointless. + Button button = new Button ("Click Me"); button.Clicked += new EventHandler(EasterEggCB); textView.AddChildAtAnchor (button, buttonAnchor); @@ -84,7 +75,6 @@ namespace GtkDemo combo.AppendText ("Option 1"); combo.AppendText ("Option 2"); combo.AppendText ("Option 3"); - combo.Active = 0; textView.AddChildAtAnchor (combo, menuAnchor); @@ -94,7 +84,7 @@ namespace GtkDemo textView.AddChildAtAnchor (scale, scaleAnchor); scale.ShowAll (); - Gtk.Image image = new Gtk.Image (Gdk.Pixbuf.LoadFromResource ("floppybuddy.gif")); + Gtk.Image image = Gtk.Image.LoadFromResource ("floppybuddy.gif"); textView.AddChildAtAnchor (image, animationAnchor); image.ShowAll (); @@ -103,26 +93,29 @@ namespace GtkDemo entry.ShowAll (); } + const int gray50_width = 2; + const int gray50_height = 2; + const string gray50_bits = "\x02\x01"; + private void CreateTags (TextBuffer buffer) { - /* Create a bunch of tags. Note that it's also possible to - * create tags with gtk_text_tag_new() then add them to the - * tag table for the buffer, gtk_text_buffer_create_tag() is - * just a convenience function. Also note that you don't have - * to give tags a name; pass NULL for the name to create an - * anonymous tag. - * - * In any real app, another useful optimization would be to create - * a GtkTextTagTable in advance, and reuse the same tag table for - * all the buffers with the same tag set, instead of creating - * new copies of the same tags for every buffer. - * - * Tags are assigned default priorities in order of addition to the - * tag table. That is, tags created later that affect the same text - * property affected by an earlier tag will override the earlier - * tag. You can modify tag priorities with - * gtk_text_tag_set_priority(). - */ + // Create a bunch of tags. Note that it's also possible to + // create tags with gtk_text_tag_new() then add them to the + // tag table for the buffer, gtk_text_buffer_create_tag() is + // just a convenience function. Also note that you don't have + // to give tags a name; pass NULL for the name to create an + // anonymous tag. + // + // In any real app, another useful optimization would be to create + // a GtkTextTagTable in advance, and reuse the same tag table for + // all the buffers with the same tag set, instead of creating + // new copies of the same tags for every buffer. + // + // Tags are assigned default priorities in order of addition to the + // tag table. That is, tags created later that affect the same text + // property affected by an earlier tag will override the earlier + // tag. You can modify tag priorities with + // gtk_text_tag_set_priority(). TextTag tag = new TextTag ("heading"); tag.Weight = Pango.Weight.Bold; @@ -142,11 +135,11 @@ namespace GtkDemo buffer.TagTable.Add (tag); tag = new TextTag ("xx-small"); - tag.Scale = Pango.Scale.XX_Small; + tag.Scale = Pango.Scale.XX_Small; buffer.TagTable.Add (tag); tag = new TextTag ("x-large"); - tag.Scale = Pango.Scale.X_Large; + tag.Scale = Pango.Scale.X_Large; buffer.TagTable.Add (tag); tag = new TextTag ("monospace"); @@ -161,22 +154,18 @@ namespace GtkDemo tag.Background = "red"; buffer.TagTable.Add (tag); - int gray50_width = 2; - int gray50_height = 2; - string gray50_bits = new string ((char) 0x02, (char) 0x01); - // The C gtk-demo passes NULL for the drawable param, which isn't // multi-head safe, so it seems bad to allow it in the C# API. // But the Window isn't realized at this point, so we can't get // an actual Drawable from it. So we kludge for now. - Pixmap stipple = Pixmap.CreateBitmapFromData (Gdk.Screen.Default.RootWindow, (string) gray50_bits, gray50_width, gray50_height); - + Pixmap stipple = Pixmap.CreateBitmapFromData (Gdk.Screen.Default.RootWindow, gray50_bits, gray50_width, gray50_height); + tag = new TextTag ("background_stipple"); tag.BackgroundStipple = stipple; buffer.TagTable.Add (tag); tag = new TextTag ("foreground_stipple"); - tag.ForegroundStipple = stipple; + tag.ForegroundStipple = stipple; buffer.TagTable.Add (tag); tag = new TextTag ("big_gap_before_line"); @@ -246,28 +235,25 @@ namespace GtkDemo tag.WrapMode = WrapMode.Word; tag.Direction = TextDirection.Rtl; tag.Indent = 30; - tag.LeftMargin = 20; + tag.LeftMargin = 20; tag.RightMargin = 20; buffer.TagTable.Add (tag); - } + } private void InsertText (TextBuffer buffer) { - // we use resources for portability and convenience Pixbuf pixbuf = Gdk.Pixbuf.LoadFromResource ("gtk-logo-rgb.gif"); - pixbuf.ScaleSimple (32, 32, InterpType.Bilinear); + pixbuf = pixbuf.ScaleSimple (32, 32, InterpType.Bilinear); - /* get start of buffer; each insertion will revalidate the - * iterator to point to just after the inserted text. - */ + // get start of buffer; each insertion will revalidate the + // iterator to point to just after the inserted text. - TextIter insertIter; - - insertIter = buffer.GetIterAtOffset (0); + TextIter insertIter = buffer.StartIter; buffer.Insert (ref insertIter, - "The text widget can display text with all kinds of nifty attributes.It also supports multiple views of the same buffer; this demo is showing the same buffer in two places.\n\n"); + "The text widget can display text with all kinds of nifty attributes. It also supports multiple views of the same buffer; this demo is showing the same buffer in two places.\n\n"); buffer.InsertWithTagsByName (ref insertIter, "Font styles. ", "heading"); + buffer.Insert (ref insertIter, "For example, you can have "); buffer.InsertWithTagsByName (ref insertIter, "italic", "italic"); buffer.Insert (ref insertIter, ", "); @@ -276,150 +262,168 @@ namespace GtkDemo buffer.InsertWithTagsByName (ref insertIter, "monospace (typewriter)", "monospace"); buffer.Insert (ref insertIter, ", or "); buffer.InsertWithTagsByName (ref insertIter, "big", "big"); - buffer.Insert (ref insertIter, " text"); + buffer.Insert (ref insertIter, " text. "); buffer.Insert (ref insertIter, - "It's best not to hardcode specific text sizes; you can use relative sizes as with CSS, such as "); + "It's best not to hardcode specific text sizes; you can use relative sizes as with CSS, such as "); buffer.InsertWithTagsByName (ref insertIter, "xx-small", "xx-small"); - buffer.Insert (ref insertIter, ", or"); + buffer.Insert (ref insertIter, " or"); buffer.InsertWithTagsByName (ref insertIter, "x-large", "x-large"); buffer.Insert (ref insertIter, - " to ensure that your program properly adapts if the user changes the default font size.\n\n"); - buffer.InsertWithTagsByName (ref insertIter, "Colors such as", "heading"); + " to ensure that your program properly adapts if the user changes the default font size.\n\n"); + + buffer.InsertWithTagsByName (ref insertIter, "Colors. ", "heading"); + + buffer.Insert (ref insertIter, "Colors such as "); buffer.InsertWithTagsByName (ref insertIter, "a blue foreground", "blue_foreground"); - buffer.Insert (ref insertIter, ", or "); + buffer.Insert (ref insertIter, " or "); buffer.InsertWithTagsByName (ref insertIter, "a red background", "red_background"); - buffer.Insert (ref insertIter, " or even "); + buffer.Insert (ref insertIter, " or even "); buffer.InsertWithTagsByName (ref insertIter, "a stippled red background", "red_background", "background_stipple"); - buffer.Insert (ref insertIter, ", or "); + + buffer.Insert (ref insertIter, " or "); buffer.InsertWithTagsByName (ref insertIter, "a stippled blue foreground on solid red background", "blue_foreground", "red_background", "foreground_stipple"); buffer.Insert (ref insertIter, " (select that to read it) can be used.\n\n"); + buffer.InsertWithTagsByName (ref insertIter, "Underline, strikethrough, and rise. ", "heading"); + buffer.InsertWithTagsByName (ref insertIter, "Strikethrough", "strikethrough"); buffer.Insert (ref insertIter, ", "); buffer.InsertWithTagsByName (ref insertIter, "underline", "underline"); buffer.Insert (ref insertIter, ", "); - buffer.InsertWithTagsByName (ref insertIter, "double_underline", "double_underline"); + buffer.InsertWithTagsByName (ref insertIter, "double underline", "double_underline"); buffer.Insert (ref insertIter, ", "); buffer.InsertWithTagsByName (ref insertIter, "superscript", "superscript"); - buffer.Insert (ref insertIter, ", and "); + buffer.Insert (ref insertIter, ", and "); buffer.InsertWithTagsByName (ref insertIter, "subscript", "subscript"); buffer.Insert (ref insertIter, " are all supported.\n\n"); - buffer.InsertWithTagsByName (ref insertIter, "Images. ", "heading"); - buffer.Insert (ref insertIter, "The buffer can have images in it: "); - - insertIter = buffer.GetIterAtMark (buffer.InsertMark); - buffer.InsertPixbuf (ref insertIter, pixbuf); - insertIter = buffer.GetIterAtMark (buffer.InsertMark); - buffer.InsertPixbuf (ref insertIter, pixbuf); - insertIter = buffer.GetIterAtMark (buffer.InsertMark); - buffer.InsertPixbuf (ref insertIter, pixbuf); + buffer.InsertWithTagsByName (ref insertIter, "Images. ", "heading"); + + buffer.Insert (ref insertIter, "The buffer can have images in it: "); + + buffer.InsertPixbuf (ref insertIter, pixbuf); + buffer.InsertPixbuf (ref insertIter, pixbuf); + buffer.InsertPixbuf (ref insertIter, pixbuf); buffer.Insert (ref insertIter, " for example.\n\n"); + buffer.InsertWithTagsByName (ref insertIter, "Spacing. ", "heading"); - buffer.InsertWithTagsByName (ref insertIter, "You can adjust the amount of space before each line.\n", "big_gap_before_line", "wide_margins"); - buffer.InsertWithTagsByName (ref insertIter, "You can also adjust the amount of space after each line; this line has a whole lot of space after it.\n", "big_gap_after_line", "wide_margins"); - buffer.InsertWithTagsByName (ref insertIter, "You can also adjust the amount of space between wrapped lines; this line has extra space between each wrapped line in the same paragraph. To show off wrapping, some filler text: the quick brown fox jumped over the lazy dog. Blah blah blah blah blah blah blah blah blah.\n", "double_spaced_line", "wide_margins"); + + buffer.Insert (ref insertIter, "You can adjust the amount of space before each line.\n"); + buffer.InsertWithTagsByName (ref insertIter, "This line has a whole lot of space before it.\n", + "big_gap_before_line", "wide_margins"); + buffer.InsertWithTagsByName (ref insertIter, "You can also adjust the amount of space after each line; this line has a whole lot of space after it.\n", + "big_gap_after_line", "wide_margins"); + + buffer.InsertWithTagsByName (ref insertIter, "You can also adjust the amount of space between wrapped lines; this line has extra space between each wrapped line in the same paragraph. To show off wrapping, some filler text: the quick brown fox jumped over the lazy dog. Blah blah blah blah blah blah blah blah blah.\n", + "double_spaced_line", "wide_margins"); + buffer.Insert (ref insertIter, "Also note that those lines have extra-wide margins.\n\n"); + buffer.InsertWithTagsByName (ref insertIter, "Editability. ", "heading"); - buffer.InsertWithTagsByName (ref insertIter, "This line is 'locked down' and can't be edited by the user - just try it! You can't delete this line.\n\n", "not_editable"); + + buffer.InsertWithTagsByName (ref insertIter, "This line is 'locked down' and can't be edited by the user - just try it! You can't delete this line.\n\n", + "not_editable"); + buffer.InsertWithTagsByName (ref insertIter, "Wrapping. ", "heading"); + buffer.Insert (ref insertIter, "This line (and most of the others in this buffer) is word-wrapped, using the proper Unicode algorithm. Word wrap should work in all scripts and languages that GTK+ supports. Let's make this a long paragraph to demonstrate: blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah\n\n"); - buffer.InsertWithTagsByName (ref insertIter, "This line has character-based wrapping, and can wrap between any two character glyphs. Let's make this a long paragraph to demonstrate: blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah\n\n", "char_wrap"); - buffer.InsertWithTagsByName (ref insertIter, "This line has all wrapping turned off, so it makes the horizontal scrollbar appear.\n\n\n", "no_wrap"); + + buffer.InsertWithTagsByName (ref insertIter, "This line has character-based wrapping, and can wrap between any two character glyphs. Let's make this a long paragraph to demonstrate: blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah\n\n", + "char_wrap"); + + buffer.InsertWithTagsByName (ref insertIter, "This line has all wrapping turned off, so it makes the horizontal scrollbar appear.\n\n\n", + "no_wrap"); + buffer.InsertWithTagsByName (ref insertIter, "Justification. ", "heading"); + + buffer.InsertWithTagsByName (ref insertIter, "\nThis line has center justification.\n", "center"); + buffer.InsertWithTagsByName (ref insertIter, "This line has right justification.\n", "right_justify"); - buffer.InsertWithTagsByName (ref insertIter, "\nThis line has big wide margins. Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.\n", "wide_margins"); + + buffer.InsertWithTagsByName (ref insertIter, "\nThis line has big wide margins. Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.\n", + "wide_margins"); + buffer.InsertWithTagsByName (ref insertIter, "Internationalization. ", "heading"); buffer.Insert (ref insertIter, "You can put all sorts of Unicode text in the buffer.\n\nGerman (Deutsch S\u00fcd) Gr\u00fc\u00df Gott\nGreek (\u0395\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03ac) \u0393\u03b5\u03b9\u03ac \u03c3\u03b1\u03c2\nHebrew \u05e9\u05dc\u05d5\u05dd\nJapanese (\u65e5\u672c\u8a9e)\n\nThe widget properly handles bidirectional text, word wrapping, DOS/UNIX/Unicode paragraph separators, grapheme boundaries, and so on using the Pango internationalization framework.\n"); - buffer.Insert (ref insertIter, "Here's a word-wrapped quote in a right-to-left language:\n"); + buffer.Insert (ref insertIter, "Here's a word-wrapped quote in a right-to-left language:\n"); buffer.InsertWithTagsByName (ref insertIter, "\u0648\u0642\u062f \u0628\u062f\u0623 \u062b\u0644\u0627\u062b \u0645\u0646 \u0623\u0643\u062b\u0631 \u0627\u0644\u0645\u0624\u0633\u0633\u0627\u062a \u062a\u0642\u062f\u0645\u0627 \u0641\u064a \u0634\u0628\u0643\u0629 \u0627\u0643\u0633\u064a\u0648\u0646 \u0628\u0631\u0627\u0645\u062c\u0647\u0627 \u0643\u0645\u0646\u0638\u0645\u0627\u062a \u0644\u0627 \u062a\u0633\u0639\u0649 \u0644\u0644\u0631\u0628\u062d\u060c \u062b\u0645 \u062a\u062d\u0648\u0644\u062a \u0641\u064a \u0627\u0644\u0633\u0646\u0648\u0627\u062a \u0627\u0644\u062e\u0645\u0633 \u0627\u0644\u0645\u0627\u0636\u064a\u0629 \u0625\u0644\u0649 \u0645\u0624\u0633\u0633\u0627\u062a \u0645\u0627\u0644\u064a\u0629 \u0645\u0646\u0638\u0645\u0629\u060c \u0648\u0628\u0627\u062a\u062a \u062c\u0632\u0621\u0627 \u0645\u0646 \u0627\u0644\u0646\u0638\u0627\u0645 \u0627\u0644\u0645\u0627\u0644\u064a \u0641\u064a \u0628\u0644\u062f\u0627\u0646\u0647\u0627\u060c \u0648\u0644\u0643\u0646\u0647\u0627 \u062a\u062a\u062e\u0635\u0635 \u0641\u064a \u062e\u062f\u0645\u0629 \u0642\u0637\u0627\u0639 \u0627\u0644\u0645\u0634\u0631\u0648\u0639\u0627\u062a \u0627\u0644\u0635\u063a\u064a\u0631\u0629\u002e \u0648\u0623\u062d\u062f \u0623\u0643\u062b\u0631 \u0647\u0630\u0647 \u0627\u0644\u0645\u0624\u0633\u0633\u0627\u062a \u0646\u062c\u0627\u062d\u0627 \u0647\u0648 \u00bb\u0628\u0627\u0646\u0643\u0648\u0633\u0648\u0644\u00ab \u0641\u064a \u0628\u0648\u0644\u064a\u0641\u064a\u0627.\n\n", "rtl_quote"); buffer.Insert (ref insertIter, "You can put widgets in the buffer: Here's a button: "); - insertIter = buffer.GetIterAtMark(buffer.InsertMark); - buttonAnchor = buffer.CreateChildAnchor (ref insertIter); - - buffer.Insert (ref insertIter, "and a menu"); - insertIter = buffer.GetIterAtMark(buffer.InsertMark); - menuAnchor = buffer.CreateChildAnchor (ref insertIter); - - buffer.Insert (ref insertIter, "and a scale"); - insertIter = buffer.GetIterAtMark(buffer.InsertMark); - scaleAnchor = buffer.CreateChildAnchor (ref insertIter); - - buffer.Insert (ref insertIter, "and an animation"); - insertIter = buffer.GetIterAtMark(buffer.InsertMark); + buttonAnchor = buffer.CreateChildAnchor (ref insertIter); + buffer.Insert (ref insertIter, " and a menu: "); + menuAnchor = buffer.CreateChildAnchor (ref insertIter); + buffer.Insert (ref insertIter, " and a scale: "); + scaleAnchor = buffer.CreateChildAnchor (ref insertIter); + buffer.Insert (ref insertIter, " and an animation: "); animationAnchor = buffer.CreateChildAnchor (ref insertIter); - buffer.Insert (ref insertIter, " finally a text entry: "); - insertIter = buffer.GetIterAtMark(buffer.InsertMark); - entryAnchor = buffer.CreateChildAnchor (ref insertIter); - - buffer.Insert (ref insertIter, "\n"); + entryAnchor = buffer.CreateChildAnchor (ref insertIter); + buffer.Insert (ref insertIter, ".\n"); buffer.Insert (ref insertIter, "\n\nThis demo doesn't demonstrate all the GtkTextBuffer features; it leaves out, for example: invisible/hidden text (doesn't work in GTK 2, but planned), tab stops, application-drawn areas on the sides of the widget for displaying breakpoints and such..."); - buffer.ApplyTag("word_wrap", buffer.StartIter, buffer.EndIter); - + buffer.ApplyTag ("word_wrap", buffer.StartIter, buffer.EndIter); } - private void WindowDelete (object o, DeleteEventArgs args) + protected override bool OnDeleteEvent (Gdk.Event evt) { - this.Hide (); - this.Destroy (); - args.RetVal = true; + Destroy (); + return true; } - private void RecursiveAttach (int depth, TextView view, TextChildAnchor anchor) + private void RecursiveAttach (int depth, TextView view, TextChildAnchor anchor) { - if (depth > 4) - return; + if (depth > 4) + return; - TextView childView = new TextView (view.Buffer); - /* Event box is to add a black border around each child view */ - EventBox eventBox = new EventBox (); - Gdk.Color blackColor = new Gdk.Color (0x0, 0x0, 0x0); - eventBox.ModifyBg (StateType.Normal,blackColor); - - Alignment align = new Alignment (0.5f, 0.5f, 1.0f, 1.0f); - align.BorderWidth = 1; + TextView childView = new TextView (view.Buffer); - eventBox.Add (align); - align.Add (childView); + // Event box is to add a black border around each child view + EventBox eventBox = new EventBox (); + Gdk.Color color = new Gdk.Color (); + Gdk.Color.Parse ("black", ref color); + eventBox.ModifyBg (StateType.Normal, color); - view.AddChildAtAnchor (eventBox, anchor); + Alignment align = new Alignment (0.5f, 0.5f, 1.0f, 1.0f); + align.BorderWidth = 1; - RecursiveAttach (depth+1, childView, anchor); + eventBox.Add (align); + align.Add (childView); + + view.AddChildAtAnchor (eventBox, anchor); + + RecursiveAttach (depth+1, childView, anchor); } - + private void EasterEggCB (object o, EventArgs args) { TextIter insertIter; - TextBuffer bufferCB = new TextBuffer (null); - insertIter = bufferCB.GetIterAtOffset (0); - bufferCB.Insert (ref insertIter, "This buffer is shared by a set of nested text views.\n Nested view:\n"); - TextChildAnchor anchor = bufferCB.CreateChildAnchor (ref insertIter); - bufferCB.Insert (ref insertIter, "\nDon't do this in real applications, please.\n"); - TextView viewCB = new TextView (bufferCB); - - RecursiveAttach (0, viewCB, anchor); + TextBuffer buffer = new TextBuffer (null); + insertIter = buffer.StartIter; + buffer.Insert (ref insertIter, "This buffer is shared by a set of nested text views.\n Nested view:\n"); + TextChildAnchor anchor = buffer.CreateChildAnchor (ref insertIter); + buffer.Insert (ref insertIter, "\nDon't do this in real applications, please.\n"); + TextView view = new TextView (buffer); - Gtk.Window window = new Gtk.Window (null); - ScrolledWindow scrolledWindow = new ScrolledWindow (null, null); - scrolledWindow.SetPolicy (PolicyType.Automatic, PolicyType.Automatic); + RecursiveAttach (0, view, anchor); + + Gtk.Window window = new Gtk.Window (Gtk.WindowType.Toplevel); + ScrolledWindow sw = new ScrolledWindow (); + sw.SetPolicy (PolicyType.Automatic, PolicyType.Automatic); + + window.Add (sw); + sw.Add (view); - window.Add (scrolledWindow); - scrolledWindow.Add (viewCB); - window.SetDefaultSize (300, 400); window.ShowAll (); } diff --git a/sample/GtkDemo/DemoTreeStore.cs b/sample/GtkDemo/DemoTreeStore.cs index 483b21a33..102a2d8d3 100644 --- a/sample/GtkDemo/DemoTreeStore.cs +++ b/sample/GtkDemo/DemoTreeStore.cs @@ -1,10 +1,3 @@ -// -// DemoTreeItem.cs, port of tree_store.c from gtk-demo -// -// Author: Daniel Kornhauser -// -// Copyright (C) 2003, Ximian Inc. - /* Tree View/Tree Store * * The Gtk.TreeStore is used to store data in tree form, to be @@ -20,218 +13,216 @@ using System.Collections; using Gtk; using GLib; -namespace GtkDemo +namespace GtkDemo { [Demo ("TreeStore", "DemoTreeStore.cs", "Tree View")] public class DemoTreeStore : Gtk.Window { private TreeStore store; - public DemoTreeStore () : base ("TreeStore Demo") + public DemoTreeStore () : base ("Card planning sheet") { - this.DeleteEvent += new DeleteEventHandler (WindowDelete); - VBox vbox = new VBox (false, 8); vbox.BorderWidth = 8; - this.Add (vbox); + Add (vbox); - vbox.PackStart (new Label ("Jonathan's Holiday Card Planning Sheet"), false, false, 0); + vbox.PackStart (new Label ("Jonathan's Holiday Card Planning Sheet"), + false, false, 0); - ScrolledWindow scrolledWindow = new ScrolledWindow (); - scrolledWindow.ShadowType = ShadowType.EtchedIn; - scrolledWindow.SetPolicy (PolicyType.Automatic, PolicyType.Automatic); - vbox.PackStart (scrolledWindow, true, true, 0); + ScrolledWindow sw = new ScrolledWindow (); + sw.ShadowType = ShadowType.EtchedIn; + sw.SetPolicy (PolicyType.Automatic, PolicyType.Automatic); + vbox.PackStart (sw, true, true, 0); - // create model + // create model CreateModel (); - + // create tree view TreeView treeView = new TreeView (store); treeView.RulesHint = true; - TreeSelection treeSelection = treeView.Selection; - treeSelection.Mode = SelectionMode.Multiple; + treeView.Selection.Mode = SelectionMode.Multiple; AddColumns (treeView); - scrolledWindow.Add (treeView); + + sw.Add (treeView); // expand all rows after the treeview widget has been realized - for (int i = 0; i < 12; i++) - { - treeView.ExpandRow (new TreePath (i.ToString ()), false); - } + treeView.Realized += ExpandRows; - this.SetDefaultSize (650, 400); - this.ShowAll (); + SetDefaultSize (650, 400); + ShowAll (); } + private void ExpandRows (object obj, EventArgs args) + { + TreeView treeView = obj as TreeView; + + treeView.ExpandAll (); + } + + ArrayList columns = new ArrayList (); + private void ItemToggled (object sender, ToggledArgs args) { - CellRendererToggle cellRendererToggle = sender as CellRendererToggle; - int column = (int) cellRendererToggle.PersistentData["column"]; - + int column = columns.IndexOf (sender); + Gtk.TreeIter iter; - if (store.GetIterFromString (out iter, args.Path)) - { + if (store.GetIterFromString (out iter, args.Path)) { bool val = (bool) store.GetValue (iter, column); - Console.WriteLine ("toggled {0} with value {1}", args.Path, !val); store.SetValue (iter, column, !val); } } private void AddColumns (TreeView treeView) { + CellRendererText text; + CellRendererToggle toggle; + // column for holiday names - CellRendererText rendererText = new CellRendererText (); - rendererText.Xalign = 0.0f; - rendererText.PersistentData ["column"] = Column.HolidayName; - TreeViewColumn column = new TreeViewColumn ("Holiday", rendererText, - "text", Column.HolidayName); + text = new CellRendererText (); + text.Xalign = 0.0f; + columns.Add (text); + TreeViewColumn column = new TreeViewColumn ("Holiday", text, + "text", Column.HolidayName); treeView.InsertColumn (column, (int) Column.HolidayName); // alex column - CellRendererToggle rendererToggle = new CellRendererToggle (); - rendererToggle.Xalign = 0.0f; - rendererToggle.PersistentData ["column"] = Column.Alex; - rendererToggle.Toggled += new ToggledHandler (ItemToggled); - rendererToggle.Visible = true; - rendererToggle.Activatable = true; - rendererToggle.Active = true; - column = new TreeViewColumn ("Alex", rendererToggle, "active", (int) Column.Alex); + toggle = new CellRendererToggle (); + toggle.Xalign = 0.0f; + columns.Add (toggle); + toggle.Toggled += new ToggledHandler (ItemToggled); + column = new TreeViewColumn ("Alex", toggle, + "active", (int) Column.Alex, + "visible", (int) Column.Visible, + "activatable", (int) Column.World); column.Sizing = TreeViewColumnSizing.Fixed; column.FixedWidth = 50; column.Clickable = true; treeView.InsertColumn (column, (int) Column.Alex); // havoc column - rendererToggle = new CellRendererToggle (); - rendererToggle.Xalign = 0.0f; - rendererToggle.PersistentData ["column"] = Column.Havoc; - rendererToggle.Toggled += new ToggledHandler (ItemToggled); - column = new TreeViewColumn ("Havoc", rendererToggle, "active", (int) Column.Havoc); - column.Visible = true; - rendererToggle.Activatable = true; - rendererToggle.Active = true; + toggle = new CellRendererToggle (); + toggle.Xalign = 0.0f; + columns.Add (toggle); + toggle.Toggled += new ToggledHandler (ItemToggled); + column = new TreeViewColumn ("Havoc", toggle, + "active", (int) Column.Havoc, + "visible", (int) Column.Visible); treeView.InsertColumn (column, (int) Column.Havoc); column.Sizing = TreeViewColumnSizing.Fixed; column.FixedWidth = 50; column.Clickable = true; // tim column - rendererToggle = new CellRendererToggle (); - rendererToggle.Xalign = 0.0f; - rendererToggle.PersistentData ["column"] = Column.Tim; - rendererToggle.Toggled += new ToggledHandler (ItemToggled); - column = new TreeViewColumn ("Tim", rendererToggle, "active", (int) Column.Tim); - column.Visible = true; - rendererToggle.Activatable = true; - rendererToggle.Active = true; + toggle = new CellRendererToggle (); + toggle.Xalign = 0.0f; + columns.Add (toggle); + toggle.Toggled += new ToggledHandler (ItemToggled); + column = new TreeViewColumn ("Tim", toggle, + "active", (int) Column.Tim, + "visible", (int) Column.Visible, + "activatable", (int) Column.World); treeView.InsertColumn (column, (int) Column.Tim); column.Sizing = TreeViewColumnSizing.Fixed; column.FixedWidth = 50; column.Clickable = true; // owen column - rendererToggle = new CellRendererToggle (); - rendererToggle.Xalign = 0.0f; - rendererToggle.PersistentData ["column"] = Column.Owen; - rendererToggle.Toggled += new ToggledHandler (ItemToggled); - column = new TreeViewColumn ("Owen", rendererToggle, "active", (int) Column.Owen); - column.Visible = true; - rendererToggle.Activatable = true; - rendererToggle.Active = true; + toggle = new CellRendererToggle (); + toggle.Xalign = 0.0f; + columns.Add (toggle); + toggle.Toggled += new ToggledHandler (ItemToggled); + column = new TreeViewColumn ("Owen", toggle, + "active", (int) Column.Owen, + "visible", (int) Column.Visible); treeView.InsertColumn (column, (int) Column.Owen); column.Sizing = TreeViewColumnSizing.Fixed; column.FixedWidth = 50; column.Clickable = true; // dave column - rendererToggle = new CellRendererToggle (); - rendererToggle.Xalign = 0.0f; - rendererToggle.PersistentData ["column"] = Column.Dave; - rendererToggle.Toggled += new ToggledHandler (ItemToggled); - column = new TreeViewColumn ("Dave", rendererToggle, "active", (int) Column.Dave); - column.Visible = true; - rendererToggle.Activatable = true; - rendererToggle.Active = true; + toggle = new CellRendererToggle (); + toggle.Xalign = 0.0f; + columns.Add (toggle); + toggle.Toggled += new ToggledHandler (ItemToggled); + column = new TreeViewColumn ("Dave", toggle, + "active", (int) Column.Dave, + "visible", (int) Column.Visible); treeView.InsertColumn (column, (int) Column.Dave); column.Sizing = TreeViewColumnSizing.Fixed; column.FixedWidth = 50; column.Clickable = true; } - private void WindowDelete (object o, DeleteEventArgs args) + protected override bool OnDeleteEvent (Gdk.Event evt) { - this.Hide (); - this.Destroy (); - args.RetVal = true; + Destroy (); + return true; } private void CreateModel () { // create tree store - store = new TreeStore ( - typeof(string), - typeof(bool), - typeof(bool), - typeof(bool), - typeof(bool), - typeof(bool), - typeof(bool), - typeof(bool)); - - // add data to the tree store + store = new TreeStore (typeof (string), + typeof (bool), + typeof (bool), + typeof (bool), + typeof (bool), + typeof (bool), + typeof (bool), + typeof (bool)); - foreach (MyTreeItem month in toplevel) - { - TreeIter iter = store.AppendValues (month.Label, - false, - false, - false, - false, - false, - false, - false); - - foreach (MyTreeItem hollyday in month.Children) - { - store.AppendValues (iter, - hollyday.Label, - hollyday.Alex, - hollyday.Havoc, - hollyday.Tim, - hollyday.Owen, - hollyday.Dave, - true); + // add data to the tree store + foreach (MyTreeItem month in toplevel) { + TreeIter iter = store.AppendValues (month.Label, + false, + false, + false, + false, + false, + false, + false); + + foreach (MyTreeItem holiday in month.Children) { + store.AppendValues (iter, + holiday.Label, + holiday.Alex, + holiday.Havoc, + holiday.Tim, + holiday.Owen, + holiday.Dave, + true, + holiday.WorldHoliday); } } } - + // tree data - private static MyTreeItem[] january = - { - new MyTreeItem ("New Years Day", true, true, true, true, false, true, null ), - new MyTreeItem ("Presidential Inauguration", false, true, false, true, false, false, null ), - new MyTreeItem ("Martin Luther King Jr. day", false, true, false, true, false, false, null ) - }; + private static MyTreeItem[] january = + { + new MyTreeItem ("New Years Day", true, true, true, true, false, true, null ), + new MyTreeItem ("Presidential Inauguration", false, true, false, true, false, false, null ), + new MyTreeItem ("Martin Luther King Jr. day", false, true, false, true, false, false, null ) + }; private static MyTreeItem[] february = { new MyTreeItem ( "Presidents' Day", false, true, false, true, false, false, null ), new MyTreeItem ( "Groundhog Day", false, false, false, false, false, false, null ), - new MyTreeItem ( "Valentine's Day", false, false, false, false, true, true, null ) + new MyTreeItem ( "Valentine's Day", false, false, false, false, true, true, null ) }; private static MyTreeItem[] march = { new MyTreeItem ( "National Tree Planting Day", false, false, false, false, false, false, null ), - new MyTreeItem ( "St Patrick's Day", false, false, false, false, false, true, null ) + new MyTreeItem ( "St Patrick's Day", false, false, false, false, false, true, null ) }; - + private static MyTreeItem[] april = { new MyTreeItem ( "April Fools' Day", false, false, false, false, false, true, null ), new MyTreeItem ( "Army Day", false, false, false, false, false, false, null ), new MyTreeItem ( "Earth Day", false, false, false, false, false, true, null ), - new MyTreeItem ( "Administrative Professionals' Day", false, false, false, false, false, false, null ) + new MyTreeItem ( "Administrative Professionals' Day", false, false, false, false, false, false, null ) }; private static MyTreeItem[] may = @@ -240,34 +231,34 @@ namespace GtkDemo new MyTreeItem ( "National Day of Prayer", false, false, false, false, false, false, null ), new MyTreeItem ( "Mothers' Day", false, false, false, false, false, true, null ), new MyTreeItem ( "Armed Forces Day", false, false, false, false, false, false, null ), - new MyTreeItem ( "Memorial Day", true, true, true, true, false, true, null ) + new MyTreeItem ( "Memorial Day", true, true, true, true, false, true, null ) }; private static MyTreeItem[] june = { new MyTreeItem ( "June Fathers' Day", false, false, false, false, false, true, null ), new MyTreeItem ( "Juneteenth (Liberation of Slaves)", false, false, false, false, false, false, null ), - new MyTreeItem ( "Flag Day", false, true, false, true, false, false, null ) + new MyTreeItem ( "Flag Day", false, true, false, true, false, false, null ) }; private static MyTreeItem[] july = { new MyTreeItem ( "Parents' Day", false, false, false, false, false, true, null ), - new MyTreeItem ( "Independence Day", false, true, false, true, false, false, null ) + new MyTreeItem ( "Independence Day", false, true, false, true, false, false, null ) }; private static MyTreeItem[] august = { new MyTreeItem ( "Air Force Day", false, false, false, false, false, false, null ), new MyTreeItem ( "Coast Guard Day", false, false, false, false, false, false, null ), - new MyTreeItem ( "Friendship Day", false, false, false, false, false, false, null ) + new MyTreeItem ( "Friendship Day", false, false, false, false, false, false, null ) }; private static MyTreeItem[] september = { new MyTreeItem ( "Grandparents' Day", false, false, false, false, false, true, null ), new MyTreeItem ( "Citizenship Day or Constitution Day", false, false, false, false, false, false, null ), - new MyTreeItem ( "Labor Day", true, true, true, true, false, true, null ) + new MyTreeItem ( "Labor Day", true, true, true, true, false, true, null ) }; private static MyTreeItem[] october = @@ -311,40 +302,30 @@ namespace GtkDemo new MyTreeItem ("November", false, false, false, false, false, false, november), new MyTreeItem ("December", false, false, false, false, false, false, december) }; - + // TreeItem structure public class MyTreeItem { - public string Label; - public bool Alex; - public bool Havoc; - public bool Tim; - public bool Owen; - public bool Dave; - public bool World_holiday; /* shared by the European hackers */ - public MyTreeItem[] Children; - - public MyTreeItem ( - string label, - bool alex, - bool havoc, - bool tim, - bool owen, - bool dave, - bool world_holiday, - MyTreeItem[] children) - { - Label = label; - Alex = alex; - Havoc = havoc; - Tim = tim; - Owen = owen; - Dave = dave; - World_holiday = world_holiday; - Children = children; + public string Label; + public bool Alex, Havoc, Tim, Owen, Dave; + public bool WorldHoliday; // shared by the European hackers + public MyTreeItem[] Children; + + public MyTreeItem (string label, bool alex, bool havoc, bool tim, + bool owen, bool dave, bool worldHoliday, + MyTreeItem[] children) + { + Label = label; + Alex = alex; + Havoc = havoc; + Tim = tim; + Owen = owen; + Dave = dave; + WorldHoliday = worldHoliday; + Children = children; + } } - - } + // columns public enum Column { @@ -354,9 +335,9 @@ namespace GtkDemo Tim, Owen, Dave, + Visible, World, - Num, } } } diff --git a/sample/GtkDemo/DemoUIManager.cs b/sample/GtkDemo/DemoUIManager.cs index 094f8e41a..4486bd637 100644 --- a/sample/GtkDemo/DemoUIManager.cs +++ b/sample/GtkDemo/DemoUIManager.cs @@ -6,141 +6,150 @@ using System; using Gtk; -namespace GtkDemo +namespace GtkDemo { [Demo ("UIManager", "DemoUIManager.cs")] public class DemoUIManager : Window { - VBox vbox; + enum Color { + Red, + Green, + Blue + }; + + enum Shape { + Square, + Rectangle, + Oval + }; const string uiInfo = - "" + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - ""; + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + ""; - public DemoUIManager () : base ("Demo UIManager") + public DemoUIManager () : base ("UI Manager") { - 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[] - { + ActionEntry[] entries = 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)) + new ActionEntry ("New", Stock.New, "_New", "N", "Create a new file", new EventHandler (ActionActivated)), + new ActionEntry ("Open", Stock.Open, "_Open", "O", "Open a file", new EventHandler (ActionActivated)), + new ActionEntry ("Save", Stock.Save, "_Save", "S", "Save current file", new EventHandler (ActionActivated)), + new ActionEntry ("SaveAs", Stock.SaveAs, "Save _As", null, "Save to a file", new EventHandler (ActionActivated)), + new ActionEntry ("Quit", Stock.Quit, "_Quit", "Q", "Quit", new EventHandler (ActionActivated)), + new ActionEntry ("About", null, "_About", "A", "About", new EventHandler (ActionActivated)), + new ActionEntry ("Logo", "demo-gtk-logo", null, null, "Gtk#", new EventHandler (ActionActivated)) }; - ToggleActionEntry[] toggleActions = new ToggleActionEntry[] - { - new ToggleActionEntry ("Bold", Stock.Bold, "_Bold", "B", "Bold", new EventHandler (OnActionActivated), false) + ToggleActionEntry[] toggleEntries = new ToggleActionEntry[] { + new ToggleActionEntry ("Bold", Stock.Bold, "_Bold", "B", "Bold", new EventHandler (ActionActivated), true) }; - 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)) + + RadioActionEntry[] colorEntries = new RadioActionEntry[] { + new RadioActionEntry ("Red", null, "_Red", "R", "Blood", (int)Color.Red), + new RadioActionEntry ("Green", null, "_Green", "G", "Grass", (int)Color.Green), + new RadioActionEntry ("Blue", null, "_Blue", "B", "Sky", (int)Color.Blue) }; - 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)) + RadioActionEntry[] shapeEntries = new RadioActionEntry[] { + new RadioActionEntry ("Square", null, "_Square", "S", "Square", (int)Shape.Square), + new RadioActionEntry ("Rectangle", null, "_Rectangle", "R", "Rectangle", (int)Shape.Rectangle), + new RadioActionEntry ("Oval", null, "_Oval", "O", "Egg", (int)Shape.Oval) }; - ActionGroup group = new ActionGroup ("group"); - group.Add (actions); - group.Add (toggleActions); - group.Add (colorActions); - group.Add (shapeActions); + ActionGroup actions = new ActionGroup ("group"); + actions.Add (entries); + actions.Add (toggleEntries); + actions.Add (colorEntries, (int)Color.Red, new ChangedHandler (RadioActionActivated)); + actions.Add (shapeEntries, (int)Shape.Oval, new ChangedHandler (RadioActionActivated)); UIManager uim = new UIManager (); - uim.InsertActionGroup (group, (int) uim.NewMergeId ()); - uim.AddWidget += new AddWidgetHandler (OnAddWidget); + uim.InsertActionGroup (actions, 0); + AddAccelGroup (uim.AccelGroup); uim.AddUiFromString (uiInfo); + + VBox box1 = new VBox (false, 0); + Add (box1); + + box1.PackStart (uim.GetWidget ("/MenuBar"), false, false, 0); + + Label label = new Label ("Type\n\nto start"); + label.SetSizeRequest (200, 200); + label.SetAlignment (0.5f, 0.5f); + box1.PackStart (label, true, true, 0); + + HSeparator separator = new HSeparator (); + box1.PackStart (separator, false, true, 0); + + VBox box2 = new VBox (false, 10); + box2.BorderWidth = 10; + box1.PackStart (box2, false, true, 0); + + Button button = new Button ("close"); + button.Clicked += new EventHandler (CloseClicked); + box2.PackStart (button, true, true, 0); + button.CanDefault = true; + button.GrabDefault (); + + ShowAll (); } - - private void OnActionActivated (object sender, EventArgs a) + + private void ActionActivated (object sender, EventArgs a) { Action action = sender as Action; - Console.WriteLine ("** Message: Action \"{0}\" activated", action.Name); + Console.WriteLine ("Action \"{0}\" activated", action.Name); } - private void WindowDelete (object o, DeleteEventArgs args) + private void RadioActionActivated (object sender, ChangedArgs args) { - this.Hide (); - this.Destroy (); - args.RetVal = true; + Console.WriteLine ("Radio action \"{0}\" selected", args.Current.Name); } - void OnCloseClicked (object sender, EventArgs a) + protected override bool OnDeleteEvent (Gdk.Event evt) { - this.Hide (); - this.Destroy (); + Destroy (); + return true; } - void OnAddWidget (object sender, AddWidgetArgs a) + void CloseClicked (object sender, EventArgs a) { - a.Widget.Show (); - vbox.PackStart (a.Widget, false, true, 0); + Destroy (); } } } - diff --git a/sample/GtkDemo/README b/sample/GtkDemo/README index e08a3384d..ff03ef3f2 100644 --- a/sample/GtkDemo/README +++ b/sample/GtkDemo/README @@ -1,7 +1,10 @@ -This port of gtk-demo.c is still INCOMPLETE. If you can contribute to it -don't hesitate to mail your patches to gtk-sharp-list@lists.ximian.com +This is a mostly complete port of gtk-demo to Gtk#; for notes on +what's missing, see the TODO file. +The original port was done by Daniel Kornhauser (dkor@alum.mit.edu), +with additions/changes/fixes by various other people, as seen in the +main gtk-sharp ChangeLog. -To compile it just type Make - - Daniel Kornhauser. +For the most part, the various demos should stay as close as possible +to the C version, so that GtkDemo.exe can be compared against gtk-demo +to make sure Gtk# is working correctly. diff --git a/sample/GtkDemo/TODO b/sample/GtkDemo/TODO index 667166ccd..af9d90b5d 100644 --- a/sample/GtkDemo/TODO +++ b/sample/GtkDemo/TODO @@ -1,20 +1,14 @@ General - - general C#-ification + - gtk-demo passes a widget to each demo that is used to set the + Screen and sometimes Parent of each demo window + - Demo window management is not the same as in gtk-demo DemoMain - syntax highlighting -DemoStockBrowser - - underline _label properly - - use StudlyCaps instead of current horrible hack - - missing stockitems for some reason - - remove duplication in ListStore, and use DataFunc's - -DemoHyperText - - link tags are recreated too much and never removed +"Change Display" is missing Future ------ IconView - gtk 2.6 RotatedText - pango 1.6 -