TextArea double-click?

Hi,
There seems to be no Double-Click action event for a text area on OS X, so I was wondering if anyone had a workaround?

Thank you all in advance.

Create your own through the MouseDown event.

If you double click on a word in a TextArea, it selects it. This is taken care of by the system.

What do you want to achieve ?

Thanks Kem / Michel.

Michel,
I have a text area which is read only.
I would like to make the option available for the user to be able to double click the text area - in order to open the contents into an edit window.

Based on your description, this doesn’t seem intuitive. Might an Edit button next to the TextArea work better?

Sounds more like it. Or, you could have a little edit/pencil icon appear in the corner of your TextArea, when you MouseEnter, much like in Xojo.

if you still want to go the DoubleClick method… try something like this

Sub MouseUp (X as Integer, Y as Integer)
  Dim doubleClickTime, currentClickTicks as Integer
  
  #If TargetMacOS then
    Declare Function GetDblTime Lib "Carbon" () as Integer
    DoubleClickTime = GetDblTime()
  #endif
  
  #If TargetWin32 then
    Declare Function GetDoubleClickTime Lib "User32.DLL" () as Integer
    doubleClickTime = GetDoubleClickTime()
  #endif
  
  #if TargetLinux then
    Declare Function gtk_settings_get_default lib "libgtk-x11-2.0.so" as Ptr
    Declare Sub g_object_get lib "libgtk-x11-2.0.so" (Obj as Ptr, first_property_name as CString, ByRef doubleClicktime as Integer, Null as Integer)
    
    Dim gtkSettings as MemoryBlock
    
    gtkSettings = gtk_settings_get_default()
    
    g_object_get(gtkSettings,"gtk-double-click-time",doubleClickTime, 0)
    // DoubleClickTime now holds the number of milliseconds
    DoubleClickTime = DoubleClickTime / 1000.0 * 60
  #endif
  
  currentClickTicks = ticks
  //if the two clicks happened close enough together in time
  If (currentClickTicks - lastClickTicks) <= doubleClickTime then
    //if the two clicks occured close enough together in space
    If Abs(X - lastClickX) <= 5 And Abs(Y - LastClickY) <= 5 then
      DoubleClick //a double click has occured so call the event
    end if
  end if
  lastClickTicks = currentClickTicks
  lastClickX = X
  lastClickY = Y

Copied from the LR

[quote=93456:@Richard Summers]I have a text area which is read only.
I would like to make the option available for the user to be able to double click the text area - in order to open the contents into an edit window[/quote]

Even a red only textarea will still let double click select the word, so you coud simply use SelChange.

Otherwise here is the principle of reading double click in MouseDown :

  • Create a static integer variable called oldstart
  • Upon beginning of MouseDown compare Microseconds to OldStart. If the difference is more than 100000 and 150000 (between 1/10th and 1/15th of a second, may need adjustment) consider that a double click
  • Store Microseconds into OldStart

Kem

In the toolbar, I have NEW, EDIT, and DELETE buttons (that is my preferred way of doing this).

Someone advised me however, that some people prefer to directly double click what they are looking at in the text area (in order to edit it), as opposed to having to move the cursor back up to the toolbar to click on the edit button.

I wherefore, wanted to give them the option of being able to double click the text area in order to open the window.

Dave was faster :wink:

Wow - so many answers.

Michel - thanks for the advice.
Dave - thanks for the actual code.
Kem - did my last post make more sense?
Gavin - Thanks for the advice.

Did I leave anyone out? :slight_smile:

[quote=93461:@Richard Summers]I wherefore, wanted to give them the option of being able to double click the text area in order to open the window.

[/quote]

Remember a while ago you wanted to inhibit the word selection in a read only textarea, and I told you to overlay a canvas over it. You can still do the same : doubleclick is available in a canvas.

Michel - yes, I remember - I will definitely consider that as an option - thank you.

Still unsure as to wether I should allow double-clicking to edit - or if it is better to stick to my toolbar buttons only approach.
What seems more intuitive to you guys?

I am happy to allow in-line editing in the text area, but my problem then is that I have no idea how to determine when the person has stopped typing - in order to update the database entry in question?

Simple…
create a timer
every keystroke reset the timer
if the timer fires … then the person was 'idle"… then if the TA was changed, update your database

set the time to a few seconds

Dave, I don’t like that approach only because slow typists will experience delays. More, someone could type a character, then immediately close the window before the Timer has a chance to fire.

I’d prefer taking advantage of the LostFocus and and Close events. If a change has been made, set a flag. On LostFocus and Close, check that flag and update as needed.

If there is more than one field, do this at the Window level and do all your updates at once in the CancelClose (or other appropriate) event. You’ll minimize interactions with the database this way too.

[quote=93465:@Richard Summers]Michel - yes, I remember - I will definitely consider that as an option - thank you.

Still unsure as to wether I should allow double-clicking to edit - or if it is better to stick to my toolbar buttons only approach.
What seems more intuitive to you guys?[/quote]
Unless it’s some sort of customized TextArea, so that it doesn’t look like a regular one, I’d say it’s very unintuitive. On OS X (and Windows), the standard behavior is to be able to double-click a textarea which automatically selects content (a double-click would select a word, triple-click selects a paragraph).

Personally… I prefer to not update the database at all as long as the “record” is still on the screen…

But he did say “stopped typing” :slight_smile:

Dave / Kem / Gavin - thanks for all the ideas.

So - Is the recommended / more practical solution, to have the text area not read only, which allow the user to single click to edit. Then, when the focus is lost - update the database?

Does that sound more practical in your valued opinions?
Just trying to get an idea of the most practical approach - before I give myself a brain ache trying to achieve it :slight_smile:

doubleclick.xojo_binary_project

This double click will conform to the system settings.

You can let the textarea become editable, and render the canvas invisible while editing.