Initial revision
[ssr] / StraySrc / Libraries / Core / TearSupt / README
CommitLineData
2ee739cc 1Tearoff Menu System
2~~~~~~~~~~~~~~~~~~~
3
4A while ago, as Tim was leaving after a hacking session, I mentioned how
5nice it would be if only RISC OS allowed menus to be tearoffable, like
6OpenLook menus are. He pointed out that impossibility shouldn't be much
7of a barrier to us, and we got coding.
8
9Tearoff menus look just like normal menus, except there's a grey bar
10along the top, just below the title, with a `Tear' button in it. When
11the user clicks the `Tear' button, the rest of the menu tree goes away,
12leaving the tornoff menu behind, so that options can be chosen from it
13whenever the user needs to. Tornoff menus have two buttons in their
14grey bar area: `Close' closes the menu, and `Fold' hides the menu part
15away, leaving just the title behind, a bit like Corel's rollups (only
16without the irritating animation).
17
18The main support code was written as part of STEEL, in C. It handles
19the obvious (but quite difficult) stuff related to highlighting the
20right items, opening the right submenus, and drawing the windows, and
21Tim wrote it all. (He later wrote the corresponding Sapphire code --
22the user- and programmer-visible bits of our tearoff support are
23entirely written by him.)
24
25There's one aspect of tearoff handling which can't be handled from an
26application: making the main menu tree `transient'. There are three
27times when the Wimp closes a transient window `silently':
28
29 * when the user clicks outside of the menu tree;
30 * when the user presses the `Escape' key; and
31 * when an application calls Wimp_CreateMenu.
32
33In the first case, the mouse click is passed on to the receiving window;
34in the second, the keypress is swallowed by the Wimp.
35
36These three cases are handled by some vector interceptions. Normally
37this would be done by a module. Tim wanted the vector traps to be hard
38to extract, though, and a small module would be easy for other
39programmers to reverse engineer and implement their own tearoffs. The
40`tearoff support code' is statically linked into the application which
41uses it, and copied into an RMA block if it's not there already.
42
43The interface to the TearSupt code is simple:
44
45 * ts_init initialises the support code.
46
47 * ts_opened says that the application has opened a transient window,
48 and wants to be notified about events which might cause it to be
49 closed.
50
51 * ts_closed says that the transient window has been closed.
52
53 * ts_switch switches Wimp_CreateMenu trapping on and off (an
54 implemention detail requires this).
55
56 * ts_unload removes the tearoff support code from memory.
57
58Tearoff Support traps several vectors. One is trapped all the time:
59
60 * ChangeEnvironmentV is trapped, as part of a particularly hacky way
61 of communicating with the TearSupt code. It traps a call with R0 =
62 -1 and returns its address and version number. This is very nasty.
63
64Others are only trapped while there's a `fake transient' open, and cause
65Wimp messages to be sent to the owner of the window:
66
67 * MouseV is trapped: all mouse clicks are picked up, and passed on as
68 messages.
69
70 * InsV is trapped: insertion of an `escape' keypress into the keyboard
71 buffer causes a message to be sent.
72
73 * The hardware SWI vector is trapped: a call to Wimp_CreateMenu causes
74 a message to be sent.
75
76Just to make life more awkward, the code is encrypted (very weakly: it's
77not worth the effort and code space of doing it properly). I considered
78removing the encryption code, but (a) I preferred to leave everything
79the way it was (more or less) as a record of the nasty things Straylight
80sometimes do, and (b) I couldn't be bothered.
81
82Anyway, all the code is really nasty. I'd recommend that you avoid
83reading it too closely. Oh, the SWI patch may be instructive to those
84who've not seen the job done before: I think it works properly in all
85circumstances.
86
87Of course, anyone's allowed to use tearoff menus. You're even allowed
88to use our code to implement them, as long as you stick to the GPL. And
89finally, if someone comes up with a SWI chunk, I may be convinced to
90permit binary distribution of a tearoff support module using our code.
91--
92[mdw]