! Copyright (C) 2005, 2006 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. IN: gadgets-listener DEFER: call-listener 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) ; : ( command -- command ) [ hand-clicked get find-world hide-glass ] swap modify-command ; : ( target command -- button ) (command-button) ; : ( target commands -- gadget ) [ ] map-with make-pile 1 over set-pack-fill dup menu-theme ; : hooked-operations ( hook obj -- seq ) object-operations swap modify-commands ; : operations-menu ( presentation -- ) dup dup presentation-hook curry over presentation-object hooked-operations over presentation-object swap 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 ; : ( gadget quot -- button ) [ call-listener drop ] curry ; ! 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 ; : apply-quotation-style ( style gadget -- style gadget ) quotation [ ] apply-style ; : ( style text -- gadget )