Exemple #1
0
  /** Creates the "Example" widgets. */
  void createExampleWidgets() {

    /* Compute the widget style */
    int style = getDefaultStyle();
    if (horizontalButton.getSelection()) style |= SWT.H_SCROLL;
    if (verticalButton.getSelection()) style |= SWT.V_SCROLL;
    if (borderButton.getSelection()) style |= SWT.BORDER;
    if (noBackgroundButton.getSelection()) style |= SWT.NO_BACKGROUND;
    if (noFocusButton.getSelection()) style |= SWT.NO_FOCUS;
    if (noMergePaintsButton.getSelection()) style |= SWT.NO_MERGE_PAINTS;
    if (noRedrawResizeButton.getSelection()) style |= SWT.NO_REDRAW_RESIZE;

    /* Create the example widgets */
    paintCount = 0;
    cx = 0;
    cy = 0;
    canvas = new Canvas(canvasGroup, style);
    canvas.addPaintListener(
        new PaintListener() {
          public void paintControl(PaintEvent e) {
            paintCount++;
            GC gc = e.gc;
            if (fillDamageButton.getSelection()) {
              Color color = e.display.getSystemColor(colors[paintCount % colors.length]);
              gc.setBackground(color);
              gc.fillRectangle(e.x, e.y, e.width, e.height);
            }
            Point size = canvas.getSize();
            gc.drawArc(cx + 1, cy + 1, size.x - 2, size.y - 2, 0, 360);
            gc.drawRectangle(cx + (size.x - 10) / 2, cy + (size.y - 10) / 2, 10, 10);
          }
        });
    canvas.addControlListener(
        new ControlAdapter() {
          public void controlResized(ControlEvent event) {
            Point size = canvas.getSize();
            maxX = size.x * 3 / 2;
            maxY = size.y * 3 / 2;
            resizeScrollBars();
          }
        });
    ScrollBar bar = canvas.getHorizontalBar();
    if (bar != null) {
      bar.addSelectionListener(
          new SelectionAdapter() {
            public void widgetSelected(SelectionEvent event) {
              scrollHorizontal((ScrollBar) event.widget);
            }
          });
    }
    bar = canvas.getVerticalBar();
    if (bar != null) {
      bar.addSelectionListener(
          new SelectionAdapter() {
            public void widgetSelected(SelectionEvent event) {
              scrollVertical((ScrollBar) event.widget);
            }
          });
    }
  }
Exemple #2
0
 void propagateWidget(boolean enabled) {
   super.propagateWidget(enabled);
   if (formHandle != 0) propagateHandle(enabled, formHandle, OS.None);
   if (scrolledHandle != 0) {
     propagateHandle(enabled, scrolledHandle, OS.None);
     if (horizontalBar != null) horizontalBar.propagateWidget(enabled);
     if (verticalBar != null) verticalBar.propagateWidget(enabled);
   }
 }
Exemple #3
0
 void releaseChildren(boolean destroy) {
   if (horizontalBar != null) {
     horizontalBar.release(false);
     horizontalBar = null;
   }
   if (verticalBar != null) {
     verticalBar.release(false);
     verticalBar = null;
   }
   super.releaseChildren(destroy);
 }
  /**
   * Installs this highlighter into the specified StyledText object. Client can manually call
   * detach() method, then wants to destroy this object.
   */
  public void attach(StyledText parent) {
    detach();

    text = parent;
    text.addDisposeListener(ml);
    text.addLineStyleListener(ml);
    text.addLineBackgroundListener(ml);
    text.addPaintListener(ml);
    text.addVerifyListener(ml);
    text.addExtendedModifyListener(ml);
    text.addControlListener(ml);
    text.addKeyListener(ml);
    text.addTraverseListener(ml);
    text.addMouseListener(ml);
    text.addSelectionListener(ml);
    text.getContent().addTextChangeListener(ml);
    ScrollBar sb = text.getVerticalBar();
    if (sb != null) sb.addSelectionListener(ml);
    updateViewport();

    new Thread() {
      public void run() {
        // setPriority(Thread.NORM_PRIORITY-1);
        while (true) {
          try {
            sleep(300);
          } catch (InterruptedException e) {
          }
          if (baseEditor == null || text == null) break;
          if (backParserDelay) {
            backParserDelay = false;
            try {
              sleep(1500);
            } catch (InterruptedException e) {
            }
            continue;
          }
          ;
          Display.getDefault()
              .syncExec(
                  new Runnable() {
                    public void run() {
                      if (baseEditor == null || text == null) return;
                      if (text.isDisposed()) return;
                      // System.out.println(System.currentTimeMillis());
                      baseEditor.idleJob(80);
                      // redrawFrom(text.getLineAtOffset(text.getCaretOffset()));
                    }
                  });
        }
        ;
      };
    }.start();
  }
