00001 #ifndef __OS_CLASS_H
00002 #define __OS_CLASS_H
00003
00005 #include <xbitmapimage.h>
00006 #include <xfont.h>
00007 #include <xevent.h>
00008 #include <xapplication.h>
00009 #include <xpainter.h>
00010 #include <xfont.h>
00011 #include <xfontmetrics.h>
00012
00013 typedef pthread_t OsThread;
00014 typedef XFont *OsFont;
00015 typedef XApplication OsApplication;
00016 typedef XPainter *OsPainter;
00017 typedef XBitmapImage *OsBitmap;
00018 typedef char16 OsChar;
00019
00020 #undef Bool
00021
00022 class GMessage : public XlibEvent
00023 {
00024 friend class XApplication;
00025 XEvent Local;
00026
00027 XEvent *GetLocal()
00028 {
00029
00030
00031
00032 Local.type = ClientMessage;
00033 return &Local;
00034 }
00035
00036 GMessage(XEvent *e) : XlibEvent(e)
00037 {
00038 }
00039
00040 public:
00041 GMessage(int M = 0, int A = 0, int B = 0) : XlibEvent(GetLocal())
00042 {
00043 m() = M;
00044 a() = A;
00045 b() = B;
00046 }
00047
00048 int &m() { return (int&) (GetEvent()->xclient.message_type); }
00049 int &a() { return (int&) (Data()[0]); }
00050 int &b() { return (int&) (Data()[1]); }
00051
00052 long *Data()
00053 {
00054 return GetEvent()->xclient.data.l;
00055 }
00056 };
00057
00059 #define MsgCode(Msg) ((Msg->type() == ClientMessage) ? ((GMessage*)Msg)->m() : 0)
00060 #define MsgA(Msg) ((Msg->type() == ClientMessage) ? ((GMessage*)Msg)->a() : 0)
00061 #define MsgB(Msg) ((Msg->type() == ClientMessage) ? ((GMessage*)Msg)->b() : 0)
00062
00063 extern GMessage CreateMsg(int m, int a, int b);
00064
00066 template <class q>
00067 class XView : public q
00068 {
00069 friend class GView;
00070
00071 protected:
00072 GView *v;
00073 bool _Paint;
00074
00075 void OnClick(XlibEvent *e, bool down, bool dbl, bool move);
00076 bool OnKey(XlibEvent *e, bool down);
00077 void setBackgroundMode(ViewBackground b) {}
00078
00079 public:
00080 XView(GView *view, bool p = true);
00081 XView(GView *view, Window Existing);
00082 ~XView();
00083
00084 void _SetWndPtr(void *p);
00085 void *_GetWndPtr();
00086
00087
00088 void resizeEvent(XlibEvent *e);
00089 void paintEvent(XlibEvent *e);
00090 void customEvent(XlibEvent *e);
00091 void notifyEvent(int i = 0);
00092
00093
00094 void mousePressEvent(XlibEvent *e);
00095 void mouseDoubleClickEvent(XlibEvent *e);
00096 void mouseReleaseEvent(XlibEvent *e);
00097 void mouseMoveEvent(XlibEvent *e);
00098 void leaveEvent(XlibEvent *e);
00099 void enterEvent(XlibEvent *e);
00100 void wheelEvent(XlibEvent *e);
00101
00102
00103 void focusInEvent(XlibEvent *e);
00104 void focusOutEvent(XlibEvent *e);
00105
00106
00107 bool keyPressEvent(XlibEvent *e);
00108 bool keyReleaseEvent(XlibEvent *e);
00109 };
00110
00111 typedef XView<XWidget> DefaultOsView;
00112
00113 class XWindow : public XMainWindow
00114 {
00115 GWindow *Wnd;
00116
00117 public:
00118 XWindow(GWindow *wnd);
00119 ~XWindow();
00120
00121 void _SetWndPtr(void *p);
00122 void *_GetWndPtr();
00123 void SetModal();
00124
00125 void resizeEvent(XlibEvent *re);
00126 void closeEvent(XlibEvent *ce);
00127 void paintEvent(XlibEvent *e);
00128 void customEvent(XlibEvent *e);
00129 void propertyEvent(XlibEvent *e);
00130 };
00131
00132 class Xgc : public XObject
00133 {
00134 GC Gc;
00135 Pixmap Pix;
00136
00137 public:
00138 Xgc(Pixmap p)
00139 {
00140 XGCValues n;
00141 Pix = p;
00142 Gc = XCreateGC( XDisplay(),
00143 Pix,
00144 0,
00145 &n);
00146 }
00147
00148 ~Xgc()
00149 {
00150 if (Gc)
00151 XFreeGC(XDisplay(), Gc);
00152 }
00153
00154 operator GC()
00155 {
00156 return Gc;
00157 }
00158 };
00159
00160 class Ximg : public XObject
00161 {
00162 XImage *Img;
00163 int Line;
00164 char *Data;
00165
00166 public:
00167 Ximg(int x, int y, int depth)
00168 {
00169 Line = (x * depth + 7) / 8;
00170 Data = (char*)malloc(Line * y);
00171 Img = XCreateImage( XDisplay(),
00172 DefaultVisual(XDisplay(), 0),
00173 depth,
00174 ZPixmap,
00175 0,
00176 Data,
00177 x, y,
00178 8,
00179 Line);
00180 }
00181
00182 ~Ximg()
00183 {
00184 XDestroyImage(Img);
00185 }
00186
00187 operator XImage *()
00188 {
00189 return Img;
00190 }
00191
00192 uchar *operator [](int y)
00193 {
00194 if (y >= 0 AND y < Img->height)
00195 {
00196 return (uchar*)Img->data + (y * Img->bytes_per_line);
00197 }
00198 return 0;
00199 }
00200
00201 void Set(int x, int y, int Col)
00202 {
00203 XPutPixel(Img, x, y, Col);
00204 }
00205
00206 int Get(int x, int y)
00207 {
00208 return XGetPixel(Img, x, y);
00209 }
00210
00211 int X()
00212 {
00213 return Img->width;
00214 }
00215
00216 int Y()
00217 {
00218 return Img->height;
00219 }
00220
00221 int Depth()
00222 {
00223 return Img->depth;
00224 }
00225 };
00226
00227 class Xpix : public XObject
00228 {
00229 Drawable v;
00230 Pixmap Pix;
00231
00232 public: Xpix(Drawable draw, Ximg *Img)
00233 {
00234 v = draw;
00235 Pix = (Img) ? XCreatePixmap(XDisplay(),
00236 v,
00237 Img->X(),
00238 Img->Y(),
00239 Img->Depth()) : 0;
00240 if (Pix)
00241 {
00242 Xgc Gc(Pix);
00243 XPutImage(XDisplay(), Pix, Gc, *Img, 0, 0, 0, 0, Img->X(), Img->Y());
00244 }
00245 }
00246
00247 ~Xpix()
00248 {
00249 if (Pix)
00250 XFreePixmap(XDisplay(), Pix);
00251 }
00252
00253 operator Pixmap()
00254 {
00255 return Pix;
00256 }
00257
00258 void Detach()
00259 {
00260 Pix = 0;
00261 }
00262 };
00263
00264 #endif