diff dwt/custom/CTabItem.d @ 240:ce446666f5a2

Update to SWT 3.4M7
author Frank Benoit <benoit@tionex.de>
date Mon, 12 May 2008 19:13:01 +0200
parents 380bad9f6852
children 5a30aa9820f3
line wrap: on
line diff
--- a/dwt/custom/CTabItem.d	Mon May 12 15:36:37 2008 +0200
+++ b/dwt/custom/CTabItem.d	Mon May 12 19:13:01 2008 +0200
@@ -25,6 +25,7 @@
 import dwt.graphics.Point;
 import dwt.graphics.RGB;
 import dwt.graphics.Rectangle;
+import dwt.graphics.TextLayout;
 import dwt.widgets.Control;
 import dwt.widgets.Display;
 import dwt.widgets.Item;
@@ -135,13 +136,10 @@
  */
 public this (CTabFolder parent, int style, int index) {
     closeRect = new Rectangle(0, 0, 0, 0);
-    super (parent, checkStyle(style));
+    super (parent, style);
     showClose = (style & DWT.CLOSE) !is 0;
     parent.createItem (this, index);
 }
-static int checkStyle(int style) {
-    return DWT.NONE;
-}
 
 /*
  * Return whether to use ellipses or just truncate labels
@@ -160,16 +158,19 @@
     if (gc.textExtent(text, FLAGS).x <= width) return text;
     int ellipseWidth = gc.textExtent(ellipses, FLAGS).x;
     int length = text.length;
-    int end = length - 1;
+    TextLayout layout = new TextLayout(getDisplay());
+    layout.setText(text);
+    int end = layout.getPreviousOffset(length, DWT.MOVEMENT_CLUSTER);
     while (end > 0) {
         text = text[ 0 .. end ];
         int l = gc.textExtent(text, FLAGS).x;
         if (l + ellipseWidth <= width) {
-            return text ~ ellipses;
+            break;
         }
-        end--;
+        end = layout.getPreviousOffset(end, DWT.MOVEMENT_CLUSTER);
     }
-    return text[ 0 .. 1 ];
+    layout.dispose();
+    return end is 0 ? text.substring(0, 1) : text ~ ellipses;
 }
 
 public override void dispose() {
@@ -768,6 +769,24 @@
     return parent;
 }
 /**
+ * Returns <code>true</code> to indicate that the receiver's close button should be shown.
+ * Otherwise return <code>false</code>. The initial value is defined by the style (DWT.CLOSE)
+ * that was used to create the receiver.
+ * 
+ * @return <code>true</code> if the close button should be shown
+ *
+ * @exception DWTException <ul>
+ *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ * 
+ * @since 3.4
+ */
+public bool getShowClose() {
+    checkWidget();
+    return showClose;
+}
+/**
  * Returns the receiver's tool tip text, or null if it has
  * not been set.
  *
@@ -998,6 +1017,27 @@
         parent.redrawTabs();
     }
 }
+/**
+ * Sets to <code>true</code> to indicate that the receiver's close button should be shown.
+ * If the parent (CTabFolder) was created with DWT.CLOSE style, changing this value has
+ * no effect.
+ * 
+ * @param close the new state of the close button
+ *
+ * @exception DWTException <ul>
+ *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ * 
+ * @since 3.4
+ */
+public void setShowClose(bool close) {
+    checkWidget();
+    if (showClose is close) return;
+    showClose = close;
+    parent.updateItems();
+    parent.redrawTabs();
+}
 public override void setText (String string) {
     checkWidget();
     if (string is null) DWT.error (DWT.ERROR_NULL_ARGUMENT);
@@ -1025,4 +1065,5 @@
     checkWidget();
     toolTipText = string;
 }
+
 }