[Gambas-user] WebTextArea vs. TextArea controlling events

Bruce Steers bsteers4 at gmail.com
Thu Sep 29 13:36:04 CEST 2022


On Thu, 29 Sept 2022 at 11:53, Rolf-Werner Eilert <rwe-sse at osnanet.de>
wrote:

> Good morning everyone!
>
> Today I played a bit with WebTextArea and tried to implement some of the
> events controlling key, mouse etc. compared to TextArea. I have 3.17.2
> on this system.
>
> Long time ago I wrote a little program controlling the keystrokes of
> TextArea_KeyPress. This reads somewhat like this:
>
>    If key.Control Then     'Strg+Taste übergehen:
>      Stop Event
>
>    Else                    'einfache Tasten alle übergehen:
>      Select Case key.Code
>      Case key.BackSpace, key.BackTab, key.Delete
>        Stop Event
>      Case key.Down, key.Up, key.Left, key.Right
>        Stop Event
>      Case key.Home, key.End, key.PageDown, key.PageUp
>        Stop Event
>      End Select
>
>    End If
>
> I had also implemented my own linewrap to limit input to 70 characters a
> line. All this runs pretty well there.
>
> Now I wanted to know if there is a chance to implement this to a WebApp.
> So I used WebTextArea and inserted the code above (and somewhat more)
> from the old project to WebTextArea_KeyPress. But WebTextArea doesn't
> seem to catch the keystrokes or at least the code doesn't have any
> effect. Is there a chance to have it run like this?
>
> Furthermore, I found that TextArea_MouseDown and _MouseUp don't exist.
> These would be nice to have. Is there a technical reason they do not
> exist, or have they just not been implemented yet?
>
> Thanks for all insight!
>
> Rolf
>

The gb.web.gui components are currently a bit limited.
The events have been kept at a minimum as probably would end up in a lot of
javascript code for the browser.
I think?
Personally i think it would be good for WebControl to be updated to support
a few more standard events we are used to. I think it should be okay (not
code hungry) as lines like 'If Object.CanRaise(Me, "MouseUp") Then
PrintMoreJSCode()' mean that if you do not use the MouseUp event then the
code is not added.


You should be able to make your own version, gb web components are mostly
easy to override..

Check out the following code  (Save in in your project as WebTextArea.class)

------------------------
' Gambas class file

Export

Event MouseDown
Event MouseUp

Public Sub _UpdateProperty(sProp As String, vVal As Variant)

  Select sProp
    Case "mouse"
      If vVal = "down" Then Raise MouseDown Else Raise MouseUp
      Return
  End Select
  Super._UpdateProperty(sProp, vVal)

End

Public Sub _BeforeRender()

  Print "<textarea"; Me._GetClassId(); " autocomplete=\"off\"";
  If Object.CanRaise(Me, "Change") Then
    Print " oninput=\"gw.textarea.onChange("; JS(Me.Name); ");\"";
  Else
    Print " oninput=\"gw.textarea.onUpdate("; JS(Me.Name); ");\"";
  Endif
  'If Object.CanRaise(Me, "Change") Then Print "
oninput=\"gw.textarea.onChange("; JS(Me.Name); ");\"";
  'Print Me._GetUpdateJS("onblur", "text", "this.value");

'  Add MouseUp and MouseDown triggers
  If Object.CanRaise(Me, "MouseDown") Then Print
Me._GetUpdateJS("onmousedown", "mouse", "'down'");
  If Object.CanRaise(Me, "MouseUp") Then Print Me._GetUpdateJS("onmouseup",
"mouse", "'up'");

  If Not Me.Enabled Then Print " disabled";
  If $bReadOnly Then Print " readonly";
  If $sPlaceHolder Then Print " placeholder=\""; Html($sPlaceHolder); "\"";
  Me._RenderStyleSheet()
  Print ">";

End
------------------------

That code will add MouseUp and MouseDown events to WebTextArea you can use
the same methods to add other javascript events like KeyPress and such.

It is a copy of the _Beforerender() method from WebTextArea.class of
gb.web.gui with additions to set up the mouse events. this overrides the
default WebTextArea _Beforerender method as the file name is
WebTextArea.class.
these events are then processed in the overridden '_UpdateProperty()'
method as shown (that method then fires the parent _UpdateProperty()
method).

Hope that makes sense
BruceS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20220929/0e1a74a5/attachment-0001.htm>


More information about the User mailing list