All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.swt.ole.win32.SinkObject Maven / Gradle / Ivy

The newest version!
package org.eclipse.swt.ole.win32;

import org.eclipse.swt.*;
import org.eclipse.swt.internal.ole.win32.*;


/**
 * @author S2267
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class SinkObject {
    // supporting Event Sink attributes
    private OleEventSinkImpl[] oleEventSink = new OleEventSinkImpl[0];
    private GUID[] oleEventSinkGUID = new GUID[0];
    private int[] oleEventSinkIUnknown = new int[0];


    /**
     * 
     */
    public SinkObject() {
    }
   
    
    public void disconnectEventSinks() {

      for (int i = 0; i < oleEventSink.length; i++) {
        OleEventSinkImpl sink = oleEventSink[i];
        sink.disconnect();
        sink.Release();
      }
      oleEventSink = new OleEventSinkImpl[0];
      oleEventSinkGUID = new GUID[0];
      oleEventSinkIUnknown = new int[0];
    }
    
   /**
    * Adds the listener to receive events.
    *  
    * @param iunknown  the IUnknown of the automation object.
    * 
    * @param guid GUID of the source object that provides the event notification.
    * 
    * @param eventID the id of the event
    * 
    * @param listener the listener
    * 
    * @exception SWTError
    *  
  • ERROR_NULL_ARGUMENT when listener is null
*/ public void addEventListener(int iunknown, GUID guid, int eventID, OleListener listener) { if (listener == null || iunknown == 0 || guid == null) OLE.error (SWT.ERROR_NULL_ARGUMENT); // have we connected to this kind of event sink before? int index = -1; for (int i = 0; i < oleEventSinkGUID.length; i++) { if (COM.IsEqualGUID(oleEventSinkGUID[i], guid)) { if (iunknown == oleEventSinkIUnknown[i]) { index = i; break; } } } if (index != -1) { oleEventSink[index].addListener(eventID, listener); } else { int oldLength = oleEventSink.length; OleEventSinkImpl[] newOleEventSink = new OleEventSinkImpl[oldLength + 1]; GUID[] newOleEventSinkGUID = new GUID[oldLength + 1]; int[] newOleEventSinkIUnknown = new int[oldLength + 1]; System.arraycopy(oleEventSink, 0, newOleEventSink, 0, oldLength); System.arraycopy(oleEventSinkGUID, 0, newOleEventSinkGUID, 0, oldLength); System.arraycopy(oleEventSinkIUnknown, 0, newOleEventSinkIUnknown, 0, oldLength); oleEventSink = newOleEventSink; oleEventSinkGUID = newOleEventSinkGUID; oleEventSinkIUnknown = newOleEventSinkIUnknown; oleEventSink[oldLength] = new OleEventSinkImpl(iunknown, guid); oleEventSinkGUID[oldLength] = guid; oleEventSinkIUnknown[oldLength] = iunknown; oleEventSink[oldLength].AddRef(); oleEventSink[oldLength].connect(); oleEventSink[oldLength].addListener(eventID, listener); } } /** * Removes the listener. * * @param eventID the event identifier * * @param listener the listener * * @exception SWTError *
  • ERROR_NULL_ARGUMENT when listener is null
*/ void removeEventListener(int iunknown, GUID guid, int eventID, OleListener listener) { if (listener == null || guid == null) throw new SWTError (SWT.ERROR_NULL_ARGUMENT); for (int i = 0; i < oleEventSink.length; i++) { if (COM.IsEqualGUID(oleEventSinkGUID[i], guid)) { if (iunknown == oleEventSinkIUnknown[i]) { oleEventSink[i].removeListener(eventID, listener); if (!oleEventSink[i].hasListeners()) { //free resources associated with event sink oleEventSink[i].disconnect(); oleEventSink[i].Release(); int oldLength = oleEventSink.length; if (oldLength == 1) { oleEventSink = new OleEventSinkImpl[0]; oleEventSinkGUID = new GUID[0]; oleEventSinkIUnknown = new int[0]; } else { OleEventSinkImpl[] newOleEventSink = new OleEventSinkImpl[oldLength - 1]; System.arraycopy(oleEventSink, 0, newOleEventSink, 0, i); System.arraycopy(oleEventSink, i + 1, newOleEventSink, i, oldLength - i - 1); oleEventSink = newOleEventSink; GUID[] newOleEventSinkGUID = new GUID[oldLength - 1]; System.arraycopy(oleEventSinkGUID, 0, newOleEventSinkGUID, 0, i); System.arraycopy(oleEventSinkGUID, i + 1, newOleEventSinkGUID, i, oldLength - i - 1); oleEventSinkGUID = newOleEventSinkGUID; int[] newOleEventSinkIUnknown = new int[oldLength - 1]; System.arraycopy(oleEventSinkIUnknown, 0, newOleEventSinkIUnknown, 0, i); System.arraycopy(oleEventSinkIUnknown, i + 1, newOleEventSinkIUnknown, i, oldLength - i - 1); oleEventSinkIUnknown = newOleEventSinkIUnknown; } } return; } } } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy