Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] Capturing Drop events over browser widget

Hello,
 
I'm trying to capture the drop (FileTransfer) event in a browser widget. I tried hooking a DropTarget( ) to the *.swt.browser widget with no success. Then I tried to go the Ole way and create a Shell.Explorer site automation and try to hook the DropTarget( ) to both the OleFrame and OleControlSite with no success. (yeah, I'm kind of hacking it)
 
I have the feeling that I need to enable something in the Ole control and use some sort of OleListener.. but I can't find clear documentation of how get deep down in the API and capture drag/drop events.
 
Have anyone done anything in this area?
 
Any input would be appreciated. Below is a short program  demostrating what I'm trying to do. Step D is the one I'm having trouble with, getting the Drop listener to work.
 
Thank you,
-Edwin

 
 
import org.eclipse.swt.*;
import
org.eclipse.swt.ole.win32.*;
import
org.eclipse.swt.internal.ole.win32.*;
import
org.eclipse.swt.widgets.*;
import
org.eclipse.swt.events.*;
import org.eclipse.swt.dnd.*;

public class test
{
public static void main(String[] args)
{
 //a. Create Shell
Display display = new
Display();
Shell shell = new
Shell( display );
shell.setSize( 610, 400 );

//b. Create Browser (the old way)
OleFrame frame = new
OleFrame( shell, SWT.NONE );
OleControlSite site = new OleControlSite( frame, SWT.NONE, "Shell.Explorer"
);
site.doVerb( OLE.OLEIVERB_INPLACEACTIVATE );
OleAutomation browser = new
OleAutomation( site );


//c. Disable "link navigation" and go to google
int[] nameIds = browser.getIDsOfNames(new String[] { "RegisterAsDropTarget"} );
//is this really necessary (I wonder)?
browser.setProperty(nameIds[0], new Variant(false
) ); //true or false --doesn't work

nameIds = browser.getIDsOfNames( new String[] { "Navigate", "URL"
} );
browser.invoke( nameIds[0], new Variant[] { new Variant("http://www.google.com"
) },
new int
[] { nameIds[1] } );


//d. Listen to drop events ???
DropTarget target = new
DropTarget(frame, DND.DROP_COPY ); // <--help here!!!
target.setTransfer( new
Transfer[] { FileTransfer.getInstance() } );
target.addDropListener( new
DropTargetListener()
{
        public void dragEnter(DropTargetEvent event) { System.out.println("drag enter"
); }
        public void dragLeave(DropTargetEvent event) { System.out.println("drag leave"
);}
        public void dragOver(DropTargetEvent event) { System.out.println("drag over"
);}
        public void dragOperationChanged(DropTargetEvent event) { System.out.println("drag changed"
);}
        public void dropAccept(DropTargetEvent event) { System.out.println("drag accept"
);}
        public void
drop(DropTargetEvent event)
        {
                String[] files = (String[]) event.data;
//expects FileTransfer data
                for (int
p=0;p<files.length; p++)
                System.out.println( files[p] );
        }
/*drop*/
});



//e. Show window
frame.setBounds( 0,0, 600, 400 );
shell.open();

while
(!shell.isDisposed())
{
        if
(!display.readAndDispatch())
                display.sleep();
} /*while*/

browser.dispose();
display.dispose();
}/*main*/
 
}/*test*/

Back to the top