PDA

View Full Version : ContextMenu inheritance


vernid
11-01-2007, 01:45 AM
Hi,

I have a view which contains subviews. I have defined a contextmenu on the main view and I would like that all subviews have it too.

So, I would like in fact that all subviews inherite the contextmenu from its parent.

Code example:

<canvas>
<view name="v" width="50%" height="50%" bgcolor="blue">
<handler name="oninit">
var cm1 = new LzContextMenu(); cm1.hideBuiltInItems();
this.setContextMenu(cm1);
</handler>
<view width="50%" height="50%" bgcolor="red">
</view>
</view>

</canvas>

I would like that the red view got my context menu.

Is there a way to say that a view must inherite from the parent menu without creating it from the view (oninit)?

Thanks
Dominique

senshi
11-01-2007, 05:36 AM
I guess you need to iterate over all subviews and sub-subviews etc.
and assign for every view the context-menu:


<view name="v" width="50%" height="50%" bgcolor="blue">
<handler name="oninit"><![CDATA[
var cm1 = new LzContextMenu();
cm1.hideBuiltInItems();
this.setContextMenu(cm1);

var sv = this.subviews;
if (sv) {
for (var i = 0; i < sv.length; ++i) {
var sview = sv[i];
sview.setContextMenu(cm1);

var ssv = sview.subviews;
if (ssv) {
sv = sv.concat(ssv);
}
}
}
]]></handler>

<view width="50%" height="50%" bgcolor="red">
<view width="50%" height="50%" bgcolor="green">
<view width="50%" height="50%" bgcolor="yellow">
<view width="50%" height="50%" bgcolor="white">
</view>
</view>
</view>
</view>

</view>

vernid
11-01-2007, 09:02 AM
Thanks,

I would tought about a recursive solution, but you show me that we can change a vector while iterating on it which is often an issue in Java.

Regards
Dominique