Unicode and revBrowser: "selected" property and callback messages

Slava Paperno slava at lexiconbridge.com
Sun May 29 09:49:40 EDT 2011


Thanks, Mike.

Briefly: when a JavaScript function returns a Russian string to
revBrowserCallScript(), the Unicode characters in it are replaced with
question marks, just like they are in the "selected" property of the
revBrowser instance.

In more detail:
I know and understand what you say about the three advanced callback
messages. Sending a timed message after the stack receives a click is a neat
trick: the user doesn't have to do anything. I'll remember that.

Setting up a JS function in the Web page to return the selected word is
easy. The problem is that when I look at what revBrowserCallScript()
returns, the Russian part of it is all question marks.

The JS function I added to the Web page first uses alert(selectedTextStr) to
show me what the selection is, and then returns the value of that
selectedTextStr. The stack receives it as the return value of the
revBrowserCallScript() call, and I examine it in LC. The English portion of
it is fine, but the Russian (Unicode) characters are replaced by question
marks--even though in the alert() popup it is correct.

This gives me an idea: In the JS function I can convert the Russian
characters to their decimal values, pass those numbers to the stack, and
have the stack convert them back to Unicode... I'll try that, if there's
nothing else that can be done.

Slava

> -----Original Message-----
> From: use-livecode-bounces at lists.runrev.com [mailto:use-livecode-
> bounces at lists.runrev.com] On Behalf Of Mike Bonner
> Sent: Sunday, May 29, 2011 9:07 AM
> To: How to use LiveCode
> Subject: Re: Unicode and revBrowser: "selected" property and callback
> messages
> 
> Can't help with the Unicode part, but if you turn on advanced messages
> in
> revbrowser, you can catch clicks.
> 
> revbrowserset sBrowserId,"messages",true
> From the dictionary:
> *Note: The "advanced" callback messages are: browserClick, browserOut
> and
> browserOver. These messages are only sent when the "messages" property
> is
> set to true. The other callback messages are always sent.*
> 
> In your web page, you could have a click place the word in a holding
> variable, in livecode you could time track the clicks (since there is
> no
> browserDoubleClick as far as I can tell) and if a 2nd click occurs
> quickly
> enough then use revbrowsercallscript to get the value.  Or you could
> handle
> things mostly on the javascript side, catch a doubleclick and set a the
> holding var, then wait for livecode to again use revbrowsercallscript
> to
> call a javascript function that will return the clicked word.  2nd
> option is
> probably better.
> 
> 2011/5/29 Slava Paperno <slava at lexiconbridge.com>
> 
> > Thanks for thinking about this, Jacqueline. The problem persists.
> >
> > I said:
> > > > When a user double-clicks a word in the revBrowser window, I
> would like
> > a message
> > > to be sent by revBrowser to the stack, with that word as a
> parameter.
> >
> > And you said:
> > > Your best bet is to put in a feature
> > > request in the QCC, but of course you probably don't want to wait.
> >
> > I also said:
> > > > As a slightly different approach, I thought I might tell the user
> to
> > > select a word in the Web page that is displayed by revBrowser, and
> then
> > > click a button in the card. That would be less intuitive for the
> user,
> > but
> > > still practical. So I put this script in the button's mouseUp
> handler:
> > > >
> > > > get revBrowserGet(gBrowserID, "selected")
> > > > put uniEncode(it, "UTF8") into locSelectedText
> > > > set the unicodeText of field "BrowserSelection" of this card to
> > locSelectedText
> > > >
> > > > The last line of this script works fine when the selected text is
> > > > English. When it is Russian, a question mark is received in each
> > character of
> > > > "it."
> >
> > And you said:
> > > The first thing I'd try is not uniEncoding the string at all. If
> the
> > > browser is showing it correctly it may already be UTF-16, and any
> > > further conversion would corrupt it. If that's true, then the
> method I
> > > posted before should be all you need. Just grab the string, prepare
> the
> > > field to accept Unicode, and set the unicodetext of the field to
> the
> > > string.
> >
> > And I said: I have tried all sorts of combinations of uniEncoding and
> > uniDecoding everything around this process. When I examine the
> English
> > characters in the string returned by the "selection" property, I
> conclude
> > that it is in a single-byte charset. For example, when the string
> АБВABC is
> > selected in revBrowser display, this call:
> >
> > get rebRbrowserGet(gBrowserID, "selected")
> > answer char 1 to 6 of it
> >
> > displays this:
> >
> > ???ABC
> >
> > That tells me that "it" is not in UTF-16. If it is indeed in ANSI
> (or,
> > worse
> > yet, ASCII), then the question marks are entirely natural: as I said,
> > applications that are non-Unicode compliant have always done that.
> But
> > since
> > the Web page in revBrowser has the meta tag that says:
> >
> > meta http-equiv="Content-Type" content="text/html;charset=UTF-8"
> >
> > The browser should know it is a double-byte text. The question is,
> does its
> > "selected" property know that? If you have evidence this is
> otherwise,
> > please let me know.
> >
> > You also said:
> > > If that doesn't work...
> > >    put uniEncode(it,"Unicode") into locSelectedText
> >
> > That is different from what I have done only in that you suggest
> "Unicode"
> > where I use "UTF8". Changing that to your version hasn't made a
> difference.
> > I think the problem is the content of the "selected" property--but
> I've
> > only
> > been playing with LC for a couple of weeks, so I can't trust myself.
> >
> > You kindly said:
> > > And if that doesn't work, I can try to find out why.
> >
> > I would appreciate any other pointers... Perhaps I am thinking in the
> > Director box, andthere is a natively LC way to achieve what I need?
> >
> > Slava
> >
> > > Jacqueline Landman Gay         |     jacque at hyperactivesw.com
> > > HyperActive Software           |     http://www.hyperactivesw.com







More information about the use-livecode mailing list