Skip to content

Commit 1bf6b79

Browse files
committed
GC#drawIcon draws *.ico(for some icons) with black background on
Windows10 - Fixes #185 Change-Id: Idec2ddb0086a58c8d28c7616a628e2802d06ce56 Signed-off-by: Niraj Modi <[email protected]>
1 parent 9ac10ff commit 1bf6b79

File tree

2 files changed

+80
-3
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics
  • tests/org.eclipse.swt.tests.win32/ManualTests/org/eclipse/swt/tests/win32/snippets

2 files changed

+80
-3
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2020 IBM Corporation and others.
2+
* Copyright (c) 2000, 2022 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -1797,8 +1797,9 @@ static long createDIB(int width, int height, int depth) {
17971797
}
17981798
break;
17991799
case 32:
1800-
newDepth = 24;
1801-
newPalette = new PaletteData(0xFF, 0xFF00, 0xFF0000);
1800+
if (!(redMask == 0xFF00 && greenMask == 0xFF0000 && blueMask == 0xFF000000)) {
1801+
newPalette = new PaletteData(0xFF00, 0xFF0000, 0xFF000000);
1802+
}
18021803
break;
18031804
default:
18041805
SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2022 IBM Corporation and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* IBM Corporation - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.swt.tests.win32.snippets;
15+
16+
import java.util.ArrayList;
17+
import java.util.List;
18+
19+
import org.eclipse.swt.SWT;
20+
import org.eclipse.swt.graphics.Image;
21+
import org.eclipse.swt.graphics.ImageData;
22+
import org.eclipse.swt.program.Program;
23+
import org.eclipse.swt.widgets.Display;
24+
import org.eclipse.swt.widgets.Shell;
25+
26+
public class SWTIssue185 {
27+
28+
public static void main(String[] args) {
29+
final Display display = new Display();
30+
31+
final List<Image> images = createImages(display, "zip", "jpg", "txt", "pdf", "png", "msi", "theme");
32+
33+
final Shell shell = new Shell(display);
34+
35+
shell.addListener(SWT.Paint, event -> {
36+
int x = 0;
37+
for (Image image : images) {
38+
event.gc.drawImage(image, x, 0);
39+
x += image.getImageData().width;
40+
x += 10;
41+
}
42+
});
43+
44+
shell.setSize(400, 300);
45+
shell.open();
46+
47+
while (!shell.isDisposed()) {
48+
if (!display.readAndDispatch()) {
49+
display.sleep();
50+
}
51+
}
52+
53+
for (Image image : images) {
54+
image.dispose();
55+
}
56+
57+
display.dispose();
58+
}
59+
60+
private static List<Image> createImages(Display display, String... extensions) {
61+
final List<Image> images = new ArrayList<>();
62+
for (String extension : extensions) {
63+
final Program program = Program.findProgram(extension);
64+
if (program == null) {
65+
continue;
66+
}
67+
final ImageData data = program.getImageData();
68+
if (data == null) {
69+
continue;
70+
}
71+
images.add(new Image(display, data));
72+
}
73+
return images;
74+
}
75+
76+
}

0 commit comments

Comments
 (0)