Re: wxRichTextCtrl scroll events? Is it possible to capture them?
Tony Kennedy <[email protected]>
| Newsgroups | gmane.comp.lib.wxwindows.general |
|---|---|
| Message-ID | <[email protected]> |
Just in case anyone else wants to do this, I've got some working code below.
Tony.
First, capture all the scroll events during construction.
m_itemRichTextCtrl_OriginalFile->Bind(wxEVT_SCROLLWIN_TOP,
&wxMyPanel::OnOriginalFileScrolled, this);
m_itemRichTextCtrl_OriginalFile->Bind(wxEVT_SCROLLWIN_BOTTOM,
&wxMyPanel::OnOriginalFileScrolled, this);
m_itemRichTextCtrl_OriginalFile->Bind(wxEVT_SCROLLWIN_LINEUP,
&wxMyPanel::OnOriginalFileScrolled, this);
m_itemRichTextCtrl_OriginalFile->Bind(wxEVT_SCROLLWIN_LINEDOWN,
&wxMyPanel::OnOriginalFileScrolled, this);
m_itemRichTextCtrl_OriginalFile->Bind(wxEVT_SCROLLWIN_PAGEUP,
&wxMyPanel::OnOriginalFileScrolled, this);
m_itemRichTextCtrl_OriginalFile->Bind(wxEVT_SCROLLWIN_PAGEDOWN,
&wxMyPanel::OnOriginalFileScrolled, this);
m_itemRichTextCtrl_OriginalFile->Bind(wxEVT_SCROLLWIN_THUMBTRACK,
&wxMyPanel::OnOriginalFileScrolled, this);
m_itemRichTextCtrl_OriginalFile->Bind(wxEVT_SCROLLWIN_THUMBRELEASE,
&wxMyPanel::OnOriginalFileScrolled, this);
m_itemRichTextCtrl_ModifiedFile->Bind(wxEVT_SCROLLWIN_TOP,
&wxMyPanel::OnOriginalFileScrolled, this);
m_itemRichTextCtrl_ModifiedFile->Bind(wxEVT_SCROLLWIN_BOTTOM,
&wxMyPanel::OnModifiedFileScrolled, this);
m_itemRichTextCtrl_ModifiedFile->Bind(wxEVT_SCROLLWIN_LINEUP,
&wxMyPanel::OnModifiedFileScrolled, this);
m_itemRichTextCtrl_ModifiedFile->Bind(wxEVT_SCROLLWIN_LINEDOWN,
&wxMyPanel::OnModifiedFileScrolled, this);
m_itemRichTextCtrl_ModifiedFile->Bind(wxEVT_SCROLLWIN_PAGEUP,
&wxMyPanel::OnModifiedFileScrolled, this);
m_itemRichTextCtrl_ModifiedFile->Bind(wxEVT_SCROLLWIN_PAGEDOWN,
&wxMyPanel::OnModifiedFileScrolled, this);
m_itemRichTextCtrl_ModifiedFile->Bind(wxEVT_SCROLLWIN_THUMBTRACK,
&wxMyPanel::OnModifiedFileScrolled, this);
m_itemRichTextCtrl_ModifiedFile->Bind(wxEVT_SCROLLWIN_THUMBRELEASE,
&wxMyPanel::OnModifiedFileScrolled, this);
Here are the two handlers. The CallAfter is needed as the control being
scrolled has not scrolled yet when these are triggered. If you process
immediately, the other control does not quite scroll enough.
void wxMyPanel ::OnOriginalFileScrolled(wxScrollWinEvent& event)
{
CallAfter(& wxMyPanel ::MatchScrolledRichTextCtrlWindow,
m_itemRichTextCtrl_OriginalFile, m_itemRichTextCtrl_ModifiedFile);
event.Skip();
}
void wxMyPanel ::OnModifiedFileScrolled(wxScrollWinEvent& event)
{
CallAfter(& wxMyPanel
::MatchScrolledRichTextCtrlWindow,m_itemRichTextCtrl_ModifiedFile,
m_itemRichTextCtrl_OriginalFile);
event.Skip();
}
void wxMyPanel ::MatchScrolledRichTextCtrlWindow(wxRichTextCtrl*
pScrolledControl, wxRichTextCtrl* pControlToScroll)
{
int x, y;
pScrolledControl ->GetViewStart(&x, &y);
pControlToScroll ->Scroll(x, y);
pControlToScroll ->Refresh();
}
On Thursday, 5 October 2023 at 16:30:53 UTC+1 Tony Kennedy wrote:
> I've got two wxRichTextCtrl controls that I want to synchronize their
> vertical position.
>
> So now I'm binding to a bunch of scroll events. I catch them ok, and can
> work out the scroll position and set that on the window I want to sync. The
> scroll bar even moves on the linked control, but the contents of the window
> itself does not scroll.
>
> Anyone have any ideas?
>
> Thanks in advance,
>
> Tony.
>
--
Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
---
You received this message because you are subscribed to the Google Groups "wx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/wx-users/ce7259df-e699-4f38-8a0f-f7b573add890n%40googlegroups.com.