Exemple #5
0
 void redrawWidget(
     int x, int y, int width, int height, boolean redrawAll, boolean allChildren, boolean trim) {
   super.redrawWidget(x, y, width, height, redrawAll, allChildren, trim);
   if (!trim) return;
   if (formHandle == 0 && scrolledHandle == 0) return;
   short[] root_x = new short[1], root_y = new short[1];
   OS.XtTranslateCoords(handle, (short) x, (short) y, root_x, root_y);
   if (formHandle != 0) {
     short[] form_x = new short[1], form_y = new short[1];
     OS.XtTranslateCoords(formHandle, (short) 0, (short) 0, form_x, form_y);
     redrawHandle(
         root_x[0] - form_x[0], root_y[0] - form_y[0], width, height, redrawAll, formHandle);
   }
   if (scrolledHandle != 0) {
     short[] scrolled_x = new short[1], scrolled_y = new short[1];
     OS.XtTranslateCoords(scrolledHandle, (short) 0, (short) 0, scrolled_x, scrolled_y);
     redrawHandle(
         root_x[0] - scrolled_x[0],
         root_y[0] - scrolled_y[0],
         width,
         height,
         redrawAll,
         scrolledHandle);
     if (horizontalBar != null && horizontalBar.getVisible()) {
       int horizontalHandle = horizontalBar.handle;
       short[] hscroll_x = new short[1], hscroll_y = new short[1];
       OS.XtTranslateCoords(horizontalHandle, (short) 0, (short) 0, hscroll_x, hscroll_y);
       redrawHandle(
           root_x[0] - hscroll_x[0],
           root_y[0] - hscroll_y[0],
           width,
           height,
           redrawAll,
           horizontalHandle);
     }
     if (verticalBar != null && verticalBar.getVisible()) {
       int verticalHandle = verticalBar.handle;
       short[] vscroll_x = new short[1], vscroll_y = new short[1];
       OS.XtTranslateCoords(verticalHandle, (short) 0, (short) 0, vscroll_x, vscroll_y);
       redrawHandle(
           root_x[0] - vscroll_x[0],
           root_y[0] - vscroll_y[0],
           width,
           height,
           redrawAll,
           verticalHandle);
     }
   }
 }
 /**
  * Removes this object from the corresponding StyledText widget. Object can't be used after this
  * call, until another attach. This method is called automatically, when StyledText widget is
  * disposed
  */
 public void detach() {
   if (text == null) return;
   text.removeDisposeListener(ml);
   text.removeLineStyleListener(ml);
   text.removeLineBackgroundListener(ml);
   text.removePaintListener(ml);
   text.removeVerifyListener(ml);
   text.removeExtendedModifyListener(ml);
   text.removeControlListener(ml);
   text.removeKeyListener(ml);
   text.removeTraverseListener(ml);
   text.removeMouseListener(ml);
   text.removeSelectionListener(ml);
   ScrollBar sb = text.getVerticalBar();
   if (sb != null) sb.removeSelectionListener(ml);
   baseEditor = null;
 }
  void onDispose(Event event) {
    removeListener(SWT.Dispose, listener);
    notifyListeners(SWT.Dispose, event);
    event.type = SWT.None;

    table.removeListener(SWT.FocusIn, tableListener);
    table.removeListener(SWT.MouseDown, tableListener);
    unhookRowColumnListeners();
    ScrollBar hBar = table.getHorizontalBar();
    if (hBar != null) {
      hBar.removeListener(SWT.Selection, resizeListener);
    }
    ScrollBar vBar = table.getVerticalBar();
    if (vBar != null) {
      vBar.removeListener(SWT.Selection, resizeListener);
    }
  }
