/*
 * Minimal Toolbox application, using the event veneers library.
 */

#include <stdlib.h>
#include "wimp.h"
#include "toolbox.h"
#include "event.h"
#include "wimplib.h"

#define WimpVersion    310

static  WimpPollBlock  poll_block;
static  MessagesFD     messages;
static  IdBlock        id_block;

/*
 * Event handler to be called when toolbox event 1
 * is generated (by click on the 'Quit' entry of
 * the iconbar menu.
 */

int quit_event(int event_code, ToolboxEvent *event, IdBlock *id_block,void *handle)
{
  event_code = event_code;
  event = event;
  id_block = id_block;
  handle = handle;

  exit(0);
  return(1);
}


/*
 * Message handler to be called on receipt of a
 * Quit or PreQuit message from the Wimp.
 */


int quit_message(WimpMessage *message,void *handle)
{
  message = message;
  handle = handle;

  exit(0);
  return(1);
}


int main(void)
{
    int    toolbox_events = 0,
           wimp_messages = 0,
           event_code;

    /*
     * register ourselves with the Toolbox.
     */

    toolbox_initialise (0, WimpVersion, &wimp_messages, &toolbox_events, "<MinApp$Dir>",
                        &messages, &id_block, 0, 0, 0);


    /*
     * initialise the event library.
     */

    event_initialise (&id_block);

    event_set_mask (1+256);

    /*
     * register handler for toolbox event 1,
     * which is generated by the 'Quit' option on the
     * iconbar menu.  Also register message handlers
     * to quit properly when quit messages are
     * received from the wimp.
     */

    event_register_toolbox_handler(-1,1,quit_event,0);
    event_register_message_handler(Wimp_MQuit,quit_message,0);
    event_register_message_handler(Wimp_MPreQuit,quit_message,0);

    /*
     * poll loop
     */

    while (TRUE)
    {
        event_poll (&event_code, &poll_block, 0);
    }
}
