From: dave@kanga.lcs.mit.edu (David Sternlicht)
Newsgroups: comp.windows.interviews
Subject: updated cedit program...
Date: 8 Sep 92 23:22:43 GMT
Organization: MIT

Here is an updated (beta2) version of the cedit program:
I dont have time to comment it  right now, although I should  sorry...

			
				dave sternlicht
				mit X consortium
				dave@expo.lcs.mit.edu

#!/bin/sh
# To extract, remove the header and type "sh filename"
#
# This archive contains the following files:
#
#         ./Imakefile
#         ./Makefile
#         ./cedit.c
#
if `test ! -s ./Imakefile`
then
echo "writing ./Imakefile"
sed 's/^X//' > ./Imakefile << '\End\Of\File\'
XXCOMM
XXCOMM InterViews resource editor
XXCOMM
X
X#ifdef InObjectCodeDir
X
XUse_libInterViews()
XComplexProgramTarget(cedit)
X
XMakeObjectFromSrc(cedit)
X
X#else
X
XMakeInObjectCodeDir()
X
X#endif
\End\Of\File\
else
  echo "will not over write ./Imakefile"
fi
if `test ! -s ./Makefile`
then
echo "writing ./Makefile"
sed 's/^X//' > ./Makefile << '\End\Of\File\'
X# Makefile generated by imake - do not edit!
X# $XConsortium: imake.c,v 1.70 92/09/03 19:55:35 rws Exp $
X#
X# The cpp used on this machine replaces all newlines and multiple tabs and
X# spaces in a macro expansion with a single space.  Imake tries to compensate
X# for this, but is not always successful.
X#
X
X# Read "InterViews/template" to understand how this Makefile was generated.
X# Edit <InterViews/arch.def> to add support for a new platform.
X# Edit <InterViews/iv-sun.cf> to change platform-specific parameters.
X# Edit <InterViews/local.def> to change site-specific parameters.
X# Edit <Imakefile> to change actions that make should perform.
X
X# architecture:  SUN4
X
X# platform:  $XConsortium: sun.cf,v 1.77 92/05/29 18:37:21 rws Exp $
X
X# operating system:  SunOS 4.1.2
X
X# $XConsortium: sunLib.rules,v 1.9 92/06/28 17:43:02 rws Exp $
X
X              SHELL = /bin/sh
X
X              IMAKE = imake
X         IMAKEFLAGS = \
X -T "InterViews/template"\
X -I$(CONFIGDIR) -I$(XCONFIGDIR)\
X $(SPECIAL_IMAKEFLAGS)
X SPECIAL_IMAKEFLAGS =   -DUseInstalled
X             DEPEND = makedepend
X     DEPEND_CCFLAGS = $(CCDEFINES) $(CCINCLUDES) -I/usr/include/CC
X               MAKE = make
X           PASSARCH = ARCH="$(ARCH)" SPECIAL_IMAKEFLAGS="$(SPECIAL_IMAKEFLAGS)"
X          ARCHORCPU = $$CPU
X               ARCH = $(ARCHORCPU)$(SPECIAL_ARCH)
X       SPECIAL_ARCH =
X
X           CCDRIVER = CC +p
X           CCSUFFIX = c
X                SRC = .
X              SLASH = /
X               SRCS = $(SRC)$(SLASH)*.$(CCSUFFIX)
X               OBJS = *.o
X               AOUT = a.out
X
X            CCFLAGS = $(APP_CCFLAGS) $(IV_CCFLAGS) $(EXTRA_CCFLAGS)
X         IV_CCFLAGS = \
X \
X \
X $(SHARED_CCFLAGS)\
X $(CCDEFINES)\
X $(CCINCLUDES)
X      DEBUG_CCFLAGS = -g
X   OPTIMIZE_CCFLAGS = -O
X     SHARED_CCFLAGS =
X      EXTRA_CCFLAGS = -pipe
X
X          CCDEFINES = $(APP_CCDEFINES) $(IV_CCDEFINES) $(EXTRA_CCDEFINES)
X       IV_CCDEFINES = $(LANGUAGE_CCDEFINES) $(BACKWARD_CCDEFINES)
X LANGUAGE_CCDEFINES = -Dcplusplus_2_1
X BACKWARD_CCDEFINES =
X    EXTRA_CCDEFINES =
X
X         CCINCLUDES = $(APP_CCINCLUDES) $(IV_CCINCLUDES) $(EXTRA_CCINCLUDES)
X      IV_CCINCLUDES = \
X $(BACKWARD_CCINCLUDES)\
X $(TOP_CCINCLUDES)\
X $(X_CCINCLUDES)
XBACKWARD_CCINCLUDES =
X     TOP_CCINCLUDES = -I$(INCDIR)
X       X_CCINCLUDES =
X   EXTRA_CCINCLUDES =
X
X          CCLDFLAGS = $(APP_CCLDFLAGS) $(IV_CCLDFLAGS) $(EXTRA_CCLDFLAGS)
X       IV_CCLDFLAGS = \
X \
X \
X $(NONSHARED_CCLDFLAGS)
XNONSHARED_CCLDFLAGS =
X    EXTRA_CCLDFLAGS =
X
X          CCDEPLIBS = $(APP_CCDEPLIBS) $(IV_CCDEPLIBS) $(EXTRA_CCDEPLIBS)
X       IV_CCDEPLIBS = \
X $(DEPLIBUNIDRAW)\
X $(DEPLIBGRAPHIC)\
X $(DEPLIBIV)\
X $(DEPLIBXEXT)\
X $(DEPLIBX11)\
X $(DEPLIBM)
X    EXTRA_CCDEPLIBS =
X
X           CCLDLIBS = $(APP_CCLDLIBS) $(IV_CCLDLIBS) $(EXTRA_CCLDLIBS)
X        IV_CCLDLIBS = \
X $(LIBDIRPATH)\
X $(LDLIBUNIDRAW)\
X $(LDLIBGRAPHIC)\
X $(LDLIBIV)\
X $(XLIBDIRPATH)\
X $(LDLIBXEXT)\
X $(LDLIBX11)\
X $(LDLIBM)\
X $(ABSLIBDIRPATH)
X     EXTRA_CCLDLIBS =
X
X            INSTALL = install
X       INSTPGMFLAGS = -s
X       INSTBINFLAGS = -m 0755
X       INSTUIDFLAGS = -m 4755
X       INSTLIBFLAGS = -m 0644
X       INSTINCFLAGS = -m 0444
X       INSTMANFLAGS = -m 0444
X       INSTDATFLAGS = -m 0444
X      INSTKMEMFLAGS = -g kmem -m 2755
X
X                 AR = ar cq
X                 AS = as
X                 CP = cp
X                CPP = /lib/cpp $(EXTRA_CCDEFINES)
X      PREPROCESSCMD = $(CCDRIVER) -E $(EXTRA_CCDEFINES)
X                 LD = ld
X                 LN = ln -s
X          MKDIRHIER = mkdirhier
X                 MV = mv
X             RANLIB = ranlib
X    RANLIBINSTFLAGS =
X                 RM = rm -f
X             RM_CMD = $(RM) ,* .emacs_* *..c *.BAK *.CKP *.a *.bak *.ln *.o a.out core errs make.log make.out tags TAGS
X              TROFF = psroff
X
X                TOP = .
X        CURRENT_DIR = .
X
X             BINDIR = /interviews/bin/$(ARCH)
X          CONFIGDIR = /interviews/config
X             INCDIR = /interviews/include
X             LIBDIR = /interviews/lib/$(ARCH)
X          LIBALLDIR = /interviews/lib/all
X             MANDIR = /interviews/man
X
X       ABSCONFIGDIR = /interviews/config
X          ABSLIBDIR = /interviews/lib/$(ARCH)
X       ABSLIBALLDIR = /interviews/lib/all
X         XCONFIGDIR = /usr/lib/X11/config
X            XINCDIR = /usr/include
X            XLIBDIR = /usr/lib
X          PSFONTDIR = /usr/lib/ps
X
Xall::
X
XMakefile::
X	-@if [ -f Makefile ]; then \
X	$(RM) Makefile.bak; \
X	$(MV) Makefile Makefile.bak; \
X	else exit 0; fi
X	$(IMAKE) $(IMAKEFLAGS) -DTOPDIR=$(TOP) -DCURDIR=$(CURRENT_DIR)
XMakefiles::
Xdepend::
Xinstall::
X
Xclean::
X	@$(RM_CMD) "#"*
X
X# -------------------------------------------------------------------------
X
X#
X# InterViews resource editor
X#
X
XMakefiles::
X	@echo "Making Makefiles" \
X	"for $(ARCH) in $(CURRENT_DIR)/$(ARCH)"
X	-@if [ ! -d $(ARCH) ]; then \
X	mkdir $(ARCH); \
X	chmod g+w $(ARCH); \
X	fi; \
X	if [ -f $(ARCH)/Makefile ]; then \
X	$(RM) $(ARCH)/Makefile.bak; \
X	$(MV) $(ARCH)/Makefile $(ARCH)/Makefile.bak; \
X	fi; \
X	$(IMAKE) $(IMAKEFLAGS) \
X	-DTOPDIR=../$(TOP) -DCURDIR=$(CURRENT_DIR)/$(ARCH) \
X	-DInObjectCodeDir -s $(ARCH)/Makefile
X
Xdepend::
X	-@for i in $(ARCH); \
X	do \
X	if [ -d $$i ]; then ( \
X	echo "depending" \
X	"for $(ARCH) in $(CURRENT_DIR)/$$i"; \
X	cd $$i; \
X	$(MAKE) $(PASSARCH) depend; \
X	) else continue; fi; \
X	done
X
Xall::
X	-@for i in $(ARCH); \
X	do \
X	if [ -d $$i ]; then ( \
X	echo "making all" \
X	"for $(ARCH) in $(CURRENT_DIR)/$$i"; \
X	cd $$i; \
X	$(MAKE) $(PASSARCH) all; \
X	) else continue; fi; \
X	done
X
Xinstall::
X	-@for i in $(ARCH); \
X	do \
X	if [ -d $$i ]; then ( \
X	echo "installing" \
X	"for $(ARCH) in $(CURRENT_DIR)/$$i"; \
X	cd $$i; \
X	$(MAKE) $(PASSARCH) install; \
X	) else continue; fi; \
X	done
X
Xclean::
X	-@for i in $(ARCH); \
X	do \
X	if [ -d $$i ]; then ( \
X	echo "cleaning" \
X	"for $(ARCH) in $(CURRENT_DIR)/$$i"; \
X	cd $$i; \
X	$(MAKE) $(PASSARCH) clean; \
X	) else continue; fi; \
X	done
X
XMakefiles.debug:
X	@$(MAKE) ARCH="$(ARCH).debug" \
X	SPECIAL_IMAKEFLAGS="$(SPECIAL_IMAKEFLAGS) -DUseDebug" \
X	Makefiles
Xdepend.debug:
X	@$(MAKE) ARCH="$(ARCH).debug" \
X	SPECIAL_IMAKEFLAGS="$(SPECIAL_IMAKEFLAGS) -DUseDebug" \
X	depend
Xall.debug:
X	@$(MAKE) ARCH="$(ARCH).debug" \
X	SPECIAL_IMAKEFLAGS="$(SPECIAL_IMAKEFLAGS) -DUseDebug" \
X	all
Xinstall.debug:
X	@$(MAKE) ARCH="$(ARCH).debug" \
X	SPECIAL_IMAKEFLAGS="$(SPECIAL_IMAKEFLAGS) -DUseDebug" \
X	install
Xclean.debug:
X	@$(MAKE) ARCH="$(ARCH).debug" \
X	SPECIAL_IMAKEFLAGS="$(SPECIAL_IMAKEFLAGS) -DUseDebug" \
X	clean
X
XMakefiles.noshared:
X	@$(MAKE) ARCH="$(ARCH).noshared" \
X	SPECIAL_IMAKEFLAGS="$(SPECIAL_IMAKEFLAGS) -DUseNonShared" \
X	Makefiles
Xdepend.noshared:
X	@$(MAKE) ARCH="$(ARCH).noshared" \
X	SPECIAL_IMAKEFLAGS="$(SPECIAL_IMAKEFLAGS) -DUseNonShared" \
X	depend
Xall.noshared:
X	@$(MAKE) ARCH="$(ARCH).noshared" \
X	SPECIAL_IMAKEFLAGS="$(SPECIAL_IMAKEFLAGS) -DUseNonShared" \
X	all
Xinstall.noshared:
X	@$(MAKE) ARCH="$(ARCH).noshared" \
X	SPECIAL_IMAKEFLAGS="$(SPECIAL_IMAKEFLAGS) -DUseNonShared" \
X	install
Xclean.noshared:
X	@$(MAKE) ARCH="$(ARCH).noshared" \
X	SPECIAL_IMAKEFLAGS="$(SPECIAL_IMAKEFLAGS) -DUseNonShared" \
X	clean
X
\End\Of\File\
else
  echo "will not over write ./Makefile"
