]> Pileus Git - ~andy/gtk/blob - gdk/win32/gdkmain-win32.c
Implement the functions that until now just were non-functional stubs. For
[~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-2002 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   { "max-colors",    GDK_ARG_INT,  &gdk_max_colors,  (GdkArgFunc) NULL},
56   { NULL }
57 };
58
59 int __stdcall
60 DllMain(HINSTANCE hinstDLL,
61         DWORD     dwReason,
62         LPVOID    reserved)
63 {
64   gdk_dll_hinstance = hinstDLL;
65
66   return TRUE;
67 }
68
69 gboolean
70 _gdk_windowing_init_check (int    argc,
71                            char **argv)
72 {
73   gchar buf[10];
74
75 #ifdef HAVE_WINTAB
76   if (getenv ("GDK_IGNORE_WINTAB") != NULL)
77     gdk_input_ignore_wintab = TRUE;
78 #endif
79   if (getenv ("GDK_EVENT_FUNC_FROM_WINDOW_PROC") != NULL)
80     gdk_event_func_from_window_proc = TRUE;
81
82   if (gdk_synchronize)
83     GdiSetBatchLimit (1);
84
85   gdk_app_hmodule = GetModuleHandle (NULL);
86   gdk_display_hdc = CreateDC ("DISPLAY", NULL, NULL, NULL);
87   gdk_root_window = GetDesktopWindow ();
88   windows_version = GetVersion ();
89
90   _gdk_input_locale = GetKeyboardLayout (0);
91   GetLocaleInfo (MAKELCID (LOWORD (_gdk_input_locale), SORT_DEFAULT),
92                  LOCALE_IDEFAULTANSICODEPAGE,
93                  buf, sizeof (buf));
94   _gdk_input_codepage = atoi (buf);
95   GDK_NOTE (MISC, g_print ("input_locale: %#lx, codepage:%d\n",
96                            _gdk_input_locale, _gdk_input_codepage));
97
98   CoInitialize (NULL);
99
100   cf_rtf = RegisterClipboardFormat ("Rich Text Format");
101   cf_utf8_string = RegisterClipboardFormat ("UTF8_STRING");
102
103   utf8_string = gdk_atom_intern ("UTF8_STRING", FALSE);
104   compound_text = gdk_atom_intern ("COMPOUND_TEXT", FALSE);
105   text_uri_list = gdk_atom_intern ("text/uri-list", FALSE);
106
107   local_dnd = gdk_atom_intern ("LocalDndSelection", FALSE);
108   gdk_win32_dropfiles = gdk_atom_intern ("DROPFILES_DND", FALSE);
109   gdk_ole2_dnd = gdk_atom_intern ("OLE2_DND", FALSE);
110
111   _gdk_selection_property = gdk_atom_intern ("GDK_SELECTION", FALSE);
112
113   _gdk_win32_selection_init ();
114
115   return TRUE;
116 }
117
118 void
119 gdk_win32_api_failed (const gchar *where,
120                       gint         line,
121                       const gchar *api)
122 {
123   gchar *msg = g_win32_error_message (GetLastError ());
124   g_warning ("%s:%d: %s failed: %s", where, line, api, msg);
125   g_free (msg);
126 }
127
128 void
129 gdk_other_api_failed (const gchar *where,
130                       gint         line,
131                       const gchar *api)
132 {
133   g_warning ("%s:%d: %s failed", where, line, api);
134 }
135
136 void
137 gdk_win32_gdi_failed (const gchar *where,
138                       gint         line,
139                       const gchar *api)
140 {
141   /* On Win9x GDI calls are implemented in 16-bit code and thus
142    * don't set the 32-bit error code, sigh.
143    */
144   if (IS_WIN_NT ())
145     gdk_win32_api_failed (where, line, api);
146   else
147     gdk_other_api_failed (where, line, api);
148 }
149
150 void
151 gdk_set_use_xshm (gboolean use_xshm)
152 {
153   /* Always on */
154 }
155
156 gboolean
157 gdk_get_use_xshm (void)
158 {
159   return TRUE;
160 }
161
162 /*
163  *--------------------------------------------------------------
164  * gdk_screen_width
165  *
166  *   Return the width of the screen.
167  *
168  * Arguments:
169  *
170  * Results:
171  *
172  * Side effects:
173  *
174  *--------------------------------------------------------------
175  */
176
177 gint
178 gdk_screen_width (void)
179 {
180   return GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (_gdk_parent_root)->impl)->width;
181 }
182
183 /*
184  *--------------------------------------------------------------
185  * gdk_screen_height
186  *
187  *   Return the height of the screen.
188  *
189  * Arguments:
190  *
191  * Results:
192  *
193  * Side effects:
194  *
195  *--------------------------------------------------------------
196  */
197
198 gint
199 gdk_screen_height (void)
200 {
201   return GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (_gdk_parent_root)->impl)->height;
202 }
203
204 /*
205  *--------------------------------------------------------------
206  * gdk_screen_width_mm
207  *
208  *   Return the width of the screen in millimetres.
209  *
210  * Arguments:
211  *
212  * Results:
213  *
214  * Side effects:
215  *
216  *--------------------------------------------------------------
217  */
218
219 gint
220 gdk_screen_width_mm (void)
221 {
222   return GetDeviceCaps (gdk_display_hdc, HORZSIZE);
223 }
224
225 /*
226  *--------------------------------------------------------------
227  * gdk_screen_height
228  *
229  *   Return the height of the screen in millimetres.
230  *
231  * Arguments:
232  *
233  * Results:
234  *
235  * Side effects:
236  *
237  *--------------------------------------------------------------
238  */
239
240 gint
241 gdk_screen_height_mm (void)
242 {
243   return GetDeviceCaps (gdk_display_hdc, VERTSIZE);
244 }
245
246 void
247 gdk_set_sm_client_id (const gchar* sm_client_id)
248 {
249   g_warning("gdk_set_sm_client_id %s", sm_client_id ? sm_client_id : "NULL");
250 }
251
252 void
253 gdk_beep (void)
254 {
255   Beep(1000, 50);
256 }
257
258 void
259 _gdk_windowing_exit (void)
260 {
261   _gdk_win32_dnd_exit ();
262   CoUninitialize ();
263   DeleteDC (gdk_display_hdc);
264   gdk_display_hdc = NULL;
265 }
266
267 gchar *
268 gdk_get_display (void)
269 {
270   return "Win32";
271 }
272
273 void
274 gdk_error_trap_push (void)
275 {
276 }
277
278 gint
279 gdk_error_trap_pop (void)
280 {
281   return 0;
282 }