From b1efdbe888efad86576a0adfae4800142433fae6 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 20 Jan 2010 16:05:09 +0000 Subject: [PATCH] 2010-01-20 16:57 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbwin/wapi_wingdi.c ! Guarded for ! HB_OS_WIN_CE. (mingwarm compiles it, but poccarm doesn't) Maybe to focus on important things, we should drop POCC support altogether? * contrib/hbwin/win_tprn.prg * WIN_DELETEDC() calls deleted. 'hDC := NIL' is enough. * contrib/hbwin/Makefile + contrib/hbwin/wapi_alloc.c * contrib/hbwin/win_prn1.c + Moved hbwapi_* low-level object handling functions to separate WAPI source. * WIN_DELETEDC() converted to compatibility stub, it will no longer release the handle. * contrib/hbwin/win_prn1.c * contrib/hbwin/win_prn2.c * contrib/hbwin/win_prn3.c * contrib/hbwin/win_dll.c % Deleted '#if defined( HB_OS_WIN )' guards. (we can readd them for extra safety, but in this case they should be readded consistently for all source files) % Deleted '! defined( __RSXNT__ )' guards RSXNT is not supported a dead compiler since long. % Deleted '! defined( __CYGWIN__ )' guards. It compiles with current Cygwin, if someone is interested in older versions, pls send build results. --- harbour/ChangeLog | 31 +++++ harbour/contrib/hbwin/Makefile | 1 + harbour/contrib/hbwin/wapi_alloc.c | 182 ++++++++++++++++++++++++++++ harbour/contrib/hbwin/wapi_wingdi.c | 4 + harbour/contrib/hbwin/win_dll.c | 2 +- harbour/contrib/hbwin/win_prn1.c | 133 +------------------- harbour/contrib/hbwin/win_prn2.c | 3 +- harbour/contrib/hbwin/win_prn3.c | 3 +- harbour/contrib/hbwin/win_tprn.prg | 2 - 9 files changed, 224 insertions(+), 137 deletions(-) create mode 100644 harbour/contrib/hbwin/wapi_alloc.c diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 09c4c17e6e..a2e9dc3658 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,37 @@ past entries belonging to author(s): Viktor Szakats. */ +2010-01-20 16:57 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) + * contrib/hbwin/wapi_wingdi.c + ! Guarded for ! HB_OS_WIN_CE. + (mingwarm compiles it, but poccarm doesn't) + Maybe to focus on important things, we should drop + POCC support altogether? + + * contrib/hbwin/win_tprn.prg + * WIN_DELETEDC() calls deleted. 'hDC := NIL' is enough. + + * contrib/hbwin/Makefile + + contrib/hbwin/wapi_alloc.c + * contrib/hbwin/win_prn1.c + + Moved hbwapi_* low-level object handling functions to + separate WAPI source. + * WIN_DELETEDC() converted to compatibility stub, it + will no longer release the handle. + + * contrib/hbwin/win_prn1.c + * contrib/hbwin/win_prn2.c + * contrib/hbwin/win_prn3.c + * contrib/hbwin/win_dll.c + % Deleted '#if defined( HB_OS_WIN )' guards. + (we can readd them for extra safety, but in this case + they should be readded consistently for all source files) + % Deleted '! defined( __RSXNT__ )' guards + RSXNT is not supported a dead compiler since long. + % Deleted '! defined( __CYGWIN__ )' guards. + It compiles with current Cygwin, if someone is interested + in older versions, pls send build results. + 2010-01-20 13:51 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbwin/Makefile + contrib/hbwin/wapi_wingdi.c diff --git a/harbour/contrib/hbwin/Makefile b/harbour/contrib/hbwin/Makefile index c6668efca1..e2155b7ef7 100644 --- a/harbour/contrib/hbwin/Makefile +++ b/harbour/contrib/hbwin/Makefile @@ -28,6 +28,7 @@ C_SOURCES := \ win_prn2.c \ win_prn3.c \ win_regc.c \ + wapi_alloc.c \ wapi_commctrl.c \ wapi_err.c \ wapi_shellapi.c \ diff --git a/harbour/contrib/hbwin/wapi_alloc.c b/harbour/contrib/hbwin/wapi_alloc.c new file mode 100644 index 0000000000..ff33eccf3b --- /dev/null +++ b/harbour/contrib/hbwin/wapi_alloc.c @@ -0,0 +1,182 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * Low-level Windows object handling functions + * + * Copyright 2008 Viktor Szakats (harbour.01 syenar.hu) + * 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. + * + */ + +#define HB_OS_WIN_USED + +#include "hbapi.h" +#include "hbwapi.h" + +static HB_GARBAGE_FUNC( s_gc_HDC_release ) +{ + void ** ph = ( void ** ) Cargo; + + /* Check if pointer is not NULL to avoid multiple freeing */ + if( ph && *ph ) + { + /* Destroy the object */ + DeleteDC( ( HDC ) *ph ); + + /* set pointer to NULL to avoid multiple freeing */ + *ph = NULL; + } +} + +static const HB_GC_FUNCS s_gc_HDC_funcs = +{ + s_gc_HDC_release, + hb_gcDummyMark +}; + +void hbwapi_ret_HDC( HDC p ) +{ + if( p ) + { + void ** ph = ( void ** ) hb_gcAllocate( sizeof( HDC * ), &s_gc_HDC_funcs ); + + *ph = p; + + hb_retptrGC( ph ); + } + else + hb_retptr( NULL ); +} + +HDC hbwapi_par_HDC( int iParam ) +{ + void ** ph = ( void ** ) hb_parptrGC( &s_gc_HDC_funcs, iParam ); + + return ph ? ( HDC ) * ph : ( HDC ) hb_parptr( iParam ); +} + +static HB_GARBAGE_FUNC( s_gc_HPEN_release ) +{ + void ** ph = ( void ** ) Cargo; + + /* Check if pointer is not NULL to avoid multiple freeing */ + if( ph && * ph ) + { + /* Destroy the object */ + DeleteObject( ( HPEN ) * ph ); + + /* set pointer to NULL to avoid multiple freeing */ + *ph = NULL; + } +} + +static const HB_GC_FUNCS s_gc_HPEN_funcs = +{ + s_gc_HPEN_release, + hb_gcDummyMark +}; + +void hbwapi_ret_HPEN( HPEN p ) +{ + if( p ) + { + void ** ph = ( void ** ) hb_gcAllocate( sizeof( HPEN * ), &s_gc_HPEN_funcs ); + + *ph = p; + + hb_retptrGC( ph ); + } + else + hb_retptr( NULL ); +} + +HPEN hbwapi_par_HPEN( int iParam ) +{ + void ** ph = ( void ** ) hb_parptrGC( &s_gc_HPEN_funcs, iParam ); + + return ph ? ( HPEN ) * ph : NULL; +} + +static HB_GARBAGE_FUNC( s_gc_HFONT_release ) +{ + void ** ph = ( void ** ) Cargo; + + /* Check if pointer is not NULL to avoid multiple freeing */ + if( ph && * ph ) + { + /* Destroy the object */ + DeleteObject( ( HFONT ) * ph ); + + /* set pointer to NULL to avoid multiple freeing */ + *ph = NULL; + } +} + +static const HB_GC_FUNCS s_gc_HFONT_funcs = +{ + s_gc_HFONT_release, + hb_gcDummyMark +}; + +void hbwapi_ret_HFONT( HFONT p ) +{ + if( p ) + { + void ** ph = ( void ** ) hb_gcAllocate( sizeof( HFONT * ), &s_gc_HFONT_funcs ); + + *ph = p; + + hb_retptrGC( ph ); + } + else + hb_retptr( NULL ); +} + +HFONT hbwapi_par_HFONT( int iParam ) +{ + void ** ph = ( void ** ) hb_parptrGC( &s_gc_HFONT_funcs, iParam ); + + return ph ? ( HFONT ) * ph : NULL; +} diff --git a/harbour/contrib/hbwin/wapi_wingdi.c b/harbour/contrib/hbwin/wapi_wingdi.c index 1b0486f9c7..0e50cd179a 100644 --- a/harbour/contrib/hbwin/wapi_wingdi.c +++ b/harbour/contrib/hbwin/wapi_wingdi.c @@ -94,6 +94,8 @@ DEVMODE * hbwapi_par_DEVMODE( DEVMODE * p, int iParam, HB_BOOL bMandatory ) return bMandatory ? p : NULL; } +#if ! defined( HB_OS_WIN_CE ) + HB_FUNC( WAPI_CREATEDC ) { void * hDriver; @@ -420,3 +422,5 @@ HB_FUNC( WAPI_GETTEXTFACE ) else hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); } + +#endif diff --git a/harbour/contrib/hbwin/win_dll.c b/harbour/contrib/hbwin/win_dll.c index 905203dc2b..ed7c1912ba 100644 --- a/harbour/contrib/hbwin/win_dll.c +++ b/harbour/contrib/hbwin/win_dll.c @@ -64,7 +64,7 @@ #include "hbapiitm.h" #include "hbwinuni.h" -#if defined( HB_OS_WIN ) && !defined( __CYGWIN__ ) && !defined( HB_NO_ASM ) +#if !defined( __CYGWIN__ ) && !defined( HB_NO_ASM ) /* ================================================================== * DynaCall support comments below diff --git a/harbour/contrib/hbwin/win_prn1.c b/harbour/contrib/hbwin/win_prn1.c index 9f7e199661..ebf8cd475c 100644 --- a/harbour/contrib/hbwin/win_prn1.c +++ b/harbour/contrib/hbwin/win_prn1.c @@ -74,138 +74,12 @@ #include "hbwapi.h" #include "hbwinuni.h" -#if defined( HB_OS_WIN ) && !defined( HB_OS_WIN_CE ) +#if ! defined( HB_OS_WIN_CE ) #ifndef INVALID_FILE_SIZE #define INVALID_FILE_SIZE ( DWORD ) 0xFFFFFFFF #endif -static HB_GARBAGE_FUNC( s_gc_HDC_release ) -{ - void ** ph = ( void ** ) Cargo; - - /* Check if pointer is not NULL to avoid multiple freeing */ - if( ph && *ph ) - { - /* Destroy the object */ - DeleteDC( ( HDC ) *ph ); - - /* set pointer to NULL to avoid multiple freeing */ - *ph = NULL; - } -} - -static const HB_GC_FUNCS s_gc_HDC_funcs = -{ - s_gc_HDC_release, - hb_gcDummyMark -}; - -void hbwapi_ret_HDC( HDC p ) -{ - if( p ) - { - void ** ph = ( void ** ) hb_gcAllocate( sizeof( HDC * ), &s_gc_HDC_funcs ); - - *ph = p; - - hb_retptrGC( ph ); - } - else - hb_retptr( NULL ); -} - -HDC hbwapi_par_HDC( int iParam ) -{ - void ** ph = ( void ** ) hb_parptrGC( &s_gc_HDC_funcs, iParam ); - - return ph ? ( HDC ) * ph : ( HDC ) hb_parptr( iParam ); -} - -static HB_GARBAGE_FUNC( s_gc_HPEN_release ) -{ - void ** ph = ( void ** ) Cargo; - - /* Check if pointer is not NULL to avoid multiple freeing */ - if( ph && * ph ) - { - /* Destroy the object */ - DeleteObject( ( HPEN ) * ph ); - - /* set pointer to NULL to avoid multiple freeing */ - *ph = NULL; - } -} - -static const HB_GC_FUNCS s_gc_HPEN_funcs = -{ - s_gc_HPEN_release, - hb_gcDummyMark -}; - -void hbwapi_ret_HPEN( HPEN p ) -{ - if( p ) - { - void ** ph = ( void ** ) hb_gcAllocate( sizeof( HPEN * ), &s_gc_HPEN_funcs ); - - *ph = p; - - hb_retptrGC( ph ); - } - else - hb_retptr( NULL ); -} - -HPEN hbwapi_par_HPEN( int iParam ) -{ - void ** ph = ( void ** ) hb_parptrGC( &s_gc_HPEN_funcs, iParam ); - - return ph ? ( HPEN ) * ph : NULL; -} - -static HB_GARBAGE_FUNC( s_gc_HFONT_release ) -{ - void ** ph = ( void ** ) Cargo; - - /* Check if pointer is not NULL to avoid multiple freeing */ - if( ph && * ph ) - { - /* Destroy the object */ - DeleteObject( ( HFONT ) * ph ); - - /* set pointer to NULL to avoid multiple freeing */ - *ph = NULL; - } -} - -static const HB_GC_FUNCS s_gc_HFONT_funcs = -{ - s_gc_HFONT_release, - hb_gcDummyMark -}; - -void hbwapi_ret_HFONT( HFONT p ) -{ - if( p ) - { - void ** ph = ( void ** ) hb_gcAllocate( sizeof( HFONT * ), &s_gc_HFONT_funcs ); - - *ph = p; - - hb_retptrGC( ph ); - } - else - hb_retptr( NULL ); -} - -HFONT hbwapi_par_HFONT( int iParam ) -{ - void ** ph = ( void ** ) hb_parptrGC( &s_gc_HFONT_funcs, iParam ); - - return ph ? ( HFONT ) * ph : NULL; -} - HB_FUNC( WIN_CREATEDC ) { if( HB_ISCHAR( 1 ) ) @@ -271,11 +145,10 @@ HB_FUNC( WIN_ABORTDOC ) hb_retl( hDC && ( AbortDoc( hDC ) > 0 ) ); } +/* Compatibility dummy */ HB_FUNC( WIN_DELETEDC ) { - s_gc_HDC_release( hb_parptrGC( &s_gc_HDC_funcs, 1 ) ); - - hb_retni( 0 ); /* Return zero as a new handle even if fails */ + hb_retni( 0 ); } HB_FUNC( WIN_STARTPAGE ) diff --git a/harbour/contrib/hbwin/win_prn2.c b/harbour/contrib/hbwin/win_prn2.c index f70ca2153b..5563d79d8b 100644 --- a/harbour/contrib/hbwin/win_prn2.c +++ b/harbour/contrib/hbwin/win_prn2.c @@ -58,8 +58,7 @@ #include "hbapiitm.h" #include "hbwinuni.h" -#if defined( HB_OS_WIN ) && \ - !( defined( __RSXNT__ ) || defined( __CYGWIN__ ) || defined( HB_OS_WIN_CE ) ) +#if ! defined( HB_OS_WIN_CE ) #define _ENUMPRN_FLAGS_ ( PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS ) diff --git a/harbour/contrib/hbwin/win_prn3.c b/harbour/contrib/hbwin/win_prn3.c index 737825716d..2bd35370d6 100644 --- a/harbour/contrib/hbwin/win_prn3.c +++ b/harbour/contrib/hbwin/win_prn3.c @@ -55,8 +55,7 @@ #include "hbapi.h" #include "hbwinuni.h" -#if defined( HB_OS_WIN ) && \ - !( defined( __RSXNT__ ) || defined( __CYGWIN__ ) || defined( HB_OS_WIN_CE ) ) +#if ! defined( HB_OS_WIN_CE ) /* NOTE: Based on hb_strncat() */ static TCHAR * hb_tstrncat( TCHAR * pDest, const TCHAR * pSource, HB_SIZE nLen ) diff --git a/harbour/contrib/hbwin/win_tprn.prg b/harbour/contrib/hbwin/win_tprn.prg index 7310dccf1f..c6ec384900 100644 --- a/harbour/contrib/hbwin/win_tprn.prg +++ b/harbour/contrib/hbwin/win_tprn.prg @@ -248,7 +248,6 @@ METHOD Create() CLASS WIN_PRN ENDIF IF !lResult - win_DeleteDC( ::hPrinterDC ) ::hPrinterDC := NIL ELSE // Set mapping mode to pixels, topleft down @@ -291,7 +290,6 @@ METHOD Destroy() CLASS WIN_PRN IF ::Printing ::EndDoc() ENDIF - win_DeleteDC( ::hPrinterDC ) ::hPrinterDC := NIL ENDIF RETURN .T.