Added new samples widgets and modified togglebutton.

svn path=/trunk/gtk-sharp/; revision=9187
This commit is contained in:
Alejandro Sánchez Acosta 2002-11-25 19:09:29 +00:00
parent 701aba3e4a
commit 89e3c84951
9 changed files with 778 additions and 1 deletions

View File

@ -0,0 +1,11 @@
CSC = mcs
DLLS = -r glib-sharp.dll \
-r gtk-sharp.dll \
-r gdk-sharp.dll \
-r System.Drawing.dll
all:
$(CSC) /unsafe $(DLLS) eventbox.cs
clean:
rm -f *.exe

View File

@ -0,0 +1,68 @@
// eventbox.cs - Gtk# Tutorial example
//
// Author: Alejandro Sánchez Acosta <raciel@es.gnu.org>
// Cesar Octavio Lopez Nataren <cesar@ciencias.unam.mx>
//
// (c) 2002 Alejandro Sánchez Acosta
// Cesar Octavio Lopez Nataren
namespace GtkSharpTutorial {
using Gtk;
using GtkSharp;
using Gdk;
using GdkSharp;
using System;
using System.Drawing;
public class eventbox
{
static void delete_event (object obj, DeleteEventArgs args)
{
Application.Quit();
}
static void exitbutton_event (object obj, ButtonPressEventArgs args)
{
Application.Quit();
}
public static void Main (string[] args)
{
Gtk.Window window;
Gdk.CursorType cursortype;
EventBox eventbox;
Label label;
Application.Init();
window = new Gtk.Window ("Eventbox");
window.DeleteEvent += new DeleteEventHandler (delete_event);
window.BorderWidth = 10;
eventbox = new EventBox ();
window.Add (eventbox);
eventbox.Show();
label = new Label ("Click here to quit, quit, quit, quit");
eventbox.Add(label);
label.Show();
label.SetSizeRequest(110, 20);
/* eventbox.Events = GDK_BUTTON_PRESS_MASK; */ //Add this feature
eventbox.ButtonPressEvent += new ButtonPressEventHandler (exitbutton_event);
eventbox.Realize();
eventbox.GdkWindow.Cursor = Cursor.New(CursorType.Hand1);
window.Show();
Application.Run();
}
}
}

View File

@ -0,0 +1,12 @@
CSC = mcs
DLLS = -r glib-sharp.dll \
-r gtk-sharp.dll \
-r gdk-sharp.dll \
-r glib-sharp.dll \
-r System.Drawing.dll
all:
$(CSC) /unsafe $(DLLS) packing.cs
clean:
rm -f *.exe

View File

