added wxStaticText::Wrap()
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35202 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -18,6 +18,7 @@ All:
|
|||||||
|
|
||||||
All (GUI):
|
All (GUI):
|
||||||
|
|
||||||
|
- Added wxStaticText::Wrap()
|
||||||
- Added wxXmlResource::Unload().
|
- Added wxXmlResource::Unload().
|
||||||
- Possibility of modeless wxWizard dialog (with presentation in sample).
|
- Possibility of modeless wxWizard dialog (with presentation in sample).
|
||||||
- Fixed a rare crash due to malformed HTML in wxHTML (Xavier Nodet).
|
- Fixed a rare crash due to malformed HTML in wxHTML (Xavier Nodet).
|
||||||
|
@@ -36,6 +36,7 @@ See also \helpref{window styles overview}{windowstyles}.
|
|||||||
|
|
||||||
\latexignore{\rtfignore{\wxheading{Members}}}
|
\latexignore{\rtfignore{\wxheading{Members}}}
|
||||||
|
|
||||||
|
|
||||||
\membersection{wxStaticText::wxStaticText}\label{wxstatictextconstr}
|
\membersection{wxStaticText::wxStaticText}\label{wxstatictextconstr}
|
||||||
|
|
||||||
\func{}{wxStaticText}{\void}
|
\func{}{wxStaticText}{\void}
|
||||||
@@ -68,6 +69,7 @@ Constructor, creating and showing a text control.
|
|||||||
|
|
||||||
\helpref{wxStaticText::Create}{wxstatictextcreate}
|
\helpref{wxStaticText::Create}{wxstatictextcreate}
|
||||||
|
|
||||||
|
|
||||||
\membersection{wxStaticText::Create}\label{wxstatictextcreate}
|
\membersection{wxStaticText::Create}\label{wxstatictextcreate}
|
||||||
|
|
||||||
\func{bool}{Create}{\param{wxWindow* }{parent}, \param{wxWindowID}{ id},\rtfsp
|
\func{bool}{Create}{\param{wxWindow* }{parent}, \param{wxWindowID}{ id},\rtfsp
|
||||||
@@ -76,12 +78,14 @@ Constructor, creating and showing a text control.
|
|||||||
|
|
||||||
Creation function, for two-step construction. For details see \helpref{wxStaticText::wxStaticText}{wxstatictextconstr}.
|
Creation function, for two-step construction. For details see \helpref{wxStaticText::wxStaticText}{wxstatictextconstr}.
|
||||||
|
|
||||||
|
|
||||||
\membersection{wxStaticText::GetLabel}\label{wxstatictextgetlabel}
|
\membersection{wxStaticText::GetLabel}\label{wxstatictextgetlabel}
|
||||||
|
|
||||||
\constfunc{wxString}{GetLabel}{\void}
|
\constfunc{wxString}{GetLabel}{\void}
|
||||||
|
|
||||||
Returns the contents of the control.
|
Returns the contents of the control.
|
||||||
|
|
||||||
|
|
||||||
\membersection{wxStaticText::SetLabel}\label{wxstatictextsetlabel}
|
\membersection{wxStaticText::SetLabel}\label{wxstatictextsetlabel}
|
||||||
|
|
||||||
\func{virtual void}{SetLabel}{\param{const wxString\& }{ label}}
|
\func{virtual void}{SetLabel}{\param{const wxString\& }{ label}}
|
||||||
@@ -93,3 +97,12 @@ label unless the control has wxST\_NO\_AUTORESIZE flag.
|
|||||||
|
|
||||||
\docparam{label}{The new label to set. It may contain newline characters.}
|
\docparam{label}{The new label to set. It may contain newline characters.}
|
||||||
|
|
||||||
|
|
||||||
|
\membersection{wxStaticText::Wrap}\label{wxstatictextwrpa}
|
||||||
|
|
||||||
|
\func{void}{Wrap}{\param{int }{width}}
|
||||||
|
|
||||||
|
This functions wraps the controls label so that each of its lines becomes at
|
||||||
|
most \arg{width} pixels wide if possible (the lines are broken at words
|
||||||
|
boundaries so it might not be the case if words are too long). If \arg{width}
|
||||||
|
is negative, no wrapping is done.
|
||||||
|
@@ -25,6 +25,12 @@ class WXDLLEXPORT wxStaticTextBase : public wxControl
|
|||||||
public:
|
public:
|
||||||
wxStaticTextBase() { }
|
wxStaticTextBase() { }
|
||||||
|
|
||||||
|
// wrap the text of the control so that no line is longer than the given
|
||||||
|
// width (if possible: this function won't break words)
|
||||||
|
//
|
||||||
|
// NB: implemented in dlgcmn.cpp for now
|
||||||
|
void Wrap(int width);
|
||||||
|
|
||||||
// overriden base virtuals
|
// overriden base virtuals
|
||||||
virtual bool AcceptsFocus() const { return false; }
|
virtual bool AcceptsFocus() const { return false; }
|
||||||
virtual bool HasTransparentBackground() { return true; }
|
virtual bool HasTransparentBackground() { return true; }
|
||||||
|
@@ -40,11 +40,63 @@
|
|||||||
#include "wx/containr.h"
|
#include "wx/containr.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
#if wxUSE_STATTEXT
|
||||||
// wxDialogBase
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// FIXME - temporary hack in absence of wxtopLevelWindow, should be always used
|
// ----------------------------------------------------------------------------
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxDialogBase
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// FIXME - temporary hack in absence of wxTopLevelWindow, should be always used
|
||||||
#ifdef wxTopLevelWindowNative
|
#ifdef wxTopLevelWindowNative
|
||||||
BEGIN_EVENT_TABLE(wxDialogBase, wxTopLevelWindow)
|
BEGIN_EVENT_TABLE(wxDialogBase, wxTopLevelWindow)
|
||||||
WX_EVENT_TABLE_CONTROL_CONTAINER(wxDialogBase)
|
WX_EVENT_TABLE_CONTROL_CONTAINER(wxDialogBase)
|
||||||
@@ -68,104 +120,153 @@ void wxDialogBase::Init()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if wxUSE_STATTEXT // && wxUSE_TEXTCTRL
|
#if wxUSE_STATTEXT
|
||||||
|
|
||||||
wxSizer *wxDialogBase::CreateTextSizer( const wxString& message )
|
void wxTextWrapper::Wrap(wxWindow *win, const wxString& text, int widthMax)
|
||||||
{
|
{
|
||||||
bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
|
const wxChar *lastSpace = NULL;
|
||||||
|
|
||||||
wxString text = message;
|
|
||||||
|
|
||||||
// I admit that this is complete bogus, but it makes
|
|
||||||
// message boxes work for pda screens temporarily..
|
|
||||||
int max_width = -1;
|
|
||||||
if (is_pda)
|
|
||||||
{
|
|
||||||
max_width = wxSystemSettings::GetMetric( wxSYS_SCREEN_X ) - 25;
|
|
||||||
text += wxT('\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
wxBoxSizer *box = new wxBoxSizer( wxVERTICAL );
|
|
||||||
|
|
||||||
// get line height for empty lines
|
|
||||||
int y = 0;
|
|
||||||
wxFont font( GetFont() );
|
|
||||||
if (!font.Ok())
|
|
||||||
font = *wxSWISS_FONT;
|
|
||||||
GetTextExtent( wxT("H"), (int*)NULL, &y, (int*)NULL, (int*)NULL, &font);
|
|
||||||
|
|
||||||
size_t last_space = 0;
|
|
||||||
wxString line;
|
wxString line;
|
||||||
for ( size_t pos = 0; pos < text.length(); pos++ )
|
|
||||||
|
const wxChar *lineStart = text.c_str();
|
||||||
|
for ( const wxChar *p = lineStart; ; p++ )
|
||||||
{
|
{
|
||||||
switch ( text[pos] )
|
if ( IsStartOfNewLine() )
|
||||||
{
|
{
|
||||||
case wxT('\n'):
|
OnNewLine();
|
||||||
if (!line.empty())
|
|
||||||
{
|
lastSpace = NULL;
|
||||||
wxStaticText *s = new wxStaticText( this, wxID_ANY, line );
|
line.clear();
|
||||||
box->Add( s );
|
lineStart = p;
|
||||||
line = wxEmptyString;
|
}
|
||||||
}
|
|
||||||
else
|
if ( *p == _T('\n') || *p == _T('\0') )
|
||||||
{
|
{
|
||||||
box->Add( 5, y );
|
DoOutputLine(line);
|
||||||
}
|
|
||||||
|
if ( *p == _T('\0') )
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
else // not EOL
|
||||||
|
{
|
||||||
|
if ( *p == _T(' ') )
|
||||||
|
lastSpace = p;
|
||||||
|
|
||||||
case wxT('&'):
|
line += *p;
|
||||||
// this is used as accel mnemonic prefix in the wxWidgets
|
|
||||||
// controls but in the static messages created by
|
|
||||||
// CreateTextSizer() (used by wxMessageBox, for example), we
|
|
||||||
// don't want this special meaning, so we need to quote it
|
|
||||||
line += wxT('&');
|
|
||||||
|
|
||||||
// fall through to add it normally too
|
if ( widthMax >= 0 && lastSpace )
|
||||||
|
{
|
||||||
|
int width;
|
||||||
|
win->GetTextExtent(line, &width, NULL);
|
||||||
|
|
||||||
default:
|
if ( width > widthMax )
|
||||||
if (text[pos] == wxT(' '))
|
|
||||||
last_space = pos;
|
|
||||||
|
|
||||||
line += message[pos];
|
|
||||||
|
|
||||||
if (is_pda)
|
|
||||||
{
|
{
|
||||||
int width = 0;
|
// remove the last word from this line
|
||||||
GetTextExtent( line, &width, (int*)NULL, (int*)NULL, (int*)NULL, &font );
|
line.erase(lastSpace - lineStart, p + 1 - lineStart);
|
||||||
|
DoOutputLine(line);
|
||||||
|
|
||||||
if (width > max_width)
|
// go back to the last word of this line which we didn't
|
||||||
{
|
// output yet
|
||||||
// exception if there was no previous space
|
p = lastSpace;
|
||||||
if (last_space == 0)
|
|
||||||
last_space = pos;
|
|
||||||
|
|
||||||
int diff = pos-last_space;
|
|
||||||
int len = line.Len();
|
|
||||||
line.Remove( len-diff, diff );
|
|
||||||
|
|
||||||
wxStaticText *s = new wxStaticText( this, wxID_ANY, line );
|
|
||||||
box->Add( s );
|
|
||||||
|
|
||||||
pos = last_space;
|
|
||||||
last_space = 0;
|
|
||||||
line = wxEmptyString;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
//else: no wrapping at all or impossible to wrap
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// remaining text behind last '\n'
|
|
||||||
if (!line.empty())
|
|
||||||
{
|
|
||||||
wxStaticText *s2 = new wxStaticText( this, wxID_ANY, line );
|
|
||||||
box->Add( s2 );
|
|
||||||
}
|
|
||||||
|
|
||||||
return box;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // wxUSE_STATTEXT // && wxUSE_TEXTCTRL
|
wxSizer *wxDialogBase::CreateTextSizer(const wxString& message)
|
||||||
|
{
|
||||||
|
// I admit that this is complete bogus, but it makes
|
||||||
|
// message boxes work for pda screens temporarily..
|
||||||
|
int widthMax = -1;
|
||||||
|
const bool is_pda = wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA;
|
||||||
|
if (is_pda)
|
||||||
|
{
|
||||||
|
widthMax = wxSystemSettings::GetMetric( wxSYS_SCREEN_X ) - 25;
|
||||||
|
}
|
||||||
|
|
||||||
|
// '&' is used as accel mnemonic prefix in the wxWidgets controls but in
|
||||||
|
// the static messages created by CreateTextSizer() (used by wxMessageBox,
|
||||||
|
// for example), we don't want this special meaning, so we need to quote it
|
||||||
|
wxString text(message);
|
||||||
|
text.Replace(_T("&"), _T("&&"));
|
||||||
|
|
||||||
|
|
||||||
|
class TextSizerWrapper : public wxTextWrapper
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TextSizerWrapper(wxWindow *win)
|
||||||
|
{
|
||||||
|
m_win = win;
|
||||||
|
m_hLine = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxSizer *CreateSizer(const wxString& text, int widthMax)
|
||||||
|
{
|
||||||
|
m_sizer = new wxBoxSizer(wxVERTICAL);
|
||||||
|
Wrap(m_win, text, widthMax);
|
||||||
|
return m_sizer;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void OnOutputLine(const wxString& line)
|
||||||
|
{
|
||||||
|
if ( !line.empty() )
|
||||||
|
{
|
||||||
|
m_sizer->Add(new wxStaticText(m_win, wxID_ANY, line));
|
||||||
|
}
|
||||||
|
else // empty line, no need to create a control for it
|
||||||
|
{
|
||||||
|
if ( !m_hLine )
|
||||||
|
m_hLine = m_win->GetCharHeight();
|
||||||
|
|
||||||
|
m_sizer->Add(5, m_hLine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
wxWindow *m_win;
|
||||||
|
wxSizer *m_sizer;
|
||||||
|
int m_hLine;
|
||||||
|
};
|
||||||
|
|
||||||
|
TextSizerWrapper wrapper(this);
|
||||||
|
|
||||||
|
return wrapper.CreateSizer(text, widthMax);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxStaticTextBase::Wrap(int width)
|
||||||
|
{
|
||||||
|
class LabelWrapper : public wxTextWrapper
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void WrapLabel(wxStaticTextBase *text, int widthMax)
|
||||||
|
{
|
||||||
|
m_text.clear();
|
||||||
|
Wrap(text, text->GetLabel(), widthMax);
|
||||||
|
text->SetLabel(m_text);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void OnOutputLine(const wxString& line)
|
||||||
|
{
|
||||||
|
m_text += line;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void OnNewLine()
|
||||||
|
{
|
||||||
|
m_text += _T('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
wxString m_text;
|
||||||
|
};
|
||||||
|
|
||||||
|
LabelWrapper wrapper;
|
||||||
|
wrapper.WrapLabel(this, width);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // wxUSE_STATTEXT
|
||||||
|
|
||||||
#if wxUSE_BUTTON
|
#if wxUSE_BUTTON
|
||||||
|
|
||||||
|
@@ -23,6 +23,7 @@
|
|||||||
*wxMediaCtrl*ShowPlayerControls*wxMediaPlayerControls*;
|
*wxMediaCtrl*ShowPlayerControls*wxMediaPlayerControls*;
|
||||||
*wxMessageOutputBest*;
|
*wxMessageOutputBest*;
|
||||||
*wxShadowObject*;
|
*wxShadowObject*;
|
||||||
|
*wxStaticText*Wrap*;
|
||||||
*wxTopLevelWindowGTK*RequestUserAttention*;
|
*wxTopLevelWindowGTK*RequestUserAttention*;
|
||||||
*wxWindowMSW*MSWWindowProc*;
|
*wxWindowMSW*MSWWindowProc*;
|
||||||
*wxWizard*FinishLayout*;
|
*wxWizard*FinishLayout*;
|
||||||
|
Reference in New Issue
Block a user