Ejemplo n.º 1
0
  /**
   * Sets the font that the receiver will use to paint textual information for the specified cell in
   * this item to the font specified by the argument, or to the default font for that kind of
   * control if the argument is null.
   *
   * @param index the column index
   * @param font the new font (or null)
   * @exception IllegalArgumentException
   *     <ul>
   *       <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed
   *     </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>
   *
   * @since 3.0
   */
  public void setFont(int index, Font font) {
    checkWidget();
    if (font != null && font.isDisposed()) {
      SWT.error(SWT.ERROR_INVALID_ARGUMENT);
    }
    int count = Math.max(1, parent.getColumnCount());
    if (0 > index || index > count - 1) return;
    if (cellFont == null) {
      if (font == null) return;
      cellFont = new Font[count];
    }
    Font oldFont = cellFont[index];
    if (oldFont == font) return;
    cellFont[index] = font;
    if (oldFont != null && oldFont.equals(font)) return;

    int modelIndex =
        parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns[index].modelIndex;
    int /*long*/ fontHandle = font != null ? font.handle : 0;
    OS.gtk_list_store_set(parent.modelHandle, handle, modelIndex + Table.CELL_FONT, fontHandle, -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;

    if (font != null) {
      boolean customDraw =
          (parent.columnCount == 0) ? parent.firstCustomDraw : parent.columns[index].customDraw;
      if (!customDraw) {
        if ((parent.style & SWT.VIRTUAL) == 0) {
          int /*long*/ parentHandle = parent.handle;
          int /*long*/ column = 0;
          if (parent.columnCount > 0) {
            column = parent.columns[index].handle;
          } else {
            column = OS.gtk_tree_view_get_column(parentHandle, index);
          }
          if (column == 0) return;
          int /*long*/ textRenderer = parent.getTextRenderer(column);
          int /*long*/ imageRenderer = parent.getPixbufRenderer(column);
          OS.gtk_tree_view_column_set_cell_data_func(
              column, textRenderer, display.cellDataProc, parentHandle, 0);
          OS.gtk_tree_view_column_set_cell_data_func(
              column, imageRenderer, display.cellDataProc, parentHandle, 0);
        }
        if (parent.columnCount == 0) {
          parent.firstCustomDraw = true;
        } else {
          parent.columns[index].customDraw = true;
        }
      }
    }
  }
Ejemplo n.º 2
0
 /**
  * Sets the receiver's image at a column.
  *
  * @param index the column index
  * @param image the new image
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_INVALID_ARGUMENT - if the image has been disposed
  *     </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 setImage(int index, Image image) {
   checkWidget();
   if (image != null && image.isDisposed()) {
     error(SWT.ERROR_INVALID_ARGUMENT);
   }
   if (image != null && image.type == SWT.ICON) {
     if (image.equals(_getImage(index))) return;
   }
   int count = Math.max(1, parent.getColumnCount());
   if (0 > index || index > count - 1) return;
   int /*long*/ pixbuf = 0;
   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);
     pixbuf = imageList.getPixbuf(imageIndex);
   }
   int modelIndex =
       parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns[index].modelIndex;
   OS.gtk_list_store_set(parent.modelHandle, handle, modelIndex + Table.CELL_PIXBUF, pixbuf, -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();
     }
   }
   /*
    * Bug in GTK.  When in fixed height mode, GTK does not recalculate the cell renderer width
    * when the image is changed in the model.  The fix is to force it to recalculate the width if
    * more space is required.
    */
   if ((parent.style & SWT.VIRTUAL) != 0 && parent.currentItem == null) {
     if (OS.GTK_VERSION >= OS.VERSION(2, 3, 2)) {
       if (image != null) {
         int /*long*/ parentHandle = parent.handle;
         int /*long*/ column = OS.gtk_tree_view_get_column(parentHandle, index);
         int[] w = new int[1];
         int /*long*/ pixbufRenderer = parent.getPixbufRenderer(column);
         OS.gtk_tree_view_column_cell_get_position(column, pixbufRenderer, null, w);
         if (w[0] < image.getBounds().width) {
           /*
            * There is no direct way to clear the cell renderer width so we
            * are relying on the fact that it is done as part of modifying
            * the style.
            */
           int /*long*/ style = OS.gtk_widget_get_modifier_style(parentHandle);
           parent.modifyStyle(parentHandle, style);
         }
       }
     }
   }
   cached = true;
 }
Ejemplo n.º 3
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();
 }
