示例#1
1
 /**
  * Event.detail line start offset (input) Event.text line text (input) LineStyleEvent.styles
  * Enumeration of StyleRanges, need to be in order. (output) LineStyleEvent.background line
  * background color (output)
  */
 public void lineGetStyle(LineStyleEvent event) {
   Vector styles = new Vector();
   int token;
   StyleRange lastStyle;
   // If the line is part of a block comment, create one style for the entire line.
   if (inBlockComment(event.lineOffset, event.lineOffset + event.lineText.length())) {
     styles.addElement(
         new StyleRange(event.lineOffset, event.lineText.length(), getColor(COMMENT), null));
     event.styles = new StyleRange[styles.size()];
     styles.copyInto(event.styles);
     return;
   }
   Color defaultFgColor = ((Control) event.widget).getForeground();
   scanner.setRange(event.lineText);
   token = scanner.nextToken();
   while (token != EOF) {
     if (token == OTHER) {
       // do nothing for non-colored tokens
     } else if (token != WHITE) {
       Color color = getColor(token);
       // Only create a style if the token color is different than the
       // widget's default foreground color and the token's style is not
       // bold.  Keywords are bolded.
       if ((!color.equals(defaultFgColor)) || (token == KEY)) {
         StyleRange style =
             new StyleRange(
                 scanner.getStartOffset() + event.lineOffset, scanner.getLength(), color, null);
         if (token == KEY) {
           style.fontStyle = SWT.BOLD;
         }
         if (styles.isEmpty()) {
           styles.addElement(style);
         } else {
           // Merge similar styles.  Doing so will improve performance.
           lastStyle = (StyleRange) styles.lastElement();
           if (lastStyle.similarTo(style) && (lastStyle.start + lastStyle.length == style.start)) {
             lastStyle.length += style.length;
           } else {
             styles.addElement(style);
           }
         }
       }
     } else if ((!styles.isEmpty())
         && ((lastStyle = (StyleRange) styles.lastElement()).fontStyle == SWT.BOLD)) {
       int start = scanner.getStartOffset() + event.lineOffset;
       lastStyle = (StyleRange) styles.lastElement();
       // A font style of SWT.BOLD implies that the last style
       // represents a java keyword.
       if (lastStyle.start + lastStyle.length == start) {
         // Have the white space take on the style before it to
         // minimize the number of style ranges created and the
         // number of font style changes during rendering.
         lastStyle.length += scanner.getLength();
       }
     }
     token = scanner.nextToken();
   }
   event.styles = new StyleRange[styles.size()];
   styles.copyInto(event.styles);
 }
示例#2
0
 Color _getForeground() {
   int /*long*/[] ptr = new int /*long*/[1];
   OS.gtk_tree_model_get(parent.modelHandle, handle, Table.FOREGROUND_COLUMN, ptr, -1);
   if (ptr[0] == 0) return parent.getForeground();
   GdkColor gdkColor = new GdkColor();
   OS.memmove(gdkColor, ptr[0], GdkColor.sizeof);
   return Color.gtk_new(display, gdkColor);
 }
示例#3
0
 void createHandle() {
   super.createHandle();
   state |= THEME_BACKGROUND;
   if (OS.COMCTL32_MAJOR < 6) {
     layout = new TextLayout(display);
     if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION(4, 10)) {
       linkColor = Color.win32_new(display, OS.GetSysColor(OS.COLOR_HOTLIGHT));
     } else {
       linkColor = new Color(display, LINK_FOREGROUND);
     }
     disabledColor = Color.win32_new(display, OS.GetSysColor(OS.COLOR_GRAYTEXT));
     offsets = new Point[0];
     ids = new String[0];
     mnemonics = new int[0];
     selection = new Point(-1, -1);
     focusIndex = mouseDownIndex = -1;
   }
 }
示例#4
0
 void releaseWidget() {
   super.releaseWidget();
   if (layout != null) layout.dispose();
   layout = null;
   if (linkColor != null) linkColor.dispose();
   linkColor = null;
   disabledColor = null;
   offsets = null;
   ids = null;
   mnemonics = null;
   text = null;
 }
示例#5
0
  /**
   * Sets the background color at the given column index in the receiver to the color specified by
   * the argument, or to the default system color for the item if the argument is null.
   *
   * @param index the column index
   * @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 3.0
   */
  public void setBackground(int index, Color color) {
    checkWidget();
    if (color != null && color.isDisposed()) {
      SWT.error(SWT.ERROR_INVALID_ARGUMENT);
    }
    if (_getBackground(index).equals(color)) return;
    int count = Math.max(1, parent.getColumnCount());
    if (0 > index || index > count - 1) return;
    int modelIndex =
        parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns[index].modelIndex;
    GdkColor gdkColor = color != null ? color.handle : null;
    OS.gtk_list_store_set(
        parent.modelHandle, handle, modelIndex + Table.CELL_BACKGROUND, 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;

    if (color != 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;
        }
      }
    }
  }
