Re: [racket-dev] while resizing drawing into a canvas is off

2011-10-21 Thread Marijn
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 10/20/11 20:30, Robby Findler wrote:
 On Thu, Oct 20, 2011 at 11:34 AM, Marijn hk...@gentoo.org wrote:
 -BEGIN PGP SIGNED MESSAGE- Hash: SHA1
 
 Hi Robby,
 
 On 10/20/11 18:15, Robby Findler wrote:
 Generally, the menukey-c, menukey-v, keybindings (and
 friends) come about via the menus, not via a keymap% object.
 And those menus come in via a frame. I'm not sure how you're
 using your library, but you might want to consider some of the
 mixins in the framework whose names start with frame:.
 
 I'm actually trying to create something spreadsheet-like. I'm
 using editors to manage(display/edit) cell contents. Although
 each cell(-editor) individually doesn't have a menu, when used in
 a complete application there probably will be menus, and I'm
 planning to check out what the framework provides.
 
 However, I don't understand the logic of menus that bring about
 key bindings for editors.
 
 I'm not sure how to respond here, except to say that that's what
 the GUI designers of the world seem to have come up with. The
 keybindings that you asked for earlier (control-c and control-v for
 copy and paste under windows, for example (command-c and command-v
 on the mac)) are there because they are shortcuts for menu items,
 not because they are keybindings at the level of the editor.

So you're saying this is something that is inherited from Gtk and the
Windows and OSX graphics layers?

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

iEYEARECAAYFAk6hM5UACgkQp/VmCx0OL2yxQACdEN5pStXBxVEwKIZJFwpu+nvx
P84AoIap2s2eG2cm8VLLR/A/sMSc5XzQ
=O+19
-END PGP SIGNATURE-
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev


Re: [racket-dev] while resizing drawing into a canvas is off

2011-10-21 Thread Robby Findler
On Fri, Oct 21, 2011 at 3:55 AM, Marijn hk...@gentoo.org wrote:
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1

 On 10/20/11 20:30, Robby Findler wrote:
 On Thu, Oct 20, 2011 at 11:34 AM, Marijn hk...@gentoo.org wrote:
 -BEGIN PGP SIGNED MESSAGE- Hash: SHA1

 Hi Robby,

 On 10/20/11 18:15, Robby Findler wrote:
 Generally, the menukey-c, menukey-v, keybindings (and
 friends) come about via the menus, not via a keymap% object.
 And those menus come in via a frame. I'm not sure how you're
 using your library, but you might want to consider some of the
 mixins in the framework whose names start with frame:.

 I'm actually trying to create something spreadsheet-like. I'm
 using editors to manage(display/edit) cell contents. Although
 each cell(-editor) individually doesn't have a menu, when used in
 a complete application there probably will be menus, and I'm
 planning to check out what the framework provides.

 However, I don't understand the logic of menus that bring about
 key bindings for editors.

 I'm not sure how to respond here, except to say that that's what
 the GUI designers of the world seem to have come up with. The
 keybindings that you asked for earlier (control-c and control-v for
 copy and paste under windows, for example (command-c and command-v
 on the mac)) are there because they are shortcuts for menu items,
 not because they are keybindings at the level of the editor.

 So you're saying this is something that is inherited from Gtk and the
 Windows and OSX graphics layers?

Roughly, yes.

You can, of course, make keybindings (via a keymap%) that would cover
standard bindings such as these, but it would be confusing to users of
your library (assuming you package this up as a library) and you'd be
duplicating a bunch of code.

Robby
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev


Re: [racket-dev] while resizing drawing into a canvas is off

2011-10-20 Thread Marijn
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi Matthew,

On 10/18/11 17:10, Matthew Flatt wrote:
 At Tue, 18 Oct 2011 16:32:54 +0200, Marijn wrote:
 the attached program draws a grid in a canvas and paints a few of
 the cells so created. When resizing the window, the grid is also
 dynamically resized together with the coloring of a few painted
 cells. Everything seems to work fine, except that while the
 window is being changed in size the drawing is off and the
 colored cells do not properly correspond to the drawn grid. You
 can see this especially well if you hold down the mouse button
 after resizing. When releasing it the grid lines will change
 position to match up once more with the colorings.
 
 This was due to an internal inconsistency with `get-char-width'
 and `get-char-height'. I've pushed a repair.

