A text window is a subwindow of a frame (or a panel, on some platforms), offering some basic ability to display scrolling text. Editing is possible under all platforms, but if editing is required under Windows, the wxNATIVE_IMPL style should be included. This is because the default implementation is a read-only text window that can display more than the 64K or so of text allowed using the standard edit control.
Some manipulation functions take integer positions, starting from zero.
Many of these functions are currently platform-specific, and have yet to be fully implemented or tested.
For compilers other than Borland C++, this class also derives from streambuf. You can then use instances of wxTextWindow for the usual ostream operations, for example:
wxTextWindow *textwin = new wxTextWindow(...); ostream stream(textwin); stream << "Hello! C++ streams are neat." << endl;wxTextWindow::wxTextWindow
void wxTextWindow(void)
Constructor, for deriving classes.
void wxTextWindow(wxWindow *parent, int x = -1, int y = -1,
int width = -1, int height = -1, long style = 0, char *name = "textWindow")
Constructor.
Under Windows and Motif, the parent can be either a frame or panel. Under XView, the parent must be a frame.
The parameters x, y, width and height can be omitted on construction if the position and size will later be set (for example by a application frame's OnSize callback, or if there is only one subwindow for the frame, in which case the subwindow fills the frame).
style is a bit list of some of the following:
wxBORDER | Use this style to draw a thin border in MS Windows (non-native implementation only). |
wxNATIVE_IMPL | Use this style to allow editing under MS Windows, albeit with a 64K limitation. |
wxREADONLY | Use this style to disable editing. |
wxHSCROLL | Use this style to enable a horizontal scrollbar, or leave it out to allow line wrapping. Windows and Motif only. |
The name parameter is used to associate a name with the item, allowing the application user to set Motif resource values for individual text windows.
void ~wxTextWindow(void)
Destructor. Deletes any stored text before deleting the physical window.
void Clear(void)
Clears the window and deletes the stored text.
Bool Create(wxWindow *parent, int x = -1, int y = -1,
int width = -1, int height = -1, long style = 0, char *name = "textWindow")
Creates the text item for two-step construction. Derived classes should call or replace this function. See wxTextWindow::wxTextWindow for further details.
Bool Copy(void)
Copies the selected text onto the clipboard.
Motif and Windows only.
Bool Cut(void)
Copies the selected text onto the clipboard, and then deletes the text from the window.
Motif and Windows only.
void DiscardEdits(void)
Resets the internal 'modified' flag as if the current edits had been saved.
char * GetContents(void)
Gets a pointer to a newly allocated buffer containing the text window contents. Free the buffer with the C++ delete operator.
long GetInsertionPoint(void)
Gets the current insertion point.
Motif and XView only.
long GetLastPosition(void)
Gets the position representing the end of the text window contents.
Motif and XView only.
int GetLineLength(long lineNo)
Gets the length of the specified line (starting from zero).
int GetLineText(long lineNo, char *buffer)
Puts the contents of the specified line (starting from zero) into the given buffer, returning the number of characters copied.
int GetNumberOfLines(void)
Gets the number of lines in the text window buffer.
void SetSelection(long from, long to)
Selects the text between from and to.
Bool LoadFile(char * file)
Loads and displays the named file, if it exists. Success is indicated by a return value of TRUE.
Bool Modified(void)
Returns TRUE if the text has been modified.
void OnChar(wxKeyEvent& event)
In Motif and Windows, it is possible to intercept character input by overriding this member. Call this function to let the default behaviour take place; not calling it results in the character being ignored. You can replace the keyCode member of event to translate keystrokes.
Note that Windows and Motif have different ways of implementing the default behaviour. In Windows, calling wxTextWindow::OnChar immediately processes the character. In Motif, calling this function simply sets a flag to let default processing happen. This might affect the way in which you write your OnChar function on different platforms.
Under Windows, the wxNATIVE_IMPL flag must be passed to the wxTextWindow constructor if overriding OnChar is to have any effect.
See wxEvtHandler::OnChar and wxKeyEvent for more details of the keystroke event.
Bool Paste(void)
Pastes text from the clipboard into the text window.
Motif and Windows only.
long PositionToXY(long pos, long *x, long *y)
Converts given character and line position to a position.
Motif and Windows only.
void Remove(long from, long to)
Removes the text between from and to.
void Replace(long from, long to, char *value)
Replaces the text between from and to with value.
Bool SaveFile(char * file)
Saves the text in the named file. Success is indicated by a return value of TRUE.
void SetFont(wxFont *font)
Sets the font for the text window.
Windows and Motif only.
void SetEditable(Bool editable)
Determines whether the text window is user-editable
void SetInsertionPoint(long pos)
Sets the current insertion point to pos.
void SetInsertionPointEnd(void)
Sets the current insertion point to the end of the text.
Motif and XView only.
void ShowPosition(long pos)
Makes the line containing the given position visible.
Motif and XView only.
void WriteText(char * text)
Writes the text into the text window. Presently there is no means of writing text to other than the end of the existing text. Newlines in the text string are the only control characters allowed, and they will cause appropriate line breaks. See << for more convenient ways of writing to the window.
long XYToPosition(long x, long y)
Converts given character and line position to a position.
wxTextWindow& operator <<(char *s)
wxTextWindow& operator <<(int i)
wxTextWindow& operator <<(long i)
wxTextWindow& operator <<(float f)
wxTextWindow& operator <<(double d)
wxTextWindow& operator <<(char c)
Operator definitions for writing to a text window, for example:
wxTextWindow *wnd = new wxTextWindow(my_frame); (*wnd) << "Welcome to text window number " << 1 << ".\n";