Focus after dragdrop

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
andyh1234
Posts: 476
Joined: Mon Aug 13, 2007 4:44 pm
Contact:

Focus after dragdrop

Post by andyh1234 » Mon Oct 19, 2009 3:09 pm

Having a small problem with dragdrop

After dragging some text, and dropping it in a filed the field does not take the focus, in fact focus just seems to vanish from the whole stack.

Ive tried adding

Code: Select all

on dragdrop
focus on field "xyz" of card "xyz" of stack "xyz"
pass dragdrop
end dragdrop
 
if the on dragdrop handler, but the focus is still being lost.

Trying...

Code: Select all

put the focusedobject
returns....

Code: Select all

field id 1035 of card id 1002 of stack "/Applications/Revolution Enterprise/3.5.0-gm-2/Toolset/revmessagebox.rev"
Any ideas how I can get the app to focus on the field accepting the drop?

Thanks

Andy

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Mon Oct 19, 2009 3:48 pm

Andy,

Where are you dragging from?

If I start Revolution, create a new stack with a new field and don't add any scripts, I can drag files and text into the new field, after which the stack and the field get focus. I think that the problem is not in your field (just delete yor dragdrop handler).

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

andyh1234
Posts: 476
Joined: Mon Aug 13, 2007 4:44 pm
Contact:

Post by andyh1234 » Mon Oct 19, 2009 5:10 pm

Thanks Mark,

Ive just tried that and it works.

What I am doing is dragging within the same field so I can re-order items within the field. The user can select an item and drag it, but when its dropped the control just loses the focus.

Im using the code...

Code: Select all

on dragenter
  set the DragAction to "copy" -- need to do this to get the control to accept a drop from itself
    pass dragenter
end dragenter

on dragstart
   set the dragData["text"] to the selectedtext of me 
  pass dragstart
end dragstart

on dragdrop
   put the mouseline into cLine
   put word 2 of cLine into cLine
  /* more code to handle the drop commented out, focus already lost */
  pass dragdrop
end dragdrop

Ill keep bashing away at it, and when I find the answer Ill let you know what I was doing wrong in case it affects anyone else!

Thanks

Andy

andyh1234
Posts: 476
Joined: Mon Aug 13, 2007 4:44 pm
Contact:

Post by andyh1234 » Mon Oct 19, 2009 5:25 pm

Thanks again Mark,

Ive just been through all the code commenting everything out and adding them back in one by one, and found the offending function. Just working through it now and Ill post the problem I had and the solution as soon as I have it fixed.

Thanks

Andy

andyh1234
Posts: 476
Joined: Mon Aug 13, 2007 4:44 pm
Contact:

Post by andyh1234 » Mon Oct 19, 2009 5:52 pm

Ok, the problem was...

In dragstart there was a command..

Code: Select all

set the dragData["text"] to myText
 set the dragImage to CreateDragImage("212,225,252"
)

This code creates an image that can be used for the drag image, and seemed to work quite well, it will be from one of the sample stacks.

Code: Select all

function CreateDragImage bColor
   local tRect,tempImage
   -----
   if there is a fld "ImageTemplate" then 
      delete fld "ImageTemplate" -- just in case
   end if
   
   set the visible of the templateField to false
   set the height of the templateField to the effective textHeight of me + 6
   set the width of the templateField to 450
   set the threeD of the templateField to false
   set the borderWidth of the templateField to 1
   set the fixedLineHeight of the templateField to false
   set the dontWrap of the templateField to true
   set showFocusBorder of the templateField to false
   set backColor of the templateField to bColor
   set borderColor of the templateField to "red"
   set name of the templateField to "ImageTemplate"
   create field
   reset the templateField
   -----
   set the itemdel to tab
   put (item 1 of dragData["text"]) into fld "ImageTemplate"
   set the textalign of fld "ImageTemplate" to "center"
   --set the width of fld "ImageTemplate" to the formattedWidth of fld "ImageTemplate"
   
   put the rect of fld "ImageTemplate" into tRect
   -----
   
   lock screen
   show fld "ImageTemplate"
   
   -- combination of visble property and screen lock make that nothing appear but the snapshot is OK :-)

--********** next line caused the problem **********
   export snapshot from rect tRect of this cd to tempImage as jpeg
--********** previous line caused the problem **********
   
   -- export image to a variable
   hide fld "ImageTemplate"
   unlock screen
   lock messages -- important to speed up the process
   create invisible image -- we don't want to see it
   set the text of last image to tempImage
   if there is an image ID 6001 then delete image ID 6001
   set the ID of last image to 6001
   unlock messages
   
   return the ID of last image -- we need it to set the dragImage property
   
end CreateDragImage
The problem line is 'export snapshot from rect tRect of this cd to tempImage as jpeg'

As long as that line is commented out, everything works as designed (apart from the image being created), if I add the line back the drag image is created and shown, but after the drop all keyboard focus on the control is lost, and I cant seem to get it back, even clicking on the field doesn't get the keyboard focus back.

I guess for now Ill abandon the drag image!

Thanks again.

Andy

Post Reply