Ejemplo n.º 4
0
 /**
  * Enables the receiver if the argument is <code>true</code>, and disables it otherwise.
  *
  * <p>A disabled control is typically not selectable from the user interface and draws with an
  * inactive or "grayed" look.
  *
  * @param enabled the new enabled state
  * @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 setEnabled(boolean enabled) {
   checkWidget();
   long /*int*/ topHandle = topHandle();
   if (OS.GTK_WIDGET_SENSITIVE(topHandle) == enabled) return;
   OS.gtk_widget_set_sensitive(topHandle, enabled);
   if (enabled) {
     /*
      * Bug in GTK.  GtkButton requires an enter notify before it
      * allows the button to be pressed, but events are dropped when
      * widgets are insensitive.  The fix is to hide and show the
      * button if the pointer is within its bounds.
      */
     int[] x = new int[1], y = new int[1];
     OS.gdk_window_get_pointer(parent.paintWindow(), x, y, null);
     if (getBounds().contains(x[0], y[0])) {
       OS.gtk_widget_hide(handle);
       OS.gtk_widget_show(handle);
     }
   } else {
     /*
      * Bug in GTK. Starting with 2.14, if a button is disabled
      * through on a button press, the field which keeps track
      * whether the pointer is currently in the button is never updated.
      * As a result, when it is re-enabled it automatically enters
      * a PRELIGHT state. The fix is to set a NORMAL state.
      */
     if (OS.GTK_VERSION >= OS.VERSION(2, 14, 0)) {
       OS.gtk_widget_set_state(topHandle, OS.GTK_STATE_NORMAL);
     }
   }
 }
Ejemplo n.º 5
0
 long /*int*/ gtk_clicked(long /*int*/ widget) {
   Event event = new Event();
   if ((style & SWT.DROP_DOWN) != 0) {
     long /*int*/ eventPtr = OS.gtk_get_current_event();
     if (eventPtr != 0) {
       GdkEvent gdkEvent = new GdkEvent();
       OS.memmove(gdkEvent, eventPtr, GdkEvent.sizeof);
       long /*int*/ topHandle = topHandle();
       switch (gdkEvent.type) {
         case OS.GDK_KEY_RELEASE: // Fall Through..
         case OS.GDK_BUTTON_PRESS:
         case OS.GDK_2BUTTON_PRESS:
         case OS.GDK_BUTTON_RELEASE:
           {
             boolean isArrow = false;
             if (OS.GTK_VERSION < OS.VERSION(2, 6, 0)) {
               double[] x_win = new double[1];
               double[] y_win = new double[1];
               OS.gdk_event_get_coords(eventPtr, x_win, y_win);
               int x = OS.GTK_WIDGET_X(arrowHandle) - OS.GTK_WIDGET_X(handle);
               int width = OS.GTK_WIDGET_WIDTH(arrowHandle);
               if ((((parent.style & SWT.RIGHT_TO_LEFT) == 0) && x <= (int) x_win[0])
                   || (((parent.style & SWT.RIGHT_TO_LEFT) != 0) && (int) x_win[0] <= x + width)) {
                 isArrow = true;
               }
             } else if (widget == arrowHandle) {
               isArrow = true;
               topHandle = widget;
               /*
                * Feature in GTK. ArrowButton stays in toggled state if there is no popup menu.
                * It is required to set back the state of arrow to normal state after it is clicked.
                */
               OS.g_signal_handlers_block_matched(
                   widget, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CLICKED);
               OS.gtk_toggle_button_set_active(widget, false);
               OS.g_signal_handlers_unblock_matched(
                   widget, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CLICKED);
             }
             if (isArrow) {
               event.detail = SWT.ARROW;
               event.x = OS.GTK_WIDGET_X(topHandle);
               if ((parent.style & SWT.MIRRORED) != 0)
                 event.x = parent.getClientWidth() - OS.GTK_WIDGET_WIDTH(topHandle) - event.x;
               event.y = OS.GTK_WIDGET_Y(topHandle) + OS.GTK_WIDGET_HEIGHT(topHandle);
             }
             break;
           }
       }
       OS.gdk_event_free(eventPtr);
     }
   }
   if ((style & SWT.RADIO) != 0) {
     if ((parent.getStyle() & SWT.NO_RADIO_GROUP) == 0) {
       selectRadio();
     }
   }
   sendSelectionEvent(SWT.Selection, event, false);
   return 0;
 }
