Class Canvas

All Implemented Interfaces:
Drawable
Direct Known Subclasses:
AnimatedProgress, CLabel, Decorations, GLCanvas, StyledText, TableCursor, TreeCursor

public class Canvas extends Composite
Instances of this class provide a surface for drawing arbitrary graphics.
Styles:
(none)
Events:
(none)

This class may be subclassed by custom control implementors who are building controls that are not constructed from aggregates of other controls. That is, they are either painted using SWT graphics calls or are handled by native methods.

See Also:
  • Field Details

    • caret

      Caret caret
    • ime

      IME ime
    • drawFlag

      boolean drawFlag
  • Constructor Details

    • Canvas

      Canvas()
    • Canvas

      public Canvas(Composite parent, int style)
      Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

      The style value is either one of the style constants defined in class SWT which is applicable to instances of this class, or must be built by bitwise OR'ing together (that is, using the int "|" operator) two or more of those SWT style constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses.

      Parameters:
      parent - a composite control which will be the parent of the new instance (cannot be null)
      style - the style of control to construct
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the parent is null
      SWTException -
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
      See Also:
  • Method Details

    • drawBackground

      public void drawBackground(GC gc, int x, int y, int width, int height)
      Fills the interior of the rectangle specified by the arguments, with the receiver's background.
      Parameters:
      gc - the gc where the rectangle is to be filled
      x - the x coordinate of the rectangle to be filled
      y - the y coordinate of the rectangle to be filled
      width - the width of the rectangle to be filled
      height - the height of the rectangle to be filled
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the gc is null
      • ERROR_INVALID_ARGUMENT - if the gc has been disposed
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.2
    • getCaret

      public Caret getCaret()
      Returns the caret.

      The caret for the control is automatically hidden and shown when the control is painted or resized, when focus is gained or lost and when an the control is scrolled. To avoid drawing on top of the caret, the programmer must hide and show the caret when drawing in the window any other time.

      Returns:
      the caret for the receiver, may be null
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • getIMCaretPos

      Point getIMCaretPos()
      Overrides:
      getIMCaretPos in class Control
    • getIME

      public IME getIME()
      Returns the IME.
      Returns:
      the IME
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.4
    • gtk_button_press_event

      long gtk_button_press_event(long widget, long event)
      Overrides:
      gtk_button_press_event in class Composite
    • gtk_commit

      long gtk_commit(long imcontext, long text)
      Overrides:
      gtk_commit in class Control
    • gtk_draw

      long gtk_draw(long widget, long cairo)
      Overrides:
      gtk_draw in class Composite
    • gtk4_draw

      void gtk4_draw(long widget, long cairo, Rectangle bounds)
      Overrides:
      gtk4_draw in class Control
    • drawCaretInFocus

      void drawCaretInFocus(long widget, long cairo)
    • drawCaret

      private void drawCaret(long widget, long cairo)
    • gtk_focus_in_event

      long gtk_focus_in_event(long widget, long event)
      Overrides:
      gtk_focus_in_event in class Composite
    • gtk_focus_out_event

      long gtk_focus_out_event(long widget, long event)
      Overrides:
      gtk_focus_out_event in class Composite
    • gtk4_focus_enter_event

      void gtk4_focus_enter_event(long handle, long event)
      Overrides:
      gtk4_focus_enter_event in class Control
      Parameters:
      handle - the corresponding controller responsible for capturing the event
      event - the GdkEvent captured
    • gtk4_focus_leave_event

      void gtk4_focus_leave_event(long handle, long event)
      Overrides:
      gtk4_focus_leave_event in class Control
      Parameters:
      handle - the corresponding controller responsible for capturing the event
      event - the GdkEvent captured
    • gtk_preedit_changed

      long gtk_preedit_changed(long imcontext)
      Overrides:
      gtk_preedit_changed in class Control
    • redrawWidget

      void redrawWidget(int x, int y, int width, int height, boolean redrawAll, boolean all, boolean trim)
      Overrides:
      redrawWidget in class Scrollable
    • releaseChildren

      void releaseChildren(boolean destroy)
      Overrides:
      releaseChildren in class Composite
    • reskinChildren

      void reskinChildren(int flags)
      Overrides:
      reskinChildren in class Composite
    • scroll

      public void scroll(int destX, int destY, int x, int y, int width, int height, boolean all)
      Scrolls a rectangular area of the receiver by first copying the source area to the destination and then causing the area of the source which is not covered by the destination to be repainted. Children that intersect the rectangle are optionally moved during the operation. In addition, all outstanding paint events are flushed before the source area is copied to ensure that the contents of the canvas are drawn correctly.
      Parameters:
      destX - the x coordinate of the destination
      destY - the y coordinate of the destination
      x - the x coordinate of the source
      y - the y coordinate of the source
      width - the width of the area
      height - the height of the area
      all - trueif children should be scrolled, and false otherwise
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • setBounds

      int setBounds(int x, int y, int width, int height, boolean move, boolean resize)
      Overrides:
      setBounds in class Composite
    • setCaret

      public void setCaret(Caret caret)
      Sets the receiver's caret.

      The caret for the control is automatically hidden and shown when the control is painted or resized, when focus is gained or lost and when an the control is scrolled. To avoid drawing on top of the caret, the programmer must hide and show the caret when drawing in the window any other time.

      Parameters:
      caret - the new caret for the receiver, may be null
      Throws:
      IllegalArgumentException -
      • ERROR_INVALID_ARGUMENT - if the caret has been disposed
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • setFont

      public void setFont(Font font)
      Description copied from class: Control
      Sets the font that the receiver will use to paint textual information to the font specified by the argument, or to the default font for that kind of control if the argument is null.
      Overrides:
      setFont in class Control
      Parameters:
      font - the new font (or null)
    • setIME

      public void setIME(IME ime)
      Sets the receiver's IME.
      Parameters:
      ime - the new IME for the receiver, may be null
      Throws:
      IllegalArgumentException -
      • ERROR_INVALID_ARGUMENT - if the IME has been disposed
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      Since:
      3.4
    • updateCaret

      void updateCaret()