! Copyright (C) 2005, 2006 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. IN: gadgets-presentations USING: arrays definitions gadgets gadgets-borders gadgets-buttons gadgets-labels gadgets-theme generic hashtables tools io kernel prettyprint sequences strings styles words help math models namespaces ; TUPLE: presentation object hook ; : invoke-presentation ( presentation command -- ) over dup presentation-hook call >r presentation-object r> invoke-command ; : invoke-primary ( presentation -- ) dup presentation-object primary-operation invoke-presentation ; : invoke-secondary ( presentation -- ) dup presentation-object secondary-operation invoke-presentation ; : show-mouse-help ( presentation -- ) dup presentation-object swap find-world [ world-status set-model ] [ drop ] if* ; : hide-mouse-help ( presentation -- ) find-world [ world-status f swap set-model ] when* ; M: presentation ungraft* ( presentation -- ) dup hide-mouse-help delegate ungraft* ; C: presentation ( label object -- button ) [ drop ] over set-presentation-hook [ set-presentation-object ] keep swap [ invoke-primary ] over set-gadget-delegate ; : (command-button) ( target command -- label quot ) dup command-name -rot [ invoke-command drop ] curry curry ; : ( target command -- button ) (command-button) ; : ( target classes -- toolbar ) [ commands "toolbar" swap hash ] map concat [ ] map-with make-shelf ; : ( hook target command -- button ) rot >r (command-button) [ hand-clicked get find-world hide-glass ] r> 3append ; : ( hook target commands -- gadget ) [ >r 2dup r> ] map 2nip make-filled-pile dup menu-theme ; : operations-menu ( presentation -- ) dup dup presentation-hook curry over presentation-object dup object-operations swap show-menu ; presentation H{ { T{ button-down f f 3 } [ operations-menu ] } { T{ mouse-leave } [ dup hide-mouse-help button-update ] } { T{ motion } [ dup show-mouse-help button-update ] } } set-gestures ! Presentation help bar : ( model -- gadget ) [ [ summary ] [ "" ] if* ] dup reverse-video-theme ;