@ -0,0 +1,236 @@
// packingdemo.cs - Gtk# Tutorial example
//
// Author: Alejandro Sánchez Acosta <raciel@es.gnu.org>
// Cesar Octavio Lopez Nataren <cesar@ciencias.unam.mx>
//
// (c) 2002 Alejandro Sánchez Acosta
// Cesar Octavio Lopez Nataren
namespace GtkSharpTutorial {
using Gtk;
using GtkSharp;
using Gdk;
using GdkSharp;
using Glib;
using GlibSharp;
using System;
using System.Drawing;
public class fixedcontainer
{
public int x = 50;
public int y = 50;
static Gtk.HBox make_box (bool homogeneous, int spacing, bool expand, bool fill, uint padding)
{
HBox box;
Box box1;
Button button;
string padstr;
box = new HBox (homogeneous, spacing);
button = new Button ("gtk_box_pack");
box.PackStart (button, expand, fill, padding);
button.Show();
button = new Button ("(box,");
box.PackStart (button, expand, fill, padding);
button.Show();
button = new Button ("button");
box.PackStart (button, expand, fill, padding);
button.Show();
if (expand == true)
button = new Button ("TRUE");
else
button = new Button ("FALSE");
box.PackStart (button, expand, fill, padding);
button.Show();
button = new Button (fill ? "TRUE," : "FALSE,");
box.PackStart(button, expand, fill, padding);
button.Show();
padstr=padding.ToString()+");";
button = new Button (padstr);
box.PackStart (button, expand, fill, padding);
button.Show();
return box;
}
static void delete_event (object obj, DeleteEventArgs args)
{
Application.Quit();
}
static void exitbutton_event (object obj, ButtonPressEventArgs args)
{
Application.Quit();
}
public static int Main (string[] args)
{
Gtk.Window window;
Button button;
VBox box1;
HBox box2;
HSeparator separator;
Misc misc;
Box quitbox;
int which;
Gtk.Label label;
Application.Init();
if (args.Length !=1) {
Console.WriteLine ("Usage: packbox num, where num is 1, 2 o 3");
return (1);
}
which = Convert.ToInt32 (args[0]);
window = new Gtk.Window ("packingdemo");
window.DeleteEvent += new DeleteEventHandler (delete_event);
window.BorderWidth = 10;
box1 = new VBox (false, 0);
switch (which) {
case 1:
label=new Gtk.Label("gtk_hbox_new (FALSE, 0);");
box2 = new HBox (false, 0);
label.SetAlignment (0, 0);
box1.PackStart (label, false, false, 0);
label.Show();
box2 = make_box (false, 0, false, false, 0);
box1.PackStart (box2, false, false, 0);
box2.Show();
box2 = make_box (false, 0, true, false, 0);
box1.PackStart (box2, false, false, 0);
box2.Show();
box2 = make_box (false, 0, true, true, 0);
box1.PackStart (box2, false, false, 0);
box2.Show();
separator = new HSeparator ();
box1.PackStart (separator, false, true, 5);
separator.Show();
box1 = new VBox (true, 0);
label=new Gtk.Label("gtk_hbox_new (TRUE, 0);");
label.SetAlignment (0, 0);
box1.PackStart(label, false, false, 0);
label.Show();
box2 = make_box (true, 0, true, true, 0);
box1.PackStart (box2, false, false, 0);
box2.Show();
box2 = make_box (true, 0, true, true, 0);
box1.PackStart(box2, false, false, 0);
box2.Show();
separator = new HSeparator();
box1.PackStart (separator, false, true, 5);
separator.Show();
break;
case 2:
box2 = new HBox (false, 10);
label = new Gtk.Label("gtk_hbox_new (FALSE, 10);");
label.SetAlignment (0, 0);
box1.PackStart (box2, false, false, 0);
box1.Show();
box2 = make_box (false, 10, true, true, 0);
box1.PackStart (box2, false, false, 0);
box2.Show();
separator = new HSeparator ();
box1.PackStart (separator, false, true, 5);
separator.Show();
box2 = new HBox (false, 0);
label=new Gtk.Label("gtk_hbox_new (FALSE, 0);");
label.SetAlignment (0, 0);
box1.PackStart (label, false, false, 0);
label.Show();
box2 = make_box (false, 0, true, false, 10);
box1.PackStart (box2, false, false, 0);
box2.Show();
box2 = make_box (false, 0, true, true, 10);
box1.PackStart (box2, false, false, 0);
box2.Show();
separator = new HSeparator ();
box1.PackStart(separator, false, true, 5);
separator.Show();
break;
case 3:
box2 = make_box (false, 0, false, false, 0);
label = new Label ("end");
box2.PackEnd(label, false, false, 0);
label.Show();
box1.PackStart(box2, false, false, 0);
box2.Show();
separator = new HSeparator();
separator.SetSizeRequest(400, 5);
box1.PackStart (separator, false, true, 5);
separator.Show();
break;
}
quitbox = new HBox (false, 0);
button = new Button ("Quit");
button.Clicked += new EventHandler (ClickedEventHandler);
quitbox.PackStart(button, true, false, 0);
box1.PackStart (quitbox, false, false, 0);
window.Add(box1);
button.Show();
quitbox.Show();
box1.Show();
window.Show();
Application.Run();
return 0;
}
static void ClickedEventHandler(object sender, EventArgs e)
{
Application.Quit();
}
}
}

View File

@ -0,0 +1,11 @@
CSC = mcs
DLLS = -r glib-sharp.dll \
-r gtk-sharp.dll \
-r gdk-sharp.dll \
-r System.Drawing.dll
all:
$(CSC) /unsafe $(DLLS) rangeWidgetsSample.cs
clean:
rm -f *.exe

View File

