home *** CD-ROM | disk | FTP | other *** search
- /* Title: hidetest.c
- *
- * Purpose: An example program to illustrate the use of the HiddenLib
- * replacement resspr functions.
- *
- * This program is essentially just a rip off of WExample by Acorn. I have
- * altered it just to include my new replacement resspr functions, to
- * demonstrate just how easy it is to hide a Sprites file inside your
- * !RunImage file.
- *
- * When started it sets up an icon on the icon bar. Clicking on the icon
- * opens a window. The icon has a menu for 'Info' and 'Quit'. Only one window
- * may be opened. This program isn't much use in itself, but it can be used
- * as a skeleton for developing other applications.
- */
-
- #include "wimp.h"
- #include "wimpt.h"
- #include "win.h"
- #include "event.h"
- #include "baricon.h"
- #include "sprite.h"
- #include "res.h"
- #include "resspr+.h"
- #include "menu.h"
- #include "template.h"
- #include "dbox.h"
- #include "werr.h"
-
- #include <stdlib.h>
-
- /********************************* CONSTANTS ********************************/
-
- /* Menu items */
- #define HideTest_menu_info 1
- #define HideTest_menu_quit 2
-
- /* Info box field for the version string */
- #define HideTest_info_field 4
-
- /******************************** GLOBAL DATA *******************************/
-
- /* Application version */
- static char *HideTest_Version_String = "1.00 (24 April 1989)";
-
- /* The top of the menu tree */
- static menu HideTest_menu;
-
- /* Handle for the HideTest window */
- static wimp_w HideTest_win_handle;
-
- /* Flag - is the window open */
- static BOOL HideTest_window_open = FALSE;
-
- extern sprite_area *sprites;
- extern int sprites_length;
-
- /***************************** WINDOW FUNCTIONS *****************************/
-
- /*--- Create the window, yielding its handle. Return TRUE if ok. ---*/
- static BOOL HideTest_create_window(char *name, wimp_w *handle)
- {
- wimp_wind *window; /* Pointer to window definition */
-
- /* Find template for the window */
- window = template_syshandle(name);
- if (window == 0)
- return FALSE;
-
- /* Create the window, dealing with errors */
- return (wimpt_complain(wimp_create_wind(window, handle)) == 0);
- }
-
- /*--- Individual event routines for the window ---*/
- static void HideTest_redraw_window(wimp_w handle)
- {
- /* Redrawing the window here does nothing - just go through the loop */
- int more;
- wimp_redrawstr r;
-
- /* Start the redraw */
- r.w = handle;
- wimpt_noerr(wimp_redraw_wind(&r, &more));
-
- /* Do the redraw loop */
- while (more)
- {
- wimp_get_rectangle(&r, &more);
- }
- }
-
- static void HideTest_open_window(wimp_openstr *o)
- {
- /* Just pass the open request on to the wimp */
- wimpt_noerr(wimp_open_wind(o));
- }
-
- /****************************** EVENT HANDLERS ******************************/
-
- /*--- Event handler called on a left click on the icon. ---*/
- static void HideTest_iconclick(wimp_i icon)
- {
- icon = icon; /* We don't need the handle: this stops compiler warning */
-
- /* Open the window - only one allowed */
- if (HideTest_window_open)
- werr(FALSE, "Only one window may be opened");
- else
- {
- wimp_wstate state;
-
- /* Get the state of the window */
- if (wimpt_complain(wimp_get_wind_state(HideTest_win_handle, &state)) == 0)
- {
- state.o.behind = -1; /* Make sure window is opened in front */
- wimpt_noerr(wimp_open_wind(&state.o));
- HideTest_window_open = TRUE;
- }
- }
- }
-
- /*--- Display the program info box - called from the menu processor. ---*/
- static void HideTest_info_about_program(void)
- {
- dbox d; /* Dialogue box handle */
-
- /* Create the dialogue box */
- if (d = dbox_new("ProgInfo"), d != NULL)
- {
- /* Fill in the version number */
- dbox_setfield(d, HideTest_info_field, HideTest_Version_String);
-
- /* Show the dialogue box */
- dbox_show(d);
-
- /* Keep it on the screen as long as needed */
- dbox_fillin(d);
-
- /* Dispose of the dialogue box */
- dbox_dispose(&d);
- }
- }
-
- /*--- Event handler for the menu. ---*/
- static void HideTest_menuproc(void *handle, char *hit)
- {
- handle = handle; /* We don't need handle: this stops compiler warning */
-
- /* Find which menu item was hit and take action as appropriate */
- switch (hit[0])
- {
- case HideTest_menu_info:
- HideTest_info_about_program();
- break;
-
- case HideTest_menu_quit:
- /* Exit from the program. The wimp gets rid of the window and icon */
- exit(0);
- }
- }
-
- /*--- Event handler for window. ---*/
- static void HideTest_event_handler(wimp_eventstr *e, void *handle)
- {
- handle = handle; /* We don't need handle: this stops compiler warning */
-
- /* Deal with event */
- switch (e->e)
- {
- case wimp_EREDRAW:
- HideTest_redraw_window(e->data.o.w);
- break;
-
- case wimp_EOPEN:
- HideTest_open_window(&e->data.o);
- break;
-
- case wimp_ECLOSE: /* Pass on close request */
- wimpt_noerr(wimp_close_wind(e->data.o.w));
- HideTest_window_open = FALSE;
-
- default: /* Ignore any other event */
- break;
- }
- }
-
- /****************************** INITIALISATION ******************************/
-
- /*--- Initialise the program, returning TRUE if it was all OK. ---*/
- static BOOL HideTest_initialise(void)
- {
- /* RISC_OSlib initialisation */
- wimpt_init("HiddenLib HideTest"); /* Main Wimp initialisation */
- res_init("HideTest"); /* Resources */
-
-
- resspr_init(sprites, sprites_length); /* This line initialises your hidden */
- /* Sprite area. sprites and sprites_length */
- /* are external */
-
- template_init(); /* Templates */
- dbox_init(); /* Dialogue boxes */
-
- /* Create the main window, and declare its event handler */
- if (!HideTest_create_window("MainWindow", &HideTest_win_handle))
- return FALSE; /* Window creation failed */
- win_register_event_handler(HideTest_win_handle, HideTest_event_handler, 0);
-
- /* Create the menu tree */
- if (HideTest_menu = menu_new("HideTest", ">Info,Quit"), HideTest_menu == NULL)
- return FALSE; /* Menu create failed */
-
- /* Set up the icon on the icon bar, and declare its event handlers */
- baricon("!test", (int)resspr_area(), HideTest_iconclick);
- if (!event_attachmenu(win_ICONBAR, HideTest_menu, HideTest_menuproc, 0))
- return FALSE; /* Unable to attach menu */
-
- /* All went ok */
- return TRUE;
- }
-
- /******************************* MAIN PROGRAM ********************************/
-
- /*--- Main entry point. ---*/
- int main()
- {
- if (HideTest_initialise())
- {
- /* The main event loop */
- while (TRUE)
- event_process();
- }
-
- return 0;
- }
-