/** * Sets the receiver's text. The string may include the mnemonic character. * * <p>Mnemonics are indicated by an '&' 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 '&' can be escaped by doubling it in the string, * causing a single '&' 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(); }
public void setImage(Image image) { checkWidget(); if ((style & SWT.SEPARATOR) != 0) return; super.setImage(image); if (image != null) { ImageList imageList = parent.imageList; if (imageList == null) imageList = parent.imageList = new ImageList(); int imageIndex = imageList.indexOf(image); if (imageIndex == -1) { imageIndex = imageList.add(image); } else { imageList.put(imageIndex, image); } long /*int*/ pixbuf = imageList.getPixbuf(imageIndex); OS.gtk_image_set_from_pixbuf(imageHandle, pixbuf); } else { OS.gtk_image_set_from_pixbuf(imageHandle, 0); } /* * 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(); }
/** * Sets the receiver's tool tip text to the argument, which may be null indicating that the * default tool tip for the control will be shown. For a control that has a default tool tip, such * as the Tree control on Windows, setting the tool tip text to an empty string replaces the * default, causing no tool tip text to be shown. * * <p>The mnemonic indicator (character '&') is not displayed in a tool tip. To display a * single '&' in the tool tip, the character '&' can be escaped by doubling it in the * string. * * @param string the new tool tip text (or null) * @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 setToolTipText(String string) { checkWidget(); if (parent.toolTipText == null) { Shell shell = parent._getShell(); setToolTipText(shell, string); } toolTipText = string; /* * Since tooltip text of a tool-item is used in overflow * menu when images are not shown, it is required to * reset the proxy menu when the tooltip text changes. * Otherwise, the old menuItem appears in the overflow * menu as a blank item. */ 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); } }
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; }