Page 1 of 1

wxRichTextCtrl bug: style applied to whole line on enter

Posted: Mon Sep 09, 2019 9:29 pm
by PeterO
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 2527 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 2527 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

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

Posted: Mon Sep 09, 2019 9:57 pm
by ONEEYEMAN
Hi,
If you can reproduce this behavior in the richtext sample, then it definitely a bug. ;-)
What's your environment? wx version?

Thank you.

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

Posted: Tue Sep 10, 2019 6:53 am
by PeterO
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 2499 times

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

Posted: Tue Sep 10, 2019 7:09 am
by evstevemd
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?

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

Posted: Tue Sep 10, 2019 8:09 am
by PeterO
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

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

Posted: Tue Sep 10, 2019 8:57 am
by doublemax
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.

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

Posted: Tue Sep 10, 2019 9:09 am
by PeterO
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?

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

Posted: Tue Sep 10, 2019 11:05 am
by evstevemd
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!

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

Posted: Tue Sep 10, 2019 2:10 pm
by ONEEYEMAN
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.

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

Posted: Wed Sep 11, 2019 8:52 am
by PeterO
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

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

Posted: Wed Sep 11, 2019 2:15 pm
by ONEEYEMAN
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.

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

Posted: Thu Sep 12, 2019 6:25 pm
by PeterO
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.

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

Posted: Thu Sep 12, 2019 9:30 pm
by ONEEYEMAN
Hi,
Yes, you can.
Just create a wxTextCtrl object with the TE_RICH2 style.

Thank you.