GtkSharp/sample/GtkDemo/DemoClipboard.cs
Dan Winship 246d4e1620 * samples/GtkDemo/*.cs: General fixup and cleanup; Remove some
gratuitous differences from the C version. Make comment and indent
	style consistent. Don't use "this." where not needed. Override
	OnDeleteEvent rather than connecting one's own DeleteEvent signal.

	* sample/GtkDemo/DemoApplicationWindow.cs (static
	DemoApplicationWindow): register the Gtk logo icon with
	StockManager so it shows up correctly in the toolbar.
	(AddActions): Register the radio items as radio items so they work
	right.

	* sample/GtkDemo/DemoHyperText.cs (EventAfter): handle
	link-clicking from Widget.WidgetEventAfter (as in the C version),
	rather than ButtonRelease, now that WidgetEventAfter is wrapped.

	* sample/GtkDemo/DemoImages.cs (DemoImages): use
	Gtk.Image.LoadFromResource (particularly to make the animation
	work right).
	(OnDestroyed): handle clean up (remove the timeout, etc)

	* sample/GtkDemo/DemoMain.cs (LoadStream): Fix handling of blank
	lines and whitespace to match the C version.

	* sample/GtkDemo/DemoPixbuf.cs (Expose): Use
	System.Runtime.InteropServices.Marshal.Copy() to copy
	pixbuf.Pixels to pass to DrawRgbImageDithalign, to make this more
	like the C version (and probably faster?)
	(timeout): Remove the FIXME since it seems to work now

	* sample/GtkDemo/DemoStockBrowser.cs: Simplify a bunch. Use
	reflection to get the C# names of the stock icons rather than
	trying to correctly re-mangle the ids. Display the Label with the
	accelerator underlined.

	* sample/GtkDemo/DemoTextView.cs (AttachWidgets): use
	Gtk.Image.LoadFromResource, so the image is properly loaded as an
	animation, not a static image. Don't set the combobox's "Active"
	property (for consistency with the C version).
	(InsertText): Fix miscellaneous differences with the C version.
	Remove some leftover cruft from earlier workarounds for gtk# bugs.

	* sample/GtkDemo/DemoTreeStore.cs (AddColumns): Make this more
	like the C version so the checkboxes are sensitized and hidden
	correctly on a per-row basis.

	* sample/GtkDemo/DemoUIManager.cs: Make the radio menu items work.

	* sample/GtkDemo/README: 
	* sample/GtkDemo/TODO: update

svn path=/trunk/gtk-sharp/; revision=42481
2005-04-01 21:08:14 +00:00

83 lines
2.1 KiB
C#

/* Clipboard
*
* GtkClipboard is used for clipboard handling. This demo shows how to
* copy and paste text to and from the clipboard.
*
* This is actually from gtk+ 2.6's gtk-demo, but doesn't use any 2.6
* functionality
*/
using System;
using Gtk;
namespace GtkDemo
{
[Demo ("Clipboard", "DemoClipboard.cs")]
public class DemoClipboard : Gtk.Window
{
Entry pasteEntry, copyEntry;
public DemoClipboard () : base ("Demo Clipboard")
{
VBox vbox = new VBox ();
vbox.BorderWidth = 8;
Label copyLabel = new Label ("\"Copy\" will copy the text\nin the entry to the clipboard");
vbox.PackStart (copyLabel, false, true, 0);
vbox.PackStart (CreateCopyBox (), false, true, 0);
Label pasteLabel = new Label ("\"Paste\" will paste the text from the clipboard to the entry");
vbox.PackStart (pasteLabel, false, false, 0);
vbox.PackStart (CreatePasteBox (), false, false, 0);
Add (vbox);
ShowAll ();
}
HBox CreateCopyBox ()
{
HBox hbox = new HBox (false, 4);
hbox.BorderWidth = 8;
copyEntry = new Entry ();
Button copyButton = new Button (Stock.Copy);
copyButton.Clicked += new EventHandler (CopyClicked);
hbox.PackStart (copyEntry, true, true, 0);
hbox.PackStart (copyButton, false, false, 0);
return hbox;
}
HBox CreatePasteBox ()
{
HBox hbox = new HBox (false, 4);
hbox.BorderWidth = 8;
pasteEntry = new Entry ();
Button pasteButton = new Button (Stock.Paste);
pasteButton.Clicked += new EventHandler (PasteClicked);
hbox.PackStart (pasteEntry, true, true, 0);
hbox.PackStart (pasteButton, false, false, 0);
return hbox;
}
void CopyClicked (object obj, EventArgs args)
{
Clipboard clipboard = copyEntry.GetClipboard (Gdk.Selection.Clipboard);
clipboard.SetText (copyEntry.Text);
}
void PasteClicked (object obj, EventArgs args)
{
Clipboard clipboard = pasteEntry.GetClipboard (Gdk.Selection.Clipboard);
clipboard.RequestText (new ClipboardTextReceivedFunc (PasteReceived));
}
void PasteReceived (Clipboard clipboard, string text)
{
pasteEntry.Text = text;
}
protected override bool OnDeleteEvent (Gdk.Event evt)
{
Destroy ();
return true;
}
}
}