Lines 27-33
import org.eclipse.swt.graphics.*;
Link Here
|
27 |
* </p><p> |
27 |
* </p><p> |
28 |
* <dl> |
28 |
* <dl> |
29 |
* <dt><b>Styles:</b></dt> |
29 |
* <dt><b>Styles:</b></dt> |
30 |
* <dd>FLAT, HORIZONTAL, VERTICAL</dd> |
30 |
* <dd>FLAT, HORIZONTAL, VERTICAL, CENTER, LEFT, RIGHT</dd> |
31 |
* <dt><b>Events:</b></dt> |
31 |
* <dt><b>Events:</b></dt> |
32 |
* <dd>(none)</dd> |
32 |
* <dd>(none)</dd> |
33 |
* </dl> |
33 |
* </dl> |
Lines 709-752
void onPaint(Event event) {
Link Here
|
709 |
boolean nativeGripper = false; |
709 |
boolean nativeGripper = false; |
710 |
|
710 |
|
711 |
/* Draw gripper. */ |
711 |
/* Draw gripper. */ |
712 |
if (!isLocked) { |
712 |
if ((items[row][i].getStyle() & SWT.FLEXIBLE_SPACE) == 0) { |
713 |
rect = fixRectangle(bounds.x, bounds.y, CoolItem.MINIMUM_WIDTH, bounds.height); |
713 |
if (!isLocked && (items.length > 1 || items[row].length > 1)) { |
714 |
if (!flat) nativeGripper = drawGripper(rect.x, rect.y, rect.width, rect.height, vertical); |
714 |
rect = fixRectangle(bounds.x, bounds.y, CoolItem.MINIMUM_WIDTH, bounds.height); |
715 |
if (!nativeGripper) { |
715 |
if (!flat) nativeGripper = drawGripper(rect.x, rect.y, rect.width, rect.height, vertical); |
716 |
int grabberTrim = 2; |
716 |
if (!nativeGripper) { |
717 |
int grabberHeight = bounds.height - (2 * grabberTrim) - 1; |
717 |
int grabberTrim = 2; |
|
|
718 |
int grabberHeight = bounds.height - (2 * grabberTrim) - 1; |
719 |
gc.setForeground(shadowColor); |
720 |
rect = fixRectangle( |
721 |
bounds.x + CoolItem.MARGIN_WIDTH, |
722 |
bounds.y + grabberTrim, |
723 |
2, |
724 |
grabberHeight); |
725 |
gc.drawRectangle(rect); |
726 |
gc.setForeground(highlightColor); |
727 |
rect = fixRectangle( |
728 |
bounds.x + CoolItem.MARGIN_WIDTH, |
729 |
bounds.y + grabberTrim + 1, |
730 |
bounds.x + CoolItem.MARGIN_WIDTH, |
731 |
bounds.y + grabberTrim + grabberHeight - 1); |
732 |
gc.drawLine(rect.x, rect.y, rect.width, rect.height); |
733 |
rect = fixRectangle( |
734 |
bounds.x + CoolItem.MARGIN_WIDTH, |
735 |
bounds.y + grabberTrim, |
736 |
bounds.x + CoolItem.MARGIN_WIDTH + 1, |
737 |
bounds.y + grabberTrim); |
738 |
gc.drawLine(rect.x, rect.y, rect.width, rect.height); |
739 |
} |
740 |
} |
741 |
|
742 |
/* Draw separator. */ |
743 |
if (!flat && !nativeGripper && i != 0) { |
718 |
gc.setForeground(shadowColor); |
744 |
gc.setForeground(shadowColor); |
719 |
rect = fixRectangle( |
745 |
rect = fixRectangle(bounds.x, bounds.y, bounds.x, bounds.y + bounds.height - 1); |
720 |
bounds.x + CoolItem.MARGIN_WIDTH, |
|
|
721 |
bounds.y + grabberTrim, |
722 |
2, |
723 |
grabberHeight); |
724 |
gc.drawRectangle(rect); |
725 |
gc.setForeground(highlightColor); |
726 |
rect = fixRectangle( |
727 |
bounds.x + CoolItem.MARGIN_WIDTH, |
728 |
bounds.y + grabberTrim + 1, |
729 |
bounds.x + CoolItem.MARGIN_WIDTH, |
730 |
bounds.y + grabberTrim + grabberHeight - 1); |
731 |
gc.drawLine(rect.x, rect.y, rect.width, rect.height); |
746 |
gc.drawLine(rect.x, rect.y, rect.width, rect.height); |
732 |
rect = fixRectangle( |
747 |
gc.setForeground(highlightColor); |
733 |
bounds.x + CoolItem.MARGIN_WIDTH, |
748 |
rect = fixRectangle(bounds.x + 1, bounds.y, bounds.x + 1, bounds.y + bounds.height - 1); |
734 |
bounds.y + grabberTrim, |
|
|
735 |
bounds.x + CoolItem.MARGIN_WIDTH + 1, |
736 |
bounds.y + grabberTrim); |
737 |
gc.drawLine(rect.x, rect.y, rect.width, rect.height); |
749 |
gc.drawLine(rect.x, rect.y, rect.width, rect.height); |
738 |
} |
750 |
} |
739 |
} |
751 |
} |
740 |
|
|
|
741 |
/* Draw separator. */ |
742 |
if (!flat && !nativeGripper && i != 0) { |
743 |
gc.setForeground(shadowColor); |
744 |
rect = fixRectangle(bounds.x, bounds.y, bounds.x, bounds.y + bounds.height - 1); |
745 |
gc.drawLine(rect.x, rect.y, rect.width, rect.height); |
746 |
gc.setForeground(highlightColor); |
747 |
rect = fixRectangle(bounds.x + 1, bounds.y, bounds.x + 1, bounds.y + bounds.height - 1); |
748 |
gc.drawLine(rect.x, rect.y, rect.width, rect.height); |
749 |
} |
750 |
} |
752 |
} |
751 |
if (!flat && row + 1 < items.length) { |
753 |
if (!flat && row + 1 < items.length) { |
752 |
/* Draw row separator. */ |
754 |
/* Draw row separator. */ |
Lines 844-858
int layoutItems () {
Link Here
|
844 |
if (row > 0) y += rowSpacing; |
846 |
if (row > 0) y += rowSpacing; |
845 |
|
847 |
|
846 |
/* lay the items out */ |
848 |
/* lay the items out */ |
|
|
849 |
// if there is only one row and only one item, then jack it over to the left so |
850 |
// we don't leave a space for a gripper |
851 |
if (items.length == 1 && items[row].length == 1) { |
852 |
x -= (CoolItem.MARGIN_WIDTH + CoolItem.GRABBER_WIDTH); |
853 |
// MS: this just looks better ... i don't know where the extra comes from |
854 |
// admittedly, this is dirty as hell |
855 |
x -= 5; |
856 |
} |
857 |
|
858 |
// We need to do a sweep across all items first to determine the unspaced width |
859 |
// of the items so that we can then apply flexible spacing and alignment |
860 |
int flexibleSpaceCount = 0; |
861 |
Rectangle[] itemBounds = new Rectangle[count]; |
847 |
for (int i = 0; i < count; i++) { |
862 |
for (int i = 0; i < count; i++) { |
848 |
CoolItem child = items[row][i]; |
863 |
CoolItem child = items[row][i]; |
|
|
864 |
if ((child.getStyle() & SWT.FLEXIBLE_SPACE) != 0) { |
865 |
flexibleSpaceCount ++; |
866 |
} |
849 |
int newWidth = available + child.internalGetMinimumWidth(); |
867 |
int newWidth = available + child.internalGetMinimumWidth(); |
850 |
if (i + 1 < count) { |
868 |
if (i + 1 < count) { |
851 |
newWidth = Math.min(newWidth, child.requestedWidth); |
869 |
newWidth = Math.min(newWidth, child.requestedWidth); |
852 |
available -= (newWidth - child.internalGetMinimumWidth()); |
870 |
available -= (newWidth - child.internalGetMinimumWidth()); |
853 |
} |
871 |
} |
|
|
872 |
itemBounds[i] = new Rectangle(x, y, newWidth, rowHeight); |
873 |
x += newWidth; |
874 |
} |
875 |
|
876 |
int flexibleSpacePerItem = 0; |
877 |
// If there is any flexible space in the coolbar, then alignment doesn't apply because |
878 |
// the flexible space will take up all the free space |
879 |
if (flexibleSpaceCount == 0) { |
880 |
if ((style & SWT.LEFT) != 0) { |
881 |
// leave it alone |
882 |
} |
883 |
else if ((style & SWT.CENTER) != 0) { |
884 |
int halfAvailable = available / 2; |
885 |
for (int i = 0; i < count; i ++) { |
886 |
itemBounds[i].x += halfAvailable; |
887 |
} |
888 |
} |
889 |
else if ((style & SWT.RIGHT) != 0) { |
890 |
for (int i = 0; i < count; i ++) { |
891 |
itemBounds[i].x += available; |
892 |
} |
893 |
} |
894 |
} |
895 |
else { |
896 |
// Divide out the available space across all of the flexible space cool items |
897 |
flexibleSpacePerItem = available / flexibleSpaceCount; |
898 |
} |
899 |
|
900 |
// As we run through the items, accumulate flexible space as we hand it out |
901 |
int flexibleSpaceOffset = 0; |
902 |
for (int i = 0; i < count; i ++) { |
903 |
CoolItem child = items[row][i]; |
854 |
Rectangle oldBounds = child.internalGetBounds(); |
904 |
Rectangle oldBounds = child.internalGetBounds(); |
855 |
Rectangle newBounds = new Rectangle(x, y, newWidth, rowHeight); |
905 |
Rectangle newBounds = itemBounds[i]; |
|
|
906 |
newBounds.x += flexibleSpaceOffset; |
856 |
if (!oldBounds.equals(newBounds)) { |
907 |
if (!oldBounds.equals(newBounds)) { |
857 |
child.setBounds(newBounds.x, newBounds.y, newBounds.width, newBounds.height); |
908 |
child.setBounds(newBounds.x, newBounds.y, newBounds.width, newBounds.height); |
858 |
Rectangle damage = new Rectangle(0, 0, 0, 0); |
909 |
Rectangle damage = new Rectangle(0, 0, 0, 0); |
Lines 881-887
int layoutItems () {
Link Here
|
881 |
} |
932 |
} |
882 |
internalRedraw(damage.x, damage.y, damage.width, damage.height); |
933 |
internalRedraw(damage.x, damage.y, damage.width, damage.height); |
883 |
} |
934 |
} |
884 |
x += newWidth; |
935 |
// we can probably just skip the item redraw entirely since it's just an empty space, |
|
|
936 |
// but i was afraid of breaking something, so just let it go ... |
937 |
if ((child.getStyle() & SWT.FLEXIBLE_SPACE) != 0) { |
938 |
flexibleSpaceOffset += flexibleSpacePerItem; |
939 |
} |
885 |
} |
940 |
} |
886 |
y += rowHeight; |
941 |
y += rowHeight; |
887 |
} |
942 |
} |