]> gitweb.factorcode.org Git - factor.git/blob - basis/ui/gadgets/presentations/presentations.factor
ui.theme: updates to color scheme.
[factor.git] / basis / ui / gadgets / presentations / presentations.factor
1 ! Copyright (C) 2005, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel memoize namespaces ui.commands ui.gadgets
4 ui.gadgets.borders ui.gadgets.buttons ui.gadgets.buttons.private
5 ui.gadgets.glass ui.gadgets.menus ui.gadgets.status-bar
6 ui.gadgets.worlds ui.gestures ui.operations ui.pens.solid ui.theme ;
7 IN: ui.gadgets.presentations
8
9 TUPLE: presentation < button object hook ;
10
11 TUPLE: presentation-menu < border presentation ;
12
13 : invoke-presentation ( presentation command -- )
14     [ [ dup hook>> call( presentation -- ) ] [ object>> ] bi ] dip
15     invoke-command ;
16
17 : invoke-primary ( presentation -- )
18     dup object>> primary-operation
19     invoke-presentation ;
20
21 : invoke-secondary ( presentation -- )
22     dup object>> secondary-operation
23     invoke-presentation ;
24
25 : show-mouse-help ( presentation -- )
26     [ [ object>> ] keep show-summary ] [ button-update ] bi ;
27
28 : <presentation> ( label object -- button )
29     [ [ invoke-primary ] presentation new-button ] dip
30         >>object
31         [ drop ] >>hook
32         roll-button-theme ;
33
34 M: presentation ungraft*
35     dup hand-gadget get-global child? [ dup hide-status ] when
36     call-next-method ;
37
38 MEMO: selected-pen-boundary ( -- button-pen )
39     roll-button-rollover-border <solid> dup dup f f <button-pen> ;
40
41 <PRIVATE
42 : setup-presentation ( presentation -- presentation )
43     selected-pen-boundary >>boundary ;
44 PRIVATE>
45
46 : <presentation-menu> ( presentation target hook -- menu )
47     <operations-menu> presentation-menu new-border
48         swap >>presentation
49         { 0 0 } >>size ;
50
51 : show-presentation-menu ( presentation -- )
52     setup-presentation dup
53     [ ] [ object>> ] [ dup hook>> curry ] tri
54     <presentation-menu> show-menu ;
55
56 M: presentation-menu hide-glass-hook
57     presentation>> button-pen-boundary >>boundary drop ;
58
59 presentation H{
60     { T{ button-down f f 3 } [ show-presentation-menu ] }
61     { mouse-leave [ [ hide-status ] [ button-update ] bi ] }
62     { mouse-enter [ show-mouse-help ] }
63     ! Responding to motion too allows nested presentations to
64     ! display status help properly, when the mouse leaves a
65     ! nested presentation and is still inside the parent, the
66     ! parent doesn't receive a mouse-enter
67     { motion [ show-mouse-help ] }
68 } set-gestures