Hyper Lexicon

Implementing Hyper Links in PowerBuilder 
Last Updated 06 Jan 1998 
Send me your comments EMail your comments to me
 

 
 
Click here to download Hyper Lexicon: 
hyperlex.zip, 22kb, PB4, Windows 3.x/Windows95
Hyper Lexicon is an example application which demonstrates how to create Hyper Links in PowerBuilder. Hyper Lexicon presents the user with a list of terms and their meanings. The meaning of a term can contain links to other terms. Such terms are shown as Hyper Links. When the user clicks on an hyper linked term, the application automatically 'jumps' to the meaning of the clicked term.
 

Some Background

 I built this application in  response to the following post by Martine Guebel on the PB-L List server  -

What I am actually developing is an online dictionary for which I want the user to be able to click highlighted words (i.e. hot spots) in the definitions and get (i.e. jump to) the definition for the clicked words. In  fact the definitions are not displayed in data windows but in multiline edit controls.

For example:

Call
1. Short for call option.  2. An option whereby the issuer of a bond is given a right of redemption before maturity, at a given price and on a given date.

 When the user clicks "option" he automatically gets the definition of the word "option". All such words are currently preceded by a "*" in my database. How can I tell PB4 that all words preceded by a "*" must be turned into hot spots ?

Click here to see the entire post and replies...
 

Strategy

To build such a hyper linked dictionary, one would need the means to achieve the following-
  1. The control used to display the meaning of a term should permit parts of the text (the hyper links) to be formatted in a different manner.
  2. When the mouse pointer is moved over a hyper linked word, the pointer should change to something like a Pointing Finger.
  3. When the user clicks on a hyper link, the control should provide a way of identifying the clicked word/s.
PB4 controls like the MLE do not posses any of the above listed capabilities. Even with a PB5 RTE, (1) is possible but I don't think (2) and (3) are.
 

How It Works

The approach I took here is to first parse the string and break it up into normal and hyper linked parts and then plot it on an external datawindow. The external datawindow has a fixed number of columns defined. The columns used for displaying hyper linked word/s has different formatting in terms of color and underline. Also the pointer property is set to the Pointing Finger cursor. Thus each normal and hyper linked part of the line is actually plotted into separate fields. When the user clicks on an hyper linked word it is simple to find out the row and the column he clicked on using GetClickedRow() and GetClickedColumn(). Using these, the contents of the hyper link are obtained using GetItemString().

While developing this mechanism, a major hurdle I faced was with correctly sizing a field while plotting it and then positioning it accurately with respect to the previous field. The problem is - how does one find out the width of a string for a given font when it is displayed in a column. I had almost given up had it not been for another post on PB-L. Many thanks to Arthur Hefti <arthur@CATSOFT.CH> for his uo_textwidth.  I have used uo_textwidth to determine the length of a column in PBUs if it has to display a given string.
 

Limitations

A limitation to this approach is that the maximum number of words that can be shown on a single line must be decided at design time. This is not so bad, since even if one used a normal MLE, the width of the MLE would have to be fixed at design time.



The entire post and replies:

Date:    Fri, 19 Dec 1997 07:23:31 +0100
From:    Martine Guebel <martine.guebel@WRITETC.COM>
Subject: Hotspots in PB4

Hi PB gurus,

As I didn't receive much feeback from my previous attempt, I have taken
the liberty to ask again:
does anyone of you knows how I can create hotspots on part of the
strings displayed in a datawindow in PB4 ?

Thanks for your input.
___

Write! Technical Communications
Martine GUEBEL
Tel.: + (32) 2 714 42 82
Fax : + (32) 2 714 42 22
E-mail  : mgu@writetc.com
Website : http://www.writetc.com

----------------------------------------------

Date:    Sat, 20 Dec 1997 11:38:22 +0500
From:    Jiggy <jiggys@USA.NET>
Subject: Re: Hotspots in PB4

Martine,
        I am not sure exactly what sort of HotSpots you want to create in your DW -
1. Do you want a particular part of the DW, say a picture, to be a HotSpot,
which when clicked would initiate some action,OR
2. Do you want some text/column to act as hyperlinks, much like HTML or
Windows Help.

In either case, here is the general approach you can consider -

1. Right click the desired HotSpot object, i.e Picture/Text/Column, and set
the Pointer Property to something that looks like the hyperlink Hand
pointer. You might have to build the ICO cursor resource or use the ones
supplied.
2. In the clicked event of the datawindow check the object which was
clicked on using the GetObjectAtPointer() function. Now depending upon the
object, initiate the desired processing.

Jiggy

-------------------------------------------------

Date: Mon, 22 Dec 1997 07:28:22 +0100
From: "Martine Guebel" <martine.guebel@writetc.com>
Reply-To: mgu@writetc.com
Organization: Write! Technical Communication
To: jiggys@USA.NET
Subject: Hotspots (again)

Hi Jiggy,
Thanks for answering my question about hotspots in PB4.
I know I was not clear enough. What I am actually developing is an online dictionary for which I want the user to be able to click highlighted words (i.e. hotspots) in the definitions and get (i.e. jump to) the definition for the clicked words. In fact the definitions are not displayed in data windows but in multiline edit controls.

For example:

Call
1. Short for call option.  2. An option whereby the issuer of a bond is given a right of redemption before maturity, at a given price and on a given date.

>> When the user clicks "option" he automatically gets the definition of the word "option". All such words are currently preceded by a "*" in my database. How can I tell PB4 that all words preceded by a "*" must be turned into hotspots ?

Thanks again for investigating. It would be the best Christmas present for me if you could find an answer.
 
Martine
----------------------------------------------------------------------------
  1