[plt-scheme] The missing drawing context

From: Jens Axel Soegaard (jensaxel at soegaard.net)
Date: Fri Mar 20 15:27:55 EDT 2009

Hi,

Robby wrote:
 > Oh, I think you have to wait and do the layout when you get the dc.
 > I'm not remembering which callbacks inform you of that, but I think
 > you should try get-extent and, if that fails, on-paint.

I tried both get-extent and on-paint, but they never seem
to be called. In the example below, the pasteboard contains
a string-snip. I can move the string snip within the pasteboard
without any problems. Just to make sure everything was
wired correctly, I make on-focus display 'on-focus and that
did work.

So now I am wondering why on-paint isn't called.

/Jens Axel



#lang scheme/gui

(define (make-string-snip string)
   (make-object string-snip% string))

(define (insert-snip editor snip)
   (send editor insert snip))

(define (insert-snips editor snips)
   (for-each (λ (s) (insert-snip editor s)) snips))

(define (get-width dc snip)
   (let ([w (box 0)])
     (send snip get-extent dc 0 0 w)
     (unbox w)))

(define column-pasteboard%
   (class pasteboard%
     (super-new)
     (define/override (get-extent . more)
       (display "get-extent:\n") (/ 0 0))
     (define/override (on-paint . more) (display 'on-paint) (/ 0 0))
     (define/override (on-focus . more)
       (display (format "on-focus!\n")))))

(define column-editor-snip%
   (class editor-snip%
     (super-new)
     (define/override (draw . more) (/ 2 0))))

; ---

(define pasteboard (new column-pasteboard%))
(define snips (map make-string-snip '("Foo" ))) ;"Bar" "Baz" "Qux")))

(define editor-snip
   (new column-editor-snip%
        [editor pasteboard]
        [min-width 100]
        [min-height 100]))

(insert-snips pasteboard snips)
editor-snip



> 
> On Thu, Mar 19, 2009 at 3:40 PM, Jens Axel Soegaard
> <jensaxel at soegaard.net> wrote:
>> Robby Findler wrote:
>>> The pasteboard has to be in an editor-canvas to have a dc, I believe.
>>> In general, there are multiple possible dc classes that have different
>>> font sizing information (eg, canvas-dc% that draws on the screen and
>>> post-script-dc% that prints).
>> The reason I put the pasteboard in an editor-snip was to make
>> it displayable in the DrScheme REPL. Since a user program
>> can't get to DrScheme's editor canvas, I am a little unsure
>> on how to achive what I want.
>>
>> The over all goal is to implement something like:
>>
>> http://reference.wolfram.com/mathematica/ref/Column.html
>> (and http://reference.wolfram.com/mathematica/guide/GridsAndTables.html)
>>
>> /Jens Axel
>>
>> _________________________________________________
>>  For list-related administrative tasks:
>>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>>
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.