1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-05 08:05:24 +02:00

Bug 158301 - adding back drawn control support for windows platforms

This commit is contained in:
David Dykstal 2006-11-02 17:02:28 +00:00
parent 1c12d002b3
commit 593a240622
2 changed files with 83 additions and 72 deletions

View file

@ -56,17 +56,18 @@ public class InheritButton extends Composite {
/**
* Value is 12 pixels.
*/
// public static final int DEFAULT_WIDTH = 40;
public static final int DEFAULT_WIDTH = 12;
/**
* Value is 20 pixels.
*/
// public static final int DEFAULT_HEIGHT = 35;
public static final int DEFAULT_HEIGHT = 20;
// private Image leftArrow = null; // arrow points left, value is inherited
// private Image rightArrow = null; // arrow points right, value is the local value
private Image leftArrow = null; // arrow points left, value is inherited
private Image rightArrow = null; // arrow points right, value is the local value
private boolean isLocal = false; // default is "inherit"
private Button toggle = null;
private boolean isDrawn = false; // button is to be drawn or use arrow implementation
/**
* Create a new InheritButton.
@ -74,10 +75,13 @@ public class InheritButton extends Composite {
*/
public InheritButton(Composite parent) {
super(parent, SWT.NONE);
// GridData data = new GridData(SWT.CENTER, SWT.CENTER, false, false);
// data.widthHint = DEFAULT_WIDTH;
// data.heightHint = DEFAULT_HEIGHT;
// setLayoutData(data);
isDrawn = System.getProperty("os.name").toLowerCase().startsWith("win");
if (isDrawn) {
GridData data = new GridData(SWT.CENTER, SWT.CENTER, false, false);
data.widthHint = DEFAULT_WIDTH;
data.heightHint = DEFAULT_HEIGHT;
setLayoutData(data);
}
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
@ -86,9 +90,17 @@ public class InheritButton extends Composite {
}
private void initializeToggle(Composite parent) {
// toggle = new Button(parent, SWT.PUSH );
toggle = new Button(parent, SWT.ARROW );
// createToggleImages(toggle.getBackground());
if (isDrawn) {
toggle = new Button(parent, SWT.PUSH );
createToggleImages(toggle.getBackground());
toggle.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
disposeToggleImages();
}
});
} else {
toggle = new Button(parent, SWT.ARROW );
}
toggle.getAccessible().addAccessibleListener(new AccessibleAdapter() {
public void getHelp(AccessibleEvent e) { // this is the one that should supply the text heard.
e.result = "";
@ -109,11 +121,6 @@ public class InheritButton extends Composite {
}
}
});
// toggle.addDisposeListener(new DisposeListener() {
// public void widgetDisposed(DisposeEvent e) {
// disposeToggleImages();
// }
// });
toggle.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
setToggleImage();
}
@ -208,9 +215,12 @@ public class InheritButton extends Composite {
* In the "inherit" state, the arrow image points to the left.
*/
private void setToggleImage() {
// toggle.setImage(isLocal ? rightArrow : leftArrow);
int alignment = isLocal ? SWT.RIGHT : SWT.LEFT;
toggle.setAlignment(alignment);
if (isDrawn) {
toggle.setImage(isLocal ? rightArrow : leftArrow);
} else {
int alignment = isLocal ? SWT.RIGHT : SWT.LEFT;
toggle.setAlignment(alignment);
}
}
/**
@ -219,38 +229,38 @@ public class InheritButton extends Composite {
* @param backgroundColor The background color with which the arrow images
* should be painted. The foreground color is black.
*/
// private void createToggleImages(Color backgroundColor) {
// Display display = Display.getCurrent();
// GC gc = null;
// if (display != null) {
// leftArrow = new Image(display, 3, 5);
// gc = new GC(leftArrow);
// gc.setBackground(backgroundColor);
// gc.fillRectangle(leftArrow.getBounds());
// gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
// gc.drawLine(0, 2, 0, 2);
// gc.drawLine(1, 1, 1, 3);
// gc.drawLine(2, 0, 2, 4);
// gc.dispose();
// rightArrow = new Image(display, 3, 5);
// gc = new GC(rightArrow);
// gc.setBackground(backgroundColor);
// gc.fillRectangle(rightArrow.getBounds());
// gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
// gc.drawLine(0, 0, 0, 4);
// gc.drawLine(1, 1, 1, 3);
// gc.drawLine(2, 2, 2, 2);
// gc.dispose();
// }
// }
private void createToggleImages(Color backgroundColor) {
Display display = Display.getCurrent();
GC gc = null;
if (display != null) {
leftArrow = new Image(display, 3, 5);
gc = new GC(leftArrow);
gc.setBackground(backgroundColor);
gc.fillRectangle(leftArrow.getBounds());
gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
gc.drawLine(0, 2, 0, 2);
gc.drawLine(1, 1, 1, 3);
gc.drawLine(2, 0, 2, 4);
gc.dispose();
rightArrow = new Image(display, 3, 5);
gc = new GC(rightArrow);
gc.setBackground(backgroundColor);
gc.fillRectangle(rightArrow.getBounds());
gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
gc.drawLine(0, 0, 0, 4);
gc.drawLine(1, 1, 1, 3);
gc.drawLine(2, 2, 2, 2);
gc.dispose();
}
}
/**
* Dispose of the images used for the arrow graphics. Should be invoked
* when the button is disposed.
*/
// private void disposeToggleImages() {
// if (leftArrow != null) leftArrow.dispose();
// if (rightArrow != null) rightArrow.dispose();
// }
private void disposeToggleImages() {
if (leftArrow != null) leftArrow.dispose();
if (rightArrow != null) rightArrow.dispose();
}
}

