Re: Some event ideas...

Xenomorph <[email protected]>
Newsgroups gmane.comp.lib.wxwindows.wxnet
Message-ID <1083897114.29461.42.camel@dellkiste>
Am Fr, den 07.05.2004 schrieb Bryan Bulten um 1:45: 
> > AddCommandListener(Event.wxEVT_COMMAND_BUTTON_CLICKED, ID, value,
> > this);
> 
> In what cases would the last argument not be 'this'?

I have added that because the old EVT_ events are getting added with
owner = null to the list... So I needed a second AddCommandRangeListener
and AddCommandListener method.

> > it also adds a reference of the calling object to the arraylist
> > listeners.
> > 
> > When an event calls back MarshalEvent, it tries to find equal objects
> > in the list and calls all! delegates, not only the last added one.
> 
> Yes, it calls all delegates, but does not check the event type for which
> they are registered.

I saw that shortly after writing my message and made a change. Event
type is already in the struct...

> I'm also not sure if that modification would help during this situation:
> 
>   button.Clicked = new EventHandler(OnClicked1);
>   EVT_BUTTON(-1, new EventHandler(OnClicked2));

> Since the array of listeners are completely separate, the event would be
> handled by the last handler only.  So in this case, even with he event
> type checked, it would not work.

No. In that case only OnClicked1 gets called for button. Because you add
button with owner this and the others with owner = null.

But if you add:

button.Clicked += new EventListener( OnClicked2 )
button.Clicked += new EventListener(OnClicked1);
EVT_BUTTON(-1, new EventListener(OnClicked2));

Everything works as it should, when pressing button button both event
methods get called... All the other buttons only call OnClicked2...
(I have tested this already with ModalDialog in Dialogs sample...)
Every Clicked += gets a new iListener number...

> I think that there may need to be a static hash of listeners, and that
> MarshalEvent needs to be passed an event type.  The listeners could then
> be indexed by the event type, and looked up based on the event ID. 
> (Writing something to do this now....).

Do we really need a static hash ??? :) I'm to tired now... 4:18 am...

> Either that, or I'm completely missing the point of your code :-)

Maybe the last one... :))))))))))))))
Just look at MarshalEvent again... 
Again: EVT_BUTTON added events are not the same as .Clicked += events.
Every Clicked += event gets a new iListener nr, that means a new
wxProxyData object...

Time to go to bed...

Greetings
Alexander

private void MarshalEvent(IntPtr wxEvent, int iListener)
		{
			// Create an appropriate .NET wrapper for the event object
				
			Event e = Event.CreateFrom(wxEvent);
	
			// Send it off to the registered listener
	
			//EventListener listener = (EventListener)listeners[iListener];
		
			SListener listener = (SListener)listeners[iListener];
		
			foreach ( SListener sl in listeners )
			{
				// continue if listener equals sl, because it will be handled below
				if ( listener.Equals( sl ) ) continue;
			
				if ( sl.owner != null && listener.owner != null )
				{
					if ( sl.owner.Equals( listener.owner ) && sl.eventType ==
listener.eventType )
					{
						sl.listener(this, e);
					}
				}
			}
		
			listener.listener(this, e);
		}



-------------------------------------------------------
This SF.Net email is sponsored by Sleepycat Software
Learn developer strategies Cisco, Motorola, Ericsson & Lucent use to 
deliver higher performing products faster, at low TCO.
http://www.sleepycat.com/telcomwpreg.php?From=osdnemail3
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.