Exemple #8
0
 /**
  * Scrolls the canvas vertically.
  *
  * @param scrollBar
  */
 void scrollVertical(ScrollBar scrollBar) {
   Rectangle bounds = canvas.getClientArea();
   int y = -scrollBar.getSelection();
   if (y + maxY < bounds.height) {
     y = bounds.height - maxY;
   }
   canvas.scroll(cx, y, cx, cy, maxX, maxY, false);
   cy = y;
 }
Exemple #9
0
 /**
  * Scrolls the canvas horizontally.
  *
  * @param scrollBar
  */
 void scrollHorizontal(ScrollBar scrollBar) {
   Rectangle bounds = canvas.getClientArea();
   int x = -scrollBar.getSelection();
   if (x + maxX < bounds.width) {
     x = bounds.width - maxX;
   }
   canvas.scroll(x, cy, cx, cy, maxX, maxY, false);
   cx = x;
 }
Exemple #10
0
  boolean setScrollBarVisible(ScrollBar bar, boolean visible) {
    if (scrolledHandle == 0) return false;
    int barHandle = bar.handle;
    boolean managed = OS.XtIsManaged(barHandle);
    if (managed == visible) return false;

    /*
     * Feature in Motif.  Hiding or showing a scroll bar
     * can cause the widget to automatically resize in
     * the OS.  This behavior is unwanted.  The fix is
     * to force the widget to resize to original size.
     */
    int[] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
    OS.XtGetValues(scrolledHandle, argList, argList.length / 2);

    int[] argList1 = {OS.XmNwidth, 0, OS.XmNheight, 0};
    OS.XtGetValues(handle, argList1, argList1.length / 2);

    /* Hide or show the scroll bar */
    if (visible) {
      OS.XtManageChild(barHandle);
    } else {
      OS.XtUnmanageChild(barHandle);
    }
    if ((state & CANVAS) != 0) {
      if (formHandle != 0) {
        boolean showBorder = (style & SWT.BORDER) != 0;
        int margin = showBorder || visible ? 3 : 0;
        if ((bar.style & SWT.V_SCROLL) != 0) {
          int[] argList2 = new int[] {OS.XmNmarginWidth, margin};
          OS.XtSetValues(formHandle, argList2, argList2.length / 2);
        }
        if ((bar.style & SWT.H_SCROLL) != 0) {
          int[] argList2 = new int[] {OS.XmNmarginHeight, margin};
          OS.XtSetValues(formHandle, argList2, argList2.length / 2);
        }
      }
    }

    /*
     * Feature in Motif.  When XtSetValues() is used to restore the width and
     * height of the widget, the new width and height are sometimes ignored.
     * The fix is to use XtResizeWidget().
     */
    OS.XtResizeWidget(scrolledHandle, argList[1], argList[3], argList[5]);

    bar.sendEvent(visible ? SWT.Show : SWT.Hide);
    int[] argList3 = {OS.XmNwidth, 0, OS.XmNheight, 0};
    OS.XtGetValues(handle, argList3, argList3.length / 2);
    return argList1[1] != argList3[1] || argList1[3] != argList3[3];
  }
Exemple #11
0
 ScrollBar createStandardBar(int style) {
   if (scrolledHandle == 0) return null;
   ScrollBar bar = new ScrollBar();
   bar.parent = this;
   bar.style = style;
   bar.display = display;
   int[] argList = {OS.XmNhorizontalScrollBar, 0, OS.XmNverticalScrollBar, 0};
   OS.XtGetValues(scrolledHandle, argList, argList.length / 2);
   if (style == SWT.H_SCROLL) bar.handle = argList[1];
   if (style == SWT.V_SCROLL) bar.handle = argList[3];
   bar.hookEvents();
   bar.register();
   return bar;
 }
Exemple #12
0
 /** Resizes the maximum and thumb of both scrollbars. */
 void resizeScrollBars() {
   Rectangle clientArea = canvas.getClientArea();
   ScrollBar bar = canvas.getHorizontalBar();
   if (bar != null) {
     bar.setMaximum(maxX);
     bar.setThumb(clientArea.width);
     bar.setPageIncrement(clientArea.width);
   }
   bar = canvas.getVerticalBar();
   if (bar != null) {
     bar.setMaximum(maxY);
     bar.setThumb(clientArea.height);
     bar.setPageIncrement(clientArea.height);
   }
 }
