Commit 9935bf7b authored by mathieu _alkama_ m's avatar mathieu _alkama_ m Committed by Gargaj
Browse files

Make the clipboard on windows great again (#124)

Fixes crashes on clipboard handling.
Also dont paste when there's nothing to paste.
parent edcc7916
......@@ -193,6 +193,8 @@ void ShaderEditor::Copy()
void ShaderEditor::Paste()
{
int n = Clipboard::GetContentsLength();
if (n == 0) return;
char * p = new char[n + 1];
memset(p,0,n+1);
Clipboard::GetContents( p, n );
......
......@@ -8,16 +8,27 @@ namespace Clipboard
if ( !::OpenClipboard( hWnd ) )
return;
EmptyClipboard();
HGLOBAL hData = GlobalAlloc( GMEM_MOVEABLE, ( len + 1 ) * sizeof( char ) );
if ( !hData ) {
CloseClipboard();
return;
}
HGLOBAL h = GlobalAlloc( GMEM_MOVEABLE, ( len + 1 ) * sizeof( char ) );
WCHAR * pMem = (WCHAR*) GlobalLock( h );
WCHAR * pMem = (WCHAR*) GlobalLock( hData );
if ( !pMem ) {
GlobalFree( hData );
CloseClipboard();
return;
}
ZeroMemory( pMem, ( len + 1 ) * sizeof( char ) );
CopyMemory( pMem, data, ( len + 1 ) * sizeof( char ) );
GlobalUnlock( h );
SetClipboardData( CF_TEXT, h );
GlobalUnlock( hData );
EmptyClipboard();
SetClipboardData( CF_TEXT, hData );
CloseClipboard();
}
......@@ -29,9 +40,21 @@ namespace Clipboard
return 0;
HANDLE hData = GetClipboardData( CF_TEXT );
if ( !hData ) {
CloseClipboard();
return 0;
}
const char * buffer = (const char*) GlobalLock( hData );
if ( !buffer ) {
CloseClipboard();
return 0;
}
int n = strlen( buffer );
GlobalUnlock( hData );
CloseClipboard();
return n;
......@@ -44,9 +67,21 @@ namespace Clipboard
return;
HANDLE hData = GetClipboardData( CF_TEXT );
if ( !hData ) {
CloseClipboard();
return;
}
const char * buffer = (const char*) GlobalLock( hData );
if ( !buffer ) {
CloseClipboard();
return;
}
strncpy( data, buffer, len );
GlobalUnlock( hData );
CloseClipboard();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment