Commit 9f3b82e1 authored by Tor Lillqvist's avatar Tor Lillqvist
Browse files

Win32 version of GDK source files and resource files (cursors and icons).

parent ced58eb1
/* GDK - The GIMP Drawing Kit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
* Copyright (C) 1998-1999 Tor Lillqvist
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <io.h>
#include "gdk.h"
#include "gdkprivate.h"
#include "gdkinput.h"
#include "gdkx.h"
#include "gdkkeysyms.h"
#include "gdki18n.h"
static void gdkx_XConvertCase (KeySym symbol,
KeySym *lower,
KeySym *upper);
#define XConvertCase gdkx_XConvertCase
static void gdk_exit_func (void);
static RETSIGTYPE gdk_signal (int signum);
/* Private variable declarations
*/
static int gdk_initialized = 0; /* 1 if the library is initialized,
* 0 otherwise.
*/
static guint start; /* We use the millisecond
* timestamps from GetTickCount
*/
static gboolean timerp = TRUE; /* If TRUE use timeouts when waiting
* for Windows messages
*/
static guint32 timer_val = 20; /* Timeout in milliseconds.
*/
#ifdef G_ENABLE_DEBUG
static const GDebugKey gdk_debug_keys[] = {
{"events", GDK_DEBUG_EVENTS},
{"misc", GDK_DEBUG_MISC},
{"dnd", GDK_DEBUG_DND},
{"color-context", GDK_DEBUG_COLOR_CONTEXT},
{"xim", GDK_DEBUG_XIM},
{"selection", GDK_DEBUG_SELECTION}
};
static const int gdk_ndebug_keys = sizeof(gdk_debug_keys)/sizeof(GDebugKey);
#endif /* G_ENABLE_DEBUG */
int __stdcall
DllMain(HINSTANCE hinstDLL,
DWORD dwReason,
LPVOID reserved)
{
gdk_DLLInstance = hinstDLL;
return TRUE;
}
/*
*--------------------------------------------------------------
* gdk_init
*
* Initialize the library for use.
*
* Arguments:
* "argc" is the number of arguments.
* "argv" is an array of strings.
*
* Results:
* "argc" and "argv" are modified to reflect any arguments
* which were not handled. (Such arguments should either
* be handled by the application or dismissed).
*
* Side effects:
* The library is initialized.
*
*--------------------------------------------------------------
*/
gboolean
gdk_init_check (int *argc,
char ***argv)
{
HRESULT hres;
gint i, j, k;
if (gdk_initialized)
return TRUE;
if (g_thread_supported ())
gdk_threads_mutex = g_mutex_new ();
start = GetTickCount ();
#ifdef G_ENABLE_DEBUG
{
gchar *debug_string = getenv("GDK_DEBUG");
if (debug_string != NULL)
gdk_debug_flags = g_parse_debug_string (debug_string,
(GDebugKey *) gdk_debug_keys,
gdk_ndebug_keys);
}
#endif /* G_ENABLE_DEBUG */
if (getenv ("GDK_IGNORE_WINTAB") != NULL)
gdk_input_ignore_wintab = TRUE;
if (argc && argv)
{
if (*argc > 0)
{
gchar *d;
d = strrchr((*argv)[0], G_DIR_SEPARATOR);
if (d != NULL)
g_set_prgname (d + 1);
else
g_set_prgname ((*argv)[0]);
}
for (i = 1; i < *argc;)
{
#ifdef G_ENABLE_DEBUG
if ((strcmp ("--gdk-debug", (*argv)[i]) == 0) ||
(strncmp ("--gdk-debug=", (*argv)[i], 12) == 0))
{
gchar *equal_pos = strchr ((*argv)[i], '=');
if (equal_pos != NULL)
{
gdk_debug_flags |= g_parse_debug_string (equal_pos+1,
(GDebugKey *) gdk_debug_keys,
gdk_ndebug_keys);
}
else if ((i + 1) < *argc && (*argv)[i + 1])
{
gdk_debug_flags |= g_parse_debug_string ((*argv)[i+1],
(GDebugKey *) gdk_debug_keys,
gdk_ndebug_keys);
(*argv)[i] = NULL;
i += 1;
}
(*argv)[i] = NULL;
}
else if ((strcmp ("--gdk-no-debug", (*argv)[i]) == 0) ||
(strncmp ("--gdk-no-debug=", (*argv)[i], 15) == 0))
{
gchar *equal_pos = strchr ((*argv)[i], '=');
if (equal_pos != NULL)
{
gdk_debug_flags &= ~g_parse_debug_string (equal_pos+1,
(GDebugKey *) gdk_debug_keys,
gdk_ndebug_keys);
}
else if ((i + 1) < *argc && (*argv)[i + 1])
{
gdk_debug_flags &= ~g_parse_debug_string ((*argv)[i+1],
(GDebugKey *) gdk_debug_keys,
gdk_ndebug_keys);
(*argv)[i] = NULL;
i += 1;
}
(*argv)[i] = NULL;
}
else
#endif /* G_ENABLE_DEBUG */
if (strcmp ("--sync", (*argv)[i]) == 0)
{
(*argv)[i] = NULL;
GdiSetBatchLimit (1);
}
else if (strcmp ("--name", (*argv)[i]) == 0)
{
if ((i + 1) < *argc && (*argv)[i + 1])
{
(*argv)[i++] = NULL;
g_set_prgname ((*argv)[i]);
(*argv)[i] = NULL;
}
}
else if (strcmp ("--gdk-no-wintab", (*argv)[i]) == 0
|| strcmp ("--gdk-ignore-wintab", (*argv)[i]) == 0)
{
(*argv)[i++] = NULL;
gdk_input_ignore_wintab = TRUE;
}
i += 1;
}
for (i = 1; i < *argc; i++)
{
for (k = i; k < *argc; k++)
if ((*argv)[k] != NULL)
break;
if (k > i)
{
k -= i;
for (j = i + k; j < *argc; j++)
(*argv)[j-k] = (*argv)[j];
*argc -= k;
}
}
}
else
{
g_set_prgname ("<unknown>");
}
gdk_ProgInstance = GetModuleHandle (NULL);
gdk_DC = CreateDC ("DISPLAY", NULL, NULL, NULL);
gdk_selection_request_msg = RegisterWindowMessage ("gdk-selection-request");
gdk_selection_notify_msg = RegisterWindowMessage ("gdk-selection-notify");
gdk_selection_clear_msg = RegisterWindowMessage ("gdk-selection-clear");
gdk_selection_property = gdk_atom_intern ("GDK_SELECTION", FALSE);
gdk_clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE);
gdk_win32_dropfiles_atom = gdk_atom_intern ("DROPFILES_DND", FALSE);
gdk_ole2_dnd_atom = gdk_atom_intern ("OLE2_DND", FALSE);
gdk_progclass = g_basename (g_get_prgname ());
gdk_progclass[0] = toupper (gdk_progclass[0]);
gdk_root_window = HWND_DESKTOP;
g_atexit (gdk_exit_func);
gdk_events_init ();
gdk_visual_init ();
gdk_window_init ();
gdk_image_init ();
gdk_input_init ();
gdk_selection_init ();
gdk_dnd_init ();
gdk_initialized = 1;
return TRUE;
}
void
gdk_init (int *argc, char ***argv)
{
if (!gdk_init_check (argc, argv))
{
g_warning ("cannot initialize GDK");
exit(1);
}
}
/*
*--------------------------------------------------------------
* gdk_exit
*
* Restores the library to an un-itialized state and exits
* the program using the "exit" system call.
*
* Arguments:
* "errorcode" is the error value to pass to "exit".
*
* Results:
* Allocated structures are freed and the program exits
* cleanly.
*
* Side effects:
*
*--------------------------------------------------------------
*/
void
gdk_exit (int errorcode)
{
/* de-initialisation is done by the gdk_exit_func(),
no need to do this here (Alex J.) */
exit (errorcode);
}
void
gdk_set_use_xshm (gint use_xshm)
{
/* Always on */
}
gint
gdk_get_use_xshm (void)
{
return TRUE;
}
/*
*--------------------------------------------------------------
* gdk_time_get
*
* Get the number of milliseconds since the library was
* initialized.
*
* Arguments:
*
* Results:
* The time since the library was initialized is returned.
* This time value is accurate to milliseconds even though
* a more accurate time down to the microsecond could be
* returned.
*
* Side effects:
*
*--------------------------------------------------------------
*/
guint32
gdk_time_get (void)
{
guint32 milliseconds;
guint32 end = GetTickCount ();
if (end < start)
milliseconds = 0xFFFFFFFF - (start - end) + 1;
else
milliseconds = end - start;
return milliseconds;
}
/*
*--------------------------------------------------------------
* gdk_timer_get
*
* Returns the current timer.
*
* Arguments:
*
* Results:
* Returns the current timer interval. This interval is
* in units of milliseconds.
*
* Side effects:
*
*--------------------------------------------------------------
*/
guint32
gdk_timer_get (void)
{
return timer_val;
}
/*
*--------------------------------------------------------------
* gdk_timer_set
*
* Sets the timer interval.
*
* Arguments:
* "milliseconds" is the new value for the timer.
*
* Results:
*
* Side effects:
* Calls to "gdk_event_get" will last for a maximum
* of time of "milliseconds". However, a value of 0
* milliseconds will cause "gdk_event_get" to block
* indefinately until an event is received.
*
*--------------------------------------------------------------
*/
void
gdk_timer_set (guint32 milliseconds)
{
timer_val = milliseconds;
#ifdef USE_PEEKNAMEDPIPE
/* When using PeekNamedPipe, can't have too long timeouts.
*/
if (timer_val > 10)
timer_val = 10;
else if (timer_val == 0)
timer_val = 0;
#endif
}
void
gdk_timer_enable (void)
{
timerp = TRUE;
}
void
gdk_timer_disable (void)
{
#ifdef USE_PEEKNAMEDPIPE
/* Can't disable timeouts when using PeekNamedPipe */
#else
timerp = FALSE;
#endif
}
/*
*--------------------------------------------------------------
* gdk_screen_width
*
* Return the width of the screen.
*
* Arguments:
*
* Results:
*
* Side effects:
*
*--------------------------------------------------------------
*/
gint
gdk_screen_width (void)
{
gint return_val;
return_val = gdk_root_parent.width;
return return_val;
}
/*
*--------------------------------------------------------------
* gdk_screen_height
*
* Return the height of the screen.
*
* Arguments:
*
* Results:
*
* Side effects:
*
*--------------------------------------------------------------
*/
gint
gdk_screen_height (void)
{
gint return_val;
return_val = gdk_root_parent.height;
return return_val;
}
/*
*--------------------------------------------------------------
* gdk_screen_width_mm
*
* Return the width of the screen in millimetres.
*
* Arguments:
*
* Results:
*
* Side effects:
*
*--------------------------------------------------------------
*/
gint
gdk_screen_width_mm (void)
{
HDC hdc;
gint return_val;
hdc = GetDC (NULL);
return_val = GetDeviceCaps (hdc, HORZSIZE);
ReleaseDC (NULL, hdc);
return return_val;
}
/*
*--------------------------------------------------------------
* gdk_screen_height
*
* Return the height of the screen in millimetres.
*
* Arguments:
*
* Results:
*
* Side effects:
*
*--------------------------------------------------------------
*/
gint
gdk_screen_height_mm (void)
{
HDC hdc;
gint return_val;
hdc = GetDC (NULL);
return_val = GetDeviceCaps (hdc, VERTSIZE);
ReleaseDC (NULL, hdc);
return return_val;
}
void
gdk_key_repeat_disable (void)
{
/* XXX */
}
void
gdk_key_repeat_restore (void)
{
/* XXX */
}
/*
*--------------------------------------------------------------
* gdk_flush
*
* Flushes the Xlib output buffer and then waits
* until all requests have been received and processed
* by the X server. The only real use for this function
* is in dealing with XShm.
*
* Arguments:
*
* Results:
*
* Side effects:
*
*--------------------------------------------------------------
*/
void
gdk_flush (void)
{
GdiFlush ();
}
void
gdk_beep (void)
{
Beep(1000, 50);
}
/*
*--------------------------------------------------------------
* gdk_exit_func
*
* This is the "atexit" function that makes sure the
* library gets a chance to cleanup.
*
* Arguments:
*
* Results:
*
* Side effects:
* The library is un-initialized and the program exits.
*
*--------------------------------------------------------------
*/
static void
gdk_exit_func (void)
{
static gboolean in_gdk_exit_func = FALSE;
GDK_NOTE (MISC, g_print ("gdk_exit_func\n"));
/* This is to avoid an infinite loop if a program segfaults in
an atexit() handler (and yes, it does happen, especially if a program
has trounced over memory too badly for even g_message to work) */
if (in_gdk_exit_func == TRUE)
return;
in_gdk_exit_func = TRUE;
if (gdk_initialized)
{
gdk_image_exit ();
gdk_input_exit ();
gdk_key_repeat_restore ();
gdk_dnd_exit ();
gdk_initialized = 0;
}
}
gchar *
gdk_get_display(void)
{
return "local:";
}
/*************************************************************
* gdk_error_trap_push:
* Push an error trap. X errors will be trapped until
* the corresponding gdk_error_pop(), which will return
* the error code, if any.
* arguments:
*
* results: