From 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d Mon Sep 17 00:00:00 2001 From: Jef Date: Tue, 24 Sep 2024 14:54:57 +0200 Subject: Initial community commit --- Src/Wasabi/api/wndmgr/autopopup.cpp | 157 ++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 Src/Wasabi/api/wndmgr/autopopup.cpp (limited to 'Src/Wasabi/api/wndmgr/autopopup.cpp') diff --git a/Src/Wasabi/api/wndmgr/autopopup.cpp b/Src/Wasabi/api/wndmgr/autopopup.cpp new file mode 100644 index 00000000..58212998 --- /dev/null +++ b/Src/Wasabi/api/wndmgr/autopopup.cpp @@ -0,0 +1,157 @@ +#include +#include "autopopup.h" + +static PtrListQuickSorted entries; +static int nid=0; + +int AutoPopup::registerGuid(int skinpartid, GUID g, const wchar_t *desc, const wchar_t *prefered_container, int required) +{ + if (desc == NULL || !*desc) desc = L"[????]"; + AutoPopupEntry *ape = new AutoPopupEntry(skinpartid, g, NULL, desc, prefered_container, required); + entries.addItem(ape); + return ape->getNid(); +} + +int AutoPopup::registerGroupId(int skinpartid, const wchar_t *groupid, const wchar_t *desc, const wchar_t *prefered_container, int required) { + if (desc == NULL || !*desc) desc = L"[????]"; + AutoPopupEntry *ape = new AutoPopupEntry(skinpartid, INVALID_GUID, groupid, desc, prefered_container, required); + entries.addItem(ape); + return ape->getNid(); +} + +int AutoPopup::getNumItems() { return entries.getNumItems(); } +AutoPopupEntry *AutoPopup::enumItem(int n) { return entries.enumItem(n); } + +int AutoPopup::getNumGroups() { + int n = 0; + foreach(entries) + AutoPopupEntry *e = entries.getfor(); + if (e->getGroupId() != NULL && e->getGuid() == INVALID_GUID) n++; + endfor; + return n; +} + +int AutoPopup::getNumGuids() { + int n = 0; + foreach(entries) + AutoPopupEntry *e = entries.getfor(); + if (e->getGroupId() == NULL && e->getGuid() != INVALID_GUID) n++; + endfor; + return n; +} + +const wchar_t *AutoPopup::enumGroup(int n) { + int c = 0; + foreach(entries) + AutoPopupEntry *e = entries.getfor(); + if (e->getGroupId() != NULL && e->getGuid() == INVALID_GUID) { + if (c == n) return e->getGroupId(); + c++; + } + endfor; + return NULL; +} + +GUID AutoPopup::enumGuid(int n) { + int c = 0; + foreach(entries) + AutoPopupEntry *e = entries.getfor(); + if (e->getGroupId() == NULL && e->getGuid() != INVALID_GUID) { + if (c == n) return e->getGuid(); + c++; + } + endfor; + return INVALID_GUID; +} + +const wchar_t *AutoPopup::enumGroupDescription(int n) { + int c = 0; + foreach(entries) + AutoPopupEntry *e = entries.getfor(); + if (e->getGroupId() != NULL && e->getGuid() == INVALID_GUID) { + if (c == n) return e->getDescription(); + c++; + } + endfor; + return NULL; +} + +const wchar_t *AutoPopup::enumGuidDescription(int n) { + int c = 0; + foreach(entries) + AutoPopupEntry *e = entries.getfor(); + if (e->getGroupId() == NULL && e->getGuid() != INVALID_GUID) { + if (c == n) return e->getDescription(); + c++; + } + endfor; + return NULL; +} + + +AutoPopupEntry *AutoPopup::getByDesc(const wchar_t *desc) { + foreach(entries) + if (!WCSICMP(desc, entries.getfor()->getDescription())) + return entries.getfor(); + endfor; + return NULL; +} + +void AutoPopup::reset() { entries.deleteAll(); nid = 0; } + +const wchar_t *AutoPopup::getDefaultContainerParams(const wchar_t *groupid, GUID g, int *flag) { + if (groupid == NULL) { // guid + for (int i=entries.getNumItems()-1;i>=0;i--) { + if (entries.enumItem(i)->getGuid() == g) { + if (flag != NULL) *flag = entries.enumItem(i)->getContainerHow(); + return entries.enumItem(i)->getPreferedContainer(); + } + } + } else { // groupid + for (int i=entries.getNumItems()-1;i>=0;i--) + { + if (WCSCASEEQLSAFE(entries.enumItem(i)->getGroupId(), groupid)) + { + if (flag != NULL) *flag = entries.enumItem(i)->getContainerHow(); + return entries.enumItem(i)->getPreferedContainer(); + } + } + } + return NULL; +} + +void AutoPopup::unregister(int id) { + for (int i=0;igetNid() == id) { + delete ape; + entries.removeByPos(i); + i--; + continue; + } + } +} + +void AutoPopup::removeSkinPart(int id) { + for (int i=0;igetSkinpart() == id) { + delete ape; + entries.removeByPos(i); + i--; + } + } +} + +int AutoPopup::allocNid() { return nid++; } + +void AutoPopup::removeAllAddons() { + for (int i=0;igetSkinpart() != SKINPARTID_NONE) { + delete ape; + entries.removeByPos(i); + i--; + } + } +} -- cgit