Ejemplo n.º 6
0
 @Override
 void setBackgroundColor(long /*int*/ context, long /*int*/ handle, GdkRGBA rgba) {
   if (OS.GTK_VERSION >= OS.VERSION(3, 16, 0)) {
     String css = "GtkToolbar {background-color: " + gtk_rgba_to_css_string(rgba) + "}";
     gtk_css_provider_load_from_css(context, css);
   } else {
     super.setBackgroundColor(context, handle, rgba);
   }
 }
Ejemplo n.º 7
0
 void showWidget(int index) {
   if (handle != 0) OS.gtk_widget_show(handle);
   if (labelHandle != 0) OS.gtk_widget_show(labelHandle);
   if (imageHandle != 0) OS.gtk_widget_show(imageHandle);
   if ((style & SWT.DROP_DOWN) != 0 && OS.GTK_VERSION < OS.VERSION(2, 6, 0)) {
     if (arrowBoxHandle != 0) OS.gtk_widget_show(arrowBoxHandle);
     if (arrowHandle != 0) OS.gtk_widget_show(arrowHandle);
   }
   OS.gtk_toolbar_insert(parent.handle, handle, index);
 }
Ejemplo n.º 8
0
 /**
  * Sets the receiver's background color to the color specified by the argument, or to the default
  * system color for the item if the argument is null.
  *
  * @param color the new color (or null)
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed
  *     </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>
  *
  * @since 2.0
  */
 public void setBackground(Color color) {
   checkWidget();
   if (color != null && color.isDisposed()) {
     SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   }
   if (_getBackground().equals(color)) return;
   GdkColor gdkColor = color != null ? color.handle : null;
   OS.gtk_list_store_set(parent.modelHandle, handle, Table.BACKGROUND_COLUMN, gdkColor, -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;
 }
Ejemplo n.º 9
0
 void clear() {
   if (parent.currentItem == this) return;
   if (cached || (parent.style & SWT.VIRTUAL) == 0) {
     int columnCount = OS.gtk_tree_model_get_n_columns(parent.modelHandle);
     for (int i = 0; i < columnCount; i++) {
       OS.gtk_list_store_set(parent.modelHandle, handle, i, 0, -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 = false;
   font = null;
   cellFont = null;
 }
Ejemplo n.º 10
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;
 }
Ejemplo n.º 11
0
 /**
  * Sets the font that the receiver will use to paint textual information for this item to the font
  * specified by the argument, or to the default font for that kind of control if the argument is
  * null.
  *
  * @param font the new font (or null)
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed
  *     </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>
  *
  * @since 3.0
  */
 public void setFont(Font font) {
   checkWidget();
   if (font != null && font.isDisposed()) {
     SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   }
   Font oldFont = this.font;
   if (oldFont == font) return;
   this.font = font;
   if (oldFont != null && oldFont.equals(font)) return;
   int /*long*/ fontHandle = font != null ? font.handle : 0;
   OS.gtk_list_store_set(parent.modelHandle, handle, Table.FONT_COLUMN, fontHandle, -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;
 }
Ejemplo n.º 12
0
 /**
  * Returns a rectangle describing the size and location relative to its parent of an image at a
  * column in the table. An empty rectangle is returned if index exceeds the index of the table's
  * last column.
  *
  * @param index the index that specifies the column
  * @return the receiver's bounding image rectangle
  * @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 Rectangle getImageBounds(int index) {
   checkWidget();
   if (!parent.checkData(this)) error(SWT.ERROR_WIDGET_DISPOSED);
   int /*long*/ parentHandle = parent.handle;
   int /*long*/ column = 0;
   if (index >= 0 && index < parent.columnCount) {
     column = parent.columns[index].handle;
   } else {
     column = OS.gtk_tree_view_get_column(parentHandle, index);
   }
   if (column == 0) return new Rectangle(0, 0, 0, 0);
   int /*long*/ pixbufRenderer = parent.getPixbufRenderer(column);
   if (pixbufRenderer == 0) return new Rectangle(0, 0, 0, 0);
   GdkRectangle rect = new GdkRectangle();
   int /*long*/ path = OS.gtk_tree_model_get_path(parent.modelHandle, handle);
   OS.gtk_widget_realize(parentHandle);
   OS.gtk_tree_view_get_cell_area(parentHandle, path, column, rect);
   OS.gtk_tree_path_free(path);
   if ((parent.getStyle() & SWT.MIRRORED) != 0)
     rect.x = parent.getClientWidth() - rect.width - rect.x;
   /*
    * The OS call gtk_cell_renderer_get_size() provides the width of image to be drawn
    * by the cell renderer.  If there is no image in the cell, the width is zero.  If the table contains
    * images of varying widths, gtk_cell_renderer_get_size() will return the width of the image,
    * not the width of the area in which the image is drawn.
    * New API was added in GTK 2.1.3 for determining the full width of the renderer area.
    * For earlier versions of GTK, the result is only correct if all rows have images of the same
    * width.
    */
   if (OS.GTK_VERSION >= OS.VERSION(2, 1, 3)) {
     int[] x = new int[1], w = new int[1];
     OS.gtk_tree_view_column_cell_get_position(column, pixbufRenderer, x, w);
     rect.x += x[0];
     rect.width = w[0];
   } else {
     int[] w = new int[1];
     OS.gtk_tree_view_column_cell_set_cell_data(column, parent.modelHandle, handle, false, false);
     OS.gtk_cell_renderer_get_size(pixbufRenderer, parentHandle, null, null, null, w, null);
     rect.width = w[0];
   }
   int width = OS.gtk_tree_view_column_get_visible(column) ? rect.width : 0;
   return new Rectangle(rect.x, rect.y, width, rect.height + 1);
 }
Ejemplo n.º 13
0
  /**
   * Returns a rectangle describing the receiver's size and location relative to its parent at a
   * column in the table.
   *
   * @param index the index that specifies the column
   * @return the receiver's bounding column rectangle
   * @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 Rectangle getBounds(int index) {
    checkWidget();
    if (!parent.checkData(this)) error(SWT.ERROR_WIDGET_DISPOSED);
    int /*long*/ parentHandle = parent.handle;
    int /*long*/ column = 0;
    if (index >= 0 && index < parent.columnCount) {
      column = parent.columns[index].handle;
    } else {
      column = OS.gtk_tree_view_get_column(parentHandle, index);
    }
    if (column == 0) return new Rectangle(0, 0, 0, 0);
    int /*long*/ path = OS.gtk_tree_model_get_path(parent.modelHandle, handle);
    OS.gtk_widget_realize(parentHandle);
    GdkRectangle rect = new GdkRectangle();
    OS.gtk_tree_view_get_cell_area(parentHandle, path, column, rect);
    OS.gtk_tree_path_free(path);
    if ((parent.getStyle() & SWT.MIRRORED) != 0)
      rect.x = parent.getClientWidth() - rect.width - rect.x;

    if (index == 0 && (parent.style & SWT.CHECK) != 0) {
      if (OS.GTK_VERSION >= OS.VERSION(2, 1, 3)) {
        int[] x = new int[1], w = new int[1];
        OS.gtk_tree_view_column_cell_get_position(column, parent.checkRenderer, x, w);
        rect.x += x[0] + w[0];
        rect.width -= x[0] + w[0];
      } else {
        int[] w = new int[1];
        OS.gtk_cell_renderer_get_size(
            parent.checkRenderer, parentHandle, null, null, null, w, null);
        int[] buffer = new int[1];
        OS.gtk_widget_style_get(parentHandle, OS.horizontal_separator, buffer, 0);
        rect.x += w[0] + buffer[0];
        rect.width -= w[0] + buffer[0];
      }
    }
    int width = OS.gtk_tree_view_column_get_visible(column) ? rect.width + 1 : 0;
    return new Rectangle(rect.x, rect.y, width, rect.height + 1);
  }
Ejemplo n.º 14
0
  @Override
  LRESULT WM_IME_COMPOSITION(long /*int*/ wParam, long /*int*/ lParam) {
    if (ime != null) {
      LRESULT result = ime.WM_IME_COMPOSITION(wParam, lParam);
      if (result != null) return result;
    }

    /*
     * Bug in Windows.  On Korean Windows XP, the IME window
     * for the Korean Input System (MS-IME 2002) always opens
     * in the top left corner of the screen, despite the fact
     * that ImmSetCompositionWindow() was called to position
     * the IME when focus is gained.  The fix is to position
     * the IME on every WM_IME_COMPOSITION message.
     */
    if (!OS.IsWinCE && OS.WIN32_VERSION == OS.VERSION(5, 1)) {
      if (OS.IsDBLocale) {
        short langID = OS.GetSystemDefaultUILanguage();
        short primaryLang = OS.PRIMARYLANGID(langID);
        if (primaryLang == OS.LANG_KOREAN) {
          if (caret != null && caret.isFocusCaret()) {
            POINT ptCurrentPos = new POINT();
            if (OS.GetCaretPos(ptCurrentPos)) {
              COMPOSITIONFORM lpCompForm = new COMPOSITIONFORM();
              lpCompForm.dwStyle = OS.CFS_POINT;
              lpCompForm.x = ptCurrentPos.x;
              lpCompForm.y = ptCurrentPos.y;
              long /*int*/ hIMC = OS.ImmGetContext(handle);
              OS.ImmSetCompositionWindow(hIMC, lpCompForm);
              OS.ImmReleaseContext(handle, hIMC);
            }
          }
        }
      }
    }
    return super.WM_IME_COMPOSITION(wParam, lParam);
  }
Ejemplo n.º 15
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();
  }
Ejemplo n.º 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);
  }
