Skip to content

Commit 8040707

Browse files
ShahzaibIbrahimHeikoKlare
authored andcommitted
[win32] Encapsulate Font handle with win32_getHandle
The handle of Font is encapsulated and exposed only via static method win32_getHandle and direct access to the field is replaced by access to that method.
1 parent f10721a commit 8040707

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

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

Lines changed: 22 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
@@ -172,7 +171,8 @@ public Font(Device device, String name, int height, int style) {
172171
super(device);
173172
if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
174173
this.zoom = DPIUtil.getNativeDeviceZoom();
175-
init(new FontData (name, height, style));
174+
FontData fd = new FontData (name, height, style);
175+
init(fd);
176176
this.fontHeight = height;
177177
init();
178178
}
@@ -181,7 +181,8 @@ public Font(Device device, String name, int height, int style) {
181181
super(device);
182182
if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
183183
this.zoom = DPIUtil.getNativeDeviceZoom();
184-
init(new FontData (name, height, style));
184+
FontData fd = new FontData (name, height, style);
185+
init(fd);
185186
this.fontHeight = height;
186187
init();
187188
}
@@ -285,6 +286,23 @@ public String toString () {
285286
return "Font {" + handle + "}";
286287
}
287288

289+
/**
290+
* Creates or returns a handle for the requested font.
291+
* <p>
292+
* <b>IMPORTANT:</b> This method is not part of the public API for
293+
* <code>Font</code>. It is marked public only so that it can be shared within
294+
* the packages provided by SWT. It is not available on all platforms, and
295+
* should never be called from application code.
296+
*
297+
* @param font the font to get the handle of
298+
* @return handle of the font
299+
*
300+
* @noreference This method is not intended to be referenced by clients.
301+
*/
302+
public static long win32_getHandle(Font font) {
303+
return font.handle;
304+
}
305+
288306
/**
289307
* Invokes platform specific functionality to allocate a new font.
290308
* <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
@@ -3439,7 +3439,7 @@ public void setFont (Font font) {
34393439
long hFont = 0;
34403440
if (newFont != null) {
34413441
if (newFont.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
3442-
hFont = newFont.handle;
3442+
hFont = Font.win32_getHandle(newFont);
34433443
}
34443444
this.font = newFont;
34453445
if (hFont == 0) hFont = defaultFont ();

0 commit comments

Comments
 (0)