Kirix Support Forums

Not catching (or understanding) DOM Event

Please post all general questions, comments, bug reports, and any other wxWebConnect feedback here.

Not catching (or understanding) DOM Event

Postby mpeavy on Fri Oct 01, 2010 2:13 pm

Hi all,

I have an event handler that is trying to catch DOM events (wxEVT_WEB_DOMEVENT). But the handler is never called. So I am not sure if I am doing something wrong or misunderstanding when a DOM event is supposed to be called.

I thought it would be called when the DOM itself changes. For example, I have a cell in a table that is updated to either "left" or "right" corresponding to the left or right mouse click. A javascript event is triggered (document.onMouseDown) which then updates the cell contents. I assumed that this would cause a wxEVT_WEB_DOMEVENT event.

Should it, or am I misunderstanding the DOM event? When does a DOM event ever get called?

Thanks for your help.
Matt.
mpeavy
Registered User
 
Posts: 3
Joined: Sat Sep 11, 2010 10:45 pm

Re: Not catching (or understanding) DOM Event

Postby jonmmorgan on Fri Oct 01, 2010 11:38 pm

Hi,

I haven't really used the DOM event support in production. However, I tried using it a few months ago before I switched to doing something else, and still have the code (in Python), which I think worked. Essentially, you have to make sure that you both add a listener for the particular DOM event you want to catch, and register for getting the DOM event itself. Once you have got the DOM event, you have to figure out which listener has been triggered. For example, I was wanting mouseover and mouseout events on the document, so used the following:

WX_MOUSE_OVER_EVENT = 999991
WX_MOUSE_OUT_EVENT = 999992

...

In setup:
self.Bind(wx.wc.EVT_WEB_DOMCONTENTLOADED, self.DomContentLoaded)
self.Bind(wx.wc.EVT_WEB_DOMEVENT, self.DomEventReceived)

def DomContentLoaded(self, event):
document = self.GetDOMDocument()
document.AddEventListener("mouseover", self, WX_MOUSE_OVER_EVENT, True)
document.AddEventListener("mouseout", self, WX_MOUSE_OUT_EVENT, True)


def DomEventReceived(self, event):
event_id = event.GetId()
if event_id not in (WX_MOUSE_OVER_EVENT, WX_MOUSE_OUT_EVENT):
return

if event_id == WX_MOUSE_OVER_EVENT:
print "Mouse over"
elif event_id == WX_MOUSE_OUT_EVENT:
print "Mouse out"

I don't know exactly what that would look like in C++, and I don't know if there is a better way of catching the events than this (it certainly feels to me a bit clumsy).

I think sometimes (maybe even often) it is easier to do your work in Javascript (maybe by executing a script, or by including the script in the HTML you display). If you can do it in Javascript, I think it tends to be easier to interact with the DOM in Javascript, especially if you include a library like jQuery. I have really not used the WebConnect DOM API much yet, but I do use quite a bit of Javascript.
jonmmorgan
Registered User
 
Posts: 94
Joined: Fri May 14, 2010 9:48 am

Re: Not catching (or understanding) DOM Event

Postby mpeavy on Sun Oct 03, 2010 5:38 pm

Thanks Jon.

I'll give that a try and post the C++ code if I get it to work.

Matt.
mpeavy
Registered User
 
Posts: 3
Joined: Sat Sep 11, 2010 10:45 pm

Return to wxWebConnect Questions, Thoughts & Feedback