src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m
author sveerabhadra
Fri, 22 Dec 2017 11:00:06 +0530
changeset 48640 42ad9a781f51
parent 47216 71c04702a3d5
permissions -rw-r--r--
8190192: Double click on the title bar no longer repositions the window Reviewed-by: serb, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     1
/*
23610
5eee22a40e7b 8034209: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/CClipboard.m
serb
parents: 23010
diff changeset
     2
 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     4
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    10
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    15
 * accompanied this code).
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    16
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    20
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    23
 * questions.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    24
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    25
23610
5eee22a40e7b 8034209: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/CClipboard.m
serb
parents: 23010
diff changeset
    26
#import "CDataTransferer.h"
5eee22a40e7b 8034209: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/CClipboard.m
serb
parents: 23010
diff changeset
    27
#import "ThreadUtilities.h"
5eee22a40e7b 8034209: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/CClipboard.m
serb
parents: 23010
diff changeset
    28
#import "jni_util.h" 
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    29
#import <Cocoa/Cocoa.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    30
#import <JavaNativeFoundation/JavaNativeFoundation.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    31
24152
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
    32
@interface CClipboard : NSObject { }
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
    33
@property NSInteger changeCount;
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
    34
@property jobject clipboardOwner;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    35
24152
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
    36
+ (CClipboard*)sharedClipboard;
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
    37
- (void)declareTypes:(NSArray *)types withOwner:(jobject)owner jniEnv:(JNIEnv*)env;
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
    38
- (void)checkPasteboard:(id)sender;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    39
@end
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    40
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    41
@implementation CClipboard
24152
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
    42
@synthesize changeCount = _changeCount;
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
    43
@synthesize clipboardOwner = _clipboardOwner;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    44
24152
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
    45
// Clipboard creation is synchronized at the Java level
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
    46
+ (CClipboard*)sharedClipboard {
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
    47
    static CClipboard* sClipboard = nil;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    48
    if (sClipboard == nil) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    49
        sClipboard = [[CClipboard alloc] init];
21784
71e061011ef1 7124253: [macosx] Flavor change notification not coming
pchelko
parents: 16709
diff changeset
    50
        [[NSNotificationCenter defaultCenter] addObserver:sClipboard selector: @selector(checkPasteboard:)
71e061011ef1 7124253: [macosx] Flavor change notification not coming
pchelko
parents: 16709
diff changeset
    51
                                                     name: NSApplicationDidBecomeActiveNotification
71e061011ef1 7124253: [macosx] Flavor change notification not coming
pchelko
parents: 16709
diff changeset
    52
                                                   object: nil];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    53
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    54
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    55
    return sClipboard;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    56
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    57
24152
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
    58
- (id)init {
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
    59
    if (self = [super init]) {
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
    60
        self.changeCount = [[NSPasteboard generalPasteboard] changeCount];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    61
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    62
    return self;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    63
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    64
24152
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
    65
- (void)declareTypes:(NSArray*)types withOwner:(jobject)owner jniEnv:(JNIEnv*)env {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    66
    @synchronized(self) {
24152
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
    67
        if (owner != NULL) {
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
    68
            if (self.clipboardOwner != NULL) {
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
    69
                JNFDeleteGlobalRef(env, self.clipboardOwner);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    70
            }
24152
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
    71
            self.clipboardOwner = JNFNewGlobalRef(env, owner);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    72
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    73
    }
24152
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
    74
    [ThreadUtilities performOnMainThreadWaiting:YES block:^() {
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
    75
        self.changeCount = [[NSPasteboard generalPasteboard] declareTypes:types owner:self];
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
    76
    }];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    77
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    78
24152
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
    79
- (void)checkPasteboard:(id)sender {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    80
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    81
    // This is called via NSApplicationDidBecomeActiveNotification.
16709
ee3542d637fe 8010925: COPY AND PASTE TO AND FROM SIGNED APPLET FAILS AFTER FIRST INTERNAL COPY PRFRMD
mcherkas
parents: 15985
diff changeset
    82
    
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    83
    // If the change count on the general pasteboard is different than when we set it
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    84
    // someone else put data on the clipboard.  That means the current owner lost ownership.
24152
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
    85
    
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    86
    NSInteger newChangeCount = [[NSPasteboard generalPasteboard] changeCount];
24152
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
    87
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
    88
    if (self.changeCount != newChangeCount) {
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
    89
        self.changeCount = newChangeCount;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    90
21784
71e061011ef1 7124253: [macosx] Flavor change notification not coming
pchelko
parents: 16709
diff changeset
    91
        // Notify that the content might be changed
71e061011ef1 7124253: [macosx] Flavor change notification not coming
pchelko
parents: 16709
diff changeset
    92
        static JNF_CLASS_CACHE(jc_CClipboard, "sun/lwawt/macosx/CClipboard");
71e061011ef1 7124253: [macosx] Flavor change notification not coming
pchelko
parents: 16709
diff changeset
    93
        static JNF_STATIC_MEMBER_CACHE(jm_contentChanged, jc_CClipboard, "notifyChanged", "()V");
71e061011ef1 7124253: [macosx] Flavor change notification not coming
pchelko
parents: 16709
diff changeset
    94
        JNIEnv *env = [ThreadUtilities getJNIEnv];
71e061011ef1 7124253: [macosx] Flavor change notification not coming
pchelko
parents: 16709
diff changeset
    95
        JNFCallStaticVoidMethod(env, jm_contentChanged);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    96
21784
71e061011ef1 7124253: [macosx] Flavor change notification not coming
pchelko
parents: 16709
diff changeset
    97
        // If we have a Java pasteboard owner, tell it that it doesn't own the pasteboard anymore.
71e061011ef1 7124253: [macosx] Flavor change notification not coming
pchelko
parents: 16709
diff changeset
    98
        static JNF_MEMBER_CACHE(jm_lostOwnership, jc_CClipboard, "notifyLostOwnership", "()V");
71e061011ef1 7124253: [macosx] Flavor change notification not coming
pchelko
parents: 16709
diff changeset
    99
        @synchronized(self) {
24152
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
   100
            if (self.clipboardOwner) {
21784
71e061011ef1 7124253: [macosx] Flavor change notification not coming
pchelko
parents: 16709
diff changeset
   101
                JNIEnv *env = [ThreadUtilities getJNIEnv];
24152
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
   102
                JNFCallVoidMethod(env, self.clipboardOwner, jm_lostOwnership); // AWT_THREADING Safe (event)
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
   103
                JNFDeleteGlobalRef(env, self.clipboardOwner);
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
   104
                self.clipboardOwner = NULL;
21784
71e061011ef1 7124253: [macosx] Flavor change notification not coming
pchelko
parents: 16709
diff changeset
   105
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   106
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   107
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   108
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   109
29885
6eb60fac3383 8071668: [macosx] Clipboard does not work with 3rd parties Clipboard Managers
anashaty
parents: 26751
diff changeset
   110
- (BOOL) checkPasteboardWithoutNotification:(id)application {
6eb60fac3383 8071668: [macosx] Clipboard does not work with 3rd parties Clipboard Managers
anashaty
parents: 26751
diff changeset
   111
    AWT_ASSERT_APPKIT_THREAD;
6eb60fac3383 8071668: [macosx] Clipboard does not work with 3rd parties Clipboard Managers
anashaty
parents: 26751
diff changeset
   112
    
6eb60fac3383 8071668: [macosx] Clipboard does not work with 3rd parties Clipboard Managers
anashaty
parents: 26751
diff changeset
   113
    NSInteger newChangeCount = [[NSPasteboard generalPasteboard] changeCount];
6eb60fac3383 8071668: [macosx] Clipboard does not work with 3rd parties Clipboard Managers
anashaty
parents: 26751
diff changeset
   114
    
6eb60fac3383 8071668: [macosx] Clipboard does not work with 3rd parties Clipboard Managers
anashaty
parents: 26751
diff changeset
   115
    if (self.changeCount != newChangeCount) {
6eb60fac3383 8071668: [macosx] Clipboard does not work with 3rd parties Clipboard Managers
anashaty
parents: 26751
diff changeset
   116
        self.changeCount = newChangeCount;    
6eb60fac3383 8071668: [macosx] Clipboard does not work with 3rd parties Clipboard Managers
anashaty
parents: 26751
diff changeset
   117
        return YES;
6eb60fac3383 8071668: [macosx] Clipboard does not work with 3rd parties Clipboard Managers
anashaty
parents: 26751
diff changeset
   118
    } else {
6eb60fac3383 8071668: [macosx] Clipboard does not work with 3rd parties Clipboard Managers
anashaty
parents: 26751
diff changeset
   119
        return NO;
6eb60fac3383 8071668: [macosx] Clipboard does not work with 3rd parties Clipboard Managers
anashaty
parents: 26751
diff changeset
   120
    }
6eb60fac3383 8071668: [macosx] Clipboard does not work with 3rd parties Clipboard Managers
anashaty
parents: 26751
diff changeset
   121
}
6eb60fac3383 8071668: [macosx] Clipboard does not work with 3rd parties Clipboard Managers
anashaty
parents: 26751
diff changeset
   122
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   123
@end
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   124
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   125
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   126
 * Class:     sun_lwawt_macosx_CClipboard
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   127
 * Method:    declareTypes
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   128
 * Signature: ([JLsun/awt/datatransfer/SunClipboard;)V
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   129
*/
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   130
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CClipboard_declareTypes
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   131
(JNIEnv *env, jobject inObject, jlongArray inTypes, jobject inJavaClip)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   132
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   133
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   134
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   135
    jint i;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   136
    jint nElements = (*env)->GetArrayLength(env, inTypes);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   137
    NSMutableArray *formatArray = [NSMutableArray arrayWithCapacity:nElements];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   138
    jlong *elements = (*env)->GetPrimitiveArrayCritical(env, inTypes, NULL);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   139
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   140
    for (i = 0; i < nElements; i++) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   141
        NSString *pbFormat = formatForIndex(elements[i]);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   142
        if (pbFormat)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   143
            [formatArray addObject:pbFormat];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   144
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   145
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   146
    (*env)->ReleasePrimitiveArrayCritical(env, inTypes, elements, JNI_ABORT);
