Recent

Author Topic: scrolling Tmemos simultaneously ?  (Read 3064 times)

Etienne_L

  • Newbie
  • Posts: 1
scrolling Tmemos simultaneously ?
« on: October 03, 2024, 03:15:29 pm »
Hi all,

I would like two Tmemos to scroll simultaneously  ( to move in a text and a translation ).

Could be
- catching scrolling events in one Tmemo and propagate them to the other ?
- programmatically setting the starting position of the visible part of the text in the Tmemos, in an event handler of an external, master scrollbar ?

I tried, but did not succeded. Thanks for hints !

Etienne

P.S. Target are windows and linux, but just one platform would already be good help.

wizzwizz4

  • New Member
  • *
  • Posts: 20
Re: scrolling Tmemos simultaneously ?
« Reply #1 on: October 03, 2024, 06:16:05 pm »
In idiomatic Tcl/Tk, you would solve this by putting both Tmemos in a frame, expanded vertically so they fill all available space (and increase the frame's bounding box as necessary), and attaching a scrollbar to it in the usual manner. Is that approach possible here? Maybe with a TScrollBox?

programmatically setting the starting position of the visible part of the text in the Tmemos, in an event handler of an external, master scrollbar ?

If you take this approach, you also need to set the height of the external scrollbar to the height of the Tmemos if/when that changes. If they have different heights to each other, you need a way to reconcile them: maybe taking the maximum? Depends what you're trying to achieve.

wizzwizz4

  • New Member
  • *
  • Posts: 20
Re: scrolling Tmemos simultaneously ?
« Reply #2 on: October 05, 2024, 04:49:06 pm »
This feature is implemented in kdiff3, a Qt program written in C++. You might be able to re-use the design. I think the relevant file is difftextwindow.cpp.

Joanna from IRC

  • Hero Member
  • *****
  • Posts: 1173
Re: scrolling Tmemos simultaneously ?
« Reply #3 on: October 05, 2024, 05:20:52 pm »
I believe the original poster who has abandoned thread was asking about tmemo lcl controls in Lazarus
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

MarkMLl

  • Hero Member
  • *****
  • Posts: 7859
Re: scrolling Tmemos simultaneously ?
« Reply #4 on: October 05, 2024, 06:32:03 pm »
I believe the original poster who has abandoned thread was asking about tmemo lcl controls in Lazarus

I suggest not jumping to that sort of conclusion prematurely, since he might merely be waiting for an answer he understands.

The suggestion of referring to a C++ file in extremis is entirely valid, in the absence of other suggestions.

I've done a little bit of manipulation of TMemo/TRichMemo positioning (in the context of /preventing/ it from tracking program-initiated inserts) but in no way consider myself an expert. In the interest of providing /something/ which might possibly be useful some of the relevant stuff is at https://forum.lazarus.freepascal.org/index.php/topic,67337.msg519191.html#msg519191

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

TRon

  • Hero Member
  • *****
  • Posts: 3453
Re: scrolling Tmemos simultaneously ?
« Reply #5 on: October 05, 2024, 09:33:53 pm »
The suggestion of referring to a C++ file in extremis is entirely valid, in the absence of other suggestions.

Indeed but unfortunately those are not very helpful either (other than showing us that it can be done). The diff viewer in double commander (which is written in laz/fpc) does it as well (I haven't looked at its code yet) but those are probably not tmemo's.

The main problem is making it work cross-platform (doing it for windows has many online examples and is fairly simple to accomplish) and I seem unable to 'catch' the scroll-message(s) by using the default hack trickery and adding the scroll-message methods. TMemo uses its own custom scrollbar class so perhaps I overlooked something or am required to overload the Tmemo message-loop itself entirely. I was also unable to locate any relevant example on the forum and/or wiki (specifically aimed for tmemo).
« Last Edit: October 05, 2024, 09:47:12 pm by TRon »
This tagline is powered by AI

MarkMLl

  • Hero Member
  • *****
  • Posts: 7859
Re: scrolling Tmemos simultaneously ?
« Reply #6 on: October 05, 2024, 10:22:50 pm »
Meld is another, albeit Python :-/

The main problem is making it work cross-platform (doing it for windows has many online examples and is fairly simple to accomplish) and I seem unable to 'catch' the scroll-message(s) by using the default hack trickery and adding the scroll-message methods. TMemo uses its own custom scrollbar class so perhaps I overlooked something or am required to overload the Tmemo message-loop itself entirely. I was also unable to locate any relevant example on the forum and/or wiki (specifically aimed for tmemo).

I was assuming that something like using an external scrollbar to drive the two memos' carets would do the job, but going back and reading OP's "...to move in a text and a translation..." suggests that it's rather more than scrolling since a good translation might reorder fairly large chunks to make the result idiomatic (which again highlights Meld, which is good at such things).

I note that the Wikipedia article on text comparison utilities mentions one being available in the Lazarus IDE (which I don't think I've investigated), but I don't know whether that scrolls two panes: in any event my comment above applies. Updated: it doesn't, it displays diff output in a single pane.

MarkMLl
« Last Edit: October 06, 2024, 08:52:54 am by MarkMLl »
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

TRon

  • Hero Member
  • *****
  • Posts: 3453
Re: scrolling Tmemos simultaneously ?
« Reply #7 on: October 05, 2024, 10:26:48 pm »
You are right MarkMLI,

I overlooked that what you emphasized and instead focused on the part "catching scrolling events in one Tmemo and propagate them to the other ? "

Now, the example you linked to makes much more sense  :)
This tagline is powered by AI

MarkMLl

  • Hero Member
  • *****
  • Posts: 7859
Re: scrolling Tmemos simultaneously ?
« Reply #8 on: October 05, 2024, 11:07:38 pm »
Now, the example you linked to makes much more sense  :)

