changeset 77:26c6c9dfd13c

ui.forms compile, just FormTextModel with xml reimpl left todo
author Frank Benoit <benoit@tionex.de>
date Sat, 24 May 2008 06:59:31 +0200
parents e193036d82c9
children 4ac9946b9fb5
files dwtx/ui/forms/widgets/ToggleHyperlink.d dwtx/ui/internal/forms/widgets/BusyIndicator.d dwtx/ui/internal/forms/widgets/FormImages.d dwtx/ui/internal/forms/widgets/FormUtil.d dwtx/ui/internal/forms/widgets/FormsResources.d dwtx/ui/internal/forms/widgets/ImageHyperlinkSegment.d dwtx/ui/internal/forms/widgets/ImageSegment.d dwtx/ui/internal/forms/widgets/Locator.d dwtx/ui/internal/forms/widgets/ObjectSegment.d dwtx/ui/internal/forms/widgets/Paragraph.d dwtx/ui/internal/forms/widgets/PixelConverter.d dwtx/ui/internal/forms/widgets/SWTUtil.d dwtx/ui/internal/forms/widgets/SelectionData.d dwtx/ui/internal/forms/widgets/TextHyperlinkSegment.d dwtx/ui/internal/forms/widgets/TextSegment.d dwtx/ui/internal/forms/widgets/TitleRegion.d
diffstat 16 files changed, 102 insertions(+), 70 deletions(-) [+]
line wrap: on
line diff
--- a/dwtx/ui/forms/widgets/ToggleHyperlink.d	Sat May 24 06:18:55 2008 +0200
+++ b/dwtx/ui/forms/widgets/ToggleHyperlink.d	Sat May 24 06:59:31 2008 +0200
@@ -44,6 +44,9 @@
  * @since 3.0
  */
 public abstract class ToggleHyperlink : AbstractHyperlink {
+
+    alias AbstractHyperlink.computeSize computeSize;
+
     protected int innerWidth;
     protected int innerHeight;
     protected bool hover;
--- a/dwtx/ui/internal/forms/widgets/BusyIndicator.d	Sat May 24 06:18:55 2008 +0200
+++ b/dwtx/ui/internal/forms/widgets/BusyIndicator.d	Sat May 24 06:59:31 2008 +0200
@@ -36,6 +36,8 @@
 
 public final class BusyIndicator : Canvas {
 
+    alias Canvas.computeSize computeSize;
+
     class BusyThread : Thread {
         Rectangle bounds;
         Display display;
--- a/dwtx/ui/internal/forms/widgets/FormImages.d	Sat May 24 06:18:55 2008 +0200
+++ b/dwtx/ui/internal/forms/widgets/FormImages.d	Sat May 24 06:59:31 2008 +0200
@@ -117,9 +117,9 @@
             if (null !is cast(ComplexImageIdentifier)obj ) {
                 ComplexImageIdentifier id = cast(ComplexImageIdentifier) obj;
                 if (super.equals(obj)  &&
-                        id.fVertical is fVertical && Arrays.opEquals(id.fPercents, fPercents)) {
+                        id.fVertical is fVertical && ArrayEquals(id.fPercents, fPercents)) {
                     if ((id.fBg is null && fBg is null) ||
-                            (id.fBg !is null && id.fBg.equals(fBg)))
+                            (id.fBg !is null && id.fBg.opEquals(fBg)))
                         return true;
                     // if the only thing that isn't the same is the background color
                     // still return true if it does not matter (percents add up to 100)
@@ -189,8 +189,8 @@
             return result.getImage();
         }
         Image image = createGradient(display, colors, percents, length, vertical, bg);
-        images.put(id, new ImageReference(image));
-        ids.put(image, id);
+        images.add(id, new ImageReference(image));
+        ids.add(image, id);
         return image;
     }
 
--- a/dwtx/ui/internal/forms/widgets/FormUtil.d	Sat May 24 06:18:55 2008 +0200
+++ b/dwtx/ui/internal/forms/widgets/FormUtil.d	Sat May 24 06:59:31 2008 +0200
@@ -75,12 +75,12 @@
 
     static const int V_SCROLL_INCREMENT = 64;
 
-    public static const String DEBUG = PLUGIN_ID + "/debug"; //$NON-NLS-1$
+    public static const String DEBUG = PLUGIN_ID ~ "/debug"; //$NON-NLS-1$
 
-    public static const String DEBUG_TEXT = DEBUG + "/text"; //$NON-NLS-1$
-    public static const String DEBUG_TEXTSIZE = DEBUG + "/textsize"; //$NON-NLS-1$
+    public static const String DEBUG_TEXT = DEBUG ~ "/text"; //$NON-NLS-1$
+    public static const String DEBUG_TEXTSIZE = DEBUG ~ "/textsize"; //$NON-NLS-1$
 
-    public static const String DEBUG_FOCUS = DEBUG + "/focus"; //$NON-NLS-1$
+    public static const String DEBUG_FOCUS = DEBUG ~ "/focus"; //$NON-NLS-1$
 
     public static const String FOCUS_SCROLLING = "focusScrolling"; //$NON-NLS-1$
 
@@ -247,7 +247,7 @@
         ScrolledComposite scomp = getScrolledComposite(c);
         if (scomp !is null) {
             Object data = scomp.getData(FOCUS_SCROLLING);
-            if (data is null || !data.equals(Boolean.FALSE))
+            if (data is null || !data.opEquals(Boolean.FALSE))
                 FormUtil.ensureVisible(scomp, c);
         }
     }
@@ -510,16 +510,16 @@
         return new Image(device, data);
     }
 
