diff dwt/custom/CTabFolderLayout.d @ 41:6337764516f1

Sync dwt/custom with dwt-linux (took copy of complete folder)
author Frank Benoit <benoit@tionex.de>
date Tue, 07 Oct 2008 16:29:55 +0200
parents f565d3a95c0a
children
line wrap: on
line diff
--- a/dwt/custom/CTabFolderLayout.d	Tue Oct 07 14:41:31 2008 +0200
+++ b/dwt/custom/CTabFolderLayout.d	Tue Oct 07 16:29:55 2008 +0200
@@ -7,97 +7,85 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
- *     
  * Port to the D programming language:
- *     Jacob Carlborg <jacob.carlborg@gmail.com>
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
 module dwt.custom.CTabFolderLayout;
 
-import Math = tango.math.Math;
+import dwt.dwthelper.utils;
 
 import dwt.DWT;
-import dwt.custom.CTabFolder;
-import dwt.custom.CTabItem;
 import dwt.graphics.GC;
 import dwt.graphics.Point;
 import dwt.widgets.Composite;
 import dwt.widgets.Control;
 import dwt.widgets.Layout;
+import dwt.custom.CTabFolder;
+import dwt.custom.CTabItem;
 
 /**
  * This class provides the layout for CTabFolder
- * 
+ *
  * @see CTabFolder
  */
 class CTabFolderLayout : Layout {
-    protected Point computeSize (Composite composite, int wHint, int hHint, bool flushCache) {
-        CTabFolder folder = cast(CTabFolder) composite;
-        CTabItem[] items = folder.items;
-        // preferred width of tab area to show all tabs
-        int tabW = 0;
-        GC gc = new GC(folder);
-        for (int i = 0; i < items.length; i++) {
-            if (folder.single) {
-                tabW = Math.max(tabW, items[i].preferredWidth(gc, true, false));
-            }
-            else {
-                tabW += items[i].preferredWidth(gc, i is folder.selectedIndex, false);
-            }
-        }
-        gc.dispose();
-        tabW += 3;
-        if (folder.showMax)
-            tabW += CTabFolder.BUTTON_SIZE;
-        if (folder.showMin)
-            tabW += CTabFolder.BUTTON_SIZE;
-        if (folder.single)
-            tabW += 3 * CTabFolder.BUTTON_SIZE / 2; //chevron
-        if (folder.topRight !is null) {
-            Point pt = folder.topRight.computeSize(DWT.DEFAULT, folder.tabHeight, flushCache);
-            tabW += 3 + pt.x;
+protected override Point computeSize(Composite composite, int wHint, int hHint, bool flushCache) {
+    CTabFolder folder = cast(CTabFolder)composite;
+    CTabItem[] items = folder.items;
+    // preferred width of tab area to show all tabs
+    int tabW = 0;
+    GC gc = new GC(folder);
+    for (int i = 0; i < items.length; i++) {
+        if (folder.single) {
+            tabW = Math.max(tabW, items[i].preferredWidth(gc, true, false));
+        } else {
+            tabW += items[i].preferredWidth(gc, i is folder.selectedIndex, false);
         }
-        if (!folder.single && !folder.simple)
-            tabW += folder.curveWidth - 2 * folder.curveIndent;
+    }
+    gc.dispose();
+    tabW += 3;
+    if (folder.showMax) tabW += CTabFolder.BUTTON_SIZE;
+    if (folder.showMin) tabW += CTabFolder.BUTTON_SIZE;
+    if (folder.single) tabW += 3*CTabFolder.BUTTON_SIZE/2; //chevron
+    if (folder.topRight !is null) {
+        Point pt = folder.topRight.computeSize(DWT.DEFAULT, folder.tabHeight, flushCache);
+        tabW += 3 + pt.x;
+    }
+    if (!folder.single && !folder.simple) tabW += folder.curveWidth - 2*folder.curveIndent;
 
-        int controlW = 0;
-        int controlH = 0;
-        // preferred size of controls in tab items
-        for (int i = 0; i < items.length; i++) {
-            Control control = items[i].getControl();
-            if (control !is null && !control.isDisposed()) {
-                Point size = control.computeSize(wHint, hHint, flushCache);
-                controlW = Math.max(controlW, size.x);
-                controlH = Math.max(controlH, size.y);
-            }
+    int controlW = 0;
+    int controlH = 0;
+    // preferred size of controls in tab items
+    for (int i = 0; i < items.length; i++) {
+        Control control = items[i].getControl();
+        if (control !is null && !control.isDisposed()){
+            Point size = control.computeSize (wHint, hHint, flushCache);
+            controlW = Math.max (controlW, size.x);
+            controlH = Math.max (controlH, size.y);
         }
-
-        int minWidth = Math.max(tabW, controlW);
-        int minHeight = (folder.minimized) ? 0 : controlH;
-        if (minWidth is 0)
-            minWidth = CTabFolder.DEFAULT_WIDTH;
-        if (minHeight is 0)
-            minHeight = CTabFolder.DEFAULT_HEIGHT;
-
-        if (wHint !is DWT.DEFAULT)
-            minWidth = wHint;
-        if (hHint !is DWT.DEFAULT)
-            minHeight = hHint;
-
-        return new Point(minWidth, minHeight);
     }
 
-    protected bool flushCache (Control control) {
-        return true;
-    }
+    int minWidth = Math.max(tabW, controlW);
+    int minHeight = (folder.minimized) ? 0 : controlH;
+    if (minWidth is 0) minWidth = CTabFolder.DEFAULT_WIDTH;
+    if (minHeight is 0) minHeight = CTabFolder.DEFAULT_HEIGHT;
+
+    if (wHint !is DWT.DEFAULT) minWidth  = wHint;
+    if (hHint !is DWT.DEFAULT) minHeight = hHint;
 
-    protected void layout (Composite composite, bool flushCache) {
-        CTabFolder folder = cast(CTabFolder) composite;
-        // resize content
-        if (folder.selectedIndex !is -1) {
-            Control control = folder.items[folder.selectedIndex].getControl();
-            if (control !is null && !control.isDisposed()) {
-                control.setBounds(folder.getClientArea());
-            }
+    return new Point (minWidth, minHeight);
+}
+protected override bool flushCache(Control control) {
+    return true;
+}
+protected override void layout(Composite composite, bool flushCache) {
+    CTabFolder folder = cast(CTabFolder)composite;
+    // resize content
+    if (folder.selectedIndex !is -1) {
+        Control control = folder.items[folder.selectedIndex].getControl();
+        if (control !is null && !control.isDisposed()) {
+            control.setBounds(folder.getClientArea());
         }
     }
 }
+}