@ -0,0 +1,295 @@
// checkbuttons.cs - GTK# Tutorial example
//
// Authors: Alejandro Sanchez Acosta <raciel@es.gnu.org>
// Cesar Octavio Lopez Nataren <cesar@ciencias.unam.mx>
//
// (C) 2002 Alejandro Sanchez Acosta <raciel@es.gnu.org>
// Cesar Octavio Lopez Nataren <cesar@ciencias.unam.mx>
namespace GtkSharpTutorial {
using Gtk;
using GtkSharp;
using System;
using System.Drawing;
public class rangeWidgetsSamples
{
static HScale hscale;
static VScale vscale;
static void cb_pos_menu_select (object obj, PositionType pos)
{
/* Set the value position on both scale widgets */
((Scale) hscale).ValuePos = pos;
((Scale) vscale).ValuePos = pos;
}
static void cb_update_menu_select (object obj, UpdateType policy)
{
/* Set the update policy for both scale widgets */
((Range) hscale).UpdatePolicy = policy;
((Range) vscale).UpdatePolicy = policy;
}
static void cb_digits_scale (Adjustment adj)
{
/* Set the number of decimal places to which adj->value is rounded */
/* FIXME: this might be wrong */
// ((Scale) hscale) = adj.Value;
// ((Scale) vscale) = adj.Value;
}
// FIXME
static void cb_page_size (Adjustment get, Adjustment set)
{
/* Set the page size and page increment size of the sample
* adjustment to the value specified by the "Page Size" scale */
//set.PageSize = get.Value;
//set->page_increment = = get.Value;
/* This sets the adjustment and makes it emit the "changed" signal to
reconfigure all the widgets that are attached to this signal. */
//set.ClampPage (
}
// FIXME
static void cb_draw_value (ToggleButton button)
{
/* Turn the value display on the scale widgets off or on depending
* on the state of the checkbutton */
//((Scale) hscale).DrawValue button.Active
//((Scale) vscale).DrawValue button.Active
}
/* Convenience functions */
// FIXME:
static Widget make_menu_item (string name /*, callback , gpointer */)
{
Widget w = null;
return w;
}
static void scale_set_default_values (Scale s)
{
s.UpdatePolicy = UpdateType.Continuous;
s.Digits = 1;
s.ValuePos = PositionType.Top;
s.DrawValue = true;
}
static void create_range_controls ()
{
Window window;
VBox box1, box3;
Box box2;
Button button;
HScrollbar scrollbar;
HSeparator separator;
Widget item; /* FIXME: find out the exactly widgets */
OptionMenu opt;
Menu menu;
Label label;
Scale scale;
Adjustment adj1, adj2;
window = new Window (WindowType.Toplevel);
// window.DeleteEvent += new DeleteEventHandler
window.Title = "range controls";
box1 = new VBox (false, 0);
window.Add (box1);
box1.ShowAll ();
box2 = new HBox (false, 0);
box2.BorderWidth = 10;
box1.PackStart (box2, true, true, 0);
box2.ShowAll ();
/* value, lower, upper, step_increment, page_increment, page_size */
/* Note that the page_size value only makes a difference for
* scrollbar widgets, and the highest value you'll get is actually
* (upper - page_size). */
adj1 = new Adjustment (0.0, 0.0, 101.0, 0.1, 1.0, 1.0);
vscale = new VScale ((Adjustment) adj1);
scale_set_default_values (vscale);
box2.PackStart (vscale, true, true, 0);
vscale.ShowAll ();
box3 = new VBox (false, 10);
box2.PackStart (box3, true, true, 0);
box3.ShowAll ();
/* Reuse the same adjustment */
hscale = new HScale ((Adjustment) adj1);
hscale.SetSizeRequest (200, -1);
scale_set_default_values (hscale);
box3.PackStart (hscale, true, true, 0);
hscale.ShowAll ();
/* reuse the same adjustment again */
scrollbar = new HScrollbar ((Adjustment) adj1);
/* Notice how this causes the scales to always be updated
* continuously when the scrollbar is moved */
scrollbar.UpdatePolicy = UpdateType.Continuous;
box3.PackStart (scrollbar, true, true, 0);
scrollbar.ShowAll ();
box2 = new HBox (false, 10);
box2.BorderWidth = 10;
box1.PackStart (box2, true, true, 0);
box2.ShowAll ();
/* A checkbutton to control whether the value is displayed or not */
button = new Button ("Display value on scale widgets");
//FIXME
//((ToggleButton) button).Active = true;
// FIXME: find out the handler signature
//((ToggleButton) button).Toggled +=
box2.PackStart (button, true, true, 0);
button.ShowAll ();
box2 = new HBox (false, 10);
box2.BorderWidth = 10;
/* An option menu to change the position of the value */
label = new Label ("Scale Value Position:");
box2.PackStart (label, false, false, 0);
label.ShowAll ();
opt = new OptionMenu ();
menu = new Menu ();
//FIXME:
item = new MenuItem ();
menu.Append (item);
// item =
menu.Append (item);
// item =
menu.Append (item);
// item =
menu.Append (item);
((OptionMenu) opt).Menu = menu;
box2.PackStart (opt, true, true, 0);
opt.ShowAll ();
box1.PackStart (box2, true, true, 0);
box2.ShowAll ();
box2 = new HBox (false, 10);
box2.BorderWidth = 10;
/* Yet another option menu, this time for the update policy of the
* scale widgets */
label = new Label ("Scale Update Policy:");
box2.PackStart (label, false, false, 0);
label.ShowAll ();
opt = new OptionMenu ();
menu = new Menu ();
// FIXME: continuous
item = new MenuItem ();
menu.Append (item);
// FIXME: discontinuous
item = new MenuItem ();
menu.Append (item);
//FIXME: delayed
item = new MenuItem ();
menu.Append (item);
opt.Menu = menu;
box2.PackStart (opt, true, true, 0);
opt.ShowAll ();
box1.PackStart (box2, true, true, 0);
box2.ShowAll ();
box2 = new HBox (false, 10);
box2.BorderWidth = 10;
/* An HScale widget for adjusting the number of digits on the
* sample scales. */
label = new Label ("Scale Digits:");
box2.PackStart (label, false, false, 0);
label.ShowAll ();
adj2 = new Adjustment (1.0, 0.0, 5.0, 1.0, 1.0, 0.0);
//FIXME: add a value_changed signal handler
scale = new HScale (adj2);
scale.Digits = 0;
box2.PackStart (scale, true, true, 0);
scale.ShowAll ();
box1.PackStart (box2, true, true, 0);
box2.ShowAll ();
box2 = new HBox (false, 10);
box2.BorderWidth = 10;
/* And, one last HScale widget for adjusting the page size of the
* scrollbar. */
label = new Label ("Scrollbar Page Size:");
box2.PackStart (label, false, false, 0);
label.ShowAll ();
adj2 = new Adjustment (1.0, 1.0, 101.0, 1.0, 1.0, 0.0);
// FIXME: write a value_changed signal handler
scale = new HScale (adj2);
scale.Digits = 0;
box2.PackStart (scale, true, true, 0);
scale.ShowAll ();
box1.PackStart (box2, true, true, 0);
box2.ShowAll ();
separator = new HSeparator ();
box1.PackStart (separator, false, true, 0);
separator.ShowAll ();
box2 = new VBox (false, 10);
box2.BorderWidth = 10;
box1.PackStart (box2, false, true, 0);
box2.ShowAll ();
button = new Button ("Quit");
// FIXME: write a clicked signal handler
box2.PackStart (button, true, true, 0);
//FIXME: set widget flags
//FIXME: grab default
button.ShowAll ();
window.ShowAll ();
}
public static void Main (string [] args)
{
Application.Init ();
create_range_controls ();
Application.Run ();
}
}
}

