00001 #ifndef _WINC_XWINDOW
00002 #define _WINC_XWINDOW
00003
00004 #include <X11/Xlib.h>
00005
00006 #include <WXP/Device.h>
00007 #include <WXP/Image.h>
00008 #include <WXP/Listener.h>
00009 #include <WXP/Point.h>
00010 #include <WXP/Points.h>
00011 #include <WXP/Rect.h>
00012 #include <WXP/String.h>
00013
00014 namespace WXP {
00015 class XWindow : public Device, public Listener {
00016 struct XFrame {
00017 char title[50];
00018 Pixmap pixmap;
00019 float delay;
00020 int flag;
00021 };
00022
00023 struct XCallbackItem {
00024 int type;
00025 Window window;
00026 Listener *listener;
00027 const void *data;
00028 struct XCallbackItem *next;
00029 };
00030
00031 static Display *display;
00032 static int managed;
00033 static int num_errors;
00034 static int error;
00035 static int error_print;
00036 static XCallbackItem *callbackroot;
00037 static XWindow *windows[10];
00038 static int num_windows;
00039
00040 int type;
00041 bool inverse;
00042 int width, height;
00043 int x, y;
00044 int fixed;
00045 bool mapped;
00046 bool icon;
00047 bool opened;
00048 char name[30];
00049 char connect[40];
00050 char title[60];
00051 int window_num;
00052 int show_win_num;
00053
00054 int screen;
00055 Colormap color_map;
00056 Window window;
00057 Window dwindow;
00058 Window drawing;
00059 Visual *visual;
00060 int depth;
00061
00062 Cursor cursor_x;
00063 Cursor cursor_ptr;
00064 Cursor cursor_move;
00065 Cursor cursor_loop;
00066 Cursor cursor_stop;
00067 Cursor cursor_draw;
00068 Cursor cursor_rect;
00069 Cursor cursor_text;
00070 Cursor cursor_wait;
00071 int cursor;
00072
00073 int fore_color;
00074 int back_color;
00075 char background[40];
00076 int bg_color;
00077
00078 XRectangle clip;
00079
00080 GC base_gc;
00081 GC draw_gc;
00082 GC line_gc;
00083 GC text_gc;
00084 GC fill_gc;
00085 GC mark_gc;
00086 int line_style;
00087 int line_width;
00088 Pixmap fill_pat[20];
00089 int text_halign;
00090 int text_valign;
00091 XFontStruct *font_info;
00092 int image_halign;
00093 int image_valign;
00094
00095
00096 int max_frame;
00097 int num_frame;
00098 int cur_frame;
00099 int looping;
00100 int direct;
00101 float delay;
00102 float end_delay;
00103 int start_frame;
00104 int end_frame;
00105 XFrame *frames;
00106
00107 int initStatic();
00108 int printImage( XImage *ximage );
00109
00110 public:
00111 XWindow();
00112 ~XWindow();
00113 int init();
00114 int setParam( const char *str );
00115 int open();
00116 int getDevice( String &str );
00117 int resize(float rwidth, float rheight);
00118 int addCallback( const char *event, Listener *list, const void *data );
00119 int doCallback( const char *ev_str, const char *ev_data );
00120 void callback( const char *ev_str, const char *ev_data, const void *data );
00121 int close();
00122 int setFocus();
00123 int unsetFocus();
00124 int update();
00125 int clear();
00126 int clearRect( Rect &rect );
00127 int manage();
00128 int unmanage();
00129 int setTitle( const char *str );
00130 inline const char *getTitle(){ return title; };
00131 int setIcon(bool val);
00132 int setFixed(bool val);
00133 int setCursor(int type);
00134 inline int getCursor(){ return cursor; };
00135 int setInverse(bool val);
00136 bool getInverse();
00137 int setBackground( const char *str );
00138 int setSize(float rwidth, float rheight);
00139 int getSize(float &width, float &height);
00140 inline float getWidth() { return width; };
00141 inline float getHeight() { return height; };
00142 int setOffset(float rx, float ry);
00143 int getOffset(float &x, float &y);
00144 int getCoords( Rect &rect );
00145 Rect getCoords();
00146 int allocColor( float red, float grn, float blu );
00147 int setColor( int type, int ind );
00148 int setLineWidth( int type, float width );
00149 int setLineStyle( int type, int style );
00150 int setFillStyle( int type, int style );
00151 int drawLine( int type, float x1, float y1, float x2, float y2 );
00152 int drawLine( int type, Points &pts );
00153 int drawFill( int type, Points &pts );
00154 int setImageAlign( int h, int v );
00155 int drawImage( Image &image, float x, float y );
00156 int drawImage( Image &image, int bgcolor, float x, float y );
00157 int getImage( Image &image );
00158 int setFont( const char *name );
00159 int setTextAlign( int h, int v );
00160 int drawText( Point &pt, const char *str );
00161 Rect getClip();
00162 int setClip( float x1, float y1, float x2, float y2 );
00163 int setClip( Rect rect );
00164 Pixmap getFramePixmap( int ind );
00165 int copyFrame( int dest, int src );
00166 int displayFrame( int ind );
00167 int clearFrame( int ind );
00168 int newFrame( int ind );
00169 int newFrame();
00170 bool isLooping();
00171 int getFrame();
00172 int setFrame( int ind );
00173 int incFrame( int step );
00174 int deleteFrame( int ind );
00175 int deleteFrame();
00176 int getNumFrames();
00177 int loopRate( int dir );
00178 int toggleLoop();
00179 int message( const char *str );
00180 int printGC( int type );
00181 int bell( int len );
00182
00183 static int mainloop();
00184 static int waitEvent();
00185 static int checkEvent();
00186 static int addWindow( Window &win );
00187 static int processEvent( XEvent *event );
00188 static int procCallback( Window win, int type, const char *ev_str, const char *ev_data );
00189 static int newCallback( Window win, int event, Listener *list, const void *data );
00190 static int deleteCallbacks( Window );
00191 static int errorHandler( Display *dpy, XErrorEvent *error );
00192 static int errorIOHandler( Display *dpy );
00193
00194 static const int AnyEvent = 0;
00195 static const int Redraw = 50;
00196
00197 static const int WINDOW = 1;
00198 static const int PIXMAP = 2;
00199
00200 static const int CURSOR_X = 0;
00201 static const int CURSOR_PTR = 1;
00202 static const int CURSOR_MOVE = 2;
00203 static const int CURSOR_LOOP = 3;
00204 static const int CURSOR_STOP = 4;
00205 static const int CURSOR_DRAW = 5;
00206 static const int CURSOR_RECT = 6;
00207 static const int CURSOR_PLUS = 6;
00208 static const int CURSOR_TEXT = 7;
00209 static const int CURSOR_WAIT = 8;
00210 };
00211 }
00212 #endif