/**
 * Generic useful headers
 * (C) Nettle developers 2000-2002
 *
 * $Id: generic,v 1.33 2003/01/10 14:10:09 archifishal Exp $
 */

#ifndef GENERIC_H
#define GENERIC_H

/* Include fortify.h (Debugging) */
#include "fortify.h"

typedef enum
{
  false = 0, true = 1
} bool;

#define NOT(x) ((x)?false:true)
#define BOOL(x) ((x)?true:false)

typedef unsigned long colour_t;

/* Standard includes */
#include <assert.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>

/* RISC OS includes */
#include "kernel.h"
#include "swis.h"

#ifndef Wimp_AutoScroll
#define Wimp_AutoScroll 0x000400fd
#endif

/* Compiler warning suppression */

#define NOT_USED(a) (a=a)

/* minimum / maximum macros */
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))

/* Unions/Structs */

struct coords
{
  int x, y;
};

struct coordspair
{
  struct coords tl, br;
};

struct os_spriteop_area
{
  int total_size;
  int number_of_sprites;
  int offset_to_1st_sprite;
  int offset_to_1st_free_word;
  /* Remaining data */
};

struct wimp_closewindow_block
{
  int window_handle;
};

union icon_data
{
  struct
  {
    char text[12];
  } t;

  struct
  {
    char *text;
    char *validation;
    int text_len;
  } it;

  struct
  {
    char *sprite;
    struct os_spriteop_area *sprite_area;
    int sprite_len;
  } is;
};

struct wimp_createicon_block
{
  int window_handle;
  struct coords min;
  struct coords max;
  unsigned int icon_flags;
  union icon_data contents;
};

struct wimp_createwindow_block
{
  struct coords min;
  struct coords max;
  struct coords scroll;
  int handle_behind;
  unsigned int window_flags;
  unsigned char title_fg;
  unsigned char title_bg;
  unsigned char work_fg;
  unsigned char work_bg;
  unsigned char scroll_outer_colour;
  unsigned char scroll_inner_colour;
  unsigned char title_focus_colour;
  unsigned char flags;
  struct coords work_min;
  struct coords work_max;
  unsigned int icon_flags;
  unsigned int workarea_flags;
  struct os_spriteop_area *sprite_area;
  unsigned short min_width;
  unsigned short min_height;
  union icon_data title;
  int number_of_icons;
  /* Icon definitions follow... */
};

struct wimp_deleteicon_block
{
  int window_handle;
  int icon_handle;
};

struct wimp_deletewindow_block
{
  int window_handle;
};

struct wimp_dragbox_block
{
  int window_handle;
  int drag_type;
  struct coords min;
  struct coords max;
  struct coords parent_min;
  struct coords parent_max;
  int r12_value;

  /* Maybe... */
  int *drawbox_routine;
  int *removebox_routine;
  int *movebox_routine;
};

struct wimp_autoscroll_block
{
  int window_handle;
  int left_pause;
  int bottom_pause;
  int right_pause;
  int top_pause;
  int pause_duration;
  int statechange_handler;
  int r12_value;
};

struct wimp_getcaretposition_block
{
  int window_handle;
  int icon_handle;
  struct coords pos;
  int height_and_flags;
  int index;
};

struct wimp_geticonstate_block
{
  int window_handle;
  int icon_handle;
  struct coords min;
  struct coords max;
  unsigned int icon_flags;
  union icon_data contents;
};

struct wimp_getpointerinfo_block
{
  struct coords pos;
  int buttons;
  int window_handle;
  int icon_handle;
};

struct wimp_getwindowinfo_block
{
  int window_handle;
  struct coords min;
  struct coords max;
  struct coords scroll;
  int handle_behind;
  unsigned int window_flags;
  unsigned char title_fg;
  unsigned char title_bg;
  unsigned char work_fg;
  unsigned char work_bg;
  unsigned char scroll_outer_colour;
  unsigned char scroll_inner_colour;
  unsigned char title_focus_colour;
  unsigned char flags;
  struct coords work_min;
  struct coords work_max;
  unsigned int icon_flags;
  unsigned int workarea_flags;
  struct os_spriteop_area *sprite_area;
  unsigned short min_width;
  unsigned short min_height;
  union icon_data title;
  int number_of_icons;
  /* Icon definitions follow... */
};

struct wimp_getwindowoutline_block
{
  int window_handle;
  struct coords min;
  struct coords max;
};

struct wimp_getwindowstate_block
{
  int window_handle;
  struct coords min;
  struct coords max;
  struct coords scroll;
  int handle_behind;
  unsigned int window_flags;
};

