Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .mvn/extensions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<extension>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-build</artifactId>
<version>5.0.1</version>
<version>5.0.2</version>
</extension>
</extensions>
Original file line number Diff line number Diff line change
Expand Up @@ -5091,6 +5091,7 @@ boolean sendMouseEvent (int type, int button, int count, int detail, boolean sen
flushQueueOnDnd();
} else {
dragDetectionQueue.add(event);
return true;
}
break;
case SWT.MouseUp:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ private boolean isReusable(int width, int height) {
private Optional<InternalImageHandle> createHandleAtExactSize(int width, int height) {
Optional<ImageData> imageData = imageProvider.loadImageDataAtExactSize(width, height);
if (imageData.isPresent()) {
ImageData adaptedData = adaptImageDataIfDisabledOrGray(imageData.get());
temporaryHandleContainer = init(adaptedData, -1);
temporaryHandleContainer = init(imageData.get(), -1);
return Optional.of(temporaryHandleContainer);
}
return Optional.empty();
Expand All @@ -253,8 +252,7 @@ private InternalImageHandle getOrCreateImageHandleAtClosestSize(int widthHint, i
InternalImageHandle bestFittingHandle = imageHandleManager.get(imageZoom);
if (bestFittingHandle == null) {
ImageData bestFittingImageData = imageProvider.loadImageData(imageZoom).element();
ImageData adaptedData = adaptImageDataIfDisabledOrGray(bestFittingImageData);
bestFittingHandle = temporaryHandleContainer = init(adaptedData, -1);
bestFittingHandle = temporaryHandleContainer = init(bestFittingImageData, -1);
}
return bestFittingHandle;
}
Expand Down Expand Up @@ -771,6 +769,10 @@ public Image(Device device, ImageGcDrawer imageGcDrawer, int width, int height)
init();
}

private ElementAtZoom<ImageData> adaptImageDataIfDisabledOrGray(ElementAtZoom<ImageData> dataAtZoom) {
return new ElementAtZoom<>(adaptImageDataIfDisabledOrGray(dataAtZoom.element()), dataAtZoom.zoom());
}

private ImageData adaptImageDataIfDisabledOrGray(ImageData data) {
ImageData returnImageData = null;
switch (this.styleFlag) {
Expand Down Expand Up @@ -2058,6 +2060,10 @@ protected boolean isPersistentImageHandleRequriedForImageData() {
return false;
}

/**
* Returns image data at the best-fitting available zoom for the given zoom.
* The returned data will have a potential gray/disable style applied.
*/
protected abstract ElementAtZoom<ImageData> loadImageData(int zoom);

abstract ImageData newImageData(int zoom);
Expand All @@ -2071,6 +2077,10 @@ ElementAtZoom<ImageData> getClosestAvailableImageData(int zoom) {
return new ElementAtZoom<>(imageData, closestZoom);
}

/**
* Returns image data at the exact requested size if available.
* The returned data will have a potential gray/disable style applied.
*/
protected Optional<ImageData> loadImageDataAtExactSize(int width, int height) {
return Optional.empty(); // exact size not available
}
Expand Down Expand Up @@ -2174,7 +2184,6 @@ protected DestroyableImageHandle newImageHandle(ZoomContext zoomContext) {
private DestroyableImageHandle initializeHandleFromSource(ZoomContext zoomContext) {
ElementAtZoom<ImageData> imageDataAtZoom = loadImageData(zoomContext.targetZoom());
ImageData imageData = DPIUtil.scaleImageData(device, imageDataAtZoom.element(), zoomContext.targetZoom(), imageDataAtZoom.zoom());
imageData = adaptImageDataIfDisabledOrGray(imageData);
return newImageHandle(imageData, zoomContext);
}
}
Expand Down Expand Up @@ -2202,7 +2211,8 @@ protected Rectangle getBounds(int zoom) {

@Override
protected ElementAtZoom<ImageData> loadImageData(int zoom) {
return new ElementAtZoom<>(imageDataAtBaseZoom, baseZoom);
ImageData adaptedImageData = adaptImageDataIfDisabledOrGray(imageDataAtBaseZoom);
return new ElementAtZoom<>(adaptedImageData, baseZoom);
}

@Override
Expand Down Expand Up @@ -2233,7 +2243,8 @@ protected ElementAtZoom<ImageData> loadImageData(int zoom) {
ImageData scaledMask = DPIUtil.scaleImageData(device, maskAt100, zoom, 100);
scaledMask = ImageData.convertMask(scaledMask);
ImageData mergedData = applyMask(scaledSource, scaledMask);
return new ElementAtZoom<>(mergedData, zoom);
ImageData adaptedData = adaptImageDataIfDisabledOrGray(mergedData);
return new ElementAtZoom<>(adaptedData, zoom);
}

@Override
Expand All @@ -2260,7 +2271,8 @@ private ImageDataLoaderStreamProviderWrapper(byte[] inputStreamData) {

@Override
protected ElementAtZoom<ImageData> loadImageData(int zoom) {
return ImageDataLoader.loadByZoom(new ByteArrayInputStream(inputStreamData), FileFormat.DEFAULT_ZOOM, zoom);
ElementAtZoom<ImageData> imageDataAtZoom = ImageDataLoader.loadByZoom(new ByteArrayInputStream(inputStreamData), FileFormat.DEFAULT_ZOOM, zoom);
return adaptImageDataIfDisabledOrGray(imageDataAtZoom);
}

@Override
Expand All @@ -2278,7 +2290,8 @@ AbstractImageProviderWrapper createCopy(Image image) {
protected Optional<ImageData> loadImageDataAtExactSize(int targetWidth, int targetHeight) {
if (ImageDataLoader.isDynamicallySizable(new ByteArrayInputStream(this.inputStreamData))) {
ImageData imageDataAtSize = ImageDataLoader.loadBySize(new ByteArrayInputStream(this.inputStreamData), targetWidth, targetHeight);
return Optional.of(imageDataAtSize);
ImageData adaptedImageDataAtSize = adaptImageDataIfDisabledOrGray(imageDataAtSize);
return Optional.of(adaptedImageDataAtSize);
}
return Optional.empty();
}
Expand Down Expand Up @@ -2470,7 +2483,6 @@ protected DestroyableImageHandle newImageHandle(ZoomContext zoomContext) {
private DestroyableImageHandle initializeHandleFromSource(int zoom) {
ElementAtZoom<ImageData> imageDataAtZoom = loadImageData(zoom);
ImageData imageData = DPIUtil.scaleImageData (device, imageDataAtZoom.element(), zoom, imageDataAtZoom.zoom());
imageData = adaptImageDataIfDisabledOrGray(imageData);
return init(imageData, zoom);
}

Expand All @@ -2497,7 +2509,8 @@ protected ElementAtZoom<ImageData> loadImageData(int zoom) {
// Load at appropriate zoom via loader
if (fileForZoom.zoom() != zoom && ImageDataLoader.canLoadAtZoom(fileForZoom.element(), fileForZoom.zoom(), zoom)) {
ElementAtZoom<ImageData> imageDataAtZoom = ImageDataLoader.loadByZoom(fileForZoom.element(), fileForZoom.zoom(), zoom);
return new ElementAtZoom<>(imageDataAtZoom.element(), zoom);
ImageData adaptedImageData = adaptImageDataIfDisabledOrGray(imageDataAtZoom.element());
return new ElementAtZoom<>(adaptedImageData, zoom);
}

// Load at file zoom (native or via loader) and rescale
Expand All @@ -2517,7 +2530,7 @@ protected ElementAtZoom<ImageData> loadImageData(int zoom) {
temporaryImageHandle.destroy();
}
}
return imageDataAtZoom;
return adaptImageDataIfDisabledOrGray(imageDataAtZoom);
}

@Override
Expand Down Expand Up @@ -2727,7 +2740,8 @@ protected Optional<ImageData> loadImageDataAtExactSize(int targetWidth, int targ
String fileName = DPIUtil.validateAndGetImagePathAtZoom(this.provider, 100).element();
if (ImageDataLoader.isDynamicallySizable(fileName)) {
ImageData imageDataAtSize = ImageDataLoader.loadBySize(fileName, targetWidth, targetHeight);
return Optional.of(imageDataAtSize);
ImageData adaptedImageDataAtSize = adaptImageDataIfDisabledOrGray(imageDataAtSize);
return Optional.of(adaptedImageDataAtSize);
}
return Optional.empty();
}
Expand All @@ -2740,7 +2754,8 @@ private class ImageDataProviderWrapper extends BaseImageProviderWrapper<ImageDat

@Override
protected ElementAtZoom<ImageData> loadImageData(int zoom) {
return DPIUtil.validateAndGetImageDataAtZoom (provider, zoom);
ElementAtZoom<ImageData> imageDataAtZoom = DPIUtil.validateAndGetImageDataAtZoom (provider, zoom);
return adaptImageDataIfDisabledOrGray(imageDataAtZoom);
}

@Override
Expand All @@ -2756,7 +2771,8 @@ protected Optional<ImageData> loadImageDataAtExactSize(int targetWidth, int targ
SWT.error(SWT.ERROR_INVALID_ARGUMENT, null,
" ImageDataAtSizeProvider returned null for width=" + targetWidth + ", height=" + targetHeight);
}
return Optional.of(imageData);
ImageData adaptedImageData = adaptImageDataIfDisabledOrGray(imageData);
return Optional.of(adaptedImageData);
}
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,6 @@ public Image get (int index) {
return images [index];
}

public int getStyle () {
return style;
}

public long getHandle(int targetZoom) {
if (!zoomToHandle.containsKey(targetZoom)) {
int scaledWidth = DPIUtil.pointToPixel(DPIUtil.pixelToPoint(width, this.zoom), targetZoom);
Expand Down Expand Up @@ -374,6 +370,11 @@ public Point getImageSize() {
return Win32DPIUtils.pixelToPointAsSize(new Point (cx [0], cy [0]), zoom);
}

public boolean isFittingFor(int style, int width, int height, int zoom) {
Point imageSize = getImageSize();
return this.style == style && imageSize.x == width && imageSize.y == height && this.zoom == zoom;
}

public int indexOf (Image image) {
int count = OS.ImageList_GetImageCount (handle);
for (int i=0; i<count; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2045,12 +2045,9 @@ ImageList getImageList (int style, int width, int height, int zoom) {
while (i < length) {
ImageList list = imageList [i];
if (list == null) break;
Point size = list.getImageSize();
if (size.x == width && size.y == height) {
if (list.getStyle () == style) {
list.addRef();
return list;
}
if (list.isFittingFor(style, width, height, zoom)) {
list.addRef();
return list;
}
i++;
}
Expand All @@ -2075,12 +2072,9 @@ ImageList getImageListToolBar (int style, int width, int height, int zoom) {
while (i < length) {
ImageList list = toolImageList [i];
if (list == null) break;
Point size = list.getImageSize();
if (size.x == width && size.y == height) {
if (list.getStyle () == style) {
list.addRef();
return list;
}
if (list.isFittingFor(style, width, height, zoom)) {
list.addRef();
return list;
}
i++;
}
Expand All @@ -2105,12 +2099,9 @@ ImageList getImageListToolBarDisabled (int style, int width, int height, int zoo
while (i < length) {
ImageList list = toolDisabledImageList [i];
if (list == null) break;
Point size = list.getImageSize();
if (size.x == width && size.y == height) {
if (list.getStyle () == style) {
list.addRef();
return list;
}
if (list.isFittingFor(style, width, height, zoom)) {
list.addRef();
return list;
}
i++;
}
Expand All @@ -2135,12 +2126,9 @@ ImageList getImageListToolBarHot (int style, int width, int height, int zoom) {
while (i < length) {
ImageList list = toolHotImageList [i];
if (list == null) break;
Point size = list.getImageSize();
if (size.x == width && size.y == height) {
if (list.getStyle () == style) {
list.addRef();
return list;
}
if (list.isFittingFor(style, width, height, zoom)) {
list.addRef();
return list;
}
i++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class TrayItem extends Item {
public TrayItem (Tray parent, int style) {
super (parent, style);
this.parent = parent;
this.nativeZoom = display.getDeviceZoom();
parent.createItem (this, parent.getItemCount ());
createUpdateWidget (true);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 Christoph Läubrich and others.
* Copyright (c) 2024, 2026 Christoph Läubrich and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -95,8 +95,7 @@ public void testShowWhile() {
@Test
@Timeout(value = 30)
public void testShowWhileWithFuture() {
ExecutorService executor = Executors.newSingleThreadExecutor();
try {
try (ExecutorService executor = Executors.newSingleThreadExecutor()){
Shell shell = new Shell();
Display display = shell.getDisplay();
Cursor busyCursor = display.getSystemCursor(SWT.CURSOR_WAIT);
Expand Down Expand Up @@ -129,8 +128,6 @@ public void testShowWhileWithFuture() {
shell.dispose();
while (!display.isDisposed() && display.readAndDispatch()) {
}
} finally {
executor.shutdownNow();
}
}

Expand Down