home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 113 / EnigmaAmiga113CD.iso / software / sviluppo / easygui_os12 / examples / easygui / testchange_os12_2.e < prev    next >
Encoding:
Text File  |  2000-06-05  |  8.0 KB  |  291 lines

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