File Request 2Availability LightWave 6.0 The file request 2 global returns a function that prompts the user for a file selection. The request displays the file dialog currently installed in LightWave. This may be the default system dialog or a custom file dialog plug-in. See the File Request global for an alternative interface to the file dialog mechanism. The primary advantage of this file request global over the original File Request is a smarter and more flexible interface to the file dialog. The dialog is initialized by filling out a structure, rather than through a limited number of function arguments. Note that in contrast to the original, this global allows plug-ins to call the file request activation function directly. Plug-ins calling this global act as the host side of the FileRequester plug-in class. Global Call LWFileActivateFunc *filereq; filereq = global( LWFILEACTIVATEFUNC_GLOBAL, GFUSE_TRANSIENT ); The global function returns a pointer to an LWFileActivateFunc. typedef int LWFileActivateFunc (int version, LWFileReqLocal *); The return value of this function can be any of the values defined for the return values of activation functions. Any value other than AFUNC_OK must be handled as an error. The version is passed as the version argument to the file request plug-in's activation function. This should be set to the value defined by the LWFILEREQ_VERSION symbol in lwdialog.h. File request plug-ins with a different activation version will return AFUNC_BADVERSION. The second argument to this function is a pointer to a structure that is passed as the local argument to the file request plug-in's activation function. The Local Structure The file request function passes an LWFileReqLocal as the local argument to the activation function of the file request plug-in. typedef struct st_LWFileReqLocal { int reqType; int result; const char *title; const char *fileType; char *path; char *baseName; char *fullName; int bufLen; int (*pickName) (void); } LWFileReqLocal;
Example This code fragment asks the user for the name of an image file to save. #include <lwserver.h> #include <lwhost.h> #define MAXFILESZ 260 static char node[ MAXFILESZ ] = "", path[ MAXFILESZ ] = "", name[ MAXFILESZ ] = ""; static LWFileReqLocal frloc; LWFileActivateFunc *filereq; int result; filereq = global( LWFILEACTIVATEFUNC_GLOBAL, GFUSE_TRANSIENT ); if ( !filereq ) goto NoFileReq; /* global calls can fail */ frloc.reqType = FREQ_SAVE; frloc.title = "Save Image"; frloc.bufLen = MAXFILESZ; frloc.pickName = NULL; frloc.fileType = "Images"; frloc.path = path; frloc.baseName = node; frloc.fullName = name; strcpy( frloc.path, "MyImages" ); /* a relative path */ strcpy( frloc.baseName, "foo" ); /* a default name */ result = filereq( LWFILEREQ_VERSION, &frloc ); if ( result == AFUNC_OK && frloc.result > 0 ) { save_image( myimage, frloc.fullName ); ... |