/* **********************************************************************
 * *                                                                    *
 * *    Global variables and functions for IRIS X interface.            *
 * *                                                                    *
 * **********************************************************************
 * File: iris/xuif/iris.h
 *
 *                        COPYRIGHT (c) 2005  BY
 *          SIGMET INCORPORATED, WESTFORD MASSACHUSETTS, U.S.A.
 * 
 * THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND  COPIED
 * ONLY  IN  ACCORDANCE WITH  THE  TERMS  OF  SUCH  LICENSE  AND WITH THE
 * INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE  OR  ANY OTHER
 * COPIES  THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
 * OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF  THE  SOFTWARE  IS  HEREBY
 * TRANSFERED.
 */

#ifndef IRIS_H
#define IRIS_H

#ifdef IRIS_ALLOCATE
#define EXTERN
#else
#define EXTERN extern
#endif

/* Globals */

EXTERN pid_t irtdisp_pid_c;
EXTERN pid_t iris_servers_lst_pid_c;
EXTERN pid_t iaudio_setup_pid_c;


/* Different IRIS MENUS */
#define MENU_AMS     1
#define MENU_DBG     2
#define MENU_DPYOPT  3
#define MENU_IRIS    4
#define MENU_ISM     5 
#define MENU_MSG     6
#define MENU_NST     7
#define MENU_OVR     8
#define MENU_PCF     9
#define MENU_POM    10 
#define MENU_PRJ    11 
#define MENU_PSC    12
#define MENU_RST    14
#define MENU_TAB    15
#define MENU_TAP    16
#define MENU_TCF    17
#define MENU_TSC    18



/* Application context and top level widgets  
** Used for interfacing with viewcenter stuff or UIM/X
*/
EXTERN XtAppContext    UxAppContext;
EXTERN Widget          UxTopLevel;
EXTERN Display         *UxDisplay;
EXTERN int             UxScreen;
EXTERN Colormap        colormap_c;
EXTERN XVisualInfo     visualInfo_c;
EXTERN Window          top_wnd_c;
EXTERN SINT4           top_depth_c;
EXTERN GC              copy_gc_c;


/* Application context and top level widgets */

EXTERN XtAppContext app_context_c;
EXTERN Display *main_display_c;
EXTERN Widget  iris_top_c;
EXTERN Widget  iris_main_c;
EXTERN Widget  iris_form_c;


EXTERN Widget  top_mainbar;
EXTERN Widget  top_exitbtn, top_exitpdw;
EXTERN Widget  top_menubtn, top_menupdw;
EXTERN Widget  top_connbtn, top_connpdw;
EXTERN Widget  top_setupbtn, top_setuppdw;
EXTERN Widget  top_helpbtn, top_helppdw;
EXTERN Widget  top_drawareafrm, top_drawarea;

void top_exit_cbf
  (Widget wgt_a,
   int idx_a,
   XmPushButtonCallbackStruct* cbd_a
   );
void top_menu_cbf
  (Widget wgt_a,
   int idx_a,
   XmPushButtonCallbackStruct* cbd_a
   );
void update_cust_serv_btns(void);

void top_conn_cbf
  (Widget wgt_a,
   int idx_a,
   XmPushButtonCallbackStruct* cbd_a
   );
void top_setup_cbf
  (Widget wgt_a,
   int idx_a,
   XmPushButtonCallbackStruct* cbd_a
   );

void top_drawarea_exp_cbf
  (Widget wgt_a,
   XtPointer client_data_a,
   XmDrawingAreaCallbackStruct* cbd_a
   );

void buttonPress_cbf( Widget w, XtPointer client_data,
   XButtonPressedEvent *evt_a );
void button1Motion_cbf( Widget w, XtPointer client_data,
   XPointerMovedEvent *evt_a );
void buttonRelease_cbf( Widget w, XtPointer client_data,
   XButtonReleasedEvent *evt_a );


void createBackgroundPM(void);
void setDisconnectBackground(void);
void setConnectBackground(void);

