home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / e / EasyGUI_v33b2.lha / Src / EasyGUI / testchange2.e < prev    next >
Text File  |  1997-02-12  |  8KB  |  278 lines

  1. -> testchange2.e - shows use of some changeXXX() functions
  2. MODULE 'tools/exceptions',
  3.        'exec/lists', 'exec/nodes',
  4.        'graphics/text', 'graphics/view',
  5.        'libraries/gadtools',
  6.        'amigalib/lists',
  7.        'tools/easygui'
  8.  
  9. RAISE "SCRN" IF OpenS()=NIL
  10.  
  11. -> Index of the sub-GUI in the main GUI list.
  12. CONST SUB_POS=3
  13.  
  14. -> The custom screen.
  15. DEF scr=NIL
  16.  
  17. -> The main GUI, the list of sub-GUIs, the titles and the menus.
  18. DEF gui:PTR TO LONG, subguis:PTR TO LONG, titles:PTR TO LONG, menus
  19.  
  20. -> The connected window, the main window, a gh for multiforall() and a tmp.
  21. DEF ghconn=NIL, ghmain, forall, tmp
  22.  
  23. -> The slider in the connected and main windows, and the check in main.
  24. DEF connsl=NIL, mainsl=NIL:PTR TO LONG, mainchk=NIL
  25.  
  26. PROC main() HANDLE
  27.   DEF mh=NIL
  28.   -> The list of GUIs we'll use (and change) as sub-GUIs in the main GUI.
  29.   subguis:=[
  30.              [COLS,
  31.                [TEXT,'Try the menus!',NIL,TRUE,1],
  32.                [SLIDE,{ignore},'Colors:',FALSE,1,8,3,5,'']
  33.              ],
  34.              [COLS,
  35.                [SLIDE,{ignore},'Colors:',FALSE,1,8,3,5,''],
  36.                [CHECK,{ignore},'Ignore case',TRUE,FALSE]
  37.              ],
  38.              [COLS,
  39.                [CHECK,{ignore},'Ignore case',TRUE,TRUE],
  40.                [PALETTE,{ignore},'Palette:',3,5,2,0]
  41.              ]
  42.            ]
  43.   -> The main GUI.
  44.   gui:=[ROWS,
  45.          [COLS,
  46.            [SPACEH],
  47.             -> Use generic action function, with BUTTON data 0, 1 or 2.
  48.            [BUTTON,{change_gui},'GUI _X',0,"x"],
  49.            [SPACEH],
  50.            [BUTTON,{change_gui},'GUI _Y',1,"y"],
  51.            [SPACEH],
  52.            [BUTTON,{change_gui},'GUI _Z',2,"z"],
  53.            [SPACEH]
  54.          ],
  55.          [SPACE],
  56.          0, -> The sub-GUI, initialise this below...
  57.          [SPACE],
  58.          [COLS,
  59.            [SBUTTON,{block_all},'_Block All',0,"b"],
  60.            [SBUTTON,{close_all},'_Close All',0,"c"]
  61.          ],
  62.          [BAR],
  63.          mainchk:=[CHECK,{connected_win},'Create/Destroy Connected Window',
  64.                    FALSE,FALSE],
  65.          mainsl:=[SLIDE,{main_sl_fun},'Connected:    ',FALSE,1,20,3,5,'\d[2]']
  66.        ]
  67.   -> Initially, use the first sub-GUI.
  68.   gui[SUB_POS]:=subguis[]
  69.   titles:=['GUI X','GUI Y','GUI Z']
  70.   -> We're going to share the menus between our two windows.
  71.   menus:=[NM_TITLE,0,'Project',      NIL,0,0,0,
  72.            NM_ITEM,0,'Quit',         'Q',0,0,0,
  73.           NM_TITLE,0,'Screen',       NIL,0,0,0,
  74.            NM_ITEM,0,'Default',      'D',0,0,{default},
  75.            NM_ITEM,0,'Custom',       'C',0,0,{custom},
  76.           NM_TITLE,0,'Window Type',  NIL,0,0,0,
  77.            NM_ITEM,0,'No Border',    'N',0,0,{noborder},
  78.            NM_ITEM,0,'Basic',        'B',0,0,{basic},
  79.            NM_ITEM,0,'No Size',      'O',0,0,{nosize},
  80.            NM_ITEM,0,'Size',         'S',0,0,{size},
  81.           NM_TITLE,0,'GUI',          NIL,0,0,0,
  82.            NM_ITEM,0,'X',            'X',0,0,{x},
  83.            NM_ITEM,0,'Y',            'Y',0,0,{y},
  84.            NM_ITEM,0,'Z',            'Z',0,0,{z},
  85.           NM_TITLE,0,'Font',         NIL,0,0,0,
  86.            NM_ITEM,0,'Screen',       'F',0,0,{font},
  87.            NM_ITEM,0,'Topaz',        'T',0,0,{topaz},
  88.           NM_END,  0,NIL,            NIL,0,0,0]:newmenu
  89.   -> Start a multi-window group.
  90.   mh:=multiinit()
  91.   -> Open the main GUI.
  92.   ghmain:=addmultiA(mh, 'Check out the menus...', gui,
  93.                    [EG_MENU,menus, EG_CLOSE,{closemain}, NIL])
  94.   -> Process messages.
  95.   multiloop(mh)
  96. EXCEPT DO
  97.   cleanmulti(mh)
  98.   -> If we opened the screen, close it.
  99.   IF scr THEN CloseS(scr)
  100.   report_exception()
  101. ENDPROC
  102.  
  103.  
  104. ->>> Main GUI/shared action functions <<<-
  105.  
  106. -> Close all windows, prompt then reopen.
  107. PROC close_all(gh) HANDLE
  108.   allclose(gh)
  109.   easyguiA('New GUI',
  110.           [ROWS,
  111.              [TEXT,'Old GUIs closed',NIL,TRUE,15],
  112.              [TEXT,'Close me to reopen!',NIL,TRUE,15]
  113.           ])
  114. EXCEPT DO
  115.   allopen(gh)
  116.   ReThrow()
  117. ENDPROC
  118.  
  119. -> Block all windows, prompt then unblock.
  120. PROC block_all(gh:PTR TO guihandle) HANDLE
  121.   multiforall({forall},gh.mh,`blockwin(forall))
  122.   easyguiA('New GUI',
  123.           [ROWS,
  124.              [TEXT,'Old GUIs blocked',NIL,TRUE,15],
  125.              [TEXT,'Close me to unblock!',NIL,TRUE,15]
  126.           ])
  127. EXCEPT DO
  128.   multiforall({forall},gh.mh,`unblockwin(forall))
  129.   ReThrow()
  130. ENDPROC
  131.  
  132. -> Change the font to default (screen) or Topaz.
  133. PROC font(info) IS change_font(info,NIL)
  134. PROC topaz(info) IS change_font(info,['topaz.font',8,0,0]:textattr)
  135.  
  136. -> Change to the default public screen.
  137. PROC default(gh:PTR TO guihandle) HANDLE
  138.   allclose(gh)
  139.   IF scr
  140.     CloseS(scr)
  141.     -> The screen is now invalid.
  142.     scr:=NIL
  143.   ENDIF
  144.   multiforall({forall},gh.mh,`changescreen(forall,NIL))
  145. EXCEPT DO
  146.   allopen(gh)
  147.   ReThrow()
  148. ENDPROC
  149.  
  150. -> Change to a custom screen.
  151. PROC custom(gh:PTR TO guihandle) HANDLE
  152.   allclose(gh)
  153.   IF scr=NIL THEN scr:=OpenS(640,400,4,V_HIRES OR V_LACE,'Custom Screen')
  154.   tmp:=scr
  155.   multiforall({forall},gh.mh,`changescreen(forall,tmp))
  156. EXCEPT DO
  157.   allopen(gh)
  158.   ReThrow()
  159. ENDPROC
  160.  
  161. -> Change the window type.
  162. PROC noborder(info) IS change_type(info,WTYPE_NOBORDER)
  163. PROC basic(info) IS change_type(info,WTYPE_BASIC)
  164. PROC nosize(info) IS change_type(info,WTYPE_NOSIZE)
  165. PROC size(info) IS change_type(info,WTYPE_SIZE)
  166.  
  167. -> Change the main GUI.
  168. PROC x(info) IS change_gui(0,ghmain)
  169. PROC y(info) IS change_gui(1,ghmain)
  170. PROC z(info) IS change_gui(2,ghmain)
  171.  
  172. PROC change_gui(index,gh)
  173.   changetitle(gh,titles[index])
  174.   gui[SUB_POS]:=subguis[index]
  175.   changegui(gh,gui)
  176. ENDPROC
  177.  
  178. PROC ignore(info,x) IS EMPTY
  179.  
  180.  
  181. ->>> Connection code <<<-
  182.  
  183. -> Connected slider on main GUI.
  184. PROC main_sl_fun(info,cur)
  185.   IF ghconn THEN setslide(ghconn,connsl,cur)
  186. ENDPROC
  187.  
  188. -> Connected slider on the other GUI.
  189. PROC conn_sl_fun(info,cur)
  190.   IF ghmain THEN setslide(ghmain,mainsl,cur)
  191. ENDPROC
  192.  
  193.  
  194. ->>> Closing code <<<-
  195.  
  196. -> Closing the main GUI quits.
  197. PROC closemain(mh,gh) IS quitgui(0)
  198.  
  199. -> Closing the other GUI destroys it.
  200. PROC closeconn(mh,info)
  201.   cleangui(ghconn)
  202.   -> The guihandle is now invalid.
  203.   ghconn:=NIL
  204.   -> Uncheck the check in the main GUI.
  205.   IF mainchk THEN setcheck(ghmain,mainchk,FALSE)
  206. ENDPROC
  207.  
  208.  
  209. ->>> Other GUI functions <<<-
  210.  
  211. -> React to check changes on main GUI.
  212. PROC connected_win(gh:PTR TO guihandle,bool)
  213.   IF bool
  214.     -> If it's been created reopen it, else create and add it to the group.
  215.     IF ghconn
  216.       openwin(ghconn)
  217.     ELSE
  218.       ghconn:=addmultiA(gh.mh, 'Connected Window',
  219.              [ROWS,
  220.                connsl:=[SLIDE,{conn_sl_fun},'Connected:    ',FALSE,1,20,
  221.                         IF mainsl THEN mainsl[SLI_CURR] ELSE 3,10,'\d[2]'],
  222.                [COLS,
  223.                  [SBUTTON,{block_all},'_Block All',0,"b"],
  224.                  [SBUTTON,{close_all},'_Close All',0,"c"]
  225.                ],
  226.                [SBUTTON,{clean_gui},'cl_eangui()',0,"e"]
  227.              ],
  228.              [EG_TOP,0, EG_LEFT,0, EG_MENU,menus,
  229.               EG_SCRN,scr, EG_CLOSE,{closeconn}, NIL])
  230.     ENDIF
  231.   ELSEIF ghconn
  232.     -> If it's been created, destroy it.
  233.     cleangui(ghconn)
  234.     -> The guihandle is now invalid.
  235.     ghconn:=NIL
  236.   ENDIF
  237. ENDPROC
  238.  
  239. -> Action function for cleangui() button (reuse closeconn()).
  240. PROC clean_gui(info) IS closeconn(0,0)
  241.  
  242.  
  243. ->>> Auxiliary functions <<<-
  244.  
  245. -> Close all GUIs (and update check on main GUI)
  246. PROC allclose(gh:PTR TO guihandle)
  247.   multiforall({forall},gh.mh,`closewin(forall))
  248.   -> Make check false only if the other window exists
  249.   IF ghconn THEN setcheck(ghmain,mainchk,FALSE)
  250. ENDPROC
  251.  
  252. -> Open all GUIs (and update check on main GUI)
  253. PROC allopen(gh:PTR TO guihandle)
  254.   multiforall({forall},gh.mh,`openwin(forall))
  255.   -> Make check true only if the other window exists
  256.   IF ghconn THEN setcheck(ghmain,mainchk,TRUE)
  257. ENDPROC
  258.  
  259. -> Change the window type.
  260. PROC change_type(gh:PTR TO guihandle,t) HANDLE
  261.   allclose(gh)
  262.   tmp:=t
  263.   multiforall({forall},gh.mh,`changewintype(forall,tmp))
  264. EXCEPT DO
  265.   allopen(gh)
  266.   ReThrow()
  267. ENDPROC
  268.  
  269. -> Change the window font.
  270. PROC change_font(gh:PTR TO guihandle,tattr) HANDLE
  271.   allclose(gh)
  272.   tmp:=tattr
  273.   multiforall({forall},gh.mh,`changefont(forall,tmp))
  274. EXCEPT DO
  275.   allopen(gh)
  276.   ReThrow()
  277. ENDPROC
  278.