Forwarding events to different windows
Alan Robertson (52) 420 posts |
I’ve been learning C during the past few months and I’m in need of a solution to my coding problem. I’m trying to forward wimp events to differing windows in a generic way, rather than have to use switch case statements in the program. e.g. a window containing a scrollbar may have to forward it’s events to a list of different windows as they may need to respond to that event so they move their windows. Different windows upon creation would have to register their need to respond to events of their sibbling/parent/child windows where required I guess. Anyone know the right way to achieve this? I’m struggling to wrap my head round how to do this registering, mapping and forwarding. Clues & code more than welcome! |
Steve Fryatt (216) 2055 posts |
Function pointers are the way that it’s usually done. Most Wimp libraries will come with an event dispatcher, so check whatever you’re using to see if it’s suitable. The usual trick is that windows pass their handles and a pointer to a handler function for the events that they’re interested in, and when an event arrives via In your case, it sounds as if you would need slightly different data structures and forwarding logic, but ultimately it will be a similar approach. I’m fairly sure that RISCOSlib contains code like this; I’m more familiar with the event library in SFLib, for obvious reasons! |
Alan Robertson (52) 420 posts |
Thanks for the info and pointers. So if I understand correctly:
Is that right? I’ll also have a look at your SFLib and see what it does. :-) |
Matthew Phillips (473) 689 posts |
An unordered linked list is fast enough for this sort of purpose, I would say. Obviously it might get slow if you have thousands of windows. The software library we use (sorry, source not available) allows code modules to register to receive events relating to particular window handles. There is a linked list attached to each window data structure. The items in the list specify:
The events are dealt with via a bit-significant value, which is not directly related to Wimp poll codes. For example, there are bits for clicks, drags and double-clicks for each mouse button, and bits for particular significant keys like Escape, as well as standard things like “key pressed”, “pointer leaving”, “pointer entering” which correspond directly to Wimp poll reason codes. That’s obviously rather more complicated, and requires a bit more code in your central Wimp_Poll loop, but it’s quite effective. If you want a mouse click handler, you just register the procedure with several of the bits set. There are separate arrangements for registering user message handlers of various sorts — the kinds of things that are not tied to windows. |
Rick Murray (539) 13432 posts |
Matthew – what you’ve just described sounds quite a bit like DeskLib’s event handling. Alan: It’s written in French(ish) because the article is in French(ish). If you can’t read French, download the source code (at same URL) as it is commented in English so you can follow what’s going on. |