commit 694303b3fd17bf2fbf4def1cd5bff624d5090e02
parent 672f56fe661af07cb429142d22f227bc26cd8524
Author: Michael Savage <mikejsavage@gmail.com>
Date: Sat, 8 Sep 2018 17:42:53 +0300
Copying on Windows
Diffstat:
3 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/src/platform_ui.h b/src/platform_ui.h
@@ -8,3 +8,5 @@ void platform_ui_term();
void platform_fill_rect( int left, int top, int width, int height, Colour colour, bool bold );
void platform_draw_char( int left, int top, char c, Colour colour, bool bold, bool force_bold_font );
void platform_make_dirty( int left, int top, int width, int height );
+
+void platform_set_clipboard( const char * str, size_t len );
diff --git a/src/textbox.cc b/src/textbox.cc
@@ -3,6 +3,8 @@
#include "common.h"
#include "textbox.h"
#include "ui.h"
+#include "platform.h"
+#include "platform_ui.h"
#if PLATFORM_WINDOWS
#define NEWLINE_STRING "\r\n"
@@ -244,7 +246,7 @@ void textbox_mouse_up( TextBox * tb, int window_x, int window_y ) {
}
}
- printf( "%s\n", selected );
+ platform_set_clipboard( selected, selected_length );
free( selected );
tb->selecting = false;
diff --git a/src/win32.cc b/src/win32.cc
@@ -220,6 +220,28 @@ bool ui_set_font( const char * name, int size ) {
return true;
}
+void platform_set_clipboard( const char * str, size_t len ) {
+ if( OpenClipboard( UI.hwnd ) == FALSE )
+ return;
+
+ HGLOBAL mem = GlobalAlloc( GMEM_MOVEABLE, len );
+ if( mem == NULL ) {
+ CloseClipboard();
+ return;
+ }
+
+ void * p = GlobalLock( mem );
+ if( p == NULL )
+ FATAL( "GlobalLock" );
+
+ memcpy( p, str, len );
+ GlobalUnlock( mem );
+
+ EmptyClipboard();
+ SetClipboardData( CF_TEXT, mem );
+ CloseClipboard();
+}
+
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ) {
switch( msg ) {
case WM_CREATE: {