1 // StockManager.cs - Gtk.Stock item manager 2 // 3 // Authors: Mike Kestner <mkestner@ximian.com> 4 // 5 // Copyright (c) 2005 Novell, Inc. 6 // 7 // This program is free software; you can redistribute it and/or 8 // modify it under the terms of version 2 of the Lesser GNU General 9 // Public License as published by the Free Software Foundation. 10 // 11 // This program is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 // Lesser General Public License for more details. 15 // 16 // You should have received a copy of the GNU Lesser General Public 17 // License along with this program; if not, write to the 18 // Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 // Boston, MA 02111-1307, USA. 20 21 22 namespace Gtk { 23 24 using System; 25 using System.Runtime.InteropServices; 26 27 public class StockManager { 28 29 [DllImport("libgtk-win32-2.0-0.dll", CallingConvention=CallingConvention.Cdecl)] gtk_stock_add_static(ref Gtk.StockItem items, uint n_items)30 static extern void gtk_stock_add_static(ref Gtk.StockItem items, uint n_items); 31 32 [Obsolete ("Use StockManager.Add instead")] AddStatic(Gtk.StockItem items, uint n_items)33 public static void AddStatic(Gtk.StockItem items, uint n_items) 34 { 35 gtk_stock_add_static(ref items, n_items); 36 } 37 38 [StructLayout(LayoutKind.Sequential)] 39 struct ConstStockItem { 40 public IntPtr StockId; 41 public IntPtr Label; 42 public Gdk.ModifierType Modifier; 43 public uint Keyval; 44 public IntPtr TranslationDomain; 45 operator StockItemGtk.StockManager.ConstStockItem46 public static explicit operator StockItem (ConstStockItem csi) 47 { 48 Gtk.StockItem item = new Gtk.StockItem (); 49 item.StockId = GLib.Marshaller.Utf8PtrToString (csi.StockId); 50 item.Label = GLib.Marshaller.Utf8PtrToString (csi.Label); 51 item.Modifier = csi.Modifier; 52 item.Keyval = csi.Keyval; 53 item.TranslationDomain = GLib.Marshaller.Utf8PtrToString (csi.TranslationDomain); 54 return item; 55 } 56 } 57 58 [DllImport("libgtk-win32-2.0-0.dll", CallingConvention=CallingConvention.Cdecl)] gtk_stock_lookup(IntPtr stock_id, out ConstStockItem item)59 static extern bool gtk_stock_lookup (IntPtr stock_id, out ConstStockItem item); 60 Lookup(string stock_id, ref Gtk.StockItem item)61 public static bool Lookup (string stock_id, ref Gtk.StockItem item) 62 { 63 ConstStockItem const_item; 64 IntPtr native_id = GLib.Marshaller.StringToPtrGStrdup (stock_id); 65 bool found = gtk_stock_lookup (native_id, out const_item); 66 GLib.Marshaller.Free (native_id); 67 if (!found) 68 return false; 69 item = (StockItem) const_item; 70 return true; 71 } 72 LookupItem(string stock_id, out Gtk.StockItem item)73 public static bool LookupItem (string stock_id, out Gtk.StockItem item) 74 { 75 item = StockItem.Zero; 76 return Lookup (stock_id, ref item); 77 } 78 79 [DllImport("libgtk-win32-2.0-0.dll", CallingConvention=CallingConvention.Cdecl)] gtk_stock_add(ref Gtk.StockItem item, uint n_items)80 static extern void gtk_stock_add(ref Gtk.StockItem item, uint n_items); 81 82 [DllImport("libgtk-win32-2.0-0.dll", CallingConvention=CallingConvention.Cdecl)] gtk_stock_add(Gtk.StockItem[] items, uint n_items)83 static extern void gtk_stock_add(Gtk.StockItem[] items, uint n_items); 84 85 [Obsolete ("Use the StockItem or StockItem[] overload instead.")] Add(Gtk.StockItem items, uint n_items)86 public static void Add (Gtk.StockItem items, uint n_items) 87 { 88 gtk_stock_add(ref items, n_items); 89 } 90 Add(Gtk.StockItem item)91 public static void Add (Gtk.StockItem item) 92 { 93 gtk_stock_add (ref item, 1); 94 } 95 Add(Gtk.StockItem[] items)96 public static void Add (Gtk.StockItem[] items) 97 { 98 gtk_stock_add (items, (uint) items.Length); 99 } 100 101 } 102 } 103