View file

@ -613,31 +613,32 @@ public class SystemHistoryCombo extends Composite implements ISystemCombo, Trave
scheme used an SWT.ARROW button style which was not tab enabled and could not provide a focus rectangle.
Changes: made the control a push button, programmatically drew the arrow on the button, and provided accessibility information.
*/
/*
* dwd: as of eclipse 3.2 it now appears the arrow buttons are accessible, reverting to previous implementation.
*/
historyButton = new Button(this, SWT.ARROW);
historyButton.setAlignment(SWT.UP);
// historyButton = new Button(this, SWT.PUSH);
// Display display = this.getDisplay();
// final Image upArrow = new Image(display, 5, 6);
// GC gc = new GC(upArrow);
// gc.setBackground(historyButton.getBackground());
// gc.fillRectangle(upArrow.getBounds());
// gc.setForeground(historyButton.getForeground());
// gc.drawLine(0, 5, 4, 5);
// gc.drawLine(0, 4, 4, 4);
// gc.drawLine(1, 3, 3, 3);
// gc.drawLine(1, 2, 3, 2);
// gc.drawLine(2, 1, 2, 1);
// gc.drawLine(2, 0, 2, 0);
// gc.dispose();
// historyButton.addDisposeListener(new DisposeListener() {
// public void widgetDisposed(DisposeEvent e) {
// upArrow.dispose();
// }
// });
// historyButton.setImage(upArrow);
boolean isDrawn = System.getProperty("os.name").toLowerCase().startsWith("win");
if (isDrawn) {
historyButton = new Button(this, SWT.PUSH);
Display display = this.getDisplay();
final Image upArrow = new Image(display, 5, 6);
GC gc = new GC(upArrow);
gc.setBackground(historyButton.getBackground());
gc.fillRectangle(upArrow.getBounds());
gc.setForeground(historyButton.getForeground());
gc.drawLine(0, 5, 4, 5);
gc.drawLine(0, 4, 4, 4);
gc.drawLine(1, 3, 3, 3);
gc.drawLine(1, 2, 3, 2);
gc.drawLine(2, 1, 2, 1);
gc.drawLine(2, 0, 2, 0);
gc.dispose();
historyButton.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
upArrow.dispose();
}
});
historyButton.setImage(upArrow);
} else {
historyButton = new Button(this, SWT.ARROW);
historyButton.setAlignment(SWT.UP);
}
historyButton.setToolTipText(SystemResources.RESID_WORKWITHHISTORY_BUTTON_TIP);
historyButton.getAccessible().addAccessibleListener(new AccessibleAdapter() {
public void getHelp(AccessibleEvent e) { // this is the one that should supply the text heard.