예제 #1
0
 /**
  * Sets the selection state of the receiver.
  *
  * <p>When the receiver is of type <code>CHECK</code> or <code>RADIO</code>, it is selected when
  * it is checked (which some platforms draw as a pushed in button).
  *
  * @param selected the new selection 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 setSelection(boolean selected) {
   checkWidget();
   if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return;
   OS.g_signal_handlers_block_matched(handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CLICKED);
   OS.gtk_toggle_tool_button_set_active(handle, selected);
   OS.g_signal_handlers_unblock_matched(handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CLICKED);
 }
예제 #2
0
 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
     }
   }
 }
예제 #3
0
 int /*long*/ gtk_commit(int /*long*/ imcontext, int /*long*/ textPtr) {
   if (!isInlineEnabled()) return 0;
   boolean doit = true;
   ranges = null;
   styles = null;
   caretOffset = commitCount = 0;
   if (textPtr != 0 && inComposition) {
     int length = OS.strlen(textPtr);
     if (length != 0) {
       byte[] buffer = new byte[length];
       OS.memmove(buffer, textPtr, length);
       char[] chars = Converter.mbcsToWcs(null, buffer);
       Event event = new Event();
       event.detail = SWT.COMPOSITION_CHANGED;
       event.start = startOffset;
       event.end = startOffset + text.length();
       event.text = text = chars != null ? new String(chars) : "";
       commitCount = text.length();
       sendEvent(SWT.ImeComposition, event);
       doit = event.doit;
       text = "";
       startOffset = -1;
       commitCount = 0;
     }
   }
   inComposition = false;
   return doit ? 0 : 1;
 }
예제 #4
0
 public void setImage(Image image) {
   checkWidget();
   if ((style & SWT.SEPARATOR) != 0) return;
   super.setImage(image);
   if (image != null) {
     ImageList imageList = parent.imageList;
     if (imageList == null) imageList = parent.imageList = new ImageList();
     int imageIndex = imageList.indexOf(image);
     if (imageIndex == -1) {
       imageIndex = imageList.add(image);
     } else {
       imageList.put(imageIndex, image);
     }
     long /*int*/ pixbuf = imageList.getPixbuf(imageIndex);
     OS.gtk_image_set_from_pixbuf(imageHandle, pixbuf);
   } else {
     OS.gtk_image_set_from_pixbuf(imageHandle, 0);
   }
   /*
    * If Text/Image of a tool-item changes, then it is
    * required to reset the proxy menu. Otherwise, the
    * old menuItem appears in the overflow menu.
    */
   if ((style & SWT.DROP_DOWN) != 0) {
     proxyMenuItem = 0;
     proxyMenuItem = OS.gtk_tool_item_retrieve_proxy_menu_item(handle);
     OS.g_signal_connect(
         proxyMenuItem, OS.activate, ToolBar.menuItemSelectedFunc.getAddress(), handle);
   }
   parent.relayout();
 }
예제 #5
0
 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);
 }
예제 #6
0
 /**
  * Sets the OpenGL context associated with this GLCanvas to be the current GL context.
  *
  * @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 setCurrent() {
   checkWidget();
   if (GLX.glXGetCurrentContext() == context) return;
   int /*long*/ window = OS.GTK_WIDGET_WINDOW(handle);
   int /*long*/ xDisplay = OS.gdk_x11_drawable_get_xdisplay(window);
   GLX.glXMakeCurrent(xDisplay, xWindow, context);
 }
예제 #7
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);
     }
   }
 }
예제 #8
0
 void setOrientation(boolean create) {
   super.setOrientation(create);
   if ((parent.style & SWT.RIGHT_TO_LEFT) != 0 || !create) {
     int dir = (parent.style & SWT.RIGHT_TO_LEFT) != 0 ? OS.GTK_TEXT_DIR_RTL : OS.GTK_TEXT_DIR_LTR;
     OS.gtk_widget_set_direction(handle, dir);
     OS.gtk_container_forall(handle, display.setDirectionProc, dir);
   }
 }
예제 #9
0
 /**
  * Returns the number of items contained in the receiver.
  *
  * @return the number of items
  * @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 int getItemCount() {
   checkWidget();
   long /*int*/ list = OS.gtk_container_get_children(handle);
   if (list == 0) return 0;
   int itemCount = OS.g_list_length(list);
   OS.g_list_free(list);
   return itemCount;
 }
