implement some of the DemoApplicationWindow

fix some bugs in DemoEditableCells
use more consistent tabs and spaces
add a TODO of what is left
use the using () pattern to dispose Dialogs automatically
use args.RetVal when handling the DeleteEvent

svn path=/trunk/gtk-sharp/; revision=32017
This commit is contained in:
John Luke 2004-08-07 17:06:29 +00:00
parent 92553bb827
commit db410e9497
19 changed files with 636 additions and 698 deletions

View file

@ -1,2 +1,4 @@
Makefile
Makefile.in
GtkDemo.exe
GtkDemo.exe.mdb

View file

@ -19,24 +19,29 @@ using Gtk;
namespace GtkDemo
{
public class DemoApplicationWindow
public class DemoApplicationWindow : Window
{
private Gtk.Window window;
// for the statusbar
const int ctx = 1;
const string fmt = "Cursor at row {0} column {1} - {2} chars in document";
int row, column, count = 0;
Statusbar statusbar;
// static ItemFactoryEntry items[] = { new ItemFactoryEntry ("/_File", null, 0, 0, "<Branch>" )};
public DemoApplicationWindow ()
public DemoApplicationWindow () : base ("Demo Application Window")
{
window = new Gtk.Window ("Demo Application Window");
window.SetDefaultSize (400, 300);
window.DeleteEvent += new DeleteEventHandler (WindowDelete);
this.SetDefaultSize (400, 300);
this.DeleteEvent += new DeleteEventHandler (WindowDelete);
VBox vbox = new VBox (false, 0);
window.Add (vbox);
this.Add (vbox);
// Create the menubar
AccelGroup accelGroup = new AccelGroup ();
window.AddAccelGroup (accelGroup);
this.AddAccelGroup (accelGroup);
MenuBar menubar = CreateMenu ();
vbox.PackStart (menubar, false, false, 0);
@ -45,10 +50,12 @@ namespace GtkDemo
vbox.PackStart (toolbar, false, false, 0);
TextView textview = new TextView ();
textview.Buffer.MarkSet += new MarkSetHandler (OnMarkSet);
vbox.PackStart (textview, true, true, 0);
Statusbar statusbar = new Statusbar ();
statusbar.Push (1, "Cursor at row 0 column 0 - 0 chars in document");
statusbar = new Statusbar ();
UpdateStatus ();
vbox.PackStart (statusbar, false, false, 0);
//ItemFactory itemFactory = new ItemFactory (typeof (MenuBar),"<main>", accelGroup);
@ -63,7 +70,7 @@ namespace GtkDemo
// create menu items
//STUCK : Didn't find any examples of ItemFactory
window.ShowAll ();
this.ShowAll ();
}
private MenuBar CreateMenu ()
@ -95,16 +102,32 @@ namespace GtkDemo
private void OnToolbarClicked (object o, EventArgs args)
{
MessageDialog md = new MessageDialog (window, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Close, "You selected a toolbar button.");
using (MessageDialog md = new MessageDialog (this, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Close, "You selected a toolbar button.")) {
md.Run ();
md.Hide ();
md.Dispose ();
}
}
private void WindowDelete (object o, DeleteEventArgs args)
{
window.Hide ();
window.Destroy ();
this.Hide ();
this.Destroy ();
args.RetVal = true;
}
void OnMarkSet (object o, MarkSetArgs args)
{
TextIter iter = args.Location;
row = iter.Line + 1;
column = iter.VisibleLineOffset;
count = args.Mark.Buffer.CharCount;
UpdateStatus ();
}
void UpdateStatus ()
{
statusbar.Pop (ctx);
statusbar.Push (ctx, String.Format (fmt, row, column, count));
}
}
}

View file

@ -12,25 +12,20 @@
*/
using System;
using Gtk;
namespace GtkDemo
{
public class DemoButtonBox
public class DemoButtonBox : Gtk.Window
{
private Gtk.Window window;
public DemoButtonBox ()
public DemoButtonBox () : base ("Button Boxes")
{
// Create a Window
window = new Gtk.Window ("Button Boxes");
window.DeleteEvent += new DeleteEventHandler (WindowDelete);
window.BorderWidth = 10;
this.DeleteEvent += new DeleteEventHandler (WindowDelete);
this.BorderWidth = 10;
// Add Vertical Box
VBox mainVbox = new VBox (false,0);
window.Add (mainVbox);
this.Add (mainVbox);
// Add Horizontal Frame
Frame horizontalFrame = new Frame ("Horizontal Button Boxes");
@ -58,7 +53,7 @@ namespace GtkDemo
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 ();
this.ShowAll ();
}
// Create a Button Box with the specified parameters
@ -95,8 +90,9 @@ namespace GtkDemo
private void WindowDelete (object o, DeleteEventArgs args)
{
window.Hide ();
window.Destroy ();
this.Hide ();
this.Destroy ();
args.RetVal = true;
}
}
}

