From 8414073d1c2ca7c04bb417ce57fbc00a5feb6f2b Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 20 Jun 2006 06:58:41 +0000 Subject: [PATCH] 2006-06-20 08:55 UTC+0100 Viktor Szakats (viktor.szakats syenar.hu) * harbour/source/rtl/gtwin/gtwin.c + Copied Windows Clipboard support from the GTWVT driver. So now it is available in Win32 console apps too. (Thanks Przemek for the functions and instructions). Set/Get the Clipboard using: hb_GTInfo( GTI_CLIPBOARDDATA[, ] ) --- harbour/ChangeLog | 7 +++ harbour/source/rtl/gtwin/gtwin.c | 81 ++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index eea5cab62e..189a14277c 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,13 @@ 2002-12-01 13:30 UTC+0100 Foo Bar */ + after updating local HVM functions. + +2006-06-20 11:33 UTC+0100 Viktor Szakats (viktor.szakats syenar.hu) + * harbour/source/rtl/gtwin/gtwin.c + ! Possible (double) fix to properly handle embedded zero bytes + +2006-06-20 09:45 UTC+0100 Viktor Szakats (viktor.szakats syenar.hu) * harbour/source/rtl/gtwin/gtwin.c * harbour/source/rtl/gtwxt/gtwxt.c + Copied Windows Clipboard support from the GTWVT driver. So now diff --git a/harbour/source/rtl/gtwin/gtwin.c b/harbour/source/rtl/gtwin/gtwin.c index 9e9190dc48..8abddb7c5e 100644 --- a/harbour/source/rtl/gtwin/gtwin.c +++ b/harbour/source/rtl/gtwin/gtwin.c @@ -1753,6 +1753,64 @@ static int kbdShiftsState( void ) return kbdShifts; } +static void hb_gt_win_SetClipboard( char * szClipData, ULONG ulLen ) +{ + LPTSTR lptstrCopy; + HGLOBAL hglbCopy; + UINT uFormat = OEM_CHARSET; + + if ( OpenClipboard( NULL ) ) + { + EmptyClipboard(); + + /* Allocate a global memory object for the text. */ + hglbCopy = GlobalAlloc( GMEM_MOVEABLE, ulLen + 1 ); + if ( hglbCopy ) + { + /* Lock the handle and copy the text to the buffer. */ + lptstrCopy = ( LPSTR ) GlobalLock( hglbCopy ); + memcpy( lptstrCopy, szClipData, ulLen ); + lptstrCopy[ ulLen ] = 0; + GlobalUnlock( hglbCopy ); + /* Place the handle on the clipboard. */ + SetClipboardData( uFormat, hglbCopy ); + } + CloseClipboard(); + } +} + +static BOOL hb_gt_win_GetClipboard( char ** pszClipData, ULONG *pulLen ) +{ + HGLOBAL hglb; + LPTSTR lptstr; + UINT uFormat = OEM_CHARSET; + + *pulLen = 0; + *pszClipData = NULL; + if ( IsClipboardFormatAvailable( uFormat ) && OpenClipboard( NULL ) ) + { + hglb = GetClipboardData( uFormat ); + if ( hglb ) + { + lptstr = ( LPSTR ) GlobalLock( hglb ); + if ( lptstr != NULL ) + { + *pulLen = strlen( lptstr ); + + if( *pulLen ) + { + *pszClipData = ( char * ) hb_xgrab( *pulLen + 1 ); + memcpy( *pszClipData, lptstr, *pulLen + 1 ); + } + GlobalUnlock( hglb ); + } + } + CloseClipboard(); + } + + return *pulLen != 0; +} + /* *********************************************************************** */ static BOOL hb_gt_win_Info( int iType, PHB_GT_INFO pInfo ) @@ -1810,6 +1868,29 @@ static BOOL hb_gt_win_Info( int iType, PHB_GT_INFO pInfo ) s_bAltKeyHandling = hb_itemGetL( pInfo->pNewVal ); break; + case GTI_CLIPBOARDDATA: + if( hb_itemType( pInfo->pNewVal ) & HB_IT_STRING ) + { + hb_gt_win_SetClipboard( hb_itemGetCPtr( pInfo->pNewVal ), + hb_itemGetCLen( pInfo->pNewVal ) ); + } + else + { + char * szClipboardData; + ULONG ulLen; + if( hb_gt_win_GetClipboard( &szClipboardData, &ulLen ) ) + { + pInfo->pResult = hb_itemPutCPtr( pInfo->pResult, + szClipboardData, + strlen( szClipboardData ) ); + } + else + { + pInfo->pResult = hb_itemPutC( pInfo->pResult, "" ); + } + } + break; + default: return HB_GTSUPER_INFO( iType, pInfo ); }