简体   繁体   English

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

[英]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). 开发平台是Fedora上的Eclipse RCP 3.4(它使用的是Gtk本机组件)。 I need to avoid word wrapping. 我需要避免自我包装。

ie: "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. 我已经看到swt Text句柄是用OS.GTK_WRAP_WORD_CHAR包装模式构建的。 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 ? 我想用OS.GTK_WRAP_WORDOS.GTK_WRAP_NONE这样的常量测试行为,但我不知道如何执行这个奇迹? Is it possible to modify platform specific configuration programmatically ? 是否可以通过编程方式修改特定于平台的配置?

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的解决方案。

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. 顺便说一句,即使你可以,将模式设置为OS.GTK_WRAP_WORD和OS.GTK_WRAP_NONE也不会得到你想要的行为,因为第一个断开了单词之间的界限,就像OS.GTK_WRAP_WORD_CHAR一样,第二个没有断线。 The mode you're looking for is GTK_WRAP_CHAR. 您正在寻找的模式是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_CHAR等常量甚至未在org.eclipse.swt.internal.gtk.OS中声明,这表明SWT的创建者可能反对允许这种行为,即使在理论上也是如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM