2003-10-30 Daniel Kornhauser Eisenberg <dkor@alum.mit.edu>

* sample/GtkDemo/DemoApplicationWindow.cs : New sample, Unfinished, 5%  Done
* sample/GtkDemo/DemoButtonBox.cs :      New sample,
* sample/GtkDemo/DemoColorSelection.cs : New sample,
* sample/GtkDemo/DemoDialog.cs :         New sample,
* sample/GtkDemo/DemoDrawingArea.cs :    New sample,
* sample/GtkDemo/DemoEditableCells.cs :  New sample, Needs clean up
* sample/GtkDemo/DemoImages.cs :         New sample, Unfinished, 75% Done
* sample/GtkDemo/DemoItemFactory.cs :    New sample, Unfinished, 5%  Done
* sample/GtkDemo/DemoListStore.cs :      New sample,
* sample/GtkDemo/DemoMain.cs :           New sample, Unifnished, 60% Done
* sample/GtkDemo/DemoMenus.cs :          New sample,
* sample/GtkDemo/DemoPanes.cs :          New sample,
* sample/GtkDemo/DemoPixbuf.cs :         New sample, Needs clean up
* sample/GtkDemo/DemoSizeGroup.cs :      New sample,
* sample/GtkDemo/DemoStockBrowser.cs :   New sample, Unfinished, 20% Done
* sample/GtkDemo/DemoTextView.cs :       New sample, Unfinished, 99% Done
* sample/GtkDemo/DemoTreeStore.cs :      New sample, Unfinished, 95% Done
* sample/GtkDemo/images : Several Images for the samples
* sample/GtkDemo/Makefile : Very simple Makefile
* sample/GtkDemo/README : Mentions explicitely unfinished state of port

svn path=/trunk/gtk-sharp/; revision=19489
This commit is contained in:
Daniel Kornhauser Eisenberg 2003-10-30 23:57:41 +00:00
parent 7cf6671bce
commit b3a7fd2924
19 changed files with 3301 additions and 0 deletions

View File

@ -0,0 +1,62 @@
//
// ApplicationWindow.cs, port of appwindow.c from gtk-demo
//
// Author: Daniel Kornhauser <dkor@alum.mit.edu>
//
// Copyright (C) 2003, Ximian Inc.
/* Application main window
*
* Demonstrates a typical application window, with menubar, toolbar, statusbar.
*/
// : - Is this necesary? /* Set up item factory to go away with the window */
using System;
using Gtk;
using GtkSharp;
namespace GtkDemo
{
public class DemoApplicationWindow
{
private Gtk.Window window;
// static ItemFactoryEntry items[] = { new ItemFactoryEntry ("/_File", null, 0, 0, "<Branch>" )};
public DemoApplicationWindow ()
{
window = new Gtk.Window ("Demo Application Window");
window.DeleteEvent += new DeleteEventHandler (WindowDelete);
Table table = new Table (1, 4, false);
window.Add (table);
// Create the menubar
AccelGroup accelGroup = new AccelGroup ();
window.AddAccelGroup (accelGroup);
//ItemFactory itemFactory = new ItemFactory ((uint) typeof (MenuBar),"<main>", accelGroup);
// static ItemFactoryEntry items[] = { new ItemFactoryEntry ("/_File", null, 0, 0, "<Branch>" )};
// Set up item factory to go away with the window
// Is this necesary ?
// create menu items
//STUCK : Didn't find any examples of ItemFactory
window.ShowAll ();
}
private void WindowDelete (object o, DeleteEventArgs args)
{
window.Hide ();
window.Destroy ();
}
}
}

View File

@ -0,0 +1,103 @@
//
// DemoButtonBox.cs, port of buttonbox.c from gtk-demo
//
// Author: Daniel Kornhauser <dkor@alum.mit.edu>
//
// Copyright (C) 2003, Ximian Inc.
/* Button Boxes
*
* The Button Box widgets are used to arrange buttons with padding.
*/
using System;
using Gtk;
using GtkSharp;
namespace GtkDemo
{
public class DemoButtonBox
{
private Gtk.Window window;
public DemoButtonBox ()
{
// Create a Window
window = new Gtk.Window ("Button Boxes");
window.DeleteEvent += new DeleteEventHandler (WindowDelete);
window.BorderWidth = 10;
// Add Vertical Box
VBox mainVbox = new VBox (false,0);
window.Add (mainVbox);
// Add Horizontal Frame
Frame horizontalFrame = new Frame ("Horizontal Button Boxes");
mainVbox.PackStart (horizontalFrame);
VBox vbox = new VBox (false, 0) ;
vbox.BorderWidth = 10;
horizontalFrame.Add (vbox);
// Pack Buttons
vbox.PackStart(CreateButtonBox (true, "Spread (spacing 40)", 40, 85, 20, ButtonBoxStyle.Spread));
vbox.PackStart(CreateButtonBox (true, "Edge (spacing 30)", 30, 85, 20, ButtonBoxStyle.Edge));
vbox.PackStart(CreateButtonBox (true, "Start (spacing 20)", 20, 85, 20, ButtonBoxStyle.Start));
vbox.PackStart(CreateButtonBox (true, "End (spacing 10)", 10, 85, 20, ButtonBoxStyle.End));
// Add Vertical Frame
Frame verticalFrame = new Frame ("Vertical Button Boxes");
mainVbox.PackStart (verticalFrame);
HBox hbox = new HBox (false, 0);
hbox.BorderWidth = 10;
verticalFrame.Add (hbox);
// Pack Buttons
hbox.PackStart(CreateButtonBox (false, "Spread (spacing 5)", 5, 85, 20, ButtonBoxStyle.Spread));
hbox.PackStart(CreateButtonBox (false, "Edge (spacing 30)", 30, 85, 20, ButtonBoxStyle.Edge));
hbox.PackStart(CreateButtonBox (false, "Start (spacing 20)", 20, 85, 20, ButtonBoxStyle.Start));
hbox.PackStart(CreateButtonBox (false, "End (spacing 20)", 20, 85, 20, ButtonBoxStyle.End));
window.ShowAll ();
}
// Create a Button Box with the specified parameters
private Frame CreateButtonBox (bool horizontal, string title, int spacing, int childW , int childH , ButtonBoxStyle layout)
{
Frame frame = new Frame (title);
Gtk.ButtonBox bbox ;
if (horizontal == true)
{
bbox = new Gtk.HButtonBox ();
}
else
{
bbox = new Gtk.VButtonBox ();
}
bbox.BorderWidth = 5;
frame.Add (bbox);
// Set the appearance of the Button Box
bbox.Layout = layout;
bbox.Spacing= spacing;
Button buttonOk = Button.NewFromStock (Stock.Ok);
bbox.Add (buttonOk);
Button buttonCancel = Button.NewFromStock (Stock.Cancel);
bbox.Add (buttonCancel);
Button buttonHelp = Button.NewFromStock (Stock.Help);
bbox.Add (buttonHelp);
return frame;
}
private void WindowDelete (object o, DeleteEventArgs args)
{
window.Hide ();
window.Destroy ();
}
}
}

View File

@ -0,0 +1,110 @@
//
// DemoColorSelection.cs, port of colorsel.c from gtk-demo
//
// Author: Daniel Kornhauser <dkor@alum.mit.edu>
//
// Copyright (C) 2003, Ximian Inc.
/*
*
* GtkColorSelection lets the user choose a color. GtkColorSelectionDialog is
* a prebuilt dialog containing a GtkColorSelection.
*
*/
using System;
using Gdk;
using Gtk;
using GtkSharp;
namespace GtkDemo
{
public class DemoColorSelection
{
private Gtk.Window window ;
private Gdk.Color color;
private ColorSelectionDialog colorSelectionDialog;
private Gtk.DrawingArea drawingArea;
public DemoColorSelection ()
{
window = new Gtk.Window ("Color Selection");
window.DeleteEvent += new DeleteEventHandler (WindowDelete);
window.BorderWidth = 8;
VBox vbox = new VBox (false,8);
vbox.BorderWidth = 8;
window.Add (vbox);
// Create the color swatch area
Frame frame = new Frame ();
frame.ShadowType = ShadowType.In;
vbox.PackStart (frame, true, true, 0);
drawingArea = new DrawingArea ();
drawingArea.ExposeEvent += new ExposeEventHandler (ExposeEventCallback);
// set a minimum size
drawingArea.SetSizeRequest (200,200);
// set the color
color = new Gdk.Color (0, 0, 0xff);
drawingArea.ModifyBg (StateType.Normal, color);
frame.Add (drawingArea);
Alignment alignment = new Alignment (1.0f, 0.5f, 0.0f, 0.0f);
Button button = new Button ("_Change the above color");
button.Clicked += new EventHandler (ChangeColorCallback);
alignment.Add (button);
vbox.PackStart (alignment);
window.ShowAll ();
}
private void WindowDelete (object o, DeleteEventArgs args)
{
window.Hide ();
window.Destroy ();
}
// Expose callback for the drawing area
private void ExposeEventCallback (object o, ExposeEventArgs args)
{
EventExpose eventExpose = args.Event;
Gdk.Window window = eventExpose.window;
Rectangle area = eventExpose.area;
window.DrawRectangle (drawingArea.Style.BackgroundGC(StateType.Normal),
true,
area.x, area.y,
area.width, area.height);
SignalArgs sa = (SignalArgs) args;
sa.RetVal = true;
}
private void ChangeColorCallback (object o, EventArgs args)
{
colorSelectionDialog = new ColorSelectionDialog ("Changing color");
colorSelectionDialog.TransientFor = window;
colorSelectionDialog.ColorSelection.PreviousColor = color;
colorSelectionDialog.ColorSelection.CurrentColor = color;
colorSelectionDialog.ColorSelection.HasPalette = true;
colorSelectionDialog.CancelButton.Clicked += new EventHandler (Color_Selection_Cancel);
colorSelectionDialog.OkButton.Clicked += new EventHandler (Color_Selection_OK);
colorSelectionDialog.ShowAll();
}
private void Color_Selection_OK (object o, EventArgs args)
{
Gdk.Color selected = colorSelectionDialog.ColorSelection.CurrentColor;
drawingArea.ModifyBg (StateType.Normal, selected);
colorSelectionDialog.Destroy ();
}
private void Color_Selection_Cancel (object o, EventArgs args)
{
colorSelectionDialog.Destroy ();
}
}
}

View File

@ -0,0 +1,149 @@
//
// DemoDialog.cs, port of dialog.c from gtk-demo
//
// Author Daniel Kornhauser <dkor@alum.mit.edu>
//
// Copyright (C) 2003, Ximian Inc.
/*
*
*Dialog widgets are used to pop up a transient window for user feedback.
*
*/
// TODO: - Couldn't find a good equivalent to gtk_dialog_new_with_buttons
// in InteractiveDialogClicked
// - Check how to handle response type. Can we make the button to have
// the binding to the cancel signal automagicly like in
// gtk_dialog_new_with_buttons or should we just use the if ?
using System;
using Gtk;
using GtkSharp;
namespace GtkDemo
{
public class DemoDialog
{
private Gtk.Window window;
private Entry entry1;
private Entry entry2;
public DemoDialog ()
{
window = new Gtk.Window ("Dialogs");
window.DeleteEvent += new DeleteEventHandler(WindowDelete);
window.BorderWidth = 8;
Frame frame = new Frame ("Dialogs");
window.Add (frame);
VBox vbox = new VBox (false, 8);
vbox.BorderWidth = 8;
frame.Add (vbox);
// Standard message dialog
HBox hbox = new HBox (false,8);
vbox.PackStart (hbox, false, false, 0);
Button button = new Button ("_Message Dialog");
button.Clicked += new EventHandler (MessageDialogClicked);
hbox.PackStart (button, false, false, 0);
vbox.PackStart (new HSeparator());
// Interactive dialog
hbox = new HBox (false, 8);
vbox.PackStart (hbox, false, false, 0);
VBox vbox2 = new VBox (false, 0);
button = new Button ("_Interactive Dialog");
button.Clicked += new EventHandler (InteractiveDialogClicked);
hbox.PackStart (vbox2, false, false, 0);
vbox2.PackStart (button, false, false, 0);
Table table = new Table (2, 2, false);
table.RowSpacing = 4;
table.ColumnSpacing = 4;
hbox.PackStart (table);
Label label = Label.NewWithMnemonic ("_Entry1");
table.Attach (label, 0, 1, 0, 1);
entry1 = new Entry ();
table.Attach (entry1, 1, 2, 0, 1);
label.MnemonicWidget = entry1;
label = Label.NewWithMnemonic ("E_ntry2");
table.Attach (label,0,1,1,2);
entry2 = new Entry ();
table.Attach (entry2, 1, 2, 1, 2);
label.MnemonicWidget = entry2;
window.ShowAll ();
}
private void WindowDelete (object o, DeleteEventArgs args)
{
window.Hide ();
window.Destroy ();
}
private int i = 1;
private void MessageDialogClicked (object o, EventArgs args)
{
string message = String.Format("This message box has been popped up the following\n number of times:\n\n {0:D} ", i);
Dialog dialog = new MessageDialog(window,
DialogFlags.Modal | DialogFlags.DestroyWithParent,
MessageType.Info,
ButtonsType.Ok,
message);
dialog.Run ();
dialog.Destroy ();
i++;
}
private void InteractiveDialogClicked (object o, EventArgs args)
{
MessageDialog dialog = new MessageDialog (window,
DialogFlags.Modal | DialogFlags.DestroyWithParent,
MessageType.Question,
ButtonsType.Ok,
null);
dialog.AddButton ("_Non-stock Button", (int) ResponseType.Cancel);
HBox hbox = new HBox (false, 8);
hbox.BorderWidth = 8;
dialog.VBox.PackStart (hbox, false, false, 0);
Table table = new Table (2, 2, false);
table.RowSpacing = 4;
table.ColumnSpacing = 4;
hbox.PackStart (table, false, false, 0);
Label label = Label.NewWithMnemonic ("_Entry1");
table.Attach (label, 0, 1, 0, 1);
Entry localEntry1 = new Entry();
localEntry1.Text = entry1.Text;
table.Attach (localEntry1, 1, 2, 0, 1);
label.MnemonicWidget = localEntry1;
label = Label.NewWithMnemonic ("E_ntry2");
table.Attach (label, 0, 1, 1, 2);
Entry localEntry2 = new Entry();
localEntry2.Text = entry2.Text;
table.Attach (localEntry2, 1, 2, 1, 2);
label.MnemonicWidget = localEntry2;
hbox.ShowAll ();
ResponseType response = (ResponseType) dialog.Run ();
if (response == ResponseType.Ok)
{
entry1.Text = localEntry1.Text;
entry2.Text = localEntry2.Text;
}
dialog.Destroy ();
}
}
}

