home *** CD-ROM | disk | FTP | other *** search
- /*
- *
- * Title : Lesson 2
- * System : New Risc-OS library. */
- #define Version "1.0"
- /* Copyright : (c) John Winters
- * Date : 31st May, 1993
- * Author : John H. Winters
- *
- * Function : Lesson 2 of the Spirit library tutorial.
- *
- * Note that this example uses literal strings within the
- * code. I wouldn't do this in a real application, but
- * I think it makes the working clearer in this case.
- *
- *
- * Modification history.
- *
- * Version :
- * Date :
- * Author :
- * Changes :
- *
- */
-
- #include <stdlib.h>
- #include "winapp.h"
-
- /*
- *==========================================================================
- *
- * Hash defines.
- *
- *==========================================================================
- */
-
- #define MENU_INFO 0 /* Menu entry for information */
- #define MENU_QUIT 1 /* Menu entry to quit */
- #define TFN_VERSION 4 /* Field number for version string */
-
- /*
- *==========================================================================
- *
- * Local data.
- *
- *==========================================================================
- */
-
- /*
- * Handle on the dialogue box which we use to give process information.
- */
- static t_dbox InfoDbox ;
- /*
- * String to place in our information dialogue box.
- */
- static char VersionString [] = Version " (31st May, 1993)" ;
-
- /*
- *==========================================================================
- *
- * Externally visible data.
- *
- *==========================================================================
- */
-
- /*
- * This data item gives the name of the directory to look in when loading
- * resources. It will make the library code look for an environment
- * variable <Lesson2$Dir> which points to the correct directory.
- */
- const char WA_resource_dir [] = "Lesson2" ;
- /*
- * This data item defines the task name.
- */
- const char WA_task_name [] = "Lesson 2" ;
-
- /*
- *==========================================================================
- *
- * Forward declarations.
- *
- *==========================================================================
- */
-
- static void MenuHandler (
- void *reference,
- const int *hit) ;
-
- /*
- *==========================================================================
- *
- * Externally visible routines.
- *
- *==========================================================================
- */
-
- unsigned int WA_BeginProcessing (void)
-
- /*
- * Function :
- * This routine is called after we have succesfully
- * called WIMP_Initialise and are ready to go ahead.
- *
- * Parameters :
- * None.
- *
- * Returns :
- * TRUE if we are happy to go on, FALSE otherwise.
- *
- */
-
- {
- t_menu_block *MainMenu ;
-
- /*
- * Create a menu to attach to our icon. The syntax for the menu
- * string is as for Acorn's product.
- */
- MainMenu = WA_BuildMenu (WA_resource_dir,
- ">Info, Quit") ;
- if (MainMenu == NULL)
- {
- LOG_Error ("Failed to create a menu.\n") ;
- }
- else
- {
- /*
- * Now create a dialogue box from the template we loaded
- * earlier. It's a non-persistent one (FALSE), and
- * doesn't require a handler or reference (NULL, NULL).
- */
- InfoDbox = WA_CreateDbox ("ProgInfo", FALSE, NULL, NULL) ;
- if (InfoDbox == NULL)
- {
- LOG_Error ("Can't create information dbox.\n") ;
- }
- else
- {
- /*
- * Inject our current version number into the dialogue
- * box.
- */
- WA_SetDboxField (InfoDbox,
- TFN_VERSION,
- VersionString) ;
- /*
- * Now pop our icon on the bar, and attach a menu to it.
- * If an error occurs it will be reported for us.
- */
- return ((WA_IconToBar ("!lesson2", TRUE)) &&
- (WA_AttachMenu (ICON_BAR,
- MainMenu,
- MenuHandler,
- NULL))) ;
- }
- }
- return (FALSE) ;
- }
-
-
- unsigned int WA_LoadResources (void)
-
- /*
- * Function :
- * This is our opportunity to load whatever resources
- * we require before WIMP_Initialise is called.
- *
- * Parameters :
- * None.
- *
- * Returns :
- * TRUE if we are happy to go on, FALSE otherwise.
- *
- */
-
- {
- t_LOG_HandlerMask mask ;
-
- /*
- * Arrange for any messages to appear in a pop-up box. A more
- * sophisticated application would probably arrange its own
- * message handling, but this easy method is provided for noddy
- * code.
- */
- mask.value = 0 ;
- mask.b.LHM_Debug = TRUE ;
- mask.b.LHM_Info = TRUE ;
- mask.b.LHM_Warning = TRUE ;
- mask.b.LHM_Error = TRUE ;
- mask.b.LHM_SevereError = TRUE ;
- WA_SetPopupErrors (mask) ;
- /*
- * Now we need a sprite to put on the icon bar, and a template
- * for our information box. Note that we are here loading our sprite
- * from the !Sprites file in our application directory. If we were
- * using more than one sprite, we would probably use a separate
- * sprite file.
- */
- return ((WA_LoadSprites ("!Sprites")) &&
- (WA_LoadTemplate ("Templates", "ProgInfo"))) ;
- }
-
- /*
- *==========================================================================
- *
- * Local routines.
- *
- *==========================================================================
- */
-
- static void MenuHandler (
- void *reference,
- const int *hit)
-
- /*
- * Function :
- * Menu event handler.
- *
- * Parameters :
- * reference Ignored.
- * hit Indication of the menu hit.
- *
- * Returns :
- * None.
- *
- */
-
- {
- reference = reference ;
- /*
- * See which menu entry has been chosen.
- */
- switch (hit [0])
- {
- case MENU_INFO :
- WA_DisplayDbox (InfoDbox) ;
- break ;
-
- case MENU_QUIT :
- /*
- * This call causes our application to exit in an
- * orderly manner.
- */
- WA_WindUp () ;
- break ;
-
- }
- }
-