Text box
Text box
Hi, could anyone please explain to me or give me some references on how does the logic behind a text box work? Most importantly I am interested how does the inserting/cutting text work. It does sound really simple, but I just can't find out a complete way to do this.
Re: Text box
The textbox should keep track of the string and it's cursor position (as well as a starting point of the highlight if you're selecting text). When it's time to insert you insert this new string at the cursor in the textbox string. When it's time to cut you know to take out the portion of the string between the two points.
How advanced are you looking? Full blown OO? If so I suggest looking at some source codehttp://guichan.sourceforge.net/api/. It's a pretty good demonstration of the inner workings of a GUI.
How advanced are you looking? Full blown OO? If so I suggest looking at some source codehttp://guichan.sourceforge.net/api/. It's a pretty good demonstration of the inner workings of a GUI.
Re: Text box
I have already used a text box when typing the question, you don't really need to explain what it does . I am rather intrested in how is the text stored and what actually happens with memory when inserting and cutting. I doubt you move some char array after each insert/cut.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Text box
If you consider how much bytes would actually be copied in a single line of text if you cut one out of it, it's typically not going to be more than three digits. Is that a meaningful amount to try and let loose any more complex method?
Re: Text box
Well... no What if there is 1MB text after the position from which you cut? But real thanks for mentioning it, it made me actually try it out in notepad and boy is it slow as hell. Originally I was actually doing insert/cut in binary data with approx 1MB in size and since its a lot of cuts and inserts I tried to somehow convert the problem, but apparently WinAPI text boxes are not gonna... uhh cut it
Anyway I have an idea how to do it, now that I know it is not gonna be worse than the usual way I'm gonna do it. Thanks.
Anyway I have an idea how to do it, now that I know it is not gonna be worse than the usual way I'm gonna do it. Thanks.
Re: Text box
Hi,
If you're going to be doing a lot of editing, have you looked at piece tables?
Cheers,
Adam
If you're going to be doing a lot of editing, have you looked at piece tables?
Cheers,
Adam
Re: Text box
That's actually what I had in mind, never heard of the term though. Still, in case of text box it could be a little bit time consuming when displaying the text, but better than moving the array all the time for sure. I just tried a little bit of editing in Notepad++ and it seems it does not have this problem I saw in classic notepad. Before I commit to do it with piece table I will yet try to compare the source codes of these two. Maybe I will find out Notepad++ uses piece tables already
Re: Text box
Good luck with that. The notepad that comes with windows is closed source.pyjong wrote:Before I commit to do it with piece table I will yet try to compare the source codes of these two.
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
If you're new, check this out.
Re: Text box
Well.. it is, buuut... c'monThe notepad that comes with windows is closed source.
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: Text box
Off the top of my head: arrays, gaps, linked lists, line spans, fixed size buffers, piece tables, ropes, etc. The method you ought to use depends on many things: memory constraints, how common each type of operation is, maximum text length, required features such as history of changes, etc.pyjong wrote:Hi, could anyone please explain to me or give me some references on how does the logic behind a text box work? Most importantly I am interested how does the inserting/cutting text work. It does sound really simple, but I just can't find out a complete way to do this.
If your knowledge is insufficient to do even rudimentary string manipulation efficiently, why are you tricking yourself into thinking you can develop an OS? Get a book on algorithms and data structrues, study it carefully, and come back once you are ready. (Sorry for being so blunt.)
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]