Unicode and revBrowser: "selected" property and callback messages

Slava Paperno slava at lexiconbridge.com
Sun May 29 01:21:56 EDT 2011


Hi again, Jacqueline! Thanks for keeping up this dialog.

You said:

> By convention, a UTF-8 file doesn't use a BOM.

When I save my Unicode files as UTF-8 text (from the Windows Notepad or
Dreamweaver, for example), the files do have a BOM. I found that when I read
them into LC variables, I have to strip the first two characters, otherwise
my attempts to determine the code point of a specific character fail,
because there are these two extra ones in front. But that's not my problem
here. I will explain what I tried to say in an earlier message. (I have
changed the subject line accordingly.)

Very briefly, for experts like you, my questions are:

1) can a JavaScript function in the Web page that is displayed by revBrowser
send a message back to the stack, and pass a parameter with that message?
Something like onmouseclick="CallMotherStack(myValueStr)"? 

2) can the "selected" property of revBrowser hold a Unicode string?

Now the same in detail:

I am learning LC so I can use it to build a front end to a Russian-English
dictionary database (SQLite). I am a moderately proficient programmer with
several applications used by hundreds of people, but I am a babe in the LC
woods.

My dictionary entries in the database are in HTML format, with Russian
stored as Unicode characters (not HTML entities). So my LC stack takes this
long HTML string (a complete Web page, including some JS and CSS) and makes
this call:

revBrowserSet(gBrowserID, "htmltext", locHTMLString)

This works great, and the instance of revBrowser displays the Russian and
English text beautifully. My LC handlers are even able to call my JS
functions in the Web page by using revBrowserCallScript().

But I also want to do the reverse: to have a JS function in the Web page
send a message back to the stack. Here is why: when the user double-clicks a
Russian word in the revBrowser pane, I want my LC handler to look up that
word in the database.

In my Adobe Director application, I do this by placing this JS in the Web
page's body tag:

body ondblclick='textRange=document.selection.createRange(); selectedWord =
textRange.text; if (selectedWord.length!=0)
{window.external.execDirectorScript(selectedWord)}'

In Director, we use something called WebXtra, a sort of plug-in that embeds
a mini-Web browser in the "sprite" on the "stage," which is very similar to
embedding revBrowser in a "control" on a "card." When the user double-clicks
a word in the Web page that is displayed by WebXtra, function
execDirectorScript() sends a message and an argument to the sprite, where my
handler intercepts it and looks up selectedWord in the database.

That's what I am trying to reproduce in my proof-of-concept LC stack.

I know from the LC Dictionary that revBrowser does send three callback
messages to the stack: browserClick, browserOut, and browserOver. In other
words, revBrowser can, to a certain extent, inform the stack of what's going
on in the Web page. I am hoping that someone has extended the capabilities
of revBrowser, and that more interesting info can be sent to the stack by
the Web page that revBrowser is displaying. Specifically, when my 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. That's my
Question Number One.

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") --"it" is now the text that the
user selected in the Web page
put uniEncode(it, "UTF8") into locSelectedText --now locSelectedText should
be UTF-16
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."
This is not a display or font problem--they are indeed question marks. We
know that this type of remapping is done by older applications that are not
Unicode-compliant.

That is my Question Number Two: am I doing something wrong, or is the
"selected" property of revBrowser incapable of holding a Unicode string?

I am tremendously grateful to you (and the rest of the LC community) for all
the help folks like me receive on this list. I plan to upload my
proof-of-concept stack to LC as a live example of what can be done with
bilingual Unicode texts, for those who might be struggling with the same
issues.

Slava 






More information about the use-livecode mailing list