Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
FDPUtilities.h
/* |
File: FDPUtilities.c |
Description: utilities used in FinderDragPro.c. Routines in this file are used in the |
FinderDragPro.c file; however, since they are not directly related |
to the example, they have been moved here to simplify the main file. |
Author: John Montbriand |
Copyright: Copyright: © 1999 by Apple Computer, Inc. |
all rights reserved. |
Disclaimer: You may incorporate this sample code into your applications without |
restriction, though the sample code has been provided "AS IS" and the |
responsibility for its operation is 100% yours. However, what you are |
not permitted to do is to redistribute the source as "DSC Sample Code" |
after having made changes. If you're going to re-distribute the source, |
we require that you make it clear in the source that the code was |
descended from Apple Sample Code, but that you've made changes. |
Change History (most recent first): |
9/9/99 created by John Montbriand |
*/ |
#ifndef __FDPUTILITIES__ |
#define __FDPUTILITIES__ |
#include <MacTypes.h> |
#include <Files.h> |
#include <Aliases.h> |
#include <Drag.h> |
#include <Icons.h> |
#include <QDOffscreen.h> |
#include <Script.h> |
/* ValidFSSpec verifies that *spec refers is formatted correctly, and it |
verifies that it refers to an existing file in an existing directory on |
and existing volume. If *spec is valid, the function returns noErr, |
otherwise an error is returned. */ |
OSErr ValidFSSpec(FSSpec *spec); |
/* ResolveAliasQuietly resolves an alias using a fast search with no user interaction. Our main loop |
periodically resolves gFileAlias comparing the result to gTargetFile to keep the display up to date. |
As a result, we would like the resolve alias call to be as quick as possible AND since the application |
may be in the background when it is called, we don't want any user interaction. */ |
OSErr ResolveAliasQuietly(ConstFSSpecPtr fromFile, AliasHandle alias, FSSpec *target, Boolean *wasChanged); |
/* MakeHFSFlavorFromAlias converts an alias handle into a HFSFlavor |
structure filling in the fields with their correct values. */ |
OSErr MakeHFSFlavorFromAlias(AliasHandle theAlias, HFSFlavor *theFlavor); |
/* IconsToMaskedPixMap converts either an IconServices icon reference or a IconUtilities icon suite into a |
(GWorldPtr, RgnHandle) pair appropriate for dragging as a transparent icon image. if iconReference |
then calls to IconServices are made, if iconSuite is not null, then calls to icon services are made. |
The resulting graphics world and region handle are returned in *imageGWorld and *maskRgn. */ |
OSErr IconsToMaskedPixMap(const Rect *iconRect, Handle iconSuite, IconRef iconReference, |
GWorldPtr *imageGWorld, RgnHandle *maskRgn); |
/* GrayOutBox grays out an area of the screen in the current grafport. |
*theBox is in local coordinates in the current grafport. This routine |
is for direct screen drawing only. */ |
void GrayOutBox(Rect *theBox); |
/* ShowDragHiliteBox is called to hilite the drop box area in the |
main window. Here, we draw a 3 pixel wide border around *boxBounds. */ |
OSErr ShowDragHiliteBox(DragReference theDragRef, Rect *boxBounds); |
/* CopyFileCmd starts a thread manager background task to copy a file. parameters specify |
the files to copy, and callbacks made to the caller during the copy operation. It is not |
re-entrant. */ |
enum { |
/* codes passed in the message parameter to the callback routine passed |
to the CopyFileCmd routine. */ |
kCopyStart, /* called at the beginning of the copy operation */ |
kCopyRun, /* called during the copy operation. */ |
kCopyEnd,/* called at the end of the copy operation (including when it aborts or on error) */ |
/* error code indicating returned if an attempt is made to copy a directory */ |
kCannotCopyDirError = 2335, |
kCopyNotRentrantError = 2336, /* only one copy at a time */ |
kCopyBufferSize = (16*1024) /* size of the io buffer for file copies */ |
/* we use a smaller buffer so the probability of the progress box |
showing up is improved. */ |
}; |
/* called back periodically durring the copy operation. This routine provides |
opportunity for the caller to display feedback for the copy operation. theFile |
is the source file being copied, message will be one of the codes defined above, |
and percentComplete indicates the percentage of the operation that has been completed. */ |
typedef void (*CopyCallback)(FSSpec *theFile, short message, long percentCompleted); |
/* called back back if an error occurs during the copy operation. |
theFile specifies the source file name, errorCode specifies the error causing |
the abort. if AbortCopyOperation is called, errorCode will be userCanceledErr. */ |
typedef void (*CopyErrorHandler)(FSSpec *theFile, short errorCode); |
/* CopyFileCmd starts a copy command copying the source file to the target file. This routine |
assumes that the target file has been created. If the copy fails, the target file |
will be deleted. the callback and the errorhandler are called as appropriate during the operation. */ |
OSErr CopyFileCmd(FSSpec *theSource, FSSpec *theTarget, CopyCallback callback, CopyErrorHandler errorhandler); |
/* AbortCopyOperation aborts the copy operation. All structures allocated are disposed, |
files opened are closed, and any files created are deleted. */ |
void AbortCopyOperation(void); |
/* CopyFileInProgress returns true while a copy operation is in progress */ |
Boolean CopyFileInProgress(void); |
#endif |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-01-14