/*
**	Gui.h
**
**	Copyright (C) 1993,94,95,96,98 by Bernardo Innocenti
**
**	Various definitions for the user interface.
*/

#ifndef INTUITION_INTUITION_H
#include <intuition/intuition.h>
#endif

#ifndef XMODULE_PRIV_H
#include <XModulePriv.h>
#endif


/***************/
/* WinUserData */
/***************/

/* This structure holds data needed to handle windows
 * in a nice Object oriented way (no more endless switches :-)
 */
struct WinUserData
{
	struct MinNode		 Link;	/* Used to mantain a list of all open windows. */

	struct Window		*Win;
	ULONG				 GCount;
	struct Gadget		**Gadgets;
	struct GInfo		*GInfo;
	UBYTE				*Keys;
	struct TextAttr		*Attr;
	struct TextFont		*Font;
	struct NewMenu		*NewMenu;
	struct Menu			*MenuStrip;
	struct Gadget		*GList;
	ULONG				*LayoutArgs;
	struct WindowBorder	*Borders;
	struct AppWindow	*AppWin;
	ULONG				 Flags;
	ULONG				 IDCMPFlags;
	STRPTR				 Title;

	ULONG				 WindowID;
	struct IBox			 WindowSize;
	struct IBox			 WindowZoom;
	LONG				 WUDFlags;
	APTR				 UserData;
	STRPTR				 HelpNode;

	/* Window specific user functions */
	LONG (*PreOpenFunc)(struct WinUserData *);
	void (*PostOpenFunc)(struct WinUserData *);
	LONG (*PreCloseFunc)(struct WinUserData *);
	void (*PostCloseFunc)(struct WinUserData *);
	void (*IDCMPFunc)(struct WinUserData *);
	void (*DropIcon)(struct AppMessage *);
	void (*LayoutCleanupFunc)(struct WinUserData *);
};


/* Flags for WinUserData->WUDFlags */

#define WUDF_REOPENME		(1<<0)	/* Open this window again later				*/
#define WUDF_LOCALEDONE		(1<<1)	/* Set when menustrip has been localized	*/
#define WUDF_JUSTRESIZED	(1<<3)	/* Set just after an IDCMP_NEWSIZE			*/

#define WUDF_CUSTOMLAYOUT	(1<<2)
/* Do not use the standard layout routines for
 * this window.  If not NULL, wud->LayoutArgs must point to
 * a user function which should create and position the gadgets.
 *
 *	struct Gadget *CustomLayoutFunc (struct WinUserData *wud);
 */



struct WDescr
{
	struct WinUserData	*Wud;			/* Pointer to WinUserData				*/
	UWORD				 UseCnt;		/* Number of WUDs of this kind			*/
	UWORD				 Flags;			/* Some flags, see below				*/
	struct TagItem		*CreationTags;	/* See <gui.h> for possible tags		*/
};



/* Flags for WDescr->Flags */
#define XMWINF_OPENMULTI	(1<<0)	/* Allow opening multiple times				*/
#define XMWINF_LOCALEDONE	(1<<1)	/* Set when menustrip has been localized	*/


/* Window IDs */

enum
{
	WID_TOOLBOX,
	WID_PREFS,
	WID_SONGINFO,
	WID_INSTRUMENTS,
	WID_SEQUENCE,
	WID_PATTERN,
	WID_PLAY,
	WID_SAMPLE,
	WID_OPTIMIZATION,
	WID_SAVERS,
	WID_PATTPREFS,
	WID_PATTSIZE,
	WID_CLEAR,
	WID_LOG,
	WID_PROGRESS,

	WID_COUNT
};



