wxWidgets: wxTextWrapper Class Reference

| Version: 3.1.5

Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
wxTextWrapper Class Referenceabstract
Class List by Category » Graphics Device Interface (GDI)

`#include </cygdrive/c/Users/Hamis/Cygwin-packaging/wxWidgets3.1/wxWidgets3.1-3.1.5-3.x86_64/src/wxWidgets-3.1.5/interface/wx/textwrapper.h>`

## Detailed Description

Helps wrap lines of text to given width.

This is a generic purpose class which can be used to wrap lines of text to the specified width. It doesn't do anything by itself but simply calls its virtual OnOutputLine() and OnNewLine() methods for each wrapped line of text, you need to implement them in your derived class to actually do something useful.

Here is an example function using this class which inserts hard line breaks into a string of text at the positions where it would be wrapped:

wxString WrapText(wxWindow *win, const wxString& text, int widthMax)
{
class HardBreakWrapper : public wxTextWrapper
{
public:
HardBreakWrapper(wxWindow *win, const wxString& text, int widthMax)
{
Wrap(win, text, widthMax);
}
wxString const& GetWrapped() const { return m_wrapped; }
protected:
virtual void OnOutputLine(const wxString& line)
{
m_wrapped += line;
}
virtual void OnNewLine()
{
m_wrapped += '\n';
}
private:
wxString m_wrapped;
};
HardBreakWrapper wrapper(win, text, widthMax);
return wrapper.GetWrapped();
}
wxString
String class for passing textual data to or receiving it from wxWidgets.
Definition string.h:315
wxTextWrapper::OnOutputLine
virtual void OnOutputLine(const wxString &line)=0
Called by Wrap() for each wrapped line of text.
wxTextWrapper::OnNewLine
virtual void OnNewLine()
Called at the start of each subsequent line of text by Wrap().
wxTextWrapper::wxTextWrapper
wxTextWrapper()
Trivial default constructor.
wxTextWrapper::Wrap
void Wrap(wxWindow *win, const wxString &text, int widthMax)
Wrap the given text.
wxWindow
wxWindow is the base class for all windows and represents any visible object on screen.
Definition window.h:346

##

Library: None; this class implementation is entirely header-based.

<>< =''>:</>&;&;< =''>\ </></>

## Public Member Functions
| wxTextWrapper ()
| Trivial default constructor.
void | Wrap (wxWindow *win, const wxString &text, int widthMax)
| Wrap the given text.

## Protected Member Functions
virtual void | OnOutputLine (const wxString &line)=0
| Called by Wrap() for each wrapped line of text.
virtual void | OnNewLine ()
| Called at the start of each subsequent line of text by Wrap().

## Constructor & Destructor Documentation

## ◆ wxTextWrapper()

wxTextWrapper::wxTextWrapper | ( |  | ) |

Trivial default constructor.

## Member Function Documentation

## ◆ OnNewLine()

virtual void wxTextWrapper::OnNewLine | ( |  | ) |
| protectedvirtual

Called at the start of each subsequent line of text by Wrap().

This method may not be called at all if the entire text passed to Wrap() fits into the specified width.

## ◆ OnOutputLine()

virtual void wxTextWrapper::OnOutputLine | ( | const wxString & | line | ) |
| protectedpure virtual

Called by Wrap() for each wrapped line of text.

This method will always be called at least once by Wrap(). Notice that line may be empty if the text passed to Wrap() was empty itself.

## ◆ Wrap()

void wxTextWrapper::Wrap | ( | wxWindow * | win,
|  | const wxString & | text,
|  | int | widthMax )

Wrap the given text.

This method will call OnOutputLine() for every line of wrapped text and OnNewLine() before the beginning of every new line after the first one (so it might be never called at all if the width of entire text is less than widthMax).

Parameters

  win | A non-NULL window used for measuring the text extents.
  text | The text to wrap.
  widthMax | Maximal width of each line of text or `-1` to disable wrapping.