2 // "$Id: x.H 8706 2011-05-21 10:05:19Z AlbrechtS $"
4 // X11 header file for the Fast Light Tool Kit (FLTK).
6 // Copyright 1998-2011 by Bill Spitzak and others.
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.
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.
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
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
28 // These are internal fltk symbols that are necessary or useful for
29 // calling Xlib. You should include this file if (and ONLY if) you
30 // need to call Xlib directly. These symbols may not exist on non-X
33 /** \class Fl_Mac_App_Menu
34 Mac OS-specific class allowing to localize the application menu.
36 These character strings are used to build the application menu. They can be localized
37 at run time to any UTF-8 text by placing instructions such as this \e very
40 Fl_Mac_App_Menu::print = "Imprimer la fenĂȘtre";
44 #if !defined(Fl_X_H) && !defined(FL_DOXYGEN)
47 # include "Enumerations.H"
48 #include <FL/Fl_Cairo.H>
52 # elif defined(__APPLE__)
55 # if defined(_ABIN32) || defined(_ABI64) // fix for broken SGI Irix X .h files
56 # pragma set woff 3322
58 # include <X11/Xlib.h>
59 # include <X11/Xutil.h>
60 # if defined(_ABIN32) || defined(_ABI64)
61 # pragma reset woff 3322
63 # include <X11/Xatom.h>
64 # include "Fl_Window.H"
66 // Mirror X definition of Region to Fl_Region, for portability...
67 typedef cairo_region_t * Fl_Region;
69 FL_EXPORT void fl_open_display();
70 FL_EXPORT void fl_open_display(Display*);
71 FL_EXPORT void fl_close_display();
73 // constant info about the X server connection:
74 extern FL_EXPORT Display *fl_display;
75 extern FL_EXPORT int fl_screen;
76 extern FL_EXPORT XVisualInfo *fl_visual;
77 extern FL_EXPORT Colormap fl_colormap;
81 extern FL_EXPORT GC fl_gc;
82 extern FL_EXPORT Window fl_window;
83 FL_EXPORT ulong fl_xpixel(Fl_Color i);
84 FL_EXPORT ulong fl_xpixel(uchar r, uchar g, uchar b);
85 FL_EXPORT void fl_clip_region(Fl_Region);
86 FL_EXPORT Fl_Region fl_clip_region();
88 // feed events into fltk:
89 FL_EXPORT int fl_handle(const XEvent&);
91 // you can use these in Fl::add_handler() to look at events:
92 extern FL_EXPORT const XEvent* fl_xevent;
93 extern FL_EXPORT ulong fl_event_time;
95 // off-screen pixmaps: create, destroy, draw into, copy to window:
96 typedef ulong Fl_Offscreen;
97 FL_EXPORT void fl_offscreen_get_dimensions ( Fl_Offscreen p, unsigned int *w, unsigned int *h );
98 # define fl_create_offscreen(w,h) \
99 XCreatePixmap(fl_display, \
100 (Fl_Surface_Device::surface()->class_name() == Fl_Display_Device::class_id ? \
101 fl_window : fl_xid(Fl::first_window()) ) , \
102 w, h, fl_visual->depth)
103 // begin/end are macros that save the old state in local variables:
104 # define fl_begin_offscreen(pixmap) \
105 Window _sw=fl_window; fl_window=pixmap; \
106 Fl_Surface_Device *_ss = Fl_Surface_Device::surface(); Fl_Display_Device::display_device()->set_current(); \
107 unsigned int _W, _H; \
108 fl_offscreen_get_dimensions( pixmap, &_W, &_H ); \
109 cairo_surface_t *_cs = Fl::cairo_create_surface( fl_window, _W, _H ); \
110 cairo_t *_old_cc = fl_cairo_context; \
111 fl_cairo_context = cairo_create( _cs ); \
112 cairo_surface_destroy( _cs ); \
114 # define fl_end_offscreen() \
115 fl_pop_clip(); fl_window = _sw; _ss->set_current(); \
116 cairo_destroy( fl_cairo_context ); \
117 fl_cairo_context = _old_cc
119 extern void fl_copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy);
120 # define fl_delete_offscreen(pixmap) XFreePixmap(fl_display, pixmap)
123 typedef ulong Fl_Bitmask;
125 extern FL_EXPORT Fl_Bitmask fl_create_bitmask(int w, int h, const uchar *data);
126 extern FL_EXPORT Fl_Bitmask fl_create_alphamask(int w, int h, int d, int ld, const uchar *data);
127 extern FL_EXPORT void fl_delete_bitmask(Fl_Bitmask bm);
129 #if defined(FL_LIBRARY) || defined(FL_INTERNALS)
130 extern FL_EXPORT Window fl_message_window;
131 extern FL_EXPORT void *fl_xftfont;
132 FL_EXPORT Fl_Region XRectangleRegion(int x, int y, int w, int h); // in fl_rect.cxx
134 // access to core fonts:
135 // This class provides a "smart pointer" that returns a pointer to an XFontStruct.
136 // The global variable fl_xfont can be called wherever a bitmap "core" font is
137 // needed, e.g. when rendering to a GL context under X11.
138 // With Xlib / X11 fonts, fl_xfont will return the current selected font.
139 // With XFT / X11 fonts, fl_xfont will attempt to return the bitmap "core" font most
140 // similar to (usually the same as) the current XFT font.
141 class Fl_XFont_On_Demand
144 Fl_XFont_On_Demand(XFontStruct* p = NULL) : ptr(p) { }
145 Fl_XFont_On_Demand& operator=(const Fl_XFont_On_Demand& x)
146 { ptr = x.ptr; return *this; }
147 Fl_XFont_On_Demand& operator=(XFontStruct* p)
148 { ptr = p; return *this; }
149 XFontStruct* value();
150 operator XFontStruct*() { return value(); }
151 XFontStruct& operator*() { return *value(); }
152 XFontStruct* operator->() { return value(); }
153 bool operator==(const Fl_XFont_On_Demand& x) { return ptr == x.ptr; }
154 bool operator!=(const Fl_XFont_On_Demand& x) { return ptr != x.ptr; }
158 extern FL_EXPORT Fl_XFont_On_Demand fl_xfont;
160 // this object contains all X-specific stuff about a window:
161 // Warning: this object is highly subject to change!
162 // FL_LIBRARY or FL_INTERNALS must be defined to access this class.
163 class FL_EXPORT Fl_X {
166 Window other_xid; /* for double buffering */
168 cairo_t *other_cc; /* for double buffering */
172 char wait_for_expose;
173 char cairo_surface_invalid;
175 static Fl_X* i(const Fl_Window* wi) {return wi->i;}
176 void setwindow(Fl_Window* wi) {w=wi; wi->i=this;}
178 static void make_xid(Fl_Window*,XVisualInfo* =fl_visual, Colormap=fl_colormap);
179 static Fl_X* set_xid(Fl_Window*, Window);
180 // kludges to get around protection:
181 void flush() {w->flush();}
182 static void x(Fl_Window* wi, int X) {wi->x(X);}
183 static void y(Fl_Window* wi, int Y) {wi->y(Y);}
186 extern FL_EXPORT char fl_override_redirect; // hack into Fl_X::make_xid()
187 extern FL_EXPORT int fl_background_pixel; // hack into Fl_X::make_xid()
188 extern FL_EXPORT Window fl_parent_window; // hack into Fl_X::make_xid()
190 inline Window fl_xid(const Fl_Window* w) { Fl_X *temp = Fl_X::i(w); return temp ? temp->xid : 0; }
194 extern Window fl_xid_(const Fl_Window* w);
195 #define fl_xid(w) fl_xid_(w)
197 #endif // FL_LIBRARY || FL_INTERNALS
199 FL_EXPORT Fl_Window* fl_find(Window xid);
200 FL_EXPORT void fl_embed ( Fl_Window *w, Window parent );
201 extern FL_EXPORT bool fl_embed_called;
203 // Dummy function to register a function for opening files via the window manager...
204 inline void fl_open_callback(void (*)(const char *)) {}
206 extern FL_EXPORT int fl_parse_color(const char* p, uchar& r, uchar& g, uchar& b);
212 // End of "$Id: x.H 8706 2011-05-21 10:05:19Z AlbrechtS $".