home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 1: Amiga
/
FrozenFish-Apr94.iso
/
bbs
/
alib
/
d5xx
/
d534
/
term.lha
/
Term
/
Source.LZH
/
MacroPanel.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-07-07
|
14KB
|
480 lines
/* $Revision Header * Header built automatically - do not edit! *************
*
* (C) Copyright 1990 by Olaf 'Olsen' Barthel & MXM
*
* Name .....: MacroPanel.c
* Created ..: Monday 21-Jan-91 20:12
* Revision .: 0
*
* Date Author Comment
* ========= ======== ====================
* 21-Jan-91 Olsen Created this file!
*
* $Revision Header ********************************************************/
#include "TermGlobal.h"
enum { GAD_F1,GAD_F2,GAD_F3,GAD_F4,GAD_F5,GAD_F6,GAD_F7,GAD_F8,GAD_F9,
GAD_F10,GAD_QUALIFIER,GAD_USE,GAD_LOAD,GAD_SAVE,GAD_CANCEL };
enum { MEN_USEMACROS=1,MEN_LOADMACROS,MEN_SAVEMACROS,MEN_QUALIFIER,
MEN_CANCELMACROS,MEN_QUITPANEL };
STATIC struct NewMenu MacroMenu[] =
{
{ NM_TITLE, "Project", 0 , 0, 0, (APTR)0},
{ NM_ITEM, "Load Macros", "L", 0, 0, (APTR)MEN_LOADMACROS},
{ NM_ITEM, "Save Macros", "S", 0, 0, (APTR)MEN_SAVEMACROS},
{ NM_ITEM, NM_BARLABEL, 0 , 0, 0, (APTR)0},
{ NM_ITEM, "Modifier", "M", 0, 0, (APTR)MEN_QUALIFIER},
{ NM_ITEM, NM_BARLABEL, 0 , 0, 0, (APTR)0},
{ NM_ITEM, "Use", "U", 0, 0, (APTR)MEN_USEMACROS},
{ NM_ITEM, "Cancel", "C", 0, 0, (APTR)MEN_CANCELMACROS},
{ NM_ITEM, NM_BARLABEL, 0 , 0, 0, (APTR)0},
{ NM_ITEM, "Quit", "Q", 0, 0, (APTR)MEN_QUITPANEL},
{ NM_END, 0, 0 , 0, 0, (APTR)0}
};
#define WIDTH 535
#define HEIGHT 163
STATIC STRPTR ModifierString[5] =
{
(STRPTR)"None",
(STRPTR)"Shift",
(STRPTR)"Alternate",
(STRPTR)"Control",
NULL
};
STATIC struct Gadget *
CreateAllGadgets(struct Gadget **GadgetArray,struct Gadget **GadgetList,APTR VisualInfo,UWORD TopEdge)
{
struct Gadget *Gadget;
struct NewGadget NewGadget;
UWORD Counter = 0,Offset;
if(Gadget = CreateContext(GadgetList))
{
NewGadget . ng_Width = 484;
NewGadget . ng_Height = 12;
NewGadget . ng_GadgetText = "F 1";
NewGadget . ng_TextAttr = &DefaultFont;
NewGadget . ng_VisualInfo = VisualInfo;
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_Flags = NG_HIGHLABEL;
NewGadget . ng_LeftEdge = (strlen(NewGadget . ng_GadgetText) + 2) * 8 + 1;
NewGadget . ng_TopEdge = 1 + TopEdge;
GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
GTST_MaxChars,256,
TAG_DONE);
NewGadget . ng_GadgetText = "F 2";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 2;
GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
GTST_MaxChars,256,
TAG_DONE);
NewGadget . ng_GadgetText = "F 3";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 2;
GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
GTST_MaxChars,256,
TAG_DONE);
NewGadget . ng_GadgetText = "F 4";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 2;
GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
GTST_MaxChars,256,
TAG_DONE);
NewGadget . ng_GadgetText = "F 5";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 2;
GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
GTST_MaxChars,256,
TAG_DONE);
NewGadget . ng_GadgetText = "F 6";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 2;
GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
GTST_MaxChars,256,
TAG_DONE);
NewGadget . ng_GadgetText = "F 7";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 2;
GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
GTST_MaxChars,256,
TAG_DONE);
NewGadget . ng_GadgetText = "F 8";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 2;
GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
GTST_MaxChars,256,
TAG_DONE);
NewGadget . ng_GadgetText = "F 9";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 2;
GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
GTST_MaxChars,256,
TAG_DONE);
NewGadget . ng_GadgetText = "F10";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 2;
GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
GTST_MaxChars,256,
TAG_DONE);
NewGadget . ng_GadgetText = "Key _Modifier";
NewGadget . ng_Width = 100;
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_LeftEdge = WIDTH >> 1;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 4;
GadgetArray[Counter++] = Gadget = CreateGadget(CYCLE_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
GTCY_Labels, ModifierString,
GTCY_Active, 0,
TAG_DONE);
NewGadget . ng_Width = 52;
NewGadget . ng_Height = 12;
NewGadget . ng_GadgetText = "_Use";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_Flags = 0;
NewGadget . ng_LeftEdge = 10;
NewGadget . ng_TopEdge = HEIGHT - 3 - NewGadget . ng_Height;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
TAG_DONE);
Offset = (WIDTH + NewGadget . ng_Width) / 4 + 8;
NewGadget . ng_GadgetText = "_Load";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_LeftEdge = NewGadget . ng_LeftEdge + Offset;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
TAG_DONE);
NewGadget . ng_GadgetText = "_Save";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_LeftEdge = NewGadget . ng_LeftEdge + Offset;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
TAG_DONE);
NewGadget . ng_GadgetText = "_Cancel";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_LeftEdge = NewGadget . ng_LeftEdge + Offset;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
TAG_DONE);
}
DubGadList(GadgetArray[0]);
return(Gadget);
}
VOID
MacroPanel(struct MacroKeys *MacroKeys)
{
struct Window *PanelWindow;
struct Menu *PanelMenu;
struct Gadget *GadgetList;
struct Gadget *GadgetArray[GAD_CANCEL + 1];
LONG i;
struct MacroKeys *Keys;
if(Keys = (struct MacroKeys *)AllocMem(sizeof(struct MacroKeys),MEMF_PUBLIC|MEMF_CLEAR))
{
CopyMem(MacroKeys,Keys,sizeof(struct MacroKeys));
if(CreateAllGadgets(&GadgetArray[0],&GadgetList,VisualInfo,Screen -> WBorTop + Screen -> Font -> ta_YSize + 1))
{
if(PanelMenu = CreateMenus(MacroMenu,
GTMN_FrontPen, 0,
TAG_DONE))
{
if(LayoutMenus(PanelMenu,VisualInfo,
GTMN_TextAttr,&DefaultFont,
TAG_DONE))
{
if(PanelWindow = OpenWindowTags(NULL,
WA_Left, (Screen -> Width - WIDTH) >> 1,
WA_Top, (Screen -> Height - HEIGHT) >> 1,
WA_Width, WIDTH,
WA_Height, HEIGHT,
WA_Activate, TRUE,
WA_DragBar, TRUE,
WA_DepthGadget, TRUE,
WA_CloseGadget, TRUE,
WA_RMBTrap, TRUE,
WA_DepthGadget, TRUE,
WA_CustomScreen,Screen,
WA_IDCMP, IDCMP_GADGETDOWN | IDCMP_CLOSEWINDOW | SLIDERIDCMP | CHECKBOXIDCMP | LISTVIEWIDCMP | IDCMP_MENUPICK | IDCMP_RAWKEY | IDCMP_ACTIVEWINDOW,
WA_Title, "Macro Preferences",
TAG_DONE))
{
struct IntuiMessage *Massage;
ULONG Class,Code;
struct Gadget *Gadget;
BYTE Terminated = FALSE;
UBYTE DummyBuffer[256],*DummyChar;
struct FileRequest *FileRequest;
LONG Modifier = 0,Value;
PushWindow(PanelWindow);
AddGList(PanelWindow,GadgetList,(UWORD)-1,(UWORD)-1,NULL);
RefreshGList(GadgetList,PanelWindow,NULL,(UWORD)-1);
GT_RefreshWindow(PanelWindow,NULL);
SetMenuStrip(PanelWindow,PanelMenu);
PanelWindow -> Flags &= ~WFLG_RMBTRAP;
for(i = 0 ; i < 10 ; i++)
{
GT_SetGadgetAttrs(GadgetArray[GAD_F1 + i],PanelWindow,NULL,
GTST_String,Keys -> Keys[Modifier][i],
TAG_DONE);
}
ActivateGadget(GadgetArray[GAD_F1],PanelWindow,NULL);
ActiveGadget = GadgetArray[GAD_F1];
while(!Terminated)
{
WaitPort(PanelWindow -> UserPort);
while(!Terminated && (Massage = (struct IntuiMessage *)GT_GetIMsg(PanelWindow -> UserPort)))
{
Class = Massage -> Class;
Code = Massage -> Code;
Gadget = (struct Gadget *)Massage -> IAddress;
GT_ReplyIMsg(Massage);
if(Class == IDCMP_ACTIVEWINDOW && ActiveGadget)
ActivateGadget(ActiveGadget,PanelWindow,NULL);
if(Class == IDCMP_RAWKEY)
{
if(Code == IECODE_UP_PREFIX|103 && CommandWindow == PanelWindow)
ActivateGadget(CommandGadget,PanelWindow,NULL);
}
if(Class == IDCMP_GADGETDOWN)
{
if((Gadget -> GadgetType & GTYP_GTYPEMASK) == GTYP_STRGADGET)
ActiveGadget = Gadget;
}
if(Class == IDCMP_MENUPICK)
{
struct MenuItem *MenuItem;
while(Code != MENUNULL)
{
MenuItem = ItemAddress(PanelMenu,Code);
switch((ULONG)MENU_USERDATA(MenuItem))
{
case MEN_QUITPANEL: Class = IDCMP_CLOSEWINDOW;
break;
case MEN_USEMACROS: Class = IDCMP_GADGETUP;
Gadget = GadgetArray[GAD_USE];
break;
case MEN_LOADMACROS: Class = IDCMP_GADGETUP;
Gadget = GadgetArray[GAD_LOAD];
break;
case MEN_SAVEMACROS: Class = IDCMP_GADGETUP;
Gadget = GadgetArray[GAD_SAVE];
break;
case MEN_QUALIFIER: if(Modifier == 3)
Value = 0;
else
Value = Modifier + 1;
GT_SetGadgetAttrs(GadgetArray[GAD_QUALIFIER],PanelWindow,NULL,
GTCY_Active,Value,
TAG_DONE);
Class = IDCMP_GADGETUP;
Gadget = GadgetArray[GAD_QUALIFIER];
Code = Value;
goto GadCheck;
case MEN_CANCELMACROS: Class = IDCMP_GADGETUP;
Gadget = GadgetArray[GAD_CANCEL];
break;
default: break;
}
Code = MenuItem -> NextSelect;
}
if(ActiveGadget)
ActivateGadget(ActiveGadget,PanelWindow,NULL);
}
if(Class == IDCMP_CLOSEWINDOW)
Terminated = TRUE;
GadCheck: if(Class == IDCMP_GADGETUP)
{
switch(Gadget -> GadgetID)
{
case GAD_QUALIFIER: for(i = 0 ; i < 10 ; i++)
strcpy(Keys -> Keys[Modifier][i],((struct StringInfo *)GadgetArray[i] -> SpecialInfo) -> Buffer);
Modifier = Code;
for(i = 0 ; i < 10 ; i++)
{
GT_SetGadgetAttrs(GadgetArray[GAD_F1 + i],PanelWindow,NULL,
GTST_String,Keys -> Keys[Modifier][i],
TAG_DONE);
}
break;
case GAD_USE: Terminated = TRUE;
for(i = 0 ; i < 10 ; i++)
strcpy(Keys -> Keys[Modifier][i],((struct StringInfo *)GadgetArray[i] -> SpecialInfo) -> Buffer);
CopyMem(Keys,MacroKeys,sizeof(struct MacroKeys));
break;
case GAD_LOAD: strcpy(DummyBuffer,LastMacros);
DummyChar = PathPart(DummyBuffer);
*DummyChar = 0;
SetWait(PanelWindow);
PanelWindow -> Flags |= WFLG_RMBTRAP;
if(FileRequest = GetFile("Load Macro Keys...",DummyBuffer,FilePart(LastMacros),DummyBuffer,"#?.term",FALSE,FALSE))
{
if(!LoadMacros(DummyBuffer,Keys))
MyEasyRequest(Window,"Couldn't load macro keys\n\"%s\"!","Continue",DummyBuffer);
else
{
strcpy(Config . MacroFile,DummyBuffer);
strcpy(LastMacros,DummyBuffer);
for(i = 0 ; i < 10 ; i++)
{
GT_SetGadgetAttrs(GadgetArray[GAD_F1 + i],PanelWindow,NULL,
GTST_String,Keys -> Keys[Modifier][i],
TAG_DONE);
}
}
}
ClearPointer(PanelWindow);
PanelWindow -> Flags &= ~WFLG_RMBTRAP;
break;
case GAD_SAVE: strcpy(DummyBuffer,LastMacros);
DummyChar = PathPart(DummyBuffer);
*DummyChar = 0;
SetWait(PanelWindow);
PanelWindow -> Flags |= WFLG_RMBTRAP;
for(i = 0 ; i < 10 ; i++)
strcpy(Keys -> Keys[Modifier][i],((struct StringInfo *)GadgetArray[i] -> SpecialInfo) -> Buffer);
if(FileRequest = GetFile("Save Macro Keys...",DummyBuffer,FilePart(LastMacros),DummyBuffer,"#?.term",TRUE,FALSE))
{
if(!WriteIFFData(DummyBuffer,Keys,sizeof(struct MacroKeys),'KEYS'))
MyEasyRequest(Window,"Couldn't save macro keys\n\"%s\"!","Continue",DummyBuffer);
else
strcpy(LastMacros,DummyBuffer);
}
ClearPointer(PanelWindow);
PanelWindow -> Flags &= ~WFLG_RMBTRAP;
break;
case GAD_CANCEL: Terminated = TRUE;
CopyMem(Keys,MacroKeys,sizeof(struct MacroKeys));
break;
default: break;
}
}
}
}
PanelWindow -> Flags |= WFLG_RMBTRAP;
ClearMenuStrip(PanelWindow);
RemoveGList(PanelWindow,GadgetList,(UWORD)-1);
PopWindow();
CloseWindow(PanelWindow);
}
}
FreeMenus(PanelMenu);
}
FreeGadgets(GadgetList);
}
FreeMem(Keys,sizeof(struct MacroKeys));
}
}