Пример #1
0
 /**
  * Sets the height of the receiver. This is height of the item when it is expanded, excluding the
  * height of the header.
  *
  * @param height the new height
  * @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 void setHeight(int height) {
   checkWidget();
   if (height < 0) return;
   this.height = height;
   OS.gtk_widget_set_size_request(clientHandle, -1, height);
   parent.layoutItems(0, false);
 }
Пример #2
0
 /**
  * Sets the width of the receiver, for <code>SEPARATOR</code> ToolItems.
  *
  * @param width the new width. If the new value is <code>SWT.DEFAULT</code>, the width is a
  *     fixed-width area whose amount is determined by the platform. If the new value is 0 a
  *     vertical or horizontal line will be drawn, depending on the setting of the corresponding
  *     style bit (<code>SWT.VERTICAL</code> or <code>SWT.HORIZONTAL</code>). If the new value is
  *     <code>SWT.SEPARATOR_FILL</code> a variable-width space is inserted that acts as a spring
  *     between the two adjoining items which will push them out to the extent of the containing
  *     ToolBar.
  * @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 void setWidth(int width) {
   checkWidget();
   if ((style & SWT.SEPARATOR) == 0) return;
   if (width < 0) return;
   boolean isVertical = (parent.style & SWT.VERTICAL) != 0;
   OS.gtk_widget_set_size_request(handle, width, isVertical ? 6 : 15);
   parent.relayout();
 }
Пример #3
0
 void resizeControl() {
   if (control != null && !control.isDisposed()) {
     /*
      * Set the size and location of the control
      * separately to minimize flashing in the
      * case where the control does not resize
      * to the size that was requested.  This
      * case can occur when the control is a
      * combo box.
      */
     Rectangle itemRect = getBounds();
     control.setSize(itemRect.width, itemRect.height);
     OS.gtk_widget_set_size_request(handle, itemRect.width, itemRect.height);
     Rectangle rect = control.getBounds();
     rect.x = itemRect.x + (itemRect.width - rect.width) / 2;
     rect.y = itemRect.y + (itemRect.height - rect.height) / 2;
     control.setLocation(rect.x, rect.y);
   }
 }
Пример #4
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);
 }