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; }
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; }
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; }
int /*long*/ gtk_preedit_changed(int /*long*/ imcontext) { if (!isInlineEnabled()) return 0; ranges = null; styles = null; commitCount = 0; int /*long*/ imHandle = imHandle(); int /*long*/[] preeditString = new int /*long*/[1]; int /*long*/[] pangoAttrs = new int /*long*/[1]; int[] cursorPos = new int[1]; OS.gtk_im_context_get_preedit_string(imHandle, preeditString, pangoAttrs, cursorPos); caretOffset = cursorPos[0]; char[] chars = null; if (preeditString[0] != 0) { int length = OS.strlen(preeditString[0]); byte[] buffer = new byte[length]; OS.memmove(buffer, preeditString[0], length); chars = Converter.mbcsToWcs(null, buffer); if (pangoAttrs[0] != 0) { int count = 0; int /*long*/ iterator = OS.pango_attr_list_get_iterator(pangoAttrs[0]); while (OS.pango_attr_iterator_next(iterator)) count++; OS.pango_attr_iterator_destroy(iterator); ranges = new int[count * 2]; styles = new TextStyle[count]; iterator = OS.pango_attr_list_get_iterator(pangoAttrs[0]); PangoAttrColor attrColor = new PangoAttrColor(); PangoAttrInt attrInt = new PangoAttrInt(); int[] start = new int[1]; int[] end = new int[1]; for (int i = 0; i < count; i++) { OS.pango_attr_iterator_range(iterator, start, end); ranges[i * 2] = (int) /*64*/ OS.g_utf16_pointer_to_offset(preeditString[0], preeditString[0] + start[0]); ranges[i * 2 + 1] = (int) /*64*/ OS.g_utf16_pointer_to_offset(preeditString[0], preeditString[0] + end[0]) - 1; styles[i] = new TextStyle(null, null, null); int /*long*/ attr = OS.pango_attr_iterator_get(iterator, OS.PANGO_ATTR_FOREGROUND); if (attr != 0) { OS.memmove(attrColor, attr, PangoAttrColor.sizeof); GdkColor color = new GdkColor(); color.red = attrColor.color_red; color.green = attrColor.color_green; color.blue = attrColor.color_blue; styles[i].foreground = Color.gtk_new(display, color); } attr = OS.pango_attr_iterator_get(iterator, OS.PANGO_ATTR_BACKGROUND); if (attr != 0) { OS.memmove(attrColor, attr, PangoAttrColor.sizeof); GdkColor color = new GdkColor(); color.red = attrColor.color_red; color.green = attrColor.color_green; color.blue = attrColor.color_blue; styles[i].background = Color.gtk_new(display, color); } attr = OS.pango_attr_iterator_get(iterator, OS.PANGO_ATTR_UNDERLINE); if (attr != 0) { OS.memmove(attrInt, attr, PangoAttrInt.sizeof); styles[i].underline = attrInt.value != OS.PANGO_UNDERLINE_NONE; ; styles[i].underlineStyle = SWT.UNDERLINE_SINGLE; switch (attrInt.value) { case OS.PANGO_UNDERLINE_DOUBLE: styles[i].underlineStyle = SWT.UNDERLINE_DOUBLE; break; case OS.PANGO_UNDERLINE_ERROR: styles[i].underlineStyle = SWT.UNDERLINE_ERROR; break; } if (styles[i].underline) { attr = OS.pango_attr_iterator_get(iterator, OS.PANGO_ATTR_UNDERLINE_COLOR); if (attr != 0) { OS.memmove(attrColor, attr, PangoAttrColor.sizeof); GdkColor color = new GdkColor(); color.red = attrColor.color_red; color.green = attrColor.color_green; color.blue = attrColor.color_blue; styles[i].underlineColor = Color.gtk_new(display, color); } } } OS.pango_attr_iterator_next(iterator); } OS.pango_attr_iterator_destroy(iterator); OS.pango_attr_list_unref(pangoAttrs[0]); } OS.g_free(preeditString[0]); } if (chars != null) { if (text.length() == 0) { /* * Bug in GTK. In Solaris, the IME sends multiple * preedit_changed signals with an empty text. * This behavior is not correct for SWT and can * cause the editor to replace its current selection * with an empty string. The fix is to ignore any * preedit_changed signals with an empty text when * the preedit buffer is already empty. */ if (chars.length == 0) return 0; startOffset = -1; } int end = startOffset + text.length(); if (startOffset == -1) { Event event = new Event(); event.detail = SWT.COMPOSITION_SELECTION; sendEvent(SWT.ImeComposition, event); startOffset = event.start; end = event.end; } inComposition = true; Event event = new Event(); event.detail = SWT.COMPOSITION_CHANGED; event.start = startOffset; event.end = end; event.text = text = chars != null ? new String(chars) : ""; sendEvent(SWT.ImeComposition, event); } return 1; }