Could you perhaps comment on the slowness of the cursor appearing in a
clicked cell? It seems to have something to do with the timer
frequency, because if I decrease the frequency the first time that the
cursor appears is also sooner after clicking in a cell.

Another thing. How do you enable simple select/copy/cut/paste behavior
with standard key-bindings in an editor?

Thanks,

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

iEYEARECAAYFAk6f5wsACgkQp/VmCx0OL2xPLgCgjPdS/Ii9Kdyj4bNKZGLYRcOh
qn0An14oOSrI57/XU/n3tkELHvs4qhg3
=90cJ
-END PGP SIGNATURE-
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev


Re: [racket-dev] while resizing drawing into a canvas is off

2011-10-20 Thread Marijn
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 10/20/11 14:53, Matthew Flatt wrote:
 At Thu, 20 Oct 2011 11:16:59 +0200, Marijn wrote:
 Could you perhaps comment on the slowness of the cursor appearing
 in a clicked cell? It seems to have something to do with the
 timer frequency, because if I decrease the frequency the first
 time that the cursor appears is also sooner after clicking in a
 cell.
 
 I think you need to add `(send grid refresh)' to the admin's 
 `set-focus' method.

It's funny that you mention this `set-focus' method, because I can't
find it in the docs, although my code seems to think it's a canvas%
method (oops?). I hope my confusion isn't contagious. ;P
Calling `refresh' of either the display or the editor in the admin's
on-focus works beautifully though, thanks.

 Calling `on-focus' doesn't make an editor request a refresh, so
 the refresh is currently happening only when the caret is blinked
 (which does cause a refresh request).

That explains it.

 Another thing. How do you enable simple select/copy/cut/paste
 behavior with standard key-bindings in an editor?
 
 Apply `(current-text-keymap-initializer)' to the editor.

I'm kinda struggling with this one. What I came up with is:

(define default-keymap (new keymap%))
((current-text-keymap-initializer) default-keymap)
(add-text-keymap-functions default-keymap)

and then I do (send editor set-keymap default-keymap) for each editor.
Is that what you meant?
This makes some emacs-like bindings work (C-a and C-e go to beginning
and end of line, C-y - yank). Is there a way to get the more familiar
{C-a - select-all, C-v - copy-selection, etc.} bindings?

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

iEYEARECAAYFAk6gRRAACgkQp/VmCx0OL2ybiACfaC+KRtsiWWZKPoGbW7NrD0J6
TOEAnjhJ02SucsrekmvzVTgl2icwGkAM
=+/MB
-END PGP SIGNATURE-
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev


Re: [racket-dev] while resizing drawing into a canvas is off

2011-10-20 Thread Matthew Flatt
At Thu, 20 Oct 2011 17:58:08 +0200, Marijn wrote:
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1
 
 On 10/20/11 14:53, Matthew Flatt wrote:
  At Thu, 20 Oct 2011 11:16:59 +0200, Marijn wrote:
  Could you perhaps comment on the slowness of the cursor appearing
  in a clicked cell? It seems to have something to do with the
  timer frequency, because if I decrease the frequency the first
  time that the cursor appears is also sooner after clicking in a
  cell.
  
  I think you need to add `(send grid refresh)' to the admin's 
  `set-focus' method.
 
 It's funny that you mention this `set-focus' method, because I can't
 find it in the docs, although my code seems to think it's a canvas%
 method (oops?). I hope my confusion isn't contagious. ;P
 Calling `refresh' of either the display or the editor in the admin's
 on-focus works beautifully though, thanks.

Sorry --- I meant the `on-focus' method in your admin class.

  Another thing. How do you enable simple select/copy/cut/paste
  behavior with standard key-bindings in an editor?
  
  Apply `(current-text-keymap-initializer)' to the editor.
 
 I'm kinda struggling with this one. What I came up with is:
 
 (define default-keymap (new keymap%))
 ((current-text-keymap-initializer) default-keymap)
 (add-text-keymap-functions default-keymap)
 
 and then I do (send editor set-keymap default-keymap) for each editor.
 Is that what you meant?

Yes, though I forgot exactly how the parameter value works.

 This makes some emacs-like bindings work (C-a and C-e go to beginning
 and end of line, C-y - yank). Is there a way to get the more familiar
 {C-a - select-all, C-v - copy-selection, etc.} bindings?

Use `add-editor-keymap-functions' in addition to
`add-text-keymap-functions'.

_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev


Re: [racket-dev] while resizing drawing into a canvas is off

2011-10-20 Thread Robby Findler
Generally, the menukey-c, menukey-v, keybindings (and friends)
come about via the menus, not via a keymap% object. And those menus
come in via a frame. I'm not sure how you're using your library, but
you might want to consider some of the mixins in the framework whose
names start with frame:.

Robby

On Thu, Oct 20, 2011 at 11:12 AM, Matthew Flatt mfl...@cs.utah.edu wrote:
 At Thu, 20 Oct 2011 17:58:08 +0200, Marijn wrote:
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1

 On 10/20/11 14:53, Matthew Flatt wrote:
  At Thu, 20 Oct 2011 11:16:59 +0200, Marijn wrote:
  Could you perhaps comment on the slowness of the cursor appearing
  in a clicked cell? It seems to have something to do with the
  timer frequency, because if I decrease the frequency the first
  time that the cursor appears is also sooner after clicking in a
  cell.
 
  I think you need to add `(send grid refresh)' to the admin's
  `set-focus' method.

 It's funny that you mention this `set-focus' method, because I can't
 find it in the docs, although my code seems to think it's a canvas%
 method (oops?). I hope my confusion isn't contagious. ;P
 Calling `refresh' of either the display or the editor in the admin's
 on-focus works beautifully though, thanks.

 Sorry --- I meant the `on-focus' method in your admin class.

  Another thing. How do you enable simple select/copy/cut/paste
  behavior with standard key-bindings in an editor?
 
  Apply `(current-text-keymap-initializer)' to the editor.

 I'm kinda struggling with this one. What I came up with is:

 (define default-keymap (new keymap%))
 ((current-text-keymap-initializer) default-keymap)
 (add-text-keymap-functions default-keymap)

 and then I do (send editor set-keymap default-keymap) for each editor.
 Is that what you meant?

 Yes, though I forgot exactly how the parameter value works.

 This makes some emacs-like bindings work (C-a and C-e go to beginning
 and end of line, C-y - yank). Is there a way to get the more familiar
 {C-a - select-all, C-v - copy-selection, etc.} bindings?

 Use `add-editor-keymap-functions' in addition to
 `add-text-keymap-functions'.

 _
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev


_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev

Re: [racket-dev] while resizing drawing into a canvas is off

2011-10-20 Thread Marijn
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 10/20/11 18:12, Matthew Flatt wrote:
 At Thu, 20 Oct 2011 17:58:08 +0200, Marijn wrote:
 Another thing. How do you enable simple
 select/copy/cut/paste behavior with standard key-bindings in
 an editor?
 
 Apply `(current-text-keymap-initializer)' to the editor.
 
 I'm kinda struggling with this one. What I came up with is:
 
 (define default-keymap (new keymap%)) 
 ((current-text-keymap-initializer) default-keymap) 
 (add-text-keymap-functions default-keymap)

