diff --git a/harbour/ChangeLog b/harbour/ChangeLog index f7f65081eb..5dbb820b62 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,37 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-12-10 22:46 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) + * contrib/hbqt/hbqt_events.cpp + * contrib/hbqt/hbqt_slots.cpp + ! Fixed events/slots handling to make sure the objects + always exist on access. + % This also made explicit initialization from .prg + code unnecessary, so these two functions got deleted: + QT_SETEVENTFILTER(), QT_SETEVENTSLOTS() + ! Fixed events/slots handling to reset thread local object + pointer to NULL after destruction. + + * contrib/hbxbp/xbpsle.prg + * contrib/hbxbp/xbplistbox.prg + * contrib/hbxbp/xbpwindow.prg + * contrib/hbxbp/xbptreeview.prg + * contrib/hbxbp/xbpdialog.prg + * contrib/hbxbp/xbpspinbutton.prg + * contrib/hbxbp/xbpgeneric.prg + % Simple wrapper named HBXBP_SETEVENTFILTER() deleted and + replaced with QT_GETEVENTFILTER() calls. + (name still subject to change) + + ; NOTE: 1) In demoxbp MT mode build, the second dialog behaves + strangely. It updates the screen slowly and not at all. + Pritpal, please check it to make sure not some + recent change broke it. + 2) Forgot to mention in prev entry, but removing + HBQMainWindow() mutex altogether didn't cause any + change/loss of functionality in my tests, so my + question is: Is it really needed? + 2009-12-10 22:22 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbqt/hbqt_hbqmainwindow.cpp * contrib/hbxbp/xbpgeneric.prg diff --git a/harbour/contrib/hbqt/hbqt_events.cpp b/harbour/contrib/hbqt/hbqt_events.cpp index 677cd17637..195c9be8ee 100644 --- a/harbour/contrib/hbqt/hbqt_events.cpp +++ b/harbour/contrib/hbqt/hbqt_events.cpp @@ -75,24 +75,18 @@ typedef struct static HB_TSD_NEW( s_events, sizeof( HB_EVENTS ), NULL, NULL ); -#define HB_GETQTEVENTFILTER() ( ( PHB_EVENTS ) hb_stackGetTSD( &s_events ) ) +#define HB_QTTHREAD_EVENTS() ( ( 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; -} + PHB_EVENTS p_events = HB_QTTHREAD_EVENTS(); -HB_FUNC( QT_SETEVENTFILTER ) -{ - qt_setEventFilter(); + if( ! p_events->t_events ) + p_events->t_events = new Events(); + + return p_events->t_events; } HB_FUNC( QT_GETEVENTFILTER ) @@ -100,6 +94,17 @@ HB_FUNC( QT_GETEVENTFILTER ) hb_retptr( qt_getEventFilter() ); } +HB_FUNC( QT_EVENTS_DESTROY ) +{ + PHB_EVENTS p_events = HB_QTTHREAD_EVENTS(); + + if( p_events->t_events ) + { + p_events->t_events->~Events(); + p_events->t_events = NULL; + } +} + /*----------------------------------------------------------------------*/ Events::Events( QObject * parent ) : QObject( parent ) @@ -145,11 +150,6 @@ bool Events::eventFilter( QObject * object, QEvent * event ) return ret; } -HB_FUNC( QT_EVENTS_DESTROY ) -{ - qt_getEventFilter()->~Events(); -} - HB_FUNC( QT_CONNECT_EVENT ) { QObject * object = ( QObject* ) hbqt_gcpointer( 1 ); /* get sender */ diff --git a/harbour/contrib/hbqt/hbqt_slots.cpp b/harbour/contrib/hbqt/hbqt_slots.cpp index ec27cd74d4..cd726a789d 100644 --- a/harbour/contrib/hbqt/hbqt_slots.cpp +++ b/harbour/contrib/hbqt/hbqt_slots.cpp @@ -73,24 +73,29 @@ typedef struct static HB_TSD_NEW( s_slots, sizeof( HB_SLOTS ), NULL, NULL ); -#define HB_GETQTEVENTSLOTS() ( ( PHB_SLOTS ) hb_stackGetTSD( &s_slots ) ) +#define HB_QTTHREAD_SLOTS() ( ( PHB_SLOTS ) hb_stackGetTSD( &s_slots ) ) /*----------------------------------------------------------------------*/ -static void qt_setEventSlots() -{ - if( ! HB_GETQTEVENTSLOTS()->t_slots ) - HB_GETQTEVENTSLOTS()->t_slots = new Slots(); -} - static Slots * qt_getEventSlots( void ) { - return HB_GETQTEVENTSLOTS()->t_slots; + PHB_SLOTS p_slots = HB_QTTHREAD_SLOTS(); + + if( ! p_slots->t_slots ) + p_slots->t_slots = new Slots(); + + return p_slots->t_slots; } -HB_FUNC( QT_SETEVENTSLOTS ) +HB_FUNC( QT_SLOTS_DESTROY ) { - qt_setEventSlots(); + PHB_SLOTS p_slots = HB_QTTHREAD_SLOTS(); + + if( p_slots->t_slots ) + { + p_slots->t_slots->~Slots(); + p_slots->t_slots = NULL; + } } /*----------------------------------------------------------------------*/ @@ -502,7 +507,6 @@ HB_FUNC( QT_CONNECT_SIGNAL ) PHB_ITEM codeblock = hb_itemNew( hb_param( 3, HB_IT_BLOCK ) ); /* get codeblock */ bool ret; - qt_setEventSlots(); Slots * t_slots = qt_getEventSlots(); if( signal == ( QString ) "clicked()" ) ret = object->connect( object, SIGNAL( clicked() ) , t_slots, SLOT( clicked() ) , Qt::AutoConnection ); @@ -758,11 +762,6 @@ HB_FUNC( QT_DISCONNECT_SIGNAL ) hb_retl( bFreed ); } -HB_FUNC( QT_SLOTS_DESTROY ) -{ - qt_getEventSlots()->~Slots(); -} - /*----------------------------------------------------------------------*/ #endif diff --git a/harbour/contrib/hbxbp/xbpdialog.prg b/harbour/contrib/hbxbp/xbpdialog.prg index 9c1c49c47a..a986d9662c 100644 --- a/harbour/contrib/hbxbp/xbpdialog.prg +++ b/harbour/contrib/hbxbp/xbpdialog.prg @@ -148,10 +148,6 @@ METHOD XbpDialog:create( oParent, oOwner, aPos, aSize, aPresParams, lVisible ) SetAppWindow( Self ) - /* Initialize Qt's event stacks */ - QT_SetEventSlots() - QT_SetEventFilter() - /* Thread specific event buffer */ hbxbp_InitializeEventBuffer() @@ -160,7 +156,7 @@ METHOD XbpDialog:create( oParent, oOwner, aPos, aSize, aPresParams, lVisible ) hbxbp_SetEventLoop( ::oEventLoop ) /* Instal Event Filter */ - ::oWidget:installEventFilter( hbxbp_SetEventFilter() ) + ::oWidget:installEventFilter( QT_GetEventFilter() ) ::connectWindowEvents() // diff --git a/harbour/contrib/hbxbp/xbpgeneric.prg b/harbour/contrib/hbxbp/xbpgeneric.prg index d37c6284ed..87abafda00 100644 --- a/harbour/contrib/hbxbp/xbpgeneric.prg +++ b/harbour/contrib/hbxbp/xbpgeneric.prg @@ -146,12 +146,6 @@ FUNCTION hbxbp_ClearEventBuffer() /*----------------------------------------------------------------------*/ -FUNCTION hbxbp_SetEventFilter() - - RETURN QT_GetEventFilter() - -/*----------------------------------------------------------------------*/ - FUNCTION hbxbp_SetEventLoop( oELoop ) t_oEventLoop := oELoop diff --git a/harbour/contrib/hbxbp/xbplistbox.prg b/harbour/contrib/hbxbp/xbplistbox.prg index 5dd1d0ec7f..74f2dc284c 100644 --- a/harbour/contrib/hbxbp/xbplistbox.prg +++ b/harbour/contrib/hbxbp/xbplistbox.prg @@ -178,7 +178,7 @@ METHOD XbpListBox:create( oParent, oOwner, aPos, aSize, aPresParams, lVisible ) ::oWidget:setMouseTracking( .t. ) /* Window Events */ - ::oWidget:installEventFilter( hbxbp_SetEventFilter() ) + ::oWidget:installEventFilter( QT_GetEventFilter() ) ::connectEvent( ::pWidget, QEvent_ContextMenu, {|o,e| ::grabEvent( QEvent_ContextMenu, e, o ) } ) /* Signal-slots */ diff --git a/harbour/contrib/hbxbp/xbpsle.prg b/harbour/contrib/hbxbp/xbpsle.prg index ce2bd58b07..53d566b444 100644 --- a/harbour/contrib/hbxbp/xbpsle.prg +++ b/harbour/contrib/hbxbp/xbpsle.prg @@ -146,7 +146,7 @@ METHOD XbpSLE:create( oParent, oOwner, aPos, aSize, aPresParams, lVisible ) ::oWidget:setMaxLength( ::bufferLength ) #if 0 - QT_QObject_InstallEventFilter( ::pWidget, hbxbp_SetEventFilter() ) + QT_QObject_InstallEventFilter( ::pWidget, QT_GetEventFilter() ) ::connectEvent( ::pWidget, QEvent_FocusIn , {|o,e| ::exeBlock( 7, e, o ) } ) ::connectEvent( ::pWidget, QEvent_FocusOut, {|o,e| ::exeBlock( 8, e, o ) } ) diff --git a/harbour/contrib/hbxbp/xbpspinbutton.prg b/harbour/contrib/hbxbp/xbpspinbutton.prg index a5a4c69127..a97060c3a1 100644 --- a/harbour/contrib/hbxbp/xbpspinbutton.prg +++ b/harbour/contrib/hbxbp/xbpspinbutton.prg @@ -154,7 +154,7 @@ METHOD XbpSpinButton:create( oParent, oOwner, aPos, aSize, aPresParams, lVisible ::oWidget:setAlignment( es_[ ::align ] ) #if 0 //////////////////////////////////// - QT_QObject_InstallEventFilter( ::pWidget, hbxbp_SetEventFilter() ) + QT_QObject_InstallEventFilter( ::pWidget, QT_GetEventFilter() ) HBXBP_DEBUG( "XbpSpinButton:create 2" ) ::connectEvent( ::pWidget, QEvent_FocusIn , {|o,e| ::exeBlock( 7, e, o ) } ) ::connectEvent( ::pWidget, QEvent_FocusOut, {|o,e| ::exeBlock( 8, e, o ) } ) diff --git a/harbour/contrib/hbxbp/xbptreeview.prg b/harbour/contrib/hbxbp/xbptreeview.prg index 72bf08e3b1..802204004a 100644 --- a/harbour/contrib/hbxbp/xbptreeview.prg +++ b/harbour/contrib/hbxbp/xbptreeview.prg @@ -168,7 +168,7 @@ METHOD XbpTreeView:create( oParent, oOwner, aPos, aSize, aPresParams, lVisible ) ::oRootItem:oWidget := oW /* Window Events */ - ::oWidget:installEventFilter( hbxbp_SetEventFilter() ) + ::oWidget:installEventFilter( QT_GetEventFilter() ) ::connectEvent( ::pWidget, QEvent_ContextMenu, {|o,e| ::grabEvent( QEvent_ContextMenu, e, o ) } ) //::connect( ::pWidget, "currentItemChanged(QTWItem)" , {|o,p1,p2| ::exeBlock( 1, p1, p2, o ) } ) diff --git a/harbour/contrib/hbxbp/xbpwindow.prg b/harbour/contrib/hbxbp/xbpwindow.prg index 2b6019d6ed..c2137e472f 100644 --- a/harbour/contrib/hbxbp/xbpwindow.prg +++ b/harbour/contrib/hbxbp/xbpwindow.prg @@ -414,7 +414,7 @@ METHOD XbpWindow:connectEvent( pWidget, nEvent, bBlock ) METHOD XbpWindow:connectWindowEvents() - //::oWidget:installEventFilter( hbxbp_SetEventFilter() ) + //::oWidget:installEventFilter( QT_GetEventFilter() ) ::connectEvent( ::pWidget, QEvent_MouseMove , {|o,e| ::grabEvent( QEvent_MouseMove , e, o ) } ) ::connectEvent( ::pWidget, QEvent_MouseButtonPress , {|o,e| ::grabEvent( QEvent_MouseButtonPress , e, o ) } ) @@ -752,7 +752,7 @@ METHOD XbpWindow:destroy() aeval( ::aEConnections, {|e_,i| Qt_DisConnect_Event( e_[ 1 ], e_[ 2 ] ), ; ::aEConnections[ i,1 ] := NIL, ::aEConnections[ i,2 ] := NIL, ::aEConnections[ i ] := NIL } ) ::aEConnections := {} - ::oWidget:removeEventFilter( hbxbp_SetEventFilter() ) + ::oWidget:removeEventFilter( QT_GetEventFilter() ) ENDIF IF Len( ::aChildren ) > 0