I admit to having a bit of a soft spot for Meld, although I use it rarely. In order to be able to handle reordered text it uses an algorithm by... dagnabbit, can't remember his name but he made himself very unpopular by patenting it and then being a high-profile shill for the "software is patentable" crowd.

The first time I came across this was in about 1990, when I read an implementation coded directly from the original ACM paper. It included the memorable words:

CAUTION: Well-commented code follows. Programmer does not understand what he is doing.

MarkMLl

Updated: Paul Heckel https://dl.acm.org/doi/pdf/10.1145/359460.359467
« Last Edit: October 06, 2024, 08:38:53 am by MarkMLl »
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Joanna from IRC

  • Hero Member
  • *****
  • Posts: 1173
Re: scrolling Tmemos simultaneously ?
« Reply #9 on: October 05, 2024, 11:58:55 pm »
It should be possible to set the tmemo.vertscrollbar.position however I’m not sure how to detect scrolling because I can’t find my o scroll event for either tmemo or its scroll bar. Unless the ondraw or on mousemove events would be used for this. It’s strange that tmemo doesn’t have an on scroll event.
« Last Edit: October 06, 2024, 12:04:31 am by Joanna »
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

VisualLab

  • Hero Member
  • *****
  • Posts: 518
Re: scrolling Tmemos simultaneously ?
« Reply #10 on: October 06, 2024, 12:32:06 am »
In idiomatic Tcl/Tk, you would solve this by putting both Tmemos in a frame, expanded vertically so they fill all available space (and increase the frame's bounding box as necessary), and attaching a scrollbar to it in the usual manner. Is that approach possible here? Maybe with a TScrollBox?

Exactly. That's what TScrollBox is for. It's a matter of setting the height of both TMemo controls (the source text and the translated text) so that the contents of both internal TMemo components scroll evenly. But this is a rather inelegant and makeshift solution.

This feature is implemented in kdiff3, a Qt program written in C++. You might be able to re-use the design. I think the relevant file is difftextwindow.cpp.

In this case, it is rather a control class specially prepared for this purpose that is used. A similar solution is used in NetBeans to visualize differences between two files (but it is Java code). I also remember that about 10 years ago I came across a program written in Delphi, which was used to compare PAS files. It is possible that somewhere in the depths of the Internet there is available the code of the control used in this program.

MarkMLl

  • Hero Member
  • *****
  • Posts: 7859
Re: scrolling Tmemos simultaneously ?
« Reply #11 on: October 06, 2024, 12:50:25 am »
It should be possible to set the tmemo.vertscrollbar.position however I’m not sure how to detect scrolling because I can’t find my o scroll event for either tmemo or its scroll bar. Unless the ondraw or on mousemove events would be used for this. It’s strange that tmemo doesn’t have an on scroll event.

It might be possible to "surface" something from a superclass.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

dbannon

  • Hero Member
  • *****
  • Posts: 3147
    • tomboy-ng, a rewrite of the classic Tomboy
Re: scrolling Tmemos simultaneously ?
« Reply #12 on: October 06, 2024, 05:57:35 am »
You cannot be sure that a translation will use the same number of lines as the original. So, I don't think having an external "scroll control" and applying it to both tmemos or make one a slave to the other's scrolling would work. As you scroll down, they will get out of sync.

You need a key or token in both in the content and drive the second TMemo to display the same token. But doing that unobtrusively will not be easy. Using KMemo (or, maybe TRichMemo) would allow you to embed invisible tokens between, for example, paragraphs. But big paragraphs ...

I am guessing that the user expects to type into one or both TMemos ? And could delete a token...

If both are read-only, easy, just put a "para 1" token between every para, ugly but effective. I would not use it !

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

VisualLab

  • Hero Member
  • *****
  • Posts: 518
Re: scrolling Tmemos simultaneously ?
« Reply #13 on: October 06, 2024, 12:55:46 pm »
You cannot be sure that a translation will use the same number of lines as the original. So, I don't think having an external "scroll control" and applying it to both tmemos or make one a slave to the other's scrolling would work. As you scroll down, they will get out of sync.

You need a key or token in both in the content and drive the second TMemo to display the same token. But doing that unobtrusively will not be easy. Using KMemo (or, maybe TRichMemo) would allow you to embed invisible tokens between, for example, paragraphs. But big paragraphs ...

I am guessing that the user expects to type into one or both TMemos ? And could delete a token...

If both are read-only, easy, just put a "para 1" token between every para, ugly but effective. I would not use it !

Davo

Based on your idea, I came up with an idea (quickly) to create my own classes (2):
  • a data container (component) that stores the content (original and translation) and tokens associated with it,
  • a display field (control) consisting of 2 vertical sections (original, translation) of the content visualization,
  • each of the 2 content visualization sections is a view that retrieves content from the container, displays only text but is aware of tokens,
  • the display field (control) contains a vertical synchronous content scroll bar that uses tokens.
Of course, the given idea has some drawbacks. For example, when the user removes a piece of content from one or the other section, you need to take care of correct updating of tokens and the scroll bar.

This is a rather time-consuming solution and requires some experience in writing controls.

Joanna from IRC

  • Hero Member
  • *****
  • Posts: 1173
Re: scrolling Tmemos simultaneously ?
« Reply #14 on: October 06, 2024, 01:06:48 pm »
The problem of translation not having same number of lines could be solved by adding extra line to translation or original. 

It seems that this would only be a good for readonly memos . Also is there a way to track what the index of first visible string in memo. Another thing, it’s possible that there are no line breaks but text wrapping and the whole thing could be one string?
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

 

TinyPortal © 2005-2018