How to create custom panel items in suntools
John D. Polstra
polstra!jdp at uunet.uu.net
Fri Jun 2 04:10:38 AEST 1989
In article <8904261905.AA24155 at trantor.harris-atd.com> chuck at trantor.harris-atd.com (Chuck Musciano) writes:
>X-Sun-Spots-Digest: Volume 7, Issue 276, message 2 of 18
>
> Suntools is not extensible . . .
Ah, but it *is* extensible, and the technique Sun used to make it that
way is pretty cute. Let's take as an example the following call, which
creates a new button in a panel:
button = panel_create_item(panel, PANEL_BUTTON, <attributes>, 0);
If you look in <suntool/panel.h>, you'll find that PANEL_BUTTON just
expands to the name of a function in the suntools library:
extern Panel_item panel_button();
...
#define PANEL_BUTTON panel_button
So, panel_create_item() is simply being handed a pointer to a function
(panel_button) which is responsible for setting everything up.
Panel_create_item() *calls* this function, which is expected to
initialize some things and then return a pointer to a structure (called
a Panel_item) that has a standardized layout (independent of the panel item
type) at its beginning. The standardized part of the structure
contains, among other things, pointers to functions for doing things
such as interpreting attributes, repainting, destroying the item, etc.
The remainder of the structure contains whatever additional information
is necessary to maintain that particular type of panel item.
Let's say I want to have a new type of panel item, a PANEL_VIBROROTOR.
Here's what I have to do:
1. Add these lines to <suntool/panel.h> or some other convenient
place:
extern Panel_item panel_vibrorotor();
#define PANEL_VIBROROTOR panel_vibrorotor
2. Write the panel_vibrorotor() routine and its standardized support
routines (interpret attributes, repaint, destroy, etc.).
Panel_vibrorotor() should allocate a Panel_item structure, fill in
all of the standardized fields, initialize the private fields, and
return a pointer to the structure.
Once this is done, I can say:
vr = panel_create_item(panel, PANEL_VIBROROTOR, <attributes>, 0);
and it ought to work just fine.
Interestingly, the same technique is used for implementing the various
subwindow types (PANEL, CANVAS, etc.). So you could also extend Sunview
to include new kinds of subwindows.
The catch is, of course, that Sun doesn't document the layout of the
standardized portion of the Panel_item structure. You have to figure it
out for yourself, using your favorite debugger. (Don't ask me for this
information -- I pursued it only far enough to convince myself that it
would be possible.) Also, there's no guarantee that Sun won't change
everything in a future release.
John Polstra jdp at polstra.uucp ...uunet!practic!polstra!jdp
More information about the Comp.sys.sun
mailing list