Skip to content

Commit eb09fe5

Browse files
committed
Typify methods in OSSupport
These methods accept a plain Object, rather than an SWT widget. This was originally done to avoid a ClassCastException when the widgets were loaded by a different classloader. However, this type-cast is done regardless.
1 parent 60dc886 commit eb09fe5

File tree

6 files changed

+91
-32
lines changed

6 files changed

+91
-32
lines changed

org.eclipse.wb.os.linux/src/org/eclipse/wb/internal/os/linux/OSSupportLinux.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.eclipse.swt.widgets.Menu;
3636
import org.eclipse.swt.widgets.MenuItem;
3737
import org.eclipse.swt.widgets.Shell;
38+
import org.eclipse.swt.widgets.TabItem;
3839
import org.eclipse.swt.widgets.Tree;
3940
import org.eclipse.swt.widgets.Widget;
4041

@@ -140,8 +141,8 @@ private Shell getShell(Object controlObject) {
140141
}
141142

142143
@Override
143-
public void beginShot(Object controlObject) {
144-
Shell shell = layoutShell(controlObject);
144+
public void beginShot(Control control) {
145+
Shell shell = layoutShell(control);
145146
// setup key title to be used by compiz WM (if enabled)
146147
if (!isWorkaroundsDisabled()) {
147148
// prepare
@@ -171,10 +172,10 @@ public void beginShot(Object controlObject) {
171172
}
172173

173174
@Override
174-
public void endShot(Object controlObject) {
175+
public void endShot(Control control) {
175176
// hide shell. The shell should be visible during all the period of fetching visual data.
176-
super.endShot(controlObject);
177-
Shell shell = getShell(controlObject);
177+
super.endShot(control);
178+
Shell shell = getShell(control);
178179
if (!isWorkaroundsDisabled()) {
179180
_gtk_widget_hide(getShellHandle(shell));
180181
if (m_eclipseShell != null) {
@@ -184,8 +185,8 @@ public void endShot(Object controlObject) {
184185
}
185186

186187
@Override
187-
public void makeShots(Object controlObject) throws Exception {
188-
Shell shell = getShell(controlObject);
188+
public void makeShots(Control control) throws Exception {
189+
Shell shell = getShell(control);
189190
makeShots0(shell);
190191
// check for decorations and draw if needed
191192
drawDecorations(shell, shell.getDisplay());
@@ -518,7 +519,7 @@ public final int getDefaultMenuBarHeight() {
518519
//
519520
////////////////////////////////////////////////////////////////////////////
520521
@Override
521-
public final Rectangle getTabItemBounds(Object tabItem) {
522+
public final Rectangle getTabItemBounds(TabItem tabItem) {
522523
return getWidgetBounds(tabItem);
523524
}
524525

org.eclipse.wb.os.macosx/src/org/eclipse/wb/internal/os/macosx/OSSupportMacOSX.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,25 @@ protected OSSupportMacOSX() {
6767
}
6868

6969
@Override
70-
public void beginShot(Object controlObject) {
70+
public void beginShot(Control control) {
7171
// disabling shell redraw prevents painting events
7272
// to be dispatched to design canvas. These events can
7373
// cause painting already disposed images, ex., for action instances,
7474
// which are already disposed but image references are still alive
7575
// in it's presentation in widgets tree (see Case 40141).
7676
DesignerPlugin.getShell().setRedraw(false);
77-
super.beginShot(controlObject);
77+
super.beginShot(control);
7878
}
7979

8080
@Override
81-
public void endShot(Object controlObject) {
82-
super.endShot(controlObject);
81+
public void endShot(Control control) {
82+
super.endShot(control);
8383
DesignerPlugin.getShell().setRedraw(true);
8484
}
8585

8686
@Override
87-
public void makeShots(Object controlObject) throws Exception {
87+
public void makeShots(Control control) throws Exception {
8888
// do create shots
89-
Control control = (Control) controlObject;
9089
try {
9190
// reverseDrawingOrder(control);
9291
Image sourceShot = makeShot(control);
@@ -278,8 +277,7 @@ protected void fixupSeparatorItems(Menu menu, int[] bounds, int[] menuSize, int[
278277
}
279278

280279
@Override
281-
public Rectangle getTabItemBounds(Object item) {
282-
TabItem tabItem = (TabItem) item;
280+
public Rectangle getTabItemBounds(TabItem tabItem) {
283281
TabFolder folder = tabItem.getParent();
284282
GC gc = new GC(folder);
285283
Point folderSize = folder.getSize();

org.eclipse.wb.os.win32/src/org/eclipse/wb/internal/os/win32/OSSupportWin32.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ public abstract class OSSupportWin32<H extends Number> extends OSSupport {
6363
//
6464
////////////////////////////////////////////////////////////////////////////
6565
@Override
66-
public final void makeShots(Object controlObject) throws Exception {
67-
Control control = (Control) controlObject;
66+
public final void makeShots(Control control) throws Exception {
6867
try {
6968
reverseDrawingOrder(control);
7069
makeShotsHierarchy(control);
@@ -139,9 +138,9 @@ protected void makeShotImpl(Control control, GC gc) {
139138
//
140139
////////////////////////////////////////////////////////////////////////////
141140
@Override
142-
public final Rectangle getTabItemBounds(Object tabItemObject) {
143-
TabFolder tabFolder = ((TabItem) tabItemObject).getParent();
144-
int index = ArrayUtils.indexOf(tabFolder.getItems(), tabItemObject);
141+
public final Rectangle getTabItemBounds(TabItem tabItem) {
142+
TabFolder tabFolder = tabItem.getParent();
143+
int index = ArrayUtils.indexOf(tabFolder.getItems(), tabItem);
145144
int[] bounds = new int[4];
146145
getTabItemBounds(tabFolder, index, bounds);
147146
// convert into Rectangle

org.eclipse.wb.os/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-SymbolicName: org.eclipse.wb.os;singleton:=true
5-
Bundle-Version: 1.9.300.qualifier
5+
Bundle-Version: 1.10.0.qualifier
66
Bundle-Activator: org.eclipse.wb.os.Activator
77
Bundle-Vendor: %providerName
88
Require-Bundle: org.eclipse.ui;bundle-version="[3.206.0,4.0.0)",

org.eclipse.wb.os/src/org/eclipse/wb/os/OSSupport.java

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011 Google, Inc.
2+
* Copyright (c) 2011, 2025 Google, Inc. and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -86,17 +86,45 @@ private static OSSupport getInstance() {
8686
* Created image can be requested using {@link ToolkitSupport#getShotImage(Object)}.
8787
*
8888
* Note: the control may have <code>null</code> as image, ex. if the control has the invalid size.
89+
*
90+
* @deprecated Use {@link #makeShots(Control)} instead. This method will be
91+
* removed after the 2027-12 release.
92+
*/
93+
@Deprecated(forRemoval = true, since = "2025-12")
94+
public final void makeShots(Object control) throws Exception {
95+
makeShots((Control) control);
96+
}
97+
98+
/**
99+
* Prepares shots for all {@link Control}'s in hierarchy that have flag
100+
* {@link #WBP_NEED_IMAGE}. Created image can be requested using
101+
* {@link ToolkitSupport#getShotImage(Object)}.
102+
*
103+
* Note: the control may have <code>null</code> as image, ex. if the control has
104+
* the invalid size.
89105
*/
90-
public abstract void makeShots(Object control) throws Exception;
106+
public abstract void makeShots(Control control) throws Exception;
91107

92108
/**
93109
* Prepares the process of taking screen shot. Overridden in Linux.
94110
*
95111
* @param control
96112
* the {@link Control}.
113+
* @deprecated Use {@link #beginShot(Control)} instead. This method will be
114+
* removed after the 2027-12 release.
115+
*/
116+
@Deprecated(forRemoval = true, since = "2025-12")
117+
public final void beginShot(Object controlObject) {
118+
beginShot((Control) controlObject);
119+
}
120+
121+
/**
122+
* Prepares the process of taking screen shot. Overridden in Linux.
123+
*
124+
* @param control the {@link Control}.
97125
*/
98-
public void beginShot(Object controlObject) {
99-
Shell shell = layoutShell(controlObject);
126+
public void beginShot(Control control) {
127+
Shell shell = layoutShell(control);
100128
// make visible
101129
makeShellVisible(shell);
102130
}
@@ -109,6 +137,11 @@ protected void makeShellVisible(Shell shell) {
109137
shell.setVisible(true);
110138
}
111139

140+
/**
141+
* @deprecated Use {@link #layoutShell(Control)} instead. This method will be
142+
* removed after the 2027-12 release.
143+
*/
144+
@Deprecated(forRemoval = true, since = "2025-12")
112145
protected final Shell layoutShell(Object controlObject) {
113146
Control control = (Control) controlObject;
114147
Shell shell = control.getShell();
@@ -117,6 +150,13 @@ protected final Shell layoutShell(Object controlObject) {
117150
return shell;
118151
}
119152

153+
protected final Shell layoutShell(Control control) {
154+
Shell shell = control.getShell();
155+
doLayout(shell);
156+
fixZeroSizes_begin(shell);
157+
return shell;
158+
}
159+
120160
/**
121161
* Ensures that layout is performed for all {@link Composite}-s, even if some of them are in
122162
* "null" layout, so layout request is not propagated to them automatically.
@@ -140,9 +180,20 @@ private static void doLayout(Control control) {
140180
*
141181
* @param control
142182
* the {@link Control}.
183+
* @deprecated Use {@link #endShot(Control)} instead. This method will
184+
* be removed after the 2027-12 release.
143185
*/
144-
public void endShot(Object controlObject) {
145-
Control control = (Control) controlObject;
186+
@Deprecated(forRemoval = true, since = "2025-12")
187+
public final void endShot(Object controlObject) {
188+
endShot((Control) controlObject);
189+
}
190+
191+
/**
192+
* Finalizes the process of taking screen shot. Overridden in Linux.
193+
*
194+
* @param control the {@link Control}.
195+
*/
196+
public void endShot(Control control) {
146197
fixZeroSizes_end(control);
147198
Shell shell = control.getShell();
148199
shell.setVisible(false);
@@ -152,7 +203,7 @@ public void endShot(Object controlObject) {
152203
* Return the {@link Image} of given {@link Control}.
153204
*
154205
* Note: may return <code>null</code> as image, ex. if the control has the invalid size. See also
155-
* {@link OSSupport#makeShots(Object)}.
206+
* {@link OSSupport#makeShots(Control)}.
156207
*
157208
* @return the {@link Image} of given {@link Control}.
158209
*/
@@ -209,10 +260,20 @@ private static void fixZeroSizes_end(Control control) {
209260
// TabItem bounds
210261
//
211262
////////////////////////////////////////////////////////////////////////////
263+
/**
264+
* @return the bounds of {@link TabItem}.
265+
* @deprecated Use {@link #getTabItemBounds(TabItem)} instead. This method will
266+
* be removed after the 2027-12 release.
267+
*/
268+
@Deprecated(forRemoval = true, since = "2025-12")
269+
public final Rectangle getTabItemBounds(Object item) {
270+
return getTabItemBounds((TabItem) item);
271+
}
272+
212273
/**
213274
* @return the bounds of {@link TabItem}.
214275
*/
215-
public abstract Rectangle getTabItemBounds(Object item);
276+
public abstract Rectangle getTabItemBounds(TabItem item);
216277

217278
////////////////////////////////////////////////////////////////////////////
218279
//

org.eclipse.wb.rcp/src/org/eclipse/wb/internal/rcp/model/widgets/TabItemInfo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011, 2024 Google, Inc. and others.
2+
* Copyright (c) 2011, 2025 Google, Inc. and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -54,7 +54,7 @@ protected void refresh_fetch() throws Exception {
5454
super.refresh_fetch();
5555
// set bounds
5656
{
57-
Rectangle bounds = new Rectangle(OSSupport.get().getTabItemBounds(getObject()));
57+
Rectangle bounds = new Rectangle(OSSupport.get().getTabItemBounds(getWidget()));
5858
setModelBounds(bounds);
5959
}
6060
}

0 commit comments

Comments
 (0)