#ifndef XM_XSTRUCTURES_H_
/*
 **************************************************************************
 
  $Id: xstructures.h,v 1.1 2008/07/19 22:30:29 jgs Exp $
 
  Description:	Common block shared in X-based graphics routines 
 
 **************************************************************************
*/

#include "fcinterface.h"
#include "cdefs.h"
#ifndef __cplusplus
#include "xglobals.h"
#endif

/*
  Keypress flags for special keys set in Mx.key_press by MX$IFEVENT, and
  sent to MX$CLIENT_EVENT and MX$ARROW.
*/

#define L_ArrowLeft 1001
#define L_ArrowRight 1002
#define L_ArrowUp 1003
#define L_ArrowDown 1004
#define L_ReturnKey 1005
#define L_InsertKey 1006
#define L_DeleteKey 1007
#define L_F14Key 1008
#define L_TabKey 1009
#define L_HelpKey 1010

/*
  Keypress mask bits for MX.state_mask
*/

#define L_ShiftKeyMask 1
#define L_ControlKeyMask 2
#define L_Mod1KeyMask 4
#define L_Mod2KeyMask 8
#define L_Mod3KeyMask 16
#define L_Mod4KeyMask 32
#define L_Mod5KeyMask 64
#define L_Button1Mask 128
#define L_Button2Mask 256
#define L_Button3Mask 512
#define L_ClientEventMask 32768

#define L_AvalRedraw -2

/*
  COLOR flags for MX$COLORTEXT, MX$DRAW_LINES, MX$TRACE, etc.
*/

#define L_BGColor 0
#define L_FGColor -1
#define L_XORColor -2
#define L_XWFGColor -3
#define L_XWBGColor -4
#define L_XWTSColor -5
#define L_XWBSColor -6
#define L_XWLoColor -7
#define L_NoColor -8

/*
  MX$FILL_POLYGON flags
*/

#define L_convex 1
#define L_nonconvex -1

/*
  MX$DRAW_MODE flags
*/

#define L_solid 800
#define L_dashed 801
#define L_RModeOff 900
#define L_RModeOn 901

#define L_PixelSymbol 1
#define L_CircleSymbol 2
#define L_SquareSymbol 3
#define L_PlusSymbol 4
#define L_XSymbol 5
#define L_TriangleSymbol 6
#define L_ITriangleSymbol 7

/*
  MX$CLIENT_EVENT flags
*/

#define L_SendButtonPress 1
#define L_SendButtonRelease -1
#define L_SendKeyPress 2
#define L_SendKeyRelease -2
#define L_SendMotion 3
#define L_UserEvents_Msg 4
#define L_Deiconify_Msg 5
#define L_Iconify_Msg -5
#define L_Focus_Msg 6
#define L_MoveResize_Msg 7
#define L_Move_Msg 8
#define L_Resize_Msg 78
#define L_Teach_Msg 999
#define L_Learn_Msg -999

/*
  MX$DRAWAXIS flags
*/

#define L_gridlines 1
#define L_noaxisbox 2
#define L_noxtics 4
#define L_noytics 8
#define L_noxtlab 16
#define L_noytlab 32
#define L_noxplab 64
#define L_noyplab 128
#define L_xontop 256
#define L_yonright 512
#define L_exactbox 1024
#define L_insidelab 2048
#define L_noxspecs L_noxtics+L_noxtlab+L_noxplab
#define L_noyspecs L_noytics+L_noytlab+L_noyplab

/*
  Widget Callback Structure
*/

#define L_CBenable 1
#define L_CBitem 2
#define L_CBnomask 0
#define L_CBautomask 1
#define L_CBexit -1
#define L_CBnoaction 0
#define L_CBokaction 1

typedef struct {
  int_4 item;	/* selected item */
  int_4 mode;	/* callback mode */
  int_4 optmask;	/* mask of toggleable items */
  int_4 curmask;	/* state of toggleable items */
  int_4 status;	/* return status of callback routine */
  int_4 flags;	/*  */
  real_8 value;	/*  */
} CBSTRUCT;

