Beispiel #1
0
 private void setHoverLocation(
     org.eclipse.swt.widgets.Shell shell, org.eclipse.swt.graphics.Point position) {
   org.eclipse.swt.graphics.Rectangle displayBounds = shell.getDisplay().getBounds();
   org.eclipse.swt.graphics.Rectangle shellBounds = shell.getBounds();
   shellBounds.x = Math.max(Math.min(position.x, displayBounds.width - shellBounds.width), 0);
   shellBounds.y =
       Math.max(Math.min(position.y + 16, displayBounds.height - shellBounds.height), 0);
   shell.setBounds(shellBounds);
 }
Beispiel #2
0
 int XPointerMotion(int w, int client_data, int call_data, int continue_to_dispatch) {
   int result = super.XPointerMotion(w, client_data, call_data, continue_to_dispatch);
   if (result != 0) return result;
   XMotionEvent xEvent = new XMotionEvent();
   OS.memmove(xEvent, call_data, XMotionEvent.sizeof);
   if (!dragging || (xEvent.state & OS.Button1Mask) == 0) return result;
   short[] x_root = new short[1], y_root = new short[1];
   OS.XtTranslateCoords(handle, (short) 0, (short) 0, x_root, y_root);
   int eventX = xEvent.x_root - x_root[0], eventY = xEvent.y_root - y_root[0];
   int[] argList1 = {
     OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0
   };
   OS.XtGetValues(handle, argList1, argList1.length / 2);
   int border = argList1[9],
       x = ((short) argList1[1]) - border,
       y = ((short) argList1[3]) - border;
   int width = argList1[5] + (border * 2), height = argList1[7] + (border * 2);
   int[] argList2 = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
   OS.XtGetValues(parent.handle, argList2, argList2.length / 2);
   int parentBorder = argList2[5];
   int parentWidth = argList2[1] + (parentBorder * 2);
   int parentHeight = argList2[3] + (parentBorder * 2);
   int newX = lastX, newY = lastY;
   if ((style & SWT.VERTICAL) != 0) {
     newX = Math.min(Math.max(0, eventX + x - startX - parentBorder), parentWidth - width);
   } else {
     newY = Math.min(Math.max(0, eventY + y - startY - parentBorder), parentHeight - height);
   }
   if (newX == lastX && newY == lastY) return result;
   drawBand(lastX, lastY, width, height);
   Event event = new Event();
   event.time = xEvent.time;
   event.x = newX;
   event.y = newY;
   event.width = width;
   event.height = height;
   if ((style & SWT.SMOOTH) == 0) {
     event.detail = SWT.DRAG;
   }
   sendEvent(SWT.Selection, event);
   if (isDisposed()) return result;
   if (event.doit) {
     lastX = event.x;
     lastY = event.y;
   }
   parent.update(true);
   drawBand(lastX, lastY, width, height);
   if ((style & SWT.SMOOTH) != 0) {
     setBounds(lastX, lastY, width, height);
     // widget could be disposed at this point
   }
   return result;
 }
