x.H 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. //
  2. // "$Id: x.H 7903 2010-11-28 21:06:39Z matt $"
  3. //
  4. // X11 header file for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-2010 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. #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 Window fl_message_window;
  58. extern FL_EXPORT int fl_screen;
  59. extern FL_EXPORT XVisualInfo *fl_visual;
  60. extern FL_EXPORT Colormap fl_colormap;
  61. // access to core fonts:
  62. // This class provides a "smart pointer" that returns a pointer to an XFontStruct.
  63. // The global variable fl_xfont can be called wherever a bitmap "core" font is
  64. // needed, e.g. when rendering to a GL context under X11.
  65. // With Xlib / X11 fonts, fl_xfont will return the current selected font.
  66. // With XFT / X11 fonts, fl_xfont will attempt to return the bitmap "core" font most
  67. // similar to (usually the same as) the current XFT font.
  68. class Fl_XFont_On_Demand
  69. {
  70. public:
  71. Fl_XFont_On_Demand(XFontStruct* p = NULL) : ptr(p) { }
  72. Fl_XFont_On_Demand& operator=(const Fl_XFont_On_Demand& x)
  73. { ptr = x.ptr; return *this; }
  74. Fl_XFont_On_Demand& operator=(XFontStruct* p)
  75. { ptr = p; return *this; }
  76. XFontStruct* value();
  77. operator XFontStruct*() { return value(); }
  78. XFontStruct& operator*() { return *value(); }
  79. XFontStruct* operator->() { return value(); }
  80. bool operator==(const Fl_XFont_On_Demand& x) { return ptr == x.ptr; }
  81. bool operator!=(const Fl_XFont_On_Demand& x) { return ptr != x.ptr; }
  82. private:
  83. XFontStruct *ptr;
  84. };
  85. extern FL_EXPORT Fl_XFont_On_Demand fl_xfont;
  86. // drawing functions:
  87. extern FL_EXPORT GC fl_gc;
  88. extern FL_EXPORT Window fl_window;
  89. extern FL_EXPORT void *fl_xftfont;
  90. FL_EXPORT ulong fl_xpixel(Fl_Color i);
  91. FL_EXPORT ulong fl_xpixel(uchar r, uchar g, uchar b);
  92. FL_EXPORT void fl_clip_region(Fl_Region);
  93. FL_EXPORT Fl_Region fl_clip_region();
  94. FL_EXPORT Fl_Region XRectangleRegion(int x, int y, int w, int h); // in fl_rect.cxx
  95. // feed events into fltk:
  96. FL_EXPORT int fl_handle(const XEvent&);
  97. // you can use these in Fl::add_handler() to look at events:
  98. extern FL_EXPORT const XEvent* fl_xevent;
  99. extern FL_EXPORT ulong fl_event_time;
  100. // off-screen pixmaps: create, destroy, draw into, copy to window:
  101. typedef ulong Fl_Offscreen;
  102. # define fl_create_offscreen(w,h) \
  103. XCreatePixmap(fl_display, \
  104. (fl_surface->type() == Fl_Display_Device::device_type ? \
  105. fl_window : fl_xid(Fl::first_window()) ) , \
  106. w, h, fl_visual->depth)
  107. // begin/end are macros that save the old state in local variables:
  108. # define fl_begin_offscreen(pixmap) \
  109. Window _sw=fl_window; fl_window=pixmap; \
  110. Fl_Surface_Device *_ss = fl_surface; fl_display_device->set_current(); \
  111. fl_push_no_clip()
  112. # define fl_end_offscreen() \
  113. fl_pop_clip(); fl_window = _sw; _ss->set_current()
  114. extern void fl_copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy);
  115. # define fl_delete_offscreen(pixmap) XFreePixmap(fl_display, pixmap)
  116. // Bitmap masks
  117. typedef ulong Fl_Bitmask;
  118. extern FL_EXPORT Fl_Bitmask fl_create_bitmask(int w, int h, const uchar *data);
  119. extern FL_EXPORT Fl_Bitmask fl_create_alphamask(int w, int h, int d, int ld, const uchar *data);
  120. extern FL_EXPORT void fl_delete_bitmask(Fl_Bitmask bm);
  121. // this object contains all X-specific stuff about a window:
  122. // Warning: this object is highly subject to change! It's definition
  123. // is only here so that fl_xid can be declared inline:
  124. class FL_EXPORT Fl_X {
  125. public:
  126. Window xid;
  127. Window other_xid;
  128. Fl_Window *w;
  129. Fl_Region region;
  130. Fl_X *next;
  131. char wait_for_expose;
  132. char backbuffer_bad; // used for XDBE
  133. static Fl_X* first;
  134. static Fl_X* i(const Fl_Window* wi) {return wi->i;}
  135. void setwindow(Fl_Window* wi) {w=wi; wi->i=this;}
  136. void sendxjunk();
  137. static void make_xid(Fl_Window*,XVisualInfo* =fl_visual, Colormap=fl_colormap);
  138. static Fl_X* set_xid(Fl_Window*, Window);
  139. // kludges to get around protection:
  140. void flush() {w->flush();}
  141. static void x(Fl_Window* wi, int X) {wi->x(X);}
  142. static void y(Fl_Window* wi, int Y) {wi->y(Y);}
  143. };
  144. // convert xid <-> Fl_Window:
  145. inline Window fl_xid(const Fl_Window*w) {return Fl_X::i(w)->xid;}
  146. FL_EXPORT Fl_Window* fl_find(Window xid);
  147. extern FL_EXPORT char fl_override_redirect; // hack into Fl_X::make_xid()
  148. extern FL_EXPORT int fl_background_pixel; // hack into Fl_X::make_xid()
  149. // Dummy function to register a function for opening files via the window manager...
  150. inline void fl_open_callback(void (*)(const char *)) {}
  151. extern FL_EXPORT int fl_parse_color(const char* p, uchar& r, uchar& g, uchar& b);
  152. # endif
  153. #endif
  154. //
  155. // End of "$Id: x.H 7903 2010-11-28 21:06:39Z matt $".
  156. //