/* Tags for MyOpenWindow() */
#define XMWIN_Dummy			(TAG_USER + 'WN' << 8)
#define XMWIN_NewMenu		(XMWIN_Dummy + 1)	/* Pointer to NewMenu array			*/
#define XMWIN_LayoutArgs	(XMWIN_Dummy + 2)	/* Pointer to layout args array		*/
#define XMWIN_GCount		(XMWIN_Dummy + 3)	/* Number of gadgets in window		*/
#define XMWIN_Title			(XMWIN_Dummy + 4)	/* Window title						*/
#define XMWIN_WindowFlags	(XMWIN_Dummy + 5)	/* Window flags for WA_Flags		*/
#define XMWIN_IDCMPFlags	(XMWIN_Dummy + 6)	/* Flags for WA_IDCMPFlags			*/
#define XMWIN_IDCMPFunc		(XMWIN_Dummy + 7)	/* Custom IDCMP handler				*/
#define XMWIN_DropIconFunc	(XMWIN_Dummy + 8)	/* AppWindow handler				*/
#define XMWIN_LayoutFunc	(XMWIN_Dummy + 9)	/* Your custom layout function		*/
#define XMWIN_PreOpenFunc	(XMWIN_Dummy + 10)	/* Called just before opening win	*/
#define XMWIN_PostOpenFunc	(XMWIN_Dummy + 11)	/* Called just after opening win	*/
#define XMWIN_PreCloseFunc	(XMWIN_Dummy + 12)	/* Called just before closing win	*/
#define XMWIN_PostCloseFunc	(XMWIN_Dummy + 13)	/* Called just after closing win	*/
#define XMWIN_HelpNode		(XMWIN_Dummy + 14)	/* Name of AmigaGuide node for help	*/
#define XMWIN_UserData		(XMWIN_Dummy + 15)	/* Whatever you want...				*/
#define XMWIN_LayoutCleanup	(XMWIN_Dummy + 16)	/* Cleanup for custom layout func	*/

/* You can also use standard OpenWindow() tags */



/* This structure is used by LockWindows() to
 * track modifications made to the windows.
 */
struct WindowLock
{
	struct Requester	Req;
	ULONG				OldIDCMPFlags;
	UWORD				OldMinWidth,
						OldMinHeight,
						OldMaxWidth,
						OldMaxHeight;
};



/****************/
/* WindowBorder */
/****************/

/* A linked list of these structures is attached to all
 * WUDs to keep track of the bevel boxes inside the window.
 */
struct WindowBorder
{
	struct WindowBorder	*NextBorder;
	ULONG				 Type;
	struct IBox			 Size;
};



/*********/
/* GInfo */
/*********/

/* Each WUD gets an array of GInfo structures to store
 * some precalculated layout data. Each gadget and group
 * has a GInfo structure in the array.
 */
struct GInfo
{
	WORD	GKind;					/* Object kind (#?_KIND)		*/
	UWORD	MinWidth, MinHeight;	/* Minimum size					*/
	UWORD	LabelWidth;				/* Label width for this object	*/
	UWORD	Flags;					/* See below					*/
	UWORD	Dummy;					/* Keep structure long aligned	*/
	union {
		APTR	SpecialStorage;		/* For gadget objects			*/
		struct {
			UWORD Width, Height;	/* For group objects			*/
		} Fixed;
	};
};

/* Flags for GInfo->Flags */
#define GIF_FIXEDWIDTH	(1<<0)
#define GIF_FIXEDHEIGHT	(1<<1)
#define GIF_HASBORDER	(1<<4)



/*********************/
/* LayoutGadgetsArgs */
/*********************/

/* LayoutGadgetsArgs is used to pass arguments to LayoutGadgets()
 * and CreateGadgets().
 */
struct LayoutGadgetsArgs
{
	ULONG				*Args;			/* Arguments array							*/
	ULONG				 Count;			/* GInfo array counter						*/
	struct GInfo		*GInfo;			/* GInfo array								*/
	struct WinUserData	*Wud;			/* The window we are working for			*/
	struct RastPort		*DummyRast;		/* RastPort initialzied for TextLength()	*/
	void				*VInfo;			/* VisualInfo for GadTools gadgets			*/
	struct Gadget		*PrevGad;		/* Used to link gadgets together			*/
	ULONG				*SpecialTags;	/* Storage for additional tags for gadgets	*/
};