View file

@ -13,28 +13,23 @@
*/
using System;
using Gdk;
using Gtk;
namespace GtkDemo
{
public class DemoColorSelection
public class DemoColorSelection : Gtk.Window
{
private Gtk.Window window ;
private Gdk.Color color;
private ColorSelectionDialog colorSelectionDialog;
private Gtk.DrawingArea drawingArea;
public DemoColorSelection ()
public DemoColorSelection () : base ("Color Selection")
{
window = new Gtk.Window ("Color Selection");
window.DeleteEvent += new DeleteEventHandler (WindowDelete);
window.BorderWidth = 8;
this.DeleteEvent += new DeleteEventHandler (WindowDelete);
this.BorderWidth = 8;
VBox vbox = new VBox (false,8);
vbox.BorderWidth = 8;
window.Add (vbox);
this.Add (vbox);
// Create the color swatch area
Frame frame = new Frame ();
@ -56,13 +51,14 @@ namespace GtkDemo
alignment.Add (button);
vbox.PackStart (alignment);
window.ShowAll ();
this.ShowAll ();
}
private void WindowDelete (object o, DeleteEventArgs args)
{
window.Hide ();
window.Destroy ();
this.Hide ();
this.Destroy ();
args.RetVal = true;
}
// Expose callback for the drawing area
@ -81,28 +77,21 @@ namespace GtkDemo
private void ChangeColorCallback (object o, EventArgs args)
{
colorSelectionDialog = new ColorSelectionDialog ("Changing color");
colorSelectionDialog.TransientFor = window;
using (ColorSelectionDialog colorSelectionDialog = new ColorSelectionDialog ("Changing color")) {
colorSelectionDialog.TransientFor = this;
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)
if (colorSelectionDialog.Run () == (int) ResponseType.Ok)
{
Gdk.Color selected = colorSelectionDialog.ColorSelection.CurrentColor;
drawingArea.ModifyBg (StateType.Normal, selected);
colorSelectionDialog.Destroy ();
}
private void Color_Selection_Cancel (object o, EventArgs args)
{
colorSelectionDialog.Destroy ();
colorSelectionDialog.Hide ();
}
}
}
}

View file

@ -16,26 +16,24 @@
// - 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 System;
using Gtk;
namespace GtkDemo
{
public class DemoDialog
public class DemoDialog : Gtk.Window
{
private Gtk.Window window;
private Entry entry1;
private Entry entry2;
public DemoDialog ()
public DemoDialog () : base ("Dialogs")
{
window = new Gtk.Window ("Dialogs");
window.DeleteEvent += new DeleteEventHandler(WindowDelete);
window.BorderWidth = 8;
this.DeleteEvent += new DeleteEventHandler(WindowDelete);
this.BorderWidth = 8;
Frame frame = new Frame ("Dialogs");
window.Add (frame);
this.Add (frame);
VBox vbox = new VBox (false, 8);
vbox.BorderWidth = 8;
@ -76,36 +74,40 @@ namespace GtkDemo
table.Attach (entry2, 1, 2, 1, 2);
label.MnemonicWidget = entry2;
window.ShowAll ();
this.ShowAll ();
}
private void WindowDelete (object o, DeleteEventArgs args)
{
window.Hide ();
window.Destroy ();
this.Hide ();
this.Destroy ();
args.RetVal = true;
}
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,
using (Dialog dialog = new MessageDialog (this,
DialogFlags.Modal | DialogFlags.DestroyWithParent,
MessageType.Info,
ButtonsType.Ok,
message);
message)) {
dialog.Run ();
dialog.Destroy ();
dialog.Hide ();
}
i++;
}
private void InteractiveDialogClicked (object o, EventArgs args)
{
MessageDialog dialog = new MessageDialog (window,
using (MessageDialog dialog = new MessageDialog (this,
DialogFlags.Modal | DialogFlags.DestroyWithParent,
MessageType.Question,
ButtonsType.Ok,
null);
null)) {
dialog.AddButton ("_Non-stock Button", (int) ResponseType.Cancel);
@ -142,7 +144,9 @@ namespace GtkDemo
entry2.Text = localEntry2.Text;
}
dialog.Destroy ();
dialog.Hide ();
}
}
}
}

