Path: blob/master/src/java.desktop/macosx/native/libosxui/JRSUIConstantSync.m
41149 views
/*1* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#import "JNIUtilities.h"26#import <JavaRuntimeSupport/JavaRuntimeSupport.h>2728#import "apple_laf_JRSUIConstants.h"29#import "apple_laf_JRSUIConstants_Key.h"30#import "apple_laf_JRSUIConstants_AlignmentVertical.h"31#import "apple_laf_JRSUIConstants_AlignmentHorizontal.h"32#import "apple_laf_JRSUIConstants_Animating.h"33#import "apple_laf_JRSUIConstants_ArrowsOnly.h"34#import "apple_laf_JRSUIConstants_BooleanValue.h"35#import "apple_laf_JRSUIConstants_Direction.h"36#import "apple_laf_JRSUIConstants_Focused.h"37#import "apple_laf_JRSUIConstants_FrameOnly.h"38#import "apple_laf_JRSUIConstants_IndicatorOnly.h"39#import "apple_laf_JRSUIConstants_NoIndicator.h"40#import "apple_laf_JRSUIConstants_NothingToScroll.h"41#import "apple_laf_JRSUIConstants_Orientation.h"42#import "apple_laf_JRSUIConstants_ScrollBarPart.h"43#import "apple_laf_JRSUIConstants_SegmentPosition.h"44#import "apple_laf_JRSUIConstants_SegmentTrailingSeparator.h"45#import "apple_laf_JRSUIConstants_SegmentLeadingSeparator.h"46#import "apple_laf_JRSUIConstants_ShowArrows.h"47#import "apple_laf_JRSUIConstants_Size.h"48#import "apple_laf_JRSUIConstants_State.h"49#import "apple_laf_JRSUIConstants_Variant.h"50#import "apple_laf_JRSUIConstants_Widget.h"51#import "apple_laf_JRSUIConstants_WindowType.h"52#import "apple_laf_JRSUIConstants_WindowTitleBarSeparator.h"53#import "apple_laf_JRSUIConstants_WindowClipCorners.h"5455#import "JRSUIConstantSync.h"565758static CFTypeRef widgetKey = NULL;59static CFTypeRef stateKey = NULL;60static CFTypeRef sizeKey = NULL;61static CFTypeRef directionKey = NULL;62static CFTypeRef orientationKey = NULL;63static CFTypeRef verticalAlignmentKey = NULL;64static CFTypeRef horizontalAlignmentKey = NULL;65static CFTypeRef positionKey = NULL;66static CFTypeRef pressedPartKey = NULL;67static CFTypeRef variantKey = NULL;68static CFTypeRef windowTypeKey = NULL;69static CFTypeRef focusedKey = NULL;70static CFTypeRef indicatorOnlyKey = NULL;71static CFTypeRef noIndicatorKey = NULL;72static CFTypeRef nothingToScrollKey = NULL;73static CFTypeRef arrowsOnlyKey = NULL;74static CFTypeRef frameOnlyKey = NULL;75static CFTypeRef segmentTrailingSeparatorKey = NULL;76static CFTypeRef segmentLeadingSeparatorKey = NULL;77static CFTypeRef windowFrameDrawClippedKey = NULL;78static CFTypeRef windowFrameDrawTitleSeparatorKey = NULL;79static CFTypeRef maximumValueKey = NULL;80static CFTypeRef valueKey = NULL;81static CFTypeRef animationStartTimeKey = NULL;82static CFTypeRef animationTimeKey = NULL;838485#define JRS_CONSTANT(clazz, constant) \86kJRSUI_ ## clazz ## _ ## constant8788#define JNI_CONSTANT(clazz, constant) \89apple_laf_JRSUIConstants_ ## clazz ## __ ## constant9091#define CONSTANT_CHECK(clazz, constant) \92( JRS_CONSTANT(clazz, constant) == JNI_CONSTANT(clazz, constant) )9394#define CONSISTENCY_CHECK(clazz, constant) \95if ( !CONSTANT_CHECK(clazz, constant) ) return NO;9697#define ASSIGN_KEY(key) \98key ## Key = JRSUIGetKey(JRS_CONSTANT(Key, key)); \99if (key ## Key == NULL) return NO;100101#define ASSIGN_KEY_IF_EXISTS(key, constant) \102key ## Key = JRSUIGetKey(constant);103104static BOOL init_and_check_constant_coherency() {105ASSIGN_KEY(widget);106ASSIGN_KEY(state);107ASSIGN_KEY(size);108ASSIGN_KEY(direction);109ASSIGN_KEY(orientation);110ASSIGN_KEY(verticalAlignment);111ASSIGN_KEY(horizontalAlignment);112ASSIGN_KEY(position);113ASSIGN_KEY(pressedPart);114ASSIGN_KEY(variant);115ASSIGN_KEY(windowType);116ASSIGN_KEY(focused);117ASSIGN_KEY(indicatorOnly);118ASSIGN_KEY(noIndicator);119ASSIGN_KEY(nothingToScroll);120ASSIGN_KEY(arrowsOnly);121ASSIGN_KEY(frameOnly);122ASSIGN_KEY(segmentTrailingSeparator);123ASSIGN_KEY_IF_EXISTS(segmentLeadingSeparator, 29); // kJRSUI_Key_segmentLeadingSeparator = 29124ASSIGN_KEY(windowFrameDrawClipped);125ASSIGN_KEY(windowFrameDrawTitleSeparator);126ASSIGN_KEY(maximumValue);127ASSIGN_KEY(value);128ASSIGN_KEY(animationStartTime);129ASSIGN_KEY(animationTime);130131CONSISTENCY_CHECK(Key, value);132CONSISTENCY_CHECK(Key, thumbProportion);133CONSISTENCY_CHECK(Key, thumbStart);134CONSISTENCY_CHECK(Key, animationFrame);135CONSISTENCY_CHECK(Key, windowTitleBarHeight);136137CONSISTENCY_CHECK(Widget, background);138CONSISTENCY_CHECK(Widget, buttonBevel);139CONSISTENCY_CHECK(Widget, buttonBevelInset);140CONSISTENCY_CHECK(Widget, buttonBevelRound);141CONSISTENCY_CHECK(Widget, buttonCheckBox);142CONSISTENCY_CHECK(Widget, buttonComboBox);143CONSISTENCY_CHECK(Widget, buttonComboBoxInset);144CONSISTENCY_CHECK(Widget, buttonDisclosure);145CONSISTENCY_CHECK(Widget, buttonListHeader);146CONSISTENCY_CHECK(Widget, buttonLittleArrows);147CONSISTENCY_CHECK(Widget, buttonPopDown);148CONSISTENCY_CHECK(Widget, buttonPopDownInset);149CONSISTENCY_CHECK(Widget, buttonPopDownSquare);150CONSISTENCY_CHECK(Widget, buttonPopUp);151CONSISTENCY_CHECK(Widget, buttonPopUpInset);152CONSISTENCY_CHECK(Widget, buttonPopUpSquare);153CONSISTENCY_CHECK(Widget, buttonPush);154CONSISTENCY_CHECK(Widget, buttonPushScope);155CONSISTENCY_CHECK(Widget, buttonPushScope2);156CONSISTENCY_CHECK(Widget, buttonPushTextured);157CONSISTENCY_CHECK(Widget, buttonPushInset);158CONSISTENCY_CHECK(Widget, buttonPushInset2);159CONSISTENCY_CHECK(Widget, buttonRadio);160CONSISTENCY_CHECK(Widget, buttonRound);161CONSISTENCY_CHECK(Widget, buttonRoundHelp);162CONSISTENCY_CHECK(Widget, buttonRoundInset);163CONSISTENCY_CHECK(Widget, buttonRoundInset2);164CONSISTENCY_CHECK(Widget, buttonSearchFieldCancel);165CONSISTENCY_CHECK(Widget, buttonSearchFieldFind);166CONSISTENCY_CHECK(Widget, buttonSegmented);167CONSISTENCY_CHECK(Widget, buttonSegmentedInset);168CONSISTENCY_CHECK(Widget, buttonSegmentedInset2);169CONSISTENCY_CHECK(Widget, buttonSegmentedSCurve);170CONSISTENCY_CHECK(Widget, buttonSegmentedTextured);171CONSISTENCY_CHECK(Widget, buttonSegmentedToolbar);172CONSISTENCY_CHECK(Widget, dial);173CONSISTENCY_CHECK(Widget, disclosureTriangle);174CONSISTENCY_CHECK(Widget, dividerGrabber);175CONSISTENCY_CHECK(Widget, dividerSeparatorBar);176CONSISTENCY_CHECK(Widget, dividerSplitter);177CONSISTENCY_CHECK(Widget, focus);178CONSISTENCY_CHECK(Widget, frameGroupBox);179CONSISTENCY_CHECK(Widget, frameGroupBoxSecondary);180CONSISTENCY_CHECK(Widget, frameListBox);181CONSISTENCY_CHECK(Widget, framePlacard);182CONSISTENCY_CHECK(Widget, frameTextField);183CONSISTENCY_CHECK(Widget, frameTextFieldRound);184CONSISTENCY_CHECK(Widget, frameWell);185CONSISTENCY_CHECK(Widget, growBox);186CONSISTENCY_CHECK(Widget, growBoxTextured);187CONSISTENCY_CHECK(Widget, gradient);188CONSISTENCY_CHECK(Widget, menu);189CONSISTENCY_CHECK(Widget, menuItem);190CONSISTENCY_CHECK(Widget, menuBar);191CONSISTENCY_CHECK(Widget, menuTitle);192CONSISTENCY_CHECK(Widget, progressBar);193CONSISTENCY_CHECK(Widget, progressIndeterminateBar);194CONSISTENCY_CHECK(Widget, progressRelevance);195CONSISTENCY_CHECK(Widget, progressSpinner);196CONSISTENCY_CHECK(Widget, scrollBar);197CONSISTENCY_CHECK(Widget, scrollColumnSizer);198CONSISTENCY_CHECK(Widget, slider);199CONSISTENCY_CHECK(Widget, sliderThumb);200CONSISTENCY_CHECK(Widget, synchronization);201CONSISTENCY_CHECK(Widget, tab);202CONSISTENCY_CHECK(Widget, titleBarCloseBox);203CONSISTENCY_CHECK(Widget, titleBarCollapseBox);204CONSISTENCY_CHECK(Widget, titleBarZoomBox);205CONSISTENCY_CHECK(Widget, titleBarToolbarButton);206CONSISTENCY_CHECK(Widget, toolbarItemWell);207CONSISTENCY_CHECK(Widget, windowFrame);208209CONSISTENCY_CHECK(State, active);210CONSISTENCY_CHECK(State, inactive);211CONSISTENCY_CHECK(State, disabled);212CONSISTENCY_CHECK(State, pressed);213CONSISTENCY_CHECK(State, pulsed);214CONSISTENCY_CHECK(State, rollover);215CONSISTENCY_CHECK(State, drag);216217CONSISTENCY_CHECK(Size, mini);218CONSISTENCY_CHECK(Size, small);219CONSISTENCY_CHECK(Size, regular);220CONSISTENCY_CHECK(Size, large);221222CONSISTENCY_CHECK(Direction, none);223CONSISTENCY_CHECK(Direction, up);224CONSISTENCY_CHECK(Direction, down);225CONSISTENCY_CHECK(Direction, left);226CONSISTENCY_CHECK(Direction, right);227CONSISTENCY_CHECK(Direction, north);228CONSISTENCY_CHECK(Direction, south);229CONSISTENCY_CHECK(Direction, east);230CONSISTENCY_CHECK(Direction, west);231232CONSISTENCY_CHECK(Orientation, horizontal);233CONSISTENCY_CHECK(Orientation, vertical);234235CONSISTENCY_CHECK(AlignmentHorizontal, left);236CONSISTENCY_CHECK(AlignmentHorizontal, center);237CONSISTENCY_CHECK(AlignmentHorizontal, right);238239CONSISTENCY_CHECK(AlignmentVertical, top);240CONSISTENCY_CHECK(AlignmentVertical, center);241CONSISTENCY_CHECK(AlignmentVertical, bottom);242243CONSISTENCY_CHECK(SegmentPosition, first);244CONSISTENCY_CHECK(SegmentPosition, middle);245CONSISTENCY_CHECK(SegmentPosition, last);246CONSISTENCY_CHECK(SegmentPosition, only);247248CONSISTENCY_CHECK(ScrollBarPart, none);249CONSISTENCY_CHECK(ScrollBarPart, thumb);250CONSISTENCY_CHECK(ScrollBarPart, arrowMin);251CONSISTENCY_CHECK(ScrollBarPart, arrowMax);252CONSISTENCY_CHECK(ScrollBarPart, arrowMaxInside);253CONSISTENCY_CHECK(ScrollBarPart, arrowMinInside);254CONSISTENCY_CHECK(ScrollBarPart, trackMin);255CONSISTENCY_CHECK(ScrollBarPart, trackMax);256257CONSISTENCY_CHECK(Variant, menuGlyph);258CONSISTENCY_CHECK(Variant, menuPopup);259CONSISTENCY_CHECK(Variant, menuPulldown);260CONSISTENCY_CHECK(Variant, menuHierarchical);261CONSISTENCY_CHECK(Variant, gradientListBackgroundEven);262CONSISTENCY_CHECK(Variant, gradientListBackgroundOdd);263CONSISTENCY_CHECK(Variant, gradientSideBar);264CONSISTENCY_CHECK(Variant, gradientSideBarSelection);265CONSISTENCY_CHECK(Variant, gradientSideBarFocusedSelection);266267CONSISTENCY_CHECK(WindowType, document);268CONSISTENCY_CHECK(WindowType, utility);269CONSISTENCY_CHECK(WindowType, titlelessUtility);270271return YES;272}273274static CFBooleanRef get_boolean_value_for(jbyte value) {275return (value != 0) ? kCFBooleanTrue : kCFBooleanFalse;276}277278static CFNumberRef get_boolean_number_value_for(jbyte value) {279static CFNumberRef zero = NULL;280static CFNumberRef one = NULL;281282if (!zero) {283double zeroVal = 0.0;284zero = CFNumberCreate(NULL, kCFNumberDoubleType, &zeroVal);285double oneVal = 1.0;286one = CFNumberCreate(NULL, kCFNumberDoubleType, &oneVal);287}288289return (value != 0) ? one : zero;290}291292BOOL _InitializeJRSProperties() {293static BOOL initialized = NO;294static BOOL coherent = NO;295296if (!initialized) {297coherent = init_and_check_constant_coherency();298initialized = YES;299}300301return coherent;302}303304#define MASK(property) \305apple_laf_JRSUIConstants_ ## property ## _MASK306307#define SHIFT(property) \308apple_laf_JRSUIConstants_ ## property ## _SHIFT309310#define IF_CHANGED_SET_USING(property, setter) \311{ \312jlong value = (newProperties & MASK(property)); \313if ((value - (oldProperties & MASK(property))) != 0L) { \314setter(control, value >> SHIFT(property)); \315} \316}317318#define IF_CHANGED_SET_KEYED_BOOLEAN(property, key, getter) \319{ \320jlong value = (newProperties & MASK(property)); \321if ((value - (oldProperties & MASK(property))) != 0L) { \322CFTypeRef cfValue = getter(value >> SHIFT(property)); \323if (cfValue) { \324JRSUIControlSetValueByKey(control, key, cfValue); \325} \326} \327}328329#define IF_KEY_EXISTS_DO(key, operation) \330{ \331if (key != NULL) { \332operation; \333} \334}335336jint _SyncEncodedProperties(JRSUIControlRef control, jlong oldProperties, jlong newProperties) {337if (!_InitializeJRSProperties()) abort();338339IF_CHANGED_SET_USING(Widget, JRSUIControlSetWidget);340IF_CHANGED_SET_USING(State, JRSUIControlSetState);341IF_CHANGED_SET_USING(Size, JRSUIControlSetSize);342IF_CHANGED_SET_USING(Direction, JRSUIControlSetDirection);343IF_CHANGED_SET_USING(Orientation, JRSUIControlSetOrientation);344IF_CHANGED_SET_USING(AlignmentVertical, JRSUIControlSetAlignmentVertical);345IF_CHANGED_SET_USING(AlignmentHorizontal, JRSUIControlSetAlignmentHorizontal);346IF_CHANGED_SET_USING(SegmentPosition, JRSUIControlSetSegmentPosition);347IF_CHANGED_SET_USING(ScrollBarPart, JRSUIControlSetScrollBarPart);348IF_CHANGED_SET_USING(Variant, JRSUIControlSetVariant);349IF_CHANGED_SET_USING(WindowType, JRSUIControlSetWindowType);350IF_CHANGED_SET_USING(ShowArrows, JRSUIControlSetShowArrows);351352IF_CHANGED_SET_KEYED_BOOLEAN(Focused, focusedKey, get_boolean_value_for);353IF_CHANGED_SET_KEYED_BOOLEAN(IndicatorOnly, indicatorOnlyKey, get_boolean_value_for);354IF_CHANGED_SET_KEYED_BOOLEAN(NoIndicator, noIndicatorKey, get_boolean_value_for);355IF_CHANGED_SET_KEYED_BOOLEAN(ArrowsOnly, arrowsOnlyKey, get_boolean_value_for);356IF_CHANGED_SET_KEYED_BOOLEAN(FrameOnly, frameOnlyKey, get_boolean_value_for);357IF_CHANGED_SET_KEYED_BOOLEAN(SegmentTrailingSeparator, segmentTrailingSeparatorKey, get_boolean_value_for);358IF_KEY_EXISTS_DO(segmentLeadingSeparatorKey, IF_CHANGED_SET_KEYED_BOOLEAN(SegmentLeadingSeparator, segmentLeadingSeparatorKey, get_boolean_value_for));359IF_CHANGED_SET_KEYED_BOOLEAN(NothingToScroll, nothingToScrollKey, get_boolean_value_for);360IF_CHANGED_SET_KEYED_BOOLEAN(WindowTitleBarSeparator, windowFrameDrawTitleSeparatorKey, get_boolean_value_for);361IF_CHANGED_SET_KEYED_BOOLEAN(WindowClipCorners, windowFrameDrawClippedKey, get_boolean_value_for);362IF_CHANGED_SET_KEYED_BOOLEAN(BooleanValue, valueKey, get_boolean_number_value_for);363364{ // animation is special: keep setting while true365jlong value = (newProperties & MASK(Animating));366Boolean animating = value != 0L;367Boolean changed = ((oldProperties & MASK(Animating)) - value) != 0L;368if (animating || changed) {369JRSUIControlSetAnimating(control, animating);370}371}372373return 0;374}375376377/*378* Class: apple_laf_JRSUIConstants379* Method: getPtrForConstant380* Signature: (I)J381*/382JNIEXPORT jlong JNICALL Java_apple_laf_JRSUIConstants_getPtrForConstant383(JNIEnv *env, jclass clazz, jint constant){384return ptr_to_jlong(JRSUIGetKey(constant));385}386387388