Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* libstetic/wrapper/CheckMenuItem.cs:

	* libstetic/wrapper/ImageMenuItem.cs: 
	* libstetic/wrapper/MenuBar.cs: 
	* libstetic/wrapper/MenuItem.cs: 
	* libstetic/wrapper/RadioMenuItem.cs: 
	* libstetic/wrapper/SeparatorMenuItem.cs: wrap these enough to be
	able to glade-import menus, but not really well enough to be able
	to edit them happily.

	* libstetic/Makefile.am (libstetic.dll): Change the rule to write
	all the args out to a response file and then use that.

	* libstetic/editor/Accelerator.cs: PropertyGrid editor for
	accelerators. Loosely based on EggCellRendererKeys.

	* glue/misc.c (stetic_keycode_is_modifier): for
	Stetic.Editor.Accelerator

	* glue/Makefile.am (libsteticglue_la_SOURCES): add misc.c

svn path=/trunk/stetic/; revision=43345
  • Loading branch information...
commit 03e16ef244c2e049f1731cb07758e47eedd288a8 1 parent 4d03f2a
Dan Winship authored
View
22 ChangeLog
@@ -1,3 +1,25 @@
+2005-04-20 Dan Winship <danw@novell.com>
+
+ * libstetic/wrapper/CheckMenuItem.cs:
+ * libstetic/wrapper/ImageMenuItem.cs:
+ * libstetic/wrapper/MenuBar.cs:
+ * libstetic/wrapper/MenuItem.cs:
+ * libstetic/wrapper/RadioMenuItem.cs:
+ * libstetic/wrapper/SeparatorMenuItem.cs: wrap these enough to be
+ able to glade-import menus, but not really well enough to be able
+ to edit them happily.
+
+ * libstetic/Makefile.am (libstetic.dll): Change the rule to write
+ all the args out to a response file and then use that.
+
+ * libstetic/editor/Accelerator.cs: PropertyGrid editor for
+ accelerators. Loosely based on EggCellRendererKeys.
+
+ * glue/misc.c (stetic_keycode_is_modifier): for
+ Stetic.Editor.Accelerator
+
+ * glue/Makefile.am (libsteticglue_la_SOURCES): add misc.c
+
2005-04-19 Dan Winship <danw@novell.com>
* libstetic/GladeUtils.cs (ParseProperty, PropToString): do the
View
5 glue/Makefile.am
@@ -1,4 +1,4 @@
-INCLUDES = $(GTK_CFLAGS) -std=c99
+INCLUDES = $(GTK_CFLAGS)
lib_LTLIBRARIES = libsteticglue.la
@@ -7,4 +7,5 @@ libsteticglue_la_LIBADD = $(GTK_LIBS)
libsteticglue_la_SOURCES = \
custom.c \
- paramspec.c
+ misc.c \
+ paramspec.c
View
26 glue/misc.c
@@ -0,0 +1,26 @@
+/* Copyright (c) 2005 Novell, Inc. */
+
+#include <gdk/gdk.h>
+#include <gdk/gdkx.h>
+
+gboolean stetic_keycode_is_modifier (guint keycode);
+
+gboolean
+stetic_keycode_is_modifier (guint keycode)
+{
+ static XModifierKeymap *mod_keymap;
+ static int map_size;
+ int i;
+
+ if (!mod_keymap) {
+ mod_keymap = XGetModifierMapping (gdk_display);
+ map_size = 8 * mod_keymap->max_keypermod;
+ }
+
+ for (i = 0; i < map_size; i++) {
+ if (keycode == mod_keymap->modifiermap[i])
+ return TRUE;
+ }
+
+ return FALSE;
+}
View
17 libstetic/Makefile.am
@@ -24,6 +24,7 @@ libstetic_dll_sources = \
RangeAttribute.cs \
Set.cs \
TranslatableAttribute.cs \
+ editor/Accelerator.cs \
editor/Boolean.cs \
editor/Char.cs \
editor/Color.cs \
@@ -46,6 +47,7 @@ libstetic_dll_sources = \
wrapper/ButtonBox.cs \
wrapper/Calendar.cs \
wrapper/CheckButton.cs \
+ wrapper/CheckMenuItem.cs \
wrapper/ColorButton.cs \
wrapper/ComboBox.cs \
wrapper/ComboBoxEntry.cs \
@@ -65,9 +67,11 @@ libstetic_dll_sources = \
wrapper/HScrollbar.cs \
wrapper/HSeparator.cs \
wrapper/Image.cs \
+ wrapper/ImageMenuItem.cs \
wrapper/Label.cs \
wrapper/MessageDialog.cs \
wrapper/Menu.cs \
+ wrapper/MenuBar.cs \
wrapper/MenuItem.cs \
wrapper/Misc.cs \
wrapper/Notebook.cs \
@@ -76,10 +80,12 @@ libstetic_dll_sources = \
wrapper/Paned.cs \
wrapper/ProgressBar.cs \
wrapper/RadioButton.cs \
+ wrapper/RadioMenuItem.cs \
wrapper/RadioToolButton.cs \
wrapper/Range.cs \
wrapper/Scale.cs \
wrapper/ScrolledWindow.cs \
+ wrapper/SeparatorMenuItem.cs \
wrapper/SeparatorToolItem.cs \
wrapper/SpinButton.cs \
wrapper/Statusbar.cs \
@@ -99,11 +105,10 @@ libstetic_dll_sources = \
wrapper/Widget.cs \
wrapper/Window.cs
-comma = ,
-ICON_FILES = $(wildcard $(srcdir)/wrapper/pixmaps/*.png)
-ICON_RESOURCES = $(foreach file,$(ICON_FILES),-resource:$(file)$(comma)$(notdir $(file)))
-
-libstetic.dll: $(libstetic_dll_sources) $(ICON_FILES)
- $(MCS) -g -pkg:gnome-sharp-2.0 -target:library -o $@ $(libstetic_dll_sources) $(ICON_RESOURCES)
+libstetic.dll: $(libstetic_dll_sources)
+ @rm -f sources.rsp
+ @echo $(libstetic_dll_sources) > sources.rsp
+ @for pixmap in $(srcdir)/wrapper/pixmaps/*.png; do echo -resource:$$pixmap,`basename $$pixmap` >> sources.rsp; done
+ $(MCS) -g -pkg:gnome-sharp-2.0 -target:library -o $@ @sources.rsp
CLEANFILES = libstetic.dll libstetic.dll.mdb
View
5 libstetic/ObjectWrapper.cs
@@ -202,6 +202,11 @@ protected static ItemGroup AddItemGroup (Type type, string name, params string[]
}
}
+ protected static ArrayList GetItemGroups (Type type)
+ {
+ return groups[type] as ArrayList;
+ }
+
protected static ItemGroup AddContextMenuItems (Type type, params string[] items)
{
ItemGroup group = new ItemGroup (null, type, WrappedType (type), items);
View
124 libstetic/editor/Accelerator.cs
@@ -0,0 +1,124 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace Stetic.Editor {
+
+ [PropertyEditor ("Accel", "AccelChanged")]
+ public class Accelerator : Gtk.Entry {
+
+ uint keyval;
+ Gdk.ModifierType mask;
+ bool editing;
+
+ const Gdk.ModifierType AcceleratorModifierMask = ~(
+ Gdk.ModifierType.Button1Mask |
+ Gdk.ModifierType.Button2Mask |
+ Gdk.ModifierType.Button3Mask |
+ Gdk.ModifierType.Button4Mask |
+ Gdk.ModifierType.Button5Mask);
+
+ public Accelerator ()
+ {
+ Editable = false;
+ }
+
+ protected override bool OnButtonPressEvent (Gdk.EventButton evt)
+ {
+ if (editing)
+ Ungrab (evt.Time);
+ else
+ Grab (evt.Window, evt.Time);
+ return true;
+ }
+
+ void Ungrab (uint time)
+ {
+ if (!editing)
+ return;
+ editing = false;
+
+ Gdk.Keyboard.Ungrab (time);
+ Gdk.Pointer.Ungrab (time);
+ Text = Accel;
+ }
+
+ void Grab (Gdk.Window window, uint time)
+ {
+ if (editing)
+ return;
+
+ if (Gdk.Keyboard.Grab (window, false, time) != Gdk.GrabStatus.Success)
+ return;
+ if (Gdk.Pointer.Grab (window, false, Gdk.EventMask.ButtonPressMask,
+ null, null, time) != Gdk.GrabStatus.Success) {
+ Gdk.Keyboard.Ungrab (time);
+ return;
+ }
+ GrabFocus ();
+
+ editing = true;
+ Text = "New Accelerator...";
+ }
+
+ [DllImport ("libsteticglue")]
+ static extern bool stetic_keycode_is_modifier (uint keycode);
+
+ protected override bool OnKeyPressEvent (Gdk.EventKey evt)
+ {
+ if (!editing || stetic_keycode_is_modifier (evt.HardwareKeycode))
+ return base.OnKeyPressEvent (evt);
+
+ uint keyval;
+ int effectiveGroup, level;
+ Gdk.ModifierType consumedMods, mask;
+
+ // We know this will succeed, since we're already here...
+ Gdk.Keymap.Default.TranslateKeyboardState (evt.HardwareKeycode, evt.State, evt.Group, out keyval, out effectiveGroup, out level, out consumedMods);
+ mask = evt.State & AcceleratorModifierMask & ~consumedMods;
+
+ if (evt.Key != Gdk.Key.Escape || mask != 0) {
+ this.keyval = keyval;
+ this.mask = mask;
+ }
+
+ Ungrab (evt.Time);
+ EmitAccelChanged ();
+ return true;
+ }
+
+ public new string Text {
+ set {
+ if (value == null)
+ base.Text = "";
+ else
+ base.Text = value;
+ }
+ }
+
+ public string Accel {
+ get {
+ if (keyval != 0)
+ return Gtk.Accelerator.Name (keyval, mask);
+ else
+ return null;
+ }
+ set {
+ if (value == null) {
+ keyval = 0;
+ mask = 0;
+ } else
+ Gtk.Accelerator.Parse (value, out keyval, out mask);
+ Text = Accel;
+ EmitAccelChanged ();
+ }
+ }
+
+ public event EventHandler AccelChanged;
+
+ void EmitAccelChanged ()
+ {
+ if (AccelChanged != null)
+ AccelChanged (this, EventArgs.Empty);
+ }
+ }
+}
View
22 libstetic/wrapper/CheckMenuItem.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections;
+
+namespace Stetic.Wrapper {
+
+ [ObjectWrapper ("Check Menu Item", "checkmenuitem.png", ObjectWrapperType.Internal)]
+ public class CheckMenuItem : MenuItem {
+
+ public static new Type WrappedType = typeof (Gtk.CheckMenuItem);
+
+ internal static new void Register (Type type)
+ {
+ AddItemGroup (type,
+ "Check Menu Item Properties",
+ "Label",
+ "UseUnderline",
+ "Accelerator",
+ "Active",
+ "Inconsistent");
+ }
+ }
+}
View
73 libstetic/wrapper/ImageMenuItem.cs
@@ -0,0 +1,73 @@
+using System;
+using System.Collections;
+
+namespace Stetic.Wrapper {
+
+ [ObjectWrapper ("Image Menu Item", "imagemenuitem.png", ObjectWrapperType.Internal)]
+ public class ImageMenuItem : MenuItem {
+
+ public static new Type WrappedType = typeof (Gtk.ImageMenuItem);
+
+ internal static new void Register (Type type)
+ {
+ AddItemGroup (type,
+ "Image Menu Item Properties",
+ "Image",
+ "Label",
+ "UseUnderline",
+ "Accelerator");
+ }
+
+ public static new Gtk.ImageMenuItem CreateInstance ()
+ {
+ // Use the ctor that will create an AccelLabel
+ return new Gtk.ImageMenuItem ("");
+ }
+
+ protected override void GladeImport (string className, string id, Hashtable props)
+ {
+ Gtk.StockItem stockItem = Gtk.StockItem.Zero;
+ string use_stock = GladeUtils.ExtractProperty ("use_stock", props);
+ if (use_stock == "True") {
+ stockItem = Gtk.Stock.Lookup (props["label"] as string);
+ if (stockItem.Label != null)
+ props.Remove ("label");
+ }
+ base.GladeImport (className, id, props);
+
+ if (stockItem.StockId != null)
+ Image = "stock:" + stockItem.StockId;
+ if (stockItem.Keyval != 0)
+ Accelerator = Gtk.Accelerator.Name (stockItem.Keyval, stockItem.Modifier);
+ }
+
+ string image;
+
+ [Editor (typeof (Stetic.Editor.Image))]
+ public string Image {
+ get {
+ return image;
+ }
+ set {
+ image = value;
+
+ Gtk.Widget icon;
+ Gtk.StockItem stockItem = Gtk.StockItem.Zero;
+
+ if (image.StartsWith ("stock:"))
+ stockItem = Gtk.Stock.Lookup (image.Substring (6));
+
+ if (stockItem.StockId != null) {
+ icon = new Gtk.Image (stockItem.StockId, Gtk.IconSize.Menu);
+ Label = stockItem.Label;
+ UseUnderline = true;
+ } else if (image.StartsWith ("file:"))
+ icon = new Gtk.Image (image.Substring (5));
+ else
+ icon = new Gtk.Image (Gtk.Stock.MissingImage, Gtk.IconSize.Menu);
+
+ ((Gtk.ImageMenuItem)Wrapped).Image = icon;
+ }
+ }
+ }
+}
View
2  libstetic/wrapper/Menu.cs
@@ -3,7 +3,7 @@
namespace Stetic.Wrapper {
- [ObjectWrapper ("Menu", "menu.png", ObjectWrapperType.Widget)]
+ [ObjectWrapper ("Menu", "menu.png", ObjectWrapperType.Internal)]
public class Menu : Container {
public static new Type WrappedType = typeof (Gtk.Menu);
View
11 libstetic/wrapper/MenuBar.cs
@@ -0,0 +1,11 @@
+using System;
+using System.Collections;
+
+namespace Stetic.Wrapper {
+
+ [ObjectWrapper ("Menu Bar", "menubar.png", ObjectWrapperType.Widget)]
+ public class MenuBar : Container {
+
+ public static new Type WrappedType = typeof (Gtk.MenuBar);
+ }
+}
View
147 libstetic/wrapper/MenuItem.cs
@@ -3,23 +3,146 @@
namespace Stetic.Wrapper {
- [ObjectWrapper ("MenuItem", "menuitem.png", ObjectWrapperType.Widget)]
+ [ObjectWrapper ("Menu Item", "menuitem.png", ObjectWrapperType.Internal)]
public class MenuItem : Container {
public static new Type WrappedType = typeof (Gtk.MenuItem);
- protected override void GladeImport (string className, string id, Hashtable props)
+ internal static new void Register (Type type)
{
- string label = GladeUtils.ExtractProperty ("label", props);
- string use_underline = GladeUtils.ExtractProperty ("use_underline", props);
- base.GladeImport (className, id, props);
-
- if (label != null) {
- Gtk.MenuItem item = (Gtk.MenuItem)Wrapped;
- Gtk.Label item_label = new Gtk.Label (label);
- item_label.UseUnderline = (use_underline == "True");
- item_label.Show ();
- item.Add (item_label);
+ if (type == typeof (Stetic.Wrapper.MenuItem)) {
+ AddItemGroup (type,
+ "Menu Item Properties",
+ "Label",
+ "UseUnderline",
+ "Accelerator");
+ }
+
+ foreach (ItemGroup props in GetItemGroups (type)) {
+ ItemDescriptor accelerator = props["Accelerator"];
+ if (accelerator != null) {
+ PropertyDescriptor hasSubmenu =
+ new PropertyDescriptor (typeof (Stetic.Wrapper.MenuItem),
+ typeof (Gtk.MenuItem),
+ "HasSubmenu");
+ accelerator.InvisibleIf (hasSubmenu);
+ }
+ }
+ }
+
+ public static new Gtk.MenuItem CreateInstance ()
+ {
+ // Use the ctor that will create an AccelLabel
+ return new Gtk.MenuItem ("");
+ }
+
+ public override void Wrap (object obj, bool initialized)
+ {
+ base.Wrap (obj, initialized);
+ }
+
+ public override Widget GladeImportChild (string className, string id,
+ Hashtable props, Hashtable childprops)
+ {
+ ObjectWrapper wrapper = Stetic.ObjectWrapper.GladeImport (stetic, className, id, props);
+ menuitem.Submenu = (Gtk.Menu)wrapper.Wrapped;
+ return (Widget)wrapper;
+ }
+
+ Gtk.MenuItem menuitem {
+ get {
+ return (Gtk.MenuItem)Wrapped;
+ }
+ }
+
+ Gtk.Label label {
+ get {
+ Gtk.AccelLabel label = menuitem.Child as Gtk.AccelLabel;
+ if (label != null)
+ return label;
+
+ if (menuitem.Child != null)
+ menuitem.Child.Destroy ();
+
+ label = new Gtk.AccelLabel ("");
+ label.MnemonicWidget = menuitem;
+ label.AccelWidget = menuitem;
+ label.Xalign = 0.0f;
+ label.Show ();
+ menuitem.Add (label);
+
+ return label;
+ }
+ }
+
+ public bool HasSubmenu {
+ get {
+ return menuitem.Submenu != null;
+ }
+ }
+
+ [GladeProperty (Name = "label")]
+ [Description ("Label", "The text of the menu item")]
+ public string Label {
+ get {
+ return label.LabelProp;
+ }
+ set {
+ label.LabelProp = value;
+ EmitNotify ("Label");
+ }
+ }
+
+ [GladeProperty (Name = "use_underline", Proxy = "GladeUseUnderline")]
+ [Description ("Use Underline", "If set, an underline in the text indicates the next character should be used for the mnemonic accelerator key")]
+ public bool UseUnderline {
+ get {
+ return label.UseUnderline;
+ }
+ set {
+ label.UseUnderline = value;
+ EmitNotify ("UseUnderline");
+ }
+ }
+
+ internal string GladeUseUnderline {
+ get {
+ return UseUnderline ? "True" : "False";
+ }
+ set {
+ UseUnderline = (value == "True");
+ }
+ }
+
+ Gtk.AccelGroup accelGroup;
+ string accelerator;
+
+ [Editor (typeof (Stetic.Editor.Accelerator))]
+ public string Accelerator {
+ get {
+ return accelerator;
+ }
+ set {
+ uint key;
+ Gdk.ModifierType mods;
+
+ if (accelGroup != null && accelerator != null) {
+ Gtk.Accelerator.Parse (accelerator, out key, out mods);
+ menuitem.RemoveAccelerator (accelGroup, key, mods);
+ }
+
+ accelerator = value;
+
+ if (accelerator != null) {
+ if (accelGroup == null)
+ accelGroup = new Gtk.AccelGroup ();
+
+ Gtk.Accelerator.Parse (accelerator, out key, out mods);
+ menuitem.AddAccelerator ("activate", accelGroup, key, mods,
+ Gtk.AccelFlags.Visible);
+ }
+
+ EmitNotify ("Accelerator");
}
}
}
View
58 libstetic/wrapper/RadioMenuItem.cs
@@ -0,0 +1,58 @@
+using System;
+using System.Collections;
+
+namespace Stetic.Wrapper {
+
+ [ObjectWrapper ("Radio Menu Item", "radiomenuitem.png", ObjectWrapperType.Internal)]
+ public class RadioMenuItem : MenuItem {
+
+ public static new Type WrappedType = typeof (Gtk.RadioMenuItem);
+
+ internal static new void Register (Type type)
+ {
+ AddItemGroup (type,
+ "Radio Menu Item Properties",
+ "Label",
+ "UseUnderline",
+ "Accelerator",
+ "Group",
+ "Active",
+ "Inconsistent");
+ }
+
+ static RadioGroupManager GroupManager = new RadioGroupManager (WrappedType);
+
+ public override void Wrap (object obj, bool initialized)
+ {
+ base.Wrap (obj, initialized);
+
+ Gtk.RadioMenuItem radio = (Gtk.RadioMenuItem)Wrapped;
+ if (!initialized)
+ Group = GroupManager.LastGroup;
+ else if (radio.Group == null)
+ Group = radio.Name;
+ }
+
+ protected override void GladeImport (string className, string id, Hashtable props)
+ {
+ string group = GladeUtils.ExtractProperty ("group", props);
+ base.GladeImport (className, id, props);
+
+ if (group != null)
+ Group = group;
+ else
+ Group = Wrapped.Name;
+ }
+
+ [Editor (typeof (Stetic.Editor.GroupPicker))]
+ [Description ("Group", "The name of the radio button group that this menu item belongs to")]
+ public string Group {
+ get {
+ return GroupManager[Wrapped];
+ }
+ set {
+ GroupManager[Wrapped] = value;
+ }
+ }
+ }
+}
View
11 libstetic/wrapper/SeparatorMenuItem.cs
@@ -0,0 +1,11 @@
+using System;
+using System.Collections;
+
+namespace Stetic.Wrapper {
+
+ [ObjectWrapper ("Separator Menu Item", "hseparator.png", ObjectWrapperType.Internal)]
+ public class SeparatorMenuItem : Widget {
+
+ public static new Type WrappedType = typeof (Gtk.SeparatorMenuItem);
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.