| 12
 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
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 
 | //
// 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;
namespace GtkDemo 
{
	public class DemoDialog : Gtk.Window
	{
		private Entry entry1;
		private Entry entry2;
		public DemoDialog () : base ("Dialogs")
		{
			this.DeleteEvent += new DeleteEventHandler(WindowDelete);
			this.BorderWidth = 8;
			Frame frame = new Frame ("Dialogs");
			this.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 = new Label ("_Entry1");
			table.Attach (label, 0, 1, 0, 1);
			entry1 = new Entry ();
			table.Attach (entry1, 1, 2, 0, 1);
			label.MnemonicWidget = entry1;
			
			label = new Label ("E_ntry2");
			table.Attach (label,0,1,1,2);
			entry2 = new Entry ();
			table.Attach (entry2, 1, 2, 1, 2);
			label.MnemonicWidget = entry2;			
			
			this.ShowAll ();
		}
		private void WindowDelete (object o, DeleteEventArgs args)
		{
			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);
			using (Dialog dialog = new MessageDialog (this, 
					DialogFlags.Modal | DialogFlags.DestroyWithParent,
					MessageType.Info,
					ButtonsType.Ok,
					message)) {
				dialog.Run ();
				dialog.Hide ();
			}
			i++;
		}
		private void InteractiveDialogClicked (object o, EventArgs args)
		{
			using (MessageDialog dialog = new MessageDialog (this,
					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 = new Label ("_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 = new Label ("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.Hide ();
			}
		}
	}		     
}
 |