Reaction Window Example code

/* Reaction Window */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <exec/types.h>
#include <exec/memory.h>

#include <intuition/intuition.h>
#include <intuition/icclass.h>
#include <intuition/classes.h>
#include <clib/reaction_lib_protos.h>
#include <proto/intuition.h>
#include <workbench/startup.h>
#include <workbench/workbench.h>
#include <utility/tagitem.h>
#include <proto/exec.h>
#include <proto/window.h>
#include <proto/layout.h>

#include <classes/window.h>
#include <gadgets/layout.h>
#include <clib/alib_protos.h>

#include <reaction/reaction.h>
#include <reaction/reaction_macros.h>

enum
{
GID_MAIN=0,
GID_INTEGER1,
GID_INTEGER2,
GID_DOWN,
GID_UP,
GID_QUIT,
GID_LAST
};
enum
{
WID_MAIN=0,
WID_LAST
};
enum
{
OID_MAIN=0,
OID_LAST
};

int main(void)
{
struct Window *windows[WID_LAST];
struct Library *WindowBase, *LayoutBase;
struct MsgPort *AppPort;
Object *objects[OID_LAST];
ULONG wait, signal, app, done, result;
UWORD code;

WindowBase = (struct Library *)OpenLibrary("window.class", 44);
LayoutBase = (struct Library *)OpenLibrary("gadgets/layout.gadget", 44);

if (!WindowBase || !LayoutBase) {
printf("A library could not be opened!\n");
return(30);
}
else if (AppPort = CreateMsgPort() )
{
objects[OID_MAIN] = WindowObject,
WA_ScreenTitle, "ReAction",
WA_Title, "ReAction Window Example",
WA_Activate, TRUE,
WA_DepthGadget, TRUE,
WA_DragBar, TRUE,
WA_CloseGadget, TRUE,
WA_SizeGadget, TRUE,
WA_Width, 200,
WA_Height, 150,
WINDOW_IconifyGadget, TRUE,
WINDOW_IconTitle, "Example",
WINDOW_AppPort, AppPort,
WINDOW_Position, WPOS_CENTERMOUSE,
WINDOW_ParentGroup, VLayoutObject,
LAYOUT_SpaceOuter, TRUE,
LAYOUT_DeferLayout, TRUE,
EndGroup,
EndWindow;

if (objects[OID_MAIN])
{
if (windows[WID_MAIN] = (struct Window *)RA_OpenWindow(objects[OID_MAIN]))
{
app = (1L << AppPort->mp_SigBit);
done = FALSE;
GetAttr(WINDOW_SigMask, objects[OID_MAIN], &signal);

while (!done)
{
wait = Wait( signal | SIGBREAKF_CTRL_C | app);
if (wait & SIGBREAKF_CTRL_C)
{
done = TRUE;
} else {
while (( result = RA_HandleInput(objects[OID_MAIN], &code)) != WMHI_LASTMSG)
{
switch (result & WMHI_CLASSMASK)
{
case WMHI_CLOSEWINDOW:
windows[WID_MAIN]=NULL;
done=TRUE;
break;
}
} /* End while */
} /* End if */
} /* End while */
DisposeObject(objects[OID_MAIN]);
} /* End if */
DeleteMsgPort(AppPort);
} /* End if */

if (WindowBase) CloseLibrary(WindowBase);
if (LayoutBase) CloseLibrary(LayoutBase);
return(0);
} /* End if */
} /* End main */