]> Pileus Git - ~andy/gtk/blob - gdk/win32/gdkprivate-win32.h
gdk/win32/gdkprivate-win32.h gdk/win32/gdkglobals-win32.c Add more
[~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 VK_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   GdkFont *font;
272   gint rop2;
273   GdkSubwindowMode subwindow_mode;
274   gint graphics_exposures;
275   gint pen_width;
276   DWORD pen_style;
277   GdkLineStyle line_style;
278   GdkCapStyle cap_style;
279   GdkJoinStyle join_style;
280   DWORD *pen_dashes;            /* use for PS_USERSTYLE or step-by-step rendering */
281   gint pen_num_dashes;
282   gint pen_dash_offset;
283   HBRUSH pen_hbrbg;
284
285   /* Following fields are valid while the GC exists as a Windows DC */
286   HDC hdc;
287   int saved_dc;
288
289   HPALETTE holdpal;
290 };
291
292 struct _GdkGCWin32Class
293 {
294   GdkGCClass parent_class;
295 };
296
297 GType _gdk_gc_win32_get_type (void);
298
299 gulong _gdk_win32_get_next_tick (gulong suggested_tick);
300
301 void _gdk_window_init_position     (GdkWindow *window);
302 void _gdk_window_move_resize_child (GdkWindow *window,
303                                     gint       x,
304                                     gint       y,
305                                     gint       width,
306                                     gint       height);
307 void _gdk_window_process_expose    (GdkWindow *window,
308                                     GdkRegion *invalidate_region);
309
310 void _gdk_win32_selection_init (void);
311 void _gdk_win32_dnd_exit (void);
312
313 void     gdk_win32_handle_table_insert  (HANDLE   *handle,
314                                          gpointer data);
315 void     gdk_win32_handle_table_remove  (HANDLE handle);
316
317 GdkGC    *_gdk_win32_gc_new             (GdkDrawable        *drawable,
318                                          GdkGCValues        *values,
319                                          GdkGCValuesMask     values_mask);
320
321 GdkImage *_gdk_win32_get_image          (GdkDrawable *drawable,
322                                          gint         x,
323                                          gint         y,
324                                          gint         width,
325                                          gint         height);
326
327 GdkImage *_gdk_win32_copy_to_image      (GdkDrawable *drawable,
328                                          GdkImage    *image,
329                                          gint         src_x,
330                                          gint         src_y,
331                                          gint         dest_x,
332                                          gint         dest_y,
333                                          gint         width,
334                                          gint         height);
335
336 void      _gdk_win32_blit               (gboolean              use_fg_bg,
337                                          GdkDrawableImplWin32 *drawable,
338                                          GdkGC                 *gc,
339                                          GdkDrawable           *src,
340                                          gint                   xsrc,
341                                          gint                   ysrc,
342                                          gint                   xdest,
343                                          gint                   ydest,
344                                          gint                   width,
345                                          gint                   height);
346
347 COLORREF  _gdk_win32_colormap_color     (GdkColormap *colormap,
348                                          gulong       pixel);
349
350 HRGN      _gdk_win32_bitmap_to_hrgn     (GdkPixmap   *bitmap);
351
352 HRGN      _gdk_win32_gdkregion_to_hrgn  (GdkRegion   *region,
353                                          gint         x_origin,
354                                          gint         y_origin);
355
356 void    _gdk_win32_adjust_client_rect   (GdkWindow *window,
357                                          RECT      *RECT);
358
359 void    _gdk_win32_get_adjusted_client_rect (GdkWindow *window,
360                                              RECT      *RECT);
361
362 void    _gdk_selection_property_delete (GdkWindow *);
363
364 void    _gdk_dropfiles_store (gchar *data);
365
366 void    _gdk_wchar_text_handle    (GdkFont       *font,
367                                    const wchar_t *wcstr,
368                                    int            wclen,
369                                    void         (*handler)(GdkWin32SingleFont *,
370                                                            const wchar_t *,
371                                                            int,
372                                                            void *),
373                                    void          *arg);
374
375 #ifdef G_ENABLE_DEBUG
376 gchar *_gdk_win32_color_to_string      (const GdkColor *color);
377 void   _gdk_win32_print_paletteentries (const PALETTEENTRY *pep,
378                                         const int           nentries);
379 void   _gdk_win32_print_system_palette (void);
380 void   _gdk_win32_print_hpalette       (HPALETTE     hpal);
381 void   _gdk_win32_print_dc             (HDC          hdc);
382
383 gchar *_gdk_win32_cap_style_to_string  (GdkCapStyle  cap_style);
384 gchar *_gdk_win32_fill_style_to_string (GdkFill      fill);
385 gchar *_gdk_win32_function_to_string   (GdkFunction  function);
386 gchar *_gdk_win32_join_style_to_string (GdkJoinStyle join_style);
387 gchar *_gdk_win32_line_style_to_string (GdkLineStyle line_style);
388 gchar *_gdk_win32_gcvalues_mask_to_string (GdkGCValuesMask mask);
389 gchar *_gdk_win32_window_state_to_string (GdkWindowState state);
390 gchar *_gdk_win32_drawable_description (GdkDrawable *d);
391
392 gchar *_gdk_win32_rop2_to_string       (int          rop2);
393 gchar *_gdk_win32_lbstyle_to_string    (UINT         brush_style);
394 gchar *_gdk_win32_pstype_to_string     (DWORD        pen_style);
395 gchar *_gdk_win32_psstyle_to_string    (DWORD        pen_style);
396 gchar *_gdk_win32_psendcap_to_string   (DWORD        pen_style);
397 gchar *_gdk_win32_psjoin_to_string     (DWORD        pen_style);
398 gchar *_gdk_win32_message_to_string    (UINT         msg);
399 gchar *_gdk_win32_key_to_string        (LONG         lParam);
400 gchar *_gdk_win32_cf_to_string         (UINT         format);
401 gchar *_gdk_win32_data_to_string       (const guchar*data,
402                                         int          nbytes);
403 gchar *_gdk_win32_rect_to_string       (const RECT  *rect);
404
405 gchar *_gdk_win32_gdkrectangle_to_string (const GdkRectangle *rect);
406 gchar *_gdk_win32_gdkregion_to_string    (const GdkRegion    *box);
407
408 #endif
409
410 gchar  *_gdk_win32_last_error_string (void);
411 void    _gdk_win32_api_failed        (const gchar *where,
412                                      gint line,
413                                      const gchar *api);
414 void    _gdk_other_api_failed        (const gchar *where,
415                                      gint line,
416                                      const gchar *api);
417 void    _gdk_win32_gdi_failed        (const gchar *where,
418                                      gint line,
419                                      const gchar *api);
420
421 #if defined(__GNUC__) && (__GNUC__ < 3)
422 #define WIN32_API_FAILED(api) _gdk_win32_api_failed (__FILE__ ":" __PRETTY_FUNCTION__, __LINE__, api)
423 #define WIN32_GDI_FAILED(api) _gdk_win32_gdi_failed (__FILE__ ":" __PRETTY_FUNCTION__, __LINE__, api)
424 #define OTHER_API_FAILED(api) _gdk_other_api_failed (__FILE__ ":" __PRETTY_FUNCTION__, __LINE__, api)
425 #else
426 #define WIN32_API_FAILED(api) _gdk_win32_api_failed (__FILE__, __LINE__, api)
427 #define WIN32_GDI_FAILED(api) _gdk_win32_gdi_failed (__FILE__, __LINE__, api)
428 #define OTHER_API_FAILED(api) _gdk_other_api_failed (__FILE__, __LINE__, api)
429 #endif
430  
431 /* These two macros call a GDI or other Win32 API and if the return
432  * value is zero or NULL, print a warning message. The majority of GDI
433  * calls return zero or NULL on failure. The value of the macros is nonzero
434  * if the call succeeded, zero otherwise.
435  */
436
437 #define GDI_CALL(api, arglist) (api arglist ? 1 : (WIN32_GDI_FAILED (#api), 0))
438 #define API_CALL(api, arglist) (api arglist ? 1 : (WIN32_API_FAILED (#api), 0))
439  
440 extern LRESULT CALLBACK _gdk_win32_window_procedure (HWND, UINT, WPARAM, LPARAM);
441
442 extern GdkWindow        *_gdk_root;
443
444 extern GdkDisplay       *_gdk_display;
445 extern GdkScreen        *_gdk_screen;
446
447 extern gint              _gdk_num_monitors;
448 extern GdkRectangle     *_gdk_monitors;
449
450 /* Offsets to add to Windows coordinates (which are relative to the
451  * primary monitor's origin, and thus might be negative for monitors
452  * to the left and/or above the primary monitor) to get GDK
453  * coordinates, which should be non-negative on the whole screen.
454  */
455 extern gint              _gdk_offset_x, _gdk_offset_y;
456
457 extern HDC               _gdk_display_hdc;
458 extern HINSTANCE         _gdk_dll_hinstance;
459 extern HINSTANCE         _gdk_app_hmodule;
460
461 /* These are thread specific, but GDK/win32 works OK only when invoked
462  * from a single thread anyway.
463  */
464 extern HKL               _gdk_input_locale;
465 extern gboolean          _gdk_input_locale_is_ime;
466 extern UINT              _gdk_input_codepage;
467
468 extern guint             _gdk_keymap_serial;
469 extern gboolean          _gdk_keyboard_has_altgr;
470 extern guint             _scancode_rshift;
471
472 /* Registered clipboard formats */
473 extern WORD              _cf_rtf;
474 extern WORD              _cf_utf8_string;
475 extern WORD              _cf_image_bmp;
476
477 /* GdkAtoms: properties, targets and types */
478 extern GdkAtom           _gdk_selection_property;
479 extern GdkAtom           _wm_transient_for;
480 extern GdkAtom           _targets;
481 extern GdkAtom           _save_targets;
482 extern GdkAtom           _utf8_string;
483 extern GdkAtom           _text;
484 extern GdkAtom           _compound_text;
485 extern GdkAtom           _text_uri_list;
486 extern GdkAtom           _image_bmp;
487
488 /* DND selections */
489 extern GdkAtom           _local_dnd;
490 extern GdkAtom           _gdk_win32_dropfiles;
491 extern GdkAtom           _gdk_ole2_dnd;
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 /* TRUE while a user-initiated window move or resize operation is in progress */
500 extern gboolean          _sizemove_in_progress;
501
502 /* TRUE when we are emptying the clipboard ourselves */
503 extern gboolean         _ignore_destroy_clipboard;
504
505 /* Mapping from registered clipboard format id (native) to
506  * corresponding GdkAtom
507  */
508 extern GHashTable       *_format_atom_table;
509
510 /* Hold the result of a delayed rendering */
511 extern HGLOBAL          _delayed_rendering_data;
512
513 HGLOBAL _gdk_win32_selection_convert_to_dib (HGLOBAL  hdata,
514                                              GdkAtom  target);
515
516 /* Convert a pixbuf to an HICON (or HCURSOR).  Supports alpha under
517  * Windows XP, thresholds alpha otherwise.
518  */
519 HICON _gdk_win32_pixbuf_to_hicon   (GdkPixbuf *pixbuf);
520 HICON _gdk_win32_pixbuf_to_hcursor (GdkPixbuf *pixbuf,
521                                     gint       x_hotspot,
522                                     gint       y_hotspot);
523 gboolean _gdk_win32_pixbuf_to_hicon_supports_alpha (void);
524
525 /* Initialization */
526 void _gdk_windowing_window_init (void);
527 void _gdk_root_window_size_init (void);
528 void _gdk_monitor_init(void);
529 void _gdk_visual_init (void);
530 void _gdk_dnd_init    (void);
531 void _gdk_windowing_image_init  (void);
532 void _gdk_events_init (void);
533 void _gdk_input_init  (GdkDisplay *display);
534
535 #endif /* __GDK_PRIVATE_WIN32_H__ */