Not all events are showing in CodeBlocks Topic is solved

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
Twincity9
Earned a small fee
Earned a small fee
Posts: 11
Joined: Thu Jan 24, 2019 9:24 pm

Not all events are showing in CodeBlocks

Post by Twincity9 » Thu Jan 24, 2019 9:45 pm

Hello,

I am using wxWidgets in CodeBlocks (I am both a beginner in wxWidgets and a beginner in CodeBlocks). I've added a wxTextCtrl object to my application and I now want to use its paint event to draw a line in the text window. What I don't understand is that the paint event is not visible in the event list window. The list only shows the events from the last descendant (wxTextCtrl), it does not show the events from its wxWindow ancestor nor from any other ancestor. Is there something I overlooked here?
CodeBlocksScreenshot.png
CodeBlocksScreenshot.png (47.53 KiB) Viewed 406 times
My operating system is Windows10, I am using wxWidgets 3.0 and CodeBlocks 17.12

catalin
Moderator
Moderator
Posts: 1504
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Re: Not all events are showing in CodeBlocks

Post by catalin » Thu Jan 24, 2019 10:04 pm

Is that not the expected behavior (be it right or wrong)? Does it show events defined in base classes for other widgets?

Note that C::B is not an official tool or anything else "officially" related to wxW. It is an IDE just like any other. And they have their own forum, with a direct link to it on their home webpage. You might find more helpful answers there.

Twincity9
Earned a small fee
Earned a small fee
Posts: 11
Joined: Thu Jan 24, 2019 9:24 pm

Re: Not all events are showing in CodeBlocks

Post by Twincity9 » Thu Jan 24, 2019 11:40 pm

Ok, I've just subscribed and posted to a CodeBlocks forum. I will wait for a reply there.

PB
Part Of The Furniture
Part Of The Furniture
Posts: 1914
Joined: Sun Jan 03, 2010 5:45 pm

Re: Not all events are showing in CodeBlocks

Post by PB » Fri Jan 25, 2019 7:23 am

Generally speaking, having a paint handler for a standard native control is often not so good idea, even if it may sometime somehow work on some platforms.

Twincity9
Earned a small fee
Earned a small fee
Posts: 11
Joined: Thu Jan 24, 2019 9:24 pm

Re: Not all events are showing in CodeBlocks

Post by Twincity9 » Fri Jan 25, 2019 9:43 am

Alright, then what approach should I choose for instead?

What I want to do is add a vertical line inside the wxTextCtrl window. The vertical line is meant as a helper/indicator so that the person inputting tekst knows where the tekst is exactly a number of characters wide. The line has to be redrawn every time something changes inside the wxTextCtrl window. I tried to do this in the EVT_TEXT event but then the line is only redrawn when inputting tekst and not for example when scrolling the window. A paint event should have solved both situations and all other possible situations.

PB
Part Of The Furniture
Part Of The Furniture
Posts: 1914
Joined: Sun Jan 03, 2010 5:45 pm

Re: Not all events are showing in CodeBlocks

Post by PB » Fri Jan 25, 2019 12:14 pm

Twincity9 wrote:What I want to do is add a vertical line inside the wxTextCtrl window. The vertical line is meant as a helper/indicator so that the person inputting tekst knows where the tekst is exactly a number of characters wide. The line has to be redrawn every time something changes inside the wxTextCtrl window. I tried to do this in the EVT_TEXT event but then the line is only redrawn when inputting tekst and not for example when scrolling the window. A paint event should have solved both situations and all other possible situations.
This seems quite complicated, I haven't seen anything like it myself. The current number of characters is usually displayed somewhere next to the edit control. Another solution would be to use a monospaced font and size the control so that the maximum number of characters fills the control entirely.

But if your boss demands the solution with a vertical line, I guess you must do it one way or another... Good luck

Twincity9
Earned a small fee
Earned a small fee
Posts: 11
Joined: Thu Jan 24, 2019 9:24 pm

Re: Not all events are showing in CodeBlocks

Post by Twincity9 » Fri Jan 25, 2019 2:20 pm