Beispiel #3
0
 /**
  * Sets the size of the receiver's thumb relative to the difference between its maximum and
  * minimum values. This new value will be ignored if it is less than one, and will be clamped if
  * it exceeds the receiver's current range.
  *
  * @param value the new thumb value, which must be at least one and not larger than the size of
  *     the current range
  * @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 setThumb(int value) {
   checkWidget();
   if (value < 1) return;
   value = Math.min(value, maximum - minimum);
   this.thumb = value;
   updateBar(getSelection(), minimum, maximum, value);
 }
Beispiel #4
0
 void updateBar(int selection, int minimum, int maximum, int thumb) {
   NSScroller widget = (NSScroller) view;
   selection = Math.max(minimum, Math.min(maximum - thumb, selection));
   float fraction =
       minimum == maximum ? 1 : (float) (selection - minimum) / (maximum - thumb - minimum);
   float knob = minimum == maximum ? 1 : (float) (thumb - minimum) / (maximum - minimum);
   widget.setFloatValue(fraction, knob);
 }
Beispiel #5
0
 /**
  * Sets the minimum value. If this value is negative or greater than or equal to the maximum, the
  * value is ignored. If necessary, first the thumb and then the selection are adjusted to fit
  * within the new range.
  *
  * @param value the new minimum
  * @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 setMinimum(int value) {
   checkWidget();
   if (value < 0) return;
   if (value >= maximum) return;
   if (maximum - value < thumb) {
     thumb = maximum - value;
   }
   int selection = Math.min(maximum - thumb, Math.max(getSelection(), value));
   this.minimum = value;
   updateBar(selection, value, maximum, thumb);
 }
Beispiel #6
0
 /**
  * Sets the maximum. If this value is negative or less than or equal to the minimum, the value is
  * ignored. If necessary, first the thumb and then the selection are adjusted to fit within the
  * new range.
  *
  * @param value the new maximum, which must be greater than the current minimum
  * @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 setMaximum(int value) {
   checkWidget();
   if (value < 0) return;
   if (value <= minimum) return;
   if (value - minimum < thumb) {
     thumb = value - minimum;
   }
   int selection = Math.max(minimum, Math.min(getSelection(), value - thumb));
   this.maximum = value;
   updateBar(selection, minimum, value, thumb);
 }
 public void show(int effect, int x, int y) {
   effect = checkEffect(effect);
   int handle = table.handle;
   Point coordinates = new Point(x, y);
   coordinates = table.toControl(coordinates);
   LVHITTESTINFO pinfo = new LVHITTESTINFO();
   pinfo.x = coordinates.x;
   pinfo.y = coordinates.y;
   OS.SendMessage(handle, OS.LVM_HITTEST, 0, pinfo);
   if ((effect & DND.FEEDBACK_SCROLL) == 0) {
     scrollBeginTime = 0;
     scrollIndex = -1;
   } else {
     if (pinfo.iItem != -1 && scrollIndex == pinfo.iItem && scrollBeginTime != 0) {
       if (System.currentTimeMillis() >= scrollBeginTime) {
         int top = Math.max(0, OS.SendMessage(handle, OS.LVM_GETTOPINDEX, 0, 0));
         int count = OS.SendMessage(handle, OS.LVM_GETITEMCOUNT, 0, 0);
         int index =
             (scrollIndex - 1 < top)
                 ? Math.max(0, scrollIndex - 1)
                 : Math.min(count - 1, scrollIndex + 1);
         OS.SendMessage(handle, OS.LVM_ENSUREVISIBLE, index, 0);
         scrollBeginTime = 0;
         scrollIndex = -1;
       }
     } else {
       scrollBeginTime = System.currentTimeMillis() + SCROLL_HYSTERESIS;
       scrollIndex = pinfo.iItem;
     }
   }
   LVITEM lvItem = new LVITEM();
   lvItem.stateMask = OS.LVIS_DROPHILITED;
   OS.SendMessage(handle, OS.LVM_SETITEMSTATE, -1, lvItem);
   if (pinfo.iItem != -1 && (effect & DND.FEEDBACK_SELECT) != 0) {
     lvItem.state = OS.LVIS_DROPHILITED;
     OS.SendMessage(handle, OS.LVM_SETITEMSTATE, pinfo.iItem, lvItem);
   }
   // Insert mark only supported on Windows XP with manifest
   //	if (OS.COMCTL32_MAJOR >= 6) {
   //		if ((effect & DND.FEEDBACK_INSERT_BEFORE) != 0 || (effect & DND.FEEDBACK_INSERT_AFTER) != 0)
   // {
   //			LVINSERTMARK lvinsertmark = new LVINSERTMARK();
   //			lvinsertmark.cbSize = LVINSERTMARK.sizeof;
   //			lvinsertmark.dwFlags = (effect & DND.FEEDBACK_INSERT_BEFORE) != 0 ? 0 : OS.LVIM_AFTER;
   //			lvinsertmark.iItem = pinfo.iItem == -1 ? 0 : pinfo.iItem;
   //			int hItem = pinfo.iItem;
   //			OS.SendMessage (handle, OS.LVM_SETINSERTMARK, 0, lvinsertmark);
   //		} else {
   //			OS.SendMessage (handle, OS.LVM_SETINSERTMARK, 0, 0);
   //		}
   //	}
   return;
 }
Beispiel #8
0
 /**
  * Sets the receiver's selection, minimum value, maximum value, thumb, increment and page
  * increment all at once.
  *
  * <p>Note: This is similar to setting the values individually using the appropriate methods, but
  * may be implemented in a more efficient fashion on some platforms.
  *
  * @param selection the new selection value
  * @param minimum the new minimum value
  * @param maximum the new maximum value
  * @param thumb the new thumb value
  * @param increment the new increment value
  * @param pageIncrement the new pageIncrement value
  * @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 setValues(
     int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) {
   checkWidget();
   if (minimum < 0) return;
   if (maximum < 0) return;
   if (thumb < 1) return;
   if (increment < 1) return;
   if (pageIncrement < 1) return;
   thumb = Math.min(thumb, maximum - minimum);
   this.increment = increment;
   this.pageIncrement = pageIncrement;
   updateBar(selection, minimum, maximum, thumb);
 }
 void scrollInPixels(int destX, int destY, int x, int y, int width, int height, boolean all) {
   forceResize();
   boolean isFocus = caret != null && caret.isFocusCaret();
   if (isFocus) caret.killFocus();
   RECT sourceRect = new RECT();
   OS.SetRect(sourceRect, x, y, x + width, y + height);
   RECT clientRect = new RECT();
   OS.GetClientRect(handle, clientRect);
   if (OS.IntersectRect(clientRect, sourceRect, clientRect)) {
     if (OS.IsWinCE) {
       OS.UpdateWindow(handle);
     } else {
       int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN;
       OS.RedrawWindow(handle, null, 0, flags);
     }
   }
   int deltaX = destX - x, deltaY = destY - y;
   if (findImageControl() != null) {
     if (OS.IsWinCE) {
       OS.InvalidateRect(handle, sourceRect, true);
     } else {
       int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE;
       if (all) flags |= OS.RDW_ALLCHILDREN;
       OS.RedrawWindow(handle, sourceRect, 0, flags);
     }
     OS.OffsetRect(sourceRect, deltaX, deltaY);
     if (OS.IsWinCE) {
       OS.InvalidateRect(handle, sourceRect, true);
     } else {
       int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE;
       if (all) flags |= OS.RDW_ALLCHILDREN;
       OS.RedrawWindow(handle, sourceRect, 0, flags);
     }
   } else {
     int flags = OS.SW_INVALIDATE | OS.SW_ERASE;
     /*
      * Feature in Windows.  If any child in the widget tree partially
      * intersects the scrolling rectangle, Windows moves the child
      * and copies the bits that intersect the scrolling rectangle but
      * does not redraw the child.
      *
      * Feature in Windows.  When any child in the widget tree does not
      * intersect the scrolling rectangle but the parent does intersect,
      * Windows does not move the child.  This is the documented (but
      * strange) Windows behavior.
      *
      * The fix is to not use SW_SCROLLCHILDREN and move the children
      * explicitly after scrolling.
      */
     //		if (all) flags |= OS.SW_SCROLLCHILDREN;
     OS.ScrollWindowEx(handle, deltaX, deltaY, sourceRect, null, 0, null, flags);
   }
   if (all) {
     Control[] children = _getChildren();
     for (int i = 0; i < children.length; i++) {
       Control child = children[i];
       Rectangle rect = child.getBoundsInPixels();
       if (Math.min(x + width, rect.x + rect.width) >= Math.max(x, rect.x)
           && Math.min(y + height, rect.y + rect.height) >= Math.max(y, rect.y)) {
         child.setLocationInPixels(rect.x + deltaX, rect.y + deltaY);
       }
     }
   }
   if (isFocus) caret.setFocus();
 }
