01-30-2014 02:38 AM
Hello,
I have simple question:
Parent (main) panel has a menubar and menuitems (menu_callbacks), with some shortcut keys (like <F5>, <Ctrl>+<R> etc).
The task is propagate the keystroke from the child panel to the parent panel when the parent panel is INACTIVE.
I try to make solution via EVENT_KEYSTROKE and CallPanelCallback(), but this solution doesn't work correctly ...
Any hits will be appreciated!
George
01-30-2014 04:48 AM - edited 01-30-2014 04:49 AM
This should be the default behaviour of child panels. The mechanism can be determined by ATTR_PARENT_SHARES_SHORTCUT_KEYS attribute of child panels: if True (1) an unrecognized shortcut key issued on the child panel is passed to the parent one.
The default value for this attribute is to enable the mechanism, so unless this option has been explicitly disabled the system should work correctly: are you observing a different behaviour? (Just for clarity: you should code nothing to obtain this!).
01-30-2014 05:46 AM
HI, Roberto,
I have already set this attribute for all child panels - and originaly I supose this would be the solution.
But it doesn't work - the keystrokes (line <F5>) from chils panel are not seen in parent menu_callback function or parent panel panel_callback.
(I'm using CVI2013f1)
George
01-30-2014 06:14 AM
Keys installed as a shortcut to menu items are not received in the panel callback; they trigger the menu item callback instead, if it exists, otherwise they are lost.
The panel callbacl only receives keys which are not assigned to controls or menu items.
Take a look at the attached sample: it's a modified version of "panels" example that ships with CVI.
I have set a menu bar on the main panel whith items associated to Ctrl+O, Ctrl+P and Ctrl+V shortcuts, while items in the child panel menu bar are associated to F1 to F4 keys. A message pops up each time you press a key: is a shortcut from main panel menu items, the menu callback is fired, if the child panels are shiwn, F1-4 keys again trigger the menu callback, otherwise they are trapped by the callback of the main panel. Other keys always trigger the panel callback. If child panels are not shown, even F1 to F3 trigger the panel callback. If you remove a callback from one menu item, you will see that the corresponding key is not trapped by the panel callback: it is lost since the menu item hasn't a callback associated to it.
01-30-2014 06:15 AM
Forgot to say: this examples is developed in CVI2009: I don't suppese this behaviour has changed in 2013 release, nevertheless you can try on your machine and if you see something different please post here your observations.
01-30-2014 07:20 AM
01-30-2014 07:49 AM
Well, the simplest way to obtain that effect is this one: inside the so-called "child" panel you can trap EVENT_KEYPRESS event, next on the keystroke you decide to you can simply directly call the panel callback of the "parent" panel passing event, eventData1 and eventData2 parameters the same exact values you received.
01-30-2014 08:27 AM
Hi,
That's I allready try - without sucess ...
"first - child panel":
case EVENT_KEYPRESS:
if (!KeyPressEventIsLeadByte (eventData2)) {
character = GetKeyPressEventCharacter (eventData2);
virtual = GetKeyPressEventVirtualKey (eventData2);
modifiers = GetKeyPressEventModifiers (eventData2);
if (virtual) {
CallPanelCallback (main_pMain, EVENT_KEYPRESS, eventData1, eventData2, NULL);
}
}
break;
The EVENT_KEYPRESS s catched at "second = main panel", but no menu keystroke action follows ...
George
01-30-2014 08:56 AM
I somwhow missed that you want to call a menu function in the other panel. Have you tried to call the function directly?
menuCallback (GetPanelMenuBar (main_pMain), EVENT_KEYPRESS, MENUBAR_MENU_ITEM, NULL, main_pMain);
01-30-2014 09:10 AM
Hi, Roberto,
Yes, I know that the requested behavior I could make by directly specified the appropriate action when the certain shortcut key is pressed in "child" panel.
But this solution is improper, because the duplication of shortcut definition (one in the menu design, other in callback code).
I try to found some "elegant" solution (utilizing the allready designed menu callbacks).
George