mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
Fix line endings when pasting on Windows.
[originally from svn r5736]
This commit is contained in:
28
windows.c
28
windows.c
@ -330,16 +330,37 @@ void activate_timer(frontend *fe)
|
|||||||
void write_clip(HWND hwnd, char *data)
|
void write_clip(HWND hwnd, char *data)
|
||||||
{
|
{
|
||||||
HGLOBAL clipdata;
|
HGLOBAL clipdata;
|
||||||
int len = strlen(data);
|
int len, i, j;
|
||||||
|
char *data2;
|
||||||
void *lock;
|
void *lock;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Windows expects CRLF in the clipboard, so we must convert
|
||||||
|
* any \n that has come out of the puzzle backend.
|
||||||
|
*/
|
||||||
|
len = 0;
|
||||||
|
for (i = 0; data[i]; i++) {
|
||||||
|
if (data[i] == '\n')
|
||||||
|
len++;
|
||||||
|
len++;
|
||||||
|
}
|
||||||
|
data2 = snewn(len+1, char);
|
||||||
|
j = 0;
|
||||||
|
for (i = 0; data[i]; i++) {
|
||||||
|
if (data[i] == '\n')
|
||||||
|
data2[j++] = '\r';
|
||||||
|
data2[j++] = data[i];
|
||||||
|
}
|
||||||
|
assert(j == len);
|
||||||
|
data2[j] = '\0';
|
||||||
|
|
||||||
clipdata = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, len + 1);
|
clipdata = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, len + 1);
|
||||||
if (!clipdata)
|
if (!clipdata)
|
||||||
return;
|
return;
|
||||||
lock = GlobalLock(clipdata);
|
lock = GlobalLock(clipdata);
|
||||||
if (!lock)
|
if (!lock)
|
||||||
return;
|
return;
|
||||||
memcpy(lock, data, len);
|
memcpy(lock, data2, len);
|
||||||
((unsigned char *) lock)[len] = 0;
|
((unsigned char *) lock)[len] = 0;
|
||||||
GlobalUnlock(clipdata);
|
GlobalUnlock(clipdata);
|
||||||
|
|
||||||
@ -349,6 +370,8 @@ void write_clip(HWND hwnd, char *data)
|
|||||||
CloseClipboard();
|
CloseClipboard();
|
||||||
} else
|
} else
|
||||||
GlobalFree(clipdata);
|
GlobalFree(clipdata);
|
||||||
|
|
||||||
|
sfree(data2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -933,6 +956,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
|
|||||||
write_clip(hwnd, text);
|
write_clip(hwnd, text);
|
||||||
else
|
else
|
||||||
MessageBeep(MB_ICONWARNING);
|
MessageBeep(MB_ICONWARNING);
|
||||||
|
sfree(text);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case IDM_SOLVE:
|
case IDM_SOLVE:
|
||||||
|
Reference in New Issue
Block a user