Exemplo n.º 1
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;
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
0
 @Override
 long /*int*/ gtk_key_press_event(long /*int*/ widget, long /*int*/ eventPtr) {
   long /*int*/ result = super.gtk_key_press_event(widget, eventPtr);
   if (result != 0) return result;
   if (focusIndex == -1) return result;
   GdkEventKey gdkEvent = new GdkEventKey();
   OS.memmove(gdkEvent, eventPtr, GdkEventKey.sizeof);
   switch (gdkEvent.keyval) {
     case OS.GDK_Return:
     case OS.GDK_KP_Enter:
     case OS.GDK_space:
       Event event = new Event();
       event.text = ids[focusIndex];
       sendSelectionEvent(SWT.Selection, event, true);
       break;
     case OS.GDK_Tab:
       if (focusIndex < offsets.length - 1) {
         focusIndex++;
         redraw();
       }
       break;
     case OS.GDK_ISO_Left_Tab:
       if (focusIndex > 0) {
         focusIndex--;
         redraw();
       }
       break;
   }
   return result;
 }
Exemplo n.º 4
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;
 }
Exemplo n.º 5
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;
 }
Exemplo n.º 6
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);
 }
Exemplo n.º 7
0
 /**
  * This implementation of <code>dragOver</code> provides a default drag under effect for the
  * feedback specified in <code>event.feedback</code>. The class description lists the FEEDBACK
  * constants that are applicable to the class.
  *
  * <p>For additional information see <code>DropTargetAdapter.dragOver</code>.
  *
  * <p>Subclasses that override this method should call <code>super.dragOver(event)</code> to get
  * the default drag under effect implementation.
  *
  * @param event the information associated with the drag over event
  * @see DropTargetAdapter
  * @see DropTargetEvent
  * @see DND#FEEDBACK_SELECT
  * @see DND#FEEDBACK_SCROLL
  */
 public void dragOver(DropTargetEvent event) {
   Table table = (Table) control;
   long /*int*/ handle = table.handle;
   int effect = checkEffect(event.feedback);
   Point coordinates = new Point(event.x, event.y);
   coordinates = table.toControl(coordinates);
   long /*int*/[] path = new long /*int*/[1];
   OS.gtk_tree_view_get_path_at_pos(handle, coordinates.x, coordinates.y, path, null, null, null);
   int index = -1;
   if (path[0] != 0) {
     long /*int*/ indices = OS.gtk_tree_path_get_indices(path[0]);
     if (indices != 0) {
       int[] temp = new int[1];
       OS.memmove(temp, indices, 4);
       index = temp[0];
     }
   }
   if ((effect & DND.FEEDBACK_SCROLL) == 0) {
     scrollBeginTime = 0;
     scrollIndex = -1;
   } else {
     if (index != -1 && scrollIndex == index && scrollBeginTime != 0) {
       if (System.currentTimeMillis() >= scrollBeginTime) {
         if (coordinates.y < table.getItemHeight()) {
           OS.gtk_tree_path_prev(path[0]);
         } else {
           OS.gtk_tree_path_next(path[0]);
         }
         if (path[0] != 0) {
           OS.gtk_tree_view_scroll_to_cell(handle, path[0], 0, false, 0, 0);
           OS.gtk_tree_path_free(path[0]);
           path[0] = 0;
           OS.gtk_tree_view_get_path_at_pos(
               handle, coordinates.x, coordinates.y, path, null, null, null);
         }
         scrollBeginTime = 0;
         scrollIndex = -1;
       }
     } else {
       scrollBeginTime = System.currentTimeMillis() + SCROLL_HYSTERESIS;
       scrollIndex = index;
     }
   }
   if (path[0] != 0) {
     int position = 0;
     if ((effect & DND.FEEDBACK_SELECT) != 0) position = OS.GTK_TREE_VIEW_DROP_INTO_OR_BEFORE;
     // if ((effect & DND.FEEDBACK_INSERT_BEFORE) != 0) position = OS.GTK_TREE_VIEW_DROP_BEFORE;
     // if ((effect & DND.FEEDBACK_INSERT_AFTER) != 0) position = OS.GTK_TREE_VIEW_DROP_AFTER;
     if (position != 0) {
       OS.gtk_tree_view_set_drag_dest_row(handle, path[0], OS.GTK_TREE_VIEW_DROP_INTO_OR_BEFORE);
     } else {
       OS.gtk_tree_view_set_drag_dest_row(handle, 0, OS.GTK_TREE_VIEW_DROP_BEFORE);
     }
   } else {
     OS.gtk_tree_view_set_drag_dest_row(handle, 0, OS.GTK_TREE_VIEW_DROP_BEFORE);
   }
   if (path[0] != 0) OS.gtk_tree_path_free(path[0]);
 }
