Text box

Programming, for all ages and all languages.
Post Reply
pyjong
Posts: 8
Joined: Sun Oct 07, 2012 6:23 am

Text box

Post by pyjong »

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.
Opcode
Member
Member
Posts: 29
Joined: Mon Apr 01, 2013 2:50 pm

Re: Text box

Post by Opcode »

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.
pyjong
Posts: 8
Joined: Sun Oct 07, 2012 6:23 am

Re: Text box

Post by pyjong »

I have already used a text box when typing the question, you don't really need to explain what it does :D . 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.
User avatar
Combuster
Member
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

Post by Combuster »

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?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
pyjong
Posts: 8
Joined: Sun Oct 07, 2012 6:23 am

Re: Text box

Post by pyjong »

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.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Text box

Post by AJ »

Hi,

If you're going to be doing a lot of editing, have you looked at piece tables?

Cheers,
Adam
pyjong
Posts: 8
Joined: Sun Oct 07, 2012 6:23 am

Re: Text box

Post by pyjong »

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 :)
Mikemk
Member
Member
Posts: 409
Joined: Sat Oct 22, 2011 12:27 pm

Re: Text box

Post by Mikemk »

pyjong wrote:Before I commit to do it with piece table I will yet try to compare the source codes of these two.
Good luck with that. The notepad that comes with windows is closed source.
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
pyjong
Posts: 8
Joined: Sun Oct 07, 2012 6:23 am

Re: Text box

Post by pyjong »

The notepad that comes with windows is closed source.
Well.. it is, buuut... c'mon ;)
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Text box

Post by Love4Boobies »

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.
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.

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 ]
Post Reply