[comp.windows.interviews] Help! with Compositions

connolly@convex.com (Dan Connolly) (06/07/91)

I'm trying to use Interviews to draw formatted text. The Doc program
is nifty, but it does a little more than I need, and it's not very 
robust.

The only other example code using glyphs is alert. So I used that.

I grabbed the code from the "Glyphs: Flyweight Objects for User
Interfaces" slides and substituted it in to the MakeMessage function.

The example using TBBox and LRBox ("TextView Code" slide) works! Yeah!

So I was bold and tried the code using Compositions ("Formatted
TextView code" slide). No workie. :-< Crap! This is just the tool I've
been looking for, and it won't work!

Here's the code... why doesn't it work?

And... does anybody have ANY SMALL EXAMPLES of code that uses glyphs?
The alert program is great. I need more.

Dan


--- cut here ---

/*
 *  new_alert - displays a message in a dialog box
 */

#include <IV-look/bevel.h>
#include <IV-look/button.h>
#include <IV-look/choice.h>
#include <InterViews/action.h>
#include <InterViews/background.h>
#include <InterViews/box.h>
#include <InterViews/center.h>
#include <InterViews/glue.h>
#include <InterViews/label.h>
#include <InterViews/margin.h>
#include <InterViews/window.h>
#include <InterViews/world.h>
#include <stdio.h>
#include <string.h>

declare(ActionCallback,World)
implement(ActionCallback,World)

static PropertyData props[] = {
    { "*quitbutton", "OK, OK ..." },
    { "*font", "9x15" },
    { "*transient", "on" },
    { nil }
};

static OptionDesc options[] = {
    { "font=", "*font", OptionValueAfter },
    { "button=", "*quitbutton", OptionValueAfter },
    { "-top", "*transient", OptionValueImplicit, "off" },
    { nil }
};

static Glyph* MakeMessage(Font*, Color*);

int main(int argc, char** argv) {
    World world("Alert", argc, argv, options, props);
    Font* f = world.font();
    Color* fg = world.foreground();
    Color_Intensity r, g, b;
    world.background()->intensities(&world, r, g, b);
    Color* c = new Color(
	Color_Intensity(0.8*r), Color_Intensity(0.8*g), Color_Intensity(0.8*b)
    );
    Glyph* label = new Margin(
	new Label(world.property_value("quitbutton"), f, fg), 3.0
    );
    Glyph* vspace = new VGlue(18.0);
    Glyph* hspace = new HGlue(36.0);
    Glyph* dialog = new Background(
	new TBBox(
	    new VCenter(vspace, 1.0),
	    new LRBox(
		hspace,
		new TBBox(
		    new VCenter(MakeMessage(f, fg), 1.0),
		    vspace,
		    new LMargin(
			new Button(
			    new ActionCallback(World)(&world, &World::quit),
			    new ChoiceItem(
				new Bevel(label, new Outset(c)),
				new Bevel(label, new Inset(c))
			    )
			),
			0.0, fil, 0.0
		    )
		),
		hspace
	    ),
	    vspace
	),
	c
    );

    boolean transient = world.property_is_on("transient");
    Window* w;
    if (transient) {
	TransientWindow* t = new TransientWindow(
	    new Bevel(new Margin(dialog, 2.0), new Outset(c))
	);
	t->transient_for(t);
	w = t;
    } else {
	w = new ApplicationWindow(dialog);
    }
    w->place(world.width() / 2, world.height() / 2);
    w->align(0.5, 0.5);
    w->map();
    world.RingBell(0);
    world.run();
    return 0;
}

#include <InterViews/composition.h>
#include <InterViews/texcomp.h>
#include <InterViews/discretion.h>
#include <InterViews/character.h>
#include <InterViews/patch.h>
#include "debug.h"

static Glyph* MakeMessage(Font* f, Color* fg) {
#define WIDTH (100.0)
#define LBP 10

#ifdef noworkie
    Composition *page = new LRComposition(
					  new TBBox(), new TeXCompositor(LBP),
					  nil, WIDTH);
    int c;
    while((c = getchar()) != EOF){
      if(c == '\n'){
	debug(("Newline\n"));
	page->append(new Discretionary(
				       PenaltyGood, new HGlue(fil),
				       new HGlue(0.0), nil, nil) );
      }else if (c == ' '){
	debug(("space\n"));
	page->append(new Discretionary(0, new Character(' ', f, fg),
				       new HGlue(0.0), nil, nil) );
      }else{
	debug(("char: %c\n", c));
	page->append(new Character(c, f, fg));
      }
    }
    return page;
#else

    TBBox* page = new TBBox();
    LRBox* line = new LRBox();
    int c;
    while((c = getchar()) != EOF){
      if(c == '\n'){
	debug(("Newline\n"));
	page->append(line);
	line = new LRBox();
      }else{
	debug(("char: %c\n", c));
	line->append(new Character(c, f, fg));
      }
    }
    return page;
#endif
}