feat: add some work

- add dialog parameter class for dialog helper. prepare to write real dialog popup function.
- refactor file filters class in dialog helper to make it no const syntax conflict.
- improve windows header import prefix and suffix header. remove the barrier limiting headers only can be imported once. fix define preprocessor usage bug.
- move crt warning and errors macro from project settings to internal headers.
- copy IronPad as ExceptionHandler but not adapted to this project.
This commit is contained in:
2024-05-23 09:37:41 +08:00
parent 359aff82ac
commit 84228b5f8c
10 changed files with 500 additions and 70 deletions

View File

@ -27,53 +27,52 @@ namespace YYCC::DialogHelper {
return true;
}
void FileFilters::Clear() {
m_Filters.clear();
}
bool FileFilters::Generate(WinFileFilters& win_result) const {
// clear Windows oriented data
win_result.m_WinDataStruct.reset();
win_result.m_WinFilters.clear();
bool FileFilters::Generate(UINT& filter_count, COMDLG_FILTERSPEC*& filter_specs) {
// init defualt value to prevent the scenario that caller do not check return value.
filter_count = 0u;
filter_specs = nullptr;
// clear win string vector and build new one
m_WinFilters.clear();
// build new Windows oriented string vector first
for (const auto& it : m_Filters) {
// convert name to wchar
WinFilterName name;
WinFileFilters::WinFilterName name;
if (!YYCC::EncodingHelper::UTF8ToWchar(it.first.c_str(), name))
return false;
// convert pattern and join them
std::string joined_modes(YYCC::StringHelper::Join(it.second, u8";"));
WinFilterModes modes;
WinFileFilters::WinFilterModes modes;
if (!YYCC::EncodingHelper::UTF8ToWchar(joined_modes.c_str(), modes))
return false;
// append new pair
m_WinFilters.emplace_back(std::make_pair(name, modes));
win_result.m_WinFilters.emplace_back(std::make_pair(name, modes));
}
// check filter size
// if it overflow the maximum value, return false
size_t count = m_WinFilters.size();
size_t count = win_result.m_WinFilters.size();
if (count > std::numeric_limits<UINT>::max())
return false;
// create new win data struct
// and assign string pointer from internal built win string vector.
m_WinDataStruct.reset(new COMDLG_FILTERSPEC[count]);
win_result.m_WinDataStruct.reset(new COMDLG_FILTERSPEC[count]);
for (size_t i = 0u; i < count; ++i) {
m_WinDataStruct[i].pszName = m_WinFilters[i].first.c_str();
m_WinDataStruct[i].pszSpec = m_WinFilters[i].second.c_str();
win_result.m_WinDataStruct[i].pszName = win_result.m_WinFilters[i].first.c_str();
win_result.m_WinDataStruct[i].pszSpec = win_result.m_WinFilters[i].second.c_str();
}
// set return value
filter_count = static_cast<UINT>(count);
filter_specs = m_WinDataStruct.get();
// everything is okey
return true;
}
#pragma endregion
#pragma region FileDialog
#pragma endregion