Exemplo n.º 1
0
 int /*long*/ gtk_commit(int /*long*/ imcontext, int /*long*/ textPtr) {
   if (!isInlineEnabled()) return 0;
   boolean doit = true;
   ranges = null;
   styles = null;
   caretOffset = commitCount = 0;
   if (textPtr != 0 && inComposition) {
     int length = OS.strlen(textPtr);
     if (length != 0) {
       byte[] buffer = new byte[length];
       OS.memmove(buffer, textPtr, length);
       char[] chars = Converter.mbcsToWcs(null, buffer);
       Event event = new Event();
       event.detail = SWT.COMPOSITION_CHANGED;
       event.start = startOffset;
       event.end = startOffset + text.length();
       event.text = text = chars != null ? new String(chars) : "";
       commitCount = text.length();
       sendEvent(SWT.ImeComposition, event);
       doit = event.doit;
       text = "";
       startOffset = -1;
       commitCount = 0;
     }
   }
   inComposition = false;
   return doit ? 0 : 1;
 }
Exemplo n.º 2
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.º 3
0
 String _getText(int index) {
   int count = Math.max(1, parent.getColumnCount());
   if (0 > index || index > count - 1) return "";
   int /*long*/[] ptr = new int /*long*/[1];
   int modelIndex =
       parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns[index].modelIndex;
   OS.gtk_tree_model_get(parent.modelHandle, handle, modelIndex + Table.CELL_TEXT, ptr, -1);
   if (ptr[0] == 0) return "";
   int length = OS.strlen(ptr[0]);
   byte[] buffer = new byte[length];
   OS.memmove(buffer, ptr[0], length);
   OS.g_free(ptr[0]);
   return new String(Converter.mbcsToWcs(null, buffer));
 }
Exemplo n.º 4
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.º 5
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.º 6
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.º 7
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.º 8
0
 public void setText(String string) {
   super.setText(string);
   byte[] buffer = Converter.wcsToMbcs(null, string, true);
   OS.gtk_label_set_text(labelHandle, buffer);
 }
Exemplo n.º 9
0
 int /*long*/ gtk_preedit_changed(int /*long*/ imcontext) {
   if (!isInlineEnabled()) return 0;
   ranges = null;
   styles = null;
   commitCount = 0;
   int /*long*/ imHandle = imHandle();
   int /*long*/[] preeditString = new int /*long*/[1];
   int /*long*/[] pangoAttrs = new int /*long*/[1];
   int[] cursorPos = new int[1];
   OS.gtk_im_context_get_preedit_string(imHandle, preeditString, pangoAttrs, cursorPos);
   caretOffset = cursorPos[0];
   char[] chars = null;
   if (preeditString[0] != 0) {
     int length = OS.strlen(preeditString[0]);
     byte[] buffer = new byte[length];
     OS.memmove(buffer, preeditString[0], length);
     chars = Converter.mbcsToWcs(null, buffer);
     if (pangoAttrs[0] != 0) {
       int count = 0;
       int /*long*/ iterator = OS.pango_attr_list_get_iterator(pangoAttrs[0]);
       while (OS.pango_attr_iterator_next(iterator)) count++;
       OS.pango_attr_iterator_destroy(iterator);
       ranges = new int[count * 2];
       styles = new TextStyle[count];
       iterator = OS.pango_attr_list_get_iterator(pangoAttrs[0]);
       PangoAttrColor attrColor = new PangoAttrColor();
       PangoAttrInt attrInt = new PangoAttrInt();
       int[] start = new int[1];
       int[] end = new int[1];
       for (int i = 0; i < count; i++) {
         OS.pango_attr_iterator_range(iterator, start, end);
         ranges[i * 2] =
             (int) /*64*/
                 OS.g_utf16_pointer_to_offset(preeditString[0], preeditString[0] + start[0]);
         ranges[i * 2 + 1] =
             (int) /*64*/ OS.g_utf16_pointer_to_offset(preeditString[0], preeditString[0] + end[0])
                 - 1;
         styles[i] = new TextStyle(null, null, null);
         int /*long*/ attr = OS.pango_attr_iterator_get(iterator, OS.PANGO_ATTR_FOREGROUND);
         if (attr != 0) {
           OS.memmove(attrColor, attr, PangoAttrColor.sizeof);
           GdkColor color = new GdkColor();
           color.red = attrColor.color_red;
           color.green = attrColor.color_green;
           color.blue = attrColor.color_blue;
           styles[i].foreground = Color.gtk_new(display, color);
         }
         attr = OS.pango_attr_iterator_get(iterator, OS.PANGO_ATTR_BACKGROUND);
         if (attr != 0) {
           OS.memmove(attrColor, attr, PangoAttrColor.sizeof);
           GdkColor color = new GdkColor();
           color.red = attrColor.color_red;
           color.green = attrColor.color_green;
           color.blue = attrColor.color_blue;
           styles[i].background = Color.gtk_new(display, color);
         }
         attr = OS.pango_attr_iterator_get(iterator, OS.PANGO_ATTR_UNDERLINE);
         if (attr != 0) {
           OS.memmove(attrInt, attr, PangoAttrInt.sizeof);
           styles[i].underline = attrInt.value != OS.PANGO_UNDERLINE_NONE;
           ;
           styles[i].underlineStyle = SWT.UNDERLINE_SINGLE;
           switch (attrInt.value) {
             case OS.PANGO_UNDERLINE_DOUBLE:
               styles[i].underlineStyle = SWT.UNDERLINE_DOUBLE;
               break;
             case OS.PANGO_UNDERLINE_ERROR:
               styles[i].underlineStyle = SWT.UNDERLINE_ERROR;
               break;
           }
           if (styles[i].underline) {
             attr = OS.pango_attr_iterator_get(iterator, OS.PANGO_ATTR_UNDERLINE_COLOR);
             if (attr != 0) {
               OS.memmove(attrColor, attr, PangoAttrColor.sizeof);
               GdkColor color = new GdkColor();
               color.red = attrColor.color_red;
               color.green = attrColor.color_green;
               color.blue = attrColor.color_blue;
               styles[i].underlineColor = Color.gtk_new(display, color);
             }
           }
         }
         OS.pango_attr_iterator_next(iterator);
       }
       OS.pango_attr_iterator_destroy(iterator);
       OS.pango_attr_list_unref(pangoAttrs[0]);
     }
     OS.g_free(preeditString[0]);
   }
   if (chars != null) {
     if (text.length() == 0) {
       /*
        * Bug in GTK. In Solaris, the IME sends multiple
        * preedit_changed signals with an empty text.
        * This behavior is not correct for SWT and can
        * cause the editor to replace its current selection
        * with an empty string. The fix is to ignore any
        * preedit_changed signals with an empty text when
        * the preedit buffer is already empty.
        */
       if (chars.length == 0) return 0;
       startOffset = -1;
     }
     int end = startOffset + text.length();
     if (startOffset == -1) {
       Event event = new Event();
       event.detail = SWT.COMPOSITION_SELECTION;
       sendEvent(SWT.ImeComposition, event);
       startOffset = event.start;
       end = event.end;
     }
     inComposition = true;
     Event event = new Event();
     event.detail = SWT.COMPOSITION_CHANGED;
     event.start = startOffset;
     event.end = end;
     event.text = text = chars != null ? new String(chars) : "";
     sendEvent(SWT.ImeComposition, event);
   }
   return 1;
 }