1 ! Copyright (C) 2005, 2006 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 IN: gadgets-presentations
4 USING: arrays definitions gadgets gadgets-borders
5 gadgets-buttons gadgets-labels gadgets-theme
6 generic hashtables tools io kernel prettyprint sequences strings
7 styles words help math models namespaces ;
9 TUPLE: presentation object hook ;
11 : invoke-presentation ( presentation command -- )
12 over dup presentation-hook call
13 >r presentation-object r> invoke-command ;
15 : invoke-primary ( presentation -- )
16 dup presentation-object primary-operation
19 : invoke-secondary ( presentation -- )
20 dup presentation-object secondary-operation
23 : show-mouse-help ( presentation -- )
24 dup presentation-object swap find-world
25 [ world-status set-model ] [ drop ] if* ;
27 : hide-mouse-help ( presentation -- )
28 find-world [ world-status f swap set-model ] when* ;
30 M: presentation ungraft* ( presentation -- )
31 dup hide-mouse-help delegate ungraft* ;
33 C: presentation ( label object -- button )
34 [ drop ] over set-presentation-hook
35 [ set-presentation-object ] keep
36 swap [ invoke-primary ] <roll-button>
37 over set-gadget-delegate ;
39 : (command-button) ( target command -- label quot )
41 [ invoke-command drop ] curry curry ;
43 : <command-button> ( target command -- button )
44 (command-button) <bevel-button> ;
46 : <toolbar> ( target classes -- toolbar )
47 [ commands "toolbar" swap hash ] map concat
48 [ <command-button> ] map-with
51 : <menu-item> ( hook target command -- button )
53 (command-button) [ hand-clicked get find-world hide-glass ]
54 r> 3append <roll-button> ;
56 : <commands-menu> ( hook target commands -- gadget )
57 [ >r 2dup r> <menu-item> ] map 2nip make-filled-pile
61 : operations-menu ( presentation -- )
63 dup presentation-hook curry
64 over presentation-object
65 dup object-operations <commands-menu>
69 { T{ button-down f f 3 } [ operations-menu ] }
70 { T{ mouse-leave } [ dup hide-mouse-help button-update ] }
71 { T{ motion } [ dup show-mouse-help button-update ] }
74 ! Presentation help bar
75 : <presentation-help> ( model -- gadget )
76 [ [ summary ] [ "" ] if* ] <filter> <label-control>
77 dup reverse-video-theme ;