Recent

Author Topic: Synedit question (porting delphi app)  (Read 8004 times)

snorkel

  • Hero Member
  • *****
  • Posts: 789
Synedit question (porting delphi app)
« on: October 05, 2012, 04:51:56 pm »
Hi,
I am porting a delphi app that uses synapse and the Lazarus version is missing BufferToDisplayPos.  Anyone know if the Lazarus version can do this?

Also in the BufferToDisplayPos function is a reference to a WordWrapPlugin which does not seem to exist in Lazarus Synedit.

I am trying to port the search and replace demo from the Delphi version of Synapse.
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 1.8 and FPC 3.0.4
OS: Windows 10 64 bit

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5621
    • wiki
Re: Synedit question (porting delphi app)
« Reply #1 on: October 05, 2012, 05:07:16 pm »
Maybe CharIndexToRowCol from TSynMemo?
TSynMemo is kind of deprecated, it is more or less a copy, with 4 added functions....

Note the Column is the byte in text. That differs from the pos on sreen (tab= 1 byte, but several pos on screen / utf8 = several byte, but 1 pos / full width char...)
See LogicalToPhysical


WordWrap is not yet implemented.

There is a port of the original SynEdit. But I know little about it.
http://wiki.lazarus.freepascal.org/SynEdit#Synedit_2.0.5_port

snorkel

  • Hero Member
  • *****
  • Posts: 789
Re: Synedit question (porting delphi app)
« Reply #2 on: October 05, 2012, 05:11:09 pm »
Hi Martin,
The actual line I am having issue with is:

APos := SynEditor.ClientToScreen(SynEditor.RowColumnToPixels(SynEditor.BufferToDisplayPos(BufferCoord(Column, Line) ) ) );

It gets the screen cursor position so the replace prompt dialog displays under the word to be replaced.
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 1.8 and FPC 3.0.4
OS: Windows 10 64 bit

snorkel

  • Hero Member
  • *****
  • Posts: 789
Re: Synedit question (porting delphi app)
« Reply #3 on: October 05, 2012, 05:24:00 pm »
Hey, I got it working :-)

apos:= editor.ClientToScreen(Editor.RowColumnToPixels(editor.BlockBegin));

I thought hey it's selecting the word to be replaced and saw the BlockBegin returns a tpoint, so I tried it and it works exactly the same.
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 1.8 and FPC 3.0.4
OS: Windows 10 64 bit

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5621
    • wiki
Re: Synedit question (porting delphi app)
« Reply #4 on: October 05, 2012, 05:31:31 pm »
Afaik RowColumnToPixels takes a ScreenPos (called Physical)

BlockBegin is "Logical" that is bytePos. So I a mno sure this works, if there are tabs, or accented chars....

CaretXY is "Physical" (sreenpos)

Or try LogicalToPhysical(BlockBegin)

Also test, if horiz scrolled

snorkel

  • Hero Member
  • *****
  • Posts: 789
Re: Synedit question (porting delphi app)
« Reply #5 on: October 05, 2012, 06:10:07 pm »
hmm, it works exactly like the delphi one using BlockBegin, I tested it and it moves the prompt dialog perfectly vertically and horizontally and positions it right under the selected word.
I will test it some more and if I see issues I will try some of the suggestions, but for my purposes it seems to be working fine.
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 1.8 and FPC 3.0.4
OS: Windows 10 64 bit

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7431
Re: Synedit question (porting delphi app)
« Reply #6 on: October 05, 2012, 06:21:02 pm »
Use some accented chars.

snorkel

  • Hero Member
  • *****
  • Posts: 789
Re: Synedit question (porting delphi app)
« Reply #7 on: October 05, 2012, 06:32:22 pm »
Tried it with propósito and it worked fine also worked fine with tabs in the text.
« Last Edit: October 05, 2012, 06:34:11 pm by snorkel »
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 1.8 and FPC 3.0.4
OS: Windows 10 64 bit

snorkel

  • Hero Member
  • *****
  • Posts: 789
Re: Synedit question (porting delphi app)
« Reply #8 on: October 05, 2012, 06:36:18 pm »
Should I post the converted demo project so you guys can see it all? 
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 1.8 and FPC 3.0.4
OS: Windows 10 64 bit

snorkel

  • Hero Member
  • *****
  • Posts: 789
Re: Synedit question (porting delphi app)
« Reply #9 on: October 05, 2012, 06:41:35 pm »
I tried it with CaretXY, but it puts the left edge of the dialog at the end of the selected word instead of the beginning of the selected block.
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 1.8 and FPC 3.0.4
OS: Windows 10 64 bit

snorkel

  • Hero Member
  • *****
  • Posts: 789
Re: Synedit question (porting delphi app)
« Reply #10 on: October 05, 2012, 06:49:03 pm »
ok, I looked at the source and it works because
RowColumnToPixels converts the text screen pos to the client area coordinate.
So using blockbegin should be fine for getting the demo to work.

function TCustomSynEdit.RowColumnToPixels(RowCol: TPoint): TPoint;
// converts screen position (1,1) based
// to client area coordinate (0,0 based on canvas)   
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 1.8 and FPC 3.0.4
OS: Windows 10 64 bit

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5621
    • wiki
Re: Synedit question (porting delphi app)
« Reply #11 on: October 05, 2012, 07:55:22 pm »
function TCustomSynEdit.RowColumnToPixels(RowCol: TPoint): TPoint;
// converts screen position (1,1) based
// to client area coordinate (0,0 based on canvas)

And again: BlockBegin is not the screen pos, not always

Code: [Select]
ÖÖÖ SelectMe
The screen pos are as follows
Code: [Select]
1 Ö 2 Ö 3 Ö 4 space 5 SelectMe

But an "Ö" is 2 bytes.

If BlockBegin is at the "S" (including the "S" in the selection) then BlockBegin.x = 8.

---

Same with tab
Code: [Select]
--->SelectMe
"--->" is one tab, with a tabwidth of 4.
If BlockBegin is at the "S"  then BlockBegin.x = 2 (tab is only 1 byte (#9)). But you can see you need a value of 4.

SynEdit.LogicalToPhysicalPos( SynEdit.BlockBegin ) gives the correct point.

snorkel

  • Hero Member
  • *****
  • Posts: 789
Re: Synedit question (porting delphi app)
« Reply #12 on: October 05, 2012, 08:04:32 pm »
yep, tested with those chars it moves the start pos of the dialog over a bit on the replace word.

changed it to:

apos:= editor.ClientToScreen(Editor.RowColumnToPixels(editor.LogicalToPhysicalPos(editor.BlockBegin)));

Thanks for helping me with this.

Snorkel
« Last Edit: October 05, 2012, 08:12:29 pm by snorkel »
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 1.8 and FPC 3.0.4
OS: Windows 10 64 bit