home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
514a.lha
/
TplEdit_v1.00_alpha
/
Src
/
edit.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-06-08
|
10KB
|
448 lines
/*
* EDIT.C
*/
#include "defs.h"
Prototype int OpenEditWindow(void);
Prototype void CloseEditWindow(void);
Prototype void HandleEditGadget(IMsg *);
Prototype void UpdateEWinInfo(TplRegion *);
Prototype NewGadget *MakeENG(short, short, short, short, char *, short, long, APTR);
Prototype Window *EWin;
Prototype long EWinMask;
Prototype char *DefName;
Prototype char *LabName;
Prototype char *RegName;
Prototype char *MaxName;
Prototype List EList;
Window *EWin;
Gadget *EGList;
long EWinMask;
NewGadget ENg;
char *CycLabels[] = { "Invisible", "Button", "String", "ListView", "Cycle", NULL };
char *CycOrient[] = { "Text Left", "Text Right", "Text Above", "Text Below", "Text In", NULL };
List EList;
char *DefName;
char *LabName;
char *RegName;
char *AddName;
char *MaxName;
Gadget *EGadType;
Gadget *EGadOrient;
Gadget *EGadRegText;
Gadget *EGadLabText;
Gadget *EGadDefText;
Gadget *EGadAddText;
Gadget *EGadMaxBufLen;
Gadget *EGadList;
OpenEditWindow()
{
Gadget *gad;
NewList(&EList);
if ((gad = CreateContext(&EGList)) == NULL)
return(-1);
ENg.ng_TextAttr = Scr->Font;
ENg.ng_VisualInfo= Ng.ng_VisualInfo;
EGadType = gad = CreateGadget(CYCLE_KIND, gad,
MakeENG(20, 20, 110, 16, NULL, EGAD_TYPES, 0, 0),
GTCY_Labels, CycLabels,
TAG_END
);
if (gad == NULL)
return(-1);
EGadOrient = gad = CreateGadget(CYCLE_KIND, gad,
MakeENG(20, 40, 110, 16, NULL, EGAD_LABPL, 0, 0),
GTCY_Labels, CycOrient,
TAG_END
);
if (gad == NULL)
return(-1);
gad = CreateGadget(BUTTON_KIND, gad,
MakeENG(135, 20, 40, 16, "NEW", EGAD_NEW, PLACETEXT_IN, 0),
TAG_END
);
if (gad == NULL)
return(-1);
gad = CreateGadget(BUTTON_KIND, gad,
MakeENG(180, 20, 40, 16, "DEL", EGAD_DEL, PLACETEXT_IN, 0),
TAG_END
);
if (gad == NULL)
return(-1);
gad = CreateGadget(BUTTON_KIND, gad,
MakeENG(140, 40, 80, 16, "UPDATE", EGAD_UPDATE, PLACETEXT_IN, 0),
TAG_END
);
gad = CreateGadget(BUTTON_KIND, gad,
MakeENG(225, 20, 40, 16, "MOV", EGAD_MOVE, PLACETEXT_IN, 0),
TAG_END
);
if (gad == NULL)
return(-1);
gad = CreateGadget(BUTTON_KIND, gad,
MakeENG(270, 20, 40, 16, "SIZ", EGAD_SIZE, PLACETEXT_IN, 0),
TAG_END
);
if (gad == NULL)
return(-1);
gad = CreateGadget(BUTTON_KIND, gad,
MakeENG(315, 20, 70, 16, "WANDER", EGAD_WANDER, PLACETEXT_IN, 0),
TAG_END
);
if (gad == NULL)
return(-1);
EGadRegText = gad = CreateGadget(STRING_KIND, gad,
MakeENG(100, 60, 100, 16, "REGION", EGAD_REGNAME, PLACETEXT_LEFT, 0),
GTST_MaxChars, 32,
TAG_END
);
if (gad == NULL)
return(-1);
RegName = ((StringInfo *)gad->SpecialInfo)->Buffer;
EGadLabText = gad = CreateGadget(STRING_KIND, gad,
MakeENG(100, 80, 100, 16, "LABEL", EGAD_LABEL, PLACETEXT_LEFT, 0),
GTST_MaxChars, 32,
TAG_END
);
if (gad == NULL)
return(-1);
LabName = ((StringInfo *)gad->SpecialInfo)->Buffer;
EGadDefText = gad = CreateGadget(STRING_KIND, gad,
MakeENG(100, 100, 100, 16, "DEFAULT", EGAD_DEFAULT, PLACETEXT_LEFT, 0),
GTST_MaxChars, 32,
TAG_END
);
if (gad == NULL)
return(-1);
DefName = ((StringInfo *)gad->SpecialInfo)->Buffer;
EGadMaxBufLen = gad = CreateGadget(STRING_KIND, gad,
MakeENG(100, 120, 50, 16, "BUFLEN", EGAD_MAXBUFLEN, PLACETEXT_LEFT, 0),
GTST_MaxChars, 3,
TAG_END
);
if (gad == NULL)
return(-1);
MaxName = ((StringInfo *)gad->SpecialInfo)->Buffer;
/*
* Item List
*/
gad = CreateGadget(BUTTON_KIND, gad,
MakeENG(225, 145, 40, 16, "ADD", EGAD_LADD, PLACETEXT_IN, 0),
TAG_END
);
if (gad == NULL)
return(-1);
gad = CreateGadget(BUTTON_KIND, gad,
MakeENG(270, 145, 40, 16, "DEL", EGAD_LDEL, PLACETEXT_IN, 0),
TAG_END
);
if (gad == NULL)
return(-1);
EGadAddText = gad = CreateGadget(STRING_KIND, gad,
MakeENG(225, 125, 175, 16, "ENUM", EGAD_ENUMSTR, PLACETEXT_BELOW, 0),
GTST_MaxChars, 32,
TAG_END
);
if (gad == NULL)
return(-1);
AddName = ((StringInfo *)gad->SpecialInfo)->Buffer;
EGadList = gad = CreateGadget(LISTVIEW_KIND, gad,
MakeENG(225, 40, 175, 80, NULL, EGAD_ENUM, 0, 0),
GTLV_Labels, &EList,
GTLV_ShowSelected, EGadAddText,
TAG_END
);
/*
* Window
*/
EWin = OpenWindowTags(NULL,
WA_Flags, WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|
WFLG_SIMPLE_REFRESH|WFLG_ACTIVATE|WFLG_REPORTMOUSE|
WFLG_SIZEGADGET,
WA_IDCMP, IDCMP_NEWSIZE|IDCMP_MOUSEBUTTONS|IDCMP_GADGETDOWN|
IDCMP_GADGETUP|IDCMP_MENUPICK|IDCMP_VANILLAKEY|
IDCMP_RAWKEY|IDCMP_CHANGEWINDOW|IDCMP_CLOSEWINDOW|
IDCMP_REFRESHWINDOW|IDCMP_MOUSEMOVE|IDCMP_ACTIVEWINDOW,
WA_Left, 0,
WA_Top, 0,
WA_InnerWidth, 400,
WA_InnerHeight, 160,
WA_Title, "TPL CONTROL",
WA_MinWidth, 32,
WA_MinHeight, 32,
WA_MaxWidth, -1,
WA_MaxHeight, -1,
WA_AutoAdjust, 1,
WA_PubScreen, NULL,
WA_PubScreenFallBack, 1,
WA_Gadgets, EGList,
TAG_END
);
if (EWin == NULL)
return(-1);
EWinMask = 1 << EWin->UserPort->mp_SigBit;
GT_RefreshWindow(EWin, NULL);
return(1);
}
void
CloseEditWindow()
{
if (EWin) {
ClearMenuStrip(EWin);
CloseWindow(EWin);
EWin = NULL;
}
if (EGList) {
FreeGadgets(EGList);
EGList = NULL;
}
/*
if (ENg.ng_VisualInfo) {
FreeVisualInfo(ENg.ng_VisualInfo);
ENg.ng_VisualInfo = NULL;
}
*/
}
void
HandleEditGadget(im)
IMsg *im;
{
switch(((Gadget *)im->IAddress)->GadgetID) {
case EGAD_TYPES:
NewType = im->Code;
break;
case EGAD_LABPL:
NewFlags= 1 << im->Code;
break;
case EGAD_NEW:
CurState = STATE_NEWREGION;
DisableGadgets();
break;
case EGAD_WANDER:
CurState = STATE_WANDER;
EnableGadgets();
break;
case EGAD_DEL:
DisableGadgets();
CurState = STATE_DELREGION;
break;
case EGAD_MOVE:
DisableGadgets();
CurState = STATE_MOVEREGION;
break;
case EGAD_SIZE:
DisableGadgets();
CurState = STATE_SIZEREGION;
break;
#ifdef NOTDEF
case EGAD_REGNAME:
if (CurRegion) {
StringInfo *si = (StringInfo *)(((Gadget *)im->IAddress)->SpecialInfo);
printf("%08lx %08lx\n", si->Buffer, RegName);
if (CurRegion->rg_Node.ln_Name)
free(CurRegion->rg_Node.ln_Name);
CurRegion->rg_Node.ln_Name = strdup(si->Buffer);
SetCurRegion(CurRegion);
}
break;
case EGAD_LABEL:
if (CurRegion) {
StringInfo *si = (StringInfo *)(((Gadget *)im->IAddress)->SpecialInfo);
if (CurRegion->rg_LabText)
free(CurRegion->rg_LabText);
CurRegion->rg_LabText = strdup(si->Buffer);
}
break;
case EGAD_DEFAULT:
if (CurRegion) {
StringInfo *si = (StringInfo *)(((Gadget *)im->IAddress)->SpecialInfo);
if (CurRegion->rg_DefText)
free(CurRegion->rg_DefText);
CurRegion->rg_DefText = strdup(si->Buffer);
}
break;
#endif
case EGAD_ENUMSTR:
case EGAD_LADD:
if (AddName[0] == 0)
break;
GT_SetGadgetAttrs(EGadList, EWin, NULL,
GTLV_Labels, -1,
TAG_END
);
{
MaxNode *mn;
for (mn = GetHead(&EList); mn; mn = GetSucc(mn)) {
if (strcmp(AddName, mn->ln_Name) == 0)
break;
}
if (mn == NULL)
AddNode(&EList, AddName, 1);
}
GT_SetGadgetAttrs(EGadList, EWin, NULL,
GTLV_Labels, &EList,
TAG_END
);
break;
case EGAD_LDEL:
GT_SetGadgetAttrs(EGadList, EWin, NULL,
GTLV_Labels, -1,
TAG_END
);
{
MaxNode *mn;
for (mn = GetHead(&EList); mn; mn = GetSucc(mn)) {
if (strcmp(AddName, mn->ln_Name) == 0) {
Remove(mn);
free(mn->ln_Name);
free(mn);
break;
}
}
}
GT_SetGadgetAttrs(EGadList, EWin, NULL,
GTLV_Labels, &EList,
TAG_END
);
break;
case EGAD_UPDATE:
/*
* Update currently selected gadget from TPL CONTROL window
*/
if (CurRegion) {
UpdateTplRegion(CurRegion);
SetCurRegion(CurRegion);
CurState = STATE_WANDER;
ReMakeEverything();
/*
MakeAllGadgets();
RefreshGList(GList, Win, NULL, -1);
GT_RefreshWindow(Win, NULL);
*/
}
break;
}
}
void
UpdateEWinInfo(rg)
TplRegion *rg;
{
NewType = rg->rg_Type;
NewFlags= rg->rg_Flags;
sprintf(TmpBuf, "%d", rg->rg_MaxBufLen);
GT_SetGadgetAttrs(EGadMaxBufLen, EWin, NULL,
GTST_String, TmpBuf,
TAG_END
);
GT_SetGadgetAttrs(EGadType, EWin, NULL,
GTCY_Active, rg->rg_Type,
TAG_END
);
GT_SetGadgetAttrs(EGadOrient, EWin, NULL,
GTCY_Active, (rg->rg_Flags & 0x0001) ? 0 :
(rg->rg_Flags & 0x0002) ? 1 :
(rg->rg_Flags & 0x0004) ? 2 :
(rg->rg_Flags & 0x0008) ? 4 :
(rg->rg_Flags & 0x0010) ? 5 : 0,
TAG_END
);
GT_SetGadgetAttrs(EGadRegText, EWin, NULL,
GTST_String, (rg->rg_Node.ln_Name) ? rg->rg_Node.ln_Name : "",
TAG_END
);
GT_SetGadgetAttrs(EGadLabText, EWin, NULL,
GTST_String, (rg->rg_LabText) ? rg->rg_LabText : "",
TAG_END
);
GT_SetGadgetAttrs(EGadDefText, EWin, NULL,
GTST_String, (rg->rg_DefText) ? rg->rg_DefText : "",
TAG_END
);
if (rg->rg_Type == RGT_CYCLE || rg->rg_Type == RGT_SELLIST) {
MaxNode *mn;
GT_SetGadgetAttrs(EGadList, EWin, NULL,
GTLV_Labels, -1,
TAG_END
);
while (mn = RemHead(&EList)) {
free(mn->ln_Name);
free(mn);
}
for (mn = GetHead(&rg->rg_ListSet); mn; mn = GetSucc(mn)) {
AddNode(&EList, mn->ln_Name, 1);
}
GT_SetGadgetAttrs(EGadList, EWin, NULL,
GTLV_Labels, &EList,
TAG_END
);
}
}
NewGadget *
MakeENG(le, te, w, h, ltext, gadid, flags, user)
short le;
short te;
short w;
short h;
char *ltext;
short gadid;
long flags;
APTR user;
{
ENg.ng_LeftEdge = le;
ENg.ng_TopEdge = te;
ENg.ng_Width = w;
ENg.ng_Height= h;
ENg.ng_GadgetText = ltext;
ENg.ng_GadgetID = gadid;
ENg.ng_Flags = flags;
ENg.ng_UserData = user;
return(&ENg);
}