Is there a window setting for keeping a selected passage of text even after the text has been changed/refreshed? - c++

I have a CEdit-Box containing some text, which is being refreshed by a thread every ~0.25 seconds. The problem is that everytime the text is being refreshed, a possible selection of text is being erased.
I found 2 ways to avoid this so far:
My implementation right now (1) :
Use quite a passage of logic in order to assure that the text is actually really changing, and not just refreshing itself with the exact same string. This is kind of avoiding the problem, but it feels very clunky to be honest.
Another idea (2) :
Every cycle, before the text is being refreshed, we need to grab the selection we currently have, store it, and try to reconstruct it after our text has been refreshed. However, I don't know how this would turn out if the new text doesn't contain our old string at all. I guess the functionality is implemented in WTL, but I don't think this is a very good approach.
Is there any other way? Something like a control setting which would do something like this?

Related

Hiding scale x value in graph editor

Im trying to do a simple animation and the scales x value is constant and i dont need to edit at all. however it still show on the graph editor which would be fine if the handles on the keyframes didnt overlap. its not preventing me from getting the work done but its making it take a lot longer having to fiddle with finding just the right spot to grab the proper handle
Have you tried the "Separate Dimensions" button?
Separate Dimensions
If that doesn't work, you could try tying the property you want to edit (the y-value) to a slider value via an expression, and just editing in the expression.

How to hide the header on an Xsl Fo, page overflow

I have a header, a body, and a footer set up for an Xsl Fo page sequence. There are certain items displayed on this page in blocks with a keep-together.within-page value of 1. This works really well for the most part, but I've noticed that when stuff that will span an entire page or more absolutely has to break it will end up on a new page and then get cut (which is fine) but then the header gets drawn in the middle of this making everything look a little gross/confusing (not fine) as whatever remains is drawn onto the next page.
So I'm wondering, is there some way to suppress the header on content overflow into the next page?
Or is there some way with alternative page sequences or something to achieve what I want?
Sorry for the vagueness here, and a lack of a current working representation of what's going on. I am very new to Xsl Fo, and most of our working code is under an abstracted framework, but if I knew of the correct directives or if this was possible I'm sure I could implement them into the framework and get things working.
Edit: I have attached a picture to hopefully clarify what is going on
You could put the content that you want to hide in an fo:marker and use fo:retrieve-marker in the fo:static-content that flows into the 'region-before' region.
The trick is to put a copy of the 'real' fo:marker before each of the blocks with the keep-together and also put an empty fo:marker with the same marker-class-name as the first thing inside the block. (I don't know what your XSL-FO markup is like, but you may need to put an fo:wrapper around each block as a place to put the 'real' marker.)
If retrieve-position is first-including-carryover (see https://www.w3.org/TR/xsl11/#retrieve-position), then you should get an empty fo:marker for blocks that broke across the page boundary and get the 'real' fo:marker on other pages.

WXWidgets TextCtrl or RichTextCtrl

I'm using wxWidgets for a log window of a piece of software which runs for many hours. The log can accumulate 10,000's of entries. Does the community have a suggestion for how not to have the GUI thread choke for many seconds when updating a textctrl or richtextctrl with this many lines? I'm open to using either control type but richtext is preferable to I can highlight warnings or errors.
It's currently set to readonly, so undo, redo, paste, etc are not active. I'm currently freezing and thawing it before and after adding content.
In a test case, I add 10000 lines to the text control with a freeze and thaw before and after. This operation still takes over a minute. Are these text controls simply incapable of handling long content?
Assuming your display is like a log, where each "line" is it's own entry, try using the wxListCtrl in "virtual mode". Basically, you maintain the data in your own control (a vector, array, whatever works) and the control asks you for only the data that is currently visible.
Inherit wxListCtrl with your own class and implement OnGetItem. When a row is visible, your derived control will have this method called for each row (and each column if you implement multiple columns) and you provide it with the data for that row, accessed directly from your array (list, vector, whatever).
More information is available in the wxWidgets docs here: http://docs.wxwidgets.org/3.0/classwx_list_ctrl.html#a92370967f97215e6068326645ee76624
The suggestion to use wxListCtrl in #avariant answer is a good one, however a wxTextCtrl with wxTE_RICH style should still be capable of appending 10000 lines in well less than a minute if you freeze/thaw it before/after. I'd be curious to know if you can reproduce the problem in the text sample included with wxWidgets (which already has a menu item doing something like this) and, if so, which wxWidgets port do you use.

How to store syntax-highlighted text?

I am creating a simple text editor with syntax highlighting from scratch as a school project. Right now, I use QStringList for storing the text data but later I'll be adding the syntax highlighting functionality and I don't know how should I store the data.
One option would be not to save the color information at all and continuously getting it from the code parser. But this would be probably very inefficient.
Maybe better idea is that there would be some list of structs (containing the color and the string) for every line which would store the color for every word in the text. But I'm not so sure how fast will this be either.
What is the best way to store these data?
Thank you
I'll suggest two methods.
Method 1: Store text with attributes
Change your data structure to a container of structures. The structure would contain a text string and a style variable:
struct Text_With_Properties
{
std::string text;
Properties text_properties;
};
This may take up a lot more space and may not be the most efficient method.
Method 2: Parse for Style Changes
Many editors will display the text in normal font, then make another pass parsing for style changes. For example, when a C++ keyword is found during the 2nd pass, the editor would change its style.
This method does not require any more space for the data, but does require more processing time.
This question is probably too broad. But you could probably use HTML markup. It would give you an easy way to test, as well, as you could open up the output in a browser.

How do I write a WYSIWYG editor?

I would like to program a WYSIWYG editor for HTML. I'm looking for a high level approach, which I will eventually be implementing in C++.
My initial approach is to create a hierarchy of classes which extend a common base class (node). So object "body" would contain object "p" which would contain object "b" which would contain some text.
class node {
node *parent;
vector<node> children;
string name;
map<string,string> attributes;
string text;
virtual void render(const rect &rect, const point &offset) = 0;
virtual void onEvent(const event &e);
}
The main engine would call something like body.render(screen, point(0, 0)), which would recursively render its children.
The cursor would be represented by a pointer into the object hierarchy, and each node would have its own internal cursor state, and would respond to keyboard events when it is the selected node.
For example, if the user hits the left-arrow, and the "p" node is selected, the "p" node's reaction to the keypress might be to change the current node to the parent of "p".
Abstractly, it seems like this could work, the closest thing I can find to what I'm looking for is Sigil, which at first glance seems pretty intimidating to study (main.cpp is 70k).
Before I go down this road, I was wondering if anyone had a simpler approach, or can see any pitfalls with this method.
A simpler approach, if you can do this, is to embed a web browser in your application and set contentEditable="true" on <body>. If you're on Windows, you can use the built-in one, or you can embed an engine like Gecko or WebKit.
You can look at doing color picking.
Basically you render everything twice. Once is what is displayed to the user.
The other is a bunch of bounding boxes done in unique random colours that you can turn back into pointers via a hashtable lookup or whatever. This allows you to quickly locate what is under a mouse cursor without having to recursively look up every object. You might want to miss the currently selecvted object from the color picking that way you can click twice to get the object below you current one (if you want to keep going for lower you will need to mess around with zorder depth somehow. Maybe don't render anything in the selected elements bounding box region that is over the zorder of your currently selected object).
Finally once you have selected the specific element you can enter a sub editing mode. For example turning a block of text into an editable text box with a blinking cursor, drawing borders/handles around your element to allow you to resize/manipulate it and showing a list of properties.
Realistically if your looking at making a HTML WYSIWYG editor, that will also require a HTML rendering engine. Unless you plan to make your own from scratch (which is a massive undertaking by itself), or only plan on implementing a very limited subset of HTML (which would still be fairly time-consuming). Most HTML renderer engines will include some kind of support for tapping into things like object picking. It might be worth grabbing webkit and seeing what it supports. Maybe look at the Chromium source code (Chrome includes an inbuilt webpage inspector that isn't too far off being an editor (it allows object picking and runtime editing of properties but the editing isn't totally WYSIWYG since its done in an external window, but that might be enough for what you want.
You might even do better to look at writing you editor (or parts of it) as some kind of JavaScript/Grease Monkey extension that you can load over the page being edited. You could write your whole editor in HTML or just add some support handle wrapper script that communicates to your native program.