Article View: comp.windows.misc
Article #824Re: Does anyone really understand windows?
From: Miles Bader
Date: Tue, 16 Feb 1988 23:30
Date: Tue, 16 Feb 1988 23:30
157 lines
3891 bytes
3891 bytes
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
Technical Details
Message-ID:
<sW6BGny00UhBwhM08h@andrew.cmu.edu>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!bbn!rochester!PT.CS.CMU.EDU!andrew.cmu.edu!bader+References:
<1457@sugar.UUCP>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!bbn!rochester!PT.CS.CMU.EDU!andrew.cmu.edu!bader+ From: bader+@andrew.cmu.edu (Miles Bader) Newsgroups: comp.windows.misc Subject: Re: Does anyone really understand windows? Message-ID: <sW6BGny00UhBwhM08h@andrew.cmu.edu> Date: 16 Feb 88 23:30:59 GMT References: <1457@sugar.UUCP> Organization: Carnegie Mellon University Lines: 156 In-Reply-To: <1457@sugar.UUCP>