1 /******************************************************************************* 2 * Copyright (c) 2000, 2005 IBM Corporation and others. 3 * All rights reserved. This program and the accompanying materials 4 * are made available under the terms of the Eclipse Public License v1.0 5 * which accompanies this distribution, and is available at 6 * http://www.eclipse.org/legal/epl-v10.html 7 * 8 * Contributors: 9 * IBM Corporation - initial API and implementation 10 * Port to the D programming language: 11 * Frank Benoit <benoit@tionex.de> 12 *******************************************************************************/ 13 module org.eclipse.swt.custom.CTabFolderLayout; 14 15 import java.lang.all; 16 17 import org.eclipse.swt.SWT; 18 import org.eclipse.swt.graphics.GC; 19 import org.eclipse.swt.graphics.Point; 20 import org.eclipse.swt.widgets.Composite; 21 import org.eclipse.swt.widgets.Control; 22 import org.eclipse.swt.widgets.Layout; 23 import org.eclipse.swt.custom.CTabFolder; 24 import org.eclipse.swt.custom.CTabItem; 25 26 /** 27 * This class provides the layout for CTabFolder 28 * 29 * @see CTabFolder 30 */ 31 class CTabFolderLayout : Layout { 32 protected override Point computeSize(Composite composite, int wHint, int hHint, bool flushCache) { 33 CTabFolder folder = cast(CTabFolder)composite; 34 CTabItem[] items = folder.items; 35 // preferred width of tab area to show all tabs 36 int tabW = 0; 37 GC gc = new GC(folder); 38 for (int i = 0; i < items.length; i++) { 39 if (folder.single) { 40 tabW = Math.max(tabW, items[i].preferredWidth(gc, true, false)); 41 } else { 42 tabW += items[i].preferredWidth(gc, i is folder.selectedIndex, false); 43 } 44 } 45 gc.dispose(); 46 tabW += 3; 47 if (folder.showMax) tabW += CTabFolder.BUTTON_SIZE; 48 if (folder.showMin) tabW += CTabFolder.BUTTON_SIZE; 49 if (folder.single) tabW += 3*CTabFolder.BUTTON_SIZE/2; //chevron 50 if (folder.topRight !is null) { 51 Point pt = folder.topRight.computeSize(SWT.DEFAULT, folder.tabHeight, flushCache); 52 tabW += 3 + pt.x; 53 } 54 if (!folder.single && !folder.simple) tabW += folder.curveWidth - 2*folder.curveIndent; 55 56 int controlW = 0; 57 int controlH = 0; 58 // preferred size of controls in tab items 59 for (int i = 0; i < items.length; i++) { 60 Control control = items[i].getControl(); 61 if (control !is null && !control.isDisposed()){ 62 Point size = control.computeSize (wHint, hHint, flushCache); 63 controlW = Math.max (controlW, size.x); 64 controlH = Math.max (controlH, size.y); 65 } 66 } 67 68 int minWidth = Math.max(tabW, controlW); 69 int minHeight = (folder.minimized) ? 0 : controlH; 70 if (minWidth is 0) minWidth = CTabFolder.DEFAULT_WIDTH; 71 if (minHeight is 0) minHeight = CTabFolder.DEFAULT_HEIGHT; 72 73 if (wHint !is SWT.DEFAULT) minWidth = wHint; 74 if (hHint !is SWT.DEFAULT) minHeight = hHint; 75 76 return new Point (minWidth, minHeight); 77 } 78 protected override bool flushCache(Control control) { 79 return true; 80 } 81 protected override void layout(Composite composite, bool flushCache) { 82 CTabFolder folder = cast(CTabFolder)composite; 83 // resize content 84 if (folder.selectedIndex !is -1) { 85 Control control = folder.items[folder.selectedIndex].getControl(); 86 if (control !is null && !control.isDisposed()) { 87 control.setBounds(folder.getClientArea()); 88 } 89 } 90 } 91 }