예제 #10
0
 Color _getForeground() {
   int /*long*/[] ptr = new int /*long*/[1];
   OS.gtk_tree_model_get(parent.modelHandle, handle, Table.FOREGROUND_COLUMN, ptr, -1);
   if (ptr[0] == 0) return parent.getForeground();
   GdkColor gdkColor = new GdkColor();
   OS.memmove(gdkColor, ptr[0], GdkColor.sizeof);
   return Color.gtk_new(display, gdkColor);
 }
예제 #11
0
 @Override
 int setBounds(int x, int y, int width, int height, boolean move, boolean resize) {
   OS.gtk_toolbar_set_show_arrow(handle, false);
   int result = super.setBounds(x, y, width, height, move, resize);
   if ((result & RESIZED) != 0) relayout();
   if ((style & SWT.WRAP) != 0) OS.gtk_toolbar_set_show_arrow(handle, true);
   return result;
 }
예제 #12
0
 boolean traversePage(final boolean next) {
   if (next) {
     OS.gtk_notebook_next_page(handle);
   } else {
     OS.gtk_notebook_prev_page(handle);
   }
   return true;
 }
예제 #13
0
 boolean setFocus() {
   if (!OS.gtk_widget_get_child_visible(handle)) return false;
   OS.GTK_WIDGET_SET_FLAGS(handle, OS.GTK_CAN_FOCUS);
   OS.gtk_widget_grab_focus(handle);
   // widget could be disposed at this point
   if (isDisposed()) return false;
   boolean result = OS.gtk_widget_is_focus(handle);
   if (!result) OS.GTK_WIDGET_UNSET_FLAGS(handle, OS.GTK_CAN_FOCUS);
   return result;
 }
예제 #14
0
 TableItem(Table parent, int style, int index, boolean create) {
   super(parent, style);
   this.parent = parent;
   if (create) {
     parent.createItem(this, index);
   } else {
     handle = OS.g_malloc(OS.GtkTreeIter_sizeof());
     OS.gtk_tree_model_iter_nth_child(parent.modelHandle, handle, 0, index);
   }
 }
예제 #15
0
 /**
  * Returns the item at the given, zero-relative index in the receiver. Throws an exception if the
  * index is out of range.
  *
  * @param index the index of the item to return
  * @return the item at the given index
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the
  *           list minus 1 (inclusive)
  *     </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 TabItem getItem(int index) {
   checkWidget();
   if (!(0 <= index && index < getItemCount())) error(SWT.ERROR_INVALID_RANGE);
   long /*int*/ list = OS.gtk_container_get_children(handle);
   if (list == 0) error(SWT.ERROR_CANNOT_GET_ITEM);
   int itemCount = OS.g_list_length(list);
   OS.g_list_free(list);
   if (!(0 <= index && index < itemCount)) error(SWT.ERROR_CANNOT_GET_ITEM);
   return items[index];
 }
예제 #16
0
 Color _getForeground(int index) {
   int count = Math.max(1, parent.columnCount);
   if (0 > index || index > count - 1) return _getForeground();
   int /*long*/[] ptr = new int /*long*/[1];
   int modelIndex =
       parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns[index].modelIndex;
   OS.gtk_tree_model_get(parent.modelHandle, handle, modelIndex + Table.CELL_FOREGROUND, ptr, -1);
   if (ptr[0] == 0) return _getForeground();
   GdkColor gdkColor = new GdkColor();
   OS.memmove(gdkColor, ptr[0], GdkColor.sizeof);
   return Color.gtk_new(display, gdkColor);
 }
예제 #17
0
 /**
  * Searches the receiver's list starting at the first item (index 0) until an item is found that
  * is equal to the argument, and returns the index of that item. If no item is found, returns -1.
  *
  * @param item the search item
  * @return the index of the item
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the item is null
  *     </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 int indexOf(TabItem item) {
   checkWidget();
   if (item == null) error(SWT.ERROR_NULL_ARGUMENT);
   long /*int*/ list = OS.gtk_container_get_children(handle);
   if (list == 0) return -1;
   int count = OS.g_list_length(list);
   OS.g_list_free(list);
   for (int i = 0; i < count; i++) {
     if (items[i] == item) return i;
   }
   return -1;
 }
예제 #18
0
 /**
  * Returns a rectangle describing the receiver's size and location relative to its parent.
  *
  * @return the receiver's bounding rectangle
  * @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 Rectangle getBounds() {
   checkWidget();
   parent.forceResize();
   long /*int*/ topHandle = topHandle();
   int x, y, width, height;
   x = OS.GTK_WIDGET_X(topHandle);
   y = OS.GTK_WIDGET_Y(topHandle);
   width = OS.GTK_WIDGET_WIDTH(topHandle);
   height = OS.GTK_WIDGET_HEIGHT(topHandle);
   if ((parent.style & SWT.MIRRORED) != 0) x = parent.getClientWidth() - width - x;
   if ((style & SWT.SEPARATOR) != 0 && control != null) height = Math.max(height, 23);
   return new Rectangle(x, y, width, height);
 }
