Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Label.java')
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Label.java189
1 files changed, 134 insertions, 55 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Label.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Label.java
index ac5f1acd86..0bd2a8b36b 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Label.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Label.java
@@ -1,8 +1,8 @@
package org.eclipse.swt.widgets;
/*
- * Licensed Materials - Property of IBM,
- * (c) Copyright IBM Corp. 1998, 2001 All Rights Reserved
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
*/
import org.eclipse.swt.internal.*;
@@ -11,6 +11,7 @@ import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
public class Label extends Control {
+ String text = "";
Image image;
public Label (Composite parent, int style) {
@@ -24,9 +25,9 @@ static int checkStyle (int style) {
public Point computeSize (int wHint, int hHint, boolean changed) {
if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- int border = getBorderWidth ();
- int width = border * 2, height = border * 2;
if ((style & SWT.SEPARATOR) != 0) {
+ int border = getBorderWidth ();
+ int width = border * 2, height = border * 2;
if ((style & SWT.HORIZONTAL) != 0) {
width += DEFAULT_WIDTH; height += 3;
} else {
@@ -36,23 +37,79 @@ public Point computeSize (int wHint, int hHint, boolean changed) {
if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
return new Point (width, height);
}
+
+ if ((style & SWT.WRAP) != 0) {
+ int [] args = {
+ OS.Pt_ARG_LABEL_TYPE, 0, 0, // 1
+ OS.Pt_ARG_TEXT_FONT, 0, 0, // 4
+ OS.Pt_ARG_LINE_SPACING, 0, 0, // 7
+ OS.Pt_ARG_MARGIN_WIDTH, 0, 0, // 10
+ OS.Pt_ARG_MARGIN_HEIGHT, 0, 0, // 13
+ OS.Pt_ARG_MARGIN_LEFT, 0, 0, // 16
+ OS.Pt_ARG_MARGIN_RIGHT, 0, 0, // 19
+ OS.Pt_ARG_MARGIN_TOP, 0, 0, // 22
+ OS.Pt_ARG_MARGIN_BOTTOM, 0, 0, // 25
+ };
+ OS.PtGetResources (handle, args.length / 3, args);
+ /* If we are wrapping text, calculate the height based on wHint. */
+ if (args [1] == OS.Pt_Z_STRING) {
+ int length = OS.strlen (args [4]);
+ byte [] font = new byte [length + 1];
+ OS.memmove (font, args [4], length);
+ Display display = getDisplay ();
+ PhRect_t rect = new PhRect_t ();
+ String string = text;
+ if (wHint != SWT.DEFAULT) {
+ string = display.wrapText (text, font, wHint);
+ }
+ if (hHint != SWT.DEFAULT) {
+ rect.ul_y = 0;
+ rect.lr_y = (short)(hHint - 1);
+ } else {
+ byte [] buffer = Converter.wcsToMbcs (null, string, false);
+ OS.PgExtentMultiText (rect, null, font, buffer, buffer.length, args [7]);
+ }
+ PhArea_t area = new PhArea_t ();
+ OS.PtSetAreaFromWidgetCanvas (handle, rect, area);
+ int width = area.size_w;
+ int height = area.size_h;
+ width += (args [10] * 2) + args [16] + args [19];
+ height += (args [13] * 2) + args [22] + args [25];
+ return new Point (width, height);
+ }
+ }
+
PhDim_t dim = new PhDim_t();
if (!OS.PtWidgetIsRealized (handle)) OS.PtExtentWidget (handle);
OS.PtWidgetPreferredSize(handle, dim);
- width = dim.w; height = dim.h;
+ int width = dim.w, height = dim.h;
if (wHint != SWT.DEFAULT || hHint != SWT.DEFAULT) {
+ int [] args = {
+ OS.Pt_ARG_MARGIN_WIDTH, 0, 0, // 1
+ OS.Pt_ARG_MARGIN_HEIGHT, 0, 0, // 4
+ OS.Pt_ARG_MARGIN_LEFT, 0, 0, // 7
+ OS.Pt_ARG_MARGIN_RIGHT, 0, 0, // 10
+ OS.Pt_ARG_MARGIN_TOP, 0, 0, // 13
+ OS.Pt_ARG_MARGIN_BOTTOM, 0, 0, // 16
+ };
+ OS.PtGetResources (handle, args.length / 3, args);
PhRect_t rect = new PhRect_t ();
PhArea_t area = new PhArea_t ();
rect.lr_x = (short) (wHint - 1);
rect.lr_y = (short) (hHint - 1);
OS.PtSetAreaFromWidgetCanvas (handle, rect, area);
- if (wHint != SWT.DEFAULT) width = area.size_w;
- if (hHint != SWT.DEFAULT) height = area.size_h;
+ if (wHint != SWT.DEFAULT) {
+ width = area.size_w + (args [1] * 2) + args [7] + args [10];
+ }
+ if (hHint != SWT.DEFAULT) {
+ height = area.size_h + (args [4] * 2) + args [13] + args [16];
+ }
}
return new Point (width, height);
}
void createHandle (int index) {
+ state |= HANDLE;
Display display = getDisplay ();
int parentHandle = parent.handle;
@@ -75,8 +132,12 @@ void createHandle (int index) {
int alignment = OS.Pt_LEFT;
if ((style & SWT.CENTER) != 0) alignment = OS.Pt_CENTER;
if ((style & SWT.RIGHT) != 0) alignment = OS.Pt_RIGHT;
+ int verticalAlign = (style & SWT.WRAP) != 0 ? OS.Pt_TOP : OS.Pt_CENTER;
+ boolean hasBorder = (style & SWT.BORDER) != 0;
int [] args = {
+ OS.Pt_ARG_FLAGS, hasBorder ? OS.Pt_HIGHLIGHTED : 0, OS.Pt_HIGHLIGHTED,
OS.Pt_ARG_HORIZONTAL_ALIGNMENT, alignment, 0,
+ OS.Pt_ARG_VERTICAL_ALIGNMENT, verticalAlign, 0,
OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS,
};
handle = OS.PtCreateWidget (clazz, parentHandle, args.length / 3, args);
@@ -107,44 +168,7 @@ public String getText () {
if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
if ((style & SWT.SEPARATOR) != 0) return "";
- int [] args = {
- OS.Pt_ARG_TEXT_STRING, 0, 0,
- OS.Pt_ARG_ACCEL_KEY, 0, 0,
- };
- OS.PtGetResources (handle, args.length / 3, args);
- if (args [1] == 0) return "";
- int length = OS.strlen (args [1]);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, args [1], length);
- char [] result = Converter.mbcsToWcs (null, buffer);
- int count = 0;
- int mnemonic = 0;
- if (args [4] != 0) {
- int length2 = OS.strlen (args [4]);
- if (length2 > 0) {
- byte [] buffer2 = new byte [length2];
- OS.memmove (buffer2, args [4], length2);
- char [] result2 = Converter.mbcsToWcs (null, buffer2);
- if (result2.length > 0) mnemonic = result2 [0];
- }
- }
- if (mnemonic != 0) count++;
- for (int i=0; i<result.length-1; i++)
- if (result [i] == Mnemonic) count++;
- char [] newResult = result;
- if ((count != 0) || (mnemonic != 0)) {
- newResult = new char [result.length + count];
- int i = 0, j = 0;
- while (i < result.length) {
- if ((mnemonic != 0) && (result [i] == mnemonic)) {
- if (j < newResult.length) newResult [j++] = Mnemonic;
- mnemonic = 0;
- }
- if ((newResult [j++] = result [i++]) == Mnemonic)
- if (j < newResult.length) newResult [j++] = Mnemonic;
- }
- }
- return new String (newResult);
+ return text;
}
int processPaint (int damage) {
@@ -154,9 +178,28 @@ int processPaint (int damage) {
return super.processPaint (damage);
}
+int processActivate (int info) {
+ Composite control = this.parent;
+ while (control != null) {
+ Control [] children = control._getChildren ();
+ int index = 0;
+ while (index < children.length) {
+ if (children [index] == this) break;
+ index++;
+ }
+ index++;
+ if (index < children.length) {
+ if (children [index].setFocus ()) return OS.Pt_CONTINUE;
+ }
+ control = control.parent;
+ }
+ return OS.Pt_CONTINUE;
+}
+
void releaseWidget () {
super.releaseWidget ();
image = null;
+ text = null;
}
public void setAlignment (int alignment) {
@@ -172,10 +215,20 @@ public void setAlignment (int alignment) {
OS.PtSetResources (handle, args.length / 3, args);
}
+void setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
+ super.setBounds (x, y, width, height, move, resize);
+ if (resize && (style & SWT.WRAP) != 0) setText (text);
+}
+
public boolean setFocus () {
return false;
}
+public void setFont (Font font) {
+ super.setFont (font);
+ if ((style & SWT.WRAP) != 0) setText (text);
+}
+
public void setImage (Image image) {
if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
@@ -196,20 +249,45 @@ public void setText (String string) {
if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
if ((style & SWT.SEPARATOR) != 0) return;
- char [] text = new char [string.length ()];
- string.getChars (0, text.length, text, 0);
+ text = string;
+ char [] unicode = new char [string.length ()];
+ string.getChars (0, unicode.length, unicode, 0);
int i=0, j=0;
char mnemonic=0;
- while (i < text.length) {
- if ((text [j++] = text [i++]) == Mnemonic) {
- if (i == text.length) {continue;}
- if (text [i] == Mnemonic) {i++; continue;}
- if (mnemonic == 0) mnemonic = text [i];
+ while (i < unicode.length) {
+ if ((unicode [j++] = unicode [i++]) == Mnemonic) {
+ if (i == unicode.length) {continue;}
+ if (unicode [i] == Mnemonic) {i++; continue;}
+ if (mnemonic == 0) mnemonic = unicode [i];
j--;
}
}
- while (j < text.length) text [j++] = 0;
- byte [] buffer = Converter.wcsToMbcs (null, text, true);
+ while (j < unicode.length) unicode [j++] = 0;
+ /* Wrap the text if necessary, and convert to mbcs. */
+ byte [] buffer;
+ if ((style & SWT.WRAP) != 0) {
+ int [] args = {
+ OS.Pt_ARG_TEXT_FONT, 0, 0, // 1
+ OS.Pt_ARG_WIDTH, 0, 0, // 4
+ OS.Pt_ARG_MARGIN_WIDTH, 0, 0, // 7
+ OS.Pt_ARG_MARGIN_LEFT, 0, 0, // 10
+ OS.Pt_ARG_MARGIN_RIGHT, 0, 0, // 13
+ };
+ OS.PtGetResources (handle, args.length / 3, args);
+ int length = OS.strlen (args [1]);
+ byte [] font = new byte [length + 1];
+ OS.memmove (font, args [1], length);
+ int border = 0;
+ if ((style & SWT.BORDER) != 0) border = 2;
+ int width = args [4];
+ width -= (args [7] * 2) + args [10] + args [13] + border * 2;
+ Display display = getDisplay ();
+ if (mnemonic != '\0') string = new String (unicode);
+ string = display.wrapText (string, font, width);
+ buffer = Converter.wcsToMbcs (null, string, true);
+ } else {
+ buffer = Converter.wcsToMbcs (null, unicode, true);
+ }
int ptr = OS.malloc (buffer.length);
OS.memmove (ptr, buffer, buffer.length);
int ptr2 = 0;
@@ -218,6 +296,7 @@ public void setText (String string) {
ptr2 = OS.malloc (buffer2.length);
OS.memmove (ptr2, buffer2, buffer2.length);
}
+ replaceMnemonic (mnemonic, 0);
int [] args = {
OS.Pt_ARG_TEXT_STRING, ptr, 0,
OS.Pt_ARG_LABEL_TYPE, OS.Pt_Z_STRING, 0,
@@ -228,4 +307,4 @@ public void setText (String string) {
OS.free (ptr2);
}
-} \ No newline at end of file
+}

Back to the top