04-18-2012 03:23 AM
Dear All,
I am wondering if this is the expected behavior or if I am doing something wrong:
On a panel I have a string control; on double clicking I open a file select box to select a file, the file name then is displayed on this string control. After this action, this string control is the active control, indicated by the grey frame.
I also have a menu bar with some shortcut keys defined, such as F2. It appears that F2 is not functional as long as the focus is on the string control. This is inconvenient because a typical user action is selecting a file and then pressing Fx. To solve this problem the user needs to click somewhere on the panel to move the focus to another control. Of course this could be done programmatically, but this extra effort is not necessary say for ring controls or numeric controls. Also in numeric controls I can change the numbers, but even if a numeric control is the acitve control because of editing the value F2 immediately works.
Help is appreciated.
Thanks,
Wolfgang
Solved! Go to Solution.
04-18-2012 04:21 AM
I just tried in a project of mine and had no problems in calling a menu function with its shortcut key while the focus is on a string control with a callback attached: maybe the problem lies in the string control callback, which is possibly trapping the keypress event before it is sent to the panel.
I tested both with "regular" shortcut keys (such as Ctrl + P) and with F2 only as the shortcat. My callback is not trapping EVENT_KEYPRESS event.
EDIT: I tried by swallowing keyboard presses with if (event == EVENT_KEYPRESS) return 1; but I am still able to operate on menus with shortcut keys. Seems the reason lies elsewhere: you can try progressively excluding parts of control callback and see when menus return responsive.
04-18-2012 04:52 AM
Thanks Roberto, I'll have a closer look...
04-18-2012 07:46 AM
Added details:
1) The problem is not when the focus is on the string control in general, only after a text has been displayed on the string control. If the string control is empty but selected F2 works as expected.
2) Here is the control callback, seems harmless...
if ( event == EVENT_LEFT_DOUBLE_CLICK )
{
if ( SelectResultFile () && !save_results )
{
header_line = FALSE;
save_results = TRUE;
UtilitySetMenuItemChecked ( menubar_handle, MENUBAR_MENU1_ITEM1_13, save_results );
}
}
return ( 0 );
The function SelectResultFile seems harmless, too... It calls FileSelectPopup; if a file was selected, it displays the file name on the string control and opens the file for writing.
04-19-2012 11:35 AM
I think what is happening here is that left double-click is also used to highlight text. So when you trigger the EVENT_LEFT_DOUBLE_CLICK, you are placing the text in the string control and then also highlighting it. There seems to be some strange behavior when the two of these happens at the same time because of the order of the events. You can see that moving the mouse around when returning from the file select popup causes the highlighting region to drag across the text. While in this highlighting mode, you cannot use the shortcuts for the menu. I was able to fix this by swallowing the EVENT_LEFT_DOUBLE_CLICK after setting the value of the control.
04-19-2012 12:08 PM
It also seems as if this only happens when you select the file by clicking the Load/Select/Open button. If you select it by double-clicking the file name, it doesn't seem to happen.
We've created bug ID 349930 to track this.
Luis
04-19-2012 01:21 PM
Hi Darren,
Thanks a lot for looking into it!! Your diagnosis of the 'highlighting mode' is correct and also your suggested workaround. Very useful, indeed!
Hi Luis,
this sounds really intricate - actually I never double clicked a file because in this application one is selecting a result file, whicht typically doesn't exist yet.. Thanks for the CAR, too.
To summarize: Thank you all
Wolfgang
08-13-2012 06:23 AM
I am happy to see that this bug has been fixed in CVI2012