x.H 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. //
  2. // "$Id: x.H 10158 2014-05-23 16:00:25Z 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) XCreatePixmap(fl_display, RootWindow(fl_display, fl_screen), w, h, fl_visual->depth)
  75. // begin/end are macros that save the old state in local variables:
  76. # define fl_begin_offscreen(pixmap) \
  77. Window _sw=fl_window; fl_window=pixmap; \
  78. Fl_Surface_Device *_ss = Fl_Surface_Device::surface(); Fl_Display_Device::display_device()->set_current(); \
  79. fl_push_no_clip()
  80. # define fl_end_offscreen() \
  81. fl_pop_clip(); fl_window = _sw; _ss->set_current()
  82. extern void fl_copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy);
  83. # define fl_delete_offscreen(pixmap) XFreePixmap(fl_display, pixmap)
  84. // Bitmap masks
  85. typedef ulong Fl_Bitmask;
  86. extern FL_EXPORT Fl_Bitmask fl_create_bitmask(int w, int h, const uchar *data);
  87. extern FL_EXPORT Fl_Bitmask fl_create_alphamask(int w, int h, int d, int ld, const uchar *data);
  88. extern FL_EXPORT void fl_delete_bitmask(Fl_Bitmask bm);
  89. #if defined(FL_LIBRARY) || defined(FL_INTERNALS)
  90. extern FL_EXPORT Window fl_message_window;
  91. extern FL_EXPORT void *fl_xftfont;
  92. FL_EXPORT Fl_Region XRectangleRegion(int x, int y, int w, int h); // in fl_rect.cxx
  93. // access to core fonts:
  94. // This class provides a "smart pointer" that returns a pointer to an XFontStruct.
  95. // The global variable fl_xfont can be called wherever a bitmap "core" font is
  96. // needed, e.g. when rendering to a GL context under X11.
  97. // With Xlib / X11 fonts, fl_xfont will return the current selected font.
  98. // With XFT / X11 fonts, fl_xfont will attempt to return the bitmap "core" font most
  99. // similar to (usually the same as) the current XFT font.
  100. class Fl_XFont_On_Demand
  101. {
  102. public:
  103. Fl_XFont_On_Demand(XFontStruct* p = NULL) : ptr(p) { }
  104. Fl_XFont_On_Demand& operator=(const Fl_XFont_On_Demand& x)
  105. { ptr = x.ptr; return *this; }
  106. Fl_XFont_On_Demand& operator=(XFontStruct* p)
  107. { ptr = p; return *this; }
  108. XFontStruct* value();
  109. operator XFontStruct*() { return value(); }
  110. XFontStruct& operator*() { return *value(); }
  111. XFontStruct* operator->() { return value(); }
  112. bool operator==(const Fl_XFont_On_Demand& x) { return ptr == x.ptr; }
  113. bool operator!=(const Fl_XFont_On_Demand& x) { return ptr != x.ptr; }
  114. private:
  115. XFontStruct *ptr;
  116. };
  117. extern FL_EXPORT Fl_XFont_On_Demand fl_xfont;
  118. // this object contains all X-specific stuff about a window:
  119. // Warning: this object is highly subject to change!
  120. // FL_LIBRARY or FL_INTERNALS must be defined to access this class.
  121. class FL_EXPORT Fl_X {
  122. public:
  123. Window xid;
  124. Window other_xid;
  125. Fl_Window *w;
  126. Fl_Region region;
  127. Fl_X *next;
  128. char wait_for_expose;
  129. char backbuffer_bad; // used for XDBE
  130. static Fl_X* first;
  131. static Fl_X* i(const Fl_Window* wi) {return wi->i;}
  132. void setwindow(Fl_Window* wi) {w=wi; wi->i=this;}
  133. void sendxjunk();
  134. static void make_xid(Fl_Window*,XVisualInfo* =fl_visual, Colormap=fl_colormap);
  135. static Fl_X* set_xid(Fl_Window*, Window);
  136. // kludges to get around protection:
  137. void flush() {w->flush();}
  138. static void x(Fl_Window* wi, int X) {wi->x(X);}
  139. static void y(Fl_Window* wi, int Y) {wi->y(Y);}
  140. static int ewmh_supported();
  141. };
  142. extern FL_EXPORT char fl_override_redirect; // hack into Fl_X::make_xid()
  143. extern FL_EXPORT int fl_background_pixel; // hack into Fl_X::make_xid()
  144. inline Window fl_xid(const Fl_Window* w) { Fl_X *xTemp = Fl_X::i(w); return xTemp ? xTemp->xid : 0; }
  145. #else
  146. extern Window fl_xid_(const Fl_Window* w);
  147. #define fl_xid(w) fl_xid_(w)
  148. #endif // FL_LIBRARY || FL_INTERNALS
  149. FL_EXPORT Fl_Window* fl_find(Window xid);
  150. // Dummy function to register a function for opening files via the window manager...
  151. inline void fl_open_callback(void (*)(const char *)) {}
  152. extern FL_EXPORT int fl_parse_color(const char* p, uchar& r, uchar& g, uchar& b);
  153. # endif
  154. #endif
  155. //
  156. // End of "$Id: x.H 10158 2014-05-23 16:00:25Z manolo $".
  157. //