1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
//
// 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;
namespace GtkDemo
{
public class DemoApplicationWindow : 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 () : base ("Demo Application Window")
{
this.SetDefaultSize (400, 300);
this.DeleteEvent += new DeleteEventHandler (WindowDelete);
VBox vbox = new VBox (false, 0);
this.Add (vbox);
// Create the menubar
AccelGroup accelGroup = new AccelGroup ();
this.AddAccelGroup (accelGroup);
MenuBar menubar = CreateMenu ();
vbox.PackStart (menubar, false, false, 0);
Toolbar toolbar = CreateToolbar ();
vbox.PackStart (toolbar, false, false, 0);
TextView textview = new TextView ();
textview.Buffer.MarkSet += new MarkSetHandler (OnMarkSet);
vbox.PackStart (textview, true, true, 0);
statusbar = new Statusbar ();
UpdateStatus ();
vbox.PackStart (statusbar, false, false, 0);
//ItemFactory itemFactory = new ItemFactory (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
this.ShowAll ();
}
private MenuBar CreateMenu ()
{
MenuBar menubar = new MenuBar ();
MenuItem file = new MenuItem ("File");
menubar.Append (file);
return menubar;
}
private Toolbar CreateToolbar ()
{
Toolbar toolbar = new Toolbar ();
Button open = new Button (Stock.Open);
open.Clicked += new EventHandler (OnToolbarClicked);
toolbar.AppendWidget (open, "Open", "Open");
Button quit = new Button (Stock.Quit);
quit.Clicked += new EventHandler (OnToolbarClicked);
toolbar.AppendWidget (quit, "Quit", "Quit");
Button gtk = new Button ("Gtk#");
gtk.Clicked += new EventHandler (OnToolbarClicked);
toolbar.AppendWidget (gtk, "Gtk#", "Gtk#");
return toolbar;
}
private void OnToolbarClicked (object o, EventArgs args)
{
using (MessageDialog md = new MessageDialog (this, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Close, "You selected a toolbar button.")) {
md.Run ();
md.Hide ();
}
}
private void WindowDelete (object o, DeleteEventArgs args)
{
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));
}
}
}
|