Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cut, Copy, Paste to a Top Level Form & No Menu 1

Status
Not open for further replies.

stanlyn

Programmer
Sep 3, 2003
945
US
Hi,

How do I add cut, copy, and paste functionality to a single page VFP9 app that only uses a top level form. I do have a main.prg that starts it up. No menu of any kind.

Thanks,
Stanley
 
That is to programmatically paste, but that's not the problem of stynlyn, I think.

First of all realize that even such usually system wide available hotkeys for copy, cut and paste are no longer available, if you don't have any menu at all. You don't have to now add a menu to your own top level form, it is enough if those menu items are defined in a context menu, even if you never ACTIVATE it.

In the end, to save you some steps in generating a shortcut menu:
Code:
DEFINE POPUP copypaste SHORTCUT RELATIVE FROM MROW(),MCOL()
DEFINE BAR _med_copy OF copypaste PROMPT "\<Copy" ;
	KEY CTRL+C, "Ctrl+C" ;
	MESSAGE "Copies the selection onto the Clipboard"
DEFINE BAR _med_paste OF copypaste PROMPT "\<Paste" ;
	KEY CTRL+V, "Ctrl+V" ;
	MESSAGE "Pastes the contents of the Clipboard"
DEFINE BAR _med_cut OF copypaste PROMPT "Cut (<\X)" ;
	KEY CTRL+X, "Ctrl+X" ;
	MESSAGE "Removes the selection and places it onto the Clipboard"

If you want to create this from scratch you create a menu via VFP "new" toolbar. You get there by picking New->Menu->new file->shortcut. Then to add system menu items click "Insert Bar" and yo get a choice of all system menu item sorted by menus and you can also sort it by prompt, so you find Copy in C, Paste in P, etc. You might add more than copy, paste, and cut to make more such things available. To be very clear, you don't define these items by hand and need to lookup the menu constants like _med_copy, the list of items to pick from by using "Insert Bar" will know all these constants and is your valuable time saver.

It's not a bad idea to also enable the user to use a context menu when he right clicks on your form controls, which offers options viable for that control, like these is viable for textboxes, comboboxes in combo style (not in dropdown list style), editboxes, and in general whereever a selection of text can be made in a control.

You could even design mjultiple context menus, at best one individual shortcut menu per control on your form. Actually that's a step to conform to Windows UI pepople rarely do in a VFP application, though if it would be more commonly done this wold naturally put such menu items where they belong to be. A strategy would be that activation of a control releases the current shortcut menu and defines the one for that control without activating it, as that's done by the user by a rightclick, but the options should be available also by hotkey definitions.

Just think of that everytime you do a rightclick on any application on anything and find valuable options you could use in that context there, even if the same things can be done without using the context menu. There's also no reason to not use a context menu, if you're a keyboard user, as ther is that button with a paper sheet and some lines, well no, it's not a paper sheet it symbolizes a context menu.

Chriss
 
One way of incorporating this as a general way of context menus in your application:

1. Design all base classes (It's a well known and mostly ignored general advice to do)
2. In all your control base classes add a method "definecontextmenu"
3. In the Gotfocus event do
Code:
This.definecontextmenu()
4. In the rightclick event do
Code:
This.definecontextmenu()
ACTIVATE POPUP context
The reason you don't just ACTIVATE POPUP context, but also redefine the context menu is that you don't want to show it at the position the mouse was when activating the control, but at the current mouse position MROW(),MCOL(). I know you could also define a popup once and the MOVE POPUP context TO MROW(),MCOL(), but in general, believe me, your context menu will contain items in context of the current state of the application and that control and you will also want to vary more things than just the position, like having some items and not others. So overall defining the context menu at GotFocus to have the hotkey usability is one thing and defining it at the time of the rightclick is another thing that'll pay off long term.

In the definecontextmenu method you can define your individually needed context menu. At minimum for copy&paste functionality:
Code:
DEFINE POPUP context SHORTCUT RELATIVE FROM MROW(),MCOL()
DEFINE BAR _med_copy OF context PROMPT "\<Copy" ;
	KEY CTRL+C, "Ctrl+C" ;
	MESSAGE "Copies the selection onto the Clipboard"
DEFINE BAR _med_paste OF context PROMPT "\<Paste" ;
	KEY CTRL+V, "Ctrl+V" ;
	MESSAGE "Pastes the contents of the Clipboard"
DEFINE BAR _med_cut OF context PROMPT "Cut (<\x)" ;
	KEY CTRL+X, "Ctrl+X" ;
	MESSAGE "Removes the selection and places it onto the Clipboard"

Doing it that way, you have it quite automatic aside from the actual context menu definition in each control. And even this would not mean you have to individually program every controls definecontextmenu, this code could be the default in all base control classes, so you only override this with an individual menu when you have some more specific items you want to offer to the user.

Chriss
 
And even if you decide against the context menu implementation in your application, just define one POPUP once at startup, never activate it, and the items with a hotkey definition work throughout all of your application.

Chriss
 
Hi,
Mike said:
Take a look at the Help for SYS(1500).

Chris said:
That is to programmatically paste, but that's not the problem of stynlyn, I think.

Chris is correct as I attempted something similar, and the help specifically says...
VFP Help said:
User-defined menu items and disabled system menu items cannot be activated with SYS(1500).

I could never get it to work, and since I have no menus, then read this help article, I gave up on that and asked here.

The needed functionality is the same as for any other windows app. Select the text, then cut or copy or paste over the selected.

Chris's reply will do it and actually has more power and at the individual control level. I didn't need that much power, just simple cut, copy, and paste.

For now, "scope creep" solved my need for this as I went away from the Top Level form as Desktop, to a plain form within the _Screen object with a custom menu made for the app that does a lot more than cut, copy, paste.

Thanks Chris as I can see using your suggestion for other functions as well via the context menu.

Stanley
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top