View File

@ -0,0 +1,256 @@
//
// DemoDrawingArea.cs, port of drawingarea.c from gtk-demo
//
// Author: Daniel Kornhauser <dkor@alum.mit.edu>
// Rachel Hestilow <hestilow@ximian.com>
//
// Copyright (C) 2003, Ximian Inc.
//
/* Drawing Area
*
* GtkDrawingArea is a blank area where you can draw custom displays
* of various kinds.
*
* This demo has two drawing areas. The checkerboard area shows
* how you can just draw something; all you have to do is write
* a signal handler for ExposeEvent, as shown here.
*
* The "scribble" area is a bit more advanced, and shows how to handle
* events such as button presses and mouse motion. Click the mouse
* and drag in the scribble area to draw squiggles. Resize the window
* to clear the area.
*/
using System;
using Gtk;
using Gdk;
using GtkSharp;
namespace GtkDemo {
public class DemoDrawingArea
{
private Gtk.Window window;
private static Pixmap pixmap = null;
private static DrawingArea drawingArea;
private static DrawingArea drawingArea1;
public DemoDrawingArea ()
{
window = new Gtk.Window ("Drawing Area");
window.DeleteEvent += new DeleteEventHandler (WindowDelete);
window.BorderWidth = 8;
VBox vbox = new VBox (false, 8);
vbox.BorderWidth = 8;
window.Add (vbox);
// Create the checkerboard area
Label label = new Label(null);
label.Markup = "<u>Checkerboard pattern</u>";
vbox.PackStart (label, false, false, 0);
Frame frame = new Frame ();
frame.ShadowType = ShadowType.In;
vbox.PackStart (frame, true, true, 0);
drawingArea = new DrawingArea();
// set a minimum size
drawingArea.SetSizeRequest (100,100);
frame.Add(drawingArea);
drawingArea.ExposeEvent += new ExposeEventHandler (CheckerboardExpose);
// Create the scribble area
Label label1 = new Label ("<u>Scribble area</u>");
label1.UseMarkup = true;
vbox.PackStart (label1, false, false, 0);
Frame frame1 = new Frame ();
frame1.ShadowType = ShadowType.In;
vbox.PackStart (frame1, true, true, 0);
drawingArea1 = new DrawingArea ();
// set a minimun size
drawingArea1.SetSizeRequest (100, 100);
frame1.Add (drawingArea1);
// Signals used to handle backing pixmap
drawingArea1.ExposeEvent += new ExposeEventHandler (ScribbleExpose);
drawingArea1.ConfigureEvent += new ConfigureEventHandler (ScribbleConfigure);
// Event signals
drawingArea1.MotionNotifyEvent += new MotionNotifyEventHandler (ScribbleMotionNotify);
drawingArea1.ButtonPressEvent += new ButtonPressEventHandler (ScribbleButtonPress);
// Ask to receive events the drawing area doesn't normally
// subscribe to
drawingArea1.Events = (int)EventMask.LeaveNotifyMask |
(int)EventMask.ButtonPressMask |
(int)EventMask.PointerMotionMask |
(int)EventMask.PointerMotionHintMask;
window.ShowAll ();
}
private void WindowDelete (object o, DeleteEventArgs args)
{
window.Hide ();
window.Destroy ();
}
private void CheckerboardExpose (object o, ExposeEventArgs args)
{
// Defining the size of the Checks
const int CheckSize = 10;
const int Spacing = 2;
// Defining the color of the Checks
int i, j, xcount, ycount;
Gdk.GC gc, gc1, gc2;
Gdk.Color color = new Gdk.Color ();
EventExpose eventExpose = args.Event;
Gdk.Window window = eventExpose.window;
gc1 = new Gdk.GC (window);
color.red = 30000;
color.green = 0;
color.blue = 30000;
gc1.RgbFgColor = color;
gc2 = new Gdk.GC (window);
color.red = 65535;
color.green = 65535;
color.blue = 65535;
gc2.RgbFgColor = color;
// Start redrawing the Checkerboard
xcount = 0;
i = Spacing;
while (i < drawingArea.Allocation.width){
j = Spacing;
ycount = xcount % 2; //start with even/odd depending on row
while (j < drawingArea.Allocation.height){
gc = new Gdk.GC (window);
if (ycount % 2 != 0){
gc = gc1;}
else{
gc = gc2;}
window.DrawRectangle(gc, true, i, j, CheckSize, CheckSize);
j += CheckSize + Spacing;
++ycount;
}
i += CheckSize + Spacing;
++xcount;
}
// return true because we've handled this event, so no
// further processing is required.
SignalArgs sa = (SignalArgs) args;
sa.RetVal = true;
}
private void ScribbleExpose (object o, ExposeEventArgs args)
{
// We use the "ForegroundGC" for the widget since it already exists,
// but honestly any GC would work. The only thing to worry about
// is whether the GC has an inappropriate clip region set.
EventExpose eventExpose = args.Event;
Gdk.Window window = eventExpose.window;
Rectangle area = eventExpose.area;
window.DrawDrawable (drawingArea1.Style.ForegroundGC(StateType.Normal),
pixmap,
area.x, area.y,
area.x, area.y,
area.width, area.height);
SignalArgs sa = (SignalArgs) args;
sa.RetVal = false;
}
// Create a new pixmap of the appropriate size to store our scribbles
private void ScribbleConfigure (object o, ConfigureEventArgs args)
{
EventConfigure eventConfigure = args.Event;
Gdk.Window window = eventConfigure.window;
Rectangle allocation = drawingArea1.Allocation;
pixmap = new Pixmap (window,
allocation.width,
allocation.height,
-1);
// Initialize the pixmap to white
pixmap.DrawRectangle (drawingArea1.Style.WhiteGC, true, 0, 0,
allocation.width, allocation.height);
SignalArgs sa = (SignalArgs) args;
// We've handled the configure event, no need for further processing.
sa.RetVal = true;
}
private void ScribbleMotionNotify (object o, MotionNotifyEventArgs args)
{
// This call is very important; it requests the next motion event.
// If you don't call Window.GetPointer() you'll only get
// a single motion event. The reason is that we specified
// PointerMotionHintMask in drawingArea1.Events.
// If we hadn't specified that, we could just use ExposeEvent.x, ExposeEvent.y
// as the pointer location. But we'd also get deluged in events.
// By requesting the next event as we handle the current one,
// we avoid getting a huge number of events faster than we
// can cope.
int x, y;
ModifierType state;
EventMotion ev = args.Event;
Gdk.Window window = ev.window;
if (ev.is_hint != 0) {
ModifierType s;
window.GetPointer (out x, out y, out s);
state = s;
} else {
x = (int) ev.x;
y = (int) ev.y;
state = (ModifierType) ev.state;
}
if ((state & ModifierType.Button1Mask) != 0 && pixmap != null)
DrawBrush (x, y);
/* We've handled it, stop processing */
SignalArgs sa = (SignalArgs) args;
sa.RetVal = true;
}
// Draw a rectangle on the screen
static void DrawBrush (double x, double y)
{
Rectangle update_rect = new Rectangle ();
update_rect.x = (int) x - 3;
update_rect.y = (int) y - 3;
update_rect.width = 6;
update_rect.height = 6;
//Paint to the pixmap, where we store our state
pixmap.DrawRectangle (drawingArea1.Style.BlackGC, true,
update_rect.x, update_rect.y,
update_rect.width, update_rect.height);
drawingArea1.QueueDrawArea (update_rect.x, update_rect.y,
update_rect.width, update_rect.height);
}
private void ScribbleButtonPress (object o, ButtonPressEventArgs args)
{
EventButton ev = args.Event;
if (ev.button == 1 && pixmap != null)
DrawBrush (ev.x, ev.y);
//We've handled the event, stop processing
SignalArgs sa = (SignalArgs) args;
sa.RetVal = true;
}
}
}

View File

@ -0,0 +1,240 @@
//
// DemoEditableCells.cs, port of appwindow.c from gtk-demo
//
// Author: Daniel Kornhauser <dkor@alum.mit.edu>
//
// Copyright (C) 2003, Ximian Inc.
/* Tree View/Editable Cells
*
* This demo demonstrates the use of editable cells in a Gtk.TreeView. If
* you are new to the Gtk.TreeView widgets and associates, look into
* the Gtk.ListStore example first.
*
*/
using System;
using System.Collections;
using Gtk;
using GtkSharp;
namespace GtkDemo
{
public class DemoEditableCells
{
private Gtk.Window window;
private ListStore store;
private TreeView treeView;
private ArrayList articles;
public DemoEditableCells ()
{
window = new Gtk.Window ("Color Selection");
window.SetDefaultSize (320, 200);
window.DeleteEvent += new DeleteEventHandler (WindowDelete);
VBox vbox = new VBox (false, 5);
window.Add (vbox);
vbox.PackStart (new Label ("Shopping list (you can edit the cells!)"), false, false, 0);
ScrolledWindow scrolledWindow = new ScrolledWindow (null, null);
scrolledWindow.ShadowType = ShadowType.In;
scrolledWindow.SetPolicy (PolicyType.Automatic, PolicyType.Automatic);
vbox.PackStart (scrolledWindow);
// create tree view
treeView = new TreeView ();
CreateModel ();
treeView.Model = store ;
AddColumns ();
scrolledWindow.Add (treeView);
// some buttons
HBox hbox = new HBox (true, 4);
vbox.PackStart (hbox, false, false, 0);
Button button = new Button ("Add item");
button.Clicked += new EventHandler (AddItem);
hbox.PackStart (button, true, true, 0);
button = new Button ("Remove item");
button.Clicked += new EventHandler (RemoveItem);
hbox.PackStart (button, true, true, 0);
window.ShowAll ();
}
private void AddColumns ()
{
CellRendererText renderer;
renderer = new CellRendererText ();
renderer.Edited += new EditedHandler (NumberCellEdited);
renderer.Editable = true;
// renderer.Data ("column", (int) Column.Number);
treeView.AppendColumn ("Number", renderer,
"text", (int) Column.Number);
// product column
renderer = new CellRendererText ();
renderer.Edited += new EditedHandler (TextCellEdited);
renderer.Editable = true;
// renderer.Data ("column", (int) Column.Product);
treeView.AppendColumn ("Product", renderer ,
"text", (int) Column.Product);
}
private void CreateModel ()
{
// create array
articles = new ArrayList ();
AddItems ();
// create list store
store = new ListStore (typeof (int), typeof (string), typeof (bool));
// add items
foreach (Item item in articles)
store.AppendValues (item.Number, item.Product, item.Editable);
}
private void AddItems ()
{
Item foo;
foo = new Item (3, "bottles of coke", true);
articles.Add (foo);
foo = new Item (5, "packages of noodles", true);
articles.Add (foo);
foo = new Item (2, "packages of chocolate chip cookies", true);
articles.Add (foo);
foo = new Item (1, "can of vanilla ice cream", true);
articles.Add (foo);
foo = new Item (6, "eggs", true);
articles.Add (foo);
}
private void WindowDelete (object o, DeleteEventArgs args)
{
window.Hide ();
window.Destroy ();
}
// FIXME: This is ugly.
// Figure out why the following line doesn't work
// Console.WriteLine ("articles[i] {0}", articles[i].Number);
// the code would definitely look better if I havent to do the
// following midle step to get the Number.
// foo.Number = Convert.ToInt32(args.NewText);
//, Figure out why I'm not catching the execptions..
private void NumberCellEdited (object o, EditedArgs args)
{
int i;
try
{
i = Convert.ToInt32(args.Path);
}
catch (Exception e)
{
Console.WriteLine ("Exeception {0}",e);
return; // This return should exit the callback but it doesn't
}
Console.WriteLine ("--NUMBER--1");
// //Console.WriteLine ("Path {0}", args.Path);
// //Console.WriteLine ("NewText {0}", args.NewText);
// //Console.WriteLine ("articles[i] {0}",articles[i]);
Item foo = (Item) articles[i];
// //Console.WriteLine ("foo.Number {0}", foo.Number);
// //Console.WriteLine ("");
foo.Number = Convert.ToInt32(args.NewText);
TreeIter iter = new TreeIter ();
// // How the hell do I assing the column !!!
store.GetIterFromString(out iter, args.Path);
// store.SetValue(iter, (int) Column.Number, foo.Number);
}
private void TextCellEdited (object o, EditedArgs args)
{
int i = Convert.ToInt32(args.Path);
// Console.WriteLine ("--PRODUCT--");
// Console.WriteLine ("Path {0}", args.Path);
// Console.WriteLine ("NewText {0}", args.NewText);
// Console.WriteLine ("articles[i] {0}",articles[i]);
Item foo = (Item) articles[i];
// Console.WriteLine ("foo.Product {0}", foo.Product);
// Console.WriteLine ("");
foo.Product = args.NewText;
TreeIter iter = new TreeIter ();
store.GetIterFromString(out iter, args.Path);
store.SetValue(iter, (int) Column.Product, foo.Product);
}
private void AddItem (object o, EventArgs args)
{
Item foo = new Item (0, "Description here", true);
articles.Add (foo);
store.AppendValues (foo.Number, foo.Product, foo.Editable);
}
private void RemoveItem (object o, EventArgs args)
{
TreeIter iter = new TreeIter ();
TreeModel model;
if (treeView.Selection.GetSelected (out model, ref iter))
{
TreePath path = store.GetPath (iter);
store.Remove (out iter);
//articles.RemoveAt (path.Indices[0]);
}
}
}
public enum Column
{
Number,
Product,
Editable,
};
public struct Item
{
public int Number {
get {return NumberItem;}
set {NumberItem = value;}
}
public string Product {
get {return ProductItem;}
set {ProductItem = value;}
}
public bool Editable {
get {return EditableItem;}
set {EditableItem = value;}
}
private int NumberItem;
private string ProductItem;
private bool EditableItem;
public Item (int number , string product, bool editable)
{
NumberItem = number;
ProductItem = product;
EditableItem = editable;
}
}
}

