Added TinyFileDialogs, removed file explorer and input box

This commit is contained in:
Nefrace 2024-03-31 00:10:57 +03:00
parent 55f30654f4
commit 13c9f0a239
15 changed files with 9545 additions and 113 deletions

3
.gitignore vendored
View File

@ -1,2 +1,5 @@
repico repico
ols.json ols.json
*.a
*.o
src.bin

5
build.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
C=odin
$C build src -out:repico

5
build_tfd.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
cd tinyfiledialogs
gcc -c -o tfd.o tinyfiledialogs.c
ar rcs ../tfd.a tfd.o

View File

@ -1,6 +1,5 @@
package main package main
import rl "vendor:raylib" import rl "vendor:raylib"
import "core:fmt" import "core:fmt"
import "core:strings" import "core:strings"
@ -8,6 +7,7 @@ import "core:slice"
import "core:bytes" import "core:bytes"
import "core:os" import "core:os"
import tfd "./tinyfiledialogs"
W :: 640 W :: 640
H :: 480 H :: 480
@ -16,40 +16,24 @@ width : int = W
height : int = H height : int = H
zoom : int = 1 zoom : int = 1
WrongSizeErrorTimer : i32 = 0
IsConverted : bool = false IsConverted : bool = false
FILENAME_MAX :: 255 lastFilePathBuffer : [2048]byte
fileNameBuffer : [FILENAME_MAX]byte lastFilePath := cstring(&lastFilePathBuffer[0])
fileNameString := cstring(&fileNameBuffer[0])
editMode := false
fileListScrolling : i32 = 0
fileListActive : i32 = -1
fileListFocus : i32 = -1
fileList : rl.FilePathList
State :: enum { State :: enum {
CartsInput, CartsInput,
Export,
GotError, GotError,
Exported, Exported,
FileSelect
} }
GraphicsMode :: proc() { GraphicsMode :: proc() {
files = slice.into_dynamic(filesBuf[:])
cart := Cart{} cart := Cart{}
target := Cart{} target := Cart{}
fileListTarget : ^Cart
DefaultName :string : "output.p8.png"
for char, i in DefaultName {
fileNameBuffer[i] = auto_cast char
}
copy(lastFilePathBuffer[:], "./")
errorMessages := map[CartLoadError]cstring { errorMessages := map[CartLoadError]cstring {
.None = "", .None = "",
.Wrong_Size = "The image has wrong dimensions!\n160x205 PNG file expected", .Wrong_Size = "The image has wrong dimensions!\n160x205 PNG file expected",
@ -63,20 +47,11 @@ GraphicsMode :: proc() {
rl.InitWindow(W, H, "PicoRepico") rl.InitWindow(W, H, "PicoRepico")
rl.SetTargetFPS(60) rl.SetTargetFPS(60)
//fontData := #load("font.ttf")
//font := rl.LoadFontFromMemory(".ttf", raw_data(fontData), auto_cast len(fontData), 8, nil, 0)
//font := rl.LoadFontEx("font.ttf", 32, nil, 0)
//rl.GuiSetFont(font)
//rl.GuiSetStyle(auto_cast rl.GuiControl.DEFAULT, auto_cast rl.GuiControlProperty.BORDER_COLOR_NORMAL, i32(rl.ColorToInt(rl.Color{211, 2, 255, 255})))
hw : f32 = auto_cast width / 2 hw : f32 = auto_cast width / 2
hh : f32 = auto_cast height / 2 hh : f32 = auto_cast height / 2
state := State.CartsInput state := State.CartsInput
for !rl.WindowShouldClose() { for !rl.WindowShouldClose() {
if WrongSizeErrorTimer > 0 {
WrongSizeErrorTimer -= 1
}
width = auto_cast rl.GetScreenWidth() width = auto_cast rl.GetScreenWidth()
height = auto_cast rl.GetScreenHeight() height = auto_cast rl.GetScreenHeight()
hw = auto_cast width / 2 hw = auto_cast width / 2
@ -137,24 +112,31 @@ GraphicsMode :: proc() {
rl.GuiDummyRec(rl.Rectangle{0, 0, auto_cast width, auto_cast height}, "") rl.GuiDummyRec(rl.Rectangle{0, 0, auto_cast width, auto_cast height}, "")
if rl.GuiButton(buttonCartRect, "Drag original\ncart here") { if rl.GuiButton(buttonCartRect, "Drag original\ncart here") {
fileListTarget = &cart currentError = openDialogAndLoadCart(&cart)
cd(".") if currentError != .None {
state = .FileSelect state = .GotError
}
} }
if cart.loaded { if cart.loaded {
rl.DrawTexturePro(cart.texture, cartRect, buttonCartRect, {0, 0}, 0, rl.WHITE) rl.DrawTexturePro(cart.texture, cartRect, buttonCartRect, {0, 0}, 0, rl.WHITE)
} }
if rl.GuiButton(buttonTargetRect, "Drag target\nshell here") { if rl.GuiButton(buttonTargetRect, "Drag target\nshell here") {
fileListTarget = &target currentError = openDialogAndLoadCart(&target)
cd(".") if currentError != .None {
state = .FileSelect state = .GotError
}
} }
if target.loaded { if target.loaded {
rl.DrawTexturePro(target.texture, cartRect, buttonTargetRect, {0, 0}, 0, rl.WHITE) rl.DrawTexturePro(target.texture, cartRect, buttonTargetRect, {0, 0}, 0, rl.WHITE)
} }
if !(cart.loaded && target.loaded) { rl.GuiDisable() } if !(cart.loaded && target.loaded) { rl.GuiDisable() }
if rl.GuiButton(convertButtonRect, "CONVERT!") { if rl.GuiButton(convertButtonRect, "CONVERT!") {
state = .Export result := tfd.saveFileDialog("Select path to out cart", lastFilePath, {"*.png"}, "PNG image")
if result != "" {
newCart := convertCart(cart.image, target.image)
rl.ExportImage(newCart, result)
state = .Exported
}
} }
rl.GuiEnable() rl.GuiEnable()
@ -162,18 +144,6 @@ GraphicsMode :: proc() {
rl.OpenURL("https://nefrace.itch.io") rl.OpenURL("https://nefrace.itch.io")
} }
} }
case .Export: {
res := rl.GuiTextInputBox(rl.Rectangle{hw - 100, 60, 200, 100}, "Input filename for result", "", "ok;cancel", fileNameString, FILENAME_MAX, nil)
if res == 0 || res == 2 {
state = .CartsInput
slice.fill(fileNameBuffer[:], 0)
}
if res == 1 {
newCart := convertCart(cart.image, target.image)
rl.ExportImage(newCart, fileNameString)
state = .Exported
}
}
case .Exported: { case .Exported: {
if rl.GuiMessageBox(rl.Rectangle{hw-110, 80, 220, 120}, "Success!", "Cart was exported successfully", "CLOSE") != -1 { if rl.GuiMessageBox(rl.Rectangle{hw-110, 80, 220, 120}, "Success!", "Cart was exported successfully", "CLOSE") != -1 {
state = .CartsInput state = .CartsInput
@ -184,34 +154,6 @@ GraphicsMode :: proc() {
state = .CartsInput state = .CartsInput
} }
} }
case .FileSelect: {
rl.GuiPanel(rl.Rectangle{4, 4, auto_cast width - 8, auto_cast height - 8}, "Select a file")
if rl.GuiButton(rl.Rectangle{auto_cast width - 26, 8, 16, 16}, "#128#") {
state = .CartsInput
}
if rl.GuiButton(rl.Rectangle{8, 30, 50, 22}, "Open") {
if fileListActive == -1 {break}
if rl.DirectoryExists(files[fileListActive]) {
cd(files[fileListActive])
break
}
if rl.GetFileExtension(files[fileListActive]) != ".png" {
fmt.println("not a png")
break
}
currentError = loadCart(fileListTarget, files[fileListActive])
if currentError != .None {
state = .GotError
}
state = .CartsInput
}
if rl.GuiButton(rl.Rectangle{60, 30, 50, 22}, "Up") {
cd("..")
}
rl.GuiSetStyle(auto_cast rl.GuiControl.LISTVIEW, auto_cast rl.GuiControlProperty.TEXT_ALIGNMENT, auto_cast rl.GuiTextAlignment.TEXT_ALIGN_LEFT)
res := rl.GuiListViewEx(rl.Rectangle{8, 54, auto_cast width - 16, auto_cast height - 62}, filesPtr, auto_cast filesCount, &fileListScrolling, &fileListActive, &fileListFocus)
}
} }
rl.EndDrawing() rl.EndDrawing()
@ -221,41 +163,12 @@ GraphicsMode :: proc() {
unloadCart(&target) unloadCart(&target)
} }
filesBuf : [1024*8]cstring openDialogAndLoadCart :: proc(cart: ^Cart) -> CartLoadError {
files : [dynamic]cstring result := tfd.openFileDialog("Select PNG", lastFilePath, {"*.png"}, "PNG images", false)
filesPtr : [^]cstring if result != "" {
filesCount : i32 = 0 slice.fill(lastFilePathBuffer[:], 0)
copy(lastFilePathBuffer[:], string(result))
cd :: proc(dir: cstring) -> (result: bool) { return loadCart(cart, result)
result = rl.ChangeDirectory(dir)
rl.UnloadDirectoryFiles(fileList)
clear(&files)
fileList = rl.LoadDirectoryFiles(".")
for fname in fileList.paths[:fileList.count] {
if rl.DirectoryExists(fname) || rl.GetFileExtension(fname) == ".png" {
append(&files, fname)
}
} }
return .None
slice.sort_by(files[:], proc(i,j:cstring) -> bool {
a := string(i)
b := string(j)
adir := rl.DirectoryExists(i)
bdir := rl.DirectoryExists(j)
if (adir && bdir) || (!adir && !bdir) {
return strings.compare(a, b) == -1
}
return adir && !bdir
})
filesPtr = raw_data(files)
filesCount = auto_cast len(files)
// slice.sort_by_cmp(fileList.paths[:fileList.count], strings.compare())
fileListScrolling = 0
fileListActive = -1
fileListFocus = -1
return
} }

View File

@ -0,0 +1,58 @@
package tinyfiledialogs
foreign import tfd "../../tfd.a"
@(link_prefix="tinyfd_")
foreign tfd {
beep :: proc() ---
messageBox :: proc (
title, message, dialogType, iconType: cstring,
defaultButton: i32
) -> i32 ---
@(link_name="tinyfd_openFileDialog")
openFileDialog_sys :: proc(
title, defaultPath : cstring,
numOfPatterns: i32,
filterPatterns: [^]cstring,
singleFilterDescription: cstring,
allowMultipleFiles: i32
) -> cstring ---
@(link_name="tinyfd_saveFileDialog")
saveFileDialog_sys :: proc(
title, defaultPath : cstring,
numOfPatterns: i32,
filterPatterns: [^]cstring,
singleFilterDescription: cstring,
) -> cstring ---
}
openFileDialog :: proc(
title, defaultPath : cstring,
filterPatterns: []cstring,
singleFilterDescription: cstring,
allowMultipleFiles: bool,
) -> cstring {
return openFileDialog_sys(
title, defaultPath,
i32(len(filterPatterns)),
raw_data(filterPatterns),
singleFilterDescription,
i32(allowMultipleFiles),
)
}
saveFileDialog :: proc(
title, defaultPath : cstring,
filterPatterns: []cstring,
singleFilterDescription: cstring,
) -> cstring {
return saveFileDialog_sys(
title, defaultPath,
i32(len(filterPatterns)),
raw_data(filterPatterns),
singleFilterDescription,
)
}

224
tinyfiledialogs/README.txt Normal file
View File

@ -0,0 +1,224 @@
SPDX-License-Identifier: Zlib
Copyright (c) 2014 - 2024 Guillaume Vareille http://ysengrin.com
********* TINY FILE DIALOGS OFFICIAL WEBSITE IS ON SOURCEFORGE *********
http://tinyfiledialogs.sourceforge.net
git clone http://git.code.sf.net/p/tinyfiledialogs/code tinyfd
***************************************************************************
____________________________________________________________________
| |
| 100% compatible C C++ -> You can rename tinfiledialogs.c as .cpp |
|____________________________________________________________________|
tiny file dialogs ( cross-platform C C++ ) v3.17.5 [Mar 28, 2024]
_________
/ \ Tray-popup InputBox PasswordBox MessageBox Notification Beep
|tiny file| ColorPicker OpenFileDialog SaveFileDialog SelectFolderDialog
| dialogs | ASCII UTF-8 (and also MBCS & UTF-16 for windows)
\____ ___/ Native dialog library for WINDOWS MAC OSX GTK+ QT CONSOLE
\| SSH support via automatic switch to console mode or X forwarding
C89/C18 & C++98/C++20 compliant: tested with C & C++ compilers
VisualStudio MinGW GCC Clang TinyCC OpenWatcom-v2 BorlandC SunCC ZapCC
on Windows Mac Linux Bsd Solaris Minix Raspbian Flatpak
using Gnome Kde Mate Enlightenment Cinnamon Budgie Unity Lxde Lxqt Xfce
WindowMaker IceWm Cde Jds OpenBox Awesome Jwm Xdm Cwm
Bindings for LUA, C#, dll, Fortran, Pascal, R.
Included in LWJGL(java), Rust, Haskell, Allegrobasic.
____________________________________________________________________________
| ________________________________________________________________________ |
| | ____________________________________________________________________ | |
| | | If you like tinyfiledialogs, please upvote my stackoverflow answer | | |
| | | https://stackoverflow.com/a/47651444 | | |
| | |____________________________________________________________________| | |
| |________________________________________________________________________| |
|____________________________________________________________________________|
___________________________________________________________
| |
| v3.10: NEW FORTRAN module fully implemented with examples |
| v3.13: NEW PASCAL unit fully implemented with examples |
| v3.14: NEW R inteface fully implemented with examples |
|___________________________________________________________|
_____________________________________________________________________
| |
| my email address is at the top of the header file tinyfiledialogs.h |
|_____________________________________________________________________|
________________________________________________________________________________
| ____________________________________________________________________________ |
| | | |
| | - in tinyfiledialogs, char is UTF-8 by default (since v3.6) | |
| | | |
| | on windows: | |
| | - for UTF-16, use the wchar_t functions at the bottom of the header file | |
| | - _wfopen() requires wchar_t | |
| | | |
| | - but fopen() expects MBCS (not UTF-8) | |
| | - if you want char to be MBCS: set tinyfd_winUtf8 = 0 | |
| | | |
| | - alternatively, tinyfiledialogs provides | |
| | functions to convert between UTF-8, UTF-16 and MBCS | |
| |____________________________________________________________________________| |
|________________________________________________________________________________|
___________________________________________________________________________________
| _______________________________________________________________________________ |
| | | |
| | wchar_t UTF-16 (windows only) prototypes are at the bottom of the header file | |
| |_______________________________________________________________________________| |
|___________________________________________________________________________________|
__________________________________________
| ______________________________________ |
| | | |
| | DO NOT USE USER INPUT IN THE DIALOGS | |
| |______________________________________| |
|__________________________________________|
See compilation instructions at the end of this file
void tinyfd_beep();
int tinyfd_notifyPopup(
char const * aTitle , // NULL or ""
char const * aMessage , // NULL or "" may contain \n \t
char const * aIconType ); // "info" "warning" "error"
int tinyfd_messageBox(
char const * aTitle , // NULL or ""
char const * aMessage , // NULL or "" may contain \n \t
char const * aDialogType , // "ok" "okcancel" "yesno" "yesnocancel"
char const * aIconType , // "info" "warning" "error" "question"
int aDefaultButton );
// 0 for cancel/no , 1 for ok/yes , 2 for no in yesnocancel
char const * tinyfd_inputBox(
char const * aTitle , // NULL or ""
char const * aMessage , // NULL or "" (\n and \t have no effect)
char const * aDefaultInput ); // NULL for a passwordBox, "" for an inputbox
// returns NULL on cancel
char const * tinyfd_saveFileDialog(
char const * aTitle , // NULL or ""
char const * aDefaultPathAndOrFile , // NULL or "" , ends with / to set only a directory
int aNumOfFilterPatterns , // 0 (1 in the following example)
char const * const * aFilterPatterns , // NULL or char const * lFilterPatterns[1]={"*.txt"};
char const * aSingleFilterDescription ); // NULL or "text files"
// returns NULL on cancel
char const * tinyfd_openFileDialog(
char const * aTitle , // NULL or ""
char const * aDefaultPathAndOrFile , // NULL or "" , ends with / to set only a directory
int aNumOfFilterPatterns , // 0 (2 in the following example)
char const * const * aFilterPatterns , // NULL or char const * lFilterPatterns[2]={"*.png","*.jpg"};
char const * aSingleFilterDescription , // NULL or "image files"
int aAllowMultipleSelects ); // 0
// in case of multiple files, the separator is |
// returns NULL on cancel
char const * tinyfd_selectFolderDialog(
char const * aTitle , // NULL or ""
char const * aDefaultPath ); // NULL or ""
// returns NULL on cancel
char const * tinyfd_colorChooser(
char const * aTitle , // NULL or ""
char const * aDefaultHexRGB , // NULL or "#FF0000”
unsigned char const aDefaultRGB[3] , // unsigned char lDefaultRGB[3] = { 0 , 128 , 255 };
unsigned char aoResultRGB[3] ); // unsigned char lResultRGB[3];
// returns the hexcolor as a string "#FF0000"
// aoResultRGB also contains the result
// aDefaultRGB is used only if aDefaultHexRGB is NULL
// aDefaultRGB and aoResultRGB can be the same array
// returns NULL on cancel
___________________________________________________________________________________
| _______________________________________________________________________________ |
| | | |
| | wchar_t UTF-16 (windows only) prototypes are at the bottom of the header file | |
| |_______________________________________________________________________________| |
|___________________________________________________________________________________|
- This is not for ios nor android (it works in termux though).
- The files can be renamed with extension ".cpp" as the code is 100% compatible C C++
(just comment out << extern "C" >> in the header file)
- Windows is fully supported from XP to 10 (maybe even older versions)
- C# & LUA via dll, see files in the folder EXTRAS
- OSX supported from 10.4 to latest (maybe even older versions)
- Do not use " and ' as the dialogs will be display with a warning
instead of the title, message, etc...
- There's one file filter only, it may contain several patterns.
- If no filter description is provided,
the list of patterns will become the description.
- On windows link against Comdlg32.lib and Ole32.lib
(on windows the no linking claim is a lie)
- On unix: it tries command line calls, so no such need (NO LINKING).
- On unix you need one of the following:
applescript, kdialog, zenity, matedialog, shellementary, qarma, yad,
python (2 or 3)/tkinter/python-dbus (optional), Xdialog
or curses dialogs (opens terminal if running without console).
- One of those is already included on most (if not all) desktops.
- In the absence of those it will use gdialog, gxmessage or whiptail
with a textinputbox.
- If nothing is found, it switches to basic console input,
it opens a console if needed (requires xterm + bash).
- for curses dialogs you must set tinyfd_allowCursesDialogs=1
- You can query the type of dialog that will be used (pass "tinyfd_query" as aTitle)
- String memory is preallocated statically for all the returned values.
- File and path names are tested before return, they should be valid.
- tinyfd_forceConsole=1; at run time, forces dialogs into console mode.
- On windows, console mode only make sense for console applications.
- On windows, console mode is not implemented for wchar_T UTF-16.
- Mutiple selects are not possible in console mode.
- The package dialog must be installed to run in curses dialogs in console mode.
It is already installed on most unix systems.
- On osx, the package dialog can be installed via
http://macappstore.org/dialog or http://macports.org
- On windows, for curses dialogs console mode,
dialog.exe should be copied somewhere on your executable path.
It can be found at the bottom of the following page:
http://andrear.altervista.org/home/cdialog.php
_________________________________________________________________
| |
| The project provides an Hello World example: |
| if a console is missing, it will use graphic dialogs |
| if a graphical display is absent, it will use console dialogs |
|_________________________________________________________________|
UNIX (including MacOS) :
$ clang -o hello hello.c tinyfiledialogs.c
( or gcc tcc owcc icx )
( or g++ clang++ icpx )
( some possible options :
-ansi -std=c89 -std=c++98 -pedantic -Wstrict-prototypes
-g3 -Wall -Wextra -Wdouble-promotion -Wconversion -Wno-sign-conversion
-Wno-unused-parameter -Wno-unused-function -fsanitize=undefined -fsanitize=thread
-Wno-deprecated -Wno-incompatible-compiler )
( musl instead of glibc: clang -fuse-ld=lld --rtlib=compiler-rt )
Windows :
MinGW needs gcc >= v4.9 otherwise some headers are incomplete
> gcc -o hello.exe hello.c tinyfiledialogs.c -LC:/mingw/lib -lcomdlg32 -lole32
TinyCC needs >= v0.9.27 (+ tweaks - contact me) otherwise some headers are missing
> tcc -o hello.exe hello.c tinyfiledialogs.c ^
-isystem C:\tcc\winapi-full-for-0.9.27\include\winapi ^
-lcomdlg32 -lole32 -luser32 -lshell32
Borland C :
> bcc32c -o hello.exe hello.c tinyfiledialogs.c
Windows Intel C :
> icx-cc -o hello.exe hello.c tinyfiledialogs.c -lcomdlg32 -lole32 -luser32 -lshell32
> icx-cl -o toot.exe toot.c tootlib.c comdlg32.lib ole32.lib user32.lib shell32.lib
VisualStudio command line :
> cl hello.c tinyfiledialogs.c comdlg32.lib ole32.lib user32.lib shell32.lib /W4
OpenWatcom v2: create a character-mode executable project.
VisualStudio :
Create a console application project,
it links against comdlg32.lib & ole32.lib.

305
tinyfiledialogs/hello.c Normal file
View File

@ -0,0 +1,305 @@
/* SPDX-License-Identifier: Zlib
Copyright (c) 2014 - 2024 Guillaume Vareille http://ysengrin.com
________________________________________________________________
| |
| 100% compatible C C++ -> You can rename this .c file as .cpp |
|________________________________________________________________|
********* TINY FILE DIALOGS OFFICIAL WEBSITE IS ON SOURCEFORGE *********
_________
/ \ hello.c v3.17.5 [Mar 28, 2024]
|tiny file| Hello World file created [November 9, 2014]
| dialogs |
\____ ___/ http://tinyfiledialogs.sourceforge.net
\| git clone http://git.code.sf.net/p/tinyfiledialogs/code tinyfd
____________________________________________
| |
| email: tinyfiledialogs at ysengrin.com |
|____________________________________________|
_________________________________________________________________________________
| |
| the windows only wchar_t UTF-16 prototypes are at the bottom of the header file |
|_________________________________________________________________________________|
_________________________________________________________
| |
| on windows: - since v3.6 char is UTF-8 by default |
| - if you want MBCS set tinyfd_winUtf8 to 0 |
| - functions like fopen expect MBCS |
|_________________________________________________________|
___________________________________________________________
| |
| v3.10: NEW FORTRAN module fully implemented with examples |
| https://stackoverflow.com/a/59657117 |
|___________________________________________________________|
If you like tinyfiledialogs, please upvote my stackoverflow answer
https://stackoverflow.com/a/47651444
- License -
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/*
- Here is the Hello World:
if a console is missing, it will use graphic dialogs
if a graphical display is absent, it will use console dialogs
(on windows the input box may take some time to open the first time)
See compilation instructions at the end of this file
__________________________________________
| ______________________________________ |
| | | |
| | DO NOT USE USER INPUT IN THE DIALOGS | |
| |______________________________________| |
|__________________________________________|
*/
#include <stdio.h>
#include <string.h>
#include "tinyfiledialogs.h"
#ifdef _MSC_VER
#pragma warning(disable:4996) /* silences warnings about strcpy strcat fopen*/
#endif
int main( int argc , char * argv[] )
{
int lIntValue;
char const * lPassword;
char const * lTheSaveFileName;
char const * lTheOpenFileName;
char const * lTheSelectFolderName;
char const * lTheHexColor;
char const * lWillBeGraphicMode;
unsigned char lRgbColor[3];
FILE * lIn;
char lBuffer[1024];
char const * lFilterPatterns[2] = { "*.txt", "*.text" };
(void)argv; /*to silence stupid visual studio warning*/
tinyfd_verbose = argc - 1; /* default is 0 */
tinyfd_silent = 1; /* default is 1 */
tinyfd_forceConsole = 0; /* default is 0 */
tinyfd_assumeGraphicDisplay = 0; /* default is 0 */
#ifdef _WIN32
tinyfd_winUtf8 = 1; /* default is 1 */
/* On windows, you decide if char holds 1:UTF-8(default) or 0:MBCS */
/* Windows is not ready to handle UTF-8 as many char functions like fopen() expect MBCS filenames.*/
/* This hello.c file has been prepared, on windows, to convert the filenames from UTF-8 to UTF-16
and pass them passed to _wfopen() instead of fopen() */
#endif
tinyfd_beep();
lWillBeGraphicMode = tinyfd_inputBox("tinyfd_query", NULL, NULL);
strcpy(lBuffer, "tinyfiledialogs\nv");
strcat(lBuffer, tinyfd_version);
if (lWillBeGraphicMode)
{
strcat(lBuffer, "\ngraphic mode: ");
}
else
{
strcat(lBuffer, "\nconsole mode: ");
}
strcat(lBuffer, tinyfd_response);
tinyfd_messageBox("hello", lBuffer, "ok", "info", 0);
tinyfd_notifyPopup("the title", "the message\n\tfrom outer-space", "info");
if ( lWillBeGraphicMode && ! tinyfd_forceConsole )
{
#if 0
lIntValue = tinyfd_messageBox("Hello World", "\
graphic dialogs [Yes]\n\
console mode [No]\n\
quit [Cancel]",
"yesnocancel", "question", 1);
if (!lIntValue) return 1;
tinyfd_forceConsole = (lIntValue == 2);
#else
lIntValue = tinyfd_messageBox("Hello World", "graphic dialogs [Yes] / console mode [No]", "yesno", "question", 1);
tinyfd_forceConsole = ! lIntValue;
#endif
}
lPassword = tinyfd_inputBox(
"a password box", "your password will be revealed later", NULL);
if (!lPassword) return 1;
tinyfd_messageBox("your password as read", lPassword, "ok", "info", 1);
lTheSaveFileName = tinyfd_saveFileDialog(
"let us save this password",
"./passwordFile.txt",
2,
lFilterPatterns,
NULL);
if (! lTheSaveFileName)
{
tinyfd_messageBox(
"Error",
"Save file name is NULL",
"ok",
"error",
1);
return 1 ;
}
#ifdef _WIN32
if (tinyfd_winUtf8)
lIn = _wfopen(tinyfd_utf8to16(lTheSaveFileName), L"w"); /* the UTF-8 filename is converted to UTF-16 to open the file*/
else
#endif
lIn = fopen(lTheSaveFileName, "w");
if (!lIn)
{
tinyfd_messageBox(
"Error",
"Can not open this file in write mode",
"ok",
"error",
1);
return 1 ;
}
fputs(lPassword, lIn);
fclose(lIn);
lTheOpenFileName = tinyfd_openFileDialog(
"let us read the password back",
"../",
2,
lFilterPatterns,
"text files",
1);
if (! lTheOpenFileName)
{
tinyfd_messageBox(
"Error",
"Open file name is NULL",
"ok",
"error",
0);
return 1 ;
}
#ifdef _WIN32
if (tinyfd_winUtf8)
lIn = _wfopen(tinyfd_utf8to16(lTheOpenFileName), L"r"); /* the UTF-8 filename is converted to UTF-16 */
else
#endif
lIn = fopen(lTheOpenFileName, "r");
if (!lIn)
{
tinyfd_messageBox(
"Error",
"Can not open this file in read mode",
"ok",
"error",
1);
return(1);
}
lBuffer[0] = '\0';
fgets(lBuffer, sizeof(lBuffer), lIn);
fclose(lIn);
tinyfd_messageBox("your password as it was saved", lBuffer, "ok", "info", 1);
lTheSelectFolderName = tinyfd_selectFolderDialog(
"let us just select a directory", "../../");
if (!lTheSelectFolderName)
{
tinyfd_messageBox(
"Error",
"Select folder name is NULL",
"ok",
"error",
1);
return 1;
}
tinyfd_messageBox("The selected folder is", lTheSelectFolderName, "ok", "info", 1);
lTheHexColor = tinyfd_colorChooser(
"choose a nice color",
"#FF0077",
lRgbColor,
lRgbColor);
if (!lTheHexColor)
{
tinyfd_messageBox(
"Error",
"hexcolor is NULL",
"ok",
"error",
1);
return 1;
}
tinyfd_messageBox("The selected hexcolor is", lTheHexColor, "ok", "info", 1);
tinyfd_messageBox("your read password was", lPassword, "ok", "info", 1);
return 0;
}
#ifdef _MSC_VER
#pragma warning(default:4996)
#endif
/*
OSX :
$ clang -o hello.app hello.c tinyfiledialogs.c
( or gcc )
UNIX :
$ gcc -o hello hello.c tinyfiledialogs.c
( or clang tcc owcc cc CC )
Windows :
MinGW needs gcc >= v4.9 otherwise some headers are incomplete
> gcc -o hello.exe hello.c tinyfiledialogs.c -LC:/mingw/lib -lcomdlg32 -lole32
TinyCC needs >= v0.9.27 (+ tweaks - contact me) otherwise some headers are missing
> tcc -o hello.exe hello.c tinyfiledialogs.c ^
-isystem C:\tcc\winapi-full-for-0.9.27\include\winapi ^
-lcomdlg32 -lole32 -luser32 -lshell32
Borland C: > bcc32c -o hello.exe hello.c tinyfiledialogs.c
OpenWatcom v2: create a character-mode executable project.
VisualStudio :
Create a console application project,
it links against comdlg32.lib & ole32.lib.
VisualStudio command line :
> cl hello.c tinyfiledialogs.c comdlg32.lib ole32.lib user32.lib shell32.lib /W4
*/

View File

@ -0,0 +1,241 @@
/* SPDX-License-Identifier: Zlib
Copyright (c) 2014 - 2024 Guillaume Vareille http://ysengrin.com
________________________________________________________________
| |
| 100% compatible C C++ -> You can rename this .c file as .cpp |
|________________________________________________________________|
********* TINY FILE DIALOGS OFFICIAL WEBSITE IS ON SOURCEFORGE *********
_________
/ \ hello_wchar_t.c v3.17.5 [Mar 28, 2024]
|tiny file| Hello WCHAR_T windows only file created [November 9, 2014]
| dialogs |
\____ ___/ http://tinyfiledialogs.sourceforge.net
\| git clone http://git.code.sf.net/p/tinyfiledialogs/code tinyfd
____________________________________________
| |
| email: tinyfiledialogs at ysengrin.com |
|____________________________________________|
________________________________________________________________
| |
| this file is for windows only it uses wchar_t UTF-16 functions |
|________________________________________________________________|
If you like tinyfiledialogs, please upvote my stackoverflow answer
https://stackoverflow.com/a/47651444
- License -
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
See compilation instructions at the end of this file
__________________________________________
| ______________________________________ |
| | | |
| | DO NOT USE USER INPUT IN THE DIALOGS | |
| |______________________________________| |
|__________________________________________|
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "tinyfiledialogs.h"
#ifdef _MSC_VER
#pragma warning(disable:4996) /* silences warning about wcscpy*/
#endif
int main(void) /* WINDOWS ONLY */
{
wchar_t const * lPassword;
wchar_t const * lTheSaveFileName;
wchar_t const * lTheOpenFileName;
wchar_t const * lTheSelectFolderName;
wchar_t const * lTheHexColor;
wchar_t const * lWillBeGraphicMode;
unsigned char lRgbColor[3];
FILE * lIn;
wchar_t lWcharBuff[1024];
wchar_t lBuffer[1024];
wchar_t const * lFilterPatterns[2] = { L"*.txt", L"*.text" };
tinyfd_beep();
lWillBeGraphicMode = tinyfd_inputBoxW(L"tinyfd_query", NULL, NULL);
wcscpy(lBuffer, L"v");
mbstowcs(lWcharBuff, tinyfd_version, strlen(tinyfd_version) + 1);
wcscat(lBuffer, lWcharBuff);
if (lWillBeGraphicMode)
{
wcscat(lBuffer, L"\ngraphic mode: ");
}
else
{
wcscat(lBuffer, L"\nconsole mode: ");
}
mbstowcs(lWcharBuff, tinyfd_response, strlen(tinyfd_response)+1);
wcscat(lBuffer, lWcharBuff);
wcscat(lBuffer, L"\n");
mbstowcs(lWcharBuff, tinyfd_needs + 78, strlen(tinyfd_needs + 78) + 1);
wcscat(lBuffer, lWcharBuff);
tinyfd_messageBoxW(L"hello", lBuffer, L"ok", L"info", 0);
tinyfd_notifyPopupW(L"the title", L"the message\n\tfrom outer-space", L"info");
lPassword = tinyfd_inputBoxW(
L"a password box", L"your password will be revealed later", NULL);
if (!lPassword) return 1;
lTheSaveFileName = tinyfd_saveFileDialogW(
L"let us save this password",
L"passwordFile.txt",
2,
lFilterPatterns,
NULL);
if (! lTheSaveFileName)
{
tinyfd_messageBoxW(
L"Error",
L"Save file name is NULL",
L"ok",
L"error",
1);
return 1 ;
}
lIn = _wfopen(lTheSaveFileName, L"wt, ccs=UNICODE");
if (!lIn)
{
tinyfd_messageBoxW(
L"Error",
L"Can not open this file in write mode",
L"ok",
L"error",
1);
return 1 ;
}
fputws(lPassword, lIn);
fclose(lIn);
lTheOpenFileName = tinyfd_openFileDialogW(
L"let us read the password back",
L"",
2,
lFilterPatterns,
NULL,
0);
if (! lTheOpenFileName)
{
tinyfd_messageBoxW(
L"Error",
L"Open file name is NULL",
L"ok",
L"error",
1);
return 1 ;
}
lIn = _wfopen(lTheOpenFileName, L"rt, ccs=UNICODE");
if (!lIn)
{
tinyfd_messageBoxW(
L"Error",
L"Can not open this file in read mode",
L"ok",
L"error",
1);
return(1);
}
lBuffer[0] = '\0';
fgetws(lBuffer, sizeof(lBuffer), lIn);
fclose(lIn);
tinyfd_messageBoxW(L"your password is",
lBuffer, L"ok", L"info", 1);
lTheSelectFolderName = tinyfd_selectFolderDialogW(
L"let us just select a directory", L"C:\\");
if (!lTheSelectFolderName)
{
tinyfd_messageBoxW(
L"Error",
L"Select folder name is NULL",
L"ok",
L"error",
1);
return 1;
}
tinyfd_messageBoxW(L"The selected folder is",
lTheSelectFolderName, L"ok", L"info", 1);
lTheHexColor = tinyfd_colorChooserW(
L"choose a nice color",
L"#FF0077",
lRgbColor,
lRgbColor);
if (!lTheHexColor)
{
tinyfd_messageBoxW(
L"Error",
L"hexcolor is NULL",
L"ok",
L"error",
1);
return 1;
}
tinyfd_messageBoxW(L"The selected hexcolor is",
lTheHexColor, L"ok", L"info", 1);
tinyfd_messageBoxW(L"your password was", lPassword, L"ok", L"info", 1);
return 0;
}
#ifdef _MSC_VER
#pragma warning(default:4996)
#endif
/*
MinGW needs gcc >= v4.9 otherwise some headers are incomplete
> gcc -o hello.exe hello.c tinyfiledialogs.c -LC:/mingw/lib -lcomdlg32 -lole32
TinyCC needs >= v0.9.27 (+ tweaks - contact me) otherwise some headers are missing
> tcc -o hello.exe hello.c tinyfiledialogs.c ^
-isystem C:\tcc\winapi-full-for-0.9.27\include\winapi ^
-lcomdlg32 -lole32 -luser32 -lshell32
Borland C: > bcc32c -o hello.exe hello.c tinyfiledialogs.c
OpenWatcom v2: create a character-mode executable project.
VisualStudio :
Create a console application project,
it links against comdlg32.lib & ole32.lib.
VisualStudio command line :
> cl hello.c tinyfiledialogs.c comdlg32.lib ole32.lib user32.lib shell32.lib /W4
*/

View File

@ -0,0 +1,259 @@
/* SPDX-License-Identifier: ZLIB
Copyright (c) 2014 - 2023 Guillaume Vareille http://ysengrin.com
_________
/ \ tinyfiledialogs v3.9.0 [Nov 3, 2022] zlib licence
|tiny file|
| dialogs |
\____ ___/ http://tinyfiledialogs.sourceforge.net
\| git clone http://git.code.sf.net/p/tinyfiledialogs/code tinyfd
If you like tinyfiledialogs, please upvote my stackoverflow answer
https://stackoverflow.com/a/47651444
- License -
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef __sun
#ifndef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 2 /* to accept POSIX 2 in old ANSI C standards */
#endif
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../tinyfiledialogs.h"
#define MAX_PATH_OR_CMD 1024 /* _MAX_PATH or MAX_PATH */
int tfd_quoteDetected(char const * aString);
void tfd_replaceSubStr( char const * aSource ,char const * aOldSubStr ,
char const * aNewSubStr ,char * aoDestination );
#ifndef _WIN32
int tfd_isDarwin(void);
int tfd_kdialogPresent(void);
int tfd_matedialogPresent(void);
int tfd_qarmaPresent(void);
int tfd_shellementaryPresent(void);
int tfd_xpropPresent(void);
int tfd_zenityPresent(void);
int tfd_zenity3Present(void);
#endif /*_WIN32 */
/* not cross platform - unix zenity only */
/* contributed by Attila Dusnoki */
#ifndef _WIN32
char * tinyfd_arrayDialog(
char const * aTitle , /* "" */
int aNumOfColumns , /* 2 */
char const * const * aColumns , /* {"Column 1","Column 2"} */
int aNumOfRows , /* 2 */
char const * const * aCells )
/* {"Row1 Col1","Row1 Col2","Row2 Col1","Row2 Col2"} */
{
static char lBuff [MAX_PATH_OR_CMD] ;
char lDialogString [MAX_PATH_OR_CMD] ;
FILE * lIn ;
int i ;
if (tfd_quoteDetected(aTitle)) return tinyfd_arrayDialog("INVALID TITLE WITH QUOTES", aNumOfColumns, aColumns, aNumOfRows, aCells);
for (i = 0; i < aNumOfColumns; i++)
{
if (tfd_quoteDetected(aColumns[i])) return tinyfd_arrayDialog("INVALID COLUMNS WITH QUOTES", 0, NULL, 0, NULL);
}
for (i = 0; i < aNumOfRows; i++)
{
if (tfd_quoteDetected(aCells[i])) return tinyfd_arrayDialog("INVALID ROWS WITH QUOTES", 0, NULL, 0, NULL);
}
lBuff[0]='\0';
if ( tfd_zenityPresent() || tfd_matedialogPresent() || tfd_shellementaryPresent() || tfd_qarmaPresent() )
{
if ( tfd_zenityPresent() )
{
if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"zenity");return (char *)1;}
strcpy( lDialogString , "zenity" ) ;
if ( (tfd_zenity3Present() >= 4) && !getenv("SSH_TTY") && tfd_xpropPresent() )
{
strcat( lDialogString, " --attach=$(sleep .01;xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)"); /* contribution: Paul Rouget */
}
}
else if ( tfd_matedialogPresent() )
{
if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"matedialog");return (char *)1;}
strcpy( lDialogString , "matedialog" ) ;
}
else if ( tfd_shellementaryPresent() )
{
if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"shellementary");return (char *)1;}
strcpy( lDialogString , "shellementary" ) ;
}
else
{
if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"qarma");return (char *)1;}
strcpy( lDialogString , "qarma" ) ;
if ( !getenv("SSH_TTY") && tfd_xpropPresent() )
{
strcat(lDialogString, " --attach=$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)"); /* contribution: Paul Rouget */
}
}
strcat( lDialogString , " --list --print-column=ALL" ) ;
if ( aTitle && strlen(aTitle) )
{
strcat(lDialogString, " --title=\"") ;
strcat(lDialogString, aTitle) ;
strcat(lDialogString, "\"") ;
}
if ( aColumns && (aNumOfColumns > 0) )
{
for ( i = 0 ; i < aNumOfColumns ; i ++ )
{
strcat( lDialogString , " --column=\"" ) ;
strcat( lDialogString , aColumns [i] ) ;
strcat( lDialogString , "\"" ) ;
}
}
if ( aCells && (aNumOfRows > 0) )
{
strcat( lDialogString , " " ) ;
for ( i = 0 ; i < aNumOfRows*aNumOfColumns ; i ++ )
{
strcat( lDialogString , "\"" ) ;
strcat( lDialogString , aCells [i] ) ;
strcat( lDialogString , "\" " ) ;
}
}
}
else
{
if (aTitle&&!strcmp(aTitle,"tinyfd_query")){strcpy(tinyfd_response,"");return (char *)0;}
return NULL ;
}
if (tinyfd_verbose) printf( "lDialogString: %s\n" , lDialogString ) ;
if ( ! ( lIn = popen( lDialogString , "r" ) ) )
{
return NULL ;
}
while ( fgets( lBuff , sizeof( lBuff ) , lIn ) != NULL )
{}
pclose( lIn ) ;
if ( lBuff[strlen( lBuff ) -1] == '\n' )
{
lBuff[strlen( lBuff ) -1] = '\0' ;
}
/* printf( "lBuff: %s\n" , lBuff ) ; */
if ( ! strlen( lBuff ) )
{
return NULL ;
}
return lBuff ;
}
#endif /*_WIN32 */
/* not cross platform - UNIX and OSX only */
/* contributed by srikanth http://sourceforge.net/u/cr1vct/profile */
#ifndef _WIN32
char *tinyfd_checklistDialog(
char const *aTitle,
int aNumOfOptions,
char const *const *aOptions)
{
static char lBuff[MAX_PATH_OR_CMD];
static char dest[MAX_PATH_OR_CMD];
char lDialogString[MAX_PATH_OR_CMD];
FILE *lIn;
int i ;
char *target = lDialogString;
if (tfd_quoteDetected(aTitle)) return tinyfd_checklistDialog("INVALID TITLE WITH QUOTES", aNumOfOptions, aOptions);
for (i = 0; i < aNumOfOptions; i++)
{
if (tfd_quoteDetected(aOptions[i])) return tinyfd_checklistDialog("INVALID COLUMNS WITH QUOTES", 0, NULL);
}
lBuff[0] = '\0';
if (tfd_isDarwin())
{
target += sprintf(target, "osascript -e \'set Choices to {");
for (i = 0; i < aNumOfOptions; i++)
{
if (i != aNumOfOptions - 1)
target += sprintf(target, "\"%s\", ", aOptions[i]);
else
target += sprintf(target, "\"%s\"", aOptions[i]);
}
target += sprintf(target, "}\' -e \'set Choice to choose from list Choices with prompt \"%s\" with multiple selections allowed\' -e \'Choice\'", aTitle);
}
else if (tfd_kdialogPresent())
{
target += sprintf(target, "kdialog --checklist \'%s\' ", aTitle);
for (i = 0; i < aNumOfOptions; i++)
{
target += sprintf(target, "\'%s\' \'%s\' OFF ", aOptions[i], aOptions[i]);
}
}
else if (tfd_zenityPresent())
{
target += sprintf(target, "zenity --list --column= --column= --checklist --title=\'%s\' ", aTitle);
for (i = 0; i < aNumOfOptions; i++)
{
target += sprintf(target, "\'\' \'%s\' ", aOptions[i]);
}
}
if (tinyfd_verbose)
printf("lDialogString: %s\n", lDialogString);
if (!(lIn = popen(lDialogString, "r")))
{
return NULL;
}
while (fgets(lBuff, sizeof(lBuff), lIn) != NULL)
{
}
pclose(lIn);
if (lBuff[strlen(lBuff) - 1] == '\n')
{
lBuff[strlen(lBuff) - 1] = '\0';
}
/* printf( "lBuff: %s\n" , lBuff ) ; */
if (!strlen(lBuff))
{
return NULL;
}
if (tfd_kdialogPresent())
{
tfd_replaceSubStr(lBuff, "\" \"", "|", dest);
dest[strlen(dest) - 2] = '\0';
return dest + 1;
}
if (tfd_isDarwin())
{
tfd_replaceSubStr(lBuff, "\", \"", "|", dest);
dest[strlen(dest) - 2] = '\0';
dest[strlen(dest) - 3] = '\0';
return dest + 2;
}
return lBuff;
}
#endif /*_WIN32 */