fi
if `test ! -s ./cedit.c`
then
echo "writing ./cedit.c"
sed 's/^X//' > ./cedit.c << '\End\Of\File\'
X//
X// A simple color editor using glyphs -- Dave Sternlicht, mit X consortium
X//
X
X#include <IV-look/button.h>
X#include <IV-look/dialogs.h>
X#include <IV-look/kit.h>
X#include <IV-look/menu.h>
X#include <IV-look/field.h>
X#include <IV-look/telltale.h>
X#include <InterViews/adjust.h>
X#include <InterViews/background.h>
X#include <InterViews/box.h>
X#include <InterViews/color.h>
X#include <InterViews/display.h>
X#include <InterViews/glue.h>
X#include <InterViews/label.h>
X#include <InterViews/layout.h>
X#include <InterViews/patch.h>
X#include <InterViews/session.h>
X#include <InterViews/style.h>
X#include <InterViews/window.h>
X#include <OS/string.h>
X#include <stdio.h>
X
X//
X// InputGroup class
X//
X
Xclass InputGroup : public InputHandler {
Xpublic:
X    InputGroup(Glyph*, Style*);
X    virtual ~InputGroup();
X};
X
XInputGroup::InputGroup(Glyph* g, Style* s) : InputHandler(g, s) { }
XInputGroup::~InputGroup() { }
X
X//
X// BoundedValue class
X//
X
Xclass BoundedValue : public Adjustable {
Xprotected:
X    BoundedValue();
Xpublic:
X    BoundedValue(Coord lower, Coord upper);
X    virtual ~BoundedValue();
X
X    virtual void lower_bound(Coord);
X    virtual void upper_bound(Coord);
X    virtual void current_value(Coord);
X    virtual void scroll_incr(Coord);
X    virtual void page_incr(Coord);
X
X    virtual Coord lower(DimensionName) const;
X    virtual Coord upper(DimensionName) const;
X    virtual Coord length(DimensionName) const;
X    virtual Coord cur_lower(DimensionName) const;
X    virtual Coord cur_upper(DimensionName) const;
X    virtual Coord cur_length(DimensionName) const;
X
X    virtual void scroll_to(DimensionName, Coord position);
X    virtual void scroll_forward(DimensionName);
X    virtual void scroll_backward(DimensionName);
X    virtual void page_forward(DimensionName);
X    virtual void page_backward(DimensionName);
Xprivate:
X    Coord curvalue_;
X    Coord lower_;
X    Coord span_;
X    Coord scroll_incr_;
X    Coord page_incr_;
X};
X
X
XBoundedValue::BoundedValue() {
X    scroll_incr_ = 0.0;
X    page_incr_ = 0.0;
X}
X
XBoundedValue::BoundedValue(Coord lower, Coord upper) {
X    lower_ = lower;
X    span_ = upper - lower;
X    scroll_incr_ = span_ * 0.04;
X    page_incr_ = span_ * 0.4;
X    curvalue_ = (lower + upper) * 0.5;
X}
X
XBoundedValue::~BoundedValue() { }
X
Xvoid BoundedValue::lower_bound(Coord c) { lower_ = c; }
Xvoid BoundedValue::upper_bound(Coord c) { span_ = c - lower_; }
X
Xvoid BoundedValue::current_value(Coord value) {
X    curvalue_ = value;
X    constrain(Dimension_X, curvalue_);
X    notify(Dimension_X);
X    notify(Dimension_Y);
X}
X
Xvoid BoundedValue::scroll_incr(Coord c) { scroll_incr_ = c; }
Xvoid BoundedValue::page_incr(Coord c) { page_incr_ = c; }
X
XCoord BoundedValue::lower(DimensionName) const { return lower_; }
XCoord BoundedValue::upper(DimensionName) const { return lower_ + span_; }
XCoord BoundedValue::length(DimensionName) const { return span_; }
XCoord BoundedValue::cur_lower(DimensionName) const { return curvalue_; }
XCoord BoundedValue::cur_upper(DimensionName) const { return curvalue_; }
XCoord BoundedValue::cur_length(DimensionName) const { return 0; }
X
Xvoid BoundedValue::scroll_to(DimensionName d, Coord position) {
X    Coord p = position;
X    constrain(d, p);
X    if (p != curvalue_) {
X	curvalue_ = p;
X	notify(Dimension_X);
X	notify(Dimension_Y);
X    }
X}
X
Xvoid BoundedValue::scroll_forward(DimensionName d) {
X    scroll_to(d, curvalue_ + scroll_incr_);
X}
X
Xvoid BoundedValue::scroll_backward(DimensionName d) {
X    scroll_to(d, curvalue_ - scroll_incr_);
X}
X
Xvoid BoundedValue::page_forward(DimensionName d) {
X    scroll_to(d, curvalue_ + page_incr_);
X}
X
Xvoid BoundedValue::page_backward(DimensionName d) {
X    scroll_to(d, curvalue_ - page_incr_);
X}
X
X//
X// Valuator
X//
X
Xclass Valuator : public MonoGlyph, public Observer {
Xpublic:
X    Valuator(BoundedValue*, Style*);
X    virtual ~Valuator();
X
X    virtual InputHandler* focusable() const;
X
X    virtual void update(Observable*);
X    virtual void disconnect(Observable*);
Xprivate:
X    BoundedValue* bvalue_;
X    FieldEditor* editor_;
X
X    void accept_editor(FieldEditor*);
X    void cancel_editor(FieldEditor*);
X};
X
X
XdeclareFieldEditorCallback(Valuator)
XimplementFieldEditorCallback(Valuator)
X
XValuator::Valuator(BoundedValue* bv, Style* style) : MonoGlyph(nil) {
X    Style* s = new Style(style);
X    s->alias("Valuator");
X    bvalue_ = bv;
X    bv->attach(Dimension_X, this);
X    editor_ = DialogKit::instance()->field_editor(
X	"100.00", s,
X	new FieldEditorCallback(Valuator)(
X            this, &Valuator::accept_editor, &Valuator::cancel_editor
X        )
X    );
X    body(editor_);
X    update(bv->observable(Dimension_X));
X}
X
XValuator::~Valuator() {
X    if (bvalue_ != nil) {
X	bvalue_->detach(Dimension_X, this);
X    }
X}
X
X
XInputHandler* Valuator::focusable() const {
X    return editor_;
X}
X
Xvoid Valuator::update(Observable*) {
X    Coord v = bvalue_->cur_lower(Dimension_X);
X    char buf[20];
X    sprintf(buf, "%.2f", v);
X    editor_->field(buf);
X}
X
Xvoid Valuator::disconnect(Observable*) {
X    bvalue_ = nil;
X}
X
Xvoid Valuator::accept_editor(FieldEditor*) {
X    Coord v;
X    const String& value = *editor_->text();
X    if (value.convert(v)) {
X	bvalue_->current_value(v);
X    }
X}
X
Xvoid Valuator::cancel_editor(FieldEditor*) {
X    update(bvalue_->observable(Dimension_X));
X}
X
X//
X// ColorViewer
X//
X
Xclass ColorViewer : public Patch, public Observer {
Xpublic:
X    ColorViewer(BoundedValue*, BoundedValue*, BoundedValue*, Style*);
X    virtual ~ColorViewer();
X
X    virtual void allocate(Canvas*, const Allocation&, Extension&);
X    virtual void draw(Canvas*, const Allocation&) const;
X    virtual void update(Observable*);
X    virtual void disconnect(BoundedValue*);
Xprivate:
X    Adjustable* red_;
X    Adjustable* green_;
X    Adjustable* blue_;
X    Color* color_;
X};
X
XColorViewer::ColorViewer(
X    BoundedValue* r, BoundedValue* g, BoundedValue* b, Style*
X) : Patch(nil) {
X    red_ = r;
X    red_->attach(Dimension_X, this);
X    green_ = g;
X    green_->attach(Dimension_X, this);
X    blue_ = b;
X    blue_->attach(Dimension_X, this);
X    color_ = nil;
X}
X
XColorViewer::~ColorViewer() {
X    if (red_ != nil) {
X	red_->detach(Dimension_X, this);
X    }
X    if (green_ != nil) {
X	green_->detach(Dimension_X, this);
X    }
X    if (blue_ != nil) {
X	blue_->detach(Dimension_X, this);
X    }
X}
X
Xvoid ColorViewer::allocate(Canvas* c, const Allocation& a, Extension& ext) {
X    ext.set(c, a);
X    Patch::allocate(c, a, ext);
X}
X
Xvoid ColorViewer::draw(Canvas* c, const Allocation& a) const {
X    c->fill_rect(a.left(), a.bottom(), a.right(), a.top(), color_);
X}
X
Xvoid ColorViewer::update(Observable*) {
X    Resource::unref(color_);
X    color_ = new Color(
X	float(red_->cur_lower(Dimension_X)),
X	float(green_->cur_lower(Dimension_X)),
X	float(blue_->cur_lower(Dimension_X)),
X	1.0
X    );
X    Resource::ref(color_);
X    redraw();
X}
X
Xvoid ColorViewer::disconnect(BoundedValue* a) {
X    if (a == red_) {
X	red_ = nil;
X    } else if (a == green_) {
X	green_ = nil;
X    } else if (a == blue_) {
X	blue_ = nil;
X    }
X}
X
X//
X// main
X//
X
Xint main(int argc, char** argv) {
X    Session* session = new Session(
X	"ColorViewer", argc, argv);
X    Style* style = session->style();
X    WidgetKit& kit = *WidgetKit::instance();
X    LayoutKit& layout = *LayoutKit::instance();
X    BoundedValue* bv1 = new BoundedValue(0.0, 1.0);
X    BoundedValue* bv2 = new BoundedValue(0.0, 1.0);
X    BoundedValue* bv3 = new BoundedValue(0.0, 1.0);
X    Window* w = new ApplicationWindow(
X	new Background(
X	    layout.hbox(
X		layout.vbox(
X		    layout.vcenter(
X			layout.hbox(
X                            layout.margin(
X                                kit.push_button("Quit", kit.quit()),
X                                2.0
X                            ),
X			    new Valuator(bv1, style),
X			    new Valuator(bv2, style),
X			    new Valuator(bv3, style)
X			),
X			1.0
X		    ),
X		    layout.v_fixed_span(
X			new ColorViewer(bv1, bv2, bv3, style),
X			144.0
X		    ),
X		),
X		kit.vscroll_bar(bv1),
X		kit.vscroll_bar(bv2),
X		kit.vscroll_bar(bv3)
X	    ),
X	    kit.background()
X	)
X    );
X    bv1->current_value(0.5);
X    bv2->current_value(0.5);
X    bv3->current_value(0.5);
X    return session->run_window(w);
X}
X
\End\Of\File\
else
  echo "will not over write ./cedit.c"
fi
echo "Finished archive 1 of 1"
exit