| 1 |
/* |
| 2 |
Native File Dialog |
| 3 |
|
| 4 |
User API |
| 5 |
|
| 6 |
http://www.frogtoss.com/labs |
| 7 |
*/ |
| 8 |
|
| 9 |
|
| 10 |
#ifndef _NFD_H |
| 11 |
#define _NFD_H |
| 12 |
|
| 13 |
#include <stddef.h> |
| 14 |
#include <functional> |
| 15 |
#include <string> |
| 16 |
#include <vector> |
| 17 |
|
| 18 |
/* denotes UTF-8 char */ |
| 19 |
typedef char nfdchar_t; |
| 20 |
|
| 21 |
typedef std::function<void(const char*)> nfdselcallback_t; |
| 22 |
|
| 23 |
/* opaque data structure -- see NFD_PathSet_* */ |
| 24 |
typedef struct { |
| 25 |
nfdchar_t *buf; |
| 26 |
size_t *indices; /* byte offsets into buf */ |
| 27 |
size_t count; /* number of indices into buf */ |
| 28 |
}nfdpathset_t; |
| 29 |
|
| 30 |
typedef enum { |
| 31 |
NFD_ERROR, /* programmatic error */ |
| 32 |
NFD_OKAY, /* user pressed okay, or successful return */ |
| 33 |
NFD_CANCEL /* user pressed cancel */ |
| 34 |
}nfdresult_t; |
| 35 |
|
| 36 |
|
| 37 |
/* nfd_<targetplatform>.c */ |
| 38 |
|
| 39 |
/* single file open dialog */ |
| 40 |
nfdresult_t NFD_OpenDialog( const std::vector<std::string>& filterList, |
| 41 |
const nfdchar_t *defaultPath, |
| 42 |
nfdchar_t **outPath, |
| 43 |
nfdselcallback_t selCallback = NULL, |
| 44 |
const nfdchar_t *defaultFileName = NULL ); |
| 45 |
|
| 46 |
/* multiple file open dialog */ |
| 47 |
nfdresult_t NFD_OpenDialogMultiple( const std::vector<std::string>& filterList, |
| 48 |
const nfdchar_t *defaultPath, |
| 49 |
nfdpathset_t *outPaths, |
| 50 |
nfdselcallback_t selCallback = NULL, |
| 51 |
const nfdchar_t *defaultFileName = NULL ); |
| 52 |
|
| 53 |
/* save dialog */ |
| 54 |
nfdresult_t NFD_SaveDialog( const std::vector<std::string>& filterList, |
| 55 |
const nfdchar_t *defaultPath, |
| 56 |
nfdchar_t **outPath, |
| 57 |
nfdselcallback_t selCallback = NULL, |
| 58 |
const nfdchar_t *defaultFileName = NULL ); |
| 59 |
|
| 60 |
|
| 61 |
/* select folder dialog */ |
| 62 |
nfdresult_t NFD_PickFolder( const nfdchar_t *defaultPath, |
| 63 |
nfdchar_t **outPath); |
| 64 |
|
| 65 |
/* nfd_common.c */ |
| 66 |
|
| 67 |
/* get last error -- set when nfdresult_t returns NFD_ERROR */ |
| 68 |
const char *NFD_GetError( void ); |
| 69 |
/* get the number of entries stored in pathSet */ |
| 70 |
size_t NFD_PathSet_GetCount( const nfdpathset_t *pathSet ); |
| 71 |
/* Get the UTF-8 path at offset index */ |
| 72 |
nfdchar_t *NFD_PathSet_GetPath( const nfdpathset_t *pathSet, size_t index ); |
| 73 |
/* Free the pathSet */ |
| 74 |
void NFD_PathSet_Free( nfdpathset_t *pathSet ); |
| 75 |
|
| 76 |
#endif |