From: hjv@phil.ruu.nl (Hendrik Jan Veenstra)
Subject: Re: Event dispatching
Organization: Department of Philosophy, University of Utrecht, The Netherlands
Date: Fri, 16 Oct 1992 15:48:48 GMT

aeg03@rrz.uni-koeln.de (Jan T. Kim) writes:


>Actually, the procedure check_event()  which  I  outlined  in  my
>original  posting  is  almost exactly the generic window-handling
>function you  suggest.  I  don't  see  why  it  should  make  any
>difference  whether  one  branches to the appropriate function by
>swapping pointers or by a SELECT-CASE construct.  The  number  of
>structures  containing  pointers can't be smaller than the number
>of SELECT @contents(w_handle&) constructs.
>The difference I see between your suggestion and  my  program  is
>that  you're  dispatching for the window type first, then for the
>AES window event. So, would you say it's better to do things this
>way  round?  I  always  have  thought the sequence of dispatching
>steps I chose is better because  one  has  to  dispatch  for  all
>window  events  in  any  case,  but  some  window events (such as
>WM_FULLED) don't necessitate full dispatching for window types.

To be honest, I've never handled a situation like this before, but
following my 'intuition' I would do the following (and I don't know
if any of this can be implemented in C - and I also don't know if
this is the best way to handle things, so all flames to dev/null
please).
I would first make structures, containing pointers to all the window-
handling functions. One structure per window-type - or (better) one
structure per window. You now have e.g. win_struct1, win_struct2, etc.
(or you could put them in an array). Now declare a pointer to this
kind of window-structs, e.g.
	win_struct *curr_window;
The dispatch loop would then be something like


   handle_event(int window_handle, int event)
   {    switch (window_handle)
	{ case wh1:                   /* let curr_window opint to the */
	    curr_window=win_struct1;  /* structure corresponding to   */
	    break;                    /* the current window           */
	  case wh2:
	    curr_window=win_struct2;
	    break
	etcetera.....
	}

	switch(event)
	{ case window_sized:           /* call the appropriate structure- */
	    curr_window->sizefunc;     /* member (which is a function)    */
	    break;
	  case window_moved:
	    curr_window->movefunc;
	    break;
	etcetera...
	}
   }

The syntax for calling functions is different from the above, but it's just
to get the idea... (can't get the syntax for this kind of stuff in my
head for some reason :).

Anyway, this way you need only two switches... Of course some function
pointers could be empty e.g. when a particular window is not sizeable you'll
have no 'sizefunc' for that window - but that's no problem as you'll
never receive a 'size event' for that window, so it doesn't matter where
the curr_window->sizefunc points to. You might (just to be safe) put
dummy functions in unused slots.
But as I said, I don't know if anything remotely similar can be done in GFA.

Of course you could also do everything the other way around - make structs
that contain all the sizefuncs, movefuncs, etc. etc - a structure member
per window (instead of per event as I suggested). The first switch will
now switch on event and let the pointer point to the right-kind-of-action-
structure. The second switch will then select the right member from this
structure=the right window. I find it however not too intuitive to do it
this way - I prefer my solution :).

Hope this is of any help...
BTW, this is just a 'wild idea' - I've never treid it, but can't see why it
wouldn't work....

Hendrik Jan

--
Hendrik Jan Veenstra  |  hjv@phil.ruu.nl  |   You look for your dreams in
Dept. of Philosophy   |                   |   heaven, but what the hell are
University of Utrecht |                   |   you supposed to do when they
The Netherlands       |                   |   come true...?
Newsgroups: comp.sys.atari.st.tech