FLTK 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 
44 #if !defined(Fl_X_H) && !defined(FL_DOXYGEN)
45 # define Fl_X_H
46 
47 # include "Enumerations.H"
48 
49 # ifdef WIN32
50 # include "win32.H"
51 # elif defined(__APPLE__)
52 # include "mac.H"
53 # else
54 # if defined(_ABIN32) || defined(_ABI64) // fix for broken SGI Irix X .h files
55 # pragma set woff 3322
56 # endif
57 # include <X11/Xlib.h>
58 # include <X11/Xutil.h>
59 # if defined(_ABIN32) || defined(_ABI64)
60 # pragma reset woff 3322
61 # endif
62 # include <X11/Xatom.h>
63 # include "Fl_Window.H"
64 # include "Xutf8.h"
65 // Mirror X definition of Region to Fl_Region, for portability...
66 typedef Region Fl_Region;
67 
68 FL_EXPORT void fl_open_display();
69 FL_EXPORT void fl_open_display(Display*);
70 FL_EXPORT void fl_close_display();
71 
72 // constant info about the X server connection:
73 extern FL_EXPORT Display *fl_display;
74 extern FL_EXPORT int fl_screen;
75 extern FL_EXPORT XVisualInfo *fl_visual;
76 extern FL_EXPORT Colormap fl_colormap;
77 
78 
79 // drawing functions:
80 extern FL_EXPORT GC fl_gc;
81 extern FL_EXPORT Window fl_window;
82 FL_EXPORT ulong fl_xpixel(Fl_Color i);
83 FL_EXPORT ulong fl_xpixel(uchar r, uchar g, uchar b);
84 FL_EXPORT void fl_clip_region(Fl_Region);
85 FL_EXPORT Fl_Region fl_clip_region();
86 
87 // feed events into fltk:
88 FL_EXPORT int fl_handle(const XEvent&);
89 
90 // you can use these in Fl::add_handler() to look at events:
91 extern FL_EXPORT const XEvent* fl_xevent;
92 extern FL_EXPORT ulong fl_event_time;
93 
94 // off-screen pixmaps: create, destroy, draw into, copy to window:
95 typedef ulong Fl_Offscreen;
96 # define fl_create_offscreen(w,h) \
97  XCreatePixmap(fl_display, \
98  (Fl_Surface_Device::surface()->class_name() == Fl_Display_Device::class_id ? \
99  fl_window : fl_xid(Fl::first_window()) ) , \
100  w, h, fl_visual->depth)
101 // begin/end are macros that save the old state in local variables:
102 # define fl_begin_offscreen(pixmap) \
103  Window _sw=fl_window; fl_window=pixmap; \
104  Fl_Surface_Device *_ss = Fl_Surface_Device::surface(); Fl_Display_Device::display_device()->set_current(); \
105  fl_push_no_clip()
106 # define fl_end_offscreen() \
107  fl_pop_clip(); fl_window = _sw; _ss->set_current()
108 
109 extern void fl_copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy);
110 # define fl_delete_offscreen(pixmap) XFreePixmap(fl_display, pixmap)
111 
112 // Bitmap masks
113 typedef ulong Fl_Bitmask;
114 
115 extern FL_EXPORT Fl_Bitmask fl_create_bitmask(int w, int h, const uchar *data);
116 extern FL_EXPORT Fl_Bitmask fl_create_alphamask(int w, int h, int d, int ld, const uchar *data);
117 extern FL_EXPORT void fl_delete_bitmask(Fl_Bitmask bm);
118 
119 #if defined(FL_LIBRARY) || defined(FL_INTERNALS)
120 extern FL_EXPORT Window fl_message_window;
121 extern FL_EXPORT void *fl_xftfont;
122 FL_EXPORT Fl_Region XRectangleRegion(int x, int y, int w, int h); // in fl_rect.cxx
123 
124 // access to core fonts:
125 // This class provides a "smart pointer" that returns a pointer to an XFontStruct.
126 // The global variable fl_xfont can be called wherever a bitmap "core" font is
127 // needed, e.g. when rendering to a GL context under X11.
128 // With Xlib / X11 fonts, fl_xfont will return the current selected font.
129 // With XFT / X11 fonts, fl_xfont will attempt to return the bitmap "core" font most
130 // similar to (usually the same as) the current XFT font.
131 class Fl_XFont_On_Demand
132 {
133 public:
134  Fl_XFont_On_Demand(XFontStruct* p = NULL) : ptr(p) { }
135  Fl_XFont_On_Demand& operator=(const Fl_XFont_On_Demand& x)
136  { ptr = x.ptr; return *this; }
137  Fl_XFont_On_Demand& operator=(XFontStruct* p)
138  { ptr = p; return *this; }
139  XFontStruct* value();
140  operator XFontStruct*() { return value(); }
141  XFontStruct& operator*() { return *value(); }
142  XFontStruct* operator->() { return value(); }
143  bool operator==(const Fl_XFont_On_Demand& x) { return ptr == x.ptr; }
144  bool operator!=(const Fl_XFont_On_Demand& x) { return ptr != x.ptr; }
145 private:
146  XFontStruct *ptr;
147 };
148 extern FL_EXPORT Fl_XFont_On_Demand fl_xfont;
149 
150 // this object contains all X-specific stuff about a window:
151 // Warning: this object is highly subject to change!
152 // FL_LIBRARY or FL_INTERNALS must be defined to access this class.
153 class FL_EXPORT Fl_X {
154 public:
155  Window xid;
156  Window other_xid;
157  Fl_Window *w;
158  Fl_Region region;
159  Fl_X *next;
160  char wait_for_expose;
161  char backbuffer_bad; // used for XDBE
162  static Fl_X* first;
163  static Fl_X* i(const Fl_Window* wi) {return wi->i;}
164  void setwindow(Fl_Window* wi) {w=wi; wi->i=this;}
165  void sendxjunk();
166  static void make_xid(Fl_Window*,XVisualInfo* =fl_visual, Colormap=fl_colormap);
167  static Fl_X* set_xid(Fl_Window*, Window);
168  // kludges to get around protection:
169  void flush() {w->flush();}
170  static void x(Fl_Window* wi, int X) {wi->x(X);}
171  static void y(Fl_Window* wi, int Y) {wi->y(Y);}
172 };
173 
174 extern FL_EXPORT char fl_override_redirect; // hack into Fl_X::make_xid()
175 extern FL_EXPORT int fl_background_pixel; // hack into Fl_X::make_xid()
176 
177 inline Window fl_xid(const Fl_Window* w) { Fl_X *temp = Fl_X::i(w); return temp ? temp->xid : 0; }
178 
179 #else
180 
181 extern Window fl_xid_(const Fl_Window* w);
182 #define fl_xid(w) fl_xid_(w)
183 
184 #endif // FL_LIBRARY || FL_INTERNALS
185 
186 FL_EXPORT Fl_Window* fl_find(Window xid);
187 
188 
189 // Dummy function to register a function for opening files via the window manager...
190 inline void fl_open_callback(void (*)(const char *)) {}
191 
192 extern FL_EXPORT int fl_parse_color(const char* p, uchar& r, uchar& g, uchar& b);
193 
194 # endif
195 #endif
196 
197 //
198 // End of "$Id: x.H 8706 2011-05-21 10:05:19Z AlbrechtS $".
199 //
This widget produces an actual window.
Definition: Fl_Window.H:58
void fl_clip_region(Fl_Region r)
Replaces the top of the clipping stack with a clipping region of any shape.
Definition: fl_draw.H:145
void y(int v)
Internal use only.
Definition: Fl_Widget.H:149
void fl_open_callback(void(*cb)(const char *))
Register a function called for each file dropped onto an application icon.
unsigned long ulong
unsigned long
Definition: fl_types.h:41
This file contains type definitions and general enumerations.
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:159
unsigned int Fl_Color
an FLTK color value
Definition: Enumerations.H:769
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:82
unsigned char uchar
unsigned char
Definition: fl_types.h:39
void x(int v)
Internal use only.
Definition: Fl_Widget.H:147