[comp.windows.misc] Does anyone really understand windows?

peter@sugar.UUCP (Peter da Silva) (02/16/88)

Well, the main impression I got from Usenix is this:

Everyone is rushing to do windows.

Nobody understands how to support them.

Now, I'll be the first to admit that I don't have any better answers than
anyone else. But I think that somewhere out there is the window paradigm
that will do for windowing systems what UNIX did for command-line-oriented
systems. Right now we're floundering in JCL land. At least for the programmers.

Xwindows sure isn't it (see "How hard is it to write ``Hello World'' anyway?").
Widgets sound like a promising idea, though.

NeWS isn't it (display postscript makes me think of "//DD SYSIN...").

The Mac Toolbox definitely isn't it (SKEL for the Mac is even longer than
Xwindows' "Hello World").

The Amiga Intuition has the simplest "Hello World" I've seen *... doesn't talk
to UNIX, though. Pity.

SmallTalk is pretty good, though slow (see "display postscript").

The Andrew people didn't get too much into the gory details... any info?

So... forget this "best window system" stuff.

Anyone at least got a good one?

----------
* Amiga "Hello World", modulo bugs.

#include <stdio.h>

main(ac, av)
int ac;
char **av;
{
	FILE *fp, op;

	if(!(fp = fopen("RAW:0/0/160/10/Hello World", "w"))) {
		perror("Can't open window");
		exit(1);
	}
	op = fdopen(fileno(fp), "r");
	getc(op);
	fclose(op);
	exit(0);
}
-- 
-- Peter da Silva  `-_-'  ...!hoptoad!academ!uhnix1!sugar!peter
-- Disclaimer: These U aren't mere opinions... these are *values*.

bader+@andrew.cmu.edu (Miles Bader) (02/17/88)

Here's a program for the "Andrew Toolkit" that displays helloworld in a 
window...  Note that it (like the Xtk version in David Rosenthal's paper) 
isn't a good example if you want to do more than use pre-existing views & 
dataobjects or combinations thereof (but see the second version later in this 
message).

/* --------------- start file hwapp.H --------------- */
class hwapp : application{
    overrides:
	Start() returns boolean;
};
/* --------------- end file hwapp.H --------------- */

/*  --------------- start file hwapp.c --------------- */
#include <class.h>

#include "hwapp.eh"

#include "im.ih"
#include "text.ih"
#include "textview.ih"

boolean hwapp__Start(self)
struct hwapp *self;
{
    struct text *t;
    struct textview *tv;
    struct im *im;

    if(!super_Start(self))
	return FALSE;

    t=text_New();
    if(t==NULL)
	return FALSE;

    text_InsertCharacters(t,0,"Hello world!",sizeof("Hello world!")-1);

    tv=textview_New();
    if(tv==NULL){
	text_Destroy(t);
	return FALSE;
    }

    textview_SetDataObject(tv,t);

    im=im_Create(NULL);		/* an im is effectively a window */
    if(im==NULL){
	text_Destroy(t);
	textview_Destroy(tv);
	return FALSE;
    }

    im_SetView(im,tv);

    return TRUE;
}
/*  --------------- end file hwapp.c --------------- */

To compile it, I type:
	class -I/usr/andy/include/be2 hwapp.H
	cc -c -I/usr/andy/include -I/usr/andy/include/be2 hwapp.c
	makedo hwapp.o

And to run it:
	runapp hwapp

or alternatively:
	ln -s /usr/andy/bin/runapp hw
	hw


Here's the same program, but using a custom view:

First, the driver:

/*  --------------- start file hwapp.H --------------- */
class hwapp : application{
    overrides:
	Start() returns boolean;
};
/*  --------------- end file hwapp.H --------------- */

/*  --------------- start file hwapp.c --------------- */
#include <class.h>

#include "hwapp.eh"

#include "im.ih"
#include "helloworld.ih"

boolean hwapp__Start(self)
struct hwapp *self;
{
    struct helloworld *hw;
    struct im *im;

    if(!super_Start(self))
	return FALSE;

    hw=helloworld_New();
    if(hw==NULL)
	return FALSE;

    im=im_Create(NULL);
    if(im==NULL){
	helloworld_Destroy(hw);
	return FALSE;
    }

    im_SetView(im,hw);

    return TRUE;
}
/*  --------------- end file hwapp.c --------------- */

Now, the view:

/*  --------------- start file helloworld.H --------------- */
class helloworld : view {
    overrides:
        FullUpdate(enum view_UpdateType type, long left, long top, long width, 
long right);
};
/*  --------------- end file helloworld.H --------------- */

/*  --------------- start file helloworld.c --------------- */
#include <class.h>

#include "helloworld.eh"

#include "graphic.ih"

void helloworld__FullUpdate(hw, type, left, top, width, height)
struct helloworld *hw;
enum view_UpdateType type;
long left;
long top;
long width;
long height;
{
    int x,y;
    struct rectangle VisualRect;		

    helloworld_GetVisualBounds(hw,&VisualRect);
    x = rectangle_Left(&VisualRect) + rectangle_Width(&VisualRect)/2;
    y = rectangle_Top(&VisualRect) + rectangle_Height(&VisualRect)/2;

    helloworld_MoveTo(hw,x,y);
    helloworld_DrawString(hw,"hello world",
	graphic_BETWEENTOPANDBASELINE | graphic_BETWEENLEFTANDRIGHT);    
}
/*  --------------- end file helloworld.c --------------- */

-Miles

guido@cwi.nl (Guido van Rossum) (02/17/88)

Now that we seem to be sending in "hello world" for our favourite
window programming system, here's mine for "STDWIN".  No preprocessing
needed, just compile and link with the appropriate libraries.  STDWIN is
not a window system in its own right; it is a toolbox which interfaces
to several existing window systems.  Versions exist for: Whitechapel
MG-1, X version 11, Apple Macintosh, Atari ST (soon), and (a text-only
subset) for ASCII terminals supported by termcap.  Inquire at address
below.

Guido van Rossum, Centre for Mathematics and Computer Science (CWI), Amsterdam
guido@cwi.nl or mcvax!guido or (from ARPAnet) guido%cwi.nl@uunet.uu.net

/* The "Hello, world" koan according to David Rosenthal,
   recoded for STDWIN.
   Requirements: print "Hello, world" centered in a window,
   recented after window resizes, redraw after window exposures.
   Check error returns. */

#include <stdwin.h>

char *string= "Hello, world";

int text_h, text_v;

placetext(win)
	WINDOW *win;
{
	int width, height;
	wgetwinsize(win, &width, &height);
	text_v= (height - wlineheight()) / 2;
	text_h= (width - wtextwidth(string, -1)) / 2;
}

drawproc(win, left, top, right, bottom)
	WINDOW *win;
{
	wdrawtext(text_h, text_v, string, -1);
}

main()
{
	WINDOW *win;
	winit();
	win= wopen("Hello", drawproc);
	
	if (win != 0) {
		placetext(win);
		for (;;) {
			EVENT e;
			wgetevent(&e);
			if (e.type == WE_COMMAND &&
				(e.u.command == WC_CLOSE ||
				 e.u.command == WC_CANCEL))
				break;
			if (e.type == WE_SIZE)
				placetext(win);
		}
	}
	
	wdone();
	exit(0);
}

mh@wlbr.EATON.COM (Mike Hoegeman) (02/18/88)

In article <sW6BGny00UhBwhM08h@andrew.cmu.edu> bader+@andrew.cmu.edu (Miles Bader) writes:
>
>Here's a program for the "Andrew Toolkit" that displays helloworld in a 
>window...  Note that it (like the Xtk version in David Rosenthal's paper) 
>isn't a good example if you want to do more than use pre-existing views & 
>dataobjects or combinations thereof (but see the second version later in this 
>message).


Here's A hello world window in NeWSpeak...
this is just off the top of my head but it's close enough
so you can get the idea of how the object oriented stuff
in NeWS works. It prints Hello world in the bottom left
hand corner of the window.

% send a new method to the DefaultWindow class object...
% it'll return an instance of the DefaultWindow window class
% which we'll call HelloWorldWindow 

/HelloWorldWindow framebuffer /new DefaultWindow send def

% Now send the window the title it should have and the routine to
% use to repaint when it gets damaged, resized, etc...

{
	/PaintClient { painthelloworld } def
	/FrameLabel (Hello World) def
} HelloWorldWindow send 

% the paint hello world proc...
/painthelloworld {
	gsave
	4 4 moveto 1 1 1 sethsbcolor /Times-Bold findfont 14 scalefont setfont
	(Hello World) show
	grestore
} def

% have the user drag the window size ...
/reshapefromuser HelloWorldWindow send

% and display the window...
/map HelloworldWindow send

a whopping 13 lines of postscript!

hmm@laura.UUCP (Hans-Martin Mosner) (02/25/88)

Well, since everyone is posting Hello World in their favorite window
system, here's my Smalltalk-80 version.
This is typed in from a printout (the Mac on which I have written it does not
have a connection to this host yet), but I'm fairly sure I did not make
any typos...

'From Smalltalk-80, Version 2.2 of July 4, 1987 on 24 February 1988 at 5:07:07 pm'!

View subclass: #CenteredTextView
	instanceVariableNames: 'paragraph '
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Hello'!

!CenteredTextView methodsFor: 'displaying'!

displayView
	paragraph displayOn: Display
	at: (paragraph boundingBox
		align: paragraph boundingBox center
		with: self insetDisplayBox center) origin
	clippingBox: self insetDisplayBox
	rule: 3
	mask: Form black! !

!CenteredTextView methodsFor: 'private'!

setParagraph: aParagraph
	paragraph _ aParagraph! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --"!

CenteredTextView class
	instanceVariableNames: ''!

!CenteredTextView class methodsFor: 'instance creation'!

open: aTextOrString label: aString
	| topView |
	topView _ StandardSystemView
			model: nil
			label: aString
			minimumSize: 50@40.
	topView addSubView: (self text: aTextOrString).
	topView controller open!

text: aTextOrString
	^self new setParagraph: aTextOrString asParagraph centered;
		borderWidth: 1! !

!CenteredTextView class methodsFor: 'examples'!

hello
	"CenteredTextView hello"
	self open: 'Hello World!" label: 'Hello'! !
-- 
Hans-Martin Mosner		| Don't tell Borland about Smalltalk - |
hmm@unido.{uucp,bitnet}		| they might invent Turbo Smalltalk !  |
------------------------------------------------------------------------
Disclaimer: Turbo Smalltalk may already be a trademark of Borland...

hmm@laura.UUCP (Hans-Martin Mosner) (02/25/88)

oops, one typo slipped in: in the last line, I've typed a " instead of '.

-- 
Hans-Martin Mosner		| Don't tell Borland about Smalltalk - |
hmm@unido.{uucp,bitnet}		| they might invent Turbo Smalltalk !  |
------------------------------------------------------------------------
Disclaimer: Turbo Smalltalk may already be a trademark of Borland...