24152
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
   147
    [[CClipboard sharedClipboard] declareTypes:formatArray withOwner:inJavaClip jniEnv:env];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   148
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   149
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   150
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   151
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   152
 * Class:     sun_lwawt_macosx_CClipboard
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   153
 * Method:    setData
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   154
 * Signature: ([BJ)V
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   155
*/
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   156
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CClipboard_setData
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   157
(JNIEnv *env, jobject inObject, jbyteArray inBytes, jlong inFormat)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   158
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   159
    if (inBytes == NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   160
        return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   161
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   162
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   163
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   164
    jint nBytes = (*env)->GetArrayLength(env, inBytes);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   165
    jbyte *rawBytes = (*env)->GetPrimitiveArrayCritical(env, inBytes, NULL);
23610
5eee22a40e7b 8034209: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/CClipboard.m
serb
parents: 23010
diff changeset
   166
    CHECK_NULL(rawBytes);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   167
    NSData *bytesAsData = [NSData dataWithBytes:rawBytes length:nBytes];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   168
    (*env)->ReleasePrimitiveArrayCritical(env, inBytes, rawBytes, JNI_ABORT);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   169
    NSString *format = formatForIndex(inFormat);
24152
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
   170
    [ThreadUtilities performOnMainThreadWaiting:YES block:^() {
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
   171
        [[NSPasteboard generalPasteboard] setData:bytesAsData forType:format];
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
   172
    }];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   173
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   174
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   175
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   176
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   177
 * Class:     sun_lwawt_macosx_CClipboard
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   178
 * Method:    getClipboardFormats
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   179
 * Signature: (J)[J
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   180
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   181
JNIEXPORT jlongArray JNICALL Java_sun_lwawt_macosx_CClipboard_getClipboardFormats
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   182
(JNIEnv *env, jobject inObject)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   183
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   184
    jlongArray returnValue = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   185
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   186
24152
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
   187
    __block NSArray* dataTypes;
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
   188
    [ThreadUtilities performOnMainThreadWaiting:YES block:^() {
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
   189
        dataTypes = [[[NSPasteboard generalPasteboard] types] retain];
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
   190
    }];
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
   191
    [dataTypes autorelease];
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
   192
    
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   193
    NSUInteger nFormats = [dataTypes count];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   194
    NSUInteger knownFormats = 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   195
    NSUInteger i;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   196
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   197
    // There can be any number of formats on the general pasteboard.  Find out which ones
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   198
    // we know about (i.e., live in the flavormap.properties).
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   199
    for (i = 0; i < nFormats; i++) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   200
        NSString *format = (NSString *)[dataTypes objectAtIndex:i];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   201
        if (indexForFormat(format) != -1)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   202
            knownFormats++;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   203
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   204
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   205
    returnValue = (*env)->NewLongArray(env, knownFormats);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   206
    if (returnValue == NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   207
        return NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   208
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   209
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   210
    if (knownFormats == 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   211
        return returnValue;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   212
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   213
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   214
    // Now go back and map the formats we found back to Java indexes.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   215
    jboolean isCopy;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   216
    jlong *lFormats = (*env)->GetLongArrayElements(env, returnValue, &isCopy);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   217
    jlong *saveFormats = lFormats;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   218
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   219
    for (i = 0; i < nFormats; i++) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   220
        NSString *format = (NSString *)[dataTypes objectAtIndex:i];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   221
        jlong index = indexForFormat(format);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   222
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   223
        if (index != -1) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   224
            *lFormats = index;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   225
            lFormats++;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   226
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   227
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   228
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   229
    (*env)->ReleaseLongArrayElements(env, returnValue, saveFormats, JNI_COMMIT);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   230
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   231
    return returnValue;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   232
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   233
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   234
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   235
 * Class:     sun_lwawt_macosx_CClipboard
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   236
 * Method:    getClipboardData
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   237
 * Signature: (JJ)[B
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   238
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   239
JNIEXPORT jbyteArray JNICALL Java_sun_lwawt_macosx_CClipboard_getClipboardData
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   240
(JNIEnv *env, jobject inObject, jlong format)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   241
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   242
    jbyteArray returnValue = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   243
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   244
    // Note that this routine makes no attempt to interpret the data, since we're returning
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   245
    // a byte array back to Java.  CDataTransferer will do that if necessary.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   246
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   247
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   248
    NSString *formatAsString = formatForIndex(format);
24152
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
   249
    __block NSData* clipData;
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
   250
    [ThreadUtilities performOnMainThreadWaiting:YES block:^() {
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
   251
        clipData = [[[NSPasteboard generalPasteboard] dataForType:formatAsString] retain];
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
   252
    }];
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
   253
    
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   254
    if (clipData == NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   255
        [JNFException raise:env as:"java/io/IOException" reason:"Font transform has NaN position"];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   256
        return NULL;
24152
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
   257
    } else {
dc585189ab28 8037560: [macosx] Cleanup CClipboard.m
pchelko
parents: 23651
diff changeset
   258
        [clipData autorelease];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   259
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   260
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   261
    NSUInteger dataSize = [clipData length];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   262
    returnValue = (*env)->NewByteArray(env, dataSize);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   263
    if (returnValue == NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   264
        return NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   265
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   266
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   267
    if (dataSize != 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   268
        const void *dataBuffer = [clipData bytes];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   269
        (*env)->SetByteArrayRegion(env, returnValue, 0, dataSize, (jbyte *)dataBuffer);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   270
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   271
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   272
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   273
    return returnValue;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   274
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   275
29885
6eb60fac3383 8071668: [macosx] Clipboard does not work with 3rd parties Clipboard Managers
anashaty
parents: 26751
diff changeset
   276
/*                                                                                            
6eb60fac3383 8071668: [macosx] Clipboard does not work with 3rd parties Clipboard Managers
anashaty
parents: 26751
diff changeset
   277
 * Class:     sun_lwawt_macosx_CClipboard                                                     
6eb60fac3383 8071668: [macosx] Clipboard does not work with 3rd parties Clipboard Managers
anashaty
parents: 26751
diff changeset
   278
 * Method:    checkPasteboard                                                                 
6eb60fac3383 8071668: [macosx] Clipboard does not work with 3rd parties Clipboard Managers
anashaty
parents: 26751
diff changeset
   279
 * Signature: ()V                                                                             
6eb60fac3383 8071668: [macosx] Clipboard does not work with 3rd parties Clipboard Managers
anashaty
parents: 26751
diff changeset
   280
 */                                                                                           
6eb60fac3383 8071668: [macosx] Clipboard does not work with 3rd parties Clipboard Managers
anashaty
parents: 26751
diff changeset
   281
JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_CClipboard_checkPasteboardWithoutNotification
6eb60fac3383 8071668: [macosx] Clipboard does not work with 3rd parties Clipboard Managers
anashaty
parents: 26751
diff changeset
   282
(JNIEnv *env, jobject inObject)                                                               
6eb60fac3383 8071668: [macosx] Clipboard does not work with 3rd parties Clipboard Managers
anashaty
parents: 26751
diff changeset
   283
{                                                                                             
6eb60fac3383 8071668: [macosx] Clipboard does not work with 3rd parties Clipboard Managers
anashaty
parents: 26751
diff changeset
   284
    __block BOOL ret = NO;                                                                    
6eb60fac3383 8071668: [macosx] Clipboard does not work with 3rd parties Clipboard Managers
anashaty
parents: 26751
diff changeset
   285
    JNF_COCOA_ENTER(env);                                                                     
6eb60fac3383 8071668: [macosx] Clipboard does not work with 3rd parties Clipboard Managers
anashaty
parents: 26751
diff changeset
   286
    [ThreadUtilities performOnMainThreadWaiting:YES block:^(){                                
6eb60fac3383 8071668: [macosx] Clipboard does not work with 3rd parties Clipboard Managers
anashaty
parents: 26751
diff changeset
   287
        ret = [[CClipboard sharedClipboard] checkPasteboardWithoutNotification:nil];          
6eb60fac3383 8071668: [macosx] Clipboard does not work with 3rd parties Clipboard Managers
anashaty
parents: 26751
diff changeset
   288
    }];                                                                                       
6eb60fac3383 8071668: [macosx] Clipboard does not work with 3rd parties Clipboard Managers
anashaty
parents: 26751
diff changeset
   289
                                                                                              
6eb60fac3383 8071668: [macosx] Clipboard does not work with 3rd parties Clipboard Managers
anashaty
parents: 26751
diff changeset
   290
    JNF_COCOA_EXIT(env);                                                                      
6eb60fac3383 8071668: [macosx] Clipboard does not work with 3rd parties Clipboard Managers
anashaty
parents: 26751
diff changeset
   291
    return ret;                                                                               
32427
c22b7e41adf3 8134984: Text files should end in exactly one newline
martin
parents: 29885
diff changeset
   292
}