From 1f87ad2d0005d361f19f17e353bb2baa377ef0cd Mon Sep 17 00:00:00 2001 From: Elsa Zacharia Date: Tue, 12 Dec 2023 16:52:43 +0530 Subject: [PATCH] Code cleanup : modernize switch expressions --- .../eclipse/swt/accessibility/Accessible.java | 37 +- .../org/eclipse/swt/widgets/Display.java | 1475 ++++++++--------- .../org/eclipse/swt/widgets/Tracker.java | 40 +- .../org/eclipse/swt/graphics/ImageData.java | 12 +- .../common/org/eclipse/swt/graphics/RGB.java | 68 +- .../org/eclipse/swt/internal/Callback.java | 17 +- .../org/eclipse/swt/internal/DPIUtil.java | 14 +- .../swt/internal/image/JPEGDecoder.java | 100 +- .../eclipse/swt/internal/image/PngChunk.java | 22 +- .../swt/internal/image/PngEncoder.java | 20 +- .../swt/internal/image/PngIhdrChunk.java | 110 +- .../swt/internal/image/PngTrnsChunk.java | 27 +- .../org/eclipse/swt/layout/BorderData.java | 38 +- .../org/eclipse/swt/layout/GridData.java | 44 +- 14 files changed, 887 insertions(+), 1137 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT Accessibility/cocoa/org/eclipse/swt/accessibility/Accessible.java b/bundles/org.eclipse.swt/Eclipse SWT Accessibility/cocoa/org/eclipse/swt/accessibility/Accessible.java index 3cbe48c95ef..3d6b772c27b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Accessibility/cocoa/org/eclipse/swt/accessibility/Accessible.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Accessibility/cocoa/org/eclipse/swt/accessibility/Accessible.java @@ -1671,20 +1671,15 @@ id getAttributedStringForRangeParameterizedAttribute(id parameter, int childID) int style = ts.underlineStyle; NSString attribute = OS.NSAccessibilityUnderlineTextAttribute; NSNumber styleObj = null; - switch (style) { - case SWT.UNDERLINE_SINGLE: - styleObj = NSNumber.numberWithInt(OS.kAXUnderlineStyleSingle); - break; - case SWT.UNDERLINE_DOUBLE: - styleObj = NSNumber.numberWithInt(OS.kAXUnderlineStyleDouble); - break; - case SWT.UNDERLINE_SQUIGGLE: + styleObj = switch (style) { + case SWT.UNDERLINE_SINGLE -> NSNumber.numberWithInt(OS.kAXUnderlineStyleSingle); + case SWT.UNDERLINE_DOUBLE -> NSNumber.numberWithInt(OS.kAXUnderlineStyleDouble); + case SWT.UNDERLINE_SQUIGGLE -> { attribute = OS.NSAccessibilityMisspelledTextAttribute; - styleObj = NSNumber.numberWithBool(true); - break; - default: - styleObj = NSNumber.numberWithInt(OS.kAXUnderlineStyleNone); + yield NSNumber.numberWithBool(true); } + default -> NSNumber.numberWithInt(OS.kAXUnderlineStyleNone); + }; attribString.addAttribute(attribute, styleObj, attributeRange); } @@ -1722,18 +1717,12 @@ id getAttributedStringForRangeParameterizedAttribute(id parameter, int childID) NSMutableDictionary paragraphDict = NSMutableDictionary.dictionaryWithCapacity(3); int osAlignment = 0; // FIXME: Doesn't account for right-to-left text? - switch (docAttributes.alignment) { - case SWT.CENTER: - osAlignment = OS.NSTextAlignmentCenter; - break; - case SWT.RIGHT: - osAlignment = OS.NSTextAlignmentRight; - break; - case SWT.LEFT: - default: - osAlignment = OS.NSTextAlignmentLeft; - break; - } + osAlignment = switch (docAttributes.alignment) { + case SWT.CENTER -> OS.NSTextAlignmentCenter; + case SWT.RIGHT -> OS.NSTextAlignmentRight; + case SWT.LEFT -> OS.NSTextAlignmentLeft; + default -> OS.NSTextAlignmentLeft; + }; paragraphDict.setValue(NSNumber.numberWithInt(osAlignment), NSString.stringWith("AXTextAlignment")); range.location = 0; attribString.addAttribute(NSString.stringWith("AXParagraphStyle"), paragraphDict, range); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java index 5b04b5e5ecc..d96384faacf 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java @@ -3578,26 +3578,24 @@ public boolean post(Event event) { mouseCursorPosition.y = (int) (primaryFrame.height - nsCursorPosition.y); int eventType = 0; // SWT buttons are 1-based: 1,2,3,4,5; CG buttons are 0 based: 0,2,1,3,4 - int cgButton; - switch (event.button) { - case 1: + int cgButton = switch (event.button) { + case 1 -> { eventType = (event.type == SWT.MouseDown ? OS.kCGEventLeftMouseDown : OS.kCGEventLeftMouseUp); - cgButton = 0; - break; - case 2: + yield 0; + } + case 2 -> { eventType = (event.type == SWT.MouseDown ? OS.kCGEventOtherMouseDown : OS.kCGEventOtherMouseUp); - cgButton = 2; - break; - case 3: + yield 2; + } + case 3 -> { eventType = (event.type == SWT.MouseDown ? OS.kCGEventRightMouseDown : OS.kCGEventRightMouseUp); - cgButton = 1; - break; - default: + yield 1; + } + default -> { eventType = (event.type == SWT.MouseDown ? OS.kCGEventOtherMouseDown : OS.kCGEventOtherMouseUp); - cgButton = event.button - 1; - break; + yield event.button - 1; } - + }; if (cgButton >= 0) { eventRef = OS.CGEventCreateMouseEvent(eventSource, eventType, mouseCursorPosition, cgButton); } @@ -6077,147 +6075,100 @@ static long windowProc(long id, long sel) { Widget widget = LookupWidget(id, sel); if (widget == null) return 0; - switch (Selector.valueOf(sel)) { - case sel_sendSelection: { - widget.sendSelection(); - return 0; - } - case sel_dealloc: { - widget.dealloc(id, sel); - return 0; - } - case sel_sendDoubleSelection: { - widget.sendDoubleSelection(); - return 0; - } - case sel_sendVerticalSelection: { - widget.sendVerticalSelection(); - return 0; - } - case sel_sendHorizontalSelection: { - widget.sendHorizontalSelection(); - return 0; - } - case sel_sendSearchSelection: { - widget.sendSearchSelection(); - return 0; - } - case sel_sendCancelSelection: { - widget.sendCancelSelection(); - return 0; - } - case sel_acceptsFirstResponder: { - return widget.acceptsFirstResponder(id, sel) ? 1 : 0; - } - case sel_becomeFirstResponder: { - return widget.becomeFirstResponder(id, sel) ? 1 : 0; - } - case sel_resignFirstResponder: { - return widget.resignFirstResponder(id, sel) ? 1 : 0; - } - case sel_isOpaque: { - return widget.isOpaque(id, sel) ? 1 : 0; - } - case sel_isFlipped: { - return widget.isFlipped(id, sel) ? 1 : 0; - } - case sel_canBecomeKeyView: { - return widget.canBecomeKeyView(id,sel) ? 1 : 0; - } - case sel_needsPanelToBecomeKey: { - return widget.needsPanelToBecomeKey(id,sel) ? 1 : 0; - } - case sel_becomeKeyWindow: { - widget.becomeKeyWindow(id, sel); - return 0; - } - case sel_unmarkText: { - //TODO not called? - return 0; - } - case sel_validAttributesForMarkedText: { - return widget.validAttributesForMarkedText (id, sel); - } - case sel_markedRange: { - NSRange range = widget.markedRange (id, sel); - /* NOTE that this is freed in C */ - long result = C.malloc (NSRange.sizeof); - OS.memmove (result, range, NSRange.sizeof); - return result; - } - case sel_selectedRange: { - NSRange range = widget.selectedRange (id, sel); - /* NOTE that this is freed in C */ - long result = C.malloc (NSRange.sizeof); - OS.memmove (result, range, NSRange.sizeof); - return result; - } - case sel_cellSize: { - NSSize size = widget.cellSize (id, sel); - /* NOTE that this is freed in C */ - long result = C.malloc (NSSize.sizeof); - OS.memmove (result, size, NSSize.sizeof); - return result; - } - case sel_hasMarkedText: { - return widget.hasMarkedText (id, sel) ? 1 : 0; - } - case sel_canBecomeKeyWindow: { - return widget.canBecomeKeyWindow (id, sel) ? 1 : 0; - } - case sel_accessibilityActionNames: { - return widget.accessibilityActionNames(id, sel); - } - case sel_accessibilityAttributeNames: { - return widget.accessibilityAttributeNames(id, sel); - } - case sel_accessibilityParameterizedAttributeNames: { - return widget.accessibilityParameterizedAttributeNames(id, sel); - } - case sel_getImageView: { - return widget.imageView(); - } - case sel_mouseDownCanMoveWindow: { - return (widget.mouseDownCanMoveWindow(id, sel) ? 1 : 0); - } - case sel_accessibilityFocusedUIElement: { - return widget.accessibilityFocusedUIElement(id, sel); - } - case sel_accessibilityIsIgnored: { - return (widget.accessibilityIsIgnored(id, sel) ? 1 : 0); - } - case sel_nextState: { - return widget.nextState(id, sel); - } - case sel_resetCursorRects: { - widget.resetCursorRects(id, sel); - return 0; - } - case sel_updateTrackingAreas: { - widget.updateTrackingAreas(id, sel); - return 0; - } - case sel_viewDidMoveToWindow: { - widget.viewDidMoveToWindow(id, sel); - return 0; - } - case sel_image: { - return widget.image(id, sel); - } - case sel_shouldDrawInsertionPoint: { - return widget.shouldDrawInsertionPoint(id, sel) ? 1 : 0; - } - case sel_accessibleHandle: { - return widget.accessibleHandle(); - } - case sel_clearDeferFlushing: { - widget.clearDeferFlushing(id, sel); - return 0; - } - default: { - return 0; - } - } + return switch (Selector.valueOf(sel)) { + case sel_sendSelection -> { + widget.sendSelection(); + yield 0; + } + case sel_dealloc -> { + widget.dealloc(id, sel); + yield 0; + } + case sel_sendDoubleSelection -> { + widget.sendDoubleSelection(); + yield 0; + } + case sel_sendVerticalSelection -> { + widget.sendVerticalSelection(); + yield 0; + } + case sel_sendHorizontalSelection -> { + widget.sendHorizontalSelection(); + yield 0; + } + case sel_sendSearchSelection -> { + widget.sendSearchSelection(); + yield 0; + } + case sel_sendCancelSelection -> { + widget.sendCancelSelection(); + yield 0; + } + case sel_acceptsFirstResponder -> widget.acceptsFirstResponder(id, sel) ? 1 : 0; + case sel_becomeFirstResponder -> widget.becomeFirstResponder(id, sel) ? 1 : 0; + case sel_resignFirstResponder -> widget.resignFirstResponder(id, sel) ? 1 : 0; + case sel_isOpaque -> widget.isOpaque(id, sel) ? 1 : 0; + case sel_isFlipped -> widget.isFlipped(id, sel) ? 1 : 0; + case sel_canBecomeKeyView -> widget.canBecomeKeyView(id,sel) ? 1 : 0; + case sel_needsPanelToBecomeKey -> widget.needsPanelToBecomeKey(id,sel) ? 1 : 0; + case sel_becomeKeyWindow -> { + widget.becomeKeyWindow(id, sel); + yield 0; + } + case sel_unmarkText -> /*TODO not called? */ 0; + case sel_validAttributesForMarkedText -> widget.validAttributesForMarkedText (id, sel); + case sel_markedRange -> { + NSRange range = widget.markedRange (id, sel); + /* NOTE that this is freed in C */ + long result = C.malloc (NSRange.sizeof); + OS.memmove (result, range, NSRange.sizeof); + yield result; + } + case sel_selectedRange -> { + NSRange range = widget.selectedRange (id, sel); + /* NOTE that this is freed in C */ + long result = C.malloc (NSRange.sizeof); + OS.memmove (result, range, NSRange.sizeof); + yield result; + } + case sel_cellSize -> { + NSSize size = widget.cellSize (id, sel); + /* NOTE that this is freed in C */ + long result = C.malloc (NSSize.sizeof); + OS.memmove (result, size, NSSize.sizeof); + yield result; + } + case sel_hasMarkedText -> widget.hasMarkedText (id, sel) ? 1 : 0; + case sel_canBecomeKeyWindow -> widget.canBecomeKeyWindow (id, sel) ? 1 : 0; + case sel_accessibilityActionNames -> widget.accessibilityActionNames(id, sel); + case sel_accessibilityAttributeNames -> widget.accessibilityAttributeNames(id, sel); + case sel_accessibilityParameterizedAttributeNames -> widget.accessibilityParameterizedAttributeNames(id, sel); + case sel_getImageView -> widget.imageView(); + case sel_mouseDownCanMoveWindow -> (widget.mouseDownCanMoveWindow(id, sel) ? 1 : 0); + case sel_accessibilityFocusedUIElement -> widget.accessibilityFocusedUIElement(id, sel); + case sel_accessibilityIsIgnored -> (widget.accessibilityIsIgnored(id, sel) ? 1 : 0); + case sel_nextState -> widget.nextState(id, sel); + case sel_resetCursorRects -> { + widget.resetCursorRects(id, sel); + yield 0; + } + case sel_updateTrackingAreas -> { + widget.updateTrackingAreas(id, sel); + yield 0; + } + case sel_viewDidMoveToWindow -> { + widget.viewDidMoveToWindow(id, sel); + yield 0; + } + case sel_image -> widget.image(id, sel); + case sel_shouldDrawInsertionPoint -> widget.shouldDrawInsertionPoint(id, sel) ? 1 : 0; + case sel_accessibleHandle -> widget.accessibleHandle(); + case sel_clearDeferFlushing -> { + widget.clearDeferFlushing(id, sel); + yield 0; + } + default -> 0; + }; } static long windowProc(long id, long sel, long arg0) { @@ -6276,674 +6227,590 @@ static long windowProc(long id, long sel, long arg0) { Widget widget = LookupWidget(id, sel); if (widget == null) return 0; - switch (Selector.valueOf(sel)) { - case sel_windowWillClose_: { - widget.windowWillClose(id, sel, arg0); - return 0; - } - case sel_drawRect_: { - NSRect rect = new NSRect(); - OS.memmove(rect, arg0, NSRect.sizeof); - widget.drawRect(id, sel, rect); - return 0; - } - case sel_columnAtPoint_: { - NSPoint point = new NSPoint(); - OS.memmove(point, arg0, NSPoint.sizeof); - return widget.columnAtPoint(id, sel, point); - } - case sel__drawThemeProgressArea_: { - widget._drawThemeProgressArea(id, sel, arg0); - return 0; - } - case sel_setFrameOrigin_: { - NSPoint point = new NSPoint(); - OS.memmove(point, arg0, NSPoint.sizeof); - widget.setFrameOrigin(id, sel, point); - return 0; - } - case sel_setFrameSize_: { - NSSize size = new NSSize(); - OS.memmove(size, arg0, NSSize.sizeof); - widget.setFrameSize(id, sel, size); - return 0; - } - case sel_hitTest_: { - NSPoint point = new NSPoint(); - OS.memmove(point, arg0, NSPoint.sizeof); - return widget.hitTest(id, sel, point); - } - case sel_windowShouldClose_: { - return widget.windowShouldClose(id, sel, arg0) ? 1 : 0; - } - case sel_mouseDown_: { - widget.mouseDown(id, sel, arg0); - return 0; - } - case sel_keyDown_: { - widget.keyDown(id, sel, arg0); - return 0; - } - case sel_keyUp_: { - widget.keyUp(id, sel, arg0); - return 0; - } - case sel_flagsChanged_: { - widget.flagsChanged(id, sel, arg0); - return 0; - } - case sel_mouseUp_: { - widget.mouseUp(id, sel, arg0); - return 0; - } - case sel_rightMouseDown_: { - widget.rightMouseDown(id, sel, arg0); - return 0; - } - case sel_rightMouseDragged_: { - widget.rightMouseDragged(id, sel, arg0); - return 0; - } - case sel_rightMouseUp_: { - widget.rightMouseUp(id, sel, arg0); - return 0; - } - case sel_otherMouseDown_: { - widget.otherMouseDown(id, sel, arg0); - return 0; - } - case sel_otherMouseUp_: { - widget.otherMouseUp(id, sel, arg0); - return 0; - } - case sel_otherMouseDragged_: { - widget.otherMouseDragged(id, sel, arg0); - return 0; - } - case sel_mouseMoved_: { - widget.mouseMoved(id, sel, arg0); - return 0; - } - case sel_mouseDragged_: { - widget.mouseDragged(id, sel, arg0); - return 0; - } - case sel_mouseEntered_: { - widget.mouseEntered(id, sel, arg0); - return 0; - } - case sel_mouseExited_: { - widget.mouseExited(id, sel, arg0); - return 0; - } - case sel_cursorUpdate_: { - widget.cursorUpdate(id, sel, arg0); - return 0; - } - case sel_menuForEvent_: { - return widget.menuForEvent(id, sel, arg0); - } - case sel_noResponderFor_: { - widget.noResponderFor(id, sel, arg0); - return 0; - } - case sel_shouldDelayWindowOrderingForEvent_: { - return widget.shouldDelayWindowOrderingForEvent(id, sel, arg0) ? 1 : 0; - } - case sel_acceptsFirstMouse_: { - return widget.acceptsFirstMouse(id, sel, arg0) ? 1 : 0; - } - case sel_numberOfRowsInTableView_: { - return widget.numberOfRowsInTableView(id, sel, arg0); - } - case sel_tableViewSelectionDidChange_: { - widget.tableViewSelectionDidChange(id, sel, arg0); - return 0; - } - case sel_tableViewSelectionIsChanging_: { - widget.tableViewSelectionIsChanging(id, sel, arg0); - return 0; - } - case sel_windowDidResignKey_: { - widget.windowDidResignKey(id, sel, arg0); - return 0; - } - case sel_windowDidBecomeKey_: { - widget.windowDidBecomeKey(id, sel, arg0); - return 0; - } - case sel_windowDidResize_: { - widget.windowDidResize(id, sel, arg0); - return 0; - } - case sel_windowDidMove_: { - widget.windowDidMove(id, sel, arg0); - return 0; - } - case sel_menuWillOpen_: { - widget.menuWillOpen(id, sel, arg0); - return 0; - } - case sel_menuDidClose_: { - widget.menuDidClose(id, sel, arg0); - return 0; - } - case sel_menuNeedsUpdate_: { - widget.menuNeedsUpdate(id, sel, arg0); - return 0; - } - case sel_outlineViewSelectionDidChange_: { - widget.outlineViewSelectionDidChange(id, sel, arg0); - return 0; - } - case sel_outlineViewSelectionIsChanging_: { - widget.outlineViewSelectionIsChanging(id, sel, arg0); - return 0; - } - case sel_sendEvent_: { - widget.windowSendEvent(id, sel, arg0); - return 0; - } - case sel_helpRequested_: { - widget.helpRequested(id, sel, arg0); - return 0; - } - case sel_scrollWheel_: { - widget.scrollWheel(id, sel, arg0); - return 0; - } - case sel_pageDown_: { - widget.pageDown(id, sel, arg0); - return 0; - } - case sel_pageUp_: { - widget.pageUp(id, sel, arg0); - return 0; - } - case sel_textViewDidChangeSelection_: { - widget.textViewDidChangeSelection(id, sel, arg0); - return 0; - } - case sel_textDidChange_: { - widget.textDidChange(id, sel, arg0); - return 0; - } - case sel_textDidEndEditing_: { - widget.textDidEndEditing(id, sel, arg0); - return 0; - } - case sel_attributedSubstringFromRange_: { - return widget.attributedSubstringFromRange(id, sel, arg0); - } - case sel_characterIndexForPoint_: { - return widget.characterIndexForPoint(id, sel, arg0); - } - case sel_firstRectForCharacterRange_: { - NSRect rect = widget.firstRectForCharacterRange(id, sel, arg0); - /* NOTE that this is freed in C */ - long /* int */ result = C.malloc(NSRect.sizeof); - OS.memmove(result, rect, NSRect.sizeof); - return result; - } - case sel_insertText_: { - return widget.insertText(id, sel, arg0) ? 1 : 0; - } - case sel_doCommandBySelector_: { - widget.doCommandBySelector(id, sel, arg0); - return 0; - } - case sel_highlightSelectionInClipRect_: { - widget.highlightSelectionInClipRect(id, sel, arg0); - return 0; - } - case sel_reflectScrolledClipView_: { - widget.reflectScrolledClipView(id, sel, arg0); - return 0; - } - case sel_accessibilityHitTest_: { - NSPoint point = new NSPoint(); - OS.memmove(point, arg0, NSPoint.sizeof); - return widget.accessibilityHitTest(id, sel, point); - } - case sel_accessibilityAttributeValue_: { - return widget.accessibilityAttributeValue(id, sel, arg0); - } - case sel_accessibilityPerformAction_: { - widget.accessibilityPerformAction(id, sel, arg0); - return 0; - } - case sel_accessibilityActionDescription_: { - return widget.accessibilityActionDescription(id, sel, arg0); - } - case sel_accessibilityIsAttributeSettable_: { - return widget.accessibilityIsAttributeSettable(id, sel, arg0) ? 1 : 0; - } - case sel_makeFirstResponder_: { - return widget.makeFirstResponder(id, sel, arg0) ? 1 : 0; - } - case sel_tableViewColumnDidMove_: { - widget.tableViewColumnDidMove(id, sel, arg0); - return 0; - } - case sel_tableViewColumnDidResize_: { - widget.tableViewColumnDidResize(id, sel, arg0); - return 0; - } - case sel_outlineViewColumnDidMove_: { - widget.outlineViewColumnDidMove(id, sel, arg0); - return 0; - } - case sel_outlineViewColumnDidResize_: { - widget.outlineViewColumnDidResize(id, sel, arg0); - return 0; - } - case sel_setNeedsDisplay_: { - widget.setNeedsDisplay(id, sel, arg0 != 0); - return 0; - } - case sel_setNeedsDisplayInRect_: { - widget.setNeedsDisplayInRect(id, sel, arg0); - return 0; - } - case sel_setImage_: { - widget.setImage(id, sel, arg0); - return 0; - } - case sel_headerRectOfColumn_: { - NSRect rect = widget.headerRectOfColumn(id, sel, arg0); - /* NOTE that this is freed in C */ - long /* int */ result = C.malloc(NSRect.sizeof); - OS.memmove(result, rect, NSRect.sizeof); - return result; - } - case sel_imageRectForBounds_: { - NSRect rect = new NSRect(); - OS.memmove(rect, arg0, NSRect.sizeof); - rect = widget.imageRectForBounds(id, sel, rect); - /* NOTE that this is freed in C */ - long /* int */ result = C.malloc(NSRect.sizeof); - OS.memmove(result, rect, NSRect.sizeof); - return result; - } - case sel_titleRectForBounds_: { - NSRect rect = new NSRect(); - OS.memmove(rect, arg0, NSRect.sizeof); - rect = widget.titleRectForBounds(id, sel, rect); - /* NOTE that this is freed in C */ - long /* int */ result = C.malloc(NSRect.sizeof); - OS.memmove(result, rect, NSRect.sizeof); - return result; - } - case sel_cellSizeForBounds_: { - NSRect rect = new NSRect(); - OS.memmove(rect, arg0, NSRect.sizeof); - NSSize size = widget.cellSizeForBounds(id, sel, rect); - /* NOTE that this is freed in C */ - long /* int */ result = C.malloc(NSSize.sizeof); - OS.memmove(result, size, NSSize.sizeof); - return result; - } - case sel_setObjectValue_: { - widget.setObjectValue(id, sel, arg0); - return 0; - } - case sel_updateOpenGLContext_: { - widget.updateOpenGLContext(id, sel, arg0); - return 0; - } - case sel_sizeOfLabel_: { - NSSize size = widget.sizeOfLabel(id, sel, arg0 != 0); - /* NOTE that this is freed in C */ - long /* int */ result = C.malloc(NSSize.sizeof); - OS.memmove(result, size, NSSize.sizeof); - return result; - } - case sel_comboBoxSelectionDidChange_: { - widget.comboBoxSelectionDidChange(id, sel, arg0); - return 0; - } - case sel_comboBoxWillDismiss_: { - widget.comboBoxWillDismiss(id, sel, arg0); - return 0; - } - case sel_comboBoxWillPopUp_: { - widget.comboBoxWillPopUp(id, sel, arg0); - return 0; - } - case sel_drawViewBackgroundInRect_: { - NSRect rect = new NSRect(); - OS.memmove(rect, arg0, NSRect.sizeof); - widget.drawViewBackgroundInRect(id, sel, rect); - return 0; - } - case sel_drawBackgroundInClipRect_: { - NSRect rect = new NSRect(); - OS.memmove(rect, arg0, NSRect.sizeof); - widget.drawBackgroundInClipRect(id, sel, rect); - return 0; - } - case sel_windowDidMiniaturize_: { - widget.windowDidMiniturize(id, sel, arg0); - return 0; - } - case sel_windowDidDeminiaturize_: { - widget.windowDidDeminiturize(id, sel, arg0); - return 0; - } - case sel_touchesBeganWithEvent_: { - widget.touchesBeganWithEvent(id, sel, arg0); - return 0; - } - case sel_touchesMovedWithEvent_: { - widget.touchesMovedWithEvent(id, sel, arg0); - return 0; - } - case sel_touchesEndedWithEvent_: { - widget.touchesEndedWithEvent(id, sel, arg0); - return 0; - } - case sel_touchesCancelledWithEvent_: { - widget.touchesCancelledWithEvent(id, sel, arg0); - return 0; - } - case sel_swipeWithEvent_: { - widget.swipeWithEvent(id, sel, arg0); - return 0; - } - case sel_magnifyWithEvent_: { - widget.magnifyWithEvent(id, sel, arg0); - return 0; - } - case sel_rotateWithEvent_: { - widget.rotateWithEvent(id, sel, arg0); - return 0; - } - case sel_toolbarAllowedItemIdentifiers_: { - return widget.toolbarAllowedItemIdentifiers(id, sel, arg0); - } - case sel_toolbarDefaultItemIdentifiers_: { - return widget.toolbarDefaultItemIdentifiers(id, sel, arg0); - } - case sel_toolbarSelectableItemIdentifiers_: { - return widget.toolbarSelectableItemIdentifiers(id, sel, arg0); - } - case sel_validateMenuItem_: { - return (widget.validateMenuItem(id, sel, arg0) ? 1 : 0); - } - case sel_readSelectionFromPasteboard_: { - return (widget.readSelectionFromPasteboard(id, sel, arg0) ? 1 : 0); - } - case sel_viewWillMoveToWindow_: { - widget.viewWillMoveToWindow(id, sel, arg0); - return 0; - } - case sel_cancelOperation_: { - widget.cancelOperation(id, sel, arg0); - return 0; - } - case sel_setShouldExpandItem_: { - widget.setShouldExpandItem(id, sel, arg0 != 0); - return 0; - } - case sel_setShouldScrollClipView_: { - widget.setShouldScrollClipView(id, sel, arg0 != 0); - return 0; - } - case sel_deselectRow_: { - widget.deselectRow(id, sel, arg0); - return 0; - } - case sel_deselectAll_: { - widget.deselectAll(id, sel, arg0); - return 0; - } - default: { - return 0; - } + return switch (Selector.valueOf(sel)) { + case sel_windowWillClose_ -> { + widget.windowWillClose(id, sel, arg0); + yield 0; } + case sel_drawRect_ -> { + NSRect rect = new NSRect(); + OS.memmove(rect, arg0, NSRect.sizeof); + widget.drawRect(id, sel, rect); + yield 0; + } + case sel_columnAtPoint_ -> { + NSPoint point = new NSPoint(); + OS.memmove(point, arg0, NSPoint.sizeof); + yield widget.columnAtPoint(id, sel, point); + } + case sel__drawThemeProgressArea_ -> { + widget._drawThemeProgressArea(id, sel, arg0); + yield 0; + } + case sel_setFrameOrigin_ -> { + NSPoint point = new NSPoint(); + OS.memmove(point, arg0, NSPoint.sizeof); + widget.setFrameOrigin(id, sel, point); + yield 0; + } + case sel_setFrameSize_ -> { + NSSize size = new NSSize(); + OS.memmove(size, arg0, NSSize.sizeof); + widget.setFrameSize(id, sel, size); + yield 0; + } + case sel_hitTest_ -> { + NSPoint point = new NSPoint(); + OS.memmove(point, arg0, NSPoint.sizeof); + yield widget.hitTest(id, sel, point); + } + case sel_windowShouldClose_ -> widget.windowShouldClose(id, sel, arg0) ? 1 : 0; + case sel_mouseDown_ -> { + widget.mouseDown(id, sel, arg0); + yield 0; + } + case sel_keyDown_ -> { + widget.keyDown(id, sel, arg0); + yield 0; + } + case sel_keyUp_ -> { + widget.keyUp(id, sel, arg0); + yield 0; + } + case sel_flagsChanged_ -> { + widget.flagsChanged(id, sel, arg0); + yield 0; + } + case sel_mouseUp_ -> { + widget.mouseUp(id, sel, arg0); + yield 0; + } + case sel_rightMouseDown_ -> { + widget.rightMouseDown(id, sel, arg0); + yield 0; + } + case sel_rightMouseDragged_ -> { + widget.rightMouseDragged(id, sel, arg0); + yield 0; + } + case sel_rightMouseUp_ -> { + widget.rightMouseUp(id, sel, arg0); + yield 0; + } + case sel_otherMouseDown_ -> { + widget.otherMouseDown(id, sel, arg0); + yield 0; + } + case sel_otherMouseUp_ -> { + widget.otherMouseUp(id, sel, arg0); + yield 0; + } + case sel_otherMouseDragged_ -> { + widget.otherMouseDragged(id, sel, arg0); + yield 0; + } + case sel_mouseMoved_ -> { + widget.mouseMoved(id, sel, arg0); + yield 0; + } + case sel_mouseDragged_ -> { + widget.mouseDragged(id, sel, arg0); + yield 0; + } + case sel_mouseEntered_ -> { + widget.mouseEntered(id, sel, arg0); + yield 0; + } + case sel_mouseExited_ -> { + widget.mouseExited(id, sel, arg0); + yield 0; + } + case sel_cursorUpdate_ -> { + widget.cursorUpdate(id, sel, arg0); + yield 0; + } + case sel_menuForEvent_ -> widget.menuForEvent(id, sel, arg0); + case sel_noResponderFor_ -> { + widget.noResponderFor(id, sel, arg0); + yield 0; + } + case sel_shouldDelayWindowOrderingForEvent_ -> widget.shouldDelayWindowOrderingForEvent(id, sel, arg0) ? 1 : 0; + case sel_acceptsFirstMouse_ -> widget.acceptsFirstMouse(id, sel, arg0) ? 1 : 0; + case sel_numberOfRowsInTableView_ -> widget.numberOfRowsInTableView(id, sel, arg0); + case sel_tableViewSelectionDidChange_ -> { + widget.tableViewSelectionDidChange(id, sel, arg0); + yield 0; + } + case sel_tableViewSelectionIsChanging_ -> { + widget.tableViewSelectionIsChanging(id, sel, arg0); + yield 0; + } + case sel_windowDidResignKey_ -> { + widget.windowDidResignKey(id, sel, arg0); + yield 0; + } + case sel_windowDidBecomeKey_ -> { + widget.windowDidBecomeKey(id, sel, arg0); + yield 0; + } + case sel_windowDidResize_ -> { + widget.windowDidResize(id, sel, arg0); + yield 0; + } + case sel_windowDidMove_ -> { + widget.windowDidMove(id, sel, arg0); + yield 0; + } + case sel_menuWillOpen_ -> { + widget.menuWillOpen(id, sel, arg0); + yield 0; + } + case sel_menuDidClose_ -> { + widget.menuDidClose(id, sel, arg0); + yield 0; + } + case sel_menuNeedsUpdate_ -> { + widget.menuNeedsUpdate(id, sel, arg0); + yield 0; + } + case sel_outlineViewSelectionDidChange_ -> { + widget.outlineViewSelectionDidChange(id, sel, arg0); + yield 0; + } + case sel_outlineViewSelectionIsChanging_ -> { + widget.outlineViewSelectionIsChanging(id, sel, arg0); + yield 0; + } + case sel_sendEvent_ -> { + widget.windowSendEvent(id, sel, arg0); + yield 0; + } + case sel_helpRequested_ -> { + widget.helpRequested(id, sel, arg0); + yield 0; + } + case sel_scrollWheel_ -> { + widget.scrollWheel(id, sel, arg0); + yield 0; + } + case sel_pageDown_ -> { + widget.pageDown(id, sel, arg0); + yield 0; + } + case sel_pageUp_ -> { + widget.pageUp(id, sel, arg0); + yield 0; + } + case sel_textViewDidChangeSelection_ -> { + widget.textViewDidChangeSelection(id, sel, arg0); + yield 0; + } + case sel_textDidChange_ -> { + widget.textDidChange(id, sel, arg0); + yield 0; + } + case sel_textDidEndEditing_ -> { + widget.textDidEndEditing(id, sel, arg0); + yield 0; + } + case sel_attributedSubstringFromRange_ -> widget.attributedSubstringFromRange(id, sel, arg0); + case sel_characterIndexForPoint_ -> widget.characterIndexForPoint(id, sel, arg0); + case sel_firstRectForCharacterRange_ -> { + NSRect rect = widget.firstRectForCharacterRange(id, sel, arg0); + /* NOTE that this is freed in C */ + long /* int */ result = C.malloc(NSRect.sizeof); + OS.memmove(result, rect, NSRect.sizeof); + yield result; + } + case sel_insertText_ -> widget.insertText(id, sel, arg0) ? 1 : 0; + case sel_doCommandBySelector_ -> { + widget.doCommandBySelector(id, sel, arg0); + yield 0; + } + case sel_highlightSelectionInClipRect_ -> { + widget.highlightSelectionInClipRect(id, sel, arg0); + yield 0; + } + case sel_reflectScrolledClipView_ -> { + widget.reflectScrolledClipView(id, sel, arg0); + yield 0; + } + case sel_accessibilityHitTest_ -> { + NSPoint point = new NSPoint(); + OS.memmove(point, arg0, NSPoint.sizeof); + yield widget.accessibilityHitTest(id, sel, point); + } + case sel_accessibilityAttributeValue_ -> widget.accessibilityAttributeValue(id, sel, arg0); + case sel_accessibilityPerformAction_ -> { + widget.accessibilityPerformAction(id, sel, arg0); + yield 0; + } + case sel_accessibilityActionDescription_ -> widget.accessibilityActionDescription(id, sel, arg0); + case sel_accessibilityIsAttributeSettable_ -> widget.accessibilityIsAttributeSettable(id, sel, arg0) ? 1 : 0; + case sel_makeFirstResponder_ -> widget.makeFirstResponder(id, sel, arg0) ? 1 : 0; + case sel_tableViewColumnDidMove_ -> { + widget.tableViewColumnDidMove(id, sel, arg0); + yield 0; + } + case sel_tableViewColumnDidResize_ -> { + widget.tableViewColumnDidResize(id, sel, arg0); + yield 0; + } + case sel_outlineViewColumnDidMove_ -> { + widget.outlineViewColumnDidMove(id, sel, arg0); + yield 0; + } + case sel_outlineViewColumnDidResize_ -> { + widget.outlineViewColumnDidResize(id, sel, arg0); + yield 0; + } + case sel_setNeedsDisplay_ -> { + widget.setNeedsDisplay(id, sel, arg0 != 0); + yield 0; + } + case sel_setNeedsDisplayInRect_ -> { + widget.setNeedsDisplayInRect(id, sel, arg0); + yield 0; + } + case sel_setImage_ -> { + widget.setImage(id, sel, arg0); + yield 0; + } + case sel_headerRectOfColumn_ -> { + NSRect rect = widget.headerRectOfColumn(id, sel, arg0); + /* NOTE that this is freed in C */ + long /* int */ result = C.malloc(NSRect.sizeof); + OS.memmove(result, rect, NSRect.sizeof); + yield result; + } + case sel_imageRectForBounds_ -> { + NSRect rect = new NSRect(); + OS.memmove(rect, arg0, NSRect.sizeof); + rect = widget.imageRectForBounds(id, sel, rect); + /* NOTE that this is freed in C */ + long /* int */ result = C.malloc(NSRect.sizeof); + OS.memmove(result, rect, NSRect.sizeof); + yield result; + } + case sel_titleRectForBounds_ -> { + NSRect rect = new NSRect(); + OS.memmove(rect, arg0, NSRect.sizeof); + rect = widget.titleRectForBounds(id, sel, rect); + /* NOTE that this is freed in C */ + long /* int */ result = C.malloc(NSRect.sizeof); + OS.memmove(result, rect, NSRect.sizeof); + yield result; + } + case sel_cellSizeForBounds_ -> { + NSRect rect = new NSRect(); + OS.memmove(rect, arg0, NSRect.sizeof); + NSSize size = widget.cellSizeForBounds(id, sel, rect); + /* NOTE that this is freed in C */ + long /* int */ result = C.malloc(NSSize.sizeof); + OS.memmove(result, size, NSSize.sizeof); + yield result; + } + case sel_setObjectValue_ -> { + widget.setObjectValue(id, sel, arg0); + yield 0; + } + case sel_updateOpenGLContext_ -> { + widget.updateOpenGLContext(id, sel, arg0); + yield 0; + } + case sel_sizeOfLabel_ -> { + NSSize size = widget.sizeOfLabel(id, sel, arg0 != 0); + /* NOTE that this is freed in C */ + long /* int */ result = C.malloc(NSSize.sizeof); + OS.memmove(result, size, NSSize.sizeof); + yield result; + } + case sel_comboBoxSelectionDidChange_ -> { + widget.comboBoxSelectionDidChange(id, sel, arg0); + yield 0; + } + case sel_comboBoxWillDismiss_ -> { + widget.comboBoxWillDismiss(id, sel, arg0); + yield 0; + } + case sel_comboBoxWillPopUp_ -> { + widget.comboBoxWillPopUp(id, sel, arg0); + yield 0; + } + case sel_drawViewBackgroundInRect_ -> { + NSRect rect = new NSRect(); + OS.memmove(rect, arg0, NSRect.sizeof); + widget.drawViewBackgroundInRect(id, sel, rect); + yield 0; + } + case sel_drawBackgroundInClipRect_ -> { + NSRect rect = new NSRect(); + OS.memmove(rect, arg0, NSRect.sizeof); + widget.drawBackgroundInClipRect(id, sel, rect); + yield 0; + } + case sel_windowDidMiniaturize_ -> { + widget.windowDidMiniturize(id, sel, arg0); + yield 0; + } + case sel_windowDidDeminiaturize_ -> { + widget.windowDidDeminiturize(id, sel, arg0); + yield 0; + } + case sel_touchesBeganWithEvent_ -> { + widget.touchesBeganWithEvent(id, sel, arg0); + yield 0; + } + case sel_touchesMovedWithEvent_ -> { + widget.touchesMovedWithEvent(id, sel, arg0); + yield 0; + } + case sel_touchesEndedWithEvent_ -> { + widget.touchesEndedWithEvent(id, sel, arg0); + yield 0; + } + case sel_touchesCancelledWithEvent_ -> { + widget.touchesCancelledWithEvent(id, sel, arg0); + yield 0; + } + case sel_swipeWithEvent_ -> { + widget.swipeWithEvent(id, sel, arg0); + yield 0; + } + case sel_magnifyWithEvent_ -> { + widget.magnifyWithEvent(id, sel, arg0); + yield 0; + } + case sel_rotateWithEvent_ -> { + widget.rotateWithEvent(id, sel, arg0); + yield 0; + } + case sel_toolbarAllowedItemIdentifiers_ -> widget.toolbarAllowedItemIdentifiers(id, sel, arg0); + case sel_toolbarDefaultItemIdentifiers_ -> widget.toolbarDefaultItemIdentifiers(id, sel, arg0); + case sel_toolbarSelectableItemIdentifiers_ -> widget.toolbarSelectableItemIdentifiers(id, sel, arg0); + case sel_validateMenuItem_ -> (widget.validateMenuItem(id, sel, arg0) ? 1 : 0); + case sel_readSelectionFromPasteboard_ -> (widget.readSelectionFromPasteboard(id, sel, arg0) ? 1 : 0); + case sel_viewWillMoveToWindow_ -> { + widget.viewWillMoveToWindow(id, sel, arg0); + yield 0; + } + case sel_cancelOperation_ -> { + widget.cancelOperation(id, sel, arg0); + yield 0; + } + case sel_setShouldExpandItem_ -> { + widget.setShouldExpandItem(id, sel, arg0 != 0); + yield 0; + } + case sel_setShouldScrollClipView_ -> { + widget.setShouldScrollClipView(id, sel, arg0 != 0); + yield 0; + } + case sel_deselectRow_ -> { + widget.deselectRow(id, sel, arg0); + yield 0; + } + case sel_deselectAll_ -> { + widget.deselectAll(id, sel, arg0); + yield 0; + } + default -> 0; + }; } static long windowProc(long id, long sel, long arg0, long arg1) { Widget widget = LookupWidget(id, sel); if (widget == null) return 0; - switch (Selector.valueOf(sel)) { - case sel_tabView_willSelectTabViewItem_: { - widget.tabView_willSelectTabViewItem(id, sel, arg0, arg1); - return 0; - } - case sel_tabView_didSelectTabViewItem_: { - widget.tabView_didSelectTabViewItem(id, sel, arg0, arg1); - return 0; - } - case sel_outlineView_isItemExpandable_: { - return widget.outlineView_isItemExpandable(id, sel, arg0, arg1) ? 1 : 0; - } - case sel_outlineView_numberOfChildrenOfItem_: { - return widget.outlineView_numberOfChildrenOfItem(id, sel, arg0, arg1); - } - case sel_menu_willHighlightItem_: { - widget.menu_willHighlightItem(id, sel, arg0, arg1); - return 0; - } - case sel_setMarkedText_selectedRange_: { - widget.setMarkedText_selectedRange (id, sel, arg0, arg1); - return 0; - } - case sel_cacheDisplayInRect_toBitmapImageRep_: { - NSRect rect = new NSRect (); - OS.memmove (rect, arg0, NSRect.sizeof); - widget.cacheDisplayInRect_toBitmapImageRep(id, sel, rect, arg1); - return 0; - } - case sel_drawInteriorWithFrame_inView_: { - NSRect rect = new NSRect (); - OS.memmove (rect, arg0, NSRect.sizeof); - widget.drawInteriorWithFrame_inView (id, sel, rect, arg1); - return 0; - } - case sel_drawWithExpansionFrame_inView_: { - NSRect rect = new NSRect(); - OS.memmove(rect, arg0, NSRect.sizeof); - widget.drawWithExpansionFrame_inView (id, sel, rect, arg1); - return 0; - } - case sel_drawBezelWithFrame_inView_: { - NSRect rect = new NSRect (); - OS.memmove (rect, arg0, NSRect.sizeof); - widget.drawBezelWithFrame_inView (id, sel, rect, arg1); - return 0; - } - case sel_accessibilityAttributeValue_forParameter_: { - return widget.accessibilityAttributeValue_forParameter(id, sel, arg0, arg1); - } - case sel_tableView_didClickTableColumn_: { - widget.tableView_didClickTableColumn (id, sel, arg0, arg1); - return 0; - } - case sel_outlineView_didClickTableColumn_: { - widget.outlineView_didClickTableColumn (id, sel, arg0, arg1); - return 0; - } - case sel_shouldChangeTextInRange_replacementString_: { - return widget.shouldChangeTextInRange_replacementString(id, sel, arg0, arg1) ? 1 : 0; - } - case sel_canDragRowsWithIndexes_atPoint_: { - NSPoint clickPoint = new NSPoint(); - OS.memmove(clickPoint, arg1, NSPoint.sizeof); - return widget.canDragRowsWithIndexes_atPoint(id, sel, arg0, clickPoint) ? 1 : 0; - } - case sel_expandItem_expandChildren_: { - widget.expandItem_expandChildren(id, sel, arg0, arg1 != 0); - return 0; - } - case sel_collapseItem_collapseChildren_: { - widget.collapseItem_collapseChildren(id, sel, arg0, arg1 != 0); - return 0; - } - case sel_expansionFrameWithFrame_inView_: { - NSRect rect = new NSRect(); - OS.memmove(rect, arg0, NSRect.sizeof); - rect = widget.expansionFrameWithFrame_inView(id, sel, rect, arg1); - /* NOTE that this is freed in C */ - long result = C.malloc (NSRect.sizeof); - OS.memmove (result, rect, NSRect.sizeof); - return result; - } - case sel_focusRingMaskBoundsForFrame_inView_: { - NSRect rect = new NSRect(); - OS.memmove(rect, arg0, NSRect.sizeof); - rect = widget.focusRingMaskBoundsForFrame(id, sel, rect, arg1); - /* NOTE that this is freed in C */ - long result = C.malloc (NSRect.sizeof); - OS.memmove (result, rect, NSRect.sizeof); - return result; - } - case sel_drawLabel_inRect_: { - NSRect rect = new NSRect(); - OS.memmove(rect, arg1, NSRect.sizeof); - widget.drawLabelInRect(id, sel, arg0==1, rect); - return 0; - } - case sel_scrollClipView_toPoint_: { - NSPoint point = new NSPoint(); - OS.memmove(point, arg1, NSPoint.sizeof); - widget.scrollClipViewToPoint (id, sel, arg0, point); - return 0; - } - case sel_accessibilitySetValue_forAttribute_: { - widget.accessibilitySetValue_forAttribute(id, sel, arg0, arg1); - return 0; - } - case sel_validRequestorForSendType_returnType_: { - return widget.validRequestorForSendType(id, sel, arg0, arg1); - } - case sel_writeSelectionToPasteboard_types_: { - return (widget.writeSelectionToPasteboard(id, sel, arg0, arg1) ? 1 : 0); - } - case sel_outlineView_shouldExpandItem_: { - return (widget.outlineView_shouldExpandItem_item(id, sel, arg0, arg1) ? 1 : 0); - } - case sel_selectRowIndexes_byExtendingSelection_: { - widget.selectRowIndexes_byExtendingSelection(id, sel, arg0, arg1 != 0); - return 0; - } - default: { - return 0; - } - } + return switch (Selector.valueOf(sel)) { + case sel_tabView_willSelectTabViewItem_ -> { + widget.tabView_willSelectTabViewItem(id, sel, arg0, arg1); + yield 0; + } + case sel_tabView_didSelectTabViewItem_ -> { + widget.tabView_didSelectTabViewItem(id, sel, arg0, arg1); + yield 0; + } + case sel_outlineView_isItemExpandable_ -> widget.outlineView_isItemExpandable(id, sel, arg0, arg1) ? 1 : 0; + case sel_outlineView_numberOfChildrenOfItem_ -> widget.outlineView_numberOfChildrenOfItem(id, sel, arg0, arg1); + case sel_menu_willHighlightItem_ -> { + widget.menu_willHighlightItem(id, sel, arg0, arg1); + yield 0; + } + case sel_setMarkedText_selectedRange_ -> { + widget.setMarkedText_selectedRange (id, sel, arg0, arg1); + yield 0; + } + case sel_cacheDisplayInRect_toBitmapImageRep_ -> { + NSRect rect = new NSRect (); + OS.memmove (rect, arg0, NSRect.sizeof); + widget.cacheDisplayInRect_toBitmapImageRep(id, sel, rect, arg1); + yield 0; + } + case sel_drawInteriorWithFrame_inView_ -> { + NSRect rect = new NSRect (); + OS.memmove (rect, arg0, NSRect.sizeof); + widget.drawInteriorWithFrame_inView (id, sel, rect, arg1); + yield 0; + } + case sel_drawWithExpansionFrame_inView_ -> { + NSRect rect = new NSRect(); + OS.memmove(rect, arg0, NSRect.sizeof); + widget.drawWithExpansionFrame_inView (id, sel, rect, arg1); + yield 0; + } + case sel_drawBezelWithFrame_inView_ -> { + NSRect rect = new NSRect (); + OS.memmove (rect, arg0, NSRect.sizeof); + widget.drawBezelWithFrame_inView (id, sel, rect, arg1); + yield 0; + } + case sel_accessibilityAttributeValue_forParameter_ -> widget.accessibilityAttributeValue_forParameter(id, sel, arg0, arg1); + case sel_tableView_didClickTableColumn_ -> { + widget.tableView_didClickTableColumn (id, sel, arg0, arg1); + yield 0; + } + case sel_outlineView_didClickTableColumn_ -> { + widget.outlineView_didClickTableColumn (id, sel, arg0, arg1); + yield 0; + } + case sel_shouldChangeTextInRange_replacementString_ -> widget.shouldChangeTextInRange_replacementString(id, sel, arg0, arg1) ? 1 : 0; + case sel_canDragRowsWithIndexes_atPoint_ -> { + NSPoint clickPoint = new NSPoint(); + OS.memmove(clickPoint, arg1, NSPoint.sizeof); + yield widget.canDragRowsWithIndexes_atPoint(id, sel, arg0, clickPoint) ? 1 : 0; + } + case sel_expandItem_expandChildren_ -> { + widget.expandItem_expandChildren(id, sel, arg0, arg1 != 0); + yield 0; + } + case sel_collapseItem_collapseChildren_ -> { + widget.collapseItem_collapseChildren(id, sel, arg0, arg1 != 0); + yield 0; + } + case sel_expansionFrameWithFrame_inView_ -> { + NSRect rect = new NSRect(); + OS.memmove(rect, arg0, NSRect.sizeof); + rect = widget.expansionFrameWithFrame_inView(id, sel, rect, arg1); + /* NOTE that this is freed in C */ + long result = C.malloc (NSRect.sizeof); + OS.memmove (result, rect, NSRect.sizeof); + yield result; + } + case sel_focusRingMaskBoundsForFrame_inView_ -> { + NSRect rect = new NSRect(); + OS.memmove(rect, arg0, NSRect.sizeof); + rect = widget.focusRingMaskBoundsForFrame(id, sel, rect, arg1); + /* NOTE that this is freed in C */ + long result = C.malloc (NSRect.sizeof); + OS.memmove (result, rect, NSRect.sizeof); + yield result; + } + case sel_drawLabel_inRect_ -> { + NSRect rect = new NSRect(); + OS.memmove(rect, arg1, NSRect.sizeof); + widget.drawLabelInRect(id, sel, arg0==1, rect); + yield 0; + } + case sel_scrollClipView_toPoint_ -> { + NSPoint point = new NSPoint(); + OS.memmove(point, arg1, NSPoint.sizeof); + widget.scrollClipViewToPoint (id, sel, arg0, point); + yield 0; + } + case sel_accessibilitySetValue_forAttribute_ -> { + widget.accessibilitySetValue_forAttribute(id, sel, arg0, arg1); + yield 0; + } + case sel_validRequestorForSendType_returnType_ -> widget.validRequestorForSendType(id, sel, arg0, arg1); + case sel_writeSelectionToPasteboard_types_ -> (widget.writeSelectionToPasteboard(id, sel, arg0, arg1) ? 1 : 0); + case sel_outlineView_shouldExpandItem_ -> (widget.outlineView_shouldExpandItem_item(id, sel, arg0, arg1) ? 1 : 0); + case sel_selectRowIndexes_byExtendingSelection_ -> { + widget.selectRowIndexes_byExtendingSelection(id, sel, arg0, arg1 != 0); + yield 0; + } + default -> 0; + }; } static long windowProc(long id, long sel, long arg0, long arg1, long arg2) { Widget widget = LookupWidget(id, sel); if (widget == null) return 0; - switch (Selector.valueOf(sel)) { - case sel_tableView_objectValueForTableColumn_row_: { - return widget.tableView_objectValueForTableColumn_row(id, sel, arg0, arg1, arg2); - } - case sel_tableView_shouldReorderColumn_toColumn_: { - return widget.tableView_shouldReorderColumn_toColumn(id, sel, arg0, arg1, arg2) ? 1 : 0; - } - case sel_tableView_shouldEditTableColumn_row_: { - return widget.tableView_shouldEditTableColumn_row(id, sel, arg0, arg1, arg2) ? 1 : 0; - } - case sel_outlineView_shouldReorderColumn_toColumn_: { - return widget.outlineView_shouldReorderColumn_toColumn(id, sel, arg0, arg1, arg2) ? 1 : 0; - } - case sel_outlineView_shouldEditTableColumn_item_: { - return widget.outlineView_shouldEditTableColumn_row(id, sel, arg0, arg1, arg2) ? 1 : 0; - } - case sel_textView_clickedOnLink_atIndex_: { - return widget.textView_clickOnLink_atIndex(id, sel, arg0, arg1, arg2) ? 1 : 0; - } - case sel_outlineView_child_ofItem_: { - return widget.outlineView_child_ofItem(id, sel, arg0, arg1, arg2); - } - case sel_outlineView_objectValueForTableColumn_byItem_: { - return widget.outlineView_objectValueForTableColumn_byItem(id, sel, arg0, arg1, arg2); - } - case sel_textView_willChangeSelectionFromCharacterRange_toCharacterRange_: { - NSRange range = widget.textView_willChangeSelectionFromCharacterRange_toCharacterRange(id, sel, arg0, arg1, arg2); - /* NOTE that this is freed in C */ - long result = C.malloc (NSRange.sizeof); - OS.memmove (result, range, NSRange.sizeof); - return result; - } - case sel_dragSelectionWithEvent_offset_slideBack_: { - NSSize offset = new NSSize(); - OS.memmove(offset, arg0, NSSize.sizeof); - return (widget.dragSelectionWithEvent(id, sel, arg0, arg1, arg2) ? 1 : 0); - } - case sel_drawImage_withFrame_inView_: { - NSRect rect = new NSRect (); - OS.memmove (rect, arg1, NSRect.sizeof); - widget.drawImageWithFrameInView (id, sel, arg0, rect, arg2); - return 0; - } - case sel_drawTitle_withFrame_inView_: { - NSRect rect = new NSRect (); - OS.memmove (rect, arg1, NSRect.sizeof); - rect = widget.drawTitleWithFrameInView (id, sel, arg0, rect, arg2); - /* NOTE that this is freed in C */ - long result = C.malloc (NSRect.sizeof); - OS.memmove (result, rect, NSRect.sizeof); - return result; - } - case sel_hitTestForEvent_inRect_ofView_: { - NSRect rect = new NSRect (); - OS.memmove (rect, arg1, NSRect.sizeof); - return widget.hitTestForEvent (id, sel, arg0, rect, arg2); - } - case sel_tableView_writeRowsWithIndexes_toPasteboard_: { - return (widget.tableView_writeRowsWithIndexes_toPasteboard(id, sel, arg0, arg1, arg2) ? 1 : 0); - } - case sel_outlineView_writeItems_toPasteboard_: { - return (widget.outlineView_writeItems_toPasteboard(id, sel, arg0, arg1, arg2) ? 1 : 0); - } - case sel_toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar_: { - return widget.toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar(id, sel, arg0, arg1, arg2 != 0); - } - default: { - return 0; - } - } + return switch (Selector.valueOf(sel)) { + case sel_tableView_objectValueForTableColumn_row_ -> widget.tableView_objectValueForTableColumn_row(id, sel, arg0, arg1, arg2); + case sel_tableView_shouldReorderColumn_toColumn_ -> widget.tableView_shouldReorderColumn_toColumn(id, sel, arg0, arg1, arg2) ? 1 : 0; + case sel_tableView_shouldEditTableColumn_row_ -> widget.tableView_shouldEditTableColumn_row(id, sel, arg0, arg1, arg2) ? 1 : 0; + case sel_outlineView_shouldReorderColumn_toColumn_ -> widget.outlineView_shouldReorderColumn_toColumn(id, sel, arg0, arg1, arg2) ? 1 : 0; + case sel_outlineView_shouldEditTableColumn_item_ -> widget.outlineView_shouldEditTableColumn_row(id, sel, arg0, arg1, arg2) ? 1 : 0; + case sel_textView_clickedOnLink_atIndex_ -> widget.textView_clickOnLink_atIndex(id, sel, arg0, arg1, arg2) ? 1 : 0; + case sel_outlineView_child_ofItem_ -> widget.outlineView_child_ofItem(id, sel, arg0, arg1, arg2); + case sel_outlineView_objectValueForTableColumn_byItem_ -> widget.outlineView_objectValueForTableColumn_byItem(id, sel, arg0, arg1, arg2); + case sel_textView_willChangeSelectionFromCharacterRange_toCharacterRange_ -> { + NSRange range = widget.textView_willChangeSelectionFromCharacterRange_toCharacterRange(id, sel, arg0, arg1, arg2); + /* NOTE that this is freed in C */ + long result = C.malloc (NSRange.sizeof); + OS.memmove (result, range, NSRange.sizeof); + yield result; + } + case sel_dragSelectionWithEvent_offset_slideBack_ -> { + NSSize offset = new NSSize(); + OS.memmove(offset, arg0, NSSize.sizeof); + yield (widget.dragSelectionWithEvent(id, sel, arg0, arg1, arg2) ? 1 : 0); + } + case sel_drawImage_withFrame_inView_ -> { + NSRect rect = new NSRect (); + OS.memmove (rect, arg1, NSRect.sizeof); + widget.drawImageWithFrameInView (id, sel, arg0, rect, arg2); + yield 0; + } + case sel_drawTitle_withFrame_inView_ -> { + NSRect rect = new NSRect (); + OS.memmove (rect, arg1, NSRect.sizeof); + rect = widget.drawTitleWithFrameInView (id, sel, arg0, rect, arg2); + /* NOTE that this is freed in C */ + long result = C.malloc (NSRect.sizeof); + OS.memmove (result, rect, NSRect.sizeof); + yield result; + } + case sel_hitTestForEvent_inRect_ofView_ -> { + NSRect rect = new NSRect (); + OS.memmove (rect, arg1, NSRect.sizeof); + yield widget.hitTestForEvent (id, sel, arg0, rect, arg2); + } + case sel_tableView_writeRowsWithIndexes_toPasteboard_ -> (widget.tableView_writeRowsWithIndexes_toPasteboard(id, sel, arg0, arg1, arg2) ? 1 : 0); + case sel_outlineView_writeItems_toPasteboard_ -> (widget.outlineView_writeItems_toPasteboard(id, sel, arg0, arg1, arg2) ? 1 : 0); + case sel_toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar_ -> widget.toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar(id, sel, arg0, arg1, arg2 != 0); + default -> 0; + }; } static long windowProc(long id, long sel, long arg0, long arg1, long arg2, long arg3) { Widget widget = LookupWidget(id, sel); if (widget == null) return 0; - switch (Selector.valueOf(sel)) { - case sel_tableView_willDisplayCell_forTableColumn_row_: { - widget.tableView_willDisplayCell_forTableColumn_row(id, sel, arg0, arg1, arg2, arg3); - return 0; - } - case sel_outlineView_willDisplayCell_forTableColumn_item_: { - widget.outlineView_willDisplayCell_forTableColumn_item(id, sel, arg0, arg1, arg2, arg3); - return 0; - } - case sel_outlineView_setObjectValue_forTableColumn_byItem_: { - widget.outlineView_setObjectValue_forTableColumn_byItem(id, sel, arg0, arg1, arg2, arg3); - return 0; - } - case sel_tableView_setObjectValue_forTableColumn_row_: { - widget.tableView_setObjectValue_forTableColumn_row(id, sel, arg0, arg1, arg2, arg3); - return 0; - } - case sel_view_stringForToolTip_point_userData_: { - return widget.view_stringForToolTip_point_userData(id, sel, arg0, arg1, arg2, arg3); - } - case sel_tableView_shouldTrackCell_forTableColumn_row_: { - return widget.tableView_shouldTrackCell_forTableColumn_row(id, sel, arg0, arg1, arg2, arg3) ? 1 : 0; - } - case sel_outlineView_shouldTrackCell_forTableColumn_item_: { - return widget.outlineView_shouldTrackCell_forTableColumn_item(id, sel, arg0, arg1, arg2, arg3) ? 1 : 0; - } - default: { - return 0; - } + return switch (Selector.valueOf(sel)) { + case sel_tableView_willDisplayCell_forTableColumn_row_ -> { + widget.tableView_willDisplayCell_forTableColumn_row(id, sel, arg0, arg1, arg2, arg3); + yield 0; + } + case sel_outlineView_willDisplayCell_forTableColumn_item_ -> { + widget.outlineView_willDisplayCell_forTableColumn_item(id, sel, arg0, arg1, arg2, arg3); + yield 0; + } + case sel_outlineView_setObjectValue_forTableColumn_byItem_ -> { + widget.outlineView_setObjectValue_forTableColumn_byItem(id, sel, arg0, arg1, arg2, arg3); + yield 0; } + case sel_tableView_setObjectValue_forTableColumn_row_ -> { + widget.tableView_setObjectValue_forTableColumn_row(id, sel, arg0, arg1, arg2, arg3); + yield 0; + } + case sel_view_stringForToolTip_point_userData_ -> widget.view_stringForToolTip_point_userData(id, sel, arg0, arg1, arg2, arg3); + case sel_tableView_shouldTrackCell_forTableColumn_row_ -> widget.tableView_shouldTrackCell_forTableColumn_row(id, sel, arg0, arg1, arg2, arg3) ? 1 : 0; + case sel_outlineView_shouldTrackCell_forTableColumn_item_ -> widget.outlineView_shouldTrackCell_forTableColumn_item(id, sel, arg0, arg1, arg2, arg3) ? 1 : 0; + default -> 0; + }; } static boolean isActivateShellOnForceFocus() { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tracker.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tracker.java index 65931fb7b9a..49f4f57a4c7 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tracker.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tracker.java @@ -250,35 +250,17 @@ Point adjustResizeCursor (boolean movePointer) { */ if (clientCursor == null) { Cursor newCursor = null; - switch (cursorOrientation) { - case SWT.UP: - newCursor = new Cursor(display, SWT.CURSOR_SIZENS); - break; - case SWT.DOWN: - newCursor = new Cursor(display, SWT.CURSOR_SIZENS); - break; - case SWT.LEFT: - newCursor = new Cursor(display, SWT.CURSOR_SIZEWE); - break; - case SWT.RIGHT: - newCursor = new Cursor(display, SWT.CURSOR_SIZEWE); - break; - case SWT.LEFT | SWT.UP: - newCursor = new Cursor(display, SWT.CURSOR_SIZENWSE); - break; - case SWT.RIGHT | SWT.DOWN: - newCursor = new Cursor(display, SWT.CURSOR_SIZENWSE); - break; - case SWT.LEFT | SWT.DOWN: - newCursor = new Cursor(display, SWT.CURSOR_SIZENESW); - break; - case SWT.RIGHT | SWT.UP: - newCursor = new Cursor(display, SWT.CURSOR_SIZENESW); - break; - default: - newCursor = new Cursor(display, SWT.CURSOR_SIZEALL); - break; - } + newCursor = switch (cursorOrientation) { + case SWT.UP -> new Cursor(display, SWT.CURSOR_SIZENS); + case SWT.DOWN -> new Cursor(display, SWT.CURSOR_SIZENS); + case SWT.LEFT -> new Cursor(display, SWT.CURSOR_SIZEWE); + case SWT.RIGHT -> new Cursor(display, SWT.CURSOR_SIZEWE); + case SWT.LEFT | SWT.UP -> new Cursor(display, SWT.CURSOR_SIZENWSE); + case SWT.RIGHT | SWT.DOWN -> new Cursor(display, SWT.CURSOR_SIZENWSE); + case SWT.LEFT | SWT.DOWN -> new Cursor(display, SWT.CURSOR_SIZENESW); + case SWT.RIGHT | SWT.UP -> new Cursor(display, SWT.CURSOR_SIZENESW); + default -> new Cursor(display, SWT.CURSOR_SIZEALL); + }; display.lockCursor = false; newCursor.handle.set(); display.lockCursor = true; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageData.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageData.java index 2bc2b17fdf0..c268e5caaed 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageData.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageData.java @@ -1071,12 +1071,12 @@ public RGB[] getRGBs() { */ public ImageData getTransparencyMask() { int transparencyType = getTransparencyType(); - switch (transparencyType) { - case SWT.TRANSPARENCY_ALPHA: return getTransparencyMaskFromAlphaData(); - case SWT.TRANSPARENCY_MASK: return new ImageData(width, height, 1, bwPalette(), maskPad, maskData); - case SWT.TRANSPARENCY_PIXEL: return colorMaskImage(transparentPixel); - default: return colorMaskImage(transparentPixel); - } + return switch (transparencyType) { + case SWT.TRANSPARENCY_ALPHA -> getTransparencyMaskFromAlphaData(); + case SWT.TRANSPARENCY_MASK -> new ImageData(width, height, 1, bwPalette(), maskPad, maskData); + case SWT.TRANSPARENCY_PIXEL -> colorMaskImage(transparentPixel); + default -> colorMaskImage(transparentPixel); + }; } ImageData getTransparencyMaskFromAlphaData() { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/RGB.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/RGB.java index 220ab381b38..bd62463c38d 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/RGB.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/RGB.java @@ -114,39 +114,43 @@ public RGB(float hue, float saturation, float brightness) { float p = brightness * (1 - saturation); float q = brightness * (1 - saturation * f); float t = brightness * (1 - saturation * (1 - f)); - switch(i) { - case 0: - r = brightness; - g = t; - b = p; - break; - case 1: - r = q; - g = brightness; - b = p; - break; - case 2: - r = p; - g = brightness; - b = t; - break; - case 3: - r = p; - g = q; - b = brightness; - break; - case 4: - r = t; - g = p; - b = brightness; - break; - case 5: - default: - r = brightness; - g = p; - b = q; - break; + b = switch (i) { + case 0 -> { + r = brightness; + g = t; + yield p; } + case 1 -> { + r = q; + g = brightness; + yield p; + } + case 2 -> { + r = p; + g = brightness; + yield t; + } + case 3 -> { + r = p; + g = q; + yield brightness; + } + case 4 -> { + r = t; + g = p; + yield brightness; + } + case 5 -> { + r = brightness; + g = p; + yield q; + } + default -> { + r = brightness; + g = p; + yield q; + } + }; } red = (int)(r * 255 + 0.5); green = (int)(g * 255 + 0.5); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/Callback.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/Callback.java index 90d9f2920cd..d6f4318a6ab 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/Callback.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/Callback.java @@ -122,15 +122,14 @@ public Callback (Object object, String method, int argCount, boolean isArrayBase if (isArrayBased) { signature = SIGNATURE_N; } else { - switch (argCount) { - case 0: signature = SIGNATURE_0; break; //$NON-NLS-1$ - case 1: signature = SIGNATURE_1; break; //$NON-NLS-1$ - case 2: signature = SIGNATURE_2; break; //$NON-NLS-1$ - case 3: signature = SIGNATURE_3; break; //$NON-NLS-1$ - case 4: signature = SIGNATURE_4; break; //$NON-NLS-1$ - default: - signature = getSignature(argCount); - } + signature = switch (argCount) { + case 0 -> SIGNATURE_0; + case 1 -> SIGNATURE_1; + case 2 -> SIGNATURE_2; + case 3 -> SIGNATURE_3; + case 4 -> SIGNATURE_4; + default -> getSignature(argCount); + }; } /* Bind the address */ diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java index 874339be554..604320fdf09 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java @@ -231,14 +231,12 @@ private static ImageData autoScaleImageData (Device device, final ImageData imag int height = imageData.height; int scaledWidth = Math.round ((float) width * scaleFactor); int scaledHeight = Math.round ((float) height * scaleFactor); - switch (autoScaleMethod) { - case SMOOTH: + return switch (autoScaleMethod) { + case SMOOTH -> { Image original = new Image (device, (ImageDataProvider) zoom -> imageData); - /* Create a 24 bit image data with alpha channel */ final ImageData resultData = new ImageData (scaledWidth, scaledHeight, 24, new PaletteData (0xFF, 0xFF00, 0xFF0000)); resultData.alphaData = new byte [scaledWidth * scaledHeight]; - Image resultImage = new Image (device, (ImageDataProvider) zoom -> resultData); GC gc = new GC (resultImage); gc.setAntialias (SWT.ON); @@ -251,11 +249,11 @@ private static ImageData autoScaleImageData (Device device, final ImageData imag original.dispose (); ImageData result = resultImage.getImageData (DPIUtil.getDeviceZoom ()); resultImage.dispose (); - return result; - case NEAREST: - default: - return imageData.scaledTo (scaledWidth, scaledHeight); + yield result; } + case NEAREST -> imageData.scaledTo (scaledWidth, scaledHeight); + default -> imageData.scaledTo (scaledWidth, scaledHeight); + }; } /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGDecoder.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGDecoder.java index 40d5c98721b..00df54fe0e5 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGDecoder.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGDecoder.java @@ -2462,22 +2462,18 @@ static void jpeg_calc_output_dimensions (jpeg_decompress_struct cinfo) /* Report number of components in selected colorspace. */ /* Probably this should be in the color conversion module... */ - switch (cinfo.out_color_space) { - case JCS_GRAYSCALE: - cinfo.out_color_components = 1; - break; - case JCS_RGB: - case JCS_YCbCr: - cinfo.out_color_components = 3; - break; - case JCS_CMYK: - case JCS_YCCK: - cinfo.out_color_components = 4; - break; - default: /* else must be same colorspace as in file */ - cinfo.out_color_components = cinfo.num_components; - break; - } + cinfo.out_color_components = switch (cinfo.out_color_space) { + case JCS_GRAYSCALE: + yield 1; + case JCS_RGB: + case JCS_YCbCr: + yield 3; + case JCS_CMYK: + case JCS_YCCK: + yield 4; + default: /* else must be same colorspace as in file */ + yield cinfo.num_components; + }; cinfo.output_components = (cinfo.quantize_colors ? 1 : cinfo.out_color_components); /* See if upsampler will want to emit more than one row at a time */ @@ -4189,19 +4185,12 @@ static void process_data_context_main (jpeg_decompress_struct cinfo, /* Read input data if we haven't filled the main buffer yet */ if (! main.buffer_full) { - int result; - switch (cinfo.coef.decompress_data) { - case DECOMPRESS_DATA: - result = decompress_data(cinfo, main.xbuffer[main.whichptr], main.xbuffer_offset[main.whichptr]); - break; - case DECOMPRESS_SMOOTH_DATA: - result = decompress_smooth_data(cinfo, main.xbuffer[main.whichptr], main.xbuffer_offset[main.whichptr]); - break; - case DECOMPRESS_ONEPASS: - result = decompress_onepass(cinfo, main.xbuffer[main.whichptr], main.xbuffer_offset[main.whichptr]); - break; - default: result = 0; - } + int result = switch (cinfo.coef.decompress_data) { + case DECOMPRESS_DATA -> decompress_data(cinfo, main.xbuffer[main.whichptr], main.xbuffer_offset[main.whichptr]); + case DECOMPRESS_SMOOTH_DATA -> decompress_smooth_data(cinfo, main.xbuffer[main.whichptr], main.xbuffer_offset[main.whichptr]); + case DECOMPRESS_ONEPASS -> decompress_onepass(cinfo, main.xbuffer[main.whichptr], main.xbuffer_offset[main.whichptr]); + default -> 0; + }; if (result == 0) return; /* suspension forced, can do nothing more */ main.buffer_full = true; /* OK, we have an iMCU row to work with */ @@ -4259,19 +4248,12 @@ static void process_data_simple_main (jpeg_decompress_struct cinfo, byte[][] out /* Read input data if we haven't filled the main buffer yet */ if (! main.buffer_full) { - int result; - switch (cinfo.coef.decompress_data) { - case DECOMPRESS_DATA: - result = decompress_data(cinfo, main.buffer, main.buffer_offset); - break; - case DECOMPRESS_SMOOTH_DATA: - result = decompress_smooth_data(cinfo, main.buffer, main.buffer_offset); - break; - case DECOMPRESS_ONEPASS: - result = decompress_onepass(cinfo, main.buffer, main.buffer_offset); - break; - default: result = 0; - } + int result = switch (cinfo.coef.decompress_data) { + case DECOMPRESS_DATA -> decompress_data(cinfo, main.buffer, main.buffer_offset); + case DECOMPRESS_SMOOTH_DATA -> decompress_smooth_data(cinfo, main.buffer, main.buffer_offset); + case DECOMPRESS_ONEPASS -> decompress_onepass(cinfo, main.buffer, main.buffer_offset); + default -> 0; + }; if (result == 0) return; /* suspension forced, can do nothing more */ main.buffer_full = true; /* OK, we have an iMCU row to work with */ @@ -6147,18 +6129,11 @@ static void default_decompress_parms (jpeg_decompress_struct cinfo) { if (cinfo.saw_JFIF_marker) { cinfo.jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */ } else if (cinfo.saw_Adobe_marker) { - switch (cinfo.Adobe_transform) { - case 0: - cinfo.jpeg_color_space = JCS_RGB; - break; - case 1: - cinfo.jpeg_color_space = JCS_YCbCr; - break; - default: -// WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo.Adobe_transform); - cinfo.jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */ - break; - } + cinfo.jpeg_color_space = switch (cinfo.Adobe_transform) { + case 0 -> JCS_RGB; + case 1 -> JCS_YCbCr; + default -> /* WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo.Adobe_transform); */ JCS_YCbCr; /* assume it's YCbCr */ + }; } else { /* Saw no special markers, try to guess from the component IDs */ int cid0 = cinfo.comp_info[0].component_id; @@ -6180,18 +6155,11 @@ else if (cid0 == 82 && cid1 == 71 && cid2 == 66) case 4: if (cinfo.saw_Adobe_marker) { - switch (cinfo.Adobe_transform) { - case 0: - cinfo.jpeg_color_space = JCS_CMYK; - break; - case 2: - cinfo.jpeg_color_space = JCS_YCCK; - break; - default: -// WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo.Adobe_transform); - cinfo.jpeg_color_space = JCS_YCCK; /* assume it's YCCK */ - break; - } + cinfo.jpeg_color_space = switch (cinfo.Adobe_transform) { + case 0 -> JCS_CMYK; + case 2 -> JCS_YCCK; + default -> /* WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo.Adobe_transform); */ JCS_YCCK; /* assume it's YCCK */ + }; } else { /* No special markers, assume straight CMYK. */ cinfo.jpeg_color_space = JCS_CMYK; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngChunk.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngChunk.java index b9cc0f081ba..0010d151965 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngChunk.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngChunk.java @@ -308,20 +308,14 @@ static PngChunk readNextFromStream(LEDataInputStream stream) { result = stream.read(chunk, 0, chunkLength); if (result != chunkLength) return null; - switch (tempChunk.getChunkType()) { - case CHUNK_IHDR: - return new PngIhdrChunk(chunk); - case CHUNK_PLTE: - return new PngPlteChunk(chunk); - case CHUNK_IDAT: - return new PngIdatChunk(chunk); - case CHUNK_IEND: - return new PngIendChunk(chunk); - case CHUNK_tRNS: - return new PngTrnsChunk(chunk); - default: - return new PngChunk(chunk); - } + return switch (tempChunk.getChunkType()) { + case CHUNK_IHDR -> new PngIhdrChunk(chunk); + case CHUNK_PLTE -> new PngPlteChunk(chunk); + case CHUNK_IDAT -> new PngIdatChunk(chunk); + case CHUNK_IEND -> new PngIendChunk(chunk); + case CHUNK_tRNS -> new PngTrnsChunk(chunk); + default -> new PngChunk(chunk); + }; } catch (IOException e) { return null; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngEncoder.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngEncoder.java index d87e1da2b02..cc2b61e4e58 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngEncoder.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngEncoder.java @@ -237,20 +237,12 @@ void writeImageData() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); OutputStream os = null; - switch (loader.compression) { - case 0: - os = new DeflaterOutputStream(baos, new Deflater(NO_COMPRESSION)); - break; - case 1: - os = new DeflaterOutputStream(baos, new Deflater(BEST_SPEED)); - break; - case 3: - os = new DeflaterOutputStream(baos, new Deflater(BEST_COMPRESSION)); - break; - default: - os = new DeflaterOutputStream(baos, new Deflater(DEFAULT_COMPRESSION)); - break; - } + os = switch (loader.compression) { + case 0 -> new DeflaterOutputStream(baos, new Deflater(NO_COMPRESSION)); + case 1 -> new DeflaterOutputStream(baos, new Deflater(BEST_SPEED)); + case 3 -> new DeflaterOutputStream(baos, new Deflater(BEST_COMPRESSION)); + default -> new DeflaterOutputStream(baos, new Deflater(DEFAULT_COMPRESSION)); + }; if (colorType == 3) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIhdrChunk.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIhdrChunk.java index ae221130e64..eab48ce55b1 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIhdrChunk.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIhdrChunk.java @@ -270,33 +270,33 @@ void validate(PngFileReadState readState, PngIhdrChunk headerChunk) { } String getColorTypeString() { - switch (colorType) { - case COLOR_TYPE_GRAYSCALE: return "Grayscale"; - case COLOR_TYPE_RGB: return "RGB"; - case COLOR_TYPE_PALETTE: return "Palette"; - case COLOR_TYPE_GRAYSCALE_WITH_ALPHA: return "Grayscale with Alpha"; - case COLOR_TYPE_RGB_WITH_ALPHA: return "RGB with Alpha"; - default: return "Unknown - " + colorType; - } + return switch (colorType) { + case COLOR_TYPE_GRAYSCALE -> "Grayscale"; + case COLOR_TYPE_RGB -> "RGB"; + case COLOR_TYPE_PALETTE -> "Palette"; + case COLOR_TYPE_GRAYSCALE_WITH_ALPHA -> "Grayscale with Alpha"; + case COLOR_TYPE_RGB_WITH_ALPHA -> "RGB with Alpha"; + default -> "Unknown - " + colorType; + }; } String getFilterMethodString() { - switch (filterMethod) { - case FILTER_NONE: return "None"; - case FILTER_SUB: return "Sub"; - case FILTER_UP: return "Up"; - case FILTER_AVERAGE: return "Average"; - case FILTER_PAETH: return "Paeth"; - default: return "Unknown"; - } + return switch (filterMethod) { + case FILTER_NONE -> "None"; + case FILTER_SUB -> "Sub"; + case FILTER_UP -> "Up"; + case FILTER_AVERAGE -> "Average"; + case FILTER_PAETH -> "Paeth"; + default -> "Unknown"; + }; } String getInterlaceMethodString() { - switch (interlaceMethod) { - case INTERLACE_METHOD_NONE: return "Not Interlaced"; - case INTERLACE_METHOD_ADAM7: return "Interlaced - ADAM7"; - default: return "Unknown"; - } + return switch (interlaceMethod) { + case INTERLACE_METHOD_NONE -> "Not Interlaced"; + case INTERLACE_METHOD_ADAM7 -> "Interlaced - ADAM7"; + default -> "Unknown"; + }; } @Override @@ -331,20 +331,16 @@ boolean getCanHavePalette() { * and bit depth. */ int getBitsPerPixel() { - switch (colorType) { - case COLOR_TYPE_RGB_WITH_ALPHA: - return 4 * bitDepth; - case COLOR_TYPE_RGB: - return 3 * bitDepth; - case COLOR_TYPE_GRAYSCALE_WITH_ALPHA: - return 2 * bitDepth; - case COLOR_TYPE_GRAYSCALE: - case COLOR_TYPE_PALETTE: - return bitDepth; - default: - SWT.error(SWT.ERROR_INVALID_IMAGE); - return 0; + return switch (colorType) { + case COLOR_TYPE_RGB_WITH_ALPHA -> 4 * bitDepth; + case COLOR_TYPE_RGB -> 3 * bitDepth; + case COLOR_TYPE_GRAYSCALE_WITH_ALPHA -> 2 * bitDepth; + case COLOR_TYPE_GRAYSCALE, COLOR_TYPE_PALETTE -> bitDepth; + default -> { + SWT.error(SWT.ERROR_INVALID_IMAGE); + yield 0; } + }; } /** @@ -352,18 +348,14 @@ int getBitsPerPixel() { * and bit depth. */ int getSwtBitsPerPixel() { - switch (colorType) { - case COLOR_TYPE_RGB_WITH_ALPHA: - case COLOR_TYPE_RGB: - case COLOR_TYPE_GRAYSCALE_WITH_ALPHA: - return 24; - case COLOR_TYPE_GRAYSCALE: - case COLOR_TYPE_PALETTE: - return Math.min(bitDepth, 8); - default: - SWT.error(SWT.ERROR_INVALID_IMAGE); - return 0; + return switch (colorType) { + case COLOR_TYPE_RGB_WITH_ALPHA, COLOR_TYPE_RGB, COLOR_TYPE_GRAYSCALE_WITH_ALPHA -> 24; + case COLOR_TYPE_GRAYSCALE, COLOR_TYPE_PALETTE -> Math.min(bitDepth, 8); + default -> { + SWT.error(SWT.ERROR_INVALID_IMAGE); + yield 0; } + }; } int getFilterByteOffset() { @@ -372,15 +364,10 @@ int getFilterByteOffset() { } boolean usesDirectColor() { - switch (colorType) { - case COLOR_TYPE_GRAYSCALE: - case COLOR_TYPE_GRAYSCALE_WITH_ALPHA: - case COLOR_TYPE_RGB: - case COLOR_TYPE_RGB_WITH_ALPHA: - return true; - default: - return false; - } + return switch (colorType) { + case COLOR_TYPE_GRAYSCALE, COLOR_TYPE_GRAYSCALE_WITH_ALPHA, COLOR_TYPE_RGB, COLOR_TYPE_RGB_WITH_ALPHA -> true; + default -> false; + }; } PaletteData createGrayscalePalette() { @@ -397,16 +384,11 @@ PaletteData createGrayscalePalette() { } PaletteData getPaletteData() { - switch (colorType) { - case COLOR_TYPE_GRAYSCALE: - return createGrayscalePalette(); - case COLOR_TYPE_GRAYSCALE_WITH_ALPHA: - case COLOR_TYPE_RGB: - case COLOR_TYPE_RGB_WITH_ALPHA: - return new PaletteData(0xFF0000, 0xFF00, 0xFF); - default: - return null; - } + return switch (colorType) { + case COLOR_TYPE_GRAYSCALE -> createGrayscalePalette(); + case COLOR_TYPE_GRAYSCALE_WITH_ALPHA, COLOR_TYPE_RGB, COLOR_TYPE_RGB_WITH_ALPHA -> new PaletteData(0xFF0000, 0xFF00, 0xFF); + default -> null; + }; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngTrnsChunk.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngTrnsChunk.java index 9df7d9d32ff..72210d0369d 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngTrnsChunk.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngTrnsChunk.java @@ -41,26 +41,13 @@ int getChunkType() { } void validateLength(PngIhdrChunk header, PngPlteChunk paletteChunk) { - boolean valid; - switch (header.getColorType()) { - case PngIhdrChunk.COLOR_TYPE_RGB: - // Three 2-byte values (RGB) - valid = getLength() == 6; - break; - case PngIhdrChunk.COLOR_TYPE_PALETTE: - // Three 2-byte values (RGB) - valid = getLength() <= paletteChunk.getLength(); - break; - case PngIhdrChunk.COLOR_TYPE_GRAYSCALE: - // One 2-byte value - valid = getLength() == 2; - break; - // Cannot use both Alpha and tRNS - case PngIhdrChunk.COLOR_TYPE_RGB_WITH_ALPHA: - case PngIhdrChunk.COLOR_TYPE_GRAYSCALE_WITH_ALPHA: - default: - valid = false; - } + boolean valid = switch (header.getColorType()) { + case PngIhdrChunk.COLOR_TYPE_RGB -> /* Three 2-byte values (RGB) */ getLength() == 6; + case PngIhdrChunk.COLOR_TYPE_PALETTE -> /* Three 2-byte values (RGB) */ getLength() <= paletteChunk.getLength(); + case PngIhdrChunk.COLOR_TYPE_GRAYSCALE -> /* One 2-byte value */ getLength() == 2; + case PngIhdrChunk.COLOR_TYPE_RGB_WITH_ALPHA, PngIhdrChunk.COLOR_TYPE_GRAYSCALE_WITH_ALPHA -> false; + default -> false; + }; if (!valid) { SWT.error(SWT.ERROR_INVALID_IMAGE); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/BorderData.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/BorderData.java index 808f3f785f0..f42a9811274 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/BorderData.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/BorderData.java @@ -94,20 +94,14 @@ public String toString() { } static String getRegionString(int region) { - switch (region) { - case SWT.TOP: - return "SWT.TOP"; - case SWT.RIGHT: - return "SWT.RIGHT"; - case SWT.BOTTOM: - return "SWT.BOTTOM"; - case SWT.LEFT: - return "SWT.LEFT"; - case SWT.CENTER: - return "SWT.CENTER"; - default: - return "SWT.NONE"; - } + return switch (region) { + case SWT.TOP -> "SWT.TOP"; + case SWT.RIGHT -> "SWT.RIGHT"; + case SWT.BOTTOM -> "SWT.BOTTOM"; + case SWT.LEFT -> "SWT.LEFT"; + case SWT.CENTER -> "SWT.CENTER"; + default -> "SWT.NONE"; + }; } /** @@ -116,16 +110,10 @@ static String getRegionString(int region) { * range */ int getRegion() { - switch (region) { - case TOP: - case BOTTOM: - case CENTER: - case RIGHT: - case LEFT: - return region; - case SWT.NONE: - default: - return SWT.NONE; - } + return switch (region) { + case TOP, BOTTOM, CENTER, RIGHT, LEFT -> region; + case SWT.NONE -> SWT.NONE; + default -> SWT.NONE; + }; } } \ No newline at end of file diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/GridData.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/GridData.java index 15ff936e216..3ecff268ff1 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/GridData.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/GridData.java @@ -533,29 +533,29 @@ String getName () { @Override public String toString () { String hAlign = ""; - switch (horizontalAlignment) { - case SWT.FILL: hAlign = "SWT.FILL"; break; - case SWT.BEGINNING: hAlign = "SWT.BEGINNING"; break; - case SWT.LEFT: hAlign = "SWT.LEFT"; break; - case SWT.END: hAlign = "SWT.END"; break; - case END: hAlign = "GridData.END"; break; - case SWT.RIGHT: hAlign = "SWT.RIGHT"; break; - case SWT.CENTER: hAlign = "SWT.CENTER"; break; - case CENTER: hAlign = "GridData.CENTER"; break; - default: hAlign = "Undefined "+horizontalAlignment; break; - } + hAlign = switch (horizontalAlignment) { + case SWT.FILL -> "SWT.FILL"; + case SWT.BEGINNING -> "SWT.BEGINNING"; + case SWT.LEFT -> "SWT.LEFT"; + case SWT.END -> "SWT.END"; + case END -> "GridData.END"; + case SWT.RIGHT -> "SWT.RIGHT"; + case SWT.CENTER -> "SWT.CENTER"; + case CENTER -> "GridData.CENTER"; + default -> "Undefined "+horizontalAlignment; + }; String vAlign = ""; - switch (verticalAlignment) { - case SWT.FILL: vAlign = "SWT.FILL"; break; - case SWT.BEGINNING: vAlign = "SWT.BEGINNING"; break; - case SWT.TOP: vAlign = "SWT.TOP"; break; - case SWT.END: vAlign = "SWT.END"; break; - case END: vAlign = "GridData.END"; break; - case SWT.BOTTOM: vAlign = "SWT.BOTTOM"; break; - case SWT.CENTER: vAlign = "SWT.CENTER"; break; - case CENTER: vAlign = "GridData.CENTER"; break; - default: vAlign = "Undefined "+verticalAlignment; break; - } + vAlign = switch (verticalAlignment) { + case SWT.FILL -> "SWT.FILL"; + case SWT.BEGINNING -> "SWT.BEGINNING"; + case SWT.TOP -> "SWT.TOP"; + case SWT.END -> "SWT.END"; + case END -> "GridData.END"; + case SWT.BOTTOM -> "SWT.BOTTOM"; + case SWT.CENTER -> "SWT.CENTER"; + case CENTER -> "GridData.CENTER"; + default -> "Undefined "+verticalAlignment; + }; String string = getName()+" {"; string += "horizontalAlignment="+hAlign+" "; if (horizontalIndent != 0) string += "horizontalIndent="+horizontalIndent+" ";