wxWidgets:如何更改 StyledTextCtrl 中的插入符样式(向 scintilla 发送命令)
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你没有写出你正在使用哪个版本的wxPython / wxWidgets,但我假设它是2.8.x版本。 其中包含 Scintilla 版本 1.70,而 SVN 主干(很快将作为 wxWidgets 版本 2.9 发布)具有 Scintilla 版本 1.75。 Scintilla 头文件上的 grep 显示 SCI_GETCARETSTYLE 和 SCI_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.
尝试
Try