author | sveerabhadra |
Fri, 22 Dec 2017 11:00:06 +0530 | |
changeset 48640 | 42ad9a781f51 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
12047 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
13678
diff
changeset
|
2 |
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. |
12047 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
#import "CSystemColors.h" |
|
27 |
||
28 |
#import "java_awt_SystemColor.h" |
|
29 |
#import "sun_lwawt_macosx_LWCToolkit.h" |
|
30 |
||
31 |
#import <JavaNativeFoundation/JavaNativeFoundation.h> |
|
32 |
#import <JavaRuntimeSupport/JavaRuntimeSupport.h> |
|
33 |
||
34 |
#import "ThreadUtilities.h" |
|
35 |
||
13678
5c8001201f98
7197771: Adjust jdk sources to avoid use of implementation defined value of __FILE__
ohair
parents:
12047
diff
changeset
|
36 |
/* Use THIS_FILE when it is available. */ |
5c8001201f98
7197771: Adjust jdk sources to avoid use of implementation defined value of __FILE__
ohair
parents:
12047
diff
changeset
|
37 |
#ifndef THIS_FILE |
5c8001201f98
7197771: Adjust jdk sources to avoid use of implementation defined value of __FILE__
ohair
parents:
12047
diff
changeset
|
38 |
#define THIS_FILE __FILE__ |
5c8001201f98
7197771: Adjust jdk sources to avoid use of implementation defined value of __FILE__
ohair
parents:
12047
diff
changeset
|
39 |
#endif |
5c8001201f98
7197771: Adjust jdk sources to avoid use of implementation defined value of __FILE__
ohair
parents:
12047
diff
changeset
|
40 |
|
12047 | 41 |
NSColor **sColors = nil; |
42 |
NSColor **appleColors = nil; |
|
43 |
||
44 |
@implementation CSystemColors |
|
45 |
||
46 |
+ (void)initialize { |
|
47 |
JNIEnv *env = [ThreadUtilities getJNIEnv]; |
|
48 |
JNF_COCOA_ENTER(env); |
|
49 |
[CSystemColors reloadColors]; |
|
50 |
[[NSNotificationCenter defaultCenter] addObserver:[CSystemColors class] selector:@selector(systemColorsDidChange:) name:NSSystemColorsDidChangeNotification object:nil]; |
|
51 |
JNF_COCOA_EXIT(env); |
|
52 |
} |
|
53 |
||
54 |
static JNF_CLASS_CACHE(jc_LWCToolkit, "sun/lwawt/macosx/LWCToolkit"); |
|
55 |
static JNF_STATIC_MEMBER_CACHE(jm_systemColorsChanged, jc_LWCToolkit, "systemColorsChanged", "()V"); |
|
56 |
||
57 |
+ (void)systemColorsDidChange:(NSNotification *)notification { |
|
58 |
AWT_ASSERT_APPKIT_THREAD; |
|
59 |
||
60 |
[CSystemColors reloadColors]; |
|
61 |
||
62 |
// Call LWCToolkit with the news. LWCToolkit makes certain to do its duties |
|
63 |
// from a new thread. |
|
64 |
JNIEnv* env = [ThreadUtilities getJNIEnv]; |
|
65 |
JNFCallStaticVoidMethod(env, jm_systemColorsChanged); // AWT_THREADING Safe (event) |
|
66 |
} |
|
67 |
||
68 |
||
69 |
+ (void)reloadColors { |
|
70 |
// NOTE: <rdar://problem/3447825> was filed to make this code even lazier. Each |
|
71 |
// color below could be set lazily when it was first accessed. This way the |
|
72 |
// arrays would be sparse, and filled in as SystemColors were used. |
|
73 |
int i; |
|
74 |
if (sColors == nil) { |
|
75 |
sColors = (NSColor**)malloc(sizeof(NSColor*) * java_awt_SystemColor_NUM_COLORS); |
|
76 |
} else { |
|
77 |
for (i = 0; i < java_awt_SystemColor_NUM_COLORS; i++) { |
|
23651
e41298d0da2f
8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents:
23010
diff
changeset
|
78 |
if (sColors[i] != NULL) [sColors[i] release]; |
12047 | 79 |
} |
80 |
} |
|
81 |
||
82 |
sColors[java_awt_SystemColor_DESKTOP] = [NSColor greenColor]; |
|
83 |
sColors[java_awt_SystemColor_ACTIVE_CAPTION] = [NSColor whiteColor]; |
|
84 |
sColors[java_awt_SystemColor_ACTIVE_CAPTION_TEXT] = [NSColor blackColor]; |
|
85 |
sColors[java_awt_SystemColor_ACTIVE_CAPTION_BORDER] = [NSColor whiteColor]; |
|
86 |
sColors[java_awt_SystemColor_INACTIVE_CAPTION] = [NSColor grayColor]; |
|
87 |
sColors[java_awt_SystemColor_INACTIVE_CAPTION_TEXT] = [NSColor grayColor]; |
|
88 |
sColors[java_awt_SystemColor_INACTIVE_CAPTION_BORDER] = [NSColor grayColor]; |
|
89 |
const CGFloat color = (CGFloat)0xEE/(CGFloat)0xFF; |
|
90 |
sColors[java_awt_SystemColor_WINDOW] = [NSColor colorWithCalibratedRed:color green:color blue:color alpha:1.0f]; |
|
91 |
sColors[java_awt_SystemColor_WINDOW_BORDER] = [NSColor windowFrameColor]; |
|
92 |
sColors[java_awt_SystemColor_WINDOW_TEXT] = [NSColor windowFrameTextColor]; |
|
93 |
sColors[java_awt_SystemColor_MENU] = [NSColor controlBackgroundColor]; |
|
94 |
sColors[java_awt_SystemColor_MENU_TEXT] = [NSColor controlTextColor]; |
|
95 |
sColors[java_awt_SystemColor_TEXT] = [NSColor textBackgroundColor]; |
|
96 |
sColors[java_awt_SystemColor_TEXT_TEXT] = [NSColor textColor]; |
|
97 |
sColors[java_awt_SystemColor_TEXT_HIGHLIGHT] = [NSColor selectedTextBackgroundColor]; |
|
98 |
sColors[java_awt_SystemColor_TEXT_HIGHLIGHT_TEXT] = [NSColor selectedTextColor]; |
|
99 |
sColors[java_awt_SystemColor_TEXT_INACTIVE_TEXT] = [NSColor disabledControlTextColor]; |
|
100 |
sColors[java_awt_SystemColor_CONTROL] = [NSColor controlColor]; |
|
101 |
sColors[java_awt_SystemColor_CONTROL_TEXT] = [NSColor controlTextColor]; |
|
102 |
sColors[java_awt_SystemColor_CONTROL_HIGHLIGHT] = [NSColor alternateSelectedControlColor]; |
|
103 |
sColors[java_awt_SystemColor_CONTROL_LT_HIGHLIGHT] = [NSColor alternateSelectedControlTextColor]; |
|
104 |
sColors[java_awt_SystemColor_CONTROL_SHADOW] = [NSColor controlShadowColor]; |
|
105 |
sColors[java_awt_SystemColor_CONTROL_DK_SHADOW] = [NSColor controlDarkShadowColor]; |
|
106 |
sColors[java_awt_SystemColor_SCROLLBAR] = [NSColor scrollBarColor]; |
|
107 |
sColors[java_awt_SystemColor_INFO] = [NSColor textBackgroundColor]; |
|
108 |
sColors[java_awt_SystemColor_INFO_TEXT] = [NSColor textColor]; |
|
109 |
||
110 |
for (i = 0; i < java_awt_SystemColor_NUM_COLORS; i++) { |
|
23651
e41298d0da2f
8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents:
23010
diff
changeset
|
111 |
[sColors[i] retain]; |
12047 | 112 |
} |
113 |
||
114 |
if (appleColors == nil) { |
|
115 |
appleColors = (NSColor**)malloc(sizeof(NSColor*) * sun_lwawt_macosx_LWCToolkit_NUM_APPLE_COLORS); |
|
116 |
} else { |
|
117 |
for (i = 0; i < sun_lwawt_macosx_LWCToolkit_NUM_APPLE_COLORS; i++) { |
|
23651
e41298d0da2f
8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents:
23010
diff
changeset
|
118 |
if (appleColors[i] != NULL) [appleColors[i] release]; |
12047 | 119 |
} |
120 |
} |
|
121 |
||
122 |
appleColors[sun_lwawt_macosx_LWCToolkit_KEYBOARD_FOCUS_COLOR] = [NSColor keyboardFocusIndicatorColor]; |
|
123 |
appleColors[sun_lwawt_macosx_LWCToolkit_INACTIVE_SELECTION_BACKGROUND_COLOR] = [NSColor secondarySelectedControlColor]; |
|
124 |
appleColors[sun_lwawt_macosx_LWCToolkit_INACTIVE_SELECTION_FOREGROUND_COLOR] = [NSColor controlDarkShadowColor]; |
|
125 |
||
126 |
for (i = 0; i < sun_lwawt_macosx_LWCToolkit_NUM_APPLE_COLORS; i++) { |
|
23651
e41298d0da2f
8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents:
23010
diff
changeset
|
127 |
[appleColors[i] retain]; |
12047 | 128 |
} |
129 |
} |
|
130 |
||
131 |
+ (NSColor*)getColor:(NSUInteger)colorIndex useAppleColor:(BOOL)useAppleColor { |
|
132 |
NSColor* result = nil; |
|
133 |
||
134 |
if (colorIndex < (useAppleColor) ? sun_lwawt_macosx_LWCToolkit_NUM_APPLE_COLORS : java_awt_SystemColor_NUM_COLORS) { |
|
135 |
result = (useAppleColor ? appleColors : sColors)[colorIndex]; |
|
136 |
} |
|
137 |
else { |
|
13678
5c8001201f98
7197771: Adjust jdk sources to avoid use of implementation defined value of __FILE__
ohair
parents:
12047
diff
changeset
|
138 |
NSLog(@"%s: %s %sColor: %ld not found, returning black.", THIS_FILE, __FUNCTION__, (useAppleColor) ? "Apple" : "System", colorIndex); |
12047 | 139 |
result = [NSColor blackColor]; |
140 |
} |
|
141 |
||
142 |
return result; |
|
143 |
} |
|
144 |
@end |