Cancel an event  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
espens
User
Posts: 45
Joined: Wed Jan 14, 2009 7:31 am

Cancel an event

Post by espens »

How can I cancel one of the before events? I want to cancel the save event.
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2352
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Cancel an event

Post by Vasyl-Tracker Dev Team »

Hi, Espens.

You may handle "e.document.beforeSave" event:

Code: Select all

OnEvent(LONG nEventID, IEvent *pEvent, IUnknown *pFrom)
{
       if (nEventID == n_e_document_beforeSave)
       {
              // CComPtr<IPXV_Document> pDoc;
              // pFrom->QueryInterface(&pDoc);
              // CComPtr<IPXV_DocSaveEvent> pSaveEvt;
              // pEvent->QueryInterface(&pSaveEvt);
              pEvent->put_Result(S_FALSE); // cancel save
              return;
       }
}
HTH.
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
User avatar
MartinCS
User
Posts: 153
Joined: Thu Apr 07, 2011 10:01 am
Contact:

Re: Cancel an event

Post by MartinCS »

Hi Vasyl,

regarding this topic and your reply I do have an addtional question. When I register to the "e.document.beforeSave" event how can I suppress UI messages from Pdf Editor like the save dialog (see attached file).

Martin
Attachments
2015-09-10_074101.zip
(65.79 KiB) Downloaded 159 times
Last edited by MartinCS on Thu Sep 10, 2015 5:42 am, edited 1 time in total.
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2352
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Cancel an event

Post by Vasyl-Tracker Dev Team »

Hi Martin.

Firstly, your screenshot-image is inaccessible(requires login). But, I guess you talking about "Ask for save doc before close" dialog. In this case - currently is no way to suppress it.
In the near future we will add easy method to suppress/override processing of our UI-commands.

Best
Regards.
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
User avatar
MartinCS
User
Posts: 153
Joined: Thu Apr 07, 2011 10:01 am
Contact:

Re: Cancel an event

Post by MartinCS »

Hi Vasyl,

I wasn't aware that the screenshot needed a login. My intention was to use the "[img]" tag to create an inline image. But wasn't sure how to use it. I updated my last post by uploading the screenshot of the save dialog in a zip container.

Thank you for the information. I will wait and follow the version history (https://www.pdf-xchange.com/PDFXE_history.html) for the updated version to come.


Martin
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17810
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Cancel an event

Post by Tracker Supp-Stefan »

:)
User avatar
MartinCS
User
Posts: 153
Joined: Thu Apr 07, 2011 10:01 am
Contact:

Re: Cancel an event

Post by MartinCS »

Hi Stefan,

regarding this topic I have an additional question in order to be able to cancel the close event.

I have the following code:

Register Pdf Editor events:

Code: Select all

this.pdfCtl.OnEvent += this.PdfCtl_OnEvent;
this.RegisterPdfEditorEvents();
...
private void RegisterPdfEditorEvents()
{
    this.eventIdActiveDocBeforeClose = this.pdfCtl.Inst.Str2ID("e.document.beforeClose");
    this.pdfCtl.EnableEventListening2(this.eventIdActiveDocBeforeClose, true);
}
Handle Pdf Editor events:

Code: Select all

private void PdfCtl_OnEvent(object sender, AxPDFXEdit._IPXV_ControlEvents_OnEventEvent e)
{
	if (e.nEventID == this.eventIdActiveDocBeforeClose)
	{
		if (PdfEditorEx.PdfEditorActiveDocBeforeClose(e.pEvent, pdfDocumentModel) == DialogResult.Cancel)
		{
			e.pEvent.Handled = false  // true;
			//e.pEvent.Result = 1;
			return;
		}
	}
}
The method 'PdfEditorEx.PdfEditorActiveDocBeforeClose' displays a custom user dialog with Yes, No and Cancel options (and some further internal business logic). However, what I'm finding is that regardless of the value (true, false) I set for e.pEvent.Handled, the event is not cancelled. This is resulting in documents being closed every time the event is triggered.

Is there something that I'm missing here, or is there a better way to handle a cancelled event?


Cheers,
Martin
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2352
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Cancel an event

Post by Vasyl-Tracker Dev Team »

Hi Martin.

Code: Select all

//e.pEvent.Result = 1;
Please uncomment this line in your code and it will help you..

HTH
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
User avatar
MartinCS
User
Posts: 153
Joined: Thu Apr 07, 2011 10:01 am
Contact:

Re: Cancel an event

Post by MartinCS »

I already tried the following lines of code:

Code: Select all

if (e.nEventID == this.eventIdActiveDocBeforeClose)
{
	if (PdfEditorEx.PdfEditorActiveDocBeforeClose(e.pEvent, pdfDocumentModel) == DialogResult.Cancel)
	{
		e.pEvent.Handled = false;
		e.pEvent.Result = 1;
		return;
	}
}
But it did not help me to stop the closing event.

I have a windows form which contains the pdf control. When the user clicks the close button (top right) of the windows form I close all opened pdf documents with:

Code: Select all

this.pdfCtl.Doc.Close();
This triggers the 'e.document.beforeClose' event which is handled by event id inside of the PdfCtl_OnEvent method.

My application is using a custom "save before close" dialog because I need communicate any changes to our backend system. In your earlier post you mentioned that the functionallity to suppress pdf editor UI dialogs will be implemented in the next release.
I believe that my code above is correct, but I do not understand why it is not working like I expect. I hope I was able to explain my use case, but if you require further explanation than please let me know and I would happy to oblige.
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2352
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Cancel an event

Post by Vasyl-Tracker Dev Team »

Hi Martin.

The correct code:

Code: Select all

private void pdfCtl_OnEvent(object sender, AxPDFXEdit._IPXV_ControlEvents_OnEventEvent e)
{

   if (e.nEventID == this.eventIdActiveDocBeforeClose)
   {
      if (PdfEditorEx.PdfEditorActiveDocBeforeClose(e.pEvent, pdfDocumentModel) == DialogResult.Cancel)
      {
         e.pEvent.Handled = true; // pass 'true' to notify editor that event is processed
         e.pEvent.Result = 1; // pass non-zero number to stop of document closing process (ignored when Doc.Close() called without PXV_DocClose_AllowCancel flag)
         return;
      }
   }
....
}
...

int closeFlags = (int)(PDFXEdit.PXV_DocCloseFlags.PXV_DocClose_AllowCancel);
this.pdfCtl.Doc.Close(closeFlags);
You must pass 'AllowCancel' flag to Doc.Close(), otherwise the your current event-handling will be ignored...

HTH.
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
User avatar
MartinCS
User
Posts: 153
Joined: Thu Apr 07, 2011 10:01 am
Contact:

Re: Cancel an event

Post by MartinCS »

Hi Vasyl,

I wasn't aware of the PXV:PXV_DocCloseFlags (https://sdkhelp.pdf-xchange.com/vie ... CloseFlags).

It's all working now. :D

Thank you for help!


Martin
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17810
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Cancel an event

Post by Tracker Supp-Stefan »

:)
Post Reply