From 486b9dad6e17f434590eaffb7fd18e1737dc2098 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 10 Dec 2009 15:11:48 +0000 Subject: [PATCH] 2009-12-10 16:10 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbqt/Makefile * contrib/hbqt/generator/hbqtgen.prg + Moved static source files from filelist.mk to Makefile. * contrib/hbqt/Makefile * contrib/hbqt/hbqt_slots.cpp + contrib/hbqt/hbqt_events.cpp + Moved event filter related stuff to separate file. % Cleaned lots of unnecessary QT headers includes. --- harbour/ChangeLog | 11 ++ harbour/contrib/hbqt/Makefile | 6 + harbour/contrib/hbqt/generator/hbqtgen.prg | 5 - harbour/contrib/hbqt/hbqt_events.cpp | 206 +++++++++++++++++++++ harbour/contrib/hbqt/hbqt_slots.cpp | 145 +-------------- 5 files changed, 224 insertions(+), 149 deletions(-) create mode 100644 harbour/contrib/hbqt/hbqt_events.cpp diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 65c976aafd..b64cc23df0 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,17 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-12-10 16:10 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) + * contrib/hbqt/Makefile + * contrib/hbqt/generator/hbqtgen.prg + + Moved static source files from filelist.mk to Makefile. + + * contrib/hbqt/Makefile + * contrib/hbqt/hbqt_slots.cpp + + contrib/hbqt/hbqt_events.cpp + + Moved event filter related stuff to separate file. + % Cleaned lots of unnecessary QT headers includes. + 2009-12-10 15:59 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbqt/hbqt_slots.cpp * contrib/hbxbp/xbpgeneric.prg diff --git a/harbour/contrib/hbqt/Makefile b/harbour/contrib/hbqt/Makefile index a6407b6181..00bf55d9a0 100644 --- a/harbour/contrib/hbqt/Makefile +++ b/harbour/contrib/hbqt/Makefile @@ -21,6 +21,12 @@ moc_slots.cpp : $(TOP)$(ROOT)contrib/hbqt/hbqt_slots.h include $(TOP)$(ROOT)contrib/hbqt/filelist.mk CPP_SOURCES += \ + moc_slots.cpp \ + hbqt_base.cpp \ + hbqt_utils.cpp \ + hbqt_slots.cpp \ + hbqt_destruct.cpp \ + hbqt_events.cpp \ hbqt_hbdbfmodel.cpp \ hbqt_hbdrawingarea.cpp \ hbqt_hbqmainwindow.cpp \ diff --git a/harbour/contrib/hbqt/generator/hbqtgen.prg b/harbour/contrib/hbqt/generator/hbqtgen.prg index 7a1cd5845b..8642704260 100644 --- a/harbour/contrib/hbqt/generator/hbqtgen.prg +++ b/harbour/contrib/hbqt/generator/hbqtgen.prg @@ -1661,11 +1661,6 @@ STATIC FUNCTION Build_MakeFile( cpp_, prg_, cPathOut ) aeval( hdr_, {|e| aadd( txt_, e ) } ) aadd( txt_, "CPP_SOURCES := \" ) // - aadd( txt_, " " + "moc_slots.cpp \" ) - aadd( txt_, " " + "hbqt_base.cpp \" ) - aadd( txt_, " " + "hbqt_utils.cpp \" ) - aadd( txt_, " " + "hbqt_slots.cpp \" ) - aadd( txt_, " " + "hbqt_destruct.cpp \" ) // We will strip lines below once subs proto is running #if 0 FOR EACH s IN cpp_ diff --git a/harbour/contrib/hbqt/hbqt_events.cpp b/harbour/contrib/hbqt/hbqt_events.cpp new file mode 100644 index 0000000000..e813b546b4 --- /dev/null +++ b/harbour/contrib/hbqt/hbqt_events.cpp @@ -0,0 +1,206 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * QT wrapper main header + * + * Copyright 2009 Marcos Antonio Gambeta + * + * Copyright 2009 Pritpal Bedi + * 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. + * + */ +/*----------------------------------------------------------------------*/ + +#include "hbapi.h" +#include "hbapiitm.h" +#include "hbstack.h" +#include "hbvm.h" + +#include "hbqt.h" + +#if QT_VERSION >= 0x040500 + +#include "hbqt_slots.h" + +/*----------------------------------------------------------------------*/ + +typedef struct +{ + Events * t_events; +} HB_EVENTS, * PHB_EVENTS; + +static HB_TSD_NEW( s_events, sizeof( HB_EVENTS ), NULL, NULL ); + +#define HB_GETQTEVENTFILTER() ( ( PHB_EVENTS ) hb_stackGetTSD( &s_events ) ) + +/*----------------------------------------------------------------------*/ + +static void qt_setEventFilter() +{ + if( ! HB_GETQTEVENTFILTER()->t_events ) + HB_GETQTEVENTFILTER()->t_events = new Events(); +} + +static Events * qt_getEventFilter( void ) +{ + return HB_GETQTEVENTFILTER()->t_events; +} + +HB_FUNC( QT_SETEVENTFILTER ) +{ + qt_setEventFilter(); +} + +HB_FUNC( QT_GETEVENTFILTER ) +{ + hb_retptr( qt_getEventFilter() ); +} + +/*----------------------------------------------------------------------*/ + +Events::Events( QObject * parent ) : QObject( parent ) +{ +} + +Events::~Events() +{ + listBlock.clear(); +} + +bool Events::eventFilter( QObject * object, QEvent * event ) +{ + QEvent::Type eventtype = event->type(); + + if( ( int ) eventtype == 0 ) + return false; + + char prop[ 10 ]; + hb_snprintf( prop, sizeof( prop ), "%s%i%s", "P", eventtype, "P" ); + + int found = object->property( prop ).toInt(); + + if( found == 0 ) + return false; + + bool ret = true; + + if( found <= listBlock.size() && listObj.at( found - 1 ) == object && hb_vmRequestReenter() ) + { + PHB_ITEM pObject = hb_itemPutPtr( NULL, object ); + PHB_ITEM pEvent = hb_itemPutPtr( NULL, event ); + ret = hb_itemGetL( hb_vmEvalBlockV( ( PHB_ITEM ) listBlock.at( found - 1 ), 2, pObject, pEvent ) ); + hb_itemRelease( pObject ); + hb_itemRelease( pEvent ); + + hb_vmRequestRestore(); + + if( eventtype == QEvent::Close ) + event->ignore(); + } + + return ret; +} + +HB_FUNC( QT_EVENTS_DESTROY ) +{ + qt_getEventFilter()->~Events(); +} + +HB_FUNC( QT_CONNECT_EVENT ) +{ + QObject * object = ( QObject* ) hbqt_gcpointer( 1 ); /* get sender */ + + if( object ) + { + int type = hb_parni( 2 ); + PHB_ITEM codeblock = hb_itemNew( hb_param( 3, HB_IT_BLOCK | HB_IT_BYREF ) ); + Events * t_events = qt_getEventFilter(); + + char prop[ 20 ]; + hb_snprintf( prop, sizeof( prop ), "%s%i%s", "P", type, "P" ); /* Make it a unique identifier */ + + t_events->listBlock << codeblock; + t_events->listObj << object; + + object->setProperty( prop, ( int ) t_events->listBlock.size() ); + + hb_retl( HB_TRUE ); + } + else + hb_retl( HB_FALSE ); +} + +HB_FUNC( QT_DISCONNECT_EVENT ) +{ + HB_BOOL bRet = HB_FALSE; + QObject * object = ( QObject* ) hbqt_gcpointer( 1 ); + + if( object ) + { + int type = hb_parni( 2 ); + Events * t_events = qt_getEventFilter(); + + char prop[ 20 ]; + hb_snprintf( prop, sizeof( prop ), "%s%i%s", "P", type, "P" ); /* Make it a unique identifier */ + + int i = object->property( prop ).toInt(); + if( i > 0 && i <= t_events->listBlock.size() ) + { + hb_itemRelease( t_events->listBlock.at( i - 1 ) ); + t_events->listBlock[ i - 1 ] = NULL; + t_events->listObj[ i - 1 ] = NULL; + object->setProperty( prop, QVariant() ); + bRet = HB_TRUE; + + HB_TRACE( HB_TR_DEBUG, ( " QT_DISCONNECT_EVENT: %i", type ) ); + } + } + + hb_retl( bRet ); +} + +/*----------------------------------------------------------------------*/ + +#endif diff --git a/harbour/contrib/hbqt/hbqt_slots.cpp b/harbour/contrib/hbqt/hbqt_slots.cpp index b468b115a4..ec27cd74d4 100644 --- a/harbour/contrib/hbqt/hbqt_slots.cpp +++ b/harbour/contrib/hbqt/hbqt_slots.cpp @@ -54,9 +54,9 @@ /*----------------------------------------------------------------------*/ #include "hbapi.h" -#include "hbvm.h" #include "hbapiitm.h" #include "hbstack.h" +#include "hbvm.h" #include "hbqt.h" @@ -64,27 +64,8 @@ #include "hbqt_slots.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - /*----------------------------------------------------------------------*/ -typedef struct -{ - Events * t_events; -} HB_EVENTS, * PHB_EVENTS; - -static HB_TSD_NEW( s_events, sizeof( HB_EVENTS ), NULL, NULL ); - -#define HB_GETQTEVENTFILTER() ( ( PHB_EVENTS ) hb_stackGetTSD( &s_events ) ) - typedef struct { Slots * t_slots; @@ -96,17 +77,6 @@ static HB_TSD_NEW( s_slots, sizeof( HB_SLOTS ), NULL, NULL ); /*----------------------------------------------------------------------*/ -static void qt_setEventFilter() -{ - if( ! HB_GETQTEVENTFILTER()->t_events ) - HB_GETQTEVENTFILTER()->t_events = new Events(); -} - -static Events * qt_getEventFilter( void ) -{ - return HB_GETQTEVENTFILTER()->t_events; -} - static void qt_setEventSlots() { if( ! HB_GETQTEVENTSLOTS()->t_slots ) @@ -118,16 +88,6 @@ static Slots * qt_getEventSlots( void ) return HB_GETQTEVENTSLOTS()->t_slots; } -HB_FUNC( QT_SETEVENTFILTER ) -{ - qt_setEventFilter(); -} - -HB_FUNC( QT_GETEVENTFILTER ) -{ - hb_retptr( qt_getEventFilter() ); -} - HB_FUNC( QT_SETEVENTSLOTS ) { qt_setEventSlots(); @@ -805,107 +765,4 @@ HB_FUNC( QT_SLOTS_DESTROY ) /*----------------------------------------------------------------------*/ -Events::Events( QObject * parent ) : QObject( parent ) -{ -} - -Events::~Events() -{ - listBlock.clear(); -} - -bool Events::eventFilter( QObject * object, QEvent * event ) -{ - QEvent::Type eventtype = event->type(); - - if( ( int ) eventtype == 0 ) - return false; - - char prop[ 10 ]; - hb_snprintf( prop, sizeof( prop ), "%s%i%s", "P", eventtype, "P" ); - - int found = object->property( prop ).toInt(); - - if( found == 0 ) - return false; - - bool ret = true; - - if( found <= listBlock.size() && listObj.at( found - 1 ) == object && hb_vmRequestReenter() ) - { - PHB_ITEM pObject = hb_itemPutPtr( NULL, object ); - PHB_ITEM pEvent = hb_itemPutPtr( NULL, event ); - ret = hb_itemGetL( hb_vmEvalBlockV( ( PHB_ITEM ) listBlock.at( found - 1 ), 2, pObject, pEvent ) ); - hb_itemRelease( pObject ); - hb_itemRelease( pEvent ); - - hb_vmRequestRestore(); - - if( eventtype == QEvent::Close ) - event->ignore(); - } - - return ret; -} - -HB_FUNC( QT_EVENTS_DESTROY ) -{ - qt_getEventFilter()->~Events(); -} - -HB_FUNC( QT_CONNECT_EVENT ) -{ - QObject * object = ( QObject* ) hbqt_gcpointer( 1 ); /* get sender */ - - if( object ) - { - int type = hb_parni( 2 ); - PHB_ITEM codeblock = hb_itemNew( hb_param( 3, HB_IT_BLOCK | HB_IT_BYREF ) ); - Events * t_events = qt_getEventFilter(); - - char prop[ 20 ]; - hb_snprintf( prop, sizeof( prop ), "%s%i%s", "P", type, "P" ); /* Make it a unique identifier */ - - t_events->listBlock << codeblock; - t_events->listObj << object; - - object->setProperty( prop, ( int ) t_events->listBlock.size() ); - - hb_retl( HB_TRUE ); - } - else - hb_retl( HB_FALSE ); -} - -HB_FUNC( QT_DISCONNECT_EVENT ) -{ - HB_BOOL bRet = HB_FALSE; - QObject * object = ( QObject* ) hbqt_gcpointer( 1 ); - - if( object ) - { - int type = hb_parni( 2 ); - Events * t_events = qt_getEventFilter(); - - char prop[ 20 ]; - hb_snprintf( prop, sizeof( prop ), "%s%i%s", "P", type, "P" ); /* Make it a unique identifier */ - - int i = object->property( prop ).toInt(); - if( i > 0 && i <= t_events->listBlock.size() ) - { - hb_itemRelease( t_events->listBlock.at( i - 1 ) ); - t_events->listBlock[ i - 1 ] = NULL; - t_events->listObj[ i - 1 ] = NULL; - object->setProperty( prop, QVariant() ); - bRet = HB_TRUE; - - HB_TRACE( HB_TR_DEBUG, ( " QT_DISCONNECT_EVENT: %i", type ) ); - } - } - - hb_retl( bRet ); -} - -/*----------------------------------------------------------------------*/ - #endif