]> icculus.org git repositories - theoddone33/hhexen.git/blob - include/x11window.h
9dde53486f1837eb3e0bdb970b929df1d5190508
[theoddone33/hhexen.git] / include / x11window.h
1 #ifndef X11WINDOW_H
2 #define X11WINDOW_H
3 //============================================================================
4 //
5 // $Id$
6 //
7 // X11 Pixel Port class
8 //
9 //============================================================================
10
11
12 #include <X11/Xlib.h>
13 #include <X11/Xutil.h>
14 #include <X11/xpm.h>
15
16
17 const long X11WindowDefaultInput = KeyPressMask | KeyReleaseMask |
18                                    ButtonPressMask | ButtonReleaseMask |
19                                    PointerMotionMask |
20                                    ExposureMask | StructureNotifyMask;
21
22 class X11Window
23 {
24 public:
25
26     X11Window( const char* name, Display* dis = 0, int scr = 0,
27                int swidth = 320, int sheight = 200, 
28                long inputMask = X11WindowDefaultInput );
29
30     virtual ~X11Window();
31
32     enum eError
33     {
34         kNone,
35         kOpenDisplay
36     };
37
38     int error() const { return _err; }
39
40     char* errorStr() const { return ErrorMessage[ _err ]; }
41
42     Display* display() { return _display; }
43
44     int screen() { return _screen; }
45
46     Window window() { return _win; }
47
48     void setTitle( const char* text );
49     void setIconName( const char* text );
50
51     int width() { return _width; }
52     int height() { return _height; }
53
54     int displayWidth() { return XDisplayWidth( _display, _screen ); }
55     int displayHeight() { return XDisplayHeight( _display, _screen ); }
56
57     void move( int x, int y );
58     void moveResize( int x, int y, unsigned int w, unsigned int h );
59     void resize( unsigned int newWidth, unsigned int newHeight );
60     void setSizeHints( int minW, int minH, int maxW, int maxH );
61
62     void raise();
63
64     void show();
65     void hide();
66     //int isMapped();
67
68     void iconify();
69     void unIconify();
70     int isIconified();
71
72     int eventsPending() { return XPending( _display ); }
73     void handleNextEvent();
74
75     void flush() { XFlush( _display ); }
76     void sync( Bool discard = False ) { XSync( _display, discard ); }
77
78     void hideCursor();
79     void showCursor();
80
81     KeySym keysym( XKeyEvent* event );
82
83 protected:
84
85     // These virtual event methods are called during handleNextEvent()
86
87     virtual void unknownEvent( XEvent* );
88     virtual void deleteEvent( XEvent* );
89     virtual void configureEvent( XConfigureEvent* );
90     virtual void buttonDown( XButtonEvent* );
91     virtual void buttonUp( XButtonEvent* );
92     virtual void motionEvent( XMotionEvent* );
93     virtual void keyDown( XKeyEvent* );
94     virtual void keyUp( XKeyEvent* );
95     virtual void focusIn( XFocusChangeEvent* );
96     virtual void focusOut( XFocusChangeEvent* );
97     virtual void exposeEvent( XExposeEvent* );
98
99 private:
100
101     Cursor _createNullCursor();
102     Cursor _nullCursor;
103
104     int _err;
105     static char* ErrorMessage[];
106
107     void _set( int mask ) { _flags |= mask; }
108     void _clr( int mask ) { _flags &= ~mask; }                                  
109
110     enum eFlags
111     {
112         kOpenedDisplay = 0x0001,
113     };
114
115     Display* _display;                  // The X11 display connection
116     int _screen;
117     Window _win;                            // The X11 window on the display
118     Atom _wmDeleteAtom;
119
120     //int _screenDepth;
121     //GC _gc;                                   // The window's current graphics context
122
123     int _flags;
124     int _width;
125     int _height;
126
127 };
128
129
130 #endif // X11WINDOW_H