The last line here is actually not needed and doesn't seem to do anything.

 and then I do (send editor set-keymap default-keymap) for each
 editor. Is that what you meant?
 
 Yes, though I forgot exactly how the parameter value works.
 
 This makes some emacs-like bindings work (C-a and C-e go to
 beginning and end of line, C-y - yank). Is there a way to get
 the more familiar {C-a - select-all, C-v - copy-selection,
 etc.} bindings?
 
 Use `add-editor-keymap-functions' in addition to 
 `add-text-keymap-functions'.

Actually I was already trying these, but AFAICT they don't do anything.

Marijn

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

iEYEARECAAYFAk6gS5kACgkQp/VmCx0OL2zM0QCeKhFeH89ymFTA+FzXoz0taFav
fXkAnjGjYenPu9gXbn+vIFFDdfGb3hdd
=sTyd
-END PGP SIGNATURE-
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev


Re: [racket-dev] while resizing drawing into a canvas is off

2011-10-20 Thread Marijn
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi Robby,

On 10/20/11 18:15, Robby Findler wrote:
 Generally, the menukey-c, menukey-v, keybindings (and friends) 
 come about via the menus, not via a keymap% object. And those
 menus come in via a frame. I'm not sure how you're using your
 library, but you might want to consider some of the mixins in the
 framework whose names start with frame:.

I'm actually trying to create something spreadsheet-like. I'm using
editors to manage(display/edit) cell contents. Although each
cell(-editor) individually doesn't have a menu, when used in a
complete application there probably will be menus, and I'm planning to
check out what the framework provides.

