0
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1989-93 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
ModalBox subclass:#InfoBox
|
|
14 |
instanceVariableNames:'formLabel textLabel okButton okAction'
|
|
15 |
classVariableNames:'InfoBitmap'
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Views-Interactors'
|
|
18 |
!
|
|
19 |
|
|
20 |
InfoBox comment:'
|
|
21 |
|
|
22 |
COPYRIGHT (c) 1989-93 by Claus Gittinger
|
|
23 |
All Rights Reserved
|
|
24 |
|
|
25 |
this class implements a pop-up box to show an information message
|
|
26 |
|
|
27 |
%W% %E%
|
|
28 |
written Spring/Summer 89 by claus
|
|
29 |
'!
|
|
30 |
|
|
31 |
!InfoBox class methodsFor:'instance creation'!
|
|
32 |
|
|
33 |
title:titleString
|
|
34 |
"create a new infoBox with title, aTitleString"
|
|
35 |
|
|
36 |
^ (self new) title:titleString
|
|
37 |
! !
|
|
38 |
|
|
39 |
!InfoBox methodsFor:'initialization'!
|
|
40 |
|
|
41 |
initialize
|
|
42 |
super initialize.
|
|
43 |
|
|
44 |
InfoBitmap isNil ifTrue:[
|
|
45 |
InfoBitmap := Form fromFile:'Information.xbm' resolution:100 on:device
|
|
46 |
].
|
|
47 |
|
|
48 |
formLabel := Label in:self.
|
|
49 |
self initFormBitmap.
|
|
50 |
formLabel borderWidth:0.
|
|
51 |
formLabel origin:(ViewSpacing @ ViewSpacing).
|
|
52 |
|
|
53 |
textLabel := Label label:'Information' in:self.
|
|
54 |
textLabel borderWidth:0.
|
|
55 |
textLabel origin:((ViewSpacing + formLabel width + ViewSpacing) @ ViewSpacing).
|
|
56 |
|
|
57 |
okButton := Button label:(Resources at:'ok')
|
|
58 |
action:[
|
|
59 |
okButton turnOffWithoutRedraw.
|
|
60 |
self okPressed
|
|
61 |
]
|
|
62 |
in:self.
|
|
63 |
|
|
64 |
"okButton isReturnButton:true."
|
|
65 |
okButton origin:[(width // 4) @ (height - ViewSpacing - okButton height)]
|
|
66 |
extent:[(width // 2) @ okButton height]
|
|
67 |
!
|
|
68 |
|
|
69 |
initFormBitmap
|
|
70 |
formLabel form:InfoBitmap
|
|
71 |
! !
|
|
72 |
|
|
73 |
!InfoBox methodsFor:'realization'!
|
|
74 |
|
|
75 |
show
|
|
76 |
"added bell to wake up user"
|
|
77 |
|
|
78 |
device beep.
|
|
79 |
super show
|
|
80 |
!
|
|
81 |
|
|
82 |
showAtPointer
|
|
83 |
"redefined to show the box with the cursor in the ok-box"
|
|
84 |
|
|
85 |
self fixSize.
|
|
86 |
self showAt:(device pointerPosition
|
|
87 |
- (okButton originRelativeTo:self)
|
|
88 |
- ((okButton width // 2) @ (okButton height // 2)) )
|
|
89 |
|
|
90 |
! !
|
|
91 |
|
|
92 |
!InfoBox methodsFor:'accessing'!
|
|
93 |
|
|
94 |
form:aForm
|
|
95 |
"define a form to be displayed left of the title
|
|
96 |
- usually an exclamation-mark"
|
|
97 |
|
|
98 |
formLabel form:aForm.
|
|
99 |
formLabel resize.
|
|
100 |
self resize
|
|
101 |
!
|
|
102 |
|
|
103 |
title:aString
|
|
104 |
"set the title"
|
|
105 |
|
|
106 |
textLabel label:aString.
|
|
107 |
textLabel resize.
|
|
108 |
self resize
|
|
109 |
!
|
|
110 |
|
|
111 |
title
|
|
112 |
"return the title"
|
|
113 |
|
|
114 |
^ textLabel label
|
|
115 |
!
|
|
116 |
|
|
117 |
okAction:aBlock
|
|
118 |
"define the action to be performed when ok is pressed"
|
|
119 |
|
|
120 |
okAction := aBlock
|
|
121 |
!
|
|
122 |
|
|
123 |
okText:aString
|
|
124 |
"define the text in the ok-button"
|
|
125 |
|
|
126 |
okButton label:aString.
|
|
127 |
self resize
|
|
128 |
! !
|
|
129 |
|
|
130 |
!InfoBox methodsFor:'private'!
|
|
131 |
|
|
132 |
resize
|
|
133 |
"resize myself to make everything fit into myself"
|
|
134 |
|
|
135 |
|w h extra|
|
|
136 |
|
|
137 |
w := ViewSpacing + formLabel width + ViewSpacing + textLabel width + ViewSpacing.
|
|
138 |
h := ViewSpacing
|
|
139 |
+ ((formLabel height) max:(textLabel height))
|
|
140 |
+ ViewSpacing + ViewSpacing
|
|
141 |
+ okButton height
|
|
142 |
+ ViewSpacing.
|
|
143 |
|
|
144 |
extra := margin * 2.
|
|
145 |
super extent:(w + extra) @ (h + extra)
|
|
146 |
! !
|
|
147 |
|
|
148 |
!InfoBox methodsFor:'user interaction'!
|
|
149 |
|
|
150 |
hideAndEvaluate:aBlock
|
|
151 |
"make myself invisible and evaluate aBlock"
|
|
152 |
|
|
153 |
self hide.
|
|
154 |
aBlock notNil ifTrue:[aBlock value]
|
|
155 |
!
|
|
156 |
|
|
157 |
okPressed
|
|
158 |
"user pressed ok-button; make myself invisible and if an action was
|
|
159 |
specified do it"
|
|
160 |
|
|
161 |
self hideAndEvaluate:okAction
|
|
162 |
!
|
|
163 |
|
|
164 |
keyPress:aKey x:x y:y
|
|
165 |
"return-key dublicates ok-function"
|
|
166 |
|
|
167 |
(aKey == #Return) ifTrue:[self okPressed]
|
|
168 |
! !
|