summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSilenio Quarti <silenio>2005-10-21 21:55:20 +0000
committerSilenio Quarti <silenio>2005-10-21 21:55:20 +0000
commit02f95eacfdded39651c1ac1ac9f4a4858e930540 (patch)
tree69b6db58a3b39723c40221f41413024f6e861404
parente69373b213e8626294a43ab53d920e312699c693 (diff)
downloadeclipse.platform.swt-02f95eacfdded39651c1ac1ac9f4a4858e930540.tar.gz
eclipse.platform.swt-02f95eacfdded39651c1ac1ac9f4a4858e930540.tar.xz
eclipse.platform.swt-02f95eacfdded39651c1ac1ac9f4a4858e930540.zip
remove GC creation and use static text instead of icon control
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ToolBar.java15
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ToolItem.java151
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Widget.java7
3 files changed, 147 insertions, 26 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ToolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ToolBar.java
index bb0e62ca04..877cb97811 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ToolBar.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ToolBar.java
@@ -137,7 +137,7 @@ void createItem (ToolItem item, int index) {
item.createWidget ();
System.arraycopy (items, index, items, index + 1, itemCount++ - index);
items [index] = item;
- if (parent.font != null) item.setFontStyle (parent.font);
+ item.setFontStyle (parent.font != null ? parent.font : parent.defaultFont ());
relayout ();
}
@@ -148,7 +148,6 @@ void createWidget () {
}
int defaultThemeFont () {
- if (display.smallFonts) return OS.kThemeSmallSystemFont;
return OS.kThemeToolbarFont;
}
@@ -320,10 +319,9 @@ int [] layoutHorizontal (int width, int height, boolean resize) {
int maxX = 0, rows = 1;
boolean wrap = (style & SWT.WRAP) != 0;
int itemHeight = 0;
- GC gc = new GC(this);
Point [] sizes = new Point [itemCount];
for (int i=0; i<itemCount; i++) {
- Point size = sizes [i] = items [i].computeSize (gc);
+ Point size = sizes [i] = items [i].computeSize ();
itemHeight = Math.max (itemHeight, size.y);
}
for (int i=0; i<itemCount; i++) {
@@ -335,7 +333,7 @@ int [] layoutHorizontal (int width, int height, boolean resize) {
y += ySpacing + itemHeight;
}
if (resize) {
- item.setBounds (x, y, size.x, itemHeight, gc);
+ item.setBounds (x, y, size.x, itemHeight);
boolean visible = x + size.x <= width && y + itemHeight <= height;
item.setVisible (item.handle, visible);
Control control = item.control;
@@ -347,7 +345,6 @@ int [] layoutHorizontal (int width, int height, boolean resize) {
x += xSpacing + size.x;
maxX = Math.max (maxX, x);
}
- gc.dispose();
//TODO - tempporary code
if (resize) invalidateVisibleRegion (handle);
@@ -362,10 +359,9 @@ int [] layoutVertical (int width, int height, boolean resize) {
int maxY = 0, cols = 1;
boolean wrap = (style & SWT.WRAP) != 0;
int itemWidth = 0;
- GC gc = new GC(this);
Point [] sizes = new Point [itemCount];
for (int i=0; i<itemCount; i++) {
- Point size = sizes [i] = items [i].computeSize (gc);
+ Point size = sizes [i] = items [i].computeSize ();
itemWidth = Math.max (itemWidth, size.x);
}
for (int i=0; i<itemCount; i++) {
@@ -377,7 +373,7 @@ int [] layoutVertical (int width, int height, boolean resize) {
y = marginHeight;
}
if (resize) {
- item.setBounds (x, y, itemWidth, size.y, gc);
+ item.setBounds (x, y, itemWidth, size.y);
boolean visible = x + itemWidth <= width && y + size.y <= height;
item.setVisible (item.handle, visible);
Control control = item.control;
@@ -389,7 +385,6 @@ int [] layoutVertical (int width, int height, boolean resize) {
y += ySpacing + size.y;
maxY = Math.max (maxY, y);
}
- gc.dispose();
//TODO - tempporary code
if (resize) invalidateVisibleRegion (handle);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ToolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ToolItem.java
index a7c771ef1d..fade1c740b 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ToolItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/ToolItem.java
@@ -19,6 +19,7 @@ import org.eclipse.swt.internal.carbon.CGRect;
import org.eclipse.swt.internal.carbon.CGPoint;
import org.eclipse.swt.internal.carbon.HIThemeSeparatorDrawInfo;
import org.eclipse.swt.internal.carbon.HIThemePopupArrowDrawInfo;
+import org.eclipse.swt.internal.carbon.HIThemeTextInfo;
import org.eclipse.swt.*;
import org.eclipse.swt.events.*;
@@ -43,7 +44,7 @@ import org.eclipse.swt.graphics.*;
public class ToolItem extends Item {
int handle, iconHandle, labelHandle;
int cIcon, labelCIcon;
- int visibleRgn;
+ int visibleRgn, partCode;
int width = DEFAULT_SEPARATOR_WIDTH;
ToolBar parent;
Image hotImage, disabledImage;
@@ -137,6 +138,24 @@ public ToolItem (ToolBar parent, int style, int index) {
parent.createItem (this, index);
}
+int actionProc (int theControl, int partCode) {
+ if (OS.HIVIEW && text.length () > 0) {
+ this.partCode = partCode;
+ if (theControl == labelHandle) {
+ if (image != null && iconHandle != 0) {
+ int transform = partCode != 0 ? OS.kTransformSelected : 0;
+ OS.SetControlData (iconHandle, OS.kControlEntireControl, OS.kControlIconTransformTag, 2, new short [] {(short)transform});
+ redrawWidget (iconHandle, false);
+ }
+ redrawWidget (labelHandle, false);
+ }
+ if (theControl == iconHandle) {
+ redrawWidget (labelHandle, false);
+ }
+ }
+ return OS.noErr;
+}
+
/**
* Adds the listener to the collection of listeners who will
* be notified when the control is selected, by sending
@@ -170,6 +189,36 @@ public void addSelectionListener(SelectionListener listener) {
addListener(SWT.DefaultSelection,typedListener);
}
+int callPaintEventHandler (int control, int damageRgn, int visibleRgn, int theEvent, int nextHandler) {
+ if (OS.HIVIEW && control == labelHandle && partCode != 0) {
+ HIThemeTextInfo info = new HIThemeTextInfo ();
+ info.state = OS.kThemeStatePressed;
+ Font font = parent.font;
+ if (font != null) {
+ OS.TextFont (font.id);
+ OS.TextFace (font.style);
+ OS.TextSize (font.size);
+ info.fontID = (short) OS.kThemeCurrentPortFont;
+ } else {
+ info.fontID = (short) parent.defaultThemeFont ();
+ }
+ CGRect rect = new CGRect ();
+ OS.HIViewGetBounds (labelHandle, rect);
+ int [] context = new int [1];
+ OS.GetEventParameter (theEvent, OS.kEventParamCGContextRef, OS.typeCGContextRef, null, 4, null, context);
+ int colorspace = OS.CGColorSpaceCreateDeviceRGB ();
+ OS.CGContextSetFillColorSpace (context [0], colorspace);
+ OS.CGColorSpaceRelease (colorspace);
+ OS.CGContextSetFillColor (context [0], parent.foreground != null ? parent.foreground : new float []{0, 0, 0, 1});
+ int [] ptr = new int [1];
+ OS.GetControlData (labelHandle, (short) 0, OS.kControlStaticTextCFStringTag, 4, ptr, null);
+ OS.HIThemeDrawTextBox (ptr [0], rect, info, context [0], OS.kHIThemeOrientationNormal);
+ OS.CFRelease (ptr [0]);
+ return OS.noErr;
+ }
+ return super.callPaintEventHandler (control, damageRgn, visibleRgn, theEvent, nextHandler);
+}
+
static int checkStyle (int style) {
return checkBits (style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.DROP_DOWN, 0);
}
@@ -201,8 +250,8 @@ int colorProc (int inControl, int inMessage, int inDrawDepth, int inDrawInColor)
return OS.eventNotHandledErr;
}
-Point computeSize (GC gc) {
- checkWidget();
+Point computeSize () {
+// checkWidget();
int width = 0, height = 0;
if ((style & SWT.SEPARATOR) != 0) {
if ((parent.style & SWT.HORIZONTAL) != 0) {
@@ -220,8 +269,7 @@ Point computeSize (GC gc) {
if (text.length () != 0 || image != null) {
int stringWidth = 0, stringHeight = 0;
if (text.length () != 0) {
- int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB | SWT.DRAW_MNEMONIC | SWT.DRAW_TRANSPARENT;
- Point size = gc.textExtent (text, flags);
+ Point size = textExtent ();
stringWidth = size.x;
stringHeight = size.y;
}
@@ -265,7 +313,11 @@ void createHandle () {
OS.CreateIconControl(window, null, inContent, false, outControl);
if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
iconHandle = outControl [0];
- OS.CreateIconControl(window, null, inContent, false, outControl);
+ if (OS.HIVIEW) {
+ OS.CreateStaticTextControl (window, null, 0, null, outControl);
+ } else {
+ OS.CreateIconControl (window, null, inContent, false, outControl);
+ }
if (outControl [0] == 0) error (SWT.ERROR_NO_HANDLES);
labelHandle = outControl [0];
}
@@ -589,17 +641,20 @@ void hookEvents () {
int [] mask2 = new int [] {
OS.kEventClassControl, OS.kEventControlDraw,
OS.kEventClassControl, OS.kEventControlContextualMenuClick,
+ OS.kEventClassControl, OS.kEventControlHitTest,
OS.kEventClassControl, OS.kEventControlTrack,
};
if (iconHandle != 0) {
controlTarget = OS.GetControlEventTarget (iconHandle);
OS.InstallEventHandler (controlTarget, controlProc, mask2.length / 2, mask2, iconHandle, null);
OS.SetControlColorProc (iconHandle, colorProc);
+ if (OS.HIVIEW) OS.SetControlAction (iconHandle, display.actionProc);
}
if (labelHandle != 0) {
controlTarget = OS.GetControlEventTarget (labelHandle);
OS.InstallEventHandler (controlTarget, controlProc, mask2.length / 2, mask2, labelHandle, null);
OS.SetControlColorProc (labelHandle, colorProc);
+ if (OS.HIVIEW) OS.SetControlAction (labelHandle, display.actionProc);
}
int helpProc = display.helpProc;
OS.HMInstallControlContentCallback (handle, helpProc);
@@ -652,6 +707,24 @@ int kEventControlHit (int nextHandler, int theEvent, int userData) {
return OS.eventNotHandledErr;
}
+int kEventControlHitTest (int nextHandler, int theEvent, int userData) {
+ if (OS.HIVIEW) {
+ int [] theControl = new int [1];
+ OS.GetEventParameter (theEvent, OS.kEventParamDirectObject, OS.typeControlRef, null, 4, null, theControl);
+ if (theControl [0] == labelHandle) {
+ CGRect rect = new CGRect ();
+ OS.HIViewGetBounds (labelHandle, rect);
+ CGPoint pt = new CGPoint ();
+ OS.GetEventParameter (theEvent, OS.kEventParamMouseLocation, OS.typeHIPoint, null, CGPoint.sizeof, null, pt);
+ if (OS.CGRectContainsPoint (rect, pt) != 0) {
+ OS.SetEventParameter (theEvent, OS.kEventParamControlPart, OS.typeControlPartCode, 2, new short[]{(short)1});
+ return OS.noErr;
+ }
+ }
+ }
+ return OS.eventNotHandledErr;
+}
+
int kEventControlTrack (int nextHandler, int theEvent, int userData) {
tracking = true;
return OS.eventNotHandledErr;
@@ -719,6 +792,14 @@ int kEventMouseDown (int nextHandler, int theEvent, int userData) {
tracking = false;
result = OS.CallNextEventHandler (nextHandler, theEvent);
if (tracking) {
+ if (OS.HIVIEW && text.length () > 0) {
+ partCode = 0;
+ if (labelHandle != 0) redrawWidget (labelHandle, false);
+ if (image != null && iconHandle != 0) {
+ OS.SetControlData (iconHandle, OS.kControlEntireControl, OS.kControlIconTransformTag, 2, new short [] {(short) 0});
+ redrawWidget (iconHandle, false);
+ }
+ }
org.eclipse.swt.internal.carbon.Point outPt = new org.eclipse.swt.internal.carbon.Point ();
OS.GetGlobalMouse (outPt);
Rect rect = new Rect ();
@@ -840,20 +921,19 @@ void setBackground (float [] color) {
parent.setBackground (handle, color);
if (labelHandle != 0) {
parent.setBackground (labelHandle, color);
- updateText (false);
+ if (!OS.HIVIEW) updateText (false);
}
if (iconHandle != 0) parent.setBackground (iconHandle, color);
}
-void setBounds (int x, int y, int width, int height, GC gc) {
+void setBounds (int x, int y, int width, int height) {
setBounds (handle, x, y, width, height, true, true, false);
if ((style & SWT.SEPARATOR) != 0) return;
int space = 0;
int inset = 3;
int stringWidth = 0, stringHeight = 0;
if (text.length () != 0) {
- int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB | SWT.DRAW_MNEMONIC | SWT.DRAW_TRANSPARENT;
- Point size = gc.textExtent (text, flags);
+ Point size = textExtent ();
stringWidth = size.x;
stringHeight = size.y;
}
@@ -945,16 +1025,18 @@ public void setEnabled (boolean enabled) {
}
void setFontStyle (Font font) {
- /* This code is intentionaly commented. */
-// parent.setFontStyle (labelHandle, font);
- updateText (false);
+ if (OS.HIVIEW) {
+ parent.setFontStyle (labelHandle, font);
+ } else {
+ updateText (false);
+ }
}
void setForeground (float [] color) {
parent.setForeground (handle, color);
if (labelHandle != 0) {
parent.setForeground (labelHandle, color);
- updateText (false);
+ if (!OS.HIVIEW) updateText (false);
}
if (iconHandle != 0) parent.setForeground (iconHandle, color);
}
@@ -1086,7 +1168,18 @@ public void setText (String string) {
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
if ((style & SWT.SEPARATOR) != 0) return;
super.setText (string);
- updateText (true);
+ if (OS.HIVIEW) {
+ char [] buffer = new char [text.length ()];
+ text.getChars (0, buffer.length, buffer, 0);
+ int length = fixMnemonic (buffer);
+ int ptr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, length);
+ if (ptr == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
+ OS.SetControlData (labelHandle, 0 , OS.kControlStaticTextCFStringTag, 4, new int[]{ptr});
+ OS.CFRelease (ptr);
+ redrawWidget (labelHandle, false);
+ } else {
+ updateText (true);
+ }
}
/**
@@ -1197,4 +1290,32 @@ void updateText (boolean layout) {
}
}
+Point textExtent () {
+ if (OS.HIVIEW) {
+ float [] w = new float [1], h = new float [1];
+ HIThemeTextInfo info = new HIThemeTextInfo ();
+ info.state = OS.kThemeStateActive;
+ Font font = parent.font;
+ if (font != null) {
+ OS.TextFont (font.id);
+ OS.TextFace (font.style);
+ OS.TextSize (font.size);
+ info.fontID = (short) OS.kThemeCurrentPortFont;
+ } else {
+ info.fontID = (short) parent.defaultThemeFont ();
+ }
+ int [] ptr = new int [1];
+ OS.GetControlData (labelHandle, (short) 0, OS.kControlStaticTextCFStringTag, 4, ptr, null);
+ OS.HIThemeGetTextDimensions (ptr [0], 0, info, w, h, null);
+ OS.CFRelease (ptr [0]);
+ return new Point ((int) w [0], (int) h [0]);
+ } else {
+ GC gc = new GC (parent);
+ int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB | SWT.DRAW_MNEMONIC | SWT.DRAW_TRANSPARENT;
+ Point size = gc.textExtent (text, flags);
+ gc.dispose ();
+ return size;
+ }
+}
+
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Widget.java
index 54f3a99f8f..805858cfd6 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Widget.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Widget.java
@@ -346,7 +346,8 @@ int controlProc (int nextHandler, int theEvent, int userData) {
case OS.kEventControlSetCursor: return kEventControlSetCursor (nextHandler, theEvent, userData);
case OS.kEventControlSetFocusPart: return kEventControlSetFocusPart (nextHandler, theEvent, userData);
case OS.kEventControlTrack: return kEventControlTrack (nextHandler, theEvent, userData);
- case OS.kEventControlGetFocusPart: return kEventControlGetFocusPart (nextHandler, theEvent, userData);
+ case OS.kEventControlGetFocusPart: return kEventControlGetFocusPart (nextHandler, theEvent, userData);
+ case OS.kEventControlHitTest: return kEventControlHitTest (nextHandler, theEvent, userData);
}
return OS.eventNotHandledErr;
}
@@ -1098,6 +1099,10 @@ int kEventControlHit (int nextHandler, int theEvent, int userData) {
return OS.eventNotHandledErr;
}
+int kEventControlHitTest (int nextHandler, int theEvent, int userData) {
+ return OS.eventNotHandledErr;
+}
+
int kEventControlSetCursor (int nextHandler, int theEvent, int userData) {
return OS.eventNotHandledErr;
}