-    public static bool mnemonicMatch(String text, char key) {
+    public static bool mnemonicMatch(String text, dchar key) {
         char mnemonic = findMnemonic(text);
         if (mnemonic is '\0')
             return false;
-        return Character.toUpperCase(key) is Character.toUpperCase(mnemonic);
+        return CharacterToUpper(key) is CharacterToUpper(mnemonic);
     }
 
     private static char findMnemonic(String string) {
         int index = 0;
-        int length = string.length();
+        int length = string.length;
         do {
             while (index < length && string.charAt(index) !is '&')
                 index++;
--- a/dwtx/ui/internal/forms/widgets/FormsResources.d	Sat May 24 06:18:55 2008 +0200
+++ b/dwtx/ui/internal/forms/widgets/FormsResources.d	Sat May 24 06:59:31 2008 +0200
@@ -31,17 +31,17 @@
     private static Cursor textCursor;
 
     public static Cursor getBusyCursor() {
-        if (busyCursorisnull)
+        if (busyCursor is null)
             busyCursor = new Cursor(Display.getCurrent(), DWT.CURSOR_WAIT);
         return busyCursor;
     }
     public static Cursor getHandCursor() {
-        if (handCursorisnull)
+        if (handCursor is null)
             handCursor = new Cursor(Display.getCurrent(), DWT.CURSOR_HAND);
         return handCursor;
     }
     public static Cursor getTextCursor() {
-        if (textCursorisnull)
+        if (textCursor is null)
             textCursor = new Cursor(Display.getCurrent(), DWT.CURSOR_IBEAM);
         return textCursor;
     }
--- a/dwtx/ui/internal/forms/widgets/ImageHyperlinkSegment.d	Sat May 24 06:18:55 2008 +0200
+++ b/dwtx/ui/internal/forms/widgets/ImageHyperlinkSegment.d	Sat May 24 06:59:31 2008 +0200
@@ -30,6 +30,14 @@
 
     private String tooltipText;
 
+    // reimpl for interface
+    bool contains(int x, int y){
+        return super.contains(x,y);
+    }
+    bool intersects(Rectangle rect){
+        return super.intersects(rect);
+    }
+
     public this() {
     }
 
--- a/dwtx/ui/internal/forms/widgets/ImageSegment.d	Sat May 24 06:18:55 2008 +0200
+++ b/dwtx/ui/internal/forms/widgets/ImageSegment.d	Sat May 24 06:59:31 2008 +0200
@@ -14,6 +14,7 @@
 
 import dwtx.ui.internal.forms.widgets.ObjectSegment;
 import dwtx.ui.internal.forms.widgets.SelectionData;
+import dwtx.ui.internal.forms.widgets.FormUtil;
 
 import dwt.graphics.Color;
 import dwt.graphics.GC;
@@ -48,12 +49,12 @@
     }
 
     private Image getSelectedImage(Hashtable objectTable, SelectionData selData) {
-        String key = SEL_IMAGE_PREFIX + getObjectId();
+        String key = SEL_IMAGE_PREFIX ~ getObjectId();
         Image image = getImage(key, objectTable);
         if (image is null) {
             image = FormUtil.createAlphaMashImage(selData.display, getImage(objectTable));
             if (image !is null)
-                objectTable.put(key, image);
+                objectTable.add(key, image);
         }
         return image;
     }
--- a/dwtx/ui/internal/forms/widgets/Locator.d	Sat May 24 06:18:55 2008 +0200
+++ b/dwtx/ui/internal/forms/widgets/Locator.d	Sat May 24 06:59:31 2008 +0200
@@ -48,15 +48,15 @@
     }
 
     public Locator create() {
-        try {
+//         try {
             return cast(Locator)clone();
-        }
-        catch (CloneNotSupportedException e) {
-            return null;
-        }
+//         }
+//         catch (CloneNotSupportedException e) {
+//             return null;
+//         }
     }
     public void collectHeights() {
-        heights.add(new ArrayWrapperInt( [ rowHeight, leading ] ) );
+        heights.append(new ArrayWrapperInt( [ rowHeight, leading ] ) );
         rowCounter++;
     }
     public int getBaseline(int segmentHeight) {
--- a/dwtx/ui/internal/forms/widgets/ObjectSegment.d	Sat May 24 06:18:55 2008 +0200
+++ b/dwtx/ui/internal/forms/widgets/ObjectSegment.d	Sat May 24 06:59:31 2008 +0200
@@ -84,12 +84,12 @@
     }
 
     public bool contains(int x, int y) {
-        if (boundsisnull)
+        if (bounds is null)
             return false;
         return bounds.contains(x, y);
     }
     public bool intersects(Rectangle rect) {
-        if (boundsisnull)
+        if (bounds is null)
             return false;
         return bounds.intersects(rect);
     }
@@ -140,9 +140,9 @@
         int ix = loc.x;
         int iy = loc.y;
 
-        if (alignmentisMIDDLE)
+        if (alignment is MIDDLE)
             iy = loc.getMiddle(objHeight, false);
-        else if (alignmentisBOTTOM)
+        else if (alignment is BOTTOM)
             iy = loc.getBaseline(objHeight, false);
         loc.x += objWidth;
         loc.rowHeight = Math.max(loc.rowHeight, objHeight);
--- a/dwtx/ui/internal/forms/widgets/Paragraph.d	Sat May 24 06:18:55 2008 +0200
+++ b/dwtx/ui/internal/forms/widgets/Paragraph.d	Sat May 24 06:59:31 2008 +0200
@@ -16,6 +16,8 @@
 import dwtx.ui.internal.forms.widgets.Locator;
 import dwtx.ui.internal.forms.widgets.IHyperlinkSegment;
 import dwtx.ui.internal.forms.widgets.SelectionData;
+import dwtx.ui.internal.forms.widgets.TextSegment;
+import dwtx.ui.internal.forms.widgets.TextHyperlinkSegment;
 
 import dwt.graphics.GC;
 import dwt.graphics.Rectangle;
@@ -24,6 +26,8 @@
 import dwt.dwthelper.utils;
 import tango.util.collection.ArraySeq;
 import tango.util.collection.HashMap;
+import tango.io.FileConst;
+import tango.text.Text;
 
 /**
  * @version 1.0
@@ -56,7 +60,7 @@
      */
     public ParagraphSegment[] getSegments() {
         if (segments is null)
-            return new TArraySeqParagraphSegment;
+            return null;
         return segments
                 .toArray();
     }
@@ -74,7 +78,7 @@
 
     public void parseRegularText(String text, bool expandURLs, bool wrapAllowed,
             HyperlinkSettings settings, String fontId, String colorId) {
-        if (text.length() is 0)
+        if (text.length is 0)
             return;
         if (expandURLs) {
             int loc = text.indexOf(HTTP);
@@ -87,9 +91,9 @@
                     addSegment(new TextSegment(text.substring(textLoc, loc),
                             fontId, colorId, wrapAllowed));
                     bool added = false;
-                    for (textLoc = loc; textLoc < text.length(); textLoc++) {
+                    for (textLoc = loc; textLoc < text.length; textLoc++) {
                         char c = text.charAt(textLoc);
-                        if (Character.isSpaceChar(c)) {
+                        if (CharacterIsWhitespace(c)) {
                             addHyperlinkSegment(text.substring(loc, textLoc),
                                     settings, fontId);
                             added = true;
@@ -104,7 +108,7 @@
                     }
                     loc = text.indexOf(HTTP, textLoc);
                 }
-                if (textLoc < text.length()) {
+                if (textLoc < text.length) {
                     addSegment(new TextSegment(text.substring(textLoc), fontId,
                             colorId, wrapAllowed));
                 }
@@ -128,7 +132,7 @@
         ParagraphSegment[] segments = getSegments();
         // compute heights
         Locator hloc = loc.create();
-        ArrayList heights = new ArrayList();
+        ArraySeq!(ArrayWrapperInt) heights = new ArraySeq!(ArrayWrapperInt);
         hloc.heights = heights;
         hloc.rowCounter = 0;
         int innerWidth = width - loc.marginWidth*2;
@@ -157,7 +161,7 @@
             for (int j = 0; j < segments.length; j++) {
                 ParagraphSegment segment = segments[j];
                 bool doSelect = false;
-                if (selectedLink !is null && segment.equals(selectedLink))
+                if (selectedLink !is null && segment.opEquals(cast(Object)selectedLink))
                     doSelect = true;
                 segment.layout(gc, width, loc, resourceTable, doSelect);
             }
@@ -178,7 +182,7 @@
             if (!segment.intersects(repaintRegion))
                 continue;
             bool doSelect = false;
-            if (selectedLink !is null && segment.equals(selectedLink))
+            if (selectedLink !is null && segment.opEquals(cast(Object)selectedLink))
                 doSelect = true;
             segment.paint(gc, false, resourceTable, doSelect, selData, repaintRegion);
         }
@@ -199,18 +203,16 @@
 
     public String getAccessibleText() {
         ParagraphSegment[] segments = getSegments();
-        StringWriter swriter = new StringWriter();
-        PrintWriter writer = new PrintWriter(swriter);
+        auto txt = new tango.text.Text.Text!(char);
         for (int i = 0; i < segments.length; i++) {
             ParagraphSegment segment = segments[i];
             if ( auto ts = cast(TextSegment)segment ) {
                 String text = ts.getText();
-                writer.print(text);
+                txt.append(text);
             }
         }
-        writer.println();
-        swriter.flush();
-        return swriter.toString();
+        txt.append( FileConst.NewlineString );
+        return txt.toString();
     }
 
     public ParagraphSegment findSegmentAt(int x, int y) {
--- a/dwtx/ui/internal/forms/widgets/PixelConverter.d	Sat May 24 06:18:55 2008 +0200
+++ b/dwtx/ui/internal/forms/widgets/PixelConverter.d	Sat May 24 06:59:31 2008 +0200
@@ -20,11 +20,11 @@
     /**
      * Number of horizontal dialog units per character, value <code>4</code>.
      */
-    private static final int HORIZONTAL_DIALOG_UNIT_PER_CHAR = 4;
+    private static const int HORIZONTAL_DIALOG_UNIT_PER_CHAR = 4;
 
     private FontMetrics fFontMetrics;
 
-    public PixelConverter(Control control) {
+    public this(Control control) {
         GC gc = new GC(control);
         gc.setFont(control.getFont());
         fFontMetrics = gc.getFontMetrics();
--- a/dwtx/ui/internal/forms/widgets/SWTUtil.d	Sat May 24 06:18:55 2008 +0200
+++ b/dwtx/ui/internal/forms/widgets/SWTUtil.d	Sat May 24 06:59:31 2008 +0200
@@ -22,7 +22,7 @@
 import dwt.widgets.Widget;
 
 /**
- * Utility class to simplify access to some DWT resources. 
+ * Utility class to simplify access to some DWT resources.
  */
 public class SWTUtil {
 
@@ -42,22 +42,22 @@
     /**
      * Returns the shell for the given widget. If the widget doesn't represent
      * a DWT object that manage a shell, <code>null</code> is returned.
-     * 
+     *
      * @return the shell for the given widget
      */
     public static Shell getShell(Widget widget) {
-        if (widget instanceof Control)
-            return ((Control) widget).getShell();
-        if (widget instanceof Caret)
-            return ((Caret) widget).getParent().getShell();
-        if (widget instanceof DragSource)
-            return ((DragSource) widget).getControl().getShell();
-        if (widget instanceof DropTarget)
-            return ((DropTarget) widget).getControl().getShell();
-        if (widget instanceof Menu)
-            return ((Menu) widget).getParent().getShell();
-        if (widget instanceof ScrollBar)
-            return ((ScrollBar) widget).getParent().getShell();
+        if (null !is cast(Control)widget )
+            return (cast(Control) widget).getShell();
+        if (null !is cast(Caret)widget )
+            return (cast(Caret) widget).getParent().getShell();
+        if (null !is cast(DragSource)widget )
+            return (cast(DragSource) widget).getControl().getShell();
+        if (null !is cast(DropTarget)widget )
+            return (cast(DropTarget) widget).getControl().getShell();
+        if (null !is cast(Menu)widget )
+            return (cast(Menu) widget).getParent().getShell();
+        if (null !is cast(ScrollBar)widget )
+            return (cast(ScrollBar) widget).getParent().getShell();
 
         return null;
     }
--- a/dwtx/ui/internal/forms/widgets/SelectionData.d	Sat May 24 06:18:55 2008 +0200
+++ b/dwtx/ui/internal/forms/widgets/SelectionData.d	Sat May 24 06:59:31 2008 +0200
@@ -104,7 +104,7 @@
         return start.x > stop.x;
     }
     public bool isEnclosed() {
-        return !start.equals(stop);
+        return !start.opEquals(stop);
     }
 
     public bool isSelectedRow(Locator locator) {
--- a/dwtx/ui/internal/forms/widgets/TextHyperlinkSegment.d	Sat May 24 06:18:55 2008 +0200
+++ b/dwtx/ui/internal/forms/widgets/TextHyperlinkSegment.d	Sat May 24 06:59:31 2008 +0200
@@ -38,6 +38,20 @@
 
     private HyperlinkSettings settings;
 
+    // reimpl for interface
+    String getText(){
+        return super.getText();
+    }
+    void paintFocus(GC gc, Color bg, Color fg, bool selected, Rectangle repaintRegion){
+        super.paintFocus(gc,bg,fg,selected,repaintRegion);
+    }
+    bool contains(int x, int y){
+        return super.contains(x,y);
+    }
+    bool intersects(Rectangle rect){
+        return super.intersects(rect);
+    }
+
     public this(String text, HyperlinkSettings settings,
             String fontId) {
         super(text, fontId);
--- a/dwtx/ui/internal/forms/widgets/TextSegment.d	Sat May 24 06:18:55 2008 +0200
+++ b/dwtx/ui/internal/forms/widgets/TextSegment.d	Sat May 24 06:59:31 2008 +0200
@@ -15,6 +15,7 @@
 import dwtx.ui.internal.forms.widgets.ParagraphSegment;
 import dwtx.ui.internal.forms.widgets.Locator;
 import dwtx.ui.internal.forms.widgets.SelectionData;
+import dwtx.ui.internal.forms.widgets.FormTextModel;
 
 import dwt.DWT;
 import dwt.graphics.Color;
@@ -145,7 +146,7 @@
 
     private String cleanup(String text) {
         StringBuffer buf = new StringBuffer();
-        for (int i = 0; i < text.length(); i++) {
+        for (int i = 0; i < text.length; i++) {
             char c = text.charAt(i);
             if (c is '\n' || c is '\r' || c is '\f') {
                 if (i > 0)
@@ -363,7 +364,7 @@
         //int lineY = ly + lineHeight - descent + 1;
         Rectangle br = new Rectangle(locator.x, ly, ewidth,
                 lineHeight - descent + 3);
-        areaRectangles.add(new AreaRectangle(br, 0, -1));
+        areaRectangles.append(new AreaRectangle(br, 0, -1));
         locator.x += ewidth;
         locator.width = ewidth;
         locator.rowHeight = Math.max(locator.rowHeight, extent.y);
@@ -371,7 +372,7 @@
 
     protected int convertOffsetToStringIndex(GC gc, String s, int x,
             int swidth, int selOffset) {
-        int index = s.length();
+        int index = s.length;
         while (index > 0 && x + swidth > selOffset) {
             index--;
             String ss = s.substring(0, index);
@@ -542,7 +543,7 @@
             }
             if (selectedRow) {
                 int lindex = sstart !is -1 ? sstart : 0;
-                int rindex = sstop !is -1 ? sstop : s.length();
+                int rindex = sstop !is -1 ? sstop : s.length;
                 String mid = s.substring(lindex, rindex);
                 Point extent = gc.textExtent(mid);
                 gc.setForeground(selData.fg);
@@ -589,7 +590,7 @@
 
         if (selectedRow) {
             int lindex = sstart !is -1 ? sstart : 0;
-            int rindex = sstop !is -1 ? sstop : s.length();
+            int rindex = sstop !is -1 ? sstop : s.length;
             String mid = s.substring(lindex, rindex);
             selData.addSegment(mid);
         }
@@ -691,7 +692,7 @@
                             locator.x - 1:locator.x, ly,
                             isSelectable()?lineExtent.x + 1:lineExtent.x, lineHeight - descent + 3);
                     areaRectangles
-                            .add(new AreaRectangle(br, lineStart, lastLoc));
+                            .append(new AreaRectangle(br, lineStart, lastLoc));
 
                     locator.rowHeight = Math.max(locator.rowHeight,
                             lineExtent.y);
@@ -718,7 +719,7 @@
                     isSelectable()?lineExtent.x + 1:lineExtent.x,
                     lineHeight - descent + 3);
             //int lineY = ly + lineHeight - descent + 1;
-            areaRectangles.add(new AreaRectangle(br, lineStart, lastLoc));
+            areaRectangles.append(new AreaRectangle(br, lineStart, lastLoc));
             locator.x += lastWidth;
             locator.rowHeight = Math.max(locator.rowHeight, lineExtent.y);
         }
@@ -730,7 +731,7 @@
     private void computeTextFragments(GC gc) {
         if (textFragments !is null)
             return;
-        ArrayList list = new ArrayList();
+        ArraySeq!(Object) list = new ArraySeq!(Object);
         BreakIterator wb = BreakIterator.getLineInstance();
         wb.setText(getText());
         int cursor = 0;
@@ -739,15 +740,14 @@
                 continue;
             String word = text.substring(cursor, loc);
             Point extent = gc.textExtent(word);
-            list.add(new TextFragment(cast(short) loc, cast(short) extent.x));
+            list.append(new TextFragment(cast(short) loc, cast(short) extent.x));
             cursor = loc;
         }
-        textFragments = cast(TextFragment[]) list.toArray(new TextFragment[list
-                .size()]);
+        textFragments = arraycast!(TextFragment)(list.toArray());
     }
 
     public void clearCache(String fontId) {
-        if (fontIdisnull && (this.fontId is null||this.fontId.equals(FormTextModel.BOLD_FONT_ID)))
+        if (fontId is null && (this.fontId is null||this.fontId.equals(FormTextModel.BOLD_FONT_ID)))
             textFragments = null;
         else if (fontId !is null && this.fontId !is null && fontId.equals(this.fontId))
             textFragments = null;
--- a/dwtx/ui/internal/forms/widgets/TitleRegion.d	Sat May 24 06:18:55 2008 +0200
+++ b/dwtx/ui/internal/forms/widgets/TitleRegion.d	Sat May 24 06:59:31 2008 +0200
@@ -13,6 +13,8 @@
 module dwtx.ui.internal.forms.widgets.TitleRegion;
 
 import dwtx.ui.internal.forms.widgets.BusyIndicator;
+import dwtx.ui.internal.forms.widgets.FormHeading;
+import dwtx.ui.internal.forms.widgets.FormUtil;
 
 import dwt.DWT;
 import dwt.dnd.DragSource;