allow dynamically changing most of text control styles in wxGTK
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43799 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -106,6 +106,10 @@ wxMSW:
|
|||||||
- Use system default paper size for printing instead of A4.
|
- Use system default paper size for printing instead of A4.
|
||||||
- Fix colours when converting wxBitmap with alpha to wxImage (nusi).
|
- Fix colours when converting wxBitmap with alpha to wxImage (nusi).
|
||||||
|
|
||||||
|
wxGTK:
|
||||||
|
|
||||||
|
- Allow dynamically changing most of text control styles
|
||||||
|
|
||||||
|
|
||||||
2.7.2
|
2.7.2
|
||||||
-----
|
-----
|
||||||
|
@@ -57,6 +57,14 @@ used, so that text won't be wrapped. No effect under wxGTK1.}
|
|||||||
|
|
||||||
See also \helpref{window styles overview}{windowstyles} and \helpref{wxTextCtrl::wxTextCtrl}{wxtextctrlctor}.
|
See also \helpref{window styles overview}{windowstyles} and \helpref{wxTextCtrl::wxTextCtrl}{wxtextctrlctor}.
|
||||||
|
|
||||||
|
Note that alignment styles (\windowstyle{wxTE\_LEFT},
|
||||||
|
\windowstyle{wxTE\_CENTRE} and \windowstyle{wxTE\_RIGHT}) can be changed
|
||||||
|
dynamically after control creation on wxMSW and wxGTK.
|
||||||
|
\windowstyle{wxTE\_READONLY}, \windowstyle{wxTE\_PASSWORD} and wrapping styles
|
||||||
|
can be dynamically changed under wxGTK but not wxMSW. The other styles can be
|
||||||
|
only set during control creation.
|
||||||
|
|
||||||
|
|
||||||
\wxheading{wxTextCtrl text format}
|
\wxheading{wxTextCtrl text format}
|
||||||
|
|
||||||
The multiline text controls always store the text as a sequence of lines
|
The multiline text controls always store the text as a sequence of lines
|
||||||
|
@@ -115,6 +115,8 @@ public:
|
|||||||
virtual void SetSelection(long from, long to);
|
virtual void SetSelection(long from, long to);
|
||||||
virtual void SetEditable(bool editable);
|
virtual void SetEditable(bool editable);
|
||||||
|
|
||||||
|
// Overridden wxWindow methods
|
||||||
|
virtual void SetWindowStyleFlag( long style );
|
||||||
virtual bool Enable( bool enable = true );
|
virtual bool Enable( bool enable = true );
|
||||||
|
|
||||||
// Implementation from now on
|
// Implementation from now on
|
||||||
@@ -190,6 +192,14 @@ protected:
|
|||||||
|
|
||||||
virtual void DoSetValue(const wxString &value, int flags = 0);
|
virtual void DoSetValue(const wxString &value, int flags = 0);
|
||||||
|
|
||||||
|
// wrappers hiding the differences between functions doing the same thing
|
||||||
|
// for GtkTextView and GtkEntry (all of them use current window style to
|
||||||
|
// set the given characteristic)
|
||||||
|
void GTKSetEditable();
|
||||||
|
void GTKSetVisibility();
|
||||||
|
void GTKSetWrapMode();
|
||||||
|
void GTKSetJustification();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// change the font for everything in this control
|
// change the font for everything in this control
|
||||||
void ChangeFontGlobally();
|
void ChangeFontGlobally();
|
||||||
|
@@ -712,28 +712,7 @@ bool wxTextCtrl::Create( wxWindow *parent,
|
|||||||
// Insert view into scrolled window
|
// Insert view into scrolled window
|
||||||
gtk_container_add( GTK_CONTAINER(m_widget), m_text );
|
gtk_container_add( GTK_CONTAINER(m_widget), m_text );
|
||||||
|
|
||||||
// translate wx wrapping style to GTK+
|
GTKSetWrapMode();
|
||||||
GtkWrapMode wrap;
|
|
||||||
if ( HasFlag( wxTE_DONTWRAP ) )
|
|
||||||
wrap = GTK_WRAP_NONE;
|
|
||||||
else if ( HasFlag( wxTE_CHARWRAP ) )
|
|
||||||
wrap = GTK_WRAP_CHAR;
|
|
||||||
else if ( HasFlag( wxTE_WORDWRAP ) )
|
|
||||||
wrap = GTK_WRAP_WORD;
|
|
||||||
else // HasFlag(wxTE_BESTWRAP) always true as wxTE_BESTWRAP == 0
|
|
||||||
{
|
|
||||||
// GTK_WRAP_WORD_CHAR seems to be new in GTK+ 2.4
|
|
||||||
#ifdef __WXGTK24__
|
|
||||||
if ( !gtk_check_version(2,4,0) )
|
|
||||||
{
|
|
||||||
wrap = GTK_WRAP_WORD_CHAR;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
wrap = GTK_WRAP_WORD;
|
|
||||||
}
|
|
||||||
|
|
||||||
gtk_text_view_set_wrap_mode( GTK_TEXT_VIEW( m_text ), wrap );
|
|
||||||
|
|
||||||
GtkScrolledWindowSetBorder(m_widget, style);
|
GtkScrolledWindowSetBorder(m_widget, style);
|
||||||
|
|
||||||
@@ -768,40 +747,14 @@ bool wxTextCtrl::Create( wxWindow *parent,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (style & wxTE_PASSWORD)
|
if (style & wxTE_PASSWORD)
|
||||||
{
|
GTKSetVisibility();
|
||||||
if (!multi_line)
|
|
||||||
gtk_entry_set_visibility( GTK_ENTRY(m_text), FALSE );
|
|
||||||
}
|
|
||||||
|
|
||||||
if (style & wxTE_READONLY)
|
if (style & wxTE_READONLY)
|
||||||
{
|
GTKSetEditable();
|
||||||
if (!multi_line)
|
|
||||||
gtk_editable_set_editable( GTK_EDITABLE(m_text), FALSE );
|
|
||||||
else
|
|
||||||
gtk_text_view_set_editable( GTK_TEXT_VIEW( m_text), FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (multi_line)
|
// left justification (alignment) is the default anyhow
|
||||||
{
|
if ( style & (wxTE_RIGHT | wxTE_CENTRE) )
|
||||||
if (style & wxTE_RIGHT)
|
GTKSetJustification();
|
||||||
gtk_text_view_set_justification( GTK_TEXT_VIEW(m_text), GTK_JUSTIFY_RIGHT );
|
|
||||||
else if (style & wxTE_CENTRE)
|
|
||||||
gtk_text_view_set_justification( GTK_TEXT_VIEW(m_text), GTK_JUSTIFY_CENTER );
|
|
||||||
// Left justify (alignment) is the default and we don't need to apply GTK_JUSTIFY_LEFT
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
#ifdef __WXGTK24__
|
|
||||||
// gtk_entry_set_alignment was introduced in gtk+-2.3.5
|
|
||||||
if (!gtk_check_version(2,4,0))
|
|
||||||
{
|
|
||||||
if (style & wxTE_RIGHT)
|
|
||||||
gtk_entry_set_alignment( GTK_ENTRY(m_text), 1.0 );
|
|
||||||
else if (style & wxTE_CENTRE)
|
|
||||||
gtk_entry_set_alignment( GTK_ENTRY(m_text), 0.5 );
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// We want to be notified about text changes.
|
// We want to be notified about text changes.
|
||||||
if (multi_line)
|
if (multi_line)
|
||||||
@@ -866,6 +819,116 @@ bool wxTextCtrl::Create( wxWindow *parent,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// flags handling
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void wxTextCtrl::GTKSetEditable()
|
||||||
|
{
|
||||||
|
gboolean editable = !HasFlag(wxTE_READONLY);
|
||||||
|
if ( IsSingleLine() )
|
||||||
|
gtk_editable_set_editable(GTK_EDITABLE(m_text), editable);
|
||||||
|
else
|
||||||
|
gtk_text_view_set_editable(GTK_TEXT_VIEW(m_text), editable);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxTextCtrl::GTKSetVisibility()
|
||||||
|
{
|
||||||
|
// VZ: shouldn't we assert if wxTE_PASSWORD is set for multiline control?
|
||||||
|
if ( IsSingleLine() )
|
||||||
|
gtk_entry_set_visibility(GTK_ENTRY(m_text), !HasFlag(wxTE_PASSWORD));
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxTextCtrl::GTKSetWrapMode()
|
||||||
|
{
|
||||||
|
// no wrapping in single line controls
|
||||||
|
if ( !IsMultiLine() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
// translate wx wrapping style to GTK+
|
||||||
|
GtkWrapMode wrap;
|
||||||
|
if ( HasFlag( wxTE_DONTWRAP ) )
|
||||||
|
wrap = GTK_WRAP_NONE;
|
||||||
|
else if ( HasFlag( wxTE_CHARWRAP ) )
|
||||||
|
wrap = GTK_WRAP_CHAR;
|
||||||
|
else if ( HasFlag( wxTE_WORDWRAP ) )
|
||||||
|
wrap = GTK_WRAP_WORD;
|
||||||
|
else // HasFlag(wxTE_BESTWRAP) always true as wxTE_BESTWRAP == 0
|
||||||
|
{
|
||||||
|
// GTK_WRAP_WORD_CHAR seems to be new in GTK+ 2.4
|
||||||
|
#ifdef __WXGTK24__
|
||||||
|
if ( !gtk_check_version(2,4,0) )
|
||||||
|
{
|
||||||
|
wrap = GTK_WRAP_WORD_CHAR;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif // __WXGTK24__
|
||||||
|
wrap = GTK_WRAP_WORD;
|
||||||
|
}
|
||||||
|
|
||||||
|
gtk_text_view_set_wrap_mode( GTK_TEXT_VIEW( m_text ), wrap );
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxTextCtrl::GTKSetJustification()
|
||||||
|
{
|
||||||
|
if ( IsMultiLine() )
|
||||||
|
{
|
||||||
|
GtkJustification just;
|
||||||
|
if ( HasFlag(wxTE_RIGHT) )
|
||||||
|
just = GTK_JUSTIFY_RIGHT;
|
||||||
|
else if ( HasFlag(wxTE_CENTRE) )
|
||||||
|
just = GTK_JUSTIFY_CENTER;
|
||||||
|
else // wxTE_LEFT == 0
|
||||||
|
just = GTK_JUSTIFY_LEFT;
|
||||||
|
|
||||||
|
gtk_text_view_set_justification( GTK_TEXT_VIEW(m_text), GTK_JUSTIFY_CENTER );
|
||||||
|
}
|
||||||
|
else // single line
|
||||||
|
{
|
||||||
|
#ifdef __WXGTK24__
|
||||||
|
// gtk_entry_set_alignment was introduced in gtk+-2.3.5
|
||||||
|
if (!gtk_check_version(2,4,0))
|
||||||
|
{
|
||||||
|
gfloat align;
|
||||||
|
if ( HasFlag(wxTE_RIGHT) )
|
||||||
|
align = 1.0;
|
||||||
|
else if ( HasFlag(wxTE_CENTRE) )
|
||||||
|
align = 0.5;
|
||||||
|
else // single line
|
||||||
|
align = 0.0;
|
||||||
|
|
||||||
|
gtk_entry_set_alignment(GTK_ENTRY(m_text), align);
|
||||||
|
}
|
||||||
|
#endif // __WXGTK24__
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxTextCtrl::SetWindowStyleFlag(long style)
|
||||||
|
{
|
||||||
|
long styleOld = GetWindowStyleFlag();
|
||||||
|
|
||||||
|
wxTextCtrlBase::SetWindowStyleFlag(style);
|
||||||
|
|
||||||
|
if ( (style & wxTE_READONLY) != (styleOld & wxTE_READONLY) )
|
||||||
|
GTKSetEditable();
|
||||||
|
|
||||||
|
if ( (style & wxTE_PASSWORD) != (styleOld & wxTE_PASSWORD) )
|
||||||
|
GTKSetVisibility();
|
||||||
|
|
||||||
|
static const long flagsWrap = wxTE_WORDWRAP | wxTE_CHARWRAP | wxTE_DONTWRAP;
|
||||||
|
if ( (style & flagsWrap) != (styleOld & flagsWrap) )
|
||||||
|
GTKSetWrapMode();
|
||||||
|
|
||||||
|
static const long flagsAlign = wxTE_LEFT | wxTE_CENTRE | wxTE_RIGHT;
|
||||||
|
if ( (style & flagsAlign) != (styleOld & flagsAlign) )
|
||||||
|
GTKSetJustification();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// control value
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
wxString wxTextCtrl::GetValue() const
|
wxString wxTextCtrl::GetValue() const
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( m_text != NULL, wxEmptyString, wxT("invalid text ctrl") );
|
wxCHECK_MSG( m_text != NULL, wxEmptyString, wxT("invalid text ctrl") );
|
||||||
|
Reference in New Issue
Block a user