home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The CDPD Public Domain Collection for CDTV 3
/
CDPDIII.bin
/
pd
/
commodities
/
superdark
/
main
/
tom_gadget.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-20
|
19KB
|
761 lines
/************************************************************************/
/* */
/* File tom_gadget.c */
/* */
/************************************************************************/
/* I have a special kind of structure, for my own gadget. This structure*/
/* is used to create the configuration window, but also to read the */
/* confugration (and saved it) wich is in the .info file (but this is */
/* made in the icon_data.c file) */
/* */
/************************************************************************/
#include <exec/types.h>
#include <exec/tasks.h>
#include <exec/execbase.h>
#include <dos/dosextens.h>
#include <intuition/intuition.h>
#include <intuition/gadgetclass.h>
#include <libraries/gadtools.h>
#include <libraries/reqtools.h>
#include <graphics/displayinfo.h>
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include <clib/gadtools_protos.h>
#include <clib/reqtools_protos.h>
#include "/includes/struct.h"
#include "/includes/tom_gadget.h"
extern struct my_data my_info;
extern struct appel_proc data_proc;
extern UBYTE flg_debug;
extern struct ExecBase *SysBase;
extern struct ReqToolsBase *ReqToolsBase;
int Gere_gadg();
struct tom_gadget gadg_ok ={"_Ok" ,BUTTON , 20, 80, 70,12,0,0,0,0,0};
struct tom_gadget gadg_test ={"_Test" ,BUTTON ,100, 80, 70,12,0,0,0,0,0};
struct tom_gadget gadg_cancel={"_Cancel",BUTTON ,180, 80, 70,12,0,0,0,0,0};
struct tom_gadget gadg_info ={"_Info" ,BUTTON ,260, 80, 70,12,0,0,0,0,0};
struct Screen *Scr;
struct Gadget *Gadgets_tom[MAX_GADGET+4];
/*
struct Node ModulesNodes_alea[MAX_NOM];
USHORT flg_sel[MAX_NOM];
char *p_nom_alea[MAX_NOM];
#define MAX_LONG 20
struct List ModulesListAlea = {
&ModulesListAlea.lh_Tail, ( struct Node * )0l, &ModulesListAlea.lh_Head,0,0 };
*/
struct TextAttr topaz8 = {
( STRPTR )"topaz.font", 8, 0x00, 0x01 };
SHORT win_size_x=10;
SHORT win_size_y=10;
SHORT delta;
struct TagItem WindowTags_gadg[] = {
WA_Left, 174,
WA_Top, 44,
WA_Width, 347,
WA_Height, 124,
WA_IDCMP, IDCMP_MOUSEBUTTONS|IDCMP_GADGETDOWN|IDCMP_GADGETUP|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW|IDCMP_VANILLAKEY|IDCMP_MOUSEMOVE,
WA_Flags, WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
WA_Gadgets, 0l,
WA_Title, (char *)"Work Window",
WA_MinWidth, 67,
WA_MinHeight, 21,
WA_MaxWidth, 640,
WA_MaxHeight, 256,
TAG_DONE };
/********************************************************* add_one_gadget */
struct Gadget *add_one_gadget(p_gadg,num,g,Visual)
struct tom_gadget *p_gadg;
int num;
struct Gadget *g;
APTR Visual;
{
struct NewGadget ng;
int dir,place;
char **p_liste;
ng.ng_LeftEdge = p_gadg->LeftEdge;
ng.ng_TopEdge = p_gadg->TopEdge+delta;
ng.ng_Width = p_gadg->Width;
ng.ng_Height = p_gadg->Height;
ng.ng_GadgetText = p_gadg->GadgetText;
ng.ng_TextAttr = &topaz8;
ng.ng_GadgetID = num;
ng.ng_Flags = PLACETEXT_LEFT;
ng.ng_VisualInfo = Visual;
switch(p_gadg->type_gadg){
case BUTTON:
case SCREEN:
case FONT:
ng.ng_Flags = PLACETEXT_IN;
g = CreateGadget( BUTTON_KIND, g, &ng,
GT_Underscore, '_', TAG_DONE );
break;
case SLIDER:
place= PLACETEXT_RIGHT;
dir=LORIENT_HORIZ;
if(ng.ng_Width<ng.ng_Height){
dir=LORIENT_VERT;
place= PLACETEXT_BELOW;
}
if(p_gadg->p_data!=NULL){
*((int *)(p_gadg->p_data))=p_gadg->value;
}
g = CreateGadget( SLIDER_KIND, g, &ng,
GTSL_Min, p_gadg->d1,
GTSL_Max, p_gadg->d2,
GTSL_Level,p_gadg->value,
GTSL_MaxLevelLen, 3,
GTSL_LevelFormat, "%3ld",
GTSL_LevelPlace,place,
PGA_Freedom, dir,
/*
GA_Immediate, TRUE,
*/
GA_RelVerify, TRUE,
GT_Underscore, '_',TAG_DONE );
break;
case CHECKBOX:
g = CreateGadget( CHECKBOX_KIND, g, &ng,
GTCB_Checked,(p_gadg->value==TRUE?SELECTED:0),
GT_Underscore, '_', TAG_DONE );
break;
case MX:
/* Calcul le nombre d'elements */
p_gadg->d1=0;
p_gadg->d2=0;
while(p_gadg->p_data[p_gadg->d2]!=0){
p_gadg->d2++;
}
g = CreateGadget( MX_KIND, g, &ng,
GTMX_Labels,p_gadg->p_data,
GTMX_Active,p_gadg->value,
TAG_DONE );
break;
case LISTVIEW:
g = CreateGadget( LISTVIEW_KIND, g, &ng,
GTLV_Labels, p_gadg->p_data,
GTLV_ShowSelected, 0l,
GTLV_Selected,p_gadg->value,
GT_Underscore, '_',TAG_DONE );
break;
case OWN_GADGET:
g=(struct Gadget (*)())((APTR (*)())((struct own_init *)p_gadg->p_data)->own_add)(p_gadg,g,&ng);
break;
case CYCLE:
/* Calcul le nombre d'elements */
p_gadg->d1=0;
p_gadg->d2=0;
p_liste=(char **)p_gadg->p_data;
while(p_liste[p_gadg->d2]!=0){
p_gadg->d2++;
}
p_gadg->d2--;
g = CreateGadget( CYCLE_KIND, g, &ng,
GTCY_Labels, p_gadg->p_data,
GTCY_Active,p_gadg->value,
GT_Underscore, '_',TAG_DONE );
break;
case STRING:
g = CreateGadget(STRING_KIND, g, &ng,
GTST_String,p_gadg->p_data,
GTST_MaxChars,p_gadg->d1,
GT_Underscore, '_',TAG_DONE );
break;
case INTEGER:
g = CreateGadget(INTEGER_KIND, g, &ng,
GTIN_Number,p_gadg->value,
GTST_MaxChars,p_gadg->d1,
GT_Underscore, '_',TAG_DONE );
break;
default:
break;
}
p_gadg->p_gadg=g;
return(g);
}
/************************************************** reaffiche_images */
void reaffiche_images(struct contexe *pc)
{
struct tom_gadget *p_liste;
p_liste=pc->t_g;
while(p_liste->type_gadg!=END_LISTE){
if(p_liste->type_gadg==IMAGE){
DrawImage( pc->Wnd->RPort,
(struct Image *)p_liste->p_data ,
p_liste->LeftEdge,
p_liste->TopEdge+delta );
}
p_liste++;
}
}
/************************************************************************/
/* Fonction qui cree la liste des gadgets, dans le tableau Gadgets_gadg */
/************************************************************************/
InitStuff_gadg(pc,flg_bas)
struct contexe *pc;
int flg_bas;
{
struct Gadget *g;
struct tom_gadget *p_gadg,*pg;
SHORT i,max_x,max_y;
p_gadg=pc->t_g;
if ( NOT( Scr = LockPubScreen( "Workbench" )))
return( 1l );
if ( NOT( pc->Visual = GetVisualInfo( Scr, TAG_DONE )))
return( 2l );
if ( NOT( g = CreateContext( &pc->GList )))
return( 3l );
max_x=win_size_x;
max_y=win_size_y;
pg=p_gadg;
delta=Scr->WBorTop+Scr->Font->ta_YSize-8;
while(pg->type_gadg!=END_LISTE){
if(pg->LeftEdge+pg->Width>max_x){
max_x=pg->LeftEdge+pg->Width;
}
if(pg->TopEdge+pg->Height>max_y){
max_y=pg->TopEdge+pg->Height;
}
/*
printf("[%d]: leftedge:%d topedge:%d width:%d height:%d maxx:%d maxy:%d\n",i,
pg->LeftEdge,
pg->TopEdge,
pg->Width,
pg->Height,
max_x,max_y);
*/
pg++;
}
max_y+=10;
max_x+=30;
if(flg_bas==FALSE){
gadg_ok.TopEdge=max_y;
gadg_test.TopEdge=max_y;
gadg_cancel.TopEdge=max_y;
gadg_info.TopEdge=max_y;
max_y+=gadg_ok.Height+10;
if(max_x<gadg_info.Width+gadg_info.LeftEdge){
max_x=gadg_info.Width+gadg_info.LeftEdge+10;
}
}
max_y+=delta;
if(max_x>Scr->Width)max_x=Scr->Width;
if(max_x+WindowTags_gadg[0].ti_Data>Scr->Width){
WindowTags_gadg[0].ti_Data=Scr->Width-max_x;
}
if(max_y>Scr->Height)max_y=Scr->Height;
if(max_y+WindowTags_gadg[1].ti_Data>Scr->Height){
WindowTags_gadg[1].ti_Data=Scr->Height-max_y;
}
WindowTags_gadg[0].ti_Data=(Scr->Width -max_x)/2;
WindowTags_gadg[1].ti_Data=(Scr->Height-max_y)/2;
WindowTags_gadg[2].ti_Data=max_x;
WindowTags_gadg[3].ti_Data=max_y;
if(flg_bas==FALSE){
g =add_one_gadget(&gadg_ok,GD_ok,g,pc->Visual);
Gadgets_tom[ GD_ok ]=g;
g =add_one_gadget(&gadg_test,GD_test,g,pc->Visual);
Gadgets_tom[ GD_test ]=g;
g =add_one_gadget(&gadg_cancel,GD_cancel,g,pc->Visual);
Gadgets_tom[ GD_cancel]=g;
g =add_one_gadget(&gadg_info,GD_info,g,pc->Visual);
Gadgets_tom[ GD_info ]=g;
}
i=0;
while(p_gadg[i].type_gadg!=END_LISTE){
if(pg->LeftEdge>=0){
g=add_one_gadget(&p_gadg[i],i+GD_info+1,g,pc->Visual);
Gadgets_tom[ i+GD_info+1 ] = g;
if ( NOT g ){
printf("ERREUR creation gadget\n");
return( 4l );
}
i++;
if(i==MAX_GADGET){
printf("Erreur,maximum de gadgets atteint!\n");
}
}
}
WindowTags_gadg[ 6 ].ti_Data = (ULONG)pc->GList;
WindowTags_gadg[ 7 ].ti_Data = (ULONG)pc->p_name;
if ( NOT( pc->Wnd = OpenWindowTagList( 0l, WindowTags_gadg )))
return( 5l );
GT_RefreshWindow( pc->Wnd, 0l );
reaffiche_images(pc);
return( 0l );
}
/************************************************** cleanstuff */
void CleanStuff_gadg(pc)
struct contexe *pc;
{
int i;
struct tom_gadget *p_gadg;
if ( pc->Wnd ){
p_gadg=pc->t_g;
i=0;
while(p_gadg[i].type_gadg!=END_LISTE){
if(p_gadg[i].type_gadg==OWN_GADGET){
(void (*)())((APTR (*)())((struct own_init *)p_gadg[i].p_data)->own_end)();
}
i++;
}
CloseWindow( pc->Wnd);
pc->Wnd=0;
if ( pc->GList )
FreeGadgets( pc->GList );
if(Scr)UnlockPubScreen(NULL,Scr);
if ( pc->Visual )
FreeVisualInfo( pc->Visual );
}
}
/************************************************** affiche_texte */
void affiche_texte(char *p_t,struct contexte *p_c,int flg_auto_remove)
{
struct IntuiMessage *msg;
int x,y,n,n_max,y_max;
struct RastPort *rp;
char buffer[80],*save_pt;
struct contexe my_ctx;
int old_send;
static struct tom_gadget my_gadg[]={
{"_Ok", BUTTON , 30,100, 200,12,0,0,0,0,0},
{0, END_LISTE, 0, 0, 0, 0, 0,0,0,0,0}};
old_send=my_info.flg_send;
my_info.flg_send=0;
if(p_t!=NULL){
/* Recherche de la taille du texte en x et y, pour pouvoir */
/* ouvrir une fenetre de la taille desiree */
save_pt=p_t;
n_max=0;y_max=0;
n=0;
do{
if((*p_t!='\n')&&(*p_t!=0)){
n++;
}else{
if( n_max<n ){
n_max=n;
}
n=0;
y_max++;
}
p_t++;
}while(*(p_t-1)!=0);
my_gadg[0].Width=n_max*8;
my_gadg[0].TopEdge=30+y_max*8;
if(flg_auto_remove==TRUE){
my_gadg[0].type_gadg=END_LISTE;
win_size_x=my_gadg[0].Width;
win_size_y=my_gadg[0].TopEdge;
}else{
my_gadg[0].type_gadg=BUTTON;
}
my_ctx.t_g=my_gadg;
my_ctx.GList=0;
my_ctx.p_name="SuperDark Information...";
/* Open the window and create the gadgets */
InitStuff_gadg(&my_ctx,TRUE);
/* Display the information text */
rp=my_ctx.Wnd->RPort;
x=20;y=30;
n=0;
p_t=save_pt;
SetAPen(rp,1);
do{
if((*p_t!='\n')&&(*p_t!=0)){
buffer[n]=*p_t;
n++;
}else{
Move(rp,x,y);
Text(rp,buffer,n);
x=20;y+=8;n=0;
}
p_t++;
}while(*(p_t-1)!=0);
if(flg_auto_remove==FALSE){
/* Wait for an action. Any action will close the window! */
WaitPort(my_ctx.Wnd->UserPort);
while((msg=(struct IntuiMessage *)GT_GetIMsg(my_ctx.Wnd->UserPort))!=0){
GT_ReplyIMsg(msg);
}
}else{
Delay(100);
}
CleanStuff_gadg(&my_ctx);
}
win_size_x=10;
win_size_y=10;
my_info.flg_send=old_send;
}
/************************************************** handle event */
void handle_event_gadg(pg,code,pc)
struct Gadget *pg;
int code;
struct contexe *pc;
{
int id;
struct tom_gadget *p_t;
struct rtScreenModeRequester *scrmodereq;
struct rtFontRequester *fontreq;
struct TextAttr *p_text_attr;
id=pg->GadgetID;
if(id<=GD_info){
switch(id){
case GD_info:
affiche_texte(data_proc.p_texte,pc,FALSE);
break;
case GD_ok:
pc->flg_save=TRUE;
case GD_cancel:
pc->flg_end=TRUE;
break;
case GD_test:
Forbid();
my_info.flg_send=1;
Permit();
big_blank();
my_info.flg_send=0;
break;
default:
break;
}
}else{
p_t=&pc->t_g[id-GD_info-1];
switch(p_t->type_gadg){
case BUTTON:
if(p_t->p_data!=0){
pc->flg_end=(int (*)())((APTR (*)())p_t->p_data)(pg,p_t,pc);
}
break;
case MX:
case LISTVIEW:
case CYCLE:
p_t->value=code;
break;
case STRING:
if(p_t->p_data!=NULL){
strcpy(p_t->p_data,((struct StringInfo *)(pg->SpecialInfo))->Buffer);
}
break;
case INTEGER:
p_t->value=(p_t->p_data,((struct StringInfo *)(pg->SpecialInfo))->LongInt);
printd("Integer:%d\n",p_t->value);
break;
case CHECKBOX:
if((pg->Flags&SELECTED)==0){
p_t->value=FALSE;
}else{
p_t->value=TRUE;
}
break;
case SLIDER:
p_t->value=code;
if(p_t->p_data!=NULL){
*((int *)(p_t->p_data))=code;
}
break;
case OWN_GADGET:
(void (*)())((APTR (*)())((struct own_init *)p_t->p_data)->own_press)(pg,code,pc->Wnd);
break;
case SCREEN:
printd("Screen....");
if((ReqToolsBase!=0)&&(ReqToolsBase->LibNode.lib_Version>=38)){
if (scrmodereq = rtAllocRequestA (RT_SCREENMODEREQ, NULL)) {
/* On met les parametres deja present */
if(p_t->d1!=0){
rtChangeReqAttr(scrmodereq,
RTSC_DisplayID,(ULONG)p_t->p_data,
RTSC_DisplayWidth,(ULONG)p_t->d1,
RTSC_DisplayHeight,(ULONG)p_t->d2,
RTSC_DisplayDepth,(ULONG)p_t->d3,
RTSC_OverscanType,(ULONG)p_t->value,
TAG_DONE
);
}
if (rtScreenModeRequest (scrmodereq,
"Pick a screen mode:",
RTSC_Flags, SCREQF_DEPTHGAD|SCREQF_SIZEGADS|
SCREQF_OVERSCANGAD,
TAG_END
)){
scrmodereq->DisplayID,
p_t->p_data=(char *)scrmodereq->DisplayID;
p_t->d1=scrmodereq->DisplayWidth;
p_t->d2=scrmodereq->DisplayHeight;
p_t->d3=scrmodereq->DisplayDepth;
p_t->value=scrmodereq->OverscanType;
}
rtFreeRequest (scrmodereq);
}
}else{
aff_error("To use this features, you should have\nReqTools version V38 and WB2.0\n\n");
}
break;
case FONT:
printd("Font....");
if(ReqToolsBase!=0){
if (fontreq = rtAllocRequestA (RT_FONTREQ, NULL)) {
/* On met les parametres deja present */
p_text_attr=(struct TextAttr *)p_t->p_data;
rtChangeReqAttr(fontreq,
RTFO_FontName,(ULONG)p_text_attr->ta_Name,
RTFO_FontHeight,(ULONG)p_text_attr->ta_YSize,
RTFO_FontStyle,(ULONG)p_text_attr->ta_Style,
RTFO_FontFlags,(ULONG)p_text_attr->ta_Flags
);
if (rtFontRequest (fontreq,
"Pick a font:",
RTFO_Flags, FREQF_SCALE,
TAG_END
)){
strcpy(p_text_attr->ta_Name,fontreq->Attr.ta_Name);
p_text_attr->ta_YSize=fontreq->Attr.ta_YSize;
p_text_attr->ta_Flags=fontreq->Attr.ta_Flags;
p_text_attr->ta_Style=fontreq->Attr.ta_Style;
}
rtFreeRequest (fontreq);
}
}else{
aff_error("To use this features, you should have\nReqTools\n\n");
}
break;
}
}
}
/**************************************************/
void test_bornes(struct tom_gadget *p_liste)
{
if(p_liste->value<p_liste->d1){
p_liste->value=p_liste->d2;
}
if(p_liste->value>p_liste->d2){
p_liste->value=p_liste->d1;
}
}
/************************************************** find raccourcis */
void find_raccourcis(code,pc)
int code;
struct contexe *pc;
{
USHORT i;
short dir,flg_found;
struct Gadget *gadg;
int state;
struct tom_gadget *p_liste;
char *p_text;
p_liste=pc->t_g;
i=0;
dir=1;
flg_found=FALSE;
while((p_liste->type_gadg!=END_LISTE)&&(flg_found==FALSE)){
p_text=p_liste->GadgetText;
while(*p_text!=0){
if((*p_text=='_')&&(tolower(*(p_text+1))==tolower(code))){
flg_found=TRUE;
if(isupper(code)){
dir=-1;
}
}
p_text++;
}
if(flg_found==TRUE){
gadg=Gadgets_tom[i+GD_info+1];
switch(p_liste->type_gadg){
case OWN_GADGET:
case BUTTON:
case SCREEN:
case FONT:
/*
ActivateGadget(gadg,pc->Wnd,NULL);
*/
handle_event_gadg(gadg,code,pc);
break;
case CHECKBOX:
state=FALSE;
if((gadg->Flags&SELECTED)==0){
state=TRUE;
}
GT_SetGadgetAttrs (gadg,pc->Wnd,
NULL,GTCB_Checked,state,TAG_DONE);
handle_event_gadg(gadg,code,pc);
break;
case SLIDER:
p_liste->value+=dir;
test_bornes(p_liste);
/*
GT_SetGadgetAttrs (gadg,pc->Wnd,
NULL,GTSL_Level,p_liste->d1+(p_liste->value-p_liste->d1)%(p_liste->d2-p_liste->d1+1),TAG_DONE);
*/
GT_SetGadgetAttrs (gadg,pc->Wnd,
NULL,GTSL_Level,p_liste->value,TAG_DONE);
break;
case MX:
/*
p_liste->value+=dir;
test_bornes(p_liste);
GT_SetGadgetAttrs (gadg,pc->Wnd,
NULL,GTMX_Active,(p_liste->value),TAG_DONE);
*/
break;
case CYCLE:
p_liste->value+=dir;
test_bornes(p_liste);
GT_SetGadgetAttrs (gadg,pc->Wnd,
NULL,GTCY_Active,(p_liste->value),TAG_DONE);
break;
case STRING:
case INTEGER:
ActivateGadget(gadg,pc->Wnd,NULL);
break;
case LISTVIEW:
p_liste->value+=dir;
test_bornes(p_liste);
GT_SetGadgetAttrs (gadg,pc->Wnd,
NULL,GTLV_Selected,(p_liste->value),GTLV_Top,p_liste->value,TAG_DONE);
break;
}
}
p_liste++;
i++;
}
}
/************************************************************* main_gadg */
void main_gadg(pc)
struct contexe *pc;
{
struct IntuiMessage *msg;
int class,code;
APTR IAdress;
pc->flg_end=FALSE;
do{
WaitPort(pc->Wnd->UserPort);
while((msg=(struct IntuiMessage *)GT_GetIMsg(pc->Wnd->UserPort))!=0){
class=msg->Class;
code=msg->Code;
IAdress=msg->IAddress;
GT_ReplyIMsg(msg);
switch(class){
case CLOSEWINDOW:
pc->flg_end=TRUE;
break;
case VANILLAKEY:
switch(code){
case 'o':
pc->flg_end=TRUE;
pc->flg_save=TRUE;
break;
case 'c':
case 27: /* escape */
pc->flg_end=TRUE;
break;
case 't':
handle_event_gadg(Gadgets_tom[GD_test],code,pc);
break;
case 'i':
handle_event_gadg(Gadgets_tom[GD_info],code,pc);
break;
default:
find_raccourcis(code,pc);
break;
}
break;
case GADGETDOWN:
case GADGETUP:
handle_event_gadg(IAdress,code,pc);
break;
case REFRESHWINDOW:
reaffiche_images(pc);
GT_RefreshWindow( pc->Wnd, 0l );
break;
default:
break;
}
}
}while(pc->flg_end==FALSE);
}
int Gere_gadg(struct tom_gadget *p_gadg,char *p_name)
{
struct contexe ctx;
ctx.t_g=p_gadg;
ctx.GList=0;
ctx.p_name=p_name;
ctx.flg_save=FALSE;
InitStuff_gadg(&ctx,FALSE);
main_gadg(&ctx,FALSE);
CleanStuff_gadg(&ctx);
return(ctx.flg_save);
}