void copyTopPmToWnd(UINT4 ix_a, UINT4 iy_a, UINT4 iw_a, UINT4 ih_a);


/*
void cbf
  (Widget wgt_a,
   char  *tag_a,
   XmPushButtonCallbackStruct* cbd_a
   );
*/

EXTERN Widget  ams_main_c;
EXTERN Widget  dbg_main_c;
EXTERN Widget  ism_main_c;
EXTERN Widget  msg_main_c;
EXTERN Widget  nst_main_c;
EXTERN Widget  ovr_main_c;
EXTERN Widget  pcf_main_c;
EXTERN Widget  pom_main_c;
EXTERN Widget  prj_main_c;
EXTERN Widget  psc_main_c;
EXTERN Widget  rst_main_c;
EXTERN Widget  tab_main_c;
EXTERN Widget  tap_main_c;
EXTERN Widget  tcf_main_c;
EXTERN Widget  tsc_main_c;

void iris_menu_switch( int idx_a );
void displayIrisMenubarImage(void );
void create_ams(void); 
void destroy_ams(void); 

void create_dbg(void); 
void create_err(void);
void create_ism(void);

void create_msg(void);
void destroy_msg(void);

void create_msg_pop(void);

void create_nst(void);
void destroy_nst(void);

void create_ovr(void); 
void destroy_ovr(void); 

void create_pcf(void); 
void destroy_pcf(void); 

void create_pom(void); 
void destroy_pom(void); 

void create_prj(void); 
void destroy_prj(void); 

void create_psc(void);
void destroy_psc(void);

void create_rst(void);
void destroy_rst(void);

void create_tap(void); 
void destroy_tap(void); 

void create_tcf(void);
void destroy_tcf(void);

void create_tsc(void);
void destroy_tsc(void);

EXTERN Widget  err_main_c;
void    write_err( const char* smsg_a );

EXTERN Widget  warn_msg_main_c;
void   create_warn_msg(void);
void   write_warn_msg( const char* smsg_a );
void   warn_msg_cancel_cbf( Widget wgt, char* tag, XmAnyCallbackStruct* cbd );

EXTERN Widget  msg_popup_c;
void    write_msg( const char* smsg_a );

EXTERN Widget msg_question_c;
void   create_msg_question(void);
void   write_msg_question(const char *smag_a, XtCallbackProc question_ok_cbf);
void   remove_msg_question_cbf(Widget wgt, char* tag, XmAnyCallbackStruct* cbd);



/* Customize Servers */

EXTERN Widget tops_frm;
EXTERN Widget tops_lst,tops_edittxt;

EXTERN Widget tops_wgts[20]; 
EXTERN Widget tops_wgtsHost[20]; 
void   tops_create(void);
void tops_save_cbf (Widget wgt, char* tag, XmAnyCallbackStruct* cbd);

EXTERN int    numOfServ;


/* Vertical and Horzontial Font Scale */
#define  VERT_FONT_SCALE  18
#define  HORZ_FONT_SCALE  9

/* Site Information   */

EXTERN struct server_site_info    siteinfo_c;
EXTERN struct dsp_info*           dspinfo_c;
EXTERN struct server_overlay_dir  overinfo_c;
EXTERN struct overlay_mask_dir    overmaskinfo_c;
EXTERN struct serv_dsp_manual_setup dspsetup_c;
EXTERN struct ant_manual_setup    antsetup_c;
EXTERN struct serv_ymds_time      sitetime_c;
EXTERN SINT4                      ilast_message_c;


/* Function Prototype */

void iris_timer_cbf( XtPointer, XtIntervalId * );
void tcf_request( const char* );
void pcf_request(const char *sfnam_a, SINT2 itype_a);

/* Server-Client communication in file iris_server.c */

UINT2 request_to_server
  (const char* sbufptr, const char* sreply,
   const void* ibufptr, const SINT4 icnt );
UINT2 simple_request_to_server( char* sbufptr );
void iris_server_alive_timer_cbf
( XtPointer cdata_a, XtIntervalId *id_a );

/* Main Resource database */

