#ifndef XM_XWIDGETS_H_
/*
 ************
 
    $Id: xwidgets.h,v 1.1 2008/07/19 22:30:29 jgs Exp $
 
    Description:	X-Widget structure definitions
 
*/
/*
 *************
*/

#include "fcinterface.h"
#include "mtypes.h"

typedef enum {
  XW_NONE=0, XW_MENU, XW_VALUATOR, XW_PROMPT, XW_MSGMONITOR, XW_MESSAGE,
  XW_COLORTAB, XW_COLORMAP, XW_PMONITOR, XW_FRAME, XW_FILES, XW_XWIDGET
} XWIDGET_TYPE;

typedef enum {
  XW_FREE = -4, XW_INIT, XW_RESET, XW_SETUP, XW_ONESHOT,
  XW_DRAW, XW_EVENT, XW_UPDATE, XW_UNHILITE, XW_COMMAND
} XWIDGET_OP;

typedef struct {
  int_2 cw;	/* width of widget in characters */
  int_2 ch;	/* height of widget in characters */
  int_2 cpos;	/* current cursor position in string */
  bool_2 edit;	/* indicates whether text is editable */
  bool_1 insert;	/* current insert mode state (TRUE=on) */
  bool_1 lit;	/* current state of cursor (TRUE=drawn) */
  bool_1 wrap;	/* TRUE=wrap lines longer than X-Widget */
  bool_1 nobox;	/* TRUE=Do not use X-Widget box */
  int_4 lines;	/* number of separate lines */
  int_4 cline;	/* current line position of cursor */
  int_2 cl;	/* char offset at left edge */
  int_2 ct;	/* line offset at top edge */
  M_PTR strings;	/* array of M_PTRS to strings, if 0 it is initted */
  M_PTR xscroll;	/* if not 0, pointer to /SVAL/ structure */
  M_PTR yscroll;	/* if not 0, pointer to /SVAL/ structure */
  int_2 titlebar;	/* TRUE=put prompt in X-Widget title bar */
  int_2 okaybar;		/* TRUE=include OK,CANCEL buttons below */
  real_4 time;		/* TMONITOR's last time SECNDS was checked */
} AVAL;

#define L_aval (32+3*L_M_Ptr)

typedef struct {
  M_PTR items;		/* pointer to menu items string */
  M_PTR itemc;		/* pointer to menu items colors */
  int_2 items_len;	/* length of menu items string */
  int_2 nitems;		/* number of menu items */
  int_2 iw;		/* number of columns of items in menu */
  int_2 ih;		/* number of rows of items in menu */
  int_2 lit;		/* currently highlighted item */
  int_2 cw;		/* character width of each item label */
  int_2 ldef;		/* current item number with > marker */
  int_2 nitemc;		/* current number of colors allocated in itemc */
  char pad[8];		/* stores option menu & title location info */
} MVAL;

#define L_mval (24+2*L_M_Ptr)

typedef struct {
  real_8 vmin;		/* if <= vmax, min value bound */
  real_8 vmax;		/* if >= vmin, max value bound */
  real_8 vinc;		/* increment used with +,-,++,-- buttons */
  real_8 advall;		/* used for internal formatting */
  M_PTR format;	/* pointer to format string */
  int_2 format_len;	/* length of format string */
  int_2 iexp;		/* exponent value */
  int_2 iexpc;		/* cursor position (as power of 10) */
  int_2 lsm;		/* length of numeric string */
  int_2 lsmmax;		/* maximum length of numeric string */
  int_1 buttons;		/* 0=none, 1=top, 2=bottom, 3=both */
  bool_1 cont;		/* TRUE=update control id continously */
  char pad[4];
} DVAL;

#define L_dval (L_M_Ptr+48)

typedef struct {
  int_4 nmsg;		/* max number of messages to display in box */
  int_4 rid;		/* /ID of primitive to monitor (0=all) */
  int_4 last;		/* number of messages last displayed in box */
  char pad[4];
} MSGVAL;

#define L_msgval 16

