Point minimumSize(int wHint, int hHint, boolean flushCache) {
   Control[] children = _getChildren();
   int width = 0, height = 0;
   for (int i = 0; i < children.length; i++) {
     Control child = children[i];
     int index = 0;
     int count = 0;
     long /*int*/ list = OS.gtk_container_get_children(handle);
     if (list != 0) {
       count = OS.g_list_length(list);
       OS.g_list_free(list);
     }
     while (index < count) {
       if (items[index].control == child) break;
       index++;
     }
     if (index == count) {
       Rectangle rect = child.getBounds();
       width = Math.max(width, rect.x + rect.width);
       height = Math.max(height, rect.y + rect.height);
     } else {
       Point size = child.computeSize(wHint, hHint, flushCache);
       width = Math.max(width, size.x);
       height = Math.max(height, size.y);
     }
   }
   return new Point(width, height);
 }
 /**
  * Returns the number of items contained in the receiver.
  *
  * @return the number of items
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  */
 public int getItemCount() {
   checkWidget();
   long /*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;
 }
 void createItem(TabItem item, int index) {
   long /*int*/ list = OS.gtk_container_get_children(handle);
   int itemCount = 0;
   if (list != 0) {
     itemCount = OS.g_list_length(list);
     OS.g_list_free(list);
   }
   if (!(0 <= index && index <= itemCount)) error(SWT.ERROR_INVALID_RANGE);
   if (itemCount == items.length) {
     TabItem[] newItems = new TabItem[items.length + 4];
     System.arraycopy(items, 0, newItems, 0, items.length);
     items = newItems;
   }
   long /*int*/ boxHandle = gtk_box_new(OS.GTK_ORIENTATION_HORIZONTAL, false, 0);
   if (boxHandle == 0) error(SWT.ERROR_NO_HANDLES);
   long /*int*/ labelHandle = OS.gtk_label_new_with_mnemonic(null);
   if (labelHandle == 0) error(SWT.ERROR_NO_HANDLES);
   long /*int*/ imageHandle = OS.gtk_image_new();
   if (imageHandle == 0) error(SWT.ERROR_NO_HANDLES);
   OS.gtk_container_add(boxHandle, imageHandle);
   OS.gtk_container_add(boxHandle, labelHandle);
   long /*int*/ pageHandle = OS.g_object_new(display.gtk_fixed_get_type(), 0);
   if (pageHandle == 0) error(SWT.ERROR_NO_HANDLES);
   if (OS.GTK3) {
     OS.gtk_widget_override_background_color(pageHandle, OS.GTK_STATE_FLAG_NORMAL, new GdkRGBA());
     long /*int*/ region = OS.gdk_region_new();
     OS.gtk_widget_input_shape_combine_region(pageHandle, region);
     OS.gdk_region_destroy(region);
   }
   OS.g_signal_handlers_block_matched(handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE);
   OS.gtk_notebook_insert_page(handle, pageHandle, boxHandle, index);
   OS.g_signal_handlers_unblock_matched(handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE);
   OS.gtk_widget_show(boxHandle);
   OS.gtk_widget_show(labelHandle);
   OS.gtk_widget_show(pageHandle);
   item.state |= HANDLE;
   item.handle = boxHandle;
   item.labelHandle = labelHandle;
   item.imageHandle = imageHandle;
   item.pageHandle = pageHandle;
   System.arraycopy(items, index, items, index + 1, itemCount++ - index);
   items[index] = item;
   if ((state & FOREGROUND) != 0) {
     item.setForegroundColor(getForegroundColor());
   }
   if ((state & FONT) != 0) {
     item.setFontDescription(getFontDescription());
   }
   if (itemCount == 1) {
     OS.g_signal_handlers_block_matched(handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE);
     OS.gtk_notebook_set_current_page(handle, 0);
     OS.g_signal_handlers_unblock_matched(handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE);
     Event event = new Event();
     event.item = items[0];
     sendSelectionEvent(SWT.Selection, event, false);
     // the widget could be destroyed at this point
   }
 }
 /**
  * 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
  *     <ul>
  *       <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the
  *           list minus 1 (inclusive)
  *     </ul>
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  */
 public TabItem getItem(int index) {
   checkWidget();
   if (!(0 <= index && index < getItemCount())) error(SWT.ERROR_INVALID_RANGE);
   long /*int*/ list = OS.gtk_container_get_children(handle);
   if (list == 0) error(SWT.ERROR_CANNOT_GET_ITEM);
   int itemCount = OS.g_list_length(list);
   OS.g_list_free(list);
   if (!(0 <= index && index < itemCount)) error(SWT.ERROR_CANNOT_GET_ITEM);
   return items[index];
 }
 /**
  * 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
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the item is null
  *     </ul>
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  */
 public int indexOf(TabItem item) {
   checkWidget();
   if (item == null) error(SWT.ERROR_NULL_ARGUMENT);
   long /*int*/ list = OS.gtk_container_get_children(handle);
   if (list == 0) return -1;
   int count = OS.g_list_length(list);
   OS.g_list_free(list);
   for (int i = 0; i < count; i++) {
     if (items[i] == item) return i;
   }
   return -1;
 }
 void reskinChildren(int flags) {
   if (items != null) {
     long /*int*/ list = OS.gtk_container_get_children(handle);
     if (list != 0) {
       int count = OS.g_list_length(list);
       OS.g_list_free(list);
       for (int i = 0; i < count; i++) {
         TabItem item = items[i];
         if (item != null) item.reskin(flags);
       }
     }
   }
   super.reskinChildren(flags);
 }
 /**
  * Returns the tab 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 tab item at the given point, or null if the point is not in a tab item
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the point is null
  *     </ul>
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  *
  * @since 3.4
  */
 public TabItem getItem(Point point) {
   checkWidget();
   if (point == null) error(SWT.ERROR_NULL_ARGUMENT);
   long /*int*/ list = OS.gtk_container_get_children(handle);
   if (list == 0) return null;
   int itemCount = OS.g_list_length(list);
   OS.g_list_free(list);
   for (int i = 0; i < itemCount; i++) {
     TabItem item = items[i];
     Rectangle rect = item.getBounds();
     if (rect.contains(point)) return item;
   }
   return null;
 }
 ToolItem[] _getItems() {
   long /*int*/ list = OS.gtk_container_get_children(handle);
   if (list == 0) return new ToolItem[0];
   int count = OS.g_list_length(list);
   ToolItem[] items = new ToolItem[count];
   long /*int*/ originalList = list;
   int index = 0;
   for (int i = 0; i < count; i++) {
     long /*int*/ data = OS.g_list_data(list);
     Widget widget = display.getWidget(data);
     if (widget != null) items[index++] = (ToolItem) widget;
     list = OS.g_list_next(list);
   }
   OS.g_list_free(originalList);
   if (index != items.length) {
     ToolItem[] newItems = new ToolItem[index];
     System.arraycopy(items, 0, newItems, 0, index);
     items = newItems;
   }
   return items;
 }