/* Layout modes for LayoutGadgets and CreateGadgets() */
#define LAYOUTMODE_V	0
#define LAYOUTMODE_H	1

#define VSPACING		1		/* Vertical spacing between GUI elements	*/
#define HSPACING		2		/* Horizontal spacing between GUI elements	*/
#define LABELSPACING	8		/* Extra horizontal spacing for labels		*/



/***********/
/* ScrInfo */
/***********/

struct ScrInfo
{
    ULONG	DisplayID;		/* Display mode ID				*/
    ULONG	Width;			/* Width of display in pixels	*/
    ULONG	Height;			/* Height of display in pixels	*/
    UWORD	Depth;			/* Number of bit-planes			*/
    UWORD	OverscanType;	/* Type of overscan of display	*/
    BOOL	AutoScroll;		/* Display should auto-scroll?	*/
	BOOL	OwnPalette;
	UWORD	Colors[32];
	UBYTE	PubScreenName[32];
};



/*******************/
/* File requesters */
/*******************/

/* This structure is used to reference all the file requesters.
 */
struct XMFileReq
{
	APTR	FReq;		/* Real file requester (ASL or ReqTools)				*/
	ULONG	Title;		/* Message number for title								*/
	ULONG	Flags;		/* FRF_DOSAVEMODE, FRF_DOPATTERNS, FRF_DOMULTISELECT...	*/
};

enum
{
	FREQ_LOADMOD,
	FREQ_SAVEMOD,
	FREQ_LOADINST,
	FREQ_SAVEINST,
	FREQ_LOADPATT,
	FREQ_SAVEPATT,
	FREQ_LOADMISC,
	FREQ_SAVEMISC,

	FREQ_COUNT
};



/************/
/* Switches */
/************/


struct ClearSwitches
{
	BOOL	ClearPatt,
			ClearSeq,
			ClearInstr;
};

struct SaveSwitches
{
	BOOL	SavePatt,
			SaveSeq,
			SaveInstr,
			SaveNames,
			SaveIcons;
};

struct OptSwitches
{
	BOOL	RemPatts,
			RemDupPatts,
			RemInstr,
			RemDupInstr,
			CutAfterLoop,
			CutZeroTail,
			CutPatts,
			RemapInstr;
};

struct GuiSwitches
{
	BOOL	SaveIcons,
			AskOverwrite,
			AskExit,
			ShowAppIcon,
			UseReqTools,
			SmartRefresh,
			UseDataTypes,
			InstrSaveIcons,
			AskAutosave,
			DoBackups,
			LogToFile;
	UWORD	InstrSaveMode,
			SampDrawMode,
			LogLevel,
			AutosaveTime,
			BackupVersions;
	UBYTE	BackupTemplate[64];
	UBYTE	LogFile[128];
};

struct PattSwitches
{
	WORD	AdvanceTracks,	AdvanceLines;
	ULONG	MaxUndoLevels,	MaxUndoMem;
	ULONG	Flags;							/* See <patteditclass.h> for possible flags */
	WORD	VScrollerPlace,	HScrollerPlace;
	UBYTE	ClipboardUnit,	Pad0;
	UWORD	TrackChars, Backdrop;
	ULONG	BGPen, TextPen, LinesPen, TinyLinesPen;
};



/* Possible values for (H|V)ScrollerPlace */
#define SCROLLERPLACE_NONE		0
#define SCROLLERPLACE_RIGHT		1
#define SCROLLERPLACE_BOTTOM	1
#define SCROLLERPLACE_LEFT		2



/* Instrument save modes */
enum {
	INST_8SVX,
	INST_8SVX_FIB,
	INST_RAW,
	INST_XPK
};


/* Handy macros to get a gadget string/number */

#define GetString(g)      (((struct StringInfo *)g->SpecialInfo)->Buffer)
#define GetNumber(g)      (((struct StringInfo *)g->SpecialInfo)->LongInt)