View File

@ -0,0 +1,167 @@
//
// DemoImages.cs - port of images.c gtk-demo
//
// Author: Daniel Kornhauser <dkor@alum.mit.edu>
//
// Copyright (C) 2003, Ximian Inc.
//
/* Images
*
* Gtk.Image is used to display an image; the image can be in a number of formats.
* Typically, you load an image into a Gdk.Pixbuf, then display the pixbuf.
*
* This demo code shows some of the more obscure cases, in the simple
* case a call to the constructor Gtk.Image (string filename) is all you need.
*
* If you want to put image data in your program compile it in as a resource.
* This way you will not need to depend on loading external files, your
* application binary can be self-contained.
*/
// TODO:
// Finish implementing the callback, I can't get the image
// to show up, and I'm stuck in the ProgressivePreparedCallback
// because I can't get a white background to appear
using System;
using System.IO;
using Gtk;
using Gdk;
using GtkSharp;
using GdkSharp;
namespace GtkDemo {
public class DemoImages
{
private Gtk.Window window;
private static Gtk.Image progressiveImage;
private VBox vbox;
public DemoImages ()
{
window = new Gtk.Window ("Images");
window.DeleteEvent += new DeleteEventHandler (WindowDelete);
window.BorderWidth = 8;
vbox = new VBox (false, 8);
vbox.BorderWidth = 8;
window.Add (vbox);
Gtk.Label label = new Gtk.Label ("<u>Image loaded from a file</u>");
label.UseMarkup = true;
vbox.PackStart (label, false, false, 0);
Gtk.Frame frame = new Gtk.Frame ();
frame.ShadowType = ShadowType.In;
// The alignment keeps the frame from growing when users resize
// the window
Alignment alignment = new Alignment (0.5f, 0.5f, 0f, 0f);
alignment.Add (frame);
vbox.PackStart (alignment, false, false, 0);
Gtk.Image image = new Gtk.Image ("images/gtk-logo-rgb.gif");
frame.Add (image);
// Animation
label = new Gtk.Label ("<u>Animation loaded from a file</u>");
label.UseMarkup = true;
vbox.PackStart (label);
frame = new Gtk.Frame ();
frame.ShadowType = ShadowType.In;
alignment = new Alignment (0.5f, 0.5f, 0f, 0f);
alignment.Add (frame);
vbox.PackStart (alignment, false, false, 0);
image = new Gtk.Image ("images/floppybuddy.gif");
frame.Add (image);
// Progressive
label = new Gtk.Label ("<u>Progressive image loading</u>");
label.UseMarkup = true;
vbox.PackStart (label);
frame = new Gtk.Frame ();
frame.ShadowType = ShadowType.In;
alignment = new Alignment (0.5f, 0.5f, 0f, 0f);
alignment.Add (frame);
vbox.PackStart (alignment, false, false, 0);
// Create an empty image for now; the progressive loader
// will create the pixbuf and fill it in.
//
progressiveImage = new Gtk.Image ();
frame.Add (progressiveImage);
StartProgressiveLoading ();
// Sensitivity control
Gtk.ToggleButton button = new Gtk.ToggleButton ("_Insensitive");
vbox.PackStart (button, false, false, 0);
button.Toggled += new EventHandler (ToggleSensitivity);
window.ShowAll ();
}
private void WindowDelete (object o, DeleteEventArgs args)
{
window.Hide ();
window.Destroy ();
}
private void ToggleSensitivity (object o, EventArgs args)
{
GLib.List children = vbox.Children;
foreach (Widget widget in children)
/* don't disable our toggle */
if (widget.GetType () != o.GetType () )
widget.Sensitive = !widget.Sensitive;
}
private uint timeout_id;
private void StartProgressiveLoading ()
{
/* This is obviously totally contrived (we slow down loading
* on purpose to show how incremental loading works).
* The real purpose of incremental loading is the case where
* you are reading data from a slow source such as the network.
* The timeout simply simulates a slow data source by inserting
* pauses in the reading process.
*/
timeout_id = GLib.Timeout.Add(150, new GLib.TimeoutHandler(ProgressiveTimeout));
}
static Gdk.PixbufLoader pixbufLoader;
// TODO: Finish this callback
// Decide if we want to perform crazy error handling
private bool ProgressiveTimeout()
{
Gtk.Image imageStream = new Gtk.Image ("images/alphatest.png");
pixbufLoader = new Gdk.PixbufLoader ();
pixbufLoader.AreaPrepared += new EventHandler (ProgressivePreparedCallback);
pixbufLoader.AreaUpdated += new AreaUpdatedHandler (ProgressiveUpdatedCallback);
return true;
}
static void ProgressivePreparedCallback (object obj, EventArgs args)
{
Gdk.Pixbuf pixbuf = pixbufLoader.Pixbuf;
pixbuf.Fill (0xaaaaaaff);
progressiveImage.FromPixbuf = pixbuf;
}
static void ProgressiveUpdatedCallback (object obj, AreaUpdatedArgs args)
{
}
}
}

View File

@ -0,0 +1,45 @@
//
// DemoItemFactoryDemo.cs - port of item_factory from gtk-demo
//
// Author: Daniel Kornhauser <dkor@alum.mit.edu>
//
// Copyright (C) 2003, Ximian Inc.
/* Item Factory
*
* The GtkItemFactory object allows the easy creation of menus
* from an array of descriptions of menu items.
*/
// TODO: - unfinished
using System;
using System.IO;
using Gtk;
using Gdk;
using GtkSharp;
namespace GtkDemo
{
public class DemoItemFactory
{
private Gtk.Window window;
public DemoItemFactory ()
{
window = new Gtk.Window (null);
window.DeleteEvent += new DeleteEventHandler (WindowDelete);
Gtk.AccelGroup accelGroup = new Gtk.AccelGroup ();
//STUCK OUCH !!!!
window.ShowAll ();
}
private void WindowDelete (object o, DeleteEventArgs args)
{
window.Hide ();
window.Destroy ();
}
}
}

View File

@ -0,0 +1,177 @@
//
// DemoListItem.cs, port of tree_store.c from gtk-demo
//
// Author: Daniel Kornhauser <dkor@alum.mit.edu>
//
// Copyright (C) 2003, Ximian Inc.
/* List View/List Store
*
* The Gtk.ListStore is used to store data in tree form, to be
* used later on by a Gtk.ListView to display it. This demo builds
* a simple Gtk.ListStore and displays it. If you're new to the
* Gtk.ListView widgets and associates, look into the Gtk.ListStore
* example first.
*/
using System;
using System.Collections;
using Gtk;
using GtkSharp;
namespace GtkDemo
{
public class DemoListStore
{
private Window window;
ListStore store;
public DemoListStore (){
window = new Window ("ListStore Demo");
window.DeleteEvent += new DeleteEventHandler (WindowDelete);
VBox vbox = new VBox (false, 8);
vbox.BorderWidth = 8;
window.Add (vbox);
vbox.PackStart(new Label ("This is the bug list (note: not based on real data, it would be nice to have a nice ODBC interface to bugzilla or so, though)."), false, false, 0);
ScrolledWindow scrolledWindow = new ScrolledWindow ();
scrolledWindow.ShadowType = ShadowType.EtchedIn;
scrolledWindow.SetPolicy (PolicyType.Automatic, PolicyType.Automatic);
vbox.PackStart (scrolledWindow, true, true, 0);
// create model
CreateModel();
// create tree view
TreeView treeView = new TreeView (store);
treeView.RulesHint = true;
treeView.SearchColumn = (int) ColumnNumber.Description;
AddColumns (treeView);
scrolledWindow.Add (treeView);
// finish & show
window.SetDefaultSize (650, 400);
window.ShowAll ();
}
//FIXME: Finish implementing this function, I don't know
// why it doesn't work.
private void ItemToggled (object o, ToggledArgs args)
{
Gtk.TreeIter iter;
if (store.GetIterFromString(out iter, args.Path))
{
bool val = (bool) store.GetValue(iter, 0);
Console.WriteLine("toggled {0} with value {1}", args.Path, val);
store.SetValue(iter, 0, !val);
}
}
private void AddColumns (TreeView treeView)
{
// column for fixed toggles
CellRendererToggle rendererToggle = new CellRendererToggle ();
rendererToggle.Toggled += new ToggledHandler (ItemToggled);
TreeViewColumn column = new TreeViewColumn("Fixed", rendererToggle, "active", 0);
rendererToggle.Active = true;
rendererToggle.Activatable = true;
rendererToggle.Visible = true;
// set this column to a fixed sizing (of 50 pixels)
column.Sizing = TreeViewColumnSizing.Fixed;
column.FixedWidth = 50;
treeView.AppendColumn(column);
// column for bug numbers
CellRendererText rendererText = new CellRendererText ();
column = new TreeViewColumn("Bug number", rendererText, "text", ColumnNumber.Number);
column.SortColumnId = (int) ColumnNumber.Number;
treeView.AppendColumn(column);
// column for severities
rendererText = new CellRendererText ();
column = new TreeViewColumn("Severity", rendererText, "text", ColumnNumber.Severity);
column.SortColumnId = (int) ColumnNumber.Severity;
treeView.AppendColumn(column);
// column for description
rendererText = new CellRendererText ();
column = new TreeViewColumn("Description", rendererText, "text", ColumnNumber.Description);
column.SortColumnId = (int) ColumnNumber.Description;
treeView.AppendColumn(column);
}
private void WindowDelete (object o, DeleteEventArgs args)
{
window.Hide ();
window.Destroy ();
}
private void CreateModel ()
{
store = new ListStore (
typeof(bool),
typeof(int),
typeof(string),
typeof(string));
foreach (Bug bug in bugs) {
store.AppendValues(bug.Fixed,
bug.Number,
bug.Severity,
bug.Description);}
}
//FIXME: Insted of using numbert conver enum to array using
// GetValues and then ge the Length Property
public enum ColumnNumber
{
Fixed,
Number,
Severity,
Description,
}
private static Bug[] bugs =
{
new Bug ( false, 60482, "Normal", "scrollable notebooks and hidden tabs"),
new Bug ( false, 60620, "Critical", "gdk_window_clear_area (gdkwindow-win32.c) is not thread-safe" ),
new Bug ( false, 50214, "Major", "Xft support does not clean up correctly" ),
new Bug ( true, 52877, "Major", "GtkFileSelection needs a refresh method. " ),
new Bug ( false, 56070, "Normal", "Can't click button after setting in sensitive" ),
new Bug ( true, 56355, "Normal", "GtkLabel - Not all changes propagate correctly" ),
new Bug ( false, 50055, "Normal", "Rework width/height computations for TreeView" ),
new Bug ( false, 58278, "Normal", "gtk_dialog_set_response_sensitive () doesn't work" ),
new Bug ( false, 55767, "Normal", "Getters for all setters" ),
new Bug ( false, 56925, "Normal", "Gtkcalender size" ),
new Bug ( false, 56221, "Normal", "Selectable label needs right-click copy menu" ),
new Bug ( true, 50939, "Normal", "Add shift clicking to GtkTextView" ),
new Bug ( false, 6112, "Enhancement","netscape-like collapsable toolbars" ),
new Bug ( false, 1, "Normal", "First bug :=)" )
};
}
public class Bug
{
public bool Fixed;
public int Number;
public string Severity;
public string Description;
public Bug ( bool status,
int number,
string severity,
string description)
{
Fixed = status;
Number = number;
Severity = severity;
Description = description;
}
}
}

