/******************************************************************************* * Copyright (c) 2000, 2017 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.swt.ole.win32; import org.eclipse.swt.*; import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.ole.win32.*; import org.eclipse.swt.internal.win32.*; final class OlePropertyChangeSink { private OleControlSite controlSite; //private IUnknown objIUnknown; private COMObject iPropertyNotifySink; private int refCount; private int propertyCookie; private OleEventTable eventTable; OlePropertyChangeSink(OleControlSite controlSite) { this.controlSite = controlSite; createCOMInterfaces(); } void addListener(int propertyID, OleListener listener) { if (listener == null) OLE.error (SWT.ERROR_NULL_ARGUMENT); if (eventTable == null) eventTable = new OleEventTable (); eventTable.hook(propertyID, listener); } int AddRef() { refCount++; return refCount; } void connect(IUnknown objIUnknown) { // Set up property change notification sink long[] ppvObject = new long[1]; if (objIUnknown.QueryInterface(COM.IIDIConnectionPointContainer, ppvObject) == COM.S_OK) { IConnectionPointContainer cpc = new IConnectionPointContainer(ppvObject[0]); if (cpc.FindConnectionPoint(COM.IIDIPropertyNotifySink, ppvObject) == COM.S_OK) { IConnectionPoint cp = new IConnectionPoint(ppvObject[0]); int[] cookie = new int[1]; if (cp.Advise(iPropertyNotifySink.getAddress(), cookie) == COM.S_OK) { propertyCookie = cookie[0]; } cp.Release(); } cpc.Release(); } } private void createCOMInterfaces() { iPropertyNotifySink = new COMObject(new int[]{2, 0, 0, 1, 1}){ @Override public long method0(long[] args) {return QueryInterface(args[0], args[1]);} @Override public long method1(long[] args) {return AddRef();} @Override public long method2(long[] args) {return Release();} @Override public long method3(long[] args) {return OnChanged((int)args[0]);} @Override public long method4(long[] args) {return OnRequestEdit((int)args[0]);} }; } void disconnect(IUnknown objIUnknown) { // disconnect property notification sink if (propertyCookie != 0 && objIUnknown != null) { long[] ppvObject = new long[1]; if (objIUnknown.QueryInterface(COM.IIDIConnectionPointContainer, ppvObject) == COM.S_OK) { IConnectionPointContainer cpc = new IConnectionPointContainer(ppvObject[0]); if (cpc.FindConnectionPoint(COM.IIDIPropertyNotifySink, ppvObject) == COM.S_OK) { IConnectionPoint cp = new IConnectionPoint(ppvObject[0]); if (cp.Unadvise(propertyCookie) == COM.S_OK) { propertyCookie = 0; } cp.Release(); } cpc.Release(); } } } private void disposeCOMInterfaces() { if (iPropertyNotifySink != null) iPropertyNotifySink.dispose(); iPropertyNotifySink = null; } /** * Notify listeners of an event. *
* This method notifies all listeners that an event * has occurred. * * @param eventType the desired SWT event * @param event the event data * * @exception IllegalArgumentException