是否可以修改Text swt小部件包装单词的方式?

时间:2022-02-03 22:20:20

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

开发平台是Fedora上的Eclipse RCP 3.4(它使用的是Gtk本机组件)。我需要避免自动换行。

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

即:“Hello World”显示为N°1,但我需要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 ?

我已经看到swt Text句柄是用OS.GTK_WRAP_WORD_CHAR包装模式构建的。我想用OS.GTK_WRAP_WORD或OS.GTK_WRAP_NONE这样的常量测试行为,但我不知道如何执行这个奇迹?是否可以通过编程方式修改特定于平台的配置?

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

编辑1 - 我的一位同事提出了一个解决方案:

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 (!shell.isDisposed()) {
         if (!display.readAndDispatch()) {
            display.sleep();
         }
      }
   }
}

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

结果是预期的。我正在寻找http://dev.eclipse.org的解决方案。

1 个解决方案

#1


0  

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.

顺便说一句,即使你可以,将模式设置为OS.GTK_WRAP_WORD和OS.GTK_WRAP_NONE也不会得到你想要的行为,因为第一个在单词之间断开了一行,就像OS.GTK_WRAP_WORD_CHAR一样,而第二个没有断线。您正在寻找的模式是GTK_WRAP_CHAR。但是,OS.GTK_WRAP_CHAR等常量甚至未在org.eclipse.swt.internal.gtk.OS中声明,这表明SWT的创建者可能反对允许这样的行为,即使在理论上也是如此。

#1


0  

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.

顺便说一句,即使你可以,将模式设置为OS.GTK_WRAP_WORD和OS.GTK_WRAP_NONE也不会得到你想要的行为,因为第一个在单词之间断开了一行,就像OS.GTK_WRAP_WORD_CHAR一样,而第二个没有断线。您正在寻找的模式是GTK_WRAP_CHAR。但是,OS.GTK_WRAP_CHAR等常量甚至未在org.eclipse.swt.internal.gtk.OS中声明,这表明SWT的创建者可能反对允许这样的行为,即使在理论上也是如此。