Which Form Field Has Focus?  SOLVED

PDF-XChange Editor SDK for Developers

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.
Post Reply
JSantmann@Wellsoft.com
User
Posts: 9
Joined: Wed Mar 29, 2017 1:36 am

Which Form Field Has Focus?

Post by JSantmann@Wellsoft.com »

Question #1: How can I get a handle to the IPXC_FormField that currently has focus?

----------------------------------------------------------------
Also, I am using IUIX_EventMonitor to capture keystrokes with EnableEventListening set to 'e.beforeShowContextMenu'.

The event handler is:

Function TUIEventMon.OnEventMonitor(Const Obj : IUIX_Obj ; Const pEvent : IUIX_Event) : HResult ; stdcall ;

This event handler provides Obj : IUIX_Obj which oddly contains a reference to the calling/focused field in the third child; Obj.Children[2].

Question #2: Why is it in the third child?

I can use this to get the current field text (Obj.Children[2].Text), but I can not get the field name or other IPXC_FormField information. So...

Question #3: How can I use Obj : IUIX_Obj to get a handle to the form field that evoked the call to OnEventMonitor?

Thanks.
- John
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Which Form Field Has Focus?

Post by Sasha - Tracker Dev Team »

Hello John,

Well that's not the right way of doing this. The correct way would be to listen to the https://sdkhelp.pdf-xchange.com/vi ... or_started event and get the IPXV_TextEditor interface from it. There you can see whether the IPXC_Annotation (that you can get with the Annot property) is a widget annotation and has a https://sdkhelp.pdf-xchange.com/vi ... tion_Field property.
Also, the https://sdkhelp.pdf-xchange.com/vi ... extChanged event would give you the current text from the current text editor.
Note that these events will be called if any text box/edit/combo box/text annotation etc. will be edited - so basically you will have to check whether it's a for field as I told you.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
JSantmann@Wellsoft.com
User
Posts: 9
Joined: Wed Mar 29, 2017 1:36 am

Re: Which Form Field Has Focus?

Post by JSantmann@Wellsoft.com »

Hi Alex,

Thanks for the reply.
Yes, I need to use the active IPXV_TextEditor as follows:
IPXV_TextEditor.Get_Annot ---> Annot.Get_Field
to get the active IPXC_FormField. That's the part I was missing.

However, I think it is easier to get the active IPXV_TextEditor by using IPXV_Document.ActiveTextEditor. This seems to work well.
Am I missing something?
Thanks.
- John
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Which Form Field Has Focus?  SOLVED

Post by Sasha - Tracker Dev Team »

Hello John,

If you are using those events that I previously mentioned then you should get the interface from the parameter - that would assure that you are in the correct document in the correct frame.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
JSantmann@Wellsoft.com
User
Posts: 9
Joined: Wed Mar 29, 2017 1:36 am

Re: Which Form Field Has Focus?

Post by JSantmann@Wellsoft.com »

Actually, here is a much easier/better way to read and write to the active form field (in Delphi code):
Var
PDFEditorXC :TPXV_Control ;
LDoc : IPXV_Document ;
LTextEditor : IPXV_TextEditor ;
LEdit : IUIX_Edit ;
//...
Begin
// create PDFEditorXC

LDoc := PDFEditorXC.Doc ;
LTextEditor := LDoc.ActiveTextEditor ;
If Assigned(LTextEditor) then
Begin
If LTextEditor.Get_EditCtl(LEdit) = S_OK then
If Assigned(LEdit) then
LEdit.Text := 'XXX Hello XXX' ;
End ;
End ;
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Which Form Field Has Focus?

Post by Sasha - Tracker Dev Team »

Hello JSantmann@Wellsoft.com,

Well I don't see how you can possibly get the ActiveTextEditor after the control creation and even after document opening. After you open the document there is no text editor active at all. To see when the text editor is active, you should use the events I mentioned earlier. And again, as I told before:
If you are using those events that I previously mentioned then you should get the interface from the parameter - that would assure that you are in the correct document in the correct frame.
It's not that difficult to cast a few interfaces.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
JSantmann@Wellsoft.com
User
Posts: 9
Joined: Wed Mar 29, 2017 1:36 am

Re: Which Form Field Has Focus?

Post by JSantmann@Wellsoft.com »

Hi Sasha,

Yes, I see your point, but for my particular situation, ActiveTextEditor seems to works fine.
My situation is as follows:
1) I only have one document at a time (IPXV_Document). I never have two or more instances of IPXV_Document.
2) I think I only have one frame, but I'm honestly not quite sure exactly what a frame is in this context.
3) I am calling ActiveTextEditor from inside a procedure that is only called when triggered by a keystroke which is being captured using IUIX_EventMonitor. In other words, I know a keystroke is being processed, so something is active (i.e. has focus). I don't want to trigger the event when the field first receives focus.

So, I guess I have a question: Is it possible for the end user to type text into a IPXC_FormField without there being an ActiveTextEditor? If not, then I should be OK.

Thanks.

- John
Last edited by JSantmann@Wellsoft.com on Wed Dec 20, 2017 2:36 pm, edited 1 time in total.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Which Form Field Has Focus?

Post by Sasha - Tracker Dev Team »

Hello John,
2) I am calling ActiveTextEditor from inside a procedure that is only called when triggered by a keystroke which is being captured using IUIX_EventMonitor. In other words, I know a keystroke is being processed, so something is active (i.e. has focus).
With this you have slowed the overall productivity of the API. Doing it the way I suggested would be far more efficient.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
JSantmann@Wellsoft.com
User
Posts: 9
Joined: Wed Mar 29, 2017 1:36 am

Re: Which Form Field Has Focus?

Post by JSantmann@Wellsoft.com »

Understood.
Thanks.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Which Form Field Has Focus?

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply