Skip to content

Commit fb7c2fb

Browse files
HeikoKlareclaude
andcommitted
[Win32] Remove OS.IsAppThemed() — always true on Windows 10+
Windows Classic theme was removed in Windows 8. Since SWT targets Windows 10 and later, OS.IsAppThemed() unconditionally returns true, making every !OS.IsAppThemed() branch unreachable dead code and every if (OS.IsAppThemed()) guard reducible to its body. Removes all 70+ call sites across 21 widget files: - Dead !OS.IsAppThemed() else-branches are deleted (Classic theme fallbacks for DrawFrameControl, DFCS_* drawing, TBSTYLE_TRANSPARENT clearing, RTL text-clipping space-padding, ILC_MASK flag, etc.) - if (OS.IsAppThemed()) guards are unwrapped to unconditional code (Explorer theme setup in Tree/Table createHandle, themed checkbox image lists in Tree/Table, THEME_BACKGROUND checks, wmColorChild, WM_ERASEBKGND, WM_MOVE, wmNCPaint, widgetStyle bits, etc.) - Ternary OS.IsAppThemed() ? x : y expressions replaced with x (Group offsetY adjustments, ToolBar widgetStyle TBSTYLE_TRANSPARENT) - Stale TEMPORARY CODE commented-out blocks removed (CoolBar, TabFolder) - Group.fixText(boolean enabled): enabled parameter removed as it became unused once the Classic-theme space-padding workaround was deleted - OS.IsAppThemed() declaration removed from OS.java (and auto-generated os.c / os_stats.h updated accordingly) The following OS.java declarations became unused as a result and are also removed: - OS.DrawFrameControl() and its eleven associated constants (DFCS_BUTTONCHECK, DFCS_CHECKED, DFCS_FLAT, DFCS_INACTIVE, DFCS_PUSHED, DFCS_SCROLLDOWN, DFCS_SCROLLLEFT, DFCS_SCROLLRIGHT, DFCS_SCROLLUP, DFC_BUTTON, DFC_SCROLL) — only used in the non-themed checkbox and arrow-button drawing fallbacks - OS.ImageList_AddMasked() — only used in the non-themed setCheckboxImageList() path (replaced by ImageList_Add) - OS.BS_BITMAP and OS.BS_ICON — only used in the non-themed Button.enableWidget() RTL clipping workaround Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 1122a9d commit fb7c2fb

23 files changed

Lines changed: 369 additions & 785 deletions

File tree

bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os.c

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,21 +1421,6 @@ JNIEXPORT jboolean JNICALL OS_NATIVE(DrawFocusRect)
14211421
}
14221422
#endif
14231423

1424-
#ifndef NO_DrawFrameControl
1425-
JNIEXPORT jboolean JNICALL OS_NATIVE(DrawFrameControl)
1426-
(JNIEnv *env, jclass that, jlong arg0, jobject arg1, jint arg2, jint arg3)
1427-
{
1428-
RECT _arg1, *lparg1=NULL;
1429-
jboolean rc = 0;
1430-
OS_NATIVE_ENTER(env, that, DrawFrameControl_FUNC);
1431-
if (arg1) if ((lparg1 = getRECTFields(env, arg1, &_arg1)) == NULL) goto fail;
1432-
rc = (jboolean)DrawFrameControl((HDC)arg0, lparg1, arg2, arg3);
1433-
fail:
1434-
OS_NATIVE_EXIT(env, that, DrawFrameControl_FUNC);
1435-
return rc;
1436-
}
1437-
#endif
1438-
14391424
#ifndef NO_DrawIconEx
14401425
JNIEXPORT jboolean JNICALL OS_NATIVE(DrawIconEx)
14411426
(JNIEnv *env, jclass that, jlong arg0, jint arg1, jint arg2, jlong arg3, jint arg4, jint arg5, jint arg6, jlong arg7, jint arg8)
@@ -3880,18 +3865,6 @@ JNIEXPORT jint JNICALL OS_NATIVE(ImageList_1Add)
38803865
}
38813866
#endif
38823867

