2001-10-06 Mike Kestner <mkestner@speakeasy.net>

* gtk/Button.cs : Implemented 3 constructors, 5 methods, 4 properties,
	and 6 signals.  Button API is 100% implemented.  Need to implement
	some Container methods to be able to complete testing.

svn path=/trunk/gtk-sharp/; revision=1104
This commit is contained in:
Mike Kestner 2001-10-06 02:47:11 +00:00
parent d659e12e05
commit 58dc5f24bf
2 changed files with 437 additions and 34 deletions

View file

@ -1,3 +1,9 @@
2001-10-06 Mike Kestner <mkestner@speakeasy.net>
* gtk/Button.cs : Implemented 3 constructors, 5 methods, 4 properties,
and 6 signals. Button API is 100% implemented. Need to implement
some Container methods to be able to complete testing.
2001-10-05 Mike Kestner <mkestner@speakeasy.net> 2001-10-05 Mike Kestner <mkestner@speakeasy.net>
* defs-parse.pl : A little automation for the binding. The enums and * defs-parse.pl : A little automation for the binding. The enums and

View file

@ -1,51 +1,64 @@
// GTK.Button.cs - GTK Button class implementation // GTK.Button.cs - GTK Button class implementation
// //
// Author: Bob Smith <bob@thestuff.net> // Authors: Bob Smith <bob@thestuff.net>
// Mike Kestner <mkestner@speakeasy.net>
// //
// (c) 2001 Bob Smith // (c) 2001 Bob Smith and Mike Kestner
namespace Gtk { namespace Gtk {
using System; using System;
using System.Collections;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using GLib;
/// <summary>
/// Button Class
/// </summary>
///
/// <remarks>
/// A Button user interface element.
/// </remarks>
public class Button : Widget { public class Button : Widget {
private static readonly string ClickedEvent = "clicked"; private Hashtable Signals = new Hashtable ();
/*
public event EventHandler Clicked /// <summary>
/// Button Constructor
/// </summary>
///
/// <remarks>
/// Constructs a Button with no label.
/// </remarks>
[DllImport("gtk-1.3.dll", CharSet=CharSet.Ansi,
CallingConvention=CallingConvention.Cdecl)]
static extern IntPtr gtk_button_new ();
public Button ()
{ {
add RawObject = gtk_button_new ();
{
AddSimpleEvent(ClickedEvent, value);
} }
remove
{
RemoveSimpleEvent (ClickedEvent, value);
}
}
*/
/// <summary> /// <summary>
/// Button Object Constructor /// Button Object Constructor
/// </summary> /// </summary>
/// ///
/// <remarks> /// <remarks>
/// Constructs a Button Wrapper. /// 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.
/// </remarks> /// </remarks>
///
/// <param name="obj">
/// Raw object reference from the native library.
/// </param>
public Button (IntPtr o) public Button (IntPtr obj)
{ {
RawObject = o; RawObject = obj;
}
~Button ()
{
/* FIXME: Find legal way to do this eventually.
foreach (EventHandler e in Events[ClickedEvent])
{
Clicked -= e;
}
*/
} }
/// <summary> /// <summary>
@ -53,15 +66,399 @@ namespace Gtk {
/// </summary> /// </summary>
/// ///
/// <remarks> /// <remarks>
/// Constructs a new Button with the specified content. /// 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.
/// </remarks>
///
/// <param name="label">
/// Text label or stock system id to display on the button.
/// </param>
[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));
}
/// <summary>
/// Button Constructor
/// </summary>
///
/// <remarks>
/// 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.
/// </remarks>
///
/// <param name="label">
/// Text label to display on the button face.
/// </param>
///
/// <param name="stock">
/// 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.
/// </param>
///
/// <param name="mnemonic">
/// Convert underscore to a mnemonic which can be used
/// to activate the button with the keyboard.
/// </param>
[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));
}
/// <summary>
/// Label Property
/// </summary>
///
/// <remarks>
/// Text label to display on the button face.
/// </remarks> /// </remarks>
[DllImport("gtk-1.3")] public String Label {
static extern IntPtr gtk_button_new_with_label (String str); get {
String val;
GetProperty ("label", out val);
return val;
}
set {
SetProperty ("label", value);
}
}
public Button (String str) /// <summary>
/// Relief Property
/// </summary>
///
/// <remarks>
/// Relief style used to draw the button.
/// </remarks>
public ReliefStyle Relief {
get {
int val;
GetProperty ("relief", out val);
return (ReliefStyle) val;
}
set {
SetProperty ("relief", (int) value);
}
}
/// <summary>
/// UseStock Property
/// </summary>
///
/// <remarks>
/// Indicates if stock button images should be used.
/// </remarks>
public bool UseStock {
get {
bool val;
GetProperty ("use-stock", out val);
return val;
}
set {
SetProperty ("use-stock", value);
}
}
/// <summary>
/// UseUnderline Property
/// </summary>
///
/// <remarks>
/// Indicates if underlines in the label text should be
/// treated as a mnemonic.
/// </remarks>
public bool UseUnderline {
get {
bool val;
GetProperty ("use-underline", out val);
return val;
}
set {
SetProperty ("use-underline", value);
}
}
/// <summary>
/// Activate Event
/// </summary>
///
/// <remarks>
/// Signal indicating that the button has been activated.
/// </remarks>
private static readonly string ActName = "activate";
public event EventHandler Activate
{ {
RawObject = gtk_button_new_with_label (str); 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);
} }
} }
/// <summary>
/// Clicked Event
/// </summary>
///
/// <remarks>
/// Signal indicating that the button has been clicked.
/// </remarks>
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);
}
}
/// <summary>
/// Enter Event
/// </summary>
///
/// <remarks>
/// Signal indicating that the focus has entered the button.
/// </remarks>
private static readonly string EnterName = "enter";
public event EventHandler Enter
{
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);
}
}
/// <summary>
/// Leave Event
/// </summary>
///
/// <remarks>
/// Signal indicating that the focus has left the button.
/// </remarks>
private static readonly string LeaveName = "leave";
public event EventHandler Leave
{
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);
}
}
/// <summary>
/// Pressed Event
/// </summary>
///
/// <remarks>
/// Signal indicating that the button has been pressed.
/// </remarks>
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);
}
}
/// <summary>
/// Released Event
/// </summary>
///
/// <remarks>
/// Signal indicating that the button has been released.
/// </remarks>
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);
}
}
/// <summary>
/// EmitClicked Method
/// </summary>
///
/// <remarks>
/// Emit a Signal indicating that the button has been
/// clicked.
/// </remarks>
[DllImport("gtk-1.3.dll")]
static extern void gtk_button_clicked (IntPtr obj);
public void EmitClicked ()
{
gtk_button_clicked (RawObject);
}
/// <summary>
/// EmitEnter Method
/// </summary>
///
/// <remarks>
/// Emit a Signal indicating that the focus has entered
/// the button.
/// </remarks>
[DllImport("gtk-1.3.dll")]
static extern void gtk_button_enter (IntPtr obj);
public void EmitEnter ()
{
gtk_button_enter (RawObject);
}
/// <summary>
/// EmitLeave Method
/// </summary>
///
/// <remarks>
/// Emit a Signal indicating that the focus has left the
/// button.
/// </remarks>
[DllImport("gtk-1.3.dll")]
static extern void gtk_button_leave (IntPtr obj);
public void EmitLeave ()
{
gtk_button_leave (RawObject);
}
/// <summary>
/// EmitPressed Method
/// </summary>
///
/// <remarks>
/// Emit a Signal indicating that the button has been
/// pressed.
/// </remarks>
[DllImport("gtk-1.3.dll")]
static extern void gtk_button_pressed (IntPtr obj);
public void EmitPressed ()
{
gtk_button_pressed (RawObject);
}
/// <summary>
/// EmitReleased Method
/// </summary>
///
/// <remarks>
/// Emit a Signal indicating that the button has been
/// released.
/// </remarks>
[DllImport("gtk-1.3.dll")]
static extern void gtk_button_released (IntPtr obj);
public void EmitReleased ()
{
gtk_button_released (RawObject);
}
}
} }