示例#1
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;
 }
示例#2
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;
 }
示例#3
0
 LRESULT wmNotifyChild(NMHDR hdr, int /*long*/ wParam, int /*long*/ lParam) {
   if (OS.COMCTL32_MAJOR >= 6) {
     switch (hdr.code) {
       case OS.NM_RETURN:
       case OS.NM_CLICK:
         NMLINK item = new NMLINK();
         OS.MoveMemory(item, lParam, NMLINK.sizeof);
         Event event = new Event();
         event.text = ids[item.iLink];
         sendSelectionEvent(SWT.Selection, event, true);
         break;
     }
   }
   return super.wmNotifyChild(hdr, wParam, lParam);
 }
示例#4
0
 LRESULT WM_CHAR(int /*long*/ wParam, int /*long*/ lParam) {
   LRESULT result = super.WM_CHAR(wParam, lParam);
   if (result != null) return result;
   if (OS.COMCTL32_MAJOR < 6) {
     if (focusIndex == -1) return result;
     switch ((int) /*64*/ wParam) {
       case ' ':
       case SWT.CR:
         Event event = new Event();
         event.text = ids[focusIndex];
         sendSelectionEvent(SWT.Selection, event, true);
         break;
       case SWT.TAB:
         boolean next = OS.GetKeyState(OS.VK_SHIFT) >= 0;
         if (next) {
           if (focusIndex < offsets.length - 1) {
             focusIndex++;
             redraw();
           }
         } else {
           if (focusIndex > 0) {
             focusIndex--;
             redraw();
           }
         }
         break;
     }
   } else {
     switch ((int) /*64*/ wParam) {
       case ' ':
       case SWT.CR:
       case SWT.TAB:
         /*
          * NOTE: Call the window proc with WM_KEYDOWN rather than WM_CHAR
          * so that the key that was ignored during WM_KEYDOWN is processed.
          * This allows the application to cancel an operation that is normally
          * performed in WM_KEYDOWN from WM_CHAR.
          */
         int /*long*/ code = callWindowProc(handle, OS.WM_KEYDOWN, wParam, lParam);
         return new LRESULT(code);
     }
   }
   return result;
 }
示例#5
0
 LRESULT WM_LBUTTONUP(int /*long*/ wParam, int /*long*/ lParam) {
   LRESULT result = super.WM_LBUTTONUP(wParam, lParam);
   if (result == LRESULT.ZERO) return result;
   if (OS.COMCTL32_MAJOR < 6) {
     if (mouseDownIndex == -1) return result;
     int x = OS.GET_X_LPARAM(lParam);
     int y = OS.GET_Y_LPARAM(lParam);
     Rectangle[] rects = getRectangles(mouseDownIndex);
     for (int i = 0; i < rects.length; i++) {
       Rectangle rect = rects[i];
       if (rect.contains(x, y)) {
         Event event = new Event();
         event.text = ids[mouseDownIndex];
         sendSelectionEvent(SWT.Selection, event, true);
         break;
       }
     }
   }
   mouseDownIndex = -1;
   return result;
 }
示例#6
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;
 }
示例#7
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;
 }