package org.eclipse.swt.widgets; /* * (c) Copyright IBM Corp. 2000, 2001. * All Rights Reserved */ import org.eclipse.swt.*; import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.gtk.*; import org.eclipse.swt.graphics.*; /** * Instances of this class support the layout of selectable * tool bar items. *

* The item children that may be added to instances of this class * must be of type ToolItem. *

* Note that although this class is a subclass of Composite, * it does not make sense to add Control children to it, * or set a layout on it. *

*

*
Styles:
*
FLAT, WRAP, RIGHT, HORIZONTAL, VERTICAL
*
Events:
*
(none)
*
*

* Note: Only one of the styles HORIZONTAL and VERTICAL may be specified. *

* IMPORTANT: This class is not intended to be subclassed. *

*/ public class ToolBar extends Composite { /** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. *

* The style value is either one of the style constants defined in * class SWT which is applicable to instances of this * class, or must be built by bitwise OR'ing together * (that is, using the int "|" operator) two or more * of those SWT style constants. The class description * for all SWT widget classes should include a comment which * describes the style constants which are applicable to the class. *

* * @param parent a composite control which will be the parent of the new instance (cannot be null) * @param style the style of control to construct * * @exception IllegalArgumentException * @exception SWTException * * @see SWT * @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. */ this.style = checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0); int orientation = (style & SWT.VERTICAL) != 0 ? OS.GTK_ORIENTATION_VERTICAL : OS.GTK_ORIENTATION_HORIZONTAL; OS.gtk_toolbar_set_orientation (handle, orientation); } void createHandle (int index) { state |= HANDLE; fixedHandle = OS.gtk_fixed_new (); if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES); OS.gtk_fixed_set_has_window (fixedHandle, true); handle = OS.gtk_toolbar_new (); if (handle == 0) error (SWT.ERROR_NO_HANDLES); int parentHandle = parent.parentingHandle (); OS.gtk_container_add (parentHandle, fixedHandle); OS.gtk_container_add (fixedHandle, handle); OS.gtk_widget_show (fixedHandle); OS.gtk_widget_show (handle); setForegroundColor (parent.getForegroundColor ()); setFontDescription (parent.getFontDescription ()); } public Point computeSize (int wHint, int hHint, boolean changed) { checkWidget (); if (layout != null) super.computeSize(wHint, hHint, changed); return computeNativeSize(handle, wHint, hHint, changed); } int eventHandle () { return fixedHandle; } /** * Returns the item at the given, zero-relative index in the * receiver. Throws an exception if the index is out of range. * * @param index the index of the item to return * @return the item at the given index * * @exception IllegalArgumentException * @exception SWTException */ public ToolItem getItem (int index) { checkWidget(); return getItems()[index]; } /** * Returns the item at the given point in the receiver * or null if no such item exists. The point is in the * coordinate system of the receiver. * * @param point the point used to locate the item * @return the item at the given point * * @exception IllegalArgumentException * @exception SWTException */ public ToolItem getItem (Point point) { ToolItem[] items = getItems(); for (int i=0; i *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • * */ public int getItemCount () { checkWidget(); int list = OS.gtk_container_get_children (handle); if (list == 0) return 0; int itemCount = OS.g_list_length (list); OS.g_list_free (list); return itemCount; } /** * Returns an array of TabItems which are the items * in the receiver. *

    * Note: This is not the actual structure used by the receiver * to maintain its list of items, so modifying the array will * not affect the receiver. *

    * * @return the items in the receiver * * @exception SWTException */ public ToolItem [] getItems () { checkWidget(); int list = OS.gtk_container_get_children (handle); if (list == 0) return new ToolItem [0]; int count = OS.g_list_length (list); ToolItem [] result = new ToolItem [count]; for (int i=0; iWRAP style, the * number of rows can be greater than one. Otherwise, * the number of rows is always one. * * @return the number of items * * @exception SWTException */ public int getRowCount () { checkWidget(); return 1; /* On GTK, toolbars never wrap */ } /** * Searches the receiver's list starting at the first item * (index 0) until an item is found that is equal to the * argument, and returns the index of that item. If no item * is found, returns -1. * * @param item the search item * @return the index of the item * * @exception IllegalArgumentException * @exception SWTException */ public int indexOf (ToolItem item) { checkWidget(); if (item == null) error (SWT.ERROR_NULL_ARGUMENT); // TEMPORARY CODE ToolItem [] items = getItems (); for (int i=0; i