Skip to content

Commit

Permalink
Image type SWT.ICON loses its type during re-scale
Browse files Browse the repository at this point in the history
Image initialized as SWT.ICON in
org.eclipse.swt.graphics.Image.Image(Device, ImageData, ImageData) loses
its "Icon" properties i.e. type, mask etc. when handle for different
zoom level is requested. Now implementing correct init method when the
handle is requested for image type ICON.
  • Loading branch information
ShahzaibIbrahim committed Feb 4, 2025
1 parent f08d215 commit 06ab00b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*******************************************************************************
* Copyright (c) 2024 Yatta Solutions
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Yatta Solutions - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.graphics;

import static org.junit.Assert.assertEquals;

import org.eclipse.swt.*;
import org.eclipse.swt.internal.*;
import org.eclipse.swt.widgets.*;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.extension.*;

@ExtendWith(PlatformSpecificExecutionExtension.class)
@ExtendWith(WithMonitorSpecificScalingExtension.class)
class ImagesWin32Tests {

@Test
public void testImageIconTypeShouldNotChangeAfterCallingGetHandleForDifferentZoom() {
Image icon = Display.getDefault().getSystemImage(SWT.ICON_ERROR);
try {
Image.win32_getHandle(icon, 200);
assertEquals("Image type should stay to SWT.ICON", SWT.ICON, icon.type);
} finally {
icon.dispose();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,11 @@ private ImageHandle getImageMetadata(int zoom) {
} else {
ImageData resizedData = getImageData(zoom);
ImageData newData = adaptImageDataIfDisabledOrGray(resizedData);
init(newData, zoom);
if (type == SWT.ICON) {
init(this.device, this, newData, newData.getTransparencyMask(), zoom);
} else {
init(newData, zoom);
}
init();
}
return zoomLevelToImageHandle.get(zoom);
Expand Down

0 comments on commit 06ab00b

Please sign in to comment.