From 8ed9d899b4bff5d80751ae2c763544c69526d462 Mon Sep 17 00:00:00 2001 From: pelya Date: Mon, 12 Jul 2010 13:55:55 +0300 Subject: [PATCH] Updated SDL 1.3 to rev hg-4510 --- alienblaster/project/jni/sdl/include/SDL.h | 1 + .../project/jni/sdl/include/SDL_clipboard.h | 76 +++++++++ .../jni/sdl/include/SDL_config_iphoneos.h | 7 +- .../project/jni/sdl/include/SDL_events.h | 3 + .../project/jni/sdl/include/SDL_pixels.h | 3 +- .../project/jni/sdl/include/SDL_revision.h | 2 +- .../project/jni/sdl/include/SDL_stdinc.h | 7 + .../project/jni/sdl/include/SDL_syswm.h | 18 -- .../project/jni/sdl/src/audio/SDL_audio.c | 2 + .../jni/sdl/src/events/SDL_clipboardevents.c | 47 +++++ .../sdl/src/events/SDL_clipboardevents_c.h | 31 ++++ .../project/jni/sdl/src/events/SDL_keyboard.c | 4 + .../project/jni/sdl/src/video/SDL_clipboard.c | 76 +++++++++ .../project/jni/sdl/src/video/SDL_surface.c | 2 +- .../project/jni/sdl/src/video/SDL_sysvideo.h | 6 + .../project/jni/sdl/src/video/SDL_video.c | 4 + .../sdl/src/video/cocoa/SDL_cocoaclipboard.h | 37 ++++ .../sdl/src/video/cocoa/SDL_cocoaclipboard.m | 140 +++++++++++++++ .../jni/sdl/src/video/cocoa/SDL_cocoaevents.m | 2 +- .../sdl/src/video/cocoa/SDL_cocoakeyboard.m | 2 +- .../jni/sdl/src/video/cocoa/SDL_cocoamodes.m | 2 +- .../jni/sdl/src/video/cocoa/SDL_cocoamouse.m | 2 +- .../jni/sdl/src/video/cocoa/SDL_cocoaopengl.m | 2 +- .../jni/sdl/src/video/cocoa/SDL_cocoavideo.h | 2 + .../jni/sdl/src/video/cocoa/SDL_cocoavideo.m | 6 +- .../jni/sdl/src/video/cocoa/SDL_cocoawindow.m | 5 +- .../src/video/uikit/SDL_uikitappdelegate.m | 3 +- .../sdl/src/video/uikit/SDL_uikitopengles.m | 8 +- .../jni/sdl/src/video/uikit/SDL_uikitview.h | 4 +- .../jni/sdl/src/video/uikit/SDL_uikitview.m | 69 +++++--- .../sdl/src/video/win32/SDL_win32clipboard.c | 161 ++++++++++++++++++ .../sdl/src/video/win32/SDL_win32clipboard.h | 37 ++++ .../jni/sdl/src/video/win32/SDL_win32events.c | 18 +- .../jni/sdl/src/video/win32/SDL_win32events.h | 1 - .../jni/sdl/src/video/win32/SDL_win32video.c | 17 ++ .../jni/sdl/src/video/win32/SDL_win32video.h | 4 + .../jni/sdl/src/video/win32/SDL_win32window.c | 45 +++-- .../jni/sdl/src/video/x11/SDL_x11clipboard.c | 156 +++++++++++++++++ .../jni/sdl/src/video/x11/SDL_x11clipboard.h | 33 ++++ .../jni/sdl/src/video/x11/SDL_x11events.c | 52 ++++++ .../jni/sdl/src/video/x11/SDL_x11sym.h | 11 +- .../jni/sdl/src/video/x11/SDL_x11video.c | 6 + .../jni/sdl/src/video/x11/SDL_x11video.h | 2 + .../jni/sdl/src/video/x11/SDL_x11window.c | 14 +- 44 files changed, 1025 insertions(+), 105 deletions(-) create mode 100644 alienblaster/project/jni/sdl/include/SDL_clipboard.h create mode 100644 alienblaster/project/jni/sdl/src/events/SDL_clipboardevents.c create mode 100644 alienblaster/project/jni/sdl/src/events/SDL_clipboardevents_c.h create mode 100644 alienblaster/project/jni/sdl/src/video/SDL_clipboard.c create mode 100644 alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoaclipboard.h create mode 100644 alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoaclipboard.m create mode 100644 alienblaster/project/jni/sdl/src/video/win32/SDL_win32clipboard.c create mode 100644 alienblaster/project/jni/sdl/src/video/win32/SDL_win32clipboard.h create mode 100644 alienblaster/project/jni/sdl/src/video/x11/SDL_x11clipboard.c create mode 100644 alienblaster/project/jni/sdl/src/video/x11/SDL_x11clipboard.h diff --git a/alienblaster/project/jni/sdl/include/SDL.h b/alienblaster/project/jni/sdl/include/SDL.h index 21c0cbe62..349010d39 100644 --- a/alienblaster/project/jni/sdl/include/SDL.h +++ b/alienblaster/project/jni/sdl/include/SDL.h @@ -78,6 +78,7 @@ #include "SDL_stdinc.h" #include "SDL_atomic.h" #include "SDL_audio.h" +#include "SDL_clipboard.h" #include "SDL_cpuinfo.h" #include "SDL_endian.h" #include "SDL_error.h" diff --git a/alienblaster/project/jni/sdl/include/SDL_clipboard.h b/alienblaster/project/jni/sdl/include/SDL_clipboard.h new file mode 100644 index 000000000..bc9e348db --- /dev/null +++ b/alienblaster/project/jni/sdl/include/SDL_clipboard.h @@ -0,0 +1,76 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2010 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/** + * \file SDL_clipboard.h + * + * Include file for SDL clipboard handling + */ + +#ifndef _SDL_clipboard_h +#define _SDL_clipboard_h + +#include "SDL_stdinc.h" + +#include "begin_code.h" +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +/* *INDENT-OFF* */ +extern "C" { +/* *INDENT-ON* */ +#endif + +/* Function prototypes */ + +/** + * \brief Put UTF-8 text into the clipboard + * + * \sa SDL_GetClipboardText() + */ +extern DECLSPEC int SDLCALL SDL_SetClipboardText(const char *text); + +/** + * \brief Get UTF-8 text from the clipboard, which must be freed with SDL_free() + * + * \sa SDL_SetClipboardText() + */ +extern DECLSPEC char * SDLCALL SDL_GetClipboardText(void); + +/** + * \brief Returns whether the clipboard has text + * + * \sa SDL_GetClipboardText() + */ +extern DECLSPEC SDL_bool SDLCALL SDL_HasClipboardText(void); + + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +/* *INDENT-OFF* */ +} +/* *INDENT-ON* */ +#endif +#include "close_code.h" + +#endif /* _SDL_clipboard_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/alienblaster/project/jni/sdl/include/SDL_config_iphoneos.h b/alienblaster/project/jni/sdl/include/SDL_config_iphoneos.h index f9271766c..6e031114b 100644 --- a/alienblaster/project/jni/sdl/include/SDL_config_iphoneos.h +++ b/alienblaster/project/jni/sdl/include/SDL_config_iphoneos.h @@ -145,12 +145,9 @@ typedef unsigned long uintptr_t; #define SDL_POWER_UIKIT 1 /* enable iPhone keyboard support */ -#define SDL_IPHONE_KEYBOARD 0 +#define SDL_IPHONE_KEYBOARD 1 -/* Enable emulation of multiple mice through multi-touch */ -#define SDL_IPHONE_MULTIPLE_MICE 1 - -/* Set max recognized G-force from acceleromter +/* Set max recognized G-force from accelerometer See src/joystick/uikit/SDLUIAccelerationDelegate.m for notes on why this is needed */ #define SDL_IPHONE_MAX_GFORCE 5.0 diff --git a/alienblaster/project/jni/sdl/include/SDL_events.h b/alienblaster/project/jni/sdl/include/SDL_events.h index 91bdd8624..50a0cb7c3 100644 --- a/alienblaster/project/jni/sdl/include/SDL_events.h +++ b/alienblaster/project/jni/sdl/include/SDL_events.h @@ -90,6 +90,9 @@ typedef enum SDL_JOYBUTTONDOWN, /**< Joystick button pressed */ SDL_JOYBUTTONUP, /**< Joystick button released */ + /* Clipboard events */ + SDL_CLIPBOARDUPDATE = 0x700, /**< The clipboard changed */ + /* Obsolete events */ SDL_EVENT_COMPAT1 = 0x7000, /**< SDL 1.2 events for compatibility */ SDL_EVENT_COMPAT2, diff --git a/alienblaster/project/jni/sdl/include/SDL_pixels.h b/alienblaster/project/jni/sdl/include/SDL_pixels.h index cdf338f9b..8c3216b07 100644 --- a/alienblaster/project/jni/sdl/include/SDL_pixels.h +++ b/alienblaster/project/jni/sdl/include/SDL_pixels.h @@ -112,8 +112,7 @@ enum SDL_PACKEDLAYOUT_1010102 }; -#define SDL_DEFINE_PIXELFOURCC(A, B, C, D) \ - ((A) | ((B) << 8) | ((C) << 16) | ((D) << 24)) +#define SDL_DEFINE_PIXELFOURCC(A, B, C, D) SDL_FOURCC(A, B, C, D) #define SDL_DEFINE_PIXELFORMAT(type, order, layout, bits, bytes) \ ((1 << 31) | ((type) << 24) | ((order) << 20) | ((layout) << 16) | \ diff --git a/alienblaster/project/jni/sdl/include/SDL_revision.h b/alienblaster/project/jni/sdl/include/SDL_revision.h index 20ca5cbfd..1c05de8fc 100644 --- a/alienblaster/project/jni/sdl/include/SDL_revision.h +++ b/alienblaster/project/jni/sdl/include/SDL_revision.h @@ -1 +1 @@ -#define SDL_REVISION "hg-4485:82d661ea0d5a" +#define SDL_REVISION "hg-4510:6f8175ad0335" diff --git a/alienblaster/project/jni/sdl/include/SDL_stdinc.h b/alienblaster/project/jni/sdl/include/SDL_stdinc.h index c7e7edd57..ba1e5b5b2 100644 --- a/alienblaster/project/jni/sdl/include/SDL_stdinc.h +++ b/alienblaster/project/jni/sdl/include/SDL_stdinc.h @@ -101,6 +101,13 @@ #endif /*@}*//*Cast operators*/ +/* Define a four character code as a Uint32 */ +#define SDL_FOURCC(A, B, C, D) \ + ((SDL_static_cast(Uint32, SDL_static_cast(Uint8, (A))) << 0) | \ + (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (B))) << 8) | \ + (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (C))) << 16) | \ + (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (D))) << 24)) + /** * \name Basic data types */ diff --git a/alienblaster/project/jni/sdl/include/SDL_syswm.h b/alienblaster/project/jni/sdl/include/SDL_syswm.h index 56ef7f6d2..4f7d00720 100644 --- a/alienblaster/project/jni/sdl/include/SDL_syswm.h +++ b/alienblaster/project/jni/sdl/include/SDL_syswm.h @@ -106,24 +106,6 @@ struct SDL_SysWMinfo { Display *display; /**< The X11 display */ Window window; /**< The X11 display window */ - /** - * These locking functions should be called around - * any X11 functions using the display variable. - * They lock the event thread, so should not be - * called around event functions or from event filters. - */ - /*@{*/ - void (*lock_func) (void); - void (*unlock_func) (void); - /*@}*/ - - /** - * Introduced in SDL 1.0.2. - */ - /*@{*/ - Window fswindow; /**< The X11 fullscreen window */ - Window wmwindow; /**< The X11 managed input window */ - /*@}*/ } x11; } info; }; diff --git a/alienblaster/project/jni/sdl/src/audio/SDL_audio.c b/alienblaster/project/jni/sdl/src/audio/SDL_audio.c index 606db26a7..5eb287d8b 100644 --- a/alienblaster/project/jni/sdl/src/audio/SDL_audio.c +++ b/alienblaster/project/jni/sdl/src/audio/SDL_audio.c @@ -291,6 +291,7 @@ SDL_StreamLength(SDL_AudioStreamer * stream) } /* Initialize the stream by allocating the buffer and setting the read/write heads to the beginning */ +#if 0 static int SDL_StreamInit(SDL_AudioStreamer * stream, int max_len, Uint8 silence) { @@ -309,6 +310,7 @@ SDL_StreamInit(SDL_AudioStreamer * stream, int max_len, Uint8 silence) return 0; } +#endif /* Deinitialize the stream simply by freeing the buffer */ static void diff --git a/alienblaster/project/jni/sdl/src/events/SDL_clipboardevents.c b/alienblaster/project/jni/sdl/src/events/SDL_clipboardevents.c new file mode 100644 index 000000000..2d5a2c48d --- /dev/null +++ b/alienblaster/project/jni/sdl/src/events/SDL_clipboardevents.c @@ -0,0 +1,47 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2010 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +/* Clipboard event handling code for SDL */ + +#include "SDL_events.h" +#include "SDL_events_c.h" +#include "SDL_clipboardevents_c.h" + + +int +SDL_SendClipboardUpdate(void) +{ + int posted; + + /* Post the event, if desired */ + posted = 0; + if (SDL_GetEventState(SDL_CLIPBOARDUPDATE) == SDL_ENABLE) { + SDL_Event event; + event.type = SDL_CLIPBOARDUPDATE; + + posted = (SDL_PushEvent(&event) > 0); + } + return (posted); +} + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/alienblaster/project/jni/sdl/src/events/SDL_clipboardevents_c.h b/alienblaster/project/jni/sdl/src/events/SDL_clipboardevents_c.h new file mode 100644 index 000000000..9e35a5aba --- /dev/null +++ b/alienblaster/project/jni/sdl/src/events/SDL_clipboardevents_c.h @@ -0,0 +1,31 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2010 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#ifndef _SDL_clipboardevents_c_h +#define _SDL_clipboardevents_c_h + +extern int SDL_SendClipboardUpdate(void); + +#endif /* _SDL_clipboardevents_c_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/alienblaster/project/jni/sdl/src/events/SDL_keyboard.c b/alienblaster/project/jni/sdl/src/events/SDL_keyboard.c index f25bc6af8..a2687bd26 100644 --- a/alienblaster/project/jni/sdl/src/events/SDL_keyboard.c +++ b/alienblaster/project/jni/sdl/src/events/SDL_keyboard.c @@ -551,6 +551,10 @@ SDL_UCS4ToUTF8(Uint32 ch, char *dst) int SDL_KeyboardInit(void) { + SDL_Keyboard *keyboard = &SDL_keyboard; + + /* Set the default keymap */ + SDL_memcpy(keyboard->keymap, SDL_default_keymap, sizeof(SDL_default_keymap)); return (0); } diff --git a/alienblaster/project/jni/sdl/src/video/SDL_clipboard.c b/alienblaster/project/jni/sdl/src/video/SDL_clipboard.c new file mode 100644 index 000000000..a414fa5ec --- /dev/null +++ b/alienblaster/project/jni/sdl/src/video/SDL_clipboard.c @@ -0,0 +1,76 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2010 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#include "SDL_clipboard.h" +#include "SDL_sysvideo.h" + + +int +SDL_SetClipboardText(const char *text) +{ + SDL_VideoDevice *_this = SDL_GetVideoDevice(); + + if (!text) { + text = ""; + } + if (_this->SetClipboardText) { + return _this->SetClipboardText(_this, text); + } else { + _this->clipboard_text = SDL_strdup(text); + return 0; + } +} + +char * +SDL_GetClipboardText(void) +{ + SDL_VideoDevice *_this = SDL_GetVideoDevice(); + + if (_this->GetClipboardText) { + return _this->GetClipboardText(_this); + } else { + const char *text = _this->clipboard_text; + if (!text) { + text = ""; + } + return SDL_strdup(text); + } +} + +SDL_bool +SDL_HasClipboardText(void) +{ + SDL_VideoDevice *_this = SDL_GetVideoDevice(); + + if (_this->HasClipboardText) { + return _this->HasClipboardText(_this); + } else { + if (_this->clipboard_text) { + return SDL_TRUE; + } else { + return SDL_FALSE; + } + } +} + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/alienblaster/project/jni/sdl/src/video/SDL_surface.c b/alienblaster/project/jni/sdl/src/video/SDL_surface.c index 37740b2d4..16bce3c1b 100644 --- a/alienblaster/project/jni/sdl/src/video/SDL_surface.c +++ b/alienblaster/project/jni/sdl/src/video/SDL_surface.c @@ -851,7 +851,7 @@ SDL_ConvertSurface(SDL_Surface * surface, SDL_PixelFormat * format, /* Enable alpha blending by default if the new surface has an * alpha channel or alpha modulation */ if ((surface->format->Amask && format->Amask) || - (copy_flags & SDL_COPY_MODULATE_ALPHA)) { + (copy_flags & (SDL_COPY_COLORKEY|SDL_COPY_MODULATE_ALPHA))) { SDL_SetSurfaceBlendMode(convert, SDL_BLENDMODE_BLEND); } if ((copy_flags & SDL_COPY_RLE_DESIRED) || (flags & SDL_RLEACCEL)) { diff --git a/alienblaster/project/jni/sdl/src/video/SDL_sysvideo.h b/alienblaster/project/jni/sdl/src/video/SDL_sysvideo.h index 121f413de..15cf4cd82 100644 --- a/alienblaster/project/jni/sdl/src/video/SDL_sysvideo.h +++ b/alienblaster/project/jni/sdl/src/video/SDL_sysvideo.h @@ -305,6 +305,11 @@ struct SDL_VideoDevice void (*StopTextInput) (_THIS); void (*SetTextInputRect) (_THIS, SDL_Rect *rect); + /* Clipboard */ + int (*SetClipboardText) (_THIS, const char *text); + char * (*GetClipboardText) (_THIS); + SDL_bool (*HasClipboardText) (_THIS); + /* * * */ /* Data common to all drivers */ SDL_bool suspend_screensaver; @@ -314,6 +319,7 @@ struct SDL_VideoDevice Uint8 window_magic; Uint8 texture_magic; Uint32 next_object_id; + char * clipboard_text; /* * * */ /* Data used by the GL drivers */ diff --git a/alienblaster/project/jni/sdl/src/video/SDL_video.c b/alienblaster/project/jni/sdl/src/video/SDL_video.c index 0b85cb81e..b195f14fc 100644 --- a/alienblaster/project/jni/sdl/src/video/SDL_video.c +++ b/alienblaster/project/jni/sdl/src/video/SDL_video.c @@ -3024,6 +3024,10 @@ SDL_VideoQuit(void) SDL_free(_this->displays); _this->displays = NULL; } + if (_this->clipboard_text) { + SDL_free(_this->clipboard_text); + _this->clipboard_text = NULL; + } _this->free(_this); _this = NULL; } diff --git a/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoaclipboard.h b/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoaclipboard.h new file mode 100644 index 000000000..9746e7eb5 --- /dev/null +++ b/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoaclipboard.h @@ -0,0 +1,37 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2010 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#ifndef _SDL_cocoaclipboard_h +#define _SDL_cocoaclipboard_h + +/* Forward declaration */ +struct SDL_VideoData; + +extern int Cocoa_SetClipboardText(_THIS, const char *text); +extern char *Cocoa_GetClipboardText(_THIS); +extern SDL_bool Cocoa_HasClipboardText(_THIS); +extern void Cocoa_CheckClipboardUpdate(struct SDL_VideoData * data); + +#endif /* _SDL_cocoaclipboard_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoaclipboard.m b/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoaclipboard.m new file mode 100644 index 000000000..26f6aeed2 --- /dev/null +++ b/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoaclipboard.m @@ -0,0 +1,140 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2010 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#include "SDL_cocoavideo.h" +#include "../../events/SDL_clipboardevents_c.h" + +static NSString * +GetTextFormat(_THIS) +{ +#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060 + return NSStringPboardType; +#else + SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; + + if (data->osversion >= 0x1060) { + return NSPasteboardTypeString; + } else { + return NSStringPboardType; + } +#endif +} + +int +Cocoa_SetClipboardText(_THIS, const char *text) +{ + SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; + NSAutoreleasePool *pool; + NSPasteboard *pasteboard; + NSString *format = GetTextFormat(_this); + + pool = [[NSAutoreleasePool alloc] init]; + + pasteboard = [NSPasteboard generalPasteboard]; + data->clipboard_count = [pasteboard declareTypes:[NSArray arrayWithObject:format] owner:nil]; + [pasteboard setString:[NSString stringWithUTF8String:text] forType:format]; + + [pool release]; + + return 0; +} + +char * +Cocoa_GetClipboardText(_THIS) +{ + NSAutoreleasePool *pool; + NSPasteboard *pasteboard; + NSString *format = GetTextFormat(_this); + NSString *available; + char *text; + + pool = [[NSAutoreleasePool alloc] init]; + + pasteboard = [NSPasteboard generalPasteboard]; + available = [pasteboard availableTypeFromArray: [NSArray arrayWithObject:format]]; + if ([available isEqualToString:format]) { + NSString* string; + const char *utf8; + + string = [pasteboard stringForType:format]; + if (string == nil) { + utf8 = ""; + } else { + utf8 = [string UTF8String]; + } + text = SDL_strdup(utf8); + } else { + text = SDL_strdup(""); + } + + [pool release]; + + return text; +} + +SDL_bool +Cocoa_HasClipboardText(_THIS) +{ + NSAutoreleasePool *pool; + NSPasteboard *pasteboard; + NSString *format = GetTextFormat(_this); + NSString *available; + SDL_bool result; + + pool = [[NSAutoreleasePool alloc] init]; + + pasteboard = [NSPasteboard generalPasteboard]; + available = [pasteboard availableTypeFromArray: [NSArray arrayWithObject:format]]; + if ([available isEqualToString:format]) { + result = SDL_TRUE; + } else { + result = SDL_FALSE; + } + + [pool release]; + + return result; +} + +void +Cocoa_CheckClipboardUpdate(struct SDL_VideoData * data) +{ + NSAutoreleasePool *pool; + NSPasteboard *pasteboard; + NSInteger count; + + pool = [[NSAutoreleasePool alloc] init]; + + pasteboard = [NSPasteboard generalPasteboard]; + count = [pasteboard changeCount]; + if (count != data->clipboard_count) { + if (data->clipboard_count) { + SDL_SendClipboardUpdate(); + } + data->clipboard_count = count; + } + + [pool release]; +} + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoaevents.m b/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoaevents.m index d833400e9..d1164e5c2 100644 --- a/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoaevents.m +++ b/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoaevents.m @@ -1,6 +1,6 @@ /* SDL - Simple DirectMedia Layer - Copyright (C) 1997-2009 Sam Lantinga + Copyright (C) 1997-2010 Sam Lantinga This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public diff --git a/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoakeyboard.m b/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoakeyboard.m index 9fd89d15d..83e743f50 100644 --- a/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoakeyboard.m +++ b/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoakeyboard.m @@ -1,6 +1,6 @@ /* SDL - Simple DirectMedia Layer - Copyright (C) 1997-2009 Sam Lantinga + Copyright (C) 1997-2010 Sam Lantinga This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public diff --git a/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoamodes.m b/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoamodes.m index b26905bc9..4b120a68e 100644 --- a/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoamodes.m +++ b/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoamodes.m @@ -1,6 +1,6 @@ /* SDL - Simple DirectMedia Layer - Copyright (C) 1997-2009 Sam Lantinga + Copyright (C) 1997-2010 Sam Lantinga This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public diff --git a/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoamouse.m b/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoamouse.m index e3d70bfac..c0ac2feaf 100644 --- a/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoamouse.m +++ b/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoamouse.m @@ -1,6 +1,6 @@ /* SDL - Simple DirectMedia Layer - Copyright (C) 1997-2009 Sam Lantinga + Copyright (C) 1997-2010 Sam Lantinga This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public diff --git a/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoaopengl.m b/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoaopengl.m index e80e310b5..41ab75d98 100644 --- a/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoaopengl.m +++ b/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoaopengl.m @@ -1,6 +1,6 @@ /* SDL - Simple DirectMedia Layer - Copyright (C) 1997-2009 Sam Lantinga + Copyright (C) 1997-2010 Sam Lantinga This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public diff --git a/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoavideo.h b/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoavideo.h index 8f12dc056..890624bfb 100644 --- a/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoavideo.h +++ b/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoavideo.h @@ -32,6 +32,7 @@ #include "SDL_keysym.h" #include "../SDL_sysvideo.h" +#include "SDL_cocoaclipboard.h" #include "SDL_cocoaevents.h" #include "SDL_cocoakeyboard.h" #include "SDL_cocoamodes.h" @@ -59,6 +60,7 @@ typedef struct SDL_VideoData unsigned int modifierFlags; void *key_layout; SDLTranslatorResponder *fieldEdit; + NSInteger clipboard_count; Uint32 screensaver_activity; } SDL_VideoData; diff --git a/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoavideo.m b/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoavideo.m index 86e19fda7..e4b58cb67 100644 --- a/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoavideo.m +++ b/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoavideo.m @@ -1,6 +1,6 @@ /* SDL - Simple DirectMedia Layer - Copyright (C) 1997-2009 Sam Lantinga + Copyright (C) 1997-2010 Sam Lantinga This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -108,6 +108,10 @@ Cocoa_CreateDevice(int devindex) device->StopTextInput = Cocoa_StopTextInput; device->SetTextInputRect = Cocoa_SetTextInputRect; + device->SetClipboardText = Cocoa_SetClipboardText; + device->GetClipboardText = Cocoa_GetClipboardText; + device->HasClipboardText = Cocoa_HasClipboardText; + device->free = Cocoa_DeleteDevice; return device; diff --git a/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoawindow.m b/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoawindow.m index be4045c89..be4840b82 100644 --- a/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoawindow.m +++ b/alienblaster/project/jni/sdl/src/video/cocoa/SDL_cocoawindow.m @@ -1,6 +1,6 @@ /* SDL - Simple DirectMedia Layer - Copyright (C) 1997-2009 Sam Lantinga + Copyright (C) 1997-2010 Sam Lantinga This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -128,6 +128,9 @@ static __inline__ void ConvertNSRect(NSRect *r) { /* We're going to get keyboard events, since we're key. */ SDL_SetKeyboardFocus(_data->window); + + /* Check to see if someone updated the clipboard */ + Cocoa_CheckClipboardUpdate(_data->videodata); } - (void)windowDidResignKey:(NSNotification *)aNotification diff --git a/alienblaster/project/jni/sdl/src/video/uikit/SDL_uikitappdelegate.m b/alienblaster/project/jni/sdl/src/video/uikit/SDL_uikitappdelegate.m index ac2992d32..5b18e27f2 100644 --- a/alienblaster/project/jni/sdl/src/video/uikit/SDL_uikitappdelegate.m +++ b/alienblaster/project/jni/sdl/src/video/uikit/SDL_uikitappdelegate.m @@ -42,11 +42,12 @@ int main(int argc, char **argv) { /* store arguments */ forward_argc = argc; - forward_argv = (char **)malloc(argc * sizeof(char *)); + forward_argv = (char **)malloc((argc+1) * sizeof(char *)); for (i=0; i @@ -125,7 +127,11 @@ SDL_GLContext UIKit_GL_CreateContext(_THIS, SDL_Window * window) UIKit_GL_DeleteContext(_this, view); return NULL; } - + + /* Make this window the current mouse focus for touch input */ + SDL_SetMouseFocus(window); + SDL_SetKeyboardFocus(window); + return view; } diff --git a/alienblaster/project/jni/sdl/src/video/uikit/SDL_uikitview.h b/alienblaster/project/jni/sdl/src/video/uikit/SDL_uikitview.h index 3e0315704..ca7924b92 100644 --- a/alienblaster/project/jni/sdl/src/video/uikit/SDL_uikitview.h +++ b/alienblaster/project/jni/sdl/src/video/uikit/SDL_uikitview.h @@ -22,8 +22,6 @@ #import #include "SDL_stdinc.h" -#include "SDL_mouse.h" -#include "SDL_mouse_c.h" #include "SDL_events.h" #if SDL_IPHONE_MULTIPLE_MICE @@ -38,7 +36,7 @@ #else @interface SDL_uikitview : UIView { #endif - + #if FIXME_MULTITOUCH SDL_Mouse mice[MAX_SIMULTANEOUS_TOUCHES]; #endif diff --git a/alienblaster/project/jni/sdl/src/video/uikit/SDL_uikitview.m b/alienblaster/project/jni/sdl/src/video/uikit/SDL_uikitview.m index da03d0c2e..879ac0464 100644 --- a/alienblaster/project/jni/sdl/src/video/uikit/SDL_uikitview.m +++ b/alienblaster/project/jni/sdl/src/video/uikit/SDL_uikitview.m @@ -22,8 +22,10 @@ #import "SDL_uikitview.h" +#include "../../events/SDL_keyboard_c.h" +#include "../../events/SDL_mouse_c.h" + #if SDL_IPHONE_KEYBOARD -#import "SDL_keyboard_c.h" #import "keyinfotable.h" #import "SDL_uikitappdelegate.h" #import "SDL_uikitwindow.h" @@ -33,7 +35,6 @@ - (void)dealloc { #if SDL_IPHONE_KEYBOARD - SDL_DelKeyboard(0); [textField release]; #endif [super dealloc]; @@ -64,7 +65,7 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSEnumerator *enumerator = [touches objectEnumerator]; - UITouch *touch =(UITouch*)[enumerator nextObject]; + UITouch *touch = (UITouch*)[enumerator nextObject]; #if FIXME_MULTITOUCH /* associate touches with mice, so long as we have slots */ @@ -101,12 +102,21 @@ /* re-calibrate relative mouse motion */ SDL_GetRelativeMouseState(i, NULL, NULL); - /* grab next touch */ - touch = (UITouch*)[enumerator nextObject]; - /* switch back to our old mouse */ SDL_SelectMouse(oldMouse); + /* grab next touch */ + touch = (UITouch*)[enumerator nextObject]; + } +#else + if (touch) { + CGPoint locationInView = [touch locationInView: self]; + + /* send moved event */ + SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y); + + /* send mouse down event */ + SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT); } #endif } @@ -114,10 +124,10 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { NSEnumerator *enumerator = [touches objectEnumerator]; - UITouch *touch=nil; + UITouch *touch = (UITouch*)[enumerator nextObject]; #if FIXME_MULTITOUCH - while(touch = (UITouch *)[enumerator nextObject]) { + while(touch) { /* search for the mouse slot associated with this touch */ int i, found = NO; for (i=0; idisplays; + if (display) { + window = display->windows; + if (window) { + return ((SDL_WindowData *) window->driverdata)->hwnd; + } + } + return NULL; +} + +int +WIN_SetClipboardText(_THIS, const char *text) +{ + SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; + int result = 0; + + if (OpenClipboard(GetWindowHandle(_this))) { + HANDLE hMem; + LPTSTR tstr; + SIZE_T i, size; + + /* Convert the text from UTF-8 to Windows Unicode */ + tstr = WIN_UTF8ToString(text); + if (!tstr) { + return -1; + } + + /* Find out the size of the data */ + for (size = 0, i = 0; tstr[i]; ++i, ++size) { + if (tstr[i] == '\n' && (i == 0 || tstr[i-1] != '\r')) { + /* We're going to insert a carriage return */ + ++size; + } + } + size = (size+1)*sizeof(*tstr); + + /* Save the data to the clipboard */ + hMem = GlobalAlloc(GMEM_MOVEABLE, size); + if (hMem) { + LPTSTR dst = (LPTSTR)GlobalLock(hMem); + /* Copy the text over, adding carriage returns as necessary */ + for (i = 0; tstr[i]; ++i) { + if (tstr[i] == '\n' && (i == 0 || tstr[i-1] != '\r')) { + *dst++ = '\r'; + } + *dst++ = tstr[i]; + } + *dst = 0; + GlobalUnlock(hMem); + + EmptyClipboard(); + if (!SetClipboardData(TEXT_FORMAT, hMem)) { + WIN_SetError("Couldn't set clipboard data"); + result = -1; + } + data->clipboard_count = GetClipboardSequenceNumber(); + } + SDL_free(tstr); + + CloseClipboard(); + } else { + WIN_SetError("Couldn't open clipboard"); + result = -1; + } + return result; +} + +char * +WIN_GetClipboardText(_THIS) +{ + char *text; + + text = NULL; + if (IsClipboardFormatAvailable(TEXT_FORMAT) && + OpenClipboard(GetWindowHandle(_this))) { + HANDLE hMem; + LPTSTR tstr; + + hMem = GetClipboardData(TEXT_FORMAT); + if (hMem) { + tstr = (LPTSTR)GlobalLock(hMem); + text = WIN_StringToUTF8(tstr); + GlobalUnlock(hMem); + } else { + WIN_SetError("Couldn't get clipboard data"); + } + CloseClipboard(); + } + if (!text) { + text = SDL_strdup(""); + } + return text; +} + +SDL_bool +WIN_HasClipboardText(_THIS) +{ + if (IsClipboardFormatAvailable(TEXT_FORMAT)) { + return SDL_TRUE; + } else { + return SDL_FALSE; + } +} + +void +WIN_CheckClipboardUpdate(struct SDL_VideoData * data) +{ + DWORD count; + + count = GetClipboardSequenceNumber(); + if (count != data->clipboard_count) { + if (data->clipboard_count) { + SDL_SendClipboardUpdate(); + } + data->clipboard_count = count; + } +} + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/alienblaster/project/jni/sdl/src/video/win32/SDL_win32clipboard.h b/alienblaster/project/jni/sdl/src/video/win32/SDL_win32clipboard.h new file mode 100644 index 000000000..ab2fb17a7 --- /dev/null +++ b/alienblaster/project/jni/sdl/src/video/win32/SDL_win32clipboard.h @@ -0,0 +1,37 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2010 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#ifndef _SDL_win32clipboard_h +#define _SDL_win32clipboard_h + +/* Forward declaration */ +struct SDL_VideoData; + +extern int WIN_SetClipboardText(_THIS, const char *text); +extern char *WIN_GetClipboardText(_THIS); +extern SDL_bool WIN_HasClipboardText(_THIS); +extern void WIN_CheckClipboardUpdate(struct SDL_VideoData * data); + +#endif /* _SDL_win32clipboard_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/alienblaster/project/jni/sdl/src/video/win32/SDL_win32events.c b/alienblaster/project/jni/sdl/src/video/win32/SDL_win32events.c index 1ea7e6c10..d03b672c6 100644 --- a/alienblaster/project/jni/sdl/src/video/win32/SDL_win32events.c +++ b/alienblaster/project/jni/sdl/src/video/win32/SDL_win32events.c @@ -162,7 +162,10 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) if (SDL_GetKeyboardFocus() != data->window) { SDL_SetKeyboardFocus(data->window); } - /* FIXME: Update keyboard state */ + /* + * FIXME: Update keyboard state + */ + WIN_CheckClipboardUpdate(data->videodata); } else { if (SDL_GetKeyboardFocus() == data->window) { SDL_SetKeyboardFocus(NULL); @@ -585,17 +588,4 @@ SDL_UnregisterApp() } } -/* Sets an error message based on GetLastError() */ -void -WIN_SetError(const char *prefix) -{ - TCHAR buffer[1024]; - char *message; - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, - buffer, SDL_arraysize(buffer), NULL); - message = WIN_StringToUTF8(buffer); - SDL_SetError("%s%s%s", prefix ? prefix : "", prefix ? ": " : "", message); - SDL_free(message); -} - /* vi: set ts=4 sw=4 expandtab: */ diff --git a/alienblaster/project/jni/sdl/src/video/win32/SDL_win32events.h b/alienblaster/project/jni/sdl/src/video/win32/SDL_win32events.h index 8ba8e8ab1..18e880bf4 100644 --- a/alienblaster/project/jni/sdl/src/video/win32/SDL_win32events.h +++ b/alienblaster/project/jni/sdl/src/video/win32/SDL_win32events.h @@ -31,7 +31,6 @@ extern HINSTANCE SDL_Instance; extern LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); extern void WIN_PumpEvents(_THIS); -extern void WIN_SetError(const char *prefix); #endif /* _SDL_win32events_h */ diff --git a/alienblaster/project/jni/sdl/src/video/win32/SDL_win32video.c b/alienblaster/project/jni/sdl/src/video/win32/SDL_win32video.c index c93d4f72e..2c5d3146d 100644 --- a/alienblaster/project/jni/sdl/src/video/win32/SDL_win32video.c +++ b/alienblaster/project/jni/sdl/src/video/win32/SDL_win32video.c @@ -35,6 +35,19 @@ static int WIN_VideoInit(_THIS); static void WIN_VideoQuit(_THIS); +/* Sets an error message based on GetLastError() */ +void +WIN_SetError(const char *prefix) +{ + TCHAR buffer[1024]; + char *message; + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, + buffer, SDL_arraysize(buffer), NULL); + message = WIN_StringToUTF8(buffer); + SDL_SetError("%s%s%s", prefix ? prefix : "", prefix ? ": " : "", message); + SDL_free(message); +} + /* WIN32 driver bootstrap functions */ static int @@ -163,6 +176,10 @@ WIN_CreateDevice(int devindex) device->GL_DeleteContext = WIN_GL_DeleteContext; #endif + device->SetClipboardText = WIN_SetClipboardText; + device->GetClipboardText = WIN_GetClipboardText; + device->HasClipboardText = WIN_HasClipboardText; + device->free = WIN_DeleteDevice; return device; diff --git a/alienblaster/project/jni/sdl/src/video/win32/SDL_win32video.h b/alienblaster/project/jni/sdl/src/video/win32/SDL_win32video.h index 3cfb63219..6911f49b8 100644 --- a/alienblaster/project/jni/sdl/src/video/win32/SDL_win32video.h +++ b/alienblaster/project/jni/sdl/src/video/win32/SDL_win32video.h @@ -45,6 +45,7 @@ #include "ddraw.h" #endif +#include "SDL_win32clipboard.h" #include "SDL_win32events.h" #include "SDL_win32gamma.h" #include "SDL_win32keyboard.h" @@ -60,6 +61,7 @@ #define WIN_StringToUTF8(S) SDL_iconv_string("UTF-8", "ASCII", (char *)S, (SDL_strlen(S)+1)) #define WIN_UTF8ToString(S) SDL_iconv_string("ASCII", "UTF-8", (char *)S, SDL_strlen(S)+1) #endif +extern void WIN_SetError(const char *prefix); /* Private display data */ @@ -74,6 +76,8 @@ typedef struct SDL_VideoData IDirectDraw *ddraw; #endif + DWORD clipboard_count; + const SDL_scancode *key_layout; } SDL_VideoData; diff --git a/alienblaster/project/jni/sdl/src/video/win32/SDL_win32window.c b/alienblaster/project/jni/sdl/src/video/win32/SDL_win32window.c index fc1cd154f..0de0bbeb2 100644 --- a/alienblaster/project/jni/sdl/src/video/win32/SDL_win32window.c +++ b/alienblaster/project/jni/sdl/src/video/win32/SDL_win32window.c @@ -184,7 +184,6 @@ WIN_CreateWindow(_THIS, SDL_Window * window) { SDL_VideoDisplay *display = window->display; HWND hwnd; - HWND top; RECT rect; SDL_Rect bounds; DWORD style = (WS_CLIPSIBLINGS | WS_CLIPCHILDREN); @@ -202,11 +201,6 @@ WIN_CreateWindow(_THIS, SDL_Window * window) } /* Figure out what the window area will be */ - if (window->flags & SDL_WINDOW_FULLSCREEN) { - top = HWND_TOPMOST; - } else { - top = HWND_NOTOPMOST; - } rect.left = 0; rect.top = 0; rect.right = window->w; @@ -216,9 +210,17 @@ WIN_CreateWindow(_THIS, SDL_Window * window) h = (rect.bottom - rect.top); WIN_GetDisplayBounds(_this, display, &bounds); + if (window->flags & SDL_WINDOW_FULLSCREEN) { + /* The bounds when this window is visible is the fullscreen mode */ + SDL_DisplayMode fullscreen_mode; + if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) { + bounds.w = fullscreen_mode.w; + bounds.h = fullscreen_mode.h; + } + } if ((window->flags & SDL_WINDOW_FULLSCREEN) || window->x == SDL_WINDOWPOS_CENTERED) { - x = bounds.x + (bounds.w - window->w) / 2; + x = bounds.x + (bounds.w - w) / 2; } else if (window->x == SDL_WINDOWPOS_UNDEFINED) { if (bounds.x == 0) { x = CW_USEDEFAULT; @@ -230,7 +232,7 @@ WIN_CreateWindow(_THIS, SDL_Window * window) } if ((window->flags & SDL_WINDOW_FULLSCREEN) || window->y == SDL_WINDOWPOS_CENTERED) { - y = bounds.y + (bounds.h - window->h) / 2; + y = bounds.y + (bounds.h - h) / 2; } else if (window->x == SDL_WINDOWPOS_UNDEFINED) { if (bounds.x == 0) { y = CW_USEDEFAULT; @@ -387,6 +389,7 @@ WIN_SetWindowPosition(_THIS, SDL_Window * window) HWND top; BOOL menu; int x, y; + int w, h; /* Figure out what the window area will be */ if (window->flags & SDL_WINDOW_FULLSCREEN) { @@ -405,17 +408,27 @@ WIN_SetWindowPosition(_THIS, SDL_Window * window) menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL); #endif AdjustWindowRectEx(&rect, style, menu, 0); + w = (rect.right - rect.left); + h = (rect.bottom - rect.top); WIN_GetDisplayBounds(_this, display, &bounds); + if (window->flags & SDL_WINDOW_FULLSCREEN) { + /* The bounds when this window is visible is the fullscreen mode */ + SDL_DisplayMode fullscreen_mode; + if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) { + bounds.w = fullscreen_mode.w; + bounds.h = fullscreen_mode.h; + } + } if ((window->flags & SDL_WINDOW_FULLSCREEN) || window->x == SDL_WINDOWPOS_CENTERED) { - x = bounds.x + (bounds.w - window->w) / 2; + x = bounds.x + (bounds.w - w) / 2; } else { x = bounds.x + window->x + rect.left; } if ((window->flags & SDL_WINDOW_FULLSCREEN) || window->y == SDL_WINDOWPOS_CENTERED) { - y = bounds.y + (bounds.h - window->h) / 2; + y = bounds.y + (bounds.h - h) / 2; } else { y = bounds.y + window->y + rect.top; } @@ -620,8 +633,7 @@ SDL_HelperWindowCreate(void) /* Register the class. */ SDL_HelperWindowClass = RegisterClass(&wce); if (SDL_HelperWindowClass == 0) { - SDL_SetError("Unable to create Helper Window Class: error %d.", - GetLastError()); + WIN_SetError("Unable to create Helper Window Class"); return -1; } @@ -639,8 +651,7 @@ SDL_HelperWindowCreate(void) hInstance, NULL); if (SDL_HelperWindow == NULL) { UnregisterClass(SDL_HelperWindowClassName, hInstance); - SDL_SetError("Unable to create Helper Window: error %d.", - GetLastError()); + WIN_SetError("Unable to create Helper Window"); return -1; } @@ -659,8 +670,7 @@ SDL_HelperWindowDestroy(void) /* Destroy the window. */ if (SDL_HelperWindow != NULL) { if (DestroyWindow(SDL_HelperWindow) == 0) { - SDL_SetError("Unable to destroy Helper Window: error %d.", - GetLastError()); + WIN_SetError("Unable to destroy Helper Window"); return; } SDL_HelperWindow = NULL; @@ -669,8 +679,7 @@ SDL_HelperWindowDestroy(void) /* Unregister the class. */ if (SDL_HelperWindowClass != 0) { if ((UnregisterClass(SDL_HelperWindowClassName, hInstance)) == 0) { - SDL_SetError("Unable to destroy Helper Window Class: error %d.", - GetLastError()); + WIN_SetError("Unable to destroy Helper Window Class"); return; } SDL_HelperWindowClass = 0; diff --git a/alienblaster/project/jni/sdl/src/video/x11/SDL_x11clipboard.c b/alienblaster/project/jni/sdl/src/video/x11/SDL_x11clipboard.c new file mode 100644 index 000000000..ddd8cdc41 --- /dev/null +++ b/alienblaster/project/jni/sdl/src/video/x11/SDL_x11clipboard.c @@ -0,0 +1,156 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2010 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#include /* For INT_MAX */ + +#include "SDL_events.h" +#include "SDL_x11video.h" + + +/* If you don't support UTF-8, you might use XA_STRING here */ +#if 1 +#define TEXT_FORMAT XInternAtom(display, "UTF8_STRING", False) +#else +#define TEXT_FORMAT XA_STRING +#endif + +/* Get any application owned window handle for clipboard association */ +static Window +GetWindow(_THIS) +{ + SDL_VideoDisplay *display; + SDL_Window *window; + + display = _this->displays; + if (display) { + window = display->windows; + if (window) { + return ((SDL_WindowData *) window->driverdata)->xwindow; + } + } + return None; +} + +int +X11_SetClipboardText(_THIS, const char *text) +{ + Display *display = ((SDL_VideoData *) _this->driverdata)->display; + Atom format; + Window window; + + /* Get the SDL window that will own the selection */ + window = GetWindow(_this); + if (window == None) { + SDL_SetError("Couldn't find a window to own the selection"); + return -1; + } + + /* Save the selection on the root window */ + format = TEXT_FORMAT; + XChangeProperty(display, DefaultRootWindow(display), + XA_CUT_BUFFER0, format, 8, PropModeReplace, + (const unsigned char *)text, SDL_strlen(text)); + + if (XGetSelectionOwner(display, XA_PRIMARY) != window) { + XSetSelectionOwner(display, XA_PRIMARY, window, CurrentTime); + } + return 0; +} + +char * +X11_GetClipboardText(_THIS) +{ + SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata; + Display *display = videodata->display; + Atom format; + Window window; + Window owner; + Atom selection; + Atom seln_type; + int seln_format; + unsigned long nbytes; + unsigned long overflow; + unsigned char *src; + char *text; + + text = NULL; + + /* Get the window that holds the selection */ + window = GetWindow(_this); + format = TEXT_FORMAT; + owner = XGetSelectionOwner(display, XA_PRIMARY); + if ((owner == None) || (owner == window)) { + owner = DefaultRootWindow(display); + selection = XA_CUT_BUFFER0; + } else { + /* Request that the selection owner copy the data to our window */ + owner = window; + selection = XInternAtom(display, "SDL_SELECTION", False); + XConvertSelection(display, XA_PRIMARY, format, selection, owner, + CurrentTime); + + /* FIXME: Should we have a timeout here? */ + videodata->selection_waiting = SDL_TRUE; + while (videodata->selection_waiting) { + SDL_PumpEvents(); + } + } + + if (XGetWindowProperty(display, owner, selection, 0, INT_MAX/4, False, + format, &seln_type, &seln_format, &nbytes, &overflow, &src) + == Success) { + if (seln_type == format) { + text = (char *)SDL_malloc(nbytes+1); + if (text) { + SDL_memcpy(text, src, nbytes); + text[nbytes] = '\0'; + } + } + XFree(src); + } + + if (!text) { + text = SDL_strdup(""); + } + return text; +} + +SDL_bool +X11_HasClipboardText(_THIS) +{ + /* Not an easy way to tell with X11, as far as I know... */ + char *text; + SDL_bool retval; + + text = X11_GetClipboardText(_this); + if (*text) { + retval = SDL_TRUE; + } else { + retval = SDL_FALSE; + } + SDL_free(text); + + return retval; +} + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/alienblaster/project/jni/sdl/src/video/x11/SDL_x11clipboard.h b/alienblaster/project/jni/sdl/src/video/x11/SDL_x11clipboard.h new file mode 100644 index 000000000..6d9bbb085 --- /dev/null +++ b/alienblaster/project/jni/sdl/src/video/x11/SDL_x11clipboard.h @@ -0,0 +1,33 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2010 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#ifndef _SDL_x11clipboard_h +#define _SDL_x11clipboard_h + +extern int X11_SetClipboardText(_THIS, const char *text); +extern char *X11_GetClipboardText(_THIS); +extern SDL_bool X11_HasClipboardText(_THIS); + +#endif /* _SDL_x11clipboard_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/alienblaster/project/jni/sdl/src/video/x11/SDL_x11events.c b/alienblaster/project/jni/sdl/src/video/x11/SDL_x11events.c index 147dc626d..e4d51bc6b 100644 --- a/alienblaster/project/jni/sdl/src/video/x11/SDL_x11events.c +++ b/alienblaster/project/jni/sdl/src/video/x11/SDL_x11events.c @@ -25,6 +25,7 @@ #include #include #include +#include /* For INT_MAX */ #include "SDL_x11video.h" #include "../../events/SDL_events_c.h" @@ -33,6 +34,8 @@ #include "SDL_timer.h" #include "SDL_syswm.h" +/*#define DEBUG_XEVENTS*/ + static void X11_DispatchEvent(_THIS) { @@ -286,6 +289,55 @@ X11_DispatchEvent(_THIS) } break; + /* Copy the selection from XA_CUT_BUFFER0 to the requested property */ + case SelectionRequest: { + Display *display = videodata->display; + XSelectionRequestEvent *req; + XEvent sevent; + int seln_format; + unsigned long nbytes; + unsigned long overflow; + unsigned char *seln_data; + + req = &xevent.xselectionrequest; +#ifdef DEBUG_XEVENTS + printf("SelectionRequest (requestor = %ld, target = %ld)\n", + req->requestor, req->target); +#endif + + sevent.xselection.type = SelectionNotify; + sevent.xselection.display = req->display; + sevent.xselection.selection = req->selection; + sevent.xselection.target = None; + sevent.xselection.property = None; + sevent.xselection.requestor = req->requestor; + sevent.xselection.time = req->time; + if (XGetWindowProperty(display, DefaultRootWindow(display), + XA_CUT_BUFFER0, 0, INT_MAX/4, False, req->target, + &sevent.xselection.target, &seln_format, &nbytes, + &overflow, &seln_data) == Success) { + if (sevent.xselection.target == req->target) { + XChangeProperty(display, req->requestor, req->property, + sevent.xselection.target, seln_format, PropModeReplace, + seln_data, nbytes); + sevent.xselection.property = req->property; + } + XFree(seln_data); + } + XSendEvent(display, req->requestor, False, 0, &sevent); + XSync(display, False); + } + break; + + case SelectionNotify: { +#ifdef DEBUG_XEVENTS + printf("SelectionNotify (requestor = %ld, target = %ld)\n", + xevent.xselection.requestor, xevent.xselection.target); +#endif + videodata->selection_waiting = SDL_FALSE; + } + break; + default:{ #ifdef DEBUG_XEVENTS printf("Unhandled event %d\n", xevent.type); diff --git a/alienblaster/project/jni/sdl/src/video/x11/SDL_x11sym.h b/alienblaster/project/jni/sdl/src/video/x11/SDL_x11sym.h index 0cdcfe8dc..01dc8f6a0 100644 --- a/alienblaster/project/jni/sdl/src/video/x11/SDL_x11sym.h +++ b/alienblaster/project/jni/sdl/src/video/x11/SDL_x11sym.h @@ -37,6 +37,7 @@ SDL_X11_SYM(int,XChangeWindowAttributes,(Display* a,Window b,unsigned long c,XSe SDL_X11_SYM(Bool,XCheckWindowEvent,(Display* a,Window b,long c,XEvent* d),(a,b,c,d),return) SDL_X11_SYM(int,XClearWindow,(Display* a,Window b),(a,b),return) SDL_X11_SYM(int,XCloseDisplay,(Display* a),(a),return) +SDL_X11_SYM(int,XConvertSelection,(Display* a,Atom b,Atom c,Atom d,Window e,Time f),(a,b,c,d,e,f),return) SDL_X11_SYM(int,XCopyArea,(Display* a,Drawable b,Drawable c,GC d,int e,int f,unsigned int g,unsigned int h,int i,int j),(a,b,c,d,e,f,g,h,i,j),return) SDL_X11_SYM(Colormap,XCreateColormap,(Display* a,Window b,Visual* c,int d),(a,b,c,d),return) SDL_X11_SYM(Cursor,XCreatePixmapCursor,(Display* a,Pixmap b,Pixmap c,XColor* d,XColor* e,unsigned int f,unsigned int g),(a,b,c,d,e,f,g),return) @@ -71,10 +72,11 @@ SDL_X11_SYM(XImage*,XGetImage,(Display* a,Drawable b,int c,int d,unsigned int e, SDL_X11_SYM(XModifierKeymap*,XGetModifierMapping,(Display* a),(a),return) SDL_X11_SYM(int,XGetPointerControl,(Display* a,int* b,int* c,int* d),(a,b,c,d),return) SDL_X11_SYM(int,XGetRGBColormaps,(Display* a,Window b,XStandardColormap **c,int *d,Atom e),(a,b,c,d,e),return) +SDL_X11_SYM(Window,XGetSelectionOwner,(Display* a,Atom b),(a,b),return) SDL_X11_SYM(XVisualInfo*,XGetVisualInfo,(Display* a,long b,XVisualInfo* c,int* d),(a,b,c,d),return) -SDL_X11_SYM(XWMHints*,XGetWMHints,(Display* a,Window b),(a,b),return) SDL_X11_SYM(Status,XGetWindowAttributes,(Display* a,Window b,XWindowAttributes* c),(a,b,c),return) SDL_X11_SYM(int,XGetWindowProperty,(Display* a,Window b,Atom c,long d,long e,Bool f,Atom g,Atom* h,int* i,unsigned long* j,unsigned long *k,unsigned char **l),(a,b,c,d,e,f,g,h,i,j,k,l),return) +SDL_X11_SYM(XWMHints*,XGetWMHints,(Display* a,Window b),(a,b),return) SDL_X11_SYM(int,XGrabKeyboard,(Display* a,Window b,Bool c,int d,int e,Time f),(a,b,c,d,e,f),return) SDL_X11_SYM(int,XGrabPointer,(Display* a,Window b,Bool c,unsigned int d,int e,int f,Window g,Cursor h,Time i),(a,b,c,d,e,f,g,h,i),return) SDL_X11_SYM(int,XGrabServer,(Display* a),(a),return) @@ -114,14 +116,15 @@ SDL_X11_SYM(int,XSetForeground,(Display* a,GC b,unsigned long c),(a,b,c),return) SDL_X11_SYM(XErrorHandler,XSetErrorHandler,(XErrorHandler a),(a),return) SDL_X11_SYM(XIOErrorHandler,XSetIOErrorHandler,(XIOErrorHandler a),(a),return) SDL_X11_SYM(void,XSetRGBColormaps,( Display *a,Window b,XStandardColormap *c,int d,Atom e),(a,b,c,d,e),return) +SDL_X11_SYM(int,XSetSelectionOwner,(Display* a,Atom b,Window c,Time d),(a,b,c,d),return) SDL_X11_SYM(int,XSetTransientForHint,(Display* a,Window b,Window c),(a,b,c),return) -SDL_X11_SYM(int,XSetWMHints,(Display* a,Window b,XWMHints* c),(a,b,c),return) SDL_X11_SYM(void,XSetTextProperty,(Display* a,Window b,XTextProperty* c,Atom d),(a,b,c,d),) -SDL_X11_SYM(void,XSetWMNormalHints,(Display* a,Window b,XSizeHints* c),(a,b,c),) -SDL_X11_SYM(Status,XSetWMProtocols,(Display* a,Window b,Atom* c,int d),(a,b,c,d),return) SDL_X11_SYM(int,XSetWindowBackground,(Display* a,Window b,unsigned long c),(a,b,c),return) SDL_X11_SYM(int,XSetWindowBackgroundPixmap,(Display* a,Window b,Pixmap c),(a,b,c),return) SDL_X11_SYM(int,XSetWindowColormap,(Display* a,Window b,Colormap c),(a,b,c),return) +SDL_X11_SYM(int,XSetWMHints,(Display* a,Window b,XWMHints* c),(a,b,c),return) +SDL_X11_SYM(void,XSetWMNormalHints,(Display* a,Window b,XSizeHints* c),(a,b,c),) +SDL_X11_SYM(Status,XSetWMProtocols,(Display* a,Window b,Atom* c,int d),(a,b,c,d),return) SDL_X11_SYM(int,XStoreColors,(Display* a,Colormap b,XColor* c,int d),(a,b,c,d),return) SDL_X11_SYM(Status,XStringListToTextProperty,(char** a,int b,XTextProperty* c),(a,b,c),return) SDL_X11_SYM(int,XSync,(Display* a,Bool b),(a,b),return) diff --git a/alienblaster/project/jni/sdl/src/video/x11/SDL_x11video.c b/alienblaster/project/jni/sdl/src/video/x11/SDL_x11video.c index 86a9e7db9..a3a8d2c72 100644 --- a/alienblaster/project/jni/sdl/src/video/x11/SDL_x11video.c +++ b/alienblaster/project/jni/sdl/src/video/x11/SDL_x11video.c @@ -21,6 +21,8 @@ */ #include "SDL_config.h" +#include /* For getpid() and readlink() */ + #include "SDL_video.h" #include "SDL_mouse.h" #include "../SDL_sysvideo.h" @@ -225,6 +227,10 @@ X11_CreateDevice(int devindex) device->GL_DeleteContext = X11_GLES_DeleteContext; #endif + device->SetClipboardText = X11_SetClipboardText; + device->GetClipboardText = X11_GetClipboardText; + device->HasClipboardText = X11_HasClipboardText; + device->free = X11_DeleteDevice; return device; diff --git a/alienblaster/project/jni/sdl/src/video/x11/SDL_x11video.h b/alienblaster/project/jni/sdl/src/video/x11/SDL_x11video.h index a550f8485..34647ca51 100644 --- a/alienblaster/project/jni/sdl/src/video/x11/SDL_x11video.h +++ b/alienblaster/project/jni/sdl/src/video/x11/SDL_x11video.h @@ -48,6 +48,7 @@ #include "SDL_x11dyn.h" +#include "SDL_x11clipboard.h" #include "SDL_x11events.h" #include "SDL_x11gamma.h" #include "SDL_x11keyboard.h" @@ -69,6 +70,7 @@ typedef struct SDL_VideoData int windowlistlength; Atom WM_DELETE_WINDOW; SDL_scancode key_layout[256]; + SDL_bool selection_waiting; } SDL_VideoData; extern SDL_bool X11_UseDirectColorVisuals(void); diff --git a/alienblaster/project/jni/sdl/src/video/x11/SDL_x11window.c b/alienblaster/project/jni/sdl/src/video/x11/SDL_x11window.c index 699740418..78d94dab2 100644 --- a/alienblaster/project/jni/sdl/src/video/x11/SDL_x11window.c +++ b/alienblaster/project/jni/sdl/src/video/x11/SDL_x11window.c @@ -289,9 +289,9 @@ X11_CreateWindow(_THIS, SDL_Window * window) Sint32 r, g, b; /* Is the colormap we need already registered in SDL? */ - if (colormap = + if ((colormap = X11_LookupColormap(data->display, - displaydata->screen, visual->visualid)) { + displaydata->screen, visual->visualid))) { xattr.colormap = colormap; /* printf("found existing colormap\n"); */ } else { @@ -1014,8 +1014,14 @@ X11_DestroyWindow(_THIS, SDL_Window * window) SDL_bool X11_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info) { - if (info->version.major <= SDL_MAJOR_VERSION) { - /* FIXME! */ + SDL_WindowData *data = (SDL_WindowData *) window->driverdata; + Display *display = data->videodata->display; + + if (info->version.major == SDL_MAJOR_VERSION && + info->version.minor == SDL_MINOR_VERSION) { + info->subsystem = SDL_SYSWM_X11; + info->info.x11.display = display; + info->info.x11.window = data->xwindow; return SDL_TRUE; } else { SDL_SetError("Application not compiled with SDL %d.%d\n",