summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorRaymond Lam2011-09-06 15:07:11 (EDT)
committer Felipe Heidrich2011-09-07 10:59:13 (EDT)
commita07ed48fb9192d9cee2a365d410ac695fd1c5098 (patch)
treeda9e67ef1cd1514bd4899f49de9936de3f4d7741
parent7adb8daca7b13962394692d32a959c73811bf47b (diff)
downloadeclipse.platform.swt-a07ed48fb9192d9cee2a365d410ac695fd1c5098.zip
eclipse.platform.swt-a07ed48fb9192d9cee2a365d410ac695fd1c5098.tar.gz
eclipse.platform.swt-a07ed48fb9192d9cee2a365d410ac695fd1c5098.tar.bz2
Add drawBackgroundBufferred to Control and refactor painting of Label text to use wmDrawChild.
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java12
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Label.java162
2 files changed, 50 insertions, 124 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java
index 6759028..641c43c 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java
@@ -917,6 +917,10 @@ void drawBackground (int /*long*/ hDC) {
}
void drawBackground (int /*long*/ hDC, RECT rect) {
+ if ((this.style & SWT.TRIM_FILL) != 0) {
+ drawBackgroundBuffered(hDC, rect);
+ return;
+ }
drawBackground (hDC, rect, -1, 0, 0);
}
@@ -944,6 +948,14 @@ void drawBackground (int /*long*/ hDC, RECT rect, int pixel, int tx, int ty) {
fillBackground (hDC, pixel, rect);
}
+void drawBackgroundBuffered (int /*long*/ hDC, RECT rect) {
+ int /*long*/ [] hdcBuffered = new int /*long*/ [1];
+ int /*long*/ hBufferedPaint = OS.BeginBufferedPaint(hDC, rect, OS.BPBF_TOPDOWNDIB, null, hdcBuffered);
+ OS.PatBlt(hdcBuffered[0], 0, 0, rect.right - rect.left, rect.bottom - rect.top, OS.BLACKNESS);
+ OS.BufferedPaintSetAlpha(hBufferedPaint, rect, (byte)0x00);
+ OS.EndBufferedPaint(hBufferedPaint, true);
+}
+
void drawImageBackground (int /*long*/ hDC, int /*long*/ hwnd, int /*long*/ hBitmap, RECT rect, int tx, int ty) {
RECT rect2 = new RECT ();
OS.GetClientRect (hwnd, rect2);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Label.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Label.java
index 1557202..1348951 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Label.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Label.java
@@ -225,7 +225,7 @@ public int getAlignment () {
boolean getBufferredPaint() {
Shell shell = getShell ();
- if ((shell.style & SWT.TRIM_FILL) != 0) {
+ if (((shell.style & SWT.TRIM_FILL) != 0) && ((this.style & SWT.TRIM_FILL) != 0)){
// if (image != null) return false;//note: can't be transparent for all images...
return true;//bad: should be transparent with custom draw
}
@@ -415,6 +415,7 @@ public void setText (String string) {
}
if ((style & SWT.CENTER) != 0) newBits |= OS.SS_CENTER;
if ((style & SWT.RIGHT) != 0) newBits |= OS.SS_RIGHT;
+ if ((style & SWT.TRIM_FILL) != 0) newBits |= OS.SS_OWNERDRAW; // if glass is turned on, text-only labels need to be owner-drawn as well
if (oldBits != newBits) OS.SetWindowLong (handle, OS.GWL_STYLE, newBits);
}
string = Display.withCrLf (string);
@@ -623,12 +624,6 @@ LRESULT WM_PAINT (int /*long*/ wParam, int /*long*/ lParam) {
}
LRESULT wmDrawChild (int /*long*/ wParam, int /*long*/ lParam) {
- // AERO-GLASS TODO: this is a workaround that fixes the white backgrounds that are painted
- // when the Alt key is pressed
- if (getBufferredPaint()) { // && ((style & SWT.SEPARATOR) == 0)) {
- return wmBufferedPaint(handle, 0, 0);
- }
-
DRAWITEMSTRUCT struct = new DRAWITEMSTRUCT ();
OS.MoveMemory (struct, lParam, DRAWITEMSTRUCT.sizeof);
drawBackground (struct.hDC);
@@ -701,13 +696,23 @@ LRESULT wmDrawChild (int /*long*/ wParam, int /*long*/ lParam) {
rect.right += rect.left;
rect.top = Math.max (0, (height - textHeight) / 2);
rect.bottom += rect.top;
- OS.DrawText (struct.hDC, buffer, -1, rect, flags);
+
+ if ((this.style & SWT.TRIM_FILL) == 0) {
+ OS.DrawText (struct.hDC, buffer, -1, rect, flags);
+ } else {
+ drawBufferredText(struct.hDC, buffer, rect, flags);
+ }
}
}
}
return null;
}
+LRESULT wmBufferedPaint (int /*long*/ hWnd, int /*long*/ wParam, int /*long*/ lParam) {
+ // Label widgets are owner-drawn, so this is a no-op
+ return null; // return null so that wmDrawChild gets invoked
+}
+
int getThemeGlowSize () {
int /*long*/ hTheme = OS.OpenThemeData(0, "CompositedWindow::Window;".toCharArray());
int [] glowSize = new int[1];
@@ -716,131 +721,40 @@ int getThemeGlowSize () {
return glowSize[0] > 0 ? glowSize[0] : 12;
}
-LRESULT wmBufferedPaint (int /*long*/ hWnd, int /*long*/ wParam, int /*long*/ lParam) {
- int result = 0;
-
- // BeginPaint ...
- PAINTSTRUCT ps = new PAINTSTRUCT ();
- int /*long*/ hDC = OS.BeginPaint (hWnd, ps);
-
- // copy the PAINTSTRUCT coordinates into a RECT structure
- RECT rcPaintStruct = new RECT();
- rcPaintStruct.left = ps.left;
- rcPaintStruct.right = ps.right;
- rcPaintStruct.top = ps.top;
- rcPaintStruct.bottom = ps.bottom;
-
- // calculate the client rectangle and coordinates
- RECT rcClient = new RECT();
- OS.GetClientRect(hWnd, rcClient);
- int width = rcClient.right - rcClient.left;
- int height = rcClient.bottom - rcClient.top;
-
+void drawBufferredText(int targetDC, TCHAR textBuffer, RECT rect, int dwFlags) {
// set up the buffered device context - the background is painted entirely black and its alpha
// is set to zero, resulting in a device context that is 100% transparent (if nothing is drawn to this DC,
// the glass background will just render through)
int /*long*/ [] hdcBuffered = new int /*long*/ [1];
- int /*long*/ hBufferedPaint = OS.BeginBufferedPaint(hDC, rcClient, OS.BPBF_TOPDOWNDIB, null, hdcBuffered);
- OS.PatBlt(hdcBuffered[0], 0, 0, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, OS.BLACKNESS);
- OS.BufferedPaintSetAlpha(hBufferedPaint, rcPaintStruct, (byte)0x00);
-
- // determine if we are drawing text and/or images
- boolean drawImage = image != null;
- boolean drawText = text != null && text.length () != 0;
- if (!IMAGE_AND_TEXT && drawImage) drawText = false;
-
- // if we are drawing image, calculate the margins and dimensions of the image that will be drawn
- int margin = drawText && drawImage ? MARGIN : 0;
- int imageWidth = 0, imageHeight = 0;
- if (drawImage) {
- Rectangle rect = image.getBounds ();
- imageWidth = rect.width;
- imageHeight = rect.height;
- }
-
- // if we are drawing text, calculate the dimensions of the text that will be drawn
- RECT rect = null;
- int textWidth = 0, textHeight = 0;
- if (drawText) {
- rect = new RECT ();
- int flags = OS.DT_CALCRECT | OS.DT_EDITCONTROL | OS.DT_EXPANDTABS;
- if ((style & SWT.LEFT) != 0) flags |= OS.DT_LEFT;
- if ((style & SWT.CENTER) != 0) flags |= OS.DT_CENTER;
- if ((style & SWT.RIGHT) != 0) flags |= OS.DT_RIGHT;
- if ((style & SWT.WRAP) != 0) {
- flags |= OS.DT_WORDBREAK;
- rect.right = Math.max (0, width - imageWidth - margin);
- }
- TCHAR buffer = new TCHAR (getCodePage (), text, true);
- OS.DrawText (hDC, buffer, -1, rect, flags);
- textWidth = rect.right - rect.left;
- textHeight = rect.bottom - rect.top;
- }
+ int /*long*/ hBufferedPaint = OS.BeginBufferedPaint(targetDC, rect, OS.BPBF_TOPDOWNDIB, null, hdcBuffered);
+ OS.PatBlt(hdcBuffered[0], 0, 0, rect.right /* - rect.left */, rect.bottom /* - rect.top */, OS.BLACKNESS);
+ OS.BufferedPaintSetAlpha(hBufferedPaint, rect, (byte)0x00);
- // adjust the left x-coordinate based on the label's justification
- int x = 0;
- if ((style & SWT.CENTER) != 0) {
- x = Math.max (0, (width - imageWidth - textWidth - margin) / 2);
- } else {
- if ((style & SWT.RIGHT) != 0) {
- x = width - imageWidth - textWidth - margin;
- }
- }
-
- if (drawText) {
- // setup the rectangle for drawing text
- rect.left = x + imageWidth + margin;
- rect.right += rect.left;
- rect.top = Math.max (0, (height - textHeight) / 2);
- rect.bottom += rect.top;
-
- // setup the DTTOPTS structure for calling into DrawThemeTextEx - note how we call getThemeGlowSize()
- // to apply a glow around the text we are drawing to enhance readability of the text against a glass background
- DTTOPTS DttOpts = new DTTOPTS();
- DttOpts.dwSize = DTTOPTS.sizeof;
- DttOpts.dwFlags = OS.DTT_COMPOSITED | OS.DTT_GLOWSIZE;
- DttOpts.crText = 0x00FFFFFF;
- DttOpts.iGlowSize = getThemeGlowSize ();
-
- // select the window's font into the buffered device context
- int /*long*/ hFont = OS.SendMessage(hWnd, OS.WM_GETFONT, 0, 0);
- if (hFont != 0) {
- hFont = OS.SelectObject(hdcBuffered[0], hFont);
- }
-
- // draw the text using the special DrawThemeTextEx call
- int dwFlags = ((style & SWT.WRAP) != 0) ? OS.DT_WORDBREAK : 0;
- TCHAR textBuffer = new TCHAR (getCodePage (), text, true);
- int /*long*/ hTheme = OS.OpenThemeData(0, "ControlPanelStyle;".toCharArray());
- // Aero-Glass TODO: add the OS.DrawThemeTextEx() API to swt.dll
- OS.DrawThemeTextEx(hTheme, hdcBuffered[0], 0, 0, textBuffer.chars, textBuffer.length(), dwFlags, rect, DttOpts);
-// TasktopOS.DrawThemeTextEx(hTheme, hdcBuffered[0], textBuffer.chars, dwFlags, rect, DttOpts.iGlowSize); // glowSize[0]); // this is our own JNI placeholder until swt.dll gets upgraded
- OS.CloseThemeData(hTheme);
-
- // restore the font
- if (hFont != 0) {
- OS.SelectObject(hdcBuffered[0], hFont);
- }
+ // setup the DTTOPTS structure for calling into DrawThemeTextEx - note how we call getThemeGlowSize()
+ // to apply a glow around the text we are drawing to enhance readability of the text against a glass background
+ DTTOPTS dttOpts = new DTTOPTS();
+ dttOpts.dwSize = DTTOPTS.sizeof;
+ dttOpts.dwFlags = OS.DTT_COMPOSITED | OS.DTT_GLOWSIZE;
+ dttOpts.crText = 0x00FFFFFF;
+ dttOpts.iGlowSize = getThemeGlowSize ();
+
+ // select the window's font into the buffered device context
+ int /*long*/ hFont = OS.SendMessage(this.handle, OS.WM_GETFONT, 0, 0);
+ if (hFont != 0) {
+ hFont = OS.SelectObject(hdcBuffered[0], hFont);
}
- // at this point, all drawing into the buffered device context is complete, so we can transfer its contents
- // into the target device context by calling EndBufferedPaint
- OS.EndBufferedPaint(hBufferedPaint, true);
+ // draw the text using the special DrawThemeTextEx call
+ int /*long*/ hTheme = OS.OpenThemeData(0, "ControlPanelStyle;".toCharArray());
+ OS.DrawThemeTextEx(hTheme, hdcBuffered[0], 0, 0, textBuffer.chars, textBuffer.length(), dwFlags, rect, dttOpts);
+ OS.CloseThemeData(hTheme);
- // draw the image against the regular device context - PNGs work great, but there are problems with GIFs and BMPs
- if (drawImage) {
- GCData data = new GCData();
- data.device = display;
- GC gc = GC.win32_new (hDC, data);
- gc.drawImage (this.image, 0,0);
- gc.dispose ();
- }
+ // restore the font
+ if (hFont != 0) {
+ OS.SelectObject(hdcBuffered[0], hFont);
+ }
- // EndPaint.
- OS.EndPaint (hDC, ps);
+ OS.EndBufferedPaint(hBufferedPaint, true);
- if (result == 0) return LRESULT.ZERO;
- return new LRESULT (result);
}
-
}