Пример #1
0
 void sendSelection() {
   Event event = new Event();
   int hitPart = ((NSScroller) view).hitPart();
   int value = getSelection();
   switch (hitPart) {
     case OS.NSScrollerDecrementLine:
       event.detail = SWT.ARROW_UP;
       value -= increment;
       break;
     case OS.NSScrollerDecrementPage:
       value -= pageIncrement;
       event.detail = SWT.PAGE_UP;
       break;
     case OS.NSScrollerIncrementLine:
       value += increment;
       event.detail = SWT.PAGE_DOWN;
       break;
     case OS.NSScrollerIncrementPage:
       value += pageIncrement;
       event.detail = SWT.ARROW_DOWN;
       break;
     case OS.NSScrollerKnob:
       event.detail = SWT.DRAG;
       break;
   }
   if (event.detail != SWT.DRAG) {
     setSelection(value);
   }
   sendEvent(SWT.Selection, event);
 }
Пример #2
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;
 }
Пример #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
 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;
 }
Пример #5
0
 int XPointerMotion(int w, int client_data, int call_data, int continue_to_dispatch) {
   int result = super.XPointerMotion(w, client_data, call_data, continue_to_dispatch);
   if (result != 0) return result;
   XMotionEvent xEvent = new XMotionEvent();
   OS.memmove(xEvent, call_data, XMotionEvent.sizeof);
   if (!dragging || (xEvent.state & OS.Button1Mask) == 0) return result;
   short[] x_root = new short[1], y_root = new short[1];
   OS.XtTranslateCoords(handle, (short) 0, (short) 0, x_root, y_root);
   int eventX = xEvent.x_root - x_root[0], eventY = xEvent.y_root - y_root[0];
   int[] argList1 = {
     OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0
   };
   OS.XtGetValues(handle, argList1, argList1.length / 2);
   int border = argList1[9],
       x = ((short) argList1[1]) - border,
       y = ((short) argList1[3]) - border;
   int width = argList1[5] + (border * 2), height = argList1[7] + (border * 2);
   int[] argList2 = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
   OS.XtGetValues(parent.handle, argList2, argList2.length / 2);
   int parentBorder = argList2[5];
   int parentWidth = argList2[1] + (parentBorder * 2);
   int parentHeight = argList2[3] + (parentBorder * 2);
   int newX = lastX, newY = lastY;
   if ((style & SWT.VERTICAL) != 0) {
     newX = Math.min(Math.max(0, eventX + x - startX - parentBorder), parentWidth - width);
   } else {
     newY = Math.min(Math.max(0, eventY + y - startY - parentBorder), parentHeight - height);
   }
   if (newX == lastX && newY == lastY) return result;
   drawBand(lastX, lastY, width, height);
   Event event = new Event();
   event.time = xEvent.time;
   event.x = newX;
   event.y = newY;
   event.width = width;
   event.height = height;
   if ((style & SWT.SMOOTH) == 0) {
     event.detail = SWT.DRAG;
   }
   sendEvent(SWT.Selection, event);
   if (isDisposed()) return result;
   if (event.doit) {
     lastX = event.x;
     lastY = event.y;
   }
   parent.update(true);
   drawBand(lastX, lastY, width, height);
   if ((style & SWT.SMOOTH) != 0) {
     setBounds(lastX, lastY, width, height);
     // widget could be disposed at this point
   }
   return result;
 }
Пример #6
0
 void click(boolean dropDown, int state) {
   if ((style & SWT.RADIO) != 0) {
     selectRadio();
   } else {
     if ((style & SWT.CHECK) != 0) setSelection(!set);
   }
   Event event = new Event();
   if ((style & SWT.DROP_DOWN) != 0) {
     if (dropDown) {
       event.detail = SWT.ARROW;
       int[] argList = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNheight, 0};
       OS.XtGetValues(handle, argList, argList.length / 2);
       event.x = (short) argList[1];
       event.y = (short) argList[3] + (short) argList[5];
     }
   }
   if (state != 0) setInputState(event, state);
   postEvent(SWT.Selection, event);
 }
Пример #7
0
 void HandleClick(int sender, int e) {
   if (!checkEvent(e)) return;
   if (ignoreSelection) return;
   Event event = new Event();
   if ((style & SWT.DROP_DOWN) != 0) {
     int mousePos = OS.Mouse_GetPosition(handle);
     int zero = OS.gcnew_Point(0, OS.FrameworkElement_ActualHeight(topHandle()));
     int arrowPos = OS.UIElement_TranslatePoint(arrowHandle, zero, handle);
     if (OS.Point_X(mousePos) > OS.Point_X(arrowPos)) {
       event.detail = SWT.ARROW;
       int location = OS.UIElement_TranslatePoint(handle, zero, parent.handle);
       event.x = (int) OS.Point_X(location);
       event.y = (int) OS.Point_Y(location);
       OS.GCHandle_Free(location);
     }
     OS.GCHandle_Free(arrowPos);
     OS.GCHandle_Free(zero);
     OS.GCHandle_Free(mousePos);
   }
   postEvent(SWT.Selection, event);
 }
Пример #8
0
 int XButtonPress(int w, int client_data, int call_data, int continue_to_dispatch) {
   int result = super.XButtonPress(w, client_data, call_data, continue_to_dispatch);
   if (result != 0) return result;
   XButtonEvent xEvent = new XButtonEvent();
   OS.memmove(xEvent, call_data, XButtonEvent.sizeof);
   if (xEvent.button != 1) return result;
   short[] x_root = new short[1], y_root = new short[1];
   OS.XtTranslateCoords(handle, (short) 0, (short) 0, x_root, y_root);
   startX = xEvent.x_root - x_root[0];
   startY = xEvent.y_root - y_root[0];
   int[] argList = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
   OS.XtGetValues(handle, argList, argList.length / 2);
   int border = argList[9], width = argList[5] + (border * 2), height = argList[7] + (border * 2);
   lastX = ((short) argList[1]) - border;
   lastY = ((short) argList[3]) - border;
   Event event = new Event();
   event.time = xEvent.time;
   event.x = lastX;
   event.y = lastY;
   event.width = width;
   event.height = height;
   if ((style & SWT.SMOOTH) == 0) {
     event.detail = SWT.DRAG;
   }
   sendEvent(SWT.Selection, event);
   if (isDisposed()) return result;
   if (event.doit) {
     dragging = true;
     lastX = event.x;
     lastY = event.y;
     parent.update(true);
     drawBand(event.x, event.y, width, height);
     if ((style & SWT.SMOOTH) != 0) {
       setBounds(event.x, event.y, width, height);
       // widget could be disposed at this point
     }
   }
   return result;
 }
Пример #9
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;
 }