private void updateBgColor() {
   Iterator iter = controls.iterator();
   while (iter.hasNext()) {
     Control control = (Control) iter.next();
     control.setBackground(bgColors[bgIndex]);
   }
 }
 private void updateBgImage() {
   Iterator iter = controls.iterator();
   while (iter.hasNext()) {
     Control control = (Control) iter.next();
     control.setBackgroundImage(showBgImage ? BG_PATTERN_IMAGE : null);
   }
 }
 private void updateFgColor() {
   Iterator iter = controls.iterator();
   while (iter.hasNext()) {
     Control control = (Control) iter.next();
     control.setForeground(fgColors[fgIndex]);
   }
 }
Example #4
0
 void computeSize(Control control, int wHint, int hHint, boolean flushCache) {
   if (cacheWidth != -1 && cacheHeight != -1) return;
   if (wHint == this.widthHint && hHint == this.heightHint) {
     if (defaultWidth == -1
         || defaultHeight == -1
         || wHint != defaultWhint
         || hHint != defaultHhint) {
       Point size = control.computeSize(wHint, hHint, flushCache);
       defaultWhint = wHint;
       defaultHhint = hHint;
       defaultWidth = size.x;
       defaultHeight = size.y;
     }
     cacheWidth = defaultWidth;
     cacheHeight = defaultHeight;
     return;
   }
   if (currentWidth == -1
       || currentHeight == -1
       || wHint != currentWhint
       || hHint != currentHhint) {
     Point size = control.computeSize(wHint, hHint, flushCache);
     currentWhint = wHint;
     currentHhint = hHint;
     currentWidth = size.x;
     currentHeight = size.y;
   }
   cacheWidth = currentWidth;
   cacheHeight = currentHeight;
 }
 private void updateVisible() {
   Iterator iter = controls.iterator();
   while (iter.hasNext()) {
     Control control = (Control) iter.next();
     control.setVisible(visible);
   }
 }
Example #6
0
 public static CellEditor createPropertyEditor(
     final IServiceLocator serviceLocator,
     Composite parent,
     DBPPropertySource source,
     DBPPropertyDescriptor property) {
   if (source == null) {
     return null;
   }
   final Object object = source.getEditableValue();
   if (!property.isEditable(object)) {
     return null;
   }
   CellEditor cellEditor = UIUtils.createCellEditor(parent, object, property);
   if (cellEditor != null) {
     final Control editorControl = cellEditor.getControl();
     UIUtils.addFocusTracker(serviceLocator, UIUtils.INLINE_WIDGET_EDITOR_ID, editorControl);
     editorControl.addDisposeListener(
         new DisposeListener() {
           @Override
           public void widgetDisposed(DisposeEvent e) {
             UIUtils.removeFocusTracker(serviceLocator, editorControl);
           }
         });
   }
   return cellEditor;
 }
Example #7
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 (control == null) {
     int property = OS.Control_BackgroundProperty();
     OS.DependencyObject_ClearValue(handle, property);
     OS.GCHandle_Free(property);
     Control oldControl = this.control;
     if (oldControl != null && !oldControl.isDisposed()) OS.Panel_SetZIndex(oldControl.handle, 0);
   } else {
     int brush = OS.Brushes_Transparent();
     OS.Control_Background(handle, brush);
     OS.GCHandle_Free(brush);
     int pt = OS.gcnew_Point(0, 0);
     if (pt == 0) error(SWT.ERROR_NO_HANDLES);
     int loc = OS.UIElement_TranslatePoint(handle, pt, parent.parentingHandle);
     OS.GCHandle_Free(pt);
     OS.Canvas_SetLeft(control.handle, OS.Point_X(loc));
     OS.Canvas_SetTop(control.handle, OS.Point_Y(loc));
     OS.Panel_SetZIndex(control.handle, parent.childCount);
     OS.GCHandle_Free(loc);
   }
   this.control = control;
 }
 void destroyItem(TabItem item) {
   int index = 0;
   int itemCount = getItemCount();
   while (index < itemCount) {
     if (items[index] == item) break;
     index++;
   }
   if (index == itemCount) error(SWT.ERROR_ITEM_NOT_REMOVED);
   int oldIndex = OS.gtk_notebook_get_current_page(handle);
   OS.g_signal_handlers_block_matched(handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE);
   OS.gtk_notebook_remove_page(handle, index);
   OS.g_signal_handlers_unblock_matched(handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE);
   System.arraycopy(items, index + 1, items, index, --itemCount - index);
   items[itemCount] = null;
   if (index == oldIndex) {
     int newIndex = OS.gtk_notebook_get_current_page(handle);
     if (newIndex != -1) {
       Control control = items[newIndex].getControl();
       if (control != null && !control.isDisposed()) {
         control.setBounds(getClientArea());
         control.setVisible(true);
       }
       Event event = new Event();
       event.item = items[newIndex];
       sendSelectionEvent(SWT.Selection, event, true);
       // the widget could be destroyed at this point
     }
   }
 }
