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 } }
/** * Returns an array of <code>TabItem</code>s which are the items in the receiver. * * <p>Note: This is not the actual structure used by the receiver to maintain its list of items, * so modifying the array will not affect the receiver. * * @return the items in the receiver * @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[] getItems() { checkWidget(); int count = getItemCount(); TabItem[] result = new TabItem[count]; System.arraycopy(items, 0, result, 0, count); return result; }
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 } } }
Rectangle[] getRectangles(int linkIndex) { int lineCount = layout.getLineCount(); Rectangle[] rects = new Rectangle[lineCount]; int[] lineOffsets = layout.getLineOffsets(); Point point = offsets[linkIndex]; int lineStart = 1; while (point.x > lineOffsets[lineStart]) lineStart++; int lineEnd = 1; while (point.y > lineOffsets[lineEnd]) lineEnd++; int index = 0; if (lineStart == lineEnd) { rects[index++] = layout.getBounds(point.x, point.y); } else { rects[index++] = layout.getBounds(point.x, lineOffsets[lineStart] - 1); rects[index++] = layout.getBounds(lineOffsets[lineEnd - 1], point.y); if (lineEnd - lineStart > 1) { for (int i = lineStart; i < lineEnd - 1; i++) { rects[index++] = layout.getLineBounds(i); } } } if (rects.length != index) { Rectangle[] tmp = new Rectangle[index]; System.arraycopy(rects, 0, tmp, 0, index); rects = tmp; } return rects; }
/** * Returns the styles for the ranges. * * <p>The ranges array contains start and end pairs. Each pair refers to the corresponding style * in the styles array. For example, the pair that starts at ranges[n] and ends at ranges[n+1] * uses the style at styles[n/2]. * * @return the ranges for the styles * @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> * * @see IME#getRanges */ public TextStyle[] getStyles() { checkWidget(); if (styles == null) return new TextStyle[0]; TextStyle[] result = new TextStyle[styles.length]; System.arraycopy(styles, 0, result, 0, styles.length); return result; }
/*public*/ void setTabItemList(ToolItem[] tabList) { checkWidget(); if (tabList != null) { for (int i = 0; i < tabList.length; i++) { ToolItem item = tabList[i]; if (item == null) error(SWT.ERROR_INVALID_ARGUMENT); if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); if (item.parent != this) error(SWT.ERROR_INVALID_PARENT); } ToolItem[] newList = new ToolItem[tabList.length]; System.arraycopy(tabList, 0, newList, 0, tabList.length); tabList = newList; } this.tabItemList = tabList; }
@Override Widget[] computeTabList() { ToolItem[] items = _getItems(); if (tabItemList == null) { int i = 0; while (i < items.length && items[i].control == null) i++; if (i == items.length) return super.computeTabList(); } Widget result[] = {}; if (!isTabGroup() || !isEnabled() || !isVisible()) return result; ToolItem[] list = tabList != null ? _getTabItemList() : items; for (int i = 0; i < list.length; i++) { ToolItem child = list[i]; Widget[] childList = child.computeTabList(); if (childList.length != 0) { Widget[] newResult = new Widget[result.length + childList.length]; System.arraycopy(result, 0, newResult, 0, result.length); System.arraycopy(childList, 0, newResult, result.length, childList.length); result = newResult; } } if (result.length == 0) result = new Widget[] {this}; return result; }
ToolItem[] _getItems() { long /*int*/ list = OS.gtk_container_get_children(handle); if (list == 0) return new ToolItem[0]; int count = OS.g_list_length(list); ToolItem[] items = new ToolItem[count]; long /*int*/ originalList = list; int index = 0; for (int i = 0; i < count; i++) { long /*int*/ data = OS.g_list_data(list); Widget widget = display.getWidget(data); if (widget != null) items[index++] = (ToolItem) widget; list = OS.g_list_next(list); } OS.g_list_free(originalList); if (index != items.length) { ToolItem[] newItems = new ToolItem[index]; System.arraycopy(items, 0, newItems, 0, index); items = newItems; } return items; }
String parse(String string) { int length = string.length(); offsets = new Point[length / 4]; ids = new String[length / 4]; mnemonics = new int[length / 4 + 1]; StringBuffer result = new StringBuffer(); char[] buffer = new char[length]; string.getChars(0, string.length(), buffer, 0); int index = 0, state = 0, linkIndex = 0; int start = 0, tagStart = 0, linkStart = 0, endtagStart = 0, refStart = 0; while (index < length) { char c = Character.toLowerCase(buffer[index]); switch (state) { case 0: if (c == '<') { tagStart = index; state++; } break; case 1: if (c == 'a') state++; break; case 2: switch (c) { case 'h': state = 7; break; case '>': linkStart = index + 1; state++; break; default: if (Character.isWhitespace(c)) break; else state = 13; } break; case 3: if (c == '<') { endtagStart = index; state++; } break; case 4: state = c == '/' ? state + 1 : 3; break; case 5: state = c == 'a' ? state + 1 : 3; break; case 6: if (c == '>') { mnemonics[linkIndex] = parseMnemonics(buffer, start, tagStart, result); int offset = result.length(); parseMnemonics(buffer, linkStart, endtagStart, result); offsets[linkIndex] = new Point(offset, result.length() - 1); if (ids[linkIndex] == null) { ids[linkIndex] = new String(buffer, linkStart, endtagStart - linkStart); } linkIndex++; start = tagStart = linkStart = endtagStart = refStart = index + 1; state = 0; } else { state = 3; } break; case 7: state = c == 'r' ? state + 1 : 0; break; case 8: state = c == 'e' ? state + 1 : 0; break; case 9: state = c == 'f' ? state + 1 : 0; break; case 10: state = c == '=' ? state + 1 : 0; break; case 11: if (c == '"') { state++; refStart = index + 1; } else { state = 0; } break; case 12: if (c == '"') { ids[linkIndex] = new String(buffer, refStart, index - refStart); state = 2; } break; case 13: if (Character.isWhitespace(c)) { state = 0; } else if (c == '=') { state++; } break; case 14: state = c == '"' ? state + 1 : 0; break; case 15: if (c == '"') state = 2; break; default: state = 0; break; } index++; } if (start < length) { int tmp = parseMnemonics(buffer, start, tagStart, result); int mnemonic = parseMnemonics(buffer, Math.max(tagStart, linkStart), length, result); if (mnemonic == -1) mnemonic = tmp; mnemonics[linkIndex] = mnemonic; } else { mnemonics[linkIndex] = -1; } if (offsets.length != linkIndex) { Point[] newOffsets = new Point[linkIndex]; System.arraycopy(offsets, 0, newOffsets, 0, linkIndex); offsets = newOffsets; String[] newIDs = new String[linkIndex]; System.arraycopy(ids, 0, newIDs, 0, linkIndex); ids = newIDs; int[] newMnemonics = new int[linkIndex + 1]; System.arraycopy(mnemonics, 0, newMnemonics, 0, linkIndex + 1); mnemonics = newMnemonics; } return result.toString(); }