View File

@ -0,0 +1,11 @@
CSC = mcs
DLLS = -r glib-sharp.dll \
-r gtk-sharp.dll \
-r gdk-sharp.dll \
-r System.Drawing.dll
all:
$(CSC) /unsafe $(DLLS) Scribble.cs
clean:
rm -f *.exe

View File

@ -0,0 +1,133 @@
// Scribble.cs - port of Gtk+ scribble demo
//
// Author: Rachel Hestilow <hestilow@ximian.com>
//
// (c) 2002 Rachel Hestilow
namespace GtkSamples {
using Gtk;
using Gdk;
using GtkSharp;
using System;
public class Scribble {
private static Gtk.DrawingArea darea;
private static Gdk.Pixmap pixmap = null;
public static int Main (string[] args)
{
Application.Init ();
Gtk.Window win = new Gtk.Window ("Scribble demo");
win.DeleteEvent += new DeleteEventHandler (Window_Delete);
darea = new Gtk.DrawingArea ();
darea.SetSizeRequest (200, 200);
win.Add (darea);
darea.ExposeEvent += new ExposeEventHandler (ExposeEvent);
darea.ConfigureEvent += new ConfigureEventHandler (ConfigureEvent);
darea.MotionNotifyEvent += new MotionNotifyEventHandler (MotionNotifyEvent);
darea.ButtonPressEvent += new ButtonPressEventHandler (ButtonPressEvent);
darea.Events = (int)EventMask.ExposureMask |
(int)EventMask.LeaveNotifyMask |
(int)EventMask.ButtonPressMask |
(int)EventMask.PointerMotionMask |
(int)EventMask.PointerMotionHintMask;
win.ShowAll ();
Application.Run ();
return 0;
}
static void Window_Delete (object obj, DeleteEventArgs args)
{
SignalArgs sa = (SignalArgs) args;
Application.Quit ();
sa.RetVal = true;
}
static void ExposeEvent (object obj, ExposeEventArgs args)
{
Gdk.EventExpose ev = args.Event;
Gdk.Window window = ev.window;
// FIXME: mcs bug
Gdk.Rectangle area = ev.area;
// FIXME: array marshalling not done yet so no FG */
window.DrawDrawable (darea.Style.BlackGC,
pixmap,
area.x, area.y,
area.x, area.y,
area.width, area.height);
SignalArgs sa = (SignalArgs) args;
sa.RetVal = false;
}
static void ConfigureEvent (object obj, ConfigureEventArgs args)
{
Gdk.EventConfigure ev = args.Event;
Gdk.Window window = ev.window;
Gdk.Rectangle allocation = darea.Allocation;
pixmap = new Gdk.Pixmap (window,
allocation.width,
allocation.height,
-1);
pixmap.DrawRectangle (darea.Style.WhiteGC, 1, 0, 0,
allocation.width, allocation.height);
SignalArgs sa = (SignalArgs) args;
sa.RetVal = true;
}
static void DrawBrush (double x, double y)
{
Gdk.Rectangle update_rect = new Gdk.Rectangle ();
update_rect.x = (int) x - 5;
update_rect.y = (int) y - 5;
update_rect.width = 10;
update_rect.height = 10;
pixmap.DrawRectangle (darea.Style.BlackGC, 1,
update_rect.x, update_rect.y,
update_rect.width, update_rect.height);
darea.QueueDrawArea (update_rect.x, update_rect.y,
update_rect.width, update_rect.height);
}
static void ButtonPressEvent (object obj, ButtonPressEventArgs args)
{
Gdk.EventButton ev = args.Event;
if (ev.button == 1 && pixmap != null)
DrawBrush (ev.x, ev.y);
SignalArgs sa = (SignalArgs) args;
sa.RetVal = true;
}
static void MotionNotifyEvent (object obj, MotionNotifyEventArgs args)
{
int x, y;
Gdk.ModifierType state;
Gdk.EventMotion ev = args.Event;
Gdk.Window window = ev.window;
if (ev.is_hint != 0) {
int s;
window.GetPointer (out x, out y, out s);
state = (Gdk.ModifierType) s;
} else {
x = (int) ev.x;
y = (int) ev.y;
state = (Gdk.ModifierType) ev.state;
}
if ((state & Gdk.ModifierType.Button1Mask) != 0 && pixmap != null)
DrawBrush (x, y);
SignalArgs sa = (SignalArgs) args;
sa.RetVal = true;
}
}
}

View File

@ -12,7 +12,7 @@ namespace GtkSharpTutorial {
using System;
using System.Drawing;
public class checkbuttons
public class togglebuttons
{
static void delete_event (object obj, DeleteEventArgs args)