home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
online
/
source
/
c
/
compilers
/
Tickle-4.0.sit.hqx
/
Tickle-4.0
/
src
/
SFGetFile.c
< prev
next >
Wrap
Text File
|
1993-11-18
|
6KB
|
264 lines
/*
** This source code was written by Tim Endres
** Email: time@ice.com.
** USMail: 8840 Main Street, Whitmore Lake, MI 48189
**
** Some portions of this application utilize sources
** that are copyrighted by ICE Engineering, Inc., and
** ICE Engineering retains all rights to those sources.
**
** Neither ICE Engineering, Inc., nor Tim Endres,
** warrants this source code for any reason, and neither
** party assumes any responsbility for the use of these
** sources, libraries, or applications. The user of these
** sources and binaries assumes all responsbilities for
** any resulting consequences.
*/
#include "tickle.h"
#include "tge.h"
#define SFSaveDisk (* (short *) 0x0214)
#define CurDirStore (* (long *) 0x0398)
#pragma segment Main
#define MY_GETFILE_DIALOG 777
#define getInit -1 /* Initialize */
#define getPromptItem 11
static char get_prompt[256];
pascal Boolean
SFFilter(myDialog, myEvent, myItem)
DialogPtr myDialog;
EventRecord *myEvent;
short *myItem;
{
int result = FALSE, myascii;
char title[256];
Handle myhandle;
short type;
Rect myrect;
/* Do the standard filtering... */
if (myEvent->what == keyDown)
{
myascii = myEvent->message % 256;
if ((myEvent->modifiers & 0x0100) != 0)
{
if (myascii == 'x' || myascii == 'X')
{ DlgCut(myDialog); ZeroScrap(); TEToScrap(); result = TRUE; }
else if (myascii == 'c' || myascii == 'C')
{ DlgCopy(myDialog); ZeroScrap(); TEToScrap(); result = TRUE; }
else if (myascii == 'v' || myascii == 'V')
{ DlgPaste(myDialog); result = TRUE; }
}
else if (myascii == '\015' || myascii == '\003')
{
*myItem = ((DialogRecord *) myDialog)->aDefItem;
result = TRUE;
}
}
SetPort(myDialog);
return result;
}
pascal short SFPromptHook(item, dialog)
short item;
DialogPtr dialog;
{
switch (item)
{
case getInit:
if (get_prompt[0] != '\0')
MySetText(dialog, getPromptItem, get_prompt);
get_prompt[0] = '\0';
break;
}
return item;
}
SFGetDefault(dirid, vrefnum)
long *dirid;
short *vrefnum;
{
*vrefnum = SFSaveDisk * -1;
*dirid = CurDirStore;
}
SFSetDefault(dirid, vrefnum)
long dirid;
short vrefnum;
{
SFSaveDisk = vrefnum * -1;
CurDirStore = dirid;
}
SFWDDefault(wdref)
int wdref;
{
SFSaveDisk = -1 * WDVolRef(wdref);
CurDirStore = WDDirID(wdref);
}
static long _save_sf_dirid = 0;
static short _save_sf_vrefnum = -1;
SFSaveDefault()
{
SFGetDefault(&_save_sf_dirid, &_save_sf_vrefnum);
}
SFRestoreDefault()
{
SFSetDefault(_save_sf_dirid, _save_sf_vrefnum);
}
MyGetFile(sfpoint, sfprompt, sffilter, sfnumtypes, sftypes, sfhook, sfreply)
Point sfpoint;
char *sfprompt;
FileFilterProcPtr sffilter;
int sfnumtypes;
SFTypeList sftypes;
char *sfhook;
SFReply *sfreply;
{
Point mypoint;
Handle dlog;
short saveref;
Rect myrect, screenRect;
WindowPtr myWindow;
#pragma unused(sfhook)
myWindow = FrontWindow();
if (myWindow != NULL && WPeek->windowKind == tgeWKind)
tge_activate(myWindow, 0);
saveref = CurResFile();
UseResFile(app_refnum);
strncpy(get_prompt, &sfprompt[1], sfprompt[0]);
get_prompt[sfprompt[0]] = '\0';
sfreply->version = 0;
mypoint = sfpoint;
dlog = GetResource((ResType)'DLOG', (short)MY_GETFILE_DIALOG);
if (dlog != NULL)
LoadResource(dlog);
if (dlog != NULL && *dlog != NULL)
{
screenRect = qd.screenBits.bounds;
myrect = *( *( (Rect **) dlog ) );
OffsetRect(&myrect, -myrect.left, -myrect.top);
OffsetRect(&myrect,
(screenRect.right - myrect.right) >> 1,
((screenRect.bottom - myrect.bottom) >> 2) + 10);
mypoint.h = myrect.left;
mypoint.v = myrect.top;
SFPGetFile( mypoint, sfprompt, sffilter, (short)sfnumtypes,
sftypes, (DlgHookProcPtr)SFPromptHook, sfreply,
(short)MY_GETFILE_DIALOG, (ModalFilterProcPtr)SFFilter );
if (sfreply->good)
if (sfreply->fName[0] != '\0')
if (sfreply->fName[1] == '.')
{
message_note(
"WARNING: File names may not begin with periods.\015\
You must rename this file if you save it!"
);
}
}
else
{
message_alert("ERROR #%d Could not load file dialog #%d.",
ResError(), MY_GETFILE_DIALOG);
}
UseResFile(saveref);
}
MyPutFile(sfpoint, sfprompt, sforiginal, sfhook, sfreply)
Point sfpoint;
char *sfprompt;
char *sforiginal;
DlgHookProcPtr sfhook;
SFReply *sfreply;
{
Handle dlog;
Rect screenRect;
short saveref, dialogID;
Rect myrect;
Point mypoint;
WindowPtr myWindow;
myWindow = FrontWindow();
if (WPeek->windowKind == tgeWKind)
tge_activate(myWindow, 0);
saveref = CurResFile();
UseResFile(app_refnum);
sfreply->version = 0;
mypoint = sfpoint;
dialogID = gHasStandardFile ? sfPutDialogID : putDlgID;
dlog = GetResource( (ResType)'DLOG', dialogID );
if (dlog != NULL)
LoadResource(dlog);
if ( dlog != NULL && *dlog != NULL )
{
if (dlog != NULL && *dlog != NULL)
{
screenRect = qd.screenBits.bounds;
myrect = *( *( (Rect **) dlog ) );
OffsetRect(&myrect, -myrect.left, -myrect.top);
OffsetRect(&myrect,
(screenRect.right - myrect.right) >> 1,
((screenRect.bottom - myrect.bottom) >> 2) + 10);
mypoint.h = myrect.left;
mypoint.v = myrect.top;
}
for ( ; ; )
{
if (gHasStandardFile)
{
/* Should use the new StandardFile! */
SFPutFile(mypoint, sfprompt, sforiginal, NULL, sfreply);
}
else
{
SFPPutFile(mypoint, sfprompt, sforiginal, sfhook, sfreply,
(short)dialogID, (ModalFilterProcPtr)SFFilter);
}
if (sfreply->good)
if (sfreply->fName[0] != '\0')
if (sfreply->fName[1] == '.')
{
message_note("File names may not begin with periods.");
continue;
}
break;
}
}
else
{
message_alert("ERROR #%d Could not load file dialog #%d.",
ResError(), dialogID);
}
UseResFile(saveref);
}