View file

@ -22,32 +22,29 @@
* to clear the area.
*/
using System;
using Gtk;
using Gdk;
namespace GtkDemo {
public class DemoDrawingArea
namespace GtkDemo
{
public class DemoDrawingArea : Gtk.Window
{
private Gtk.Window window;
private static Pixmap pixmap = null;
private static DrawingArea drawingArea;
private static DrawingArea drawingArea1;
public DemoDrawingArea ()
public DemoDrawingArea () : base ("Drawing Area")
{
window = new Gtk.Window ("Drawing Area");
window.DeleteEvent += new DeleteEventHandler (WindowDelete);
window.BorderWidth = 8;
this.DeleteEvent += new DeleteEventHandler (WindowDelete);
this.BorderWidth = 8;
VBox vbox = new VBox (false, 8);
vbox.BorderWidth = 8;
window.Add (vbox);
this.Add (vbox);
// Create the checkerboard area
Label label = new Label(null);
Label label = new Label ();
label.Markup = "<u>Checkerboard pattern</u>";
vbox.PackStart (label, false, false, 0);
@ -87,13 +84,14 @@ namespace GtkDemo {
drawingArea1.Events = EventMask.LeaveNotifyMask | EventMask.ButtonPressMask |
EventMask.PointerMotionMask | EventMask.PointerMotionHintMask;
window.ShowAll ();
this.ShowAll ();
}
private void WindowDelete (object o, DeleteEventArgs args)
{
window.Hide ();
window.Destroy ();
this.Hide ();
this.Destroy ();
args.RetVal = true;
}
private void CheckerboardExpose (object o, ExposeEventArgs args)
@ -122,7 +120,6 @@ namespace GtkDemo {
color.Blue = 65535;
gc2.RgbFgColor = color;
// Start redrawing the Checkerboard
xcount = 0;
i = Spacing;
@ -146,7 +143,6 @@ namespace GtkDemo {
// return true because we've handled this event, so no
// further processing is required.
args.RetVal = true;
}
private void ScribbleExpose (object o, ExposeEventArgs args)
@ -218,7 +214,6 @@ namespace GtkDemo {
args.RetVal = true;
}
// Draw a rectangle on the screen
static void DrawBrush (double x, double y)
{

View file

@ -16,26 +16,23 @@
using System;
using System.Collections;
using Gtk;
namespace GtkDemo
{
public class DemoEditableCells
public class DemoEditableCells : Gtk.Window
{
private Gtk.Window window;
private ListStore store;
private TreeView treeView;
private ArrayList articles;
public DemoEditableCells ()
public DemoEditableCells () : base ("Color Selection")
{
window = new Gtk.Window ("Color Selection");
window.SetDefaultSize (320, 200);
window.DeleteEvent += new DeleteEventHandler (WindowDelete);
this.SetDefaultSize (320, 200);
this.DeleteEvent += new DeleteEventHandler (WindowDelete);
VBox vbox = new VBox (false, 5);
window.Add (vbox);
this.Add (vbox);
vbox.PackStart (new Label ("Shopping list (you can edit the cells!)"), false, false, 0);
@ -63,11 +60,9 @@ namespace GtkDemo
button.Clicked += new EventHandler (RemoveItem);
hbox.PackStart (button, true, true, 0);
window.ShowAll ();
this.ShowAll ();
}
private void AddColumns ()
{
CellRendererText renderer;
@ -79,7 +74,6 @@ namespace GtkDemo
treeView.AppendColumn ("Number", renderer,
"text", (int) Column.Number);
// product column
renderer = new CellRendererText ();
renderer.Edited += new EditedHandler (TextCellEdited);
@ -91,7 +85,6 @@ namespace GtkDemo
private void CreateModel ()
{
// create array
articles = new ArrayList ();
AddItems ();
@ -101,7 +94,6 @@ namespace GtkDemo
// add items
foreach (Item item in articles)
store.AppendValues (item.Number, item.Product, item.Editable);
}
private void AddItems ()
@ -126,56 +118,40 @@ namespace GtkDemo
private void WindowDelete (object o, DeleteEventArgs args)
{
window.Hide ();
window.Destroy ();
this.Hide ();
this.Destroy ();
args.RetVal = true;
}
// 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;
Item foo;
try
{
i = Convert.ToInt32 (args.Path);
foo = (Item) articles[i];
foo.Number = int.Parse (args.NewText);
}
catch (Exception e)
{
Console.WriteLine ("Exeception {0}",e);
return; // This return should exit the callback but it doesn't
Console.WriteLine (e.ToString ());
return;
}
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 !!!
TreeIter iter;
store.GetIterFromString (out iter, args.Path);
// store.SetValue(iter, (int) Column.Number, foo.Number);
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]);
int i = int.Parse (args.Path);
Item foo = (Item) articles[i];
// Console.WriteLine ("foo.Product {0}", foo.Product);
// Console.WriteLine ("");
foo.Product = args.NewText;
TreeIter iter = new TreeIter ();
TreeIter iter;
store.GetIterFromString (out iter, args.Path);
store.SetValue (iter, (int) Column.Product, foo.Product);
}
@ -194,10 +170,9 @@ namespace GtkDemo
if (treeView.Selection.GetSelected (out model, out iter))
{
TreePath path = store.GetPath (iter);
int position = int.Parse (store.GetPath (iter).ToString ());
store.Remove (ref iter);
//articles.RemoveAt (path.Indices[0]);
articles.RemoveAt (position);
}
}
}

View file

@ -31,21 +31,21 @@ using System.IO;
using Gtk;
using Gdk;
namespace GtkDemo {
public class DemoImages
namespace GtkDemo
{
public class DemoImages : Gtk.Window
{
private Gtk.Window window;
private static Gtk.Image progressiveImage;
private VBox vbox;
public DemoImages ()
public DemoImages () : base ("images")
{
window = new Gtk.Window ("Images");
window.DeleteEvent += new DeleteEventHandler (WindowDelete);
window.BorderWidth = 8;
this.DeleteEvent += new DeleteEventHandler (WindowDelete);
this.BorderWidth = 8;
vbox = new VBox (false, 8);
vbox.BorderWidth = 8;
window.Add (vbox);
this.Add (vbox);
Gtk.Label label = new Gtk.Label ("<u>Image loaded from a file</u>");
label.UseMarkup = true;
@ -104,13 +104,14 @@ namespace GtkDemo {
vbox.PackStart (button, false, false, 0);
button.Toggled += new EventHandler (ToggleSensitivity);
window.ShowAll ();
this.ShowAll ();
}
private void WindowDelete (object o, DeleteEventArgs args)
{
window.Hide ();
window.Destroy ();
this.Hide ();
this.Destroy ();
args.RetVal = true;
}
private void ToggleSensitivity (object o, EventArgs args)
@ -122,7 +123,6 @@ namespace GtkDemo {
widget.Sensitive = !widget.Sensitive;
}
private uint timeout_id;
private void StartProgressiveLoading ()
{
@ -160,6 +160,5 @@ namespace GtkDemo {
{
}
}
}

View file

@ -21,24 +21,22 @@ using Gdk;
namespace GtkDemo
{
public class DemoItemFactory
public class DemoItemFactory : Gtk.Window
{
private Gtk.Window window;
public DemoItemFactory ()
public DemoItemFactory () : base ("Demo Item Factory")
{
window = new Gtk.Window (null);
window.DeleteEvent += new DeleteEventHandler (WindowDelete);
this.DeleteEvent += new DeleteEventHandler (WindowDelete);
Gtk.AccelGroup accelGroup = new Gtk.AccelGroup ();
//STUCK OUCH !!!!
window.ShowAll ();
this.ShowAll ();
}
private void WindowDelete (object o, DeleteEventArgs args)
{
window.Hide ();
window.Destroy ();
this.Hide ();
this.Destroy ();
args.RetVal = true;
}
}
}

View file

@ -21,18 +21,17 @@ using Gtk;
namespace GtkDemo
{
public class DemoListStore
public class DemoListStore : Gtk.Window
{
private Window window;
ListStore store;
public DemoListStore (){
window = new Window ("ListStore Demo");
window.DeleteEvent += new DeleteEventHandler (WindowDelete);
public DemoListStore () : base ("ListStore Demo")
{
this.DeleteEvent += new DeleteEventHandler (WindowDelete);
VBox vbox = new VBox (false, 8);
vbox.BorderWidth = 8;
window.Add (vbox);
this.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);
@ -51,15 +50,12 @@ namespace GtkDemo
scrolledWindow.Add (treeView);
// finish & show
window.SetDefaultSize (650, 400);
window.ShowAll ();
this.SetDefaultSize (650, 400);
this.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))
{
@ -97,14 +93,13 @@ namespace GtkDemo
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 ();
this.Hide ();
this.Destroy ();
args.RetVal = true;
}
private void CreateModel ()
@ -119,11 +114,13 @@ namespace GtkDemo
store.AppendValues(bug.Fixed,
bug.Number,
bug.Severity,
bug.Description);}
bug.Description);
}
}
//FIXME: Insted of using numbert conver enum to array using
// GetValues and then ge the Length Property
// FIXME: Instead of using number convert enum to array using
// GetValues and then get the Length Property
public enum ColumnNumber
{
Fixed,
@ -132,8 +129,6 @@ namespace GtkDemo
Description,
}
private static Bug[] bugs =
{
new Bug ( false, 60482, "Normal", "scrollable notebooks and hidden tabs"),
@ -153,7 +148,6 @@ namespace GtkDemo
};
}
public class Bug
{
public bool Fixed;
@ -161,9 +155,7 @@ namespace GtkDemo
public string Severity;
public string Description;
public Bug ( bool status,
int number,
string severity,
public Bug (bool status, int number, string severity,
string description)
{
Fixed = status;
@ -172,5 +164,4 @@ namespace GtkDemo
Description = description;
}
}
}

View file

@ -57,7 +57,6 @@ namespace GtkDemo
private void LoadFile (string filename)
{
Stream file = File.OpenRead (filename);
StreamReader sr = new StreamReader (file);
string s = sr.ReadToEnd ();
@ -84,10 +83,7 @@ namespace GtkDemo
// The gtk-logo-rgb icon has a white background, make it transparent
Pixbuf transparent = pixbuf.AddAlpha (true, 0xff, 0xff, 0xff);
Gdk.Pixbuf[] list = new Gdk.Pixbuf [1];
list[0] = transparent;
Gtk.Window.DefaultIconList = list;
Gtk.Window.DefaultIconList = new Gdk.Pixbuf [] {transparent};
}
}
@ -119,7 +115,6 @@ namespace GtkDemo
FontDescription fontDescription = FontDescription.FromString ("Courier 12");
textView.ModifyFont (fontDescription);
textView.WrapMode = Gtk.WrapMode.None;
}
else
{
@ -132,7 +127,6 @@ namespace GtkDemo
return scrolledWindow;
}
private TreeView CreateTree ()
{
treeView = new TreeView ();
@ -143,7 +137,7 @@ namespace GtkDemo
{
store = new TreeStore (typeof (string));
store.AppendValues ("Application Window (5% complete)");
store.AppendValues ("Application Window (75% complete)");
store.AppendValues ("Button Boxes");
store.AppendValues ("Change Display");
store.AppendValues ("Color Selector");
@ -158,16 +152,15 @@ namespace GtkDemo
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, "Editable Cells");
store.AppendValues (iter, "List Store");
store.AppendValues (iter, "Tree Store (95% complete)");
store.AppendValues (iter, "Tree Store");
return store;
}
private void OnTreeChanged (object o, EventArgs args)
{
TreeIter iter;
TreeModel model;
@ -235,7 +228,6 @@ namespace GtkDemo
default:
break;
}
}
}

