home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / gui / muibuilder21.lha / MUIBuilder / MB / E / Localized_DemoGenCodeE30b / DemoGenCodeE.e < prev    next >
Encoding:
Text File  |  1994-10-14  |  5.6 KB  |  188 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. MODULE '*Locale'
  15.  
  16.  
  17. ->*****
  18. ->** Global variables
  19. ->*****
  20. DEF dgce    :    PTR TO app_obj            -> look at GUI.em for "app_obj" object
  21. DEF cat        :    PTR TO catalog_DemoGenCodeE    -> look at Locale.e for "catalog_DemoGenCodeE" object
  22. DEF string_var    :    PTR TO CHAR            -> used by a notification (see GUI.em, lines 49 and 155)
  23.  
  24.  
  25. /*******************
  26. ** Main procedure **
  27. *******************/
  28. PROC main() HANDLE
  29.  
  30.     DEF running = TRUE , result_domethod , signal
  31.     DEF arexx : app_arexx , display : app_display
  32.     DEF change_text_hook : hook , arexx_commands : PTR TO mui_command
  33.     DEF icon = NIL
  34.  
  35.         -> localization init
  36.     localebase := OpenLibrary( 'locale.library' , 0 )
  37.     NEW cat.create()    -> see Locale.e
  38.     cat.open( NIL , NIL )    -> see Locale.e
  39.  
  40.         -> needed libraries and icon init
  41.     IF ( muimasterbase := OpenLibrary( 'muimaster.library' , MUIMASTER_VMIN ) ) = NIL THEN Throw( "LIB" , "muim" )
  42.     IF ( iconbase := OpenLibrary( 'icon.library' , 0 ) ) THEN icon := GetDiskObject( 'PROGDIR:DemoGenCodeE' ) ELSE Throw( "LIB" , "icon" )
  43.  
  44.         -> exported variables init
  45.     string_var := cat.msg_String_Variable_Put.getstr()
  46.  
  47.         -> MUI GUI init
  48.             -> in GUI.em line 22, you can see the declaration of "app_display" object
  49.             -> each field of this object correspond to a hook function declared in MUIBuilder
  50.             -> in the present case, there is only the "button_pressed" hook function (see GUI.em line 167)
  51.     installhook( display.button_pressed , {button_pressed} )
  52.  
  53.         -> ARexx init
  54.             -> for ARexx init you must fill an "app_arexx" object defined in GUI.em line 17
  55.             -> this object gets 2 fields : one for the commands and one for the arexx error hook function
  56.     installhook( change_text_hook , {change_text} )
  57.     arexx.commands := NEW arexx_commands[ 2 ]
  58.     arexx.commands[].mc_name := 'change_text'
  59.     arexx.commands[].mc_template := ''
  60.     arexx.commands[].mc_parameters := 0
  61.     arexx.commands[].mc_hook := change_text_hook
  62.     installhook( arexx.error , {arexx_error} )
  63.  
  64.         -> MUI application creation
  65.             -> for this you call the create method (see GUI.em line 57) on the "app_obj" object
  66.             -> to this method, you must give the "app_display" object
  67.             -> and if you want (not obliged), you can give an icon, the "app_arexx" object and a menu object (obsolete)
  68.     IF NEW dgce.create( display , icon , arexx ) = NIL THEN Throw( "MUI" , Mui_Error() )
  69.     dgce.init_notifications( display )
  70.  
  71.         -> Main loop
  72.     WHILE running
  73.  
  74.         result_domethod := domethod( dgce.app , [ MUIM_Application_Input , {signal} ] )
  75.         SELECT result_domethod
  76.  
  77.             CASE ID_BUTTON_PRESSED    -> see GUI.em line 42 for the definition of this ID
  78.  
  79.                 SetAttrsA( dgce.tx_result ,[Eval(`( MUIA_Text_Contents )), cat.msg_Modified_ID_Returned.getstr() ,TAG_DONE])
  80.  
  81.             CASE MUIV_Application_ReturnID_Quit
  82.  
  83.                 running := FALSE
  84.  
  85.         ENDSELECT
  86.  
  87.         IF ( signal AND running ) THEN Wait( signal )
  88.  
  89.     ENDWHILE
  90.  
  91. EXCEPT DO
  92.  
  93.     SELECT exception
  94.  
  95.         CASE "LIB"
  96.  
  97.             SELECT exceptioninfo
  98.  
  99.                 CASE "muim"
  100.  
  101.                     error_simple( cat.msg_Missing_Muimaster_Library.getstr() )
  102.  
  103.                 CASE "icon"
  104.  
  105.                     error_simple( cat.msg_Missing_Icon_Library.getstr() )
  106.  
  107.             ENDSELECT
  108.  
  109.         CASE "MEM"
  110.  
  111.             error( cat.msg_Not_Enough_Memory.getstr() )
  112.  
  113.         CASE "MUI"
  114.  
  115.             SELECT exceptioninfo
  116.  
  117.                 CASE MUIE_OutOfMemory
  118.  
  119.                     error_simple( cat.msg_Not_Enough_Memory.getstr() )
  120.  
  121.                 CASE MUIE_OutOfGfxMemory
  122.  
  123.                     error_simple( cat.msg_Not_Enough_Chip_Memory.getstr() )
  124.  
  125.                 CASE MUIE_MissingLibrary
  126.  
  127.                     error_simple( cat.msg_Missing_Library.getstr() )
  128.  
  129.                 CASE MUIE_NoARexx
  130.  
  131.                     error_simple( cat.msg_Arexx_Port.getstr() )
  132.  
  133.                 DEFAULT
  134.  
  135.                     error_simple( cat.msg_Internal_Problem.getstr() )
  136.  
  137.             ENDSELECT
  138.  
  139.     ENDSELECT
  140.  
  141.     IF dgce            THEN dgce.dispose()
  142.     IF icon            THEN FreeDiskObject( icon )
  143.     IF iconbase        THEN CloseLibrary( iconbase )
  144.     IF muimasterbase    THEN CloseLibrary( muimasterbase )
  145.     cat.close()
  146.     IF localebase        THEN CloseLibrary( localebase )
  147.  
  148. ENDPROC
  149.  
  150.  
  151. /********************************************************
  152. ** Prints an error message with an intuition requester **
  153. ********************************************************/
  154. PROC error_simple( message : PTR TO CHAR ) IS EasyRequestArgs(    NIL , [ 20 , 0 ,
  155.                                     cat.msg_DGCE_Error.getstr() ,
  156.                                     message ,
  157.                                     cat.msg_Simple_OK.getstr() ] , NIL , NIL )
  158.  
  159.  
  160. /**************************************************
  161. ** Prints an error message with an MUI requester **
  162. **************************************************/
  163. PROC error( message : PTR TO CHAR ) IS Mui_RequestA(    dgce.app ,
  164.                             dgce.wi_the_window ,
  165.                             NIL ,
  166.                             cat.msg_DGCE_Error.getstr() ,
  167.                             cat.msg_OK.getstr() ,
  168.                             message ,
  169.                             NIL )
  170.  
  171.  
  172. /******************************************************************
  173. ** Hook function called each time bt_call_hook button is pressed **
  174. ******************************************************************/
  175. PROC button_pressed( hook , obj , msg ) IS SetAttrsA( dgce.tx_result ,[Eval(`( MUIA_Text_Contents )), cat.msg_Modified_By_Hook.getstr() ,TAG_DONE])
  176.  
  177.  
  178. /******************************************************
  179. ** Hook function called by ARexx command change_text **
  180. ******************************************************/
  181. PROC change_text( hook , obj , msg ) IS SetAttrsA( dgce.tx_result ,[Eval(`( MUIA_Text_Contents )), cat.msg_Modified_By_Arexx.getstr() ,TAG_DONE])
  182.  
  183.  
  184. /******************************************************
  185. ** Hook function called by ARexx command change_text **
  186. ******************************************************/
  187. PROC arexx_error( hook , obj , msg ) IS error_simple( cat.msg_Unknown_ARexx_Command.getstr() )
  188.