311
sample/GtkDemo/DemoMain.cs Normal file
View File

@ -0,0 +1,311 @@
//
// DemoMain.cs, port of main.c from gtk-demo
//
// Author: Daniel Kornhauser <dkor@alum.mit.edu>
//
// Copyright (C) 2003, Ximian Inc.
using System;
using System.IO;
using System.Collections;
using Gdk;
using Gtk;
using GtkSharp;
using Pango;
namespace GtkDemo
{
public class DemoMain
{
private Gtk.Window window;
private TextBuffer infoBuffer = new TextBuffer(null);
private TextBuffer sourceBuffer = new TextBuffer(null);
private TreeView treeView;
private TreeStore store;
public static void Main (string[] args)
{
Application.Init ();
new DemoMain ();
Application.Run ();
}
public DemoMain ()
{
SetupDefaultIcon ();
window = new Gtk.Window ("Gtk# Code Demos");
window.SetDefaultSize (600,400);
window.DeleteEvent += new DeleteEventHandler (WindowDelete);
HBox hbox = new HBox (false, 0);
window.Add (hbox);
TreeView tree = CreateTree ();
tree.AppendColumn ("Widget (double click for demo)", new CellRendererText (), "text", 0);
tree.Model = FillTree ();
tree.Selection.Changed += new EventHandler (OnTreeChanged);
tree.RowActivated += new RowActivatedHandler (OnRowActivated);
hbox.PackStart (tree, false, false, 0);
Notebook notebook = new Notebook ();
hbox.PackStart (notebook, true, true, 0);
notebook.AppendPage (CreateText (infoBuffer, false), Label.NewWithMnemonic ("_Info"));
notebook.AppendPage (CreateText (sourceBuffer, true), Label.NewWithMnemonic ("_Source"));
window.ShowAll ();
}
private void LoadFile(string filename)
{
Stream file = File.OpenRead(filename);
StreamReader sr = new StreamReader(file);
string s = sr.ReadToEnd();
sr.Close();
file.Close();
infoBuffer.Text = filename;
sourceBuffer.Text = s;
Fontify();
}
private void Fontify()
{
}
// TODO: Display system error
private void SetupDefaultIcon ()
{
Gdk.Pixbuf pixbuf = new Gdk.Pixbuf ("images/gtk-logo-rgb.gif");
if (pixbuf != null)
{
// The gtk-logo-rgb icon has a white background, make it transparent
Pixbuf transparent = pixbuf.AddAlpha (true, 0xff, 0xff, 0xff);
GLib.List list = new GLib.List (IntPtr.Zero, typeof (Gtk.Widget));
list.Append (transparent.Handle);
Gtk.Window.DefaultIconList = list;
}
}
// BUG: I have to click twice close in order for the dialog to disappear
private void ResponseCallback (object obj, ResponseArgs args)
{
Dialog dialog = (Dialog) obj ;
dialog.Destroy ();
}
private ScrolledWindow CreateText (TextBuffer buffer, bool IsSource)
{
ScrolledWindow scrolledWindow = new ScrolledWindow ();
scrolledWindow.SetPolicy (PolicyType.Automatic, PolicyType.Automatic);
scrolledWindow.ShadowType = ShadowType.In;
TextView textView = new TextView ();
textView.Buffer = buffer;
// STUCK
textView.Editable = false;
textView.CursorVisible = false;
scrolledWindow.Add (textView);
if (IsSource)
{
FontDescription fontDescription = FontDescription.FromString ("Courier 12");
textView.ModifyFont (fontDescription);
textView.WrapMode = Gtk.WrapMode.None;
}
else
{
// Make it a bit nicer for text
textView.WrapMode = Gtk.WrapMode.Word;
textView.PixelsAboveLines = 2;
textView.PixelsBelowLines = 2;
}
return scrolledWindow;
}
private TreeView CreateTree ()
{
treeView = new TreeView ();
return treeView;
}
private TreeStore FillTree ()
{
store = new TreeStore (typeof (string));
store.AppendValues ("Application Window (5% complete)");
store.AppendValues ("Button Boxes");
store.AppendValues ("Change Display");
store.AppendValues ("Color Selector");
store.AppendValues ("Dialog and Message Boxes");
store.AppendValues ("Drawing Area");
store.AppendValues ("Images");
store.AppendValues ("Item Factory (5% complete)");
store.AppendValues ("Menus");
store.AppendValues ("Paned Widget");
store.AppendValues ("Pixbuf");
store.AppendValues ("Size Groups");
store.AppendValues ("Stock Item and Icon Browser (10% complete)");
store.AppendValues ("Text Widget (95% complete)");
TreeIter iter = store.AppendValues ("Tree View");
store.AppendValues (iter, "Editable Cells (buggy)");
store.AppendValues (iter, "List Store");
store.AppendValues (iter, "Tree Store (95% complete)");
return store;
}
private void OnTreeChanged (object o, EventArgs args)
{
TreeIter iter = new TreeIter ();
TreeModel model;
if (treeView.Selection.GetSelected (out model, ref iter))
{
TreePath path;
path = store.GetPath (iter);
switch (path.ToString()) {
case "0":
LoadFile ("DemoApplicationWindow.cs");
break;
case "1":
LoadFile ("DemoButtonBox.cs");
break;
case "2":
//
break;
case "3":
LoadFile ("DemoColorSelection.cs");
break;
case "4":
LoadFile ("DemoDialog.cs");
break;
case "5":
LoadFile ("DemoDrawingArea.cs");
break;
case "6":
LoadFile ("DemoImages.cs");
break;
case "7":
LoadFile ("DemoItemFactory.cs");
break;
case "8":
LoadFile ("DemoMenus.cs");
break;
case "9":
LoadFile ("DemoPanes.cs");
break;
case "10":
LoadFile ("DemoPixbuf.cs");
break;
case "11":
LoadFile ("DemoSizeGroup.cs");
break;
case "12":
LoadFile ("DemoStockBrowser.cs");
break;
case "13":
LoadFile ("DemoTextView.cs");
break;
case "14":
// do nothing
break;
case "14:0":
LoadFile ("DemoEditableCells.cs");
break;
case "14:1":
LoadFile ("DemoListStore.cs");
break;
case "14:2":
LoadFile ("DemoTreeStore.cs");
break;
default:
break;
}
}
}
private void OnRowActivated (object o, RowActivatedArgs args)
{
switch (args.Path.ToString ()) {
case "0":
new DemoApplicationWindow ();
break;
case "1":
new DemoButtonBox ();
break;
case "2":
//
break;
case "3":
new DemoColorSelection ();
break;
case "4":
new DemoDialog ();
break;
case "5":
new DemoDrawingArea ();
break;
case "6":
new DemoImages ();
break;
case "7":
new DemoItemFactory ();
break;
case "8":
new DemoMenus ();
break;
case "9":
new DemoPanes ();
break;
case "10":
new DemoPixbuf ();
break;
case "11":
new DemoSizeGroup ();
break;
case "12":
new DemoStockBrowser ();
break;
case "13":
new DemoTextView ();
break;
case "14":
// do nothing
break;
case "14:0":
new DemoEditableCells ();
break;
case "14:1":
new DemoListStore ();
break;
case "14:2":
new DemoTreeStore ();
break;
default:
break;
}
}
private void WindowDelete (object o, DeleteEventArgs args)
{
Application.Quit ();
args.RetVal = true;
}
}
}

178
sample/GtkDemo/DemoMenus.cs Normal file
View File

@ -0,0 +1,178 @@
//
// TestMenus.cs
//
// Author: Duncan Mak (duncan@ximian.com)
//
// Copyright (C) 2002, Duncan Mak, Ximian Inc.
//
/* Menus
*
* There are several widgets involved in displaying menus. The
* MenuBar widget is a horizontal menu bar, which normally appears
* at the top of an application. The Menu widget is the actual menu
* that pops up. Both MenuBar and Menu are subclasses of
* MenuShell; a MenuShell contains menu items
* (MenuItem). Each menu item contains text and/or images and can
* be selected by the user.
*
* There are several kinds of menu item, including plain MenuItem,
* CheckMenuItem which can be checked/unchecked, RadioMenuItem
* which is a check menu item that's in a mutually exclusive group,
* SeparatorMenuItem which is a separator bar, TearoffMenuItem
* which allows a Menu to be torn off, and ImageMenuItem which
* can place a Image or other widget next to the menu text.
*
* A MenuItem can have a submenu, which is simply a Menu to pop
* up when the menu item is selected. Typically, all menu items in a menu bar
* have submenus.
*
* The OptionMenu widget is a button that pops up a Menu when clicked.
* It's used inside dialogs and such.
*
* ItemFactory provides a higher-level interface for creating menu bars
* and menus; while you can construct menus manually, most people don't
* do that. There's a separate demo for ItemFactory.
*
*/
// TODO : window width is not exactly equal
// point on the right side
using System;
using Gtk;
using GtkSharp;
namespace GtkDemo
{
public class DemoMenus
{
private Gtk.Window window;
public DemoMenus ()
{
window = new Window ("Menus");
window.DeleteEvent += new DeleteEventHandler (WindowDelete);
AccelGroup accel_group = new AccelGroup ();
window.AddAccelGroup (accel_group);
VBox box1 = new VBox (false, 0);
window.Add (box1);
MenuBar menubar = new MenuBar ();
box1.PackStart (menubar, false, false, 0);
Menu menu = Create_Menu (2, true);
MenuItem menuitem = new MenuItem ("test\nline2");
menuitem.Submenu = menu;
menubar.Append (menuitem);
MenuItem menuitem1 = new MenuItem ("foo");
menuitem1.Submenu = Create_Menu (3, true);
menubar.Append (menuitem1);
menuitem = new MenuItem ("bar");
menuitem.Submenu = Create_Menu (4, true);
menuitem.RightJustified = true;
menubar.Append (menuitem);
menubar = new MenuBar ();
box1.PackStart (menubar, false, true, 0);
VBox box2 = new VBox (false, 10);
box2.BorderWidth = 10;
box1.PackStart (box2, true, true, 0);
menu = Create_Menu (1, false);
menu.AccelGroup = accel_group;
menu.Append (new SeparatorMenuItem ());
menuitem = new CheckMenuItem ("Accelerate Me");
menu.Append (menuitem);
menuitem.AddAccelerator ("activate", accel_group, 0xFFBE, 0, AccelFlags.Visible);
menuitem = new CheckMenuItem ("Accelerator locked");
menu.Append (menuitem);
menuitem.AddAccelerator ("activate", accel_group, 0xFFBF, 0, AccelFlags.Visible | AccelFlags.Locked);
menuitem = new CheckMenuItem ("Accelerator Frozen");
menu.Append (menuitem);
menuitem.AddAccelerator ("activate", accel_group, 0xFFBF, 0, AccelFlags.Visible);
menuitem.AddAccelerator ("activate", accel_group, 0xFFC0, 0, AccelFlags.Visible);
OptionMenu option_menu = new OptionMenu ();
option_menu.Menu = menu;
option_menu.SetHistory (3);
box2.PackStart (option_menu, true, true, 0);
box1.PackStart (new HSeparator (), false, false, 0);
box2 = new VBox (false, 10);
box2.BorderWidth = 10;
box1.PackStart (box2, false, true, 0);
Button close_button = new Button ("close");
close_button.Clicked += new EventHandler (Close_Button);
box2.PackStart (close_button, true, true, 0);
close_button.CanDefault = true;
close_button.GrabDefault ();
window.ShowAll ();
}
private Menu Create_Menu (int depth, bool tearoff)
{
if (depth < 1)
return null;
Menu menu = new Menu ();
MenuItem menuitem;
string label;
GLib.SList group = new GLib.SList (IntPtr.Zero);
if (tearoff)
{
menuitem = new TearoffMenuItem ();
menu.Append (menuitem);
menuitem.Show ();
}
for (int i = 0, j = 1; i < 5; i++, j++)
{
label = String.Format ("item {0} - {1}", depth, j);
menuitem = RadioMenuItem.NewWithLabel (group, label);
group = ((RadioMenuItem) menuitem).Group;
menuitem = new MenuItem (label);
menu.Append (menuitem);
if (i == 3)
menuitem.Sensitive = false;
Menu child = Create_Menu ((depth - 1), true);
if (child != null)
menuitem.Submenu = child;
}
return menu;
}
private void Close_Button (object o, EventArgs args)
{
window.Hide ();
window.Destroy ();
}
private void WindowDelete (object o, DeleteEventArgs args)
{
window.Hide ();
window.Destroy ();
}
}
}

183
sample/GtkDemo/DemoPanes.cs Normal file
View File

@ -0,0 +1,183 @@
//
// DemoPanes.cs
//
// Author: Daniel Kornhauser <dkor@alum.mit.edu>
//
// Copyright (C) 2002, Daniel Kornhauser, Ximian Inc.
//
/* Paned Widgets
*
* The HPaned and VPaned Widgets divide their content
* area into two panes with a divider in between that the
* user can adjust. A separate child is placed into each
* pane.
*
* There are a number of options that can be set for each pane.
* This test contains both a horizontal (HPaned) and a vertical
* (VPaned) widget, and allows you to adjust the options for
* each side of each widget.
*/
using System;
using Gtk;
using GtkSharp;
namespace GtkDemo
{
public class DemoPanes
{
private Window window;
private VPaned vpaned;
private HPaned top;
private Frame left;
private Frame right;
private Frame bottom;
private CheckButton resizeLeft;
private CheckButton shrinkLeft;
private CheckButton resizeRight;
private CheckButton shrinkRight;
private CheckButton resizeTop;
private CheckButton shrinkTop;
private CheckButton resizeBottom;
private CheckButton shrinkBottom;
private Button button;
public DemoPanes ()
{
window = new Window ("Panes");
window.DeleteEvent += new DeleteEventHandler (WindowDelete);
window.BorderWidth = 0;
VBox vbox = new VBox (false, 0);
window.Add (vbox);
vpaned = new VPaned ();
vbox.PackStart (vpaned, true, true, 0);
vpaned.BorderWidth = 5;
top = new HPaned ();
vpaned.Add1 (top);
left = new Frame ();
left.ShadowType = ShadowType.In;
left.SetSizeRequest (60, 60);
top.Add1 (left);
button = new Button ("_Hi there");
left.Add (button);
right = new Frame ();
right.ShadowType = ShadowType.In;
right.SetSizeRequest (80, 60);
top.Add2 (right);
bottom = new Frame ();
bottom.ShadowType = ShadowType.In;
bottom.SetSizeRequest (80, 60);
vpaned.Add2 (bottom);
// Now create toggle buttons to control sizing
Frame frame = new Frame ("Horizonal");
frame.BorderWidth = 4;
vbox.PackStart (frame);
Table table = new Table (3, 2, true);
frame.Add (table);
Label label = new Label ("Left");
table.Attach (label, 0, 1, 0, 1);
resizeLeft = new CheckButton ("_Resize");
table.Attach (resizeLeft, 0, 1, 1, 2);
resizeLeft.Toggled += new EventHandler (LeftCB);
shrinkLeft = new CheckButton ("_Shrink");
table.Attach (shrinkLeft, 0, 1, 2, 3);
shrinkLeft.Active = true;
shrinkLeft.Toggled += new EventHandler (LeftCB);
label = new Label ("Right");
table.Attach (label, 1, 2, 0, 1);
resizeRight = new CheckButton ("_Resize");
table.Attach (resizeRight, 1, 2, 1, 2);
resizeRight.Active = true;
resizeRight.Toggled += new EventHandler (RightCB);
shrinkRight = new CheckButton ("_Shrink");
table.Attach (shrinkRight, 1, 2, 2, 3);
shrinkRight.Active = true;
shrinkRight.Toggled += new EventHandler (RightCB);
frame = new Frame ("Vertical");
frame.BorderWidth = 4;
vbox.PackStart (frame);
table = new Table (3, 2, true);
frame.Add (table);
label = new Label ("Top");
table.Attach (label, 0, 1, 0, 1);
resizeTop = new CheckButton ("_Resize");
table.Attach (resizeTop, 0, 1, 1, 2);
resizeTop.Toggled += new EventHandler (TopCB);
shrinkTop = new CheckButton ("_Shrink");
table.Attach (shrinkTop, 0, 1, 2, 3);
shrinkTop.Active = true;
shrinkTop.Toggled += new EventHandler (TopCB);
label = new Label ("Bottom");
table.Attach (label, 1, 2, 0, 1);
resizeBottom = new CheckButton ("_Resize");
table.Attach (resizeBottom, 1, 2, 1, 2);
resizeBottom.Active = true;
resizeBottom.Toggled += new EventHandler (BottomCB);
shrinkBottom = new CheckButton ("_Shrink");
table.Attach (shrinkBottom, 1, 2, 2, 3);
shrinkBottom.Active = true;
shrinkBottom.Toggled += new EventHandler (BottomCB);
window.ShowAll ();
}
private void LeftCB (object o, EventArgs args)
{
top.Remove(left);
top.Pack1(left, resizeLeft.Active, shrinkLeft.Active);
}
private void RightCB (object o, EventArgs args)
{
top.Remove(right);
top.Pack2(right, resizeRight.Active, shrinkRight.Active);
}
private void TopCB (object o, EventArgs args)
{
vpaned.Remove(top);
vpaned.Pack1(top, resizeTop.Active, shrinkTop.Active);
}
private void BottomCB (object o, EventArgs args)
{
vpaned.Remove(bottom);
vpaned.Pack2(bottom, resizeBottom.Active, shrinkBottom.Active);
}
private void WindowDelete (object o, DeleteEventArgs args)
{
window.Hide ();
window.Destroy ();
}
}
}

View File

@ -0,0 +1,218 @@
// DemoPixbuf.cs: Pixbuf demonstration
//
// Gtk# port of pixbuf demo in gtk-demo app.
//
// Author: Yves Kurz <yves@magnific.ch>
//
// <c> 2003 Yves Kurz
/* Pixbufs
*
* A Pixbuf represents an image, normally in RGB or RGBA format.
* Pixbufs are normally used to load files from disk and perform
* image scaling.
*
* This demo is not all that educational, but looks cool. It was written
* by Extreme Pixbuf Hacker Federico Mena Quintero. It also shows
* off how to use DrawingArea to do a simple animation.
*
* Look at the Image demo for additional pixbuf usage examples.
*
*/
using Gdk;
using Gtk;
using GtkSharp;
using System;
namespace GtkDemo
{
public class DemoPixbuf : Gtk.Window
{
const int FrameDelay = 50;
const int CycleLen = 60;
const string BackgroundName = "images/background.jpg";
string [] ImageNames = {
"images/apple-red.png",
"images/gnome-applets.png",
"images/gnome-calendar.png",
"images/gnome-foot.png",
"images/gnome-gmush.png",
"images/gnome-gimp.png",
"images/gnome-gsame.png",
"images/gnu-keys.png"
};
// current frame
Pixbuf frame;
int frameNum;
// background image
Pixbuf background;
int backWidth, backHeight;
// images
Pixbuf[] images;
// drawing area
DrawingArea drawingArea;
string FindFile (string name)
{
return name;
}
// Loads the images for the demo
void LoadPixbuf ()
{
background = new Pixbuf (FindFile (BackgroundName));
backWidth = background.Width;
backHeight = background.Height;
images = new Pixbuf[ImageNames.Length];
for (int i = 0; i < ImageNames.Length; i++)
images[i] = new Pixbuf (FindFile (ImageNames[i]));
}
// Expose callback for the drawing area
void Expose (object o, ExposeEventArgs args)
{
EventExpose ev = args.Event;
Widget widget = (Widget) o;
Gdk.Rectangle area = ev.area;
frame.RenderToDrawableAlpha(
widget.GdkWindow,
0, 0,
0, 0,
backWidth, backHeight,
Gdk.PixbufAlphaMode.Full, 8,
RgbDither.Normal,
100, 100);
}
// timeout handler to regenerate the frame
bool timeout ()
{
background.CopyArea (0, 0, backWidth, backHeight, frame, 0, 0);
double f = (double) (frameNum % CycleLen) / CycleLen;
int xmid = backWidth / 2;
int ymid = backHeight / 2;
double radius = Math.Min (xmid, ymid) / 2;
for (int i = 0; i < images.Length; i++) {
double ang = 2 * Math.PI * i / images.Length - f * 2 *
Math.PI;
int iw = images[i].Width;
int ih = images[i].Height;
double r = radius + (radius / 3) * Math.Sin (f * 2 *
Math.PI);
int xpos = (int) Math.Floor (xmid + r * Math.Cos (ang) -
iw / 2 + 0.5);
int ypos = (int) Math.Floor (ymid + r * Math.Sin (ang) -
ih / 2 + 0.5);
double k = (i % 2 == 1) ? Math.Sin (f * 2 * Math.PI) :
Math.Cos (f * 2 * Math.PI);
k = 2 * k * k;
k = Math.Max (0.25, k);
Rectangle r1, r2, dest;
r1 = new Rectangle (xpos, ypos,(int) (iw * k),
(int) (ih * k));
/* FIXME: Why is that code not working (in the original gtk-demo it works
r2 = new Rectangle (0, 0, backWidth, backHeight);
dest = new Rectangle (0, 0, 0, 0);
r1.Intersect (r2, dest);
images[i].Composite (frame, dest.x, dest.y, dest.width,
dest.height, xpos, ypos, k, k,
InterpType.Nearest, (int) ((i % 2 == 1)
? Math.Max (127, Math.Abs (255 * Math.Sin (f *
2 * Math.PI)))
: Math.Max (127, Math.Abs (255 * Math.Cos (f *
2 * Math.PI)))));
*/
images[i].Composite (frame, r1.x, r1.y, r1.width,
r1.height, xpos, ypos, k, k,
InterpType.Nearest, (int) ((i % 2 == 1)
? Math.Max (127, Math.Abs (255 * Math.Sin (f *
2 * Math.PI)))
: Math.Max (127, Math.Abs (255 * Math.Cos (f *
2 * Math.PI)))));
}
drawingArea.QueueDraw ();
frameNum++;
return true;
}
private Gtk.Window window;
public DemoPixbuf () : base ("Gdk Pixbuf Demo")
{
//window = new DemoPixbuf ();
//window.DeleteEvent += new DeleteEventHandler (WindowDelete);
try {
LoadPixbuf ();
} catch (Exception e) {
MessageDialog md = new MessageDialog (this,
DialogFlags.DestroyWithParent,
MessageType.Error,
ButtonsType.Close,
"Error: \n" + e.Message);
md.Run ();
throw;
}
frame = new Pixbuf (Colorspace.Rgb, true, 8, backWidth,
backHeight);
drawingArea = new DrawingArea ();
drawingArea.ExposeEvent += new ExposeEventHandler (Expose);
Add (drawingArea);
GLib.Timeout.Add (FrameDelay, new GLib.TimeoutHandler(timeout));
this.SetDefaultSize (backWidth, backHeight);
// this.Resizable = false;
ShowAll ();
}
static void windowDelete (object obj, DeleteEventArgs args)
{
Application.Quit ();
}
}
}

View File

@ -0,0 +1,158 @@
//
// DemoSizeGroup.cs
//
// Author: Duncan Mak (duncan@ximian.com)
//
// Copyright (C) 2002, Duncan Mak, Ximian Inc.
//
/* Size Groups
*
* SizeGroup provides a mechanism for grouping a number of
* widgets together so they all request the same amount of space.
* This is typically useful when you want a column of widgets to
* have the same size, but you can't use a Table widget.
*
* Note that size groups only affect the amount of space requested,
* not the size that the widgets finally receive. If you want the
* widgets in a SizeGroup to actually be the same size, you need
* to pack them in such a way that they get the size they request
* and not more. For example, if you are packing your widgets
* into a table, you would not include the Gtk.Fill flag.
*/
using System;
using Gtk;
using GtkSharp;
namespace GtkDemo
{
public class DemoSizeGroup
{
private Dialog window;
private SizeGroup sizeGroup;
public DemoSizeGroup ()
{
window = new Dialog ();
window.Title = "Sized groups";
window.Resizable = false;
VBox vbox = new VBox (false, 5);
window.VBox.PackStart (vbox, true, true, 0);
vbox.BorderWidth = 5;
sizeGroup = new SizeGroup (SizeGroupMode.Horizontal);
//Create one frame holding color options
Frame frame = new Frame ("Color Options");
vbox.PackStart (frame, true, true, 0);
Table table = new Table (2, 2, false);
table.BorderWidth = 5;
table.RowSpacing = 5;
table.ColumnSpacing = 10;
frame.Add (table);
string [] colors = {"Red", "Green", "Blue", };
string [] dashes = {"Solid", "Dashed", "Dotted", };
string [] ends = {"Square", "Round", "Arrow", };
AddRow (table, 0, sizeGroup, "_Foreground", colors);
AddRow (table, 1, sizeGroup, "_Background", colors);
// And another frame holding line style options
frame = new Frame ("Line Options");
vbox.PackStart (frame, false, false, 0);
table = new Table (2, 2, false);
table.BorderWidth = 5;
table.RowSpacing = 5;
table.ColumnSpacing = 10;
frame.Add (table);
AddRow (table, 0, sizeGroup, "_Dashing", dashes);
AddRow (table, 1, sizeGroup, "_Line ends", ends);
// And a check button to turn grouping on and off
CheckButton checkButton = new CheckButton ("_Enable grouping");
vbox.PackStart (checkButton, false, false, 0);
checkButton.Active = true;
checkButton.Toggled += new EventHandler (ButtonToggleCb);
Button CloseButton = Button.NewFromStock (Stock.Close);
window.AddActionWidget (CloseButton, 5);
window.Response += new ResponseHandler (ResponseCallback);
window.ShowAll ();
}
// Convenience function to create an option menu holding a number of strings
private OptionMenu CreateOptionMenu (string [] strings)
{
Menu menu = new Menu ();
MenuItem menuItem;
foreach (string str in strings)
{
menuItem = new MenuItem (str);
menuItem.Show ();
menu.Append (menuItem);
}
OptionMenu optionMenu = new OptionMenu ();
optionMenu.Menu = menu;
return optionMenu;
}
private void AddRow (Table table, uint row, SizeGroup sizeGroup, string labelText, string [] options)
{
Label label = Label.NewWithMnemonic (labelText);
label.SetAlignment (0, 1);
table.Attach (label,
0, 1, row, row + 1,
AttachOptions.Expand, AttachOptions.Fill,
0, 0);
OptionMenu optionMenu = CreateOptionMenu (options);
sizeGroup.AddWidget (optionMenu);
table.Attach (optionMenu,
1, 2, row, row + 1,
AttachOptions.Expand, AttachOptions.Expand,
0, 0);
}
private void ButtonToggleCb (object o, EventArgs args)
{
ToggleGrouping ((ToggleButton) o, sizeGroup);
}
// SizeGroupMode.None is not generally useful, but is useful
// here to show the effect of SizeGroupMode.Horizontal by
// contrast
private void ToggleGrouping (ToggleButton checkButton, SizeGroup sizeGroup)
{
SizeGroupMode mode;
if (checkButton.Active)
mode = SizeGroupMode.Horizontal;
else
mode = SizeGroupMode.None;
sizeGroup.Mode = mode;
}
private void ResponseCallback (object obj, ResponseArgs args)
{
if (args.ResponseId == 5) {
window.Hide ();
window.Destroy ();}
}
}
}