Exemple #9
0
  void hookEvents() {
    super.hookEvents();
    if ((style & SWT.SEPARATOR) != 0) return;
    OS.g_signal_connect_closure(handle, OS.clicked, display.closures[CLICKED], false);
    /*
     * Feature in GTK. GtkToolItem does not respond to basic listeners
     * such as button-press, enter-notify to it. The fix is to assign
     * the listener to child (GtkButton) of the tool-item.
     */
    eventHandle = OS.gtk_bin_get_child(handle);
    if ((style & SWT.DROP_DOWN) != 0 && OS.GTK_VERSION >= OS.VERSION(2, 6, 0)) {
      long /*int*/ list = OS.gtk_container_get_children(eventHandle);
      eventHandle = OS.g_list_nth_data(list, 0);
      if (arrowHandle != 0)
        OS.g_signal_connect_closure(arrowHandle, OS.clicked, display.closures[CLICKED], false);
    }
    OS.g_signal_connect_closure(
        handle, OS.create_menu_proxy, display.closures[CREATE_MENU_PROXY], false);

    OS.g_signal_connect_closure_by_id(
        eventHandle,
        display.signalIds[ENTER_NOTIFY_EVENT],
        0,
        display.closures[ENTER_NOTIFY_EVENT],
        false);
    OS.g_signal_connect_closure_by_id(
        eventHandle,
        display.signalIds[LEAVE_NOTIFY_EVENT],
        0,
        display.closures[LEAVE_NOTIFY_EVENT],
        false);
    OS.g_signal_connect_closure_by_id(
        eventHandle, display.signalIds[FOCUS_IN_EVENT], 0, display.closures[FOCUS_IN_EVENT], false);
    OS.g_signal_connect_closure_by_id(
        eventHandle,
        display.signalIds[FOCUS_OUT_EVENT],
        0,
        display.closures[FOCUS_OUT_EVENT],
        false);
    /*
     * Feature in GTK.  Usually, GTK widgets propagate all events to their
     * parent when they are done their own processing.  However, in contrast
     * to other widgets, the buttons that make up the tool items, do not propagate
     * the mouse up/down events. It is interesting to note that they DO propagate
     * mouse motion events.  The fix is to explicitly forward mouse up/down events
     * to the parent.
     */
    int mask =
        OS.GDK_EXPOSURE_MASK
            | OS.GDK_POINTER_MOTION_MASK
            | OS.GDK_BUTTON_PRESS_MASK
            | OS.GDK_BUTTON_RELEASE_MASK
            | OS.GDK_ENTER_NOTIFY_MASK
            | OS.GDK_LEAVE_NOTIFY_MASK
            | OS.GDK_KEY_PRESS_MASK
            | OS.GDK_KEY_RELEASE_MASK
            | OS.GDK_FOCUS_CHANGE_MASK;
    OS.gtk_widget_add_events(eventHandle, mask);
    OS.g_signal_connect_closure_by_id(
        eventHandle,
        display.signalIds[BUTTON_PRESS_EVENT],
        0,
        display.closures[BUTTON_PRESS_EVENT],
        false);
    OS.g_signal_connect_closure_by_id(
        eventHandle,
        display.signalIds[BUTTON_RELEASE_EVENT],
        0,
        display.closures[BUTTON_RELEASE_EVENT],
        false);
    OS.g_signal_connect_closure_by_id(
        eventHandle, display.signalIds[EVENT_AFTER], 0, display.closures[EVENT_AFTER], false);

    long /*int*/ topHandle = topHandle();
    OS.g_signal_connect_closure_by_id(
        topHandle, display.signalIds[MAP], 0, display.closures[MAP], true);
  }