Beispiel #10
0
 Point computeSize(GC gc) {
   int width = 0, height = 0;
   if ((style & SWT.SEPARATOR) != 0) {
     if ((parent.style & SWT.HORIZONTAL) != 0) {
       width = getWidth();
       height = DEFAULT_HEIGHT;
     } else {
       width = DEFAULT_WIDTH;
       height = getWidth();
     }
     if (control != null) {
       height = Math.max(height, control.getMinimumHeight());
     }
     return new Point(width, height);
   }
   int[] argList = {
     OS.XmNmarginHeight, 0,
     OS.XmNmarginWidth, 0,
     OS.XmNshadowThickness, 0,
   };
   OS.XtGetValues(handle, argList, argList.length / 2);
   int marginHeight = argList[1], marginWidth = argList[3];
   int shadowThickness = argList[5];
   if ((parent.style & SWT.FLAT) != 0) {
     shadowThickness = Math.min(2, display.buttonShadowThickness);
   }
   if (text.length() != 0 || image != null) {
     int textWidth = 0, textHeight = 0;
     if (text.length() != 0) {
       int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB | SWT.DRAW_MNEMONIC;
       Point textExtent = gc.textExtent(text, flags);
       textWidth = textExtent.x;
       textHeight = textExtent.y;
     }
     int imageWidth = 0, imageHeight = 0;
     if (image != null) {
       Rectangle rect = image.getBounds();
       imageWidth = rect.width;
       imageHeight = rect.height;
     }
     if ((parent.style & SWT.RIGHT) != 0) {
       width = imageWidth + textWidth;
       height = Math.max(imageHeight, textHeight);
       if (imageWidth != 0 && textWidth != 0) width += 2;
     } else {
       height = imageHeight + textHeight;
       if (imageHeight != 0 && textHeight != 0) height += 2;
       width = Math.max(imageWidth, textWidth);
     }
   } else {
     width = DEFAULT_WIDTH;
     height = DEFAULT_HEIGHT;
   }
   if ((style & SWT.DROP_DOWN) != 0) {
     width += 12;
   }
   if (width != 0) {
     width += (marginWidth + shadowThickness) * 2 + 2;
   } else {
     width = DEFAULT_WIDTH;
   }
   if (height != 0) {
     height += (marginHeight + shadowThickness) * 2 + 2;
   } else {
     height = DEFAULT_HEIGHT;
   }
   return new Point(width, height);
 }
