Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

linux/X/LgiOsClasses.h

00001 #ifndef __OS_CLASS_H
00002 #define __OS_CLASS_H
00003 
00005 #include <qimage.h>
00006 #include <qfont.h>
00007 #include <qevent.h>
00008 #include <qapplication.h>
00009 #include <qpainter.h>
00010 #include <qfont.h>
00011 #include <qfontmetrics.h>
00012 
00013 typedef pthread_t                   OsThread;
00014 typedef QFont                       *OsFont;
00015 typedef QApplication                OsApplication;
00016 typedef QPainter                    *OsPainter;
00017 typedef QImage                      *OsBitmap;
00018 typedef char16                      OsChar;
00019 
00020 #undef Bool
00021 
00022 class GMessage : public QEvent
00023 {
00024     friend class QApplication;
00025     XEvent Local;
00026 
00027     XEvent *GetLocal()
00028     {
00029         // Make sure this is set BEFORE we give it
00030         // to QEvent, otherwise it'll call random
00031         // code.
00032         Local.type = ClientMessage;
00033         return &Local;
00034     }
00035 
00036     GMessage(XEvent *e) : QEvent(e)
00037     {
00038     }
00039 
00040 public:
00041     GMessage(int M = 0, int A = 0, int B = 0) : QEvent(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 QView : public q
00068 {
00069     friend class GView;
00070 
00071 protected:
00072     GView *v;
00073     bool _Paint;
00074 
00075     void OnClick(QEvent *e, bool down, bool dbl, bool move);
00076     bool OnKey(QEvent *e, bool down);
00077     void setBackgroundMode(ViewBackground b) {}
00078 
00079 public:
00080     QView(GView *view, bool p = true);
00081     QView(GView *view, Window Existing);
00082     ~QView();
00083 
00084     void _SetWndPtr(void *p);
00085     void *_GetWndPtr();
00086     
00087     // Events
00088     void resizeEvent(QEvent *e);
00089     void paintEvent(QEvent *e);
00090     void customEvent(QEvent *e);
00091     void notifyEvent(int i = 0);
00092     
00093     // Mouse events
00094     void mousePressEvent(QEvent *e);
00095     void mouseDoubleClickEvent(QEvent *e);
00096     void mouseReleaseEvent(QEvent *e);
00097     void mouseMoveEvent(QEvent *e);
00098     void leaveEvent(QEvent *e);
00099     void enterEvent(QEvent *e);
00100     void wheelEvent(QEvent *e);
00101 
00102     // Focus events
00103     void focusInEvent(QEvent *e);
00104     void focusOutEvent(QEvent *e);
00105 
00106     // Keyboard events
00107     bool keyPressEvent(QEvent *e);
00108     bool keyReleaseEvent(QEvent *e);
00109 };
00110 
00111 typedef QView<QWidget> DefaultOsView;
00112 
00113 class QWindow : public QMainWindow
00114 {
00115     GWindow *Wnd;
00116 
00117 public:
00118     QWindow(GWindow *wnd);
00119     ~QWindow();
00120 
00121     void _SetWndPtr(void *p);
00122     void *_GetWndPtr();
00123     void SetModal();
00124 
00125     void resizeEvent(QEvent *re);
00126     void closeEvent(QEvent *ce);
00127     void paintEvent(QEvent *e);
00128     void customEvent(QEvent *e);
00129     void propertyEvent(QEvent *e);
00130 };
00131 
00132 class Xgc : public QObject
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 QObject
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 QObject
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

Generated on Tue May 2 10:24:43 2006 for Lgi by  doxygen 1.4.1