wxRichTextCtrl bug: style applied to whole line on enter

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
PeterO
Earned a small fee
Earned a small fee
Posts: 14
Joined: Mon Jun 23, 2014 11:12 am

wxRichTextCtrl bug: style applied to whole line on enter

Post by PeterO » Mon Sep 09, 2019 9:29 pm

I've got this simple rich text:

Code: Select all

 r.WriteText("aaa");
 
 r.BeginTextColour(*wxRED);
 r.WriteText("bbb");
 r.EndTextColour();
 
 r.WriteText("ccc");
It shows as expected.
style bug - before.png
style bug - before.png (768 Bytes) Viewed 288 times
But when I Enter in the middle of the coloured section the whole first line is red styled.
style bug - after.png
style bug - after.png (904 Bytes) Viewed 288 times
I think it's a bug so I've made a ticket for it https://trac.wxwidgets.org/ticket/18494 but maybe I'm doing something wrong, so just to be sure I ask it here as well.

Regards,
Peter

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3408
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxRichTextCtrl bug: style applied to whole line on enter

Post by ONEEYEMAN » Mon Sep 09, 2019 9:57 pm

Hi,
If you can reproduce this behavior in the richtext sample, then it definitely a bug. ;-)
What's your environment? wx version?

Thank you.

PeterO
Earned a small fee
Earned a small fee
Posts: 14
Joined: Mon Jun 23, 2014 11:12 am

Re: wxRichTextCtrl bug: style applied to whole line on enter

Post by PeterO » Tue Sep 10, 2019 6:53 am

Windows 10, 1903
wxWidgets master branch latest-dev (as well as v3.1.2)

Noticed if I first center the text and do the same it's handled ok:
style ok.png
style ok.png (713 Bytes) Viewed 260 times

User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2252
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania
Contact:

Re: wxRichTextCtrl bug: style applied to whole line on enter

Post by evstevemd » Tue Sep 10, 2019 7:09 am

PeterO wrote:
Tue Sep 10, 2019 6:53 am
Windows 10, 1903
wxWidgets master branch latest-dev (as well as v3.1.2)

Noticed if I first center the text and do the same it's handled ok:
style ok.png
Does it happen with richtexteditor sample?
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
[Ubuntu 15.04/Windows 10 Pro - GCC/MinGW, CodeLite IDE et al]

PeterO
Earned a small fee
Earned a small fee
Posts: 14
Joined: Mon Jun 23, 2014 11:12 am

Re: wxRichTextCtrl bug: style applied to whole line on enter

Post by PeterO » Tue Sep 10, 2019 8:09 am

evstevemd wrote:
Tue Sep 10, 2019 7:09 am
Does it happen with richtexteditor sample?
Yes. See the ticket I made for it and it's attachment: https://trac.wxwidgets.org/ticket/18494

User avatar
doublemax
Moderator
Moderator
Posts: 13989
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxRichTextCtrl bug: style applied to whole line on enter

Post by doublemax » Tue Sep 10, 2019 8:57 am

FWIW, you shouldn't get your hopes up to get a fix. I have a total of 4 open tickets regarding wxRTC which are several years old. The wxRTC code is quite complex and "unique", and except for the orginal author Julian Smart there is hardly anyone able to fix anything in it. But unfortunately he's not very active.
Use the source, Luke!

PeterO
Earned a small fee
Earned a small fee
Posts: 14
Joined: Mon Jun 23, 2014 11:12 am

Re: wxRichTextCtrl bug: style applied to whole line on enter

Post by PeterO » Tue Sep 10, 2019 9:09 am

Yes I noticed the other open tickets regarding wxRichTextCtrl. I'm already trying to grasp what's going on but have a hard time understanding some portions of the code. The styling of the paragraph where the break happens is done here: https://github.com/wxWidgets/wxWidgets/ ... .cpp#L2955

Code: Select all

            if (!(fragment.GetAttributes().GetFlags() & wxTEXT_ATTR_KEEP_FIRST_PARA_STYLE))
            {
                para->SetAttributes(firstPara->GetAttributes());
                para->SetProperties(firstPara->GetProperties());
            }
'para' is the original paragraph, 'firstPara' the first paragraph of the fragment being inserted in 'para'.
But should a paragraph take over the style of a fragment being inserted anyway?

User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2252
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania
Contact:

Re: wxRichTextCtrl bug: style applied to whole line on enter

Post by evstevemd » Tue Sep 10, 2019 11:05 am

doublemax wrote:
Tue Sep 10, 2019 8:57 am
FWIW, you shouldn't get your hopes up to get a fix. I have a total of 4 open tickets regarding wxRTC which are several years old. The wxRTC code is quite complex and "unique", and except for the orginal author Julian Smart there is hardly anyone able to fix anything in it. But unfortunately he's not very active.
One time I tried to add export to Richtext and could not wrap my head around it. Of course JS was indeed supportive and failure was on my side. I think Mr. Smart ned to document how the Control works and how the classes interact with each other. Otherwise the control won't get much updates unless he's the one doing it!
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
[Ubuntu 15.04/Windows 10 Pro - GCC/MinGW, CodeLite IDE et al]

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3408
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxRichTextCtrl bug: style applied to whole line on enter

Post by ONEEYEMAN » Tue Sep 10, 2019 2:10 pm

Hi,
I think he started dropping out when we switched to git.
Anyway, I hope someone can ping him and hopefully he will come back and support his baby (wxWidgets) again.

Thank you.

PeterO
Earned a small fee
Earned a small fee
Posts: 14
Joined: Mon Jun 23, 2014 11:12 am

Re: wxRichTextCtrl bug: style applied to whole line on enter

Post by PeterO » Wed Sep 11, 2019 8:52 am

Question: If wxWidgets purpose is to use the platform's native API as much as possible, why doesn't wxRTC use/wrap the richedit control shipped with Windows with all it's functionality? AFAICS it has al the styling and paragraph formatting. https://docs.microsoft.com/en-us/window ... t-controls

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3408
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxRichTextCtrl bug: style applied to whole line on enter

Post by ONEEYEMAN » Wed Sep 11, 2019 2:15 pm

Hi,
It does - look at the wxTextCtrl with TE_RICH2 style.
However, there are some other OSes which does not have support for different styling, paragraph, etc.

That's why Julian created this special wxRTC library to be used there.

Tha's my impression.

Thank you.

PeterO
Earned a small fee
Earned a small fee
Posts: 14
Joined: Mon Jun 23, 2014 11:12 am

Re: wxRichTextCtrl bug: style applied to whole line on enter

Post by PeterO » Thu Sep 12, 2019 6:25 pm

ONEEYEMAN wrote:
Wed Sep 11, 2019 2:15 pm
It does - look at the wxTextCtrl with TE_RICH2 style.
However, there are some other OSes which does not have support for different styling, paragraph, etc.
Yes, wxTextCtrl uses the native control. But wxRTC doesn't, it draws text itself using wxDC::DrawText.

But just like wxDataViewCtrl has a native implemention on osx/gtk and a custom for msw, I thought it would be nice if we could use the native msw control with it's formatting/styling functionality.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3408
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxRichTextCtrl bug: style applied to whole line on enter

Post by ONEEYEMAN » Thu Sep 12, 2019 9:30 pm

Hi,
Yes, you can.
Just create a wxTextCtrl object with the TE_RICH2 style.

Thank you.

Post Reply