File Exchange

image thumbnail

showcontextmenu

version 1.4 (7.46 KB) by

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

1 Download

Updated

View License

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'

Comments and Ratings (5)

Igor

Igor (view profile)

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

Brett Shoelson

Brett Shoelson (view profile)

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.

nsbd

nsbd (view profile)

Igor

Igor (view profile)

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

Loginatorist

Loginatorist (view profile)

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

1.4

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

1.3

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

1.2

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

MATLAB Release
MATLAB 7.12 (R2011a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video