The line is the same idea as in CodeBlocks. It is by default dissabled but you can enable it under Settings->Editor->Margins and Caret. I am making an application that uses Lua scripts and I am always used to enable that feature in CodeBlocks and RAD Studio and NotePad++ when coding in C++. It should be possible to add that line because CodeBlocks is also created with wxWidgets. The line does not need to be fixed to an exact number of characters, just setting it by number of pixels as an x-coordinate is sufficient for me. Characters that are over the line are still drawn.

The people on the CodeBlocks forum told me to add the paint event manually, so I did. It did not solve all problems but I was told there that this is a wxWidgets question, not a CodeBlcoks or wxSmith question. So I was send back to this forum.

The paint event is not called when the wxTextCtrl is resized, the drawn line dissapears when that happens (it is redrawn but the paint event is somehow bypassed). Enabling wxFULL_REPAINT_ON_RESIZE for the wxTextCtrl has no effect. So I also added a Size event handler, that problem is solved. But the wxTextCtrl is inside a wxNoteBook as a page. When I switch pages the line also dissapears. Redrawing the line in the notebook's page-changed or page-changing-event handler has no effect.

Am I overlooking something? Isn't there one location where I can add the draw code so that it always affects the look of the wxTextCtrl?

PB
Part Of The Furniture
Part Of The Furniture
Posts: 1914
Joined: Sun Jan 03, 2010 5:45 pm

Re: Not all events are showing in CodeBlocks

Post by PB » Fri Jan 25, 2019 5:08 pm

Both Code::Blocks and Notepad++ use Scintilla for their text editor. wxWidgets Scintilla wrapper is called wxStyledTextCtrl. I would look into using wxStyledTextCtrl instead of wxTextCtrl. I have never used Scintilla/wxStyledTextCtrl, but I believe this is the group of functions for the feature you described: https://docs.wxwidgets.org/trunk/classw ... #LongLines
The feature is also used in the stc sample bundled with wxWidgets (run the sample and in the menu View chose Show long line marker).


As for the painting over a standard control, wxWidgets documentation for wxPaintEvent has
Please notice that in general it is impossible to change the drawing of a standard control (such as wxButton) and so you shouldn't attempt to handle paint events for them as even if it might work on some platforms, this is inherently not portable and won't work everywhere.
So, as I wrote before, perhaps trying to do that may not be the best approach.

catalin
Moderator
Moderator
Posts: 1504
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Re: Not all events are showing in CodeBlocks

Post by catalin » Fri Jan 25, 2019 6:05 pm

You should have probably split your discussion into multiple topics, i.e. 1) the current subject; 2) "how do I get a vertical line [...] text editor?".

Look at the subject of this topic - that is a C::B-related.
Handling paint events - wxW-related, of course.

I'd be very surprised if handling paint events for text control under MSW port will even draw anything, let alone creating artefacts if it did. And most probably there is no one single place that you'd need to add drawing code to work around various non-supported scenarios (at least I can't think of one).

As PB already told you, going for the Scintilla component should be your best bet.
Another widget that may help you - probably easier to implement but still quite different than Scintilla - is wxRichTextCtrl with its PaintAboveContent() virtual function.

Twincity9
Earned a small fee
Earned a small fee
Posts: 11
Joined: Thu Jan 24, 2019 9:24 pm

Re: Not all events are showing in CodeBlocks

Post by Twincity9 » Fri Jan 25, 2019 9:13 pm

Thanks PB, that answer is what I was looking for.

I've replaced the wxTextCtrl with a wxStyledTextCtrl and the option to add a vertical line is already there. I just added these two lines:

StyledTextCtrl->SetEdgeMode(1);
StyledTextCtrl->SetEdgeColumn(500);

So now I don't have to paint anything myself. And the good thing is that the control also has support for lua syntax, I wasn't even planning on adding that because it would be too much work but this is way better.

And Catalin, it is true that the first post started more as a CodeBlocks (wxSmith) topic then a wxWidgets topic. I wasn't fully aware of that, my mistake.


Thanks for the help

Post Reply