Home |
Class PegTextBox HMI (Human-Machine Interface) Classes |
Class PegTextBoxPegTextBox is a multi-line text display control. PegTextBox is derived from PegWindow and PegTextThing, and therefore supports the functionality of both of these PEG classes. The font, color, size, scrolling mode and other parameters can be modified, giving PegTextbox a wide variety of appearances. By default, PegTextBox left-justifies the displayed text. Center-justification is also supported. Lines of text that are too long to fit in the client width of the textbox are also wrapped by default to use two or more lines. This is controlled by the EF_WRAP style flag. The wrapping algorithm searches for whitespace, comma, or hyphen characters as logical points to break long lines. If a suitable breaking point is not found, PegTextBox simply breaks a line at the last character which fits within the client width area. If a PegTextBox is used to display a long section of text that requires more vertical lines than are visible in the TextBox client area, you can use the SetScrollMode(WSM_AUTOVSCROLL) function to give the PegTextBox a vertical scroll bar. Internally, PegTextBox maintains a set of PEGUINT offsets into the block of text displayed by the PegTextBox window. These offsets are the starting character offsets corresponding to each line of text. This allows PegTextBox to quickly display new lines of text as the text is scrolled up and down. Only a fixed maximum number of offsets are calculated at any one time (default is 100). This window of line-start offsets slides up and down as the user scrolls the text in the window. You can access these line-start offsets if needed using member functions. In addition to scroll bars, PegTextBox catches PK_PGUP and PK_PKDN PM_KEY message to scroll the displayed text up and down page by page. PegTextBox does not allow user editing. The text data displayed in the textbox can only be modified via program control using the DataSet() or Append() member functions. For a full edit-style control, refer to PegEditBox. class PegTextBox : public PegWindow, public PegTextThing { public: PegTextBox(const PegRect &Rect, PEGUINT wId = 0, PEGUINT wStyle = FF_RECESSED | EF_WRAP | TJ_LEFT, PEGCHAR * Text = NULL, PEGUINT wMaxChars = 1000, PEGUINT wMaxLines = 100); virtual void Draw(void); virtual PEGINT Message(const PegMessage &Mesg); virtual void GetVScrollInfo(PegScrollInfo * Put); virtual void GetHScrollInfo(PegScrollInfo * Put); virtual void DataSet(const PEGCHAR * Text); virtual void Append(const PEGCHAR * pText, BOOL bDraw = TRUE); virtual void SetFont(PegFont * Font); virtual void Resize(PegRect NewSize); void RewindDataSet(const PEGCHAR * Text); int LineCount(void); PEGUINT GetTopLine(void); void SetTopLineToEnd(void); void SetTopLine(int iLine); PEGCHAR * GetLineStart(int iLine, int * pPutLen); PEGUINT GetLineIndex(int iLine); void CheckBufLen(int iLen); PEGUINT GetMaxChars(void); void SetMaxChars(PEGUINT wMax); PEGCHAR * FindLinePointer(int iLine); BOOL LineDown(void); BOOL LineUp(void); void MarkLine(int iMarkLine); }; Demo programs PegDemo and Notebook use this class. Style FlagsFF_NONE, FF_THIN, FF_RAISED, FF_RECESSED, FF_THICK, EF_WRAP, TT_COPY. ConstructorParameter wMaxChars is the maximum number of characters that the text box will be required to support. If more than this number of characters are assigned using the DataSet() function, the extra characters fall off the end. If more than this number of total characters are assigned using the Append() function, the oldest characters fall off the top. Parameter wMaxLines specifies the maximum number of lines the control will be able to display. The memory requirement of the text box grows with 4*wMaxLines bytes. Method AppendAppends the indicated text to the current text box string value. If the total number of text box chars >= the maximum number of chars, PegTextBox will remove the overflow characters from the start of the text box string. This operation facilitates creation of terminal style windows. Method CopyToScratchPadCopies the currently selected text to the scratch pad. Method DataSetPegTextBox overrides the DataSet function to reset any scroll bars and to recalculate line offsets. Method DeleteMarkedTextDeletes the currently selected text. Method DrawPegTextBox overrides the Draw() function to display the textbox border and text. Method FindLinePointerFinds the PEGCHAR at the start of the given line. If iLine is beyond the total number of lines, then the method returns NULL. Method GetLineIndexReturns the starting index into the total text string at which the text for line iLine begins. Method GetLineStartReturns a pointer to the indicated line of text. Programmers must remember that the textbox text lines are actually subsets of a larger text string, i.e. the returned string is not necessarily terminated at end of the requested line. If the pLength parameter is non-NULL, this function returns the number of characters (excluding \r or \n characters) displayed on this text line. Method GetMaxCharsReturns the maximum number of characters the text box will contain. Method GetTopLineReturns the index of the top line currently displayed in the textbox. Method GetVScrollInfoGetVScrollInfo makes the scroll bars operate relative to the contained text. Method GetHScrollInfoGetHScroll makes the scroll bars operate relative to the contained text. Method LineCountReturns the total number of lines contained in the textbox. This is the total number of lines available, as opposed to the number of lines actually visible. Method LineDownScrolls the textbox down one line under program control. Method LineUpScrolls the textbox up one line under program control. Method MarkLineMarks one line of text. The marked line of text will be displayed using the PCI_STEXT and PCI_SELECTED foreground and background colors. Method MessagePegTextBox catches several mouse and keyboard messages. Method PasteFromScratchPadPastes the scratch pad text at the current cursor position. Method ResizeRecalculates the layout of the displayed text lines. Method RewindDataSetAssigns the text string pText to the TextBox, and also resets the textbox to the top line. This is useful when the textbox content is changed, after the user may have scrolled the textbox down some number of lines. When this function is used the new text is always displayed from the start. Method SetFontRecalculates the layout of the displayed text lines. Method SetMaxCharsModifies the maximum number of characters the TextBox will allow. Method SetTopLineScrolls the textbox to the indicated line number under program control. If the requested line is too far down, i.e. past the last line of text, PegTextBox sets the top line such that the last line of text is visible at the bottom of the textbox client area. Method SetTopLineToEndScrolls the textbox down such that the last line of the textbox is visible. ExamplesThe following are each different styles of PegTextBox:
|