/* Some handy definitions missing in <devices/inputevent.h> */

#define IEQUALIFIER_SHIFT	(IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT)
#define IEQUALIFIER_ALT		(IEQUALIFIER_LALT | IEQUALIFIER_RALT)
#define IEQUALIFIER_COMMAND	(IEQUALIFIER_LCOMMAND | IEQUALIFIER_RCOMMAND)


/* Any break flag */

#define SIGBREAKFLAGS (SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_D | SIGBREAKF_CTRL_E | SIGBREAKF_CTRL_F)


/**************************/
/* XModule custom gadgets */
/**************************/


#define ENDGROUP_KIND	-1	/* End of group						*/
#define VGROUP_KIND		-2	/* Vertical group					*/
#define HGROUP_KIND		-3	/* Horizontal group					*/
#define IMAGEBUTTON_KIND 20 /* button with vector image label	*/
#define BOOPSI_KIND		 21	/* BOOPSI gadget					*/


/* ti_Data is a pointer to a setup function for custom gadgets.
 * It receives the newly allocated Gadget structure and should customize
 * all fields it is interested in, as well as doing all the allocations
 * and precalculations which are needed for the custom gadget.
 *
 * When the XMGAD_BOOPSI tag is specified, SetupFunc() receves the
 * tag array pointer and the NewGadget structure associated with the
 * gadget.  SetupFunc() should then return a pointer to the BOOPSI
 * Gadget it has allocated.
 */
#define XMGAD_SetupFunc	(TAG_USER+1)


/* If ti_Data is TRUE, the layout routines will let the SetupFunc()
 * allocate a BOOPSI gadget itself, So the gadget is _not_ allocated with
 * the GadTools function CreateGadget(). When the window is closed with
 * MyCloseWindow(), or when MyOpenWindow() fails after creating the object,
 * it is your duty to DisposeObject() on these gadgets.
 */
//#define XMGAD_BOOPSI	(TAG_USER+2)



/********************/
/* External symbols */
/********************/

XREF struct Screen		*Scr;
XREF struct DrawInfo	*DrawInfo;
XREF APTR				 VisualInfo;
XREF struct ScrInfo		 ScrInfo;
XREF struct WDescr		 WDescr[];
XREF CxObj				*MyBroker;
XREF UWORD __chip		*BlockPointer;	/* for OS2.0 only */
XREF Class				*ScrollButtonClass;
XREF UWORD				 OffX, OffY;
XREF WORD				 SizeWidth, SizeHeight;
XREF ULONG				 UniqueID;

XREF struct IntuiMessage IntuiMsg;

XREF struct MsgPort
	*PubPort,
	*CxPort;

XREF struct TextAttr
	TopazAttr,
	ScreenAttr,
	WindowAttr,
	ListAttr,
	EditorAttr;

XREF struct TextFont *TopazFont;

XREF ULONG
	FileReqSig,
	AppSig,
	AudioSig,
	CxSig,
	AmigaGuideSig,
	PubPortSig,
	Signals;		// Global Wait() signals


XREF struct XMFileReq FileReqs[FREQ_COUNT];


XREF struct List
	WindowList,
	InstrList,
	PatternsList,
	SequenceList,
	LogList;


XREF struct SaveSwitches	SaveSwitches;
XREF struct ClearSwitches	ClearSwitches;
XREF struct OptSwitches		OptSwitches;
XREF struct GuiSwitches		GuiSwitches;
XREF struct PattSwitches	PattSwitches;

XREF BOOL DoNextSelect;
XREF BOOL ShowRequesters;
XREF BOOL Iconified;
XREF BOOL Quit;

