commit ebbbb16b255e7005d23b4a525425f1a4a89aeba2
Author: manish <manish10@gmail.com>
Date:   Fri Apr 26 14:23:21 2013 +0530

    fix for bug 1686

diff --git a/nvdaHelper/remote/winword.cpp b/nvdaHelper/remote/winword.cpp
index d9fa7ac..9fbec5d 100644
--- a/nvdaHelper/remote/winword.cpp
+++ b/nvdaHelper/remote/winword.cpp
@@ -50,6 +50,9 @@ using namespace std;
 #define wdDISPID_STYLE_NAMELOCAL 0
 #define wdDISPID_RANGE_SPELLINGERRORS 316
 #define wdDISPID_SPELLINGERRORS_COUNT 1
+#define wdDISPID_RANGE_APPLICATION 1000
+#define wdDISPID_APPLICATION_ISSANDBOX 492
+
 #define wdDISPID_RANGE_FONT 5
 #define wdDISPID_FONT_COLOR 159
 #define wdDISPID_FONT_BOLD 130
@@ -398,11 +401,20 @@ void generateXMLAttribsForFormatting(IDispatch* pDispatchRange, int startOffset,
 		}
 	} 
 	if(formatConfig&formatConfig_reportSpellingErrors) {
-		IDispatchPtr pDispatchSpellingErrors=NULL;
-		if(_com_dispatch_raw_propget(pDispatchRange,wdDISPID_RANGE_SPELLINGERRORS,VT_DISPATCH,&pDispatchSpellingErrors)==S_OK&&pDispatchSpellingErrors) {
-			_com_dispatch_raw_propget(pDispatchSpellingErrors,wdDISPID_SPELLINGERRORS_COUNT,VT_I4,&iVal);
-			if(iVal>0) {
-				formatAttribsStream<<L"invalid-spelling=\""<<iVal<<L"\" ";
+		IDispatchPtr pDispatchApplication=NULL;
+		if(_com_dispatch_raw_propget(pDispatchRange,wdDISPID_RANGE_APPLICATION ,VT_DISPATCH,&pDispatchApplication)==S_OK && pDispatchApplication) {
+			bool isSandbox = true;
+			// We need to ironically enter the if block if the call to get IsSandbox property fails
+			// for backward compatibility because IsSandbox was introduced with word 2010 and earlier versions will return a failure for this property access.
+			// This however, means that if this property access fails for some reason in word 2010, then we will incorrectly enter this section.
+			if(_com_dispatch_raw_propget(pDispatchApplication,wdDISPID_APPLICATION_ISSANDBOX ,VT_BOOL,&isSandbox)!=S_OK || !isSandbox ) {
+				IDispatchPtr pDispatchSpellingErrors=NULL;
+				if(_com_dispatch_raw_propget(pDispatchRange,wdDISPID_RANGE_SPELLINGERRORS,VT_DISPATCH,&pDispatchSpellingErrors)==S_OK&&pDispatchSpellingErrors) {
+					_com_dispatch_raw_propget(pDispatchSpellingErrors,wdDISPID_SPELLINGERRORS_COUNT,VT_I4,&iVal);
+					if(iVal>0) {
+						formatAttribsStream<<L"invalid-spelling=\""<<iVal<<L"\" ";
+					}
+				}
 			}
 		}
 	}
diff --git a/source/NVDAObjects/IAccessible/__init__.py b/source/NVDAObjects/IAccessible/__init__.py
index 79ba654..0542970 100644
--- a/source/NVDAObjects/IAccessible/__init__.py
+++ b/source/NVDAObjects/IAccessible/__init__.py
@@ -1797,4 +1797,5 @@ _staticMap={
 	("NUIDialog",oleacc.ROLE_SYSTEM_CLIENT):"NUIDialogClient",
 	("_WwN",oleacc.ROLE_SYSTEM_TEXT):"winword.SpellCheckErrorField",
 	("_WwO",oleacc.ROLE_SYSTEM_TEXT):"winword.SpellCheckErrorField",
+	("_WwB",oleacc.ROLE_SYSTEM_CLIENT):"winword.ProtectedDocumentPane",
 }
diff --git a/source/NVDAObjects/IAccessible/winword.py b/source/NVDAObjects/IAccessible/winword.py
index c7080285..f89fc19 100644
--- a/source/NVDAObjects/IAccessible/winword.py
+++ b/source/NVDAObjects/IAccessible/winword.py
@@ -13,6 +13,8 @@ import winUser
 import speech
 import controlTypes
 import textInfos
+import eventHandler
+import wx
 
 from . import IAccessible
 from NVDAObjects.window.winword import WordDocument 
@@ -66,3 +68,20 @@ class SpellCheckErrorField(IAccessible,WordDocument):
 		if errorText:
 			speech.speakText(errorText)
 			speech.speakSpelling(errorText)
+
+
+class ProtectedDocumentPane(IAccessible):
+	"""The pane that gets focus in case a document opens in protected mode in word
+	This is mapped to the window class _WWB and role oleacc.ROLE_SYSTEM_CLIENT
+	"""
+	
+	def event_gainFocus(self):
+		"""On gaining focus, simply set the focus on a child of type word document. 
+		This is just a container window.
+		"""
+		if eventHandler.isPendingEvents("gainFocus"):
+			return
+		document=next((x for x in self.children if isinstance(x,WordDocument)), None)  
+		if document:
+			wx.CallLater(50, document.setFocus)
+
