Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.eclipse.swt.ole.win32;
  
  import  org.eclipse.swt.*;
  import  org.eclipse.swt.internal.ole.win32.*;


Author(s):
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 < .i++) {
         OleEventSinkImpl sink = [i];
         sink.disconnect();
         sink.Release();
       }
        = new OleEventSinkImpl[0];
        = new GUID[0];
        = new int[0];
     }
    
   
Adds the listener to receive events.

Parameters:
iunknown the IUnknown of the automation object.
guid GUID of the source object that provides the event notification.
eventID the id of the event
listener the listener
Throws:
SWTError
  • ERROR_NULL_ARGUMENT when listener is null
 
     public  void addEventListener(int iunknown, GUID guidint 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 < .i++) {
         if (COM.IsEqualGUID([i], guid)) {
           if (iunknown == [i]) {
             index = i;
             break;
           }
         }
       }
       if (index != -1) {
         [index].addListener(eventIDlistener);
       } else {
         int oldLength = .;
         OleEventSinkImpl[] newOleEventSink = new OleEventSinkImpl[oldLength + 1];
         GUID[] newOleEventSinkGUID = new GUID[oldLength + 1];
         int[] newOleEventSinkIUnknown = new int[oldLength + 1];
         System.arraycopy(, 0, newOleEventSink, 0, oldLength);
         System.arraycopy(, 0, newOleEventSinkGUID, 0, oldLength);
         System.arraycopy(, 0, newOleEventSinkIUnknown, 0, oldLength);
          = newOleEventSink;
          = newOleEventSinkGUID;
          = newOleEventSinkIUnknown;
 
         [oldLength] = new OleEventSinkImpl(iunknownguid);
         [oldLength] = guid;
         [oldLength] = iunknown;
         [oldLength].AddRef();
         [oldLength].connect();
         [oldLength].addListener(eventIDlistener);
 
 
       }
     }
    
Removes the listener.

Parameters:
eventID the event identifier
listener the listener
Throws:
SWTError
  • ERROR_NULL_ARGUMENT when listener is null
 
     void removeEventListener(int iunknown, GUID guidint eventID, OleListener listener) {
      if (listener == null || guid == nullthrow new SWTError (SWT.ERROR_NULL_ARGUMENT);
      for (int i = 0; i < .i++) {
        if (COM.IsEqualGUID([i], guid)) {
          if (iunknown == [i]) {
            [i].removeListener(eventIDlistener);
            if (![i].hasListeners()) {
              //free resources associated with event sink
              [i].disconnect();
              [i].Release();
              int oldLength = .;
              if (oldLength == 1) {
                 = new OleEventSinkImpl[0];
                 = new GUID[0];
                 = new int[0];
              } else {
                OleEventSinkImpl[] newOleEventSink = new OleEventSinkImpl[oldLength - 1];
                System.arraycopy(, 0, newOleEventSink, 0, i);
                System.arraycopy(i + 1, newOleEventSinkioldLength - i - 1);
                 = newOleEventSink;
                GUID[] newOleEventSinkGUID = new GUID[oldLength - 1];
                System.arraycopy(, 0, newOleEventSinkGUID, 0, i);
                System.arraycopy(i + 1, newOleEventSinkGUIDioldLength - i - 1);
                 = newOleEventSinkGUID;
                int[] newOleEventSinkIUnknown = new int[oldLength - 1];
                System.arraycopy(, 0, newOleEventSinkIUnknown, 0, i);
                System.arraycopy(i + 1, newOleEventSinkIUnknownioldLength - i - 1);
                 = newOleEventSinkIUnknown;
              }
            }
            return;
          }
        }
      }
    }
    
    
    
    
New to GrepCode? Check out our FAQ X