Skip to content

Commit 20392c2

Browse files
Replace usages of new Image(device, width, height)
Fixing it with test intact.
1 parent 9d3227d commit 20392c2

File tree

1 file changed

+29
-8
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets

1 file changed

+29
-8
lines changed

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

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,14 +1581,25 @@ LRESULT WM_PAINT (long wParam, long lParam) {
15811581
GC paintGC = null;
15821582
Image image = null;
15831583
if ((style & (SWT.DOUBLE_BUFFERED | SWT.TRANSPARENT)) != 0) {
1584-
image = new Image (display, width, height);
15851584
paintGC = gc;
1586-
gc = new GC (image, paintGC.getStyle() & SWT.RIGHT_TO_LEFT);
1587-
GCData gcData = gc.getGCData ();
1588-
gcData.uiState = data.uiState;
1589-
gc.setForeground (getForeground ());
1590-
gc.setBackground (getBackground ());
1591-
gc.setFont (getFont ());
1585+
int originalStyle = gc.getStyle();
1586+
ImageGcDrawer drawer = new ImageGcDrawer() {
1587+
@Override
1588+
public void drawOn(GC gc, int iWidth, int iHeight) {
1589+
GCData gcData = gc.getGCData ();
1590+
gcData.uiState = data.uiState;
1591+
gc.setForeground (getForeground ());
1592+
gc.setBackground (getBackground ());
1593+
gc.setFont (getFont ());
1594+
}
1595+
1596+
@Override
1597+
public int getGcStyle() {
1598+
return originalStyle & SWT.RIGHT_TO_LEFT;
1599+
}
1600+
};
1601+
image = new Image (display, drawer, width, height);
1602+
gc = new GC(image, originalStyle & SWT.RIGHT_TO_LEFT);
15921603
if ((style & SWT.TRANSPARENT) != 0) {
15931604
OS.BitBlt (gc.handle, 0, 0, width, height, paintGC.handle, ps.left, ps.top, OS.SRCCOPY);
15941605
}
@@ -1598,6 +1609,16 @@ LRESULT WM_PAINT (long wParam, long lParam) {
15981609
OS.SetMetaRgn (gc.handle);
15991610
OS.SetWindowOrgEx (gc.handle, ps.left, ps.top, null);
16001611
OS.SetBrushOrgEx (gc.handle, ps.left, ps.top, null);
1612+
1613+
if ((style & (SWT.NO_BACKGROUND | SWT.TRANSPARENT)) != 0) {
1614+
/* This code is intentionally commented because it may be slow to copy bits from the screen */
1615+
//newPaintGC.copyArea (image, ps.left, ps.top);
1616+
} else {
1617+
RECT rect = new RECT ();
1618+
OS.SetRect (rect, ps.left, ps.top, ps.right, ps.bottom);
1619+
drawBackground (gc.handle, rect);
1620+
}
1621+
16011622
if ((style & (SWT.NO_BACKGROUND | SWT.TRANSPARENT)) != 0) {
16021623
/* This code is intentionally commented because it may be slow to copy bits from the screen */
16031624
//paintGC.copyArea (image, ps.left, ps.top);
@@ -1642,10 +1663,10 @@ LRESULT WM_PAINT (long wParam, long lParam) {
16421663
GCData gcData = gc.getGCData ();
16431664
if (gcData.focusDrawn && !isDisposed ()) updateUIState ();
16441665
}
1645-
gc.dispose();
16461666
if (!isDisposed ()) {
16471667
paintGC.drawImage (image, DPIUtil.scaleDown(ps.left, zoom), DPIUtil.scaleDown(ps.top, zoom));
16481668
}
1669+
gc.dispose();
16491670
image.dispose ();
16501671
gc = paintGC;
16511672
}

0 commit comments

Comments
 (0)