1 //
2 // "$Id: win32.H 5436 2006-09-16 16:02:00Z matt $"
3 //
4 // WIN32 header file for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2005 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
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_X_H
33 #  error "Never use <FL/win32.H> directly; include <FL/x.H> instead."
34 #endif // !Fl_X_H
35 
36 #include <windows.h>
37 // In some of the distributions, the gcc header files are missing some stuff:
38 #ifndef LPMINMAXINFO
39 #define LPMINMAXINFO MINMAXINFO*
40 #endif
41 #ifndef VK_LWIN
42 #define VK_LWIN 0x5B
43 #define VK_RWIN 0x5C
44 #define VK_APPS 0x5D
45 #endif
46 
47 // some random X equivalents
48 typedef HWND Window;
49 typedef POINT XPoint;
50 struct XRectangle {int x, y, width, height;};
51 typedef HRGN Fl_Region;
52 FL_EXPORT void fl_clip_region(Fl_Region);
XRectangleRegion(int x,int y,int w,int h)53 inline Fl_Region XRectangleRegion(int x, int y, int w, int h) {
54     return CreateRectRgn(x,y,x+w,y+h);
55 }
XDestroyRegion(Fl_Region r)56 inline void XDestroyRegion(Fl_Region r) {DeleteObject(r);}
XClipBox(Fl_Region r,XRectangle * rect)57 inline void XClipBox(Fl_Region r,XRectangle* rect) {
58     RECT win_rect; GetRgnBox(r,&win_rect);
59     rect->x=win_rect.left;
60     rect->y=win_rect.top;
61     rect->width=win_rect.right-win_rect.left;
62     rect->height=win_rect.bottom-win_rect.top;
63 }
64 #define XDestroyWindow(a,b) DestroyWindow(b)
65 #define XMapWindow(a,b) ShowWindow(b, SW_RESTORE)
66 #define XUnmapWindow(a,b) ShowWindow(b, SW_HIDE)
67 
68 #include "Fl_Window.H"
69 // this object contains all win32-specific stuff about a window:
70 // Warning: this object is highly subject to change!
71 class FL_EXPORT Fl_X {
72 public:
73   // member variables - add new variables only at the end of this block
74   Window xid;
75   HBITMAP other_xid; // for double-buffered windows
76   Fl_Window* w;
77   Fl_Region region;
78   Fl_X *next;
79   int wait_for_expose;
80   HDC private_dc; // used for OpenGL
81   HCURSOR cursor;
82   HDC saved_hdc;  // saves the handle of the DC currently loaded
83   // static variables, static functions and member functions
84   static Fl_X* first;
i(const Fl_Window * w)85   static Fl_X* i(const Fl_Window* w) {return w->i;}
86   static int fake_X_wm(const Fl_Window* w,int &X, int &Y,
87 		                 int &bt,int &bx,int &by);
setwindow(Fl_Window * wi)88   void setwindow(Fl_Window* wi) {w=wi; wi->i=this;}
flush()89   void flush() {w->flush();}
90   void set_minmax(LPMINMAXINFO minmax);
91   void mapraise();
92   static Fl_X* make(Fl_Window*);
93 };
94 extern FL_EXPORT HCURSOR fl_default_cursor;
95 extern FL_EXPORT UINT fl_wake_msg;
fl_xid(const Fl_Window * w)96 inline Window fl_xid(const Fl_Window*w) {Fl_X *temp = Fl_X::i(w); return temp ? temp->xid : 0;}
97 FL_EXPORT Fl_Window* fl_find(Window xid);
98 extern FL_EXPORT char fl_override_redirect; // hack into Fl_Window::make_xid()
99 extern FL_EXPORT int fl_background_pixel;  // hack into Fl_Window::make_xid()
100 
101 // most recent fl_color() or fl_rgbcolor() points at one of these:
102 extern FL_EXPORT struct Fl_XMap {
103   COLORREF rgb;	// this should be the type the RGB() macro returns
104   HPEN pen;	// pen, 0 if none created yet
105   int brush;	// ref to solid brush, 0 if none created yet
106 } *fl_current_xmap;
fl_RGB()107 inline COLORREF fl_RGB() {return fl_current_xmap->rgb;}
fl_pen()108 inline HPEN fl_pen() {return fl_current_xmap->pen;}
109 FL_EXPORT HBRUSH fl_brush(); // allocates a brush if necessary
110 FL_EXPORT HBRUSH fl_brush_action(int); // now does the real work
111 
112 extern FL_EXPORT HINSTANCE fl_display;
113 extern FL_EXPORT Window fl_window;
114 extern FL_EXPORT HDC fl_gc;
115 extern FL_EXPORT HPALETTE fl_palette; // non-zero only on 8-bit displays!
116 extern FL_EXPORT HDC fl_GetDC(Window);
117 extern FL_EXPORT MSG fl_msg;
118 extern FL_EXPORT void fl_release_dc(HWND w, HDC dc);
119 extern FL_EXPORT void fl_save_dc( HWND w, HDC dc);
120 
121 // off-screen pixmaps: create, destroy, draw into, copy to window
122 typedef HBITMAP Fl_Offscreen;
123 #define fl_create_offscreen(w, h) CreateCompatibleBitmap(fl_gc, w, h)
124 
125 extern FL_EXPORT HDC fl_makeDC(HBITMAP);
126 
127 #define fl_begin_offscreen(b) \
128   HDC _sgc=fl_gc; Window _sw=fl_window; \
129   fl_gc=fl_makeDC(b); int _savedc = SaveDC(fl_gc); fl_window=(HWND)b; fl_push_no_clip()
130 
131 #define fl_end_offscreen() \
132   fl_pop_clip(); RestoreDC(fl_gc, _savedc); DeleteDC(fl_gc); fl_window=_sw; fl_gc = _sgc
133 
134 FL_EXPORT void fl_copy_offscreen(int x,int y,int w,int h,HBITMAP pixmap,int srcx,int srcy);
135 FL_EXPORT void fl_copy_offscreen_with_alpha(int x,int y,int w,int h,HBITMAP pixmap,int srcx,int srcy);
136 #define fl_delete_offscreen(bitmap) DeleteObject(bitmap);
137 
138 // Bitmap masks
139 typedef HBITMAP Fl_Bitmask;
140 
141 extern FL_EXPORT Fl_Bitmask fl_create_bitmask(int w, int h, const uchar *data);
142 extern FL_EXPORT Fl_Bitmask fl_create_alphamask(int w, int h, int d, int ld, const uchar *data);
143 extern FL_EXPORT void fl_delete_bitmask(Fl_Bitmask bm);
144 
145 // Dummy function to register a function for opening files via the window manager...
fl_open_callback(void (*)(const char *))146 inline void fl_open_callback(void (*)(const char *)) {}
147 
148 extern FL_EXPORT int fl_parse_color(const char* p, uchar& r, uchar& g, uchar& b);
149 
150 //
151 // End of "$Id: win32.H 5436 2006-09-16 16:02:00Z matt $".
152 //
153