View File

@ -0,0 +1,48 @@
/* SPDX-License-Identifier: ZLIB
Copyright (c) 2014 - 2023 Guillaume Vareille http://ysengrin.com
_________
/ \ tinyfiledialogs v3.9.0 [Nov 3, 2022]
|tiny file|
| dialogs |
\____ ___/ http://tinyfiledialogs.sourceforge.net
\| git clone http://git.code.sf.net/p/tinyfiledialogs/code tinyfd
If you like tinyfiledialogs, please upvote my stackoverflow answer
https://stackoverflow.com/a/47651444
- License -
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/* not cross platform - unix zenity only */
/* contributed by Attila Dusnoki */
#ifndef _WIN32
char * tinyfd_arrayDialog(
char const * aTitle , /* NULL or "" */
int aNumOfColumns , /* 2 */
char const * const * aColumns, /* {"Column 1","Column 2"} */
int aNumOfRows, /* 2 */
char const * const * aCells);
/* {"Row1 Col1","Row1 Col2","Row2 Col1","Row2 Col2"} */
#endif /*_WIN32 */
/* not cross platform - UNIX and OSX only */
/* contributed by srikanth http://sourceforge.net/u/cr1vct/profile */
#ifndef _WIN32
char * tinyfd_checklistDialog(
char const * aTitle ,
int aNumOfOptions ,
char const * const * aOptions);
#endif /*_WIN32 */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,314 @@
/* SPDX-License-Identifier: Zlib
Copyright (c) 2014 - 2024 Guillaume Vareille http://ysengrin.com
____________________________________________________________________
| |
| 100% compatible C C++ -> You can rename tinfiledialogs.c as .cpp |
|____________________________________________________________________|
********* TINY FILE DIALOGS OFFICIAL WEBSITE IS ON SOURCEFORGE *********
_________
/ \ tinyfiledialogs.h v3.17.5 [Mar 28, 2024]
|tiny file| Unique header file created [November 9, 2014]
| dialogs |
\____ ___/ http://tinyfiledialogs.sourceforge.net
\| git clone http://git.code.sf.net/p/tinyfiledialogs/code tinyfd
____________________________________________
| |
| email: tinyfiledialogs at ysengrin.com |
|____________________________________________|
________________________________________________________________________________
| ____________________________________________________________________________ |
| | | |
| | - in tinyfiledialogs, char is UTF-8 by default (since v3.6) | |
| | | |
| | on windows: | |
| | - for UTF-16, use the wchar_t functions at the bottom of the header file | |
| | | |
| | - _wfopen() requires wchar_t | |
| | - fopen() uses char but expects ASCII or MBCS (not UTF-8) | |
| | - if you want char to be MBCS: set tinyfd_winUtf8 to 0 | |
| | | |
| | - alternatively, tinyfiledialogs provides | |
| | functions to convert between UTF-8, UTF-16 and MBCS | |
| |____________________________________________________________________________| |
|________________________________________________________________________________|
If you like tinyfiledialogs, please upvote my stackoverflow answer
https://stackoverflow.com/a/47651444
- License -
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
__________________________________________
| ______________________________________ |
| | | |
| | DO NOT USE USER INPUT IN THE DIALOGS | |
| |______________________________________| |
|__________________________________________|
*/
#ifndef TINYFILEDIALOGS_H
#define TINYFILEDIALOGS_H
#ifdef __cplusplus
extern "C" {
#endif
/******************************************************************************************************/
/**************************************** UTF-8 on Windows ********************************************/
/******************************************************************************************************/
#ifdef _WIN32
/* On windows, if you want to use UTF-8 ( instead of the UTF-16/wchar_t functions at the end of this file )
Make sure your code is really prepared for UTF-8 (on windows, functions like fopen() expect MBCS and not UTF-8) */
extern int tinyfd_winUtf8; /* on windows char strings can be 1:UTF-8(default) or 0:MBCS */
/* for MBCS change this to 0, in tinyfiledialogs.c or in your code */
/* Here are some functions to help you convert between UTF-16 UTF-8 MBSC */
char * tinyfd_utf8toMbcs(char const * aUtf8string);
char * tinyfd_utf16toMbcs(wchar_t const * aUtf16string);
wchar_t * tinyfd_mbcsTo16(char const * aMbcsString);
char * tinyfd_mbcsTo8(char const * aMbcsString);
wchar_t * tinyfd_utf8to16(char const * aUtf8string);
char * tinyfd_utf16to8(wchar_t const * aUtf16string);
#endif
/******************************************************************************************************/
/******************************************************************************************************/
/******************************************************************************************************/
/************* 3 funtions for C# (you don't need this in C or C++) : */
char const * tinyfd_getGlobalChar(char const * aCharVariableName); /* returns NULL on error */
int tinyfd_getGlobalInt(char const * aIntVariableName); /* returns -1 on error */
int tinyfd_setGlobalInt(char const * aIntVariableName, int aValue); /* returns -1 on error */
/* aCharVariableName: "tinyfd_version" "tinyfd_needs" "tinyfd_response"
aIntVariableName : "tinyfd_verbose" "tinyfd_silent" "tinyfd_allowCursesDialogs"
"tinyfd_forceConsole" "tinyfd_assumeGraphicDisplay" "tinyfd_winUtf8"
**************/
extern char tinyfd_version[8]; /* contains tinyfd current version number */
extern char tinyfd_needs[]; /* info about requirements */
extern int tinyfd_verbose; /* 0 (default) or 1 : on unix, prints the command line calls */
extern int tinyfd_silent; /* 1 (default) or 0 : on unix, hide errors and warnings from called dialogs */
/** Curses dialogs are difficult to use and counter-intuitive.
On windows they are only ascii and still uses the unix backslash ! **/
extern int tinyfd_allowCursesDialogs; /* 0 (default) or 1 */
extern int tinyfd_forceConsole; /* 0 (default) or 1 */
/* for unix & windows: 0 (graphic mode) or 1 (console mode).
0: try to use a graphic solution, if it fails then it uses console mode.
1: forces all dialogs into console mode even when an X server is present.
if enabled, it can use the package Dialog or dialog.exe.
on windows it only make sense for console applications */
extern int tinyfd_assumeGraphicDisplay; /* 0 (default) or 1 */
/* some systems don't set the environment variable DISPLAY even when a graphic display is present.
set this to 1 to tell tinyfiledialogs to assume the existence of a graphic display */
extern char tinyfd_response[1024];
/* if you pass "tinyfd_query" as aTitle,
the functions will not display the dialogs
but will return 0 for console mode, 1 for graphic mode.
tinyfd_response is then filled with the retain solution.
possible values for tinyfd_response are (all lowercase)
for graphic mode:
windows_wchar windows applescript kdialog zenity zenity3 yad matedialog
shellementary qarma python2-tkinter python3-tkinter python-dbus
perl-dbus gxmessage gmessage xmessage xdialog gdialog dunst
for console mode:
dialog whiptail basicinput no_solution */
void tinyfd_beep(void);
int tinyfd_notifyPopup(
char const * aTitle, /* NULL or "" */
char const * aMessage, /* NULL or "" may contain \n \t */
char const * aIconType); /* "info" "warning" "error" */
/* return has only meaning for tinyfd_query */
int tinyfd_messageBox(
char const * aTitle , /* NULL or "" */
char const * aMessage , /* NULL or "" may contain \n \t */
char const * aDialogType , /* "ok" "okcancel" "yesno" "yesnocancel" */
char const * aIconType , /* "info" "warning" "error" "question" */
int aDefaultButton ) ;
/* 0 for cancel/no , 1 for ok/yes , 2 for no in yesnocancel */
char * tinyfd_inputBox(
char const * aTitle , /* NULL or "" */
char const * aMessage , /* NULL or "" (\n and \t have no effect) */
char const * aDefaultInput ) ; /* NULL = passwordBox, "" = inputbox */
/* returns NULL on cancel */
char * tinyfd_saveFileDialog(
char const * aTitle , /* NULL or "" */
char const * aDefaultPathAndOrFile , /* NULL or "" , ends with / to set only a directory */
int aNumOfFilterPatterns , /* 0 (1 in the following example) */
char const * const * aFilterPatterns , /* NULL or char const * lFilterPatterns[1]={"*.txt"} */
char const * aSingleFilterDescription ) ; /* NULL or "text files" */
/* returns NULL on cancel */
char * tinyfd_openFileDialog(
char const * aTitle, /* NULL or "" */
char const * aDefaultPathAndOrFile, /* NULL or "" , ends with / to set only a directory */
int aNumOfFilterPatterns , /* 0 (2 in the following example) */
char const * const * aFilterPatterns, /* NULL or char const * lFilterPatterns[2]={"*.png","*.jpg"}; */
char const * aSingleFilterDescription, /* NULL or "image files" */
int aAllowMultipleSelects ) ; /* 0 or 1 */
/* in case of multiple files, the separator is | */
/* returns NULL on cancel */
char * tinyfd_selectFolderDialog(
char const * aTitle, /* NULL or "" */
char const * aDefaultPath); /* NULL or "" */
/* returns NULL on cancel */
char * tinyfd_colorChooser(
char const * aTitle, /* NULL or "" */
char const * aDefaultHexRGB, /* NULL or "" or "#FF0000" */
unsigned char const aDefaultRGB[3] , /* unsigned char lDefaultRGB[3] = { 0 , 128 , 255 }; */
unsigned char aoResultRGB[3] ) ; /* unsigned char lResultRGB[3]; */
/* aDefaultRGB is used only if aDefaultHexRGB is absent */
/* aDefaultRGB and aoResultRGB can be the same array */
/* returns NULL on cancel */
/* returns the hexcolor as a string "#FF0000" */
/* aoResultRGB also contains the result */
/************ WINDOWS ONLY SECTION ************************/
#ifdef _WIN32
/* windows only - utf-16 version */
int tinyfd_notifyPopupW(
wchar_t const * aTitle, /* NULL or L"" */
wchar_t const * aMessage, /* NULL or L"" may contain \n \t */
wchar_t const * aIconType); /* L"info" L"warning" L"error" */
/* windows only - utf-16 version */
int tinyfd_messageBoxW(
wchar_t const * aTitle, /* NULL or L"" */
wchar_t const * aMessage, /* NULL or L"" may contain \n \t */
wchar_t const * aDialogType, /* L"ok" L"okcancel" L"yesno" */
wchar_t const * aIconType, /* L"info" L"warning" L"error" L"question" */
int aDefaultButton ); /* 0 for cancel/no , 1 for ok/yes */
/* returns 0 for cancel/no , 1 for ok/yes */
/* windows only - utf-16 version */
wchar_t * tinyfd_inputBoxW(
wchar_t const * aTitle, /* NULL or L"" */
wchar_t const * aMessage, /* NULL or L"" (\n nor \t not respected) */
wchar_t const * aDefaultInput); /* NULL passwordBox, L"" inputbox */
/* windows only - utf-16 version */
wchar_t * tinyfd_saveFileDialogW(
wchar_t const * aTitle, /* NULL or L"" */
wchar_t const * aDefaultPathAndOrFile, /* NULL or L"" , ends with / to set only a directory */
int aNumOfFilterPatterns, /* 0 (1 in the following example) */
wchar_t const * const * aFilterPatterns, /* NULL or wchar_t const * lFilterPatterns[1]={L"*.txt"} */
wchar_t const * aSingleFilterDescription); /* NULL or L"text files" */
/* returns NULL on cancel */
/* windows only - utf-16 version */
wchar_t * tinyfd_openFileDialogW(
wchar_t const * aTitle, /* NULL or L"" */
wchar_t const * aDefaultPathAndOrFile, /* NULL or L"" , ends with / to set only a directory */
int aNumOfFilterPatterns , /* 0 (2 in the following example) */
wchar_t const * const * aFilterPatterns, /* NULL or wchar_t const * lFilterPatterns[2]={L"*.png","*.jpg"} */
wchar_t const * aSingleFilterDescription, /* NULL or L"image files" */
int aAllowMultipleSelects ) ; /* 0 or 1 */
/* in case of multiple files, the separator is | */
/* returns NULL on cancel */
/* windows only - utf-16 version */
wchar_t * tinyfd_selectFolderDialogW(
wchar_t const * aTitle, /* NULL or L"" */
wchar_t const * aDefaultPath); /* NULL or L"" */
/* returns NULL on cancel */
/* windows only - utf-16 version */
wchar_t * tinyfd_colorChooserW(
wchar_t const * aTitle, /* NULL or L"" */
wchar_t const * aDefaultHexRGB, /* NULL or L"#FF0000" */
unsigned char const aDefaultRGB[3], /* unsigned char lDefaultRGB[3] = { 0 , 128 , 255 }; */
unsigned char aoResultRGB[3]); /* unsigned char lResultRGB[3]; */
/* returns the hexcolor as a string L"#FF0000" */
/* aoResultRGB also contains the result */
/* aDefaultRGB is used only if aDefaultHexRGB is NULL */
/* aDefaultRGB and aoResultRGB can be the same array */
/* returns NULL on cancel */
#endif /*_WIN32 */
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /* TINYFILEDIALOGS_H */
/*
________________________________________________________________________________
| ____________________________________________________________________________ |
| | | |
| | on windows: | |
| | - for UTF-16, use the wchar_t functions at the bottom of the header file | |
| | - _wfopen() requires wchar_t | |
| | | |
| | - in tinyfiledialogs, char is UTF-8 by default (since v3.6) | |
| | - but fopen() expects MBCS (not UTF-8) | |
| | - if you want char to be MBCS: set tinyfd_winUtf8 to 0 | |
| | | |
| | - alternatively, tinyfiledialogs provides | |
| | functions to convert between UTF-8, UTF-16 and MBCS | |
| |____________________________________________________________________________| |
|________________________________________________________________________________|
- This is not for ios nor android (it works in termux though).
- The files can be renamed with extension ".cpp" as the code is 100% compatible C C++
(just comment out << extern "C" >> in the header file)
- Windows is fully supported from XP to 10 (maybe even older versions)
- C# & LUA via dll, see files in the folder EXTRAS
- OSX supported from 10.4 to latest (maybe even older versions)
- Do not use " and ' as the dialogs will be displayed with a warning
instead of the title, message, etc...
- There's one file filter only, it may contain several patterns.
- If no filter description is provided,
the list of patterns will become the description.
- On windows link against Comdlg32.lib and Ole32.lib
(on windows the no linking claim is a lie)
- On unix: it tries command line calls, so no such need (NO LINKING).
- On unix you need one of the following:
applescript, kdialog, zenity, matedialog, shellementary, qarma, yad,
python (2 or 3)/tkinter/python-dbus (optional), Xdialog
or curses dialogs (opens terminal if running without console).
- One of those is already included on most (if not all) desktops.
- In the absence of those it will use gdialog, gxmessage or whiptail
with a textinputbox. If nothing is found, it switches to basic console input,
it opens a console if needed (requires xterm + bash).
- for curses dialogs you must set tinyfd_allowCursesDialogs=1
- You can query the type of dialog that will be used (pass "tinyfd_query" as aTitle)
- String memory is preallocated statically for all the returned values.
- File and path names are tested before return, they should be valid.
- tinyfd_forceConsole=1; at run time, forces dialogs into console mode.
- On windows, console mode only make sense for console applications.
- On windows, console mode is not implemented for wchar_T UTF-16.
- Mutiple selects are not possible in console mode.
- The package dialog must be installed to run in curses dialogs in console mode.
It is already installed on most unix systems.
- On osx, the package dialog can be installed via
http://macappstore.org/dialog or http://macports.org
- On windows, for curses dialogs console mode,
dialog.exe should be copied somewhere on your executable path.
It can be found at the bottom of the following page:
http://andrear.altervista.org/home/cdialog.php
*/