comparison dwt/widgets/TabItem.d @ 45:d8635bb48c7c

Merge with SWT 3.5
author Jacob Carlborg <doob@me.com>
date Mon, 01 Dec 2008 17:07:00 +0100
parents e831403a80a9
children cfa563df4fdd
comparison
equal deleted inserted replaced
44:ca5e494f2bbf 45:d8635bb48c7c
1 /******************************************************************************* 1 /*******************************************************************************
2 * Copyright (c) 2000, 2006 IBM Corporation and others. 2 * Copyright (c) 2000, 2008 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials 3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0 4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at 5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html 6 * http://www.eclipse.org/legal/epl-v10.html
7 * 7 *
16 import dwt.DWT; 16 import dwt.DWT;
17 import dwt.DWTException; 17 import dwt.DWTException;
18 import dwt.graphics.Image; 18 import dwt.graphics.Image;
19 import dwt.graphics.Rectangle; 19 import dwt.graphics.Rectangle;
20 import dwt.internal.cocoa.NSPoint; 20 import dwt.internal.cocoa.NSPoint;
21 import dwt.internal.cocoa.NSRect;
21 import dwt.internal.cocoa.NSSize; 22 import dwt.internal.cocoa.NSSize;
22 import dwt.internal.cocoa.NSString; 23 import dwt.internal.cocoa.NSString;
23 import dwt.internal.cocoa.NSTabViewItem; 24 import dwt.internal.cocoa.NSTabViewItem;
24 import dwt.internal.cocoa.NSValue; 25 import dwt.internal.cocoa.NSValue;
26 import dwt.internal.cocoa.NSView;
25 import dwt.internal.cocoa.NSWindow; 27 import dwt.internal.cocoa.NSWindow;
26 import dwt.internal.cocoa.OS; 28 import dwt.internal.cocoa.OS;
27 29
28 /** 30 /**
29 * Instances of this class represent a selectable user interface object 31 * Instances of this class represent a selectable user interface object
35 * <dd>(none)</dd> 37 * <dd>(none)</dd>
36 * </dl> 38 * </dl>
37 * <p> 39 * <p>
38 * IMPORTANT: This class is <em>not</em> intended to be subclassed. 40 * IMPORTANT: This class is <em>not</em> intended to be subclassed.
39 * </p> 41 * </p>
42 *
43 * @see <a href="http://www.eclipse.org/swt/snippets/#tabfolder">TabFolder, TabItem snippets</a>
44 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
40 */ 45 */
41 public class TabItem : Item { 46 public class TabItem : Item {
42 TabFolder parent; 47 TabFolder parent;
43 Control control; 48 Control control;
44 String toolTipText; 49 String toolTipText;
141 * @since 3.4 146 * @since 3.4
142 */ 147 */
143 public Rectangle getBounds() { 148 public Rectangle getBounds() {
144 checkWidget(); 149 checkWidget();
145 Rectangle result = new Rectangle (0, 0, 0, 0); 150 Rectangle result = new Rectangle (0, 0, 0, 0);
146 if (nsItem.respondsToSelector (OS.sel_accessibilityAttributeValue_1)) { 151 if (nsItem.respondsToSelector (OS.sel_accessibilityAttributeValue_)) {
147 int posValue = OS.objc_msgSend (nsItem.id, OS.sel_accessibilityAttributeValue_1, OS.NSAccessibilityPositionAttribute ()); 152 int /*long*/ posValue = OS.objc_msgSend (nsItem.id, OS.sel_accessibilityAttributeValue_, OS.NSAccessibilityPositionAttribute ());
148 int sizeValue = OS.objc_msgSend (nsItem.id, OS.sel_accessibilityAttributeValue_1, OS.NSAccessibilitySizeAttribute ()); 153 int /*long*/ sizeValue = OS.objc_msgSend (nsItem.id, OS.sel_accessibilityAttributeValue_, OS.NSAccessibilitySizeAttribute ());
149 NSValue val = new NSValue (posValue); 154 NSValue val = new NSValue (posValue);
150 NSPoint pt = val.pointValue (); 155 NSPoint pt = val.pointValue ();
151 NSWindow window = parent.view.window (); 156 NSWindow window = parent.view.window ();
152 pt.y = window.screen ().frame ().height - pt.y; 157 pt.y = display.getPrimaryFrame().height - pt.y;
153 pt = parent.view.convertPoint_fromView_ (pt, null); 158 pt = parent.view.convertPoint_fromView_ (pt, null);
154 pt = window.convertScreenToBase (pt); 159 pt = window.convertScreenToBase (pt);
155 result.x = cast(int) pt.x; 160 result.x = cast(int) pt.x;
156 result.y = cast(int) pt.y; 161 result.y = cast(int) pt.y;
157 val = new NSValue (sizeValue); 162 val = new NSValue (sizeValue);
158 NSSize size = val.sizeValue (); 163 NSSize size = val.sizeValue ();
159 result.width = cast(int) size.width; 164 result.width = cast(int) Math.ceil (size.width);
160 result.height = cast(int) size.height; 165 result.height = cast(int) Math.ceil (size.height);
161 } 166 }
162 return result; 167 return result;
163 } 168 }
164 169
165 /** 170 /**
257 Control oldControl = this.control, newControl = control; 262 Control oldControl = this.control, newControl = control;
258 this.control = control; 263 this.control = control;
259 int index = parent.indexOf (this); 264 int index = parent.indexOf (this);
260 if (index !is parent.getSelectionIndex ()) { 265 if (index !is parent.getSelectionIndex ()) {
261 if (newControl !is null) newControl.setVisible (false); 266 if (newControl !is null) newControl.setVisible (false);
262 return; 267 } else {
263 } 268 if (newControl !is null) {
269 newControl.setVisible (true);
270 }
271 if (oldControl !is null) oldControl.setVisible (false);
272 }
273 NSView view;
264 if (newControl !is null) { 274 if (newControl !is null) {
265 // nsItem.setView(control.topView ()); 275 view = newControl.topView();
266 newControl.setBounds (parent.getClientArea ()); 276 } else {
267 newControl.setVisible (true); 277 view = (NSView)new NSView().alloc();
268 } 278 view.initWithFrame (new NSRect());
269 if (oldControl !is null) oldControl.setVisible (false); 279 view.autorelease();
280 }
281 nsItem.setView (view);
270 } 282 }
271 283
272 public void setImage (Image image) { 284 public void setImage (Image image) {
273 checkWidget (); 285 checkWidget ();
274 int index = parent.indexOf (this); 286 int index = parent.indexOf (this);