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

u_richedit - Functions/Events
There's only one event coded on the u_richedit object, a streamout event mapped to pbm_custom01 that's part of the callback support mentioned above. We'll discuss that one further when we talk about the custom DLL used to implement it.

There are a number of helper functions declared on the userobject that are only used internally. A number of the Windows API messages we're using require the setting or reading of specific bits of a flag being sent to or returned by the message. Since PowerBuilder doesn't provide native bit functions, we've borrowed heavily from the of_getbit and of_bitwiseand functions of the PowerBuilder Foundation Classes (PFC). Those methods were modified to handle larger datatypes than the original PFC methods were written to handle. One of the other helper functions is of_streamout. As this is the function that involved the message to the control that requires a callback, we'll discuss that when we talk about the custom DLL we wrote to support it.

The remaining helper function is of_seteventmask. Microsoft made a number of notification messages from the Rich Edit Control optional. To enable them so you get those notifications, you must send the EM_SETEVENTMASK message to the control and set the fourth argument of the message to the message ID of the message you want to get. In our implementation, we wanted to get the EN_SELCHANGE message, which is sent in response to the user changing the selection in the control. We respond to that notification by setting the toolbar item statuses based on the current selected text, much the way Word does. One issue with such notification is that once enabled Windows sends the notification message to the parent window of the control, not to the control itself! We address that through another Windows API function requiring a callback implemented in the wrapper u_rte object. That callback is provided by the custom DLL we've written, so we'll discuss this further when we discuss that DLL.

The remaining functions are used to implement the functionality you'd expect from a rich edit control (text formatting, etc.). Most of these are implemented through the toolbar and/or context popup menu.

Edit Operations

  • of_clear () returns integer: Clears the selected text
  • of_copy () returns integer: Copies the selected text into the clipboard as plain text
  • of_copyrtftext () returns integer: Copies the selected text into the clipboard in RTF format
  • of_cut () returns integer: Copies the selected text into the clipboard as plain text and clears the selected text
  • of_paste () returns integer: Pastes the contents of the clipboard into the control at the selected point
  • of_undo () returns integer: Undoes the last operation

Character Formatting Operations

  • of_getbold () returns boolean: Indicates whether the selected text is bolded
  • of_getfontface () returns string: Returns the name of the font face for the currently selected text
  • of_getfontsize () returns integer: Returns the size of the currently selected text in points
  • of_getitalic () returns boolean: Indicates whether the selected text is in italics
  • of_getstrikeout () returns boolean: Indicates whether the currently selected text is struck out
  • of_gettextcolor () returns long: Returns an RGB value indicating the color of the selected text
  • of_getunderline () returns boolean: Indicates whether the selected text is underlined
  • of_setbold () returns integer: Sets the currently selected text to bold
  • of_setdefaults (string as_fontname, integer ai_fontsize) returns integer: Sets the default font face and size for the control
  • of_setfontface (string as_fontname) returns integer: Sets the font face for the currently selected text
  • of_setfontsize (integer ai_fontsize) returns integer: Sets the font size for the currently selected text
  • of_setitalic () returns integer: Sets the currently selected text to italics
  • of_setstrikeout () returns integer: Sets the currently selected text to strike out
  • of_setunderline () returns integer: Underlines the currently selected text

Character Formatting Dialogs

  • of_choosefont () returns (none): Displays the Windows API ChooseFont dialog and sets the font characteristics to those selected in the dialog
  • of_settextcolor () returns integer: Displays the PowerScript ChooseColor dialog and sets the font color to that selected in the dialog

Paragraph Formatting Operations

  • of_getalign () returns integer: Returns an enumerated value indicating the alignment of the paragraph of the currently selected text. The result can be compared to the PFA_LEFT, PFA_RIGHT, PFA_CENTER, and PFA_JUSTIFY instance constants for the control.
  • of_getlinespacing () returns integer: Returns an enumerated value indicating the line spacing of the paragraph of the currently selected text. The result can be compared to the PFS_SINGLE, PFS_ONEANDAHALF, and PFS_DOUBLE instance constants for the control.
  • of_setaligncenter () returns integer: Sets the alignment of the paragraph of the currently selected text to center.
  • of_setalignjustify () returns integer: Sets the alignment of the paragraph of the currently selected text to full justification
  • of_setalignleft () returns integer: Sets the alignment of the paragraph of the currently selected text to the left
  • of_setalignright () returns integer: Sets the alignment of the paragraph of the currently selected text to the right
  • of_setlinespacedouble () returns integer: Sets the line spacing of the paragraph of the currently selected text to double
  • of_setlinespaceonehalf () returns integer: Sets the line spacing of the paragraph of the currently selected text to one and a half
  • of_setlinespacesingle () returns integer: Sets the line spacing of the paragraph of the currently selected text to single

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.