
/*
 * WimpClib release 1.04
 *
 * $Id: wimpclib,v 1.10 2001/03/31 15:47:04 joseph Exp $
 *
 */

#ifndef WIMPC_H
#define WIMPC_H

#include "wimp.h"

extern const char frontend_taskname[];

#ifndef E_CHECK_RETURN
#define E_CHECK_RETURN(x,a) { \
  _kernel_oserror *b=(a); \
  if (b) { \
    wimp_report_error( b, 0, (char *) frontend_taskname, 0, 0, 0 ); \
    return x; \
  } \
}
#endif

#ifndef E_CHECK_ABORT
#define E_CHECK_ABORT( a ) { \
  _kernel_oserror *b = ( a ); \
  if ( b ) { \
    wimp_report_error( b, 0, (char *) frontend_taskname, 0, 0, 0 ); \
    exit( 1 ); \
  } \
}
#endif

#ifndef E_RETURN
#define E_RETURN(x,a)     { _kernel_oserror eabort; \
			    eabort.errnum=0; \
			    *eabort.errmess=0; \
			    strncat(eabort.errmess, a, sizeof(eabort.errmess)-1); \
		     	    wimp_report_error( &eabort, 0, (char *)frontend_taskname, 0, 0, 0 ); \
		     	    return x; \
                          }
#endif

#ifndef E_CHECK
#define E_CHECK(a) \
  { \
    _kernel_oserror *b=(a); \
    if ( b ) \
    { \
      wimp_report_error( b, 0, (char *)frontend_taskname, 0, 0, 0 ); \
    } \
  }
#endif

#ifndef E_REPORT
#define E_REPORT(a) \
  { \
    _kernel_oserror eabort; \
    eabort.errnum=0; \
    *eabort.errmess=0; \
    strncat( eabort.errmess, a, sizeof(eabort.errmess) - 1 ); \
    wimp_report_error( &eabort, 0, (char *)frontend_taskname, 0, 0, 0 ); \
  }
#endif

int wimpc_taskpresent(const char *tname);
int wimpc_createiconbar(const char *spritename);

WimpMenu *wimpc_createmenu( int /*raw*/, char /*sep*/, const char *title, const char *entries, ... );
int wimpc_menuheight(const WimpMenu *menu);
int wimpc_menufadeitem( WimpMenu *menu, int item, int fade );
int wimpc_menuflagitem( WimpMenu */*menu*/, int /*item*/, int /*flag*/, int /*on*/ );
int wimpc_menuupdate( WimpMenu *menu, int item, void *submenu );
char *wimpc_menuread( WimpMenu */*menu*/, int /*item*/ );
void wimpc_menufade( WimpMenu */*menu*/, int /*fade*/ );


int wimpc_loadtemplate(const char *name);
int wimpc_settitle( int window, const char *text );
int wimpc_openwindowcentre( int handle, int size );
int wimpc_openwindow( int window );
int wimpc_openwindowsize( int window, int size );
int wimpc_centrewindow( WimpGetWindowStateBlock *window, int handle, int size );
void wimpc_setextent( int han, int x, int y );

void wimpc_iconselect(int window, int icon, int select);
int wimpc_iconselected(int window,int icon);
void wimpc_iconfade(int window, int icon, int fade);
char *wimpc_geticontext( int win, int icon );
int wimpc_seticontext(int window, int icon, const char *text);
int wimpc_deleteicon( int window, int icon, int delete );

void wimpc_setinfoversion( int /*winhan*/, int /*icon*/, const char */*version*/, const char */*compiledate*/ );


/* URL/URI stuff */
#define Wimp_MOpenUrl     0x4af80

#define URI_MProcess      0x4e382
#define URI_MReturnResult 0x4e383
#define URI_MProcessAck   0x4e384

/* returns 1 if url is (or can be, if checkonly true) handled, 0 otherwise. must not call wimp_poll  */
typedef int (*url_handler_func)( const char */*url*/, int /*checkonly*/ );


int url_launch( const char *url );

/* called when UserMessageRecorded of URI_MReturnResult or a UserMessageAck of type Wimp_MOpenUrl is received */
void url_bounce( const WimpMessage *mess );

/* called when UserMessageRecorded of Wimp_MOpenUrl or URI_MProcess received */
void url_recvbroadcast( WimpMessage */*mess*/, url_handler_func /*handler*/ );

#endif
