Exemplo n.º 1
0
 /**
  * Sets the receiver's text. The string may include the mnemonic character.
  *
  * <p>Mnemonics are indicated by an '&amp;' that causes the next character to be the mnemonic.
  * When the user presses a key sequence that matches the mnemonic, a selection event occurs. On
  * most platforms, the mnemonic appears underlined but may be emphasised in a platform specific
  * manner. The mnemonic indicator character '&amp;' can be escaped by doubling it in the string,
  * causing a single '&amp;' to be displayed.
  *
  * @param string the new text
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the text 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 void setText(String string) {
   checkWidget();
   if (string == null) error(SWT.ERROR_NULL_ARGUMENT);
   if ((style & SWT.SEPARATOR) != 0) return;
   if (string.equals(this.text)) return;
   super.setText(string);
   if (labelHandle == 0) return;
   char[] chars = fixMnemonic(string);
   byte[] buffer = Converter.wcsToMbcs(null, chars, true);
   OS.gtk_label_set_text_with_mnemonic(labelHandle, buffer);
   if ((style & SWT.DROP_DOWN) != 0 && OS.GTK_VERSION < OS.VERSION(2, 6, 0)) {
     if (string.length() != 0) {
       OS.gtk_widget_show(labelHandle);
     } else {
       OS.gtk_widget_hide(labelHandle);
     }
   }
   /*
    * If Text/Image of a tool-item changes, then it is
    * required to reset the proxy menu. Otherwise, the
    * old menuItem appears in the overflow menu.
    */
   if ((style & SWT.DROP_DOWN) != 0) {
     proxyMenuItem = 0;
     proxyMenuItem = OS.gtk_tool_item_retrieve_proxy_menu_item(handle);
     OS.g_signal_connect(
         proxyMenuItem, OS.activate, ToolBar.menuItemSelectedFunc.getAddress(), handle);
   }
   parent.relayout();
 }
Exemplo n.º 2
0
  @Override
  void createHandle(int index) {
    state |= HANDLE | THEME_BACKGROUND;
    fixedHandle = OS.g_object_new(display.gtk_fixed_get_type(), 0);
    if (fixedHandle == 0) error(SWT.ERROR_NO_HANDLES);
    OS.gtk_widget_set_has_window(fixedHandle, true);
    handle = OS.gtk_toolbar_new();
    if (handle == 0) error(SWT.ERROR_NO_HANDLES);
    OS.gtk_container_add(fixedHandle, handle);
    if ((style & SWT.FLAT) != 0) {
      byte[] swt_toolbar_flat = Converter.wcsToMbcs(null, "swt-toolbar-flat", true);
      OS.gtk_widget_set_name(handle, swt_toolbar_flat);
    }

    /*
     * Bug in GTK. For some reason, the toolbar style context does not read
     * the CSS style sheet until the window containing the toolbar is shown.
     * The fix is to call gtk_style_context_invalidate() which it seems to
     * force the style sheet to be read.
     */
    if (OS.GTK3) {
      long /*int*/ context = OS.gtk_widget_get_style_context(handle);
      String css = "GtkToolbar {padding-top: 4px; padding-bottom: 4px; }";
      gtk_css_provider_load_from_css(context, css);
      OS.gtk_style_context_invalidate(context);
    }

    /*
     * Bug in GTK.  GTK will segment fault if gtk_widget_reparent() is called
     * on a tool bar or on a widget hierarchy containing a tool bar when the icon
     * size is not GTK_ICON_SIZE_LARGE_TOOLBAR.  The fix is to set the icon
     * size to GTK_ICON_SIZE_LARGE_TOOLBAR.
     *
     * Note that the segmentation fault does not happen on GTK 3, but the
     * tool bar preferred size is too big with GTK_ICON_SIZE_LARGE_TOOLBAR
     * when the tool bar item has no image or text.
     */
    OS.gtk_toolbar_set_icon_size(
        handle, OS.GTK3 ? OS.GTK_ICON_SIZE_SMALL_TOOLBAR : OS.GTK_ICON_SIZE_LARGE_TOOLBAR);

    // In GTK 3 font description is inherited from parent widget which is not how SWT has always
    // worked,
    // reset to default font to get the usual behavior
    if (OS.GTK3) {
      setFontDescription(defaultFont().handle);
    }
  }
Exemplo n.º 3
0
 /**
  * Sets the receiver's text at a column
  *
  * @param index the column index
  * @param string the new text
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the text 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 void setText(int index, String string) {
   checkWidget();
   if (string == null) error(SWT.ERROR_NULL_ARGUMENT);
   if (_getText(index).equals(string)) return;
   int count = Math.max(1, parent.getColumnCount());
   if (0 > index || index > count - 1) return;
   byte[] buffer = Converter.wcsToMbcs(null, string, true);
   int modelIndex =
       parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns[index].modelIndex;
   OS.gtk_list_store_set(parent.modelHandle, handle, modelIndex + Table.CELL_TEXT, buffer, -1);
   /*
    * Bug in GTK.  When using fixed-height-mode,
    * row changes do not cause the row to be repainted.  The fix is to
    * invalidate the row when it is cleared.
    */
   if ((parent.style & SWT.VIRTUAL) != 0) {
     if (OS.GTK_VERSION >= OS.VERSION(2, 3, 2) && OS.GTK_VERSION < OS.VERSION(2, 6, 3)) {
       redraw();
     }
   }
   cached = true;
 }