View file

@ -41,25 +41,21 @@
// point on the right side
using System;
using Gtk;
namespace GtkDemo
{
public class DemoMenus
public class DemoMenus : Gtk.Window
{
private Gtk.Window window;
public DemoMenus ()
public DemoMenus () : base ("Menus")
{
window = new Window ("Menus");
window.DeleteEvent += new DeleteEventHandler (WindowDelete);
this.DeleteEvent += new DeleteEventHandler (WindowDelete);
AccelGroup accel_group = new AccelGroup ();
window.AddAccelGroup (accel_group);
this.AddAccelGroup (accel_group);
VBox box1 = new VBox (false, 0);
window.Add (box1);
this.Add (box1);
MenuBar menubar = new MenuBar ();
box1.PackStart (menubar, false, false, 0);
@ -128,7 +124,7 @@ namespace GtkDemo
close_button.CanDefault = true;
close_button.GrabDefault ();
window.ShowAll ();
this.ShowAll ();
}
private Menu Create_Menu (int depth, bool tearoff)
@ -170,14 +166,15 @@ namespace GtkDemo
private void Close_Button (object o, EventArgs args)
{
window.Hide ();
window.Destroy ();
this.Hide ();
this.Destroy ();
}
private void WindowDelete (object o, DeleteEventArgs args)
{
window.Hide ();
window.Destroy ();
this.Hide ();
this.Destroy ();
args.RetVal = true;
}
}
}

