00001
00007 #ifndef __LGI_OS_DEFS_H
00008 #define __LGI_OS_DEFS_H
00009
00010 #include <string.h>
00011 #include "assert.h"
00012 #include "LgiDefs.h"
00013 #include <stdarg.h>
00014 #include <stdlib.h>
00015 #include <stdio.h>
00016 #define _MULTI_THREADED
00017 #include <pthread.h>
00018
00019 #undef stricmp
00020
00021 #include "LgiInc.h"
00022 #include "xcb/xcb.h"
00023
00024 namespace Pango
00025 {
00026 #include "pango/pango.h"
00027 #include "pango/pangocairo.h"
00028 #include "cairo/cairo-xcb.h"
00029 }
00030
00031
00032 #define LINUX 1
00033 #define XP_CTRLS 1
00034 #define POSIX 1
00035
00036 #undef Status
00037 #undef Success
00038 #undef None
00039 #undef Above
00040 #undef Below
00041
00042 #define XStatus int
00043 #define XSuccess 0
00044 #define XAbove 0
00045 #define XBelow 1
00046 #define XNone 0L
00047
00048 class OsAppArguments
00049 {
00050 struct OsAppArgumentsPriv *d;
00051
00052 public:
00053 int Args;
00054 char **Arg;
00055
00056 OsAppArguments(int args, char **arg);
00057 ~OsAppArguments();
00058
00059 void Set(char *CmdLine);
00060 OsAppArguments &operator =(OsAppArguments &a);
00061 };
00062
00063
00064 typedef int OsProcess;
00065 typedef int OsProcessId;
00066 typedef xcb_window_t OsView;
00067 typedef xcb_window_t OsWindow;
00068 typedef char OsChar;
00069 typedef xcb_gcontext_t OsPainter;
00070 typedef Pango::PangoFontDescription* OsFont;
00071 typedef xcb_pixmap_t OsBitmap;
00072
00073 class OsApplication
00074 {
00075 class OsApplicationPriv *d;
00076
00077 protected:
00078 static OsApplication *Inst;
00079 xcb_connection_t *c;
00080 xcb_screen_t *s;
00081
00082 public:
00083 OsApplication(char Args, char **Arg);
00084 ~OsApplication();
00085
00086 static OsApplication *GetInst() { LgiAssert(Inst); return Inst; }
00087 xcb_connection_t *GetConn() { return c; };
00088 xcb_screen_t *GetScreen() { return s; }
00089 bool Check(xcb_void_cookie_t c, char *file, int line);
00090 };
00091
00092 #define XcbConn() (OsApplication::GetInst()->GetConn())
00093 #define XcbScreen() (OsApplication::GetInst()->GetScreen())
00094 #define XcbCheck(cookie) (OsApplication::GetInst()->Check(cookie, __FILE__, __LINE__))
00095 #ifdef _DEBUG
00096 #define XcbDebug(cookie) (OsApplication::GetInst()->Check(cookie, __FILE__, __LINE__))
00097 #else
00098 #define XcbDebug(cookie) cookie
00099 #endif
00100
00101 class LgiClass GMessage
00102 {
00103 xcb_generic_event_t *e;
00104
00105 public:
00106 typedef int Param;
00107
00108 GMessage(xcb_generic_event_t *ev = 0);
00109 GMessage(int m, Param a = 0, Param b = 0);
00110 ~GMessage();
00111
00112 int ResponseType() { return e ? e->response_type & ~0x80 : 0; }
00113 int Type();
00114 Param A();
00115 Param B();
00116 void Set(int m, Param a, Param b);
00117 xcb_generic_event_t *GetEvent() { return e; }
00118 void SetEvent(xcb_generic_event_t *e);
00119 bool Send(OsView Wnd);
00120
00121 #define DefCast(Obj, Id) \
00122 operator Obj*() \
00123 { \
00124 if (ResponseType() == Id) \
00125 return (Obj*)e; \
00126 LgiAssert(!"Not a valid cast."); \
00127 return 0; \
00128 }
00129
00130 DefCast(xcb_key_press_event_t, XCB_KEY_PRESS)
00131 DefCast(xcb_key_release_event_t, XCB_KEY_RELEASE)
00132 DefCast(xcb_button_press_event_t, XCB_BUTTON_PRESS)
00133 DefCast(xcb_button_release_event_t, XCB_BUTTON_RELEASE)
00134 DefCast(xcb_motion_notify_event_t, XCB_MOTION_NOTIFY)
00135 DefCast(xcb_enter_notify_event_t, XCB_ENTER_NOTIFY)
00136 DefCast(xcb_leave_notify_event_t, XCB_LEAVE_NOTIFY)
00137 DefCast(xcb_focus_in_event_t, XCB_FOCUS_IN)
00138 DefCast(xcb_focus_out_event_t, XCB_FOCUS_OUT)
00139 DefCast(xcb_keymap_notify_event_t, XCB_KEYMAP_NOTIFY)
00140 DefCast(xcb_expose_event_t, XCB_EXPOSE)
00141 DefCast(xcb_graphics_exposure_event_t, XCB_GRAPHICS_EXPOSURE)
00142 DefCast(xcb_no_exposure_event_t, XCB_NO_EXPOSURE)
00143 DefCast(xcb_visibility_notify_event_t, XCB_VISIBILITY_NOTIFY)
00144 DefCast(xcb_create_notify_event_t, XCB_CREATE_NOTIFY)
00145 DefCast(xcb_unmap_notify_event_t, XCB_UNMAP_NOTIFY)
00146 DefCast(xcb_map_notify_event_t, XCB_MAP_NOTIFY)
00147 DefCast(xcb_map_request_event_t, XCB_MAP_REQUEST)
00148 DefCast(xcb_reparent_notify_event_t, XCB_REPARENT_NOTIFY)
00149 DefCast(xcb_configure_notify_event_t, XCB_CONFIGURE_NOTIFY)
00150 DefCast(xcb_configure_request_event_t, XCB_CONFIGURE_REQUEST)
00151 DefCast(xcb_gravity_notify_event_t, XCB_GRAVITY_NOTIFY)
00152 DefCast(xcb_circulate_notify_event_t, XCB_CIRCULATE_NOTIFY)
00153 DefCast(xcb_property_notify_event_t, XCB_PROPERTY_NOTIFY)
00154 DefCast(xcb_selection_request_event_t, XCB_SELECTION_REQUEST)
00155 DefCast(xcb_selection_notify_event_t, XCB_SELECTION_NOTIFY)
00156 DefCast(xcb_colormap_notify_event_t, XCB_COLORMAP_NOTIFY)
00157 DefCast(xcb_client_message_event_t, XCB_CLIENT_MESSAGE)
00158 DefCast(xcb_mapping_notify_event_t, XCB_MAPPING_NOTIFY)
00159 };
00160
00161 class XcbAtom
00162 {
00163 xcb_atom_t Int;
00164 char *Str;
00165
00166 xcb_intern_atom_cookie_t ic;
00167 xcb_get_atom_name_cookie_t sc;
00168
00169 void SetStr(char *s, int len)
00170 {
00171 if (Str = new char[len+1])
00172 {
00173 memcpy(Str, s, len);
00174 Str[len] = 0;
00175 }
00176 }
00177
00178 public:
00179 XcbAtom(char *name, bool only_if_exists = false)
00180 {
00181 Int = 0;
00182 SetStr(name, strlen(name));
00183 ic = xcb_intern_atom (XcbConn(), only_if_exists, strlen(name), name);
00184 }
00185
00186 XcbAtom(xcb_atom_t atom)
00187 {
00188 Int = atom;
00189 Str = 0;
00190 sc = xcb_get_atom_name(XcbConn(), atom);
00191 }
00192
00193 ~XcbAtom()
00194 {
00195 DeleteArray(Str);
00196 }
00197
00198 char *Name()
00199 {
00200 if (!Str)
00201 {
00202 xcb_get_atom_name_reply_t *r =
00203 xcb_get_atom_name_reply(XcbConn(), sc, 0);
00204 if (r)
00205 {
00206 SetStr((char*)xcb_get_atom_name_name(r), xcb_get_atom_name_name_length(r));
00207 free(r);
00208 }
00209 }
00210
00211 return Str;
00212 }
00213
00214 xcb_atom_t Atom()
00215 {
00216 if (!Int)
00217 {
00218 xcb_intern_atom_reply_t *r = xcb_intern_atom_reply(XcbConn(), ic, 0);
00219 if (r)
00220 {
00221 Int = r->atom;
00222 free(r);
00223 }
00224 }
00225
00226 return Int;
00227 }
00228 };
00229
00230 #define MsgCode(Msg) Msg->Type()
00231 #define MsgA(Msg) Msg->A()
00232 #define MsgB(Msg) Msg->B()
00233
00234
00235 typedef pthread_t OsThreadId;
00236 typedef pthread_mutex_t OsSemaphore;
00237 #define LgiGetCurrentThread() pthread_self()
00238
00239
00240 #define ValidSocket(s) ((s)>=0)
00241 #define INVALID_SOCKET -1
00242 typedef int OsSocket;
00243
00245 #define LgiSleep(i) _lgi_sleep(i)
00246 LgiFunc void _lgi_sleep(int i);
00247
00248 #define atoi64 atoll
00249 #define _snprintf snprintf
00250 #define _vsnprintf vsnprintf
00251
00253 #define LgiYield() LgiApp->Run(false)
00254
00255 #define K_CHAR 0x0
00256
00258 #define LGI_FileDropFormat "text/uri-list"
00259 #define LGI_IllegalFileNameChars "\t\r\n/\\:*?\"<>|"
00260 #define LGI_WideCharset "utf-32"
00261 #define LGI_PrintfInt64 "%Li"
00262
00263 #define SND_ASYNC 1
00264
00265 #define DOUBLE_CLICK_THRESHOLD 5
00266 #define DOUBLE_CLICK_TIME 400
00267
00268
00269 #define GWF_VISIBLE 0x00000001
00270 #define GWF_DISABLED 0x00000002
00271 #define GWF_FOCUS 0x00000004
00272 #define GWF_OVER 0x00000008
00273 #define GWF_DROP_TARGET 0x00000010
00274 #define GWF_SUNKEN 0x00000020
00275 #define GWF_FLAT 0x00000040
00276 #define GWF_RAISED 0x00000080
00277 #define GWF_BORDER 0x00000100
00278 #define GWF_DIALOG 0x00000200
00279 #define GWF_DESTRUCTOR 0x00000400
00280 #define GWF_QUIT_WND 0x00000800
00281
00282
00283 #define ODS_SELECTED 0x1
00284 #define ODS_DISABLED 0x2
00285 #define ODS_CHECKED 0x4
00286
00288 #define SUNKEN 1
00290 #define RAISED 2
00292 #define CHISEL 3
00294 #define FLAT 4
00295
00297 #define DIR_CHAR '/'
00299 #define DIR_STR "/"
00301 #define EOL_SEQUENCE "\n"
00303 #define IsSlash(c) (((c)=='/')OR((c)=='\\'))
00305 #define IsQuote(c) (((c)=='\"')OR((c)=='\''))
00307 #define LGI_PATH_SEPARATOR ":"
00309 #define LGI_ALL_FILES "*"
00311 #define LGI_LIBRARY_EXT "so"
00312
00314 #define M_SYSTEM (1000)
00316 #define M_CLOSE (M_SYSTEM+1)
00318 #define M_X11_INVALIDATE (M_SYSTEM+2)
00320 #define M_X11_REPARENT (M_SYSTEM+4)
00321
00323 #define M_USER (M_SYSTEM+1000)
00324
00329 #define M_MOUSEENTER (M_USER+100)
00330
00335 #define M_MOUSEEXIT (M_USER+101)
00336
00341 #define M_CHANGE (M_USER+102)
00342
00347 #define M_DESCRIBE (M_USER+103)
00348
00349
00350 #define M_WANT_DIALOG_PROC (M_USER+104)
00351
00352 #define M_MENU (M_USER+105)
00353 #define M_COMMAND (M_USER+106)
00354 #define M_DRAG_DROP (M_USER+107)
00355
00356 #define M_TRAY_NOTIFY (M_USER+108)
00357 #define M_CUT (M_USER+109)
00358 #define M_COPY (M_USER+110)
00359 #define M_PASTE (M_USER+111)
00360 #define M_DELETE (M_USER+112)
00361 #define M_GTHREADWORK_COMPELTE (M_USER+113)
00363 #define M_PULSE (M_USER+114)
00364
00367 #define IDOK 1
00370 #define IDCANCEL 2
00373 #define IDYES 6
00376 #define IDNO 7
00377
00380 #define MB_OK 0
00383 #define MB_OKCANCEL 1
00386 #define MB_YESNOCANCEL 3
00389 #define MB_YESNO 4
00390
00391 #define MB_SYSTEMMODAL 0x1000
00392
00395 #define LGI_VKEY_CTRL 0x001
00398 #define LGI_VKEY_ALT 0x002
00401 #define LGI_VKEY_SHIFT 0x004
00402
00405 #define LGI_VMOUSE_LEFT 0x008
00408 #define LGI_VMOUSE_MIDDLE 0x010
00411 #define LGI_VMOUSE_RIGHT 0x020
00414 #define LGI_VMOUSE_CTRL 0x040
00417 #define LGI_VMOUSE_ALT 0x080
00420 #define LGI_VMOUSE_SHIFT 0x100
00423 #define LGI_VMOUSE_DOWN 0x200
00426 #define LGI_VMOUSE_DOUBLE 0x400
00427
00428
00429 #define abs(a) ( (a) < 0 ? -(a) : (a) )
00430
00431 typedef enum {
00432
00433 VK_UNKNOWN = 0,
00434 VK_FIRST = 0,
00435 VK_BACKSPACE = 0xff08,
00436 VK_TAB = 0xff09,
00437 VK_CLEAR = 12,
00438 VK_RETURN = 0xff0d,
00439 VK_PAUSE = 19,
00440 VK_ESCAPE = 0xff1b,
00441 VK_SPACE = 32,
00442 VK_EXCLAIM = 33,
00443 VK_QUOTEDBL = 34,
00444 VK_HASH = 35,
00445 VK_DOLLAR = 36,
00446 VK_AMPERSAND = 38,
00447 VK_QUOTE = 39,
00448 VK_LEFTPAREN = 40,
00449 VK_RIGHTPAREN = 41,
00450 VK_ASTERISK = 42,
00451 VK_PLUS = 43,
00452 VK_COMMA = 44,
00453 VK_MINUS = 45,
00454 VK_PERIOD = 46,
00455 VK_SLASH = 47,
00456 VK_0 = 48,
00457 VK_1 = 49,
00458 VK_2 = 50,
00459 VK_3 = 51,
00460 VK_4 = 52,
00461 VK_5 = 53,
00462 VK_6 = 54,
00463 VK_7 = 55,
00464 VK_8 = 56,
00465 VK_9 = 57,
00466 VK_COLON = 58,
00467 VK_SEMICOLON = 59,
00468 VK_LESS = 60,
00469 VK_EQUALS = 61,
00470 VK_GREATER = 62,
00471 VK_QUESTION = 63,
00472 VK_AT = 64,
00473
00474
00475
00476 VK_LEFTBRACKET = 91,
00477 VK_BACKSLASH = 92,
00478 VK_RIGHTBRACKET = 93,
00479 VK_CARET = 94,
00480 VK_UNDERSCORE = 95,
00481 VK_BACKQUOTE = 96,
00482 VK_a = 97,
00483 VK_b = 98,
00484 VK_c = 99,
00485 VK_d = 100,
00486 VK_e = 101,
00487 VK_f = 102,
00488 VK_g = 103,
00489 VK_h = 104,
00490 VK_i = 105,
00491 VK_j = 106,
00492 VK_k = 107,
00493 VK_l = 108,
00494 VK_m = 109,
00495 VK_n = 110,
00496 VK_o = 111,
00497 VK_p = 112,
00498 VK_q = 113,
00499 VK_r = 114,
00500 VK_s = 115,
00501 VK_t = 116,
00502 VK_u = 117,
00503 VK_v = 118,
00504 VK_w = 119,
00505 VK_x = 120,
00506 VK_y = 121,
00507 VK_z = 122,
00508
00509
00510
00511 VK_KP_ENTER = 0xff8d,
00512 VK_KP7 = 0xff95,
00513 VK_KP4 = 0xff96,
00514 VK_KP8 = 0xff97,
00515 VK_KP6 = 0xff98,
00516 VK_KP2 = 0xff99,
00517 VK_KP9 = 0xff9a,
00518 VK_KP3 = 0xff9b,
00519 VK_KP1 = 0xff9c,
00520 VK_KP5 = 0xff9d,
00521 VK_KP0 = 0xff9e,
00522 VK_KP_PERIOD = 0xff9f,
00523 VK_KP_MULTIPLY = 0xffaa,
00524 VK_KP_PLUS = 0xffab,
00525 VK_KP_MINUS = 0xffad,
00526 VK_KP_DIVIDE = 0xffaf,
00527 VK_KP_EQUALS = 0xffbd,
00528
00529
00530 VK_HOME = 0xff50,
00531 VK_LEFT = 0xff51,
00532 VK_UP = 0xff52,
00533 VK_RIGHT = 0xff53,
00534 VK_DOWN = 0xff54,
00535 VK_PAGEUP = 0xff55,
00536 VK_PAGEDOWN = 0xff56,
00537 VK_END = 0xff57,
00538 VK_INSERT = 0xff63,
00539
00540
00541 VK_F1 = 0xffbe,
00542 VK_F2,
00543 VK_F3,
00544 VK_F4,
00545 VK_F5,
00546 VK_F6,
00547 VK_F7,
00548 VK_F8,
00549 VK_F9,
00550 VK_F10,
00551 VK_F11,
00552 VK_F12,
00553 VK_F13,
00554 VK_F14,
00555 VK_F15,
00556
00557
00558 VK_NUMLOCK = 0xff7f,
00559 VK_CAPSLOCK = 0xffe5,
00560 VK_SCROLLOCK = 0xff14,
00561 VK_LSHIFT = 0xffe1,
00562 VK_RSHIFT,
00563 VK_LCTRL = 0xffe3,
00564 VK_RCTRL,
00565 VK_LALT = 0xffe9,
00566 VK_RALT,
00567 VK_LMETA = 0xffed,
00568 VK_RMETA,
00569 VK_LSUPER = 0xffeb,
00570 VK_RSUPER,
00571
00572
00573 VK_HELP = 0xff6a,
00574 VK_PRINT = 0xff61,
00575 VK_SYSREQ = 0xff15,
00576 VK_BREAK = 0xff6b,
00577 VK_MENU = 0xff67,
00578 VK_UNDO = 0xff65,
00579 VK_REDO,
00580 VK_EURO = 0x20ac,
00581 VK_COMPOSE = 0xff20,
00582 VK_MODE = 0xff7e,
00583 VK_DELETE = 0xffff,
00584 VK_POWER = 0x10000,
00585
00586
00587 VK_LAST
00588 } LgiKey;
00589
00590
00592
00593 #ifndef __CYGWIN__
00594 LgiFunc char *strnistr(char *a, char *b, int n);
00595 LgiFunc int strnicmp(char *a, char *b, int i);
00596 LgiFunc char *strupr(char *a);
00597 LgiFunc char *strlwr(char *a);
00598 LgiFunc int stricmp(char *a, char *b);
00599 #endif
00600
00601 LgiFunc int stricmp(char *a, char *b);
00602
00604 LgiFunc int FormatToInt(char *s);
00606 LgiFunc char *FormatToStr(int f);
00607
00608 #endif
00609