FLTK 1.3.x

x.H

00001 //
00002 // "$Id: x.H 8190 2011-01-05 10:21:45Z manolo $"
00003 //
00004 // X11 header file for the Fast Light Tool Kit (FLTK).
00005 //
00006 // Copyright 1998-2010 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 
00033 #if !defined(Fl_X_H) && !defined(FL_DOXYGEN) 
00034 #  define Fl_X_H
00035 
00036 #  include "Enumerations.H"
00037 
00038 #  ifdef WIN32
00039 #    include "win32.H"
00040 #  elif defined(__APPLE__)
00041 #    include "mac.H"
00042 #  else
00043 #    if defined(_ABIN32) || defined(_ABI64) // fix for broken SGI Irix X .h files
00044 #      pragma set woff 3322
00045 #    endif
00046 #    include <X11/Xlib.h>
00047 #    include <X11/Xutil.h>
00048 #    if defined(_ABIN32) || defined(_ABI64)
00049 #      pragma reset woff 3322
00050 #    endif
00051 #    include <X11/Xatom.h>
00052 #    include "Fl_Window.H"
00053 #    include "Xutf8.h"
00054 // Mirror X definition of Region to Fl_Region, for portability...
00055 typedef Region Fl_Region;
00056 
00057 FL_EXPORT void fl_open_display();
00058 FL_EXPORT void fl_open_display(Display*);
00059 FL_EXPORT void fl_close_display();
00060 
00061 // constant info about the X server connection:
00062 extern FL_EXPORT Display *fl_display;
00063 extern FL_EXPORT Window fl_message_window;
00064 extern FL_EXPORT int fl_screen;
00065 extern FL_EXPORT XVisualInfo *fl_visual;
00066 extern FL_EXPORT Colormap fl_colormap;
00067 
00068 // access to core fonts:
00069 // This class provides a "smart pointer" that returns a pointer to an XFontStruct.
00070 // The global variable fl_xfont can be called wherever a bitmap "core" font is
00071 // needed, e.g. when rendering to a GL context under X11.
00072 // With Xlib / X11 fonts, fl_xfont will return the current selected font.
00073 // With XFT / X11 fonts, fl_xfont will attempt to return the bitmap "core" font most
00074 // similar to (usually the same as) the current XFT font.
00075 class Fl_XFont_On_Demand
00076 {
00077 public:
00078   Fl_XFont_On_Demand(XFontStruct* p = NULL) : ptr(p) { }
00079   Fl_XFont_On_Demand& operator=(const Fl_XFont_On_Demand& x)
00080     { ptr = x.ptr;  return *this; }
00081   Fl_XFont_On_Demand& operator=(XFontStruct* p)
00082     { ptr = p;  return *this; }
00083   XFontStruct* value();
00084   operator XFontStruct*() { return value(); }
00085   XFontStruct& operator*() { return *value(); }
00086   XFontStruct* operator->() { return value(); }
00087   bool operator==(const Fl_XFont_On_Demand& x) { return ptr == x.ptr; }
00088   bool operator!=(const Fl_XFont_On_Demand& x) { return ptr != x.ptr; }
00089 private:
00090   XFontStruct *ptr;
00091 };
00092 extern FL_EXPORT Fl_XFont_On_Demand fl_xfont;
00093 
00094 // drawing functions:
00095 extern FL_EXPORT GC fl_gc;
00096 extern FL_EXPORT Window fl_window;
00097 extern FL_EXPORT void *fl_xftfont;
00098 FL_EXPORT ulong fl_xpixel(Fl_Color i);
00099 FL_EXPORT ulong fl_xpixel(uchar r, uchar g, uchar b);
00100 FL_EXPORT void fl_clip_region(Fl_Region);
00101 FL_EXPORT Fl_Region fl_clip_region();
00102 FL_EXPORT Fl_Region XRectangleRegion(int x, int y, int w, int h); // in fl_rect.cxx
00103 
00104 // feed events into fltk:
00105 FL_EXPORT int fl_handle(const XEvent&);
00106 
00107 // you can use these in Fl::add_handler() to look at events:
00108 extern FL_EXPORT const XEvent* fl_xevent;
00109 extern FL_EXPORT ulong fl_event_time;
00110 
00111 // off-screen pixmaps: create, destroy, draw into, copy to window:
00112 typedef ulong Fl_Offscreen;
00113 #   define fl_create_offscreen(w,h) \
00114   XCreatePixmap(fl_display, \
00115               (fl_surface->class_name() == Fl_Display_Device::class_id ? \
00116               fl_window : fl_xid(Fl::first_window()) ) , \
00117               w, h, fl_visual->depth)
00118 // begin/end are macros that save the old state in local variables:
00119 #    define fl_begin_offscreen(pixmap) \
00120   Window _sw=fl_window; fl_window=pixmap; \
00121   Fl_Surface_Device *_ss = fl_surface; fl_display_device->set_current(); \
00122   fl_push_no_clip()
00123 #    define fl_end_offscreen() \
00124   fl_pop_clip(); fl_window = _sw; _ss->set_current()
00125 
00126 extern void fl_copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy);
00127 #    define fl_delete_offscreen(pixmap) XFreePixmap(fl_display, pixmap)
00128 
00129 // Bitmap masks
00130 typedef ulong Fl_Bitmask;
00131 
00132 extern FL_EXPORT Fl_Bitmask fl_create_bitmask(int w, int h, const uchar *data);
00133 extern FL_EXPORT Fl_Bitmask fl_create_alphamask(int w, int h, int d, int ld, const uchar *data);
00134 extern FL_EXPORT void fl_delete_bitmask(Fl_Bitmask bm);
00135 
00136 // this object contains all X-specific stuff about a window:
00137 // Warning: this object is highly subject to change!  It's definition
00138 // is only here so that fl_xid can be declared inline:
00139 class FL_EXPORT Fl_X {
00140 public:
00141   Window xid;
00142   Window other_xid;
00143   Fl_Window *w;
00144   Fl_Region region;
00145   Fl_X *next;
00146   char wait_for_expose;
00147   char backbuffer_bad; // used for XDBE
00148   static Fl_X* first;
00149   static Fl_X* i(const Fl_Window* wi) {return wi->i;}
00150   void setwindow(Fl_Window* wi) {w=wi; wi->i=this;}
00151   void sendxjunk();
00152   static void make_xid(Fl_Window*,XVisualInfo* =fl_visual, Colormap=fl_colormap);
00153   static Fl_X* set_xid(Fl_Window*, Window);
00154   // kludges to get around protection:
00155   void flush() {w->flush();}
00156   static void x(Fl_Window* wi, int X) {wi->x(X);}
00157   static void y(Fl_Window* wi, int Y) {wi->y(Y);}
00158 };
00159 
00160 // convert xid <-> Fl_Window:
00161 inline Window fl_xid(const Fl_Window*w) {return Fl_X::i(w)->xid;}
00162 FL_EXPORT Fl_Window* fl_find(Window xid);
00163 
00164 extern FL_EXPORT char fl_override_redirect; // hack into Fl_X::make_xid()
00165 extern FL_EXPORT int fl_background_pixel;  // hack into Fl_X::make_xid()
00166 
00167 // Dummy function to register a function for opening files via the window manager...
00168 inline void fl_open_callback(void (*)(const char *)) {}
00169 
00170 extern FL_EXPORT int fl_parse_color(const char* p, uchar& r, uchar& g, uchar& b);
00171 
00172 #  endif
00173 #endif
00174 
00175 //
00176 // End of "$Id: x.H 8190 2011-01-05 10:21:45Z manolo $".
00177 //