2022-10-23 07:27:02 +00:00
|
|
|
//-----------------------------------------------------------------------------------------------------
|
|
|
|
// ___ ____ __ _ _ ____ _____ ____ _ _ ___ _ _ _
|
|
|
|
// / _ \| __ ) / /_ | || | | _ \| ____| / ___| | | |_ _| | | (_) |__ _ __ __ _ _ __ _ _
|
|
|
|
// | | | | _ \| '_ \| || |_| |_) | _| | | _| | | || | | | | | '_ \| '__/ _` | '__| | | |
|
|
|
|
// | |_| | |_) | (_) |__ _| __/| |___ | |_| | |_| || | | |___| | |_) | | | (_| | | | |_| |
|
|
|
|
// \__\_\____/ \___/ |_| |_| |_____| \____|\___/|___| |_____|_|_.__/|_| \__,_|_| \__, |
|
|
|
|
// |___/
|
|
|
|
// QB64-PE GUI Library
|
|
|
|
// Powered by tinyfiledialogs (http://tinyfiledialogs.sourceforge.net)
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------------------------------
|
|
|
|
|
2024-02-13 16:18:10 +00:00
|
|
|
#include "libqb-common.h"
|
|
|
|
|
|
|
|
#include "qbs.h"
|
2022-10-23 07:27:02 +00:00
|
|
|
#include "gui.h"
|
|
|
|
#include "image.h"
|
|
|
|
#include "tinyfiledialogs.h"
|
2023-05-01 18:49:33 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <string>
|
2024-02-13 16:18:10 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <limits.h>
|
2022-10-23 07:27:02 +00:00
|
|
|
|
2024-01-28 18:37:47 +00:00
|
|
|
/// @brief Splits a string delimited by '|' into an array of strings
|
2022-10-23 07:27:02 +00:00
|
|
|
/// @param input The string to be parsed
|
|
|
|
/// @param count Point to an integer that will hold the count of tokens. This cannot be NULL
|
|
|
|
/// @return Array of string tokens. This must be freed using gui_free_tokens()
|
|
|
|
static char **gui_tokenize(const char *input, int32_t *count) {
|
2022-10-23 20:39:55 +00:00
|
|
|
auto str = strdup(input);
|
2022-10-23 07:27:02 +00:00
|
|
|
auto capacity = 2;
|
|
|
|
char **result = (char **)malloc(capacity * sizeof(*result));
|
2022-10-23 20:39:55 +00:00
|
|
|
char *saveptr;
|
2022-10-23 07:27:02 +00:00
|
|
|
|
2022-10-23 21:29:51 +00:00
|
|
|
*count = 0;
|
2022-10-23 20:39:55 +00:00
|
|
|
auto tok = strtok_r(str, "|", &saveptr);
|
2022-10-23 07:27:02 +00:00
|
|
|
|
|
|
|
for (;;) {
|
2022-10-23 21:29:51 +00:00
|
|
|
if (*count >= capacity)
|
2022-10-23 07:27:02 +00:00
|
|
|
result = (char **)realloc(result, (capacity *= 2) * sizeof(*result));
|
|
|
|
|
2022-10-23 21:29:51 +00:00
|
|
|
result[*count] = tok ? strdup(tok) : tok;
|
2022-10-23 07:27:02 +00:00
|
|
|
|
|
|
|
if (!tok)
|
|
|
|
break;
|
|
|
|
|
2022-10-23 21:29:51 +00:00
|
|
|
++(*count);
|
|
|
|
|
2022-10-23 20:39:55 +00:00
|
|
|
tok = strtok_r(nullptr, "|", &saveptr);
|
2022-10-23 07:27:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
free(str);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Frees all string and the array itself created by gui_tokenize()
|
|
|
|
/// @param tokens Array of string pointers
|
|
|
|
static void gui_free_tokens(char **tokens) {
|
|
|
|
for (auto it = tokens; it && *it; ++it)
|
|
|
|
free(*it);
|
|
|
|
|
|
|
|
free(tokens);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Shows a system notification (on Windows this will be an action center notification)
|
|
|
|
/// @param qbsTitle [OPTIONAL] Title of the notification
|
|
|
|
/// @param qbsMessage [OPTIONAL] The message that will be displayed
|
|
|
|
/// @param qbsIconType [OPTIONAL] Icon type ("info" "warning" "error")
|
2023-05-01 18:49:33 +00:00
|
|
|
/// @param passed Optional parameter mask
|
2022-10-23 07:27:02 +00:00
|
|
|
void sub__guiNotifyPopup(qbs *qbsTitle, qbs *qbsMessage, qbs *qbsIconType, int32_t passed) {
|
2023-05-01 18:49:33 +00:00
|
|
|
std::string aTitle;
|
|
|
|
std::string aMessage;
|
|
|
|
std::string aIconType;
|
2022-10-23 07:27:02 +00:00
|
|
|
|
|
|
|
if (passed & 1)
|
2023-05-01 18:49:33 +00:00
|
|
|
aTitle.assign((const char *)qbsTitle->chr, qbsTitle->len);
|
2022-10-23 07:27:02 +00:00
|
|
|
|
|
|
|
if (passed & 2)
|
2023-05-01 18:49:33 +00:00
|
|
|
aMessage.assign((const char *)qbsMessage->chr, qbsMessage->len);
|
2022-10-23 07:27:02 +00:00
|
|
|
|
2023-05-01 18:49:33 +00:00
|
|
|
if (passed & 4) {
|
|
|
|
aIconType.assign((const char *)qbsIconType->chr, qbsIconType->len);
|
|
|
|
std::transform(aIconType.begin(), aIconType.end(), aIconType.begin(), [](unsigned char c) { return std::tolower(c); });
|
|
|
|
} else {
|
|
|
|
aIconType.assign("info");
|
|
|
|
}
|
2022-10-23 07:27:02 +00:00
|
|
|
|
2023-05-01 18:49:33 +00:00
|
|
|
tinyfd_notifyPopup(aTitle.c_str(), aMessage.c_str(), aIconType.c_str());
|
2022-10-23 07:27:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Shows a standard system message dialog box
|
2023-05-01 18:49:33 +00:00
|
|
|
/// @param qbsTitle [OPTIONAL] Title of the dialog box
|
|
|
|
/// @param qbsMessage [OPTIONAL] The message that will be displayed
|
|
|
|
/// @param qbsIconType [OPTIONAL] The dialog icon type ("info" "warning" "error")
|
|
|
|
/// @param passed Optional parameter mask
|
|
|
|
void sub__guiMessageBox(qbs *qbsTitle, qbs *qbsMessage, qbs *qbsIconType, int32_t passed) {
|
|
|
|
std::string aTitle;
|
|
|
|
std::string aMessage;
|
|
|
|
std::string aIconType;
|
2022-10-23 07:27:02 +00:00
|
|
|
|
2023-05-01 18:49:33 +00:00
|
|
|
if (passed & 1)
|
|
|
|
aTitle.assign((const char *)qbsTitle->chr, qbsTitle->len);
|
2022-10-23 07:27:02 +00:00
|
|
|
|
2023-05-01 18:49:33 +00:00
|
|
|
if (passed & 2)
|
|
|
|
aMessage.assign((const char *)qbsMessage->chr, qbsMessage->len);
|
2022-10-23 07:27:02 +00:00
|
|
|
|
2023-05-01 18:49:33 +00:00
|
|
|
if (passed & 4) {
|
|
|
|
aIconType.assign((const char *)qbsIconType->chr, qbsIconType->len);
|
|
|
|
std::transform(aIconType.begin(), aIconType.end(), aIconType.begin(), [](unsigned char c) { return std::tolower(c); });
|
|
|
|
} else {
|
|
|
|
aIconType.assign("info");
|
|
|
|
}
|
2022-10-23 07:27:02 +00:00
|
|
|
|
2023-05-01 18:49:33 +00:00
|
|
|
tinyfd_messageBox(aTitle.c_str(), aMessage.c_str(), "ok", aIconType.c_str(), 1);
|
2022-10-23 07:27:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Shows a standard system message dialog box
|
|
|
|
/// @param qbsTitle [OPTIONAL] Title of the dialog box
|
|
|
|
/// @param qbsMessage [OPTIONAL] The message that will be displayed
|
2023-05-01 18:49:33 +00:00
|
|
|
/// @param qbsDialogType [OPTIONAL] The dialog type ("ok" "okcancel" "yesno" "yesnocancel")
|
|
|
|
/// @param qbsIconType [OPTIONAL] The dialog icon type ("info" "warning" "error" "question")
|
|
|
|
/// @param nDefaultButon [OPTIONAL] The default button that will be selected
|
|
|
|
/// @param passed Optional parameter mask
|
|
|
|
/// @return 0 for cancel/no, 1 for ok/yes, 2 for no in yesnocancel
|
|
|
|
int32_t func__guiMessageBox(qbs *qbsTitle, qbs *qbsMessage, qbs *qbsDialogType, qbs *qbsIconType, int32_t nDefaultButton, int32_t passed) {
|
|
|
|
std::string aTitle;
|
|
|
|
std::string aMessage;
|
|
|
|
std::string aDialogType;
|
|
|
|
std::string aIconType;
|
2022-10-23 07:27:02 +00:00
|
|
|
|
|
|
|
if (passed & 1)
|
2023-05-01 18:49:33 +00:00
|
|
|
aTitle.assign((const char *)qbsTitle->chr, qbsTitle->len);
|
2022-10-23 07:27:02 +00:00
|
|
|
|
|
|
|
if (passed & 2)
|
2023-05-01 18:49:33 +00:00
|
|
|
aMessage.assign((const char *)qbsMessage->chr, qbsMessage->len);
|
2022-10-23 07:27:02 +00:00
|
|
|
|
2023-05-01 18:49:33 +00:00
|
|
|
if (passed & 4) {
|
|
|
|
aDialogType.assign((const char *)qbsDialogType->chr, qbsDialogType->len);
|
|
|
|
std::transform(aDialogType.begin(), aDialogType.end(), aDialogType.begin(), [](unsigned char c) { return std::tolower(c); });
|
|
|
|
} else {
|
|
|
|
aDialogType.assign("ok");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (passed & 8) {
|
|
|
|
aIconType.assign((const char *)qbsIconType->chr, qbsIconType->len);
|
|
|
|
std::transform(aIconType.begin(), aIconType.end(), aIconType.begin(), [](unsigned char c) { return std::tolower(c); });
|
|
|
|
} else {
|
|
|
|
aIconType.assign("info");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(passed & 16))
|
|
|
|
nDefaultButton = 1;
|
2022-10-23 07:27:02 +00:00
|
|
|
|
2023-05-01 18:49:33 +00:00
|
|
|
return tinyfd_messageBox(aTitle.c_str(), aMessage.c_str(), aDialogType.c_str(), aIconType.c_str(), nDefaultButton);
|
2022-10-23 07:27:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Shows an input box for getting a string from the user
|
2023-05-01 18:49:33 +00:00
|
|
|
/// @param qbsTitle [OPTIONAL] Title of the dialog box
|
|
|
|
/// @param qbsMessage [OPTIONAL] The message or prompt that will be displayed
|
2022-10-23 07:27:02 +00:00
|
|
|
/// @param qbsDefaultInput [OPTIONAL] The default response that can be changed by the user
|
2023-05-01 18:49:33 +00:00
|
|
|
/// @param passed Optional parameter mask
|
2022-10-23 07:27:02 +00:00
|
|
|
/// @return The user response or an empty string if the user cancelled
|
|
|
|
qbs *func__guiInputBox(qbs *qbsTitle, qbs *qbsMessage, qbs *qbsDefaultInput, int32_t passed) {
|
2023-05-01 18:49:33 +00:00
|
|
|
std::string aTitle;
|
|
|
|
std::string aMessage;
|
|
|
|
std::string aDefaultInput;
|
2022-10-23 07:27:02 +00:00
|
|
|
|
2023-05-01 18:49:33 +00:00
|
|
|
if (passed & 1)
|
|
|
|
aTitle.assign((const char *)qbsTitle->chr, qbsTitle->len);
|
2022-10-23 07:27:02 +00:00
|
|
|
|
2023-05-01 18:49:33 +00:00
|
|
|
if (passed & 2)
|
|
|
|
aMessage.assign((const char *)qbsMessage->chr, qbsMessage->len);
|
2022-10-24 22:54:01 +00:00
|
|
|
|
2023-05-01 18:49:33 +00:00
|
|
|
const char *sDefaultInput;
|
|
|
|
if (passed & 4) {
|
|
|
|
aDefaultInput.assign((const char *)qbsDefaultInput->chr, qbsDefaultInput->len);
|
|
|
|
sDefaultInput = !qbsDefaultInput->len ? nullptr : aDefaultInput.c_str(); // if string is "" then password box, else we pass the default input as is
|
2022-10-23 07:27:02 +00:00
|
|
|
} else {
|
2023-05-01 18:49:33 +00:00
|
|
|
sDefaultInput = aDefaultInput.c_str();
|
2022-10-23 07:27:02 +00:00
|
|
|
}
|
|
|
|
|
2023-05-01 18:49:33 +00:00
|
|
|
auto sInput = tinyfd_inputBox(aTitle.c_str(), aMessage.c_str(), sDefaultInput);
|
2022-10-23 07:27:02 +00:00
|
|
|
|
2022-10-24 22:54:01 +00:00
|
|
|
// Create a new qbs and then copy the string to it
|
2023-05-01 18:49:33 +00:00
|
|
|
auto qbsInput = qbs_new(sInput ? strlen(sInput) : 0, 1);
|
2022-10-24 22:54:01 +00:00
|
|
|
if (qbsInput->len)
|
|
|
|
memcpy(qbsInput->chr, sInput, qbsInput->len);
|
|
|
|
|
|
|
|
return qbsInput;
|
2022-10-23 07:27:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Shows the browse for folder dialog box
|
2023-05-01 18:49:33 +00:00
|
|
|
/// @param qbsTitle [OPTIONAL] Title of the dialog box
|
2022-10-23 07:27:02 +00:00
|
|
|
/// @param qbsDefaultPath [OPTIONAL] The default path from where to start browsing
|
2023-05-01 18:49:33 +00:00
|
|
|
/// @param passed Optional parameter mask
|
2022-10-23 07:27:02 +00:00
|
|
|
/// @return The path selected by the user or an empty string if the user cancelled
|
|
|
|
qbs *func__guiSelectFolderDialog(qbs *qbsTitle, qbs *qbsDefaultPath, int32_t passed) {
|
2023-05-01 18:49:33 +00:00
|
|
|
std::string aTitle;
|
|
|
|
std::string aDefaultPath;
|
2022-10-23 07:27:02 +00:00
|
|
|
|
2023-05-01 18:49:33 +00:00
|
|
|
if (passed & 1)
|
|
|
|
aTitle.assign((const char *)qbsTitle->chr, qbsTitle->len);
|
2022-10-23 07:27:02 +00:00
|
|
|
|
2023-05-01 18:49:33 +00:00
|
|
|
if (passed & 2)
|
|
|
|
aDefaultPath.assign((const char *)qbsDefaultPath->chr, qbsDefaultPath->len);
|
2022-10-23 07:27:02 +00:00
|
|
|
|
2023-05-01 18:49:33 +00:00
|
|
|
auto sFolder = tinyfd_selectFolderDialog(aTitle.c_str(), aDefaultPath.c_str());
|
2022-10-23 07:27:02 +00:00
|
|
|
|
2022-10-24 22:54:01 +00:00
|
|
|
// Create a new qbs and then copy the string to it
|
2023-05-01 18:49:33 +00:00
|
|
|
auto qbsFolder = qbs_new(sFolder ? strlen(sFolder) : 0, 1);
|
2022-10-24 22:54:01 +00:00
|
|
|
if (qbsFolder->chr)
|
|
|
|
memcpy(qbsFolder->chr, sFolder, qbsFolder->len);
|
|
|
|
|
|
|
|
return qbsFolder;
|
2022-10-23 07:27:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Shows the color picker dialog box
|
2023-05-01 18:49:33 +00:00
|
|
|
/// @param qbsTitle [OPTIONAL] Title of the dialog box
|
2022-10-23 07:27:02 +00:00
|
|
|
/// @param nDefaultRGB [OPTIONAL] Default selected color
|
2023-05-01 18:49:33 +00:00
|
|
|
/// @param passed Optional parameter mask
|
2022-10-23 07:27:02 +00:00
|
|
|
/// @return 0 on cancel (i.e. no color, no alpha, nothing). Else, returns color with alpha set to 255
|
|
|
|
uint32_t func__guiColorChooserDialog(qbs *qbsTitle, uint32_t nDefaultRGB, int32_t passed) {
|
2023-05-01 18:49:33 +00:00
|
|
|
std::string aTitle;
|
2022-10-23 07:27:02 +00:00
|
|
|
|
2023-05-01 18:49:33 +00:00
|
|
|
if (passed & 1)
|
|
|
|
aTitle.assign((const char *)qbsTitle->chr, qbsTitle->len);
|
2022-10-23 07:27:02 +00:00
|
|
|
|
2023-05-01 18:49:33 +00:00
|
|
|
if (!(passed & 2))
|
2022-10-23 07:27:02 +00:00
|
|
|
nDefaultRGB = 0;
|
|
|
|
|
|
|
|
// Break the color into RGB components
|
2023-05-01 18:49:33 +00:00
|
|
|
uint8_t lRGB[3] = {IMAGE_GET_BGRA_RED(nDefaultRGB), IMAGE_GET_BGRA_GREEN(nDefaultRGB), IMAGE_GET_BGRA_BLUE(nDefaultRGB)};
|
2022-10-23 07:27:02 +00:00
|
|
|
|
|
|
|
// On cancel, return 0 (i.e. no color, no alpha, nothing). Else, return color with alpha set to 255
|
2023-05-01 18:49:33 +00:00
|
|
|
return !tinyfd_colorChooser(aTitle.c_str(), nullptr, lRGB, lRGB) ? 0 : IMAGE_MAKE_BGRA(lRGB[0], lRGB[1], lRGB[2], 0xFF);
|
2022-10-23 07:27:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Shows the system file open dialog box
|
2023-05-01 18:49:33 +00:00
|
|
|
/// @param qbsTitle [OPTIONAL] Title of the dialog box
|
|
|
|
/// @param qbsDefaultPathAndFile [OPTIONAL] The default path (and filename) that will be pre-populated
|
|
|
|
/// @param qbsFilterPatterns [OPTIONAL] File filters separated using '|' (e.g. "*.png|*.jpg")
|
|
|
|
/// @param qbsSingleFilterDescription [OPTIONAL] Single filter description (e.g. "Image files")
|
2022-10-23 07:27:02 +00:00
|
|
|
/// @param nAllowMultipleSelects [OPTIONAL] Should multiple file selection be allowed?
|
2023-05-01 18:49:33 +00:00
|
|
|
/// @param passed Optional parameter mask
|
2022-10-23 07:27:02 +00:00
|
|
|
/// @return The file name (or names separated by '|' if multiselect was on) selected by the user or an empty string if the user cancelled
|
|
|
|
qbs *func__guiOpenFileDialog(qbs *qbsTitle, qbs *qbsDefaultPathAndFile, qbs *qbsFilterPatterns, qbs *qbsSingleFilterDescription, int32_t nAllowMultipleSelects,
|
|
|
|
int32_t passed) {
|
2023-05-01 18:49:33 +00:00
|
|
|
std::string aTitle;
|
|
|
|
std::string aDefaultPathAndFile;
|
|
|
|
std::string aFilterPatterns;
|
|
|
|
std::string aSingleFilterDescription;
|
2022-10-23 07:27:02 +00:00
|
|
|
|
2023-05-01 18:49:33 +00:00
|
|
|
if (passed & 1)
|
|
|
|
aTitle.assign((const char *)qbsTitle->chr, qbsTitle->len);
|
2022-10-23 07:27:02 +00:00
|
|
|
|
2023-05-01 18:49:33 +00:00
|
|
|
if (passed & 2)
|
|
|
|
aDefaultPathAndFile.assign((const char *)qbsDefaultPathAndFile->chr, qbsDefaultPathAndFile->len);
|
2022-10-23 07:27:02 +00:00
|
|
|
|
2023-05-01 18:49:33 +00:00
|
|
|
if (passed & 4)
|
|
|
|
aFilterPatterns.assign((const char *)qbsFilterPatterns->chr, qbsFilterPatterns->len);
|
2022-10-23 07:27:02 +00:00
|
|
|
|
2023-05-01 18:49:33 +00:00
|
|
|
const char *sSingleFilterDescription;
|
|
|
|
if (passed & 8) {
|
|
|
|
aSingleFilterDescription.assign((const char *)qbsSingleFilterDescription->chr, qbsSingleFilterDescription->len);
|
|
|
|
sSingleFilterDescription = !qbsSingleFilterDescription->len ? nullptr : aSingleFilterDescription.c_str();
|
|
|
|
} else {
|
|
|
|
sSingleFilterDescription = nullptr;
|
|
|
|
}
|
2022-10-23 07:27:02 +00:00
|
|
|
|
2023-05-01 18:49:33 +00:00
|
|
|
// If nAllowMultipleSelects is < 0 tinyfd_openFileDialog allows a program to force-free any working memory that it
|
|
|
|
// may be using and returns NULL. This is really not an issue even if it is not done because tinyfd_openFileDialog
|
|
|
|
// 'recycles' it working memory and anything not feed will be taken care of by the OS on program exit. Unfortunately
|
|
|
|
// in case of QB64, true is -1. To work around this, we trap any non-zero values and re-interpret those as 1
|
|
|
|
nAllowMultipleSelects = !(passed & 16) || !nAllowMultipleSelects ? false : true;
|
2022-10-23 07:27:02 +00:00
|
|
|
|
|
|
|
int32_t aNumOfFilterPatterns;
|
2023-05-01 18:49:33 +00:00
|
|
|
auto psaFilterPatterns = gui_tokenize(aFilterPatterns.c_str(), &aNumOfFilterPatterns); // get the number of file filters & count
|
2022-10-23 07:27:02 +00:00
|
|
|
|
2023-05-01 18:49:33 +00:00
|
|
|
auto sFileName = tinyfd_openFileDialog(aTitle.c_str(), aDefaultPathAndFile.c_str(), aNumOfFilterPatterns, psaFilterPatterns, sSingleFilterDescription,
|
|
|
|
nAllowMultipleSelects);
|
2022-10-23 07:27:02 +00:00
|
|
|
|
|
|
|
gui_free_tokens(psaFilterPatterns); // free memory used by tokenizer
|
|
|
|
|
2022-10-24 22:54:01 +00:00
|
|
|
// Create a new qbs and then copy the string to it
|
2023-05-01 18:49:33 +00:00
|
|
|
auto qbsFileName = qbs_new(sFileName ? strlen(sFileName) : 0, 1);
|
2022-10-24 22:54:01 +00:00
|
|
|
if (qbsFileName->len)
|
|
|
|
memcpy(qbsFileName->chr, sFileName, qbsFileName->len);
|
|
|
|
|
|
|
|
return qbsFileName;
|
2022-10-23 07:27:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Shows the system file save dialog box
|
2023-05-01 18:49:33 +00:00
|
|
|
/// @param qbsTitle [OPTIONAL] Title of the dialog box
|
|
|
|
/// @param qbsDefaultPathAndFile [OPTIONAL] The default path (and filename) that will be pre-populated
|
|
|
|
/// @param qbsFilterPatterns [OPTIONAL] File filters separated using '|' (e.g. "*.png|*.jpg")
|
|
|
|
/// @param qbsSingleFilterDescription [OPTIONAL] Single filter description (e.g. "Image files")
|
2022-10-23 07:27:02 +00:00
|
|
|
/// @return The file name selected by the user or an empty string if the user cancelled
|
2023-05-01 18:49:33 +00:00
|
|
|
qbs *func__guiSaveFileDialog(qbs *qbsTitle, qbs *qbsDefaultPathAndFile, qbs *qbsFilterPatterns, qbs *qbsSingleFilterDescription, int32_t passed) {
|
|
|
|
std::string aTitle;
|
|
|
|
std::string aDefaultPathAndFile;
|
|
|
|
std::string aFilterPatterns;
|
|
|
|
std::string aSingleFilterDescription;
|
2022-10-23 07:27:02 +00:00
|
|
|
|
2023-05-01 18:49:33 +00:00
|
|
|
if (passed & 1)
|
|
|
|
aTitle.assign((const char *)qbsTitle->chr, qbsTitle->len);
|
2022-10-23 07:27:02 +00:00
|
|
|
|
2023-05-01 18:49:33 +00:00
|
|
|
if (passed & 2)
|
|
|
|
aDefaultPathAndFile.assign((const char *)qbsDefaultPathAndFile->chr, qbsDefaultPathAndFile->len);
|
2022-10-23 07:27:02 +00:00
|
|
|
|
2023-05-01 18:49:33 +00:00
|
|
|
if (passed & 4)
|
|
|
|
aFilterPatterns.assign((const char *)qbsFilterPatterns->chr, qbsFilterPatterns->len);
|
2022-10-23 07:27:02 +00:00
|
|
|
|
2023-05-01 18:49:33 +00:00
|
|
|
const char *sSingleFilterDescription;
|
|
|
|
if (passed & 8) {
|
|
|
|
aSingleFilterDescription.assign((const char *)qbsSingleFilterDescription->chr, qbsSingleFilterDescription->len);
|
|
|
|
sSingleFilterDescription = !qbsSingleFilterDescription->len ? nullptr : aSingleFilterDescription.c_str();
|
|
|
|
} else {
|
|
|
|
sSingleFilterDescription = nullptr;
|
|
|
|
}
|
2022-10-23 07:27:02 +00:00
|
|
|
|
|
|
|
int32_t aNumOfFilterPatterns;
|
2023-05-01 18:49:33 +00:00
|
|
|
auto psaFilterPatterns = gui_tokenize(aFilterPatterns.c_str(), &aNumOfFilterPatterns); // get the number of file filters & count
|
2022-10-23 07:27:02 +00:00
|
|
|
|
2023-05-01 18:49:33 +00:00
|
|
|
auto sFileName = tinyfd_saveFileDialog(aTitle.c_str(), aDefaultPathAndFile.c_str(), aNumOfFilterPatterns, psaFilterPatterns, sSingleFilterDescription);
|
2022-10-23 07:27:02 +00:00
|
|
|
|
|
|
|
gui_free_tokens(psaFilterPatterns); // free memory used by tokenizer
|
|
|
|
|
2022-10-24 22:54:01 +00:00
|
|
|
// Create a new qbs and then copy the string to it
|
2023-05-01 18:49:33 +00:00
|
|
|
auto qbsFileName = qbs_new(sFileName ? strlen(sFileName) : 0, 1);
|
2022-10-24 22:54:01 +00:00
|
|
|
if (qbsFileName->len)
|
|
|
|
memcpy(qbsFileName->chr, sFileName, qbsFileName->len);
|
|
|
|
|
|
|
|
return qbsFileName;
|
2022-10-23 07:27:02 +00:00
|
|
|
}
|
2022-10-24 22:54:01 +00:00
|
|
|
|
|
|
|
/// @brief This is used internally by libqb to show warning and failure messages
|
|
|
|
/// @param message The message the will show inside the dialog box
|
|
|
|
/// @param title The dialog box title
|
|
|
|
/// @param type The type of dialog box (see tinyfd_messageBox)
|
2024-01-28 18:37:47 +00:00
|
|
|
/// @return returns the value returned by tinyfd_messageBox
|
2022-10-24 22:54:01 +00:00
|
|
|
int gui_alert(const char *message, const char *title, const char *type) { return tinyfd_messageBox(title, message, type, "error", 1); }
|
|
|
|
|
|
|
|
/// @brief This is used internally by libqb to show warning and failure messages
|
|
|
|
/// @param fmt A string that contains a printf style format
|
|
|
|
/// @param ... Additional arguments
|
|
|
|
/// @return true if successful, false otherwise
|
|
|
|
bool gui_alert(const char *fmt, ...) {
|
2022-10-24 23:17:27 +00:00
|
|
|
if (!fmt)
|
|
|
|
return false;
|
|
|
|
|
2022-10-24 22:54:01 +00:00
|
|
|
size_t l = strlen(fmt) * 2 + UCHAR_MAX;
|
|
|
|
|
|
|
|
char *buf = (char *)malloc(l);
|
|
|
|
if (!buf)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
|
|
|
|
|
|
|
if (vsnprintf(buf, l, fmt, args) < 0) {
|
|
|
|
va_end(args);
|
|
|
|
free(buf);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
gui_alert(buf, "Alert", "ok");
|
|
|
|
|
|
|
|
free(buf);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|