//  
//  Copyright (c) 1994 by Mike Romberg (  romberg@md.fsl.noaa.gov )
//  Debugged and Featurized by Michael Hemy
//
//  This file may be distributed under terms of the GPL
//

#ifndef _xwin_h_
#define _xwin_h_

#include <stdlib.h>
#include <string.h>
extern "C"
{
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#ifdef needed
#include <X11/cursorfont.h>	/* For erasing cursor - not important	*/
#endif
}

class XWin {
public:
  XWin(int argc, char *argv[], int width, int height, const char *title, 
       const char *foreground, const char *background, 
       const char *font, const char *color1, const char *color2,
       const char *color3, const char *colorn);
       
  virtual ~XWin();
  virtual void draw( void )=0;
  virtual void visnotify( void ) { draw(); }
  virtual void mapnotify( void ) { draw(); }
  virtual void clearwin();
  virtual int  getforegroundcolor( const char *name );
  virtual int  getbackgroundcolor( const char *name );
  void drawstr( int x, int y, const char *str ) 
    { XDrawImageString( disp_, window_, gc_, x, y, str, strlen( str ) ); }
  virtual void resize();
  void resize( int width, int height ){ 
    width_ = width;  height_ = height; 
    XResizeWindow( disp_, window_, width_, height_ ); 
  }
  virtual void keyrelease(char *ch);
  virtual void buttonrelease();
  virtual void buttonpress();
  virtual void checkevent();
  void map( void ) { XMapWindow( disp_, window_ ); }
  void unmap( void ) { XUnmapWindow( disp_, window_ ); }
  Display *display( void ) { return disp_; }
  Window window( void ) { return window_; }
  int height( void ) { return height_; }
  int width( void ) { return width_; }
  const char *title( void ) { return title_; }
  void title( const char *title );
  const char *iconname( void ) { return iconname_; }
  void iconname( const char *name );
  int screen( void ) { return screen_; }
  int depth( void ) { return depth_; }
  int fg_pixel( void ) { return fg_pixel_; }
  int bg_pixel( void ) { return bg_pixel_; }
  int busy_pixel( int i ) { return busy_pixel_[i]; }
  int free_pixel( void ) { return free_pixel_; }
  struct XFontStruct *xfont( void ) { return xfont_; }
  int font_height( void ) { return font_height_; }
  int font_width( void ) { return font_width_; }
  int yoff_above( void ) { return yoff_above_; }
  int yoff_below( void ) { return yoff_below_; }
  int xoff_left( void ) { return xoff_left_; }
  int xoff_right( void ) { return xoff_right_; }
  GC gc( void ) { return gc_; }
  Font font( void ) { return font_; }
  void flush( void ) { XFlush( disp_ ); }
  int positionit( void ) { return positionit_; }
protected:
  Display *disp_;
  Window window_;
  Cursor cursor_;
  int height_, width_, screen_, depth_, fg_pixel_, bg_pixel_;
  int busy_pixel_[4];
  int free_pixel_;
  int yoff_above_;
  int yoff_below_;
  int xoff_left_;
  const int xoff_right_ = 8; 
  char *title_, *iconname_;
  GC gc_;
  Font font_;
  struct XFontStruct *xfont_;
  int font_height_;
  int font_width_;
  XSizeHints hint_;
  int positionit_;

  void init(int width, int height, const char *title, 
	    const char *foreground, const char *background,
	    const char *font, const char *color1, const char *color2,
	    const char *color3, const char *colorn);
private:
};

#endif
