/*
 *  WICONIFY    A utility that allows you to iconify any Intuition window
 *              on any screen, and to open WB windows on any screen.
 *
 *  wIcon.h     Main user-level structures for programmer's interface.
 *
 *  Copyright 1990 by Davide P. Cervone, all rights reserved.
 *  You may use this code, provided this copyright notice is kept intact.
 */

#include <exec/ports.h>

/*
 *  The name of the communication port used by wIcoinfy
 */

#define WICONPORT   "wIconify-Port"

/*
 *  Makes dealing with flag bits easier
 */

#ifndef BIT
#define BIT(x)   (1<<(x))
#endif

/*
 *  define pointers for structures that may not be defined
 */

#ifndef WICONREF
#define WICONREF     APTR
#endif

#ifndef WSCREEN
#define WSCREEN      APTR
#endif


/*
 *  The main wIcon definition structure.  This is what programs use
 *  to declare the imagery and properties of an icon.  wIconify uses
 *  the wIconRef structure internally, and copies data from the wIcon
 *  definition into the wIconRef structure when an icon is created.
 *  From them on, the user has a pointer to a wIconRef, not a wIcon.
 */

struct wIcon
{
   char *Name;              /* the icon's Name */
   struct Image *Image;     /* the icon's unselected Image (NULL = default) */
   struct Image *Select;    /* the icon's Selected image (NULL = complement) */
   UWORD *Mask;             /* the icon's selected image Mask (NULL = none) */
   WORD x,y;                /* the icon's initial position */
   ULONG Flags;
      #define WI_NOICONIFY          BIT(0)  /* do not iconify this window */
      #define WI_CHANGEREFRESH      BIT(1)  /* change refresh type for icon */
      #define WI_ICONIFIED          BIT(2)  /* window is iconified */
      #define WI_NOSAVEPOS          BIT(3)  /* don't save icon X,Y when open */
      #define WI_AUTOREMOVE         BIT(9)  /* delete on screen close */
      #define WI_LOCKED             BIT(20) /* never move move icon */
      #define WI_NOORGANIZE         BIT(21) /* do not ORGANIZE icon */
      #define WI_NOMOVE             BIT(22) /* do not allow icon to be moved */
      #define WI_NOCLOSE            BIT(23) /* do not allow icon to be closed */
      #define WI_NOMULTISELECT      BIT(24) /* can't select more than one */
      #define WI_SELECTED           BIT(25) /* icon is currently selected */
/*                                            (for future expansion)
      #define WI_LTOP               BIT(26)
      #define WI_LBOTTOM            BIT(27)
      #define WI_RTOP               BIT(28)
      #define WI_RBOTTOM            BIT(29)
      #define WI_VERTICAL           BIT(30)
      #define WI_HORIZONTAL         BIT(31)
*/
   ULONG Report;                /* types of messages to report */
      #define WI_REPORTAUTOREMOVE   BIT(19) /* icon was AUTOREMOVED */
      #define WI_REPORTMOVED        BIT(20) /* icon has been moved */
      #define WI_REPORTSELECT       BIT(21) /* icon has become selected */
      #define WI_REPORTUNSELECT     BIT(22) /* icon has become unselected */
      #define WI_REPORTPRESS        BIT(23) /* icon has been pressed */
      #define WI_REPORTRELEASE      BIT(24) /* icon has been released */
      #define WI_REPORTOPEN         BIT(25) /* icon is being opened */
      #define WI_REPORTCLOSE        BIT(26) /* icon is being closed */
/*    #define WI_REPORTDROP         BIT(27)*//* another icon dropped on icon */
      #define WI_REPORTNEWSCREEN    BIT(28) /* a new screen was openned */
      #define WI_REPORTSCREENCLOSE  BIT(29) /* a screen was closed */
      #define WI_REPORTACTIVATE     BIT(30) /* wIconify window is active */
      #define WI_REPORTINACTIVE     BIT(31) /* wIconify window is inactive */
      #define WI_REPORTRESTORE      BIT(11) /* window is no longer iconified */
      #define WI_REPORTICONVERIFY   BIT(10) /* don't iconify until OKed */
      #define WI_REPORTICONEND      BIT(9)  /* wIconify is ending */
      #define WI_REPORTICONIFIED    BIT(8)  /* window has become iconified */
   struct MsgPort *IconPort;    /* port for wIconify messages */ 
};

