tinyfiledialogs.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /*_________
  2. / \ tinyfiledialogs.h v2.9.3 [July 12, 2017] zlib licence
  3. |tiny file| Unique header file created [November 9, 2014]
  4. | dialogs | Copyright (c) 2014 - 2017 Guillaume Vareille http://ysengrin.com
  5. \____ ___/ http://tinyfiledialogs.sourceforge.net
  6. \|
  7. git://git.code.sf.net/p/tinyfiledialogs/code
  8. ______________________________________________
  9. | |
  10. | email: [email protected] |
  11. |______________________________________________|
  12. A big thank you to Don Heyse http://ldglite.sf.net for
  13. his code contributions, bug corrections & thorough testing!
  14. git://git.code.sf.net/p/tinyfiledialogs/code
  15. Please
  16. 1) let me know
  17. - if you are including tiny file dialogs,
  18. I'll be happy to add your link to the list of projects using it.
  19. - If you are using it on different hardware / OS / compiler.
  20. 2) leave a review on Sourceforge. Thanks.
  21. tiny file dialogs (cross-platform C C++)
  22. InputBox PasswordBox MessageBox ColorPicker
  23. OpenFileDialog SaveFileDialog SelectFolderDialog
  24. Native dialog library for WINDOWS MAC OSX GTK+ QT CONSOLE & more
  25. SSH supported via automatic switch to console mode or X11 forwarding
  26. One C file (add it to your C or C++ project) with 6 functions:
  27. - message & question
  28. - input & password
  29. - save file
  30. - open file(s)
  31. - select folder
  32. - color picker
  33. Complements OpenGL GLFW GLUT GLUI VTK SFML TGUI SDL Ogre Unity3d ION OpenCV
  34. CEGUI MathGL GLM CPW GLOW IMGUI MyGUI GLT NGL STB & GUI less programs
  35. NO INIT
  36. NO MAIN LOOP
  37. NO LINKING
  38. NO INCLUDE
  39. The dialogs can be forced into console mode
  40. Windows (XP to 10) ASCII MBCS UTF-8 UTF-16
  41. - native code & vbs create the graphic dialogs
  42. - enhanced console mode can use dialog.exe from
  43. http://andrear.altervista.org/home/cdialog.php
  44. - basic console input
  45. Unix (command line calls) ASCII UTF-8
  46. - applescript
  47. - zenity / matedialog / qarma (zenity for qt)
  48. - kdialog
  49. - Xdialog
  50. - python2 tkinter
  51. - dialog (opens a console if needed)
  52. - basic console input
  53. The same executable can run across desktops & distributions
  54. tested with C & C++ compilers
  55. on VisualStudio MinGW Mac Linux Bsd Solaris Minix Raspbian
  56. using Gnome Kde Enlightenment Mate Cinnamon Unity
  57. Lxde Lxqt Xfce WindowMaker IceWm Cde Jds OpenBox Awesome Jwm
  58. bindings for LUA and C# dll
  59. included in LWJGL(java), rust, Allegrobasic
  60. - License -
  61. This software is provided 'as-is', without any express or implied
  62. warranty. In no event will the authors be held liable for any damages
  63. arising from the use of this software.
  64. Permission is granted to anyone to use this software for any purpose,
  65. including commercial applications, and to alter it and redistribute it
  66. freely, subject to the following restrictions:
  67. 1. The origin of this software must not be misrepresented; you must not
  68. claim that you wrote the original software. If you use this software
  69. in a product, an acknowledgment in the product documentation would be
  70. appreciated but is not required.
  71. 2. Altered source versions must be plainly marked as such, and must not be
  72. misrepresented as being the original software.
  73. 3. This notice may not be removed or altered from any source distribution.
  74. */
  75. #ifndef TINYFILEDIALOGS_H
  76. #define TINYFILEDIALOGS_H
  77. /* #define TINYFD_NOLIB */
  78. /* On windows, define TINYFD_NOLIB here
  79. if you don't want to include the code creating the graphic dialogs.
  80. Then you won't need to link against Comdlg32.lib and Ole32.lib */
  81. /* if tinydialogs.c is compiled with a C++ compiler rather than with a C compiler
  82. (ie. you change the extension from .c to .cpp), you need to comment out:
  83. extern "C" {
  84. and the corresponding closing bracket near the end of this file:
  85. }
  86. */
  87. #ifdef __cplusplus
  88. extern "C" {
  89. #endif
  90. extern char tinyfd_version[8]; /* contains tinyfd current version number */
  91. #ifdef _WIN32
  92. /* for UTF-16 use the functions at the end of this files */
  93. extern int tinyfd_winUtf8; /* 0 (default) or 1 */
  94. /* on windows string char can be 0:MBSC or 1:UTF-8
  95. unless your code is really prepared for UTF-8 on windows, leave this on MBSC.
  96. Or you can use the UTF-16 (wchar) prototypes at the end of ths file.*/
  97. #endif
  98. extern int tinyfd_forceConsole ; /* 0 (default) or 1 */
  99. /* for unix & windows: 0 (graphic mode) or 1 (console mode).
  100. 0: try to use a graphic solution, if it fails then it uses console mode.
  101. 1: forces all dialogs into console mode even when an X server is present,
  102. if the package dialog (and a console is present) or dialog.exe is installed.
  103. on windows it only make sense for console applications */
  104. extern char tinyfd_response[1024];
  105. /* if you pass "tinyfd_query" as aTitle,
  106. the functions will not display the dialogs
  107. but will return 0 for console mode, 1 for graphic mode.
  108. tinyfd_response is then filled with the retain solution.
  109. possible values for tinyfd_response are (all lowercase)
  110. for the graphic mode:
  111. windows applescript zenity zenity3 matedialog qarma kdialog
  112. xdialog tkinter gdialog gxmessage xmessage
  113. for the console mode:
  114. dialog whiptail basicinput */
  115. int tinyfd_messageBox (
  116. char const * const aTitle , /* "" */
  117. char const * const aMessage , /* "" may contain \n \t */
  118. char const * const aDialogType , /* "ok" "okcancel" "yesno" "yesnocancel" */
  119. char const * const aIconType , /* "info" "warning" "error" "question" */
  120. int const aDefaultButton) ;
  121. /* 0 for cancel/no , 1 for ok/yes , 2 for no in yesnocancel */
  122. char const * tinyfd_inputBox (
  123. char const * const aTitle , /* "" */
  124. char const * const aMessage , /* "" may NOT contain \n \t on windows */
  125. char const * const aDefaultInput) ; /* "" , if NULL it's a passwordBox */
  126. /* returns NULL on cancel */
  127. char const * tinyfd_saveFileDialog (
  128. char const * const aTitle , /* "" */
  129. char const * const aDefaultPathAndFile , /* "" */
  130. int const aNumOfFilterPatterns , /* 0 */
  131. char const * const * const aFilterPatterns , /* NULL | {"*.jpg","*.png"} */
  132. char const * const aSingleFilterDescription) ; /* NULL | "text files" */
  133. /* returns NULL on cancel */
  134. char const * tinyfd_openFileDialog (
  135. char const * const aTitle , /* "" */
  136. char const * const aDefaultPathAndFile , /* "" */
  137. int const aNumOfFilterPatterns , /* 0 */
  138. char const * const * const aFilterPatterns , /* NULL {"*.jpg","*.png"} */
  139. char const * const aSingleFilterDescription , /* NULL | "image files" */
  140. int const aAllowMultipleSelects) ; /* 0 or 1 */
  141. /* in case of multiple files, the separator is | */
  142. /* returns NULL on cancel */
  143. char const * tinyfd_selectFolderDialog (
  144. char const * const aTitle , /* "" */
  145. char const * const aDefaultPath) ; /* "" */
  146. /* returns NULL on cancel */
  147. char const * tinyfd_colorChooser(
  148. char const * const aTitle , /* "" */
  149. char const * const aDefaultHexRGB , /* NULL or "#FF0000" */
  150. unsigned char const aDefaultRGB[3] , /* { 0 , 255 , 255 } */
  151. unsigned char aoResultRGB[3]) ; /* { 0 , 0 , 0 } */
  152. /* returns the hexcolor as a string "#FF0000" */
  153. /* aoResultRGB also contains the result */
  154. /* aDefaultRGB is used only if aDefaultHexRGB is NULL */
  155. /* aDefaultRGB and aoResultRGB can be the same array */
  156. /* returns NULL on cancel */
  157. /************ NOT CROSS PLATFORM SECTION STARTS HERE ************************/
  158. #ifdef _WIN32
  159. #ifndef TINYFD_NOLIB
  160. /* windows only - utf-16 version */
  161. int tinyfd_messageBoxW(
  162. wchar_t const * const aTitle ,
  163. wchar_t const * const aMessage, /* "" may contain \n \t */
  164. wchar_t const * const aDialogType, /* "ok" "okcancel" "yesno" */
  165. wchar_t const * const aIconType, /* "info" "warning" "error" "question" */
  166. int const aDefaultButton); /* 0 for cancel/no , 1 for ok/yes */
  167. /* returns 0 for cancel/no , 1 for ok/yes */
  168. /* windows only - utf-16 version */
  169. wchar_t const * tinyfd_saveFileDialogW(
  170. wchar_t const * const aTitle, /* NULL or "" */
  171. wchar_t const * const aDefaultPathAndFile, /* NULL or "" */
  172. int const aNumOfFilterPatterns, /* 0 */
  173. wchar_t const * const * const aFilterPatterns, /* NULL or {"*.jpg","*.png"} */
  174. wchar_t const * const aSingleFilterDescription); /* NULL or "image files" */
  175. /* returns NULL on cancel */
  176. /* windows only - utf-16 version */
  177. wchar_t const * tinyfd_openFileDialogW(
  178. wchar_t const * const aTitle, /* "" */
  179. wchar_t const * const aDefaultPathAndFile, /* "" */
  180. int const aNumOfFilterPatterns , /* 0 */
  181. wchar_t const * const * const aFilterPatterns, /* NULL {"*.jpg","*.png"} */
  182. wchar_t const * const aSingleFilterDescription, /* NULL | "image files" */
  183. int const aAllowMultipleSelects) ; /* 0 or 1 */
  184. /* in case of multiple files, the separator is | */
  185. /* returns NULL on cancel */
  186. /* windows only - utf-16 version */
  187. wchar_t const * tinyfd_selectFolderDialogW(
  188. wchar_t const * const aTitle, /* "" */
  189. wchar_t const * const aDefaultPath); /* "" */
  190. /* returns NULL on cancel */
  191. /* windows only - utf-16 version */
  192. wchar_t const * tinyfd_colorChooserW(
  193. wchar_t const * const aTitle, /* "" */
  194. wchar_t const * const aDefaultHexRGB, /* NULL or "#FF0000" */
  195. unsigned char const aDefaultRGB[3] , /* { 0 , 255 , 255 } */
  196. unsigned char aoResultRGB[3]) ; /* { 0 , 0 , 0 } */
  197. /* returns the hexcolor as a string "#FF0000" */
  198. /* aoResultRGB also contains the result */
  199. /* aDefaultRGB is used only if aDefaultHexRGB is NULL */
  200. /* aDefaultRGB and aoResultRGB can be the same array */
  201. /* returns NULL on cancel */
  202. #endif /*TINYFD_NOLIB*/
  203. #else /*_WIN32*/
  204. /* unix zenity only */
  205. char const * tinyfd_arrayDialog(
  206. char const * const aTitle , /* "" */
  207. int const aNumOfColumns , /* 2 */
  208. char const * const * const aColumns, /* {"Column 1","Column 2"} */
  209. int const aNumOfRows, /* 2*/
  210. char const * const * const aCells);
  211. /* {"Row1 Col1","Row1 Col2","Row2 Col1","Row2 Col2"} */
  212. #endif /*_WIN32 */
  213. #ifdef __cplusplus
  214. }
  215. #endif
  216. #endif /* TINYFILEDIALOGS_H */
  217. /*
  218. - This is not for android nor ios.
  219. - The code is pure C, perfectly compatible with C++.
  220. - the windows only wchar_t (utf-16) prototypes are in the header file
  221. - windows is fully supported from XP to 10 (maybe even older versions)
  222. - C# & LUA via dll, see example files
  223. - OSX supported from 10.4 to 10.11 (maybe even older versions)
  224. - Avoid using " and ' in titles and messages.
  225. - There's one file filter only, it may contain several patterns.
  226. - If no filter description is provided,
  227. the list of patterns will become the description.
  228. - char const * filterPatterns[3] = { "*.obj" , "*.stl" , "*.dxf" } ;
  229. - On windows link against Comdlg32.lib and Ole32.lib
  230. This linking is not compulsary for console mode (see above).
  231. - On unix: it tries command line calls, so no such need.
  232. - On unix you need applescript, zenity, matedialog, qarma, kdialog, Xdialog,
  233. python2/tkinter or dialog (will open a terminal if running without console).
  234. - One of those is already included on most (if not all) desktops.
  235. - In the absence of those it will use gdialog, gxmessage or whiptail
  236. with a textinputbox.
  237. - If nothing is found, it switches to basic console input,
  238. it opens a console if needed (requires xterm + bash).
  239. - Use windows separators on windows and unix separators on unix.
  240. - String memory is preallocated statically for all the returned values.
  241. - File and path names are tested before return, they are valid.
  242. - If you pass only a path instead of path + filename,
  243. make sure it ends with a separator.
  244. - tinyfd_forceConsole=1; at run time, forces dialogs into console mode.
  245. - On windows, console mode only make sense for console applications.
  246. - Mutiple selects are not allowed in console mode.
  247. - The package dialog must be installed to run in enhanced console mode.
  248. It is already installed on most unix systems.
  249. - On osx, the package dialog can be installed via http://macports.org
  250. - On windows, for enhanced console mode,
  251. dialog.exe should be copied somewhere on your executable path.
  252. It can be found at the bottom of the following page:
  253. http://andrear.altervista.org/home/cdialog.php
  254. - If dialog is missing, it will switch to basic console input.
  255. - You can query the type of dialog that will be use.
  256. - MinGW needs gcc >= v4.9 otherwise some headers are incomplete.
  257. - The Hello World (and a bit more) is on the sourceforge site:
  258. */