src/macosx/native/sun/awt/CClipboard.m

Print this page




 154 
 155     [[NSPasteboard generalPasteboard] setData:[newUpdate data] forType:[newUpdate format]];
 156 }
 157 
 158 - (NSData *) javaGetDataForType:(NSString *) inFormat {
 159 
 160     NSMutableArray *args = [NSMutableArray arrayWithObject:inFormat];
 161     [ThreadUtilities performOnMainThread:@selector(_nativeGetDataForType:) on:self withObject:args waitUntilDone:YES];
 162     return [args lastObject];
 163 }
 164 
 165 - (void) _nativeGetDataForType:(NSMutableArray *) args {
 166     AWT_ASSERT_APPKIT_THREAD;
 167 
 168     NSData *returnValue = [[NSPasteboard generalPasteboard] dataForType:[args objectAtIndex:0]];
 169 
 170     if (returnValue) [args replaceObjectAtIndex:0 withObject:returnValue];
 171     else [args removeLastObject];
 172 }
 173 


 174 - (void) checkPasteboard:(id)application {
 175     AWT_ASSERT_APPKIT_THREAD;
 176     
 177     // This is called via NSApplicationDidBecomeActiveNotification.
 178     
 179     // If the change count on the general pasteboard is different than when we set it
 180     // someone else put data on the clipboard.  That means the current owner lost ownership.
 181     NSInteger newChangeCount = [[NSPasteboard generalPasteboard] changeCount];
 182     
 183     if (fChangeCount != newChangeCount) {
 184         fChangeCount = newChangeCount;    
 185 
 186         // Notify that the content might be changed
 187         static JNF_CLASS_CACHE(jc_CClipboard, "sun/lwawt/macosx/CClipboard");
 188         static JNF_STATIC_MEMBER_CACHE(jm_contentChanged, jc_CClipboard, "notifyChanged", "()V");
 189         JNIEnv *env = [ThreadUtilities getJNIEnv];
 190         JNFCallStaticVoidMethod(env, jm_contentChanged);
 191 
 192         // If we have a Java pasteboard owner, tell it that it doesn't own the pasteboard anymore.
 193         static JNF_MEMBER_CACHE(jm_lostOwnership, jc_CClipboard, "notifyLostOwnership", "()V");
 194         @synchronized(self) {
 195             if (fClipboardOwner) {
 196                 JNIEnv *env = [ThreadUtilities getJNIEnv];
 197                 JNFCallVoidMethod(env, fClipboardOwner, jm_lostOwnership); // AWT_THREADING Safe (event)
 198                 JNFDeleteGlobalRef(env, fClipboardOwner);
 199                 fClipboardOwner = NULL;
 200             }
 201         }
 202     }
 203 }
 204 













 205 @end
 206 
 207 /*
 208  * Class:     sun_lwawt_macosx_CClipboard
 209  * Method:    declareTypes
 210  * Signature: ([JLsun/awt/datatransfer/SunClipboard;)V
 211 */
 212 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CClipboard_declareTypes
 213 (JNIEnv *env, jobject inObject, jlongArray inTypes, jobject inJavaClip)
 214 {
 215 JNF_COCOA_ENTER(env);
 216 
 217     jint i;
 218     jint nElements = (*env)->GetArrayLength(env, inTypes);
 219     NSMutableArray *formatArray = [NSMutableArray arrayWithCapacity:nElements];
 220     jlong *elements = (*env)->GetPrimitiveArrayCritical(env, inTypes, NULL);
 221 
 222     for (i = 0; i < nElements; i++) {
 223         NSString *pbFormat = formatForIndex(elements[i]);
 224         if (pbFormat)


 331     NSUInteger dataSize = [clipData length];
 332     returnValue = (*env)->NewByteArray(env, dataSize);
 333     if (returnValue == NULL) {
 334         return NULL;
 335     }
 336 
 337     if (dataSize != 0) {
 338         const void *dataBuffer = [clipData bytes];
 339         (*env)->SetByteArrayRegion(env, returnValue, 0, dataSize, (jbyte *)dataBuffer);
 340     }
 341 
 342 JNF_COCOA_EXIT(env);
 343     return returnValue;
 344 }
 345 
 346 /*
 347  * Class:     sun_lwawt_macosx_CClipboard
 348  * Method:    checkPasteboard
 349  * Signature: ()V
 350  */
 351 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CClipboard_checkPasteboard
 352 (JNIEnv *env, jobject inObject )
 353 {

 354     JNF_COCOA_ENTER(env);
 355 
 356     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 357         [[CClipboard sharedClipboard] checkPasteboard:nil];
 358     }];
 359         
 360     JNF_COCOA_EXIT(env);

 361 }
 362 
 363 


 154 
 155     [[NSPasteboard generalPasteboard] setData:[newUpdate data] forType:[newUpdate format]];
 156 }
 157 
 158 - (NSData *) javaGetDataForType:(NSString *) inFormat {
 159 
 160     NSMutableArray *args = [NSMutableArray arrayWithObject:inFormat];
 161     [ThreadUtilities performOnMainThread:@selector(_nativeGetDataForType:) on:self withObject:args waitUntilDone:YES];
 162     return [args lastObject];
 163 }
 164 
 165 - (void) _nativeGetDataForType:(NSMutableArray *) args {
 166     AWT_ASSERT_APPKIT_THREAD;
 167 
 168     NSData *returnValue = [[NSPasteboard generalPasteboard] dataForType:[args objectAtIndex:0]];
 169 
 170     if (returnValue) [args replaceObjectAtIndex:0 withObject:returnValue];
 171     else [args removeLastObject];
 172 }
 173 
 174 
 175 
 176 - (void) checkPasteboard:(id)application {
 177     AWT_ASSERT_APPKIT_THREAD;
 178     
 179     // This is called via NSApplicationDidBecomeActiveNotification.
 180     
 181     // If the change count on the general pasteboard is different than when we set it
 182     // someone else put data on the clipboard.  That means the current owner lost ownership.
 183     NSInteger newChangeCount = [[NSPasteboard generalPasteboard] changeCount];
 184     
 185     if (fChangeCount != newChangeCount) {
 186         fChangeCount = newChangeCount;    
 187 
 188         // Notify that the content might be changed
 189         static JNF_CLASS_CACHE(jc_CClipboard, "sun/lwawt/macosx/CClipboard");
 190         static JNF_STATIC_MEMBER_CACHE(jm_contentChanged, jc_CClipboard, "notifyChanged", "()V");
 191         JNIEnv *env = [ThreadUtilities getJNIEnv];
 192         JNFCallStaticVoidMethod(env, jm_contentChanged);
 193 
 194         // If we have a Java pasteboard owner, tell it that it doesn't own the pasteboard anymore.
 195         static JNF_MEMBER_CACHE(jm_lostOwnership, jc_CClipboard, "notifyLostOwnership", "()V");
 196         @synchronized(self) {
 197             if (fClipboardOwner) {
 198                 JNIEnv *env = [ThreadUtilities getJNIEnv];
 199                 JNFCallVoidMethod(env, fClipboardOwner, jm_lostOwnership); // AWT_THREADING Safe (event)
 200                 JNFDeleteGlobalRef(env, fClipboardOwner);
 201                 fClipboardOwner = NULL;
 202             }
 203         }
 204     }
 205 }
 206 
 207 - (BOOL) checkPasteboardWithoutNotification:(id)application {
 208     AWT_ASSERT_APPKIT_THREAD;
 209     
 210     NSInteger newChangeCount = [[NSPasteboard generalPasteboard] changeCount];
 211     
 212     if (fChangeCount != newChangeCount) {
 213         fChangeCount = newChangeCount;    
 214         return YES;
 215     } else {
 216         return NO;
 217     }
 218 }
 219 
 220 @end
 221 
 222 /*
 223  * Class:     sun_lwawt_macosx_CClipboard
 224  * Method:    declareTypes
 225  * Signature: ([JLsun/awt/datatransfer/SunClipboard;)V
 226 */
 227 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CClipboard_declareTypes
 228 (JNIEnv *env, jobject inObject, jlongArray inTypes, jobject inJavaClip)
 229 {
 230 JNF_COCOA_ENTER(env);
 231 
 232     jint i;
 233     jint nElements = (*env)->GetArrayLength(env, inTypes);
 234     NSMutableArray *formatArray = [NSMutableArray arrayWithCapacity:nElements];
 235     jlong *elements = (*env)->GetPrimitiveArrayCritical(env, inTypes, NULL);
 236 
 237     for (i = 0; i < nElements; i++) {
 238         NSString *pbFormat = formatForIndex(elements[i]);
 239         if (pbFormat)


 346     NSUInteger dataSize = [clipData length];
 347     returnValue = (*env)->NewByteArray(env, dataSize);
 348     if (returnValue == NULL) {
 349         return NULL;
 350     }
 351 
 352     if (dataSize != 0) {
 353         const void *dataBuffer = [clipData bytes];
 354         (*env)->SetByteArrayRegion(env, returnValue, 0, dataSize, (jbyte *)dataBuffer);
 355     }
 356 
 357 JNF_COCOA_EXIT(env);
 358     return returnValue;
 359 }
 360 
 361 /*
 362  * Class:     sun_lwawt_macosx_CClipboard
 363  * Method:    checkPasteboard
 364  * Signature: ()V
 365  */
 366 JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_CClipboard_checkPasteboardWithoutNotification
 367 (JNIEnv *env, jobject inObject)
 368 {
 369     __block BOOL ret = NO;
 370     JNF_COCOA_ENTER(env);

 371     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 372         ret = [[CClipboard sharedClipboard] checkPasteboardWithoutNotification:nil];
 373     }];
 374      
 375     JNF_COCOA_EXIT(env);
 376     return ret;
 377 }
 378 
 379