View file

@ -22,14 +22,12 @@
using System;
using Gtk;
namespace GtkDemo
{
public class DemoPanes
public class DemoPanes : Gtk.Window
{
private Window window;
private VPaned vpaned;
private HPaned top;
private Frame left;
@ -45,14 +43,14 @@ namespace GtkDemo
private CheckButton resizeBottom;
private CheckButton shrinkBottom;
private Button button;
public DemoPanes ()
public DemoPanes () : base ("Panes")
{
window = new Window ("Panes");
window.DeleteEvent += new DeleteEventHandler (WindowDelete);
window.BorderWidth = 0;
this.DeleteEvent += new DeleteEventHandler (WindowDelete);
this.BorderWidth = 0;
VBox vbox = new VBox (false, 0);
window.Add (vbox);
this.Add (vbox);
vpaned = new VPaned ();
vbox.PackStart (vpaned, true, true, 0);
@ -144,7 +142,7 @@ namespace GtkDemo
shrinkBottom.Active = true;
shrinkBottom.Toggled += new EventHandler (BottomCB);
window.ShowAll ();
this.ShowAll ();
}
private void LeftCB (object o, EventArgs args)
@ -153,7 +151,6 @@ namespace GtkDemo
top.Pack1 (left, resizeLeft.Active, shrinkLeft.Active);
}
private void RightCB (object o, EventArgs args)
{
top.Remove (right);
@ -172,11 +169,10 @@ namespace GtkDemo
vpaned.Pack2 (bottom, resizeBottom.Active, shrinkBottom.Active);
}
private void WindowDelete (object o, DeleteEventArgs args)
{
window.Hide ();
window.Destroy ();
this.Hide ();
this.Destroy ();
}
}
}