EXTERN XrmDatabase main_rdbase;

void ams_serv_recv( char* stoks[], char* idata_ptr, SINT4 idata_len);
void ism_serv_recv( char* stoks[], char* idata_ptr, SINT4 idata_len);
void msg_serv_recv( char* stoks[], char* idata_ptr, SINT4 idata_len);
void nst_serv_recv( char* stoks[], char* idata_ptr, SINT4 idata_len);
void ovr_serv_recv( char* stoks[], char* idata_ptr, SINT4 idata_len);
void pcf_serv_recv( char* stoks[], char* idata_ptr, SINT4 idata_len);
void pom_serv_recv( char* stoks[], char* idata_ptr, SINT4 idata_len);
void prj_serv_recv( char* stoks[], char* idata_ptr, SINT4 idata_len);
void psc_serv_recv( char* stoks[], char* idata_ptr, SINT4 idata_len);
void rst_serv_recv( char* stoks[], char* idata_ptr, SINT4 idata_len);
void site_serv_recv( char* stoks[], char* idata_ptr, SINT4 idata_len);
void tap_serv_recv( char* stoks[], char* idata_ptr, SINT4 idata_len);
void tcf_serv_recv( char* stoks[], char* idata_ptr, SINT4 idata_len);
void tsc_serv_recv( char* stoks[], char* idata_ptr, SINT4 idata_len);

/* Top Level Error Message */

#define SMSG_COMMERROR "\
Communication error please consult IRIS manager."

#define SMSG_DUALSERVER "\
A new connection to IRIS server can not be established until\n\
the existing link is disconnected first."

#define SMSG_FAILDISPLAY "\
A X-display is missing. A X-platform is needed."

#define SMSG_NOTCONN "\
Use Connect Pulldown menu to select an IRIS server.\n\
This menu can not be used  until  a  connection to \n\
an IRIS server is made."


/*-----------------------------------------------------------------------------
    Routines here use iris.h and other shared resources of menus. Whereas the
 rounties in the [iris.xsig] are more isolated in scope.
*/
SINT2 isite_num_f( char* snam_a );
char* sxfer_count_f( SLST_HDR* lsthdr_a );
char* sxfer_max_f( SLST_HDR* lsthdr_a );
SINT2 iwindow_count_f( struct server_site_info *siteinfo_a );
SINT2 itape_count_f( struct server_site_info *siteinfo_a,
                     struct device_info tape_list[]);
SINT2 iscreen_count_f( struct server_site_info *siteinfo_a );
char* sscreen_lst_f( struct server_site_info *siteinfo_a );
SINT2 istr_to_devid_f( struct server_site_info *siteinfo_a, char* snam_a );

void  XsMergeDeflXrdb( XrmDatabase* rdb_main, char* sfname );
void  XsMergeUserXrdb( XrmDatabase* rdb_main, char* sfname );
void  XsCombineFileDatabase(const char *rf_a, XrmDatabase *main_rdb_a);


EXTERN Pixel irisBgColorTxt_c;
EXTERN Pixel irisFgColorTxt_c;
EXTERN Pixel irisBgColorPB_c;
EXTERN Pixel irisYelColor_c;
EXTERN Pixel irisRedColor_c;
EXTERN Pixel irisBlackColor_c;
EXTERN Pixel irisWhiteColor_c;
void  IrisSetBgWarningYel( Widget wgt_a );
void  IrisSetBgWarningRed( Widget wgt_a );
void  IrisSetBgDefault( Widget wgt_a );

SINT2 lcheck_valid_chars(const char *str_a);

/* Use to select with type of pixmap 
** we are using.  This can be color or black and white */
#define  PIXMAP_TYPE_ICON   1
#define  PIXMAP_TYPE_LABEL  2
#define  PIXMAP_SENSITIVE   1
#define  PIXMAP_DESENSITIVE 2

void XsSetPixmap(UINT4 pixmap_type_a, UINT4 pixmap_sens_type_a,
                 Widget wgt_a, const char* sfnam_a );

#undef EXTERN
#endif