Beispiel #11
0
  int XmNexposureCallback(int w, int client_data, int call_data) {
    if ((style & SWT.SEPARATOR) != 0) return 0;
    int xDisplay = OS.XtDisplay(handle);
    if (xDisplay == 0) return 0;
    int xWindow = OS.XtWindow(handle);
    if (xWindow == 0) return 0;
    int[] argList = {
      OS.XmNcolormap, 0,
      OS.XmNwidth, 0,
      OS.XmNheight, 0,
    };
    OS.XtGetValues(handle, argList, argList.length / 2);
    int width = argList[3], height = argList[5];

    Image currentImage = image;
    boolean enabled = getEnabled();

    if ((parent.style & SWT.FLAT) != 0) {
      boolean hasCursor = hasCursor();

      /* Set the shadow thickness */
      int thickness = 0;
      if (set || (hasCursor && enabled)) {
        thickness = Math.min(2, display.buttonShadowThickness);
      }
      argList = new int[] {OS.XmNshadowThickness, thickness};
      OS.XtSetValues(handle, argList, argList.length / 2);

      /* Determine if hot image should be used */
      if (enabled && hasCursor && hotImage != null) {
        currentImage = hotImage;
      }
    }

    GCData data = new GCData();
    data.device = display;
    data.display = xDisplay;
    data.drawable = xWindow;
    data.font = parent.font;
    data.colormap = argList[1];
    int xGC = OS.XCreateGC(xDisplay, xWindow, 0, null);
    if (xGC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
    GC gc = GC.motif_new(xGC, data);

    XmAnyCallbackStruct cb = new XmAnyCallbackStruct();
    OS.memmove(cb, call_data, XmAnyCallbackStruct.sizeof);
    if (cb.event != 0) {
      XExposeEvent xEvent = new XExposeEvent();
      OS.memmove(xEvent, cb.event, XExposeEvent.sizeof);
      Rectangle rect = new Rectangle(xEvent.x, xEvent.y, xEvent.width, xEvent.height);
      gc.setClipping(rect);
    }

    if (!enabled) {
      currentImage = disabledImage;
      if (currentImage == null && image != null) {
        currentImage = new Image(display, image, SWT.IMAGE_DISABLE);
      }
      Color disabledColor = display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
      gc.setForeground(disabledColor);
    } else {
      gc.setForeground(parent.getForeground());
    }
    gc.setBackground(parent.getBackground());

    int textX = 0, textY = 0, textWidth = 0, textHeight = 0;
    if (text.length() != 0) {
      int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB | SWT.DRAW_MNEMONIC;
      Point textExtent = gc.textExtent(text, flags);
      textWidth = textExtent.x;
      textHeight = textExtent.y;
    }
    int imageX = 0, imageY = 0, imageWidth = 0, imageHeight = 0;
    if (currentImage != null) {
      Rectangle imageBounds = currentImage.getBounds();
      imageWidth = imageBounds.width;
      imageHeight = imageBounds.height;
    }

    int spacing = 0;
    if (textWidth != 0 && imageWidth != 0) spacing = 2;
    if ((parent.style & SWT.RIGHT) != 0) {
      imageX = (width - imageWidth - textWidth - spacing) / 2;
      imageY = (height - imageHeight) / 2;
      textX = spacing + imageX + imageWidth;
      textY = (height - textHeight) / 2;
    } else {
      imageX = (width - imageWidth) / 2;
      imageY = (height - imageHeight - textHeight - spacing) / 2;
      textX = (width - textWidth) / 2;
      textY = spacing + imageY + imageHeight;
    }

    if ((style & SWT.DROP_DOWN) != 0) {
      textX -= 6;
      imageX -= 6;
    }
    if (textWidth > 0) {
      int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB | SWT.DRAW_MNEMONIC | SWT.DRAW_TRANSPARENT;
      gc.drawText(text, textX, textY, flags);
    }
    if (imageWidth > 0) gc.drawImage(currentImage, imageX, imageY);
    if ((style & SWT.DROP_DOWN) != 0) {
      int startX = width - 12, startY = (height - 2) / 2;
      int[] arrow = {startX, startY, startX + 3, startY + 3, startX + 6, startY};
      gc.setBackground(parent.getForeground());
      gc.fillPolygon(arrow);
      gc.drawPolygon(arrow);
    }
    gc.dispose();
    OS.XFreeGC(xDisplay, xGC);

    if (!enabled && disabledImage == null) {
      if (currentImage != null) currentImage.dispose();
    }
    return 0;
  }
  void drawInteriorWithFrame_inView(
      long /*int*/ id, long /*int*/ sel, NSRect cellRect, long /*int*/ view) {
    /*
     * Feature in Cocoa.  When the last column in a tree does not reach the
     * rightmost edge of the tree view, the cell that draws the rightmost-
     * column's header is also invoked to draw the header space between its
     * right edge and the tree's right edge.  If this case is detected then
     * nothing should be drawn.
     */
    int columnIndex = parent.indexOf(nsColumn);
    NSRect headerRect = parent.headerView.headerRectOfColumn(columnIndex);
    if (headerRect.x != cellRect.x || headerRect.width != cellRect.width) return;

    NSGraphicsContext context = NSGraphicsContext.currentContext();
    context.saveGraphicsState();

    int contentWidth = 0;
    NSSize stringSize = null, imageSize = null;
    NSAttributedString attrString = null;
    NSTableHeaderCell headerCell = nsColumn.headerCell();
    if (displayText != null) {
      Font font = Font.cocoa_new(display, headerCell.font());
      attrString =
          parent.createString(
              displayText, font, null, SWT.LEFT, false, (parent.state & DISABLED) == 0, false);
      stringSize = attrString.size();
      contentWidth += Math.ceil(stringSize.width);
      if (image != null) contentWidth += MARGIN; /* space between image and text */
    }
    if (image != null) {
      imageSize = image.handle.size();
      contentWidth += Math.ceil(imageSize.width);
    }

    if (parent.sortColumn == this && parent.sortDirection != SWT.NONE) {
      boolean ascending = parent.sortDirection == SWT.UP;
      headerCell.drawSortIndicatorWithFrame(cellRect, new NSView(view), ascending, 0);
      /* remove the arrow's space from the available drawing width */
      NSRect sortRect = headerCell.sortIndicatorRectForBounds(cellRect);
      cellRect.width = Math.max(0, sortRect.x - cellRect.x);
    }

    int drawX = 0;
    if ((style & SWT.CENTER) != 0) {
      drawX = (int) (cellRect.x + Math.max(MARGIN, ((cellRect.width - contentWidth) / 2)));
    } else if ((style & SWT.RIGHT) != 0) {
      drawX = (int) (cellRect.x + Math.max(MARGIN, cellRect.width - contentWidth - MARGIN));
    } else {
      drawX = (int) cellRect.x + MARGIN;
    }

    if (image != null) {
      NSRect destRect = new NSRect();
      destRect.x = drawX;
      destRect.y = cellRect.y;
      destRect.width = Math.min(imageSize.width, cellRect.width - 2 * MARGIN);
      destRect.height = Math.min(imageSize.height, cellRect.height);
      boolean isFlipped = new NSView(view).isFlipped();
      if (isFlipped) {
        context.saveGraphicsState();
        NSAffineTransform transform = NSAffineTransform.transform();
        transform.scaleXBy(1, -1);
        transform.translateXBy(0, -(destRect.height + 2 * destRect.y));
        transform.concat();
      }
      NSRect sourceRect = new NSRect();
      sourceRect.width = destRect.width;
      sourceRect.height = destRect.height;
      image.handle.drawInRect(destRect, sourceRect, OS.NSCompositeSourceOver, 1f);
      if (isFlipped) context.restoreGraphicsState();
      drawX += destRect.width;
    }

    if (displayText != null && displayText.length() > 0) {
      if (image != null) drawX += MARGIN; /* space between image and text */
      NSRect destRect = new NSRect();
      destRect.x = drawX;
      destRect.y = cellRect.y;
      destRect.width = Math.min(stringSize.width, cellRect.x + cellRect.width - MARGIN - drawX);
      destRect.height = Math.min(stringSize.height, cellRect.height);
      attrString.drawInRect(destRect);
    }
    if (attrString != null) attrString.release();

    context.restoreGraphicsState();
  }
  public Shell open(Display display) {
    clipboard = new Clipboard(display);
    shell = new Shell(display);
    shell.setText("SWT Clipboard");
    shell.setLayout(new FillLayout());

    ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL);
    Composite parent = new Composite(sc, SWT.NONE);
    sc.setContent(parent);
    parent.setLayout(new GridLayout(2, true));

    Group copyGroup = new Group(parent, SWT.NONE);
    copyGroup.setText("Copy From:");
    GridData data = new GridData(GridData.FILL_BOTH);
    copyGroup.setLayoutData(data);
    copyGroup.setLayout(new GridLayout(3, false));

    Group pasteGroup = new Group(parent, SWT.NONE);
    pasteGroup.setText("Paste To:");
    data = new GridData(GridData.FILL_BOTH);
    pasteGroup.setLayoutData(data);
    pasteGroup.setLayout(new GridLayout(3, false));

    Group controlGroup = new Group(parent, SWT.NONE);
    controlGroup.setText("Control API:");
    data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 2;
    controlGroup.setLayoutData(data);
    controlGroup.setLayout(new GridLayout(5, false));

    Group typesGroup = new Group(parent, SWT.NONE);
    typesGroup.setText("Available Types");
    data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 2;
    typesGroup.setLayoutData(data);
    typesGroup.setLayout(new GridLayout(2, false));

    status = new Label(parent, SWT.BORDER);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    data.heightHint = 60;
    status.setLayoutData(data);

    createTextTransfer(copyGroup, pasteGroup);
    createRTFTransfer(copyGroup, pasteGroup);
    createHTMLTransfer(copyGroup, pasteGroup);
    createFileTransfer(copyGroup, pasteGroup);
    createMyTransfer(copyGroup, pasteGroup);
    createControlTransfer(controlGroup);
    createAvailableTypes(typesGroup);

    sc.setMinSize(parent.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);

    Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    Rectangle monitorArea = shell.getMonitor().getClientArea();
    shell.setSize(
        Math.min(size.x, monitorArea.width - 20), Math.min(size.y, monitorArea.height - 20));
    shell.open();
    return shell;
  }