Example #9
0
 void drawRectangles(Rectangle[] rects, boolean stippled) {
   int xDisplay = display.xDisplay;
   int color = OS.XWhitePixel(xDisplay, 0);
   int xWindow = OS.XDefaultRootWindow(xDisplay);
   if (parent != null) {
     xWindow = OS.XtWindow(parent.handle);
     if (xWindow == 0) return;
     int foreground = parent.getForegroundPixel();
     Control control = parent.findBackgroundControl();
     if (control == null) control = parent;
     int background = control.getBackgroundPixel();
     color = foreground ^ background;
   }
   int gc = OS.XCreateGC(xDisplay, xWindow, 0, null);
   OS.XSetForeground(xDisplay, gc, color);
   OS.XSetSubwindowMode(xDisplay, gc, OS.IncludeInferiors);
   OS.XSetFunction(xDisplay, gc, OS.GXxor);
   int stipplePixmap = 0;
   if (stippled) {
     byte[] bits = {-86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0};
     stipplePixmap = OS.XCreateBitmapFromData(xDisplay, xWindow, bits, 8, 8);
     OS.XSetStipple(xDisplay, gc, stipplePixmap);
     OS.XSetFillStyle(xDisplay, gc, OS.FillStippled);
     OS.XSetLineAttributes(xDisplay, gc, 3, OS.LineSolid, OS.CapButt, OS.JoinMiter);
   }
   for (int i = 0; i < rects.length; i++) {
     Rectangle rect = rects[i];
     OS.XDrawRectangle(xDisplay, xWindow, gc, rect.x, rect.y, rect.width, rect.height);
   }
   if (stippled) {
     OS.XFreePixmap(xDisplay, stipplePixmap);
   }
   OS.XFreeGC(xDisplay, gc);
 }
Example #10
0
 private void updateEnabled() {
   Iterator iter = controls.iterator();
   while (iter.hasNext()) {
     Control control = (Control) iter.next();
     control.setEnabled(enabled);
   }
 }
 Point minimumSize(int wHint, int hHint, boolean flushCache) {
   Control[] children = _getChildren();
   int width = 0, height = 0;
   for (int i = 0; i < children.length; i++) {
     Control child = children[i];
     int index = 0;
     int count = 0;
     long /*int*/ list = OS.gtk_container_get_children(handle);
     if (list != 0) {
       count = OS.g_list_length(list);
       OS.g_list_free(list);
     }
     while (index < count) {
       if (items[index].control == child) break;
       index++;
     }
     if (index == count) {
       Rectangle rect = child.getBounds();
       width = Math.max(width, rect.x + rect.width);
       height = Math.max(height, rect.y + rect.height);
     } else {
       Point size = child.computeSize(wHint, hHint, flushCache);
       width = Math.max(width, size.x);
       height = Math.max(height, size.y);
     }
   }
   return new Point(width, height);
 }
Example #12
0
 public static boolean isParent(Control parent, Control child) {
   for (Control c = child; c != null; c = c.getParent()) {
     if (c == parent) {
       return true;
     }
   }
   return false;
 }
Example #13
0
 protected void layout(Composite composite, boolean flushCache) {
   CTabFolder folder = (CTabFolder) composite;
   // resize content
   if (folder.selectedIndex != -1) {
     Control control = folder.items[folder.selectedIndex].getControl();
     if (control != null && !control.isDisposed()) {
       control.setBounds(folder.getClientArea());
     }
   }
 }
Example #14
0
 public static void enableWithChildren(Composite composite, boolean enable) {
   composite.setEnabled(enable);
   for (Control child : composite.getChildren()) {
     if (child instanceof Composite) {
       enableWithChildren((Composite) child, enable);
     } else {
       child.setEnabled(enable);
     }
   }
 }
 private void onDispose() {
   if (control == null) return;
   this.Release();
   if (controlListener != null) {
     control.removeListener(SWT.Dispose, controlListener);
     control.removeListener(SWT.DragDetect, controlListener);
   }
   controlListener = null;
   control.setData(DND.DRAG_SOURCE_KEY, null);
   control = null;
   transferAgents = null;
 }