Exemplo n.º 8
0
 @Override
 long /*int*/ gtk_event_after(long /*int*/ widget, long /*int*/ gdkEvent) {
   long /*int*/ result = super.gtk_event_after(widget, gdkEvent);
   GdkEvent event = new GdkEvent();
   OS.memmove(event, gdkEvent, GdkEvent.sizeof);
   switch (event.type) {
     case OS.GDK_FOCUS_CHANGE:
       redraw();
       break;
   }
   return result;
 }
Exemplo n.º 9
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);
 }
Exemplo n.º 10
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));
 }
Exemplo n.º 11
0
 @Override
 long /*int*/ gtk_button_press_event(long /*int*/ widget, long /*int*/ event) {
   long /*int*/ result = super.gtk_button_press_event(widget, event);
   if (result != 0) return result;
   GdkEventButton gdkEvent = new GdkEventButton();
   OS.memmove(gdkEvent, event, GdkEventButton.sizeof);
   if (gdkEvent.button == 1 && gdkEvent.type == OS.GDK_BUTTON_PRESS) {
     if (focusIndex != -1) setFocus();
     int x = (int) gdkEvent.x;
     int y = (int) gdkEvent.y;
     if ((style & SWT.MIRRORED) != 0) x = getClientWidth() - x;
     int offset = layout.getOffset(x, y, null);
     int oldSelectionX = selection.x;
     int oldSelectionY = selection.y;
     selection.x = offset;
     selection.y = -1;
     if (oldSelectionX != -1 && oldSelectionY != -1) {
       if (oldSelectionX > oldSelectionY) {
         int temp = oldSelectionX;
         oldSelectionX = oldSelectionY;
         oldSelectionY = temp;
       }
       Rectangle rect = layout.getBounds(oldSelectionX, oldSelectionY);
       redraw(rect.x, rect.y, rect.width, rect.height, false);
     }
     for (int j = 0; j < offsets.length; j++) {
       Rectangle[] rects = getRectangles(j);
       for (int i = 0; i < rects.length; i++) {
         Rectangle rect = rects[i];
         if (rect.contains(x, y)) {
           focusIndex = j;
           redraw();
           return result;
         }
       }
     }
   }
   return result;
 }
Exemplo n.º 12
0
 @Override
 long /*int*/ gtk_motion_notify_event(long /*int*/ widget, long /*int*/ event) {
   long /*int*/ result = super.gtk_motion_notify_event(widget, event);
   if (result != 0) return result;
   GdkEventMotion gdkEvent = new GdkEventMotion();
   OS.memmove(gdkEvent, event, GdkEventMotion.sizeof);
   int x = (int) gdkEvent.x;
   int y = (int) gdkEvent.y;
   if ((style & SWT.MIRRORED) != 0) x = getClientWidth() - x;
   if ((gdkEvent.state & OS.GDK_BUTTON1_MASK) != 0) {
     int oldSelection = selection.y;
     selection.y = layout.getOffset(x, y, null);
     if (selection.y != oldSelection) {
       int newSelection = selection.y;
       if (oldSelection > newSelection) {
         int temp = oldSelection;
         oldSelection = newSelection;
         newSelection = temp;
       }
       Rectangle rect = layout.getBounds(oldSelection, newSelection);
       redraw(rect.x, rect.y, rect.width, rect.height, false);
     }
   } else {
     for (int j = 0; j < offsets.length; j++) {
       Rectangle[] rects = getRectangles(j);
       for (int i = 0; i < rects.length; i++) {
         Rectangle rect = rects[i];
         if (rect.contains(x, y)) {
           setCursor(display.getSystemCursor(SWT.CURSOR_HAND));
           return result;
         }
       }
     }
     setCursor(null);
   }
   return result;
 }
Exemplo n.º 13
0
 @Override
 long /*int*/ gtk_button_release_event(long /*int*/ widget, long /*int*/ event) {
   long /*int*/ result = super.gtk_button_release_event(widget, event);
   if (result != 0) return result;
   if (focusIndex == -1) return result;
   GdkEventButton gdkEvent = new GdkEventButton();
   OS.memmove(gdkEvent, event, GdkEventButton.sizeof);
   if (gdkEvent.button == 1) {
     int x = (int) gdkEvent.x;
     int y = (int) gdkEvent.y;
     if ((style & SWT.MIRRORED) != 0) x = getClientWidth() - x;
     Rectangle[] rects = getRectangles(focusIndex);
     for (int i = 0; i < rects.length; i++) {
       Rectangle rect = rects[i];
       if (rect.contains(x, y)) {
         Event ev = new Event();
         ev.text = ids[focusIndex];
         sendSelectionEvent(SWT.Selection, ev, true);
         return result;
       }
     }
   }
   return result;
 }
Exemplo n.º 14
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;
 }