src/java.desktop/macosx/native/libawt_lwawt/awt/CTrayIcon.m
author jdv
Fri, 21 Jun 2019 12:42:10 +0530
branchmetal-prototype-branch
changeset 57417 28582d575a98
parent 47508 33da1153954c
permissions -rw-r--r--
Enable volatileimage usage for back buffer
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
/*
47500
9b702b6608f9 8186559: [macos] the screen location is wrong when using AWT/SWT bridge with dual monitors
serb
parents: 47216
diff changeset
     2
 * Copyright (c) 2011, 2017, 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
32872
abca6234313d 8079965: Stop ignoring warnings for libawt_lwawt
serb
parents: 26751
diff changeset
    26
#import "jni_util.h"
abca6234313d 8079965: Stop ignoring warnings for libawt_lwawt
serb
parents: 26751
diff changeset
    27
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    28
#import <AppKit/AppKit.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    29
#import <JavaNativeFoundation/JavaNativeFoundation.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    30
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    31
#import "CTrayIcon.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    32
#import "ThreadUtilities.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    33
#include "GeomUtilities.h"
14157
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
    34
#import "LWCToolkit.h"
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    35
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    36
#define kImageInset 4.0
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    37
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    38
/**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    39
 * If the image of the specified size won't fit into the status bar,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    40
 * then scale it down proprtionally. Otherwise, leave it as is.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    41
 */
37559
09143ccbfc6e 8151773: [macosx] TrayIcon.imageAutoSize property is ignored
serb
parents: 32872
diff changeset
    42
static NSSize ScaledImageSizeForStatusBar(NSSize imageSize, BOOL autosize) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    43
    NSRect imageRect = NSMakeRect(0.0, 0.0, imageSize.width, imageSize.height);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    44
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    45
    // There is a black line at the bottom of the status bar
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    46
    // that we don't want to cover with image pixels.
37559
09143ccbfc6e 8151773: [macosx] TrayIcon.imageAutoSize property is ignored
serb
parents: 32872
diff changeset
    47
    CGFloat desiredSize = [[NSStatusBar systemStatusBar] thickness] - 1.0;
