1 /* 2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. 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 <JavaNativeFoundation/JavaNativeFoundation.h> 27 #import <JavaRuntimeSupport/JavaRuntimeSupport.h> 28 29 #import "apple_laf_JRSUIConstants.h" 30 #import "apple_laf_JRSUIConstants_Key.h" 31 #import "apple_laf_JRSUIConstants_AlignmentVertical.h" 32 #import "apple_laf_JRSUIConstants_AlignmentHorizontal.h" 33 #import "apple_laf_JRSUIConstants_Animating.h" 34 #import "apple_laf_JRSUIConstants_ArrowsOnly.h" 35 #import "apple_laf_JRSUIConstants_BooleanValue.h" 36 #import "apple_laf_JRSUIConstants_Direction.h" 37 #import "apple_laf_JRSUIConstants_Focused.h" 38 #import "apple_laf_JRSUIConstants_FrameOnly.h" 39 #import "apple_laf_JRSUIConstants_IndicatorOnly.h" 40 #import "apple_laf_JRSUIConstants_NoIndicator.h" 41 #import "apple_laf_JRSUIConstants_NothingToScroll.h" 42 #import "apple_laf_JRSUIConstants_Orientation.h" 43 #import "apple_laf_JRSUIConstants_ScrollBarPart.h" 44 #import "apple_laf_JRSUIConstants_SegmentPosition.h" 45 #import "apple_laf_JRSUIConstants_SegmentTrailingSeparator.h" 46 #import "apple_laf_JRSUIConstants_SegmentLeadingSeparator.h" 47 #import "apple_laf_JRSUIConstants_ShowArrows.h" 48 #import "apple_laf_JRSUIConstants_Size.h" 49 #import "apple_laf_JRSUIConstants_State.h" 50 #import "apple_laf_JRSUIConstants_Variant.h" 51 #import "apple_laf_JRSUIConstants_Widget.h" 52 #import "apple_laf_JRSUIConstants_WindowType.h" 53 #import "apple_laf_JRSUIConstants_WindowTitleBarSeparator.h" 54 #import "apple_laf_JRSUIConstants_WindowClipCorners.h" 55 56 #import "JRSUIConstantSync.h" 57 58 59 static CFTypeRef widgetKey = NULL; 60 static CFTypeRef stateKey = NULL; 61 static CFTypeRef sizeKey = NULL; 62 static CFTypeRef directionKey = NULL; 63 static CFTypeRef orientationKey = NULL; 64 static CFTypeRef verticalAlignmentKey = NULL; 65 static CFTypeRef horizontalAlignmentKey = NULL; 66 static CFTypeRef positionKey = NULL; 67 static CFTypeRef pressedPartKey = NULL; 68 static CFTypeRef variantKey = NULL; 69 static CFTypeRef windowTypeKey = NULL; 70 static CFTypeRef focusedKey = NULL; 71 static CFTypeRef indicatorOnlyKey = NULL; 72 static CFTypeRef noIndicatorKey = NULL; 73 static CFTypeRef nothingToScrollKey = NULL; 74 static CFTypeRef arrowsOnlyKey = NULL; 75 static CFTypeRef frameOnlyKey = NULL; 76 static CFTypeRef segmentTrailingSeparatorKey = NULL; 77 static CFTypeRef segmentLeadingSeparatorKey = NULL; 78 static CFTypeRef windowFrameDrawClippedKey = NULL; 79 static CFTypeRef windowFrameDrawTitleSeparatorKey = NULL; 80 static CFTypeRef maximumValueKey = NULL; 81 static CFTypeRef valueKey = NULL; 82 static CFTypeRef animationStartTimeKey = NULL; 83 static CFTypeRef animationTimeKey = NULL; 84 85 86 #define JRS_CONSTANT(clazz, constant) \ 87 kJRSUI_ ## clazz ## _ ## constant 88 89 #define JNI_CONSTANT(clazz, constant) \ 90 apple_laf_JRSUIConstants_ ## clazz ## __ ## constant 91 92 #define CONSTANT_CHECK(clazz, constant) \ 93 ( JRS_CONSTANT(clazz, constant) == JNI_CONSTANT(clazz, constant) ) 94 95 #define CONSISTENCY_CHECK(clazz, constant) \ 96 if ( !CONSTANT_CHECK(clazz, constant) ) return NO; 97 98 #define ASSIGN_KEY(key) \ 99 key ## Key = JRSUIGetKey(JRS_CONSTANT(Key, key)); \ 100 if (key ## Key == NULL) return NO; 101 102 #define ASSIGN_KEY_IF_EXISTS(key, constant) \ 103 key ## Key = JRSUIGetKey(constant); 104 105 static BOOL init_and_check_constant_coherency() { 106 ASSIGN_KEY(widget); 107 ASSIGN_KEY(state); 108 ASSIGN_KEY(size); 109 ASSIGN_KEY(direction); 110 ASSIGN_KEY(orientation); 111 ASSIGN_KEY(verticalAlignment); 112 ASSIGN_KEY(horizontalAlignment); 113 ASSIGN_KEY(position); 114 ASSIGN_KEY(pressedPart); 115 ASSIGN_KEY(variant); 116 ASSIGN_KEY(windowType); 117 ASSIGN_KEY(focused); 118 ASSIGN_KEY(indicatorOnly); 119 ASSIGN_KEY(noIndicator); 120 ASSIGN_KEY(nothingToScroll); 121 ASSIGN_KEY(arrowsOnly); 122 ASSIGN_KEY(frameOnly); 123 ASSIGN_KEY(segmentTrailingSeparator); 124 ASSIGN_KEY_IF_EXISTS(segmentLeadingSeparator, 29); // kJRSUI_Key_segmentLeadingSeparator = 29 125 ASSIGN_KEY(windowFrameDrawClipped); 126 ASSIGN_KEY(windowFrameDrawTitleSeparator); 127 ASSIGN_KEY(maximumValue); 128 ASSIGN_KEY(value); 129 ASSIGN_KEY(animationStartTime); 130 ASSIGN_KEY(animationTime); 131 132 CONSISTENCY_CHECK(Key, value); 133 CONSISTENCY_CHECK(Key, thumbProportion); 134 CONSISTENCY_CHECK(Key, thumbStart); 135 CONSISTENCY_CHECK(Key, animationFrame); 136 CONSISTENCY_CHECK(Key, windowTitleBarHeight); 137 138 CONSISTENCY_CHECK(Widget, background); 139 CONSISTENCY_CHECK(Widget, buttonBevel); 140 CONSISTENCY_CHECK(Widget, buttonBevelInset); 141 CONSISTENCY_CHECK(Widget, buttonBevelRound); 142 CONSISTENCY_CHECK(Widget, buttonCheckBox); 143 CONSISTENCY_CHECK(Widget, buttonComboBox); 144 CONSISTENCY_CHECK(Widget, buttonComboBoxInset); 145 CONSISTENCY_CHECK(Widget, buttonDisclosure); 146 CONSISTENCY_CHECK(Widget, buttonListHeader); 147 CONSISTENCY_CHECK(Widget, buttonLittleArrows); 148 CONSISTENCY_CHECK(Widget, buttonPopDown); 149 CONSISTENCY_CHECK(Widget, buttonPopDownInset); 150 CONSISTENCY_CHECK(Widget, buttonPopDownSquare); 151 CONSISTENCY_CHECK(Widget, buttonPopUp); 152 CONSISTENCY_CHECK(Widget, buttonPopUpInset); 153 CONSISTENCY_CHECK(Widget, buttonPopUpSquare); 154 CONSISTENCY_CHECK(Widget, buttonPush); 155 CONSISTENCY_CHECK(Widget, buttonPushScope); 156 CONSISTENCY_CHECK(Widget, buttonPushScope2); 157 CONSISTENCY_CHECK(Widget, buttonPushTextured); 158 CONSISTENCY_CHECK(Widget, buttonPushInset); 159 CONSISTENCY_CHECK(Widget, buttonPushInset2); 160 CONSISTENCY_CHECK(Widget, buttonRadio); 161 CONSISTENCY_CHECK(Widget, buttonRound); 162 CONSISTENCY_CHECK(Widget, buttonRoundHelp); 163 CONSISTENCY_CHECK(Widget, buttonRoundInset); 164 CONSISTENCY_CHECK(Widget, buttonRoundInset2); 165 CONSISTENCY_CHECK(Widget, buttonSearchFieldCancel); 166 CONSISTENCY_CHECK(Widget, buttonSearchFieldFind); 167 CONSISTENCY_CHECK(Widget, buttonSegmented); 168 CONSISTENCY_CHECK(Widget, buttonSegmentedInset); 169 CONSISTENCY_CHECK(Widget, buttonSegmentedInset2); 170 CONSISTENCY_CHECK(Widget, buttonSegmentedSCurve); 171 CONSISTENCY_CHECK(Widget, buttonSegmentedTextured); 172 CONSISTENCY_CHECK(Widget, buttonSegmentedToolbar); 173 CONSISTENCY_CHECK(Widget, dial); 174 CONSISTENCY_CHECK(Widget, disclosureTriangle); 175 CONSISTENCY_CHECK(Widget, dividerGrabber); 176 CONSISTENCY_CHECK(Widget, dividerSeparatorBar); 177 CONSISTENCY_CHECK(Widget, dividerSplitter); 178 CONSISTENCY_CHECK(Widget, focus); 179 CONSISTENCY_CHECK(Widget, frameGroupBox); 180 CONSISTENCY_CHECK(Widget, frameGroupBoxSecondary); 181 CONSISTENCY_CHECK(Widget, frameListBox); 182 CONSISTENCY_CHECK(Widget, framePlacard); 183 CONSISTENCY_CHECK(Widget, frameTextField); 184 CONSISTENCY_CHECK(Widget, frameTextFieldRound); 185 CONSISTENCY_CHECK(Widget, frameWell); 186 CONSISTENCY_CHECK(Widget, growBox); 187 CONSISTENCY_CHECK(Widget, growBoxTextured); 188 CONSISTENCY_CHECK(Widget, gradient); 189 CONSISTENCY_CHECK(Widget, menu); 190 CONSISTENCY_CHECK(Widget, menuItem); 191 CONSISTENCY_CHECK(Widget, menuBar); 192 CONSISTENCY_CHECK(Widget, menuTitle); 193 CONSISTENCY_CHECK(Widget, progressBar); 194 CONSISTENCY_CHECK(Widget, progressIndeterminateBar); 195 CONSISTENCY_CHECK(Widget, progressRelevance); 196 CONSISTENCY_CHECK(Widget, progressSpinner); 197 CONSISTENCY_CHECK(Widget, scrollBar); 198 CONSISTENCY_CHECK(Widget, scrollColumnSizer); 199 CONSISTENCY_CHECK(Widget, slider); 200 CONSISTENCY_CHECK(Widget, sliderThumb); 201 CONSISTENCY_CHECK(Widget, synchronization); 202 CONSISTENCY_CHECK(Widget, tab); 203 CONSISTENCY_CHECK(Widget, titleBarCloseBox); 204 CONSISTENCY_CHECK(Widget, titleBarCollapseBox); 205 CONSISTENCY_CHECK(Widget, titleBarZoomBox); 206 CONSISTENCY_CHECK(Widget, titleBarToolbarButton); 207 CONSISTENCY_CHECK(Widget, toolbarItemWell); 208 CONSISTENCY_CHECK(Widget, windowFrame); 209 210 CONSISTENCY_CHECK(State, active); 211 CONSISTENCY_CHECK(State, inactive); 212 CONSISTENCY_CHECK(State, disabled); 213 CONSISTENCY_CHECK(State, pressed); 214 CONSISTENCY_CHECK(State, pulsed); 215 CONSISTENCY_CHECK(State, rollover); 216 CONSISTENCY_CHECK(State, drag); 217 218 CONSISTENCY_CHECK(Size, mini); 219 CONSISTENCY_CHECK(Size, small); 220 CONSISTENCY_CHECK(Size, regular); 221 CONSISTENCY_CHECK(Size, large); 222 223 CONSISTENCY_CHECK(Direction, none); 224 CONSISTENCY_CHECK(Direction, up); 225 CONSISTENCY_CHECK(Direction, down); 226 CONSISTENCY_CHECK(Direction, left); 227 CONSISTENCY_CHECK(Direction, right); 228 CONSISTENCY_CHECK(Direction, north); 229 CONSISTENCY_CHECK(Direction, south); 230 CONSISTENCY_CHECK(Direction, east); 231 CONSISTENCY_CHECK(Direction, west); 232 233 CONSISTENCY_CHECK(Orientation, horizontal); 234 CONSISTENCY_CHECK(Orientation, vertical); 235 236 CONSISTENCY_CHECK(AlignmentHorizontal, left); 237 CONSISTENCY_CHECK(AlignmentHorizontal, center); 238 CONSISTENCY_CHECK(AlignmentHorizontal, right); 239 240 CONSISTENCY_CHECK(AlignmentVertical, top); 241 CONSISTENCY_CHECK(AlignmentVertical, center); 242 CONSISTENCY_CHECK(AlignmentVertical, bottom); 243 244 CONSISTENCY_CHECK(SegmentPosition, first); 245 CONSISTENCY_CHECK(SegmentPosition, middle); 246 CONSISTENCY_CHECK(SegmentPosition, last); 247 CONSISTENCY_CHECK(SegmentPosition, only); 248 249 CONSISTENCY_CHECK(ScrollBarPart, none); 250 CONSISTENCY_CHECK(ScrollBarPart, thumb); 251 CONSISTENCY_CHECK(ScrollBarPart, arrowMin); 252 CONSISTENCY_CHECK(ScrollBarPart, arrowMax); 253 CONSISTENCY_CHECK(ScrollBarPart, arrowMaxInside); 254 CONSISTENCY_CHECK(ScrollBarPart, arrowMinInside); 255 CONSISTENCY_CHECK(ScrollBarPart, trackMin); 256 CONSISTENCY_CHECK(ScrollBarPart, trackMax); 257 258 CONSISTENCY_CHECK(Variant, menuGlyph); 259 CONSISTENCY_CHECK(Variant, menuPopup); 260 CONSISTENCY_CHECK(Variant, menuPulldown); 261 CONSISTENCY_CHECK(Variant, menuHierarchical); 262 CONSISTENCY_CHECK(Variant, gradientListBackgroundEven); 263 CONSISTENCY_CHECK(Variant, gradientListBackgroundOdd); 264 CONSISTENCY_CHECK(Variant, gradientSideBar); 265 CONSISTENCY_CHECK(Variant, gradientSideBarSelection); 266 CONSISTENCY_CHECK(Variant, gradientSideBarFocusedSelection); 267 268 CONSISTENCY_CHECK(WindowType, document); 269 CONSISTENCY_CHECK(WindowType, utility); 270 CONSISTENCY_CHECK(WindowType, titlelessUtility); 271 272 return YES; 273 } 274 275 static CFBooleanRef get_boolean_value_for(jbyte value) { 276 return (value != 0) ? kCFBooleanTrue : kCFBooleanFalse; 277 } 278 279 static CFNumberRef get_boolean_number_value_for(jbyte value) { 280 static CFNumberRef zero = NULL; 281 static CFNumberRef one = NULL; 282 283 if (!zero) { 284 double zeroVal = 0.0; 285 zero = CFNumberCreate(NULL, kCFNumberDoubleType, &zeroVal); 286 double oneVal = 1.0; 287 one = CFNumberCreate(NULL, kCFNumberDoubleType, &oneVal); 288 } 289 290 return (value != 0) ? one : zero; 291 } 292 293 BOOL _InitializeJRSProperties() { 294 static BOOL initialized = NO; 295 static BOOL coherent = NO; 296 297 if (!initialized) { 298 coherent = init_and_check_constant_coherency(); 299 initialized = YES; 300 } 301 302 return coherent; 303 } 304 305 #define MASK(property) \ 306 apple_laf_JRSUIConstants_ ## property ## _MASK 307 308 #define SHIFT(property) \ 309 apple_laf_JRSUIConstants_ ## property ## _SHIFT 310 311 #define IF_CHANGED_SET_USING(property, setter) \ 312 { \ 313 jlong value = (newProperties & MASK(property)); \ 314 if ((value - (oldProperties & MASK(property))) != 0L) { \ 315 setter(control, value >> SHIFT(property)); \ 316 } \ 317 } 318 319 #define IF_CHANGED_SET_KEYED_BOOLEAN(property, key, getter) \ 320 { \ 321 jlong value = (newProperties & MASK(property)); \ 322 if ((value - (oldProperties & MASK(property))) != 0L) { \ 323 CFTypeRef cfValue = getter(value >> SHIFT(property)); \ 324 if (cfValue) { \ 325 JRSUIControlSetValueByKey(control, key, cfValue); \ 326 } \ 327 } \ 328 } 329 330 #define IF_KEY_EXISTS_DO(key, operation) \ 331 { \ 332 if (key != NULL) { \ 333 operation; \ 334 } \ 335 } 336 337 jint _SyncEncodedProperties(JRSUIControlRef control, jlong oldProperties, jlong newProperties) { 338 if (!_InitializeJRSProperties()) abort(); 339 340 IF_CHANGED_SET_USING(Widget, JRSUIControlSetWidget); 341 IF_CHANGED_SET_USING(State, JRSUIControlSetState); 342 IF_CHANGED_SET_USING(Size, JRSUIControlSetSize); 343 IF_CHANGED_SET_USING(Direction, JRSUIControlSetDirection); 344 IF_CHANGED_SET_USING(Orientation, JRSUIControlSetOrientation); 345 IF_CHANGED_SET_USING(AlignmentVertical, JRSUIControlSetAlignmentVertical); 346 IF_CHANGED_SET_USING(AlignmentHorizontal, JRSUIControlSetAlignmentHorizontal); 347 IF_CHANGED_SET_USING(SegmentPosition, JRSUIControlSetSegmentPosition); 348 IF_CHANGED_SET_USING(ScrollBarPart, JRSUIControlSetScrollBarPart); 349 IF_CHANGED_SET_USING(Variant, JRSUIControlSetVariant); 350 IF_CHANGED_SET_USING(WindowType, JRSUIControlSetWindowType); 351 IF_CHANGED_SET_USING(ShowArrows, JRSUIControlSetShowArrows); 352 353 IF_CHANGED_SET_KEYED_BOOLEAN(Focused, focusedKey, get_boolean_value_for); 354 IF_CHANGED_SET_KEYED_BOOLEAN(IndicatorOnly, indicatorOnlyKey, get_boolean_value_for); 355 IF_CHANGED_SET_KEYED_BOOLEAN(NoIndicator, noIndicatorKey, get_boolean_value_for); 356 IF_CHANGED_SET_KEYED_BOOLEAN(ArrowsOnly, arrowsOnlyKey, get_boolean_value_for); 357 IF_CHANGED_SET_KEYED_BOOLEAN(FrameOnly, frameOnlyKey, get_boolean_value_for); 358 IF_CHANGED_SET_KEYED_BOOLEAN(SegmentTrailingSeparator, segmentTrailingSeparatorKey, get_boolean_value_for); 359 IF_KEY_EXISTS_DO(segmentLeadingSeparatorKey, IF_CHANGED_SET_KEYED_BOOLEAN(SegmentLeadingSeparator, segmentLeadingSeparatorKey, get_boolean_value_for)); 360 IF_CHANGED_SET_KEYED_BOOLEAN(NothingToScroll, nothingToScrollKey, get_boolean_value_for); 361 IF_CHANGED_SET_KEYED_BOOLEAN(WindowTitleBarSeparator, windowFrameDrawTitleSeparatorKey, get_boolean_value_for); 362 IF_CHANGED_SET_KEYED_BOOLEAN(WindowClipCorners, windowFrameDrawClippedKey, get_boolean_value_for); 363 IF_CHANGED_SET_KEYED_BOOLEAN(BooleanValue, valueKey, get_boolean_number_value_for); 364 365 { // animation is special: keep setting while true 366 jlong value = (newProperties & MASK(Animating)); 367 Boolean animating = value != 0L; 368 Boolean changed = ((oldProperties & MASK(Animating)) - value) != 0L; 369 if (animating || changed) { 370 JRSUIControlSetAnimating(control, animating); 371 } 372 } 373 374 return 0; 375 } 376 377 378 /* 379 * Class: apple_laf_JRSUIConstants 380 * Method: getPtrForConstant 381 * Signature: (I)J 382 */ 383 JNIEXPORT jlong JNICALL Java_apple_laf_JRSUIConstants_getPtrForConstant 384 (JNIEnv *env, jclass clazz, jint constant){ 385 return ptr_to_jlong(JRSUIGetKey(constant)); 386 }