FLTK 1.3.0
x.H
00001 //
00002 // "$Id$"
00003 //
00004 // X11 header file for the Fast Light Tool Kit (FLTK).
00005 //
00006 // Copyright 1998-2011 by Bill Spitzak and others.
00007 //
00008 // This library is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU Library General Public
00010 // License as published by the Free Software Foundation; either
00011 // version 2 of the License, or (at your option) any later version.
00012 //
00013 // This library is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 // Library General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU Library General Public
00019 // License along with this library; if not, write to the Free Software
00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00021 // USA.
00022 //
00023 // Please report all bugs and problems on the following page:
00024 //
00025 //     http://www.fltk.org/str.php
00026 //
00027 
00028 // These are internal fltk symbols that are necessary or useful for
00029 // calling Xlib.  You should include this file if (and ONLY if) you
00030 // need to call Xlib directly.  These symbols may not exist on non-X
00031 // systems.
00032 
00044 #if !defined(Fl_X_H) && !defined(FL_DOXYGEN) 
00045 #  define Fl_X_H
00046 
00047 #  include "Enumerations.H"
00048 
00049 #  ifdef WIN32
00050 #    include "win32.H"
00051 #  elif defined(__APPLE__)
00052 #    include "mac.H"
00053 #  else
00054 #    if defined(_ABIN32) || defined(_ABI64) // fix for broken SGI Irix X .h files
00055 #      pragma set woff 3322
00056 #    endif
00057 #    include <X11/Xlib.h>
00058 #    include <X11/Xutil.h>
00059 #    if defined(_ABIN32) || defined(_ABI64)
00060 #      pragma reset woff 3322
00061 #    endif
00062 #    include <X11/Xatom.h>
00063 #    include "Fl_Window.H"
00064 #    include "Xutf8.h"
00065 // Mirror X definition of Region to Fl_Region, for portability...
00066 typedef Region Fl_Region;
00067 
00068 FL_EXPORT void fl_open_display();
00069 FL_EXPORT void fl_open_display(Display*);
00070 FL_EXPORT void fl_close_display();
00071 
00072 // constant info about the X server connection:
00073 extern FL_EXPORT Display *fl_display;
00074 extern FL_EXPORT int fl_screen;
00075 extern FL_EXPORT XVisualInfo *fl_visual;
00076 extern FL_EXPORT Colormap fl_colormap;
00077 
00078 
00079 // drawing functions:
00080 extern FL_EXPORT GC fl_gc;
00081 extern FL_EXPORT Window fl_window;
00082 FL_EXPORT ulong fl_xpixel(Fl_Color i);
00083 FL_EXPORT ulong fl_xpixel(uchar r, uchar g, uchar b);
00084 FL_EXPORT void fl_clip_region(Fl_Region);
00085 FL_EXPORT Fl_Region fl_clip_region();
00086 
00087 // feed events into fltk:
00088 FL_EXPORT int fl_handle(const XEvent&);
00089 
00090 // you can use these in Fl::add_handler() to look at events:
00091 extern FL_EXPORT const XEvent* fl_xevent;
00092 extern FL_EXPORT ulong fl_event_time;
00093 
00094 // off-screen pixmaps: create, destroy, draw into, copy to window:
00095 typedef ulong Fl_Offscreen;
00096 #   define fl_create_offscreen(w,h) \
00097   XCreatePixmap(fl_display, \
00098               (Fl_Surface_Device::surface()->class_name() == Fl_Display_Device::class_id ? \
00099               fl_window : fl_xid(Fl::first_window()) ) , \
00100               w, h, fl_visual->depth)
00101 // begin/end are macros that save the old state in local variables:
00102 #    define fl_begin_offscreen(pixmap) \
00103   Window _sw=fl_window; fl_window=pixmap; \
00104   Fl_Surface_Device *_ss = Fl_Surface_Device::surface(); Fl_Display_Device::display_device()->set_current(); \
00105   fl_push_no_clip()
00106 #    define fl_end_offscreen() \
00107   fl_pop_clip(); fl_window = _sw; _ss->set_current()
00108 
00109 extern void fl_copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy);
00110 #    define fl_delete_offscreen(pixmap) XFreePixmap(fl_display, pixmap)
00111 
00112 // Bitmap masks
00113 typedef ulong Fl_Bitmask;
00114 
00115 extern FL_EXPORT Fl_Bitmask fl_create_bitmask(int w, int h, const uchar *data);
00116 extern FL_EXPORT Fl_Bitmask fl_create_alphamask(int w, int h, int d, int ld, const uchar *data);
00117 extern FL_EXPORT void fl_delete_bitmask(Fl_Bitmask bm);
00118 
00119 #if defined(FL_LIBRARY) || defined(FL_INTERNALS)
00120 extern FL_EXPORT Window fl_message_window;
00121 extern FL_EXPORT void *fl_xftfont;
00122 FL_EXPORT Fl_Region XRectangleRegion(int x, int y, int w, int h); // in fl_rect.cxx
00123 
00124 // access to core fonts:
00125 // This class provides a "smart pointer" that returns a pointer to an XFontStruct.
00126 // The global variable fl_xfont can be called wherever a bitmap "core" font is
00127 // needed, e.g. when rendering to a GL context under X11.
00128 // With Xlib / X11 fonts, fl_xfont will return the current selected font.
00129 // With XFT / X11 fonts, fl_xfont will attempt to return the bitmap "core" font most
00130 // similar to (usually the same as) the current XFT font.
00131 class Fl_XFont_On_Demand
00132 {
00133 public:
00134   Fl_XFont_On_Demand(XFontStruct* p = NULL) : ptr(p) { }
00135   Fl_XFont_On_Demand& operator=(const Fl_XFont_On_Demand& x)
00136   { ptr = x.ptr;  return *this; }
00137   Fl_XFont_On_Demand& operator=(XFontStruct* p)
00138   { ptr = p;  return *this; }
00139   XFontStruct* value();
00140   operator XFontStruct*() { return value(); }
00141   XFontStruct& operator*() { return *value(); }
00142   XFontStruct* operator->() { return value(); }
00143   bool operator==(const Fl_XFont_On_Demand& x) { return ptr == x.ptr; }
00144   bool operator!=(const Fl_XFont_On_Demand& x) { return ptr != x.ptr; }
00145 private:
00146   XFontStruct *ptr;
00147 };
00148 extern FL_EXPORT Fl_XFont_On_Demand fl_xfont;
00149 
00150 // this object contains all X-specific stuff about a window:
00151 // Warning: this object is highly subject to change!  
00152 // FL_LIBRARY or FL_INTERNALS must be defined to access this class.
00153 class FL_EXPORT Fl_X {
00154 public:
00155   Window xid;
00156   Window other_xid;
00157   Fl_Window *w;
00158   Fl_Region region;
00159   Fl_X *next;
00160   char wait_for_expose;
00161   char backbuffer_bad; // used for XDBE
00162   static Fl_X* first;
00163   static Fl_X* i(const Fl_Window* wi) {return wi->i;}
00164   void setwindow(Fl_Window* wi) {w=wi; wi->i=this;}
00165   void sendxjunk();
00166   static void make_xid(Fl_Window*,XVisualInfo* =fl_visual, Colormap=fl_colormap);
00167   static Fl_X* set_xid(Fl_Window*, Window);
00168   // kludges to get around protection:
00169   void flush() {w->flush();}
00170   static void x(Fl_Window* wi, int X) {wi->x(X);}
00171   static void y(Fl_Window* wi, int Y) {wi->y(Y);}
00172 };
00173 
00174 extern FL_EXPORT char fl_override_redirect; // hack into Fl_X::make_xid()
00175 extern FL_EXPORT int fl_background_pixel;  // hack into Fl_X::make_xid()
00176 
00177 inline Window fl_xid(const Fl_Window* w) { return Fl_X::i(w)->xid; }
00178 
00179 #else
00180 
00181 extern Window fl_xid_(const Fl_Window* w);
00182 #define fl_xid(w) fl_xid_(w)
00183 
00184 #endif // FL_LIBRARY || FL_INTERNALS
00185 
00186 FL_EXPORT Fl_Window* fl_find(Window xid);
00187 
00188 
00189 // Dummy function to register a function for opening files via the window manager...
00190 inline void fl_open_callback(void (*)(const char *)) {}
00191 
00192 extern FL_EXPORT int fl_parse_color(const char* p, uchar& r, uchar& g, uchar& b);
00193 
00194 #  endif
00195 #endif
00196 
00197 //
00198 // End of "$Id$".
00199 //