x.H 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. //
  2. // "$Id: x.H 9299 2012-03-23 16:47:53Z manolo $"
  3. //
  4. // X11 header file for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-2012 by Bill Spitzak and others.
  7. //
  8. // This library is free software. Distribution and use rights are outlined in
  9. // the file "COPYING" which should have been included with this file. If this
  10. // file is missing or damaged, see the license at:
  11. //
  12. // http://www.fltk.org/COPYING.php
  13. //
  14. // Please report all bugs and problems on the following page:
  15. //
  16. // http://www.fltk.org/str.php
  17. //
  18. // These are internal fltk symbols that are necessary or useful for
  19. // calling Xlib. You should include this file if (and ONLY if) you
  20. // need to call Xlib directly. These symbols may not exist on non-X
  21. // systems.
  22. /** \class Fl_Mac_App_Menu
  23. Mac OS-specific class allowing to localize the application menu.
  24. These character strings are used to build the application menu. They can be localized
  25. at run time to any UTF-8 text by placing instructions such as this \e very
  26. early in the program:
  27. \verbatim
  28. Fl_Mac_App_Menu::print = "Imprimer la fenêtre";
  29. \endverbatim
  30. */
  31. #if !defined(Fl_X_H) && !defined(FL_DOXYGEN)
  32. # define Fl_X_H
  33. # include "Enumerations.H"
  34. # ifdef WIN32
  35. # include "win32.H"
  36. # elif defined(__APPLE__)
  37. # include "mac.H"
  38. # else
  39. # if defined(_ABIN32) || defined(_ABI64) // fix for broken SGI Irix X .h files
  40. # pragma set woff 3322
  41. # endif
  42. # include <X11/Xlib.h>
  43. # include <X11/Xutil.h>
  44. # if defined(_ABIN32) || defined(_ABI64)
  45. # pragma reset woff 3322
  46. # endif
  47. # include <X11/Xatom.h>
  48. # include "Fl_Window.H"
  49. # include "Xutf8.h"
  50. // Mirror X definition of Region to Fl_Region, for portability...
  51. typedef Region Fl_Region;
  52. FL_EXPORT void fl_open_display();
  53. FL_EXPORT void fl_open_display(Display*);
  54. FL_EXPORT void fl_close_display();
  55. // constant info about the X server connection:
  56. extern FL_EXPORT Display *fl_display;
  57. extern FL_EXPORT int fl_screen;
  58. extern FL_EXPORT XVisualInfo *fl_visual;
  59. extern FL_EXPORT Colormap fl_colormap;
  60. // drawing functions:
  61. extern FL_EXPORT GC fl_gc;
  62. extern FL_EXPORT Window fl_window;
  63. FL_EXPORT ulong fl_xpixel(Fl_Color i);
  64. FL_EXPORT ulong fl_xpixel(uchar r, uchar g, uchar b);
  65. FL_EXPORT void fl_clip_region(Fl_Region);
  66. FL_EXPORT Fl_Region fl_clip_region();
  67. // feed events into fltk:
  68. FL_EXPORT int fl_handle(const XEvent&);
  69. // you can use these in Fl::add_handler() to look at events:
  70. extern FL_EXPORT const XEvent* fl_xevent;
  71. extern FL_EXPORT ulong fl_event_time;
  72. // off-screen pixmaps: create, destroy, draw into, copy to window:
  73. typedef ulong Fl_Offscreen;
  74. # define fl_create_offscreen(w,h) \
  75. XCreatePixmap(fl_display, \
  76. (Fl_Surface_Device::surface() == Fl_Display_Device::display_device() ? \
  77. fl_window : fl_xid(Fl::first_window()) ) , \
  78. w, h, fl_visual->depth)
  79. // begin/end are macros that save the old state in local variables:
  80. # define fl_begin_offscreen(pixmap) \
  81. Window _sw=fl_window; fl_window=pixmap; \
  82. Fl_Surface_Device *_ss = Fl_Surface_Device::surface(); Fl_Display_Device::display_device()->set_current(); \
  83. fl_push_no_clip()
  84. # define fl_end_offscreen() \
  85. fl_pop_clip(); fl_window = _sw; _ss->set_current()
  86. extern void fl_copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy);
  87. # define fl_delete_offscreen(pixmap) XFreePixmap(fl_display, pixmap)
  88. // Bitmap masks
  89. typedef ulong Fl_Bitmask;
  90. extern FL_EXPORT Fl_Bitmask fl_create_bitmask(int w, int h, const uchar *data);
  91. extern FL_EXPORT Fl_Bitmask fl_create_alphamask(int w, int h, int d, int ld, const uchar *data);
  92. extern FL_EXPORT void fl_delete_bitmask(Fl_Bitmask bm);
  93. #if defined(FL_LIBRARY) || defined(FL_INTERNALS)
  94. extern FL_EXPORT Window fl_message_window;
  95. extern FL_EXPORT void *fl_xftfont;
  96. FL_EXPORT Fl_Region XRectangleRegion(int x, int y, int w, int h); // in fl_rect.cxx
  97. // access to core fonts:
  98. // This class provides a "smart pointer" that returns a pointer to an XFontStruct.
  99. // The global variable fl_xfont can be called wherever a bitmap "core" font is
  100. // needed, e.g. when rendering to a GL context under X11.
  101. // With Xlib / X11 fonts, fl_xfont will return the current selected font.
  102. // With XFT / X11 fonts, fl_xfont will attempt to return the bitmap "core" font most
  103. // similar to (usually the same as) the current XFT font.
  104. class Fl_XFont_On_Demand
  105. {
  106. public:
  107. Fl_XFont_On_Demand(XFontStruct* p = NULL) : ptr(p) { }
  108. Fl_XFont_On_Demand& operator=(const Fl_XFont_On_Demand& x)
  109. { ptr = x.ptr; return *this; }
  110. Fl_XFont_On_Demand& operator=(XFontStruct* p)
  111. { ptr = p; return *this; }
  112. XFontStruct* value();
  113. operator XFontStruct*() { return value(); }
  114. XFontStruct& operator*() { return *value(); }
  115. XFontStruct* operator->() { return value(); }
  116. bool operator==(const Fl_XFont_On_Demand& x) { return ptr == x.ptr; }
  117. bool operator!=(const Fl_XFont_On_Demand& x) { return ptr != x.ptr; }
  118. private:
  119. XFontStruct *ptr;
  120. };
  121. extern FL_EXPORT Fl_XFont_On_Demand fl_xfont;
  122. // this object contains all X-specific stuff about a window:
  123. // Warning: this object is highly subject to change!
  124. // FL_LIBRARY or FL_INTERNALS must be defined to access this class.
  125. class FL_EXPORT Fl_X {
  126. public:
  127. Window xid;
  128. Window other_xid;
  129. Fl_Window *w;
  130. Fl_Region region;
  131. Fl_X *next;
  132. char wait_for_expose;
  133. char backbuffer_bad; // used for XDBE
  134. static Fl_X* first;
  135. static Fl_X* i(const Fl_Window* wi) {return wi->i;}
  136. void setwindow(Fl_Window* wi) {w=wi; wi->i=this;}
  137. void sendxjunk();
  138. static void make_xid(Fl_Window*,XVisualInfo* =fl_visual, Colormap=fl_colormap);
  139. static Fl_X* set_xid(Fl_Window*, Window);
  140. // kludges to get around protection:
  141. void flush() {w->flush();}
  142. static void x(Fl_Window* wi, int X) {wi->x(X);}
  143. static void y(Fl_Window* wi, int Y) {wi->y(Y);}
  144. static int ewmh_supported();
  145. };
  146. extern FL_EXPORT char fl_override_redirect; // hack into Fl_X::make_xid()
  147. extern FL_EXPORT int fl_background_pixel; // hack into Fl_X::make_xid()
  148. inline Window fl_xid(const Fl_Window* w) { Fl_X *xTemp = Fl_X::i(w); return xTemp ? xTemp->xid : 0; }
  149. #else
  150. extern Window fl_xid_(const Fl_Window* w);
  151. #define fl_xid(w) fl_xid_(w)
  152. #endif // FL_LIBRARY || FL_INTERNALS
  153. FL_EXPORT Fl_Window* fl_find(Window xid);
  154. // Dummy function to register a function for opening files via the window manager...
  155. inline void fl_open_callback(void (*)(const char *)) {}
  156. extern FL_EXPORT int fl_parse_color(const char* p, uchar& r, uchar& g, uchar& b);
  157. # endif
  158. #endif
  159. //
  160. // End of "$Id: x.H 9299 2012-03-23 16:47:53Z manolo $".
  161. //