]> Pileus Git - ~andy/gtk/blob - gdk/win32/gdkprivate-win32.h
018a617aed6e3ad948a1f0ad8cee4fbe3d6c3d2a
[~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 Lesser 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  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser 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-2000.  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_WIN32_H__
28 #define __GDK_PRIVATE_WIN32_H__
29
30 #include <gdk/gdkprivate.h>
31 #include <gdk/win32/gdkwindow-win32.h>
32 #include <gdk/win32/gdkpixmap-win32.h>
33
34 #include "gdkinternals.h"
35
36 #include <config.h>
37
38 /* Make up for some minor w32api header lossage */
39
40 /* PS_JOIN_MASK is missing */
41 #ifndef PS_JOIN_MASK
42 #define PS_JOIN_MASK (PS_JOIN_BEVEL|PS_JOIN_MITER|PS_JOIN_ROUND)
43 #endif
44
45 /* CLR_INVALID is missing */
46 #ifndef CLR_INVALID
47 #define CLR_INVALID CLR_NONE
48 #endif
49
50 /* Some charsets are missing from MSVC 5 headers */
51 #ifndef JOHAB_CHARSET
52 #define JOHAB_CHARSET 130
53 #endif
54 #ifndef VIETNAMESE_CHARSET
55 #define VIETNAMESE_CHARSET 163
56 #endif
57
58 #ifndef FS_VIETNAMESE
59 #define FS_VIETNAMESE 0x100
60 #endif
61
62 /* Some virtual keycodes are missing */
63 #ifndef VM_OEM_PLUS
64 #define VK_OEM_PLUS 0xBB
65 #endif
66
67 #ifndef VK_OEM_COMMA
68 #define VK_OEM_COMMA 0xBC
69 #endif
70
71 #ifndef VK_OEM_MINUS
72 #define VK_OEM_MINUS 0xBD
73 #endif
74
75 #ifndef VK_OEM_PERIOD
76 #define VK_OEM_PERIOD 0xBE
77 #endif
78
79 #ifndef VK_OEM_1
80 #define VK_OEM_1 0xBA
81 #endif
82 #ifndef VK_OEM_2
83 #define VK_OEM_2 0xBF
84 #endif
85 #ifndef VK_OEM_3
86 #define VK_OEM_3 0xC0
87 #endif
88 #ifndef VK_OEM_4
89 #define VK_OEM_4 0xDB
90 #endif
91 #ifndef VK_OEM_5
92 #define VK_OEM_5 0xDC
93 #endif
94 #ifndef VK_OEM_6
95 #define VK_OEM_6 0xDD
96 #endif
97 #ifndef VK_OEM_7
98 #define VK_OEM_7 0xDE
99 #endif
100 #ifndef VK_OEM_8
101 #define VK_OEM_8 0xDF
102 #endif
103
104 /* Missing messages */
105 #ifndef WM_SYNCPAINT
106 #define WM_SYNCPAINT 0x88
107 #endif
108 #ifndef WM_MOUSEWHEEL
109 #define WM_MOUSEWHEEL 0X20A
110 #endif
111 #ifndef WM_GETOBJECT
112 #define WM_GETOBJECT 0x3D
113 #endif
114 #ifndef WM_NCXBUTTONDOWN
115 #define WM_NCXBUTTONDOWN 0xAB
116 #endif
117 #ifndef WM_NCXBUTTONUP
118 #define WM_NCXBUTTONUP 0xAC
119 #endif
120 #ifndef WM_NCXBUTTONDBLCLK
121 #define WM_NCXBUTTONDBLCLK 0xAD
122 #endif
123 #ifndef WM_MENURBUTTONUP
124 #define WM_MENURBUTTONUP 0x122
125 #endif
126 #ifndef WM_MENUDRAG
127 #define WM_MENUDRAG 0x123
128 #endif
129 #ifndef WM_MENUGETOBJECT
130 #define WM_MENUGETOBJECT 0x124
131 #endif
132 #ifndef WM_UNINITMENUPOPUP
133 #define WM_UNINITMENUPOPUP 0x125
134 #endif
135 #ifndef WM_MENUCOMMAND
136 #define WM_MENUCOMMAND 0x126
137 #endif
138 #ifndef WM_CHANGEUISTATE
139 #define WM_CHANGEUISTATE 0x127
140 #endif
141 #ifndef WM_UPDATEUISTATE
142 #define WM_UPDATEUISTATE 0x128
143 #endif
144 #ifndef WM_QUERYUISTATE
145 #define WM_QUERYUISTATE 0x129
146 #endif
147 #ifndef WM_XBUTTONDOWN
148 #define WM_XBUTTONDOWN 0x20B
149 #endif
150 #ifndef WM_XBUTTONUP
151 #define WM_XBUTTONUP 0x20C
152 #endif
153 #ifndef WM_XBUTTONDBLCLK
154 #define WM_XBUTTONDBLCLK 0x20D
155 #endif
156 #ifndef WM_IME_REQUEST
157 #define WM_IME_REQUEST 0x288
158 #endif
159 #ifndef WM_MOUSEHOVER
160 #define WM_MOUSEHOVER 0x2A1
161 #endif
162 #ifndef WM_MOUSELEAVE
163 #define WM_MOUSELEAVE 0x2A3
164 #endif
165 #ifndef WM_NCMOUSEHOVER
166 #define WM_NCMOUSEHOVER 0x2A0
167 #endif
168 #ifndef WM_NCMOUSELEAVE
169 #define WM_NCMOUSELEAVE 0x2A2
170 #endif
171 #ifndef WM_APPCOMMAND
172 #define WM_APPCOMMAND 0x319
173 #endif
174 #ifndef WM_HANDHELDFIRST
175 #define WM_HANDHELDFIRST 0x358
176 #endif
177 #ifndef WM_HANDHELDLAST
178 #define WM_HANDHELDLAST 0x35F
179 #endif
180 #ifndef WM_AFXFIRST
181 #define WM_AFXFIRST 0x360
182 #endif
183 #ifndef WM_AFXLAST
184 #define WM_AFXLAST 0x37F
185 #endif
186
187 #ifndef CopyCursor
188 #define CopyCursor(pcur) ((HCURSOR)CopyIcon((HICON)(pcur)))
189 #endif
190
191 /* Define some combinations of GdkDebugFlags */
192 #define GDK_DEBUG_EVENTS_OR_COLORMAP (GDK_DEBUG_EVENTS|GDK_DEBUG_COLORMAP)
193 #define GDK_DEBUG_EVENTS_OR_INPUT (GDK_DEBUG_EVENTS|GDK_DEBUG_INPUT)
194 #define GDK_DEBUG_PIXMAP_OR_COLORMAP (GDK_DEBUG_PIXMAP|GDK_DEBUG_COLORMAP)
195 #define GDK_DEBUG_MISC_OR_COLORMAP (GDK_DEBUG_MISC|GDK_DEBUG_COLORMAP)
196
197 #define GDK_TYPE_GC_WIN32              (_gdk_gc_win32_get_type ())
198 #define GDK_GC_WIN32(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_GC_WIN32, GdkGCWin32))
199 #define GDK_GC_WIN32_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_GC_WIN32, GdkGCWin32Class))
200 #define GDK_IS_GC_WIN32(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_GC_WIN32))
201 #define GDK_IS_GC_WIN32_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_GC_WIN32))
202 #define GDK_GC_WIN32_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_GC_WIN32, GdkGCWin32Class))
203
204 typedef struct _GdkColormapPrivateWin32 GdkColormapPrivateWin32;
205 typedef struct _GdkCursorPrivate        GdkCursorPrivate;
206 typedef struct _GdkWin32SingleFont      GdkWin32SingleFont;
207 typedef struct _GdkFontPrivateWin32     GdkFontPrivateWin32;
208 typedef struct _GdkGCWin32              GdkGCWin32;
209 typedef struct _GdkGCWin32Class         GdkGCWin32Class;
210
211 struct _GdkCursorPrivate
212 {
213   GdkCursor cursor;
214   HCURSOR hcursor;
215 };
216
217 struct _GdkWin32SingleFont
218 {
219   HFONT hfont;
220   UINT charset;
221   UINT codepage;
222   FONTSIGNATURE fs;
223 };
224
225 struct _GdkFontPrivateWin32
226 {
227   GdkFontPrivate base;
228   GSList *fonts;                /* List of GdkWin32SingleFonts */
229   GSList *names;
230 };
231
232 struct _GdkVisualClass
233 {
234   GObjectClass parent_class;
235 };
236
237 typedef enum {
238   GDK_WIN32_PE_STATIC,
239   GDK_WIN32_PE_AVAILABLE,
240   GDK_WIN32_PE_INUSE
241 } GdkWin32PalEntryState;
242
243 struct _GdkColormapPrivateWin32
244 {
245   HPALETTE hpal;
246   gint current_size;            /* Current size of hpal */
247   GdkWin32PalEntryState *use;
248   gint private_val;
249
250   GHashTable *hash;
251   GdkColorInfo *info;
252 };
253
254 struct _GdkGCWin32
255 {
256   GdkGC parent_instance;
257
258   /* A Windows Device Context (DC) is not equivalent to an X11
259    * GC. We can use a DC only in the window for which it was
260    * allocated, or (in the case of a memory DC) with the bitmap that
261    * has been selected into it. Thus, we have to release and
262    * reallocate a DC each time the GdkGC is used to paint into a new
263    * window or pixmap. We thus keep all the necessary values in the
264    * GdkGCWin32 object.
265    */
266
267   HRGN hcliprgn;
268
269   GdkGCValuesMask values_mask;
270
271   gulong foreground;            /* Pixel values from GdkColor, */
272   gulong background;            /* not Win32 COLORREFs */
273
274   GdkFont *font;
275   gint rop2;
276   GdkFill fill_style;
277   GdkPixmap *tile;
278   GdkPixmap *stipple;
279   GdkSubwindowMode subwindow_mode;
280   gint graphics_exposures;
281   gint pen_width;
282   DWORD pen_style;
283   DWORD *pen_dashes;            /* use for PS_USERSTYLE or step-by-step rendering */
284   gint pen_num_dashes;
285
286   /* Following fields are valid while the GC exists as a Windows DC */
287   HDC hdc;
288   int saved_dc;
289
290   HANDLE hwnd;                  /* For which window, or what bitmap is
291                                  * selected into it
292                                  */
293   HPALETTE holdpal;
294 };
295
296 struct _GdkGCWin32Class
297 {
298   GdkGCClass parent_class;
299 };
300
301 GType _gdk_gc_win32_get_type (void);
302
303 gulong _gdk_win32_get_next_tick (gulong suggested_tick);
304
305 void _gdk_window_init_position     (GdkWindow *window);
306 void _gdk_window_move_resize_child (GdkWindow *window,
307                                     gint       x,
308                                     gint       y,
309                                     gint       width,
310                                     gint       height);
311 void _gdk_window_process_expose    (GdkWindow *window,
312                                     GdkRegion *invalidate_region);
313
314 void _gdk_win32_selection_init (void);
315 void _gdk_win32_dnd_exit (void);
316
317 void     gdk_win32_handle_table_insert  (HANDLE   *handle,
318                                          gpointer data);
319 void     gdk_win32_handle_table_remove  (HANDLE handle);
320
321 GdkGC    *_gdk_win32_gc_new             (GdkDrawable        *drawable,
322                                          GdkGCValues        *values,
323                                          GdkGCValuesMask     values_mask);
324
325 GdkImage *_gdk_win32_get_image          (GdkDrawable *drawable,
326                                          gint         x,
327                                          gint         y,
328                                          gint         width,
329                                          gint         height);
330
331 GdkImage *_gdk_win32_copy_to_image      (GdkDrawable *drawable,
332                                          GdkImage    *image,
333                                          gint         src_x,
334                                          gint         src_y,
335                                          gint         dest_x,
336                                          gint         dest_y,
337                                          gint         width,
338                                          gint         height);
339
340 GdkImage *_gdk_win32_setup_pixmap_image (GdkPixmap *pixmap,
341                                          GdkWindow *window,
342                                          gint       width,
343                                          gint       height,
344                                          gint       depth,
345                                          guchar    *bits);
346
347 void      _gdk_win32_blit               (gboolean              use_fg_bg,
348                                          GdkDrawableImplWin32 *drawable,
349                                          GdkGC                 *gc,
350                                          GdkDrawable           *src,
351                                          gint                   xsrc,
352                                          gint                   ysrc,
353                                          gint                   xdest,
354                                          gint                   ydest,
355                                          gint                   width,
356                                          gint                   height);
357
358 COLORREF  _gdk_win32_colormap_color     (GdkColormap *colormap,
359                                          gulong       pixel);
360
361 HRGN      _gdk_win32_bitmap_to_hrgn     (GdkPixmap   *bitmap);
362
363 HRGN      _gdk_win32_gdkregion_to_hrgn  (GdkRegion   *region,
364                                          gint         x_origin,
365                                          gint         y_origin);
366
367 void    _gdk_selection_property_store (GdkWindow *owner,
368                                        GdkAtom    type,
369                                        gint       format,
370                                        guchar    *data,
371                                        gint       length);
372
373 void    _gdk_selection_property_delete (GdkWindow *);
374
375 void    _gdk_dropfiles_store (gchar *data);
376
377 gint    _gdk_utf8_to_ucs2         (wchar_t     *dest,
378                                    const gchar *src,
379                                    gint         src_len,
380                                    gint         dest_max);
381
382 gchar  *_gdk_ucs2_to_utf8         (const wchar_t *src,
383                                    gint           src_len);
384
385 void    _gdk_wchar_text_handle    (GdkFont       *font,
386                                    const wchar_t *wcstr,
387                                    int            wclen,
388                                    void         (*handler)(GdkWin32SingleFont *,
389                                                            const wchar_t *,
390                                                            int,
391                                                            void *),
392                                    void          *arg);
393
394 #ifdef G_ENABLE_DEBUG
395 gchar *_gdk_win32_color_to_string      (const GdkColor *color);
396 void   _gdk_win32_print_paletteentries (const PALETTEENTRY *pep,
397                                         const int           nentries);
398 void   _gdk_win32_print_system_palette (void);
399 void   _gdk_win32_print_hpalette       (HPALETTE     hpal);
400 void   _gdk_win32_print_dc             (HDC          hdc);
401
402 gchar *_gdk_win32_cap_style_to_string  (GdkCapStyle  cap_style);
403 gchar *_gdk_win32_fill_style_to_string (GdkFill      fill);
404 gchar *_gdk_win32_function_to_string   (GdkFunction  function);
405 gchar *_gdk_win32_join_style_to_string (GdkJoinStyle join_style);
406 gchar *_gdk_win32_line_style_to_string (GdkLineStyle line_style);
407 gchar *_gdk_win32_gcvalues_mask_to_string (GdkGCValuesMask mask);
408 gchar *_gdk_win32_drawable_description (GdkDrawable *d);
409
410 gchar *_gdk_win32_rop2_to_string       (int          rop2);
411 gchar *_gdk_win32_lbstyle_to_string    (UINT         brush_style);
412 gchar *_gdk_win32_pstype_to_string     (DWORD        pen_style);
413 gchar *_gdk_win32_psstyle_to_string    (DWORD        pen_style);
414 gchar *_gdk_win32_psendcap_to_string   (DWORD        pen_style);
415 gchar *_gdk_win32_psjoin_to_string     (DWORD        pen_style);
416 gchar *_gdk_win32_message_to_string    (UINT         msg);
417 gchar *_gdk_win32_rect_to_string       (const RECT  *rect);
418
419 gchar *_gdk_win32_gdkrectangle_to_string (const GdkRectangle *rect);
420 gchar *_gdk_win32_gdkregion_to_string    (const GdkRegion    *box);
421
422 #endif
423
424 gchar  *_gdk_win32_last_error_string (void);
425 void    _gdk_win32_api_failed        (const gchar *where,
426                                      gint line,
427                                      const gchar *api);
428 void    _gdk_other_api_failed        (const gchar *where,
429                                      gint line,
430                                      const gchar *api);
431 void    _gdk_win32_gdi_failed        (const gchar *where,
432                                      gint line,
433                                      const gchar *api);
434
435 #ifdef __GNUC__
436 #define WIN32_API_FAILED(api) _gdk_win32_api_failed (__FILE__ ":" __PRETTY_FUNCTION__, __LINE__, api)
437 #define WIN32_GDI_FAILED(api) _gdk_win32_gdi_failed (__FILE__ ":" __PRETTY_FUNCTION__, __LINE__, api)
438 #define OTHER_API_FAILED(api) _gdk_other_api_failed (__FILE__ ":" __PRETTY_FUNCTION__, __LINE__, api)
439 #else
440 #define WIN32_API_FAILED(api) _gdk_win32_api_failed (__FILE__, __LINE__, api)
441 #define WIN32_GDI_FAILED(api) _gdk_win32_gdi_failed (__FILE__, __LINE__, api)
442 #define OTHER_API_FAILED(api) _gdk_other_api_failed (__FILE__, __LINE__, api)
443 #endif
444  
445 /* These two macros call a GDI or other Win32 API and if the return
446  * value is zero or NULL, print a warning message. The majority of GDI
447  * calls return zero or NULL on failure. The value of the macros is nonzero
448  * if the call succeeded, zero otherwise.
449  */
450
451 #define GDI_CALL(api, arglist) (api arglist ? 1 : (WIN32_GDI_FAILED (#api), 0))
452 #define API_CALL(api, arglist) (api arglist ? 1 : (WIN32_API_FAILED (#api), 0))
453  
454 extern LRESULT CALLBACK _gdk_win32_window_procedure (HWND, UINT, WPARAM, LPARAM);
455
456 extern HWND              _gdk_root_window;
457 extern GdkWindow        *_gdk_parent_root;
458
459 extern GdkDisplay       *_gdk_display;
460 extern GdkScreen        *_gdk_screen;
461
462 extern HDC               _gdk_display_hdc;
463 extern HINSTANCE         _gdk_dll_hinstance;
464 extern HINSTANCE         _gdk_app_hmodule;
465
466 /* These are thread specific, but GDK/win32 works OK only when invoked
467  * from a single thread anyway.
468  */
469 extern HKL               _gdk_input_locale;
470 extern UINT              _gdk_input_codepage;
471
472 extern guint             _gdk_keymap_serial;
473
474 /* Registered clipboard formats */
475 extern WORD              _cf_rtf;
476 extern WORD              _cf_utf8_string;
477
478 /* GdkAtoms: Targets */
479 extern GdkAtom           _utf8_string;
480 extern GdkAtom           _compound_text;
481 extern GdkAtom           _text_uri_list;
482
483 /* DND selections */
484 extern GdkAtom           _local_dnd;
485 extern GdkAtom           _gdk_win32_dropfiles;
486 extern GdkAtom           _gdk_ole2_dnd;
487
488 extern GdkAtom           _gdk_selection_property;
489
490 extern DWORD             _windows_version;
491 #define IS_WIN_NT()      (_windows_version < 0x80000000)
492
493 /* Options */
494 extern gboolean          _gdk_input_ignore_wintab;
495 extern gint              _gdk_max_colors;
496
497 #define GDK_WIN32_COLORMAP_DATA(cmap) ((GdkColormapPrivateWin32 *) GDK_COLORMAP (cmap)->windowing_data)
498
499 /* Initialization */
500 void _gdk_windowing_window_init (void);
501 void _gdk_visual_init (void);
502 void _gdk_dnd_init    (void);
503 void _gdk_windowing_image_init  (void);
504 void _gdk_events_init (void);
505 void _gdk_input_init  (GdkDisplay *display);
506
507 #endif /* __GDK_PRIVATE_WIN32_H__ */