Exemple #10
0
 void createHandle(int index) {
   state |= HANDLE;
   int bits = SWT.SEPARATOR | SWT.RADIO | SWT.CHECK | SWT.PUSH | SWT.DROP_DOWN;
   if ((style & SWT.SEPARATOR) == 0) {
     labelHandle = OS.gtk_label_new_with_mnemonic(null);
     if (labelHandle == 0) error(SWT.ERROR_NO_HANDLES);
     imageHandle = OS.gtk_image_new_from_pixbuf(0);
     if (imageHandle == 0) error(SWT.ERROR_NO_HANDLES);
   }
   switch (style & bits) {
     case SWT.SEPARATOR:
       handle = OS.gtk_separator_tool_item_new();
       if (handle == 0) error(SWT.ERROR_NO_HANDLES);
       OS.gtk_separator_tool_item_set_draw(handle, true);
       break;
     case SWT.DROP_DOWN:
       if (OS.GTK_VERSION >= OS.VERSION(2, 6, 0)) {
         handle = OS.gtk_menu_tool_button_new(0, null);
         if (handle == 0) error(SWT.ERROR_NO_HANDLES);
         /*
          * Feature in GTK. The arrow button of DropDown tool-item is
          * disabled when it does not contain menu. The fix is to
          * find the arrow button handle and enable it.
          */
         long /*int*/ child = OS.gtk_bin_get_child(handle);
         long /*int*/ list = OS.gtk_container_get_children(child);
         arrowHandle = OS.g_list_nth_data(list, 1);
         OS.gtk_widget_set_sensitive(arrowHandle, true);
         OS.gtk_widget_set_size_request(OS.gtk_bin_get_child(arrowHandle), 8, 6);
       } else {
         /*
          * GTK does not support GtkMenuToolButton until 2.6.
          * So, we try to emulate it on the un-supported version.
          */
         handle = OS.gtk_tool_button_new(0, null);
         if (handle == 0) error(SWT.ERROR_NO_HANDLES);
         arrowBoxHandle = OS.gtk_hbox_new(false, 0);
         if (arrowBoxHandle == 0) error(SWT.ERROR_NO_HANDLES);
         arrowHandle = OS.gtk_arrow_new(OS.GTK_ARROW_DOWN, OS.GTK_SHADOW_NONE);
         if (arrowHandle == 0) error(SWT.ERROR_NO_HANDLES);
         OS.gtk_widget_set_size_request(arrowHandle, 8, 6);
         OS.gtk_container_add(arrowBoxHandle, labelHandle);
         OS.gtk_container_add(arrowBoxHandle, arrowHandle);
         /*
          * As we are try to emulate GtkMenuToolButton and in order
          * to display both the label and image, it is required
          * the set the toolitem as important. This will entitle
          * to display the label all the times.
          */
         OS.gtk_tool_item_set_is_important(handle, true);
       }
       break;
     case SWT.RADIO:
       /*
        * Because GTK enforces radio behavior in a button group
        * a radio group is not created for each set of contiguous
        * buttons, each radio button will not draw unpressed.
        * The fix is to use toggle buttons instead.
        */
     case SWT.CHECK:
       handle = OS.gtk_toggle_tool_button_new();
       if (handle == 0) error(SWT.ERROR_NO_HANDLES);
       break;
     case SWT.PUSH:
     default:
       handle = OS.gtk_tool_button_new(0, null);
       if (handle == 0) error(SWT.ERROR_NO_HANDLES);
       break;
   }
   if (labelHandle != 0) {
     OS.gtk_tool_button_set_label_widget(handle, labelHandle);
   }
   if (imageHandle != 0) {
     OS.gtk_tool_button_set_icon_widget(handle, imageHandle);
   }
   if ((parent.state & FOREGROUND) != 0) {
     setForegroundColor(parent.getForegroundColor());
   }
   if ((parent.state & FONT) != 0) {
     setFontDescription(parent.getFontDescription());
   }
   /*
    * Feature in GTK. GtkToolButton class uses this property to
    * determine whether to show or hide its label when the toolbar
    * style is GTK_TOOLBAR_BOTH_HORIZ (or SWT.RIGHT).
    */
   if ((parent.style & SWT.RIGHT) != 0) OS.gtk_tool_item_set_is_important(handle, true);
   if ((style & SWT.SEPARATOR) == 0) OS.gtk_tool_button_set_use_underline(handle, true);
 }