Welcome!

PowerBuilder Authors: Chris Pollach, Yeshim Deniz, Jayaram Krishnaswamy, Kevin Benedict, Avi Rosenthal

Related Topics: PowerBuilder

PowerBuilder: Article

Implementing the Microsoft Rich Edit Control

Part 1

The remaining event (EN_SELCHANGE) is mapped to the PBM_CUSTOM01 event and is fired by the custom DLL whenever the user changes the selection in the rich edit control. In turn it calls a function on the u_rte user object that updates the status of various toolbar items on the toolbar.

u_rte Functions
The of_ruler and of_toolbar function control the visibility of dw_ruler and dw_toolbar respectively. The of_ruler function also calls a method on the dw_ruler object to create the rulebar if it's visible.

of_ruler
rulerbar = ab_switch
this.dw_ruler.visible = ab_switch
IF ab_switch THEN dw_ruler.of_createruler( )
of_movecontrols()

of_toolbar
toolbar = ab_switch
this.dw_toolbar.visible = ab_switch
of_movecontrols()

The of_spellcheckdialog and of_spellcheckauto functions are used to interact with the Sentry Spell Check DLL. The of_settoolbarstatus function sets the status of various toolbar items on the toolbar depending on the current selection in the rich edit control. See Listing 1 at the end of this article.

The of_movecontrols method repositions the rulerbar and richedit control based on the visible status of the toolbar and rulerbar.

of_movecontrols
IF ( rulerbar AND toolbar ) THEN
   rte.y = ( dw_ruler.height + dw_toolbar.height )
   dw_ruler.y = dw_toolbar.height
ELSEIF ( rulerbar AND NOT toolbar ) THEN
   rte.y = ( dw_ruler.height )
   dw_ruler.y = 0
ELSEIF ( NOT rulerbar AND toolbar ) THEN
   rte.y = ( dw_toolbar.height )
ELSEIF ( NOT rulerbar and NOT toolbar ) THEN
   rte.y = 0
END IF

rte.height = this.height - rte.y

Return 1

Implementaion - u_ruler
The u_ruler object is a descendant of the DataWindow control. It contains a blank DataWindow object with its units set to thousands of an inch. It contains one function (of_createruler), which is used to dynamically generate the lines and text that comprise the ruler. The created instance variable determines whether the ruler has been created already so subsequent calls to create it are bypassed. See Listing 2 at the end of this article. Implementation - u_toolbar The u_toolbar object is also a descendant of the DataWindow control. We chose to use a DataWindow rather than standard user objects for a number of reasons:

  • It reduces the amount of code we have to write. We monitor two events (itemchanged and clicked) to respond to all input from the user rather than having to code an event in each of a number of separate user objects.
  • It reduces resource requirements, since the DataWindow is rendered as only two controls at runtime rather than a number of separate user objects.
  • It gives us greater flexibility over the presentation of the toolbar. We wanted to implement the "Office XP theme" for the toolbar, where the toolbar buttons are flat, selected items have a border around them, and any item that the cursor is over is shaded (see Figure 6). We found that it was easier to implement this by triggering the visibility status of a series of picture controls on a DataWindow object than by using standard controls.

The downside to this approach is that the DataWindow control doesn't natively support tooltips for DataWindow controls. We used the tooltip user object (www.onkenhout.speedlinq.nl/pbtip015.html) from Aart Onkenhout (originally developed by Rui Cruz) to implement that missing functionality.

u_toolbar Local External Functions/Instance Variables
The u_toolbar object has one local external function declaration to the TrackMouseEvent Windows API method. That, one instance variables (ib_mouseover), and two instance constants (TME_LEAVE, WM_MOUSELEAVE) are used in a custom user event (mouseleave) to ensure that the background for the item the mouse was last over is turned back off when the mouse leaves the toolbar control. The other instance variables in this user object are associated with the implementation of the tooltip user object.

u_toolbar Events/Functions
The constructor event of the u_toolbar object calls an of_getfonts object method that populates the dropdown list box with the TrueType fonts on the user's system. It uses a modified version of the enumfonts PBNI sample that was made available by Sybase for PowerBuilder 9.

Each toolbar "command button" is implemented through three picture controls. One contains the actual picture for the toolbar item (a picture of a "B" for bold, etc.) in GIF format with a transparent background. The second picture control contains a transparent box and that picture is only visible when the particular toolbar item is "selected." The third picture control contains a solid box and that picture is only visible when the mouse is over the toolbar item.

More Stories By 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.

More Stories By 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.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.