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