home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 1: Amiga
/
FrozenFish-Apr94.iso
/
bbs
/
alib
/
d5xx
/
d534
/
term.lha
/
Term
/
Source.LZH
/
ModemPanel.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-07-06
|
15KB
|
492 lines
/* $Revision Header * Header built automatically - do not edit! *************
*
* (C) Copyright 1990 by Olaf 'Olsen' Barthel & MXM
*
* Name .....: ModemPanel.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_MODEMINIT,GAD_MODEMEXIT,GAD_MODEMHANGUP,GAD_DIALPREFIX,
GAD_REDIALDELAY,GAD_DIALRETRIES,GAD_DIALTIMEOUT,GAD_AUTOCAPTURE,
GAD_AUTOBAUD,GAD_LOG,GAD_NOCARRIER,GAD_CONNECT,GAD_VOICE,GAD_RING,
GAD_BUSY,GAD_USE,GAD_CANCEL };
enum { MEN_REDIALDELAY=1,MEN_DIALRETRIES,MEN_DIALTIMEOUT,MEN_AUTOCAPTURE,
MEN_AUTOBAUD,MEN_LOG,MEN_USE,MEN_CANCEL,MEN_QUITPANEL };
STATIC struct NewMenu ModemMenu[] =
{
{ NM_TITLE, "Project", 0 , 0, 0, (APTR)0},
{ NM_ITEM, "Redial Delay", "D", 0, 0, (APTR)MEN_REDIALDELAY},
{ NM_ITEM, "Dial Retries", "R", 0, 0, (APTR)MEN_DIALRETRIES},
{ NM_ITEM, "Dial Timeout", "T", 0, 0, (APTR)MEN_DIALTIMEOUT},
{ NM_ITEM, NM_BARLABEL, 0 , 0, 0, (APTR)0},
{ NM_ITEM, "Connect Auto-Capture", "A", 0, 0, (APTR)MEN_AUTOCAPTURE},
{ NM_ITEM, "Connect Auto-Baud", "B", 0, 0, (APTR)MEN_AUTOBAUD},
{ NM_ITEM, "Log Actions", "L", 0, 0, (APTR)MEN_LOG},
{ NM_ITEM, NM_BARLABEL, 0 , 0, 0, (APTR)0},
{ NM_ITEM, "Use", "U", 0, 0, (APTR)MEN_USE},
{ NM_ITEM, "Cancel", "C", 0, 0, (APTR)MEN_CANCEL},
{ 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 632
#define HEIGHT 152
STATIC UBYTE * __saveds
ShowMinute(struct Gadget *SomeGadget,WORD Level)
{
STATIC UBYTE Buffer[6];
SPrintf(Buffer,"%2ld:%02ld",Level / 60,Level % 60);
return(Buffer);
}
STATIC struct Gadget *
CreateAllGadgets(struct Configuration *Config,struct Gadget **GadgetArray,struct Gadget **GadgetList,APTR VisualInfo,UWORD TopEdge)
{
struct Gadget *Gadget;
struct NewGadget NewGadget;
UWORD LeftEdge,Counter = 0;
if(Gadget = CreateContext(GadgetList))
{
NewGadget . ng_Width = 124;
NewGadget . ng_Height = 12;
NewGadget . ng_GadgetText = " Modem Init String";
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, 80,
GTST_String, Config -> ModemInit,
TAG_DONE);
LeftEdge = Gadget -> LeftEdge + Gadget -> Width + 8;
NewGadget . ng_GadgetText = "Modem Exit String";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 2;
GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
GTST_MaxChars, 80,
GTST_String, Config -> ModemExit,
TAG_DONE);
NewGadget . ng_GadgetText = "Modem Hangup String";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 2;
GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
GTST_MaxChars, 80,
GTST_String, Config -> ModemHangup,
TAG_DONE);
NewGadget . ng_GadgetText = "Dial Prefix";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 2;
GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
GTST_MaxChars, 80,
GTST_String, Config -> DialPrefix,
TAG_DONE);
NewGadget . ng_GadgetText = "Redial _Delay (Minutes) ";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 3;
GadgetArray[Counter++] = Gadget = CreateGadget(SLIDER_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
GTSL_Min, 0,
GTSL_Max, 60,
GTSL_Level, Config -> RedialDelay,
GTSL_LevelFormat, "%2ld",
GTSL_MaxLevelLen, 2,
TAG_DONE);
NewGadget . ng_GadgetText = "Number Of Dial _Retries ";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 3;
GadgetArray[Counter++] = Gadget = CreateGadget(SLIDER_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
GTSL_Min, 0,
GTSL_Max, 100,
GTSL_Level, Config -> DialRetries,
GTSL_LevelFormat, "%3ld",
GTSL_MaxLevelLen, 3,
TAG_DONE);
NewGadget . ng_GadgetText = "Dial _Timeout (Minutes) ";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 3;
GadgetArray[Counter++] = Gadget = CreateGadget(SLIDER_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
GTSL_Min, 0,
GTSL_Max, 1800,
GTSL_Level, Config -> DialTimeout,
GTSL_DispFunc, ShowMinute,
GTSL_LevelFormat, "%s",
GTSL_MaxLevelLen, 5,
TAG_DONE);
NewGadget . ng_GadgetText = "Connect _Auto-Capture";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 3;
GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
GTCB_Checked, Config -> ConnectAutoCapture,
TAG_DONE);
NewGadget . ng_GadgetText = "Connect Auto-_Baud";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 1;
GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
GTCB_Checked, Config -> ConnectAutoBaud,
TAG_DONE);
NewGadget . ng_GadgetText = "_Log Actions";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 1;
GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
GTCB_Checked, Config -> LogActions,
TAG_DONE);
NewGadget . ng_Width = 86;
NewGadget . ng_GadgetText = "`No Carrier' String";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_LeftEdge = LeftEdge + (strlen(NewGadget . ng_GadgetText) + 2) * 8 + 1;
NewGadget . ng_TopEdge = 1 + TopEdge;
GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
GTST_MaxChars,16,
GTST_String,Config -> NoCarrier,
TAG_DONE);
NewGadget . ng_GadgetText = "`Connect' String";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 2;
GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
GTST_MaxChars,16,
GTST_String,Config -> Connect,
TAG_DONE);
NewGadget . ng_GadgetText = "`Voice' String";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 2;
GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
GTST_MaxChars,16,
GTST_String,Config -> Voice,
TAG_DONE);
NewGadget . ng_GadgetText = "`Ring' String";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 2;
GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
GTST_MaxChars,16,
GTST_String,Config -> Ring,
TAG_DONE);
NewGadget . ng_GadgetText = "`Busy' String";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + 2;
GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
GTST_MaxChars,16,
GTST_String,Config -> Busy,
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);
NewGadget . ng_GadgetText = "_Cancel";
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_LeftEdge = WIDTH - 10 - NewGadget . ng_Width;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
TAG_DONE);
}
DubGadList(GadgetArray[0]);
return(Gadget);
}
BYTE
ModemPanel(struct Configuration *Config)
{
struct Window *PanelWindow;
struct Menu *PanelMenu;
struct Gadget *GadgetList;
struct Gadget *GadgetArray[GAD_CANCEL + 1];
CopyMem(Config,&PrivateConfig,sizeof(struct Configuration));
if(CreateAllGadgets(Config,&GadgetArray[0],&GadgetList,VisualInfo,Screen -> WBorTop + Screen -> Font -> ta_YSize + 1))
{
if(PanelMenu = CreateMenus(ModemMenu,
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_RMBTrap, TRUE,
WA_DepthGadget, TRUE,
WA_CloseGadget, TRUE,
WA_CustomScreen,Screen,
WA_IDCMP, IDCMP_GADGETDOWN | IDCMP_ACTIVEWINDOW | IDCMP_CLOSEWINDOW | SLIDERIDCMP | CHECKBOXIDCMP | LISTVIEWIDCMP | IDCMP_MENUPICK | IDCMP_RAWKEY,
WA_Title, "Modem Preferences",
TAG_DONE))
{
struct IntuiMessage *Massage;
ULONG Class,Code;
struct Gadget *Gadget;
BYTE Terminated = FALSE;
PushWindow(PanelWindow);
AddGList(PanelWindow,GadgetList,(UWORD)-1,(UWORD)-1,NULL);
RefreshGList(GadgetList,PanelWindow,NULL,(UWORD)-1);
GT_RefreshWindow(PanelWindow,NULL);
ActivateGadget(GadgetArray[GAD_MODEMINIT],PanelWindow,NULL);
ActiveGadget = GadgetArray[GAD_MODEMINIT];
SetMenuStrip(PanelWindow,PanelMenu);
PanelWindow -> Flags &= ~WFLG_RMBTRAP;
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) == 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_REDIALDELAY: if(Config -> RedialDelay < 60)
Config -> RedialDelay++;
else
Config -> RedialDelay = 0;
GT_SetGadgetAttrs(GadgetArray[GAD_REDIALDELAY],PanelWindow,NULL,
GTSL_Level,Config -> RedialDelay,
TAG_DONE);
break;
case MEN_DIALRETRIES: if(Config -> DialRetries < 100)
Config -> DialRetries++;
else
Config -> DialRetries = 0;
GT_SetGadgetAttrs(GadgetArray[GAD_DIALRETRIES],PanelWindow,NULL,
GTSL_Level,Config -> DialRetries,
TAG_DONE);
break;
case MEN_DIALTIMEOUT: if(Config -> DialTimeout < 360)
Config -> DialTimeout++;
else
Config -> DialTimeout = 0;
GT_SetGadgetAttrs(GadgetArray[GAD_DIALTIMEOUT],PanelWindow,NULL,
GTSL_Level,Config -> DialTimeout,
TAG_DONE);
break;
case MEN_AUTOCAPTURE: GT_SetGadgetAttrs(GadgetArray[GAD_AUTOCAPTURE],PanelWindow,NULL,
GTCB_Checked,GadgetArray[GAD_AUTOCAPTURE] -> Flags & GFLG_SELECTED ? FALSE : TRUE,
TAG_DONE);
break;
case MEN_AUTOBAUD: GT_SetGadgetAttrs(GadgetArray[GAD_AUTOBAUD],PanelWindow,NULL,
GTCB_Checked,GadgetArray[GAD_AUTOBAUD] -> Flags & GFLG_SELECTED ? FALSE : TRUE,
TAG_DONE);
break;
case MEN_LOG: GT_SetGadgetAttrs(GadgetArray[GAD_LOG],PanelWindow,NULL,
GTCB_Checked,GadgetArray[GAD_LOG] -> Flags & GFLG_SELECTED ? FALSE : TRUE,
TAG_DONE);
break;
case MEN_USE: Class = IDCMP_GADGETUP;
Gadget = GadgetArray[GAD_USE];
break;
case MEN_CANCEL: 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;
if(Class == IDCMP_MOUSEMOVE)
{
switch(Gadget -> GadgetID)
{
case GAD_REDIALDELAY: Config -> RedialDelay = Code;
break;
case GAD_DIALRETRIES: Config -> DialRetries = Code;
break;
case GAD_DIALTIMEOUT: Config -> DialTimeout = Code;
break;
default: break;
}
}
if(Class == IDCMP_GADGETUP)
{
switch(Gadget -> GadgetID)
{
case GAD_USE: Terminated = TRUE;
strcpy(Config -> ModemInit,((struct StringInfo *)GadgetArray[GAD_MODEMINIT] -> SpecialInfo) -> Buffer);
strcpy(Config -> ModemExit,((struct StringInfo *)GadgetArray[GAD_MODEMEXIT] -> SpecialInfo) -> Buffer);
strcpy(Config -> ModemHangup,((struct StringInfo *)GadgetArray[GAD_MODEMHANGUP] -> SpecialInfo) -> Buffer);
strcpy(Config -> DialPrefix,((struct StringInfo *)GadgetArray[GAD_DIALPREFIX] -> SpecialInfo) -> Buffer);
strcpy(Config -> NoCarrier,((struct StringInfo *)GadgetArray[GAD_NOCARRIER] -> SpecialInfo) -> Buffer);
strcpy(Config -> Connect,((struct StringInfo *)GadgetArray[GAD_CONNECT] -> SpecialInfo) -> Buffer);
strcpy(Config -> Voice,((struct StringInfo *)GadgetArray[GAD_VOICE] -> SpecialInfo) -> Buffer);
strcpy(Config -> Ring,((struct StringInfo *)GadgetArray[GAD_RING] -> SpecialInfo) -> Buffer);
Config -> ConnectAutoCapture = GadgetArray[GAD_AUTOCAPTURE] -> Flags & GFLG_SELECTED;
Config -> ConnectAutoBaud = GadgetArray[GAD_AUTOBAUD] -> Flags & GFLG_SELECTED;
Config -> LogActions = GadgetArray[GAD_LOG] -> Flags & GFLG_SELECTED;
break;
case GAD_CANCEL: Terminated = TRUE;
CopyMem(&PrivateConfig,Config,sizeof(struct Configuration));
break;
default: break;
}
}
}
}
PanelWindow -> Flags |= WFLG_RMBTRAP;
ClearMenuStrip(PanelWindow);
RemoveGList(PanelWindow,GadgetList,(UWORD)-1);
PopWindow();
CloseWindow(PanelWindow);
}
}
FreeMenus(PanelMenu);
}
FreeGadgets(GadgetList);
}
if(memcmp(&PrivateConfig,Config,sizeof(struct Configuration)))
return(TRUE);
else
return(FALSE);
}