Code covered by the BSD License  

Highlights from
showcontextmenu

5.0

5.0 | 1 rating Rate this file 13 Downloads (last 30 days) File Size: 7.46 KB File ID: #31448
image thumbnail

showcontextmenu

by

 

14 May 2011 (Updated )

Simple way to show contextmenu on left click in a nice drop-down way.

| Watch this File

File Information
Description

Use as follows:
---------------------------------
hcmenu1 = uicontextmenu;
uimenu(hcmenu1,...);
uimenu(hcmenu1,...);
showcontextmenu(hObj,hcmenu1);
---------------------------------
Try test_showcontextmenu.m for usage example.

This also contains a number of trivial routine functions:
getParentFigure(hObject)
%returns hObject's parent figure

getPositionOnFigure( hObject,units )
%returns absolute position of object on a figure

getRelPosition( hObject,units )
%get(hObject,'Position') with specific 'units'

getCurrentPoint( hFigure,units )
%get(hFigure,'currentpoint') with specific 'units'

MATLAB release MATLAB 7.12 (R2011a)
Other requirements Not tested,but should work with even quite outdated versions.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (5)
22 Jun 2012 Igor

Hi Brett,
thank you!

Concerning FINDALL, are you talking about
test_showcontextmenu3.m line 9?

You're right, and the thing is
get(tbh,'HandleVisibility') == 'off'
that's why we have to use FINDALL...

22 Jun 2012 Brett Shoelson

I haven't tried this yet, Igor, though it looks interesting. I'm intrigued by your use of normalized units, and of the steps you had to take to make this all work in them. (I'm a fan of normalized units, too, and have done similar things.)

Also, I wanted to point out that FINDALL (as opposed to FINDOBJ) returns all children of a specified object, including those whose handles are hidden.

18 May 2011 nsbd  
17 May 2011 Igor

Thanks for your comment,Matt.
I've updated the submission so that it can now handle line as object.

(However I'm still not sure this would work for all such objects (without 'units') since 'current point' seems unreliable in case of button at least.)

16 May 2011 Matt Fig

This function will error on versions of MATLAB which do not have ASSERT. For example 2006a.
Also, if the handle of the object does not have a 'units' property, the function errors. A line, for example, may have a uicontextmenu, but does not have a 'units' property.

Updates
17 May 2011

+support for lines etc. (objects without 'units' property (menu would be displayed on click position)
+"assert" removed with if..error

27 May 2011

Thanks to Jesse this now supports uipushtool and uitoggletool objects (toolbar items).
usage example provided in test_showcontextmenu3.

21 Jun 2012

added test_showcontextmenu4:
in this example, in contrast to test_showcontextmenu, right-click menu is shown below the button (not on click position)

Contact us