comparison dwt/widgets/ToolBar.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 *
13 import dwt.dwthelper.utils; 13 import dwt.dwthelper.utils;
14 14
15 15
16 import dwt.DWT; 16 import dwt.DWT;
17 import dwt.DWTException; 17 import dwt.DWTException;
18 import dwt.accessibility.ACC;
18 import dwt.graphics.Point; 19 import dwt.graphics.Point;
19 import dwt.graphics.Rectangle; 20 import dwt.graphics.Rectangle;
21 import dwt.internal.cocoa.NSArray;
22 import dwt.internal.cocoa.NSButton;
23 import dwt.internal.cocoa.NSFont;
24 import dwt.internal.cocoa.NSMutableArray;
25 import dwt.internal.cocoa.NSNumber;
20 import dwt.internal.cocoa.NSRect; 26 import dwt.internal.cocoa.NSRect;
27 import dwt.internal.cocoa.NSString;
21 import dwt.internal.cocoa.NSView; 28 import dwt.internal.cocoa.NSView;
29 import dwt.internal.cocoa.OS;
22 import dwt.internal.cocoa.SWTView; 30 import dwt.internal.cocoa.SWTView;
31 import dwt.internal.cocoa.id;
23 32
24 /** 33 /**
25 * Instances of this class support the layout of selectable 34 * Instances of this class support the layout of selectable
26 * tool bar items. 35 * tool bar items.
27 * <p> 36 * <p>
41 * <p> 50 * <p>
42 * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified. 51 * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
43 * </p><p> 52 * </p><p>
44 * IMPORTANT: This class is <em>not</em> intended to be subclassed. 53 * IMPORTANT: This class is <em>not</em> intended to be subclassed.
45 * </p> 54 * </p>
55 *
56 * @see <a href="http://www.eclipse.org/swt/snippets/#toolbar">ToolBar, ToolItem snippets</a>
57 * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: ControlExample</a>
58 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
46 */ 59 */
47 public class ToolBar : Composite { 60 public class ToolBar : Composite {
48 int itemCount; 61 int itemCount;
49 ToolItem [] items; 62 ToolItem [] items;
50 63 NSArray accessibilityAttributes = null;
64
51 /** 65 /**
52 * Constructs a new instance of this class given its parent 66 * Constructs a new instance of this class given its parent
53 * and a style value describing its behavior and appearance. 67 * and a style value describing its behavior and appearance.
54 * <p> 68 * <p>
55 * The style value is either one of the style constants defined in 69 * The style value is either one of the style constants defined in
97 } else { 111 } else {
98 this.style |= DWT.HORIZONTAL; 112 this.style |= DWT.HORIZONTAL;
99 } 113 }
100 } 114 }
101 115
116 int accessibilityAttributeNames(int /*long*/ id, int /*long*/ sel) {
117
118 if (accessibilityAttributes is null) {
119 NSMutableArray ourAttributes = NSMutableArray.arrayWithCapacity(10);
120 ourAttributes.addObject(OS.NSAccessibilityRoleAttribute);
121 ourAttributes.addObject(OS.NSAccessibilityRoleDescriptionAttribute);
122 ourAttributes.addObject(OS.NSAccessibilityParentAttribute);
123 ourAttributes.addObject(OS.NSAccessibilityPositionAttribute);
124 ourAttributes.addObject(OS.NSAccessibilitySizeAttribute);
125 ourAttributes.addObject(OS.NSAccessibilityWindowAttribute);
126 ourAttributes.addObject(OS.NSAccessibilityTopLevelUIElementAttribute);
127 ourAttributes.addObject(OS.NSAccessibilityHelpAttribute);
128 ourAttributes.addObject(OS.NSAccessibilityEnabledAttribute);
129 ourAttributes.addObject(OS.NSAccessibilityFocusedAttribute);
130 ourAttributes.addObject(OS.NSAccessibilityChildrenAttribute);
131
132 if (accessible !is null) {
133 // See if the accessible will override or augment the standard list.
134 // Help, title, and description can be overridden.
135 NSMutableArray extraAttributes = NSMutableArray.arrayWithCapacity(3);
136 extraAttributes.addObject(OS.NSAccessibilityHelpAttribute);
137 extraAttributes.addObject(OS.NSAccessibilityDescriptionAttribute);
138 extraAttributes.addObject(OS.NSAccessibilityTitleAttribute);
139
140 for (int i = extraAttributes.count() - 1; i >= 0; i--) {
141 NSString attribute = new NSString(extraAttributes.objectAtIndex(i).id);
142 if (accessible.internal_accessibilityAttributeValue(attribute, ACC.CHILDID_SELF) !is null) {
143 ourAttributes.addObject(extraAttributes.objectAtIndex(i));
144 }
145 }
146 }
147
148 accessibilityAttributes = ourAttributes;
149 accessibilityAttributes.retain();
150 }
151
152 return accessibilityAttributes.id;
153 }
154
155 int accessibilityAttributeValue (int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
156 NSString nsAttributeName = new NSString(arg0);
157
158 if (accessible !is null) {
159 id returnObject = accessible.internal_accessibilityAttributeValue(nsAttributeName, ACC.CHILDID_SELF);
160 if (returnObject !is null) return returnObject.id;
161 }
162
163 if (nsAttributeName.isEqualToString (OS.NSAccessibilityRoleAttribute) || nsAttributeName.isEqualToString (OS.NSAccessibilityRoleDescriptionAttribute)) {
164 NSString role = OS.NSAccessibilityToolbarRole;
165
166 if (nsAttributeName.isEqualToString (OS.NSAccessibilityRoleAttribute))
167 return role.id;
168 else {
169 int roleDescription = OS.NSAccessibilityRoleDescription(role.id, 0);
170 return roleDescription;
171 }
172 } else if (nsAttributeName.isEqualToString(OS.NSAccessibilityEnabledAttribute)) {
173 return NSNumber.numberWithBool(isEnabled()).id;
174 } else if (nsAttributeName.isEqualToString(OS.NSAccessibilityFocusedAttribute)) {
175 bool focused = (view.id is view.window().firstResponder().id);
176 return NSNumber.numberWithBool(focused).id;
177 }
178
179 return super.accessibilityAttributeValue(id, sel, arg0);
180 }
181
182 bool accessibilityIsIgnored(int /*long*/ id, int /*long*/ sel) {
183 // Toolbars aren't ignored.
184 return false;
185 }
186
102 static int checkStyle (int style) { 187 static int checkStyle (int style) {
103 /* 188 /*
104 * Even though it is legal to create this widget 189 * Even though it is legal to create this widget
105 * with scroll bars, they serve no useful purpose 190 * with scroll bars, they serve no useful purpose
106 * because they do not automatically scroll the 191 * because they do not automatically scroll the
125 if (hHint !is DWT.DEFAULT) extent.y = hHint; 210 if (hHint !is DWT.DEFAULT) extent.y = hHint;
126 return extent; 211 return extent;
127 } 212 }
128 213
129 void createHandle () { 214 void createHandle () {
130 SWTView widget = cast(SWTView)new SWTView().alloc(); 215 NSView widget = cast(NSView)new SWTView().alloc();
131 widget.initWithFrame(new NSRect()); 216 widget.initWithFrame(new NSRect());
132 // widget.setDrawsBackground(false); 217 // widget.setDrawsBackground(false);
133 widget.setTag(jniRef);
134 view = widget; 218 view = widget;
135 parent.contentView().addSubview_(widget);
136 } 219 }
137 220
138 void createItem (ToolItem item, int index) { 221 void createItem (ToolItem item, int index) {
139 if (!(0 <= index && index <= itemCount)) error (DWT.ERROR_INVALID_RANGE); 222 if (!(0 <= index && index <= itemCount)) error (DWT.ERROR_INVALID_RANGE);
140 if (itemCount is items.length) { 223 if (itemCount is items.length) {
141 ToolItem [] newItems = new ToolItem [itemCount + 4]; 224 ToolItem [] newItems = new ToolItem [itemCount + 4];
142 System.arraycopy (items, 0, newItems, 0, items.length); 225 System.arraycopy (items, 0, newItems, 0, items.length);
143 items = newItems; 226 items = newItems;
144 } 227 }
145 item.createWidget(); 228 item.createWidget();
146 view.addSubview_(item.view); 229 view.addSubview(item.view);
147 System.arraycopy (items, index, items, index + 1, itemCount++ - index); 230 System.arraycopy (items, index, items, index + 1, itemCount++ - index);
148 items [index] = item; 231 items [index] = item;
149 relayout (); 232 relayout ();
150 } 233 }
151 234
419 items = null; 502 items = null;
420 } 503 }
421 super.releaseChildren (destroy); 504 super.releaseChildren (destroy);
422 } 505 }
423 506
507 void releaseHandle () {
508 super.releaseHandle ();
509 if (accessibilityAttributes !is null) accessibilityAttributes.release();
510 accessibilityAttributes = null;
511 }
512
424 void removeControl (Control control) { 513 void removeControl (Control control) {
425 super.removeControl (control); 514 super.removeControl (control);
426 for (int i=0; i<itemCount; i++) { 515 for (int i=0; i<itemCount; i++) {
427 ToolItem item = items [i]; 516 ToolItem item = items [i];
428 if (item.control is control) item.setControl (null); 517 if (item.control is control) item.setControl (null);
429 } 518 }
430 } 519 }
431 520
432 int setBounds (int x, int y, int width, int height, bool move, bool resize) { 521 void resized () {
433 int result = super.setBounds (x, y, width, height, move, resize); 522 super.resized ();
434 if ((result & RESIZED) !is 0) relayout (); 523 relayout ();
435 return result; 524 }
525
526 void setFont(NSFont font) {
527 for (int i = 0; i < itemCount; i++) {
528 ToolItem item = items[i];
529 if (item.button !is null) ((NSButton)item.button).setAttributedTitle(item.createString());
530 }
436 } 531 }
437 532
438 public void setRedraw (bool redraw) { 533 public void setRedraw (bool redraw) {
439 checkWidget(); 534 checkWidget();
440 super.setRedraw (redraw); 535 super.setRedraw (redraw);