09143ccbfc6e 8151773: [macosx] TrayIcon.imageAutoSize property is ignored
serb
parents: 32872
diff changeset
    48
    if (autosize) {
09143ccbfc6e 8151773: [macosx] TrayIcon.imageAutoSize property is ignored
serb
parents: 32872
diff changeset
    49
        imageRect.size.width = desiredSize;
09143ccbfc6e 8151773: [macosx] TrayIcon.imageAutoSize property is ignored
serb
parents: 32872
diff changeset
    50
        imageRect.size.height = desiredSize;
09143ccbfc6e 8151773: [macosx] TrayIcon.imageAutoSize property is ignored
serb
parents: 32872
diff changeset
    51
    } else {
09143ccbfc6e 8151773: [macosx] TrayIcon.imageAutoSize property is ignored
serb
parents: 32872
diff changeset
    52
        CGFloat scaleFactor = MIN(1.0, desiredSize/imageSize.height);
09143ccbfc6e 8151773: [macosx] TrayIcon.imageAutoSize property is ignored
serb
parents: 32872
diff changeset
    53
        imageRect.size.width *= scaleFactor;
09143ccbfc6e 8151773: [macosx] TrayIcon.imageAutoSize property is ignored
serb
parents: 32872
diff changeset
    54
        imageRect.size.height *= scaleFactor;
09143ccbfc6e 8151773: [macosx] TrayIcon.imageAutoSize property is ignored
serb
parents: 32872
diff changeset
    55
    }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    56
    imageRect = NSIntegralRect(imageRect);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    57
    return imageRect.size;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    58
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    59
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    60
@implementation AWTTrayIcon
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
- (id) initWithPeer:(jobject)thePeer {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    63
    if (!(self = [super init])) return nil;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    64
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    65
    peer = thePeer;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    66
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    67
    theItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    68
    [theItem retain];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    69
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    70
    view = [[AWTTrayIconView alloc] initWithTrayIcon:self];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    71
    [theItem setView:view];
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
    return self;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    74
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    75
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    76
-(void) dealloc {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    77
    JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    78
    JNFDeleteGlobalRef(env, peer);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    79
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    80
    [[NSStatusBar systemStatusBar] removeStatusItem: theItem];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    81
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    82
    // Its a bad idea to force the item to release our view by setting
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    83
    // the item's view to nil: it can lead to a crash in some scenarios.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    84
    // The item will release the view later on, so just set the view's image
14157
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
    85
    // and tray icon to nil since we are done with it.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    86
    [view setImage: nil];
14157
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
    87
    [view setTrayIcon: nil];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    88
    [view release];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    89
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    90
    [theItem release];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    91
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    92
    [super dealloc];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    93
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    94
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    95
- (void) setTooltip:(NSString *) tooltip{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    96
    [view setToolTip:tooltip];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    97
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    98
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    99
-(NSStatusItem *) theItem{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   100
    return theItem;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   101
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   102
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   103
- (jobject) peer{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   104
    return peer;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   105
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   106
37559
09143ccbfc6e 8151773: [macosx] TrayIcon.imageAutoSize property is ignored
serb
parents: 32872
diff changeset
   107
- (void) setImage:(NSImage *) imagePtr sizing:(BOOL)autosize {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   108
    NSSize imageSize = [imagePtr size];
37559
09143ccbfc6e 8151773: [macosx] TrayIcon.imageAutoSize property is ignored
serb
parents: 32872
diff changeset
   109
    NSSize scaledSize = ScaledImageSizeForStatusBar(imageSize, autosize);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   110
    if (imageSize.width != scaledSize.width ||
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   111
        imageSize.height != scaledSize.height) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   112
        [imagePtr setSize: scaledSize];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   113
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   114
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   115
    CGFloat itemLength = scaledSize.width + 2.0*kImageInset;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   116
    [theItem setLength:itemLength];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   117
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   118
    [view setImage:imagePtr];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   119
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   120
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   121
- (NSPoint) getLocationOnScreen {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   122
    return [[view window] convertBaseToScreen: NSZeroPoint];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   123
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   124
14157
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   125
-(void) deliverJavaMouseEvent: (NSEvent *) event {
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   126
    [AWTToolkit eventCountPlusPlus];
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   127
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   128
    JNIEnv *env = [ThreadUtilities getJNIEnv];
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   129
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   130
    NSPoint eventLocation = [event locationInWindow];
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   131
    NSPoint localPoint = [view convertPoint: eventLocation fromView: nil];
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   132
    localPoint.y = [view bounds].size.height - localPoint.y;
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   133
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   134
    NSPoint absP = [NSEvent mouseLocation];
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   135
    NSEventType type = [event type];
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   136
47500
9b702b6608f9 8186559: [macos] the screen location is wrong when using AWT/SWT bridge with dual monitors
serb
parents: 47216
diff changeset
   137
    absP = ConvertNSScreenPoint(NULL, absP);
14157
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   138
    jint clickCount;
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   139
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   140
    clickCount = [event clickCount];
43823
bf04b9310757 8173876: Fast precise scrolling and DeltaAccumulator fix for macOS Sierra 10.12.2
malenkov
parents: 42201
diff changeset
   141
bf04b9310757 8173876: Fast precise scrolling and DeltaAccumulator fix for macOS Sierra 10.12.2
malenkov
parents: 42201
diff changeset
   142
    jdouble deltaX = [event deltaX];
bf04b9310757 8173876: Fast precise scrolling and DeltaAccumulator fix for macOS Sierra 10.12.2
malenkov
parents: 42201
diff changeset
   143
    jdouble deltaY = [event deltaY];
bf04b9310757 8173876: Fast precise scrolling and DeltaAccumulator fix for macOS Sierra 10.12.2
malenkov
parents: 42201
diff changeset
   144
    if ([AWTToolkit hasPreciseScrollingDeltas: event]) {
bf04b9310757 8173876: Fast precise scrolling and DeltaAccumulator fix for macOS Sierra 10.12.2
malenkov
parents: 42201
diff changeset
   145
        deltaX = [event scrollingDeltaX] * 0.1;
bf04b9310757 8173876: Fast precise scrolling and DeltaAccumulator fix for macOS Sierra 10.12.2
malenkov
parents: 42201
diff changeset
   146
        deltaY = [event scrollingDeltaY] * 0.1;
bf04b9310757 8173876: Fast precise scrolling and DeltaAccumulator fix for macOS Sierra 10.12.2
malenkov
parents: 42201
diff changeset
   147
    }
bf04b9310757 8173876: Fast precise scrolling and DeltaAccumulator fix for macOS Sierra 10.12.2
malenkov
parents: 42201
diff changeset
   148
23268
2cdb715ff32d 8029868: Fix KSS issues in sun.lwawt.macosx
pchelko
parents: 15322
diff changeset
   149
    static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/NSEvent");
41773
58254fa6487a 8166591: [macos 10.12] Trackpad scrolling of text on OS X 10.12 Sierra is very fast (Trackpad, Retina only)
alexsch
parents: 37559
diff changeset
   150
    static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IIIIIIIIDDI)V");
14157
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   151
    jobject jEvent = JNFNewObject(env, jctor_NSEvent,
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   152
                                  [event type],
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   153
                                  [event modifierFlags],
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   154
                                  clickCount,
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   155
                                  [event buttonNumber],
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   156
                                  (jint)localPoint.x, (jint)localPoint.y,
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   157
                                  (jint)absP.x, (jint)absP.y,
43823
bf04b9310757 8173876: Fast precise scrolling and DeltaAccumulator fix for macOS Sierra 10.12.2
malenkov
parents: 42201
diff changeset
   158
                                  deltaY,
bf04b9310757 8173876: Fast precise scrolling and DeltaAccumulator fix for macOS Sierra 10.12.2
malenkov
parents: 42201
diff changeset
   159
                                  deltaX,
41773
58254fa6487a 8166591: [macos 10.12] Trackpad scrolling of text on OS X 10.12 Sierra is very fast (Trackpad, Retina only)
alexsch
parents: 37559
diff changeset
   160
                                  [AWTToolkit scrollStateWithEvent: event]);
24555
42926c558bc8 8042752: [macosx] NSEvent instances leak throw JNI local references
pchelko
parents: 23328
diff changeset
   161
    CHECK_NULL(jEvent);
14157
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   162
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   163
    static JNF_CLASS_CACHE(jc_TrayIcon, "sun/lwawt/macosx/CTrayIcon");
23268
2cdb715ff32d 8029868: Fix KSS issues in sun.lwawt.macosx
pchelko
parents: 15322
diff changeset
   164
    static JNF_MEMBER_CACHE(jm_handleMouseEvent, jc_TrayIcon, "handleMouseEvent", "(Lsun/lwawt/macosx/NSEvent;)V");
14157
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   165
    JNFCallVoidMethod(env, peer, jm_handleMouseEvent, jEvent);
24555
42926c558bc8 8042752: [macosx] NSEvent instances leak throw JNI local references
pchelko
parents: 23328
diff changeset
   166
    (*env)->DeleteLocalRef(env, jEvent);
14157
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   167
}
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   168
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   169
@end //AWTTrayIcon
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   170
//================================================
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   171
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   172
@implementation AWTTrayIconView
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   173
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   174
-(id)initWithTrayIcon:(AWTTrayIcon *)theTrayIcon {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   175
    self = [super initWithFrame:NSMakeRect(0, 0, 1, 1)];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   176
14157
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   177
    [self setTrayIcon: theTrayIcon];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   178
    isHighlighted = NO;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   179
    image = nil;
42201
cdf51b0d0361 7153700: [macosx] add support for MouseMotionListener to the TrayIcon
mhalder
parents: 41773
diff changeset
   180
    trackingArea = nil;
47500
9b702b6608f9 8186559: [macos] the screen location is wrong when using AWT/SWT bridge with dual monitors
serb
parents: 47216
diff changeset
   181
42201
cdf51b0d0361 7153700: [macosx] add support for MouseMotionListener to the TrayIcon
mhalder
parents: 41773
diff changeset
   182
    [self addTrackingArea];
47500
9b702b6608f9 8186559: [macos] the screen location is wrong when using AWT/SWT bridge with dual monitors
serb
parents: 47216
diff changeset
   183
42201
cdf51b0d0361 7153700: [macosx] add support for MouseMotionListener to the TrayIcon
mhalder
parents: 41773
diff changeset
   184
    return self;
cdf51b0d0361 7153700: [macosx] add support for MouseMotionListener to the TrayIcon
mhalder
parents: 41773
diff changeset
   185
}
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   186
42201
cdf51b0d0361 7153700: [macosx] add support for MouseMotionListener to the TrayIcon
mhalder
parents: 41773
diff changeset
   187
- (void)addTrackingArea {
47500
9b702b6608f9 8186559: [macos] the screen location is wrong when using AWT/SWT bridge with dual monitors
serb
parents: 47216
diff changeset
   188
    NSTrackingAreaOptions options = NSTrackingMouseMoved |
9b702b6608f9 8186559: [macos] the screen location is wrong when using AWT/SWT bridge with dual monitors
serb
parents: 47216
diff changeset
   189
                                    NSTrackingInVisibleRect |
42201
cdf51b0d0361 7153700: [macosx] add support for MouseMotionListener to the TrayIcon
mhalder
parents: 41773
diff changeset
   190
                                    NSTrackingActiveAlways;
cdf51b0d0361 7153700: [macosx] add support for MouseMotionListener to the TrayIcon
mhalder
parents: 41773
diff changeset
   191
    trackingArea = [[NSTrackingArea alloc] initWithRect: CGRectZero
cdf51b0d0361 7153700: [macosx] add support for MouseMotionListener to the TrayIcon
mhalder
parents: 41773
diff changeset
   192
                                                options: options
cdf51b0d0361 7153700: [macosx] add support for MouseMotionListener to the TrayIcon
mhalder
parents: 41773
diff changeset
   193
                                                owner: self
cdf51b0d0361 7153700: [macosx] add support for MouseMotionListener to the TrayIcon
mhalder
parents: 41773
diff changeset
   194
                                                userInfo: nil];
cdf51b0d0361 7153700: [macosx] add support for MouseMotionListener to the TrayIcon
mhalder
parents: 41773
diff changeset
   195
    [self addTrackingArea:trackingArea];
12047
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   198
-(void) dealloc {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   199
    [image release];
42201
cdf51b0d0361 7153700: [macosx] add support for MouseMotionListener to the TrayIcon
mhalder
parents: 41773
diff changeset
   200
    [trackingArea release];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   201
    [super dealloc];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   202
}
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
- (void)setHighlighted:(BOOL)aFlag
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   205
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   206
    if (isHighlighted != aFlag) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   207
        isHighlighted = aFlag;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   208
        [self setNeedsDisplay:YES];
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
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   211
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   212
- (void)setImage:(NSImage*)anImage {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   213
    [anImage retain];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   214
    [image release];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   215
    image = anImage;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   216
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   217
    if (image != nil) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   218
        [self setNeedsDisplay:YES];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   219
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   220
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   221
14157
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   222
-(void)setTrayIcon:(AWTTrayIcon*)theTrayIcon {
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   223
    trayIcon = theTrayIcon;
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   224
}
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   225
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   226
- (void)menuWillOpen:(NSMenu *)menu
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
    [self setHighlighted:YES];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   229
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   230
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   231
- (void)menuDidClose:(NSMenu *)menu
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
    [menu setDelegate:nil];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   234
    [self setHighlighted:NO];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   235
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   236
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   237
- (void)drawRect:(NSRect)dirtyRect
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
    if (image == nil) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   240
        return;
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   243
    NSRect bounds = [self bounds];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   244
    NSSize imageSize = [image size];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   245
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   246
    NSRect drawRect = {{ (bounds.size.width - imageSize.width) / 2.0,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   247
        (bounds.size.height - imageSize.height) / 2.0 }, imageSize};
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   248
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   249
    // don't cover bottom pixels of the status bar with the image
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   250
    if (drawRect.origin.y < 1.0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   251
        drawRect.origin.y = 1.0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   252
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   253
    drawRect = NSIntegralRect(drawRect);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   254
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   255
    [trayIcon.theItem drawStatusBarBackgroundInRect:bounds
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   256
                                withHighlight:isHighlighted];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   257
    [image drawInRect:drawRect
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   258
             fromRect:NSZeroRect
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   259
            operation:NSCompositeSourceOver
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   260
             fraction:1.0
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   261
     ];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   262
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   263
14157
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   264
- (void)mouseDown:(NSEvent *)event {
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   265
    [trayIcon deliverJavaMouseEvent: event];
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   266
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   267
    // don't show the menu on ctrl+click: it triggers ACTION event, like right click
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   268
    if (([event modifierFlags] & NSControlKeyMask) == 0) {
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   269
        //find CTrayIcon.getPopupMenuModel method and call it to get popup menu ptr.
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   270
        JNIEnv *env = [ThreadUtilities getJNIEnv];
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   271
        static JNF_CLASS_CACHE(jc_CTrayIcon, "sun/lwawt/macosx/CTrayIcon");
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   272
        static JNF_MEMBER_CACHE(jm_getPopupMenuModel, jc_CTrayIcon, "getPopupMenuModel", "()J");
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   273
        jlong res = JNFCallLongMethod(env, trayIcon.peer, jm_getPopupMenuModel);
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   274
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   275
        if (res != 0) {
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   276
            CPopupMenu *cmenu = jlong_to_ptr(res);
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   277
            NSMenu* menu = [cmenu menu];
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   278
            [menu setDelegate:self];
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   279
            [trayIcon.theItem popUpStatusItemMenu:menu];
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   280
            [self setNeedsDisplay:YES];
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   281
        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   282
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   283
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   284
14157
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   285
- (void) mouseUp:(NSEvent *)event {
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   286
    [trayIcon deliverJavaMouseEvent: event];
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   287
}
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   288
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   289
- (void) mouseDragged:(NSEvent *)event {
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   290
    [trayIcon deliverJavaMouseEvent: event];
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   291
}
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   292
42201
cdf51b0d0361 7153700: [macosx] add support for MouseMotionListener to the TrayIcon
mhalder
parents: 41773
diff changeset
   293
- (void) mouseMoved: (NSEvent *)event {
cdf51b0d0361 7153700: [macosx] add support for MouseMotionListener to the TrayIcon
mhalder
parents: 41773
diff changeset
   294
    [trayIcon deliverJavaMouseEvent: event];
cdf51b0d0361 7153700: [macosx] add support for MouseMotionListener to the TrayIcon
mhalder
parents: 41773
diff changeset
   295
}
cdf51b0d0361 7153700: [macosx] add support for MouseMotionListener to the TrayIcon
mhalder
parents: 41773
diff changeset
   296
14157
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   297
- (void) rightMouseDown:(NSEvent *)event {
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   298
    [trayIcon deliverJavaMouseEvent: event];
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   299
}
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   300
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   301
- (void) rightMouseUp:(NSEvent *)event {
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   302
    [trayIcon deliverJavaMouseEvent: event];
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   303
}
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   304
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   305
- (void) rightMouseDragged:(NSEvent *)event {
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   306
    [trayIcon deliverJavaMouseEvent: event];
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   307
}
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   308
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   309
- (void) otherMouseDown:(NSEvent *)event {
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   310
    [trayIcon deliverJavaMouseEvent: event];
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   311
}
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   312
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   313
- (void) otherMouseUp:(NSEvent *)event {
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   314
    [trayIcon deliverJavaMouseEvent: event];
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   315
}
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   316
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   317
- (void) otherMouseDragged:(NSEvent *)event {
5d50d32dd770 7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents: 12047
diff changeset
   318
    [trayIcon deliverJavaMouseEvent: event];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   319
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   320
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   321
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   322
@end //AWTTrayIconView
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   323
//================================================
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   324
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   325
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   326
 * Class:     sun_lwawt_macosx_CTrayIcon
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   327
 * Method:    nativeCreate
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   328
 * Signature: ()J
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   329
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   330
JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CTrayIcon_nativeCreate
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   331
(JNIEnv *env, jobject peer) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   332
    __block AWTTrayIcon *trayIcon = nil;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   333
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   334
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   335
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   336
    jobject thePeer = JNFNewGlobalRef(env, peer);
15322
3638f33225ec 7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents: 14157
diff changeset
   337
    [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   338
        trayIcon = [[AWTTrayIcon alloc] initWithPeer:thePeer];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   339
    }];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   340
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   341
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   342
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   343
    return ptr_to_jlong(trayIcon);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   344
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   345
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   346
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   347
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   348
 * Class: java_awt_TrayIcon
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   349
 * Method: initIDs
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   350
 * Signature: ()V
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   351
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   352
JNIEXPORT void JNICALL Java_java_awt_TrayIcon_initIDs
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   353
(JNIEnv *env, jclass cls) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   354
    //Do nothing.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   355
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   356
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   357
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   358
 * Class:     sun_lwawt_macosx_CTrayIcon
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   359
 * Method:    nativeSetToolTip
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   360
 * Signature: (JLjava/lang/String;)V
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   361
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   362
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CTrayIcon_nativeSetToolTip
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   363
(JNIEnv *env, jobject self, jlong model, jstring jtooltip) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   364
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   365
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   366
    AWTTrayIcon *icon = jlong_to_ptr(model);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   367
    NSString *tooltip = JNFJavaToNSString(env, jtooltip);
15322
3638f33225ec 7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents: 14157
diff changeset
   368
    [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   369
        [icon setTooltip:tooltip];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   370
    }];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   371
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   372
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   373
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   374
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   375
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   376
 * Class:     sun_lwawt_macosx_CTrayIcon
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   377
 * Method:    setNativeImage
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   378
 * Signature: (JJZ)V
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   379
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   380
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CTrayIcon_setNativeImage
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   381
(JNIEnv *env, jobject self, jlong model, jlong imagePtr, jboolean autosize) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   382
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   383
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   384
    AWTTrayIcon *icon = jlong_to_ptr(model);
15322
3638f33225ec 7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents: 14157
diff changeset
   385
    [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   386
        [icon setImage:jlong_to_ptr(imagePtr) sizing:autosize];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   387
    }];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   388
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   389
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   390
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   391
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   392
JNIEXPORT jobject JNICALL
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   393
Java_sun_lwawt_macosx_CTrayIcon_nativeGetIconLocation
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   394
(JNIEnv *env, jobject self, jlong model) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   395
    jobject jpt = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   396
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   397
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   398
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   399
    __block NSPoint pt = NSZeroPoint;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   400
    AWTTrayIcon *icon = jlong_to_ptr(model);
15322
3638f33225ec 7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents: 14157
diff changeset
   401
    [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   402
        NSPoint loc = [icon getLocationOnScreen];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   403
        pt = ConvertNSScreenPoint(env, loc);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   404
    }];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   405
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   406
    jpt = NSToJavaPoint(env, pt);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   407
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   408
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   409
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   410
    return jpt;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   411
}
47508
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47500
diff changeset
   412
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47500
diff changeset
   413
JNIEXPORT void JNICALL
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47500
diff changeset
   414
Java_sun_lwawt_macosx_CTrayIcon_nativeShowNotification
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47500
diff changeset
   415
(JNIEnv *env, jobject self, jlong model, jobject jcaption, jobject jtext,
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47500
diff changeset
   416
              long nsimage) {
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47500
diff changeset
   417
JNF_COCOA_ENTER(env);
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47500
diff changeset
   418
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47500
diff changeset
   419
    AWTTrayIcon *icon = jlong_to_ptr(model);
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47500
diff changeset
   420
    NSString *caption = JNFJavaToNSString(env, jcaption);
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47500
diff changeset
   421
    NSString *text = JNFJavaToNSString(env, jtext);
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47500
diff changeset
   422
    NSImage * contentImage = jlong_to_ptr(nsimage);
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47500
diff changeset
   423
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47500
diff changeset
   424
    [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47500
diff changeset
   425
        NSUserNotification *notification = [[NSUserNotification alloc] init];
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47500
diff changeset
   426
        notification.title = caption;
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47500
diff changeset
   427
        notification.informativeText = text;
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47500
diff changeset
   428
        notification.contentImage = contentImage;
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47500
diff changeset
   429
        notification.soundName = NSUserNotificationDefaultSoundName;
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47500
diff changeset
   430
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47500
diff changeset
   431
        [[NSUserNotificationCenter defaultUserNotificationCenter]
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47500
diff changeset
   432
            deliverNotification:notification];
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47500
diff changeset
   433
    }];
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47500
diff changeset
   434
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47500
diff changeset
   435
JNF_COCOA_EXIT(env);
33da1153954c 8187639: TrayIcon is not properly supported on macOS in multi-screen environment
serb
parents: 47500
diff changeset
   436
}