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