Page 1 of 1
Detecting a double click in an unlocked field
Posted: Wed Oct 16, 2013 11:38 pm
by tjm167us
In a text field, I want to be able to do something when there is a double mouse click. How can this be done? (mouseDoubleDown and mouseDoubleUp messages don't get sent in unlocked text fields).
The only handler that seems at all applicable would be the selectionChanged handler, but it doesn't provide you with the action that caused it to be called in the first place.
Phrased another way:
What message does the engine intercept to create the default doubleClick (highlight chunk) behavior?
Re: Detecting a double click in an unlocked field
Posted: Wed Oct 16, 2013 11:47 pm
by FourthWorld
Users expect a double-click in a field to select a word. This is a long-standing convention on every desktop OS LiveCode supports.
What action do you want to trigger with that? Could there be another way to do it?
Re: Detecting a double click in an unlocked field
Posted: Thu Oct 17, 2013 12:24 am
by tjm167us
Hi Richard,
I appreciate your prompt response! This is more of a hypothetical thing, because I know of a different way to solve my particular problem. I just became a little perplexed, because a message invariably has to get to the engine to create that default behavior, but there is no documented message in the text field docs that I have successfully intercepted to disallow the behavior.
Having said that, below is what I'm trying to accomplish.
What I want:
I have created a find function that allows you to type a word into the "search" field and press the "find" button. What then happens is all of the occurrences of that string are highlighted in the body of text. I highlight the text by setting the backColor custom property of the chunk of text to "yellow".
The problem arises when I select an already highlighted chunk in the field. The yellow looks like it is in the foreground and the selected color is behind it.
To address this, I am going to create a function in the selectionChanged handler that accomplishes the following:
1. Determine what, if any, of the selected text is also highlighted.
2. Change the overlapped text (by overlapped I mean highlighted AND selected) to be a yellowish-green color.
Something I am still unsure about however is how to deal with drag-selecting. If a user drag-selects some text that is highlighted, selectionChanged won't be called until after they release the drag. Any ideas?
Thanks, Tom
Re: Detecting a double click in an unlocked field
Posted: Thu Oct 17, 2013 1:25 am
by dunbarx
Hi.
Does this help:
Code: Select all
on selectionChanged
if the the backColor of the clickChunk = "255,255,0" then set the backColor of the clickChunk to "green"
end selectionChanged
I think this can be easily extended to all the colored text found by your "find".
Craig Newman
Re: Detecting a double click in an unlocked field
Posted: Thu Oct 17, 2013 1:44 am
by tjm167us
Craig, Thank you. I did something very similar (except with selectedChunk), but it still doesn't address the problem of updating. I am questioning whether selectionChanged is the right handler, because I want the backColor to update to the "green" color AS the user is dragging, not after the mouse is released. Any ideas?
Thanks,
Tom
Re: Detecting a double click in an unlocked field
Posted: Thu Oct 17, 2013 4:53 am
by dunbarx
Hi.
I think I see. After playing around with the many "dragxxx" and "dropxxx" functions and messages, it seems what you need is a function called the "dragText" or the "dragChunk". This would have to hold its "shape" whilst being dragged, so that it can change color and still stay intact during that process.
I am not sure this is readily doable, but others may find a way. Long ago, I created a small transparent field that I loaded with the soon-to-be dropped text, and moved that field along with the mouseLoc, managing the thing while the mouse was down. It worked, deleting the original chunk. Is this too clunky?
Craig
Re: Detecting a double click in an unlocked field
Posted: Thu Oct 17, 2013 1:51 pm
by tjm167us
Craig,
I considered the myriad of dragXXX messages, but they don't get called unless you have some text selected, then try and move the selected text. That means it is not called as you are dragging the cursor to select text. Having said that, I figured out a way to update the highlighting color in real time (as I am dragging to select text). I will accomplish this by putting my code that accomplishes the following:
1. Determine what, if any, of the selected text is also highlighted.
2. Change the overlapped text (by overlapped I mean highlighted AND selected) to be a yellowish-green color.
into a timer loop that is called periodically. Provided the timer loop is set up with a small enough periodicity that one can reasonably drag to select text, but not too fast to bog down computing, this should work just fine! Below is some "proof of concept" code that demonstrates that the selectedText variable is updated as new text is selected (i.e. it doesn't wait to update this variable until the selectionChanged message is sent or anything). My user interface consists of a text field with text in it (to highlight as the loop is running), and two buttons: one to start the loop, and one to stop the loop.
This is the "Start" button code:
Code: Select all
on mouseUp
call "startLooping"
end mouseUp
This is the "Stop" button code:
Code: Select all
on mouseUp
call "stopLooping"
end mouseUp
This is the stack code:
Code: Select all
local loopCount=1
local stopLoopingVar = false
on preOpenStack
call "timerLoop"
end preOpenStack
on timerLoop
if stopLoopingVar is false then
send "timerLoop" to me in 1000 milliseconds
put "timerLoop"&& loopCount& return after msg
--Add code here to do the highlighting
put the selectedChunk into theChunkExp
if word 2 of theChunkExp < word 4 of theChunkExp then
put tab&the selectedChunk&return after msg
end if
add 1 to loopCount
end if
end timerLoop
on stopLooping
put true into stopLoopingVar
put 1 into loopCount
end stopLooping
on startLooping
put empty into msg
put false into stopLoopingVar
call "timerLoop"
end startLooping
Re: Detecting a double click in an unlocked field
Posted: Thu Oct 17, 2013 2:04 pm
by Klaus
Hi Tom,
little hint: You only need to "CALL" a handler if that handler is NOT in the current message path!
In your case you just need to "evoke" the handler:
Code: Select all
on mouseUp
startLooping
end mouseUp
Code: Select all
on mouseUp
stopLooping
end mouseUp
Best
Klaus
Re: Detecting a double click in an unlocked field
Posted: Thu Oct 17, 2013 3:38 pm
by FourthWorld
I wonder if a mouseMove handler may be better than a timer here.
Re: Detecting a double click in an unlocked field
Posted: Thu Oct 17, 2013 5:01 pm
by tjm167us
Klaus,
Thanks for the suggestion, I agree!
Richard, that is an interesting idea, but may be overkill (too computationally intensive). Like I mentioned to Craig:
Provided the timer loop is set up with a small enough periodicity that one can reasonably drag to select text, but not too fast to bog down computing, this [timer-based method] should work just fine!
With some very rough timing, it appears as though the mouseMove handler was called on my slow computer anywhere from ~150-250x/second, whereas I think I can accomplish a satisfactory "as you drag" effect by updating at ~20-30x/second (although I haven't yet tested this).
Do you have any reason to be wary of using the timer-based approach? I can further refine the timer-based approach by stopping/starting the timer loop on exit/entry of the text field, so it's not needlessly running in other parts of the application.
Related to my original question, do you know of any documentation available that explains which handlers the engine uses to create default behaviors for the built-in controls?
This could be mighty helpful in harnessing the full-power of the message path (by knowing what behaviors you will affect by trapping messages).