예제 #19
0
 public Point computeSize(int wHint, int hHint, boolean changed) {
   checkWidget();
   Point size = super.computeSize(wHint, hHint, changed);
   if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
   if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
   boolean scrollable = OS.gtk_notebook_get_scrollable(handle);
   OS.gtk_notebook_set_scrollable(handle, false);
   Point notebookSize = computeNativeSize(handle, wHint, hHint, changed);
   OS.gtk_notebook_set_scrollable(handle, scrollable);
   size.x = Math.max(notebookSize.x, size.x);
   size.y = Math.max(notebookSize.y, size.y);
   return size;
 }
예제 #20
0
 void reskinChildren(int flags) {
   if (items != null) {
     long /*int*/ list = OS.gtk_container_get_children(handle);
     if (list != 0) {
       int count = OS.g_list_length(list);
       OS.g_list_free(list);
       for (int i = 0; i < count; i++) {
         TabItem item = items[i];
         if (item != null) item.reskin(flags);
       }
     }
   }
   super.reskinChildren(flags);
 }
예제 #21
0
 String _getText(int index) {
   int count = Math.max(1, parent.getColumnCount());
   if (0 > index || index > count - 1) return "";
   int /*long*/[] ptr = new int /*long*/[1];
   int modelIndex =
       parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns[index].modelIndex;
   OS.gtk_tree_model_get(parent.modelHandle, handle, modelIndex + Table.CELL_TEXT, ptr, -1);
   if (ptr[0] == 0) return "";
   int length = OS.strlen(ptr[0]);
   byte[] buffer = new byte[length];
   OS.memmove(buffer, ptr[0], length);
   OS.g_free(ptr[0]);
   return new String(Converter.mbcsToWcs(null, buffer));
 }
예제 #22
0
 /**
  * Sets the checked state of the checkbox for this item. This state change only applies if the
  * Table was created with the SWT.CHECK style.
  *
  * @param checked the new checked state of the checkbox
  * @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 setChecked(boolean checked) {
   checkWidget();
   if ((parent.style & SWT.CHECK) == 0) return;
   if (_getChecked() == checked) return;
   OS.gtk_list_store_set(parent.modelHandle, handle, Table.CHECKED_COLUMN, checked, -1);
   /*
    * GTK+'s "inconsistent" state does not match SWT's concept of grayed.  To
    * show checked+grayed differently from unchecked+grayed, we must toggle the
    * grayed state on check and uncheck.
    */
   OS.gtk_list_store_set(
       parent.modelHandle, handle, Table.GRAYED_COLUMN, !checked ? false : grayed, -1);
   cached = true;
 }
예제 #23
0
 /**
  * Returns the tab item at the given point in the receiver or null if no such item exists. The
  * point is in the coordinate system of the receiver.
  *
  * @param point the point used to locate the item
  * @return the tab item at the given point, or null if the point is not in a tab item
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the point is null
  *     </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>
  *
  * @since 3.4
  */
 public TabItem getItem(Point point) {
   checkWidget();
   if (point == null) error(SWT.ERROR_NULL_ARGUMENT);
   long /*int*/ list = OS.gtk_container_get_children(handle);
   if (list == 0) return null;
   int itemCount = OS.g_list_length(list);
   OS.g_list_free(list);
   for (int i = 0; i < itemCount; i++) {
     TabItem item = items[i];
     Rectangle rect = item.getBounds();
     if (rect.contains(point)) return item;
   }
   return null;
 }
예제 #24
0
 long /*int*/ gtk_button_release_event(long /*int*/ widget, long /*int*/ event) {
   GdkEventButton gdkEvent = new GdkEventButton();
   OS.memmove(gdkEvent, event, GdkEventButton.sizeof);
   double x = gdkEvent.x;
   gdkEvent.x += OS.GTK_WIDGET_X(handle);
   double y = gdkEvent.y;
   gdkEvent.y += OS.GTK_WIDGET_Y(handle);
   OS.memmove(event, gdkEvent, GdkEventButton.sizeof);
   long /*int*/ result = parent.gtk_button_release_event(widget, event);
   gdkEvent.x = x;
   gdkEvent.y = y;
   OS.memmove(event, gdkEvent, GdkEventButton.sizeof);
   return result;
 }
