PtText

PtText — A single-line or multi-line text entry/display field.

Synopsis

class PtText PtLabel
{
    columns;            // short  (Pt_ARG_COLUMNS)    
    cursor_position;    // short  (Pt_ARG_CURSOR_POSITION)    
    edit_mask;          // string  (Pt_ARG_EDIT_MASK)    
    max_length;         // short  (Pt_ARG_MAX_LENGTH)    
    text_flags;         // flag  (Pt_ARG_TEXT_FLAGS)    
}
		

Base Classes

PtWidget <-- PtBasic <-- PtLabel <-- PtText

Description

This widget is a box that accepts text entry and displays text strings. Its cursor toggles between insert and replace modes, and can be used to select ranges of text. Possible callbacks include text changes, cursor movements, and pressing the Enter key.

[Note]

For detailed information, please refer to PtText in the Photon documentation.

Instance Variables

columns

An integer specifying the width of the widget in columns, where each column is the width of the character 'M'. This variable will take effect only if the dim variable for the widget is set to nil.

cursor_position

An integer specifying the number of characters to the left of the cursor. Default is -1.

edit_mask

This variable is not currently implemented.

max_length

An integer specifying the maximum number of characters the widget will accept.

text_flags

This instance variable controls certain characteristics of the widget, and may be a combination of zero or more of the following flags:

ConstantDescription
Pt_CURSOR_VISIBLEMakes the cursor as visible. Default is ON.
Pt_EDITABLEMakes the text editable. Default is ON.
Pt_INSERT_MODEToggles between insert and replace modes. Default is insert.
Pt_TEXT_AUTO_HIGHLIGHTHighlights text when widget has focus. Default is OFF.
Pt_CHANGE_ACTIVATEInternal informational bit.
Pt_EDIT_ACTIVATEInternal informational bit.
Pt_TEXT_FULLInternal informational bit.
Pt_NO_RANGE_SELECTIONInternal informational bit.
Pt_RESIZE_WIDTHInternal informational bit.
Pt_TEXT_RANGE_ACTIVEInternal informational bit.
Pt_TEXT_CHANGEDInternal informational bit.

Callbacks

The following callbacks are associated with this widget:

CallbackDescription
Pt_CB_MODIFY_VERIFYThis callback is generated when a text string is going to be changed.
Pt_CB_TEXT_CHANGEDThis callback is generated when the text string value changes (same as modify_notify.
Pt_CB_MODIFY_NOTIFYThis callback is generated when the text string value changes (same as text_changed.
Pt_CB_MOTION_VERIFYThis callback is generated when the cursor position is going to be changed.
Pt_CB_MOTION_NOTIFYThis callback is generated when the cursor position has changed.

Associated Classes

PtComboBox, PtCallbackInfo, PtTextCallback

Convenience Functions

Arguments

widgetA PtText widget.
startThe start of the selected text.
endThe end of the selected text.

Functions

These functions are extensions of QNX Photon functions. You can refer to the PtText function documentation in QNX Helpviewer for more information about them.

numchars = PtTextGetSelection (widget) -- gets a range of text previously selected with PtTextSetSelection.

Returns the number of characters selected, or -1 to indicate that the widget is not a PtText widget.

numchars = PtTextSetSelection (widget, start, end) -- Selects text specified by start and end. If start and end are equal to each other, or if they are both greater than the number of characters in the widget, this function may return 0.

Returns the number of characters selected, or -1 to indicate that the widget is not a PtText widget.

Example

This example, ex_PtText.g, is included in the product distribution.

#!/usr/cogent/bin/phgamma

/*
 * This example puts 3 PtText widgets into a window.
 * The first PtText widget allows for text entry.  Its width is
 * specified at 12 columns (M_width), and maximum length is 15
 * characters. The second PtText widget displays the cursor
 * position in the first PtText widget.  The third PtText widget
 * displays the text entered when the Enter key is pressed in the
 * first widget.
 */
require_lisp("PhotonWidgets.lsp");
require_lisp("PhabTemplate.lsp");
PtInit(nil);

wfile = PhabReadWidgetFile (string(_os_, "-WidgetFiles/wgt/text.wgtw"));
window = PhabCreateWidgets(wfile, nil, nil);

win = PhabLookupWidget(window,#text,nil);
tx1 = PhabLookupWidget(window,#PtText1,nil);
tx2 = PhabLookupWidget(window,#PtText2,nil);
tx3 = PhabLookupWidget(window,#PtText3,nil);
ebut = PhabLookupWidget(window,#TextButtonExit,nil);

/*
 * Specify the characteristics of the PtText widgets.
 */
tx1.dim = nil;
tx1.columns = 12;
tx1.max_length = 15;
tx2.text_flags = cons(Pt_EDITABLE, nil);
tx3.text_flags = cons(Pt_EDITABLE, nil);

/*
 * Attach callbacks for text changes, cursor motion, and pressing
 * the Enter key.
 */
PtAttachCallback(tx1, Pt_CB_TEXT_CHANGED,
                 #entry = tx1.text_string);

PtAttachCallback(tx1, Pt_CB_MOTION_NOTIFY,
                 #tx2.text_string = string(tx1.cursor_position));	 

PtAttachCallback(tx1, Pt_CB_ACTIVATE, #tx1.text_string = "");
PtAttachCallback(tx1, Pt_CB_ACTIVATE, #tx2.text_string = "");
PtAttachCallback(tx1, Pt_CB_ACTIVATE, #tx3.text_string = entry);
PtAttachCallback(ebut, Pt_CB_ACTIVATE, #exit_program(1));

PtRealizeWidget(win);
PtMainLoop();