Subject: Am I insane ?

From: [email-masked] (Christian Brunschen)
Date: Tue, 12 Oct 1993 13:12 +0100 (MET)

You know, I've had a really wild idea.  The kind of idea that will be
discribed as either "insane" or "insanely great".

Let me give you some background:

Our university has recently installed 50 Sun SPARCclassic machines --
the first machines on campus that have actual sound support (no NeXTen
on campus here, alas). We are running, on these machines, Solaris 2.1
-- ie, SunOS 5.2 -- but under vanilla X11R5, using twm as a window
manager.

An immediate side effect of sound-aware machines showing up was that
people have started associating sounds with actions in the window
manager: A friend of mine has a gun-shot sound for the window-kill
function. To achieve this, he created a function of his own (winkill)
which plays the sound and kills the window using twm:s f.kill
function. He then replaced all calls to f.kill with calls to his own
winkill.

What he did was basically, subclass twm, and override the f.kill
function.

This was not difficult in any way. However, I could not do that under
NeXTSTEP with the current set of tools available. Oh, sure, I could
open every .nib file in my entire file system and drop "bang.snd" on
the close button of every window. But this is a non-general way of
doing it and requres much work on my part -- and I have to redo _all_
the work if I want to use another sound, or do something else than
just play a sound.

(So, where's the really neat idea? Coming real soon, promise :-)

What I would _really_ like to do is replace the Window class, as it is
in the system, with a subclass that I have defined myself. Obviously,
I don't have the source code to most applications, so this approach
doesn't appear very workable. Or is it? Hmmm... Waitasec .. Ah! Bingo!
there it is ... "poseAs"!

OK, now we have a way to replace one class by a subclass; There is one
restriction -- we can't add any instance varibales -- but that should
be possible to circumvent if we absolutely _have_ to, so no big deal.

We also know how to load classes -- NXBundle is there to help us.

So, what we need is simple a way to, automatically at application
startup, do the following:

* Check the defaults database for which classes should be replaced,
and which classes should take their places 

* Load each replacementclass (an NXBundle, most likely)

* Send each replacement class the respective +poseAs: message

All of this must, of course, be done before we have started using any
of the classes we replace.

So, we create a class -- preferrably a subclass of Application -- that
does all of this; we could place it in Application's +initialize
method, so it will be done before (almost) anything else.

We use this MiscApplication class instead of Application in our
applications. And now, I can simply create my own subclass of Window
that goes "KaBLAM!" when it is closed, put this class in an NXBundle,
do a dwrite (something like "dwrite GLOBAL replacementClasses
BlamWindow:Window" perhaps) and every application that uses
MiscApplication will automatically use the BlamWindow class instead of
plain old Window -- even in their own subclasses of Window!  (For
details on this, consult documentation -- and please point out any
errors that I have made in my reasoning.)

(Why am I not being more detailed? Beacuse I am not sure about the
details! :)

What's _really_ neat about this is that it can be made to work for
arbitrary classes -- ie, you could replace Object with a version that
prints debugging info, or something. (Of course, in most applications
this isn't really something we want J. Random User to do, so some kind
of security system (like, "don't replace any classes that are above
View in the class hierarchy") should be implemented as well.) This is
en _extremely_ general and powerful way of customizing application
behaviour to suit your needs -- not only can you have a window that
goes BLAM everytime you close it, you can also (for instance) have a
scroller give you audio feedback as to its position (shouldn't be too
hard to do, should it? Let it make a sound with a frequency (or
volume) that is calculated from where the scroller is ... and you
automatically get it in _every app_ that uses the MiscApplication
object, not just apps where the implementor thought this would be a
cool idea! :-) !!

How does this help me with existing applications? It doesn't. But
since this idea is so damn general, maybe we could convince people to
start using it in their applications.

Any comments ? Is this insane, or insanely great ?

Best regards

// Christian Brunschen

| Christian Brunschen, Husmansv. 26, S-227 38 Lund, Sweden             |
| voice/fax/data +46 (0)46 139345, email [email-masked]              |
| PGP 2.2 Public Key available on request. | ObCelebrityQuote:         |
| "Oh, foo."                                                           |
|     - Andrew R. Koenig ([email-masked]) after dropping a piece |
|       of chalk during a lecture on C++ in Lund, Sweden, April 1993   |