]> Pileus Git - ~andy/gtk/blob - gdk/win32/gdkprivate-win32.h
Support added for building using a GNU toolchain on Win32,
[~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 #include <gdk/gdktypes.h>
53
54 /* Define corresponding Windows types for some X11 types, just for laziness.
55  */
56
57 #include <glib.h>
58
59 typedef HANDLE XID;
60 typedef PALETTEENTRY XColor;
61 typedef HDC GC;
62 typedef ATOM Atom;
63 typedef HCURSOR Cursor;
64 typedef guint VisualID;
65 typedef DWORD KeySym;
66 typedef int Status;
67
68 /* Define some of the X11 constants also here, again just for laziness */
69
70 /* Generic null resource */
71 #define None 0
72
73 /* Error codes */
74 #define Success            0
75
76 /* Grabbing status */
77 #define GrabSuccess        0
78 #define AlreadyGrabbed     2
79
80 /* For CreateColormap */
81 #define AllocNone 0
82 #define AllocAll 1
83
84 /* Notify modes */
85 #define NotifyNormal 0
86 #define NotifyHint 1
87
88 /* Some structs are somewhat useful to emulate internally, just to
89    keep the code less #ifdefed.  */
90 typedef struct {
91   HPALETTE palette;             /* Palette handle used when drawing. */
92   guint size;                   /* Number of entries in the palette. */
93   gboolean stale;               /* 1 if palette needs to be realized,
94                                  * otherwise 0. */
95   gboolean *in_use;
96   gboolean rc_palette;          /* If RC_PALETTE is on in the RASTERCAPS */
97   gulong sizepalette;           /* SIZEPALETTE if rc_palette */
98 } ColormapStruct, *Colormap;
99   
100 typedef struct {
101   gint map_entries;
102   guint visualid;
103   guint bitspixel;
104 } Visual;
105
106 typedef struct {
107   Colormap colormap;
108   unsigned long red_max;
109   unsigned long red_mult;
110   unsigned long green_max;
111   unsigned long green_mult;
112   unsigned long blue_max;
113   unsigned long blue_mult;
114   unsigned long base_pixel;
115 } XStandardColormap;
116
117 extern LRESULT CALLBACK 
118 gdk_WindowProc (HWND, UINT, WPARAM, LPARAM);
119
120 #define gdk_window_lookup(xid)     ((GdkWindow*) gdk_xid_table_lookup (xid))
121 #define gdk_pixmap_lookup(xid)     ((GdkPixmap*) gdk_xid_table_lookup (xid))
122
123 /* HFONTs clash with HWNDs, so add dithering to HFONTs... (hack) */
124 #define HFONT_DITHER 43
125 #define gdk_font_lookup(xid)       ((GdkFont*) gdk_xid_table_lookup ((HANDLE) ((guint) xid + HFONT_DITHER)))
126
127 #ifdef __cplusplus
128 extern "C" {
129 #endif /* __cplusplus */
130
131
132 typedef struct _GdkWindowPrivate       GdkWindowPrivate;
133 typedef struct _GdkWindowPrivate       GdkPixmapPrivate;
134 typedef struct _GdkImagePrivate        GdkImagePrivate;
135 typedef struct _GdkGCPrivate           GdkGCPrivate;
136 typedef struct _GdkColormapPrivate     GdkColormapPrivate;
137 typedef struct _GdkColorInfo           GdkColorInfo;
138 typedef struct _GdkVisualPrivate       GdkVisualPrivate;
139 typedef struct _GdkFontPrivate         GdkFontPrivate;
140 typedef struct _GdkCursorPrivate       GdkCursorPrivate;
141 typedef struct _GdkEventFilter         GdkEventFilter;
142 typedef struct _GdkClientFilter        GdkClientFilter;
143 typedef struct _GdkColorContextPrivate GdkColorContextPrivate;
144 typedef struct _GdkRegionPrivate       GdkRegionPrivate;
145
146
147 struct _GdkWindowPrivate
148 {
149   GdkWindow window;
150   GdkWindow *parent;
151   HANDLE xwindow;
152   gint16 x;
153   gint16 y;
154   guint16 width;
155   guint16 height;
156   guint8 resize_count;
157   guint8 window_type;
158   guint ref_count;
159   guint destroyed : 2;
160   guint mapped : 1;
161   guint guffaw_gravity : 1;
162
163   /* We must keep the event mask here to filter them ourselves */
164   gint event_mask;
165
166   /* Values for bg_type */
167 #define GDK_WIN32_BG_NORMAL 0
168 #define GDK_WIN32_BG_PIXEL 1
169 #define GDK_WIN32_BG_PIXMAP 2
170 #define GDK_WIN32_BG_PARENT_RELATIVE 3
171 #define GDK_WIN32_BG_TRANSPARENT 4
172
173   /* We draw the background ourselves at WM_ERASEBKGND  */
174   guchar bg_type;
175   GdkColor bg_pixel;
176   GdkPixmap *bg_pixmap;
177
178   HCURSOR xcursor;
179
180   /* Window size hints */
181   gint hint_flags;
182   gint hint_x, hint_y;
183   gint hint_min_width, hint_min_height;
184   gint hint_max_width, hint_max_height;
185
186   gint extension_events;
187   gboolean extension_events_selected;
188
189   GList *filters;
190   GdkColormap *colormap;
191   GList *children;
192 };
193
194 struct _GdkImagePrivate
195 {
196   GdkImage image;
197   HBITMAP ximage;
198   gpointer x_shm_info;
199
200   void (*image_put) (GdkDrawable *window,
201                      GdkGC       *gc,
202                      GdkImage    *image,
203                      gint         xsrc,
204                      gint         ysrc,
205                      gint         xdest,
206                      gint         ydest,
207                      gint         width,
208                      gint         height);
209 };
210
211 struct _GdkGCPrivate
212 {
213   GdkGC gc;
214   GC xgc;
215   /* A Windows Device Context (DC) is not equivalent to an X11
216    * GC. We can use a DC only in the window for which it was
217    * allocated, or (in the case of a memory DC) with the bitmap that
218    * has been selected into it. Thus, we have to release and
219    * reallocate a DC each time the GdkGC is used to paint into a new
220    * window or pixmap. We thus keep all the necessary values in the
221    * GdkGCPrivate struct.
222    */
223   GdkGCValuesMask values_mask;
224   GdkColor foreground;
225   GdkColor background;
226   HFONT font;
227   gint rop2;
228   GdkFill fill_style;
229   GdkPixmap *tile;
230   GdkPixmap *stipple;
231   HRGN clip_region;
232   GdkSubwindowMode subwindow_mode;
233   gint ts_x_origin;
234   gint ts_y_origin;
235   gint clip_x_origin;
236   gint clip_y_origin;
237   gint graphics_exposures;
238   gint pen_width;
239   DWORD pen_style;
240   HANDLE hwnd;                  /* If a DC is allocated, for which window
241                                    or what bitmap is selected into it */
242   int saved_dc;
243   guint ref_count;
244 };
245
246 typedef enum {
247   GDK_COLOR_WRITEABLE = 1 << 0
248 } GdkColorInfoFlags;
249
250 struct _GdkColorInfo
251 {
252   GdkColorInfoFlags flags;
253   guint ref_count;
254 };
255
256 struct _GdkColormapPrivate
257 {
258   GdkColormap colormap;
259   Colormap xcolormap;
260   GdkVisual *visual;
261   gint private_val;
262
263   GHashTable *hash;
264   GdkColorInfo *info;
265   time_t last_sync_time;
266   
267   guint ref_count;
268 };
269
270 struct _GdkVisualPrivate
271 {
272   GdkVisual visual;
273   Visual *xvisual;
274 };
275
276 struct _GdkFontPrivate
277 {
278   GdkFont font;
279   /* XFontStruct *xfont; */
280   /* generic pointer point to XFontStruct or XFontSet */
281   /* in Win32 a HFONT */ 
282   gpointer xfont;
283   guint ref_count;
284 };
285
286 struct _GdkCursorPrivate
287 {
288   GdkCursor cursor;
289   Cursor xcursor;
290 };
291
292 struct _GdkEventFilter {
293   GdkFilterFunc function;
294   gpointer data;
295 };
296
297 struct _GdkClientFilter {
298   GdkAtom       type;
299   GdkFilterFunc function;
300   gpointer      data;
301 };
302
303 #ifdef USE_XIM
304
305 typedef struct _GdkICPrivate GdkICPrivate;
306
307 struct _GdkICPrivate
308 {
309   XIC xic;
310   GdkICAttr *attr;
311   GdkICAttributesType mask;
312 };
313
314 #endif /* USE_XIM */
315
316 struct _GdkColorContextPrivate
317 {
318   GdkColorContext color_context;
319   XStandardColormap std_cmap;
320 };
321
322 struct _GdkRegionPrivate
323 {
324   GdkRegion region;
325   HRGN xregion;
326 };
327
328 typedef enum {
329   GDK_DEBUG_MISC          = 1 << 0,
330   GDK_DEBUG_EVENTS        = 1 << 1,
331   GDK_DEBUG_DND           = 1 << 2,
332   GDK_DEBUG_COLOR_CONTEXT = 1 << 3,
333   GDK_DEBUG_XIM           = 1 << 4,
334   GDK_DEBUG_SELECTION     = 1 << 5
335 } GdkDebugFlag;
336
337 void gdk_events_init (void);
338 void gdk_window_init (void);
339 void gdk_visual_init (void);
340 void gdk_selection_init (void);
341 void gdk_dnd_init    (void);
342 void gdk_dnd_exit    (void);
343 void gdk_image_init  (void);
344 void gdk_image_exit  (void);
345
346 GdkColormap* gdk_colormap_lookup (Colormap  xcolormap);
347 GdkVisual*   gdk_visual_lookup   (Visual   *xvisual);
348
349 void gdk_window_add_colormap_windows (GdkWindow *window);
350 void gdk_window_destroy_notify       (GdkWindow *window);
351
352 void     gdk_xid_table_insert (XID      *xid,
353                                gpointer  data);
354 void     gdk_xid_table_remove (XID       xid);
355 gpointer gdk_xid_table_lookup (XID       xid);
356
357 /* Internal functions */
358
359 HDC     gdk_gc_predraw  (GdkWindowPrivate *window_private,
360                          GdkGCPrivate *gc_private);
361 void    gdk_gc_postdraw (GdkWindowPrivate *window_private,
362                          GdkGCPrivate *gc_private);
363 HRGN    BitmapToRegion  (HBITMAP hBmp);
364
365 void    gdk_sel_prop_store (GdkWindow *owner,
366                             GdkAtom    type,
367                             gint       format,
368                             guchar    *data,
369                             gint       length);
370
371 void       gdk_event_queue_append (GdkEvent *event);
372
373 /* Please see gdkwindow.c for comments on how to use */ 
374 HWND gdk_window_xid_at(HWND base, gint bx, gint by, gint x, gint y, GList *excludes, gboolean excl_child);
375 HWND gdk_window_xid_at_coords(gint x, gint y, GList *excludes, gboolean excl_child);
376
377 extern gint              gdk_debug_level;
378 extern gint              gdk_show_events;
379 extern gint              gdk_stack_trace;
380 extern gchar            *gdk_display_name;
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
392 #ifdef USE_XIM
393 /* XIM support */
394 gint   gdk_im_open               (void);
395 void   gdk_im_close              (void);
396 void   gdk_ic_cleanup            (void);
397
398 extern GdkICPrivate *gdk_xim_ic;                /* currently using IC */
399 extern GdkWindow *gdk_xim_window;               /* currently using Window */
400 #endif /* USE_XIM */
401
402 extern HDC               gdk_DC;
403 extern HINSTANCE         gdk_DLLInstance;
404 extern HINSTANCE         gdk_ProgInstance;
405
406 extern UINT              gdk_selection_notify_msg;
407 extern UINT              gdk_selection_request_msg;
408 extern UINT              gdk_selection_clear_msg;
409 extern GdkAtom           gdk_clipboard_atom;
410 extern GdkAtom           gdk_win32_dropfiles_atom;
411 extern GdkAtom           gdk_ole2_dnd_atom;
412
413 /* Debugging support */
414
415 #ifdef G_ENABLE_DEBUG
416
417 #define GDK_NOTE(type,action)                G_STMT_START { \
418     if (gdk_debug_flags & GDK_DEBUG_##type)                 \
419        { action; };                          } G_STMT_END
420
421 #else /* !G_ENABLE_DEBUG */
422
423 #define GDK_NOTE(type,action)
424       
425 #endif /* G_ENABLE_DEBUG */
426
427 GDKVAR guint gdk_debug_flags;
428
429 /* Internal functions for debug output etc. */
430
431 char   *gdk_color_to_string (GdkColor *);
432
433 #ifdef __cplusplus
434 }
435 #endif /* __cplusplus */
436
437
438 #endif /* __GDK_PRIVATE_H__ */