
#include "wimp.h"
#include "wimpt.h"
#include "win.h"
#include "event.h"
#include "baricon.h"
#include "res.h"
#include "resspr.h"
#include "menu.h"
#include "template.h"
#include "dbox.h"
#include "werr.h"
#include "txt.h"
#include <stdlib.h>
#include "kernel.h"
#include "txtedit.h"
#include "xferrecv.h"
#include "flex.h"
#include "swis.h"
#include "ctype.h"
#include "string.h"
 
/* this is the application menu */
static menu sfp_menu;

/* clicking on the icon bar does nothing */
static void noop (wimp_i icon) 
{
        icon=icon;
}




/* display info box */

static void display_info(void)
{
        dbox d;
        if (d=dbox_new("ProgInfo"),d!=NULL)
        {
                dbox_show(d);
                dbox_fillin(d);
                dbox_dispose(&d);
        }
}                        

/* flags are maintained to kepp track of the toggleable menu items */

static void menu_handler(void *handle,char *hit)
{
        handle=handle; /* stop compiler warning */
        switch (hit[0]) {
                case 1:
                        display_info();
                        return;
                case 2:
                        exit(0);
        }
}           
                                   
void events_handle(wimp_eventstr *e, void *handle)
{               
        int filetype;
        char *filename,cl[128];
        handle=handle;
        
        /* we're only interested in a file being dropped
         * onto the icon bar
         */

        if ((e->e==wimp_ESEND || e->e==wimp_ESENDWANTACK)
            && (e->data.msg.hdr.action==wimp_MDATALOAD )) {
                filetype=xferrecv_checkinsert(&filename);
                sprintf(cl,"*iconsprites %s",filename);
                system(cl);
                sprintf(cl,"call: <texture$dir>.redraw");
                system(cl);
        }
}

static BOOL init (void)
{
        wimpt_wimpversion(310);
        wimpt_init("Texture");
        res_init("Texture");
        resspr_init();
        template_init();
        dbox_init();
        if (sfp_menu=menu_new("Texture",
        ">Info,Quit"),
                sfp_menu==NULL) return FALSE;

        baricon("!texture", (int) resspr_area(),noop);
        if (!event_attachmenu(win_ICONBAR,sfp_menu,menu_handler,
                0)) return FALSE;
        win_register_event_handler(win_ICONBARLOAD,events_handle,0); 
        win_claim_unknown_events(win_ICONBARLOAD);
        return TRUE;
}                                            

int main()
{
        if (init())
        {       
                while(1) event_process();
        }
        return 0;
}
