How to get/set caret position? SOLVED
Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan
Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.
When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.
When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
How to get/set caret position?
When the text selection tool is enabled it is possible to place a caret in the document view.
Is it possible to get/set the position of this caret?
Just to avoid potential confusion, I'm not talking about text selection here - which means IPXV_TextSelection / IPXV_PageTextSelection aren't applicable (at least as far as I'm aware).
Is it possible to get/set the position of this caret?
Just to avoid potential confusion, I'm not talking about text selection here - which means IPXV_TextSelection / IPXV_PageTextSelection aren't applicable (at least as far as I'm aware).
- Tracker Supp-Stefan
- Site Admin
- Posts: 17941
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
- Contact:
Re: How to get/set caret position?
Hello Woodgnome,
Is it this caret that you are referring to: If yes - this is placed when the text selection tool is active, and a click is done over a text area.
Then selection with e.g. Shift + arrow keys is possible.
Regards,
Stefan
Is it this caret that you are referring to: If yes - this is placed when the text selection tool is active, and a click is done over a text area.
Then selection with e.g. Shift + arrow keys is possible.
Regards,
Stefan
Re: How to get/set caret position?
Hello Stefan,
Yes, that is the caret I am referring to - but I was hoping for a programmatic approach
Yes, that is the caret I am referring to - but I was hoping for a programmatic approach
-
- User
- Posts: 5522
- Joined: Fri Nov 21, 2014 8:27 am
- Contact:
Re: How to get/set caret position?
Hello Woodgnome,
Please check this topic:
viewtopic.php?f=66&t=28988&p=116014&hil ... on#p116014
Cheers,
Alex
Please check this topic:
viewtopic.php?f=66&t=28988&p=116014&hil ... on#p116014
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Re: How to get/set caret position?
Unfortunately, that does not work with zero-width selection (which is how many application often treat a caret). That's what I meant when I said IPXV_TextSelection / IPXV_PageTextSelection are not applicable.
Here's my sample code if you would like to reproduce:
Calling SelectText(doc, 0, 1, 1) correctly selects the second character on the first page of the document.
Calling SelectText(doc, 0, 1, 0) does absolutely nothing.
As for getting the caret position, same problem with zero-width selection. Sample code:
If there is a zero-width selection textSel.Count is 0 and thus it's not possible to get the IPXV_PageTextSelection object.
SDK version: 7.0.327.1
Here's my sample code if you would like to reproduce:
Code: Select all
public static void SelectText(IPXV_Document doc, uint pageIndex, uint charIndex, uint selectionLength)
{
int nSel = _pxvInst.Str2ID("selection.text");
IPXV_TextSelection textSel = (IPXV_TextSelection)doc.CreateStdSel((uint)nSel);
IPXV_PageTextSelection pts = textSel.GetSel(pageIndex, true);
pts.SelectChars(charIndex, selectionLength, true);
textSel.OnAdd(doc);
textSel.Show(true);
}
Calling SelectText(doc, 0, 1, 0) does absolutely nothing.
As for getting the caret position, same problem with zero-width selection. Sample code:
Code: Select all
public CaretPosition GetCaretPosition(IPXV_Document doc)
{
IPXV_DocSelection docSel = doc.ActiveSel;
if (docSel is IPXV_TextSelection textSel)
{
if (textSel.Count > 0)
{
IPXV_PageTextSelection pts = textSel[0]; // Get the first text selection cluster
pts.GetRange(0, out uint charIndex, out uint selectionLength); // Get firstCharIndex of the selction cluster
return new CaretPosition(pts.PageIndex, charIndex, selectionLength); // charIndex + selectionLength if end of selection is wanted
}
}
return null;
}
SDK version: 7.0.327.1
-
- User
- Posts: 5522
- Joined: Fri Nov 21, 2014 8:27 am
- Contact:
Re: How to get/set caret position?
Hello Woodgnome,
I've forwarded that question to the appropriate developer - he'll look into this when he has time.
Cheers,
Alex
I've forwarded that question to the appropriate developer - he'll look into this when he has time.
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Re: How to get/set caret position?
Any update on this?
Would be nice to know, even if it's just not possible with the current SDK.
Would be nice to know, even if it's just not possible with the current SDK.
-
- User
- Posts: 5522
- Joined: Fri Nov 21, 2014 8:27 am
- Contact:
Re: How to get/set caret position?
Hello Woodgnome,
There are methods like that, though they are not in the SDK. I have added them to the IPXV_TextSelection interface, though this needs to be approved by our lead dev. Once he says that it's OK - I can give you a dev. build dll for testing. For the reference, I've added SetCaretPos and HideCaret methods, so that you would be able to show and hide the caret if needed.
Cheers,
Alex
There are methods like that, though they are not in the SDK. I have added them to the IPXV_TextSelection interface, though this needs to be approved by our lead dev. Once he says that it's OK - I can give you a dev. build dll for testing. For the reference, I've added SetCaretPos and HideCaret methods, so that you would be able to show and hide the caret if needed.
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Re: How to get/set caret position?
Sounds good, I'll keep an eye out.
Will there be a GetCaretPos method as well?
Will there be a GetCaretPos method as well?
-
- User
- Posts: 5522
- Joined: Fri Nov 21, 2014 8:27 am
- Contact:
Re: How to get/set caret position?
Hello Woodgnome,
Yes there also will be a method like that.
Cheers,
Alex
Yes there also will be a method like that.
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
-
- User
- Posts: 5522
- Joined: Fri Nov 21, 2014 8:27 am
- Contact:
Re: How to get/set caret position? SOLVED
Hello Woodgnome,
I've prepared a dev build for you with these methods (note that dev builds are not stable and should not be used for production): Also, here's a code sample on how to use it:
Cheers,
Alex
I've prepared a dev build for you with these methods (note that dev builds are not stable and should not be used for production): Also, here's a code sample on how to use it:
Code: Select all
int nSel = pdfCtl.Inst.Str2ID("selection.text");
IPXV_TextSelection textSel = (IPXV_TextSelection)pdfCtl.Doc.CreateStdSel((uint)nSel);
uint p, l, c = 0;
textSel.GetCaretPos(out p, out l, out c); //all values will be -1
textSel.SetCaretPos(0, 0, 2); //the caret position will be put on 0 page, on 0 line before the 2 character
textSel.GetCaretPos(out p, out l, out c); //this will give 0,0,2 accordingly
textSel.HideCaret();//this will hide the caret
textSel.GetCaretPos(out p, out l, out c);//all values will be -1
pdfCtl.Doc.ActiveSel = textSel;//the active selection will be replaced with new caret pos
textSel.Show(true);
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Re: How to get/set caret position?
Just tested this - a few questions:
It would make more sense that these methods (GetRange() / GetCaretPos() / SetCaretPos()) are consistent with regard to their values/parameters because they are closely related.
Out of the two possibilities (page + character offset / page + line + line character offset) I believe page + character offset is the simpler, because it's hard to define what a line is and how it works (how many lines are there? What is the length of each line? What constitues a new line? A new PDF text command? A line break? Visual position in the document?).
All of those questions would be irrelevant if working with only page + character offset.
- Is it correctly understood that it is not possible to get caret position ("all values will be -1") unless caret position has been set programmatically first?
If so, it's sort of handicapped in that I would like to be able to get the caret position at an arbitrary time. - When working with ranges (IPXV_PageTextSelection.GetRange()) these always use character offsets relative to the entire page. Is it possible to have GetCaretPos()/SetCaretPos() do the same as opposed to line + character offset in the line?
It would make more sense that these methods (GetRange() / GetCaretPos() / SetCaretPos()) are consistent with regard to their values/parameters because they are closely related.
Out of the two possibilities (page + character offset / page + line + line character offset) I believe page + character offset is the simpler, because it's hard to define what a line is and how it works (how many lines are there? What is the length of each line? What constitues a new line? A new PDF text command? A line break? Visual position in the document?).
All of those questions would be irrelevant if working with only page + character offset.
-
- User
- Posts: 5522
- Joined: Fri Nov 21, 2014 8:27 am
- Contact:
Re: How to get/set caret position?
Hello Woodgnome,
1) You will have to obtain the existing IPXV_TextSelection, not create new one - then yes, you can get the existing caret position.
2) Well, you would have to write a small conversion method if you need that representation.
Cheers,
Alex
1) You will have to obtain the existing IPXV_TextSelection, not create new one - then yes, you can get the existing caret position.
2) Well, you would have to write a small conversion method if you need that representation.
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Re: How to get/set caret position?
1) Ah, I can now call GetCaretPos() on the IPXV_TextSelection I obtain in my GetCaretPosition() code sample - great!
2) Ok, so to confirm:
The line/character indices and counts that GetCaretPos()/SetCaretPos() work with are identical to the ones that can be obtained in:
If yes, a few questions for clarification:
2) Ok, so to confirm:
The line/character indices and counts that GetCaretPos()/SetCaretPos() work with are identical to the ones that can be obtained in:
Code: Select all
var pageText =
doc // IPXV_Document
.CoreDoc // IPXC_Document
.Pages[i] // IPXC_Page
.GetText(...); // IPXC_PageText
var lineInfo =
pageText // IPXC_PageText
.LineInfo[j] // PXC_TextLineInfo
- What is the difference between IPXC_PageText.CharCount and IPXC_PageText.CharsCount?
- When creating a IPXC_GetPageTextOptions for use with IPXC_Page.GetText(...), what is the difference between setting nVersion to 1 or 2 (the explanations in the documentation make no sense to me whatsoever)?
- Is the order of IPXC_PageText.LineInfo[lineIndex] the same as when selecting text using the mouse cursor?
-
- User
- Posts: 5522
- Joined: Fri Nov 21, 2014 8:27 am
- Contact:
Re: How to get/set caret position?
Hello Woodgnome,
1) There are several duplicates for that interface - basically the old ones weren't removed because of the policy that someone could have already used them and that could cause some potential errors in project. Basically, some argument types were changed and also the method names - you can use either of them - they all should work correctly.
2) These are two method of the text gathering - first one will be more like the PDF structure is written, the second one will have more visual oriented generation - these can vary from file to file. Basically, you can stick to the second version - should give the needed results for you.
3) Yes, those should be the same lines.
Cheers,
Alex
1) There are several duplicates for that interface - basically the old ones weren't removed because of the policy that someone could have already used them and that could cause some potential errors in project. Basically, some argument types were changed and also the method names - you can use either of them - they all should work correctly.
2) These are two method of the text gathering - first one will be more like the PDF structure is written, the second one will have more visual oriented generation - these can vary from file to file. Basically, you can stick to the second version - should give the needed results for you.
3) Yes, those should be the same lines.
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Re: How to get/set caret position?
Alright, sounds good.
When can we expect the changes to be released in a production build?
When can we expect the changes to be released in a production build?
-
- User
- Posts: 5522
- Joined: Fri Nov 21, 2014 8:27 am
- Contact:
Re: How to get/set caret position?
Hello Woodgnome,
If all goes as planned we will hold the release in a few weeks or so.
Cheers,
Alex
If all goes as planned we will hold the release in a few weeks or so.
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Re: How to get/set caret position?
Cool, looking forward to that
-
- User
- Posts: 5522
- Joined: Fri Nov 21, 2014 8:27 am
- Contact:
Re: How to get/set caret position?
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