diff --git a/ChangeLog b/ChangeLog index 7cb97df72..2c703b02a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2003-11-22 John Luke + + * sample/PrintSample.cs: add small Gnome.Print example + * sample/Makefile.in: add print example to gnome build + 2003-11-19 Peter Williams * gtk/Gtk.metadata: Add some array attributes for some "type *elem, diff --git a/sample/Makefile.in b/sample/Makefile.in index 96375a735..55ecfef58 100755 --- a/sample/Makefile.in +++ b/sample/Makefile.in @@ -2,7 +2,7 @@ MCS=mcs @ENABLE_GNOME_TRUE@ GNOME_PATH=-L ../art -L ../gnome @ENABLE_GNOME_TRUE@ GNOME_ASSEMBLY=-r art-sharp.dll -r gnome-sharp.dll -@ENABLE_GNOME_TRUE@ GNOME_TARGETS=gnome-hello-world.exe canvas-example.exe fifteen.exe +@ENABLE_GNOME_TRUE@ GNOME_TARGETS=gnome-hello-world.exe canvas-example.exe fifteen.exe print.exe @ENABLE_GLADE_TRUE@ GLADE_PATH=-L ../glade @ENABLE_GLADE_TRUE@ GLADE_ASSEMBLY=-r glade-sharp.dll @@ -33,6 +33,9 @@ canvas-example.exe: CanvasExample.cs fifteen.exe: Fifteen.cs $(MCS) --unsafe -o fifteen.exe $(local_paths) $(all_assemblies) Fifteen.cs + +print.exe: PrintSample.cs + $(MCS) --unsafe -o print.exe $(local_paths) $(all_assemblies) PrintSample.cs button.exe: ButtonApp.cs $(MCS) --unsafe -o button.exe $(local_paths) $(all_assemblies) ButtonApp.cs diff --git a/sample/PrintSample.cs b/sample/PrintSample.cs new file mode 100644 index 000000000..172f26ea9 --- /dev/null +++ b/sample/PrintSample.cs @@ -0,0 +1,81 @@ +using System; +using Gtk; +using GtkSharp; +using Gnome; + +class PrintSample +{ + TextView tv; + + static void Main () + { + new PrintSample (); + } + + PrintSample () + { + Application.Init (); + Gtk.Window win = new Gtk.Window ("Print sample"); + win.SetDefaultSize (400, 300); + win.DeleteEvent += new DeleteEventHandler (OnWinDelete); + + VBox vbox = new VBox (false, 0); + win.Add (vbox); + + tv = new TextView (); + tv.Buffer.Text = "Hello World"; + vbox.PackStart (tv, true, true, 0); + + Button print = new Button (Gtk.Stock.Print); + print.Clicked += new EventHandler (OnPrintClicked); + vbox.PackStart (print, false, true, 0); + + win.ShowAll (); + Application.Run (); + } + + void MyPrint (PrintContext gpc) + { + Print.Beginpage (gpc, "demo"); + Print.Moveto (gpc, 1, 700); + Print.Show (gpc, tv.Buffer.Text); + Print.Showpage (gpc); + } + + void OnPrintClicked (object o, EventArgs args) + { + PrintJob pj = new PrintJob (PrintConfig.Default ()); + PrintDialog dialog = new PrintDialog (pj, "Print Test", 0); + int response = dialog.Run (); + Console.WriteLine ("response: " + response); + + if (response == (int) PrintButtons.Cancel) { + Console.WriteLine ("Canceled"); + dialog.Hide (); + dialog.Dispose (); + return; + } + + PrintContext ctx = pj.Context; + MyPrint (ctx); + + pj.Close (); + + switch (response) { + case (int) PrintButtons.Print: + pj.Print (); + break; + case (int) PrintButtons.Preview: + new PrintJobPreview (pj, "Print Test").Show (); + break; + } + + dialog.Hide (); + dialog.Dispose (); + } + + void OnWinDelete (object o, DeleteEventArgs args) + { + Application.Quit (); + } +}