Contents Up Previous Next

wxTextWindow: wxWindow

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
wxTextWindow::~wxTextWindow
wxTextWindow::Clear
wxTextWindow::Create
wxTextWindow::Copy
wxTextWindow::Cut
wxTextWindow::DiscardEdits
wxTextWindow::GetContents
wxTextWindow::GetInsertionPoint
wxTextWindow::GetLastPosition
wxTextWindow::GetLineLength
wxTextWindow::GetLineText
wxTextWindow::GetNumberOfLines
wxTextWindow::SetSelection
wxTextWindow::LoadFile
wxTextWindow::Modified
wxTextWindow::OnChar
wxTextWindow::Paste
wxTextWindow::PositionToXY
wxTextWindow::Remove
wxTextWindow::Replace
wxTextWindow::SaveFile
wxTextWindow::SetFont
wxTextWindow::SetEditable
wxTextWindow::SetInsertionPoint
wxTextWindow::SetInsertionPointEnd
wxTextWindow::ShowPosition
wxTextWindow::WriteText
wxTextWindow::XYToPosition
wxTextWindow::operator <<


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.


wxTextWindow::~wxTextWindow

void ~wxTextWindow(void)

Destructor. Deletes any stored text before deleting the physical window.


wxTextWindow::Clear

void Clear(void)

Clears the window and deletes the stored text.


wxTextWindow::Create

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.


wxTextWindow::Copy

Bool Copy(void)

Copies the selected text onto the clipboard.

Motif and Windows only.


wxTextWindow::Cut

Bool Cut(void)

Copies the selected text onto the clipboard, and then deletes the text from the window.

Motif and Windows only.


wxTextWindow::DiscardEdits

void DiscardEdits(void)

Resets the internal 'modified' flag as if the current edits had been saved.


wxTextWindow::GetContents

char * GetContents(void)

Gets a pointer to a newly allocated buffer containing the text window contents. Free the buffer with the C++ delete operator.


wxTextWindow::GetInsertionPoint

long GetInsertionPoint(void)

Gets the current insertion point.

Motif and XView only.


wxTextWindow::GetLastPosition

long GetLastPosition(void)

Gets the position representing the end of the text window contents.

Motif and XView only.


wxTextWindow::GetLineLength

int GetLineLength(long lineNo)

Gets the length of the specified line (starting from zero).


wxTextWindow::GetLineText

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.


wxTextWindow::GetNumberOfLines

int GetNumberOfLines(void)

Gets the number of lines in the text window buffer.


wxTextWindow::SetSelection

void SetSelection(long from, long to)

Selects the text between from and to.


wxTextWindow::LoadFile

Bool LoadFile(char * file)

Loads and displays the named file, if it exists. Success is indicated by a return value of TRUE.


wxTextWindow::Modified

Bool Modified(void)

Returns TRUE if the text has been modified.


wxTextWindow::OnChar

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.


wxTextWindow::Paste

Bool Paste(void)

Pastes text from the clipboard into the text window.

Motif and Windows only.


wxTextWindow::PositionToXY

long PositionToXY(long pos, long *x, long *y)

Converts given character and line position to a position.

Motif and Windows only.


wxTextWindow::Remove

void Remove(long from, long to)

Removes the text between from and to.


wxTextWindow::Replace

void Replace(long from, long to, char *value)

Replaces the text between from and to with value.


wxTextWindow::SaveFile

Bool SaveFile(char * file)

Saves the text in the named file. Success is indicated by a return value of TRUE.


wxTextWindow::SetFont

void SetFont(wxFont *font)

Sets the font for the text window.

Windows and Motif only.


wxTextWindow::SetEditable

void SetEditable(Bool editable)

Determines whether the text window is user-editable


wxTextWindow::SetInsertionPoint

void SetInsertionPoint(long pos)

Sets the current insertion point to pos.


wxTextWindow::SetInsertionPointEnd

void SetInsertionPointEnd(void)

Sets the current insertion point to the end of the text.

Motif and XView only.


wxTextWindow::ShowPosition

void ShowPosition(long pos)

Makes the line containing the given position visible.

Motif and XView only.


wxTextWindow::WriteText

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.


wxTextWindow::XYToPosition

long XYToPosition(long x, long y)

Converts given character and line position to a position.


wxTextWindow::operator <<

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";