home *** CD-ROM | disk | FTP | other *** search
- /*
- ** $Id: ImportPanel.c,v 1.4 92/04/21 16:58:59 olsen Sta Locker: olsen $
- ** $Revision: 1.4 $
- ** $Date: 92/04/21 16:58:59 $
- **
- ** Editing panel for phone unit settings
- **
- ** Copyright ⌐ 1990-1992 by Olaf `Olsen' Barthel & MXM
- ** All Rights Reserved
- */
-
- #include "termGlobal.h"
-
- enum { GAD_LIST,GAD_REPLACE,GAD_APPEND,GAD_CANCEL };
-
- #define WIDTH 480
- #define HEIGHT 126
-
- #define GADGET_WIDTH 140
- #define GADGET_COUNT 3
- #define GADGET_SPACE (GADGET_WIDTH + ((WIDTH - 20) - (GADGET_COUNT * GADGET_WIDTH)) / (GADGET_COUNT - 1))
-
- STATIC struct Gadget *
- CreateAllGadgets(struct List *PhoneList,struct Gadget **GadgetArray,struct Gadget **GadgetList,APTR VisualInfo,UWORD TopEdge)
- {
- struct Gadget *Gadget;
- struct NewGadget NewGadget;
- UWORD Counter = 0;
-
- memset(&NewGadget,0,sizeof(struct NewGadget));
-
- if(Gadget = CreateContext(GadgetList))
- {
- NewGadget . ng_LeftEdge = 10;
- NewGadget . ng_TopEdge = TopEdge + INTERHEIGHT + 8 + INTERHEIGHT;
- NewGadget . ng_Width = WIDTH - 20;
- NewGadget . ng_Height = 9 * 8 + 12;
- NewGadget . ng_GadgetText = LocaleString(MSG_GLOBAL_NAME_LIST_GAD);
- NewGadget . ng_TextAttr = &DefaultFont;
- NewGadget . ng_GadgetID = Counter;
- NewGadget . ng_Flags = PLACETEXT_ABOVE|NG_HIGHLABEL;
- NewGadget . ng_VisualInfo = VisualInfo;
-
- GadgetArray[Counter++] = Gadget = CreateGadget(LISTVIEW_KIND,Gadget,&NewGadget,
- GT_Underscore, '_',
- GTLV_Labels, PhoneList,
- GTLV_ShowSelected, NULL,
- TAG_DONE);
-
- if(!Gadget)
- return(NULL);
-
- NewGadget . ng_LeftEdge = 10;
- NewGadget . ng_TopEdge = Gadget -> TopEdge + Gadget -> Height + INTERHEIGHT + 12;
- NewGadget . ng_Width = 140;
- NewGadget . ng_Height = 12;
- NewGadget . ng_GadgetText = LocaleString(MSG_IMPORTPANEL_REPLACE_RATES_GAD);
- NewGadget . ng_GadgetID = Counter;
- NewGadget . ng_Flags = PLACETEXT_IN;
-
- GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
- GT_Underscore, '_',
- GA_Disabled, TRUE,
- TAG_DONE);
-
- NewGadget . ng_LeftEdge = NewGadget . ng_LeftEdge + GADGET_SPACE;
- NewGadget . ng_GadgetText = LocaleString(MSG_IMPORTPANEL_APPEND_RATES_GAD);
- NewGadget . ng_GadgetID = Counter;
-
- GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
- GT_Underscore, '_',
- GA_Disabled, TRUE,
- TAG_DONE);
-
- NewGadget . ng_LeftEdge = NewGadget . ng_LeftEdge + GADGET_SPACE;
- NewGadget . ng_GadgetText = LocaleString(MSG_GLOBAL_CANCEL_GAD);
- NewGadget . ng_GadgetID = Counter;
-
- GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
- GT_Underscore, '_',
- TAG_DONE);
- }
-
- return(Gadget);
- }
-
- VOID
- ImportPanel(struct PhoneEntry *Entry,struct List *PhoneList)
- {
- struct Window *PanelWindow;
- struct Gadget *GadgetList;
- struct Gadget *GadgetArray[GAD_CANCEL + 1];
-
- if(CreateAllGadgets(PhoneList,&GadgetArray[0],&GadgetList,VisualInfo,Screen -> WBorTop + Screen -> Font -> ta_YSize + 1))
- {
- 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_CLOSEWINDOW | IDCMP_VANILLAKEY | BUTTONIDCMP | LISTVIEWIDCMP,
- WA_Title, LocaleString(MSG_IMPORTPANEL_IMPORT_RATES_TXT),
- TAG_DONE))
- {
- struct IntuiMessage *Massage;
- ULONG Class,Code;
- struct Gadget *Gadget;
- BYTE Terminated = FALSE;
- LONG Selected = ~0;
-
- PushWindow(PanelWindow);
-
- AddGList(PanelWindow,GadgetList,(UWORD)-1,(UWORD)-1,NULL);
- RefreshGList(GadgetList,PanelWindow,NULL,(UWORD)-1);
- GT_RefreshWindow(PanelWindow,NULL);
-
- 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_VANILLAKEY)
- KeySelect(GadgetArray,GAD_CANCEL,Code,PanelWindow,&Gadget,&Class,&Code);
-
- if(Class == IDCMP_CLOSEWINDOW)
- Terminated = TRUE;
-
- if(Class == IDCMP_GADGETUP)
- {
- switch(Gadget -> GadgetID)
- {
- case GAD_LIST: if(Entry != Phonebook[Code])
- {
- if(Selected == ~0)
- {
- GT_SetGadgetAttrs(GadgetArray[GAD_REPLACE],PanelWindow,NULL,
- GA_Disabled, FALSE,
- TAG_DONE);
-
- GT_SetGadgetAttrs(GadgetArray[GAD_APPEND],PanelWindow,NULL,
- GA_Disabled, FALSE,
- TAG_DONE);
- }
-
- Selected = Code;
- }
- else
- {
- if(Selected != ~0)
- {
- GT_SetGadgetAttrs(GadgetArray[GAD_REPLACE],PanelWindow,NULL,
- GA_Disabled, TRUE,
- TAG_DONE);
-
- GT_SetGadgetAttrs(GadgetArray[GAD_APPEND],PanelWindow,NULL,
- GA_Disabled, TRUE,
- TAG_DONE);
-
- Selected = ~0;
- }
- }
-
- break;
-
- case GAD_APPEND:
- case GAD_REPLACE:
-
- if(Gadget -> GadgetID == GAD_REPLACE)
- {
- FreeTimeDateList((struct List *)&Entry -> TimeDateList);
-
- CopyTimeDateList((struct List *)&Phonebook[Selected] -> TimeDateList,(struct List *)&Entry -> TimeDateList,FALSE);
- }
- else
- CopyTimeDateList((struct List *)&Phonebook[Selected] -> TimeDateList,(struct List *)&Entry -> TimeDateList,TRUE);
-
- Terminated = TRUE;
-
- break;
-
- case GAD_CANCEL:Terminated = TRUE;
-
- break;
-
- default: break;
- }
- }
- }
- }
-
- RemoveGList(PanelWindow,GadgetList,(UWORD)-1);
-
- PopWindow();
-
- CloseWindow(PanelWindow);
- }
-
- FreeGadgets(GadgetList);
- }
- }
-