XREF LONG
	ToolBoxWinTags[],
	PrefsWinTags[],
	SongInfoWinTags[],
	InstrumentsWinTags[],
	SequenceWinTags[],
	PatternWinTags[],
	PlayWinTags[],
	SampleWinTags[],
	OptimizationWinTags[],
	SaversWinTags[],
	PattPrefsWinTags[],
	PattSizeWinTags[],
	ClearWinTags[],
	LogWinTags[],
	ProgressWinTags[];



/***********************/
/* Function prototypes */
/***********************/

GLOBALCALL void	OpenProgressWindow	(void);
GLOBALCALL void	CloseProgressWindow	(void);

GLOBALCALL void	UpdateInstrList		(void);
GLOBALCALL void	UpdateInstrInfo		(void);
GLOBALCALL void	DetatchSongInfoList (void);
GLOBALCALL void	UpdateSongInfoList	(void);
GLOBALCALL void	UpdateSongInfo		(void);
GLOBALCALL void	UpdatePatternList	(void);
GLOBALCALL void	UpdateSequenceList	(void);
/*
GLOBALCALL void	UpdateSample		(void);
GLOBALCALL void	UpdateSampInfo		(void);
GLOBALCALL void	UpdateSampGraph		(void);
*/
GLOBALCALL void	UpdateSampleMenu	(void);
GLOBALCALL void	UpdateGuiSwitches	(void);
GLOBALCALL void	UpdateInstrSwitches (void);
GLOBALCALL void	UpdateClearSwitches	(void);
GLOBALCALL void	UpdateSaveSwitches	(void);
GLOBALCALL void	UpdateOptSwitches	(void);
GLOBALCALL void	UpdatePrefsWindow	(void);
GLOBALCALL void	UpdatePattern		(void);
GLOBALCALL void	UpdateEditorInst	(void);
//GLOBALCALL void	UpdatePlay			(void);

GLOBALCALL void	UpdatePattSize		(void);
GLOBALCALL void	UpdatePattPrefs		(void);

GLOBALCALL void	ToolBoxDropIcon		(struct AppMessage *msg);

GLOBALCALL void	HandleIDCMP			(void);
GLOBALCALL void	LockWindows			(void);
GLOBALCALL void	UnlockWindows		(void);
GLOBALCALL void	RevealWindow		(struct WinUserData *wud);
GLOBALCALL void	SetGadgets			(struct WinUserData *wud, LONG arg, ...);

GLOBALCALL LONG	AddListViewNodeA	(struct List *lv, CONST_STRPTR label, LONG *args);
GLOBALCALL LONG	AddListViewNode		(struct List *lv, CONST_STRPTR label, ...);
GLOBALCALL void	RemListViewNode		(struct Node *n);
GLOBALCALL struct Image *NewImageObject (ULONG which);
GLOBALCALL struct Window *NewWindow	(ULONG id);
GLOBALCALL struct Window *MyOpenWindow (struct WinUserData *wud);
GLOBALCALL void	MyCloseWindow		(struct WinUserData *wud);
GLOBALCALL struct WinUserData *CreateWUD (ULONG id);
GLOBALCALL void	DeleteLayoutInfo	(struct WinUserData	*wud);

GLOBALCALL void	ReopenWindows		(void);
GLOBALCALL LONG	SetupScreen			(void);
GLOBALCALL void	CloseDownScreen		(void);

GLOBALCALL struct Gadget *CreateUpButton (ULONG id, struct Gadget *target, LONG *map, LONG Place);
GLOBALCALL struct Gadget *CreateDnButton (ULONG id, struct Gadget *target, LONG *map, LONG Place);
GLOBALCALL struct Gadget *CreateSxButton (ULONG id, struct Gadget *target, LONG *map);
GLOBALCALL struct Gadget *CreateDxButton (ULONG id, struct Gadget *target, LONG *map);
GLOBALCALL struct Gadget *CreateVSlider (ULONG id, struct Gadget *target, LONG *map, LONG ButtonsSpacing, LONG Place);
GLOBALCALL struct Gadget *CreateHSlider (ULONG id, struct Gadget *target, LONG *map, LONG ButtonsSpacing);
