void createItem(TabItem item, int index) { long /*int*/ list = OS.gtk_container_get_children(handle); int itemCount = 0; if (list != 0) { itemCount = OS.g_list_length(list); OS.g_list_free(list); } if (!(0 <= index && index <= itemCount)) error(SWT.ERROR_INVALID_RANGE); if (itemCount == items.length) { TabItem[] newItems = new TabItem[items.length + 4]; System.arraycopy(items, 0, newItems, 0, items.length); items = newItems; } long /*int*/ boxHandle = gtk_box_new(OS.GTK_ORIENTATION_HORIZONTAL, false, 0); if (boxHandle == 0) error(SWT.ERROR_NO_HANDLES); long /*int*/ labelHandle = OS.gtk_label_new_with_mnemonic(null); if (labelHandle == 0) error(SWT.ERROR_NO_HANDLES); long /*int*/ imageHandle = OS.gtk_image_new(); if (imageHandle == 0) error(SWT.ERROR_NO_HANDLES); OS.gtk_container_add(boxHandle, imageHandle); OS.gtk_container_add(boxHandle, labelHandle); long /*int*/ pageHandle = OS.g_object_new(display.gtk_fixed_get_type(), 0); if (pageHandle == 0) error(SWT.ERROR_NO_HANDLES); if (OS.GTK3) { OS.gtk_widget_override_background_color(pageHandle, OS.GTK_STATE_FLAG_NORMAL, new GdkRGBA()); long /*int*/ region = OS.gdk_region_new(); OS.gtk_widget_input_shape_combine_region(pageHandle, region); OS.gdk_region_destroy(region); } OS.g_signal_handlers_block_matched(handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE); OS.gtk_notebook_insert_page(handle, pageHandle, boxHandle, index); OS.g_signal_handlers_unblock_matched(handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE); OS.gtk_widget_show(boxHandle); OS.gtk_widget_show(labelHandle); OS.gtk_widget_show(pageHandle); item.state |= HANDLE; item.handle = boxHandle; item.labelHandle = labelHandle; item.imageHandle = imageHandle; item.pageHandle = pageHandle; System.arraycopy(items, index, items, index + 1, itemCount++ - index); items[index] = item; if ((state & FOREGROUND) != 0) { item.setForegroundColor(getForegroundColor()); } if ((state & FONT) != 0) { item.setFontDescription(getFontDescription()); } if (itemCount == 1) { 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, 0); OS.g_signal_handlers_unblock_matched(handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE); Event event = new Event(); event.item = items[0]; sendSelectionEvent(SWT.Selection, event, false); // the widget could be destroyed at this point } }
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); } } }
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 } } }
/** * 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); }
long /*int*/ gtk_clicked(long /*int*/ widget) { Event event = new Event(); if ((style & SWT.DROP_DOWN) != 0) { long /*int*/ eventPtr = OS.gtk_get_current_event(); if (eventPtr != 0) { GdkEvent gdkEvent = new GdkEvent(); OS.memmove(gdkEvent, eventPtr, GdkEvent.sizeof); long /*int*/ topHandle = topHandle(); switch (gdkEvent.type) { case OS.GDK_KEY_RELEASE: // Fall Through.. case OS.GDK_BUTTON_PRESS: case OS.GDK_2BUTTON_PRESS: case OS.GDK_BUTTON_RELEASE: { boolean isArrow = false; if (OS.GTK_VERSION < OS.VERSION(2, 6, 0)) { double[] x_win = new double[1]; double[] y_win = new double[1]; OS.gdk_event_get_coords(eventPtr, x_win, y_win); int x = OS.GTK_WIDGET_X(arrowHandle) - OS.GTK_WIDGET_X(handle); int width = OS.GTK_WIDGET_WIDTH(arrowHandle); if ((((parent.style & SWT.RIGHT_TO_LEFT) == 0) && x <= (int) x_win[0]) || (((parent.style & SWT.RIGHT_TO_LEFT) != 0) && (int) x_win[0] <= x + width)) { isArrow = true; } } else if (widget == arrowHandle) { isArrow = true; topHandle = widget; /* * Feature in GTK. ArrowButton stays in toggled state if there is no popup menu. * It is required to set back the state of arrow to normal state after it is clicked. */ OS.g_signal_handlers_block_matched( widget, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CLICKED); OS.gtk_toggle_button_set_active(widget, false); OS.g_signal_handlers_unblock_matched( widget, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CLICKED); } if (isArrow) { event.detail = SWT.ARROW; event.x = OS.GTK_WIDGET_X(topHandle); if ((parent.style & SWT.MIRRORED) != 0) event.x = parent.getClientWidth() - OS.GTK_WIDGET_WIDTH(topHandle) - event.x; event.y = OS.GTK_WIDGET_Y(topHandle) + OS.GTK_WIDGET_HEIGHT(topHandle); } break; } } OS.gdk_event_free(eventPtr); } } if ((style & SWT.RADIO) != 0) { if ((parent.getStyle() & SWT.NO_RADIO_GROUP) == 0) { selectRadio(); } } sendSelectionEvent(SWT.Selection, event, false); return 0; }