10#pragma warning(disable: 26454)
18 tabData::tabData(
const wstring& text,
const filesystem::path& pathToImage,
const function<
void()>& callback) :
20 pathToImage(pathToImage),
26 tabData::tabData(
const wstring& text,
const filesystem::path& pathToImage,
const string& functionName,
const string& moduleName) :
28 pathToImage(pathToImage),
29 functionName(functionName),
30 moduleName(moduleName)
36 throw exceptions::CantFindFunctionFromModuleException(functionName, moduleName, __FILE__, __FUNCTION__, __LINE__);
42 LRESULT BaseTabControl::windowMessagesHandle(HWND handle, UINT message, WPARAM wparam, LPARAM lparam,
bool& isUsed)
44 if (message == WM_NOTIFY)
46 NMHDR* notification =
reinterpret_cast<NMHDR*
>(lparam);
48 if (notification->code == TCN_SELCHANGE)
52 LRESULT currentTab = this->getSelectedTab();
56 callbacks[currentTab]();
71 standard_classes::tabControl,
74 styles::DefaultStyles(),
77 images(imagesWidth, imagesHeight)
89 return this->
insertText(this->
size(), text, functionName, moduleName);
96 item.mask = TCIF_TEXT;
97 item.pszText =
const_cast<wchar_t*
>(text.data());
98 item.cchTextMax =
static_cast<int>(text.size());
100 LRESULT result = SendMessageW(
handle, TCM_INSERTITEM, index,
reinterpret_cast<LPARAM
>(&item));
106 tabs.emplace(
tabs.begin() + index, text, filesystem::path(), *it);
116 item.mask = TCIF_TEXT;
117 item.pszText =
const_cast<wchar_t*
>(text.data());
118 item.cchTextMax =
static_cast<int>(text.size());
120 LRESULT result = SendMessageW(
handle, TCM_INSERTITEM, index,
reinterpret_cast<LPARAM
>(&item));
128 throw exceptions::CantFindFunctionFromModuleException(functionName, moduleName, __FILE__, __FUNCTION__, __LINE__);
133 tabs.emplace(
tabs.begin() + index, text, filesystem::path(), functionName, moduleName);
146 return this->
insertImage(this->
size(), pathToImage, functionName, moduleName);
151 if (!filesystem::exists(pathToImage))
153 throw exceptions::FileDoesNotExist(pathToImage, __FILE__, __FUNCTION__, __LINE__);
163 item.mask = TCIF_IMAGE;
164 item.iImage =
images[pathToImage];
166 LRESULT result = SendMessageW(
handle, TCM_INSERTITEM, index,
reinterpret_cast<LPARAM
>(&item));
172 tabs.emplace(
tabs.begin() + index, wstring(), pathToImage, *it);
178 LRESULT
BaseTabControl::insertImage(
size_t index,
const filesystem::path& pathToImage,
const string& functionName,
const string& moduleName)
180 if (!filesystem::exists(pathToImage))
182 throw exceptions::FileDoesNotExist(pathToImage, __FILE__, __FUNCTION__, __LINE__);
192 item.mask = TCIF_IMAGE;
193 item.iImage =
images[pathToImage];
195 LRESULT result = SendMessageW(
handle, TCM_INSERTITEM, index,
reinterpret_cast<LPARAM
>(&item));
203 throw exceptions::CantFindFunctionFromModuleException(functionName, moduleName, __FILE__, __FUNCTION__, __LINE__);
208 tabs.emplace(
tabs.begin() + index, wstring(), pathToImage, functionName, moduleName);
226 if (!filesystem::exists(pathToImage))
228 throw exceptions::FileDoesNotExist(pathToImage, __FILE__, __FUNCTION__, __LINE__);
238 item.mask = TCIF_TEXT | TCIF_IMAGE;
239 item.pszText =
const_cast<wchar_t*
>(text.data());
240 item.cchTextMax =
static_cast<int>(text.size());
241 item.iImage =
images[pathToImage];
243 LRESULT result = SendMessageW(
handle, TCM_INSERTITEM, index,
reinterpret_cast<LPARAM
>(&item));
249 tabs.emplace(
tabs.begin() + index, text, pathToImage, *it);
255 LRESULT
BaseTabControl::insertTextAndImage(
size_t index,
const wstring& text,
const filesystem::path& pathToImage,
const string& functionName,
const string& moduleName)
257 if (!filesystem::exists(pathToImage))
259 throw exceptions::FileDoesNotExist(pathToImage, __FILE__, __FUNCTION__, __LINE__);
269 item.mask = TCIF_TEXT | TCIF_IMAGE;
270 item.pszText =
const_cast<wchar_t*
>(text.data());
271 item.cchTextMax =
static_cast<int>(text.size());
272 item.iImage =
images[pathToImage];
274 LRESULT result = SendMessageW(
handle, TCM_INSERTITEM, index,
reinterpret_cast<LPARAM
>(&item));
282 throw exceptions::CantFindFunctionFromModuleException(functionName, moduleName, __FILE__, __FUNCTION__, __LINE__);
287 tabs.emplace(
tabs.begin() + index, text, pathToImage, functionName, moduleName);
295 bool result = SendMessageW(
handle, TCM_DELETEITEM,
static_cast<WPARAM
>(index), NULL);
309 bool result = SendMessageW(
handle, TCM_DELETEALLITEMS, NULL, NULL);
323 return SendMessageW(
handle, TCM_GETITEMCOUNT, NULL, NULL);
326 bool BaseTabControl::setItem(
size_t index,
const function<
void()>& callback,
const wstring& text,
const filesystem::path& pathToImage)
328 if (!pathToImage.empty() && !filesystem::exists(pathToImage))
337 item.mask |= TCIF_TEXT;
339 item.pszText =
const_cast<wchar_t*
>(text.data());
340 item.cchTextMax =
static_cast<int>(text.size());
343 if (!pathToImage.empty())
350 item.mask |= TCIF_IMAGE;
352 item.iImage =
images[pathToImage];
355 bool result = SendMessageW(
handle, TCM_SETITEM, index,
reinterpret_cast<LPARAM
>(&item));
361 tabs[index] =
tabData(text, pathToImage, callback);
367 bool BaseTabControl::setItem(
size_t index,
const string& functionName,
const string& moduleName,
const wstring& text,
const filesystem::path& pathToImage)
370 const HMODULE& module = instance.getModules().at(moduleName);
376 throw exceptions::CantFindFunctionFromModuleException(functionName, moduleName, __FILE__, __FUNCTION__, __LINE__);
379 if (!pathToImage.empty() && !filesystem::exists(pathToImage))
381 throw exceptions::FileDoesNotExist(pathToImage, __FILE__, __FUNCTION__, __LINE__);
388 item.mask |= TCIF_TEXT;
390 item.pszText =
const_cast<wchar_t*
>(text.data());
391 item.cchTextMax =
static_cast<int>(text.size());
394 if (!pathToImage.empty())
401 item.mask |= TCIF_IMAGE;
403 item.iImage =
images[pathToImage];
406 bool result = SendMessageW(
handle, TCM_SETITEM, index,
reinterpret_cast<LPARAM
>(&item));
412 tabs[index] =
tabData(text, pathToImage, functionName, moduleName);
420 return SendMessageW(
handle, TCM_SETCURSEL,
static_cast<WPARAM
>(index), NULL);
425 return tabs.at(index);
430 return SendMessageW(
handle, TCM_GETCURSEL, NULL, NULL);
455 using json::utility::jsonObject;
459 vector<jsonObject> jsonTabs;
465 auto serializeText = [
this](jsonObject& object,
const tabData& data)
467 if (data.text.empty())
472 object.data.push_back({
"tabText"s,
utility::to_string(data.text, ISerializable::getCodepage()) });
474 auto serializePathToImage = [](jsonObject& object,
const tabData& data)
476 if (data.pathToImage.empty())
481 object.data.push_back({
"tabImagePath"s, data.pathToImage.string() });
483 auto serializeCallback = [](jsonObject& object,
const tabData& data)
485 object.data.push_back({
"functionName"s, data.functionName });
486 object.data.push_back({
"moduleName"s, data.moduleName });
490 for (
const auto& i :
tabs)
494 if (i.functionName.size())
496 serializeText(
object, i);
498 serializePathToImage(
object, i);
500 serializeCallback(
object, i);
502 json::utility::appendArray(move(
object), jsonTabs);
506 serializeText(
object, i);
508 serializePathToImage(
object, i);
510 json::utility::appendArray(move(
object), jsonTabs);
514 current.data.push_back({
"tabs"s, move(jsonTabs) });
Base class for all windows, controls, etc.
virtual json::JSONBuilder getStructure() const override
const std::wstring windowName
Base class for all windows that has children windows.
virtual LRESULT insertText(size_t index, const std::wstring &text, const std::function< void()> &onClick) final
virtual json::JSONBuilder getStructure() const override
virtual uint16_t getImagesWidth() const final
virtual bool setItem(size_t index, const std::function< void()> &callback, const std::wstring &text=L"", const std::filesystem::path &pathToImage=L"") final
virtual LRESULT getSelectedTab() const final
virtual const tabData & getItem(size_t index) const final
virtual bool removeTab(size_t index) final
virtual LRESULT setSelection(size_t index) final
virtual LRESULT appendImage(const std::filesystem::path &pathToImage, const std::function< void()> &onClick) final
virtual bool clear() final
virtual LRESULT insertTextAndImage(size_t index, const std::wstring &text, const std::filesystem::path &pathToImage, const std::function< void()> &onClick) final
virtual LRESULT insertImage(size_t index, const std::filesystem::path &pathToImage, const std::function< void()> &onClick) final
std::vector< std::function< void()> > callbacks
virtual LRESULT appendText(const std::wstring &text, const std::function< void()> &onClick) final
virtual size_t size() const final
virtual LRESULT appendTextAndImage(const std::wstring &text, const std::filesystem::path &pathToImage, const std::function< void()> &onClick) final
utility::ImagesHolder images
virtual void setTextColor(uint8_t red, uint8_t green, uint8_t blue) final override
Not implemented.
virtual void setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue) final override
Not implemented.
std::vector< tabData > tabs
virtual uint16_t getImagesHeight() const final
const std::unordered_map< std::string, std::string > & getModulesPaths() const
Get all loaded modules paths.
static GUIFramework & get()
Singleton instance access.
Throws by asset finding methods.
virtual uint16_t getImagesWidth() const final
virtual HIMAGELIST getImageList() const final
virtual uint16_t getImagesHeight() const final
virtual bool contains(const std::filesystem::path &pathToImage) const final
uint16_t addImage(const std::filesystem::path &pathToImage) override
void throwNotImplementedException(string_view methodName, string_view className)
string to_string(wstring_view stringToConvert, uint32_t codepage)
void(*)() onClickSignature
Default on click signature.
BaseTabControl::tabData tabData
All settings for windows.