View File

@ -0,0 +1,74 @@
//
// StockBrowser.cs, port of stock_browser.c from gtk-demo
//
// Author: Daniel Kornhauser <dkor@media.mit.edu>
//
// (C) 2003 Ximian, Inc.
using System;
using Gtk;
using GtkSharp;
namespace GtkDemo
{
public class DemoStockBrowser
{
private Gtk.Window window;
public DemoStockBrowser ()
{
window = new Gtk.Window ("Stock Item Browser Demo");
window.SetDefaultSize (600, 400);
window.DeleteEvent += new DeleteEventHandler (WindowDelete);
window.BorderWidth = 8;
HBox hbox = new HBox (false, 8);
window.Add (hbox);
ScrolledWindow scrolledWindow = new ScrolledWindow (null, null);
scrolledWindow.SetPolicy (PolicyType.Never, PolicyType.Automatic);
hbox.PackStart (scrolledWindow, true, true, 0);
TreeView list = new TreeView ();
list.AppendColumn ("Icon", new CellRendererPixbuf (), "pixbuf", 0);
list.AppendColumn ("Name", new CellRendererText (), "text", 1);
list.AppendColumn ("Label", new CellRendererText (), "text", 2);
list.AppendColumn ("Accel", new CellRendererText (), "text", 3);
list.Model = CreateStore ();
scrolledWindow.Add (list);
Frame frame = new Frame ();
hbox.PackStart (frame, true, true, 0);
window.ShowAll ();
}
// private TreeModel CreateModel ()
// {
// ListStore store;
// TreeModel model = new TreeModel ();
// return model;
// }
private ListStore CreateStore ()
{
// image, name, label, accel
ListStore store = new Gtk.ListStore (typeof (Gdk.Pixbuf), typeof(string), typeof(string), typeof(string));
for (int i =1; i < 10; i++)
{
Image icon = new Image ("images/MonoIcon.png");
store.AppendValues (icon, "Gtk.Stock.Ok", "Ok", "_Ok");
}
return store;
}
private void WindowDelete (object o, DeleteEventArgs args)
{
window.Hide ();
window.Destroy ();
}
}
}

View File