3883-
#ifndef NO_ImageList_1AddMasked
3884-
JNIEXPORT jint JNICALL OS_NATIVE(ImageList_1AddMasked)
3885-
(JNIEnv *env, jclass that, jlong arg0, jlong arg1, jint arg2)
3886-
{
3887-
jint rc = 0;
3888-
OS_NATIVE_ENTER(env, that, ImageList_1AddMasked_FUNC);
3889-
rc = (jint)ImageList_AddMasked((HIMAGELIST)arg0, (HBITMAP)arg1, (COLORREF)arg2);
3890-
OS_NATIVE_EXIT(env, that, ImageList_1AddMasked_FUNC);
3891-
return rc;
3892-
}
3893-
#endif
3894-
38953868
#ifndef NO_ImageList_1BeginDrag
38963869
JNIEXPORT jboolean JNICALL OS_NATIVE(ImageList_1BeginDrag)
38973870
(JNIEnv *env, jclass that, jlong arg0, jint arg1, jint arg2, jint arg3)
@@ -4442,18 +4415,6 @@ JNIEXPORT jboolean JNICALL OS_NATIVE(InvalidateRgn)
44424415
}
44434416
#endif
44444417

4445-
#ifndef NO_IsAppThemed
4446-
JNIEXPORT jboolean JNICALL OS_NATIVE(IsAppThemed)
4447-
(JNIEnv *env, jclass that)
4448-
{
4449-
jboolean rc = 0;
4450-
OS_NATIVE_ENTER(env, that, IsAppThemed_FUNC);
4451-
rc = (jboolean)IsAppThemed();
4452-
OS_NATIVE_EXIT(env, that, IsAppThemed_FUNC);
4453-
return rc;
4454-
}
4455-
#endif
4456-
44574418
#ifndef NO_IsHungAppWindow
44584419
JNIEXPORT jboolean JNICALL OS_NATIVE(IsHungAppWindow)
44594420
(JNIEnv *env, jclass that, jlong arg0)

bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_stats.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ typedef enum {
129129
DragQueryFile_FUNC,
130130
DrawEdge_FUNC,
131131
DrawFocusRect_FUNC,
132-
DrawFrameControl_FUNC,
133132
DrawIconEx_FUNC,
134133
DrawMenuBar_FUNC,
135134
DrawText_FUNC,
@@ -304,7 +303,6 @@ typedef enum {
304303
INITCOMMONCONTROLSEX_1sizeof_FUNC,
305304
INPUT_1sizeof_FUNC,
306305
ImageList_1Add_FUNC,
307-
ImageList_1AddMasked_FUNC,
308306
ImageList_1BeginDrag_FUNC,
309307
ImageList_1Create_FUNC,
310308
ImageList_1Destroy_FUNC,
@@ -344,7 +342,6 @@ typedef enum {
344342
IntersectRect_FUNC,
345343
InvalidateRect_FUNC,
346344
InvalidateRgn_FUNC,
347-
IsAppThemed_FUNC,
348345
IsDarkModeAvailable_FUNC,
349346
IsHungAppWindow_FUNC,
350347
IsIconic_FUNC,

bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,12 @@ public class OS extends C {
134134
public static final int BST_INDETERMINATE = 0x2;
135135
public static final int BST_UNCHECKED = 0x0;
136136
public static final int BS_3STATE = 0x5;
137-
public static final int BS_BITMAP = 0x80;
138137
public static final int BS_CENTER = 0x300;
139138
public static final int BS_CHECKBOX = 0x2;
140139
public static final int BS_COMMANDLINK = 0xe;
141140
public static final int BS_DEFPUSHBUTTON = 0x1;
142141
public static final int BS_FLAT = 0x8000;
143142
public static final int BS_GROUPBOX = 0x7;
144-
public static final int BS_ICON = 0x40;
145143
public static final int BS_LEFT = 0x100;
146144
public static final int BS_MULTILINE = 0x2000;
147145
public static final int BS_NOTIFY = 0x4000;
@@ -309,17 +307,7 @@ public class OS extends C {
309307
public static final int DCX_CACHE = 0x2;
310308
public static final int DEFAULT_CHARSET = 0x1;
311309
public static final int DEFAULT_GUI_FONT = 0x11;
312-
public static final int DFCS_BUTTONCHECK = 0x0;
313-
public static final int DFCS_CHECKED = 0x400;
314-
public static final int DFCS_FLAT = 0x4000;
315-
public static final int DFCS_INACTIVE = 0x100;
316-
public static final int DFCS_PUSHED = 0x200;
317-
public static final int DFCS_SCROLLDOWN = 0x1;
318-
public static final int DFCS_SCROLLLEFT = 0x2;
319-
public static final int DFCS_SCROLLRIGHT = 0x3;
320-
public static final int DFCS_SCROLLUP = 0x0;
321-
public static final int DFC_BUTTON = 0x4;
322-
public static final int DFC_SCROLL = 0x3;
310+
323311
public static final int DIB_RGB_COLORS = 0x0;
324312
public static final int DI_NORMAL = 0x3;
325313
public static final int DI_NOMIRROR = 0x10;
@@ -2605,11 +2593,7 @@ public static int HRESULT_FROM_WIN32(int x) {
26052593
* @param lpRect flags=no_out
26062594
*/
26072595
public static final native boolean DrawFocusRect (long hDC, RECT lpRect);
2608-
/**
2609-
* @param hdc cast=(HDC)
2610-
* @param lprc flags=no_out
2611-
*/
2612-
public static final native boolean DrawFrameControl (long hdc, RECT lprc, int uType, int uState);
2596+
26132597
/**
26142598
* @param hdc cast=(HDC)
26152599
* @param hIcon cast=(HICON)
@@ -3108,12 +3092,7 @@ public static int HRESULT_FROM_WIN32(int x) {
31083092
* @param hbmMask cast=(HBITMAP)
31093093
*/
31103094
public static final native int ImageList_Add (long himl, long hbmImage, long hbmMask);
3111-
/**
3112-
* @param himl cast=(HIMAGELIST)
3113-
* @param hbmImage cast=(HBITMAP)
3114-
* @param crMask cast=(COLORREF)
3115-
*/
3116-
public static final native int ImageList_AddMasked (long himl, long hbmImage, int crMask);
3095+
31173096
/** @param himl cast=(HIMAGELIST) */
31183097
public static final native boolean ImageList_BeginDrag (long himl, int iTrack, int dxHotspot, int dyHotspot);
31193098
public static final native long ImageList_Create (int cx, int cy, int flags, int cInitial, int cGrow);
@@ -3254,7 +3233,6 @@ public static int HRESULT_FROM_WIN32(int x) {
32543233
* @param hRgn cast=(HRGN)
32553234
*/
32563235
public static final native boolean InvalidateRgn (long hWnd, long hRgn, boolean bErase);
3257-
public static final native boolean IsAppThemed ();
32583236
/** @method flags=no_gen */
32593237
public static final native boolean IsDarkModeAvailable();
32603238
/** @param hWnd cast=(HWND) */

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

Lines changed: 30 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,6 @@ void _setText (String text) {
211211
* is disabled, the first pixel of the text is clipped. The fix
212212
* is to append a space to the text.
213213
*/
214-
if ((style & SWT.RIGHT_TO_LEFT) != 0) {
215-
if (!OS.IsAppThemed ()) {
216-
text = OS.IsWindowEnabled (handle) ? text : text + " ";
217-
}
218-
}
219214
TCHAR buffer = new TCHAR (getCodePage (), text, true);
220215
OS.SetWindowText (handle, buffer);
221216
if ((state & HAS_AUTO_DIRECTION) != 0) {
@@ -391,12 +386,6 @@ Point computeSizeInPixels (Point hintInPoints, int zoom, boolean changed) {
391386
} else {
392387
rect.right -= 6;
393388
}
394-
if (!OS.IsAppThemed ()) {
395-
rect.right -= 2;
396-
if (isRadioOrCheck()) {
397-
rect.right -= 2;
398-
}
399-
}
400389
}
401390
OS.DrawText (hDC, buffer, buffer.length, rect, flags);
402391
width += rect.right - rect.left;
@@ -436,37 +425,31 @@ void createHandle () {
436425
super.createHandle ();
437426
parent.state &= ~IGNORE_WM_CHANGEUISTATE;
438427

439-
if (OS.IsAppThemed ()) {
440-
/* Set the theme background.
441-
*
442-
* NOTE: On Vista this causes problems when the tab
443-
* key is pressed for push buttons so disable the
444-
* theme background drawing for these widgets for
445-
* now.
446-
*/
447-
if ((style & (SWT.PUSH | SWT.TOGGLE)) == 0) {
448-
state |= THEME_BACKGROUND;
449-
}
450-
451-
/*
452-
* Bug in Windows. For some reason, the HBRUSH that
453-
* is returned from WM_CTRLCOLOR is misaligned when
454-
* the button uses it to draw. If the brush is a solid
455-
* color, this does not matter. However, if the brush
456-
* contains an image, the image is misaligned. The
457-
* fix is to draw the background in WM_CTRLCOLOR.
458-
*
459-
* NOTE: For comctl32.dll 6.0 with themes disabled,
460-
* drawing in WM_ERASEBKGND will draw on top of the
461-
* text of the control.
462-
*/
463-
if ((style & SWT.RADIO) != 0) {
464-
state |= DRAW_BACKGROUND;
465-
}
428+
/* Set the theme background.
429+
*
430+
* NOTE: On Vista this causes problems when the tab
431+
* key is pressed for push buttons so disable the
432+
* theme background drawing for these widgets for
433+
* now.
434+
*/
435+
if ((style & (SWT.PUSH | SWT.TOGGLE)) == 0) {
436+
state |= THEME_BACKGROUND;
437+
}
466438

467-
useDarkModeExplorerTheme = display.useDarkModeExplorerTheme;
468-
maybeEnableDarkSystemTheme();
439+
/*
440+
* Bug in Windows. For some reason, the HBRUSH that
441+
* is returned from WM_CTRLCOLOR is misaligned when
442+
* the button uses it to draw. If the brush is a solid
443+
* color, this does not matter. However, if the brush
444+
* contains an image, the image is misaligned. The
445+
* fix is to draw the background in WM_CTRLCOLOR.
446+
*/
447+
if ((style & SWT.RADIO) != 0) {
448+
state |= DRAW_BACKGROUND;
469449
}
450+
451+
useDarkModeExplorerTheme = display.useDarkModeExplorerTheme;
452+
maybeEnableDarkSystemTheme();
470453
}
471454

472455
private boolean customBackgroundDrawing() {
@@ -498,22 +481,6 @@ int defaultForeground () {
498481
void enableWidget (boolean enabled) {
499482
super.enableWidget (enabled);
500483
/*
501-
* Bug in Windows. When a Button control is right-to-left and
502-
* is disabled, the first pixel of the text is clipped. The fix
503-
* is to append a space to the text.
504-
*/
505-
if ((style & SWT.RIGHT_TO_LEFT) != 0) {
506-
if (!OS.IsAppThemed ()) {
507-
int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
508-
boolean hasImage = (bits & (OS.BS_BITMAP | OS.BS_ICON)) != 0;
509-
if (!hasImage) {
510-
String string = enabled ? text : text + " ";
511-
TCHAR buffer = new TCHAR (getCodePage (), string, true);
512-
OS.SetWindowText (handle, buffer);
513-
}
514-
}
515-
}
516-
/*
517484
* Bug in Windows. When a button has the style BS_CHECKBOX
518485
* or BS_RADIOBUTTON, is checked, and is displaying both an
519486
* image and some text, when BCM_SETIMAGELIST is used to
@@ -1257,9 +1224,7 @@ LRESULT WM_UPDATEUISTATE (long wParam, long lParam) {
12571224
boolean redraw = findImageControl () != null;
12581225
if (!redraw) {
12591226
if ((state & THEME_BACKGROUND) != 0) {
1260-
if (OS.IsAppThemed ()) {
1261-
redraw = findThemeControl () != null;
1262-
}
1227+
redraw = findThemeControl () != null;
12631228
}
12641229
if (!redraw) redraw = findBackgroundControl () != null;
12651230
}
@@ -1311,12 +1276,8 @@ private int getCheckboxTextOffset(long hdc) {
13111276

13121277
SIZE size = new SIZE();
13131278

1314-
if (OS.IsAppThemed ()) {
1315-
OS.GetThemePartSize(display.hButtonTheme(nativeZoom), hdc, OS.BP_CHECKBOX, OS.CBS_UNCHECKEDNORMAL, null, OS.TS_TRUE, size);
1316-
result += size.cx;
1317-
} else {
1318-
result += DPIUtil.pointToPixel(13, nativeZoom);
1319-
}
1279+
OS.GetThemePartSize(display.hButtonTheme(nativeZoom), hdc, OS.BP_CHECKBOX, OS.CBS_UNCHECKEDNORMAL, null, OS.TS_TRUE, size);
1280+
result += size.cx;
13201281

13211282
// Windows uses half width of '0' as checkbox-to-text distance.
13221283
OS.GetTextExtentPoint32(hdc, STRING_WITH_ZERO_CHAR, 1, size);
@@ -1540,24 +1501,10 @@ LRESULT wmDrawChild (long wParam, long lParam) {
15401501
OS.MoveMemory (struct, lParam, DRAWITEMSTRUCT.sizeof);
15411502
RECT rect = new RECT ();
15421503
OS.SetRect (rect, struct.left, struct.top, struct.right, struct.bottom);
1543-
if (OS.IsAppThemed ()) {
1544-
boolean pressed = ((struct.itemState & OS.ODS_SELECTED) != 0);
1545-
boolean enabled = getEnabled ();
1546-
int iStateId = getThemeStateId(style, pressed, enabled);
1547-
OS.DrawThemeBackground (display.hScrollBarThemeAuto(nativeZoom), struct.hDC, OS.SBP_ARROWBTN, iStateId, rect, null);
1548-
} else {
1549-
int uState = OS.DFCS_SCROLLLEFT;
1550-
switch (style & (SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT)) {
1551-
case SWT.UP: uState = OS.DFCS_SCROLLUP; break;
1552-
case SWT.DOWN: uState = OS.DFCS_SCROLLDOWN; break;
1553-
case SWT.LEFT: uState = OS.DFCS_SCROLLLEFT; break;
1554-
case SWT.RIGHT: uState = OS.DFCS_SCROLLRIGHT; break;
1555-
}
1556-
if (!getEnabled ()) uState |= OS.DFCS_INACTIVE;
1557-
if ((style & SWT.FLAT) == SWT.FLAT) uState |= OS.DFCS_FLAT;
1558-
if ((struct.itemState & OS.ODS_SELECTED) != 0) uState |= OS.DFCS_PUSHED;
1559-
OS.DrawFrameControl (struct.hDC, rect, OS.DFC_SCROLL, uState);
1560-
}
1504+
boolean pressed = ((struct.itemState & OS.ODS_SELECTED) != 0);
1505+
boolean enabled = getEnabled ();
1506+
int iStateId = getThemeStateId(style, pressed, enabled);
1507+
OS.DrawThemeBackground (display.hScrollBarThemeAuto(nativeZoom), struct.hDC, OS.SBP_ARROWBTN, iStateId, rect, null);
15611508
return null;
15621509
}
15631510

0 commit comments

Comments
 (0)