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

Text Selection Operations

  • of_getrtftext () returns string: Returns a string containing the contents of the control in RTF format
  • of_getselectedtext () returns string: Returns a string containing the currently selected text in plain text format
  • of_gettext () returns string: Returns a string containing the contents of the control in plain text format
  • of_gettextlength () returns long: Returns the length of the text in the control
  • of_setrtftext (string as_rtf) returns integer: Pastes the passed-in text into the control at the current location in the RTF format
  • of_setselection (long al_start, long al_end) returns integer: Sets the selected text in the control. Passing the same value for both arguments positions the cursor at that location without selecting text.
  • of_settext (string as_text, boolean ab_replace) returns integer: Pastes the passed-in text into the control in plain text format. The second parameter indicates whether the paste should occur at the current selection or if it should replace the contents of the entire control

Zoom Operations

  • of_getzoom () returns decimal: Returns the zoom factor as a percent (100 means 100%)
  • of_setzoom (decimal zoom) returns integer: Sets the zoom factor for the control. The value passed in is a percentage (100 is 100%)

Search and Replace Functions

  • of_findtext (string as_text) returns unsignedlong: Finds the first occurrence of the specified text in the control
  • of_findtext (string as_text, long al_pos) returns unsignedlong: Finds the first occurrence of the specified text in the control that occurs after the position indicated
  • of_searchandreplace (string as_oldtext, string as_newtext) returns integer: Replaces all occurrences of the indicated text with the replacement text

Miscellaneous Operations

  • of_setautourldetect () returns integer: Tells the control to monitor text input for URLs and automatically format them as hyperlinks
  • of_settypographyoptions (long al_options) returns integer: Sets advanced typography options for the control. This function has been provided, but is not used in our implementation.

The control also contains a number of functions (of_getnewparagraphpos, of_setnewparagraphmarks,and of_showparagraphmarks) intended to support functionality similar to the "ReturnsVisible" property on the PowerBuilder RichTextEdit control. However, the Microsoft Rich Edit control doesn't provide native support for such "show nonprinting characters" functionality. To date our implementation hasn't met with our expectations, and we may drop support for this functionality.

We don't have space in this article to go through every one of these functions. Many of them are both simple and similar, so we'll touch on a couple of them briefly for illustration. You can poke around in the sample code if you want to investigate how they all operate.

For example, the of_getselectedtext function (see below) simply sends the EM_GETSELTEXT message to the control and gets the text back in the fourth argument that's passed by reference.

of_getselectedtext
long l_rc
string ls_text
ls_text = Space ( 2000 )
l_rc = GetSelText ( Handle ( this ), EM_GETSELTEXT, 0, ls_text )
Return ls_text

The of_getstrikeout function (see below) is typical of the text and paragraph formatting functions. In the getter functions, a structure is returned from the message, and then a particular bit of a flag is checked to see if it's set. In the setter functions, the particular bit is set and then the message is called passing in the structure. A mask value is also used in the setter functions to tell the control which bit of the flag it should be examining. That lets us set a particular character or paragraph format without worrying about the values of the other bits of the flag.

of_getstrikeout
ulong l_rc
s_charformat CHARFORMAT

//Tell it we're using the older CHARFORMAT structure, not CHARFORMAT2
CHARFORMAT.cbsize = 60

l_rc = GetCharFormat ( Handle ( this ), em_getcharformat, scf_selection, CHARFORMAT )

//Check bit, turn strikeout on or off
IF of_bitwiseand(CHARFORMAT.dweffects, CFE_STRIKEOUT) = CFE_STRIKEOUT THEN
  Return TRUE
ELSE
  Return FALSE
END IF

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.