Mercurial > projects > dwt-mac
comparison dwt/widgets/TabFolder.d @ 78:d226cd03f84a
Ported dwt.widgets.TabFolder
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Wed, 24 Dec 2008 13:12:21 +0100 |
parents | cfa563df4fdd |
children | c7f7f4d7091a |
comparison
equal
deleted
inserted
replaced
77:990305995bc6 | 78:d226cd03f84a |
---|---|
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 * |
8 * Contributors: | 8 * Contributors: |
9 * IBM Corporation - initial API and implementation | 9 * IBM Corporation - initial API and implementation |
10 * | |
11 * Port to the D programming language: | |
12 * Jacob Carlborg <doob@me.com> | |
10 *******************************************************************************/ | 13 *******************************************************************************/ |
11 module dwt.widgets.TabFolder; | 14 module dwt.widgets.TabFolder; |
12 | 15 |
13 import dwt.dwthelper.utils; | 16 import dwt.dwthelper.utils; |
14 | 17 |
26 import dwt.internal.cocoa.NSTabView; | 29 import dwt.internal.cocoa.NSTabView; |
27 import dwt.internal.cocoa.NSTabViewItem; | 30 import dwt.internal.cocoa.NSTabViewItem; |
28 import dwt.internal.cocoa.NSView; | 31 import dwt.internal.cocoa.NSView; |
29 import dwt.internal.cocoa.OS; | 32 import dwt.internal.cocoa.OS; |
30 import dwt.internal.cocoa.SWTTabView; | 33 import dwt.internal.cocoa.SWTTabView; |
34 | |
35 import objc = dwt.internal.objc.runtime; | |
36 import dwt.widgets.Composite; | |
37 import dwt.widgets.Control; | |
38 import dwt.widgets.TabItem; | |
39 import dwt.widgets.TypedListener; | |
31 | 40 |
32 /** | 41 /** |
33 * Instances of this class implement the notebook user interface | 42 * Instances of this class implement the notebook user interface |
34 * metaphor. It allows the user to select a notebook page from | 43 * metaphor. It allows the user to select a notebook page from |
35 * set of pages. | 44 * set of pages. |
153 return size; | 162 return size; |
154 } | 163 } |
155 | 164 |
156 public Rectangle computeTrim (int x, int y, int width, int height) { | 165 public Rectangle computeTrim (int x, int y, int width, int height) { |
157 checkWidget (); | 166 checkWidget (); |
158 NSTabView widget = (NSTabView)view; | 167 NSTabView widget = cast(NSTabView)view; |
159 NSRect rect = widget.contentRect (); | 168 NSRect rect = widget.contentRect (); |
160 x -= rect.x; y -= rect.y; | 169 x -= rect.x; y -= rect.y; |
161 width += Math.ceil (rect.x); height += Math.ceil (rect.y); | 170 width += Math.ceil (rect.x); height += Math.ceil (rect.y); |
162 return super.computeTrim (x, y, width, height); | 171 return super.computeTrim (x, y, width, height); |
163 } | 172 } |
164 | 173 |
165 void createHandle () { | 174 void createHandle () { |
166 NSTabView widget = cast(NSTabView)new SWTTabView().alloc(); | 175 NSTabView widget = cast(NSTabView)(new SWTTabView()).alloc(); |
167 widget.initWithFrame (NSRect()); | 176 widget.initWithFrame (NSRect()); |
168 widget.setDelegate(widget); | 177 widget.setDelegate(widget); |
169 if ((style & DWT.BOTTOM) !is 0) { | 178 if ((style & DWT.BOTTOM) !is 0) { |
170 widget.setTabViewType(OS.NSBottomTabsBezelBorder); | 179 widget.setTabViewType(OS.NSBottomTabsBezelBorder); |
171 } | 180 } |
181 items = newItems; | 190 items = newItems; |
182 } | 191 } |
183 System.arraycopy (items, index, items, index + 1, count - index); | 192 System.arraycopy (items, index, items, index + 1, count - index); |
184 items [index] = item; | 193 items [index] = item; |
185 itemCount++; | 194 itemCount++; |
186 NSTabViewItem nsItem = cast(NSTabViewItem)new NSTabViewItem().alloc().init(); | 195 NSTabViewItem nsItem = cast(NSTabViewItem)(new NSTabViewItem()).alloc().init(); |
187 item.nsItem = nsItem; | 196 item.nsItem = nsItem; |
188 (cast(NSTabView)view).insertTabViewItem(nsItem, index); | 197 (cast(NSTabView)view).insertTabViewItem(nsItem, index); |
189 } | 198 } |
190 | 199 |
191 void createWidget () { | 200 void createWidget () { |
262 * @since 3.4 | 271 * @since 3.4 |
263 */ | 272 */ |
264 public TabItem getItem (Point point) { | 273 public TabItem getItem (Point point) { |
265 checkWidget (); | 274 checkWidget (); |
266 if (point is null) error (DWT.ERROR_NULL_ARGUMENT); | 275 if (point is null) error (DWT.ERROR_NULL_ARGUMENT); |
267 NSPoint nsPoint = new NSPoint (); | 276 NSPoint nsPoint = NSPoint (); |
268 nsPoint.x = point.x; | 277 nsPoint.x = point.x; |
269 nsPoint.y = point.y; | 278 nsPoint.y = point.y; |
270 NSTabView tabView = cast(NSTabView) view; | 279 NSTabView tabView = cast(NSTabView) view; |
271 NSTabViewItem tabViewItem = tabView.tabViewItemAtPoint (nsPoint); | 280 NSTabViewItem tabViewItem = tabView.tabViewItemAtPoint (nsPoint); |
272 for (int i = 0; i < itemCount; i++) { | 281 for (int i = 0; i < itemCount; i++) { |
335 */ | 344 */ |
336 public TabItem [] getSelection () { | 345 public TabItem [] getSelection () { |
337 checkWidget (); | 346 checkWidget (); |
338 int index = getSelectionIndex (); | 347 int index = getSelectionIndex (); |
339 if (index is -1) return new TabItem [0]; | 348 if (index is -1) return new TabItem [0]; |
340 return new TabItem [] {items [index]}; | 349 return [items [index]]; |
341 } | 350 } |
342 | 351 |
343 /** | 352 /** |
344 * Returns the zero-relative index of the item which is currently | 353 * Returns the zero-relative index of the item which is currently |
345 * selected in the receiver, or -1 if no item is selected. | 354 * selected in the receiver, or -1 if no item is selected. |
485 * @since 3.2 | 494 * @since 3.2 |
486 */ | 495 */ |
487 public void setSelection (TabItem item) { | 496 public void setSelection (TabItem item) { |
488 checkWidget (); | 497 checkWidget (); |
489 if (item is null) error (DWT.ERROR_NULL_ARGUMENT); | 498 if (item is null) error (DWT.ERROR_NULL_ARGUMENT); |
490 setSelection (new TabItem [] {item}); | 499 setSelection ([item]); |
491 } | 500 } |
492 | 501 |
493 /** | 502 /** |
494 * Sets the receiver's selection to be the given array of items. | 503 * Sets the receiver's selection to be the given array of items. |
495 * The current selected is first cleared, then the new items are | 504 * The current selected is first cleared, then the new items are |
582 } | 591 } |
583 setSelection (index, true, false); | 592 setSelection (index, true, false); |
584 return index is getSelectionIndex (); | 593 return index is getSelectionIndex (); |
585 } | 594 } |
586 | 595 |
587 void tabView_willSelectTabViewItem(int /*long*/ id, int /*long*/ sel, int /*long*/ tabView, int /*long*/ tabViewItem) { | 596 void tabView_willSelectTabViewItem(objc.id id, objc.SEL sel, objc.id tabView, objc.id tabViewItem) { |
588 if (tabViewItem is 0) return; | 597 if (tabViewItem is 0) return; |
589 for (int i = 0; i < itemCount; i++) { | 598 for (int i = 0; i < itemCount; i++) { |
590 TabItem item = items [i]; | 599 TabItem item = items [i]; |
591 if (item.nsItem.id is tabViewItem) { | 600 if (item.nsItem.id is tabViewItem) { |
592 int currentIndex = getSelectionIndex (); | 601 int currentIndex = getSelectionIndex (); |
606 break; | 615 break; |
607 } | 616 } |
608 } | 617 } |
609 } | 618 } |
610 | 619 |
611 void tabView_didSelectTabViewItem(int /*long*/ id, int /*long*/ sel, int /*long*/ tabView, int /*long*/ tabViewItem) { | 620 void tabView_didSelectTabViewItem(objc.id id, objc.SEL sel, objc.id tabView, objc.id tabViewItem) { |
612 if (tabViewItem is 0) return; | 621 if (tabViewItem is 0) return; |
613 for (int i = 0; i < itemCount; i++) { | 622 for (int i = 0; i < itemCount; i++) { |
614 TabItem item = items [i]; | 623 TabItem item = items [i]; |
615 /* | 624 /* |
616 * Feature in Cocoa. For some reason the control on a tab being | 625 * Feature in Cocoa. For some reason the control on a tab being |