Beispiel #14
0
  int XKeyPress(int w, int client_data, int call_data, int continue_to_dispatch) {
    int result = super.XKeyPress(w, client_data, call_data, continue_to_dispatch);
    if (result != 0) return result;
    XKeyEvent xEvent = new XKeyEvent();
    OS.memmove(xEvent, call_data, XKeyEvent.sizeof);
    byte[] buffer = new byte[1];
    int[] keysym = new int[1];
    OS.XLookupString(xEvent, buffer, buffer.length, keysym, null);

    switch (keysym[0]) {
      case OS.XK_Left:
      case OS.XK_Right:
      case OS.XK_Up:
      case OS.XK_Down:
        int xChange = 0, yChange = 0;
        int stepSize = PAGE_INCREMENT;
        if ((xEvent.state & OS.ControlMask) != 0) stepSize = INCREMENT;
        if ((style & SWT.VERTICAL) != 0) {
          if (keysym[0] == OS.XK_Up || keysym[0] == OS.XK_Down) break;
          xChange = keysym[0] == OS.XK_Left ? -stepSize : stepSize;
        } else {
          if (keysym[0] == OS.XK_Left || keysym[0] == OS.XK_Right) break;
          yChange = keysym[0] == OS.XK_Up ? -stepSize : stepSize;
        }

        int[] argList1 = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
        OS.XtGetValues(handle, argList1, argList1.length / 2);
        int border = argList1[5];
        int width = argList1[1] + (border * 2), height = argList1[3] + (border * 2);
        int[] argList2 = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
        OS.XtGetValues(parent.handle, argList2, argList2.length / 2);
        int parentBorder = argList2[5];
        int parentWidth = argList2[1] + (parentBorder * 2);
        int parentHeight = argList2[3] + (parentBorder * 2);
        int newX = lastX, newY = lastY;
        if ((style & SWT.VERTICAL) != 0) {
          newX =
              Math.min(Math.max(0, lastX + xChange - parentBorder - startX), parentWidth - width);
        } else {
          newY =
              Math.min(Math.max(0, lastY + yChange - parentBorder - startY), parentHeight - height);
        }
        if (newX == lastX && newY == lastY) return result;

        /* Ensure that the pointer image does not change */
        int xDisplay = display.xDisplay;
        int xWindow = OS.XtWindow(parent.handle);
        int ptrGrabResult =
            OS.XGrabPointer(
                xDisplay,
                xWindow,
                1,
                OS.None,
                OS.GrabModeAsync,
                OS.GrabModeAsync,
                OS.None,
                cursor,
                OS.CurrentTime);

        Event event = new Event();
        event.time = xEvent.time;
        event.x = newX;
        event.y = newY;
        event.width = width;
        event.height = height;
        sendEvent(SWT.Selection, event);
        if (ptrGrabResult == OS.GrabSuccess) OS.XUngrabPointer(xDisplay, OS.CurrentTime);
        if (isDisposed()) break;

        if (event.doit) {
          lastX = event.x;
          lastY = event.y;
          if ((style & SWT.SMOOTH) != 0) {
            setBounds(event.x, event.y, width, height);
            if (isDisposed()) break;
          }
          int cursorX = event.x, cursorY = event.y;
          if ((style & SWT.VERTICAL) != 0) {
            cursorY += height / 2;
          } else {
            cursorX += width / 2;
          }
          OS.XWarpPointer(xDisplay, OS.None, xWindow, 0, 0, 0, 0, cursorX, cursorY);
        }
        break;
    }

    return result;
  }
  Image getDragSourceImage(DragSourceEvent event) {
    if (dragSourceImage != null) dragSourceImage.dispose();
    dragSourceImage = null;

    Table table = (Table) control;
    if (OS.GTK_VERSION < OS.VERSION(2, 2, 0)) return null;
    // TEMPORARY CODE
    if (table.isListening(SWT.EraseItem) || table.isListening(SWT.PaintItem)) return null;
    /*
     * Bug in GTK.  gtk_tree_selection_get_selected_rows() segmentation faults
     * in versions smaller than 2.2.4 if the model is NULL.  The fix is
     * to give a valid pointer instead.
     */
    long /*int*/ handle = table.handle;
    long /*int*/ selection = OS.gtk_tree_view_get_selection(handle);
    long /*int*/[] model = OS.GTK_VERSION < OS.VERSION(2, 2, 4) ? new long /*int*/[1] : null;
    long /*int*/ list = OS.gtk_tree_selection_get_selected_rows(selection, model);
    if (list == 0) return null;
    int count = Math.min(10, OS.g_list_length(list));

    Display display = table.getDisplay();
    if (count == 1) {
      long /*int*/ path = OS.g_list_nth_data(list, 0);
      long /*int*/ pixmap = OS.gtk_tree_view_create_row_drag_icon(handle, path);
      dragSourceImage = Image.gtk_new(display, SWT.ICON, pixmap, 0);
    } else {
      int width = 0, height = 0;
      int[] w = new int[1], h = new int[1];
      int[] yy = new int[count], hh = new int[count];
      long /*int*/[] pixmaps = new long /*int*/[count];
      GdkRectangle rect = new GdkRectangle();
      for (int i = 0; i < count; i++) {
        long /*int*/ path = OS.g_list_nth_data(list, i);
        OS.gtk_tree_view_get_cell_area(handle, path, 0, rect);
        pixmaps[i] = OS.gtk_tree_view_create_row_drag_icon(handle, path);
        OS.gdk_drawable_get_size(pixmaps[i], w, h);
        width = Math.max(width, w[0]);
        height = rect.y + h[0] - yy[0];
        yy[i] = rect.y;
        hh[i] = h[0];
      }
      long /*int*/ source = OS.gdk_pixmap_new(OS.GDK_ROOT_PARENT(), width, height, -1);
      long /*int*/ gcSource = OS.gdk_gc_new(source);
      long /*int*/ mask = OS.gdk_pixmap_new(OS.GDK_ROOT_PARENT(), width, height, 1);
      long /*int*/ gcMask = OS.gdk_gc_new(mask);
      GdkColor color = new GdkColor();
      color.pixel = 0;
      OS.gdk_gc_set_foreground(gcMask, color);
      OS.gdk_draw_rectangle(mask, gcMask, 1, 0, 0, width, height);
      color.pixel = 1;
      OS.gdk_gc_set_foreground(gcMask, color);
      for (int i = 0; i < count; i++) {
        OS.gdk_draw_drawable(source, gcSource, pixmaps[i], 0, 0, 0, yy[i] - yy[0], -1, -1);
        OS.gdk_draw_rectangle(mask, gcMask, 1, 0, yy[i] - yy[0], width, hh[i]);
        OS.g_object_unref(pixmaps[i]);
      }
      OS.g_object_unref(gcSource);
      OS.g_object_unref(gcMask);
      dragSourceImage = Image.gtk_new(display, SWT.ICON, source, mask);
    }
    OS.g_list_free(list);

    return dragSourceImage;
  }
 /**
  * Sets the size of the shell to it's "packed" size, unless that makes it larger than the monitor
  * it is being displayed on, in which case just set the shell size to be slightly smaller than the
  * monitor.
  */
 static void setShellSize(ControlExample instance, Shell shell) {
   Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
   Rectangle monitorArea = shell.getMonitor().getClientArea();
   shell.setSize(Math.min(size.x, monitorArea.width), Math.min(size.y, monitorArea.height));
 }
 void keyDown(Event event) {
   if (row == null) return;
   switch (event.character) {
     case SWT.CR:
       notifyListeners(SWT.DefaultSelection, new Event());
       return;
   }
   int rowIndex = table.indexOf(row);
   int columnIndex = column == null ? 0 : table.indexOf(column);
   switch (event.keyCode) {
     case SWT.ARROW_UP:
       setRowColumn(Math.max(0, rowIndex - 1), columnIndex, true);
       break;
     case SWT.ARROW_DOWN:
       setRowColumn(Math.min(rowIndex + 1, table.getItemCount() - 1), columnIndex, true);
       break;
     case SWT.ARROW_LEFT:
     case SWT.ARROW_RIGHT:
       {
         int columnCount = table.getColumnCount();
         if (columnCount == 0) break;
         int[] order = table.getColumnOrder();
         int index = 0;
         while (index < order.length) {
           if (order[index] == columnIndex) break;
           index++;
         }
         if (index == order.length) index = 0;
         int leadKey = (getStyle() & SWT.RIGHT_TO_LEFT) != 0 ? SWT.ARROW_RIGHT : SWT.ARROW_LEFT;
         if (event.keyCode == leadKey) {
           setRowColumn(rowIndex, order[Math.max(0, index - 1)], true);
         } else {
           setRowColumn(rowIndex, order[Math.min(columnCount - 1, index + 1)], true);
         }
         break;
       }
     case SWT.HOME:
       setRowColumn(0, columnIndex, true);
       break;
     case SWT.END:
       {
         int i = table.getItemCount() - 1;
         setRowColumn(i, columnIndex, true);
         break;
       }
     case SWT.PAGE_UP:
       {
         int index = table.getTopIndex();
         if (index == rowIndex) {
           Rectangle rect = table.getClientArea();
           TableItem item = table.getItem(index);
           Rectangle itemRect = item.getBounds(0);
           rect.height -= itemRect.y;
           int height = table.getItemHeight();
           int page = Math.max(1, rect.height / height);
           index = Math.max(0, index - page + 1);
         }
         setRowColumn(index, columnIndex, true);
         break;
       }
     case SWT.PAGE_DOWN:
       {
         int index = table.getTopIndex();
         Rectangle rect = table.getClientArea();
         TableItem item = table.getItem(index);
         Rectangle itemRect = item.getBounds(0);
         rect.height -= itemRect.y;
         int height = table.getItemHeight();
         int page = Math.max(1, rect.height / height);
         int end = table.getItemCount() - 1;
         index = Math.min(end, index + page - 1);
         if (index == rowIndex) {
           index = Math.min(end, index + page - 1);
         }
         setRowColumn(index, columnIndex, true);
         break;
       }
   }
 }