58
|
1 |
HorizontalPanelView subclass:#ButtonPanel
|
|
2 |
instanceVariableNames:'receiver argumentToSelector'
|
|
3 |
classVariableNames:''
|
|
4 |
poolDictionaries:''
|
|
5 |
privateIn:UIPainter
|
|
6 |
!
|
|
7 |
|
|
8 |
!UIPainter::ButtonPanel methodsFor:'accessing'!
|
|
9 |
|
|
10 |
receiver
|
|
11 |
^ receiver
|
|
12 |
!
|
|
13 |
|
|
14 |
receiver:aReceiver
|
|
15 |
receiver := aReceiver
|
|
16 |
! !
|
|
17 |
|
|
18 |
!UIPainter::ButtonPanel methodsFor:'initialization'!
|
|
19 |
|
|
20 |
initialize
|
|
21 |
"initialize and setup buttons
|
|
22 |
"
|
|
23 |
super initialize.
|
|
24 |
|
|
25 |
self level:-1.
|
|
26 |
self borderWidth:0.
|
|
27 |
self horizontalLayout:#leftSpace.
|
|
28 |
argumentToSelector := 1.
|
|
29 |
|
|
30 |
self specification do:[:anArray|
|
|
31 |
|selector image button seperator|
|
|
32 |
|
|
33 |
selector := anArray at:1.
|
|
34 |
|
|
35 |
selector notNil ifTrue:[
|
|
36 |
image := Image fromFile:( anArray at:2 ).
|
|
37 |
button := Button label:image in:self.
|
|
38 |
|
|
39 |
selector last == $: ifFalse:[
|
|
40 |
button action:[
|
|
41 |
receiver notNil ifTrue:[
|
|
42 |
receiver perform:selector
|
|
43 |
]
|
|
44 |
]
|
|
45 |
] ifTrue:[
|
|
46 |
button pressAction:[
|
|
47 |
receiver notNil ifTrue:[
|
|
48 |
receiver perform:selector with:argumentToSelector
|
|
49 |
]
|
|
50 |
].
|
|
51 |
button autoRepeat:true.
|
|
52 |
button menuHolder:self; menuMessage:#editMenu; menuPerformer:self.
|
|
53 |
]
|
|
54 |
] ifFalse:[
|
|
55 |
seperator := View in:self.
|
|
56 |
seperator extent:20@1.
|
|
57 |
seperator borderWidth:0.
|
|
58 |
]
|
|
59 |
].
|
|
60 |
|
|
61 |
!
|
|
62 |
|
|
63 |
specification
|
|
64 |
"return a spec for the buttons in the panel;
|
|
65 |
entries consists of selector and bitmap-filename.
|
|
66 |
nil selectors are taken as separators (see setupButtonPanel)"
|
|
67 |
|
|
68 |
^ #(
|
|
69 |
#( alignSelectionLeft 'b_alignL.xbm' )
|
|
70 |
#( alignSelectionRight 'b_alignR.xbm' )
|
|
71 |
#( alignSelectionLeftAndRight 'b_alignLR.xbm' )
|
|
72 |
#( nil )
|
|
73 |
#( alignSelectionTop 'b_alignT.xbm' )
|
|
74 |
#( alignSelectionBottom 'b_alignB.xbm' )
|
|
75 |
#( alignSelectionTopAndBottom 'b_alignTB.xbm' )
|
|
76 |
#( nil )
|
|
77 |
#( alignSelectionCenterHor 'b_alignCH.xbm' )
|
|
78 |
#( alignSelectionCenterVer 'b_alignCV.xbm' )
|
|
79 |
#( nil )
|
|
80 |
#( moveSelectionLeft: 'b_moveLeft.xbm' )
|
|
81 |
#( moveSelectionRight: 'b_moveRight.xbm' )
|
|
82 |
#( moveSelectionUp: 'b_moveUp.xbm' )
|
|
83 |
#( moveSelectionDown: 'b_moveDown.xbm' )
|
|
84 |
)
|
|
85 |
|
|
86 |
|
|
87 |
! !
|
|
88 |
|
|
89 |
!UIPainter::ButtonPanel methodsFor:'menu'!
|
|
90 |
|
|
91 |
editMenu
|
|
92 |
"edit menu used by buttons using an argument for the receiver; the argumentToSelector
|
|
93 |
"
|
|
94 |
|menu|
|
|
95 |
|
|
96 |
menu := PopUpMenu labels:#( '1' '2' '4' '10' '20' '..' )
|
|
97 |
args:#( 1 2 4 10 20 nil ).
|
|
98 |
|
|
99 |
menu action:[:anArg||no|
|
|
100 |
(no := anArg) isNil ifTrue:[
|
|
101 |
no := EnterBox request:'number'.
|
|
102 |
no := SmallInteger readFrom:no onError:0.
|
|
103 |
].
|
|
104 |
no ~~ 0 ifTrue:[
|
|
105 |
|index view|
|
|
106 |
|
|
107 |
view := (WindowGroup lastEventQuerySignal raise) view.
|
|
108 |
view := view menuPerformer.
|
|
109 |
argumentToSelector := no.
|
|
110 |
view pressAction value.
|
|
111 |
argumentToSelector := 1.
|
|
112 |
]
|
|
113 |
].
|
|
114 |
^ menu
|
|
115 |
! !
|
|
116 |
|