Outlook steals space from the the Add-In

Add-in Express™ Support Service
That's what is more important than anything else

Outlook steals space from the the Add-In
 
Pawel Forys




Posts: 17
Joined: 2016-04-27
Hi,
I have an Outlook Addin (Add-In Express for Office 2013) which main role is to open an WPF window containing the WebBrowser, which embeds the specific business Web Application. I already had to solve several issues with WPF WebBrowser not receiving specific keystrokes like enter,delete, ctrl+c, ctrl-v etc. This however was successfully handled by approach described here: https://blogs.msdn.microsoft.com/vsod/2010/04/08/using-shortcut-keys-to-call-a-function-in-an-office-add-in/.

Those issues were at least consistent. The last one I am facing relates to spacebar. In general space is treated similar to other alphanumeric keys and it does not require intercepting. This is not true however in all the cases. Whenever user focuses Outlook on specific Email (by focusing I don't mean selecting email in the navigation pane, but rather clicking on the body of the email in the right-main pane) then Outlook uses spacebar as a navigation shortcut. This way user is able to browse through email content and switching to next emails.

Problem appears when user after focusing on right pane, opens my Addin WPF window and uses HTML box to provide text containing spaces. In that state Outlook is still navigating in the Outlook Explorer underneath, "stealing" spacebar hit, even though WPF window is the one active, not Outlook Explorer. This means Web App never receives the space. Only when User "loses focus" from the current email, even by clicking on the current displayed email in navigation pane, then Outlook seems to release the ownership over spacebar and it works as expected again.

I see 2 potential solutions for the problem:
1. Whenever Addin WPF window is activated, to force Outlook explorer to loose focus from the currently displayed email in right-main pane. I have not yet found a way to achieve it though. Maybe there is a way to change focus to navigation pane programmatically?

2. Intercept the space and trigger the predefined javascript method to inject space. This however it tricky, because in cases when spacebar works correctly, my Addin would receive 2 spaces - one by simply receiving the spacebar hit and second by injection.

Would you have any suggestions, how this problem could be approached? Thanks in advance!
Posted 04 Aug, 2016 02:55:19 Top
Andrei Smolin


Add-in Express team


Posts: 18833
Joined: 2006-05-11
Hello Pawel,

Is using a task pane possible for you? We tried to solve these issues for our ADXOlForm. Try to use the WebBrowser on a pane. Note that you must comment out the code that sets hooks and handles keyboard shortcuts. Also, you can try yo use System.Windows.Forms.WebBrowser.


Andrei Smolin
Add-in Express Team Leader
Posted 04 Aug, 2016 06:12:29 Top
Pawel Forys




Posts: 17
Joined: 2016-04-27
Hi Andrei,
Thank you for your feedback. Using task pane is not a real option due to usability reasons. The Web app, that I am embedding have complex views and would take too much space from Outlook. I have used WPF together with 3rd party libraries to make the Window look modern (similar to Outlook 2013). Correct me if I am wrong but in case of using WPF I am not able to use Forms.WebBrowser.

Is it possible to create some "dummy" (the best invisible) pane that I could somehow trigger focus on? I have been experimenting a bit and for example swithing Views in Explorer forces Reading Pane to loose focus which solves my problem. This action is however too heavy. Could you think on some other event in Outlook that could cause loose focus from the reading pane? I have been investigating is there a possibility of triggering mouse clicks or selection changes, but nothing worked so far (selection change is not an option due to Conversation mode we need to have in the Navigation Pane).
Posted 04 Aug, 2016 06:55:16 Top
Andrei Smolin


Add-in Express team


Posts: 18833
Joined: 2006-05-11
Pawel,

Please test if your code works on an ADXOlForm. If it works, we will consider providing our code to you in some way.


Andrei Smolin
Add-in Express Team Leader
Posted 04 Aug, 2016 07:23:53 Top
Pawel Forys




Posts: 17
Joined: 2016-04-27
Hi Andrei,
I folled your advice. First I changed the WebBrowser from System.Windows.Controls.WebBrowser to System.Windows.Forms.WebBrowser. I figured out that is actually possible by using WidowsFormHost element in WPF:


 <Grid>
        <WindowsFormsHost Name="WindowsFormsHost">
            <WindowsFormsHost.Child>
                <wf:WebBrowser Name="WebBrowser" Margin="0,0,0,0"/>
            </WindowsFormsHost.Child>
        </WindowsFormsHost>
    </Grid>


This however did not solve anything. Outlook still kept intercepting the spacebar when having focus on reading pane.

After that I started experimenting with ADXOlForm. I saw that it handles the focus correctly and I could use spaces freely when Browser was embedded in it.

To my huge suprise I noticed that at the same time my separate WPF window with the browser also started to work. I realized that all I have to do to make it behave correctly is to add adxOlFormsManager to my Addin module. And that's it. I have not changed any of the properties on this compoment. Not even had to create any collection for it with any ADXOlForm. Just simply adding empty ADXOlFormsManager to AddinModule does the trick.

I also checked that this fix doesn't work with System.Windows.Controls.WebBrowser. So in summary fixing the problem consisted of 2 steps:
- changing System.Windows.Controls.WebBrowser to System.Windows.Forms.WebBrowser
- adding empty ADXOlFormsManager to my AddinModule

I suspect that your ADXOlFormsManager has some impact on the Outlook region focus, changing it default behavior. Now the focus is taken out of the reading pane correctly after I activate my custom WPF window.
Does it make sense? Or what could be the explanation? Is it safe to assume that this unexpected fix will also work with future versions of Addin Express?

Thanks and best
Pawel
Posted 05 Aug, 2016 04:45:37 Top
Andrei Smolin


Add-in Express team


Posts: 18833
Joined: 2006-05-11
Hello Pawel,

This isn't expected. We can't guarantee that this will work in future Add-in Express versions.


Andrei Smolin
Add-in Express Team Leader
Posted 05 Aug, 2016 06:21:56 Top