// GTK.Button.cs - GTK Button class implementation // // Authors: Bob Smith // Mike Kestner // // (c) 2001 Bob Smith and Mike Kestner namespace Gtk { using System; using System.Collections; using System.Runtime.InteropServices; using GLib; /// /// Button Class /// /// /// /// A Button user interface element. /// public class Button : Widget { private Hashtable Signals = new Hashtable (); /// /// Button Constructor /// /// /// /// Constructs a Button with no label. /// [DllImport("gtk-1.3.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)] static extern IntPtr gtk_button_new (); public Button () { RawObject = gtk_button_new (); } /// /// Button Object Constructor /// /// /// /// Constructs a Button Wrapper from a raw object. This /// constructor is primarily used internally by gtk-sharp, /// but could conceivably be called by an application if /// the need to wrap a raw button object presents itself. /// /// /// /// Raw object reference from the native library. /// public Button (IntPtr obj) { RawObject = obj; } /// /// Button Constructor /// /// /// /// Constructs a new Button with the specified label. /// Note, that underlines in the label provided will /// be converted into mnemonics and the label will be /// interpreted as a stock system identifier if possible. /// If this behavior is not desired, more control can be /// obtained with an overloaded constructor. /// /// /// /// Text label or stock system id to display on the button. /// [DllImport("gtk-1.3.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)] static extern IntPtr gtk_button_new_from_stock (IntPtr str); public Button (String label) { RawObject = gtk_button_new_from_stock ( Marshal.StringToHGlobalAnsi (label)); } /// /// Button Constructor /// /// /// /// Constructs a new Button with the specified label. /// Underlines in the label can be converted to mnemonics /// based on the specified flag. The label can identify /// a stock button if desired as well. /// /// /// /// Text label to display on the button face. /// /// /// /// Indicates if the stock system should be used. If the /// label does not represent a known stock button, it will /// instead be used verbatim with mnemonic if an underline /// is included. /// /// /// /// Convert underscore to a mnemonic which can be used /// to activate the button with the keyboard. /// [DllImport("gtk-1.3.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)] static extern IntPtr gtk_button_new_with_mnemonic (IntPtr str); [DllImport("gtk-1.3.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)] static extern IntPtr gtk_button_new_with_label (IntPtr str); public Button (String label, bool stock, bool mnemonic) { if (stock) RawObject = gtk_button_new_from_stock ( Marshal.StringToHGlobalAnsi (label)); else if (mnemonic) RawObject = gtk_button_new_with_mnemonic ( Marshal.StringToHGlobalAnsi (label)); else RawObject = gtk_button_new_with_label ( Marshal.StringToHGlobalAnsi (label)); } /// /// Label Property /// /// /// /// Text label to display on the button face. /// public String Label { get { String val; GetProperty ("label", out val); return val; } set { SetProperty ("label", value); } } /// /// Relief Property /// /// /// /// Relief style used to draw the button. /// public ReliefStyle Relief { get { int val; GetProperty ("relief", out val); return (ReliefStyle) val; } set { SetProperty ("relief", (int) value); } } /// /// UseStock Property /// /// /// /// Indicates if stock button images should be used. /// public bool UseStock { get { bool val; GetProperty ("use-stock", out val); return val; } set { SetProperty ("use-stock", value); } } /// /// UseUnderline Property /// /// /// /// Indicates if underlines in the label text should be /// treated as a mnemonic. /// public bool UseUnderline { get { bool val; GetProperty ("use-underline", out val); return val; } set { SetProperty ("use-underline", value); } } /// /// Activated Event /// /// /// /// Signal indicating that the button has been activated. /// private static readonly string ActName = "activate"; public event EventHandler Activated { add { if (Events [ActName] == null) Signals [ActName] = new SimpleSignal ( this, RawObject, ActName, value); Events.AddHandler (ActName, value); } remove { Events.RemoveHandler (ActName, value); if (Events [ActName] == null) Signals.Remove (ActName); } } /// /// Clicked Event /// /// /// /// Signal indicating that the button has been clicked. /// private static readonly string ClkName = "clicked"; public event EventHandler Clicked { add { if (Events [ClkName] == null) Signals [ClkName] = new SimpleSignal ( this, RawObject, ClkName, value); Events.AddHandler (ClkName, value); } remove { Events.RemoveHandler (ClkName, value); if (Events [ClkName] == null) Signals.Remove (ClkName); } } /// /// Entered Event /// /// /// /// Signal indicating that the focus has entered the button. /// private static readonly string EnterName = "enter"; public event EventHandler Entered { add { if (Events [EnterName] == null) Signals [EnterName] = new SimpleSignal ( this, RawObject, EnterName, value); Events.AddHandler (EnterName, value); } remove { Events.RemoveHandler (EnterName, value); if (Events [EnterName] == null) Signals.Remove (EnterName); } } /// /// Left Event /// /// /// /// Signal indicating that the focus has left the button. /// private static readonly string LeaveName = "leave"; public event EventHandler Left { add { if (Events [LeaveName] == null) Signals [LeaveName] = new SimpleSignal ( this, RawObject, LeaveName, value); Events.AddHandler (LeaveName, value); } remove { Events.RemoveHandler (LeaveName, value); if (Events [LeaveName] == null) Signals.Remove (LeaveName); } } /// /// Pressed Event /// /// /// /// Signal indicating that the button has been pressed. /// private static readonly string PressName = "pressed"; public event EventHandler Pressed { add { if (Events [PressName] == null) Signals [PressName] = new SimpleSignal ( this, RawObject, PressName, value); Events.AddHandler (PressName, value); } remove { Events.RemoveHandler (PressName, value); if (Events [PressName] == null) Signals.Remove (PressName); } } /// /// Released Event /// /// /// /// Signal indicating that the button has been released. /// private static readonly string RelName = "released"; public event EventHandler Released { add { if (Events [RelName] == null) Signals [RelName] = new SimpleSignal ( this, RawObject, RelName, value); Events.AddHandler (RelName, value); } remove { Events.RemoveHandler (RelName, value); if (Events [RelName] == null) Signals.Remove (RelName); } } /// /// Click Method /// /// /// /// Emit a Signal indicating that the button has been /// clicked. /// [DllImport("gtk-1.3.dll")] static extern void gtk_button_clicked (IntPtr obj); public void Click () { gtk_button_clicked (RawObject); } /// /// Enter Method /// /// /// /// Emit a Signal indicating that the focus has entered /// the button. /// [DllImport("gtk-1.3.dll")] static extern void gtk_button_enter (IntPtr obj); public void Enter () { gtk_button_enter (RawObject); } /// /// Leave Method /// /// /// /// Emit a Signal indicating that the focus has left the /// button. /// [DllImport("gtk-1.3.dll")] static extern void gtk_button_leave (IntPtr obj); public void Leave () { gtk_button_leave (RawObject); } /// /// Pressed Method /// /// /// /// Emit a Signal indicating that the button has been /// pressed. /// [DllImport("gtk-1.3.dll")] static extern void gtk_button_pressed (IntPtr obj); public void Press () { gtk_button_pressed (RawObject); } /// /// Release Method /// /// /// /// Emit a Signal indicating that the button has been /// released. /// [DllImport("gtk-1.3.dll")] static extern void gtk_button_released (IntPtr obj); public void Release () { gtk_button_released (RawObject); } } }