home *** CD-ROM | disk | FTP | other *** search
- /* wimpmain.c */
-
- /* If you include this in your build, then your program will start by
- putting an icon on the icom bar. This can then be used as an entry to a user
- program. If the icon is clicked, then user_main is called; if a file is
- dropped on the icon, then user_main is called with the name of the file as
- the first parameter. In both cases, a dummy zeroth parameter is passed to
- user_main. Thus, by taking a command line program, and replacing main by
- user_main, you can turn it into a WIMP program. If user_main returns, then
- it can be called again.
- A further click or file will be ignored until user_main returns, in case
- user_main calls the event processor.
- Some strings are expected to exist:
- char *taskname, char *resources, char *iconname, char *Version_String
-
- *** NB. Dropping of files on the icon bar has not yet been implemented. It
- may follow in later releases
- ***
-
- */
-
- #include "resspr.h"
- #include "baricon.h"
- #include "event.h"
- #include "menu.h"
- #include "dbox.h"
- #include "win.h"
-
- #include "wimpc.h"
-
- extern char *taskname;
- extern char *resources;
- extern char *iconname;
- extern char *Version_String;
- extern int user_main(int argc, char *argv[]);
-
-
- static BOOL running = TRUE;
- static BOOL user_called = FALSE;
-
- char *arguments[2];
-
- /* Menu items */
- #define menu_info 1
- #define menu_quit 2
-
- /* Info box field for the version string */
- #define info_field 4
-
- /* The top of the menu tree */
- static menu icon_menu;
-
- /*--- Event handler called on a left click on the icon. ---*/
- /* On each click, we call the tester */
- static void iconclick(wimp_i icon)
- {
- icon = icon; /* We don't need the handle: this stops compiler warning */
- if (!user_called)
- {
- arguments[0] = taskname;
- user_called = TRUE;
- user_main(1, arguments);
- user_called = FALSE;
- }
- }
-
- /*--- Display the program info box - called from the menu processor. ---*/
- static void 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, info_field, 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 icon_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 menu_info:
- info_about_program();
- break;
-
- case menu_quit:
- running = FALSE;
- break;
- }
- }
-
- #ifdef DROPS
- /* Background event handler - used for drops onto icon */
- static void bkg_events (wimp_eventstr *e, void *handle)
- {
- handle = handle ; /* avoid not used warning */
-
- switch (e->e)
- { case wimp_ESEND:
- case wimp_ESENDWANTACK:
- { wimp_msgstr *msg = &e->data.msg; /* Make access easier */
-
- switch (msg->hdr.action)
- {
- /* Response to help could be inserted here */
-
- case wimp_MDATASAVE:
- case wimp_MDATALOAD:
- case wimp_MDATAOPEN:
- err = load_file (NULL, NULL, &zero, msg->hdr.action!=wimp_MDATALOAD);
- break;
- }
- }
- }
- }
- #endif
-
-
- int main()
- {
- /* Start up the wimp */
- wimpc_init(taskname, resources);
-
- /* Create the menu tree */
- if (icon_menu = menu_new(taskname, ">Info,Quit"), icon_menu == NULL)
- return FALSE; /* Menu create failed */
-
- /* Place icon on the icon bar and register an event handler for it */
- baricon(iconname, (int)resspr_area(), iconclick);
- if (!event_attachmenu(win_ICONBAR, icon_menu, icon_menuproc, 0))
- return 1; /* Unable to attach menu */
-
- #ifdef DROPS
- /* Set up a dummy window event handler to get icon messages */
- win_register_event_handler (win_ICONBARLOAD, bkg_events, 0);
- win_claim_unknown_events (win_ICONBARLOAD);
- #endif
-
- /* Process events */
- while (running) event_process();
- return 0;
- }
-