示例#6
0
 Color _getForeground(int index) {
   int count = Math.max(1, parent.columnCount);
   if (0 > index || index > count - 1) return _getForeground();
   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_FOREGROUND, ptr, -1);
   if (ptr[0] == 0) return _getForeground();
   GdkColor gdkColor = new GdkColor();
   OS.memmove(gdkColor, ptr[0], GdkColor.sizeof);
   return Color.gtk_new(display, gdkColor);
 }
 /**
  * Constructs a new Pattern that represents a linear, two color gradient. Drawing with the pattern
  * will cause the resulting area to be tiled with the gradient specified by the arguments.
  *
  * <p>This operation requires the operating system's advanced graphics subsystem which may not be
  * available on some platforms.
  *
  * @param device the device on which to allocate the pattern
  * @param x1 the x coordinate of the starting corner of the gradient
  * @param y1 the y coordinate of the starting corner of the gradient
  * @param x2 the x coordinate of the ending corner of the gradient
  * @param y2 the y coordinate of the ending corner of the gradient
  * @param color1 the starting color of the gradient
  * @param alpha1 the starting alpha value of the gradient
  * @param color2 the ending color of the gradient
  * @param alpha2 the ending alpha value of the gradient
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device, or if
  *           either color1 or color2 is null
  *       <li>ERROR_INVALID_ARGUMENT - if either color1 or color2 has been disposed
  *     </ul>
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available
  *     </ul>
  *
  * @exception SWTError
  *     <ul>
  *       <li>ERROR_NO_HANDLES if a handle for the pattern could not be obtained
  *     </ul>
  *
  * @see #dispose()
  * @since 3.2
  */
 public Pattern(
     Device device,
     float x1,
     float y1,
     float x2,
     float y2,
     Color color1,
     int alpha1,
     Color color2,
     int alpha2) {
   super(device);
   if (color1 == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
   if (color1.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   if (color2 == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
   if (color2.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   this.device.checkCairo();
   handle = Cairo.cairo_pattern_create_linear(x1, y1, x2, y2);
   if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
   GC.setCairoPatternColor(handle, 0, color1, alpha1);
   GC.setCairoPatternColor(handle, 1, color2, alpha2);
   Cairo.cairo_pattern_set_extend(handle, Cairo.CAIRO_EXTEND_REPEAT);
   init();
 }
示例#8
0
 public void setBackground(Color color) {
   super.setBackground(color);
   // Are these settings the same as before?
   if (backgroundImage == null && gradientColors == null && gradientPercents == null) {
     if (color == null) {
       if (background == null) return;
     } else {
       if (color.equals(background)) return;
     }
   }
   background = color;
   backgroundImage = null;
   gradientColors = null;
   gradientPercents = null;
   redraw();
 }
示例#9
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;
 }
示例#10
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;
 }
示例#11
0
  /**
   * Initializes any internal resources needed by the device.
   *
   * <p>This method is called after <code>create</code>.
   *
   * <p>If subclasses reimplement this method, they must call the <code>super</code> implementation.
   *
   * @see #create
   */
  protected void init() {
    /* Create the standard colors */
    colors = new Color[SWT.COLOR_DARK_GRAY + 1];
    colors[SWT.COLOR_BLACK] = colors[0] = Color.wpf_new(this, OS.Colors_Black());
    colors[SWT.COLOR_DARK_RED] = Color.wpf_new(this, OS.Colors_Maroon());
    colors[SWT.COLOR_DARK_GREEN] = Color.wpf_new(this, OS.Colors_Green());
    colors[SWT.COLOR_DARK_YELLOW] = Color.wpf_new(this, OS.Colors_Olive());
    colors[SWT.COLOR_DARK_BLUE] = Color.wpf_new(this, OS.Colors_Navy());
    colors[SWT.COLOR_DARK_MAGENTA] = Color.wpf_new(this, OS.Colors_Purple());
    colors[SWT.COLOR_DARK_CYAN] = Color.wpf_new(this, OS.Colors_Teal());
    colors[SWT.COLOR_GRAY] = Color.wpf_new(this, OS.Colors_Silver());
    colors[SWT.COLOR_DARK_GRAY] = Color.wpf_new(this, OS.Colors_Silver());
    colors[SWT.COLOR_RED] = Color.wpf_new(this, OS.Colors_Red());
    colors[SWT.COLOR_GREEN] = Color.wpf_new(this, OS.Colors_Lime());
    colors[SWT.COLOR_YELLOW] = Color.wpf_new(this, OS.Colors_Yellow());
    colors[SWT.COLOR_BLUE] = Color.wpf_new(this, OS.Colors_Blue());
    colors[SWT.COLOR_MAGENTA] = Color.wpf_new(this, OS.Colors_Magenta());
    colors[SWT.COLOR_CYAN] = Color.wpf_new(this, OS.Colors_Cyan());
    colors[SWT.COLOR_WHITE] = Color.wpf_new(this, OS.Colors_White());

    /* Initialize the system font slot */
    int fontFamily = OS.SystemFonts_MessageFontFamily();
    int style = OS.SystemFonts_MessageFontStyle();
    int weight = OS.SystemFonts_MessageFontWeight();
    double size = OS.SystemFonts_MessageFontSize();
    int typeface = OS.gcnew_Typeface(fontFamily, style, weight, OS.FontStretches_Normal);
    OS.GCHandle_Free(fontFamily);
    OS.GCHandle_Free(style);
    OS.GCHandle_Free(weight);
    systemFont = Font.wpf_new(this, typeface, size);
  }
示例#12
0
 /**
  * Invokes platform specific functionality to allocate a new color.
  *
  * <p><b>IMPORTANT:</b> This method is <em>not</em> part of the public API for <code>Color</code>.
  * It is marked public only so that it can be shared within the packages provided by SWT. It is
  * not available on all platforms, and should never be called from application code.
  *
  * @param device the device on which to allocate the color
  * @param handle the handle for the color
  * @param alpha the int for the alpha content in the color
  * @return a new color object containing the specified device and handle
  * @noreference This method is not intended to be referenced by clients.
  */
 public static Color win32_new(Device device, int handle, int alpha) {
   Color color = new Color(device);
   color.handle = handle;
   color.alpha = alpha;
   return color;
 }
示例#13
0
 public static Color motif_new(Device device, XColor xColor) {
   Color color = new Color(device);
   color.handle = xColor;
   return color;
 }