Experimental "paste" support for text fields.

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1827 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Adrien Destugues 2011-09-25 08:45:48 +00:00
parent 4dc40e7784
commit afa22ae0ac
2 changed files with 64 additions and 6 deletions

View File

@ -120,8 +120,10 @@ byte Native_filesel(byte load)
// Check if cancel
return CommDlgExtendedError();
}
#else ifndef(__linux__) // This makes no sense on X11-oriented platform. Nothing is really native there.
#else
#ifndef(__linux__) // This makes no sense on X11-oriented platform. Nothing is really native there.
#warning "EXPERIMENTAL function for native fileselector not available for this platform!"
#endif
return 255; // fail !
#endif
}

View File

@ -41,6 +41,11 @@
#include "input.h"
#include "engine.h"
#ifdef __WIN32__
#include <Windows.h>
#include <SDL_syswm.h>
#endif
// Virtual keyboard is mandatory on these platforms:
#if defined(__GP2X__) || defined(__WIZ__) || defined(__CAANOO__)
#ifndef VIRT_KEY
@ -143,6 +148,42 @@ void Init_virtual_keyboard(word y_pos, word keyboard_width, word keyboard_height
}
}
// Inspired from http://www.libsdl.org/projects/scrap/
// TODO X11 and others
char* getClipboard()
{
char* dst = NULL;
#ifdef __WIN32__
SDL_SysWMinfo info;
HWND SDL_Window;
SDL_VERSION(&info.version);
if ( SDL_GetWMInfo(&info) )
{
SDL_Window = info.window;
if ( IsClipboardFormatAvailable(CF_TEXT) && OpenClipboard(SDL_Window) )
{
HANDLE hMem;
char *src;
hMem = GetClipboardData(CF_TEXT);
if ( hMem != NULL )
{
src = (char *)GlobalLock(hMem);
dst = strdup(src);
GlobalUnlock(hMem);
}
CloseClipboard();
}
}
#endif
return dst;
}
/****************************************************************************
* Enhanced super scanf deluxe pro plus giga mieux :-) *
****************************************************************************/
@ -410,9 +451,23 @@ byte Readline_ex(word x_pos,word y_pos,char * str,byte visible_size,byte max_siz
input_key=Key_ANSI;
if (Mouse_K)
input_key=SDLK_RETURN;
// Handle paste request on CTRL+v
if ((Key & MOD_CTRL) && ((Key & 0xFFF) == 'v'))
{
char* data = getClipboard();
if (data == NULL) continue; // No clipboard data
// TODO Insert it at the cursor position, not at the end
// TODO Update cursor position
// TODO This doesn't respect the "allowed chars" restriction
strncat(str, data, max_size - size);
free(data);
goto affichage;
}
} while(input_key==0);
}
Hide_cursor();
switch (input_key)
{
case SDLK_DELETE : // Suppr.
@ -529,6 +584,7 @@ byte Readline_ex(word x_pos,word y_pos,char * str,byte visible_size,byte max_siz
// On regarde si la touche est autorisée
if ( Valid_character(input_key))
is_authorized=1;
break;
case INPUT_TYPE_HEXA:
if ( (input_key>='0') && (input_key<='9') )
is_authorized=1;