Solved

Copy,cut,paste,undo,redo in C++

Posted on 2009-04-07
4
2,116 Views
Last Modified: 2013-11-17
I am trying to create an application like Notepad. Where can I find functions for copy,cut,paste? Also , there will be more than one Edit objects, so , how can i make the undo function to undo the last general action? (I cannot use Edit1->Undo() because there are multiple Edit objects)

Thanks
0
Comment
Question by:Chrysaor
  • 3
4 Comments
 
LVL 4

Expert Comment

by:KrisTheComputerGuy
ID: 24092482
I found a tutorial on how to use the Command software design pattern to support multiple undos.

http://kapo-cpp.blogspot.com/2007/10/multilevel-undo-with-command-pattern.html

Design patterns can be tricky at first. But their pretty cool stuff.
0
 
LVL 4

Accepted Solution

by:
KrisTheComputerGuy earned 250 total points
ID: 24092762
I guess I'm a bit confused on the question. I had assumed your looking for a multi-undo solution where the use can undo and redo multiple times. But rereading the question it seems much simpler now. The previous post has a lot of jargon in it related to UML and advanced Object Oriented Concepts. It'll likely be overkill & overwhelming. Sorry about that.


If however you only need a single undo/redo solution that works for the last text box changed, then I can suggest the following solution.

Cut copy, paste, undo & redo are likely already built into the objects themselves. Check the documentation by pressing F1 while a class is selected in the editor. Borand Builder objects have an event that is called when the object's value is changed. I forget the name of the event.

Do you know how to use pointers? They are useful. For a single undo, all you need is a global pointer in your software that remembers (points to) the last object which had its value changed. Have the events update the global pointer, assigning the .this pointer to the global.  Then have the undo button simply do a call on that pointer. Don't forget to set you initialize your pointer to NULL (and to check for null in the undo/redo) to prevent catastrophies.

For redo you can simply setup another pointer that gets assigned the value of the undo pointer when undo is selected by the user. Setting the undo to NULL.



Also: Check out this tutorial for some great info on using borland C++ builder
http://www.yevol.com/en/bcb/
http://www.yevol.com/en/bcb/Lesson25.htm   (memos & rich edit boxes)
0
 
LVL 4

Expert Comment

by:KrisTheComputerGuy
ID: 24092796
You can find a tutorial on pointers at:

http://www.cplusplus.com/doc/tutorial/pointers/
0
 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 250 total points
ID: 24094875
Hmmm. Don't think taht pointers can solve the issue without a general design. For a single undo or redo the user can take the functionality of the edit control anyhow (CTRL+Z or CTRL+Y). But if you want to go back multiple steps done in different edit controls, check-boxes, comboboxes, you rarely can do that by switching a few pointers.

You better make a new class/struct - e. g. named Operation - which has the following members:

   - ID of the control which was changed
   - contents before change
   - contents after change

and a container - e. g. a std::vector<Operation> - where you can store new objects of that class together with a 'current' index which always points to that slot of the container which was current.

Then for any major update of the user - you create a new Operation which protocols that update and add it to the container.

In case of an 'undo', you read the last operation from container and make it reverse, i. e. put the previous contents back to the control and decrement the 'current'. In case of a redo go forward (if any entries were available) and increment the current. If there are new updates while the current was not last you delete all forward operations and make the new update the last.

To detect 'major updates' you could handle teh WM_SET_FOCUS message when the user leaves one control and goes to the next. Or, if you want to track partial changes in a big edit control, you have to log all single key-strokes or updates of an edit control and the operation structure needs to be adapted to taht.
 
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now