! 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-outliner gadgets-panes gadgets-paragraphs gadgets-theme generic hashtables tools io kernel prettyprint sequences strings styles words help math models namespaces ; ! Clickable objects 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 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 ( gadget 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 ) [ [ presentation-object summary ] [ "" ] if* ] dup reverse-video-theme ; ! Character styles : apply-style ( style gadget key quot -- style gadget ) >r pick hash r> when* ; inline : apply-foreground-style ( style gadget -- style gadget ) foreground [ over set-label-color ] apply-style ; : apply-background-style ( style gadget -- style gadget ) background [ over set-gadget-interior ] apply-style ; : specified-font ( style -- font ) [ font swap hash [ "monospace" ] unless* ] keep [ font-style swap hash [ plain ] unless* ] keep font-size swap hash [ 12 ] unless* 3array ; : apply-font-style ( style gadget -- style gadget ) over specified-font over set-label-font ; : apply-presentation-style ( style gadget -- style gadget ) presented [ ] apply-style ; : ( style text -- gadget )