You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

215 lines
7.3KB

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