home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************************\
-
- dialogs module
-
- part of suntar, ⌐1991-92 Sauro & Gabriele Speranza
-
- This program is public domain, feel free to use it or part of it for anything
-
- \*******************************************************************************/
-
- #include "antiglue.h"
- /* #include "system7.h" */
-
- #include "windows.h"
- #include "suntar.h"
-
- #include <string.h>
-
- #define CONTROL_ON 1 /* Control value for on */
- #define CONTROL_OFF 0 /* Control value for off */
-
- #define ESC 27
-
- #define TITLEBARHEIGHT 20
-
- #define obSet 1
- #define obSave 2
- #define obCancel 3
-
- #define ob800 6
- #define obAlias 7
- #define obCreaDir 8
- #define obModiDate 10
- #define obUseSys7_SF 11
- #define obDelInc 12
- #define obTrunc14 13
- #define obUnderscore 14
- #define obSupprShell 15
- #define obVerify 16
- #define obSmallASCII 17
-
- #define obFirstCheck ob800
- #define obLastCheck (obFirstCheck+last_check_option-first_check_option)
-
- #define obTextCr 18
- #define obGIFCr 19
- #define obDelay 21
- #define obMinBeep 20
- #define obTarPopup 5
- #define obTarPopupTitle (obTarPopup-1)
- #define obWrASCPopup 22
-
- #define sdFind 1
- #define sdExtract 2
- #define sdCancel 3
- #define sdScrollingList 4
-
- #define fdFind 1
- #define fdCancel 2
- #define fdCheck 3
- #define fdSText 4
- #define fdText 5
-
- #define mouseClicksDisabled -1
-
- extern char FINITO[],DONE[];
-
- void SetCheckBox(DialogPtr,short);
- void set_option_var(DialogPtr,short,Boolean *);
- void get_option_var(DialogPtr,short,Boolean);
- void find_and_select(void);
- void select_list_filter(EventRecord *);
- void prepara_nome(char*,char*,long,short,short);
- static void list_updater(EventRecord *);
- static void list_activater(EventRecord *);
-
-
- static int button_code;
- DialogPtr ListDialog=NULL;
- static ListHandle LHandle;
- static Rect cornice;
- static Boolean at_start;
-
-
- pascal Boolean modal_filter (DialogPtr,EventRecord *,short *);
- static pascal Boolean modal_filter (theDialog,theEvent,itemHit)
- DialogPtr theDialog;
- register EventRecord *theEvent;
- short *itemHit;
- {
- /* unfortunately some events are simply ignored during some Toolbox calls:
- the event loop contained in the Alert or ModalDialog system routine can't know
- how to handle update an activate routines for user windows; furthermore, even the
- outline to the default button is not redrawn: if, for example, a screen saver
- blanks the screen, the outline is lost because ModalDialog updates only what it
- knows. Hence, I had to create an event filter for all modal dialogs, including
- standard file dialogs and Alert.
- Really, the best thing would be if Apple allowed to use the windowPic field in the window
- record in a different way: place there a pointer to an application-defined routine
- which handles updates and activates and is called implicitly by GetNextEvent, which
- then will return false (so solving the problems for such events) and furthermore
- if a button could have a standard attribute "outlined" so that, DrawDialog could
- do the right job (that second thing seems to have been done, see TN 304).
- Another thing that GetNextEvent should do is calling FindWindow for mouseDown events,
- so that you get the information about which window was clicked even if that window
- was closed between the time of the click and the moment you get the event (for example,
- suntar 1.0 closed the about box when the Button function returned true, but the
- mouseDown event remained in the event queue... In suntar 1.2, the same problem
- has remained for the "going to background" dialog)
- */
- short kind;
- Handle h;
- Rect r;
- switch(theEvent->what){
- case keyDown:
- if((unsigned char)theEvent->message==CR || (unsigned char)theEvent->message==enter_key){
- GetDItem(theDialog,1,&kind,&h,&r);
- SelectButton(h);
- *itemHit=1;
- return true;
- }
- break;
- case updateEvt:
- if((DialogPtr)theEvent->message==theDialog){
- /* ModalDialog would do the update, but without OutlineControl...
- hence, I handle the event directly here */
- WindowPtr w=NULL;
- int item;
- DialogSelect(theEvent,&w,&item);
-
- GetDItem(theDialog,1,&kind,&h,&r);
- OutlineControl(h);
- theEvent->what=nullEvent;
- }
- else
- UpdateFilter(theEvent);
- break;
- case activateEvt:
- UpdateFilter(theEvent);
- break;
- /* luckily, ModalDialog masks out disk insertions, so that they are received
- only after the dialog is closed: otherwise, I would not know what to
- do in that case... */
- }
-
- return false;
- }
-
- /* constants for positioning the default item within its box */
- #define leftSlop 13 /* leave this much space on left of title */
- #define rightSlop 5 /* this much on right */
- #define botSlop 5 /* this much below baseline */
-
- extern MenuHandle tarPopupMenu,ntAPopupMenu;
- static short curr_tarpopup,curr_ntApopup;
-
- pascal void redrawPopup(WindowPtr,short);
- static pascal void redrawPopup(theWindow,itemNo)
- WindowPtr theWindow;
- short itemNo;
- {
- /* inspired to Apple's Sample Code 006, but adding the triangle */
- short kind;
- Handle h;
- Rect r;
- char title[32];
- MenuHandle menu_h;
- short curr_item;
- PolyHandle triangle;
- #define triang_top -12
- #define triang_left -18
- GetDItem(theWindow,itemNo,&kind,&h,&r);
-
- if(itemNo==obTarPopup){
- menu_h=tarPopupMenu;
- curr_item=curr_tarpopup;
- }
- else if(itemNo==obWrASCPopup){
- menu_h=ntAPopupMenu;
- curr_item=curr_ntApopup;
- }
-
- GetItem (menu_h,curr_item,&title);
- InsetRect(&r,-1,-1); /* make it a little bigger */
-
- /* draw the box and its drop shadow */
- FrameRect(&r);
- MoveTo(r.right,r.top+2); LineTo(r.right,r.bottom);
- LineTo(r.left+2,r.bottom);
- /* draw the string */
- MoveTo(r.left+leftSlop,r.bottom-botSlop);
- DrawString(title);
-
- /* draw the triangle (according to the Guidelines of IM Vol 6) */
- triangle=OpenPoly();
- MoveTo(r.right+triang_left,r.bottom+triang_top);
- LineTo(r.right+triang_left+12, r.bottom+triang_top);
- LineTo(r.right+triang_left+6,r.bottom+triang_top+6);
- ClosePoly();
- FillPoly(triangle,black);
- KillPoly(triangle);
- }
-
- pascal Boolean options_filter (DialogPtr,EventRecord *,short *);
- static pascal Boolean options_filter (theDialog,theEvent,itemHit)
- DialogPtr theDialog;
- register EventRecord *theEvent;
- short *itemHit;
- {
- short my_item;
-
- if(theEvent->what==mouseDown){
- GrafPtr savePort;
- Point mouseLoc= theEvent->where;
- GetPort(&savePort);
- SetPort(theDialog);
- GlobalToLocal(&mouseLoc);
-
- my_item=FindDItem(theDialog, mouseLoc)+1;
-
- if ( my_item== obTarPopup || my_item==obWrASCPopup){
- /* again, inspired to Apple's Sample Code 006 */
- short kind;
- Handle h;
- Rect r,promptBox;
- Point popLoc;
- long chosen;
- MenuHandle menu_h;
- short curr_item;
-
- if(my_item==obTarPopup){
- GetDItem(theDialog,obTarPopupTitle,&kind,&h,&promptBox);
- InvertRect(&promptBox);
- menu_h=tarPopupMenu;
- curr_item= curr_tarpopup;
- }
- else{
- menu_h=ntAPopupMenu;
- curr_item=curr_ntApopup;
- }
- InsertMenu(menu_h,-1);
- GetDItem(theDialog,my_item,&kind,&h,&r);
- popLoc = *(Point*)&r.top;
- LocalToGlobal(&popLoc);
- CalcMenuSize(menu_h); /*Work around Menu Mgr bug*/
- EraseRect(&r);
- chosen = PopUpMenuSelect(menu_h, popLoc.v, popLoc.h, curr_item);
- if(my_item==obTarPopup){
- InvertRect(&promptBox);
- DeleteMenu(tarPopupID);
- if(chosen) curr_tarpopup = loword(chosen);
- }
- else{
- DeleteMenu(ntAPopupID);
- if(chosen) curr_ntApopup = loword(chosen);
- }
-
- InvalRect(&r);
- theEvent->what=nullEvent;
- }
- SetPort(savePort);
- return false;
- }
- else if(theEvent->what==keyDown && (char)theEvent->message==ESC)
- theEvent->what=nullEvent; /* the dialog has no equivalent for Cancel,
- if I don't remove it it will go in the text
- (TextEdit does not know that ESC has a special
- meaning) */
- else if(theEvent->what==keyDown && (theEvent->modifiers & cmdKey) ){
- /* handle the edit commands in the dialog... */
- if(((char)theEvent->message|0x20)=='c'){
- DlgCopy (theDialog);
- theEvent->what=nullEvent;
- }
- else if(((char)theEvent->message|0x20)=='x'){
- DlgCut (theDialog);
- theEvent->what=nullEvent;
- }
- if(((char)theEvent->message|0x20)=='v'){
- if( TEGetScrapLen() <=8)
- DlgPaste (theDialog);
- else
- SysBeep(5); /* don't paste a very long string to a very small field */
- theEvent->what=nullEvent;
- }
- return false;
- }
- else
- return modal_filter(theDialog,theEvent,itemHit);
- }
-
- void options_box()
- {
- int i,currentRadio;
- Str255 buffer;
- /*EventRecord myEvent;*/
- DialogPtr myDialog;
- short kind;
- Handle h;
- Rect r;
- short itemHit;
- AlertTHndl alertHandle;
- SignedByte oldflags;
-
- SetCursor(&arrow);
-
- if (alertHandle = Get1Resource('DLOG',128)) {
- oldflags=HGetState(alertHandle);
- HNoPurge((Handle)alertHandle);
- PositionDialog( &((**alertHandle).boundsRect));
- }
- myDialog = GetNewDialog (128,NULL,(char*)-1);
-
- if(myDialog!=NULL){
- if(non_text_ASCII >3 ) non_text_ASCII=0;
- #ifdef V_122
- currentRadio= obFirstRadio+non_text_ASCII;
- SetRadioButton(myDialog,currentRadio,CONTROL_ON);
- #endif
-
- GetDItem(myDialog,obTextCr,&kind,&h,&r);
- buffer[0]=4;
- mcopy(&buffer[1],&text_creator,4);
- SetIText(h,buffer);
-
- GetDItem(myDialog,obGIFCr,&kind,&h,&r);
- buffer[0]=4;
- mcopy(&buffer[1],&gif_creator,4);
- SetIText(h,buffer);
-
- GetDItem(myDialog,obDelay,&kind,&h,&r);
- my_itoa((long)delay_back,buffer);
- c2pstr(buffer);
- SetIText(h,buffer);
-
- GetDItem(myDialog,obMinBeep,&kind,&h,&r);
- my_itoa((long)min_to_beep,buffer);
- c2pstr(buffer);
- SetIText(h,buffer);
-
- for(i=first_check_option;i<=last_check_option;i++){
- if(i!=skip_check_option)
- get_option_var(myDialog,obFirstCheck-first_check_option+i,options.opt_bytes[i]);
- }
-
- GetDItem(myDialog,obTarPopup,&kind,&h,&r);
- SetDItem (myDialog,obTarPopup, kind, (Handle)redrawPopup, &r);
- curr_tarpopup=tar_version+1;
- GetDItem(myDialog,obWrASCPopup,&kind,&h,&r);
- SetDItem (myDialog,obWrASCPopup, kind, (Handle)redrawPopup, &r);
- curr_ntApopup=non_text_ASCII+1;
-
- do {
- ModalDialog(options_filter,&itemHit);
- if(itemHit>=obFirstCheck && itemHit <= obLastCheck)
- SetCheckBox(myDialog,itemHit);
- #ifdef V_122
- else if(itemHit>=obFirstRadio && itemHit <= obLastRadio){
- SetRadioButton(myDialog,currentRadio,CONTROL_OFF);
- SetRadioButton(myDialog,(currentRadio=itemHit),CONTROL_ON);
- }
- #endif
- }
- while (itemHit != obSave && itemHit != obCancel && itemHit != obSet );
-
- if( itemHit != obCancel){
- GetDItem(myDialog,obTextCr,&kind,&h,&r);
- GetIText(h,buffer);
- for(i=buffer[0];i<=4;)
- buffer[++i]=' ';
- mcopy(&text_creator,&buffer[1],4);
-
- GetDItem(myDialog,obGIFCr,&kind,&h,&r);
- GetIText(h,buffer);
- for(i=buffer[0];i<=4;)
- buffer[++i]=' ';
- mcopy(&gif_creator,&buffer[1],4);
-
- GetDItem(myDialog,obDelay,&kind,&h,&r);
- GetIText(h,buffer);
- i= pstrtoi(buffer);
- if(i>0 && i<20*60)
- delay_back = i;
-
- GetDItem(myDialog,obMinBeep,&kind,&h,&r);
- GetIText(h,buffer);
- i= pstrtoi(buffer);
- if(i>0)
- min_to_beep = i;
-
- for(i=first_check_option;i<=last_check_option;i++){
- if(i!=skip_check_option)
- set_option_var(myDialog,obFirstCheck-first_check_option+i,&options.opt_bytes[i]);
- }
-
- /*non_text_ASCII = currentRadio - obFirstRadio;*/
- tar_version=curr_tarpopup-1;
- non_text_ASCII=curr_ntApopup-1;
-
- if(itemHit==obSave) save_options();
- }
-
- HSetState(alertHandle,oldflags);
- DisposDialog(myDialog);
- }
- }
-
-
- pascal void redrawList(WindowPtr,short);
- static pascal void redrawList(theWindow,itemNo)
- WindowPtr theWindow;
- short itemNo;
- {
- LUpdate(((WindowPtr)ListDialog)->visRgn,LHandle);
- FrameRect (&cornice);
- }
-
- void select_and_extract()
- {
- /* this routine makes too many too different things, and the handling of
- AIX tar made things worst: it should be broken into at least two pieces,
- one handling the window and its list, the other one handling the tar/bar
- archive */
-
- long length;
- Boolean more_files;
- Rect rView,dataBounds;
- int i,theCell;
- char buffer[150];
- Point myCell;
- int ci_stanno_certo;
- sector_t last_header;
- AlertTHndl alertHandle;
- sector_t ** sectorList;
- Size sectListSize;
- SignedByte oldflags;
- static char s1[]="Nessun file parte qui\n", s2[]="No file starts in this disk\n";
-
- ListDialog=NULL;
- LHandle=NULL;
- sectListSize=0;
- if(setjmp(main_loop)<0) {
- if(ListDialog){
- if(LHandle!=0) LDispose(LHandle);
- DisposDialog(ListDialog);
- remove_handlers(ListDialog);
- ListDialog=NULL;
- }
- if(sectListSize) DisposHandle(sectorList);
- return;
- }
-
- if(aspetta_inserzione(in_Italia?"\pInserisci il disco in formato UNIX":
- "\pInsert the disk in UNIX format")) return;
- if(di.is_not_initialized) return;
-
- fase=reading_disk;
-
- {
- enum formats fmt;
- previousFormat=tar_unknown;
- fmt=identify_format();
-
- if(fmt==tar_format){
- bar_archive=false;
- last_header=0;
- }
- else if(fmt==bar_format){
- bar_archive=true;
- floppy_n=untar_number( ((barh_type*)disk_buffer)->volume_num,true);
- last_header= (untar_number( ((barh_type*)disk_buffer)->size,true)+1023)>>9;
- }
- else{
- diskEject();
- return; /* i messaggi sono giê comparsi... */
- }
- }
-
- if(last_header>=sectors_on_floppy){ /* only for bar... */
- printf(in_Italia ? s1:s2);
- return;
- }
-
- alertHandle = (AlertTHndl)Get1Resource('DLOG',131);
-
- if (alertHandle) {
- oldflags=HGetState(alertHandle);
- HNoPurge((Handle)alertHandle);
- (**alertHandle).boundsRect.top-=TITLEBARHEIGHT;
- PositionDialog( &((**alertHandle).boundsRect));
- (**alertHandle).boundsRect.top+=TITLEBARHEIGHT;
- ListDialog=GetNewDialog(131,NULL,-1L);
- SetWTitle (ListDialog,in_Italia?"\pSelezione files":"\pFile selection");
- install_handlers(ListDialog,list_updater,list_activater);
-
- /*printf("windowKind=%d\n",((WindowPeek)ListDialog)->windowKind); 2!*/
- ((WindowPeek)ListDialog)->refCon= -2;
-
- SetPort(ListDialog);
- {
- static char *titoli[]={"\pTrova╔","\pEstrai","\pAnnulla"};
- short kind;
- Handle h;
- Rect r;
- for(i=1;i<=3;i++){
- GetDItem(ListDialog,i,&kind,&h,&r);
- if(in_Italia) SetCTitle(h,titoli[i-1]);
- HiliteControl(h, 255);
- }
- GetDItem(ListDialog,sdScrollingList,&kind,&h,&rView);
- SetDItem (ListDialog,sdScrollingList, kind, (Handle)redrawList, &rView);
- }
-
- /*TextFont(3);*/
- {FontInfo fInfo;
- GetFontInfo(&fInfo);
- i=fInfo.ascent+fInfo.descent+fInfo.leading;
- }
- rView.bottom= rView.top+ ((rView.bottom-rView.top)/i) * i;
- cornice=rView;
- InsetRect(&cornice,-1,-1);
-
- rView.right -= 15;
- ci_stanno_certo= (rView.right-rView.left)/CharWidth('m');
-
- /*PenSize(1,1);*/
- FrameRect (&cornice);
-
- dataBounds.top = 0;
- dataBounds.left = 0;
- dataBounds.bottom = 0;
- dataBounds.right = 1;
- LHandle = LNew(&rView, /* position in window */
- &dataBounds,/* initial size of array */
- 0L, /* cell size (0 = default) */
- 0, /* resource ID of LDEF */
- ListDialog, /* window pointer */
- true, /* drawit */
- false, /* has grow */
- false, /* scrollHoriz */
- true); /* scrollVert */
-
- (**LHandle).selFlags = lNoExtend | lNoRect | lUseSense | lExtendDrag | lNoNilHilite;
-
- for(;;){ /* loop on disks, for AIX only */
- extern Boolean disco_espulso;
- int files_on_floppy=0;
- my_event_filter=select_list_filter;
- theCell=0;
- disco_espulso=false;
- listonly=1;
- while(last_header<sectors_on_floppy){
- unsigned char linkflag;
- /* printf ("leggo %ld\n",(long)last_header); */
- check_events();
- leggi_settore(last_header,disk_buffer);
- if(check_error()) raise_error();
-
- sect_n=last_header;
- if(check_all_zero(disk_buffer)){
- if(last_header==0||(bar_archive||hasVheader)&&last_header==1)
- printf(in_Italia?"Disco vuoto\n":"No data on disk\n");
- break;
- }
-
- linkflag=get_linkflag(&length);
- if( linkflag=='\0'||linkflag=='0'||linkflag=='7' ){
- /*print_info(bar_archive ? ((barh_type*)disk_buffer)->name :
- ((tarh_type*)disk_buffer)->name,length);*/
- if(!sectListSize)
- sectorList= NewHandle(sectListSize=sizeof(sector_t));
- else
- SetHandleSize (sectorList, sectListSize+=sizeof(sector_t) );
- /* it should be:
- (*sectorList)[sectListSize/sizeof(sector_t)-1] = last_header;
- but optimizing:
- */
- *(sector_t*)(((char*)(*sectorList))+sectListSize-sizeof(sector_t)) = last_header;
-
- theCell=LAddRow(1,theCell+1,LHandle);
- myCell.v=theCell;
- myCell.h=0;
- prepara_nome(
- bar_archive ? ((barh_type*)disk_buffer)->name :
- ((tarh_type*)disk_buffer)->name,
- buffer, length, ci_stanno_certo, rView.right-rView.left);
-
- LSetCell(buffer, strlen(buffer), myCell, LHandle);
- files_on_floppy++;
- }
- last_header += (length+1023)/512;
- } /* end while */
-
- if(files_on_floppy==0){
- if(last_header>=sectors_on_floppy)
- printf(in_Italia?s1:s2);
- else
- printf(in_Italia?"Fine archivio\n":"End of archive\n");
-
- if(previousFormat==tar_GNU||previousFormat!=tar_AIX&&tar_version==tar_GNU||
- last_header<sectors_on_floppy){
- diskEject();
- break;
- }
- }
- theCell=LAddRow(1,theCell+1,LHandle); /* an empty cell, at the only purpose to
- be able to click on it and deselect all other items: I hate not to
- be able to return to that initial state ! */
- myCell.v=theCell;
- myCell.h=0;
- LSetCell(buffer, 0, myCell, LHandle);
- /*LDoDraw(true,LHandle); /* useful only if LNew had drawit = false */
-
- for(i=1;i<=3;i++){ /* riabilito i bottoni...*/
- short kind;
- Handle h;
- Rect r;
- GetDItem(ListDialog,i,&kind,&h,&r);
- HiliteControl(h, 0);
- }
- fase=ricevuto_comando;
-
- button_code=0;
- while(!button_code){
- extern long last_selection;
- if(files_on_floppy!=0)
- MainEvent();
- else
- button_code=sdExtract;
- /* if(last_selection==menuItemMess(fileID,fmSelect)){
- if(ListDialog != FrontWindow() ) SelectWindow(ListDialog);
- last_selection=0;
- }
- */
- if(button_code==sdFind){
- find_and_select();
- button_code=0;
- }
- else if(button_code==sdExtract){
- myCell.v=0;
- more_files=LGetSelect(true,&myCell,LHandle);
- if(myCell.v==theCell) /* Å la cella vuota in fondo
- --the empty cell */
- more_files=false;
- if(more_files)
- select_directory();
- else
- reply.good=true;
- if( !reply.good || !more_files&&(tar_version!=tar_AIX||previousFormat==tar_GNU))
- button_code=0;
- }
- accept_abort_command();
- }
-
- if(button_code==sdCancel)
- break;
- if(button_code==sdExtract){ /* se sono qui, ho giê selezionato il folder
- e ho giê trovato il primo item selezionato
- -- note that some operations handling that event have been
- performed inside the item-event loop above */
- for(i=1;i<=3;i++){ /* disabilito i bottoni...*/
- short kind;
- Handle h;
- Rect r;
- GetDItem(ListDialog,i,&kind,&h,&r);
- HiliteControl(h, 255);
- }
- /* avverti il filtro di non accettare click sulla lista:
- -- disable the handling of the list by the event filter
- */
- button_code = mouseClicksDisabled;
- listonly=0;
- fase=selected_reading;
- while(more_files){
- /* il get va fatto prima, sia per non chiedere destinazione se nessuno Å selezionato,
- sia per togliere la finestra prima di iniziare l'ultima estrazione
- -- find next file selected before extracting the current one: there are a couple of
- reasons to do that before rather than after
- */
- Point curr_cell;
- /*
- i=sizeof(buffer);
- LGetCell(buffer,&i,myCell,LHandle);
- buffer[i]=0;
- printf("%d:%s [%ld]\n",myCell.v,buffer,(long)(*sectorList)[myCell.v]);
- */
- sect_n = (*sectorList)[myCell.v];
-
- curr_cell = myCell;
- myCell.v++;
- more_files=LGetSelect(true,&myCell,LHandle);
- if(myCell.v==theCell) more_files=false;
- if(!more_files&& (tar_version!=tar_AIX || previousFormat==tar_GNU || last_header<sectors_on_floppy) ){
- /* tolgo il dialogo subito, per non rischiare di fare confusione se
- dovesse saltar fuori anche il dialogo di disk insert
- -- remove the dialog before starting extracting the last file,
- that reduces the confusion in case the disk insertion dialog appears...
- */
- LDispose(LHandle);
- LHandle=NULL;
- DisposDialog(ListDialog);
- remove_handlers(ListDialog);
- ListDialog=NULL;
- my_event_filter=NULL;
- }
-
- leggi_settore(sect_n,&disk_buffer);
- if(check_error()) raise_error();
-
- listonly=0;
- if(bar_archive)
- unbar();
- else
- untar();
- if(ListDialog){ /* deseleziono il nome del file appena salvato...
- -- deselect the file name */
- LSetSelect(false,curr_cell,LHandle);
- LAutoScroll(LHandle);
- }
- }
- if(tar_version==tar_AIX && last_header>=sectors_on_floppy){
- /* svuota la lista !
- -- delete the current items in the list... */
- LDelRow (0,0,LHandle);
- sectListSize=0;
- /* non c'Å bisogno di deallocare sectorList perchÄ tanto ci
- penserê la SetHandleSize */
- /* get next disk */
- last_header-=sectors_on_floppy;
- if(!disco_espulso){
- riprova:
- diskEject();
- if(aspetta_inserzione(in_Italia?
- "\pInserisci il prossimo disco tar":
- "\pInsert next tar disk")) break;
- if(di.is_not_initialized) goto riprova; /* cannot use a do-while,
- the above break must exit from another loop... */
- }
- else
- last_header=sect_n;
- previousFormat=tar_AIX;
- button_code=0;
- fase=reading_disk;
- }
- else{
- printf(in_Italia?FINITO:DONE);
- fine_lavoro();
- break;
- }
- }
- }
-
- HSetState(alertHandle,oldflags);
- if(ListDialog){
- LDispose(LHandle);
- DisposDialog(ListDialog);
- remove_handlers(ListDialog);
- ListDialog=NULL;
- }
- if(sectListSize) DisposHandle(sectorList);
- }
-
- my_event_filter=NULL;
- }
-
- static void prepara_nome(name_ptr, buffer, length, ci_stanno_certo, pixel_size)
- /* modify the file name so that it contains the file size and fits within the
- limited space of the list */
- char *name_ptr;
- register char *buffer;
- long length;
- int ci_stanno_certo,pixel_size;
- {
- int ln,ls,l;
- char len_buff[20];
-
- len_buff[0]=' ';
- len_buff[1]='(';
- if(length>9999){
- my_itoa((long)((length+512)>>10),&len_buff[2]);
- ls=strlen(len_buff);
- strcpy(&len_buff[ls]," Kbyt");
- ls += 5;
- }
- else{
- my_itoa((long)length,&len_buff[2]);
- ls=strlen(len_buff);
- strcpy(&len_buff[ls]," byt");
- ls += 4;
- }
-
- ln=strlen(name_ptr);
-
- mcopy(buffer,name_ptr,ln);
- mcopy(&buffer[ln],len_buff,ls+1);
-
- if(ln+ls > ci_stanno_certo){
- register int i;
- GrafPtr savePort;
-
- GetPort( &savePort );
- SetPort( ListDialog ); /* perchÄ Å dalla GrafPort che StringWidth deduce
- font e size da usare... */
- c2pstr(buffer);
- i=1;
- while(StringWidth(buffer)>pixel_size){
- while(i<ln && buffer[i]!='/') i++;
- if(i>=ln) break; /* non c'Å nessun path da tagliare, meglio lasciare
- cosô come Å */
- buffer[1]='╔';
- mcopy(&buffer[2],&buffer[i],ln+ls-i+2);
- buffer[0] -= i-2; ln -= i-2;
- i=3; /* per non ritrovare lo stesso'/' */
- }
- p2cstr(buffer);
- SetPort( savePort );
- }
- mcopy(&buffer[ln+ls],"es)",6);
- }
-
- pascal short my_search(char *,char *,int,int);
- static pascal short my_search(p1,p2,l1,l2)
- register char *p1,*p2;
- register int l1,l2;
- {
- int i=0;
- #define bufsize 80
- unsigned char buffer[bufsize];
- register unsigned char *p;
-
- if(!l1) return 1;
-
- /* i nomi sono passati attraverso prepara_nome, quindi devo cominciare col
- togliere il numero di bytes
- -- P2 is the search string, in lowercase. P1 is the string installed in the list,
- which was not converted to lowercase and was altered by prepara_nome so that it
- contains the byte count in parentheses: it's better to extract the meaningful
- part, translating to lowercase, and in order to use strncmp do that as a C string
- */
- while(l1>0 && p1[--l1]!='(')
- ;
- l1--; /* lo spazio... */
- p=&buffer[bufsize-1];
- *p='\0';
- while(l1>0 && p1[--l1] != '/'){
- if(p1[l1]>='A' && p1[l1]<='Z')
- *--p = p1[l1] + 'a'-'A';
- else
- *--p = p1[l1];
- }
-
- /*printf("!%s!\n",p); */
-
- while(*p){
- if(!strncmp(p,p2,(size_t)l2) ) return 0;
- if(at_start) return 1;
- p++;
- }
- return 1;
- }
-
- static void find_and_select()
-
- /* handle the find dialog and the find operation */
- {
- Str255 buffer;
- DialogPtr myDialog;
- short kind;
- Handle h;
- Rect r;
- short itemHit;
-
- {
- AlertTHndl alertHandle;
- register Rect *p;
- short vs,hs;
- GrafPtr savePort;
- SignedByte oldflags;
-
- alertHandle = (AlertTHndl)Get1Resource('DLOG',135);
- oldflags=HGetState(alertHandle);
- HNoPurge((Handle)alertHandle);
-
- /* center the dialog near the Find button from which it was generated */
-
- GetPort(&savePort);
- SetPort(ListDialog);
-
- GetDItem(ListDialog,sdFind,&kind,&h,&r);
-
- LocalToGlobal(&r); /* really, r.topLeft */
-
- p= &(**alertHandle).boundsRect;
- vs= p->bottom - p->top;
- hs= p->right - p->left;
-
- if( (p->top=r.top-80)<(kind=MBARHEIGHT+15))
- p->top=kind;
- else if(p->top > (kind=screenHeight-vs-15))
- p->top = kind;
-
- if( (p->left=r.left-50)<15)
- p->left=15;
- else if(p->left > (kind=screenWidth-hs-15))
- p->left = kind;
-
- p->bottom=p->top+vs;
- p->right=p->left+hs;
- SetPort(savePort);
-
- myDialog = GetNewDialog (135,NULL,(char*)-1);
- HSetState(alertHandle,oldflags);
- }
-
- if(myDialog!=NULL){
- if(in_Italia){
- static char* titoli[]={"\pTrova","\pNon trovare",
- "\pil testo Å all\'inizio del nome","\pSeleziona i nomi contenenti" };
- int i;
- for(i=fdFind;i<fdSText;i++){
- GetDItem(myDialog,i,&kind,&h,&r);
- SetCTitle(h,titoli[i-fdFind]);
- }
- GetDItem(myDialog,fdSText,&kind,&h,&r);
- SetIText(h,titoli[3]);
- }
- /* handle the dialog */
- do {
-
- ModalDialog(modal_filter,&itemHit);
- if(itemHit==fdCheck)
- SetCheckBox(myDialog,itemHit);
- }
- while (itemHit != fdFind && itemHit != fdCancel );
-
- GetDItem(myDialog,fdText,&kind,&h,&r);
- GetIText(h,buffer);
- GetDItem(myDialog,fdCheck,&kind,&h,&r);
- at_start = GetCtlValue(h);
-
- DisposDialog(myDialog);
-
- if(itemHit==fdFind){
- register int i;
- Point myCell;
-
- if(buffer[0]!=0){
- for(i=1;i<=buffer[0];i++)
- if(buffer[i]>='A'&&buffer[i]<='Z') buffer[i] += 'a'-'A';
- /* if(buffer[i]=='/') ???? */
- /* buffer[buffer[0]+1]='\0'; */
-
- myCell.v=myCell.h=0;
- while( LSearch(&buffer[1],buffer[0],my_search,&myCell,LHandle)){
- /*printf("%d,%d\n",myCell.v,myCell.h);*/
- LSetSelect(true,myCell,LHandle);
- myCell.v++;
- }
- LAutoScroll(LHandle);
- }
- /*printf("%d:%p\n",at_start,buffer);*/
- }
- }
- }
-
- static void list_updater(theEvent)
- EventRecord *theEvent;
- {
- short j;
- DialogPtr w=NULL;
- DialogSelect(theEvent,&w,&j);
- }
-
- static void list_activater(theEvent)
- EventRecord *theEvent;
- {
- if(theEvent->modifiers & activeFlag) SetPort( ListDialog );
- LActivate((theEvent->modifiers & activeFlag)!=0,LHandle);
- }
-
- static void select_list_filter(theEvent)
- register EventRecord *theEvent;
- {
- int i,j;
-
- switch(theEvent->what){
- /* no, non c'Å un bottone di default ! e devo lasciare attivi i comandi
- case keyDown:
- case autoKey:
- if((unsigned char)theEvent->message==CR || (unsigned char)theEvent->message==enter_key)
- button_code=1;
- theEvent->what=nullEvent;
- break;
- */
- case mouseDown:
- {
- WindowPtr whichWindow;
- int i;
-
- i=FindWindow( theEvent->where, &whichWindow );
- if(whichWindow==(WindowPtr)ListDialog){
- GrafPtr savePort;
-
- GetPort( &savePort );
- SetPort( ListDialog );
- switch(i){
- case inContent:
- if (whichWindow != FrontWindow() )
- SelectWindow(whichWindow);
- else{
- Point localPt = theEvent->where;
- ControlHandle theControl;
-
- GlobalToLocal(&localPt);
-
- if (localPt.h > cornice.right+5){
- #if 0
- if( (FindControl(localPt, whichWindow, &theControl)) != 0) {
- if(TrackControl(theControl, localPt, 0L)){
- short kind;
- Handle h;
- Rect r;
- short i=0;
- do
- GetDItem(ListDialog,++i,&kind,&h,&r);
- while(h!=theControl && i<=3);
- if(h==theControl)
- button_code=i;
- }
- }
- #endif
- if( IsDialogEvent(theEvent)){
- if(DialogSelect(theEvent,&ListDialog,&j))
- button_code=j;
- }
- }
- else{
- if(button_code!=mouseClicksDisabled || localPt.h > cornice.right-15){
- /*int doubleClick;*/
- /*doubleClick =LClick(localPt,theEvent->modifiers,LHandle); */
- /* should check for double clicks here */
- LClick(localPt,theEvent->modifiers,LHandle);
- }
- }
- }
- break;
- case inDrag:
- SetPort(savePort); /* MainEvent lo gestisce correttamente */
- return;
- }
- theEvent->what=nullEvent;
- SetPort(savePort);
- }
- }
- break;
- }
- }
-
-
-
- void my_alert()
- /* a centered alert, with an "OK" button */
- {
- AlertTHndl alertHandle;
- SignedByte oldflags;
-
- check_foreground();
- alertHandle = (AlertTHndl)Get1Resource('ALRT',ErrorAlert);
- oldflags=HGetState(alertHandle);
- HNoPurge((Handle)alertHandle);
- PositionDialog( &((**alertHandle).boundsRect));
- SetCursor(&arrow);
- Alert(ErrorAlert, modal_filter); /* we've tried to use NoteAlert &Co, but
- the icon has the same feature of the button outline, it disappears
- when a screen saver blanks the screen (even without our event filter):
- to avoid that, one must add an icon item to the DITL, and not to use
- NoteAlert at all */
- HSetState(alertHandle,oldflags);
- }
-
-
-
- short my_modal_dialog(dialog_ID,titoli_italiani,n_titoli)
- /* A centered modal dialog. It may display button titles in both
- English and Italian
- */
- char **titoli_italiani;
- {
- DialogPtr myDialog;
- short item;
- AlertTHndl alertHandle;
- short kind;
- Handle h;
- Rect r;
- SignedByte oldflags;
-
- check_foreground();
- SetCursor(&arrow);
-
- alertHandle = (AlertTHndl)Get1Resource('DLOG',dialog_ID);
- if (alertHandle) {
- oldflags=HGetState(alertHandle);
- HNoPurge((Handle)alertHandle);
- PositionDialog( &((**alertHandle).boundsRect));
- myDialog=GetNewDialog(dialog_ID,NULL,-1L);
- if(in_Italia && titoli_italiani){
- int fatti=0;
- for(item=1;fatti<n_titoli;item++){
- GetDItem(myDialog,item,&kind,&h,&r);
- if((kind&0x7F)==ctrlItem+btnCtrl){
- SetCTitle(h,*titoli_italiani++);
- fatti++;
- }
- }
- }
- ModalDialog(modal_filter,&item);
-
- HSetState(alertHandle,oldflags);
- DisposDialog(myDialog);
- return item;
- }
- }
-
-
- static void set_option_var(dialog,item,var)
- DialogPtr dialog;
- short item;
- Boolean *var;
- {
- short kind;
- Handle h;
- Rect r;
-
- GetDItem(dialog,item,&kind,&h,&r);
- *var = GetCtlValue(h);
- }
-
- static void get_option_var(dialog,item,var)
- DialogPtr dialog;
- short item;
- Boolean var;
- {
- short kind;
- Handle h;
- Rect r;
-
- GetDItem(dialog,item,&kind,&h,&r);
- SetCtlValue(h,var);
- }
-
- void SetCheckBox(dialog,item)
- DialogPtr dialog;
- short item;
- {
- short kind;
- Handle h;
- Rect r;
-
- GetDItem(dialog,item,&kind,&h,&r);
- SetCtlValue((ControlHandle)h,!GetCtlValue(h));
- }
-
- int dialogo_tipo_file()
- {
- int i,currentRadio;
- DialogPtr myDialog;
- short kind;
- Handle h;
- Rect r;
- short itemHit;
- AlertTHndl alertHandle;
- SignedByte oldflags;
-
- #define first_radio 3
-
- if (alertHandle = Get1Resource('DLOG',134)) {
- oldflags=HGetState(alertHandle);
- HNoPurge((Handle)alertHandle);
- PositionDialog( &((**alertHandle).boundsRect));
- }
- myDialog = GetNewDialog (134,NULL,(char*)-1);
-
- if(myDialog!=NULL){
-
- currentRadio= first_radio;
- SetRadioButton(myDialog,currentRadio,CONTROL_ON);
-
- do {
- ModalDialog(modal_filter,&itemHit);
- if(itemHit!=1){
- SetRadioButton(myDialog,currentRadio,CONTROL_OFF);
- SetRadioButton(myDialog,(currentRadio=itemHit),CONTROL_ON);
- }
- }
- while (itemHit != 1 );
-
- HSetState(alertHandle,oldflags);
- DisposDialog(myDialog);
- }
- return currentRadio-first_radio;
- }
-