• No results found

Using the u_rte RichTextEdit control

In document pfcug (Page 169-174)

You use the PowerBuilder RichTextEdit control to enhance an application with word processing capabilities. The PFC u_rte control makes it easier for you to work with a RichTextEdit control. U_rte allows you to:

• Display new documents, optionally inserting them into the current document

• Insert pictures into documents, optionally displaying a dialog box prompting the user for the filename

Using standard visual user objects

• Print documents

• Add Find and Replace capabilities to a RichTextEdit control • Control text properties

For complete information on the PowerBuilder RichTextEdit control, see the PowerBuilder User’s Guide and Application Techniques.

Displaying rich text

documents U_rte provides events that allow the user to specify the rich text document to open: pfc_Open Replaces the current document with the selected document,

prompting the user before discarding the current document

pfc_InsertFile Inserts the selected document into the current document. The RichTextEdit control replaces the current selection when the file is inserted

You can also populate the RichTextEdit control by calling the PowerScript InsertDocument function.

v To display a document (replacing the current document): • Call the pfc_Open event:

rte_doc.Event pfc_Open()

v To insert a document into the current document: • Call the pfc_InsertFile function:

rte_doc.Event pfc_InsertFile()

The InsertDocument PowerScript function

You can also call the PowerScript InsertDocument function to display a document. If you use this function to display a file in an empty control, you must also call the of_SetFileName function to specify the name of the file associated with the RichTextEdit control.

Inserting pictures U_rte provides an event that displays a dialog box for the user to choose a bitmap to insert at the current cursor position. The RichTextEdit control replaces the current selection when the bitmap is inserted.

v To display the Insert Picture dialog box: • Call the pfc_InsertPicture event:

Tracking the picture’s filename

If you want to track the filename of the inserted picture, call the of_InsertPicture function instead of the pfc_InsertPicture event. Printing rich text

documents U_rte provides events that allow you to print the data in RichTextEdit controls. You can: • Display a Print dialog box, allowing you to choose options before printing

PFC uses the s_printdlgattrib structure to pass properties to the n_cst_platform of_PrintDlg function. You can use the pfc_PrePrintDlg event to further customize the contents of the Print dialog box by modifying elements in the s_printdlgattrib structure.

The values in the s_printdlgattrib structure reflect selected RichTextEdit Print properties (such as collate, page numbers, and number of copies). • Print a RichTextEdit control without displaying the Print dialog box U_rte also provides functions that allow you to control the printing of page numbers.

v To display the Print dialog box:

1 (Optional) Add code to the pfc_PrePrintDlg event to modify the information used by the pfc_PrintDlg function (this example provides a default for the number of copies specification):

astr_printdlg.l_copies = 1

2 Call the pfc_Print event:

rte_doc.Event pfc_Print()

v To print a RichTextEdit control without displaying the Print dialog box: • Call the pfc_PrintImmediate event:

rte_doc.Event pfc_PrintImmediate()

v To control the printing of page numbers:

1 (Optional) Specify the page number upon which page numbers should first appear. For example, many styles suppress the page number on the first page of a document:

Using standard visual user objects

2 Identify the name of the field into which PFC places the page number (this example assumes an input field named PAGENUM):

rte_doc.of_SetPageInputField("PAGENUM")

v To print continuous pages when sharing data with a DataWindow or DataStore:

1 Perform all the steps necessary for the RichText file to share data with the DataWindow or DataStore:

ids_empdata = CREATE n_ds

ids_empdata.DataObject = "d_sharerte" ids_empdata.of_SetTransObject(SQLCA) IF ids_empdata.Retrieve() = -1 THEN

MessageBox("Retrieve", "Retrieve error") END IF

rte_doc.DataSource(ids_empdata)

2 Call the of_SetContinuousPages function:

rte_doc.of_SetContinuousPages(TRUE)

3 Print the document:

rte_doc.Event pfc_Print( )

For more information on sharing data between a RichTextEdit control and a DataWindow or DataStore, see Application Techniques.

Using the RTE find

service U_rte features a find and replace service that you can use to enhance a RichTextEdit control. Once the service is enabled, PFC displays Find and Replace dialog boxes when the user selects Edit>Find or Edit>Replace from the menu bar of a menu that descends from the PFC m_master menu and the RichTextEdit control has focus.

You can also display Find and Replace dialog boxes programmatically.

v To display the Find dialog box: 1 Enable the Find service:

rte_doc.of_SetFind(TRUE)

2 Call the pfc_FindDlg event:

v To display the Replace dialog box: 1 Enable the Find service:

rte_doc.of_SetFind(TRUE)

2 Call the pfc_ReplaceDlg event:

rte_doc.Event pfc_ReplaceDlg()

Controlling text

properties U_rte allows you to access properties for selected text in a RichTextEdit control. This feature allows you to change a single property at a time, leaving the other properties as is. This differs from the PowerScript SetTextStyle function, which requires that you specify all possible text properties.

v To set text properties:

1 (Optional) Establish a mechanism that allows the user to specify text properties (the example ahead uses checkboxes).

2 Call the of_SetTextStylexxx functions to set text properties:

SetRedraw(FALSE) rte_doc.of_SetTextStyleBold(cbx_bold.Checked) rte_doc.of_SetTextStyleItalic(cbx_italic.Checked) rte_doc.of_SetTextStyleUnderline & (cbx_underline.Checked) rte_doc.of_SetTextStyleStrikeout & (cbx_strikeout.Checked) rte_doc.of_SetTextStyleSubscript & (cbx_subscript.Checked) rte_doc.of_SetTextStyleSuperscript & (cbx_superscript.Checked) SetRedraw(TRUE)

v To access text properties:

1 (Optional) Establish a mechanism that displays text properties (the example ahead uses checkboxes).

2 Call the of_GetTextStyle function:

n_cst_textstyleattrib lnv_style rte_doc.of_GetTextStyle & (lnv_style)

cbx_bold.Checked = lnv_style.ib_bold cbx_italic.Checked = lnv_style.ib_italic

Using standard visual user objects cbx_underline.Checked = & lnv_style.ib_underlined cbx_strikeout.Checked = lnv_style.ib_strikeout cbx_subscript.Checked = lnv_style.ib_subscript cbx_superscript.Checked = & lnv_style.ib_superscript

In document pfcug (Page 169-174)