home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / gui / muibuilder21.lha / MUIBuilder / MB / E / DemoGenCodeE30b / DemoGenCodeE.e < prev    next >
Encoding:
Text File  |  1994-10-14  |  5.1 KB  |  179 lines

  1. OPT OSVERSION = 37
  2.  
  3.  
  4. ->*****
  5. ->** External modules
  6. ->*****
  7. MODULE 'locale'
  8. MODULE 'muimaster' , 'libraries/mui'
  9. MODULE 'utility/tagitem' , 'utility/hooks'
  10. MODULE 'tools/boopsi' , 'tools/installhook'
  11. MODULE 'icon'
  12.  
  13. MODULE '*GUI'
  14.  
  15.  
  16. ->*****
  17. ->** Global variables
  18. ->*****
  19. DEF dgce    :    PTR TO app_obj            -> look at GUI.em for "app_obj" object
  20. DEF string_var    :    PTR TO CHAR            -> used by a notification (see GUI.em, lines 49 and 155)
  21.  
  22.  
  23. /*******************
  24. ** Main procedure **
  25. *******************/
  26. PROC main() HANDLE
  27.  
  28.     DEF running = TRUE , result_domethod , signal
  29.     DEF arexx : app_arexx , display : app_display
  30.     DEF change_text_hook : hook , arexx_commands : PTR TO mui_command
  31.     DEF icon = NIL
  32.  
  33.         -> needed libraries and icon init
  34.     IF ( muimasterbase := OpenLibrary( 'muimaster.library' , MUIMASTER_VMIN ) ) = NIL THEN Throw( "LIB" , "muim" )
  35.     IF ( iconbase := OpenLibrary( 'icon.library' , 0 ) ) THEN icon := GetDiskObject( 'PROGDIR:DemoGenCodeE' ) ELSE Throw( "LIB" , "icon" )
  36.  
  37.         -> exported variables init
  38.     string_var := 'String variable put !'
  39.  
  40.         -> MUI GUI init
  41.             -> in GUI.em line 22, you can see the declaration of "app_display" object
  42.             -> each field of this object correspond to a hook function declared in MUIBuilder
  43.             -> in the present case, there is only the "button_pressed" hook function (see GUI.em line 167)
  44.     installhook( display.button_pressed , {button_pressed} )
  45.  
  46.         -> ARexx init
  47.             -> for ARexx init you must fill an "app_arexx" object defined in GUI.em line 17
  48.             -> this object gets 2 fields : one for the commands and one for the arexx error hook function
  49.     installhook( change_text_hook , {change_text} )
  50.     arexx.commands := NEW arexx_commands[ 2 ]
  51.     arexx.commands[].mc_name := 'change_text'
  52.     arexx.commands[].mc_template := ''
  53.     arexx.commands[].mc_parameters := 0
  54.     arexx.commands[].mc_hook := change_text_hook
  55.     installhook( arexx.error , {arexx_error} )
  56.  
  57.         -> MUI application creation
  58.             -> for this you call the create method (see GUI.em line 57) on the "app_obj" object
  59.             -> to this method, you must give the "app_display" object
  60.             -> and if you want (not obliged), you can give an icon, the "app_arexx" object and a menu object (obsolete)
  61.     IF NEW dgce.create( display , icon , arexx ) = NIL THEN Throw( "MUI" , Mui_Error() )
  62.     dgce.init_notifications( display )
  63.  
  64.         -> Main loop
  65.     WHILE running
  66.  
  67.         result_domethod := domethod( dgce.app , [ MUIM_Application_Input , {signal} ] )
  68.         SELECT result_domethod
  69.  
  70.             CASE ID_BUTTON_PRESSED    -> see GUI.em line 42 for the definition of this ID
  71.  
  72.                 SetAttrsA( dgce.tx_result ,[Eval(`( MUIA_Text_Contents )), 'Modifed by ID returned !' ,TAG_DONE])
  73.  
  74.             CASE MUIV_Application_ReturnID_Quit
  75.  
  76.                 running := FALSE
  77.  
  78.         ENDSELECT
  79.  
  80.         IF ( signal AND running ) THEN Wait( signal )
  81.  
  82.     ENDWHILE
  83.  
  84. EXCEPT DO
  85.  
  86.     SELECT exception
  87.  
  88.         CASE "LIB"
  89.  
  90.             SELECT exceptioninfo
  91.  
  92.                 CASE "muim"
  93.  
  94.                     error_simple( 'Can''t open muimaster.library !' )
  95.  
  96.                 CASE "icon"
  97.  
  98.                     error_simple( 'Can''t open icon.library !' )
  99.  
  100.             ENDSELECT
  101.  
  102.         CASE "MEM"
  103.  
  104.             error( 'Not enough memory !' )
  105.  
  106.         CASE "MUI"
  107.  
  108.             SELECT exceptioninfo
  109.  
  110.                 CASE MUIE_OutOfMemory
  111.  
  112.                     error_simple( 'Not enough memory !' )
  113.  
  114.                 CASE MUIE_OutOfGfxMemory
  115.  
  116.                     error_simple( 'Not enough chip memory !' )
  117.  
  118.                 CASE MUIE_MissingLibrary
  119.  
  120.                     error_simple( 'Can''t open a needed library !' )
  121.  
  122.                 CASE MUIE_NoARexx
  123.  
  124.                     error_simple( 'Can''t create arexx port !' )
  125.  
  126.                 DEFAULT
  127.  
  128.                     error_simple( 'Internal problem !' )
  129.  
  130.             ENDSELECT
  131.  
  132.     ENDSELECT
  133.  
  134.     IF dgce            THEN dgce.dispose()
  135.     IF icon            THEN FreeDiskObject( icon )
  136.     IF iconbase        THEN CloseLibrary( iconbase )
  137.     IF muimasterbase    THEN CloseLibrary( muimasterbase )
  138.  
  139. ENDPROC
  140.  
  141.  
  142. /********************************************************
  143. ** Prints an error message with an intuition requester **
  144. ********************************************************/
  145. PROC error_simple( message : PTR TO CHAR ) IS EasyRequestArgs(    NIL , [ 20 , 0 ,
  146.                                     'DemoGenCodeE error !' ,
  147.                                     message ,
  148.                                     '_OK' ] , NIL , NIL )
  149.  
  150.  
  151. /**************************************************
  152. ** Prints an error message with an MUI requester **
  153. **************************************************/
  154. PROC error( message : PTR TO CHAR ) IS Mui_RequestA(    dgce.app ,
  155.                             dgce.wi_the_window ,
  156.                             NIL ,
  157.                             'DemoGenCodeE error !' ,
  158.                             '*_OK' ,
  159.                             message ,
  160.                             NIL )
  161.  
  162.  
  163. /******************************************************************
  164. ** Hook function called each time bt_call_hook button is pressed **
  165. ******************************************************************/
  166. PROC button_pressed( hook , obj , msg ) IS SetAttrsA( dgce.tx_result ,[Eval(`( MUIA_Text_Contents )), 'Modified by called hook function !' ,TAG_DONE])
  167.  
  168.  
  169. /******************************************************
  170. ** Hook function called by ARexx command change_text **
  171. ******************************************************/
  172. PROC change_text( hook , obj , msg ) IS SetAttrsA( dgce.tx_result ,[Eval(`( MUIA_Text_Contents )), 'Modifed by ARexx command change_text !' ,TAG_DONE])
  173.  
  174.  
  175. /******************************************************
  176. ** Hook function called by ARexx command change_text **
  177. ******************************************************/
  178. PROC arexx_error( hook , obj , msg ) IS error_simple( 'Unknown ARexx command recieved !' )
  179.