[futurebasic] Re: [FB] Carbon event related to moving selected text in edit fields

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : December 2011 : Group Archive : Group : All Groups

From: Robert Purves <listrp@...>
Date: Fri, 30 Dec 2011 16:17:24 +1300
Domokos Vekas wrote:

> Furthermore, is it possible to prevent the user from dragging text to a different edit field?

Interestingly hard...
Here are three failed attempts. None prevents text from being dropped on edit field 2 in your demo.
Robert P.


[1]
toolbox fn SetControlDragTrackingEnabled( ControlRef inControl, Boolean inTracks ) = OSStatus

// no error, and no effect
err = fn SetControlDragTrackingEnabled( button&( 2 ), _false ) 


[2]
include "Tlbx HIView.incl"
_kControlSupportsDragAndDrop = 1 << 12

// paramErr (-50), and no effect
err = fn HIViewChangeFeatures( button&( 2 ), 0, _kControlSupportsDragAndDrop ) 


[3]
include "Tlbx ControlDefinitions.incl"

begin enum
_kEventParamControlWouldAcceptDrop = _"cldg"
end enum

local fn DragHandler( nextHandler as EventHandlerCallRef, theEvent as EventRef, userData as pointer )
'~'1
dim as OSStatus     result : result = _eventNotHandledErr
dim as Boolean      bool

select switch fn GetEventKind( theEvent )
case _kEventControlDragEnter
bool = _false // _true allows kEventControlDragReceive to occur
fn SetEventParameter( theEvent, _kEventParamControlWouldAcceptDrop, _typeBoolean, sizeof( bool ), @bool )
result = _noErr
case _kEventControlDragReceive
result = _noErr
end select
end fn = result

fn SetAutomaticControlDragTrackingEnabledForWindow( w, _true ) // needed for kEventControlDragXxxx
fn CEAddEvent( _kEventClassControl, _kEventControlDragEnter )
fn CEAddEvent( _kEventClassControl, _kEventControlDragReceive )
fn CEInstallControlEventHandler( button&( 2 ), @fn DragHandler, 0, 0 )