nfd.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // This software is provided 'as-is', without any express or implied
  2. // warranty. In no event will the authors be held liable for any damages
  3. // arising from the use of this software.
  4. // Permission is granted to anyone to use this software for any purpose,
  5. // including commercial applications, and to alter it and redistribute it
  6. // freely, subject to the following restrictions:
  7. // 1. The origin of this software must not be misrepresented; you must not
  8. // claim that you wrote the original software. If you use this software
  9. // in a product, an acknowledgment in the product documentation would be
  10. // appreciated but is not required.
  11. // 2. Altered source versions must be plainly marked as such, and must not be
  12. // misrepresented as being the original software.
  13. // 3. This notice may not be removed or altered from any source distribution.
  14. // https://github.com/mlabbe/nativefiledialog
  15. #pragma once
  16. #include <stddef.h>
  17. #include <stdint.h>
  18. typedef char nfdchar_t;
  19. typedef struct {
  20. nfdchar_t *buf;
  21. size_t *indices; /* byte offsets into buf */
  22. size_t count; /* number of indices into buf */
  23. }nfdpathset_t;
  24. typedef enum {
  25. NFD_ERROR, /* programmatic error */
  26. NFD_OKAY, /* user pressed okay, or successful return */
  27. NFD_CANCEL /* user pressed cancel */
  28. }nfdresult_t;
  29. nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList,
  30. const nfdchar_t *defaultPath,
  31. nfdchar_t **outPath );
  32. nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList,
  33. const nfdchar_t *defaultPath,
  34. nfdpathset_t *outPaths );
  35. nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList,
  36. const nfdchar_t *defaultPath,
  37. nfdchar_t **outPath );
  38. nfdresult_t NFD_PickFolder( const nfdchar_t *defaultPath,
  39. nfdchar_t **outPath);
  40. const char *NFD_GetError( void );
  41. size_t NFD_PathSet_GetCount( const nfdpathset_t *pathSet );
  42. nfdchar_t *NFD_PathSet_GetPath( const nfdpathset_t *pathSet, size_t index );
  43. void NFD_PathSet_Free( nfdpathset_t *pathSet );
  44. #define NFD_MAX_STRLEN 256
  45. #define _NFD_UNUSED(x) ((void)x)
  46. #define NFD_UTF8_BOM "\xEF\xBB\xBF"
  47. void *NFDi_Malloc( size_t bytes );
  48. void NFDi_Free( void *ptr );
  49. void NFDi_SetError( const char *msg );
  50. int NFDi_SafeStrncpy( char *dst, const char *src, size_t maxCopy );
  51. int32_t NFDi_UTF8_Strlen( const nfdchar_t *str );
  52. int NFDi_IsFilterSegmentChar( char ch );