diff options
author | Felipe Heidrich <fheidric> | 2004-04-16 21:54:26 +0000 |
---|---|---|
committer | Felipe Heidrich <fheidric> | 2004-04-16 21:54:26 +0000 |
commit | 38a668b0ccd1d833fa9d04266ea54d6a121b973a (patch) | |
tree | 8acfad6c018149f8b9a50406777b1aeee0a4ef08 /bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets | |
parent | 627bed0d1b682a0f533dde99c53beac29b1f066b (diff) | |
download | eclipse.platform.swt-38a668b0ccd1d833fa9d04266ea54d6a121b973a.tar.gz eclipse.platform.swt-38a668b0ccd1d833fa9d04266ea54d6a121b973a.tar.xz eclipse.platform.swt-38a668b0ccd1d833fa9d04266ea54d6a121b973a.zip |
*** empty log message ***
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets')
-rwxr-xr-x | bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/CoolBar.java | 53 | ||||
-rwxr-xr-x | bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/CoolItem.java | 77 |
2 files changed, 83 insertions, 47 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/CoolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/CoolBar.java index 54d2b57c9e..8f37cc710c 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/CoolBar.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/CoolBar.java @@ -53,7 +53,7 @@ public class CoolBar extends Composite { OS.GetClassInfo (0, ReBarClass, lpWndClass); ReBarProc = lpWndClass.lpfnWndProc; } - static final int INSET = 4; + static final int SEPARATOR_WIDTH = 2; static final int MAX_WIDTH = 0x7FFF; /** @@ -146,17 +146,16 @@ public Point computeSize (int wHint, int hHint, boolean changed) { rbBand.cbSize = REBARBANDINFO.sizeof; rbBand.fMask = OS.RBBIM_IDEALSIZE | OS.RBBIM_STYLE; int rowWidth = 0; + int separator = (style & SWT.FLAT) == 0 ? SEPARATOR_WIDTH : 0; for (int i = 0; i < count; i++) { OS.SendMessage(handle, OS.RB_GETBANDINFO, i, rbBand); - OS.SendMessage(handle, OS.RB_GETBANDBORDERS, i, rect); if ((rbBand.fStyle & OS.RBBS_BREAK) != 0) { - width = Math.max(width, rowWidth); + width = Math.max(width, rowWidth - separator); rowWidth = 0; } - rowWidth += rbBand.cxIdeal + rect.left + INSET; - if ((style & SWT.FLAT) == 0) rowWidth += rect.right; + rowWidth += rbBand.cxIdeal + getMargin (i) + separator; } - width = Math.max(width, rowWidth); + width = Math.max(width, rowWidth - separator); if (redraw) { if (OS.COMCTL32_MAJOR >= 6) { OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0); @@ -335,6 +334,28 @@ void destroyItem (CoolItem item) { originalItems = newOriginals; } +int getMargin (int index) { + int margin = 0; + if (OS.COMCTL32_MAJOR >= 6) { + MARGINS margins = new MARGINS (); + OS.SendMessage (handle, OS.RB_GETBANDMARGINS, 0, margins); + margin += margins.cxLeftWidth + margins.cxRightWidth; + } + RECT rect = new RECT (); + OS.SendMessage (handle, OS.RB_GETBANDBORDERS, index, rect); + if ((style & SWT.FLAT) != 0) { + /* + * Bug in Windows. When the style bit RBS_BANDBORDERS is not set + * the rectangle returned by RBS_BANDBORDERS is four pixels too small. + * The fix is to add four pixels to the result. + */ + margin += rect.left + 4; + } else { + margin += rect.left + rect.right; + } + return margin; +} + /** * Returns the item that is currently displayed at the given, * zero-relative index. Throws an exception if the index is @@ -480,11 +501,19 @@ public Point [] getItemSizes () { REBARBANDINFO rbBand = new REBARBANDINFO (); rbBand.cbSize = REBARBANDINFO.sizeof; rbBand.fMask = OS.RBBIM_CHILDSIZE; + int separator = (style & SWT.FLAT) == 0 ? SEPARATOR_WIDTH : 0; + MARGINS margins = new MARGINS (); for (int i=0; i<count; i++) { RECT rect = new RECT (); OS.SendMessage (handle, OS.RB_GETRECT, i, rect); OS.SendMessage (handle, OS.RB_GETBANDINFO, i, rbBand); - sizes [i] = new Point (rect.right - rect.left + 2, rbBand.cyChild); + if (OS.COMCTL32_MAJOR >= 6) { + OS.SendMessage (handle, OS.RB_GETBANDMARGINS, 0, margins); + rect.left -= margins.cxLeftWidth; + rect.right += margins.cxRightWidth; + } + if (!isLastItemOfRow(i)) rect.right += separator; + sizes [i] = new Point (rect.right - rect.left, rbBand.cyChild); } return sizes; } @@ -504,6 +533,16 @@ int getLastIndexOfRow (int index) { return count - 1; } +boolean isLastItemOfRow (int index) { + int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0); + if (index + 1 == count) return true; + REBARBANDINFO rbBand = new REBARBANDINFO (); + rbBand.cbSize = REBARBANDINFO.sizeof; + rbBand.fMask = OS.RBBIM_STYLE; + OS.SendMessage (handle, OS.RB_GETBANDINFO, index + 1, rbBand); + return (rbBand.fStyle & OS.RBBS_BREAK) != 0; +} + /** * Returns whether or not the receiver is 'locked'. When a coolbar * is locked, its items cannot be repositioned. diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/CoolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/CoolItem.java index ea7cdf9b2c..72c87a1d92 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/CoolItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/CoolItem.java @@ -186,11 +186,7 @@ public Point computeSize (int wHint, int hHint) { int width = wHint, height = hHint; if (wHint == SWT.DEFAULT) width = 32; if (hHint == SWT.DEFAULT) height = 32; - int hwnd = parent.handle; - RECT rect = new RECT (); - OS.SendMessage (hwnd, OS.RB_GETBANDBORDERS, index, rect); - width += rect.left + CoolBar.INSET; - if ((parent.style & SWT.FLAT) == 0) width += rect.right; + width += parent.getMargin (index); return new Point (width, height); } @@ -212,7 +208,16 @@ public Rectangle getBounds () { int hwnd = parent.handle; RECT rect = new RECT (); OS.SendMessage (hwnd, OS.RB_GETRECT, index, rect); - int width = rect.right - rect.left + 2; + if (OS.COMCTL32_MAJOR >= 6) { + MARGINS margins = new MARGINS (); + OS.SendMessage (hwnd, OS.RB_GETBANDMARGINS, 0, margins); + rect.left -= margins.cxLeftWidth; + rect.right += margins.cxRightWidth; + } + if (!parent.isLastItemOfRow (index)) { + rect.right += (parent.style & SWT.FLAT) == 0 ? CoolBar.SEPARATOR_WIDTH : 0; + } + int width = rect.right - rect.left; int height = rect.bottom - rect.top; return new Rectangle (rect.left, rect.top, width, height); } @@ -367,10 +372,7 @@ public Point getPreferredSize () { rbBand.cbSize = REBARBANDINFO.sizeof; rbBand.fMask = OS.RBBIM_CHILDSIZE | OS.RBBIM_IDEALSIZE; OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, rbBand); - RECT rect = new RECT (); - OS.SendMessage (hwnd, OS.RB_GETBANDBORDERS, index, rect); - int width = rbBand.cxIdeal + rect.left + CoolBar.INSET; - if ((parent.style & SWT.FLAT) == 0) width += rect.right; + int width = rbBand.cxIdeal + parent.getMargin (index); return new Point (width, rbBand.cyMinChild); } @@ -393,8 +395,6 @@ public void setPreferredSize (int width, int height) { height = Math.max (0, height); ideal = true; int hwnd = parent.handle; - RECT rect = new RECT (); - OS.SendMessage (hwnd, OS.RB_GETBANDBORDERS, index, rect); REBARBANDINFO rbBand = new REBARBANDINFO (); rbBand.cbSize = REBARBANDINFO.sizeof; @@ -404,9 +404,7 @@ public void setPreferredSize (int width, int height) { /* Set the size fields we are currently modifying. */ rbBand.fMask = OS.RBBIM_CHILDSIZE | OS.RBBIM_IDEALSIZE; - rbBand.cxIdeal = width - rect.left - CoolBar.INSET; - if ((parent.style & SWT.FLAT) == 0) rbBand.cxIdeal -= rect.right; - rbBand.cxIdeal = Math.max (0, rbBand.cxIdeal); + rbBand.cxIdeal = Math.max (0, width - parent.getMargin (index)); rbBand.cyMaxChild = height; if (!minimum) rbBand.cyMinChild = height; OS.SendMessage (hwnd, OS.RB_SETBANDINFO, index, rbBand); @@ -452,7 +450,16 @@ public Point getSize() { int hwnd = parent.handle; RECT rect = new RECT (); OS.SendMessage (hwnd, OS.RB_GETRECT, index, rect); - int width = rect.right - rect.left + 2; + if (OS.COMCTL32_MAJOR >= 6) { + MARGINS margins = new MARGINS (); + OS.SendMessage (hwnd, OS.RB_GETBANDMARGINS, 0, margins); + rect.left -= margins.cxLeftWidth; + rect.right += margins.cxRightWidth; + } + if (!parent.isLastItemOfRow (index)) { + rect.right += (parent.style & SWT.FLAT) == 0 ? CoolBar.SEPARATOR_WIDTH : 0; + } + int width = rect.right - rect.left; int height = rect.bottom - rect.top; return new Point (width, height); } @@ -483,37 +490,27 @@ public void setSize (int width, int height) { REBARBANDINFO rbBand = new REBARBANDINFO (); rbBand.cbSize = REBARBANDINFO.sizeof; - /* - * Do not set the size for the last item on the row. - */ - int count = OS.SendMessage (hwnd, OS.RB_GETBANDCOUNT, 0, 0); - boolean isLastItem; - if (index + 1 == count) { - isLastItem = true; - } else { - rbBand.fMask = OS.RBBIM_STYLE; - OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index + 1, rbBand); - isLastItem = (rbBand.fStyle & OS.RBBS_BREAK) != 0; - rbBand.fMask = 0; - } - /* Get the child size fields first so we don't overwrite them. */ rbBand.fMask = OS.RBBIM_CHILDSIZE | OS.RBBIM_IDEALSIZE; OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, rbBand); /* Set the size fields we are currently modifying. */ - rbBand.fMask = OS.RBBIM_CHILDSIZE | OS.RBBIM_IDEALSIZE; - if (!ideal) { - RECT rect = new RECT (); - OS.SendMessage (hwnd, OS.RB_GETBANDBORDERS, index, rect); - rbBand.cxIdeal = width - rect.left - CoolBar.INSET; - if ((parent.style & SWT.FLAT) == 0) rbBand.cxIdeal -= rect.right; - rbBand.cxIdeal = Math.max (0, rbBand.cxIdeal); - } + if (!ideal) rbBand.cxIdeal = Math.max (0, width - parent.getMargin (index)); if (!minimum) rbBand.cyMinChild = height; rbBand.cyChild = rbBand.cyMaxChild = height; - if (!isLastItem) { - rbBand.cx = width - 2; + + /* + * Do not set the size for the last item on the row. + */ + if (!parent.isLastItemOfRow (index)) { + if (OS.COMCTL32_MAJOR >= 6) { + MARGINS margins = new MARGINS (); + OS.SendMessage (hwnd, OS.RB_GETBANDMARGINS, 0, margins); + width -= margins.cxLeftWidth; + width -= margins.cxRightWidth; + } + int separator = (parent.style & SWT.FLAT) == 0 ? CoolBar.SEPARATOR_WIDTH : 0; + rbBand.cx = width - separator; rbBand.fMask |= OS.RBBIM_SIZE; } OS.SendMessage (hwnd, OS.RB_SETBANDINFO, index, rbBand); |