typedef struct wIcon WICON;


/*
 *  If the IconPort field of the wIcon structure is not NULL, it points to
 *  a message port where wIconify will send messages when things happen
 *  to the specified icon.  The Report field of the wIcon structure 
 *  specifies what kind of messages are to be reported.  When an Icon event is
 *  reported, the port will receive a wIconMessage as defined below.  The
 *  Action field will contain one of the report flags as defined above, which
 *  indicates what event occured.  When your program is done with the message
 *  it should reply to the message as normal.  If the Action is 
 *  WI_REPORTICONVERIFY, however, you should set or clear the WI_ICONIFYOK
 *  flag in the Flags field of the wIconMessage depending on whether it is
 *  OK to iconify the window or not.
 *
 *  The wIconMessage is also used by the wIconCalls library to contact
 *  wIconify directly (to add and remove icons, move icons, etc).
 *  The Actions defined below are for this purpose, and are not used by
 *  the messages received by an IconPort.  User programs will not
 *  usually specify these messages directly, but will use the wIconCalls
 *  library to manager these messages.  The union at the bottom of
 *  the structure is also for this purpose, and will not contain useful
 *  data when a wIconMessage is received by an IconPort.
 *
 *  Note that many icons can share the same IconPort.
 */

struct wIconMessage
{
   struct Message Message;          /* the Exec message structure */
   struct Window *Window;           /* affected window */
   WICONREF *Icon;                  /* the affected icon */
   ULONG Action;                    /* what to do */
     /* any of the WI_REPORT... flags above may also appear here */
     #define WI_ICONIFY     1   /* window should be iconified */
     #define WI_RESTORE     2   /* window should be restored */
     #define WI_ICONOF      3   /* returns icon of given window */
     #define WI_SETICON     4   /* associates an icon with a window */
     #define WI_UNSETICON   5   /* unsets an icon from a window */
     #define WI_SELECTICON  6   /* select a given icon */
     #define WI_UNSELECT    7   /* unselect a given icon */
     #define WI_MOVEICON    8   /* move an icon to a new position */
     #define WI_ADDICON     9   /* add a new icon to a screen */
     #define WI_REMOVEICON  10  /* remove an icon from a screen */
     #define WI_REDRAW      11  /* screen needs refreshing */
     #define WI_UPDATEICON  12  /* update icon imagery, etc. */
     #define WI_BACKDROPOF  13  /* wIconify window of a given screen */

     #define WI_REMSCREEN   32  /* screen should be unlinked */
     #define WI_CLOSEICON   33  /* icon should get a CLOSE message */
     #define WI_SELECTNEXT  34  /* select next icon in the list */
     #define WI_NEWSCREEN   35  /* create a new screen */
     #define WI_MAKEWB      36  /* make a screen the WB screen */
     #define WI_OPENSELECT  37  /* open all selected icons */
     #define WI_CLOSESELECT 38  /* close all selected icons */
     #define WI_OPENON      39  /* set OPEN WINDOW menus */

     #define WI_MAKECONTACT 64  /* initial library contact message */
     #define WI_VERSIONOK   65  /*  versions are OK */
     #define WI_VERSIONBAD  66  /*  versions don't match */
     #define WI_ENDICONIFY  67  /* ask iconify to end */
     #define WI_ENDOK       68  /*  end was OK */
     #define WI_ENDFAILED   69  /*  end is pending screen closes */

   ULONG Flags;
     #define WI_NOREPLY     BIT(31) /* wIconify should free this message */
     #define WI_ADDTOSELECT BIT(30) /* for WI_SELECTICON */
     #define WI_ICONMESSAGE BIT(29) /* wIconify originated this message */
     #define WI_REPORT      BIT(28) /* This is a REPORT message */
     #define WI_ICONIFYOK   BIT(1)  /* answer to WI_REPORTICONVERIFY */
     #define WI_CHANGE      BIT(0)  /* window refresh bits should be changed */
   union
   {
      struct Window *Window;
      struct Screen *Screen;
      WSCREEN *wScreen;
      struct {WORD x,y;} Position;
      struct {UWORD Depth,Modes;} NewScreen;
      struct {UWORD Maj,Min;} Version;
      struct {UWORD ScreenType,SizeToFit;} OpenOn;
      WICON *Icon;
      APTR DataPtr;
   } Data;                          /* special data used by icon commands */
};
