- Changed I_GetFromClipboard() to return an FString.

SVN r1414 (trunk)
This commit is contained in:
Randy Heit 2009-02-08 03:32:27 +00:00
parent be165578ea
commit 025e36ee41
8 changed files with 32 additions and 27 deletions

View file

@ -1,4 +1,5 @@
February 7, 2009
- Changed I_GetFromClipboard() to return an FString.
- Added GTK+-based clipboard support for Linux.
- Fixed: Most Linux filesystems do not fill in d_type for scandir(), so we
cannot rely on it to detect directories.

View file

@ -1739,13 +1739,14 @@ static bool C_HandleKey (event_t *ev, BYTE *buffer, int len)
}
else
{ // paste from clipboard
char *clip = I_GetFromClipboard ();
if (clip != NULL)
FString clip = I_GetFromClipboard ();
if (clip.IsNotEmpty())
{
strtok (clip, "\r\n\b");
int cliplen = (int)strlen (clip);
// Only paste the first line.
long brk = clip.IndexOfAny("\r\n\b");
int cliplen = brk >= 0 ? brk : clip.Len();
cliplen = MIN(len, cliplen);
// Make sure there's room for the whole thing.
if (buffer[0] + cliplen > len)
{
cliplen = len - buffer[0];
@ -1764,7 +1765,6 @@ static bool C_HandleKey (event_t *ev, BYTE *buffer, int len)
makestartposgood ();
HistPos = NULL;
}
delete[] clip;
}
break;
}

View file

@ -150,16 +150,19 @@ bool CT_Responder (event_t *ev)
}
else if (ev->data1 == 'V' && (ev->data3 & GKM_CTRL))
{
char *clip = I_GetFromClipboard ();
if (clip != NULL)
FString clip = I_GetFromClipboard ();
if (clip.IsNotEmpty())
{
char *clip_p = clip;
strtok (clip, "\n\r\b");
// Only paste the first line.
const char *clip_p = clip;
while (*clip_p)
{
if (*clip_p == '\n' || *clip_p == '\r' || *clip_p == '\b')
{
break;
}
CT_AddChar (*clip_p++);
}
delete[] clip;
}
}
}

View file

@ -646,7 +646,7 @@ void M_ScreenShot (const char *filename)
else
#endif
{
int dirlen;
size_t dirlen;
autoname = Args->CheckValue("-shotdir");
if (autoname == NULL)
{

View file

@ -2,7 +2,7 @@
#define __I_INPUT_H__
void I_PutInClipboard (const char *str);
char *I_GetFromClipboard ();
FString I_GetFromClipboard ();
struct GUIDName
{

View file

@ -596,7 +596,7 @@ void I_PutInClipboard (const char *str)
#endif
}
char *I_GetFromClipboard ()
FString I_GetFromClipboard ()
{
#ifndef NO_GTK
if (GtkAvailable)
@ -607,12 +607,12 @@ char *I_GetFromClipboard ()
gchar *text = gtk_clipboard_wait_for_text(clipboard);
if (text != NULL)
{
char *copy = copystring(text);
FString copy(text);
g_free(text);
return copy;
}
}
}
#endif
return NULL;
return "";
}

View file

@ -2024,15 +2024,15 @@ void I_PutInClipboard (const char *str)
CloseClipboard ();
}
char *I_GetFromClipboard ()
FString I_GetFromClipboard ()
{
char *retstr = NULL;
FString retstr;
HGLOBAL cliphandle;
char *clipstr;
char *nlstr;
if (!IsClipboardFormatAvailable (CF_TEXT) || !OpenClipboard (Window))
return NULL;
return retstr;
cliphandle = GetClipboardData (CF_TEXT);
if (cliphandle != NULL)
@ -2040,15 +2040,16 @@ char *I_GetFromClipboard ()
clipstr = (char *)GlobalLock (cliphandle);
if (clipstr != NULL)
{
retstr = copystring (clipstr);
GlobalUnlock (clipstr);
nlstr = retstr;
// Convert CR-LF pairs to just LF
while ( (nlstr = strstr (retstr, "\r\n")) )
// Convert CR-LF pairs to just LF while copying to the FString
for (nlstr = clipstr; *nlstr != '\0'; ++nlstr)
{
memmove (nlstr, nlstr + 1, strlen (nlstr) - 1);
if (nlstr[0] == '\r' && nlstr[1] == '\n')
{
nlstr++;
}
retstr += *nlstr;
}
GlobalUnlock (clipstr);
}
}

View file

@ -39,7 +39,7 @@
bool I_InitInput (void *hwnd);
void I_ShutdownInput ();
void I_PutInClipboard (const char *str);
char *I_GetFromClipboard ();
FString I_GetFromClipboard ();
void I_GetEvent ();