wxWidgets:如何更改 StyledTextCtrl 中的插入符样式(向 scintilla 发送命令)

发布于 2024-07-18 03:03:53 字数 1048 浏览 5 评论 0原文

wxWidgets 有 wxStyledTextCtrl (据我所知)在幕后使用 Scintilla

我对 Scintilla API 不太了解,但我有点知道你向它发出命令。

特别是,我想让光标具有块样式,我在 Notepad++ 中找到了以下代码片段:

execute(SCI_SETCARETSTYLE, CARETSTYLE_BLOCK)

我想在 StyledTextCtrl 中执行相同的操作,但我不知道如何访问场景后面的 scinitilla 控件。

我该怎么做呢?

PS 我正在 wxPython 中工作,但我认为这没有什么区别。

更新:

在深入研究 wxWidgets 的 C++ 源代码后,我发现大多数函数只是调用 SendMsg,例如:

// Get the time in milliseconds that the caret is on and off. 0 = steady on.
void wxStyledTextCtrl::SetCaretPeriod(int periodMilliseconds)
{
    SendMsg(2076, periodMilliseconds, 0);
}

所以我认为这就是向底层 scintilla 组件发送命令的方式。

所以,我得到了我需要的值

#define CARETSTYLE_INVISIBLE 0
#define CARETSTYLE_LINE 1
#define CARETSTYLE_BLOCK 2
#define SCI_SETCARETSTYLE 2512
#define SCI_GETCARETSTYLE 2513

所以SCI_SETCARETSTYLE是2512,块样式是2。

所以我用这些参数调用了SengMsg

self.SendMsg(2512, 2)

但似乎没有任何影响!

可能是什么原因? 我该如何调试这个?

wxWidgets has wxStyledTextCtrl which (as I understand) uses Scintilla behind the scenes

I don't know much about Scintilla API, but I kinda have the idea that you issue commands to it.

In particular, I want to make the cursor have a block style, I found in Notepad++ the following snippet:

execute(SCI_SETCARETSTYLE, CARETSTYLE_BLOCK)

I want to do the same in the StyledTextCtrl, but I have no idea how to get to the scinitilla control behind the scene.

How do I do this?

P.S. I'm working in wxPython, but I suppose it doesn't make a difference.

Update:

After some digging in the c++ sources of wxWidgets, I found that most functions just call SendMsg, for instance:

// Get the time in milliseconds that the caret is on and off. 0 = steady on.
void wxStyledTextCtrl::SetCaretPeriod(int periodMilliseconds)
{
    SendMsg(2076, periodMilliseconds, 0);
}

So I figured that this is how one would send commands to the underlying scintilla component.

So, I got the values I need

#define CARETSTYLE_INVISIBLE 0
#define CARETSTYLE_LINE 1
#define CARETSTYLE_BLOCK 2
#define SCI_SETCARETSTYLE 2512
#define SCI_GETCARETSTYLE 2513

So SCI_SETCARETSTYLE is 2512, and block style is 2.

So I called SengMsg with these parameters:

self.SendMsg(2512, 2)

But there didn't seem to be any effect!

What could be the reason? How can I debug this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

○闲身 2024-07-25 03:03:53

你没有写出你正在使用哪个版本的wxPython / wxWidgets,但我假设它是2.8.x版本。 其中包含 Scintilla 版本 1.70,而 SVN 主干(很快将作为 wxWidgets 版本 2.9 发布)具有 Scintilla 版本 1.75。 Scintilla 头文件上的 grep 显示 SCI_GETCARETSTYLESCI_SETCARETSTYLE 仅在 wxWidgets 主干中,因此这些消息根本不会在wxWidgets 2.8。

You don't write which version of wxPython / wxWidgets you are using, but I assume that it is the 2.8.x version. This contains Scintilla version 1.70, while the SVN trunk (soon to be released as wxWidgets version 2.9) has Scintilla version 1.75. A grep over the Scintilla header files reveals that SCI_GETCARETSTYLE and SCI_SETCARETSTYLE are only in the wxWidgets trunk, so those messages will not be handled at all in wxWidgets 2.8.

似最初 2024-07-25 03:03:53

尝试

self.SendMsg(msg=2512, lp=2)

Try

self.SendMsg(msg=2512, lp=2)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文