[comp.windows.interviews] PushButton for 3.0

juando@cnm.us.es (05/06/91)

	I am building the class PushButton (just as an exercise) using
3.0 classes only, derived from class Button. I just want a button with a
label inside. The constructor would be declared something like:

    PushButton(const char *s, Font *f, Color *fg, Color *bg, Action *a);

	The telltale for the Button would be built inside this constructor,
however, Button parent class requires the telltale before I can build it.
I know I can pass nil to Button constructor and set it later because telltale_
is protected, not private, but then listener_ would be initialized whith a nil
Glyph. Can someone tell me how could this be done?

	Thanks.

	    Juan

calder@uluru.stanford.edu (Paul Calder) (05/08/91)

Juan has a good question about building PushButtons from glyphs ...

    The telltale for the Button would be built inside this constructor,
    however, Button parent class requires the telltale before I can build it.

Here are two suggestions; I prefer the first.

1. PushButton needn't be derived from Button.  Just make it a MonoGlyph.

    PushButton::PushButton (...) : MonoGlyph(nil) {
        Telltale* t  = ...;
        Button* b = new Button(..., t, );
        body(b)
    }

2. Use a helper function to build the Telltale.

    static Telltale* make_telltale (...) {
        Telltale* t = ...;
        return t;
    }

    PushButton::PushButton (
        ...
    ) : Button(..., make_telltale(...), ...) {
        ...
    }

--
Paul Calder
Computer Systems Lab
Stanford University
calder@lurch.stanford.edu