graft/ungraft protocol replaces broken add/remove-notifyy

darcs
slava 2006-06-29 08:07:10 +00:00
parent 5f26260396
commit ee3acaabc1
5 changed files with 31 additions and 18 deletions

View File

@ -37,7 +37,8 @@ M: array rect-dim drop { 0 0 } ;
TUPLE: gadget TUPLE: gadget
pref-dim parent children orientation pref-dim parent children orientation
visible? relayout? root? clipped? interior boundary ; visible? relayout? root? clipped? grafted?
interior boundary ;
M: gadget = eq? ; M: gadget = eq? ;

View File

@ -11,10 +11,10 @@ C: control ( model gadget quot -- gadget )
[ set-control-model ] keep [ set-control-model ] keep
dup model-changed ; dup model-changed ;
M: control add-notify* M: control graft*
dup control-model add-connection ; dup control-model add-connection ;
M: control remove-notify* M: control ungraft*
dup control-model remove-connection ; dup control-model remove-connection ;
M: control model-changed ( gadget -- ) M: control model-changed ( gadget -- )

View File

@ -112,7 +112,9 @@ M: pane stream-flush ( pane -- ) drop ;
M: pane stream-readln ( pane -- line ) M: pane stream-readln ( pane -- line )
[ over set-pane-continuation stop ] callcc1 nip ; [ over set-pane-continuation stop ] callcc1 nip ;
: scroll-pane ( pane -- ) pane-active [ scroll>gadget ] when* ; : scroll-pane ( pane -- )
#! Only input panes scroll.
dup pane-input [ dup pane-active scroll>gadget ] when drop ;
M: pane stream-terpri ( pane -- ) M: pane stream-terpri ( pane -- )
dup pane-current prepare-print dup pane-current prepare-print

View File

@ -4,22 +4,28 @@ IN: gadgets
USING: generic hashtables kernel math namespaces sequences USING: generic hashtables kernel math namespaces sequences
vectors words ; vectors words ;
GENERIC: add-notify* ( gadget -- ) GENERIC: graft* ( gadget -- )
M: gadget add-notify* drop ; M: gadget graft* drop ;
: add-notify ( gadget -- ) : graft ( gadget -- )
dup [ add-notify ] each-child add-notify* ; t over set-gadget-grafted?
dup graft*
dup [ graft ] each-child ;
GENERIC: remove-notify* ( gadget -- ) GENERIC: ungraft* ( gadget -- )
M: gadget remove-notify* drop ; M: gadget ungraft* drop ;
: remove-notify ( gadget -- ) : ungraft ( gadget -- )
dup [ remove-notify* ] each-child remove-notify* ; dup gadget-grafted? [
dup [ ungraft* ] each-child
dup ungraft*
f over set-gadget-grafted?
] when drop ;
: (unparent) ( gadget -- ) : (unparent) ( gadget -- )
dup remove-notify dup ungraft
dup forget-pref-dim f swap set-gadget-parent ; dup forget-pref-dim f swap set-gadget-parent ;
: unparent ( gadget -- ) : unparent ( gadget -- )
@ -38,11 +44,14 @@ M: gadget remove-notify* drop ;
: clear-gadget ( gadget -- ) : clear-gadget ( gadget -- )
dup (clear-gadget) relayout ; dup (clear-gadget) relayout ;
: ((add-gadget)) ( gadget box -- )
[ gadget-children ?push ] keep set-gadget-children ;
: (add-gadget) ( gadget box -- ) : (add-gadget) ( gadget box -- )
over unparent over unparent
dup pick set-gadget-parent dup pick set-gadget-parent
[ gadget-children ?push ] 2keep swapd set-gadget-children [ ((add-gadget)) ] 2keep
add-notify ; gadget-grafted? [ graft ] [ drop ] if ;
: add-gadget ( gadget parent -- ) : add-gadget ( gadget parent -- )
#! Add a gadget to a parent gadget. #! Add a gadget to a parent gadget.

View File

@ -96,7 +96,7 @@ C: titled-gadget ( gadget title -- )
] if* ; inline ] if* ; inline
: start-world ( world -- ) : start-world ( world -- )
dup add-notify dup graft
dup gadget-title over set-title dup gadget-title over set-title
dup relayout dup relayout
world-gadget request-focus ; world-gadget request-focus ;
@ -112,12 +112,13 @@ C: titled-gadget ( gadget title -- )
focused-ancestors f focus-gestures ; focused-ancestors f focus-gestures ;
: unfocus-world ( world -- ) : unfocus-world ( world -- )
f over set-world-focused?
#! Sent when native window loses focus. #! Sent when native window loses focus.
f over set-world-focused?
focused-ancestors f swap focus-gestures ; focused-ancestors f swap focus-gestures ;
: reset-world ( world -- ) : reset-world ( world -- )
dup unfocus-world dup unfocus-world
dup ungraft
f over set-world-focus f over set-world-focus
f over set-world-handle f over set-world-handle
world-fonts clear-hash ; world-fonts clear-hash ;
@ -126,7 +127,7 @@ C: titled-gadget ( gadget title -- )
dup hand-clicked close-global dup hand-clicked close-global
dup hand-gadget close-global dup hand-gadget close-global
f over request-focus* f over request-focus*
dup remove-notify dup ungraft
dup free-fonts dup free-fonts
reset-world ; reset-world ;