Comments
litl_phil wrote: While it's nice that Google and Acer share the vision of cloud-based computing, it's also worth noting that we at litl already have a webbook on the market (available at litl.com) that runs our own cloud-based OS. Unlike Chrome, litlOS is focused on creating a new and better web experience for the home, so we don't have the usual browser interface, we have our own innovative UI. In conjunction with easel mode (litl's inverted-V position) and our growing cohort of litl channels (special apps t...
Cloud Expo on Google News


2008 West
DIAMOND SPONSOR:
Data Direct
SOA, WOA and Cloud Computing: The New Frontier for Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
GOLD SPONSORS:
Appsense
User Environment Management – The Third Layer of the Desktop
Cordys
Cloud Computing for Business Agility
EMC
CMIS: A Multi-Vendor Proposal for a Service-Based Content Management Interoperability Standard
Freedom OSS
Practical SOA” Max Yankelevich
Intel
Architecting an Enterprise Service Router (ESR) – A Cost-Effective Way to Scale SOA Across the Enterprise
Sensedia
Return on Assests: Bringing Visibility to your SOA Strategy
Symantec
Managing Hybrid Endpoint Environments
VMWare
Game-Changing Technology for Enterprise Clouds and Applications
Click For 2008 West
Event Webcasts

2008 West
PLATINUM SPONSORS:
Appcelerator
Get ‘Rich’ Quick: Rapid Prototyping for RIA with ZERO Server Code
Keynote Systems
Designing for and Managing Performance in the New Frontier of Rich Internet Applications
GOLD SPONSORS:
ICEsoft
How Can AJAX Improve Homeland Security?
Isomorphic
Beyond Widgets: What a RIA Platform Should Offer
Oracle
REAs: Rich Enterprise Applications
Click For 2008 Event Webcasts
SYS-CON.TV
Top Links You Must Click On


Implementing the Microsoft Rich Edit Control
Part 2

As we mentioned in Part 1 (PBDJ, Vol. 12, issue 7), we needed to implement spell checking in the rich edit fields in our application (see Figures 1 and 2).

To do that, we got a license for the Sentry Spelling Checker Engine from Wintertree Software (www.wintertree-software.com). The utility is easily implemented and works quite well on standard Rich Edit controls. However, the PowerBuilder Rich Edit control is an OEM version of an old third-party control that was popular before Microsoft introduced its Rich Edit control to the common controls. As a result, the messages and functions it supports are completely different from those that the Sentry utility is trying to use to interact with the control.

In Part 1 we created a custom visual user object based on the Microsoft Rich Edit control. In Part 2, we will write two custom DLLs to support the functionality of the rich edit control that we weren't able to implement directly through PowerBuilder. One is a PBNI extension and the other is a standard DLL.

enumfont PowerBuilder extension
Sybase made an enumfont PowerBuilder extension available as an example of implementing PBNI when PowerBuilder 9 was first released. However, as originally written, the extension wasn't fully suited to our purposes. This was primarily because it used the rather old EnumFontFamilies function in the Windows API and only allowed a choice between screen or printer fonts. The EnumFontFamilies function often returns a particular font family several times if there are multiple charsets for the same font family. Rather than trying to filter out the list returned by that function, we modified the extension to use the newer EnumFontFamiliesEx function. That method provides more control upfront over the selection of the font families that are returned, and we modified the extension so it only returns TrueType fonts that have an ANSI charset.

The changes to the original enumfont extension are primarily in two areas. In the call to the Windows API function (originally called EnumPrinterFonts or EnumScreenFonts, but now called EnumTrueTypeFonts), there is now an additional LOGFONT structure that's prepared and passed into the call to indicate the font characteristics the call should match.

EnumTrueTypeFonts
HDC hdc = GetDC(NULL);

UserData ud;
LOGFONT lf = { 0, 0, 0, 0, 0, 0, 0, 0, ANSI_CHARSET,
0, 0, 0, 0, "\0" };

ud.session = session;
ud.object = ci->pArgs->GetAt(0)->GetObject();

int ret = EnumFontFamiliesEx(hdc, &lf,
(FONTENUMPROC)&CFontEnumerator::EnumFontProc,
(LPARAM)&ud, 0 );
ReleaseDC(NULL, hdc);

ci->returnValue->SetLong((pblong)ret);

return PBX_OK;

The other major change is in the callback function (EnumFontProc) that the Windows API calls for each font name. Both the original version and the modified version contained a FontType argument that indicates (among other things) whether or not the font being passed in is a TrueType font. The difference is that we are now checking that argument for a TrueType font, and exiting the callback without proceeding further if it's not. In addition, the structure in which the font name is returned to the callback procedure has a slightly different format for the newer call.

EnumFontProc
UserData* ud = (UserData*)lparam;

if ( !( FontType & TRUETYPE_FONTTYPE ) )
{
   return 1 ;
}

pbclass clz = ud->session->GetClass(ud->object);
pbmethodID mid = ud->session->GetMethodID(clz, "onnewfont",
PBRT_EVENT, "IS");

PBCallInfo ci;
ud->session->InitCallInfo(clz, mid, &ci);

ci.pArgs->GetAt(0)->SetString(lpelfe->elfLogFont.lfFaceName);
ud->session->TriggerEvent(ud->object, mid, &ci);
pbint ret = ci.returnValue->GetInt();

ud->session->FreeCallInfo(&ci);

return 1 ;

richedit.dll
One of the principal reasons that a PBNI extension was used to get the list of fonts is because the Windows API function that returns that information requires a callback function to implement it, something that PowerBuilder doesn't directly support. The same issue came up in two other areas in our implementation:

  • Retrieving the RTF formatted text from the control using the EM_STREAMOUT Windows message.
  • Receiving notifications of selection changes in the rich edit control via the EN_SELCHANGE Windows message.
The richedit.dll was developed to provide callback support to the PowerBuilder user objects.

The richedit.dll contains four exported functions. Two of them are used to let the DLL know how to communicate back to the PowerBuilder object that's working with it. In both cases, the handle to the PowerBuilder user object is passed in as an argument and stored locally in the DLL.

SetControl
void __declspec(dllexport) __stdcall SetControl(
DWORD hControl
)
{
   iControl = (HWND)hControl ;
   return ;
}

SetUserObject
void __declspec(dllexport) __stdcall SetUserObject(
DWORD hUserObject
)
{
iUserObject = (HWND)hUserObject ;
return ;
}

About Bruce Armstrong
Bruce Armstrong is a development lead with Integrated Data Services (www.get-integrated.com). A charter member of TeamSybase, he has been using PowerBuilder since version 1.0.B. He was a contributing author to SYS-CON's PowerBuilder 4.0 Secrets of the Masters and the editor of SAMs' PowerBuilder 9: Advanced Client/Server Development.

About Demetrios Tsakiris
Demetrios Tsakiris is a senior programmer at Integrated Data Services. He has been working with PowerBuilder since version 5.0 and has a total of 5 1/2 years in the programming world. Demetrios is also an Oracle, Sybase, and Unix developer.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

Enterprise Open Source Magazine Latest Stories . . .
Oracle seems to have divided the open source ranks over the MySQL delay it’s having closing its acquisition of Sun. Eben Moglin, the GPL’s most ardent defender and delineator, the lawyer who has worked hand in glove for years with the Free Software Foundation’s founder Richard Stallman...
Cloud computing is a game changer. The cloud is disrupting traditional software and hardware business models by disrupting how IT service gets delivered. Entrepreneurial opportunities abound as this classic disruptive technology begins to proliferate, so it is no surprise that SYS-CON'...
The irony is that Oracle has advanced MySQL, lost money in the process, and helped its competitors - all at the same time. When Oracle buys Sun and controls MySQL the gift (other than to Microsoft SQL Server) keeps on giving as the existential threat to RDBs is managed by Redwood Shore...
WSO2, the open source SOA company, today announced the launch of the WSO2 Cloud Platform. Available today, the new WSO2 Cloud Platform features a family of WSO2 Cloud Virtual Machines; WSO2 Cloud Connectors for enabling fast, secure cloud services; and the multi-tenant WSO2 Governance-...
Now, the open source Mozilla Thunderbird client software can be used with Open-Xchange collaboration software. The "Community OXtender for Thunderbird" software connector gives users full access to appointments and contacts stored in the Open-Xchange Server and enables them to use Thun...
Morph Labs, a leading provider of enterprise cloud computing technology, today announced an introductory trial of the Morph CloudServer, an open, standards-based server IT organizations can use to rapidly model and evaluate their cloud implementations. A miniature "Cloud Environment in...
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON Featured Whitepapers
ADS BY GOOGLE