-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMSGBOX.CBL
More file actions
298 lines (298 loc) · 13.8 KB
/
MSGBOX.CBL
File metadata and controls
298 lines (298 loc) · 13.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
*>--------------------------------------------------------------------------------------------------------------<*
*>-> Message display using OO
*>--------------------------------------------------------------------------------------------------------------<*
class-id. msgbox.
environment division.
configuration section.
special-names.
decimal-point is comma.
*>--------------------------------------------------------------------------------------------------------------<*
*>-> Import another necessary classes
repository.
class ICobolVar as "com.iscobol.types.CobolVar"
class JBoolean as "boolean"
class MessageBox as "MSGBOX"
.
*>--------------------------------------------------------------------------------------------------------------<*
*>-> STATIC AREA
*>--------------------------------------------------------------------------------------------------------------<*
id division. factory.
working-storage section.
*>--------------------------------------------------------------------------------------------------------------<*
*>-> Constants found on "isgui.def"
*>--------------------------------------------------------------------------------------------------------------<*
*>-> Buttons
78 mb-ok value 1.
78 mb-yes-no value 2.
78 mb-ok-cancel value 3.
78 mb-yes-no-cancel value 4.
*>-> Return code
78 mb-yes value 1.
78 mb-no value 2.
78 mb-cancel value 3.
*>-> Icons
78 mb-default-icon value 1.
78 mb-warning-icon value 2.
78 mb-error-icon value 3.
procedure division.
*>--------------------------------------------------------------------------------------------------------------<*
*>/**
*> Displays a standard information message using provided text
*>
*> @param inText Text to display
*>*/
id division. method-id. show as "show".
linkage section.
77 inText object reference ICobolVar.
procedure division using inText.
show.
MessageBox:>new(inText):>show.
end method.
end factory.
*>--------------------------------------------------------------------------------------------------------------<*
*>-> OBJECT AREA
*>--------------------------------------------------------------------------------------------------------------<*
id division. object.
working-storage section.
*>-> Self reference to this object
77 selfInstance object reference MessageBox.
*>-> Message text
77 w-text pic x any length value spaces.
*>-> Message title
77 w-title pic x any length value spaces.
*>-> Icon
77 w-icon pic 9(01) value mb-default-icon comp-x.
88 w-icon-default value mb-default-icon.
88 w-icon-warning value mb-warning-icon.
88 w-icon-error value mb-error-icon.
*>-> Buttons
77 w-buttons pic 9(01) value mb-ok comp-x.
88 w-buttons-ok value mb-ok.
88 w-buttons-yesno value mb-yes-no.
88 w-buttons-okcancel value mb-ok-cancel.
88 w-buttons-yesnocancel value mb-yes-no-cancel.
77 w-default-button pic 9(01) value mb-yes comp-x.
88 w-default-button-yes value mb-yes.
88 w-default-button-no value mb-no.
*>-> Return
77 w-return pic 9(01) value zeros comp-x.
88 w-return-yes value mb-yes.
88 w-return-no value mb-no.
88 w-return-cancel value mb-cancel.
*>-> Text substitutions table
01 w-subst-tab.
05 w-subst-occ occurs dynamic
capacity in w-subst-size initialized.
10 w-subst pic x any length value spaces.
*>--------------------------------------------------------------------------------------------------------------<*
procedure division.
*>--------------------------------------------------------------------------------------------------------------<*
*>/**
*> Object constructor
*>
*> @param inText Text to display
*>*/
id division. method-id. new_met as "new".
linkage section.
77 inText object reference ICobolVar.
procedure division using inText.
move inText to w-text.
*>-> Saves a referente to this own object, allowing return it on each method for "Builder Pattern"
set selfInstance to self.
end method.
*>--------------------------------------------------------------------------------------------------------------<*
*>/**
*> Adds a substition text element to be applied on message text
*>
*> @param inText Text to be replaced on message place holders
*>*/
id division. method-id. addSub as "addSub".
linkage section.
77 inText object reference ICobolVar.
procedure division using inText returning selfInstance.
move $trim(inText) to w-subst(w-subst-size + 1).
end method.
*>--------------------------------------------------------------------------------------------------------------<*
*>/**
*> Defines a custom title
*>
*> @param inTitle Message title text
*>*/
id division. method-id. withTitle as "withTitle".
linkage section.
77 inTitle object reference ICobolVar.
procedure division using inTitle returning selfInstance.
move inTitle to w-title.
end method.
*>--------------------------------------------------------------------------------------------------------------<*
*>/**
*> Allows "Yes" and "No" buttons
*> After "show", use methods "actionYes" or "actionNo" to test which button was pressed
*>
*>*/
id division. method-id. buttonsYesNo as "buttonsYesNo".
procedure division returning selfInstance.
set w-buttons-yesno to true.
end method.
*>--------------------------------------------------------------------------------------------------------------<*
*>/**
*> Allows "OK" and "Cancel" buttons
*> After "show", use methods "actionOk" or "actionCancel" to test which button was pressed
*>
*>*/
id division. method-id. buttonsOkCancel as "buttonsOkCancel".
procedure division returning selfInstance.
set w-buttons-okcancel to true.
end method.
*>--------------------------------------------------------------------------------------------------------------<*
*>/**
*> Allows "Yes", "No" and "Cancel" buttons
*> After "show", use methods "actionYes", "actionNo" or "actionCancel" to test which button was pressed
*>
*>*/
id division. method-id. buttonsYesNoCancel as "buttonsYesNoCancel".
procedure division returning selfInstance.
set w-buttons-okcancel to true.
end method.
*>--------------------------------------------------------------------------------------------------------------<*
*>/**
*> Makes button "No" focused by default
*>
*>*/
id division. method-id. defaultButtonNo as "defaultButtonNo".
procedure division returning selfInstance.
set w-default-button-no to true.
end method.
*>--------------------------------------------------------------------------------------------------------------<*
*>/**
*> Defines icon as "Error"
*>
*>*/
id division. method-id. withErrorIcon as "withErrorIcon".
procedure division returning selfInstance.
set w-icon-error to true.
end method.
*>--------------------------------------------------------------------------------------------------------------<*
*>/**
*> Defines icon as "Warning"
*>
*>*/
id division. method-id. withWarningIcon as "withWarningIcon".
procedure division returning selfInstance.
set w-icon-warning to true.
end method.
*>--------------------------------------------------------------------------------------------------------------<*
*>/**
*> Display message
*>
*>*/
id division. method-id. show as "show".
working-storage section.
77 table-i pic is 9(04) value is zeros comp-x.
77 mask-i pic is zzzz9 value is zeros.
77 place-holder pic x any length value is spaces.
procedure division returning selfInstance.
if w-title = spaces
perform load-default-title,
end-if.
if w-subst-size > 0
perform apply-substitutions-on-text,
end-if.
display message w-text
title w-title
type w-buttons
default w-default-button
icon w-icon
centered
returning w-return.
exit method.
load-default-title.
evaluate true,
when w-icon-default
if w-buttons-yesno or w-buttons-yesnocancel
move "Question message" to w-title,
else,
move "Information" to w-title,
end-if,
when w-icon-warning
move "Warning message" to w-title,
when w-icon-error
move "Error message" to w-title,
end-evaluate.
apply-substitutions-on-text.
perform
varying table-i from w-subst-size by -1
until table-i = 0
move spaces to place-holder,
move table-i to mask-i,
string "%", $trim(mask-i)
into place-holder,
call "C$REPLACE_ALL" using w-text, place-holder, w-subst(table-i),
end-perform.
end method.
*>--------------------------------------------------------------------------------------------------------------<*
*>/**
*> Return true if button "Yes" was selected
*>
*> @return boolean
*>*/
id division. method-id. actionYes as "actionYes".
working-storage section.
77 outReturn object reference JBoolean.
procedure division returning outReturn.
if w-return-yes
set outReturn to true,
else,
set outReturn to false,
end-if.
end method.
*>--------------------------------------------------------------------------------------------------------------<*
*>/**
*> Return true if button "No" was selected
*>
*> @return boolean
*>*/
id division. method-id. actionNo as "actionNo".
working-storage section.
77 outReturn object reference JBoolean.
procedure division returning outReturn.
if w-return-no
set outReturn to true,
else,
set outReturn to false,
end-if.
end method.
*>--------------------------------------------------------------------------------------------------------------<*
*>/**
*> Return true if button "Cancel" was selected
*>
*> @return boolean
*>*/
id division. method-id. actionCancel as "actionCancel".
working-storage section.
77 outReturn object reference JBoolean.
procedure division returning outReturn.
if w-return-cancel
set outReturn to true,
else,
set outReturn to false,
end-if.
end method.
*>--------------------------------------------------------------------------------------------------------------<*
*>/**
*> Return true if button "Ok" was selected
*>
*> @return boolean
*>*/
id division. method-id. actionOk as "actionOk".
working-storage section.
77 outReturn object reference JBoolean.
procedure division returning outReturn.
if w-buttons-ok or (w-buttons-okcancel and not w-return-cancel)
set outReturn to true,
else,
set outReturn to false,
end-if.
end method.
end object.
*>--------------------------------------------------------------------------------------------------------------<*