View file

@ -30,10 +30,10 @@ 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",
@ -59,9 +59,6 @@ namespace GtkDemo
// drawing area
DrawingArea drawingArea;
string FindFile (string name)
{
return name;
@ -81,11 +78,9 @@ namespace GtkDemo
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;
@ -98,11 +93,8 @@ namespace GtkDemo
Gdk.PixbufAlphaMode.Full, 8,
RgbDither.Normal,
100, 100);
}
// timeout handler to regenerate the frame
bool timeout ()
{
@ -170,23 +162,23 @@ namespace GtkDemo
return true;
}
private Gtk.Window window;
public DemoPixbuf () : base ("Gdk Pixbuf Demo")
{
//window = new DemoPixbuf ();
//window.DeleteEvent += new DeleteEventHandler (WindowDelete);
this.DeleteEvent += new DeleteEventHandler (OnWindowDelete);
try {
try
{
LoadPixbuf ();
} catch (Exception e) {
MessageDialog md = new MessageDialog (this,
} catch (Exception e)
{
using (MessageDialog md = new MessageDialog (this,
DialogFlags.DestroyWithParent,
MessageType.Error,
ButtonsType.Close,
"Error: \n" + e.Message);
"Error: \n" + e.Message)) {
md.Run ();
md.Hide ();
}
throw;
}
@ -205,13 +197,12 @@ namespace GtkDemo
ShowAll ();
}
static void windowDelete (object obj, DeleteEventArgs args)
void OnWindowDelete (object obj, DeleteEventArgs args)
{
Application.Quit ();
this.Hide ();
this.Destroy ();
args.RetVal = true;
}
}
}

