I am trying to create a visual plugin in Delphi and host it in a WPF application. I have a strange problem when tabbing between the WPF controls and the Delphi controls but cannot figure out how to solve it.
See the screenshot of an app reproducing the problem. The tab order should be as follows (referring to screenshot): WpfEdit1->DelphiEdit1->DelphiEdit2->DelphiEdit3->WpfEdit2. I have attached source code for the Delphi plugin and Wpf host for reference.
When the user attempts to tab from WpfEdit1 to DelphiEdit1, focus is set to the WindowsFormsHost in the host app first, and the user has to press the tab key another time to get to DelphiEdit1. When Shift-tabbing back focus goes directly back to WpfEdit1 as desired. A similar behavior occurs when tabbing between DelphiEdit3 and WpfEdit2. The problem only happens from the second time the user tabs between controls; the first time everything is OK!
Hi, the problem is that HostPanel is not intended to be used with the WindowsFormsHost, so we never tested it in that scenario.
However, i’ve tried your sample, and looks like i have a workaround for this problem, since GotKeyboardFocus is only hits when the focus should go to a plugin, you can use this event to manually transfer the focus. To do so, you will need a reference to a plugin instance, so your loading code can look like this:
private IHYCrossPlatformVisualPlugin m_Plugin;
[..]
private void button1_Click(object sender, RoutedEventArgs e)
{
ModuleManager l_moduleManager = new ModuleManager();
LoadedModule l_module = l_moduleManager.LoadModule("NewPluginLibrary.dll");
foreach (UnmanagedPluginDescriptor l_plugindescriptor in l_module.Plugins)
{
m_Plugin = l_moduleManager.CreateInstance(l_plugindescriptor) as IHYCrossPlatformVisualPlugin;
m_host.HostPlugin(m_Plugin as IBasePlugin);
break;
}
}
And when GotKeyboardFocus hits just tell the plugin to process tab key:
and thanks for your quick response! I tried your suggested fix and it does seem to work as expected, I’ll implement it into the source code of the actual plugin.
You mention that HostPanel is not intended to work with WindowsHostPanel - do you have a suggestion how we should host Delphi code within a WPF Plugin? I am working with a solution with a host application written in Delphi hosting different WPF plugins which again may host Delphi plugins. It mostly works but we do have several problems regarding transfer of focus, window activation and handling of shortcut keys.
We would like to see a solution with more “seamless” transport of focus and shortcut keys between the plugin levels as this would help in making the plugin framework appear as one integrated platform instead of the current feeling where a lot of effort has to be done to integrate the plugins. I have reported an issue regarding focus and tab key earlier (http://connect.remobjects.com/discussion/1218/handling-of-tab-key-in-cwpf-visualplugin) and see that the plugins basically overrides how WPF handles focus transitions. Would it be an idea to use the default WPF tab-key handling and look at the interfaces IKeyboardInputSite and IKeyboardInputSink when it comes to transition of focus between host/plugins?
genus said: You mention that HostPanel is not intended to work with WindowsHostPanel - do you have a suggestion how we should host Delphi code within a WPF Plugin?
Unfortunately there is no solution for this scenario exists at the moment, currently we support only WinForms, VCL and FMX as host platforms.
The problem with the HostPanel being hosted in the WindowsFormsHost is that host panel tries to access to the parent Form to perform some actions (like focus handling), so this may be the reason why you experience problems with focus.
However, please feel free to contact us, and i will try to help you with these problems.
genus said: We would like to see a solution with more "seamless" transport of focus and shortcut keys between the plugin levels as this would help in making the plugin framework appear as one integrated platform instead of the current feeling where a lot of effort has to be done to integrate the plugins.
I've logged your suggestion from the previous topic regarding focus for review, so we will try to fix this problem. But what about shortcuts key? Currently we are not aware of any problems with them.
genus said: Would it be an idea to use the default WPF tab-key handling and look at the interfaces IKeyboardInputSite and IKeyboardInputSink when it comes to transition of focus between host/plugins?