×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Popup Menu help
3

Popup Menu help

Popup Menu help

(OP)
Hi All,
I rarely use the VFP Menu systems, but I do find the POPUP menu capability really useful.
I have a POPUP menu that I'm using for things like Copy, Paste, Undo, Redo, etc.
One thing I noticed is that the "skip for" allows for "disabling" options. So to that I have two questions:

1) Is there a way to show "Paste" disabled when nothing is available in the clipboard? (I'm using the _MED_COPY, _MED_CUT and _MED_PASTE options with Bar # for these when "selected")
2) When an item is disabled, the icon turns to just a grey block. Is there some way to show a "disabled" icon?


Best Regards,
Scott
MSc ISM, MIET, MASHRAE, CDCP, CDCS, CDCE, CTDC, CTIA, ATS

"I try to be nice, but sometimes my mouth doesn't cooperate."

RE: Popup Menu help

Good question, Scott. I wish I knew the answer.

I was always under the impression that, if you use _MED_PASTE, the Paste option would automatically be disabled if there was no text to paste. Similarly, Copy and Cut would be disabled if there was no text highlighted. But I've just checked my own apps, and I see that's not the case.

In fact, Paste is active even if the target control is read-only.

If you manage to find the answer, I would be glad to know about it.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Popup Menu help

1) you can SKIP FOR glBoolvalue - a public variable and then change that. It can even be a function call returning a boolean .T. or .F., but you won't define the times this is evaluated nor will the change of a public variable trigger the change of the menu item. The SKIP value will at least be evaluated when the popup is drawn and when you hover the menu item with the mouse. My experiences with this are from applying SKIP for conditions by user permissions and for that matter I created a caching mechanism so a call to the permission function would answer with a cached value rather than looking up user permission. That's the only way to cope with the amount of calls to not burden the application mainly doing user permission function calls. The cache value has a lifetime of a few minutes only to enable enough control about user permissions.

In the end, it is possible as determining EMPTY(_CLIPBOARD) is quite a fast operation, is local and thus needs no caching, but experiment with SKIP FOR EMPTY(_CLIPBOARD) yourself, I won't guarantee it to work flawlessly. Make it SKIP FOR emptyclipboard() and a function of that name logging each call and returning EMPTY(_CLIPBOARD) and you'll see how often this is called.

You can also SET SKIP OF, but then need to intercept any change of _clipboard. You'll need BINDEVENT to Windows messages about the clipboard to get that fancy.

It's quite useless to do that even better than Word processing software. A user will see whether something is in the clipboard by pasting. I sometimes find myself surprised I couldn't copy something, more often when "copying" images or pressing PRT key not putting a screenshot into the image clipboard than when copy&pasting text.

2) DEFINE BAR only has the picture clause, unlike a command button also having a DisabledPicture you only have the greyed out effect as is also automatic to buttons with no specified DisabledPicture.

If you want that behaviour you'd need to create your own SKIP effect within the code triggered by a menu item only acting when the SKIP condition is false, but then you also don't have the greyed out menu item text. Besides while there is SET SKIP OF there isn't SET PICTURE or similar, so you'd need to RELEASE BAR and redefine it to reflect changes that way. You might even start creating your own popup forms for menus if you start going that detailed about features not offered natively or barely offered by stretching the capabilities in such ways. It might even be simpler to make use of web browser control and using any JS/CSS library for web menus to get where you want using something existing from that web development domain.

There is the VFPX OOP Menu and in the SFBar class the skip for condition, caption picture and so on are properties, but there is no cPictureFile_assign method, so changing this cPictureFile when the bar already is rendered doesn't change it, the oop menu still bases menu bars on native VFP menu bars.

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

RE: Popup Menu help

Scott, after posting my reply I realised that, if the clipboard contains no text, then EMPTY(_cliptext) returns .T. So you could use that condition in your Skip For clause to disable the Paste command.

I see Olaf has already mentioned that possibility.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Popup Menu help

But you would also need to disable the Paste command if the parent control was read-only. To do that, you would need an object reference to the control to be available to the menu:

CODE -->

* In the right-click event of the control
poObject = THIS
DO MyMenu.MPR

* In MyMenu.MPR
DEFINE BAR _med_paste OF shortcut PROMPT "\<Paste" ;
  PICTRES _med_paste ;
  KEY CTRL+V, "Ctrl+V" SKIP FOR EMPTY(_cliptext) OR poObject.ReadOnly 

And now that you have the object reference, you could disable the Copy and Cut commands if no text was selected:

CODE -->

DEFINE BAR _med_copy OF shortcut PROMPT "\<Copy" ;
  PICTRES _med_copy ;
  KEY CTRL+C, "Ctrl+C" SKIP FOR poOjbect.SelLength = 0

DEFINE BAR _med_cut OF shortcut PROMPT "Cu\<t" ;
  PICTRES _med_cut ;
  KEY CTRL+X, "Ctrl+X" SKIP FOR poOjbect.SelLength = 0 

In those cases, you wouldn't need to test for read-only.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Popup Menu help

(OP)
Hi Mike,
This was awesome. Sorry it took so long to get back to this point, but couple other bugs and client demands took me away from it. I just came back to it, implemented it as you mention and it worked!
So now I am using a single pop-up menu (Edit menu) that also carries my "Google ME!" feature with it, and disables Paste (and a few other controls) based on the state and type of field the focus is on. Really slick!

Best Regards,
Scott
MSc ISM, MIET, MASHRAE, CDCP, CDCS, CDCE, CTDC, CTIA, ATS

"I try to be nice, but sometimes my mouth doesn't cooperate."

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close