blob: 9297e9f7bc14d70b39a3769b82bc2e2b697185e6 [file] [log] [blame]
DRC2ff39b82011-07-28 08:38:59 +00001//
2// "$Id: win32.H 8726 2011-05-23 18:32:47Z AlbrechtS $"
3//
4// WIN32 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// Do not directly include this file, instead use <FL/x.H>. It will
29// include this file if WIN32 is defined. This is to encourage
30// portability of even the system-specific code...
31
32#ifndef FL_DOXYGEN
33#ifndef Fl_X_H
34# error "Never use <FL/win32.H> directly; include <FL/x.H> instead."
35#endif // !Fl_X_H
36
37#include <windows.h>
38typedef HRGN Fl_Region;
39typedef HWND Window;
40typedef POINT XPoint;
41
42#include <FL/Fl_Window.H>
43
44// this part is included only when compiling the FLTK library or if requested explicitly
45#if defined(FL_LIBRARY) || defined(FL_INTERNALS)
46
47// In some of the distributions, the gcc header files are missing some stuff:
48#ifndef LPMINMAXINFO
49#define LPMINMAXINFO MINMAXINFO*
50#endif
51#ifndef VK_LWIN
52#define VK_LWIN 0x5B
53#define VK_RWIN 0x5C
54#define VK_APPS 0x5D
55#endif
56
57// some random X equivalents
58struct XRectangle {int x, y, width, height;};
59extern Fl_Region XRectangleRegion(int x, int y, int w, int h);
60inline void XDestroyRegion(Fl_Region r) {DeleteObject(r);}
61inline void XClipBox(Fl_Region r,XRectangle* rect) {
62 RECT win_rect; GetRgnBox(r,&win_rect);
63 rect->x=win_rect.left;
64 rect->y=win_rect.top;
65 rect->width=win_rect.right-win_rect.left;
66 rect->height=win_rect.bottom-win_rect.top;
67}
68#define XDestroyWindow(a,b) DestroyWindow(b)
69#define XMapWindow(a,b) ShowWindow(b, SW_RESTORE)
70#define XUnmapWindow(a,b) ShowWindow(b, SW_HIDE)
71
72// this object contains all win32-specific stuff about a window:
73// Warning: this object is highly subject to change!
74class FL_EXPORT Fl_X {
75public:
76 // member variables - add new variables only at the end of this block
77 Window xid;
78 HBITMAP other_xid; // for double-buffered windows
79 Fl_Window* w;
80 Fl_Region region;
81 Fl_X *next;
82 int wait_for_expose;
83 HDC private_dc; // used for OpenGL
84 HCURSOR cursor;
Henrik Andersson485f4192011-09-16 11:51:32 +000085 int custom_cursor;
DRC2ff39b82011-07-28 08:38:59 +000086 HDC saved_hdc; // saves the handle of the DC currently loaded
87 // static variables, static functions and member functions
88 static Fl_X* first;
89 static Fl_X* i(const Fl_Window* w) {return w->i;}
90 static int fake_X_wm(const Fl_Window* w,int &X, int &Y,
91 int &bt,int &bx,int &by);
92 void setwindow(Fl_Window* wi) {w=wi; wi->i=this;}
93 void flush() {w->flush();}
94 void set_minmax(LPMINMAXINFO minmax);
95 void mapraise();
DRC685f17e2011-07-28 09:23:00 +000096 int set_cursor(Fl_Cursor);
97 int set_cursor(const Fl_RGB_Image*, int, int);
DRC2ff39b82011-07-28 08:38:59 +000098 static Fl_X* make(Fl_Window*);
99};
100extern FL_EXPORT HCURSOR fl_default_cursor;
101extern FL_EXPORT UINT fl_wake_msg;
102extern FL_EXPORT char fl_override_redirect; // hack into Fl_Window::make_xid()
103extern FL_EXPORT int fl_background_pixel; // hack into Fl_Window::make_xid()
104extern FL_EXPORT HPALETTE fl_palette; // non-zero only on 8-bit displays!
105extern FL_EXPORT void fl_release_dc(HWND w, HDC dc);
106extern FL_EXPORT void fl_save_dc( HWND w, HDC dc);
107
108inline Window fl_xid(const Fl_Window* w) { Fl_X *temp = Fl_X::i(w); return temp ? temp->xid : 0; }
109
110#else
111FL_EXPORT Window fl_xid_(const Fl_Window* w);
112#define fl_xid(w) fl_xid_(w)
113#endif // FL_LIBRARY || FL_INTERNALS
114
115FL_EXPORT Fl_Window* fl_find(Window xid);
116void fl_clip_region(Fl_Region);
117
118// most recent fl_color() or fl_rgbcolor() points at one of these:
119extern FL_EXPORT struct Fl_XMap {
120 COLORREF rgb; // this should be the type the RGB() macro returns
121 HPEN pen; // pen, 0 if none created yet
122 int brush; // ref to solid brush, 0 if none created yet
123} *fl_current_xmap;
124inline COLORREF fl_RGB() {return fl_current_xmap->rgb;}
125inline HPEN fl_pen() {return fl_current_xmap->pen;}
126FL_EXPORT HBRUSH fl_brush(); // allocates a brush if necessary
127FL_EXPORT HBRUSH fl_brush_action(int); // now does the real work
128
129extern FL_EXPORT HINSTANCE fl_display;
130extern FL_EXPORT Window fl_window;
131extern FL_EXPORT HDC fl_gc;
132extern FL_EXPORT MSG fl_msg;
133extern FL_EXPORT HDC fl_GetDC(Window);
134extern FL_EXPORT HDC fl_makeDC(HBITMAP);
135
136// off-screen pixmaps: create, destroy, draw into, copy to window
137typedef HBITMAP Fl_Offscreen;
138#define fl_create_offscreen(w, h) \
139 CreateCompatibleBitmap( (fl_gc ? fl_gc : fl_GetDC(0) ) , w, h)
140
141# define fl_begin_offscreen(b) \
142 HDC _sgc=fl_gc; Window _sw=fl_window; \
143 Fl_Surface_Device *_ss = Fl_Surface_Device::surface(); Fl_Display_Device::display_device()->set_current(); \
144 fl_gc=fl_makeDC(b); int _savedc = SaveDC(fl_gc); fl_window=(HWND)b; fl_push_no_clip()
145
146# define fl_end_offscreen() \
147 fl_pop_clip(); RestoreDC(fl_gc, _savedc); DeleteDC(fl_gc); _ss->set_current(); fl_window=_sw; fl_gc = _sgc
148
149
150FL_EXPORT void fl_copy_offscreen(int x,int y,int w,int h,HBITMAP pixmap,int srcx,int srcy);
151FL_EXPORT void fl_copy_offscreen_with_alpha(int x,int y,int w,int h,HBITMAP pixmap,int srcx,int srcy);
152#define fl_delete_offscreen(bitmap) DeleteObject(bitmap)
153
154// Bitmap masks
155typedef HBITMAP Fl_Bitmask;
156
157extern FL_EXPORT Fl_Bitmask fl_create_bitmask(int w, int h, const uchar *data);
158extern FL_EXPORT Fl_Bitmask fl_create_alphamask(int w, int h, int d, int ld, const uchar *data);
159extern FL_EXPORT void fl_delete_bitmask(Fl_Bitmask bm);
160
161// Dummy function to register a function for opening files via the window manager...
162inline void fl_open_callback(void (*)(const char *)) {}
163
164extern FL_EXPORT int fl_parse_color(const char* p, uchar& r, uchar& g, uchar& b);
165#endif // FL_DOXYGEN
166//
167// End of "$Id: win32.H 8726 2011-05-23 18:32:47Z AlbrechtS $".
168//