]> Pileus Git - ~andy/gtk/blob - gdk/win32/gdkprivate-win32.h
a35bd703b0b80b9a4e24314139b1d11c3e56ccf8
[~andy/gtk] / gdk / win32 / gdkprivate-win32.h
1 /* GDK - The GIMP Drawing Kit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /*
21  * Modified by the GTK+ Team and others 1997-1999.  See the AUTHORS
22  * file for a list of people on the GTK+ Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
25  */
26
27 #ifndef __GDK_PRIVATE_H__
28 #define __GDK_PRIVATE_H__
29
30 #define STRICT                  /* We want strict type checks */
31 #include <windows.h>
32
33 /* Make up for some minor mingw32 lossage */
34
35 /* PS_JOIN_MASK is missing from the mingw32 headers */
36 #ifndef PS_JOIN_MASK
37 #define PS_JOIN_MASK (PS_JOIN_BEVEL|PS_JOIN_MITER|PS_JOIN_ROUND)
38 #endif
39
40 /* CLR_INVALID is missing */
41 #ifndef CLR_INVALID
42 #define CLR_INVALID CLR_NONE
43 #endif
44
45 /* MB_CUR_MAX is missing */
46 #ifndef MB_CUR_MAX
47 extern int *__imp___mb_cur_max;
48 #define MB_CUR_MAX (*__imp___mb_cur_max)
49 #endif
50
51 #include <time.h>
52
53 #include <gdk/gdktypes.h>
54
55 #include <gdk/gdkcursor.h>
56 #include <gdk/gdkevents.h>
57 #include <gdk/gdkfont.h>
58 #include <gdk/gdkgc.h>
59 #include <gdk/gdkim.h>
60 #include <gdk/gdkimage.h>
61 #include <gdk/gdkregion.h>
62 #include <gdk/gdkvisual.h>
63 #include <gdk/gdkwindow.h>
64
65 #define GDK_DRAWABLE_TYPE(d) (((GdkDrawablePrivate *)d)->window_type)
66 #define GDK_IS_WINDOW(d) (GDK_DRAWABLE_TYPE(d) <= GDK_WINDOW_TEMP || \
67                           GDK_DRAWABLE_TYPE(d) == GDK_WINDOW_FOREIGN)
68 #define GDK_IS_PIXMAP(d) (GDK_DRAWABLE_TYPE(d) == GDK_DRAWABLE_PIXMAP)
69 #define GDK_DRAWABLE_DESTROYED(d) (((GdkDrawablePrivate *)d)->destroyed)
70
71 #define gdk_window_lookup(xid)     ((GdkWindow*) gdk_xid_table_lookup (xid))
72 #define gdk_pixmap_lookup(xid)     ((GdkPixmap*) gdk_xid_table_lookup (xid))
73
74 /* HFONTs clash with HWNDs, so add dithering to HFONTs... (hack) */
75 #define HFONT_DITHER 43
76 #define gdk_font_lookup(xid)       ((GdkFont*) gdk_xid_table_lookup ((HANDLE) ((guint) xid + HFONT_DITHER)))
77
78 #ifdef __cplusplus
79 extern "C" {
80 #endif /* __cplusplus */
81
82 /* Define corresponding Windows types for some X11 types, just for laziness.
83  */
84
85 typedef HANDLE XID;
86 typedef PALETTEENTRY XColor;
87 typedef HDC GC;
88 typedef ATOM Atom;
89 typedef HCURSOR Cursor;
90 typedef guint VisualID;
91 typedef DWORD KeySym;
92 typedef int Status;
93
94 /* Define some of the X11 constants also here, again just for laziness */
95
96 /* Generic null resource */
97 #define None 0
98
99 /* Error codes */
100 #define Success            0
101
102 /* Grabbing status */
103 #define GrabSuccess        0
104 #define AlreadyGrabbed     2
105
106 /* For CreateColormap */
107 #define AllocNone 0
108 #define AllocAll 1
109
110 /* Notify modes */
111 #define NotifyNormal 0
112 #define NotifyHint 1
113
114 /* Some structs are somewhat useful to emulate internally, just to
115    keep the code less #ifdefed.  */
116 typedef struct {
117   HPALETTE palette;             /* Palette handle used when drawing. */
118   guint size;                   /* Number of entries in the palette. */
119   gboolean stale;               /* 1 if palette needs to be realized,
120                                  * otherwise 0. */
121   gboolean *in_use;
122   gboolean rc_palette;          /* If RC_PALETTE is on in the RASTERCAPS */
123   gulong sizepalette;           /* SIZEPALETTE if rc_palette */
124 } ColormapStruct, *Colormap;
125   
126 typedef struct {
127   gint map_entries;
128   guint visualid;
129   guint bitspixel;
130 } Visual;
131
132 typedef struct {
133   Colormap colormap;
134   unsigned long red_max;
135   unsigned long red_mult;
136   unsigned long green_max;
137   unsigned long green_mult;
138   unsigned long blue_max;
139   unsigned long blue_mult;
140   unsigned long base_pixel;
141 } XStandardColormap;
142
143 typedef struct _GdkDrawablePrivate     GdkDrawablePrivate;
144 /* typedef struct _GdkDrawablePrivate     GdkPixmapPrivate; */
145 typedef struct _GdkWindowPrivate       GdkWindowPrivate;
146 typedef struct _GdkImagePrivate        GdkImagePrivate;
147 typedef struct _GdkGCPrivate           GdkGCPrivate;
148 typedef struct _GdkColormapPrivate     GdkColormapPrivate;
149 typedef struct _GdkColorInfo           GdkColorInfo;
150 typedef struct _GdkVisualPrivate       GdkVisualPrivate;
151 typedef struct _GdkFontPrivate         GdkFontPrivate;
152 typedef struct _GdkCursorPrivate       GdkCursorPrivate;
153 typedef struct _GdkEventFilter         GdkEventFilter;
154 typedef struct _GdkClientFilter        GdkClientFilter;
155 typedef struct _GdkRegionPrivate       GdkRegionPrivate;
156
157 struct _GdkDrawablePrivate
158 {
159   GdkDrawable drawable;
160
161   guint8 window_type;
162   guint ref_count;
163
164   guint16 width;
165   guint16 height;
166
167   HANDLE xwindow;
168   GdkColormap *colormap;
169
170   guint destroyed : 2;
171 };
172
173 struct _GdkWindowPrivate
174 {
175   GdkDrawablePrivate drawable;
176
177   GdkWindow *parent;
178   gint16 x;
179   gint16 y;
180   guint8 resize_count;
181   guint mapped : 1;
182   guint guffaw_gravity : 1;
183
184   /* We must keep the event mask here to filter them ourselves */
185   gint event_mask;
186
187   /* Values for bg_type */
188 #define GDK_WIN32_BG_NORMAL 0
189 #define GDK_WIN32_BG_PIXEL 1
190 #define GDK_WIN32_BG_PIXMAP 2
191 #define GDK_WIN32_BG_PARENT_RELATIVE 3
192 #define GDK_WIN32_BG_TRANSPARENT 4
193
194   /* We draw the background ourselves at WM_ERASEBKGND  */
195   guchar bg_type;
196   GdkColor bg_pixel;
197   GdkPixmap *bg_pixmap;
198
199   HCURSOR xcursor;
200
201   /* Window size hints */
202   gint hint_flags;
203   gint hint_x, hint_y;
204   gint hint_min_width, hint_min_height;
205   gint hint_max_width, hint_max_height;
206
207   gint extension_events;
208   gboolean extension_events_selected;
209
210   GList *filters;
211   GList *children;
212 };
213
214 struct _GdkImagePrivate
215 {
216   GdkImage image;
217   HBITMAP ximage;
218   gpointer x_shm_info;
219
220   void (*image_put) (GdkDrawable *window,
221                      GdkGC       *gc,
222                      GdkImage    *image,
223                      gint         xsrc,
224                      gint         ysrc,
225                      gint         xdest,
226                      gint         ydest,
227                      gint         width,
228                      gint         height);
229 };
230
231 struct _GdkGCPrivate
232 {
233   GdkGC gc;
234   GC xgc;
235   /* A Windows Device Context (DC) is not equivalent to an X11
236    * GC. We can use a DC only in the window for which it was
237    * allocated, or (in the case of a memory DC) with the bitmap that
238    * has been selected into it. Thus, we have to release and
239    * reallocate a DC each time the GdkGC is used to paint into a new
240    * window or pixmap. We thus keep all the necessary values in the
241    * GdkGCPrivate struct.
242    */
243   GdkGCValuesMask values_mask;
244   GdkColor foreground;
245   GdkColor background;
246   HFONT font;
247   gint rop2;
248   GdkFill fill_style;
249   GdkPixmap *tile;
250   GdkPixmap *stipple;
251   HRGN clip_region;
252   GdkSubwindowMode subwindow_mode;
253   gint ts_x_origin;
254   gint ts_y_origin;
255   gint clip_x_origin;
256   gint clip_y_origin;
257   gint graphics_exposures;
258   gint pen_width;
259   DWORD pen_style;
260   HANDLE hwnd;                  /* If a DC is allocated, for which window
261                                    or what bitmap is selected into it */
262   int saved_dc;
263   guint ref_count;
264 };
265
266 typedef enum {
267   GDK_COLOR_WRITEABLE = 1 << 0
268 } GdkColorInfoFlags;
269
270 struct _GdkColorInfo
271 {
272   GdkColorInfoFlags flags;
273   guint ref_count;
274 };
275
276 struct _GdkColormapPrivate
277 {
278   GdkColormap colormap;
279   Colormap xcolormap;
280   GdkVisual *visual;
281   gint private_val;
282
283   GHashTable *hash;
284   GdkColorInfo *info;
285   time_t last_sync_time;
286   
287   guint ref_count;
288 };
289
290 struct _GdkVisualPrivate
291 {
292   GdkVisual visual;
293   Visual *xvisual;
294 };
295
296 struct _GdkFontPrivate
297 {
298   GdkFont font;
299   /* XFontStruct *xfont; */
300   /* generic pointer point to XFontStruct or XFontSet */
301   /* in Win32 a HFONT */ 
302   gpointer xfont;
303   guint ref_count;
304 };
305
306 struct _GdkCursorPrivate
307 {
308   GdkCursor cursor;
309   Cursor xcursor;
310 };
311
312 struct _GdkEventFilter {
313   GdkFilterFunc function;
314   gpointer data;
315 };
316
317 struct _GdkClientFilter {
318   GdkAtom       type;
319   GdkFilterFunc function;
320   gpointer      data;
321 };
322
323 struct _GdkRegionPrivate
324 {
325   GdkRegion region;
326   HRGN xregion;
327 };
328
329 typedef enum {
330   GDK_DEBUG_MISC          = 1 << 0,
331   GDK_DEBUG_EVENTS        = 1 << 1,
332   GDK_DEBUG_DND           = 1 << 2,
333   GDK_DEBUG_COLOR_CONTEXT = 1 << 3,
334   GDK_DEBUG_XIM           = 1 << 4,
335   GDK_DEBUG_SELECTION     = 1 << 5
336 } GdkDebugFlag;
337
338 void gdk_events_init (void);
339 void gdk_window_init (void);
340 void gdk_visual_init (void);
341 void gdk_selection_init (void);
342 void gdk_dnd_init    (void);
343 void gdk_dnd_exit    (void);
344 void gdk_image_init  (void);
345 void gdk_image_exit  (void);
346
347 GdkColormap* gdk_colormap_lookup (Colormap  xcolormap);
348 GdkVisual*   gdk_visual_lookup   (Visual   *xvisual);
349
350 void gdk_window_add_colormap_windows (GdkWindow *window);
351 void gdk_window_destroy_notify       (GdkWindow *window);
352
353 void     gdk_xid_table_insert (XID      *xid,
354                                gpointer  data);
355 void     gdk_xid_table_remove (XID       xid);
356 gpointer gdk_xid_table_lookup (XID       xid);
357
358 /* Internal functions */
359
360 HDC     gdk_gc_predraw  (GdkDrawablePrivate *drawable_private,
361                          GdkGCPrivate       *gc_private);
362 void    gdk_gc_postdraw (GdkDrawablePrivate *drawable_private,
363                          GdkGCPrivate       *gc_private);
364 HRGN    BitmapToRegion  (HBITMAP hBmp);
365
366 void    gdk_sel_prop_store (GdkWindow *owner,
367                             GdkAtom    type,
368                             gint       format,
369                             guchar    *data,
370                             gint       length);
371
372 void       gdk_event_queue_append (GdkEvent *event);
373
374 /* Please see gdkwindow.c for comments on how to use */ 
375 HWND gdk_window_xid_at(HWND base, gint bx, gint by, gint x, gint y, GList *excludes, gboolean excl_child);
376 HWND gdk_window_xid_at_coords(gint x, gint y, GList *excludes, gboolean excl_child);
377
378 extern gint              gdk_debug_level;
379 extern gint              gdk_show_events;
380 extern gint              gdk_stack_trace;
381 extern HWND              gdk_root_window;
382 extern HWND              gdk_leader_window;
383 GDKVAR GdkWindowPrivate  gdk_root_parent;
384 GDKVAR Atom              gdk_selection_property;
385 extern GdkWindow        *selection_owner[];
386 GDKVAR gchar            *gdk_progclass;
387 GDKVAR gint              gdk_error_code;
388 GDKVAR gint              gdk_error_warnings;
389 GDKVAR gint              gdk_null_window_warnings;
390 extern GList            *gdk_default_filters;
391 extern gint              gdk_event_func_from_window_proc;
392
393 extern HDC               gdk_DC;
394 extern HINSTANCE         gdk_DLLInstance;
395 extern HINSTANCE         gdk_ProgInstance;
396
397 extern UINT              gdk_selection_notify_msg;
398 extern UINT              gdk_selection_request_msg;
399 extern UINT              gdk_selection_clear_msg;
400 extern GdkAtom           gdk_clipboard_atom;
401 extern GdkAtom           gdk_win32_dropfiles_atom;
402 extern GdkAtom           gdk_ole2_dnd_atom;
403
404 extern LRESULT CALLBACK gdk_WindowProc (HWND, UINT, WPARAM, LPARAM);
405
406 /* Debugging support */
407
408 #ifdef G_ENABLE_DEBUG
409
410 #define GDK_NOTE(type,action)                G_STMT_START { \
411     if (gdk_debug_flags & GDK_DEBUG_##type)                 \
412        { action; };                          } G_STMT_END
413
414 #else /* !G_ENABLE_DEBUG */
415
416 #define GDK_NOTE(type,action)
417       
418 #endif /* G_ENABLE_DEBUG */
419
420 GDKVAR guint gdk_debug_flags;
421
422 /* Internal functions for debug output etc. */
423
424 char   *gdk_color_to_string (GdkColor *);
425
426 #ifdef __cplusplus
427 }
428 #endif /* __cplusplus */
429
430
431 #endif /* __GDK_PRIVATE_H__ */