Example #16
0
 private void updateFont() {
   Iterator iter = controls.iterator();
   while (iter.hasNext()) {
     Control control = (Control) iter.next();
     control.setFont(font);
   }
   // Force layout
   if (controls.size() > 0) {
     Composite parent = ((Control) controls.get(0)).getParent();
     parent.layout(true, true);
   }
 }
Example #17
0
 /**
  * Determine whether this control or any of it's child has focus
  *
  * @param control control to check
  * @return true if it has focus
  */
 public static boolean hasFocus(Control control) {
   Control focusControl = control.getDisplay().getFocusControl();
   if (focusControl == null) {
     return false;
   }
   for (Control fc = focusControl; fc != null; fc = fc.getParent()) {
     if (fc == control) {
       return true;
     }
   }
   return false;
 }
Example #18
0
 /**
  * Sets the control that is shown when the item is expanded.
  *
  * @param control the new control (or null)
  * @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 (this.control == control) return;
   this.control = control;
   if (control != null) {
     control.setVisible(expanded);
   }
   parent.layoutItems(0, true);
 }
 int setBounds(int x, int y, int width, int height, boolean move, boolean resize) {
   int result = super.setBounds(x, y, width, height, move, resize);
   if ((result & RESIZED) != 0) {
     int index = getSelectionIndex();
     if (index != -1) {
       TabItem item = items[index];
       Control control = item.control;
       if (control != null && !control.isDisposed()) {
         control.setBounds(getClientArea());
       }
     }
   }
   return result;
 }
Example #20
0
 private void updateRoundedBorder(
     final int width,
     final Color color,
     final int topLeft,
     final int topRight,
     final int bottomRight,
     final int bottomLeft) {
   Iterator iter = controls.iterator();
   while (iter.hasNext()) {
     Control control = (Control) iter.next();
     Object adapter = control.getAdapter(IWidgetGraphicsAdapter.class);
     IWidgetGraphicsAdapter gfxAdapter = (IWidgetGraphicsAdapter) adapter;
     gfxAdapter.setRoundedBorder(width, color, topLeft, topRight, bottomRight, bottomLeft);
   }
 }
Example #21
0
 void enableWidget(boolean enabled) {
   if (OS.COMCTL32_MAJOR >= 6) {
     LITEM item = new LITEM();
     item.mask = OS.LIF_ITEMINDEX | OS.LIF_STATE;
     item.stateMask = OS.LIS_ENABLED;
     item.state = enabled ? OS.LIS_ENABLED : 0;
     while (OS.SendMessage(handle, OS.LM_SETITEM, 0, item) != 0) {
       item.iLink++;
     }
   } else {
     TextStyle linkStyle = new TextStyle(null, enabled ? linkColor : disabledColor, null);
     linkStyle.underline = true;
     for (int i = 0; i < offsets.length; i++) {
       Point point = offsets[i];
       layout.setStyle(linkStyle, point.x, point.y);
     }
     redraw();
   }
   /*
    * Feature in Windows.  For some reason, setting
    * LIS_ENABLED state using LM_SETITEM causes the
    * SysLink to become enabled.  To be specific,
    * calling IsWindowEnabled() returns true.  The
    * fix is disable the SysLink after LM_SETITEM.
    */
   super.enableWidget(enabled);
 }
Example #22
0
 @Override
 void createWidget(int index) {
   super.createWidget(index);
   layout.setFont(getFont());
   text = "";
   initAccessible();
 }
Example #23
0
 void releaseHandle() {
   super.releaseHandle();
   if (textHandle != 0) OS.GCHandle_Free(textHandle);
   textHandle = 0;
   if (imageHandle != 0) OS.GCHandle_Free(imageHandle);
   imageHandle = 0;
 }
Example #24
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();
 }
