! 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-grids 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 command ; C: presentation ( button object command -- button ) [ set-presentation-command ] keep [ set-presentation-object ] keep [ set-gadget-delegate ] keep ; : ( gadget object -- button ) >r f r> f ; : ( target command -- button ) dup command-name f -rot ; : ( target commands -- gadget ) [ hand-clicked get find-world hide-glass ] modify-operations [ ] map-with make-pile 1 over set-pack-fill ; : operations-menu ( presentation -- gadget ) dup presentation-command [ drop ] [ dup presentation-object dup object-operations swap show-menu ] if ; : invoke-presentation ( presentation -- ) dup presentation-object swap presentation-command [ dup default-operation ] unless* invoke-command ; : 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* ; presentation H{ { T{ button-up } [ [ invoke-presentation ] if-clicked ] } { T{ button-down f f 3 } [ [ operations-menu ] if-clicked ] } { T{ mouse-leave } [ dup hide-mouse-help button-update ] } { T{ mouse-enter } [ 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 ] 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 )