@ -0,0 +1,468 @@
//
// DemoTextView.cs, port of textview.c form gtk-demo
//
// Author: Daniel Kornhauser <dkor@alum.mit.edu>
//
// (C) 2003 Ximian, Inc.
/* Text Widget
*
* The Gtk.TextView widget displays a Gtk.TextBuffer. One Gtk.TextBuffer
* can be displayed by multiple Gtk.TextViews. This demo has two views
* displaying a single buffer, and shows off the widget's text
* formatting features.
*/
using System;
using System.IO;
using Gdk;
using Gtk;
using GtkSharp;
namespace GtkDemo
{
public class DemoTextView
{
private Gtk.Window window;
TextView view1;
TextView view2;
public DemoTextView ()
{
window = new Gtk.Window ("TextView Demo");
window.DeleteEvent += new DeleteEventHandler (WindowDelete);
window.SetDefaultSize (450,450);
window.BorderWidth = 0;
VPaned vpaned = new VPaned ();
vpaned.BorderWidth = 5;
window.Add (vpaned);
/* For convenience, we just use the autocreated buffer from
* the first text view; you could also create the buffer
* by itself with new Gtk.TextBuffer (), then later create
* a view widget.
*/
view1 = new TextView ();
TextBuffer buffer = view1.Buffer;
view2 = new TextView(buffer);
ScrolledWindow scrolledWindow = new ScrolledWindow ();
scrolledWindow.SetPolicy (PolicyType.Automatic, Gtk.PolicyType.Automatic);
vpaned.Add1 (scrolledWindow);
scrolledWindow.Add (view1);
scrolledWindow = new Gtk.ScrolledWindow ();
scrolledWindow.SetPolicy (Gtk.PolicyType.Automatic, Gtk.PolicyType.Automatic);
vpaned.Add2 (scrolledWindow);
scrolledWindow.Add (view2);
CreateTags (buffer);
InsertText(buffer);
AttachWidgets(view1);
AttachWidgets(view2);
vpaned.ShowAll();
window.ShowAll ();
}
private TextChildAnchor buttonAnchor;
private TextChildAnchor menuAnchor;
private TextChildAnchor scaleAnchor;
private TextChildAnchor animationAnchor;
private TextChildAnchor entryAnchor;
private void AttachWidgets (TextView textView)
{
Button button = new Button ("Click Me");
button.Clicked += new EventHandler(EasterEggCB);
textView.AddChildAtAnchor (button, buttonAnchor);
button.ShowAll ();
OptionMenu option = new OptionMenu ();
Menu menu = new Menu ();
MenuItem menuItem = new MenuItem ("Option 1");
menu.Append(menuItem);
menuItem = new MenuItem ("Option 2");
menu.Append(menuItem);
menuItem = new MenuItem ("Option 3");
menu.Append(menuItem);
option.Menu = menu;
textView.AddChildAtAnchor (option, menuAnchor);
menu.ShowAll ();
HScale scale = new HScale (null);
scale.SetRange (0,100);
scale.SetSizeRequest (70, -1);
textView.AddChildAtAnchor (scale, scaleAnchor);
scale.ShowAll ();
Gtk.Image image = new Gtk.Image ("images/floppybuddy.gif");
textView.AddChildAtAnchor (image, animationAnchor);
image.ShowAll ();
Entry entry = new Entry ();
textView.AddChildAtAnchor (entry, entryAnchor);
image.ShowAll ();
}
private void CreateTags (TextBuffer buffer)
{
/* Create a bunch of tags. Note that it's also possible to
* create tags with gtk_text_tag_new() then add them to the
* tag table for the buffer, gtk_text_buffer_create_tag() is
* just a convenience function. Also note that you don't have
* to give tags a name; pass NULL for the name to create an
* anonymous tag.
*
* In any real app, another useful optimization would be to create
* a GtkTextTagTable in advance, and reuse the same tag table for
* all the buffers with the same tag set, instead of creating
* new copies of the same tags for every buffer.
*
* Tags are assigned default priorities in order of addition to the
* tag table. That is, tags created later that affect the same text
* property affected by an earlier tag will override the earlier
* tag. You can modify tag priorities with
* gtk_text_tag_set_priority().
*/
TextTag tag = new TextTag("heading");
//tag.Weigth = Pango.Weight.Bold;
tag.Size = (int) Pango.Scale.PangoScale * 15;
buffer.TagTable.Add(tag);
tag = new TextTag("italic");
tag.Style = Pango.Style.Italic;
buffer.TagTable.Add(tag);
tag = new TextTag("bold");
// An object reference is required for the non-static field `Weight'
//tag.Weight = Pango.Weight.Bold;
buffer.TagTable.Add(tag);
tag = new TextTag("big");
// Expression denotes a `type' where a `variable, value' was expected
tag.Size = (int) Pango.Scale.PangoScale * 20;
buffer.TagTable.Add(tag);
tag = new TextTag("xx-small");
tag.Scale = 15 * Pango.Scale.XX_Small;
buffer.TagTable.Add(tag);
tag = new TextTag("x-large");
tag.Scale = 15 * Pango.Scale.X_Large;
buffer.TagTable.Add(tag);
tag = new TextTag("monospace");
tag.Family = "monospace";
buffer.TagTable.Add(tag);
tag = new TextTag("blue_foreground");
tag.Foreground = "blue";
buffer.TagTable.Add(tag);
tag = new TextTag("red_background");
tag.Background = "red";
buffer.TagTable.Add(tag);
int gray50_width = 2;
int gray50_height = 2;
string gray50_bits = new string ((char) 0x02, (char) 0x01);
//Bitmap stipple = Bitmap.CreateFromData(null, (string) gray50_bits, gray50_width, gray50_height );
tag = new TextTag("background_stipple");
// tag.BackgroundStipple = stipple;
// Cannot convert type 'Gdk.Bitmap' to 'Gdk.Pixmap'
buffer.TagTable.Add(tag);
tag = new TextTag("foreground_stipple");
// Cannot convert type 'Gdk.Bitmap' to 'Gdk.Pixmap'
// tag.ForegroundStipple = stipple;
buffer.TagTable.Add(tag);
tag = new TextTag("big_gap_before_line");
tag.PixelsAboveLines = 30;
buffer.TagTable.Add(tag);
tag = new TextTag("big_gap_after_line");
tag.PixelsBelowLines = 30;
buffer.TagTable.Add(tag);
tag = new TextTag("double_spaced_line");
tag.PixelsInsideWrap = 10;
buffer.TagTable.Add(tag);
tag = new TextTag("not_editable");
tag.Editable = false;
buffer.TagTable.Add(tag);
tag = new TextTag("word_wrap");
tag.WrapMode = WrapMode.Word;
buffer.TagTable.Add(tag);
tag = new TextTag("char_wrap");
tag.WrapMode = WrapMode.Char;
buffer.TagTable.Add(tag);
tag = new TextTag("no_wrap");
tag.WrapMode = WrapMode.None;
buffer.TagTable.Add(tag);
tag = new TextTag("center");
tag.Justification = Justification.Center;
buffer.TagTable.Add(tag);
tag = new TextTag("right_justify");
tag.Justification = Justification.Right;
buffer.TagTable.Add(tag);
tag = new TextTag("wide_margins");
tag.LeftMargin = 50;
tag.RightMargin = 50;
buffer.TagTable.Add(tag);
tag = new TextTag("strikethrough");
tag.Strikethrough = true;
buffer.TagTable.Add(tag);
tag = new TextTag("underline");
tag.Underline = Pango.Underline.Single;
buffer.TagTable.Add(tag);
tag = new TextTag("double_underline");
tag.Underline = Pango.Underline.Double;
buffer.TagTable.Add(tag);
tag = new TextTag("superscript");
tag.Rise = (int) Pango.Scale.PangoScale * 10;
tag.Size = (int) Pango.Scale.PangoScale * 8;
buffer.TagTable.Add(tag);
tag = new TextTag("subscript");
tag.Rise = (int) Pango.Scale.PangoScale * -10;
tag.Size = (int) Pango.Scale.PangoScale * 8;
buffer.TagTable.Add(tag);
tag = new TextTag("rtl_quote");
tag.WrapMode = WrapMode.Word;
//tag.Direction = TextMode.Dir.Rtl
tag.Indent = 30;
tag.LeftMargin = 20;
tag.RightMargin = 20;
buffer.TagTable.Add(tag);
}
private void InsertText (TextBuffer buffer)
{
/* demo_find_file() looks in the the current directory first,
* so you can run gtk-demo without installing GTK, then looks
* in the location where the file is installed.
*/
// Error handling here, check for file existence, etc.
Pixbuf pixbuf = new Pixbuf ("images/gtk-logo-rgb.gif");
pixbuf.ScaleSimple (32, 32, InterpType.Bilinear);
/* get start of buffer; each insertion will revalidate the
* iterator to point to just after the inserted text.
*/
TextIter insertIter;
insertIter = buffer.GetIterAtOffset (0);
buffer.Insert(insertIter,
"The text widget can display text with all kinds of nifty attributes.It also supports multiple views of the same buffer; this demo is showing the same buffer in two places.\n\n");
InsertWithTagsByName (buffer, "Font styles. ", new string[] {"heading"});
Insert (buffer, "For example, you can have ");
InsertWithTagsByName (buffer, "italic", new string[] {"italic"});
Insert (buffer, ", ");
InsertWithTagsByName (buffer, "bold", new string[] {"bold"});
Insert (buffer, ", or ");
InsertWithTagsByName (buffer, "monospace (typewriter)", new string[] {"monospace"});
Insert (buffer, ", or ");
InsertWithTagsByName (buffer, "big", new string[] {"big"});
Insert (buffer, " text");
Insert (buffer,
"It's best not to hardcode specific text sizes; you can use relative sizes as with CSS, such as ");
InsertWithTagsByName (buffer, "xx-small", new string[] {"xx-small"});
Insert (buffer, ", or");
InsertWithTagsByName (buffer, "x-large", new string[] {"x-large"});
Insert (buffer,
" to ensure that your program properly adapts if the user changes the default font size.\n\n");
InsertWithTagsByName (buffer, "Colors such as", new string[] {"heading"});
InsertWithTagsByName (buffer, "a blue foreground", new string[] {"blue_foreground"});
Insert (buffer, ", or ");
InsertWithTagsByName (buffer, "a red background", new string[] {"red_background"});
Insert (buffer, " or even ");
// Change InsertWithTagsByName to work with 2 and 3 args
// InsertWithTagsByName ("a stippled red background",
// "red_background",
// "background_stipple");
//Insert (buffer, ", or ");
//InsertWithTagsByName ("a stippled red background",
// "a stippled blue foreground on solid red background", -1,
// "blue_foreground",
// "red_background",
// "foreground_stipple")
Insert (buffer, " (select that to read it) can be used.\n\n");
InsertWithTagsByName (buffer, "Underline, strikethrough, and rise. ", new string[] {"heading"});
InsertWithTagsByName (buffer, "Strikethrough", new string[] {"strikethrough"});
Insert (buffer, ", ");
InsertWithTagsByName (buffer, "underline", new string[] {"underline"});
Insert (buffer, ", ");
InsertWithTagsByName (buffer, "double_underline", new string[] {"double_underline"});
Insert (buffer, ", ");
InsertWithTagsByName (buffer, "superscript", new string[] {"superscript"});
Insert (buffer, ", and ");
InsertWithTagsByName (buffer, "subscript", new string[] {"subscript"});
Insert (buffer," are all supported.\n\n");
InsertWithTagsByName (buffer, "Images. ", new string[] {"heading"});
Insert (buffer,"The buffer can have images in it: ");
buffer.GetIterAtMark (out insertIter, buffer.InsertMark);
buffer.InsertPixbuf (insertIter, pixbuf);
buffer.GetIterAtMark (out insertIter, buffer.InsertMark);
buffer.InsertPixbuf (insertIter, pixbuf);
buffer.GetIterAtMark (out insertIter, buffer.InsertMark);
buffer.InsertPixbuf (insertIter, pixbuf);
Insert (buffer, " for example.\n\n");
InsertWithTagsByName (buffer, "Spacing. ", new string[] {"heading"});
InsertWithTagsByName (buffer, "You can adjust the amount of space before each line.\n", new string[] {"big_gap_before_line", "wide_margins"});
InsertWithTagsByName (buffer, "You can also adjust the amount of space after each line; this line has a whole lot of space after it.\n", new string[] {"big_gap_after_line", "wide_margins"});
InsertWithTagsByName (buffer, "You can also adjust the amount of space between wrapped lines; this line has extra space between each wrapped line in the same paragraph. To show off wrapping, some filler text: the quick brown fox jumped over the lazy dog. Blah blah blah blah blah blah blah blah blah.\n", new string[] {"double_spaced_line", "wide_margins"});
Insert (buffer, "Also note that those lines have extra-wide margins.\n\n");
InsertWithTagsByName (buffer, "Editability. ", new string[] {"heading"});
InsertWithTagsByName (buffer, "This line is 'locked down' and can't be edited by the user - just try it! You can't delete this line.\n\n", new string[] {"not_editable"});
InsertWithTagsByName (buffer, "Wrapping. ", new string[] {"heading"});
Insert (buffer,"This line (and most of the others in this buffer) is word-wrapped, using the proper Unicode algorithm. Word wrap should work in all scripts and languages that GTK+ supports. Let's make this a long paragraph to demonstrate: blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah\n\n");
InsertWithTagsByName (buffer, "This line has character-based wrapping, and can wrap between any two character glyphs. Let's make this a long paragraph to demonstrate: blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah\n\n", new string[] {"char_wrap"});
InsertWithTagsByName (buffer, "This line has all wrapping turned off, so it makes the horizontal scrollbar appear.\n\n\n", new string[] {"no_wrap"});
InsertWithTagsByName (buffer, "Justification. ", new string[] {"heading"});
InsertWithTagsByName (buffer, "\nThis line has center justification.\n", new string[] {"center"});
InsertWithTagsByName (buffer, "This line has right justification.\n", new string[] {"right_justify"});
InsertWithTagsByName (buffer, "\nThis line has big wide margins. Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.\n", new string[] {"wide_margins"});
InsertWithTagsByName (buffer, "Internationalization. ", new string[] {"heading"});
//Insert (buffer, "You can put all sorts of Unicode text in the buffer.\n\nGerman (Deutsch S\303\274d) Gr\303\274\303\237 Gott\nGreek (\316\225\316\273\316\273\316\267\316\275\316\271\316\272\316\254) \316\223\316\265\316\271\316\254 \317\203\316\261\317\202\nHebrew \327\251\327\234\327\225\327\235\nJapanese (\346\227\245\346\234\254\350\252\236)\n\nThe widget properly handles bidirectional text, word wrapping, DOS/UNIX/Unicode paragraph separators, grapheme boundaries, and so on using the Pango internationalization framework.\n");
Insert (buffer, "Here's a word-wrapped quote in a right-to-left language:\n");
//InsertWithTagsByName (buffer, "\331\210\331\202\330\257 \330\250\330\257\330\243 \330\253\331\204\330\247\330\253 \331\205\331\206 \330\243\331\203\330\253\330\261 \330\247\331\204\331\205\330\244\330\263\330\263\330\247\330\252 \330\252\331\202\330\257\331\205\330\247 \331\201\331\212 \330\264\330\250\331\203\330\251 \330\247\331\203\330\263\331\212\331\210\331\206 \330\250\330\261\330\247\331\205\330\254\331\207\330\247 \331\203\331\205\331\206\330\270\331\205\330\247\330\252 \331\204\330\247 \330\252\330\263\330\271\331\211 \331\204\331\204\330\261\330\250\330\255\330\214 \330\253\331\205 \330\252\330\255\331\210\331\204\330\252 \331\201\331\212 \330\247\331\204\330\263\331\206\331\210\330\247\330\252 \330\247\331\204\330\256\331\205\330\263 \330\247\331\204\331\205\330\247\330\266\331\212\330\251 \330\245\331\204\331\211 \331\205\330\244\330\263\330\263\330\247\330\252 \331\205\330\247\331\204\331\212\330\251 \331\205\331\206\330\270\331\205\330\251\330\214 \331\210\330\250\330\247\330\252\330\252 \330\254\330\262\330\241\330\247 \331\205\331\206 \330\247\331\204\331\206\330\270\330\247\331\205 \330\247\331\204\331\205\330\247\331\204\331\212 \331\201\331\212 \330\250\331\204\330\257\330\247\331\206\331\207\330\247\330\214 \331\210\331\204\331\203\331\206\331\207\330\247 \330\252\330\252\330\256\330\265\330\265 \331\201\331\212 \330\256\330\257\331\205\330\251 \331\202\330\267\330\247\330\271 \330\247\331\204\331\205\330\264\330\261\331\210\330\271\330\247\330\252 \330\247\331\204\330\265\330\272\331\212\330\261\330\251. \331\210\330\243\330\255\330\257 \330\243\331\203\330\253\330\261 \331\207\330\260\331\207 \330\247\331\204\331\205\330\244\330\263\330\263\330\247\330\252 \331\206\330\254\330\247\330\255\330\247 \331\207\331\210 \302\273\330\250\330\247\331\206\331\203\331\210\330\263\331\210\331\204\302\253 \331\201\331\212 \330\250\331\210\331\204\331\212\331\201\331\212\330\247.\n\n", new string[] {"rtl_quote"});
//InsertWithTagsByName (buffer, "\x2", new string[] {"rtl_quote"});
Insert (buffer, "You can put widgets in the buffer: Here's a button: ");
buffer.GetIterAtMark(out insertIter, buffer.InsertMark);
buttonAnchor = buffer.CreateChildAnchor (insertIter);
Insert (buffer, "and a menu");
buffer.GetIterAtMark(out insertIter, buffer.InsertMark);
menuAnchor = buffer.CreateChildAnchor (insertIter);
Insert (buffer, "and a scale");
buffer.GetIterAtMark(out insertIter, buffer.InsertMark);
scaleAnchor = buffer.CreateChildAnchor (insertIter);
Insert (buffer, "and an animation");
buffer.GetIterAtMark(out insertIter, buffer.InsertMark);
animationAnchor = buffer.CreateChildAnchor (insertIter);
Insert (buffer, " finally a text entry: ");
buffer.GetIterAtMark(out insertIter, buffer.InsertMark);
entryAnchor = buffer.CreateChildAnchor (insertIter);
Insert (buffer, "\n");
Insert (buffer, "\n\nThis demo doesn't demonstrate all the GtkTextBuffer features; it leaves out, for example: invisible/hidden text (doesn't work in GTK 2, but planned), tab stops, application-drawn areas on the sides of the widget for displaying breakpoints and such...");
//Insert (buffer,);
//InsertWithTagsByName (buffer, , new string[] {});
buffer.ApplyTag("word_wrap", buffer.StartIter, buffer.EndIter);
}
private void InsertWithTagsByName (TextBuffer buffer , string insertText, string[] fontName)
{
TextIter insertIter, beginIter, endIter;
int begin, end;
begin = buffer.CharCount;
buffer.GetIterAtMark(out insertIter, buffer.InsertMark);
buffer.Insert (insertIter, insertText);
end = buffer.CharCount;
foreach (string fontItem in fontName){
buffer.GetIterAtOffset (out endIter, end);
buffer.GetIterAtOffset (out beginIter, begin);
buffer.ApplyTag (fontItem, beginIter, endIter);}
}
private void Insert (TextBuffer buffer , string insertText)
{
TextIter insertIter;
buffer.GetIterAtMark(out insertIter, buffer.InsertMark);
buffer.Insert (insertIter, insertText);
}
private void WindowDelete (object o, DeleteEventArgs args)
{
window.Hide ();
window.Destroy ();
}
private void RecursiveAttach (int depth, TextView view, TextChildAnchor anchor)
{
if (depth > 4)
return;
TextView childView = new TextView (view.Buffer);
/* Event box is to add a black border around each child view */
EventBox eventBox = new EventBox ();
Gdk.Color blackColor = new Gdk.Color (0x0, 0x0, 0x0);
eventBox.ModifyBg(StateType.Normal,blackColor);
Alignment align = new Alignment (0.5f, 0.5f, 1.0f, 1.0f);
align.BorderWidth = 1;
eventBox.Add (align);
align.Add (childView);
view.AddChildAtAnchor (eventBox, anchor);
RecursiveAttach(depth+1, childView, anchor);
}
private void EasterEggCB (object o, EventArgs args)
{
TextIter insertIter;
TextBuffer bufferCB = new TextBuffer (null);
Insert(bufferCB, "This buffer is shared by a set of nested text views.\n Nested view:\n");
bufferCB.GetIterAtMark(out insertIter, bufferCB.InsertMark);
TextChildAnchor anchor = bufferCB.CreateChildAnchor (insertIter);
Insert(bufferCB, "\nDon't do this in real applications, please.\n");
TextView viewCB = new TextView (bufferCB);
RecursiveAttach(0, viewCB, anchor);
Gtk.Window window = new Gtk.Window (null);
ScrolledWindow scrolledWindow = new ScrolledWindow(null, null);
scrolledWindow.SetPolicy (PolicyType.Automatic, PolicyType.Automatic);
window.Add (scrolledWindow);
scrolledWindow.Add (viewCB);
window.SetDefaultSize (300, 400);
window.ShowAll ();
}
}
}

View File

