Esempio n. 1
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];
  }
Esempio n. 2
0
 /**
  * Sets the control that is used to fill the bounds of the item when the item is a <code>SEPARATOR
  * </code>.
  *
  * @param control the new control
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_INVALID_ARGUMENT - if the control has been disposed
  *       <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree
  *     </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 setControl(Control control) {
   checkWidget();
   if (control != null) {
     if (control.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
     if (control.parent != parent) error(SWT.ERROR_INVALID_PARENT);
   }
   if ((style & SWT.SEPARATOR) == 0) return;
   if (this.control == control) return;
   this.control = control;
   int[] argList = {
     OS.XmNseparatorType,
     control == null
         ? ((parent.style & SWT.FLAT) != 0 ? OS.XmSHADOW_ETCHED_IN : OS.XmSHADOW_ETCHED_OUT)
         : OS.XmNO_LINE,
   };
   OS.XtSetValues(handle, argList, argList.length / 2);
   if (control != null && !control.isDisposed()) {
     /*
      * It is possible that the control was created with a
      * z-order below that of the current tool item. In this
      * case, the control is not visible because it is
      * obscured by the tool item. The fix is to move the
      * control above this tool item in the z-order.
      * The code below is similar to the code found in
      * setZOrder.
      */
     int xDisplay = OS.XtDisplay(handle);
     if (xDisplay == 0) return;
     if (!OS.XtIsRealized(handle)) {
       Shell shell = parent.getShell();
       shell.realizeWidget();
     }
     int topHandle1 = control.topHandle();
     int window1 = OS.XtWindow(topHandle1);
     if (window1 == 0) return;
     int topHandle2 = this.topHandle();
     int window2 = OS.XtWindow(topHandle2);
     if (window2 == 0) return;
     XWindowChanges struct = new XWindowChanges();
     struct.sibling = window2;
     struct.stack_mode = OS.Above;
     int screen = OS.XDefaultScreen(xDisplay);
     int flags = OS.CWStackMode | OS.CWSibling;
     OS.XReconfigureWMWindow(xDisplay, window1, screen, flags, struct);
   }
   parent.relayout();
 }
Esempio n. 3
0
 void setDrawPressed(boolean value) {
   int shadowType = value ? OS.XmSHADOW_IN : OS.XmSHADOW_OUT;
   int[] argList = {OS.XmNshadowType, shadowType};
   OS.XtSetValues(handle, argList, argList.length / 2);
 }
Esempio n. 4
0
 void setForegroundPixel(int pixel) {
   int[] argList = {OS.XmNforeground, pixel};
   OS.XtSetValues(handle, argList, argList.length / 2);
 }
Esempio n. 5
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();
   int[] argList = {OS.XmNsensitive, enabled ? 1 : 0};
   OS.XtSetValues(handle, argList, argList.length / 2);
 }
Esempio n. 6
0
 void setBackgroundPixel(int pixel) {
   int[] argList = {OS.XmNforeground, 0, OS.XmNhighlightColor, 0};
   OS.XtGetValues(handle, argList, argList.length / 2);
   OS.XmChangeColor(handle, pixel);
   OS.XtSetValues(handle, argList, argList.length / 2);
 }
Esempio n. 7
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;
  }