struct wimp_getrectangle_block
{
  int window_handle;
  struct coords vismin;
  struct coords vismax;
  struct coords scroll;
  struct coords drawmin;
  struct coords drawmax;
};

struct wimp_openwindow_block
{
  int window_handle;
  struct coords min;
  struct coords max;
  struct coords scroll;
  int handle_behind;
};

struct wimp_reporterror_block
{
  int errnum;
  char errmess[252];
};

struct wimp_setextent_block
{
  struct coords min;
  struct coords max;
};

struct wimp_seticonstate_block
{
  int window_handle;
  int icon_handle;
  int eor;
  int clear;
};

struct wimp_whichicon_block
{
  int icons[64];
};

struct wimp_ploticon_block
{
  struct coords min;
  struct coords max;
  unsigned int icon_flags;
  union icon_data contents;
};

struct wimp_gadgetsizes
{
  int window_handle;
  int left_border;
  int bottom_border;
  int right_border;
  int top_border;
  int gadget_back_width;
  int gadget_close_width;
  int zero1;
  int gadget_title_width;
  int zero2;
  int gadget_iconise_width;
  int gadget_toggle_width;
  int gadget_toggle_height;
  int gadget_vscrolltop_height;
  int gadget_scrollup_height;
  int gadget_vscrollwell_height;
  int gadget_scrolldown_height;
  int gadget_vscrollbottom_height;
  int gadget_adjust_height;
  int gadget_adjust_width;
  int gadget_hscrollright_width;
  int gadget_scrollright_width;
  int gadget_hscrollwell_width;
  int gadget_scrollleft_width;
  int gadget_hscrollleft_left;
};

struct colourpicker_block
{
  unsigned int flags;
  char *title;
  struct coords bl, tr; /* bl.y = 0x80000000, tr.x =0x7FFFFFFF */
  int zero0, zero1; /* 0, 0 */
  colour_t colour;
  int extsize;/* normally 0 */
  int exttype;
  /* extension data */
};

#define WIMP_ICON_TEXT_BIT       (1<<0)
#define WIMP_ICON_SPRITE_BIT     (1<<1)
#define WIMP_ICON_BORDER_BIT     (1<<2)
#define WIMP_ICON_HCENT_BIT      (1<<3)
#define WIMP_ICON_VCENT_BIT      (1<<4)
#define WIMP_ICON_FILLED_BIT     (1<<5)
#define WIMP_ICON_FONT_BIT       (1<<6)
#define WIMP_ICON_HELP_BIT       (1<<7)
#define WIMP_ICON_INDIRECTED_BIT (1<<8)
#define WIMP_ICON_RJUSTIFY_BIT   (1<<9)
#define WIMP_ICON_ADJUST_BIT     (1<<10)
#define WIMP_ICON_HALFSIZE_BIT   (1<<11)
#define WIMP_ICON_TYPE(x)        ((x)<<12)
#define WIMP_ICON_ESG(x)         ((x)<<16)
#define WIMP_ICON_SELECTED_BIT   (1<<21)
#define WIMP_ICON_SHADED_BIT     (1<<22)
#define WIMP_ICON_DELETED_BIT    (1<<23)
#define WIMP_ICON_FGCOL(x)       ((x)<<24)
#define WIMP_ICON_BGCOL(x)       ((x)<<28)
#define WIMP_ICON_FHANDLE(x)     ((x)<<24)

#define WIMP_MESSAGE_QUIT                    0
#define WIMP_MESSAGE_DATASAVE                1
#define WIMP_MESSAGE_DATASAVEACK             2
#define WIMP_MESSAGE_DATALOAD                3
#define WIMP_MESSAGE_DATALOADACK             4
#define WIMP_MESSAGE_PREQUIT                 8
#define WIMP_MESSAGE_CLIP_CLAIMENTITY       15
#define WIMP_MESSAGE_CLIP_DATAREQUEST       16
#define WIMP_MESSAGE_MENUWARNING       0x400c0
#define WIMP_MESSAGE_MODECHANGE        0x400c1
#define WIMP_MESSAGE_MENUSDELETED      0x400c9
#define WIMP_MESSAGE_WINDOWINFO        0x400cc
#define COLOURPICKER_COLOUR_CHOICE     0x47700
#define COLOURPICKER_CLOSE_REQUEST     0x47702
#define WIMP_MESSAGE_TASKWINDOW_INPUT  0x808c0
#define WIMP_MESSAGE_TASKWINDOW_OUTPUT 0x808c1
#define WIMP_MESSAGE_TASKWINDOW_EGO    0x808c2
#define WIMP_MESSAGE_TASKWINDOW_MORIO  0x808c3
#define WIMP_MESSAGE_TASKWINDOW_MORITE 0x808c4


#endif
