NTK 1.3.0
x.H
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
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
31// systems.
32
43
44#if !defined(Fl_X_H) && !defined(FL_DOXYGEN)
45# define Fl_X_H
46
47# include "Enumerations.H"
48#include <FL/Fl_Cairo.H>
49
50# ifdef WIN32
51# include "win32.H"
52# elif defined(__APPLE__)
53# include "mac.H"
54# else
55# if defined(_ABIN32) || defined(_ABI64) // fix for broken SGI Irix X .h files
56# pragma set woff 3322
57# endif
58# include <X11/Xlib.h>
59# include <X11/Xutil.h>
60# if defined(_ABIN32) || defined(_ABI64)
61# pragma reset woff 3322
62# endif
63# include <X11/Xatom.h>
64# include "Fl_Window.H"
65# include "Xutf8.h"
66// Mirror X definition of Region to Fl_Region, for portability...
67typedef cairo_region_t * Fl_Region;
68
69FL_EXPORT void fl_open_display();
70FL_EXPORT void fl_open_display(Display*);
71FL_EXPORT void fl_close_display();
72
73// constant info about the X server connection:
74extern FL_EXPORT Display *fl_display;
75extern FL_EXPORT int fl_screen;
76extern FL_EXPORT XVisualInfo *fl_visual;
77extern FL_EXPORT Colormap fl_colormap;
78
79
80// drawing functions:
81extern FL_EXPORT GC fl_gc;
82extern FL_EXPORT Window fl_window;
83FL_EXPORT ulong fl_xpixel(Fl_Color i);
84FL_EXPORT ulong fl_xpixel(uchar r, uchar g, uchar b);
85FL_EXPORT void fl_clip_region(Fl_Region);
86FL_EXPORT Fl_Region fl_clip_region();
87
88// feed events into fltk:
89FL_EXPORT int fl_handle(const XEvent&);
90
91// you can use these in Fl::add_handler() to look at events:
92extern FL_EXPORT const XEvent* fl_xevent;
93extern FL_EXPORT ulong fl_event_time;
94
95// off-screen pixmaps: create, destroy, draw into, copy to window:
96typedef ulong Fl_Offscreen;
97FL_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 ); \
113 fl_push_no_clip()
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
118
119extern 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)
121
122// Bitmap masks
123typedef ulong Fl_Bitmask;
124
125extern FL_EXPORT Fl_Bitmask fl_create_bitmask(int w, int h, const uchar *data);
126extern FL_EXPORT Fl_Bitmask fl_create_alphamask(int w, int h, int d, int ld, const uchar *data);
127extern FL_EXPORT void fl_delete_bitmask(Fl_Bitmask bm);
128
129#if defined(FL_LIBRARY) || defined(FL_INTERNALS)
130extern FL_EXPORT Window fl_message_window;
131extern FL_EXPORT void *fl_xftfont;
132FL_EXPORT Fl_Region XRectangleRegion(int x, int y, int w, int h); // in fl_rect.cxx
133
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.
141class Fl_XFont_On_Demand
142{
143public:
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; }
155private:
156 XFontStruct *ptr;
157};
158extern FL_EXPORT Fl_XFont_On_Demand fl_xfont;
159
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.
163class FL_EXPORT Fl_X {
164public:
165 Window xid;
166 Window other_xid; /* for double buffering */
167 cairo_t *cc;
168 cairo_t *other_cc; /* for double buffering */
169 Fl_Window *w;
170 Fl_Region region;
171 Fl_X *next;
172 char wait_for_expose;
173 char cairo_surface_invalid;
174 static Fl_X* first;
175 static Fl_X* i(const Fl_Window* wi) {return wi->i;}
176 void setwindow(Fl_Window* wi) {w=wi; wi->i=this;}
177 void sendxjunk();
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);}
184};
185
186extern FL_EXPORT char fl_override_redirect; // hack into Fl_X::make_xid()
187extern FL_EXPORT int fl_background_pixel; // hack into Fl_X::make_xid()
188extern FL_EXPORT Window fl_parent_window; // hack into Fl_X::make_xid()
189
190inline Window fl_xid(const Fl_Window* w) { Fl_X *temp = Fl_X::i(w); return temp ? temp->xid : 0; }
191
192#else
193
194extern Window fl_xid_(const Fl_Window* w);
195#define fl_xid(w) fl_xid_(w)
196
197#endif // FL_LIBRARY || FL_INTERNALS
198
199FL_EXPORT Fl_Window* fl_find(Window xid);
200FL_EXPORT void fl_embed ( Fl_Window *w, Window parent );
201extern FL_EXPORT bool fl_embed_called;
202
203// Dummy function to register a function for opening files via the window manager...
204inline void fl_open_callback(void (*)(const char *)) {}
205
206extern FL_EXPORT int fl_parse_color(const char* p, uchar& r, uchar& g, uchar& b);
207
208# endif
209#endif
210
211//
212// End of "$Id: x.H 8706 2011-05-21 10:05:19Z AlbrechtS $".
213//
This file contains type definitions and general enumerations.
unsigned int Fl_Color
an FLTK color value
Definition Enumerations.H:764
void x(int v)
Internal use only.
Definition Fl_Widget.H:150
void y(int v)
Internal use only.
Definition Fl_Widget.H:152
This widget produces an actual window.
Definition Fl_Window.H:58
virtual void flush()
Forces the window to be drawn, this window is also made current and calls draw().
Definition Fl.cxx:1751
unsigned char uchar
unsigned char
Definition fl_types.h:39
unsigned long ulong
unsigned long
Definition fl_types.h:41
ulong fl_xpixel(uchar r, uchar g, uchar b)
Returns the X pixel number used to draw the given rgb color.
Definition fl_color.cxx:147
Fl_Region fl_clip_region()
Returns the current clipping region.
Definition fl_draw.H:149
void fl_copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy)
Copy a rectangular area of the given offscreen buffer into the current drawing destination.
Definition Fl_Double_Window.cxx:58
void fl_open_callback(void(*cb)(const char *))
Register a function called for each file dropped onto an application icon.