View file

@ -22,24 +22,21 @@
*/
using System;
using Gtk;
namespace GtkDemo
{
public class DemoSizeGroup
public class DemoSizeGroup : Dialog
{
private Dialog window;
private SizeGroup sizeGroup;
public DemoSizeGroup ()
{
window = new Dialog ();
window.Title = "Sized groups";
window.Resizable = false;
this.Title = "Size groups";
this.Resizable = false;
VBox vbox = new VBox (false, 5);
window.VBox.PackStart (vbox, true, true, 0);
this.VBox.PackStart (vbox, true, true, 0);
vbox.BorderWidth = 5;
sizeGroup = new SizeGroup (SizeGroupMode.Horizontal);
@ -81,10 +78,10 @@ namespace GtkDemo
checkButton.Toggled += new EventHandler (ButtonToggleCb);
Button CloseButton = new Button (Stock.Close);
window.AddActionWidget (CloseButton, 5);
window.Response += new ResponseHandler (ResponseCallback);
this.AddActionWidget (CloseButton, ResponseType.Close);
this.Response += new ResponseHandler (ResponseCallback);
window.ShowAll ();
this.ShowAll ();
}
// Convenience function to create an option menu holding a number of strings
@ -147,11 +144,11 @@ namespace GtkDemo
}
private void ResponseCallback (object obj, ResponseArgs args)
{
if (((int) args.ResponseId) == 5) {
window.Hide ();
window.Destroy ();}
if ((args.ResponseId) == ResponseType.Close) {
this.Hide ();
this.Destroy ();
}
}
}
}

View file

