summaryrefslogtreecommitdiffstats
path: root/src/menu.inc
blob: 7426cb4ee80951ffef735c5ff98a58d1772b96c3 (plain)
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
%
% Main menu (boot entry + boot options + panel).
%
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

% max number of boot option input fields
/boot.ed.max 2 def

% boot option input line separator
/boot.splitchar 1 def
/boot.splitstr 1 string dup 0 boot.splitchar put def

% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Create new main window.
%
% ( ) ==> ( window )
%
/window.main {
  widget.size array
  dup .type t_main put
  dup .font font.normal put
  dup .ed.font font.normal put
  dup .color.fg boot.text.normal put
  
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Initialize main window.
%
% ( window ) ==> ( )
%
/main.init {
  pop
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Redraw main window.
% (E.g. after selecting a new language.)
%
% ( window ) ==> ( )
%
/main.redraw {

  % boot.drawlabels

  main.drawmenu
  /keepbootoptions 1 def
  menu.entry true MenuSelect
  /keepbootoptions .undef def

  panel.show
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Draw boot option input field labels.
%
% ( ) == > ( )
%
/boot.drawlabels {
  boot.show not { return } if

  boot.text.options setcolor
  window.current .font get setfont
  boot.ed.list {
    dup .inp_x get 10 sub over .inp_y get moveto
    currentpoint
    currentpoint 0 exch moveto
    currentpoint rot 1 add fontheight image
    moveto
    dup .inp_show get {
      .inp_label get exec showright
    } { pop } ifelse
  } forall
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Setup boot option input field.
%
% ( ) == > ( )
%
/boot.input.setup {
  % HACK: we do not need to do this function if not boot.show,
  % and since we have some ugly overlap of bootoptions on the panel
  % we really do not want to do it if not really useful
  boot.show not { return } if

  boot.ed.list {
    dup .inp_x get over .inp_y get boot.ed.height add moveto

    currentpoint boot.ed.width 2 image

    currentcolor
    currenttransparency

    white setcolor
    0xe0 settransparency

    2 index .inp_show get {
      boot.ed.width 2 fillrect
    } if

    settransparency
    setcolor

    pop

  } forall
} def


/boot.input.preinit {

  boot.ed.list { dup .inp_show false put .inp_buf get 0 0 put } forall

  menu.args menu.entry get boot.splitchar split

    0 1 boot.ed.list length 1 sub {
      over over aget dup .undef ne {
        boot.ed.list rot get dup .inp_show true put .inp_buf get exch strcpy pop
      } {
        pop pop exit
      } ifelse
    } for

  free

  config.nobootoptions menu.texts menu.entry get iselement {
    boot.ed.list 0 get .inp_show false put
  } if

  boot.ed.list { splitcmdline } forall

} def

% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Activate boot option input field.
%
% ( ) == > ( )
%
/bootoptions.init {
  window.current .color.fg get setcolor
  window.current .ed.font get setfont

  boot.ed.list boot.window .ed.focus get get edit.hidecursor

  boot.window .ed.focus 0 put

  boot.show {
    boot.ed.list {
      dup .inp_show get {
        dup
        dup dup .inp_buf get exch over edit.init
        "" ne { ' ' edit.input } { pop } ifelse
        edit.hidecursor
      } {
        edit.done
      } ifelse
    } forall
    boot.ed.list boot.window .ed.focus get get dup .inp_show get {
      edit.showcursor
      % HACK: there is some ugly overlap of bootoptions on the panel
      % so force to redraw the panel after displaying bootoptions
      panel.show
    } { pop } ifelse

    boot.ed.list {
      dup .inp_show get .inp_visible exch put
    } forall

  } if
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Redraw boot option input field.
%
% ( ) == > ( )
%
/bootoptions.redraw {

  % clear old options

  boot.text.options setcolor
  window.current .font get setfont
  boot.ed.list {
    dup .inp_x get 10 sub over .inp_y get moveto
    currentpoint
    currentpoint 0 exch moveto
    currentpoint rot 1 add fontheight image
    moveto
    dup .inp_show get {
      .inp_label get exec showright
    } { pop } ifelse
  } forall

  boot.drawlabels
  boot.input.setup

} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Draw boot menu.
%
% No entry is marked as selected.
%
% ( ) == > ( )
%
/main.drawmenu {
  menu.text.normal setcolor

  /x menu.start.x def
  /y menu.start.y def

  /menu.bar.width.old menu.bar.width def

  /menu.bar.width
    menu.bar.min.width
    menu.texts { menuitemmap strsize pop menu.text.xofs 2 mul add 2 add max } forall
  def

  0 1 menu.visible.entries 1 sub {
   x y moveto currentpoint menu.bar.width.old menu.bar.height image
   x config.rtl { menu.bar.width menu.text.xofs sub } { menu.text.xofs } ifelse add
   y menu.text.yofs add moveto
   menu.texts exch menu.shift add get menuitemmap
   currentfont exch font.large setfont show.rtl setfont
   /y y menu.item.height add def
  } for

} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Select/deselect menu entry.
%
% If an entry is selected (status = true), the boot options input field is
% initialized.
%
% ( entry status ) ==> ( )
%
% status:
%  false	not selected
%  true		selected
%
% Note: menu.bar.width must be valid even if status = false.
%
/MenuSelect {
  /menu.status exch def

  /menu.idx over def

  menu.shift sub
  menu.item.height mul menu.start.y add
  menu.start.x exch
  moveto

  currentpoint
  menu.status {
    menu.bar.color setcolor
    currenttransparency
    menu.bar.transparency settransparency
    menu.bar.width menu.bar.height
    fillrect
    settransparency
  } {
    currentpoint menu.bar.width menu.bar.height image
  } ifelse
  moveto

  config.rtl { menu.bar.width menu.text.xofs sub } { menu.text.xofs } ifelse
  menu.text.yofs rmoveto
  menu.status {
    menu.text.select
  } {
    menu.text.normal
  } ifelse
  setcolor
  menu.texts menu.idx get menuitemmap
  menu.status { config.talk { dup speak } if } if
  currentfont exch font.large setfont show.rtl setfont

  menu.status {
    % init boot options
    keepbootoptions .undef eq {

      boot.input.preinit

      false
        boot.ed.list {
          dup .inp_show get exch .inp_visible get xor or
        } forall
      {
        boot.input.setup
        boot.drawlabels
      } if

      bootoptions.init
    } {
      bootoptions.redraw
    } ifelse

    % set help context
    "main" help.setcontext
    menu.texts menu.idx get
    dup help.findpage "" eq {
      pop
    } {
      help.setcontext
    } ifelse
  } if

} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Draw main window.
%
% ( window ) ==> ( )
%
/main.show {
  window.push

  /menu.shift 0 def
  /menu.visible.entries menu.texts length menu.max.entries min def

  % get index of default entry
  /menu.entry 0 def
  0 1 menu.texts length 1 sub {
    dup menu.texts exch get menu.dentry eq { /menu.entry exch def exit } { pop } ifelse
  } for

  menu.entry menu.visible.entries sub 0 ge {
    /menu.shift menu.entry menu.texts length menu.visible.entries sub min def
  } if

  boot.text.options setcolor

  window.current .font get setfont

  /boot.ed.width screen.size pop boot.pos.x boot.pos.y pop sub 20 sub def
  /boot.ed.height fontheight 2 add def

  /boot.window window.current def

  /boot.ed.list [
    0 1 boot.ed.max 1 sub {
      [
        boot.pos.x boot.pos.y exch 10 add exch 1 sub 4 -1 roll boot.ed.height 5 add mul add
        over over moveto boot.ed.width boot.ed.height savescreen
        cmdlinelength string
        cmdlinelength
        .undef
        cmdlinelength string
        "More Options"
        false
        false
      ]
    } for
  ] def

  boot.ed.list 0 get .inp_label /txt_bootoptions put

  boot.window .ed.list boot.ed.list put
  boot.window .ed.focus 0 put

  main.drawmenu

  boot.drawlabels

  menu.entry true MenuSelect

  % find default splash mode
  % 0 1 splash.options length 1 sub {
  %   splash.options over get menu.args menu.entry get exch strstr {
  %     /splash.default exch def
  %   } {
  %     pop
  %   } ifelse
  % } for

  panel.init

  "main" help.setcontext

} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Split command line into hidden and normal part.
%
% ( edit_object ) == > ( )
%
/splitcmdline {
  dup length .inp_hidden le { pop return } if
  dup .inp_hidden get .undef eq { pop return } if

  dup .inp_hidden get over .inp_buf get strcpy pop

  dup .inp_hidden get "showopts" bootopt.find dup {
    dup "showopts" length add skipspaces
    2 index .inp_buf get exch strcpy dropspaces
    0 0 put
    .inp_hidden get dropspaces
  } {
    pop dup .inp_hidden get 0 0 put
    .inp_buf get dropspaces
  } ifelse
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Handle keyboard input.
%
% ( key_in ) ==> ( key_out )
%
/main.input {
  dup 0 eq { return } if 

  % handle panel entries
  panel.input

  dup keyF10 eq {
    power_off
    pop 0
  } if

  dup keyEsc eq { exit_popup pop 0 } if

  dup keyEnter eq {
    /window.action actStart def
    pop 0
  } if

  dup keyUp eq {
    menu.entry 0 gt {
      menu.entry false MenuSelect
      menu.entry menu.shift eq {
        /menu.shift menu.shift 1 sub def main.drawmenu
      } if
      /menu.entry menu.entry 1 sub def
      menu.entry true MenuSelect
    } if
    pop 0
  } if

  dup keyDown eq {
    menu.entry menu.texts length 1 sub lt {
      menu.entry false MenuSelect
      menu.visible.entries menu.entry menu.shift sub sub 1 eq {
        /menu.shift menu.shift 1 add def main.drawmenu
      } if
      /menu.entry menu.entry 1 add def
      menu.entry true MenuSelect
    } if
    pop 0
  } if

  dup keyPgUp eq {
    menu.entry 0 gt {
      menu.entry false MenuSelect
      /menu.entry 0 def
      menu.shift 0 ne {
        /menu.shift 0 def main.drawmenu
      } if
      menu.entry true MenuSelect
    } if
    pop 0
  } if

  dup keyPgDown eq {
    menu.entry menu.texts length 1 sub lt {
      menu.entry false MenuSelect
      /menu.entry menu.texts length 1 sub def
      menu.texts length menu.visible.entries sub dup menu.shift ne {
        /menu.shift exch def main.drawmenu
      } {
        pop
      } ifelse
      menu.entry true MenuSelect
    } if
    pop 0
  } if

  dup 0 ne {
    "opt" help.setcontext
  } if

} def