Example #25
0
 void releaseWidget() {
   super.releaseWidget();
   if (cursor != 0) {
     int display = OS.XtDisplay(handle);
     if (display != 0) OS.XFreeCursor(display, cursor);
   }
   cursor = 0;
 }
 void setSelection(int index, boolean notify) {
   if (index < 0) return;
   int oldIndex = OS.gtk_notebook_get_current_page(handle);
   if (oldIndex == index) return;
   if (oldIndex != -1) {
     TabItem item = items[oldIndex];
     Control control = item.control;
     if (control != null && !control.isDisposed()) {
       control.setVisible(false);
     }
   }
   OS.g_signal_handlers_block_matched(handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE);
   OS.gtk_notebook_set_current_page(handle, index);
   OS.g_signal_handlers_unblock_matched(handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE);
   int newIndex = OS.gtk_notebook_get_current_page(handle);
   if (newIndex != -1) {
     TabItem item = items[newIndex];
     Control control = item.control;
     if (control != null && !control.isDisposed()) {
       control.setBounds(getClientArea());
       control.setVisible(true);
     }
     if (notify) {
       Event event = new Event();
       event.item = item;
       sendSelectionEvent(SWT.Selection, event, true);
     }
   }
 }
  /**
   * Creates a new <code>DragSource</code> to handle dragging from the specified <code>Control
   * </code>. Creating an instance of a DragSource may cause system resources to be allocated
   * depending on the platform. It is therefore mandatory that the DragSource instance be disposed
   * when no longer required.
   *
   * @param control the <code>Control</code> that the user clicks on to initiate the drag
   * @param style the bitwise OR'ing of allowed operations; this may be a combination of any of
   *     DND.DROP_NONE, DND.DROP_COPY, DND.DROP_MOVE, DND.DROP_LINK
   * @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>
   *
   * @exception SWTError
   *     <ul>
   *       <li>ERROR_CANNOT_INIT_DRAG - unable to initiate drag source; this will occur if more than
   *           one drag source is created for a control or if the operating system will not allow
   *           the creation of the drag source
   *     </ul>
   *     <p>NOTE: ERROR_CANNOT_INIT_DRAG should be an SWTException, since it is a recoverable error,
   *     but can not be changed due to backward compatibility.
   * @see Widget#dispose
   * @see DragSource#checkSubclass
   * @see DND#DROP_NONE
   * @see DND#DROP_COPY
   * @see DND#DROP_MOVE
   * @see DND#DROP_LINK
   */
  public DragSource(Control control, int style) {
    super(control, checkStyle(style));
    this.control = control;
    if (control.getData(DND.DRAG_SOURCE_KEY) != null) {
      DND.error(DND.ERROR_CANNOT_INIT_DRAG);
    }
    control.setData(DND.DRAG_SOURCE_KEY, this);
    createCOMInterfaces();
    this.AddRef();

    controlListener =
        new Listener() {
          public void handleEvent(Event event) {
            if (event.type == SWT.Dispose) {
              if (!DragSource.this.isDisposed()) {
                DragSource.this.dispose();
              }
            }
            if (event.type == SWT.DragDetect) {
              if (!DragSource.this.isDisposed()) {
                DragSource.this.drag(event);
              }
            }
          }
        };
    control.addListener(SWT.Dispose, controlListener);
    control.addListener(SWT.DragDetect, controlListener);

    this.addListener(
        SWT.Dispose,
        new Listener() {
          public void handleEvent(Event e) {
            DragSource.this.onDispose();
          }
        });

    Object effect = control.getData(DEFAULT_DRAG_SOURCE_EFFECT);
    if (effect instanceof DragSourceEffect) {
      dragEffect = (DragSourceEffect) effect;
    } else if (control instanceof Tree) {
      dragEffect = new TreeDragSourceEffect((Tree) control);
    } else if (control instanceof Table) {
      dragEffect = new TableDragSourceEffect((Table) control);
    }
  }
Example #28
0
 /**
  * Sets the control that is used to fill the client area of the tab folder when the user selects
  * the tab item.
  *
  * <p>
  *
  * @param control the new control (or null)
  * @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 (this.control != null && this.control.isDisposed()) {
     this.control = null;
   }
   Control oldControl = this.control;
   Control newControl = control;
   this.control = control;
   int index = parent.indexOf(this);
   if (index != parent.getSelectionIndex()) {
     if (newControl != null) {
       newControl.setVisible(false);
     }
   } else {
     if (newControl != null) {
       newControl.setBounds(parent.getClientArea());
       newControl.setVisible(true);
     }
     if (oldControl != null) {
       oldControl.setVisible(false);
     }
   }
 }
Example #29
0
 void resizeControl() {
   if (control != null && !control.isDisposed()) {
     /*
      * Set the size and location of the control
      * separately to minimize flashing in the
      * case where the control does not resize
      * to the size that was requested.  This
      * case can occur when the control is a
      * combo box.
      */
     Rectangle itemRect = getBounds();
     control.setSize(itemRect.width, itemRect.height);
     Rectangle rect = control.getBounds();
     rect.x = itemRect.x + (itemRect.width - rect.width) / 2;
     rect.y = itemRect.y + (itemRect.height - rect.height) / 2;
     control.setLocation(rect.x, rect.y);
   }
 }
Example #30
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);
   }
 }