< prev index next >

modules/graphics/src/main/java/com/sun/glass/ui/gtk/GtkView.java

Print this page

        

@@ -27,17 +27,19 @@
 import com.sun.glass.ui.Pixels;
 import com.sun.glass.ui.View;
 import java.nio.Buffer;
 import java.nio.ByteBuffer;
 import java.nio.IntBuffer;
+import java.util.ArrayList;
 import java.util.Map;
 
 final class GtkView extends View {
     
     private boolean imEnabled = false;
     private boolean isInPreeditMode = false;
     private final StringBuilder preedit = new StringBuilder();
+    private ByteBuffer attributes;
     private int lastCaret;
 
     private native void enableInputMethodEventsImpl(long ptr, boolean enable);
 
     @Override

@@ -115,17 +117,80 @@
 
     private void notifyPreeditMode(boolean enabled){
         isInPreeditMode = enabled;
     }
 
-    protected void notifyInputMethodDraw(String text, int first, int length, int caret) {
+
+    protected void notifyInputMethodDraw(String text, int first, int length, int caret, byte[] attr) {
+        int[] boundary = null;
+        byte[] values = null;
+
+        if (attributes == null ) {
+            attributes = ByteBuffer.allocate(32);
+        }
+
+        if (length > 0) {
+            preedit.replace(first, first + length, "");
+        }
+
         if (text != null) {
-            preedit.replace(first, first + length, text);
+            preedit.insert(first, text);
         } else {
+            if (attr == null) {
             preedit.setLength(0);
         }
-        notifyInputMethod(preedit.toString(), null, null, null, 0, caret, 0);
+        }
+
+        if (attributes.capacity() < preedit.length()) {
+            ByteBuffer tmp  = ByteBuffer.allocate((int) (preedit.length() * 1.5));
+            tmp.put(attributes);
+            attributes = tmp;
+        }
+
+        attributes.limit(preedit.length());
+
+        if (attr != null && attributes.limit() >= (first + attr.length)) {
+            attributes.position(first);
+            attributes.put(attr);
+        }
+                    
+        if (attributes.limit() > 0) {
+            ArrayList<Integer> boundaryList = new ArrayList<>();
+            ArrayList<Byte> valuesList = new ArrayList<>();
+            attributes.rewind();
+            byte lastAttribute = attributes.get();
+
+            boundaryList.add(0);
+            valuesList.add(lastAttribute);
+
+            int i = 1;
+            while (attributes.hasRemaining()) {
+                byte a = attributes.get();
+                if (lastAttribute != a) {
+                    boundaryList.add(i);
+                    valuesList.add(a);
+                }
+                lastAttribute = a;
+                i++;
+            }
+
+            boundaryList.add(attributes.limit());
+
+            boundary = new int[boundaryList.size()];
+            i = 0;
+            for (Integer e : boundaryList) {
+                boundary[i++] = e;
+            }
+
+            values = new byte[valuesList.size()];
+            i = 0;
+            for (Byte e: valuesList) {
+                values[i++] = e;
+            }
+        }
+
+        notifyInputMethod(preedit.toString(), boundary, boundary, values, 0, caret, 0);
         lastCaret = caret;
     }
     
     protected void notifyInputMethodCaret(int pos, int direction, int style) {
         switch (direction) {
< prev index next >