@ -6,24 +6,20 @@
// (C) 2003 Ximian, Inc.
using System;
using Gtk;
namespace GtkDemo
{
public class DemoStockBrowser
public class DemoStockBrowser : Gtk.Window
{
private Gtk.Window window;
public DemoStockBrowser ()
public DemoStockBrowser () : base ("Stock Item Browser Demo")
{
window = new Gtk.Window ("Stock Item Browser Demo");
window.SetDefaultSize (600, 400);
window.DeleteEvent += new DeleteEventHandler (WindowDelete);
window.BorderWidth = 8;
this.SetDefaultSize (600, 400);
this.DeleteEvent += new DeleteEventHandler (WindowDelete);
this.BorderWidth = 8;
HBox hbox = new HBox (false, 8);
window.Add (hbox);
this.Add (hbox);
ScrolledWindow scrolledWindow = new ScrolledWindow (null, null);
scrolledWindow.SetPolicy (PolicyType.Never, PolicyType.Automatic);
@ -40,16 +36,9 @@ namespace GtkDemo
Frame frame = new Frame ();
hbox.PackStart (frame, true, true, 0);
window.ShowAll ();
this.ShowAll ();
}
// private TreeModel CreateModel ()
// {
// ListStore store;
// TreeModel model = new TreeModel ();
// return model;
// }
private ListStore CreateStore ()
{
// image, name, label, accel
@ -66,8 +55,9 @@ namespace GtkDemo
private void WindowDelete (object o, DeleteEventArgs args)
{
window.Hide ();
window.Destroy ();
this.Hide ();
this.Destroy ();
args.RetVal = true;
}
}
}

View file

@ -13,8 +13,6 @@
* formatting features.
*/
using System;
using System.IO;
@ -23,21 +21,20 @@ using Gtk;
namespace GtkDemo
{
public class DemoTextView
public class DemoTextView : Gtk.Window
{
private Gtk.Window window;
TextView view1;
TextView view2;
public DemoTextView ()
public DemoTextView () : base ("TextView Demo")
{
window = new Gtk.Window ("TextView Demo");
window.DeleteEvent += new DeleteEventHandler (WindowDelete);
window.SetDefaultSize (450,450);
window.BorderWidth = 0;
this.DeleteEvent += new DeleteEventHandler (WindowDelete);
this.SetDefaultSize (450,450);
this.BorderWidth = 6;
VPaned vpaned = new VPaned ();
vpaned.BorderWidth = 5;
window.Add (vpaned);
this.Add (vpaned);
/* For convenience, we just use the autocreated buffer from
* the first text view; you could also create the buffer
@ -66,14 +63,15 @@ namespace GtkDemo
vpaned.ShowAll();
window.ShowAll ();
this.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");
@ -106,7 +104,6 @@ namespace GtkDemo
Entry entry = new Entry ();
textView.AddChildAtAnchor (entry, entryAnchor);
image.ShowAll ();
}
private void CreateTags (TextBuffer buffer)
@ -392,7 +389,6 @@ namespace GtkDemo
TextIter insertIter, beginIter, endIter;
int begin, end;
begin = buffer.CharCount;
insertIter = buffer.GetIterAtMark(buffer.InsertMark);
buffer.Insert (insertIter, insertText);
@ -400,21 +396,22 @@ namespace GtkDemo
foreach (string fontItem in fontName) {
endIter = buffer.GetIterAtOffset (end);
beginIter = buffer.GetIterAtOffset (begin);
buffer.ApplyTag (fontItem, beginIter, endIter);}
buffer.ApplyTag (fontItem, beginIter, endIter);
}
}
private void Insert (TextBuffer buffer , string insertText)
{
TextIter insertIter;
insertIter = buffer.GetIterAtMark (buffer.InsertMark);
buffer.Insert (insertIter, insertText);
}
private void WindowDelete (object o, DeleteEventArgs args)
{
window.Hide ();
window.Destroy ();
this.Hide ();
this.Destroy ();
args.RetVal = true;
}
private void RecursiveAttach (int depth, TextView view, TextChildAnchor anchor)
@ -437,7 +434,6 @@ namespace GtkDemo
view.AddChildAtAnchor (eventBox, anchor);
RecursiveAttach (depth+1, childView, anchor);
}
private void EasterEggCB (object o, EventArgs args)
@ -462,7 +458,6 @@ namespace GtkDemo
window.SetDefaultSize (300, 400);
window.ShowAll ();
}
}
}

View file

@ -22,19 +22,17 @@ using GLib;
namespace GtkDemo
{
public class DemoTreeStore
public class DemoTreeStore : Gtk.Window
{
private Window window;
private TreeStore store;
public DemoTreeStore ()
public DemoTreeStore () : base ("TreeStore Demo")
{
window = new Window ("TreeStore Demo");
window.DeleteEvent += new DeleteEventHandler (WindowDelete);
this.DeleteEvent += new DeleteEventHandler (WindowDelete);
VBox vbox = new VBox (false, 8);
vbox.BorderWidth = 8;
window.Add (vbox);
this.Add (vbox);
vbox.PackStart (new Label ("Jonathan's Holiday Card Planning Sheet"), false, false, 0);
@ -60,10 +58,8 @@ namespace GtkDemo
treeView.ExpandRow (new TreePath (i.ToString ()), false);
}
window.SetDefaultSize (650, 400);
window.ShowAll ();
this.SetDefaultSize (650, 400);
this.ShowAll ();
}
private void ItemToggled (object o, ToggledArgs args)
@ -106,7 +102,6 @@ namespace GtkDemo
column.Clickable = true;
treeView.InsertColumn (column, (int) Column.Alex);
// havoc column
rendererToggle = new CellRendererToggle ();
rendererToggle.Xalign = 0.0f;
@ -166,13 +161,13 @@ namespace GtkDemo
column.Sizing = TreeViewColumnSizing.Fixed;
column.FixedWidth = 50;
column.Clickable = true;
}
private void WindowDelete (object o, DeleteEventArgs args)
{
window.Hide ();
window.Destroy ();
this.Hide ();
this.Destroy ();
args.RetVal = true;
}
private void CreateModel ()
@ -189,7 +184,6 @@ namespace GtkDemo
typeof(bool));
// add data to the tree store
// STUCK !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
foreach (MyTreeItem month in toplevel)
{
@ -212,11 +206,8 @@ namespace GtkDemo
hollyday.Owen,
hollyday.Dave,
true);
}
}
}
// tree data
@ -327,7 +318,6 @@ namespace GtkDemo
};
// TreeItem structure
// report bug array mismatch declaration
public class MyTreeItem
{
public string Label;

18
sample/GtkDemo/TODO Normal file
View file

@ -0,0 +1,18 @@
General
- general C#-ification
- embed PixBufs instead of loading from disk
DemoApplicationWindow
- ItemFactory stuff
DemoIconFactory
- almost everything
DemoImages
- fix the progressive loading image
DemoStockBrowser
- almost everything
DemoTextView
- small issue with international text