Bug 482308 - [win32] Main Menu not refreshed after deactivating Word
authorSzymon Ptaszkiewicz <szymon.ptaszkiewicz@pl.ibm.com>
Fri, 8 Jan 2016 11:08:15 +0000 (12:08 +0100)
committerNiraj Modi <niraj.modi@in.ibm.com>
Thu, 21 Jan 2016 09:55:52 +0000 (15:25 +0530)
editor

Change-Id: I0d268ac91e0317c6eabc5bf0b0334009582b5ea5
Signed-off-by: Szymon Ptaszkiewicz <szymon.ptaszkiewicz@pl.ibm.com>
bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleClientSite.java
bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleFrame.java

index 3ddae69..46bb952 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -122,13 +122,26 @@ protected OleClientSite(Composite parent, int style) {
        isStatic = false;
 
        listener = new Listener() {
+               private int nestedFocusEvents = 0;
                public void handleEvent(Event e) {
                        switch (e.type) {
                        case SWT.Resize :
                        case SWT.Move :    onResize(e); break;
                        case SWT.Dispose : onDispose(e); break;
-                       case SWT.FocusIn:  onFocusIn(e); break;
-                       case SWT.FocusOut:  onFocusOut(e); break;
+                       case SWT.FocusIn:
+                               nestedFocusEvents++;
+                               onFocusIn(e);
+                               nestedFocusEvents--;
+                               if (nestedFocusEvents == 0)
+                                       frame.onFocusIn(e);
+                               break;
+                       case SWT.FocusOut:
+                               nestedFocusEvents++;
+                               onFocusOut(e);
+                               nestedFocusEvents--;
+                               if (nestedFocusEvents == 0)
+                                       frame.onFocusOut(e);
+                               break;
                        case SWT.Paint:    onPaint(e); break;
                        case SWT.Traverse: onTraverse(e); break;
                        case SWT.KeyDown: /* required for traversal */ break;
index 6344188..de3fdd9 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -59,6 +59,10 @@ final public class OleFrame extends Composite
 
        private Listener listener;
        
+       private long /*int*/ shellHandle;
+       private long /*int*/ oldMenuHandle;
+       private long /*int*/ newMenuHandle;
+
        private static String CHECK_FOCUS = "OLE_CHECK_FOCUS"; //$NON-NLS-1$
        private static String HHOOK = "OLE_HHOOK"; //$NON-NLS-1$
        private static String HHOOKMSG = "OLE_HHOOK_MSG"; //$NON-NLS-1$
@@ -575,6 +579,15 @@ private void onDispose(Event e) {
        removeListener(SWT.Resize, listener);
        removeListener(SWT.Move, listener);
 }
+void onFocusIn(Event e) {
+       if (OS.GetMenu(shellHandle) != newMenuHandle)
+               OS.SetMenu(shellHandle, newMenuHandle);
+}
+void onFocusOut(Event e) {
+       Control control = getDisplay().getFocusControl();
+       if (OS.GetMenu(shellHandle) != oldMenuHandle && control != null && control.handle != shellHandle)
+               OS.SetMenu(shellHandle, oldMenuHandle);
+}
 private void onResize(Event e) {
        if (objIOleInPlaceActiveObject != null) {
                RECT lpRect = new RECT();
@@ -767,8 +780,9 @@ private int SetMenu(long /*int*/ hmenuShared, long /*int*/ holemenu, long /*int*
        }
        if (hmenuShared == 0) return COM.E_FAIL;
        
-       OS.SetMenu(handle, hmenuShared);
-       OS.DrawMenuBar(handle);
+       shellHandle = handle;
+       oldMenuHandle = menubar.handle;
+       newMenuHandle = hmenuShared;
        
        return COM.OleSetMenuDescriptor(holemenu, handle, hwndActiveObject, iOleInPlaceFrame.getAddress(), inPlaceActiveObject);
 }