Exemple #13
0
 void reskinChildren(int flags) {
   if (horizontalBar != null) horizontalBar.reskin(flags);
   if (verticalBar != null) verticalBar.reskin(flags);
   super.reskinChildren(flags);
 }
Exemple #14
0
 void destroyScrollBar(ScrollBar bar) {
   setScrollBarVisible(bar, false);
   if ((state & CANVAS) != 0) bar.destroyHandle();
 }
  /**
   * Constructs a new instance of this class given its parent table and a style value describing its
   * behavior and appearance.
   *
   * <p>The style value is either one of the style constants defined in class <code>SWT</code> which
   * is applicable to instances of this class, or must be built by <em>bitwise OR</em>'ing together
   * (that is, using the <code>int</code> "|" operator) two or more of those <code>SWT</code> style
   * constants. The class description lists the style constants that are applicable to the class.
   * Style bits are also inherited from superclasses.
   *
   * @param parent a Table control which will be the parent of the new instance (cannot be null)
   * @param style the style of control to construct
   * @exception IllegalArgumentException
   *     <ul>
   *       <li>ERROR_NULL_ARGUMENT - if the parent is null
   *     </ul>
   *
   * @exception SWTException
   *     <ul>
   *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
   *       <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass
   *     </ul>
   *
   * @see SWT#BORDER
   * @see Widget#checkSubclass()
   * @see Widget#getStyle()
   */
  public TableCursor(Table parent, int style) {
    super(parent, style);
    table = parent;
    setBackground(null);
    setForeground(null);

    listener =
        event -> {
          switch (event.type) {
            case SWT.Dispose:
              onDispose(event);
              break;
            case SWT.FocusIn:
            case SWT.FocusOut:
              redraw();
              break;
            case SWT.KeyDown:
              keyDown(event);
              break;
            case SWT.Paint:
              paint(event);
              break;
            case SWT.Traverse:
              {
                event.doit = true;
                switch (event.detail) {
                  case SWT.TRAVERSE_ARROW_NEXT:
                  case SWT.TRAVERSE_ARROW_PREVIOUS:
                  case SWT.TRAVERSE_RETURN:
                    event.doit = false;
                    break;
                }
                break;
              }
          }
        };
    int[] events =
        new int[] {SWT.Dispose, SWT.FocusIn, SWT.FocusOut, SWT.KeyDown, SWT.Paint, SWT.Traverse};
    for (int i = 0; i < events.length; i++) {
      addListener(events[i], listener);
    }

    tableListener =
        event -> {
          switch (event.type) {
            case SWT.MouseDown:
              tableMouseDown(event);
              break;
            case SWT.FocusIn:
              tableFocusIn(event);
              break;
          }
        };
    table.addListener(SWT.FocusIn, tableListener);
    table.addListener(SWT.MouseDown, tableListener);

    disposeItemListener =
        event -> {
          unhookRowColumnListeners();
          row = null;
          column = null;
          _resize();
        };
    disposeColumnListener =
        event -> {
          unhookRowColumnListeners();
          row = null;
          column = null;
          _resize();
        };
    resizeListener = event -> _resize();
    ScrollBar hBar = table.getHorizontalBar();
    if (hBar != null) {
      hBar.addListener(SWT.Selection, resizeListener);
    }
    ScrollBar vBar = table.getVerticalBar();
    if (vBar != null) {
      vBar.addListener(SWT.Selection, resizeListener);
    }

    getAccessible()
        .addAccessibleControlListener(
            new AccessibleControlAdapter() {
              @Override
              public void getRole(AccessibleControlEvent e) {
                e.detail = ACC.ROLE_TABLECELL;
              }
            });
    getAccessible()
        .addAccessibleListener(
            new AccessibleAdapter() {
              @Override
              public void getName(AccessibleEvent e) {
                if (row == null) return;
                int columnIndex = column == null ? 0 : table.indexOf(column);
                e.result = row.getText(columnIndex);
              }
            });
  }