typedef void (*MX_CBFUNC)(CBSTRUCT*);
typedef void (*MX_VOIDFUNC)();

/*
  Following is the structure for specifying real world coordinate system in
  a window.  Structure contains real world and pixel coordinates of a square
  area in the window.  x1 and x2 always specify the left and right edges of
  the square respectively.  y1 and y2 are the top and bottom.  xmin, xmax
  ymin and ymax specify real world values at each of these edges.  Mapping
  of pixel edges to real world values by the graphics libraries depends on
  value of the origin field in the Mx structure below.  Mx.origin's value
  can be 1, 2, 3 or 4 specifying the 4 quadrants of a cartesion coordinate
  system.  The mapping of edges is displayed below:
 
                       ymax    |    ymax
                   x          x|x          x
                   m     2    m|m    1     m
                   a          i|i          a
                   x          n|n          x
                       ymin    |    ymin
                  -------------+--------------
                       ymin    |    ymin
                   x          x|x          x
                   m     3    m|m    4     m
                   a          i|i          a
                   x          n|n          x
                       ymax    |    ymax
 
  X-Plot is an example of a quadrant 1 plotting field.  stk.ymin is the
  bottom edge of the screen and stk.ymax the top.  X-Raster is a quadrant 4
  field where the stk.ymin value is at the top of the screen and stk.ymax
  is at the bottom (y values increase as you travel lower in the window.)
 
*/

#define L_stkstruct 64
#define L_xstack L_stkstruct

typedef struct {
  real_8 xmin;	/* real world val at x1(origin=1,4) or x2(origin=2,4) */
  real_8 xmax;	/* real world val at x2(origin=1,4) or x1(origin=2,4) */
  real_8 ymin;	/* real world val at y2(origin=1,2) or y1(origin=3,4) */
  real_8 ymax;	/* real world val at y1(origin=1,2) or y2(origin=3,4) */
  real_8 xscl;	/* ratio of X real world units to pixel units */
  real_8 yscl;	/* ratio of Y real world units to pixel units */
  int_4 x1;	/* left edge relative to window (pixels) */
  int_4 y1;	/* top edge relative to window (pixels) */
  int_4 x2;	/* right edge relative to window (pixels) */
  int_4 y2;	/* bottom edge relative to window (pixels) */
} STKSTRUCT;

/*
  structure for specifying a pixmap image
*/

#define L_mapstruct 12

typedef struct {
  int_2 x, y, w, h;
  int_4 ip;
} MAPSTRUCT;

#define L_pixstruct 4

typedef struct {
  int_2 x;
  int_2 y;
} PIXSTRUCT;

#define L_FreeMap 1
#define L_NewMap 2
#define L_PutMap 4
#define L_MoveMap 8
#define L_ClipMap 16

/*
 ************************************
  Mx common graphics context structure
 ************************************
*/

#define L_stack 10
#define L_color 64
#define L_zoommax 10

