home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
new
/
util
/
cdity
/
yak
/
src
/
help.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-10-05
|
12KB
|
393 lines
/*
* help.c
*
* Opens help/settings window and handles events.
* For yak.
*
* Martin W. Scott, 12-Sep-92.
*/
#include <exec/types.h>
#include <dos/dosextens.h>
#include <graphics/gfxmacros.h>
#include <libraries/commodities.h>
#include <intuition/gadgetclass.h>
#include <intuition/intuition.h>
#include <libraries/gadtools.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/intuition.h>
#include <proto/gadtools.h>
#include <proto/graphics.h>
#include <proto/commodities.h>
#include <string.h>
#include "yak.h"
#include "hotkey_types.h"
#include "gui.h"
#include "version.h"
#define CATCOMP_NUMBERS
#include "locale/yak_locale_strings.h"
extern LONG (*HandleIDCMP)(void);
struct Window *curwin;
/* static protos */
static void InitRootGadgets(void);
static __regargs void NewPattern(UWORD gdx, UWORD n, struct Gadget *gad);
BOOL ShowRootWindow(void);
static BOOL SwitchToHotkeyWindow(void);
static BOOL SwitchToMiscWindow(void);
static BOOL SwitchToBlankWindow(void);
/* menu numbers */
#define LOAD 0
#define SAVE 1
#define HIDE 2
#define QUIT 3
/* initialise individual gadget in specified window */
__regargs void
InitWindowGadget(UWORD num, LONG tagtype, LONG tagvalue, UBYTE WindowID)
{
switch(WindowID)
{
case ROOT_WINDOW:
GT_SetGadgetAttrs(RootGadgets[num], RootWnd, NULL, tagtype, tagvalue, TAG_DONE);
break;
case HOTKEY_WINDOW:
GT_SetGadgetAttrs(HotKeyGadgets[num], HotKeyWnd, NULL, tagtype, tagvalue, TAG_DONE);
break;
case MISC_WINDOW:
GT_SetGadgetAttrs(MiscGadgets[num], MiscWnd, NULL, tagtype, tagvalue, TAG_DONE);
break;
case BLANK_WINDOW:
GT_SetGadgetAttrs(BlankGadgets[num], BlankWnd, NULL, tagtype, tagvalue, TAG_DONE);
break;
case KEYDEF_WINDOW:
GT_SetGadgetAttrs(KeyDefGadgets[num], KeyDefWnd, NULL, tagtype, tagvalue, TAG_DONE);
break;
}
}
__regargs void
InitToggleGadgets( UBYTE WindowID )
{
UWORD i;
for (i = 0; i < NUM_TOGGLES; i++)
if ((toggles[i].gadid != -1) &&
(toggles[i].winid == WindowID))
{
InitWindowGadget(toggles[i].gadid,
GTCB_Checked,
toggles[i].pos,
WindowID);
}
}
/* initialise all gadgets */
static void
InitRootGadgets(void)
{
InitToggleGadgets(ROOT_WINDOW);
InitWindowGadget(GDX_AutoPat, GTST_String, (LONG)patterns[YP_AUTOSCR_PAT].patstr, ROOT_WINDOW);
InitWindowGadget(GDX_ClickPat, GTST_String, (LONG)patterns[YP_CLICKSCR_PAT].patstr, ROOT_WINDOW);
InitWindowGadget(GDX_PopPat, GTST_String, (LONG)patterns[YP_POPWIN_PAT].patstr, ROOT_WINDOW);
InitWindowGadget(GDX_ClickWinPat, GTST_String, (LONG)patterns[YP_CLICKWIN_PAT].patstr, ROOT_WINDOW);
}
/* show current window */
BOOL
ShowYakInterface(void)
{
if (curwin) /* already opened */
{
ScreenToFront(curwin->WScreen);
WindowToFront(curwin);
ActivateWindow(curwin);
return TRUE;
}
if (SetupScreen())
return FALSE;
return ShowRootWindow();
}
/* show our Root window */
BOOL
ShowRootWindow(void)
{
InitGUI ();
if (!OpenRootWindow()) /* like the name says... */
{
InitRootGadgets();
wndsigflag = 1 << RootWnd->UserPort->mp_SigBit;
HandleIDCMP = HandleRootIDCMP;
curwin = RootWnd;
return TRUE;
}
FreeGadgets(RootGList);
FreeMenus(RootMenus);
CloseDownScreen();
curwin = NULL;
wndsigflag = 0L;
return FALSE;
}
/* update windows position for next openings */
void
UpdateWindowsPosition (void)
{
RootLeft = curwin->LeftEdge;
WindowTop = curwin->TopEdge;
}
/* hide our window */
void
HideInterface(void)
{
if (curwin)
{
UpdateWindowsPosition();
if (RootWnd)
CloseRootWindow();
else
if (MiscWnd)
CloseMiscWindow();
else
if (HotKeyWnd)
CloseHotKeyWindow();
else
if (BlankWnd)
CloseBlankWindow();
else
CloseKeyDefWindow();
CloseDownScreen();
wndsigflag = NULL;
curwin = NULL;
}
}
/* switch from Root window to hotkey window */
static BOOL
SwitchToHotkeyWindow(void)
{
HotKeyLeft = RootWnd->LeftEdge;
WindowTop = RootWnd->TopEdge;
CloseRootWindow();
return ShowHotKeyWindow();
}
/* switch from Root window to misc window */
static BOOL
SwitchToMiscWindow(void)
{
MiscLeft = RootWnd->LeftEdge;
WindowTop = RootWnd->TopEdge;
CloseRootWindow();
return ShowMiscWindow();
}
/* switch from Root window to blank window */
static BOOL
SwitchToBlankWindow(void)
{
BlankLeft = RootWnd->LeftEdge;
WindowTop = RootWnd->TopEdge;
CloseRootWindow();
return ShowBlankWindow();
}
/* handle pattern string-gadget */
static __regargs void
NewPattern(UWORD gdx, UWORD n, struct Gadget *gad)
{
char *newpatstr;
newpatstr = GetString(gad);
if (!InitPattern(newpatstr, n))
{
DisplayBeep(Scr);
InitWindowGadget(gdx, GTST_String, (LONG)patterns[n].patstr, ROOT_WINDOW);
}
}
/* handle Root window events */
LONG
HandleRootIDCMP(void)
{
struct IntuiMessage *msg;
struct Gadget *gadget;
ULONG class;
UWORD code;
while (msg = GT_GetIMsg(RootWnd->UserPort))
{
class = msg->Class;
code = msg->Code;
gadget = (struct Gadget *)msg->IAddress;
GT_ReplyIMsg(msg);
switch (class)
{
case CLOSEWINDOW:
HideInterface();
return ROOT_OKAY;
case GADGETUP:
case GADGETDOWN:
switch (gadget->GadgetID)
{
case GD_EditHotkeys:
if (!SwitchToHotkeyWindow())
PostError(getString(Couldnt_open_other_window_ERR));
return ROOT_OKAY;
case GD_Miscellaneous:
if (!SwitchToMiscWindow())
PostError(getString(Couldnt_open_other_window_ERR));
return ROOT_OKAY;
case GD_Blanking:
if (!SwitchToBlankWindow())
PostError(getString(Couldnt_open_other_window_ERR));
return ROOT_OKAY;
case GD_AutoPat:
NewPattern(GDX_AutoPat, YP_AUTOSCR_PAT, gadget);
break;
case GD_ClickPat:
NewPattern(GDX_ClickPat, YP_CLICKSCR_PAT, gadget);
break;
case GD_PopPat:
NewPattern(GDX_PopPat, YP_POPWIN_PAT, gadget);
break;
case GD_ClickWinPat:
NewPattern(GDX_ClickWinPat, YP_CLICKWIN_PAT, gadget);
break;
case GD_Hide:
HideInterface();
return ROOT_O