All good points Rick. My app will support printing from various
modules: Report Writer, Graph Plotter, Screen Snapshot etc. While I
never meant for the user to attempt to print simultaneously, it is
possible he /she would begin setting up the print job and then switch
to another window in my app. My idea was to encapsulate the print
mechanism in a class to prevent interference from another app window.
The example code was greatly simplified, the real version would
contain additional structures for margins, headers, footers, printer
and font metrics etc, all unique to each module. This makes a class
implementation very attractive.
Your point re one print abort procedure per thread is a good one. I
think a reasonable solution is to use a non-class generic print abort
procedure (like your example below) and simply set it immediately
before the actual printing begins.
I goofed the ['], code shown was quickly (poorly) converted to an
class example. My first attempt was the normal :NONAME CB: method but
the :NONAME code wouldn't compile. :NONAME also does not appear to be
allowed in a class.
> Question: where is the variable ABORT-PRINT? set?
ABORT-PRINT? is set in a modeless dialog box allowing a user to cancel
the print job. The abort procedure requires additional logic to
support the modeless dialog box.
Thanks,
Mike
----- Original Message -----
From: "Rick VanNorman" <rick_at_neverslow.com>
To: <sftalk_at_forth.com>
Sent: Saturday, March 31, 2001 12:09 AM
Subject: [sftalk] Re: Callback in a Class
>
> Mike,
>
> Sigh.
> The problem with implementing a callback is that the interface
between
> windows and SwiftForth (or any program for that matter) is complex.
> Look at the definition of CB: if you don't believe me.
>
> Note also that the concept of a class for dealing with things like
the
> print-abort callback is almost not viable because the whole idea of
> classes is to abstract things that are done many times. Only one
> print job is likely to be in operation at one time, the api only
allows
> one callback such as that per thread, etc.
>
> If I was implementing it, I would abstract by pulling the variable
and
> the callback and the callback proc all out of the class, and happily
> reference them from the class.
>
> (Note also your line of code
>
> > ['] AbrtProc 2 CB: ABORTPROC <<<<<<<< THIS DIES!!!
>
> ['] is a *compiler* word, not an interpreter word. It has no defined
> interpreter behavior or semantics per ans. Should have used just ' )
>
> I can write a callback routine for the class. But I don't think it
> is worth the effort, nor do I think there is any tangible payback
> to it.
>
> Question: where is the variable ABORT-PRINT? set?
>
> Regards,
> Rick
>
> My code would probably look like this:
>
> Function: SetAbortProc ( hDCprt abortProc -- res )
>
> VARIABLE ABORT-PRINT?
>
> \ Classic Printer Abort Procedure
> : AbrtProc ( hDCprt error -- flag ) \ True = Continue
> 2DROP ( hDC error )
> BEGIN WINMSG 0 0 0 PM_REMOVE PeekMessage
> WHILE WINMSG TranslateMessage DROP
> WINMSG DispatchMessage DROP
> REPEAT ABORT-PRINT? @ NOT ;
>
> ' AbrtProc 2 CB: ABORTPROC
>
> CLASS PRT-FOO
>
> PRINTDIALOG BUILDS prtdlg
>
> : SET-ABORT-PROC
> prtdlg DC @ ABORTPROC :: SetAbortProc DROP ;
>
> : DEFAULT-PRINTER ( -- )
> 0 prtdlg DevMode ! 0 prtdlg DevNames !
> PD_RETURNDC PD_RETURNDEFAULT OR prtdlg Flags !
> PRINTDIALOG SIZEOF prtdlg StructSize !
> prtdlg ADDR :: PrintDlg 0= IOR_PRT_NODEFPRINTER ?THROW ;
>
>
> : CONSTRUCT ( -- )
> DEFAULT-PRINTER
> SET-ABORT-PROC
> ( Actual Printing )
> ;
>
> END-CLASS
> R
>
> --------------------------------------------------------------------
-- > sftalk_at_forth.com The SwiftForth programming discussion email list > To unsubscribe, send subject "unsubscribe sftalk" to listar_at_forth.com > For help with listar commands, send subject "help" to listar_at_forth.com > Archives are located at http://www.forth.com/sftalk -- check them out! > ---------------------------------------------------------------------- sftalk_at_forth.com The SwiftForth programming discussion email list To unsubscribe, send subject "unsubscribe sftalk" to listar_at_forth.com For help with listar commands, send subject "help" to listar_at_forth.com Archives are located at http://www.forth.com/sftalk -- check them out!Received on Sat Mar 31 2001 - 09:13:41 PST
Subscribe to our e-mail list service. It's free for all SwiftForth and SwiftX users!
This archive was generated 09-Feb-2012. Archive updated nightly.