Tuesday, August 08, 2017

Spell checking in the new PowerBuilder 2017 Rich Text Edit Control

The original Rich Text Editing control shipped with PowerBuilder was based on an OEM of a popular third party control at the time called HighEdit. By the time 10.5 came out though, that control was quite dated and no longer supported by the vendor. As a result, in 2006 Sybase replaced that control with an OEM of another popular third party control called TX Text Control. There are licensing issues with that control though.  So with the release of PowerBuilder 2017 Appeon updated the control again, replacing the OEM of the TX Text Control with an OEM of the TE Edit Control.




Note that if you encounter regressions with the new control you can switch back to the TX Text Control through a new RichTextEdit option in the Additional Properties dialog for the application object.  If you do however, you will have to obtain your own license of TX Text Control.


One feature that became possible when Sybase adopted the OEM of the TX Text Control was in place spell checking of the text through third party utilities like JRSpell, WSpell or VSSpell. With the previous control, about the only thing you could do was copy out the unformatted text, spell check that using Word through OLE Automation, and then paste back in corrected, but unformatted, text.  Many people found losing the formatting of the text an unpleasant side effect of spell checking that way.  The new controlled allowed spell checking to be done without losing formatting.


In order for those third party utilities to perform in place spell checking, they needed to be provided with the handle to the control containing the rich text.  In an article I did for the PowerBuilder Developers Journal when the control was first introduced, I provide sample code for obtaining the control handle to pass to those utilities.  The sample code was essentially this, where a_rte is a reference to the PowerBuilder rich text edit control:

 ulong        hWin  
 hWin = Handle ( a_rte )  
 hWin = FindWindowEx ( hWin, 0, "PBTxTextControl", 0 )  
 hWin = FindWindowEx ( hWin, 0, "AfxOleControl42u", 0 )  
 hWin = FindWindowEx ( hWin, 0, "TX11P", 0 )  

Starting with the PowerBuilder RTE control we had to drill down three levels until we reached the part of the OEM TX Text Control that contained the text.  FindWindowEx is a windows API call to get a control handle based on a class name.  The text values included here are the class names that PowerBuilder used for the various controls.  Note that each time a new version of PowerBuilder was released and referenced a newer version of the TX Text Control the last class name used here had to be updated for the class name for that version.

With the new rich text edit control in PowerBuilder 2017 we use the same technique, though we don't have to drill down quite so deeply.  The code I'm using now in my migrated PowerBuilder 2017 application looks like this.

 ulong        hWin  
 hWin = Handle ( a_rte )  
 hWin = FindWindowEx ( hWin, 0, "Ter24Class", 0 )  


4 comments:

Unknown said...

Bruce,
Your solution works fine for Powerbuilder 2017 R1, but I've just updated to R3 and it stop working.

Could you please advise what classname is applicable for PB 2017 R3?
Thanks.

Unknown said...

Hello Bruce.
Interested in your article here.
We have a bilingual requirement to fill.
Do you know if the control will spell check French text?

Bruce Armstrong said...

WSpell has dictionaries in 13 non-English languages, including French. See: https://www.wintertree-software.com/dev/dict/spelling-engines.html

The VSSpell link in the article is out of date. A more current one follows. They only have dictionaries in English, Spanish and Dutch: https://www.componentsource.com/product/componentone-vsspell/about

JRSpell only has dictionaries in English and German: http://www.jrsoft.de/en/jrspellcheckere.html

Bruce Armstrong said...

I assume you're asking about the classnames for the OEM version of the TX Text Control. It would appear from the runtime files information in the 2017 R3 docs that they upgraded to version 17 of TX Text Control, and so I would assume that the last line should be changed to:

hWin = FindWindowEx ( hWin, 0, "TX17P", 0 )

https://docs.appeon.com/pb2017r3/application_techniques/ch35s04.html

The best thing to do anytime you upgrade the Powerbuilder version is to open a window containing a rich text control and then use a utility such as WinSpy (http://www.catch22.net/software/winspy) to check the control names.