summaryrefslogtreecommitdiffstats
path: root/bundles/org.eclipse.swt
diff options
context:
space:
mode:
authorFelipe Heidrich <fheidric>2006-04-19 15:31:59 +0000
committerFelipe Heidrich <fheidric>2006-04-19 15:31:59 +0000
commitf9f3156adc6e8f40d328c15f0f2aa9510ae00291 (patch)
treefe70e785788c8ac874fe8dcd0a0adb5bc4c5083c /bundles/org.eclipse.swt
parent581e2be923c73fa26ac8208dc1b808c769e30134 (diff)
downloadeclipse.platform.swt-f9f3156adc6e8f40d328c15f0f2aa9510ae00291.tar.gz
eclipse.platform.swt-f9f3156adc6e8f40d328c15f0f2aa9510ae00291.tar.xz
eclipse.platform.swt-f9f3156adc6e8f40d328c15f0f2aa9510ae00291.zip
Bug 131265 - Make ExpandBar background changeable by users
Diffstat (limited to 'bundles/org.eclipse.swt')
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ExpandBar.java66
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ExpandItem.java38
2 files changed, 71 insertions, 33 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ExpandBar.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ExpandBar.java
index a2b8ba411a..7b866b8697 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ExpandBar.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ExpandBar.java
@@ -44,8 +44,8 @@ public class ExpandBar extends Composite {
int itemCount;
int focusIndex;
int spacing;
- int yCurrentScroll;
- static final int HEADER_HEIGHT = 24;
+ int yCurrentScroll;
+ int hFont;
/**
@@ -127,9 +127,11 @@ public Point computeSize (int wHint, int hHint, boolean changed) {
if (itemCount > 0) {
int hDC = OS.GetDC (handle);
int hTheme = 0;
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
+ if (isAppThemed ()) {
hTheme = OS.OpenThemeData (handle, EXPLORERBAR);
}
+ int oldHFont = 0;
+ if (hFont != 0) oldHFont = OS.SelectObject (hDC, hFont);
height += spacing;
for (int i = 0; i < itemCount; i++) {
ExpandItem item = items [i];
@@ -138,6 +140,7 @@ public Point computeSize (int wHint, int hHint, boolean changed) {
height += spacing;
width = Math.max (width, item.getPreferredWidth (hTheme, hDC));
}
+ if (hFont != 0) OS.SelectObject (hDC, oldHFont);
OS.ReleaseDC (handle, hDC);
if (hTheme != 0) OS.CloseThemeData (hTheme);
}
@@ -177,13 +180,13 @@ void createWidget () {
super.createWidget ();
items = new ExpandItem [4];
focusIndex = -1;
- if (OS.COMCTL32_MAJOR < 6 || !OS.IsAppThemed ()) {
+ if (!isAppThemed ()) {
backgroundMode = SWT.INHERIT_DEFAULT;
}
}
int defaultBackground() {
- if (OS.COMCTL32_MAJOR < 6 || !OS.IsAppThemed ()) {
+ if (!isAppThemed ()) {
return OS.GetSysColor (OS.COLOR_WINDOW);
}
return super.defaultBackground();
@@ -221,7 +224,7 @@ void drawThemeBackground (int hDC, int hwnd, RECT rect) {
void drawWidget (GC gc, RECT clipRect) {
int hTheme = 0;
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
+ if (isAppThemed ()) {
hTheme = OS.OpenThemeData (handle, EXPLORERBAR);
}
if (hTheme != 0) {
@@ -245,15 +248,14 @@ void drawWidget (GC gc, RECT clipRect) {
Control findBackgroundControl () {
Control control = super.findBackgroundControl ();
- if (OS.COMCTL32_MAJOR < 6 || !OS.IsAppThemed ()) {
+ if (!isAppThemed ()) {
if (control == null) control = this;
}
return control;
}
-Control findThemeControl () {
- /* It is not possible to change the background of this control */
- return this;
+Control findThemeControl () {
+ return isAppThemed () ? this : super.findThemeControl ();
}
/**
@@ -330,6 +332,17 @@ public int getSpacing () {
return spacing;
}
+int getBandHeight () {
+ if (hFont == 0) return ExpandItem.CHEVRON_SIZE;
+ int hDC = OS.GetDC (handle);
+ int oldHFont = OS.SelectObject (hDC, hFont);
+ TEXTMETRIC lptm = OS.IsUnicode ? (TEXTMETRIC)new TEXTMETRICW() : new TEXTMETRICA();
+ OS.GetTextMetrics (hDC, lptm);
+ OS.SelectObject (hDC, oldHFont);
+ OS.ReleaseDC (handle, hDC);
+ return Math.max (ExpandItem.CHEVRON_SIZE, lptm.tmHeight + 4);
+}
+
/**
* Searches the receiver's list starting at the first item
* (index 0) until an item is found that is equal to the
@@ -357,6 +370,13 @@ public int indexOf (ExpandItem item) {
return -1;
}
+boolean isAppThemed () {
+ if (background != -1) return false;
+ if (foreground != -1) return false;
+ if (hFont != 0) return false;
+ return OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ();
+}
+
void layoutItems (int index, boolean setScrollbar) {
if (index < itemCount) {
int y = spacing - yCurrentScroll;
@@ -413,6 +433,20 @@ public void removeExpandListener (ExpandListener listener) {
eventTable.unhook (SWT.Collapse, listener);
}
+public void setFont (Font font) {
+ super.setFont (font);
+ hFont = font != null ? font.handle : 0;
+ layoutItems (0, true);
+}
+
+void setBackgroundPixel (int pixel) {
+ super.setBackgroundPixel (pixel);
+ if (!OS.IsWinCE) {
+ int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE | OS.RDW_ALLCHILDREN;
+ OS.RedrawWindow (handle, null, 0, flags);
+ }
+}
+
void setScrollbar () {
if (itemCount == 0) return;
if ((style & SWT.V_SCROLL) == 0) return;
@@ -420,12 +454,12 @@ void setScrollbar () {
OS.GetClientRect (handle, rect);
int height = rect.bottom - rect.top;
ExpandItem item = items [itemCount - 1];
- int maxHeight = item.y + ExpandBar.HEADER_HEIGHT + spacing;
+ int maxHeight = item.y + getBandHeight () + spacing;
if (item.expanded) maxHeight += item.height;
//claim bottom free space
if (yCurrentScroll > 0 && height > maxHeight) {
- yCurrentScroll = Math.max(0, yCurrentScroll + maxHeight - height);
+ yCurrentScroll = Math.max (0, yCurrentScroll + maxHeight - height);
layoutItems (0, false);
}
maxHeight += yCurrentScroll;
@@ -531,7 +565,7 @@ LRESULT WM_LBUTTONDOWN (int wParam, int lParam) {
int y = (short) (lParam >> 16);
for (int i = 0; i < itemCount; i++) {
ExpandItem item = items[i];
- boolean hover = item.x <= x && x < (item.x + item.width) && item.y <= y && y < (item.y + ExpandBar.HEADER_HEIGHT);
+ boolean hover = item.x <= x && x < (item.x + item.width) && item.y <= y && y < (item.y + getBandHeight());
if (hover && focusIndex != i) {
items [focusIndex].redraw (true);
focusIndex = i;
@@ -550,7 +584,7 @@ LRESULT WM_LBUTTONUP (int wParam, int lParam) {
ExpandItem item = items [focusIndex];
int x = (short) (lParam & 0xFFFF);
int y = (short) (lParam >> 16);
- boolean hover = item.x <= x && x < (item.x + item.width) && item.y <= y && y < (item.y + ExpandBar.HEADER_HEIGHT);
+ boolean hover = item.x <= x && x < (item.x + item.width) && item.y <= y && y < (item.y + getBandHeight());
if (hover) {
Event event = new Event ();
event.item = item;
@@ -568,7 +602,7 @@ LRESULT WM_MOUSEMOVE (int wParam, int lParam) {
int y = (short) (lParam >> 16);
for (int i = 0; i < itemCount; i++) {
ExpandItem item = items[i];
- boolean hover = item.x <= x && x < (item.x + item.width) && item.y <= y && y < (item.y + ExpandBar.HEADER_HEIGHT);
+ boolean hover = item.x <= x && x < (item.x + item.width) && item.y <= y && y < (item.y + getBandHeight());
if (item.hover != hover) {
item.hover = hover;
item.redraw (false);
@@ -654,4 +688,4 @@ LRESULT wmScroll (ScrollBar bar, boolean update, int hwnd, int msg, int wParam,
}
return result;
}
-}
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ExpandItem.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ExpandItem.java
index 1e9bb5aa70..90b0b4c028 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ExpandItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ExpandItem.java
@@ -40,6 +40,7 @@ public class ExpandItem extends Item {
int imageHeight, imageWidth;
static final int TEXT_INSET = 6;
static final int BORDER = 1;
+ static final int CHEVRON_SIZE = 24;
/**
* Constructs a new instance of this class given its parent
@@ -170,7 +171,7 @@ private void drawChevron (int hDC, RECT rect) {
void drawItem (GC gc, int hTheme, RECT clipRect, boolean drawFocus) {
int hDC = gc.handle;
- int headerHeight = ExpandBar.HEADER_HEIGHT;
+ int headerHeight = parent.getBandHeight ();
RECT rect = new RECT ();
OS.SetRect (rect, x, y, x + width, y + headerHeight);
if (hTheme != 0) {
@@ -195,10 +196,10 @@ void drawItem (GC gc, int hTheme, RECT clipRect, boolean drawFocus) {
if (hTheme != 0) {
OS.DrawThemeText (hTheme, hDC, OS.EBP_NORMALGROUPHEAD, 0, buffer.chars, buffer.length(), OS.DT_VCENTER | OS.DT_SINGLELINE, 0, rect);
} else {
- NONCLIENTMETRICS info = OS.IsUnicode ? (NONCLIENTMETRICS) new NONCLIENTMETRICSW () : new NONCLIENTMETRICSA ();
- info.cbSize = NONCLIENTMETRICS.sizeof;
int hFont = 0, oldFont = 0;
- if (!OS.IsWinCE) {
+ if (!OS.IsWinCE && parent.hFont == 0) {
+ NONCLIENTMETRICS info = OS.IsUnicode ? (NONCLIENTMETRICS) new NONCLIENTMETRICSW () : new NONCLIENTMETRICSA ();
+ info.cbSize = NONCLIENTMETRICS.sizeof;
if (OS.SystemParametersInfo (OS.SPI_GETNONCLIENTMETRICS, 0, info, 0)) {
LOGFONT logFont = OS.IsUnicode ? (LOGFONT) ((NONCLIENTMETRICSW)info).lfCaptionFont : ((NONCLIENTMETRICSA)info).lfCaptionFont;
hFont = OS.CreateFontIndirect (logFont);
@@ -214,7 +215,10 @@ void drawItem (GC gc, int hTheme, RECT clipRect, boolean drawFocus) {
}
}
}
- rect.left = rect.right - headerHeight;
+ int chevronSize = ExpandItem.CHEVRON_SIZE;
+ rect.left = rect.right - chevronSize;
+ rect.top = y + (headerHeight - chevronSize) / 2;
+ rect.bottom = rect.top + chevronSize;
if (hTheme != 0) {
int partID = expanded ? OS.EBP_NORMALGROUPCOLLAPSE : OS.EBP_NORMALGROUPEXPAND;
int stateID = hover ? OS.EBNGC_HOT : OS.EBNGC_NORMAL;
@@ -227,7 +231,7 @@ void drawItem (GC gc, int hTheme, RECT clipRect, boolean drawFocus) {
OS.DrawFocusRect (hDC, rect);
}
if (expanded) {
- if (OS.COMCTL32_MAJOR < 6 || !OS.IsAppThemed ()) {
+ if (!parent.isAppThemed ()) {
int pen = OS.CreatePen (OS.PS_SOLID, 1, OS.GetSysColor (OS.COLOR_BTNFACE));
int oldPen = OS.SelectObject (hDC, pen);
int [] points = {
@@ -292,7 +296,7 @@ public boolean getExpanded () {
*/
public int getHeaderHeight () {
checkWidget ();
- return Math.max (ExpandBar.HEADER_HEIGHT, imageHeight);
+ return Math.max (parent.getBandHeight (), imageHeight);
}
/**
@@ -326,7 +330,7 @@ public ExpandBar getParent () {
}
int getPreferredWidth (int hTheme, int hDC) {
- int width = ExpandItem.TEXT_INSET * 2 + ExpandBar.HEADER_HEIGHT;
+ int width = ExpandItem.TEXT_INSET * 2 + ExpandItem.CHEVRON_SIZE;
if (image != null) {
width += ExpandItem.TEXT_INSET + imageWidth;
}
@@ -336,10 +340,10 @@ int getPreferredWidth (int hTheme, int hDC) {
if (hTheme != 0) {
OS.GetThemeTextExtent (hTheme, hDC, OS.EBP_NORMALGROUPHEAD, 0, buffer.chars, buffer.length(), OS.DT_SINGLELINE, null, rect);
} else {
- NONCLIENTMETRICS info = OS.IsUnicode ? (NONCLIENTMETRICS) new NONCLIENTMETRICSW () : new NONCLIENTMETRICSA ();
- info.cbSize = NONCLIENTMETRICS.sizeof;
int hFont = 0, oldFont = 0;
- if (!OS.IsWinCE) {
+ if (!OS.IsWinCE && parent.hFont == 0) {
+ NONCLIENTMETRICS info = OS.IsUnicode ? (NONCLIENTMETRICS) new NONCLIENTMETRICSW () : new NONCLIENTMETRICSA ();
+ info.cbSize = NONCLIENTMETRICS.sizeof;
if (OS.SystemParametersInfo (OS.SPI_GETNONCLIENTMETRICS, 0, info, 0)) {
LOGFONT logFont = OS.IsUnicode ? (LOGFONT) ((NONCLIENTMETRICSW)info).lfCaptionFont : ((NONCLIENTMETRICSA)info).lfCaptionFont;
hFont = OS.CreateFontIndirect (logFont);
@@ -359,7 +363,7 @@ int getPreferredWidth (int hTheme, int hDC) {
void redraw (boolean all) {
int parentHandle = parent.handle;
- int headerHeight = ExpandBar.HEADER_HEIGHT;
+ int headerHeight = parent.getBandHeight ();
RECT rect = new RECT ();
int left = all ? x : x + width - headerHeight;
OS.SetRect (rect, left, y, x + width, y + headerHeight);
@@ -368,7 +372,7 @@ void redraw (boolean all) {
OS.SetRect (rect, x + ExpandItem.TEXT_INSET, y + headerHeight - imageHeight, x + ExpandItem.TEXT_INSET + imageWidth, y);
OS.InvalidateRect (parentHandle, rect, true);
}
- if (OS.COMCTL32_MAJOR < 6 || !OS.IsAppThemed ()) {
+ if (!parent.isAppThemed ()) {
OS.SetRect (rect, x, y + headerHeight, x + width, y + headerHeight + height + 1);
OS.InvalidateRect (parentHandle, rect, true);
}
@@ -386,7 +390,7 @@ void releaseWidget () {
void setBounds (int x, int y, int width, int height, boolean move, boolean size) {
redraw (true);
- int headerHeight = ExpandBar.HEADER_HEIGHT;
+ int headerHeight = parent.getBandHeight ();
if (move) {
if (imageHeight > headerHeight) {
y += (imageHeight - headerHeight);
@@ -401,7 +405,7 @@ void setBounds (int x, int y, int width, int height, boolean move, boolean size)
redraw (true);
}
if (control != null && !control.isDisposed ()) {
- if (OS.COMCTL32_MAJOR < 6 || !OS.IsAppThemed ()) {
+ if (!parent.isAppThemed ()) {
x += BORDER;
width = Math.max (0, width - BORDER * 2);
height = Math.max (0, height - BORDER);
@@ -434,9 +438,9 @@ public void setControl (Control control) {
}
this.control = control;
if (control != null) {
- int headerHeight = ExpandBar.HEADER_HEIGHT;
+ int headerHeight = parent.getBandHeight ();
control.setVisible (expanded);
- if (OS.COMCTL32_MAJOR < 6 || !OS.IsAppThemed ()) {
+ if (!parent.isAppThemed ()) {
int width = Math.max (0, this.width - BORDER * 2);
int height = Math.max (0, this.height - BORDER);
control.setBounds (x + BORDER, y + headerHeight, width, height);