typedef struct {

  FSTRING(name, 20);	/* name of primitive (used for MHELP) */
  FSTRING(title, 40);	/* title displayed in window title bar */
  FSTRING(node, 40);	/* display server node to plot to */
  FSTRING(wspace, 80);/* RDA: CDE workspace(s) to display to (names or #'s) */

  int_4 left;		/* distance of win from left edge of screen (pixels) */
  int_4 top;		/* distance of win from top edge of screen (pixels) */
  int_4 width;		/* width of window (pixels) */
  int_4 height;		/* height of window (pixels) */

  int_4 screen_width;	/* width of screen (pixels) */
  int_4 screen_height;	/* height of screen (pixels) */

  int_4 text_size_lock;	/* /XTS value, locks text font size if abs val > 1 */
  int_4 text_w;		/* width of text font in pixels */
  int_4 text_h;		/* height of text font (plus 1/3 for line spacing) */

  bool_4 breakflag;	/* graphics break flag, set by window Close */
  bool_4 icon;		/* is window currently iconified ? */
  bool_4 noevent;/* process user events ? (mouse clicks, keyboard, etc) */
  int_4 origin;		/* Mx.stk() origin quadrant (1, 2, 3 or 4) */
  bool_4 rmode;		/* use double lines and extra GC for XOR graphics ? */
  bool_4 no_arrow_move;	/* disallow mouse moves with arrow keys ? */
  int_2 noexit;		/* value disabling window exit: 1=CR,2=menu,3=WinMgr */
  int_2 xs;		/* /XS value for macros with window setup files */

  FSTRING(xtag, 20);	/* result to write LM click X location to */
  FSTRING(ytag, 20);	/* result to write LM click Y location to */
  FSTRING(ztag, 20);	/* result to write LM click Z location to */
  FSTRING(xytag, 20);	/* result to write LM click X+Y location to */

  bool_4 exposure;	/* part or all of window exposed ? */
  bool_4 resize;		/* window resized ? */
  bool_4 motion_notify;	/* mouse moved in window ? */
  int_4 xpos;		/* x pixel loc of mouse when event occurred */
  int_4 ypos;		/* y pixel loc of mouse when event occurred */
  int_4 button_press;	/* mouse button pressed: 1=LM, 2=MM, 3=RM */
  int_4 button_release;	/* mouse button released: 1=LM, 2=MM, 3=RM */
  int_2 key_press;	/* integer value of keyboard key pressed (0 if none) */
  char key_char;	/* ASCII character of keyboard key pressed */
  char key_upchar;	/* upcase of key_char above */
  int_u4 state_mask;	/* state of modifier keys and mouse buttons */

  int_1 xi;	/* -1=normal, 1=white bg, 2=B&W white bg, -2=B&W */
  int_1 xcmax;	/* /XCMAX switch - limits the number of colors allocated */
  int_2 shrcmap;	/* /XCSHR switch for ds prims sharing colormaps */
  int_2 clast;		/* internal field */
  int_2 parent;		/* parent window xs id (if <= 0 user root window) */
/*
  	  RDA: change all color-carrying pixels to 4-bytes!!!! 
*/
  int_u4 xwlo;	/* color pixel location of xwidget back contrast color */
  int_u4 xwbs;	/* color pixel location of xwidget bottom shadow color */
  int_u4 xwts;		/* color pixel location of xwidget top shadow color */
  int_u4 xwbg;		/* color pixel location of xwidget background color */
  int_u4 xwfg;		/* color pixel location of xwidget foreground color */
  int_u4 tpix;		/* scratch color area for mx_colorlab */
  int_u4 white;		/* color pixel location of fg color */
  int_u4 black;		/* color pixel location of bg color */
  int_u4 pixel[L_color];	/* color pixel locations of allocated colors */

/*
  	 -- (optional) requested screen Visual (colormap) characteristics
*/
  int_4 visDepth;     /* /VISDEPTH= typically 4,8,24 bits - Xserver dependent */
  int_4 visClass;    /* /VISCLASS= 0..5 = StaticGray .. TrueColor,DirectColor */

  int_4 visID;        /* /VISUALID=    Explicit ID (as from xdpyinfo utility) */
  int_4 visDebug;        /* /VISUALDEBUG= Debug flag */
  int_4 scanline_pad;	/* pixmap/window image parameter for selected visual */
  int_4 bits_per_pixel;	/* pixmap/window image parameter for selected visual */

/*
 +++
  jdh added
*/
  int_4 font_id;
  int_4 headless;
/*
 ---
*/

/*
 +++
  DR 11175
*/
  int_4 disable_menu;
  int_4 filler;
/*
 ---
*/

  STKSTRUCT stk[L_stack];	/* real world coordinate systems */
  int_4 level;			/* current valid stk structure in array */

  int_4 zlevel;			/* internal MX$ZOOM fields */
  MAPSTRUCT zoom[L_zoommax];

#ifdef __cplusplus
  private:
  int_u1 GLOBALS[160];	/* internal graphics library globals */
#else
  XGLOBALS glob;	/* internal graphics library globals */
#endif

} MX;

#define L_Mx sizeof(MX)


#define XM_XSTRUCTURES_H_
#endif /* XM_XSTRUCTURES_H_ */
