开发者

Is it possible to modify how Text swt widget wrap word?

The development platform is an Eclipse RCP 3.4 on Fedora (It's using Gtk native component). I need to avoid word wrapping.

i.e.: "Hello World" is displayed as case N°1 but I need the case N°2.

1|Hello    |    2|Hello Wor|
 |World    |     |ld       |

Is there a simple solution ?

I've seen that swt Text handle is build with OS.GTK_WRAP_WORD_CHAR wrap mode. I would like to test the behaviour with constant like OS.GTK_WRAP_WORD or OS.GTK_WRAP_NONE but I don't know how to perform this miracle ? Is it possible to modify platform specific configuration programmatically ?

EDIT 1 - There is a solution from one of my colleagues:

import org.eclipse.swt.SWT;
import org.eclipse.swt.internal.gtk.OS;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class SampleGrabExcess {
   public static void main(String[] args) {
      Display display = new Display();
      Shell shell = new Shell(display);
      shell.setLayout(new GridLayout());
      shell.setSize(70, 70);

      GridData gridData = new GridData();
      Text addressText = new Text(shell, SWT.BORDER | SWT.MULTI) {
         @Override
         protected void checkSubclass() {}

         @Override
         protected void checkWidget() {
            OS.gtk_text_view_set_wrap_mode(handle, 1);
            super.checkWidget();
         }

      };
      gridData = new GridData();
      gridData.horizontalAlignment = SWT.FILL;
      gridData.grabExcessHorizontalSpace = true;
      gridData.verticalAlignment = SWT.FILL;
      gridData.grabExcessVerticalSpace = true;
      addressText.setLayoutData(gridData);
      addressText.setText("Hello World.");

      shell.open();

      while (!shel开发者_Go百科l.isDisposed()) {
         if (!display.readAndDispatch()) {
            display.sleep();
         }
      }
   }
}

The result is that expected. I'm looking for a solution from http://dev.eclipse.org.


No, I don't see how you could do that.

Btw, even if you could, setting the mode to OS.GTK_WRAP_WORD and OS.GTK_WRAP_NONE wouldn't get you the desired behaviour, since the first one breaks line in between words, just like OS.GTK_WRAP_WORD_CHAR, and the second one doesn't break lines at all. The mode you're looking for is GTK_WRAP_CHAR. However, the fact that a constant such as OS.GTK_WRAP_CHAR isn't even declared in org.eclipse.swt.internal.gtk.OS indicates that the creators of SWT were probably against allowing such behaviour, even in theory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