wxTextCtrl: Switching on the fly from wrap to hscroll

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
User avatar
rocrail
Super wx Problem Solver
Super wx Problem Solver
Posts: 293
Joined: Fri Oct 02, 2009 2:02 pm
Contact:

wxTextCtrl: Switching on the fly from wrap to hscroll

Post by rocrail »

Hi,

I'm looking for a way to switch between wrap and hsrcoll during the TextCtrl is visible.

I tried this code: (m_XML is the wxTextCtrl)

Code: Select all

void XmlDlg::onWrap( wxCommandEvent& event ) {
  long style = m_XML->GetWindowStyleFlag();
  if( m_Wrap->IsChecked() )
    style |= wxTE_DONTWRAP;
  else
    style &= ~wxTE_DONTWRAP;
  m_XML->SetWindowStyleFlag(style);
  m_XML->Refresh();
}
But this does do not the trick; Nothing changes.
(onWrap is linked with a CheckBox.)

Any suggestion?
Best regards,
Rob.
https://wiki.rocrail.net
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxTextCtrl: Switching on the fly from wrap to hscroll

Post by doublemax »

These flags are usually converted to the corresponding flags for the underlying native control only when it is created. But changing these flags afterwards is sometimes not supported.

You'll probably have to recreate the control if you want to change that style.
Use the source, Luke!
User avatar
rocrail
Super wx Problem Solver
Super wx Problem Solver
Posts: 293
Joined: Fri Oct 02, 2009 2:02 pm
Contact:

Re: wxTextCtrl: Switching on the fly from wrap to hscroll

Post by rocrail »

Hi,
OK, but what purpose has the SetWindowStyleFlag function if it has more or less no effect?
Best regards,
Rob.
https://wiki.rocrail.net
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxTextCtrl: Switching on the fly from wrap to hscroll

Post by doublemax »

rocrail wrote: Tue May 21, 2019 2:00 pm Hi,
OK, but what purpose has the SetWindowStyleFlag function if it has more or less no effect?
It works for some (maybe even many) flags, but not for all.
Use the source, Luke!
New Pagodi
Super wx Problem Solver
Super wx Problem Solver
Posts: 466
Joined: Tue Jun 20, 2006 6:47 pm
Contact:

Re: wxTextCtrl: Switching on the fly from wrap to hscroll

Post by New Pagodi »

rocrail wrote: Tue May 21, 2019 2:00 pm Hi,
OK, but what purpose has the SetWindowStyleFlag function if it has more or less no effect?
In fairness, the documentation does state:
Please note that some styles cannot be changed after the window creation and that Refresh() might need to be called after changing the others for the change to take place immediately.
If you need a text control that can turn word wrapping on and off that will work on all ports, you can use wxStyledTextCtrl. It's a little more complicated than a text control however.
User avatar
rocrail
Super wx Problem Solver
Super wx Problem Solver
Posts: 293
Joined: Fri Oct 02, 2009 2:02 pm
Contact:

Re: wxTextCtrl: Switching on the fly from wrap to hscroll

Post by rocrail »

Thanks for that Tip!
wxStyledTextCtrl looks the right Control for this purpose. :)
Best regards,
Rob.
https://wiki.rocrail.net
User avatar
rocrail
Super wx Problem Solver
Super wx Problem Solver
Posts: 293
Joined: Fri Oct 02, 2009 2:02 pm
Contact:

Re: wxTextCtrl: Switching on the fly from wrap to hscroll

Post by rocrail »

The on the fly WordWrap with the wxStyledTextCtrl does work.
I also could change the font to teletype.
But, how to highlight XML is a riddle to me...
Best regards,
Rob.
https://wiki.rocrail.net
User avatar
rocrail
Super wx Problem Solver
Super wx Problem Solver
Posts: 293
Joined: Fri Oct 02, 2009 2:02 pm
Contact:

Re: wxTextCtrl: Switching on the fly from wrap to hscroll

Post by rocrail »

Using the Wiki Example it was easy:
https://wiki.wxwidgets.org/WxStyledTextCtrl
Best regards,
Rob.
https://wiki.rocrail.net
User avatar
rocrail
Super wx Problem Solver
Super wx Problem Solver
Posts: 293
Joined: Fri Oct 02, 2009 2:02 pm
Contact:

Re: wxTextCtrl: Switching on the fly from wrap to hscroll

Post by rocrail »

Since which wxWidgets Version is this control available? 3.0?
Best regards,
Rob.
https://wiki.rocrail.net
User avatar
rocrail
Super wx Problem Solver
Super wx Problem Solver
Posts: 293
Joined: Fri Oct 02, 2009 2:02 pm
Contact:

Re: wxTextCtrl: Switching on the fly from wrap to hscroll

Post by rocrail »

At linking under Ubuntu 18.04 the Control is not available. No Compile error...
undef.png
Best regards,
Rob.
https://wiki.rocrail.net
New Pagodi
Super wx Problem Solver
Super wx Problem Solver
Posts: 466
Joined: Tue Jun 20, 2006 6:47 pm
Contact:

Re: wxTextCtrl: Switching on the fly from wrap to hscroll

Post by New Pagodi »

You need to change

Code: Select all

`wx-config --libs std,aui`
to

Code: Select all

`wx-config --libs std,aui,stc`
New Pagodi
Super wx Problem Solver
Super wx Problem Solver
Posts: 466
Joined: Tue Jun 20, 2006 6:47 pm
Contact:

Re: wxTextCtrl: Switching on the fly from wrap to hscroll

Post by New Pagodi »

rocrail wrote: Wed May 22, 2019 2:33 pm Since which wxWidgets Version is this control available? 3.0?
I'm not sure when it was added, but I was recently looking at commits from 2004, so it's been in for a long time.
alys666
Super wx Problem Solver
Super wx Problem Solver
Posts: 329
Joined: Tue Oct 18, 2016 2:31 pm

Re: wxTextCtrl: Switching on the fly from wrap to hscroll

Post by alys666 »

New Pagodi wrote: Wed May 22, 2019 3:03 pm You need to change

Code: Select all

`wx-config --libs std,aui`
to

Code: Select all

`wx-config --libs std,aui,stc`
yes. different components of wx widgets may lie in different libs.
if code was compiled, but linked with error "undefined reference ..." - it's linker has not found needed library.

to see which libs wxWidgets has, type in terminal -

Code: Select all

wx-config --libs all
in my version it returms -

Code: Select all

-L/usr/local/lib -pthread   -lwx_gtk3u_xrc-3.0 -lwx_gtk3u_stc-3.0 -lwx_gtk3u_richtext-3.0 -lwx_gtk3u_ribbon-3.0 -lwx_gtk3u_propgrid-3.0 -lwx_gtk3u_aui-3.0 -lwx_gtk3u_gl-3.0 -lwx_gtk3u_html-3.0 -lwx_gtk3u_qa-3.0 -lwx_gtk3u_adv-3.0 -lwx_gtk3u_core-3.0 -lwx_baseu_xml-3.0 -lwx_baseu_net-3.0 -lwx_baseu-3.0 
here you see real names of wxWidgets libs with nicks - xrc,stc,richtext, propgrid...etc.
wxStyledTextControl(it's just a wrapper for Scintilla editor) just lies in library with nick "stc".
ubuntu 20.04, wxWidgets 3.2.1
Post Reply