On Jun 3, 2006, at 11:20 AM, Charles Yeomans wrote:
If you want to write separate window classes for MacOS and Windows
(for ease of layout, perhaps), then you'll need to introduce some
additional classes for delegation of event handling. Here's a way to
do it without massive subclassing. Define a class
CrowdedWindowEventHandler. Move all of the window methods to it.
These methods should only be called from handlers, so you can make
them private. Then start adding a bunch of public methods for
event-handling --
HandleOpen(w as Window)
HandleClose(w as Window)
HandleEnableMenuItems(w as Window)
HandleOpen(b as BevelButton)
HandleAction(b as BevelButton)
HandleKeyDown(e as EditField, key as String) as Boolean
etc.
Passing a reference to the control or window removes the need for a
circular reference.
Now drop an instance of CrowdedWindowEventHandler onto the window;
call this widget EventHandler. Then go to each event handler in the
window and call the corresponding handler --
Sub Open()
EventHandler.HandleOpen me
End Sub
You can then implement window behavior as needed in the handler
methods. If you need to get the state of other controls in a handler,
that's certainly possible. You could do something like
CrowdedWindow(b.Window).EditField1.Text. Casting is generally a code
smell, but since CrowdedWindowEventHandler is auxiliary to
CrowdedWindow, it's a reasonable thing to do in this case.
Wouldn't you have to cast either to MacOSCrowdedWindow or
WindowsCrowdedWindow to get access to a control like editField1? I'm
not sure what exact role CrowdedWindow is playing, but whether it is an
interface or a super to MacOSCrowdedWindow and WindowsCrowdedWindow,
CrowdedWindow doesn't have any controls. That means every call via
casting to a control needs to be done on a per-target basis, which is
even messier! Am I missing something in your framework?
Lisa
------------------------------------------
Lisa Sawin
Glass Bead Software
http://www.glassbead.com/
REALbasic 2005 r4 running on Mac OS 10.3.9
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>