extracted wxTextWrapper in its own header and made it public
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60848 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -841,6 +841,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
|
|||||||
wx/textctrl.h
|
wx/textctrl.h
|
||||||
wx/textdlg.h
|
wx/textdlg.h
|
||||||
wx/textentry.h
|
wx/textentry.h
|
||||||
|
wx/textwrapper.h
|
||||||
wx/toolbar.h
|
wx/toolbar.h
|
||||||
wx/validate.h
|
wx/validate.h
|
||||||
wx/valtext.h
|
wx/valtext.h
|
||||||
|
@@ -342,6 +342,7 @@ All (GUI):
|
|||||||
- Building OpenGL library is now enabled by default.
|
- Building OpenGL library is now enabled by default.
|
||||||
- Improve wxTreeCtrl::ScrollTo() in generic version (Raanan Barzel).
|
- Improve wxTreeCtrl::ScrollTo() in generic version (Raanan Barzel).
|
||||||
- Added wxDC::CopyAttributes() and use it in wxBufferedDC.
|
- Added wxDC::CopyAttributes() and use it in wxBufferedDC.
|
||||||
|
- Added wxTextWrapper helper class useful for wrapping lines of text.
|
||||||
|
|
||||||
MSW:
|
MSW:
|
||||||
|
|
||||||
|
@@ -14,61 +14,6 @@
|
|||||||
|
|
||||||
#include "wx/window.h"
|
#include "wx/window.h"
|
||||||
|
|
||||||
#if wxUSE_STATTEXT
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// wxTextWrapper
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// this class is used to wrap the text on word boundary: wrapping is done by
|
|
||||||
// calling OnStartLine() and OnOutputLine() functions
|
|
||||||
class wxTextWrapper
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
wxTextWrapper() { m_eol = false; }
|
|
||||||
|
|
||||||
// win is used for getting the font, text is the text to wrap, width is the
|
|
||||||
// max line width or -1 to disable wrapping
|
|
||||||
void Wrap(wxWindow *win, const wxString& text, int widthMax);
|
|
||||||
|
|
||||||
// we don't need it, but just to avoid compiler warnings
|
|
||||||
virtual ~wxTextWrapper() { }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
// line may be empty
|
|
||||||
virtual void OnOutputLine(const wxString& line) = 0;
|
|
||||||
|
|
||||||
// called at the start of every new line (except the very first one)
|
|
||||||
virtual void OnNewLine() { }
|
|
||||||
|
|
||||||
private:
|
|
||||||
// call OnOutputLine() and set m_eol to true
|
|
||||||
void DoOutputLine(const wxString& line)
|
|
||||||
{
|
|
||||||
OnOutputLine(line);
|
|
||||||
|
|
||||||
m_eol = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// this function is a destructive inspector: when it returns true it also
|
|
||||||
// resets the flag to false so calling it again woulnd't return true any
|
|
||||||
// more
|
|
||||||
bool IsStartOfNewLine()
|
|
||||||
{
|
|
||||||
if ( !m_eol )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
m_eol = false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool m_eol;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // wxUSE_STATTEXT
|
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
wxMARKUP_ENTITY_AMP,
|
wxMARKUP_ENTITY_AMP,
|
||||||
|
68
include/wx/textwrapper.h
Normal file
68
include/wx/textwrapper.h
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: wx/textwrapper.h
|
||||||
|
// Purpose: declaration of wxTextWrapper class
|
||||||
|
// Author: Vadim Zeitlin
|
||||||
|
// Created: 2009-05-31 (extracted from dlgcmn.cpp via wx/private/stattext.h)
|
||||||
|
// RCS-ID: $Id$
|
||||||
|
// Copyright: (c) 1999, 2009 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||||
|
// Licence: wxWindows licence
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef _WX_TEXTWRAPPER_H_
|
||||||
|
#define _WX_TEXTWRAPPER_H_
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxTextWrapper
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// this class is used to wrap the text on word boundary: wrapping is done by
|
||||||
|
// calling OnStartLine() and OnOutputLine() functions
|
||||||
|
class wxTextWrapper
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxTextWrapper() { m_eol = false; }
|
||||||
|
|
||||||
|
// win is used for getting the font, text is the text to wrap, width is the
|
||||||
|
// max line width or -1 to disable wrapping
|
||||||
|
void Wrap(wxWindow *win, const wxString& text, int widthMax);
|
||||||
|
|
||||||
|
// we don't need it, but just to avoid compiler warnings
|
||||||
|
virtual ~wxTextWrapper() { }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// line may be empty
|
||||||
|
virtual void OnOutputLine(const wxString& line) = 0;
|
||||||
|
|
||||||
|
// called at the start of every new line (except the very first one)
|
||||||
|
virtual void OnNewLine() { }
|
||||||
|
|
||||||
|
private:
|
||||||
|
// call OnOutputLine() and set m_eol to true
|
||||||
|
void DoOutputLine(const wxString& line)
|
||||||
|
{
|
||||||
|
OnOutputLine(line);
|
||||||
|
|
||||||
|
m_eol = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// this function is a destructive inspector: when it returns true it also
|
||||||
|
// resets the flag to false so calling it again wouldn't return true any
|
||||||
|
// more
|
||||||
|
bool IsStartOfNewLine()
|
||||||
|
{
|
||||||
|
if ( !m_eol )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
m_eol = false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool m_eol;
|
||||||
|
|
||||||
|
wxDECLARE_NO_COPY_CLASS(wxTextWrapper);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // _WX_TEXTWRAPPER_H_
|
||||||
|
|
100
interface/wx/textwrapper.h
Normal file
100
interface/wx/textwrapper.h
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: wx/textwrapper.h
|
||||||
|
// Purpose: documentation of wxTextWrapper interface
|
||||||
|
// Author: Vadim Zeitlin
|
||||||
|
// RCS-ID: $Id$
|
||||||
|
// Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||||
|
// Licence: wxWindows license
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/**
|
||||||
|
@class wxTextWrapper
|
||||||
|
|
||||||
|
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:
|
||||||
|
@code
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
@endcode
|
||||||
|
|
||||||
|
@library{none}
|
||||||
|
@category{gdi}
|
||||||
|
*/
|
||||||
|
class wxTextWrapper
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
Trivial default constructor.
|
||||||
|
*/
|
||||||
|
wxTextWrapper();
|
||||||
|
|
||||||
|
/**
|
||||||
|
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 @a text is
|
||||||
|
less than @a widthMax).
|
||||||
|
|
||||||
|
@param win
|
||||||
|
A non-@NULL window used for measuring the text extents.
|
||||||
|
@param text
|
||||||
|
The text to wrap.
|
||||||
|
@param widthMax
|
||||||
|
Maximal width of each line of text or @c -1 to disable wrapping.
|
||||||
|
*/
|
||||||
|
void Wrap(wxWindow *win, const wxString& text, int widthMax);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/**
|
||||||
|
Called by Wrap() for each wrapped line of text.
|
||||||
|
|
||||||
|
This method will always be called at least once by Wrap(). Notice that
|
||||||
|
@a line may be empty if the text passed to Wrap() was empty itself.
|
||||||
|
*/
|
||||||
|
virtual void OnOutputLine(const wxString& line) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
virtual void OnNewLine();
|
||||||
|
};
|
@@ -40,9 +40,9 @@
|
|||||||
#include "wx/statline.h"
|
#include "wx/statline.h"
|
||||||
#include "wx/sysopt.h"
|
#include "wx/sysopt.h"
|
||||||
#include "wx/module.h"
|
#include "wx/module.h"
|
||||||
#include "wx/private/stattext.h"
|
|
||||||
#include "wx/bookctrl.h"
|
#include "wx/bookctrl.h"
|
||||||
#include "wx/scrolwin.h"
|
#include "wx/scrolwin.h"
|
||||||
|
#include "wx/textwrapper.h"
|
||||||
|
|
||||||
#if wxUSE_DISPLAY
|
#if wxUSE_DISPLAY
|
||||||
#include "wx/display.h"
|
#include "wx/display.h"
|
||||||
|
@@ -24,6 +24,7 @@
|
|||||||
#pragma hdrstop
|
#pragma hdrstop
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "wx/textwrapper.h"
|
||||||
#include "wx/private/stattext.h"
|
#include "wx/private/stattext.h"
|
||||||
|
|
||||||
#ifndef WX_PRECOMP
|
#ifndef WX_PRECOMP
|
||||||
|
Reference in New Issue
Block a user