LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How send menu shortcut keystroke from child to parent panel

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

0 Kudos
Message 1 of 11
(4,458 Views)

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



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 11
(4,454 Views)

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

0 Kudos
Message 3 of 11
(4,446 Views)

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.

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 11
(4,443 Views)

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 5 of 11
(4,440 Views)
Hi, Roberto,
 
you are right, the example of course works correctly.
 
I'm such a fool,  - because I thought of the child panels in "user", not the programmatic concept.
 
Explanation: the "child" panels are programmed as "top-level panel", I use
panel = DuplicatePanel (0, gui_dpl_pPoll, title, VAL_KEEP_SAME_POSITION, VAL_KEEP_SAME_POSITION);
because I want to let the child panel 'float' over whole display ().
 
When I change
panel = DuplicatePanel (main_pMain, gui_dpl_pPoll, title, ...
the keystroke is propagated correctly .... But the child panel is (of course) cropped to parent panel boundary.
 
So I rephrase the question - how to send menu shortcut keystroke (not processed) from one (top-level) panel to another panel?
 
George
 
0 Kudos
Message 6 of 11
(4,437 Views)

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 7 of 11
(4,435 Views)

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

 

0 Kudos
Message 8 of 11
(4,431 Views)

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



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 9 of 11
(4,427 Views)

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

0 Kudos
Message 10 of 11
(4,425 Views)