[racket] how to add text-field-style behavior to rectangles drawn on a canvas

From: Marijn (hkBst at gentoo.org)
Date: Thu Oct 6 06:40:18 EDT 2011

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 10/05/11 15:02, Matthew Flatt wrote:
> At Wed, 05 Oct 2011 15:00:06 +0200, Marijn wrote:
>> Suppose one has a spreadsheet-like grid drawn on a canvas%. How
>> does one add text-field%-style behavior to the rectangles drawn?
> 
> You could implement an `editor-admin%' subclass to manage a
> `text%' within the grid.

Thanks for that suggestion, I'm looking into that right now.

Unfortunately the docs could use some work in this area, so I've also
tried to use the source. The most useful seems to be editor-canvas.rkt
in the collects/mred/private/wxme directory.

My current understanding is that:

- - The display (a grid in my case) should create an editor-admin% which
in turn should have a field to refer back to its display. When an
editor becomes available to the display, the display will notify the
editor of the editor-admin% instance through which it should direct
its requests.

- - The editor-admin% get-dc method is used to determine the upper left
corner of the area in the drawing context into which the editor should
draw itself. If I read the source correctly the docs are wrong here in
that "The x box is filled with the x-origin of the DC in editor
coordinates, unless x is #f." really should be something like "Unless
x is #f, the x box is filled with the x-coordinate of the upper left
corner of the area in the drawing context into which the editor should
draw itself."

- - The get-view method determines the area of the editor which should
be drawn into the dc returned by get-dc at the dc coordinates returned
in the box arguments of get-dc. The full? argument is #t in case of an
embedded editor.

- - The get-max-view method is not used to determine a bounding box of
all displays of this editor in display coordinates (which doesn't even
make sense). Instead it is used to determine the union of all regions
in the editor which are viewed in some display. But how does get-view
know which of the displayed regions if there are multiple to return?
And how does get-dc then know of which display to return the dc and
upper left corner?

- - The grab-caret method is specified in the docs to call the editor's
own-caret method. Well, maybe it doesn't claim that it will be called
directly, but as I understand it now, it really will defer to the
display by calling its set-focus method. I didn't check whether the
set-focus method does or doesn't call the editor's own-caret method.

- - The modified method is used to determine whether content in an
editor is different from that same content stored on disk. Or?

- - The needs-update method is specified in the docs to call the
editor's refresh method, but in the code it calls methods (repaint,
redraw) of the display instead.

Marijn
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.18 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk6NhZIACgkQp/VmCx0OL2wHhQCgm/j2XgBtgvu09nQy7qaDmJxZ
R1oAn3hdwxiX698gZAtotwwntlOBAE4g
=2A38
-----END PGP SIGNATURE-----


Posted on the users mailing list.