Example #1
0
 public void setImage(Image image) {
   checkWidget();
   if ((style & SWT.SEPARATOR) != 0) return;
   if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
   super.setImage(image);
   updateImages(getEnabled() && parent.getEnabled());
 }
Example #2
0
 void register() {
   super.register();
   display.addWidget(clientHandle, this);
   display.addWidget(boxHandle, this);
   display.addWidget(labelHandle, this);
   display.addWidget(imageHandle, this);
 }
Example #3
0
 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();
 }
Example #4
0
 void deregister() {
   super.deregister();
   display.removeWidget(clientHandle);
   display.removeWidget(boxHandle);
   display.removeWidget(labelHandle);
   display.removeWidget(imageHandle);
 }
Example #5
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();
 }
Example #6
0
 void releaseWidget() {
   super.releaseWidget();
   if (imageList != null) imageList.dispose();
   if (parent.lastFocus == this) parent.lastFocus = null;
   imageList = null;
   control = null;
 }
Example #7
0
 void setOrientation(boolean create) {
   super.setOrientation(create);
   if ((parent.style & SWT.RIGHT_TO_LEFT) != 0 || !create) {
     int dir = (parent.style & SWT.RIGHT_TO_LEFT) != 0 ? OS.GTK_TEXT_DIR_RTL : OS.GTK_TEXT_DIR_LTR;
     OS.gtk_widget_set_direction(handle, dir);
     OS.gtk_container_forall(handle, display.setDirectionProc, dir);
   }
 }
Example #8
0
 void releaseWidget() {
   super.releaseWidget();
   if (parent.currentFocusItem == this) parent.currentFocusItem = null;
   parent = null;
   control = null;
   hotImage = disabledImage = null;
   toolTipText = null;
 }
Example #9
0
 void releaseWidget() {
   super.releaseWidget();
   releaseImages();
   control = null;
   toolTipText = null;
   disabledImage = hotImage = null;
   if (disabledImage2 != null) disabledImage2.dispose();
   disabledImage2 = null;
 }
Example #10
0
 public void setImage(Image image) {
   super.setImage(image);
   if (imageList != null) imageList.dispose();
   imageList = null;
   if (image != null) {
     if (image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
     imageList = new ImageList();
     int imageIndex = imageList.add(image);
     long /*int*/ pixbuf = imageList.getPixbuf(imageIndex);
     OS.gtk_image_set_from_pixbuf(imageHandle, pixbuf);
     if (text.length() == 0) OS.gtk_widget_hide(labelHandle);
     OS.gtk_widget_show(imageHandle);
   } else {
     OS.gtk_image_set_from_pixbuf(imageHandle, 0);
     OS.gtk_widget_show(labelHandle);
     OS.gtk_widget_hide(imageHandle);
   }
 }
Example #11
0
 void hookEvents() {
   super.hookEvents();
   OS.g_signal_connect_closure(handle, OS.activate, display.closures[ACTIVATE], false);
   OS.g_signal_connect_closure(handle, OS.activate, display.closures[ACTIVATE_INVERSE], true);
   OS.g_signal_connect_closure_by_id(
       handle,
       display.signalIds[BUTTON_PRESS_EVENT],
       0,
       display.closures[BUTTON_PRESS_EVENT],
       false);
   OS.g_signal_connect_closure_by_id(
       handle, display.signalIds[FOCUS_OUT_EVENT], 0, display.closures[FOCUS_OUT_EVENT], false);
   OS.g_signal_connect_closure(
       clientHandle, OS.size_allocate, display.closures[SIZE_ALLOCATE], true);
   OS.g_signal_connect_closure_by_id(
       handle,
       display.signalIds[ENTER_NOTIFY_EVENT],
       0,
       display.closures[ENTER_NOTIFY_EVENT],
       false);
 }
Example #12
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(text)) return;
    super.setText(string);
    long /*int*/ hwnd = parent.handle;
    TBBUTTONINFO info = new TBBUTTONINFO();
    info.cbSize = TBBUTTONINFO.sizeof;
    info.dwMask = OS.TBIF_TEXT | OS.TBIF_STYLE;
    info.fsStyle = (byte) (widgetStyle() | OS.BTNS_AUTOSIZE);
    long /*int*/ hHeap = OS.GetProcessHeap(), pszText = 0;
    if (string.length() != 0) {
      info.fsStyle |= OS.BTNS_SHOWTEXT;
      TCHAR buffer = new TCHAR(parent.getCodePage(), string, true);
      int byteCount = buffer.length() * TCHAR.sizeof;
      pszText = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
      OS.MoveMemory(pszText, buffer, byteCount);
      info.pszText = pszText;
    }
    OS.SendMessage(hwnd, OS.TB_SETBUTTONINFO, id, info);
    if (pszText != 0) OS.HeapFree(hHeap, 0, pszText);

    /*
     * Bug in Windows.  For some reason, when the font is set
     * before any tool item has text, the tool items resize to
     * a very small size.  Also, a tool item will only show text
     * when text has already been set on one item and then a new
     * item is created.  The fix is to use WM_SETFONT to force
     * the tool bar to redraw and layout.
     */
    parent.setDropDownItems(false);
    long /*int*/ hFont = OS.SendMessage(hwnd, OS.WM_GETFONT, 0, 0);
    OS.SendMessage(hwnd, OS.WM_SETFONT, hFont, 0);
    parent.setDropDownItems(true);
    parent.layoutItems();
  }
Example #13
0
 void releaseHandle() {
   if (handle != 0) OS.g_free(handle);
   handle = 0;
   super.releaseHandle();
   parent = null;
 }
Example #14
0
 void releaseHandle() {
   super.releaseHandle();
   arrowHandle = labelHandle = imageHandle = eventHandle = 0;
 }
Example #15
0
 void register() {
   super.register();
   if (eventHandle != 0) display.addWidget(eventHandle, this);
   if (arrowHandle != 0) display.addWidget(arrowHandle, this);
 }
Example #16
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);
  }
Example #17
0
 public void dispose() {
   if (isDisposed()) return;
   ToolBar parent = this.parent;
   super.dispose();
   parent.relayout();
 }
Example #18
0
 void deregister() {
   super.deregister();
   if (eventHandle != 0) display.removeWidget(eventHandle);
   if (arrowHandle != 0) display.removeWidget(arrowHandle);
 }
Example #19
0
 void createWidget(int index) {
   super.createWidget(index);
   showWidget(index);
   parent.relayout();
 }
Example #20
0
 void createWidget(int index) {
   super.createWidget(index);
   showWidget(index);
   parent.createItem(this, style, index);
 }
Example #21
0
 void destroyWidget() {
   parent.destroyItem(this);
   super.destroyWidget();
 }
Example #22
0
 void releaseHandle() {
   super.releaseHandle();
   parent = null;
   id = -1;
 }
Example #23
0
 void releaseWidget() {
   super.releaseWidget();
   font = null;
   cellFont = null;
 }
Example #24
0
 public void setText(String string) {
   super.setText(string);
   byte[] buffer = Converter.wcsToMbcs(null, string, true);
   OS.gtk_label_set_text(labelHandle, buffer);
 }
Example #25
0
 void releaseHandle() {
   super.releaseHandle();
   clientHandle = boxHandle = labelHandle = imageHandle = 0;
   parent = null;
 }