Exemplo n.º 4
0
  /**
   * This implementation of <code>javaToNative</code> converts an ImageData object represented by
   * java <code>ImageData</code> to a platform specific representation.
   *
   * @param object a java <code>ImageData</code> containing the ImageData to be converted
   * @param transferData an empty <code>TransferData</code> object that will be filled in on return
   *     with the platform specific format of the data
   * @see Transfer#nativeToJava
   */
  public void javaToNative(Object object, TransferData transferData) {
    if (!checkImage(object) || !isSupportedType(transferData)) {
      DND.error(DND.ERROR_INVALID_DATA);
    }
    if (OS.GTK_VERSION < OS.VERSION(2, 4, 0)) return;

    ImageData imgData = (ImageData) object;
    if (imgData == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
    Image image = new Image(Display.getCurrent(), imgData);
    long /*int*/ pixbuf = ImageList.createPixbuf(image);
    if (pixbuf != 0) {
      String typeStr = "";
      if (transferData.type == JPEG_ID) typeStr = "jpeg";
      else if (transferData.type == PNG_ID) typeStr = "png";
      else if (transferData.type == BMP_ID) typeStr = "bmp";
      else if (transferData.type == EPS_ID) typeStr = "eps";
      else if (transferData.type == PCX_ID) typeStr = "pcx";
      else if (transferData.type == PPM_ID) typeStr = "ppm";
      else if (transferData.type == RGB_ID) typeStr = "rgb";
      else if (transferData.type == TGA_ID) typeStr = "tga";
      else if (transferData.type == XBM_ID) typeStr = "xbm";
      else if (transferData.type == XPM_ID) typeStr = "xpm";
      else if (transferData.type == XV_ID) typeStr = "xv";
      byte[] type = Converter.wcsToMbcs(null, typeStr, true);
      long /*int*/[] buffer = new long /*int*/[1];
      long /*int*/[] len = new long /*int*/[1];
      if (type == null) return;
      OS.gdk_pixbuf_save_to_bufferv(pixbuf, buffer, len, type, null, null, null);
      OS.g_object_unref(pixbuf);
      transferData.pValue = buffer[0];
      transferData.length = (int) (len[0] + 3) / 4 * 4;
      transferData.result = 1;
      transferData.format = 32;
    }
    image.dispose();
  }
Exemplo n.º 5
0
  long /*int*/ gtk_create_menu_proxy(long /*int*/ widget) {
    /*
     * Feature in GTK. If the item is a radio/check button
     * with only image, then that image does not appear in
     * the overflow menu.
     * The fix is to create and use the proxy menu for the
     * items appearing in the overflow menu.
     */
    byte[] buffer = Converter.wcsToMbcs(null, "menu-id", true); // $NON-NLS-1$
    if (proxyMenuItem != 0) {
      /*
       * The menuItem to appear in the overflow menu is cached
       * for the tool-item. If the text/image of the item changes,
       * then the proxyMenu is reset.
       */
      OS.gtk_tool_item_set_proxy_menu_item(widget, buffer, proxyMenuItem);
      return 1;
    }

    if (image != null) {
      ImageList imageList = parent.imageList;
      if (imageList != null) {
        int index = imageList.indexOf(image);
        if (index != -1) {
          long /*int*/ pixbuf = imageList.getPixbuf(index);
          byte[] label = null;
          int[] showImages = new int[] {1};
          long /*int*/ settings = OS.gtk_settings_get_default();
          if (settings != 0) {
            long /*int*/ property =
                OS.g_object_class_find_property(
                    OS.G_OBJECT_GET_CLASS(settings), OS.gtk_menu_images);
            if (property != 0) OS.g_object_get(settings, OS.gtk_menu_images, showImages, 0);
          }

          /*
           * GTK tool items with only image appear as blank items
           * in overflow menu when the system property "gtk-menu-images"
           * is set to false. To avoid that, display the tooltip text
           * if available, in the overflow menu.
           * Feature in GTK. When the menuItem is initialised only
           * with the image, the overflow menu appears very sloppy.
           * The fix is to initialise menu item with empty string.
           */
          if (text == null || text.length() == 0) {
            if ((showImages[0] == 0) && (toolTipText != null))
              label = Converter.wcsToMbcs(null, toolTipText, true);
            else label = new byte[] {0};
          } else {
            label = Converter.wcsToMbcs(null, text, true);
          }
          long /*int*/ menuItem = OS.gtk_image_menu_item_new_with_label(label);
          long /*int*/ menuImage = OS.gtk_image_new_from_pixbuf(pixbuf);
          OS.gtk_image_menu_item_set_image(menuItem, menuImage);
          OS.gtk_tool_item_set_proxy_menu_item(widget, buffer, menuItem);
          /*
           * Since the arrow button does not appear in the drop_down
           * item, we request the menu-item and then, hook the
           * activate signal to send the Arrow selection signal.
           */
          proxyMenuItem = OS.gtk_tool_item_get_proxy_menu_item(widget, buffer);
          OS.g_signal_connect(
              menuItem, OS.activate, ToolBar.menuItemSelectedFunc.getAddress(), handle);
          return 1;
        }
      }
    }
    return 0;
  }
Exemplo n.º 6
0
 public void setText(String string) {
   super.setText(string);
   byte[] buffer = Converter.wcsToMbcs(null, string, true);
   OS.gtk_label_set_text(labelHandle, buffer);
 }