@ -0,0 +1,385 @@
//
// DemoTreeItem.cs, port of tree_store.c from gtk-demo
//
// Author: Daniel Kornhauser <dkor@alum.mit.edu>
//
// Copyright (C) 2003, Ximian Inc.
/* Tree View/Tree Store
*
* The Gtk.TreeStore is used to store data in tree form, to be
* used later on by a Gtk.TreeView to display it. This demo builds
* a simple Gtk.TreeStore and displays it. If you're new to the
* Gtk.TreeView widgets and associates, look into the Gtk.ListStore
* example first.
*/
using System;
using System.Collections;
using Gtk;
using GtkSharp;
using GLib;
namespace GtkDemo
{
public class DemoTreeStore
{
private Window window;
private TreeStore store;
public DemoTreeStore ()
{
window = new Window ("TreeStore Demo");
window.DeleteEvent += new DeleteEventHandler (WindowDelete);
VBox vbox = new VBox (false, 8);
vbox.BorderWidth = 8;
window.Add (vbox);
vbox.PackStart(new Label ("Jonathan's Holiday Card Planning Sheet"), false, false, 0);
ScrolledWindow scrolledWindow = new ScrolledWindow ();
scrolledWindow.ShadowType = ShadowType.EtchedIn;
scrolledWindow.SetPolicy (PolicyType.Automatic, PolicyType.Automatic);
vbox.PackStart (scrolledWindow, true, true, 0);
// create model
CreateModel();
// create tree view
TreeView treeView = new TreeView (store);
treeView.RulesHint = true;
TreeSelection treeSelection = treeView.Selection;
treeSelection.Mode = SelectionMode.Multiple;
AddColumns (treeView);
scrolledWindow.Add (treeView);
// expand all rows after the treeview widget has been realized
window.SetDefaultSize (650, 400);
window.ShowAll ();
}
//FIXME: Finish implementing this function
private void ItemToggled (object o, ToggledArgs args)
{
Console.WriteLine("toggled {0} with value", args.Path);
GLib.Object cellRendererToggle = (GLib.Object) o;
Console.WriteLine("Column {0}",cellRendererToggle.Data["column"]);
//GLib.Value columnValue = new GLib.Value();
//column.GetProperty("column", columnValue);
//Console.WriteLine("toggled {0} with value", columnValue.Val);
CellRenderer cellRenderer = (CellRenderer) o;
//Value value = new Value();
//cellRenderer.GetProperty("column", value);
//Console.WriteLine( value.Val );
// Gtk.TreeIter iter;
// if (store.GetIterFromString(out iter, args.Path))
// {
// bool val = (bool) store.GetValue(iter, 0);
// Console.WriteLine("toggled {0} with value {1}", args.Path, val);
// store.SetValue(iter, 2, !val);
// }
}
private void AddColumns (TreeView treeView)
{
// column for holiday names
CellRendererText rendererText = new CellRendererText ();
rendererText.Xalign = 0.0f;
GLib.Object ugly = (GLib.Object) rendererText;
ugly.Data ["column"] = Column.HolidayName;
TreeViewColumn column = new TreeViewColumn("Holiday", rendererText,
"text", Column.HolidayName);
treeView.InsertColumn(column, (int) Column.HolidayName);
// alex column
CellRendererToggle rendererToggle = new CellRendererToggle ();
rendererToggle.Xalign = 0.0f;
ugly = (GLib.Object) rendererToggle;
ugly.Data ["column"] = Column.Alex;
rendererToggle.Toggled += new ToggledHandler (ItemToggled);
rendererToggle.Visible = true;
rendererToggle.Activatable = true;
rendererToggle.Active = true;
column = new TreeViewColumn("Alex", rendererToggle, "active", (int) Column.Alex);
column.Sizing = TreeViewColumnSizing.Fixed;
column.FixedWidth = 50;
column.Clickable = true;
treeView.InsertColumn(column, (int) Column.Alex);
// havoc column
rendererToggle = new CellRendererToggle ();
rendererToggle.Xalign = 0.0f;
ugly = (GLib.Object) rendererToggle;
ugly.Data ["column"] = Column.Havoc;
rendererToggle.Toggled += new ToggledHandler (ItemToggled);
column = new TreeViewColumn("Havoc", rendererToggle, "active", (int) Column.Havoc);
column.Visible = true;
rendererToggle.Activatable = true;
rendererToggle.Active = true;
treeView.InsertColumn(column, (int) Column.Havoc);
column.Sizing = TreeViewColumnSizing.Fixed;
column.FixedWidth = 50;
column.Clickable = true;
// tim column
rendererToggle = new CellRendererToggle ();
rendererToggle.Xalign = 0.0f;
ugly = (GLib.Object) rendererToggle;
ugly.Data ["column"] = Column.Tim;
rendererToggle.Toggled += new ToggledHandler (ItemToggled);
column = new TreeViewColumn("Tim", rendererToggle, "active", (int) Column.Tim);
column.Visible = true;
rendererToggle.Activatable = true;
rendererToggle.Active = true;
treeView.InsertColumn(column, (int) Column.Tim);
column.Sizing = TreeViewColumnSizing.Fixed;
column.FixedWidth = 50;
column.Clickable = true;
// owen column
rendererToggle = new CellRendererToggle ();
rendererToggle.Xalign = 0.0f;
ugly = (GLib.Object) rendererToggle;
ugly.Data ["column"] = Column.Owen;
rendererToggle.Toggled += new ToggledHandler (ItemToggled);
column = new TreeViewColumn("Owen", rendererToggle, "active", (int) Column.Owen);
column.Visible = true;
rendererToggle.Activatable = true;
rendererToggle.Active = true;
treeView.InsertColumn(column, (int) Column.Owen);
column.Sizing = TreeViewColumnSizing.Fixed;
column.FixedWidth = 50;
column.Clickable = true;
// dave column
rendererToggle = new CellRendererToggle ();
rendererToggle.Xalign = 0.0f;
ugly = (GLib.Object) rendererToggle;
ugly.Data ["column"] = Column.Dave;
rendererToggle.Toggled += new ToggledHandler (ItemToggled);
column = new TreeViewColumn("Dave", rendererToggle, "active", (int) Column.Dave);
column.Visible = true;
rendererToggle.Activatable = true;
rendererToggle.Active = true;
treeView.InsertColumn(column, (int) Column.Dave);
column.Sizing = TreeViewColumnSizing.Fixed;
column.FixedWidth = 50;
column.Clickable = true;
}
private void WindowDelete (object o, DeleteEventArgs args)
{
window.Hide ();
window.Destroy ();
}
private void CreateModel ()
{
// create tree store
store = new TreeStore (
typeof(string),
typeof(bool),
typeof(bool),
typeof(bool),
typeof(bool),
typeof(bool),
typeof(bool),
typeof(bool));
// add data to the tree store
// STUCK !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
foreach (MyTreeItem month in toplevel)
{
TreeIter iter = store.AppendValues (month.Label,
false,
false,
false,
false,
false,
false,
false);
foreach (MyTreeItem hollyday in month.Children)
{
store.AppendValues (iter,
hollyday.Label,
hollyday.Alex,
hollyday.Havoc,
hollyday.Tim,
hollyday.Owen,
hollyday.Dave,
true);
}
}
}
// tree data
private static MyTreeItem[] january =
{
new MyTreeItem ("New Years Day", true, true, true, true, false, true, null ),
new MyTreeItem ("Presidential Inauguration", false, true, false, true, false, false, null ),
new MyTreeItem ("Martin Luther King Jr. day", false, true, false, true, false, false, null )
};
private static MyTreeItem[] february =
{
new MyTreeItem ( "Presidents' Day", false, true, false, true, false, false, null ),
new MyTreeItem ( "Groundhog Day", false, false, false, false, false, false, null ),
new MyTreeItem ( "Valentine's Day", false, false, false, false, true, true, null )
};
private static MyTreeItem[] march =
{
new MyTreeItem ( "National Tree Planting Day", false, false, false, false, false, false, null ),
new MyTreeItem ( "St Patrick's Day", false, false, false, false, false, true, null )
};
private static MyTreeItem[] april =
{
new MyTreeItem ( "April Fools' Day", false, false, false, false, false, true, null ),
new MyTreeItem ( "Army Day", false, false, false, false, false, false, null ),
new MyTreeItem ( "Earth Day", false, false, false, false, false, true, null ),
new MyTreeItem ( "Administrative Professionals' Day", false, false, false, false, false, false, null )
};
private static MyTreeItem[] may =
{
new MyTreeItem ( "Nurses' Day", false, false, false, false, false, false, null ),
new MyTreeItem ( "National Day of Prayer", false, false, false, false, false, false, null ),
new MyTreeItem ( "Mothers' Day", false, false, false, false, false, true, null ),
new MyTreeItem ( "Armed Forces Day", false, false, false, false, false, false, null ),
new MyTreeItem ( "Memorial Day", true, true, true, true, false, true, null )
};
private static MyTreeItem[] june =
{
new MyTreeItem ( "June Fathers' Day", false, false, false, false, false, true, null ),
new MyTreeItem ( "Juneteenth (Liberation of Slaves)", false, false, false, false, false, false, null ),
new MyTreeItem ( "Flag Day", false, true, false, true, false, false, null )
};
private static MyTreeItem[] july =
{
new MyTreeItem ( "Parents' Day", false, false, false, false, false, true, null ),
new MyTreeItem ( "Independence Day", false, true, false, true, false, false, null )
};
private static MyTreeItem[] august =
{
new MyTreeItem ( "Air Force Day", false, false, false, false, false, false, null ),
new MyTreeItem ( "Coast Guard Day", false, false, false, false, false, false, null ),
new MyTreeItem ( "Friendship Day", false, false, false, false, false, false, null )
};
private static MyTreeItem[] september =
{
new MyTreeItem ( "Grandparents' Day", false, false, false, false, false, true, null ),
new MyTreeItem ( "Citizenship Day or Constitution Day", false, false, false, false, false, false, null ),
new MyTreeItem ( "Labor Day", true, true, true, true, false, true, null )
};
private static MyTreeItem[] october =
{
new MyTreeItem ( "National Children's Day", false, false, false, false, false, false, null ),
new MyTreeItem ( "Bosses' Day", false, false, false, false, false, false, null ),
new MyTreeItem ( "Sweetest Day", false, false, false, false, false, false, null ),
new MyTreeItem ( "Mother-in-Law's Day", false, false, false, false, false, false, null ),
new MyTreeItem ( "Navy Day", false, false, false, false, false, false, null ),
new MyTreeItem ( "Columbus Day", false, true, false, true, false, false, null ),
new MyTreeItem ( "Halloween", false, false, false, false, false, true, null )
};
private static MyTreeItem[] november =
{
new MyTreeItem ( "Marine Corps Day", false, false, false, false, false, false, null ),
new MyTreeItem ( "Veterans' Day", true, true, true, true, false, true, null ),
new MyTreeItem ( "Thanksgiving", false, true, false, true, false, false, null )
};
private static MyTreeItem[] december =
{
new MyTreeItem ( "Pearl Harbor Remembrance Day", false, false, false, false, false, false, null ),
new MyTreeItem ( "Christmas", true, true, true, true, false, true, null ),
new MyTreeItem ( "Kwanzaa", false, false, false, false, false, false, null )
};
private static MyTreeItem[] toplevel =
{
new MyTreeItem ("January", false, false, false, false, false, false, january),
new MyTreeItem ("February", false, false, false, false, false, false, february),
new MyTreeItem ("March", false, false, false, false, false, false, march),
new MyTreeItem ("April", false, false, false, false, false, false, april),
new MyTreeItem ("May", false, false, false, false, false, false, may),
new MyTreeItem ("June", false, false, false, false, false, false, june),
new MyTreeItem ("July", false, false, false, false, false, false, july),
new MyTreeItem ("August", false, false, false, false, false, false, august),
new MyTreeItem ("September", false, false, false, false, false, false, september),
new MyTreeItem ("October", false, false, false, false, false, false, october),
new MyTreeItem ("November", false, false, false, false, false, false, november),
new MyTreeItem ("December", false, false, false, false, false, false, december)
};
// TreeItem structure
// report bug array mismatch declaration
public class MyTreeItem
{
public string Label;
public bool Alex;
public bool Havoc;
public bool Tim;
public bool Owen;
public bool Dave;
public bool World_holiday; /* shared by the European hackers */
public MyTreeItem[] Children;
public MyTreeItem (
string label,
bool alex,
bool havoc,
bool tim,
bool owen,
bool dave,
bool world_holiday,
MyTreeItem[] children)
{
Label = label;
Alex = alex;
Havoc = havoc;
Tim = tim;
Owen = owen;
Dave = dave;
World_holiday = world_holiday;
Children = children;
}
}
// columns
public enum Column
{
HolidayName,
Alex,
Havoc,
Tim,
Owen,
Dave,
Visible,
World,
Num,
}
}
}

10
sample/GtkDemo/Makefile Normal file
View File

@ -0,0 +1,10 @@
CSC = mcs
DLLS = /r:gtk-sharp.dll /r:glib-sharp.dll /r:pango-sharp.dll /r:gdk-sharp.dll /r:System.Drawing.dll
all:
$(CSC) -g /out:GtkDemo.exe *.cs $(DLLS)
clean:
rm -f GtkDemo.exe

7
sample/GtkDemo/README Normal file
View File

@ -0,0 +1,7 @@
This port of gtk-demo.c is still INCOMPLETE. If you can't contribute to it
don't hesistate to mail your patches at the gtk-sharp-list@lists.ximian.com
To compile it just type Make
Daniel Kornhauser.