typedef struct {
  int_1 wtype;		/* x-widget type */
  char dtype;		/* data type */
  int_1 group;		/* control panel group ID */
  bool_1 common_help;	/* if TRUE look for help in XCOMMON.EXP */
  int_4 mask;		/* attributes bit-mask */
  int_4 x, y;		/* position of x-widget's upper left corner */
  int_4 w, h;		/* x-widget dimensions in pixels */
  FSTRING(label, L_max_resname);	/* results label */
  real_8 val;		/* control value  ascii value length */
  M_PTR callback;	/* callback pointer */
  M_PTR aval;		/* ascii control value pointer */
  M_PTR title;		/* x-widget title string pointer */
  int_4 aval_len;	/* ascii value max length */
  int_4 title_len;	/* title string length */
  int_4 id;		/* control ID */
  real_4 pause;		/* pause between repeated events */
  union {
      AVAL av;	/* AVAL x-widget specific fields */
      MVAL mv;	/* MVAL x-widget specific fields */
      DVAL dv;	/* DVAL x-widget specific fields */
      MSGVAL msgv;	/* MSGMONITOR x-widget specific fields */
      int_4 border;	/* FRAME border width (<0 for fill) */
  } u;
/*
 +++
  wgd added
*/
  int_4 MWMIndex;        /*Index of MWM structure for Headless  WGD */
  int_4 MWMMaster;       /*Index of MWM master Macro slot. */
/*
 ---
*/
} XWIDGET;

#define L_xwidget	sizeof(XWIDGET)

#ifndef __cplusplus
void mx_prompt (const char *prompt, char *str, int lenp, int lens);

int mx_kbstring (const char *prompt, char *str, int x, int y,
  int linel, int lenp, int lens);

void mx_dval (const char *prompt, real_8 *v,
  real_8 *vmin, real_8 *vmax, real_8 *vinc, int_4 id, int length);

void mx_fval (const char *prompt, real_4 *v,
  real_4 *vmin, real_4 *vmax, real_4 *vinc, int_4 id, int length);

void mx_lval (const char *prompt, int_4 *v,
  int_4 *vmin, int_4 *vmax, int_4 *vinc, int_4 id, int length);

int mx_menu (int mask, const char *str, int length);

int_4 mx_widget (XWIDGET *xw, XWIDGET_OP op);

int mx_aval (XWIDGET *xw, XWIDGET_OP op);

void mx_dflval (XWIDGET *xw, XWIDGET_OP op);

int mx_mval (XWIDGET *xw, XWIDGET_OP op);

void mx_msgval (XWIDGET *xw, XWIDGET_OP op);
#endif

typedef struct {
  int_4 flag;		/* flag field for MX$SCROLLBAR routine */
  int_4 action;		/* returned action performed (XW_EVENT) */
  real_8 smin, srange;	/* min and range values of scroll bar */
  real_8 tmin, trange;	/* min and range values of trough */
  real_8 step;		/* ratios of smin to move for step */
  real_8 page;		/* ratios of smin to move for page */
  real_8 scale;		/* ratio to scale by for expand/shrink */
  bool_4 dragoutline;	/* FALSE = smooth scroll, TRUE = drag & drop */
  real_4 initial_pause;
  real_4 repeat_pause;

  int_2 x, y, w, h;		/* These fields are private and are to be */
  int_2 s1, sw, swmin, soff;	/* set through other interfaces */
  int_2 a1, a2, arrow;
  bool_1 mxevent;
  int_1 origin;
  int_4 repeat_count;
} SCROLLBAR;

#define L_scrollbar 96

#define SB_EXPAND 1
#define SB_SHRINK 2
#define SB_FULL 3
#define SB_STEPINC 4
#define SB_STEPDEC 5
#define SB_PAGEINC 6
#define SB_PAGEDEC 7
#define SB_DRAG 8

#ifndef __cplusplus
bool_4 mx_scroll (SCROLLBAR *sv, XWIDGET_OP op);

void mx_scroll_loc (SCROLLBAR *sv, int x, int y, int w, int h, int origin);

void mx_scroll_vals (SCROLLBAR *sv, real_8 smin, real_8 srange, real_8 tmin,
		     real_8 trange, real_8 step, real_8 page, real_8 scale);

int mx_scrollbar (SCROLLBAR *sb, int xs, int xe, int ys, int ye,
		  real_8 *ps, real_8 *pe, real_8 qs, real_8 qe);
#endif

#define XM_XWIDGETS_H_
#endif /* XM_XWIDGETS_H_ */