예제 #25
0
 /**
  * Sets the grayed state of the checkbox for this item. This state change only applies if the
  * Table was created with the SWT.CHECK style.
  *
  * @param grayed the new grayed state of the checkbox;
  * @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 setGrayed(boolean grayed) {
   checkWidget();
   if ((parent.style & SWT.CHECK) == 0) return;
   if (this.grayed == grayed) return;
   this.grayed = grayed;
   /*
    * GTK+'s "inconsistent" state does not match SWT's concept of grayed.
    * Render checked+grayed as "inconsistent", unchecked+grayed as blank.
    */
   int /*long*/[] ptr = new int /*long*/[1];
   OS.gtk_tree_model_get(parent.modelHandle, handle, Table.CHECKED_COLUMN, ptr, -1);
   OS.gtk_list_store_set(
       parent.modelHandle, handle, Table.GRAYED_COLUMN, ptr[0] == 0 ? false : grayed, -1);
   cached = true;
 }
예제 #26
0
 @Override
 public Point computeSize(int wHint, int hHint, boolean changed) {
   checkWidget();
   if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
   if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
   /*
    * Feature in GTK. Size of toolbar is calculated incorrectly
    * and appears as just the overflow arrow, if the arrow is enabled
    * to display. The fix is to disable it before the computation of
    * size and enable it if WRAP style is set.
    */
   OS.gtk_toolbar_set_show_arrow(handle, false);
   Point size = computeNativeSize(handle, wHint, hHint, changed);
   if ((style & SWT.WRAP) != 0) OS.gtk_toolbar_set_show_arrow(handle, true);
   return size;
 }
예제 #27
0
 long /*int*/ clientHandle() {
   int index = OS.gtk_notebook_get_current_page(handle);
   if (index != -1 && items[index] != null) {
     return items[index].pageHandle;
   }
   return handle;
 }
예제 #28
0
 void relayout() {
   ToolItem[] items = getItems();
   boolean hasText = false, hasImage = false;
   for (int i = 0; i < items.length; i++) {
     ToolItem item = items[i];
     if (item != null) {
       item.resizeControl();
       hasText |= item.text != null && item.text.length() > 0;
       hasImage |= item.image != null;
     }
   }
   int type = OS.GTK_TOOLBAR_ICONS;
   if (hasText && hasImage) {
     if ((style & SWT.RIGHT) != 0) {
       type = OS.GTK_TOOLBAR_BOTH_HORIZ;
     } else {
       type = OS.GTK_TOOLBAR_BOTH;
     }
   } else if (hasText) {
     type = OS.GTK_TOOLBAR_TEXT;
   } else if (hasImage) {
     type = OS.GTK_TOOLBAR_ICONS;
   }
   OS.gtk_toolbar_set_style(handle, type);
 }
예제 #29
0
 long /*int*/ menuItemSelected(long /*int*/ widget, ToolItem item) {
   Event event = new Event();
   switch (item.style) {
     case SWT.DROP_DOWN:
       /*
        * Feature in GTK. The DROP_DOWN item does not
        * contain arrow button in the overflow menu. So, it
        * is impossible to select the menu of that item.
        * The fix is to consider the item selection
        * as Arrow click, in order to popup the drop-down.
        */
       event.detail = SWT.ARROW;
       GtkAllocation allocation = new GtkAllocation();
       OS.gtk_widget_get_allocation(widget, allocation);
       event.x = allocation.x;
       if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth() - allocation.width - event.x;
       event.y = allocation.y + allocation.height;
       break;
     case SWT.RADIO:
       if ((style & SWT.NO_RADIO_GROUP) == 0) item.selectRadio();
       break;
     case SWT.CHECK:
       boolean currentSelection = item.getSelection();
       item.setSelection(!currentSelection);
   }
   item.sendSelectionEvent(SWT.Selection, event, false);
   return 0;
 }
예제 #30
0
 long /*int*/ gtk_event_after(long /*int*/ widget, long /*int*/ gdkEvent) {
   GdkEvent event = new GdkEvent();
   OS.memmove(event, gdkEvent, GdkEvent.sizeof);
   switch (event.type) {
     case OS.GDK_BUTTON_PRESS:
       {
         GdkEventButton gdkEventButton = new GdkEventButton();
         OS.memmove(gdkEventButton, gdkEvent, GdkEventButton.sizeof);
         if (gdkEventButton.button == 3) {
           parent.showMenu((int) gdkEventButton.x_root, (int) gdkEventButton.y_root);
         }
         break;
       }
   }
   return 0;
 }