However, I don't understand the logic of menus that bring about key
bindings for editors.

Marijn

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

iEYEARECAAYFAk6gTaQACgkQp/VmCx0OL2xPwQCeKkbJVMxYHBiCk3ERSmKockhM
atIAoIhmA0QMroKZATMWI3xRXUWjEBc6
=7eHt
-END PGP SIGNATURE-
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev


Re: [racket-dev] while resizing drawing into a canvas is off

2011-10-20 Thread Robby Findler
On Thu, Oct 20, 2011 at 11:34 AM, Marijn hk...@gentoo.org wrote:
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1

 Hi Robby,

 On 10/20/11 18:15, Robby Findler wrote:
 Generally, the menukey-c, menukey-v, keybindings (and friends)
 come about via the menus, not via a keymap% object. And those
 menus come in via a frame. I'm not sure how you're using your
 library, but you might want to consider some of the mixins in the
 framework whose names start with frame:.

 I'm actually trying to create something spreadsheet-like. I'm using
 editors to manage(display/edit) cell contents. Although each
 cell(-editor) individually doesn't have a menu, when used in a
 complete application there probably will be menus, and I'm planning to
 check out what the framework provides.

 However, I don't understand the logic of menus that bring about key
 bindings for editors.

I'm not sure how to respond here, except to say that that's what the
GUI designers of the world seem to have come up with. The keybindings
that you asked for earlier (control-c and control-v for copy and paste
under windows, for example (command-c and command-v on the mac)) are
there because they are shortcuts for menu items, not because they are
keybindings at the level of the editor.

Robby
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev


Re: [racket-dev] while resizing drawing into a canvas is off

2011-10-19 Thread Marijn
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 10/18/11 17:10, Matthew Flatt wrote:
 At Tue, 18 Oct 2011 16:32:54 +0200, Marijn wrote:
 the attached program draws a grid in a canvas and paints a few of
 the cells so created. When resizing the window, the grid is also
 dynamically resized together with the coloring of a few painted
 cells. Everything seems to work fine, except that while the
 window is being changed in size the drawing is off and the
 colored cells do not properly correspond to the drawn grid. You
 can see this especially well if you hold down the mouse button
 after resizing. When releasing it the grid lines will change
 position to match up once more with the colorings.
 
 This was due to an internal inconsistency with `get-char-width'
 and `get-char-height'. I've pushed a repair.

Thanks for the quick fix.

 Beware that, under Windows, `on-paint' is called before `on-size', 
 which means that the state update in your `on-size' callback
 happens too late. I think it would be nicer if `on-size' reliably
 came before `on-paint' but it's difficult to maintain those kinds
 of guarantees across all platforms. One solution is to add a call
 to `refresh' in your `on-size' callback.

Thanks for the heads-up. I've added the call to refresh and made a
mental note not to assume too much about the order in which call-backs
get called.

Marijn

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

iEYEARECAAYFAk6ehuwACgkQp/VmCx0OL2zejQCgmCP1oh8jFBzbaT7IafLDDshU
7WIAn3FlMLQmzS1YTRkunb5Pr+CA9VhA
=d8Hp
-END PGP SIGNATURE-
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev


[racket-dev] while resizing drawing into a canvas is off

2011-10-18 Thread Marijn
Dear list,

the attached program draws a grid in a canvas and paints a few of the
cells so created. When resizing the window, the grid is also dynamically
resized together with the coloring of a few painted cells. Everything
seems to work fine, except that while the window is being changed in
size the drawing is off and the colored cells do not properly correspond
to the drawn grid. You can see this especially well if you hold down the
mouse button after resizing. When releasing it the grid lines will
change position to match up once more with the colorings.

Marijn
#lang racket/gui

;;; multi-dimensional arrays
(require srfi/25)

(define cell-editor%
  (class text%
(init)
(super-new)
))

