Example: System Widget As a Child
|
10 ! *********************************************************************
20 ! Example: SYSTEM Widget As a Child
30 !
40 ! This program shows the user of the SYSTEM widget as a child
50 ! widget. The program displays a PANEL widget, puts a PRINTER
60 ! widget on it, and then creates a SYSTEM widget containing an
70 ! array of buttons. When you click a button, the event is listed
80 ! in the PRINTER widget.
90 !
100 ! **************************************************************
110 !
120 CLEAR SCREEN
130 INTEGER D(1:4),Dw,Dh,Nlines ! Display handling variables
140 INTEGER Px,Py,Pw,Ph ! Main PANEL parameters
150 INTEGER Gx,Gy ! Internal spacing
160 INTEGER Nr,Nc,R,C,Bx,By,Bw,Bh ! PUSHBUTTON variables
170 INTEGER Prx,Pry,Prw,Prh ! PRINTER parameters
180 DIM Ev$(1:2)[50],S$[50] ! Returns event source - GP string
190 !
200 ! Set up a PANEL in the center of the printing display (above the
210 ! display (above the softkeys, etc.) and put a SYSTEM MENU on it
220 ! so you can quit the program.
230 !
240 STATUS CRT,13;Nlines
250 GESCAPE CRT,3;D(*)
260 Dw=D(3)-D(1)
270 Dh=(D(4)-D(2))*((Nlines-7)/Nlines)
280 !
290 Pw=Dw*.9
300 Ph=Dh*.9
310 Px=(Dw-Pw)/2
320 Py=(Dh-Ph)/2
330 !
340 ASSIGN @Main TO WIDGET "PANEL";SET ("VISIBLE":0)
350 CONTROL @Main;SET ("X":Px,"Y":Py,"WIDTH":Pw,"HEIGHT":Ph)
360 CONTROL @Main;SET ("SYSTEM MENU":"Quit")
370 CONTROL @Main;SET ("MAXIMIZABLE":0,"RESIZABLE":0)
380 CONTROL @Main;SET ("TITLE":" Example: SYSTEM Widget As a Child")
390 STATUS @Main;RETURN ("INSIDE WIDTH":Iw,"INSIDE HEIGHT":Ih)
400 !
410 ! Create a SYSTEM widget as a child of the main PANEL and
420 ! populate with PUSHBUTTONS.
430 !
440 ASSIGN @Sys TO WIDGET "SYSTEM";PARENT @Main
450 !
460 Gx=Iw*.02
470 Gy=Gx
480 !
490 Nr=9
500 Nc=6
510 Bh=(Ih-2*Gy)/Nr
520 Bw=Iw*.08
530 !
540 FOR R=1 TO Nr
550 By=Gy+(R-1)*Bh
560 FOR C=1 TO Nc
570 Bx=Gx+(C-1)*Bw
580 S$="B"&VAL$(R)&VAL$(C)
590 CONTROL @Sys;SET ("*NAME":S$,"*CREATE":"PUSHBUTTON")
600 CONTROL @Sys;SET ("X":Bx,"Y":By,"WIDTH":Bw,"HEIGHT":Bh)
610 CONTROL @Sys;SET ("LABEL":S$)
620 NEXT C
630 NEXT R
640 !
650 ! Set up a PRINTER widget on the main PANEL (not as part of
660 ! the SYSTEM widget) to log events.
670 !
680 Prw=Iw-(Nc*Bw+3*Gx)
690 Prh=Ih-2*Gy
700 Prx=Iw-(Prw+Gy)
710 Pry=Gy
720 ASSIGN @Prn TO WIDGET "PRINTER";PARENT @Main
730 CONTROL @Prn;SET ("X":Prx,"Y":Pry,"WIDTH":Prw,"HEIGHT":Prh)
740 !
750 ! Set up an event to trap the PUSHBUTTONs in the SYSTEM widget.
760 !
770 ON EVENT @Sys,"ACTIVATED" GOSUB Handler
780 !
790 ! Set event to quit on SYSTEM MENU, make whole thing visible,
800 ! loop and wait for an event.
810 !
820 ON EVENT @Main,"SYSTEM MENU" GOTO Finis
830 CONTROL @Main;SET ("VISIBLE":1)
840 !
850 LOOP
860 WAIT FOR EVENT
870 END LOOP
880 STOP
890 !
900 ! This event handler confirms PUSHBUTTON events by printing out
910 ! the event and its source.
920 !
930 Handler: !
940 STATUS @Sys;RETURN ("*QUEUED EVENT":Ev$(*))
950 S$="Name/Event: "&Ev$(1)&"/"&Ev$(2)
960 CONTROL @Prn;SET ("APPEND TEXT":S$)
970 RETURN
980 !
990 Finis: !
1000 ASSIGN @Main TO * ! Delete PANEL widget
1010 CLEAR SCREEN
1020 END