About a month ago there was some discussion about printing in gtk-sharp,
and I have recently had a need to give it a try.  One of my problems is
that I want to print the content of a widget that will most likely have
multiple pages.  To set the number of pages, I need to reference my
Gtk.PrintOperation object from my BeginPrintHandler (as the Gtk
documentation suggests).  The problem is, that my object is out of
scope.  Here's an example:

protected virtual void OnPrintButtonClicked (object sender,
System.EventArgs e)
{
        Gtk.PrintOperation Op = new PrintOperation();

        Op.Unit = Gtk.Unit.Pixel;
        Op.BeginPrint += new BeginPrintHandler(OnBeginPrint);
        Op.DrawPage += new DrawPageHandler(OnDrawPage);
        
        Res = Op.Run(Gtk.PrintOperationAction.PrintDialog, this);
}

public void OnBeginPrint(object sender, Gtk.BeginPrintArgs Args)
{
        int nSize = SomeSizeCalculationFunction();
                
        int nPages = nSize / (int)Args.Context.Height;
                
        if(nSize % Args.Context.Height > 0)
        {
                nPages++;
        }
        
        Op.NPages = nPages; // OUT OF SCOPE
}

This can be easily solved by making Op global, but isn't there a way to
include Op in the Gtk.BeginPrintArgs object?  Right now the only thing
it contains is the PrintContext, which is also needed, but is only one
factor in the page count calculation.

This isn't a problem in C, because the parameters passed to a BeginPrint
signal handler include the PrintOperation pointer.  I just thought that
maybe the C# handler should match.

--Jestin

_______________________________________________
Gtk-sharp-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list

Reply via email to