(define cell-editor-admin%
  (class editor-admin%
(init-field grid row column editor)

(super-new)

(define blinker
  (new timer% (notify-callback (lambda () (send editor blink-caret)

(define/public (start-caret-blinking interval)
  (send blinker start interval))

(define/public (stop-caret-blinking)
  (send blinker stop))

(define/public (on-char char)
  (send editor on-char char))

(define/public (on-focus on?)
  (if on?
  (send blinker start 500)
  (send blinker stop))
  (send editor on-focus on?))

(define/public (redraw-editor)
  (send editor
refresh
0 0
(send grid get-cell-pixel-width) (send grid get-cell-pixel-height) 
(if (eq? this (send grid get-active-admin))
'show-caret
'no-caret)
#f))

(define/override (get-dc (x #f) (y #f))
  (when x (set-box! x (- -2 (send grid column-x column
  (when y (set-box! y (- -2 (send grid row-y row
  (send grid get-dc) )

(define/override (get-max-view x y w h (full? #f))
  (get-view x y w h full?))

(define/override (get-view x y w h (full? #f))
  (when x (set-box! x 0))
  (when y (set-box! y 0))
  (when w (set-box! w (send grid get-cell-pixel-width)))
  (when h (set-box! h (send grid get-cell-pixel-height))) )

(define/override (grab-caret (domain 'global))
  (when (eq? domain 'global)
(send grid set-focus)))

(define/override (modified modified?)
  (values))

(define/override (needs-update x y w h)
  (send grid refresh))

(define/override (popup-menu menu x y)
  #f)

(define/override (refresh-delayed?)
  #f)

(define/override (resized refresh?)
  (send grid refresh)) ;; only when refresh? arg ?

(define/override (scroll-to x y w h (refresh? #t) (bias 'none))
  (send grid refresh)) ;; necessary ?

(define/override (update-cursor)
  (values))

))

(define grid%
  (class canvas%
(init-field nr-rows nr-columns)
(init parent
 (min-height 0) (min-width 0)
 (stretchable-height #t) (stretchable-width #t))

(define cell-char-width 5)
(define cell-char-height 1)

(super-new (parent parent)
   (min-height min-height) (min-width min-width)
   (stretchable-height stretchable-height) (stretchable-width 
stretchable-width))

(define dc (send this get-dc))

(define char-width-scale 1)
(define char-height-scale 1.3)
(define (char-width) (* (send dc get-char-width) char-width-scale))
(define (char-height) (* (send dc get-char-height) char-height-scale))

(display char-width: ) (displayln (char-width))
(display char-height: ) (displayln (char-height))

(define (cell-pixel-width) (inexact-exact (ceiling (* cell-char-width 
(char-width)
(define (cell-pixel-height) (inexact-exact (ceiling (* cell-char-height 
(char-height)
(define (cell+border-pixel-width) (+ (cell-pixel-width) 1))
(define (cell+border-pixel-height) (+ (cell-pixel-height) 1))

(define/public (get-cell-pixel-width) (cell-pixel-width))
(define/public (get-cell-pixel-height) (cell-pixel-height))

(define (window-height) (+ 1 (* nr-rows (cell+border-pixel-height
(define (window-width) (+ 1 (* nr-columns (cell+border-pixel-width

;(display window-width: ) (displayln window-width)
;(display window-height: ) (displayln window-height)

;;; set window size
(send this min-width (max min-width (window-width)))
(send this min-height (max min-height (window-height)))

(define (x-column x)
  (inexact-exact (floor (/ x (cell+border-pixel-width)
(define (y-row y)
  (inexact-exact (floor (/ y (cell+border-pixel-height)
(define/public (column-x column)
  (* column (cell+border-pixel-width)))
(define/public (row-y row)
  (* row (cell+border-pixel-height)))

(define (paint-cell row column color)
  (send dc set-pen  1 'transparent)
  (send dc set-brush color 'solid)
  (send dc draw-rectangle
(column-x column) (row-y row)

Re: [racket-dev] while resizing drawing into a canvas is off

2011-10-18 Thread Matthew Flatt
At Tue, 18 Oct 2011 16:32:54 +0200, Marijn wrote:
 the attached program draws a grid in a canvas and paints a few of the
 cells so created. When resizing the window, the grid is also dynamically
 resized together with the coloring of a few painted cells. Everything
 seems to work fine, except that while the window is being changed in
 size the drawing is off and the colored cells do not properly correspond
 to the drawn grid. You can see this especially well if you hold down the
 mouse button after resizing. When releasing it the grid lines will
 change position to match up once more with the colorings.

This was due to an internal inconsistency with `get-char-width' and
`get-char-height'. I've pushed a repair.

Beware that, under Windows, `on-paint' is called before `on-size',
which means that the state update in your `on-size' callback happens
too late. I think it would be nicer if `on-size' reliably came before
`on-paint' but it's difficult to maintain those kinds of guarantees
across all platforms. One solution is to add a call to `refresh' in
your `on-size' callback.

_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev