From caf97287758599f951cde078a4374f8901ebbe57 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Thu, 22 Jun 2006 14:55:19 +0000 Subject: [PATCH] 2006-06-22 16:35 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/source/rtl/Makefile + harbour/source/rtl/gtclip.c + harbour/source/rtl/gttone.c * harbour/include/hbgtcore.h * separated low level TONE and ClipBoard code for W32 new functions: hb_gt_w32_Tone() hb_gt_w32_SetClipboard() hb_gt_w32_GetClipboard() Please update non GNU make files * harbour/source/rtl/gtwin/gtwin.c * harbour/source/rtl/gtwvt/gtwvt.c * use hb_gt_w32_*() for common GT code * harbour/config/w32/global.cf + harbour/source/rtl/gtgui/Makefile + harbour/source/rtl/gtgui/gtgui.c + added GTGUI GT driver - it inherits from GTNUL and add support for TONE and CLIPBOARD --- harbour/ChangeLog | 22 +++ harbour/config/w32/global.cf | 1 + harbour/include/hbgtcore.h | 12 ++ harbour/source/rtl/Makefile | 2 + harbour/source/rtl/gtclip.c | 117 +++++++++++++ harbour/source/rtl/gtgui/Makefile | 12 ++ harbour/source/rtl/gtgui/gtgui.c | 157 +++++++++++++++++ harbour/source/rtl/gttone.c | 273 ++++++++++++++++++++++++++++++ harbour/source/rtl/gtwin/gtwin.c | 251 +-------------------------- harbour/source/rtl/gtwvt/gtwvt.c | 261 +--------------------------- 10 files changed, 606 insertions(+), 502 deletions(-) create mode 100644 harbour/source/rtl/gtclip.c create mode 100644 harbour/source/rtl/gtgui/Makefile create mode 100644 harbour/source/rtl/gtgui/gtgui.c create mode 100644 harbour/source/rtl/gttone.c diff --git a/harbour/ChangeLog b/harbour/ChangeLog index cb90fbf1c4..3a05f95d64 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,28 @@ 2002-12-01 13:30 UTC+0100 Foo Bar */ + +2006-06-22 17:28 UTC+0100 Viktor Szakats (viktor.szakats syenar.hu) + * harbour/makefile.bc + * Updated for latest changes. + +2006-06-22 16:35 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/source/rtl/Makefile + + harbour/source/rtl/gtclip.c + + harbour/source/rtl/gttone.c + * harbour/include/hbgtcore.h + * separated low level TONE and ClipBoard code for W32 + new functions: + hb_gt_w32_Tone() + hb_gt_w32_SetClipboard() + hb_gt_w32_GetClipboard() + Please update non GNU make files + + * harbour/source/rtl/gtwin/gtwin.c + * harbour/source/rtl/gtwvt/gtwvt.c + * use hb_gt_w32_*() for common GT code + + * harbour/config/w32/global.cf + harbour/source/rtl/gtgui/Makefile + harbour/source/rtl/gtgui/gtgui.c + added GTGUI GT driver - it inherits from GTNUL and add support diff --git a/harbour/config/w32/global.cf b/harbour/config/w32/global.cf index 5147e74d46..6df385f9fd 100644 --- a/harbour/config/w32/global.cf +++ b/harbour/config/w32/global.cf @@ -10,6 +10,7 @@ HB_GT_LIBS=\ gtstd \ gtwin \ gtwvt \ + gtgui \ # gtcrs \ # gtsln \ diff --git a/harbour/include/hbgtcore.h b/harbour/include/hbgtcore.h index f9aa3ec88e..92436d57dc 100644 --- a/harbour/include/hbgtcore.h +++ b/harbour/include/hbgtcore.h @@ -80,6 +80,7 @@ #define HB_GT_QTc HB_GT_QTC #define HB_GT_xvt HB_GT_XVT #define HB_GT_xwc HB_GT_XWC +#define HB_GT_gui HB_GT_GUI #define HB_GT_alleg HB_GT_ALLEG /* These hacks are needed to force preprocessing if id/x is also a macro */ @@ -474,6 +475,8 @@ extern void hb_gt_WhoCares( void * pCargo ); #define HB_GTSUPER_REDRAW(r,c,l) (HB_GTSUPER)->Redraw(r,c,l) #define HB_GTSUPER_REFRESH() (HB_GTSUPER)->Refresh() #define HB_GTSUPER_FLUSH() (HB_GTSUPER)->Flush() +#define HB_GTSUPER_TONE(f,d) (HB_GTSUPER)->Tone(f,d) +#define HB_GTSUPER_BELL() (HB_GTSUPER)->Bell() #define HB_GTSUPER_SETDISPCP(t,h,b) (HB_GTSUPER)->SetDispCP(t,h,b) #define HB_GTSUPER_SETKEYCP(t,h) (HB_GTSUPER)->SetKeyCP(t,h) #define HB_GTSUPER_INFO(i,p) (HB_GTSUPER)->Info(i,p) @@ -511,4 +514,13 @@ extern HB_EXPORT BOOL hb_gtLoad( char * szGtName, PHB_GT_FUNCS pFuncTable ); extern HB_EXPORT BOOL hb_gtUnLoad( void ); extern HB_EXPORT void hb_gtStartupInit( void ); + +/* low level GT functions common to different GTs supported by RTL */ +#if defined( HB_OS_WIN_32 ) +void hb_gt_w32_Tone( double dFrequency, double dDuration ); +void hb_gt_w32_SetClipboard( UINT uFormat, char * szClipData, ULONG ulLen ); +BOOL hb_gt_w32_GetClipboard( UINT uFormat, char ** pszClipData, ULONG *pulLen ); +#endif /* HB_OS_WIN_32 */ + + #endif /* HB_GTCORE_H_ */ diff --git a/harbour/source/rtl/Makefile b/harbour/source/rtl/Makefile index f34ab48d99..75fea26f23 100644 --- a/harbour/source/rtl/Makefile +++ b/harbour/source/rtl/Makefile @@ -42,7 +42,9 @@ C_SOURCES=\ gete.c \ gt.c \ gtapi.c \ + gtclip.c \ gtsys.c \ + gttone.c \ gtfunc.c \ gx.c \ hardcr.c \ diff --git a/harbour/source/rtl/gtclip.c b/harbour/source/rtl/gtclip.c new file mode 100644 index 0000000000..c91844a2fe --- /dev/null +++ b/harbour/source/rtl/gtclip.c @@ -0,0 +1,117 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * Low level ClipBoard code common to some GT drivers + * + * Copyright 2006 Przemyslaw Czerpak + * www - http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + + +/* NOTE: User programs should never call this layer directly! */ + +#define HB_OS_WIN_32_USED +#include "hbgtcore.h" + +#if defined( HB_OS_WIN_32 ) + +void hb_gt_w32_SetClipboard( UINT uFormat, char * szClipData, ULONG ulLen ) +{ + LPTSTR lptstrCopy; + HGLOBAL hglbCopy; + + 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(); + } +} + +BOOL hb_gt_w32_GetClipboard( UINT uFormat, char ** pszClipData, ULONG *pulLen ) +{ + HGLOBAL hglb; + LPTSTR lptstr; + + *pulLen = 0; + *pszClipData = NULL; + if( IsClipboardFormatAvailable( uFormat ) && OpenClipboard( NULL ) ) + { + hglb = GetClipboardData( uFormat ); + if( hglb ) + { + lptstr = ( LPSTR ) GlobalLock( hglb ); + if( lptstr != NULL ) + { + *pulLen = GlobalSize( hglb ); + + if( *pulLen ) + { + *pszClipData = ( char * ) hb_xgrab( *pulLen + 1 ); + memcpy( *pszClipData, lptstr, *pulLen + 1 ); + } + GlobalUnlock( hglb ); + } + } + CloseClipboard(); + } + + return *pulLen != 0; +} + +#endif /* HB_OS_WIN_32 */ diff --git a/harbour/source/rtl/gtgui/Makefile b/harbour/source/rtl/gtgui/Makefile new file mode 100644 index 0000000000..08aa82e124 --- /dev/null +++ b/harbour/source/rtl/gtgui/Makefile @@ -0,0 +1,12 @@ +# +# $Id$ +# + +ROOT = ../../../ + +C_SOURCES=\ + gtgui.c \ + +LIBNAME=gtgui + +include $(TOP)$(ROOT)config/lib.cf diff --git a/harbour/source/rtl/gtgui/gtgui.c b/harbour/source/rtl/gtgui/gtgui.c new file mode 100644 index 0000000000..35553b1040 --- /dev/null +++ b/harbour/source/rtl/gtgui/gtgui.c @@ -0,0 +1,157 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * Mini GT for GUI programs. + * Now it supports only low level TONE and CLIPBOARD code for W32 + * + * Copyright 2006 Przemyslaw Czerpak + * www - http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + + +/* NOTE: User programs should never call this layer directly! */ + +#define HB_GT_NAME GUI + +#define HB_OS_WIN_32_USED + +#include "hbgtcore.h" +#include "hbinit.h" +#include "hbapiitm.h" + +/* *********************************************************************** */ + +static HB_GT_FUNCS SuperTable; +#define HB_GTSUPER (&SuperTable) + +/* *********************************************************************** */ +/* dDuration is in 'Ticks' (18.2 per second) */ +static void hb_gt_gui_Tone( double dFrequency, double dDuration ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_gt_gui_Tone(%lf, %lf)", dFrequency, dDuration)); + +#if defined( HB_OS_WIN_32 ) + hb_gt_w32_Tone( dFrequency, dDuration ); +#else + HB_GTSUPER_TONE( dFrequency, dDuration ); +#endif +} + +/* *********************************************************************** */ + +static BOOL hb_gt_gui_Info( int iType, PHB_GT_INFO pInfo ) +{ + HB_TRACE( HB_TR_DEBUG, ( "hb_gt_gui_Info(%d,%p)", iType, pInfo ) ); + + switch( iType ) + { +#if defined( HB_OS_WIN_32 ) + case GTI_CLIPBOARDDATA: + if( hb_itemType( pInfo->pNewVal ) & HB_IT_STRING ) + { + hb_gt_w32_SetClipboard( CF_TEXT, hb_itemGetCPtr( pInfo->pNewVal ), + hb_itemGetCLen( pInfo->pNewVal ) ); + } + else + { + char * szClipboardData; + ULONG ulLen; + + if( hb_gt_w32_GetClipboard( CF_TEXT, &szClipboardData, &ulLen ) ) + { + pInfo->pResult = hb_itemPutCPtr( pInfo->pResult, + szClipboardData, ulLen ); + } + else + { + pInfo->pResult = hb_itemPutC( pInfo->pResult, "" ); + } + } + break; +#endif + default: + return HB_GTSUPER_INFO( iType, pInfo ); + } + + return TRUE; +} + +/* *********************************************************************** */ + +static BOOL hb_gt_FuncInit( PHB_GT_FUNCS pFuncTable ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_gt_FuncInit(%p)", pFuncTable)); + + pFuncTable->Tone = hb_gt_gui_Tone; + pFuncTable->Info = hb_gt_gui_Info; + + return TRUE; +} + +/* ********************************************************************** */ + +static HB_GT_INIT gtInit = { HB_GT_DRVNAME( HB_GT_NAME ), + hb_gt_FuncInit, + HB_GTSUPER }; + +HB_GT_ANNOUNCE( HB_GT_NAME ) + +HB_CALL_ON_STARTUP_BEGIN( _hb_startup_gt_Init_ ) + hb_gtRegister( >Init ); +HB_CALL_ON_STARTUP_END( _hb_startup_gt_Init_ ) + +#if defined( HB_PRAGMA_STARTUP ) + #pragma startup _hb_startup_gt_Init_ +#elif defined(HB_MSC_STARTUP) + #if _MSC_VER >= 1010 + #pragma data_seg( ".CRT$XIY" ) + #pragma comment( linker, "/Merge:.CRT=.data" ) + #else + #pragma data_seg( "XIY" ) + #endif + static HB_$INITSYM hb_vm_auto__hb_startup_gt_Init_ = _hb_startup_gt_Init_; + #pragma data_seg() +#endif diff --git a/harbour/source/rtl/gttone.c b/harbour/source/rtl/gttone.c new file mode 100644 index 0000000000..c033ac314d --- /dev/null +++ b/harbour/source/rtl/gttone.c @@ -0,0 +1,273 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * Low level tone code common to some GT drivers + * + * Copyright 2006 Przemyslaw Czerpak + * www - http://www.harbour-project.org + * + * the body of TONE function from W32 taken from GTWIN created by + * the following authors: + * Copyright 1999 David G. Holm + * Copyright 1999-2006 Paul Tucker + * Copyright 2005 Andi Jahja + * Copyright 2005 Przemyslaw Czerpak + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + + +/* NOTE: User programs should never call this layer directly! */ + + +#define HB_OS_WIN_32_USED +#include "hbgtcore.h" + +#if defined( HB_OS_WIN_32 ) + +#if defined( HB_ARCH_32BIT ) && \ + ( defined(__BORLANDC__) || defined(_MSC_VER) || \ + defined(__WATCOMC__) || defined(__MINGW32__) ) +static int hb_Inp9x( USHORT usPort ) +{ + USHORT usVal; + + HB_TRACE(HB_TR_DEBUG, ("hb_Inp9x(%hu)", usPort)); + + #if defined( __BORLANDC__ ) || defined(__DMC__) + + _DX = usPort; + __emit__(0xEC); /* ASM IN AL, DX */ + __emit__(0x32,0xE4); /* ASM XOR AH, AH */ + usVal = _AX; + + #elif defined( __XCC__ ) + + __asm { + mov dx, usPort + xor ax, ax + in al, dx + mov usVal, ax + } + + #elif defined( __MINGW32__ ) + __asm__ __volatile__ ("inb %w1,%b0":"=a" (usVal):"Nd" (usPort)); + + #elif defined( __WATCOMC__ ) + + usVal = inp( usPort ); + + #else + + usVal = _inp( usPort ); + + #endif + + return usVal; +} + +/* *********************************************************************** */ + +static int hb_Outp9x( USHORT usPort, USHORT usVal ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_Outp9x(%hu, %hu)", usPort, usVal)); + + #if defined( __BORLANDC__ ) || defined(__DMC__) + + _DX = usPort; + _AL = usVal; + __emit__(0xEE); /* ASM OUT DX, AL */ + + #elif defined( __XCC__ ) + + __asm { + mov dx, usPort + mov ax, usVal + out dx, al + } + + #elif defined( __MINGW32__ ) + + __asm__ __volatile__ ("outb %b0,%w1": :"a" (usVal), "Nd" (usPort)); + + #elif defined( __WATCOMC__ ) + + outp( usPort, usVal ); + + #else + + _outp( usPort, usVal ); + + #endif + + return usVal; +} + +/* *********************************************************************** */ +/* dDurat is in seconds */ +static void hb_gt_w9xTone( double dFreq, double dDurat ) +{ + INT uLSB,uMSB; + ULONG lAdjFreq; + + HB_TRACE(HB_TR_DEBUG, ("hb_gt_w9xtone(%lf, %lf)", dFreq, dDurat)); + + /* sync with internal clock with very small time period */ + hb_idleSleep( 0.01 ); + + /* Clipper ignores Tone() requests (but delays anyway) if Frequency is + less than < 20 hz (and so should we) to maintain compatibility .. */ + + if( dFreq >= 20.0 ) + { + /* Setup Sound Control Port Registers and timer channel 2 */ + hb_Outp9x(67, 182) ; + + lAdjFreq = (ULONG)( 1193180 / dFreq ) ; + + if( (LONG) lAdjFreq < 0 ) + uLSB = lAdjFreq + 65536; + else + uLSB = lAdjFreq % 256; + + if( (LONG) lAdjFreq < 0 ) + uMSB = lAdjFreq + 65536; + else + uMSB = lAdjFreq / 256; + + + /* set the frequency (LSB,MSB) */ + + hb_Outp9x(66, uLSB); + hb_Outp9x(66, uMSB); + + /* Get current Port setting */ + /* enable Speaker Data & Timer gate bits */ + /* (00000011B is bitmask to enable sound) */ + /* Turn on Speaker - sound Tone for duration.. */ + + hb_Outp9x(97, hb_Inp9x( 97 ) | 3); + + hb_idleSleep( dDurat ); + + /* Read back current Port value for Reset */ + /* disable Speaker Data & Timer gate bits */ + /* (11111100B is bitmask to disable sound) */ + /* Turn off the Speaker ! */ + + hb_Outp9x(97, hb_Inp9x( 97 ) & 0xFC); + } + else + { + hb_idleSleep( dDurat ); + } +} +#endif + +/* *********************************************************************** */ +/* dDurat is in seconds */ +static void hb_gt_wNtTone( double dFreq, double dDurat ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_gt_wNtTone(%lf, %lf)", dFreq, dDurat)); + + /* Clipper ignores Tone() requests (but delays anyway) if Frequency is + less than < 20 hz. Windows NT minimum is 37... */ + + if( dFreq >= 37.0 ) + { + Beep( (ULONG) dFreq, (ULONG) ( dDurat * 1000 ) ); /* Beep wants Milliseconds */ + } + else + { + hb_idleSleep( dDurat ); + } +} + +/* *********************************************************************** */ +/* dDuration is in 'Ticks' (18.2 per second) */ +void hb_gt_w32_Tone( double dFrequency, double dDuration ) +{ + static OSVERSIONINFO s_osv; + static BOOL s_fInit = TRUE; + + HB_TRACE(HB_TR_DEBUG, ("hb_gt_w32_Tone(%lf, %lf)", dFrequency, dDuration)); + + if( s_fInit ) + { + s_osv.dwOSVersionInfoSize = sizeof( OSVERSIONINFO ); + GetVersionEx( &s_osv ); + s_fInit = FALSE; + } + + /* + * According to the Clipper NG, the duration in 'ticks' is truncated to the + * interger portion ... Depending on the platform, Harbour allows a finer + * resolution, but the minimum is 1 tick (for compatibility) + */ + /* Convert from ticks to seconds */ + dDuration = ( HB_MIN( HB_MAX( 1.0, dDuration ), ULONG_MAX ) ) / 18.2; + + /* keep the frequency in an acceptable range */ + dFrequency = HB_MIN( HB_MAX( 0.0, dFrequency ), 32767.0 ); + + /* If Windows 95 or 98, use w9xTone for BCC32, MSVC */ + if( s_osv.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS ) + { + #if defined( HB_ARCH_32BIT ) && \ + ( defined( __BORLANDC__ ) || defined( _MSC_VER ) || \ + defined( __WATCOMC__ ) || defined(__MINGW32__) ) + hb_gt_w9xTone( dFrequency, dDuration ); + #else + hb_gt_wNtTone( dFrequency, dDuration ); + #endif + } + /* If Windows NT or NT2k, use wNtTone, which provides TONE() + reset sequence support (new) */ + else /* if( s_osv.dwPlatformId == VER_PLATFORM_WIN32_NT ) */ + { + hb_gt_wNtTone( dFrequency, dDuration ); + } +} + +#endif /* HB_OS_WIN_32 */ diff --git a/harbour/source/rtl/gtwin/gtwin.c b/harbour/source/rtl/gtwin/gtwin.c index 8255bd7072..e991f2aee5 100644 --- a/harbour/source/rtl/gtwin/gtwin.c +++ b/harbour/source/rtl/gtwin/gtwin.c @@ -630,7 +630,6 @@ static void hb_gt_win_Init( FHANDLE hFilenoStdin, FHANDLE hFilenoStdout, FHANDLE { HB_TRACE(HB_TR_DEBUG, ("hb_gt_win_Init(%p,%p,%p)", hFilenoStdin, hFilenoStdout, hFilenoStderr)); - /* If Windows 95 or 98, use w9xTone for BCC32, MSVC */ s_osv.dwOSVersionInfoSize = sizeof( OSVERSIONINFO ); GetVersionEx( &s_osv ); if( s_osv.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS ) @@ -1475,199 +1474,13 @@ static int hb_gt_win_ReadKey( int iEventMask ) /* *********************************************************************** */ -#if defined( HB_ARCH_32BIT ) && \ - ( defined(__BORLANDC__) || defined(_MSC_VER) || \ - defined(__WATCOMC__) || defined(__MINGW32__) ) -static int hb_Inp9x( USHORT usPort ) -{ - USHORT usVal; - - HB_TRACE(HB_TR_DEBUG, ("hb_Inp9x(%hu)", usPort)); - - #if defined( __BORLANDC__ ) || defined(__DMC__) - - _DX = usPort; - __emit__(0xEC); /* ASM IN AL, DX */ - __emit__(0x32,0xE4); /* ASM XOR AH, AH */ - usVal = _AX; - - #elif defined( __XCC__ ) - - __asm { - mov dx, usPort - xor ax, ax - in al, dx - mov usVal, ax - } - - #elif defined( __MINGW32__ ) - __asm__ __volatile__ ("inb %w1,%b0":"=a" (usVal):"Nd" (usPort)); - - #elif defined( __WATCOMC__ ) - - usVal = inp( usPort ); - - #else - - usVal = _inp( usPort ); - - #endif - - return usVal; -} - -/* *********************************************************************** */ - -static int hb_Outp9x( USHORT usPort, USHORT usVal ) -{ - HB_TRACE(HB_TR_DEBUG, ("hb_Outp9x(%hu, %hu)", usPort, usVal)); - - #if defined( __BORLANDC__ ) || defined(__DMC__) - - _DX = usPort; - _AL = usVal; - __emit__(0xEE); /* ASM OUT DX, AL */ - - #elif defined( __XCC__ ) - - __asm { - mov dx, usPort - mov ax, usVal - out dx, al - } - - #elif defined( __MINGW32__ ) - - __asm__ __volatile__ ("outb %b0,%w1": :"a" (usVal), "Nd" (usPort)); - - #elif defined( __WATCOMC__ ) - - outp( usPort, usVal ); - - #else - - _outp( usPort, usVal ); - - #endif - - return usVal; -} - -/* *********************************************************************** */ -/* dDurat is in seconds */ -static void hb_gt_win_w9xTone( double dFreq, double dDurat ) -{ - INT uLSB,uMSB; - ULONG lAdjFreq; - - HB_TRACE(HB_TR_DEBUG, ("hb_gt_win_w9xtone(%lf, %lf)", dFreq, dDurat)); - - /* sync with internal clock with very small time period */ - hb_idleSleep( 0.01 ); - - /* Clipper ignores Tone() requests (but delays anyway) if Frequency is - less than < 20 hz (and so should we) to maintain compatibility .. */ - - if( dFreq >= 20.0 ) - { - /* Setup Sound Control Port Registers and timer channel 2 */ - hb_Outp9x(67, 182) ; - - lAdjFreq = (ULONG)( 1193180 / dFreq ) ; - - if( (LONG) lAdjFreq < 0 ) - uLSB = lAdjFreq + 65536; - else - uLSB = lAdjFreq % 256; - - if( (LONG) lAdjFreq < 0 ) - uMSB = lAdjFreq + 65536; - else - uMSB = lAdjFreq / 256; - - - /* set the frequency (LSB,MSB) */ - - hb_Outp9x(66, uLSB); - hb_Outp9x(66, uMSB); - - /* Get current Port setting */ - /* enable Speaker Data & Timer gate bits */ - /* (00000011B is bitmask to enable sound) */ - /* Turn on Speaker - sound Tone for duration.. */ - - hb_Outp9x(97, hb_Inp9x( 97 ) | 3); - - hb_idleSleep( dDurat ); - - /* Read back current Port value for Reset */ - /* disable Speaker Data & Timer gate bits */ - /* (11111100B is bitmask to disable sound) */ - /* Turn off the Speaker ! */ - - hb_Outp9x(97, hb_Inp9x( 97 ) & 0xFC); - - } - else - { - hb_idleSleep( dDurat ); - } -} -#endif - -/* *********************************************************************** */ -/* dDurat is in seconds */ -static void hb_gt_win_wNtTone( double dFreq, double dDurat ) -{ - HB_TRACE(HB_TR_DEBUG, ("hb_gt_win_wNtTone(%lf, %lf)", dFreq, dDurat)); - - /* Clipper ignores Tone() requests (but delays anyway) if Frequency is - less than < 20 hz. Windows NT minimum is 37... */ - - if( dFreq >= 37.0 ) - { - Beep( (ULONG) dFreq, (ULONG) ( dDurat * 1000 ) ); /* Beep wants Milliseconds */ - } - else - { - hb_idleSleep( dDurat ); - } -} - /* *********************************************************************** */ /* dDuration is in 'Ticks' (18.2 per second) */ static void hb_gt_win_Tone( double dFrequency, double dDuration ) { HB_TRACE(HB_TR_DEBUG, ("hb_gt_win_Tone(%lf, %lf)", dFrequency, dDuration)); - /* - * According to the Clipper NG, the duration in 'ticks' is truncated to the - * interger portion ... Depending on the platform, Harbour allows a finer - * resolution, but the minimum is 1 tick (for compatibility) - */ - /* Convert from ticks to seconds */ - dDuration = ( HB_MIN( HB_MAX( 1.0, dDuration ), ULONG_MAX ) ) / 18.2; - - /* keep the frequency in an acceptable range */ - dFrequency = HB_MIN( HB_MAX( 0.0, dFrequency ), 32767.0 ); - - /* If Windows 95 or 98, use w9xTone for BCC32, MSVC */ - if( s_osv.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS ) - { - #if defined( HB_ARCH_32BIT ) && \ - ( defined( __BORLANDC__ ) || defined( _MSC_VER ) || \ - defined( __WATCOMC__ ) || defined(__MINGW32__) ) - hb_gt_win_w9xTone( dFrequency, dDuration ); - #else - hb_gt_win_wNtTone( dFrequency, dDuration ); - #endif - } - /* If Windows NT or NT2k, use wNtTone, which provides TONE() - reset sequence support (new) */ - else /* if( s_osv.dwPlatformId == VER_PLATFORM_WIN32_NT ) */ - { - hb_gt_win_wNtTone( dFrequency, dDuration ); - } + hb_gt_w32_Tone( dFrequency, dDuration ); } /* *********************************************************************** */ @@ -1771,64 +1584,6 @@ static int kbdShiftsState( void ) return kbdShifts; } -static void hb_gt_win_SetClipboard( char * szClipData, ULONG ulLen ) -{ - LPTSTR lptstrCopy; - HGLOBAL hglbCopy; - UINT uFormat = CF_OEMTEXT; - - 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 = CF_OEMTEXT; - - *pulLen = 0; - *pszClipData = NULL; - if ( IsClipboardFormatAvailable( uFormat ) && OpenClipboard( NULL ) ) - { - hglb = GetClipboardData( uFormat ); - if ( hglb ) - { - lptstr = ( LPSTR ) GlobalLock( hglb ); - if ( lptstr != NULL ) - { - *pulLen = GlobalSize( hglb ); - - 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 ) @@ -1889,14 +1644,14 @@ static BOOL hb_gt_win_Info( int iType, PHB_GT_INFO pInfo ) case GTI_CLIPBOARDDATA: if( hb_itemType( pInfo->pNewVal ) & HB_IT_STRING ) { - hb_gt_win_SetClipboard( hb_itemGetCPtr( pInfo->pNewVal ), + hb_gt_w32_SetClipboard( CF_OEMTEXT, hb_itemGetCPtr( pInfo->pNewVal ), hb_itemGetCLen( pInfo->pNewVal ) ); } else { char * szClipboardData; ULONG ulLen; - if( hb_gt_win_GetClipboard( &szClipboardData, &ulLen ) ) + if( hb_gt_w32_GetClipboard( CF_OEMTEXT, &szClipboardData, &ulLen ) ) { pInfo->pResult = hb_itemPutCPtr( pInfo->pResult, szClipboardData, diff --git a/harbour/source/rtl/gtwvt/gtwvt.c b/harbour/source/rtl/gtwvt/gtwvt.c index 82664b052c..36b65bd0ff 100644 --- a/harbour/source/rtl/gtwvt/gtwvt.c +++ b/harbour/source/rtl/gtwvt/gtwvt.c @@ -1186,64 +1186,6 @@ static DWORD hb_gt_wvt_ProcessMessages( void ) return msg.wParam; } -static void hb_gt_wvt_SetClipboard( char * szClipData, ULONG ulLen ) -{ - LPTSTR lptstrCopy; - HGLOBAL hglbCopy; - UINT uFormat = ( _s.CodePage == OEM_CHARSET ) ? CF_OEMTEXT : CF_TEXT; - - 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_wvt_GetClipboard( char ** pszClipData, ULONG *pulLen ) -{ - HGLOBAL hglb; - LPTSTR lptstr; - UINT uFormat = ( _s.CodePage == OEM_CHARSET ) ? CF_OEMTEXT : CF_TEXT; - - *pulLen = 0; - *pszClipData = NULL; - if ( IsClipboardFormatAvailable( uFormat ) && OpenClipboard( NULL ) ) - { - hglb = GetClipboardData( uFormat ); - if ( hglb ) - { - lptstr = ( LPSTR ) GlobalLock( hglb ); - if ( lptstr != NULL ) - { - *pulLen = GlobalSize( hglb ); - - if( *pulLen ) - { - *pszClipData = ( char * ) hb_xgrab( *pulLen + 1 ); - memcpy( *pszClipData, lptstr, *pulLen + 1 ); - } - GlobalUnlock( hglb ); - } - } - CloseClipboard(); - } - - return *pulLen != 0; -} - static BOOL hb_gt_wvt_ValidWindowSize( int rows, int cols, HFONT hFont, int iWidth ) { HDC hdc; @@ -1350,7 +1292,6 @@ static void hb_gt_wvt_Init( FHANDLE hFilenoStdin, FHANDLE hFilenoStdout, FHANDLE hb_errInternal( 10001, "It's not a window GUI program.", "", "" ); } - /* If Windows 95 or 98, use w9xTone for BCC32, MSVC */ s_osv.dwOSVersionInfoSize = sizeof( OSVERSIONINFO ); GetVersionEx( &s_osv ); @@ -1461,205 +1402,13 @@ static int hb_gt_wvt_ReadKey( int iEventMask ) return fKey ? c : 0; } -/* *********************************************************************** */ - -/* - * Tone code copied from gtwin - */ - -#if defined( HB_ARCH_32BIT ) && \ - ( defined(__BORLANDC__) || defined(_MSC_VER) || \ - defined(__WATCOMC__) || defined(__MINGW32__) ) -static int hb_Inp9x( USHORT usPort ) -{ - USHORT usVal; - - HB_TRACE(HB_TR_DEBUG, ("hb_Inp9x(%hu)", usPort)); - - #if defined( __BORLANDC__ ) || defined(__DMC__) - - _DX = usPort; - __emit__(0xEC); /* ASM IN AL, DX */ - __emit__(0x32,0xE4); /* ASM XOR AH, AH */ - usVal = _AX; - - #elif defined( __XCC__ ) - - __asm { - mov dx, usPort - xor ax, ax - in al, dx - mov usVal, ax - } - - #elif defined( __MINGW32__ ) - __asm__ __volatile__ ("inb %w1,%b0":"=a" (usVal):"Nd" (usPort)); - - #elif defined( __WATCOMC__ ) - - usVal = inp( usPort ); - - #else - - usVal = _inp( usPort ); - - #endif - - return usVal; -} - -/* *********************************************************************** */ - -static int hb_Outp9x( USHORT usPort, USHORT usVal ) -{ - HB_TRACE(HB_TR_DEBUG, ("hb_Outp9x(%hu, %hu)", usPort, usVal)); - - #if defined( __BORLANDC__ ) || defined(__DMC__) - - _DX = usPort; - _AL = usVal; - __emit__(0xEE); /* ASM OUT DX, AL */ - - #elif defined( __XCC__ ) - - __asm { - mov dx, usPort - mov ax, usVal - out dx, al - } - - #elif defined( __MINGW32__ ) - - __asm__ __volatile__ ("outb %b0,%w1": :"a" (usVal), "Nd" (usPort)); - - #elif defined( __WATCOMC__ ) - - outp( usPort, usVal ); - - #else - - _outp( usPort, usVal ); - - #endif - - return usVal; -} - -/* *********************************************************************** */ -/* dDurat is in seconds */ -static void hb_gt_wvt_w9xTone( double dFreq, double dDurat ) -{ - INT uLSB,uMSB; - ULONG lAdjFreq; - - HB_TRACE(HB_TR_DEBUG, ("hb_gt_wvt_w9xtone(%lf, %lf)", dFreq, dDurat)); - - /* sync with internal clock with very small time period */ - hb_idleSleep( 0.01 ); - - /* Clipper ignores Tone() requests (but delays anyway) if Frequency is - less than < 20 hz (and so should we) to maintain compatibility .. */ - - if( dFreq >= 20.0 ) - { - /* Setup Sound Control Port Registers and timer channel 2 */ - hb_Outp9x(67, 182) ; - - lAdjFreq = (ULONG)( 1193180 / dFreq ) ; - - if( (LONG) lAdjFreq < 0 ) - uLSB = lAdjFreq + 65536; - else - uLSB = lAdjFreq % 256; - - if( (LONG) lAdjFreq < 0 ) - uMSB = lAdjFreq + 65536; - else - uMSB = lAdjFreq / 256; - - - /* set the frequency (LSB,MSB) */ - - hb_Outp9x(66, uLSB); - hb_Outp9x(66, uMSB); - - /* Get current Port setting */ - /* enable Speaker Data & Timer gate bits */ - /* (00000011B is bitmask to enable sound) */ - /* Turn on Speaker - sound Tone for duration.. */ - - hb_Outp9x(97, hb_Inp9x( 97 ) | 3); - - hb_idleSleep( dDurat ); - - /* Read back current Port value for Reset */ - /* disable Speaker Data & Timer gate bits */ - /* (11111100B is bitmask to disable sound) */ - /* Turn off the Speaker ! */ - - hb_Outp9x(97, hb_Inp9x( 97 ) & 0xFC); - - } - else - { - hb_idleSleep( dDurat ); - } -} -#endif - -/* *********************************************************************** */ -/* dDurat is in seconds */ -static void hb_gt_wvt_wNtTone( double dFreq, double dDurat ) -{ - HB_TRACE(HB_TR_DEBUG, ("hb_gt_wvt_wNtTone(%lf, %lf)", dFreq, dDurat)); - - /* Clipper ignores Tone() requests (but delays anyway) if Frequency is - less than < 20 hz. Windows NT minimum is 37... */ - - if( dFreq >= 37.0 ) - { - Beep( (ULONG) dFreq, (ULONG) ( dDurat * 1000 ) ); /* Beep wants Milliseconds */ - } - else - { - hb_idleSleep( dDurat ); - } -} - /* *********************************************************************** */ /* dDuration is in 'Ticks' (18.2 per second) */ static void hb_gt_wvt_Tone( double dFrequency, double dDuration ) { HB_TRACE(HB_TR_DEBUG, ("hb_gt_wvt_Tone(%lf, %lf)", dFrequency, dDuration)); - /* - * According to the Clipper NG, the duration in 'ticks' is truncated to the - * interger portion ... Depending on the platform, Harbour allows a finer - * resolution, but the minimum is 1 tick (for compatibility) - */ - /* Convert from ticks to seconds */ - dDuration = ( HB_MIN( HB_MAX( 1.0, dDuration ), ULONG_MAX ) ) / 18.2; - - /* keep the frequency in an acceptable range */ - dFrequency = HB_MIN( HB_MAX( 0.0, dFrequency ), 32767.0 ); - - /* If Windows 95 or 98, use w9xTone for BCC32, MSVC */ - if( _s.Win9X ) - { - #if defined( HB_ARCH_32BIT ) && \ - ( defined( __BORLANDC__ ) || defined( _MSC_VER ) || \ - defined( __WATCOMC__ ) || defined(__MINGW32__) ) - hb_gt_wvt_w9xTone( dFrequency, dDuration ); - #else - hb_gt_wvt_wNtTone( dFrequency, dDuration ); - #endif - } - /* If Windows NT or NT2k, use wNtTone, which provides TONE() - reset sequence support (new) */ - else /* if( s_osv.dwPlatformId == VER_PLATFORM_WIN32_NT ) */ - { - hb_gt_wvt_wNtTone( dFrequency, dDuration ); - } + hb_gt_w32_Tone( dFrequency, dDuration ); } @@ -1978,14 +1727,18 @@ static BOOL hb_gt_wvt_Info( int iType, PHB_GT_INFO pInfo ) case GTI_CLIPBOARDDATA: if( hb_itemType( pInfo->pNewVal ) & HB_IT_STRING ) { - hb_gt_wvt_SetClipboard( hb_itemGetCPtr( pInfo->pNewVal ), + hb_gt_w32_SetClipboard( _s.CodePage == OEM_CHARSET ? + CF_OEMTEXT : CF_TEXT, + hb_itemGetCPtr( pInfo->pNewVal ), hb_itemGetCLen( pInfo->pNewVal ) ); } else { char * szClipboardData; ULONG ulLen; - if( hb_gt_wvt_GetClipboard( &szClipboardData, &ulLen ) ) + if( hb_gt_w32_GetClipboard( _s.CodePage == OEM_CHARSET ? + CF_OEMTEXT : CF_TEXT, + &szClipboardData, &ulLen ) ) { pInfo->pResult = hb_itemPutCPtr( pInfo->pResult, szClipboardData,