15
15
import org .eclipse .swt .SWT ;
16
16
import org .eclipse .swt .graphics .Color ;
17
17
import org .eclipse .swt .graphics .Rectangle ;
18
+ import org .eclipse .swt .widgets .Canvas ;
18
19
import org .eclipse .swt .widgets .Control ;
19
20
import org .eclipse .swt .widgets .Shell ;
20
21
21
22
import org .eclipse .draw2d .geometry .Dimension ;
23
+ import org .eclipse .draw2d .internal .InternalDraw2dUtils ;
22
24
23
25
/**
24
26
* Provides abstract support for classes that manage popups. Popups in Draw2d
@@ -62,7 +64,7 @@ protected PopUpHelper(Control c) {
62
64
*/
63
65
protected PopUpHelper (Control c , int shellStyle ) {
64
66
control = c ;
65
- this .shellStyle = shellStyle | SWT .NO_BACKGROUND | SWT .NO_REDRAW_RESIZE ;
67
+ this .shellStyle = shellStyle | SWT .NO_BACKGROUND | SWT .NO_REDRAW_RESIZE | SWT . DOUBLE_BUFFERED ;
66
68
}
67
69
68
70
/**
@@ -72,9 +74,8 @@ protected PopUpHelper(Control c, int shellStyle) {
72
74
* @return the newly created LightweightSystem
73
75
* @since 2.0
74
76
*/
75
- @ SuppressWarnings ("static-method" )
76
77
protected LightweightSystem createLightweightSystem () {
77
- return new LightweightSystem ();
78
+ return InternalDraw2dUtils . disableAutoscale ? new PopupHelperLightweightSystem () : new LightweightSystem ();
78
79
}
79
80
80
81
/**
@@ -219,4 +220,66 @@ protected void show() {
219
220
tipShowing = true ;
220
221
}
221
222
223
+ private class PopupHelperLightweightSystem extends LightweightSystem {
224
+
225
+ /**
226
+ * Data that can be set to scale this widget at 100%.
227
+ */
228
+ private static final String DATA_AUTOSCALE_DISABLED = "AUTOSCALE_DISABLED" ; //$NON-NLS-1$
229
+
230
+ /**
231
+ * Returns the zoom of the monitor this widget is assigned to.
232
+ *
233
+ * @return 1.0 at 100%, 1.25 at 125% etc.
234
+ */
235
+ private static double getMonitorZoomScale (Control c ) {
236
+ try {
237
+ return c .getMonitor ().getZoom () / 100.0 ;
238
+ } catch (NullPointerException e ) {
239
+ return 1.0 ;
240
+ }
241
+ }
242
+
243
+ /**
244
+ * The scalable pane that is injected between the root figure and the contents
245
+ * of this viewport.
246
+ */
247
+ private final ScalableLayeredPane scalablePane ;
248
+
249
+ private PopupHelperLightweightSystem () {
250
+ scalablePane = new ScalableLayeredPane (true );
251
+ scalablePane .setLayoutManager (new StackLayout ());
252
+ getRootFigure ().add (scalablePane );
253
+ }
254
+
255
+ /**
256
+ * Updates the scale factor of the scalable pane to the given value.
257
+ *
258
+ * @param scale The new scale factor.
259
+ */
260
+ private void setScale (double scale ) {
261
+ scalablePane .setScale (scale );
262
+ }
263
+
264
+ @ Override
265
+ public void setControl (Canvas c ) {
266
+ if (c == null ) {
267
+ return ;
268
+ }
269
+
270
+ c .setData (DATA_AUTOSCALE_DISABLED , true );
271
+ c .addListener (SWT .ZoomChanged , e -> setScale (e .detail / 100.0 ));
272
+ setScale (getMonitorZoomScale (c ));
273
+
274
+ super .setControl (c );
275
+ }
276
+
277
+ @ Override
278
+ public void setContents (IFigure figure ) {
279
+ scalablePane .removeAll ();
280
+ if (figure != null ) {
281
+ scalablePane .add (figure );
282
+ }
283
+ }
284
+ }
222
285
}
0 commit comments