Skip to content

Commit e7868f7

Browse files
authored
Merge branch 'eclipse-platform:master' into master
2 parents c31d2ca + 7f19dc5 commit e7868f7

File tree

3 files changed

+44
-15
lines changed

3 files changed

+44
-15
lines changed

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

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ public final class Cursor extends Resource {
135135
*/
136136
public Cursor(Device device, int style) {
137137
this(device);
138+
this.handle = setupCursorFromStyle(style);
139+
init();
140+
}
141+
142+
private static long setupCursorFromStyle(int style) {
138143
long lpCursorName = 0;
139144
switch (style) {
140145
case SWT.CURSOR_HAND: lpCursorName = OS.IDC_HAND; break;
@@ -162,9 +167,9 @@ public Cursor(Device device, int style) {
162167
default:
163168
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
164169
}
165-
handle = OS.LoadCursor(0, lpCursorName);
170+
long handle = OS.LoadCursor(0, lpCursorName);
166171
if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
167-
init();
172+
return handle;
168173
}
169174

170175
/**
@@ -207,6 +212,12 @@ public Cursor(Device device, ImageData source, ImageData mask, int hotspotX, int
207212
this.hotspotX = hotspotX;
208213
this.hotspotY = hotspotY;
209214
this.imageDataProvider = null;
215+
this.handle = setupCursorFromImageData(source, mask, hotspotX, hotspotY);
216+
init();
217+
this.device.registerResourceWithZoomSupport(this);
218+
}
219+
220+
private static long setupCursorFromImageData(ImageData source, ImageData mask, int hotspotX, int hotspotY) {
210221
if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
211222
if (mask == null) {
212223
if (source.getTransparencyType() != SWT.TRANSPARENCY_MASK) {
@@ -233,10 +244,9 @@ public Cursor(Device device, ImageData source, ImageData mask, int hotspotX, int
233244

234245
/* Create the cursor */
235246
long hInst = OS.GetModuleHandle(null);
236-
handle = OS.CreateCursor(hInst, hotspotX, hotspotY, source.width, source.height, sourceData, maskData);
247+
long handle = OS.CreateCursor(hInst, hotspotX, hotspotY, source.width, source.height, sourceData, maskData);
237248
if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
238-
init();
239-
this.device.registerResourceWithZoomSupport(this);
249+
return handle;
240250
}
241251

242252
/**
@@ -275,10 +285,13 @@ public Cursor(Device device, ImageData source, int hotspotX, int hotspotY) {
275285
this.hotspotX = hotspotX;
276286
this.hotspotY = hotspotY;
277287
this.imageDataProvider = null;
278-
setupCursorFromImageData(source);
288+
this.handle = setupCursorFromImageData(device, source, hotspotX, hotspotY);
289+
isIcon = true;
290+
init();
291+
this.device.registerResourceWithZoomSupport(this);
279292
}
280293

281-
private void setupCursorFromImageData(ImageData source) {
294+
private static long setupCursorFromImageData(Device device, ImageData source, int hotspotX, int hotspotY) {
282295
if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
283296
/* Check the hotspots */
284297
if (hotspotX >= source.width || hotspotX < 0 ||
@@ -333,7 +346,7 @@ private void setupCursorFromImageData(ImageData source) {
333346
if (hMask == 0) SWT.error(SWT.ERROR_NO_HANDLES);
334347
} else {
335348
ImageData mask = source.getTransparencyMask();
336-
long [] result = Image.initIcon(this.device, source, mask);
349+
long [] result = Image.initIcon(device, source, mask);
337350
hBitmap = result[0];
338351
hMask = result[1];
339352
}
@@ -344,13 +357,12 @@ private void setupCursorFromImageData(ImageData source) {
344357
info.hbmMask = hMask;
345358
info.xHotspot = hotspotX;
346359
info.yHotspot = hotspotY;
347-
handle = OS.CreateIconIndirect(info);
360+
long handle = OS.CreateIconIndirect(info);
348361
OS.DeleteObject(hBitmap);
349362
OS.DeleteObject(hMask);
350363
if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
351-
isIcon = true;
352-
init();
353-
this.device.registerResourceWithZoomSupport(this);
364+
365+
return handle;
354366
}
355367

356368
/**
@@ -390,7 +402,10 @@ public Cursor(Device device, ImageDataProvider imageDataProvider, int hotspotX,
390402
this.mask = null;
391403
this.hotspotX = hotspotX;
392404
this.hotspotY = hotspotY;
393-
setupCursorFromImageData(this.source);
405+
this.handle = setupCursorFromImageData(device, this.source, hotspotX, hotspotY);
406+
isIcon = true;
407+
init();
408+
this.device.registerResourceWithZoomSupport(this);
394409
}
395410

396411
/**
@@ -429,11 +444,11 @@ public static Long win32_getHandle (Cursor cursor, int zoom) {
429444
source = DPIUtil.scaleImageData(cursor.device, cursor.source, zoom, DEFAULT_ZOOM);
430445
}
431446
if (cursor.isIcon) {
432-
Cursor newCursor = new Cursor(cursor.device, source, cursor.hotspotX, cursor.hotspotY);
447+
Cursor newCursor = new Cursor(cursor.device, source, Win32DPIUtils.pointToPixel(cursor.hotspotX, zoom), Win32DPIUtils.pointToPixel(cursor.hotspotY, zoom));
433448
cursor.setHandleForZoomLevel(newCursor.handle, zoom);
434449
} else {
435450
ImageData mask = DPIUtil.scaleImageData(cursor.device, cursor.mask, zoom, DEFAULT_ZOOM);
436-
Cursor newCursor = new Cursor(cursor.device, source, mask, cursor.hotspotX, cursor.hotspotY);
451+
Cursor newCursor = new Cursor(cursor.device, source, mask, Win32DPIUtils.pointToPixel(cursor.hotspotX, zoom), Win32DPIUtils.pointToPixel(cursor.hotspotY, zoom));
437452
cursor.setHandleForZoomLevel(newCursor.handle, zoom);
438453
}
439454
}

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/SWTFontProvider.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ public static long getFontHandle(Font font, int zoom) {
7474
if (font == null) {
7575
SWT.error(SWT.ERROR_NULL_ARGUMENT);
7676
}
77+
if (font.isDisposed()) {
78+
return 0;
79+
}
7780
return Font.win32_getHandle(getFont(font.getDevice(), font.getFontData()[0], zoom));
7881
}
7982

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Canvas.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,17 @@ public void test_setFontLorg_eclipse_swt_graphics_Font() {
108108
font.dispose();
109109
}
110110

111+
@Test
112+
public void test_CaretWithDisposedFontDoesNotThrowException_issue2323() {
113+
Caret caret = new Caret(canvas, SWT.NONE);
114+
Font font = new Font(canvas.getDisplay(), "Default", 10, SWT.BOLD);
115+
shell.open();
116+
caret.setFont(font);
117+
font.dispose();
118+
canvas.setFocus();
119+
canvas.setCaret(caret);
120+
}
121+
111122
/* custom*/
112123
@Test
113124
public void test_consistency_MenuDetect() {

0 commit comments

Comments
 (0)