/***************************************************************************
 * listwin_pak.h -general-purpose dynamic list-window functions to make    *
 *                programming alot easier.                                 *
 *                (c) 1990 by VIDEOWORKS Computer Applications             *
 *                All rights reserved.                                     *
 *                129 Orchard Avenue, Rocky Mount, VA 24151                *                                         *
 *                (703) 483-8219 / 489-3863                                *
 *                                                                         *
 *                Designed and Developed by Paul T. Miller                 *
 *                                                                         *
 * Program Name:  N/A                                                      *
 * Version:       1                                                        *
 * Revision:      0                                                        *
 *-------------------------------------------------------------------------*
 * File: (listwin_pak.h) dynamic list-window package header file           *
 *-------------------------------------------------------------------------*
 * Modification History                                                    *
 * Date     Author   Comment                                               *
 * -------- ------   -------                                               *
 * 06-13-90    PTM   Created. ListWindow structure
 * 06-22-90    PTM   NameList structure
 * 06-23-90    PTM   Make NameList dynamically allocated
 ***************************************************************************/

#ifndef LISTWIN_PAK_H
#define LISTWIN_PAK_H

/* HandleListWindow() return codes */
#define CLOSE_LISTWINDOW   -1
#define LISTWINDOW_NONE    0
#define GOT_NAME           1


/* NameList structure - keeps track of pointers to text strings */
struct NameList {
   ULONG             Names;
   ULONG             MaxNames;
   UBYTE           **NamePtrs;
};
#define NAMELIST_SIZE   (sizeof(struct NameList))

/* ListWindow structure - keeps track of list information */
struct ListWindow {
   struct Window    *Window;     /* pointer to container window */
   struct Gadget    *UpGad;      /* pointer to this window's UP gadget */
   struct Gadget    *DownGad;    /* pointer to this window's DOWN gadget */
   struct Gadget    *PropGad;    /* pointer to this window's SCROLL gadget */
   struct NameList  *NameList;   /* pointer to the NameList structure */
   USHORT            SlotWidth;  /* width of name slot */
   USHORT            SlotHeight; /* height of name slot */
   USHORT            NameWidth;  /* maximum name width (in pixels) */
   SHORT             TotalNames; /* total number of names */
   SHORT             VisibleNum; /* visible # of names (also # of gadgets) */
   SHORT             TopNum;     /* number of top name visible */
   SHORT             Overlap;    /* # to overlap "paged" scroll of list */
   SHORT             Hidden;     /* # of names that don't fit in window */
   SHORT             Selected;   /* # of selected name */
};
#define LISTWINDOW_SIZE (sizeof(struct ListWindow))

/* listwin.c function prototypes */
int InitListWindowPackage(void);
void CloseListWindowPackage(void);

struct Window *OpenListWindow(struct NewWindow *);
int MakeListWindow(struct Window *);
void CloseListWindow(struct Window *);
void FreeListWindow(struct Window *);
int AllocateListWinGads(struct ListWindow *);
void FreeListWinGads(struct ListWindow *);

int InitListWindow(struct Window *, UBYTE **, SHORT, SHORT);
void SetListWindowNameList(struct Window *, struct NameList *, SHORT);
void SetNameListPos(struct Window *, SHORT);
void SetListWindowPropGad(struct ListWindow *);
UWORD GetListWindowPropValue(struct Window *);

int HandleListWindow(struct IntuiMessage *, UBYTE *);
SHORT HandleListWindowRawKey(struct Window *, USHORT, USHORT, APTR);
SHORT HandleListWindowKey(struct Window *, UBYTE);
SHORT HandleListWindowGadgetDown(struct Window *, struct Gadget *, USHORT);
SHORT GetListNameSlot(struct Window *, SHORT, SHORT);

LONG ConvertRawKey(USHORT, USHORT, APTR, UBYTE *, USHORT);
void ResizeListWindow(struct Window *);

struct NameList *AllocateNameList(SHORT);
void FreeNameList(struct NameList *);
int AllocateNameListPtrs(struct NameList *, ULONG);
void FreeNameListPtrs(struct NameList *);
int ResizeNameList(struct NameList *, ULONG);
void SetNameList(struct NameList *, UBYTE **, ULONG);
void SortNameList(struct NameList *);
void AddName(struct NameList *, UBYTE *);
void RemoveName(struct NameList *, UBYTE *);
void AddListWindowName(struct Window *, UBYTE *);
void RemoveListWindowName(struct Window *, UBYTE *);
void SelectListWindowName(struct Window *, UBYTE *);
void SortListWindowNames(struct Window *);

#endif   /* LISTWIN_PAK_H */