Ejemplo n.º 17
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);
 }
Ejemplo n.º 18
0
  /**
   * Returns a rectangle describing the size and location relative to its parent of the text at a
   * column in the table. An empty rectangle is returned if index exceeds the index of the table's
   * last column.
   *
   * @param index the index that specifies the column
   * @return the receiver's bounding text rectangle
   * @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>
   *
   * @since 3.3
   */
  public Rectangle getTextBounds(int index) {
    checkWidget();
    if (!parent.checkData(this)) error(SWT.ERROR_WIDGET_DISPOSED);
    int count = Math.max(1, parent.getColumnCount());
    if (0 > index || index > count - 1) return new Rectangle(0, 0, 0, 0);
    // TODO fully test on early and later versions of GTK
    // shifted a bit too far right on later versions of GTK - however, old Tree also had this
    // problem
    int /*long*/ parentHandle = parent.handle;
    int /*long*/ column = 0;
    if (index >= 0 && index < parent.columnCount) {
      column = parent.columns[index].handle;
    } else {
      column = OS.gtk_tree_view_get_column(parentHandle, index);
    }
    if (column == 0) return new Rectangle(0, 0, 0, 0);
    int /*long*/ textRenderer = parent.getTextRenderer(column);
    int /*long*/ pixbufRenderer = parent.getPixbufRenderer(column);
    if (textRenderer == 0 || pixbufRenderer == 0) return new Rectangle(0, 0, 0, 0);

    int /*long*/ path = OS.gtk_tree_model_get_path(parent.modelHandle, handle);
    OS.gtk_widget_realize(parentHandle);

    boolean isExpander = OS.gtk_tree_model_iter_n_children(parent.modelHandle, handle) > 0;
    boolean isExpanded = OS.gtk_tree_view_row_expanded(parentHandle, path);
    OS.gtk_tree_view_column_cell_set_cell_data(
        column, parent.modelHandle, handle, isExpander, isExpanded);

    GdkRectangle rect = new GdkRectangle();
    OS.gtk_tree_view_get_cell_area(parentHandle, path, column, rect);
    OS.gtk_tree_path_free(path);
    if ((parent.getStyle() & SWT.MIRRORED) != 0)
      rect.x = parent.getClientWidth() - rect.width - rect.x;
    int right = rect.x + rect.width;

    int[] x = new int[1], w = new int[1];
    parent.ignoreSize = true;
    OS.gtk_cell_renderer_get_size(textRenderer, parentHandle, null, null, null, w, null);
    parent.ignoreSize = false;
    int[] buffer = new int[1];
    if (OS.gtk_tree_view_get_expander_column(parentHandle) == column) {
      OS.gtk_widget_style_get(parentHandle, OS.expander_size, buffer, 0);
      rect.x += buffer[0] + TreeItem.EXPANDER_EXTRA_PADDING;
    }
    OS.gtk_widget_style_get(parentHandle, OS.horizontal_separator, buffer, 0);
    int horizontalSeparator = buffer[0];
    rect.x += horizontalSeparator;

    if (OS.GTK_VERSION >= OS.VERSION(2, 1, 3)) {
      OS.gtk_tree_view_column_cell_get_position(column, textRenderer, x, null);
      rect.x += x[0];
    } else {
      if ((parent.style & SWT.CHECK) != 0) {
        OS.gtk_cell_renderer_get_size(
            parent.checkRenderer, parentHandle, null, null, null, w, null);
        rect.x += w[0] + horizontalSeparator;
      }
      OS.gtk_cell_renderer_get_size(pixbufRenderer, parentHandle, null, null, null, w, null);
      rect.x += w[0] + horizontalSeparator;
    }
    if (parent.columnCount > 0) {
      if (rect.x + rect.width > right) {
        rect.width = Math.max(0, right - rect.x);
      }
    }
    int width = OS.gtk_tree_view_column_get_visible(column) ? rect.width + 1 : 0;
    return new Rectangle(rect.x, rect.y, width, rect.height + 1);
  }