home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 10
/
Fresh_Fish_10_2352.bin
/
fishdisks
/
d1001.lha
/
Programs
/
AmigaGuide
/
AG_V34
/
Source
/
HyperApp.c
next >
Wrap
C/C++ Source or Header
|
1992-12-30
|
15KB
|
681 lines
/* HyperApp.c
*/
#include <exec/types.h>
#include <exec/libraries.h>
#include <intuition/intuition.h>
#include <graphics/gfx.h>
#include <graphics/text.h>
#include <libraries/amigaguide.h>
#include <clib/alib_protos.h>
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include <clib/graphics_protos.h>
#include <clib/amigaguide_protos.h>
#include <pragmas/amigaguide_pragmas.h>
#include <stdio.h>
#define DB(x) ;
struct AppInfo
{
struct Window *ai_Window; /* Window pointer */
BOOL ai_Done; /* Done yet? */
AMIGAGUIDECONTEXT ai_AmigaGuide; /* Pointer to the AmigaGuide context */
LONG ai_Region; /* Region that the mouse if over */
struct TextFont *ai_Font; /* Window font */
};
struct FuncTable
{
VOID (*ft_Func) (struct AppInfo *);
};
struct EMenuItem
{
struct MenuItem em_MenuItem; /* Embedded menu structure */
LONG em_MenuID; /* Menu ID */
};
extern struct Library *SysBase, *DOSBase;
struct Library *IntuitionBase, *GfxBase, *AmigaGuideBase;
VOID MainFunc (struct AppInfo *);
VOID QuitFunc (struct AppInfo *);
VOID GadgetFunc (struct AppInfo *);
VOID OkayFunc (struct AppInfo *);
VOID CancelFunc (struct AppInfo *);
/* Context ID's to be sent to AmigaGuide */
STRPTR context[] =
{
"MAIN",
"QUIT",
"GADGET",
"OKAY",
"CANCEL",
NULL
};
/* Simple little prompts to display within the application window */
STRPTR quickhelp[] =
{
"HyperApp Main Window",
"",
"Transmogrify Objects",
"Positive Quit",
"Negative Quit",
NULL
};
struct FuncTable Funcs[] =
{
MainFunc,
QuitFunc,
GadgetFunc,
OkayFunc,
CancelFunc,
NULL
};
struct TextAttr TOPAZ8 =
{(STRPTR) "topaz.font", 8, 0, 0};
struct IntuiText IText3 =
{
0, 0, JAM1, 2, 1, &TOPAZ8, "Quit", NULL
};
struct EMenuItem MenuItem1 =
{
NULL, 0, 0, 142, 9, ITEMTEXT | COMMSEQ | ITEMENABLED | HIGHCOMP,
0, (APTR) & IText3, NULL, 'Q', NULL, MENUNULL, 1L
};
struct Menu Menu1 =
{
NULL, 2, 0, 64, 0, MENUENABLED, "Project", (struct MenuItem *) & MenuItem1
};
SHORT BData1[] =
{0, 0, 94, 0, 94, 13, 0, 13, 0, 0};
SHORT BData2[] =
{0, 0, 94, 0, 94, 13, 0, 13, 0, 0};
struct Border Border1 =
{0, 0, 1, 0, JAM1, 5, BData1, NULL};
struct Border Border2 =
{0, 0, 1, 0, JAM1, 5, BData2, NULL};
struct IntuiText IText1 =
{1, 0, JAM2, 26, 3, &TOPAZ8, "Cancel", NULL};
struct IntuiText IText2 =
{1, 0, JAM2, 40, 3, &TOPAZ8, "OK", NULL};
struct Gadget Gadget3 =
{
NULL, -120, -18, 95, 14, GRELBOTTOM | GRELRIGHT, RELVERIFY, BOOLGADGET,
(APTR) & Border1, NULL, &IText1, NULL, NULL, 4L, NULL
};
struct Gadget Gadget2 =
{
&Gadget3, 12, -18, 95, 14, GRELBOTTOM, RELVERIFY, BOOLGADGET,
(APTR) & Border2, NULL, &IText2, NULL, NULL, 3L, NULL
};
struct Gadget Gadget1 =
{
&Gadget2, 12, 27, -40, -48, GADGHCOMP | GRELWIDTH | GRELHEIGHT | SELECTED,
TOGGLESELECT | RELVERIFY, BOOLGADGET, NULL, NULL, NULL, NULL, NULL,
2L, NULL
};
struct TagItem WinTags[] =
{
WA_MenuHelp, TRUE,
TAG_DONE,
};
/* NewWindow Structures */
struct ExtNewWindow NewWindowStructure1 =
{
0, 0, 640, 100, -1, -1,
IDCMP_RAWKEY | IDCMP_CLOSEWINDOW | IDCMP_MENUPICK | IDCMP_MENUHELP |
IDCMP_GADGETUP | IDCMP_MOUSEMOVE,
WINDOWSIZING | WINDOWDRAG | WINDOWDEPTH | WINDOWCLOSE | WFLG_REPORTMOUSE |
SIZEBRIGHT | ACTIVATE | NOCAREREFRESH | WFLG_NW_EXTENDED,
&Gadget1, NULL, "HyperApp (Press HELP over Gadget or Menu)", NULL, NULL,
320, 50, 65535, 65535, WBENCHSCREEN, WinTags,
};
/* Determine if a point is within a rectangle */
ULONG PointInBox (WORD x, WORD y, struct IBox * box)
{
if ((x >= box->Left) &&
(x <= (box->Left + box->Width)) &&
(y >= box->Top) &&
(y <= (box->Top + box->Height)))
{
return (1L);
}
return (0L);
}
/* Find the rectangle of a gadget */
VOID gadgetBox (struct Gadget * g, struct IBox * domain, struct IBox * box)
{
/* Set the 'normal' rectangle */
box->Left = g->LeftEdge;
box->Top = g->TopEdge;
box->Width = g->Width;
box->Height = g->Height;
/* Check for relativity */
if (g->Flags & GRELRIGHT)
box->Left += domain->Width - 1;
if (g->Flags & GRELBOTTOM)
box->Top += domain->Height - 1;
if (g->Flags & GRELWIDTH)
box->Width += domain->Width;
if (g->Flags & GRELHEIGHT)
box->Height += domain->Height;
}
/* Process menu events */
VOID HandleMenuEvent (struct IntuiMessage * msg)
{
struct Window *win = msg->IDCMPWindow;
struct AppInfo *ai = (struct AppInfo *) win->UserData;
UWORD selection = msg->Code;
struct EMenuItem *item;
/* Turn off the menu button */
win->Flags |= RMBTRAP;
/* Process all menu events */
while (selection != MENUNULL)
{
/* Get the MenuItem structure address */
if (item = (struct EMenuItem *)
ItemAddress (win->MenuStrip, (LONG) selection))
{
(*(Funcs[item->em_MenuID].ft_Func)) (ai);
/* Get the next selection */
selection = item->em_MenuItem.NextSelect;
}
else
{
selection = MENUNULL;
}
}
/* Turn menu events back on. */
win->Flags &= ~RMBTRAP;
}
/* Process MenuHelp events */
VOID HandleMenuHelp (struct IntuiMessage * msg)
{
struct Window *win = msg->IDCMPWindow;
struct AppInfo *ai = (struct AppInfo *) win->UserData;
struct EMenuItem *item;
WORD mnum, inum, snum;
mnum = MENUNUM (msg->Code);
inum = ITEMNUM (msg->Code);
snum = SUBNUM (msg->Code);
printf ("m %d i %d s %d\n", mnum, inum, snum);
/* Get the MenuItem structure address */
if (item = (struct EMenuItem *)
ItemAddress (win->MenuStrip, (LONG) msg->Code))
{
/* Set the AmigaGuide context */
SetAmigaGuideContext (ai->ai_AmigaGuide, item->em_MenuID, NULL);
/* Display the node */
SendAmigaGuideContext (ai->ai_AmigaGuide, NULL);
}
else
{
/* No selectable item where help was pressed */
printf ("No item here\n");
}
}
/* Process MouseMove events */
VOID HandleMouseMove (struct IntuiMessage * msg)
{
struct Window *win = msg->IDCMPWindow;
struct AppInfo *ai = (struct AppInfo *) win->UserData;
struct Gadget *gad = win->FirstGadget;
struct IBox box;
LONG region;
if ((msg->MouseX < 0) || (msg->MouseX > win->Width) ||
(msg->MouseY < 0) || (msg->MouseY > win->Height))
{
region = -1L;
}
else
{
region = 0L;
/* Step through the gadgets to see which one the pointer was over */
while (gad && (region == 0L))
{
/* Calculate the gadget rectangle */
gadgetBox (gad, (struct IBox *) & (win->LeftEdge), &box);
/* Is the pointer within this gadget? */
if (PointInBox (msg->MouseX, msg->MouseY, &box))
{
/* Is it a system gadget? */
if (!(gad->GadgetType & GTYP_SYSGADGET))
{
/* Set the region */
region = (LONG) gad->GadgetID;
}
}
/* Get the next gadget */
gad = gad->NextGadget;
}
}
if (region != ai->ai_Region)
{
WORD tx, ty;
WORD bx, by;
tx = win->BorderLeft + 8;
ty = win->BorderTop + 2;
bx = win->Width - (win->BorderRight + 8);
by = ty + win->RPort->TxHeight;
SetDrMd (win->RPort, JAM1);
/* Clear the quick help region */
SetAPen (win->RPort, 0);
RectFill (win->RPort, tx, ty, bx, by);
/* Remember the region */
ai->ai_Region = region;
/* Display the quick help if within the window */
if (region >= 0)
{
SetAPen (win->RPort, 1);
Move (win->RPort, tx, ty + win->RPort->TxBaseline);
Text (win->RPort, quickhelp[region], strlen (quickhelp[region]));
}
}
}
/* Process GadgetHelp events */
VOID HandleGadgetHelp (struct IntuiMessage * msg)
{
struct Window *win = msg->IDCMPWindow;
struct AppInfo *ai = (struct AppInfo *) win->UserData;
struct Gadget *gad = win->FirstGadget;
struct IBox box;
LONG region;
region = 0L;
/* Step through the gadgets to see which one the pointer was over */
while (gad && (region == 0L))
{
/* Calculate the gadget rectangle */
gadgetBox (gad, (struct IBox *) & (win->LeftEdge), &box);
/* Is the pointer within this gadget? */
if (PointInBox (msg->MouseX, msg->MouseY, &box))
{
/* Is it a system gadget? */
if (gad->GadgetType & GTYP_SYSGADGET)
{
ULONG sys;
/* Which system gadg