Skip to content

Commit 44b0bf0

Browse files
[win32] Refactoring handle field with win32_getHandle
new static method win32_getHanlde is introduced to get handle instead of directly accessing the handle field
1 parent ee0fdb8 commit 44b0bf0

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ public final class Font extends Resource {
4646
* platforms and should never be accessed from application code.
4747
* </p>
4848
*
49-
* @noreference This field is not intended to be referenced by clients.
5049
*/
51-
public long handle;
50+
private long handle;
5251

5352
/**
5453
* The zoom in % of the standard resolution used for conversion of point height to pixel height
@@ -181,7 +180,8 @@ public Font(Device device, String name, int height, int style) {
181180
super(device);
182181
if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
183182
this.zoom = DPIUtil.getNativeDeviceZoom();
184-
init(new FontData (name, height, style));
183+
FontData fd = new FontData (name, height, style);
184+
init(fd);
185185
this.fontHeight = height;
186186
init();
187187
}
@@ -190,7 +190,8 @@ public Font(Device device, String name, int height, int style) {
190190
super(device);
191191
if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
192192
this.zoom = DPIUtil.getNativeDeviceZoom();
193-
init(new FontData (name, height, style));
193+
FontData fd = new FontData (name, height, style);
194+
init(fd);
194195
this.fontHeight = height;
195196
init();
196197
}
@@ -294,6 +295,25 @@ public String toString () {
294295
return "Font {" + handle + "}";
295296
}
296297

298+
/**
299+
* <b>IMPORTANT:</b> This method is not part of the public
300+
* API for Font. It is marked public only so that it
301+
* can be shared within the packages provided by SWT. It is not
302+
* available on all platforms, and should never be called from
303+
* application code.
304+
*
305+
* Creates a new handle for the requested font
306+
*
307+
* @param font the font to get the handle of
308+
*
309+
* @return handle of the font
310+
*
311+
* @noreference This method is not intended to be referenced by clients.
312+
*/
313+
public static long win32_getHandle (Font font) {
314+
return font.handle;
315+
}
316+
297317
/**
298318
* Invokes platform specific functionality to allocate a new font.
299319
* <p>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static Font getSystemFont(Device device, int zoom) {
4848
}
4949

5050
public static long getSystemFontHandle(Device device, int zoom) {
51-
return getSystemFont(device, zoom).handle;
51+
return Font.win32_getHandle(getSystemFont(device, zoom));
5252
}
5353

5454
/**
@@ -67,14 +67,14 @@ public static Font getFont(Device device, FontData fontData, int zoom) {
6767
}
6868

6969
public static long getFontHandle(Device device, FontData fontData, int zoom) {
70-
return getFont(device, fontData, zoom).handle;
70+
return Font.win32_getHandle(getFont(device, fontData, zoom));
7171
}
7272

7373
public static long getFontHandle(Font font, int zoom) {
7474
if (font == null) {
7575
SWT.error(SWT.ERROR_NULL_ARGUMENT);
7676
}
77-
return getFont(font.getDevice(), font.getFontData()[0], zoom).handle;
77+
return Font.win32_getHandle(getFont(font.getDevice(), font.getFontData()[0], zoom));
7878
}
7979

8080
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ private Font getScaledFont(int zoom) {
4444

4545
private Font createAndCacheFont(int zoom) {
4646
Font newFont = createFont(zoom);
47-
customFontHandlesKeyMap.put(newFont.handle, this);
47+
customFontHandlesKeyMap.put(Font.win32_getHandle(newFont), this);
4848
scaledFonts.put(zoom, newFont);
4949
return newFont;
5050
}

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3441,7 +3441,7 @@ public void setFont (Font font) {
34413441
long hFont = 0;
34423442
if (newFont != null) {
34433443
if (newFont.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
3444-
hFont = newFont.handle;
3444+
hFont = Font.win32_getHandle(newFont);
34453445
}
34463446
this.font = newFont;
34473447
if (hFont == 0) hFont = defaultFont ();

0 commit comments

Comments
 (0)