From 0c81f9142c05e4fd3b2cc00db94ae0622083e7a8 Mon Sep 17 00:00:00 2001 From: Jeroen Zwartepoorte Date: Fri, 26 Nov 2004 14:59:38 +0000 Subject: [PATCH] 2004-11-26 Jeroen Zwartepoorte * gtk/ActionEntry.cs: * gtk/ActionGroup.custom: * gtk/Gtk.metadata: * gtk/Makefile.am: * gtk/RadioActionEntry.cs: * gtk/ToggleActionEntry.cs: * gtk/UIManager.custom: * sample/Actions.cs: Updated to use the new *ActionEntry code. Reflects testactions.c from gtk+ now. Added C# syntactic sugar for easily defining Action's for the UIManager. Derived from the same ActionEntry structs in gtk+. svn path=/trunk/gtk-sharp/; revision=36638 --- ChangeLog | 15 ++ doc/ChangeLog | 10 ++ doc/en/Gtk/ActionEntry.xml | 161 +++++++++++++++++++ doc/en/Gtk/ActionGroup.xml | 51 +++++- doc/en/Gtk/RadioActionEntry.xml | 165 +++++++++++++++++++ doc/en/Gtk/ToggleActionEntry.xml | 196 +++++++++++++++++++++++ doc/en/Gtk/UIManager.xml | 15 +- gtk/ActionEntry.cs | 48 ++++++ gtk/ActionGroup.custom | 68 ++++++++ gtk/Gtk.metadata | 1 + gtk/Makefile.am | 4 + gtk/RadioActionEntry.cs | 50 ++++++ gtk/ToggleActionEntry.cs | 55 +++++++ gtk/UIManager.custom | 27 ++-- sample/Actions.cs | 266 ++++++++++++++++++++++++++++--- 15 files changed, 1097 insertions(+), 35 deletions(-) create mode 100644 doc/en/Gtk/ActionEntry.xml create mode 100644 doc/en/Gtk/RadioActionEntry.xml create mode 100644 doc/en/Gtk/ToggleActionEntry.xml create mode 100644 gtk/ActionEntry.cs create mode 100644 gtk/ActionGroup.custom create mode 100644 gtk/RadioActionEntry.cs create mode 100644 gtk/ToggleActionEntry.cs diff --git a/ChangeLog b/ChangeLog index 919950db3..3555c2d71 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2004-11-26 Jeroen Zwartepoorte + + * gtk/ActionEntry.cs: + * gtk/ActionGroup.custom: + * gtk/Gtk.metadata: + * gtk/Makefile.am: + * gtk/RadioActionEntry.cs: + * gtk/ToggleActionEntry.cs: + * gtk/UIManager.custom: + * sample/Actions.cs: Updated to use the new *ActionEntry code. Reflects + testactions.c from gtk+ now. + + Added C# syntactic sugar for easily defining Action's for the UIManager. + Derived from the same ActionEntry structs in gtk+. + 2004-11-22 Dan Winship * generator/ClassBase.cs: diff --git a/doc/ChangeLog b/doc/ChangeLog index e97bbfdb8..2fcd36bcb 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,13 @@ +2004-11-26 Jeroen Zwartepoorte + + * doc/en/Gtk/ActionEntry.xml: + * doc/en/Gtk/ActionGroup.xml: + * doc/en/Gtk/RadioActionEntry.xml: + * doc/en/Gtk/ToggleActionEntry.xml: + * doc/en/Gtk/UIManager.xml: + + New ActionEntry related structs & methods. + 2004-11-18 Dan Winship * en/Gtk/: update for container child property change diff --git a/doc/en/Gtk/ActionEntry.xml b/doc/en/Gtk/ActionEntry.xml new file mode 100644 index 000000000..1d840564a --- /dev/null +++ b/doc/en/Gtk/ActionEntry.xml @@ -0,0 +1,161 @@ + + + + gtk-sharp + [00 24 00 00 04 80 00 00 94 00 00 00 06 02 00 00 00 24 00 00 52 53 41 31 00 04 00 00 01 00 01 00 71 EB 6C 55 75 52 9C BF 72 44 F7 A6 EA 05 62 84 F9 EA E0 3B CF F2 CC 13 2C 9C 49 0A B3 09 EA B0 B5 6B CE 44 9D F5 03 D9 C0 A8 1E 52 05 85 CD BE 70 E2 FB 90 43 4B AC 04 FA 62 22 A8 00 98 B7 A1 A7 B3 AF 99 1A 41 23 24 BB 43 25 F6 B8 65 BB 64 EB F6 D1 C2 06 D5 73 2D DF BC 70 A7 38 9E E5 3E 0C 24 6E 32 79 74 1A D0 05 03 E4 98 42 E1 9B F3 7B 19 8B 40 21 26 CB 36 89 C2 EA 64 96 A4 7C B4] + 2.0.0.0 + neutral + + + Gtk# is thread aware, but not thread safe; See the Gtk# Thread Programming for details. + + A struct containing all the info necessary for creating an + + The ActionEntry struct is C# "syntactic sugar", designed to make it easier for developers to add s to their code. + Instead of creating a new object for each action, a developer can create an array of ActionEntry's and add them to an all at once using the method. + + + + System.ValueType + + + + + + + Field + + System.String + + + + + A unique name for the action. + + + + + + Field + + System.String + + + + + The stock icon displayed in widgets representing this action. + + + + + + Field + + System.String + + + + + The label used for menu items and buttons that activate this action. + + + + + + Field + + System.String + + + + + A tooltip for this action. + + + + + + Field + + System.String + + + + + The accelerator for the action, in the format understood by , or "" for no accelerator, or to use the stock accelerator. + + + + + + Field + + System.EventHandler + + + + + EventHandler to be called when the action is triggered. + + + + + + Constructor + + + + + + + To be added + a + a + a + To be added + + + + + Constructor + + + + + + + + To be added + a + a + a + a + To be added + + + + + Constructor + + + + + + + + + + + To be added + a + a + a + a + a + a + a + To be added + + + + diff --git a/doc/en/Gtk/ActionGroup.xml b/doc/en/Gtk/ActionGroup.xml index 84f4db09f..8f26ffb33 100644 --- a/doc/en/Gtk/ActionGroup.xml +++ b/doc/en/Gtk/ActionGroup.xml @@ -260,5 +260,54 @@ Therefore you must either set the accel path yourself with + + Method + + System.Void + + + + + + Ease of use function for adding multiple s in a single call using the struct. + a + + + + + + Method + + System.Void + + + + + + Ease of use function for adding multiple s in a single call using the struct. + a + + + + + + Method + + System.Void + + + + + + + + Ease of use function for adding multiple s in a single call using the struct. + a + a + a + + + - \ No newline at end of file + diff --git a/doc/en/Gtk/RadioActionEntry.xml b/doc/en/Gtk/RadioActionEntry.xml new file mode 100644 index 000000000..b64613a1c --- /dev/null +++ b/doc/en/Gtk/RadioActionEntry.xml @@ -0,0 +1,165 @@ + + + + gtk-sharp + [00 24 00 00 04 80 00 00 94 00 00 00 06 02 00 00 00 24 00 00 52 53 41 31 00 04 00 00 01 00 01 00 71 EB 6C 55 75 52 9C BF 72 44 F7 A6 EA 05 62 84 F9 EA E0 3B CF F2 CC 13 2C 9C 49 0A B3 09 EA B0 B5 6B CE 44 9D F5 03 D9 C0 A8 1E 52 05 85 CD BE 70 E2 FB 90 43 4B AC 04 FA 62 22 A8 00 98 B7 A1 A7 B3 AF 99 1A 41 23 24 BB 43 25 F6 B8 65 BB 64 EB F6 D1 C2 06 D5 73 2D DF BC 70 A7 38 9E E5 3E 0C 24 6E 32 79 74 1A D0 05 03 E4 98 42 E1 9B F3 7B 19 8B 40 21 26 CB 36 89 C2 EA 64 96 A4 7C B4] + 2.0.0.0 + neutral + + + Gtk# is thread aware, but not thread safe; See the Gtk# Thread Programming for details. + + A struct containing all the info necessary for creating an + + The ActionEntry struct is C# "syntactic sugar", designed to make it easier for developers to add s to their code. + Instead of creating a new object for each action, a developer can create an array of RadioActionEntry's and add them to an all at once using the method. + + + + System.ValueType + + + + + + + Field + + System.String + + + + + A unique name for the action. + + + + + + Field + + System.String + + + + + The stock icon displayed in widgets representing this action. + + + + + + Field + + System.String + + + + + The label used for menu items and buttons that activate this action. + + + + + + Field + + System.String + + + + + A tooltip for this action. + + + + + + Field + + System.String + + + + + The accelerator for the action, in the format understood by , or "" for no accelerator, or to use the stock accelerator. + + + + + + Field + + System.Int32 + + + + + Integer representing the value of the . + + + + + + Constructor + + + + + + + To be added + a + a + a + To be added + + + + + Constructor + + + + + + + + + + To be added + a + a + a + a + a + a + To be added + + + + + Constructor + + + + + + + + + + + To be added + a + a + a + a + a + a + a + To be added + + + + diff --git a/doc/en/Gtk/ToggleActionEntry.xml b/doc/en/Gtk/ToggleActionEntry.xml new file mode 100644 index 000000000..627061bca --- /dev/null +++ b/doc/en/Gtk/ToggleActionEntry.xml @@ -0,0 +1,196 @@ + + + + gtk-sharp + [00 24 00 00 04 80 00 00 94 00 00 00 06 02 00 00 00 24 00 00 52 53 41 31 00 04 00 00 01 00 01 00 71 EB 6C 55 75 52 9C BF 72 44 F7 A6 EA 05 62 84 F9 EA E0 3B CF F2 CC 13 2C 9C 49 0A B3 09 EA B0 B5 6B CE 44 9D F5 03 D9 C0 A8 1E 52 05 85 CD BE 70 E2 FB 90 43 4B AC 04 FA 62 22 A8 00 98 B7 A1 A7 B3 AF 99 1A 41 23 24 BB 43 25 F6 B8 65 BB 64 EB F6 D1 C2 06 D5 73 2D DF BC 70 A7 38 9E E5 3E 0C 24 6E 32 79 74 1A D0 05 03 E4 98 42 E1 9B F3 7B 19 8B 40 21 26 CB 36 89 C2 EA 64 96 A4 7C B4] + 2.0.0.0 + neutral + + + Gtk# is thread aware, but not thread safe; See the Gtk# Thread Programming for details. + + A struct containing all the info necessary for creating an + + The ActionEntry struct is C# "syntactic sugar", designed to make it easier for developers to add s to their code. + Instead of creating a new object for each action, a developer can create an array of ToggleActionEntry's and add them to an all at once using the method. + + + + System.ValueType + + + + + + + Field + + System.String + + + + + A unique name for the action. + + + + + + Field + + System.String + + + + + The stock icon displayed in widgets representing this action. + + + + + + Field + + System.String + + + + + The label used for menu items and buttons that activate this action. + + + + + + Field + + System.String + + + + + A tooltip for this action. + + + + + + Field + + System.String + + + + + The accelerator for the action, in the format understood by , or "" for no accelerator, or to use the stock accelerator. + + + + + + Field + + System.EventHandler + + + + + EventHandler to be called when the action is triggered. + + + + + + Field + + System.Boolean + + + + + Boolean value indicating whether the initial state of the ToggleAction is "on" or "off". + + + + + + Constructor + + + + + + + To be added + a + a + a + To be added + + + + + Constructor + + + + + + + + To be added + a + a + a + a + To be added + + + + + Constructor + + + + + + + + + To be added + a + a + a + a + a + To be added + + + + + Constructor + + + + + + + + + + + + To be added + a + a + a + a + a + a + a + a + To be added + + + + diff --git a/doc/en/Gtk/UIManager.xml b/doc/en/Gtk/UIManager.xml index 3c9d7fa40..d0f17aca7 100644 --- a/doc/en/Gtk/UIManager.xml +++ b/doc/en/Gtk/UIManager.xml @@ -387,7 +387,7 @@ The behaviour is chosen based on the "is_important" property of the action to wh - + Constructor @@ -538,5 +538,18 @@ The behaviour is chosen based on the "is_important" property of the action to wh This is intended for applications to get notification just after any action is activated. + + + Method + + System.UInt32 + + + + To be added + a + To be added + + \ No newline at end of file diff --git a/gtk/ActionEntry.cs b/gtk/ActionEntry.cs new file mode 100644 index 000000000..2edc3fb4f --- /dev/null +++ b/gtk/ActionEntry.cs @@ -0,0 +1,48 @@ +// ActionEntry.cs - Syntactic C# sugar for easily defining Actions. +// +// Authors: Jeroen Zwartepoorte +// +// Copyright (c) 2004 Jeroen Zwartepoorte +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the Lesser GNU General +// Public License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +using System; + +namespace Gtk { + public struct ActionEntry { + public string name; + public string stock_id; + public string label; + public string tooltip; + public string accelerator; + public EventHandler activated; + + public ActionEntry (string name, string stock_id) + : this (name, stock_id, null, null, null, null) {} + + public ActionEntry (string name, string stock_id, EventHandler activated) + : this (name, stock_id, null, null, null, activated) {} + + public ActionEntry (string name, string stock_id, string label, string accelerator, string tooltip, EventHandler activated) + { + this.name = name; + this.stock_id = stock_id; + this.label = label; + this.accelerator = accelerator; + this.tooltip = tooltip; + this.activated = activated; + } + } +} diff --git a/gtk/ActionGroup.custom b/gtk/ActionGroup.custom new file mode 100644 index 000000000..67c175f95 --- /dev/null +++ b/gtk/ActionGroup.custom @@ -0,0 +1,68 @@ +// ActionGroup.custom - Syntactic C# sugar for easily defining Actions. +// +// Authors: Jeroen Zwartepoorte +// +// Copyright (c) 2004 Jeroen Zwartepoorte +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the Lesser GNU General +// Public License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + + public void Add (ActionEntry[] entries) + { + foreach (ActionEntry entry in entries) { + Action action = new Action (entry.name, entry.label, entry.tooltip, entry.stock_id); + if (entry.activated != null) + action.Activated += entry.activated; + if (entry.accelerator == null) + Add (action); + else + Add (action, entry.accelerator); + } + } + + public void Add (ToggleActionEntry[] entries) + { + foreach (ToggleActionEntry entry in entries) { + ToggleAction action = new ToggleAction (entry.name, entry.label, entry.tooltip, entry.stock_id); + action.Active = entry.active; + if (entry.activated != null) + action.Activated += entry.activated; + if (entry.accelerator == null) + Add (action); + else + Add (action, entry.accelerator); + } + } + + public void Add (RadioActionEntry[] entries, int value, ChangedHandler changed) + { + GLib.SList group = new GLib.SList (typeof (RadioAction)); + RadioAction[] actions = new RadioAction[entries.Length]; + for (int i = 0; i < entries.Length; i++) { + actions[i] = new RadioAction (entries[i].name, entries[i].label, + entries[i].tooltip, entries[i].stock_id, entries[i].value); + actions[i].Group = group; + group = actions[i].Group; + actions[i].Active = value == entries[i].value; + if (entries[i].accelerator == null) + Add (actions[i]); + else + Add (actions[i], entries[i].accelerator); + } + + // Add the ChangedHandler when we're done adding all the actions. + // Otherwise, setting the Active property will trigger a premature event. + if (changed != null) + actions[0].Changed += changed; + } diff --git a/gtk/Gtk.metadata b/gtk/Gtk.metadata index a5f0b55f5..7f204c757 100644 --- a/gtk/Gtk.metadata +++ b/gtk/Gtk.metadata @@ -332,6 +332,7 @@ 1 1 ScrollAdjustmentsSet + 1 1 1 1 diff --git a/gtk/Makefile.am b/gtk/Makefile.am index 10bf92463..f55e58257 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -17,11 +17,14 @@ CLEANFILES = $(ASSEMBLY) generated-stamp generated/*.cs $(API) glue/generated.c DISTCLEANFILES = $(ASSEMBLY).config AssemblyInfo.cs sources = \ + ActionEntry.cs \ Application.cs \ ChildPropertyAttribute.cs \ ITreeNode.cs \ NodeStore.cs \ + RadioActionEntry.cs \ ThreadNotify.cs \ + ToggleActionEntry.cs \ TreeNodeAttribute.cs \ TreeNode.cs \ TreeNodeValueAttribute.cs @@ -32,6 +35,7 @@ customs = \ Accel.custom \ AccelKey.custom \ Action.custom \ + ActionGroup.custom \ Adjustment.custom \ Bin.custom \ Button.custom \ diff --git a/gtk/RadioActionEntry.cs b/gtk/RadioActionEntry.cs new file mode 100644 index 000000000..8bf9e691c --- /dev/null +++ b/gtk/RadioActionEntry.cs @@ -0,0 +1,50 @@ +// RadioActionEntry.cs - Syntactic C# sugar for easily defining RadioActions. +// +// Authors: Jeroen Zwartepoorte +// +// Copyright (c) 2004 Jeroen Zwartepoorte +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the Lesser GNU General +// Public License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +using System; + +namespace Gtk { + public struct RadioActionEntry { + public string name; + public string stock_id; + public string label; + public string tooltip; + public string accelerator; + public int value; + + public RadioActionEntry (string name, string stock_id) + : this (name, stock_id, null, null, null, 0) {} + + public RadioActionEntry (string name, string stock_id, string label, + string accelerator, string tooltip) + : this (name, stock_id, label, accelerator, tooltip, 0) {} + + public RadioActionEntry (string name, string stock_id, string label, + string accelerator, string tooltip, int value) + { + this.name = name; + this.stock_id = stock_id; + this.label = label; + this.accelerator = accelerator; + this.tooltip = tooltip; + this.value = value; + } + } +} diff --git a/gtk/ToggleActionEntry.cs b/gtk/ToggleActionEntry.cs new file mode 100644 index 000000000..57500b084 --- /dev/null +++ b/gtk/ToggleActionEntry.cs @@ -0,0 +1,55 @@ +// ToggleActionEntry.cs - Syntactic C# sugar for easily defining ToggleActions. +// +// Authors: Jeroen Zwartepoorte +// +// Copyright (c) 2004 Jeroen Zwartepoorte +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the Lesser GNU General +// Public License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +using System; + +namespace Gtk { + public struct ToggleActionEntry { + public string name; + public string stock_id; + public string label; + public string tooltip; + public string accelerator; + public EventHandler activated; + public bool active; + + public ToggleActionEntry (string name, string stock_id) + : this (name, stock_id, null, null, null, null, false) {} + + public ToggleActionEntry (string name, string stock_id, EventHandler activated) + : this (name, stock_id, null, null, null, activated, false) {} + + public ToggleActionEntry (string name, string stock_id, EventHandler activated, bool active) + : this (name, stock_id, null, null, null, activated, active) {} + + public ToggleActionEntry (string name, string stock_id, string label, + string accelerator, string tooltip, + EventHandler activated, bool active) + { + this.name = name; + this.stock_id = stock_id; + this.label = label; + this.accelerator = accelerator; + this.tooltip = tooltip; + this.activated = activated; + this.active = active; + } + } +} diff --git a/gtk/UIManager.custom b/gtk/UIManager.custom index 343da12fb..1c6777aa2 100644 --- a/gtk/UIManager.custom +++ b/gtk/UIManager.custom @@ -20,15 +20,22 @@ // Free Software Foundation, Inc., 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA. - public uint AddUiFromResource (string resource) - { - if (resource == null) - throw new ArgumentNullException ("resource"); - - System.IO.Stream s = System.Reflection.Assembly.GetCallingAssembly ().GetManifestResourceStream (resource); - if (s == null) - throw new ArgumentException ("resource must be a valid resource name of 'assembly'."); + public uint AddUiFromResource (string resource) + { + if (resource == null) + throw new ArgumentNullException ("resource"); + + System.IO.Stream s = System.Reflection.Assembly.GetCallingAssembly ().GetManifestResourceStream (resource); + if (s == null) + throw new ArgumentException ("resource must be a valid resource name of 'assembly'."); - return AddUiFromString (new System.IO.StreamReader (s).ReadToEnd ()); - } + return AddUiFromString (new System.IO.StreamReader (s).ReadToEnd ()); + } + [DllImport("libgtk-win32-2.0-0.dll")] + static extern uint gtk_ui_manager_new_merge_id (IntPtr raw); + + public uint NewMergeId () + { + return gtk_ui_manager_new_merge_id (Handle); + } diff --git a/sample/Actions.cs b/sample/Actions.cs index d39844026..43370238f 100644 --- a/sample/Actions.cs +++ b/sample/Actions.cs @@ -1,8 +1,8 @@ -// Actions.cs - Gtk.Action class Test implementation +// Actions.cs - Gtk.Action class Test implementation (port of testactions.c) // -// Author: Jeroen Zwartepoorte // -// (c) 2003 Jeroen Zwartepoorte +// (c) 2004 Jeroen Zwartepoorte namespace GtkSamples { @@ -12,18 +12,133 @@ namespace GtkSamples { public class Actions { static VBox box = null; static Statusbar statusbar = null; + static ActionGroup group = null; + static Toolbar toolbar = null; + static SpinButton spin = null; + static ActionGroup dynGroup = null; + static uint mergeId = 0; + static UIManager uim = null; /* XML description of the menus for the test app. The parser understands * a subset of the Bonobo UI XML format, and uses GMarkup for parsing */ const string ui_info = - "" + - " " + - " " + - " " + - "" + - "" + - " " + - ""; + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n"; + + static ActionEntry[] entries = new ActionEntry[] { + new ActionEntry ("Menu1Action", null, "Menu _1", null, null, null), + new ActionEntry ("Menu2Action", null, "Menu _2", null, null, null), + new ActionEntry ("Menu3Action", null, "_Dynamic Menu", null, null, null), + new ActionEntry ("cut", Stock.Cut, "C_ut", "X", + "Cut the selected text to the clipboard", + new EventHandler (OnActivate)), + new ActionEntry ("copy", Stock.Copy, "_Copy", "C", + "Copy the selected text to the clipboard", + new EventHandler (OnActivate)), + new ActionEntry ("paste", Stock.Paste, "_Paste", "V", + "Paste the text from the clipboard", + new EventHandler (OnActivate)), + new ActionEntry ("quit", Stock.Quit, null, "Q", + "Quit the application", new EventHandler (OnQuit)), + new ActionEntry ("customise-accels", null, "Customise _Accels", null, + "Customize keyboard shortcuts", + new EventHandler (OnCustomizeAccels)), + new ActionEntry ("toolbar-small-icons", null, "Small Icons", null, + null, new EventHandler (OnToolbarSizeSmall)), + new ActionEntry ("toolbar-large-icons", null, "Large Icons", null, + null, new EventHandler (OnToolbarSizeLarge)) + }; + + static ToggleActionEntry[] toggleEntries = new ToggleActionEntry[] { + new ToggleActionEntry ("bold", Stock.Bold, "_Bold", "B", + "Change to bold face", + new EventHandler (OnToggle), false), + new ToggleActionEntry ("toggle-cnp", null, "Enable Cut/Copy/Paste", + null, "Change the sensitivity of the cut, copy and paste actions", + new EventHandler (OnToggleCnp), true) + }; + + enum Justify { + Left, + Center, + Right, + Fill + }; + + static RadioActionEntry[] radioEntries = new RadioActionEntry[] { + new RadioActionEntry ("justify-left", Stock.JustifyLeft, "_Left", + "L", "Left justify the text", + (int)Justify.Left), + new RadioActionEntry ("justify-center", Stock.JustifyCenter, "C_enter", + "E", "Center justify the text", + (int)Justify.Center), + new RadioActionEntry ("justify-right", Stock.JustifyRight, "_Right", + "R", "Right justify the text", + (int)Justify.Right), + new RadioActionEntry ("justify-fill", Stock.JustifyFill, "_Fill", + "J", "Fill justify the text", + (int)Justify.Fill) + }; + + static RadioActionEntry[] toolbarEntries = new RadioActionEntry[] { + new RadioActionEntry ("toolbar-icons", null, "Icons", null, + null, (int)ToolbarStyle.Icons), + new RadioActionEntry ("toolbar-text", null, "Text", null, + null, (int)ToolbarStyle.Text), + new RadioActionEntry ("toolbar-both", null, "Both", null, + null, (int)ToolbarStyle.Both), + new RadioActionEntry ("toolbar-both-horiz", null, "Both Horizontal", + null, null, (int)ToolbarStyle.BothHoriz) + }; public static int Main (string[] args) { @@ -35,15 +150,13 @@ namespace GtkSamples { box = new VBox (false, 0); win.Add (box); - ActionGroup group = new ActionGroup ("TestGroup"); - Action action = new Action ("quit", null, "Quit the program", Stock.Quit); - action.Activated += new EventHandler (OnQuit); - group.Add (action, "Q"); + group = new ActionGroup ("TestActions"); + group.Add (entries); + group.Add (toggleEntries); + group.Add (radioEntries, (int)Justify.Left, new ChangedHandler (OnRadio)); + group.Add (toolbarEntries, (int)ToolbarStyle.BothHoriz, new ChangedHandler (OnToolbarStyle)); - action = new Action ("Menu1Action", "_File", null, null); - group.Add (action); - - UIManager uim = new UIManager (); + uim = new UIManager (); uim.AddWidget += new AddWidgetHandler (OnWidgetAdd); uim.ConnectProxy += new ConnectProxyHandler (OnProxyConnect); uim.InsertActionGroup (group, 0); @@ -52,14 +165,122 @@ namespace GtkSamples { statusbar = new Statusbar (); box.PackEnd (statusbar, false, true, 0); + VBox vbox = new VBox (false, 5); Button button = new Button ("Blah"); - box.PackEnd (button, true, true, 0); + vbox.PackEnd (button, true, true, 0); + HBox hbox = new HBox (false, 5); + spin = new SpinButton (new Adjustment (100, 100, 10000, 1, 100, 100), 100, 0); + hbox.PackStart (spin, true, true, 0); + button = new Button ("Remove"); + button.Clicked += new EventHandler (OnDynamicRemove); + hbox.PackEnd (button, false, false, 0); + button = new Button ("Add"); + button.Clicked += new EventHandler (OnDynamicAdd); + hbox.PackEnd (button, false, false, 0); + vbox.PackEnd (hbox, false, false, 0); + box.PackEnd (vbox, true, true, 0); win.ShowAll (); Application.Run (); return 0; } + static void OnActivate (object obj, EventArgs args) + { + Action action = (Action)obj; + Console.WriteLine ("Action {0} (type={1}) activated", + action.Name, action.GetType ().FullName); + } + + static void OnCustomizeAccels (object obj, EventArgs args) + { + Console.WriteLine ("Sorry, accel dialog not available"); + } + + static void OnToolbarSizeSmall (object obj, EventArgs args) + { + toolbar.IconSize = IconSize.SmallToolbar; + } + + static void OnToolbarSizeLarge (object obj, EventArgs args) + { + toolbar.IconSize = IconSize.LargeToolbar; + } + + static void OnToggle (object obj, EventArgs args) + { + ToggleAction action = (ToggleAction)obj; + Console.WriteLine ("Action {0} (type={1}) activated (active={2})", + action.Name, action.GetType ().FullName, action.Active); + } + + static void OnToggleCnp (object obj, EventArgs args) + { + Action action = (ToggleAction)obj; + bool sensitive = ((ToggleAction)action).Active; + action = group.GetAction ("cut"); + action.Sensitive = sensitive; + action = group.GetAction ("copy"); + action.Sensitive = sensitive; + action = group.GetAction ("paste"); + action.Sensitive = sensitive; + + action = group.GetAction ("toggle-cnp"); + if (sensitive) + action.Label = "Disable Cut and past ops"; + else + action.Label = "Enable Cut and paste ops"; + } + + static void OnRadio (object obj, ChangedArgs args) + { + RadioAction action = (RadioAction)obj; + Console.WriteLine ("Action {0} (type={1}) activated (active={2}) (value {3})", + action.Name, action.GetType ().FullName, + action.Active, action.CurrentValue); + } + + static void OnToolbarStyle (object obj, ChangedArgs args) + { + RadioAction action = (RadioAction)obj; + ToolbarStyle style = (ToolbarStyle)action.CurrentValue; + toolbar.ToolbarStyle = style; + } + + static void OnDynamicAdd (object obj, EventArgs args) + { + if (mergeId != 0 || dynGroup != null) + return; + + int num = spin.ValueAsInt; + dynGroup = new ActionGroup ("DynamicActions"); + uim.InsertActionGroup (dynGroup, 0); + mergeId = uim.NewMergeId (); + + for (int i = 0; i < num; i++) { + string name = "DynAction" + i; + string label = "Dynamic Action " + i; + Action action = new Action (name, label); + dynGroup.Add (action); + uim.AddUi (mergeId, "/menubar/DynamicMenu", name, + name, UIManagerItemType.Menuitem, false); + } + + uim.EnsureUpdate (); + } + + static void OnDynamicRemove (object obj, EventArgs args) + { + if (mergeId == 0 || dynGroup == null) + return; + + uim.RemoveUi (mergeId); + uim.EnsureUpdate (); + mergeId = 0; + uim.RemoveActionGroup (dynGroup); + dynGroup = null; + } + static void OnWindowDelete (object obj, DeleteEventArgs args) { Application.Quit (); @@ -68,7 +289,8 @@ namespace GtkSamples { static void OnWidgetAdd (object obj, AddWidgetArgs args) { - Console.WriteLine ("OnWidgetAdd {0}", args.Widget.Name); + if (args.Widget is Toolbar) + toolbar = (Toolbar)args.Widget; args.Widget.Show (); box.PackStart (args.Widget, false, true, 0); } @@ -87,7 +309,6 @@ namespace GtkSamples { static void OnProxyConnect (object obj, ConnectProxyArgs args) { - Console.WriteLine ("ProxyConnect {0}, {1}", args.Action, args.Proxy.Name); if (args.Proxy is MenuItem) { ((GLib.Object)args.Proxy).Data ["action"] = args.Action; ((Item)args.Proxy).Selected += new EventHandler (OnSelect); @@ -97,7 +318,6 @@ namespace GtkSamples { static void OnQuit (object obj, EventArgs args) { - Console.WriteLine ("quit"); Application.Quit (); } }