CNativeTextEditis the abstract text editing class that provides functionality for native text edit boxes. The
CViewrepresents text edit objects, allowing the user to display text inside views, type in text, and perform the usual cut, paste, and copy operations. All
CNativeTextEditobjects inherit the properties of
CView, such as sizing, dragging, and so on. As an abstract class,
CNativeTextEditrepresents a rectangular text edit area on the screen and provides basic text manipulation methods. There is no concept of lines, paragraphs, or scrolling at this level. These text properties are embodied in the various classes that are derived from
CNativeTextEdit, classes that represent the different types of text editing systems available in XVT-Power++.
||The native view|
||The maximum number of characters|
||The right margin, counted from the left|
||A temporary font used in creation; this data member is not maintained and is not valid after construction|
||The tab spacing|
Keeps count of nested |
||Command sent when the text edit receives keyboard focus|
||Command sent when the text edit loses keyboard focus|
||Command sent when text is changed by the user or programatically|
||Whether there is auto selection|
||The window needs updating|
theAttributes = TX_BORDER,
UNITS theRightMargin = 1000,
int theCharactedLimit = 1000,
const CStringRW theInitialText = NULLString,
BOOLEAN isAutoSelected = FALSE,
BOOLEAN isVisible = TRUE,
GLUETYPE theGlue = NULLSTICKY);
theAttributesare shown in Table 10.
|Constants||Operation of the Text Edit Object|
|Enables horizontal automatic scrolling when the user drags the mouse outside of the view rectangle.|
|Enables vertical automatic scrolling|
|Draws a rectangular border around the view rectangle.|
|Disables the text edit system.|
|Leaves the clear item in the Edit menu always enabled.|
|Sets text to invisiblility.|
|Does not enable the Copy command on the Edit menu.|
|Does not enable the Cut command on the edit menu.|
|Prevents the text editing system from changing the menu of the window containing the text editing object. This attribute is useful if there is no Edit menu. If a CNativeTextEdit object is placed in a window without a menubar, TX_NOMENU must be used.|
|Does not enable the Paste command on the Edit menu.|
|Limits editing to one paragraph; ignores carriage returns.|
|Enables "overtype" mode that allows users to replace existing characters when typing instead of inserting characters in front of existing text.|
|Does not allow changes to the text except from the application program.|
|Enables word wrap to the margin.|
theRightMarginis a pixel measurement of the right margin, starting from the left side and beginning at zero (0). In addition, there is a parameter that sets the default character limit at 1,000 characters.
theInitialTextis a string containing any text you may wish to initialize with the text edit system. If the
isAutoSelectedparameter is set to
TRUE, all of the text in the text edit box becomes selected when the user clicks inside the box. Finally, this initializer, like the initializers of all
CViewclasses, takes a visibility state and a glue type.
virtual void SetText(const CStringRW& theText);
SetTextsets the text for the text edit box. Any text already inside the box is replaced. This method sets the text to be exactly what is passed in.
virtual BOOLEAN Append(const CStringRW& theText);
Appendappends this string to whatever text is already inside a text edit object. This method returns a
TRUEif the append operation succeeds.
virtual CStringRW GetText(void) const;
virtual T_CNUM GetNCharInText(void) const;
virtual void SelectText(void);
virtual CStringRW GetSelectedText(void) const;
GetText, except that is applies to selected text. That is, it returns a string containing all selected text in the edit box.
virtual T_CNUM GetNCharInSelection(void) const;
virtual BOOLEAN Clear(void);
virtual BOOLEAN IsEmpty(void) const;
virtual void SetAttribute(
unsigned theAttribute,BOOLEAN isSet=TRUE);
BOOLEANvalue indicating whether to turn this attribute on or off. For further information about XVT Portability Toolkit attributes, see the initializer method
. Also, see the text editing chapter of the XVT Portability Toolkit Guide.
virtual unsigned long GetAttributes(void) const;
virtual void SetLimit(int theCharacterLimit);
TX_ONEPARattribute is set. This method sets the limit on the number of characters the paragraph, and therefore the entire text box, can contain. If you set a new limit and the text box already contains more characters than the newly set limit, the text is not truncated. For example, if you set a new limit of 400 characters for a text box that already contains 600 characters, then the 600 characters remain. However, no more text can be entered into the box.
virtual int GetLimit(void) const;
virtual void SetMargin(UNITS theRightMargin);
theRightMarginis a pixel measurement of the right margin, starting from the left side and beginning at zero (0). If the text edit object has a horizontal scrollbar, this method resets the scrollbar's range according to the new margin.
virtual UNITS GetMargin(void) const;
virtual void Reset(void);
virtual void Suspend(void);
virtual void Resume(void);
virtual void DoHit(CONTROL_INFO theControlInfo);
DoHit()in response to an
E_CONTROLmessage. These occur for such events as focus change and typing in the text edit.
virtual void SetFocusCommands(
virtual void SetTextCommand(long theTextCommand);
long GetTextCommand( void ) const;
long GetKeyFocusCommand(void) const;
long GetKeyFocusLostCommand(void) const;
virtual int Validate(int theKey,
theKeyis the ASCII value for the character key that was pressed;
isControlKeyindicate whether the Shift or Control key was pressed in conjunction with the character key.
Validateresponds to a keyboard event in one of three ways:
Validateaccepts the keyboard event and returns
theKeyas the ASCII value of the character to be placed in the text edit system.
Validaterejects the keyboard event by returning
Validateseeks to modify the keyboard event by returning the ASCII value of the character it wishes to pass on to the text edit system.
To see how
Validateworks, think of implementing a password text box. When the user enters a login name,
Validatewould behave as in case 1 by permitting the characters being typed to appear on the screen. However, when the user enters a password,
Validatemay choose to modify the input by returning an asterisk (*) for each event received. In addition,
Validatemay behave as in case 2, ignoring all tabs by returning
Override this method to implement the kind of text validation described here. By default, this method always returns the exact key that it receives.
virtual void PostValidate();
DoHit()detects a change in text content, it calls
PostValidate(). The text edit implementation uses the
CValidatorassociated with the text edit (if any) to perform standard validation of the modified text.
void SetTabSize(int theSize);
int GetTabSize(void) const;
virtual void Key(const CKey& theKey);
thekeyrepresents the character key that was pressed, including whether the Shift or Control key was pressed at the same time. This method calls
Validateto allow the user to validate the key before actually passing it on to the text edit system.
virtual void SetOrigin(const CPoint& theDelta);
theDeltaPointto it. Suppose, for example, that a text box has an origin of 10,20 and you want to shift the origin by three pixels to the right. You set the origin by giving it a delta point of 3,0, which shifts the view three pixels horizontally.
virtual void SetFont(const CFont &theNewFont,
BOOLEAN isUpdate = FALSE);
isUpdateparameter indicates whether this
SetFontmessage is simply an update message or whether it is a "real"
SetFontmessage meaning that the text box should set its own font to the new font.
virtual void Size(const CRect& theNewSize);
theNewSize, like the region that is passed in on creation of a text box, is relative to the enclosure.
virtual void Show(void);
virtual void Hide(void);
virtual void Activate(void);
virtual void Deactivate(void);
virtual void Draw(const CRect& theClippingRegion);
theClippingRegionis the part of the text box that needs to be drawn.
virtual void SetGlue(GLUETYPE theGlue);
NULLSTICKYupon creation. For a listing of valid glue types, see the list under
virtual BOOLEAN ClassCanGetKeyFocus(void) const;
virtual void Disable(void);
virtual void SetEnvironment(const CEnvironment& theNewEnvironment, BOOLEAN isUpdate = FALSE);
theNewEnvironmentthat is passed to it. By default, text boxes share their enclosure's environment. However, as soon as you use
SetEnvironmentto give a text box an environment of its own, the text box uses that environment instead of the shared environment.
virtual void DoCommand(long theCommand,
void* theData = NULL);
TXEDIT GetXVTTextEdit(void) const;
const CRect& theRegion,
unsigned theAttributes = TX_BORDER,
UNITS theRightMargin = 1000,
int theCharacterLimit = 1000);
theEnclosureis a pointer to the subview that will contain the text box. theRegion is a coordinate location, local to the enclosure, that is used to place the text box. If the text box has a border, which is the default, then the border rectangle is drawn around the
CRectobject is inset by 4 pixels inside the border. The bottom of the
CRectmay be inset even more to ensure that an integral number of lines will fit into the text box.
In addition, this constructor takes an unsigned value pertaining to the XVT Portability Toolkit attributes that the text edit system can have. These attributes can be OR'd and passed in together, as described in the Text Edit section of the "Controls" chapter of the XVT Portability Toolkit Guide. For further information about the XVT Portability Toolkit attributes, see
. Finally, this constructor takes a right margin for the text box, which is measured in logical units starting with zero (0) at the left side of the text box, and a limit on the number of characters that can fit into the text box.
CNativeTextEdit(const CNativeTextEdit& theTextEdit);
CNativeTextEdit& operator= (
const CNativeTextEdit& theTextEdit);
void GetTextInternal(T_PNUM theFirstParagraph,
CStringRW theTextBuffer) const;
GetText, but it performs the actual calculations within the text editing system.
GetTextInternaltakes the numbers of the first and last paragraphs, the numbers of the first and last lines, and the numbers of the first and last characters. Then it appends the text mapped out by these parameters to any text already contained in the given string buffer.
T_CNUM GetNCharInternal(T_PNUM theFirstParagraph,
T_CNUM theLastChar) const;
GetNCharInternaltakes the numbers of the first and last paragraphs, the numbers of the first and last lines, and the numbers of the first and last characters. Then it counts all the characters in the chunk of text mapped out by these parameters.
void GetFullPar(T_PNUM theParagraph,
CStringRW theText) const;
void GetLineInternal(T_PNUM theParagraph,
T_LNUM theLine, CStringRW theText) const;
void Truncate(CStringRW& theText);
virtual void UpdateUnits(CUnits* theUnits);
CUnitsobject indicated by
theUnits, which is the
CUnitsobject owned by the
CNativeTextEditobject, that is, an object inheriting from
CNativeTextEdit. For more information, see
virtual void PositionTextEdit(void);
virtual void DoUpdateModel(long theControllerId,
long theCommand, const CModel* theModel);
void TdiProcessEvent(EVENT* e);
void GetPartLine(T_CNUM theFirstChar,
CStringRW theText) const;
void GetPartPar(T_CNUM theStartChar,T_CNUM theEndChar,
CStringRW theText) const;
T_CNUM GetNCharInPartPar(T_CNUM theStartChar,
T_LNUM theEndLine) const;