diff options
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ToolBar.java')
-rwxr-xr-x | bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ToolBar.java | 606 |
1 files changed, 303 insertions, 303 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ToolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ToolBar.java index 5ca0f9ee5a..9e2df2bba7 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ToolBar.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ToolBar.java @@ -1,16 +1,16 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html + */ + +import org.eclipse.swt.internal.photon.*; +import org.eclipse.swt.*; +import org.eclipse.swt.graphics.*; + /** * Instances of this class support the layout of selectable * tool bar items. @@ -34,12 +34,12 @@ import org.eclipse.swt.graphics.*; * IMPORTANT: This class is <em>not</em> intended to be subclassed. * </p> */ -public class ToolBar extends Composite {
- int parentingHandle;
- int itemCount;
- ToolItem [] items;
- ToolItem lastFocus;
-
+public class ToolBar extends Composite { + int parentingHandle; + int itemCount; + ToolItem [] items; + ToolItem lastFocus; + /** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. @@ -72,128 +72,128 @@ public class ToolBar extends Composite { * @see Widget#checkSubclass * @see Widget#getStyle */ -public ToolBar (Composite parent, int style) {
- super (parent, checkStyle (style));
-
- /*
- * Ensure that either of HORIZONTAL or VERTICAL is set.
- * NOTE: HORIZONTAL and VERTICAL have the same values
- * as H_SCROLL and V_SCROLL so it is necessary to first
- * clear these bits to avoid scroll bars and then reset
- * the bits using the original style supplied by the
- * programmer.
- */
- if ((style & SWT.VERTICAL) != 0) {
- this.style |= SWT.VERTICAL;
- } else {
- this.style |= SWT.HORIZONTAL;
- }
- int orientation = (style & SWT.VERTICAL) == 0 ? OS.Pt_HORIZONTAL : OS.Pt_VERTICAL;
- OS.PtSetResource (handle, OS.Pt_ARG_ORIENTATION, orientation, 0);
-}
-
-static int checkStyle (int style) {
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- if (layout != null) {
- return super.computeSize (wHint, hHint, changed);
- }
- PhDim_t dim = new PhDim_t();
- if (!OS.PtWidgetIsRealized (handle)) OS.PtExtentWidgetFamily (handle);
- OS.PtWidgetPreferredSize(handle, dim);
- int width = dim.w, height = dim.h;
- if (wHint != SWT.DEFAULT || hHint != SWT.DEFAULT) {
- PhRect_t rect = new PhRect_t ();
- PhArea_t area = new PhArea_t ();
- rect.lr_x = (short) (wHint - 1);
- rect.lr_y = (short) (hHint - 1);
- OS.PtSetAreaFromWidgetCanvas (handle, rect, area);
- if (wHint != SWT.DEFAULT) width = area.size_w;
- if (hHint != SWT.DEFAULT) height = area.size_h;
- }
- return new Point(width, height);
-}
-
-void createHandle (int index) {
- state |= HANDLE;
- Display display = getDisplay ();
- int parentHandle = parent.parentingHandle ();
- int [] args = {
- OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS,
- };
- parentingHandle = OS.PtCreateWidget (OS.PtContainer (), parentHandle, args.length / 3, args);
- if (parentingHandle == 0) error (SWT.ERROR_NO_HANDLES);
- args = new int [] {
- OS.Pt_ARG_FLAGS, (style & SWT.NO_FOCUS) != 0 ? 0 : OS.Pt_GETS_FOCUS, OS.Pt_GETS_FOCUS,
- OS.Pt_ARG_FLAGS, hasBorder () ? OS.Pt_HIGHLIGHTED : 0, OS.Pt_HIGHLIGHTED,
- OS.Pt_ARG_TOOLBAR_FLAGS, 0, OS.Pt_TOOLBAR_DRAGGABLE | OS.Pt_TOOLBAR_END_SEPARATOR,
- OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS,
- };
- handle = OS.PtCreateWidget (display.PtToolbar, parentingHandle, args.length / 3, args);
- if ((style & SWT.FLAT) != 0) {
- OS.PtSetResource (handle, OS.Pt_ARG_BASIC_FLAGS, OS.Pt_FLAT_FILL, OS.Pt_FLAT_FILL);
- }
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-}
-
-void createItem (ToolItem item, int index) {
- if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
- if (itemCount == items.length) {
- ToolItem [] newItems = new ToolItem [itemCount + 4];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- item.createWidget (index);
- System.arraycopy (items, index, items, index + 1, itemCount++ - index);
- items [index] = item;
-}
-
-void createWidget (int index) {
- super.createWidget (index);
- items = new ToolItem [4];
- itemCount = 0;
-}
-
-void deregister () {
- super.deregister ();
- if (parentingHandle != 0) WidgetTable.remove (parentingHandle);
-}
-
-void destroyItem (ToolItem item) {
- int index = 0;
- while (index < itemCount) {
- if (items [index] == item) break;
- index++;
- }
- if (index == itemCount) return;
- System.arraycopy (items, index + 1, items, index, --itemCount - index);
- items [itemCount] = null;
-}
-
-public boolean forceFocus () {
- checkWidget();
- if (lastFocus != null && lastFocus.setFocus ()) return true;
- for (int i = 0; i < itemCount; i++) {
- ToolItem item = items [i];
- if (item.setFocus ()) return true;
- }
- return super.forceFocus ();
-}
-
+public ToolBar (Composite parent, int style) { + super (parent, checkStyle (style)); + + /* + * Ensure that either of HORIZONTAL or VERTICAL is set. + * NOTE: HORIZONTAL and VERTICAL have the same values + * as H_SCROLL and V_SCROLL so it is necessary to first + * clear these bits to avoid scroll bars and then reset + * the bits using the original style supplied by the + * programmer. + */ + if ((style & SWT.VERTICAL) != 0) { + this.style |= SWT.VERTICAL; + } else { + this.style |= SWT.HORIZONTAL; + } + int orientation = (style & SWT.VERTICAL) == 0 ? OS.Pt_HORIZONTAL : OS.Pt_VERTICAL; + OS.PtSetResource (handle, OS.Pt_ARG_ORIENTATION, orientation, 0); +} + +static int checkStyle (int style) { + /* + * Even though it is legal to create this widget + * with scroll bars, they serve no useful purpose + * because they do not automatically scroll the + * widget's client area. The fix is to clear + * the SWT style. + */ + return style & ~(SWT.H_SCROLL | SWT.V_SCROLL); +} + +protected void checkSubclass () { + if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); +} + +public Point computeSize (int wHint, int hHint, boolean changed) { + checkWidget(); + if (layout != null) { + return super.computeSize (wHint, hHint, changed); + } + PhDim_t dim = new PhDim_t(); + if (!OS.PtWidgetIsRealized (handle)) OS.PtExtentWidgetFamily (handle); + OS.PtWidgetPreferredSize(handle, dim); + int width = dim.w, height = dim.h; + if (wHint != SWT.DEFAULT || hHint != SWT.DEFAULT) { + PhRect_t rect = new PhRect_t (); + PhArea_t area = new PhArea_t (); + rect.lr_x = (short) (wHint - 1); + rect.lr_y = (short) (hHint - 1); + OS.PtSetAreaFromWidgetCanvas (handle, rect, area); + if (wHint != SWT.DEFAULT) width = area.size_w; + if (hHint != SWT.DEFAULT) height = area.size_h; + } + return new Point(width, height); +} + +void createHandle (int index) { + state |= HANDLE; + Display display = getDisplay (); + int parentHandle = parent.parentingHandle (); + int [] args = { + OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS, + }; + parentingHandle = OS.PtCreateWidget (OS.PtContainer (), parentHandle, args.length / 3, args); + if (parentingHandle == 0) error (SWT.ERROR_NO_HANDLES); + args = new int [] { + OS.Pt_ARG_FLAGS, (style & SWT.NO_FOCUS) != 0 ? 0 : OS.Pt_GETS_FOCUS, OS.Pt_GETS_FOCUS, + OS.Pt_ARG_FLAGS, hasBorder () ? OS.Pt_HIGHLIGHTED : 0, OS.Pt_HIGHLIGHTED, + OS.Pt_ARG_TOOLBAR_FLAGS, 0, OS.Pt_TOOLBAR_DRAGGABLE | OS.Pt_TOOLBAR_END_SEPARATOR, + OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS, + }; + handle = OS.PtCreateWidget (display.PtToolbar, parentingHandle, args.length / 3, args); + if ((style & SWT.FLAT) != 0) { + OS.PtSetResource (handle, OS.Pt_ARG_BASIC_FLAGS, OS.Pt_FLAT_FILL, OS.Pt_FLAT_FILL); + } + if (handle == 0) error (SWT.ERROR_NO_HANDLES); +} + +void createItem (ToolItem item, int index) { + if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE); + if (itemCount == items.length) { + ToolItem [] newItems = new ToolItem [itemCount + 4]; + System.arraycopy (items, 0, newItems, 0, items.length); + items = newItems; + } + item.createWidget (index); + System.arraycopy (items, index, items, index + 1, itemCount++ - index); + items [index] = item; +} + +void createWidget (int index) { + super.createWidget (index); + items = new ToolItem [4]; + itemCount = 0; +} + +void deregister () { + super.deregister (); + if (parentingHandle != 0) WidgetTable.remove (parentingHandle); +} + +void destroyItem (ToolItem item) { + int index = 0; + while (index < itemCount) { + if (items [index] == item) break; + index++; + } + if (index == itemCount) return; + System.arraycopy (items, index + 1, items, index, --itemCount - index); + items [itemCount] = null; +} + +public boolean forceFocus () { + checkWidget(); + if (lastFocus != null && lastFocus.setFocus ()) return true; + for (int i = 0; i < itemCount; i++) { + ToolItem item = items [i]; + if (item.setFocus ()) return true; + } + return super.forceFocus (); +} + /** * Returns the number of items contained in the receiver. * @@ -204,11 +204,11 @@ public boolean forceFocus () { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public int getItemCount () {
- checkWidget();
- return itemCount;
-}
-
+public int getItemCount () { + checkWidget(); + return itemCount; +} + /** * Returns an array of <code>TabItem</code>s which are the items * in the receiver. @@ -225,13 +225,13 @@ public int getItemCount () { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public ToolItem [] getItems () {
- checkWidget();
- ToolItem [] result = new ToolItem [itemCount];
- System.arraycopy (items, 0, result, 0, itemCount);
- return result;
-}
-
+public ToolItem [] getItems () { + checkWidget(); + ToolItem [] result = new ToolItem [itemCount]; + System.arraycopy (items, 0, result, 0, itemCount); + return result; +} + /** * Returns the item at the given, zero-relative index in the * receiver. Throws an exception if the index is out of range. @@ -247,13 +247,13 @@ public ToolItem [] getItems () { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public ToolItem getItem (int index) {
- checkWidget();
- int count = itemCount;
- if (!(0 <= index && index < count)) error (SWT.ERROR_INVALID_RANGE);
- return items [index];
-}
-
+public ToolItem getItem (int index) { + checkWidget(); + int count = itemCount; + if (!(0 <= index && index < count)) error (SWT.ERROR_INVALID_RANGE); + return items [index]; +} + /** * Returns the item at the given point in the receiver * or null if no such item exists. The point is in the @@ -270,15 +270,15 @@ public ToolItem getItem (int index) { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public ToolItem getItem (Point pt) {
- checkWidget();
- for (int i=0; i<itemCount; i++) {
- Rectangle rect = items [i].getBounds ();
- if (rect.contains (pt)) return items [i];
- }
- return null;
-}
-
+public ToolItem getItem (Point pt) { + checkWidget(); + for (int i=0; i<itemCount; i++) { + Rectangle rect = items [i].getBounds (); + if (rect.contains (pt)) return items [i]; + } + return null; +} + /** * Returns the number of rows in the receiver. When * the receiver has the <code>WRAP</code> style, the @@ -292,19 +292,19 @@ public ToolItem getItem (Point pt) { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public int getRowCount () {
- checkWidget();
- return 1;
-}
-
-boolean hasFocus () {
- for (int i=0; i<itemCount; i++) {
- ToolItem item = items [i];
- if (item.hasFocus ()) return true;
- }
- return super.hasFocus();
-}
-
+public int getRowCount () { + checkWidget(); + return 1; +} + +boolean hasFocus () { + for (int i=0; i<itemCount; i++) { + ToolItem item = items [i]; + if (item.hasFocus ()) return true; + } + return super.hasFocus(); +} + /** * Searches the receiver's list starting at the first item * (index 0) until an item is found that is equal to the @@ -323,130 +323,130 @@ boolean hasFocus () { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public int indexOf (ToolItem item) {
- checkWidget();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- int count = itemCount;
- for (int i=0; i<count; i++) {
- if (items [i] == item) return i;
- }
- return -1;
-}
-
-void moveToBack (int child) {
- OS.PtWidgetInsert (child, handle, 0);
-}
-
-int parentingHandle () {
- return parentingHandle;
-}
-
-int Ph_EV_BOUNDARY (int widget, int info) {
- if (info == 0) return OS.Pt_END;
- PtCallbackInfo_t cbinfo = new PtCallbackInfo_t ();
- OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof);
- if (cbinfo.event == 0) return OS.Pt_END;
- PhEvent_t ev = new PhEvent_t ();
- OS.memmove (ev, cbinfo.event, PhEvent_t.sizeof);
- switch ((int) ev.subtype) {
- case OS.Ph_EV_PTR_ENTER_FROM_CHILD:
- case OS.Ph_EV_PTR_LEAVE_TO_CHILD:
- return OS.Pt_CONTINUE;
- }
- return super.Ph_EV_BOUNDARY (widget, info);
-}
-
-void register () {
- super.register ();
- if (parentingHandle != 0) WidgetTable.put (parentingHandle, this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- parentingHandle = 0;
-}
-
-void releaseWidget () {
- for (int i=0; i<items.length; i++) {
- ToolItem item = items [i];
- if (item != null && !item.isDisposed ()) item.releaseResources ();
- }
- items = null;
- super.releaseWidget ();
-}
-
-void setBackgroundPixel (int pixel) {
- super.setBackgroundPixel (pixel);
- for (int i = 0; i < itemCount; i++) {
- ToolItem item = items[i];
- item.setBackgroundPixel (pixel);
- }
-}
-
-int setBounds (int x, int y, int width, int height, boolean move, boolean resize, boolean events) {
- int result = super.setBounds (x, y, width, height, move, resize, events);
- if ((result & RESIZED) != 0) {
- int [] args = {OS.Pt_ARG_WIDTH, 0, 0, OS.Pt_ARG_HEIGHT, 0, 0};
- OS.PtGetResources (parentingHandle, args.length / 3, args);
- OS.PtSetResources (handle, args.length / 3, args);
- }
- return result;
-}
-
-void setFont (int font) {
- super.setFont (font);
- for (int i = 0; i < itemCount; i++) {
- ToolItem item = items[i];
- item.setFont (font);
- }
-}
-
-void setForegroundPixel (int pixel) {
- super.setForegroundPixel (pixel);
+public int indexOf (ToolItem item) { + checkWidget(); + if (item == null) error (SWT.ERROR_NULL_ARGUMENT); + if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); + int count = itemCount; + for (int i=0; i<count; i++) { + if (items [i] == item) return i; + } + return -1; +} + +void moveToBack (int child) { + OS.PtWidgetInsert (child, handle, 0); +} + +int parentingHandle () { + return parentingHandle; +} + +int Ph_EV_BOUNDARY (int widget, int info) { + if (info == 0) return OS.Pt_END; + PtCallbackInfo_t cbinfo = new PtCallbackInfo_t (); + OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof); + if (cbinfo.event == 0) return OS.Pt_END; + PhEvent_t ev = new PhEvent_t (); + OS.memmove (ev, cbinfo.event, PhEvent_t.sizeof); + switch ((int) ev.subtype) { + case OS.Ph_EV_PTR_ENTER_FROM_CHILD: + case OS.Ph_EV_PTR_LEAVE_TO_CHILD: + return OS.Pt_CONTINUE; + } + return super.Ph_EV_BOUNDARY (widget, info); +} + +void register () { + super.register (); + if (parentingHandle != 0) WidgetTable.put (parentingHandle, this); +} + +void releaseHandle () { + super.releaseHandle (); + parentingHandle = 0; +} + +void releaseWidget () { + for (int i=0; i<items.length; i++) { + ToolItem item = items [i]; + if (item != null && !item.isDisposed ()) item.releaseResources (); + } + items = null; + super.releaseWidget (); +} + +void setBackgroundPixel (int pixel) { + super.setBackgroundPixel (pixel); + for (int i = 0; i < itemCount; i++) { + ToolItem item = items[i]; + item.setBackgroundPixel (pixel); + } +} + +int setBounds (int x, int y, int width, int height, boolean move, boolean resize, boolean events) { + int result = super.setBounds (x, y, width, height, move, resize, events); + if ((result & RESIZED) != 0) { + int [] args = {OS.Pt_ARG_WIDTH, 0, 0, OS.Pt_ARG_HEIGHT, 0, 0}; + OS.PtGetResources (parentingHandle, args.length / 3, args); + OS.PtSetResources (handle, args.length / 3, args); + } + return result; +} + +void setFont (int font) { + super.setFont (font); + for (int i = 0; i < itemCount; i++) { + ToolItem item = items[i]; + item.setFont (font); + } +} + +void setForegroundPixel (int pixel) { + super.setForegroundPixel (pixel); for (int i = 0; i < itemCount; i++) { ToolItem item = items[i]; item.setForegroundPixel (pixel); - }
-}
-
-int topHandle () {
- return parentingHandle;
-}
-
-boolean translateTraversal (int key_sym, PhKeyEvent_t phEvent) {
- boolean result = super.translateTraversal (key_sym, phEvent);
- if (result) return result;
- boolean next = false;
- switch (key_sym) {
- case OS.Pk_Up:
- case OS.Pk_Left: next = false; break;
- case OS.Pk_Down:
- case OS.Pk_Right: next = true; break;
- default: return false;
- }
- int length = itemCount;
- int index = 0;
- while (index < length) {
- if (items [index].hasFocus ()) break;
- index++;
- }
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in focus in
- * or out events. Ensure that a disposed widget is
- * not accessed.
- */
- int start = index, offset = (next) ? 1 : -1;
- while ((index = (index + offset + length) % length) != start) {
- ToolItem item = items [index];
- if (item.setFocus ()) return false;
- }
- return false;
-}
-
-int widgetClass () {
- return OS.PtToolbar ();
-}
-
-}
+ } +} + +int topHandle () { + return parentingHandle; +} + +boolean translateTraversal (int key_sym, PhKeyEvent_t phEvent) { + boolean result = super.translateTraversal (key_sym, phEvent); + if (result) return result; + boolean next = false; + switch (key_sym) { + case OS.Pk_Up: + case OS.Pk_Left: next = false; break; + case OS.Pk_Down: + case OS.Pk_Right: next = true; break; + default: return false; + } + int length = itemCount; + int index = 0; + while (index < length) { + if (items [index].hasFocus ()) break; + index++; + } + /* + * It is possible (but unlikely), that application + * code could have disposed the widget in focus in + * or out events. Ensure that a disposed widget is + * not accessed. + */ + int start = index, offset = (next) ? 1 : -1; + while ((index = (index + offset + length) % length) != start) { + ToolItem item = items [index]; + if (item.setFocus ()) return false; + } + return false; +} + +int widgetClass () { + return OS.PtToolbar (); +} + +} |