]> Pileus Git - ~andy/gtk/blob - gdk/win32/gdkmain-win32.c
54e5eedc0e02cba7427f29597fba132795226047
[~andy/gtk] / gdk / win32 / gdkmain-win32.c
1 /* GDK - The GIMP Drawing Kit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  * Copyright (C) 1998-1999 Tor Lillqvist
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 /*
22  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
23  * file for a list of people on the GTK+ Team.  See the ChangeLog
24  * files for a list of changes.  These files are distributed with
25  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
26  */
27
28 #include "config.h"
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <limits.h>
34 #include <io.h>
35
36 #include "gdk.h"
37 #include "gdkkeysyms.h"
38 #include "gdkinternals.h"
39 #include "gdkprivate-win32.h"
40 #include "gdkinput-win32.h"
41
42 #include <objbase.h>
43
44 static gboolean gdk_synchronize = FALSE;
45
46 GdkArgDesc _gdk_windowing_args[] = {
47   { "sync",          GDK_ARG_BOOL, &gdk_synchronize, (GdkArgFunc) NULL},
48   { "no-wintab",     GDK_ARG_BOOL, &gdk_input_ignore_wintab,
49                                                      (GdkArgFunc) NULL},
50   { "ignore-wintab", GDK_ARG_BOOL, &gdk_input_ignore_wintab,
51                                                      (GdkArgFunc) NULL},
52   { "event-func-from-window-proc",
53                      GDK_ARG_BOOL, &gdk_event_func_from_window_proc,
54                                                      (GdkArgFunc) NULL},
55   { NULL }
56 };
57
58 int __stdcall
59 DllMain(HINSTANCE hinstDLL,
60         DWORD     dwReason,
61         LPVOID    reserved)
62 {
63   gdk_dll_hinstance = hinstDLL;
64
65   return TRUE;
66 }
67
68 gboolean
69 _gdk_windowing_init_check (int    argc,
70                            char **argv)
71 {
72 #ifdef HAVE_WINTAB
73   if (getenv ("GDK_IGNORE_WINTAB") != NULL)
74     gdk_input_ignore_wintab = TRUE;
75 #endif
76   if (getenv ("GDK_EVENT_FUNC_FROM_WINDOW_PROC") != NULL)
77     gdk_event_func_from_window_proc = TRUE;
78
79   if (gdk_synchronize)
80     GdiSetBatchLimit (1);
81
82   gdk_app_hmodule = GetModuleHandle (NULL);
83   gdk_display_hdc = CreateDC ("DISPLAY", NULL, NULL, NULL);
84   gdk_root_window = GetDesktopWindow ();
85   windows_version = GetVersion ();
86
87   CoInitialize (NULL);
88
89   cf_rtf = RegisterClipboardFormat ("Rich Text Format");
90   cf_utf8_string = RegisterClipboardFormat ("UTF8_STRING");
91
92   utf8_string = gdk_atom_intern ("UTF8_STRING", FALSE);
93   compound_text = gdk_atom_intern ("COMPOUND_TEXT", FALSE);
94   text_uri_list = gdk_atom_intern ("text/uri-list", FALSE);
95
96   local_dnd = gdk_atom_intern ("LocalDndSelection", FALSE);
97   gdk_win32_dropfiles = gdk_atom_intern ("DROPFILES_DND", FALSE);
98   gdk_ole2_dnd = gdk_atom_intern ("OLE2_DND", FALSE);
99
100   _gdk_selection_property = gdk_atom_intern ("GDK_SELECTION", FALSE);
101
102   _gdk_win32_selection_init ();
103
104   return TRUE;
105 }
106
107 void
108 gdk_win32_api_failed (const gchar *where,
109                       gint         line,
110                       const gchar *api)
111 {
112   gchar *msg = g_win32_error_message (GetLastError ());
113   g_warning ("%s:%d: %s failed: %s", where, line, api, msg);
114   g_free (msg);
115 }
116
117 void
118 gdk_other_api_failed (const gchar *where,
119                       gint         line,
120                       const gchar *api)
121 {
122   g_warning ("%s:%d: %s failed", where, line, api);
123 }
124
125 void
126 gdk_win32_gdi_failed (const gchar *where,
127                       gint         line,
128                       const gchar *api)
129 {
130   /* On Win9x GDI calls are implemented in 16-bit code and thus
131    * don't set the 32-bit error code, sigh.
132    */
133   if (IS_WIN_NT ())
134     gdk_win32_api_failed (where, line, api);
135   else
136     gdk_other_api_failed (where, line, api);
137 }
138
139 void
140 gdk_set_use_xshm (gboolean use_xshm)
141 {
142   /* Always on */
143 }
144
145 gboolean
146 gdk_get_use_xshm (void)
147 {
148   return TRUE;
149 }
150
151 /*
152  *--------------------------------------------------------------
153  * gdk_screen_width
154  *
155  *   Return the width of the screen.
156  *
157  * Arguments:
158  *
159  * Results:
160  *
161  * Side effects:
162  *
163  *--------------------------------------------------------------
164  */
165
166 gint
167 gdk_screen_width (void)
168 {
169   return GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (_gdk_parent_root)->impl)->width;
170 }
171
172 /*
173  *--------------------------------------------------------------
174  * gdk_screen_height
175  *
176  *   Return the height of the screen.
177  *
178  * Arguments:
179  *
180  * Results:
181  *
182  * Side effects:
183  *
184  *--------------------------------------------------------------
185  */
186
187 gint
188 gdk_screen_height (void)
189 {
190   return GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (_gdk_parent_root)->impl)->height;
191 }
192
193 /*
194  *--------------------------------------------------------------
195  * gdk_screen_width_mm
196  *
197  *   Return the width of the screen in millimetres.
198  *
199  * Arguments:
200  *
201  * Results:
202  *
203  * Side effects:
204  *
205  *--------------------------------------------------------------
206  */
207
208 gint
209 gdk_screen_width_mm (void)
210 {
211   return GetDeviceCaps (gdk_display_hdc, HORZSIZE);
212 }
213
214 /*
215  *--------------------------------------------------------------
216  * gdk_screen_height
217  *
218  *   Return the height of the screen in millimetres.
219  *
220  * Arguments:
221  *
222  * Results:
223  *
224  * Side effects:
225  *
226  *--------------------------------------------------------------
227  */
228
229 gint
230 gdk_screen_height_mm (void)
231 {
232   return GetDeviceCaps (gdk_display_hdc, VERTSIZE);
233 }
234
235 void
236 gdk_set_sm_client_id (const gchar* sm_client_id)
237 {
238   g_warning("gdk_set_sm_client_id %s", sm_client_id ? sm_client_id : "NULL");
239 }
240
241 void
242 gdk_beep (void)
243 {
244   Beep(1000, 50);
245 }
246
247 void
248 _gdk_windowing_exit (void)
249 {
250   _gdk_win32_dnd_exit ();
251   CoUninitialize ();
252   DeleteDC (gdk_display_hdc);
253   gdk_display_hdc = NULL;
254 }
255
256 gchar *
257 gdk_get_display (void)
258 {
259   return "Win32";
260 }