working keydown
This commit is contained in:
parent
7350ce0bea
commit
6210e9c99b
12 changed files with 975 additions and 401 deletions
|
|
@ -20,8 +20,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
|
||||
export module Crafter.CppDOM:Bindings;
|
||||
import std;
|
||||
import :EventTypes;
|
||||
|
||||
export namespace Crafter::CppDOM::Bindings {
|
||||
export namespace Crafter::CppDOMBindings {
|
||||
int clickHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(void)>>* clickHandlers = new std::unordered_map<int, std::function<void(void)>>();
|
||||
|
||||
|
|
@ -34,6 +35,12 @@ export namespace Crafter::CppDOM::Bindings {
|
|||
int mouseMoveHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(void)>>* mouseMoveHandlers = new std::unordered_map<int, std::function<void(void)>>();
|
||||
|
||||
int mouseDownHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(void)>>* mouseDownHandlers = new std::unordered_map<int, std::function<void(void)>>();
|
||||
|
||||
int mouseUpHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(void)>>* mouseUpHandlers = new std::unordered_map<int, std::function<void(void)>>();
|
||||
|
||||
int focusHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(void)>>* focusHandlers = new std::unordered_map<int, std::function<void(void)>>();
|
||||
|
||||
|
|
@ -41,47 +48,53 @@ export namespace Crafter::CppDOM::Bindings {
|
|||
std::unordered_map<int, std::function<void(void)>>* blurHandlers = new std::unordered_map<int, std::function<void(void)>>();
|
||||
|
||||
int keyDownHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(void)>>* keyDownHandlers = new std::unordered_map<int, std::function<void(void)>>();
|
||||
std::unordered_map<int, std::function<void(Crafter::KeyboardEvent)>>* keyDownHandlers = new std::unordered_map<int, std::function<void(Crafter::KeyboardEvent)>>();
|
||||
|
||||
int keyUpHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(void)>>* keyUpHandlers = new std::unordered_map<int, std::function<void(void)>>();
|
||||
std::unordered_map<int, std::function<void(Crafter::KeyboardEvent)>>* keyUpHandlers = new std::unordered_map<int, std::function<void(Crafter::KeyboardEvent)>>();
|
||||
|
||||
int keyPressHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(void)>>* keyPressHandlers = new std::unordered_map<int, std::function<void(void)>>();
|
||||
std::unordered_map<int, std::function<void(Crafter::KeyboardEvent)>>* keyPressHandlers = new std::unordered_map<int, std::function<void(Crafter::KeyboardEvent)>>();
|
||||
|
||||
int changeHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(void)>>* changeHandlers = new std::unordered_map<int, std::function<void(void)>>();
|
||||
std::unordered_map<int, std::function<void(Crafter::ChangeEvent)>>* changeHandlers = new std::unordered_map<int, std::function<void(Crafter::ChangeEvent)>>();
|
||||
|
||||
int submitHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(void)>>* submitHandlers = new std::unordered_map<int, std::function<void(void)>>();
|
||||
|
||||
int inputHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(void)>>* inputHandlers = new std::unordered_map<int, std::function<void(void)>>();
|
||||
|
||||
int loadHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(void)>>* loadHandlers = new std::unordered_map<int, std::function<void(void)>>();
|
||||
|
||||
int errorHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(void)>>* errorHandlers = new std::unordered_map<int, std::function<void(void)>>();
|
||||
std::unordered_map<int, std::function<void(Crafter::InputEvent)>>* inputHandlers = new std::unordered_map<int, std::function<void(Crafter::InputEvent)>>();
|
||||
|
||||
int resizeHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(void)>>* resizeHandlers = new std::unordered_map<int, std::function<void(void)>>();
|
||||
std::unordered_map<int, std::function<void(Crafter::ResizeEvent)>>* resizeHandlers = new std::unordered_map<int, std::function<void(Crafter::ResizeEvent)>>();
|
||||
|
||||
int scrollHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(void)>>* scrollHandlers = new std::unordered_map<int, std::function<void(void)>>();
|
||||
std::unordered_map<int, std::function<void(Crafter::ScrollEvent)>>* scrollHandlers = new std::unordered_map<int, std::function<void(Crafter::ScrollEvent)>>();
|
||||
|
||||
int contextMenuHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(void)>>* contextMenuHandlers = new std::unordered_map<int, std::function<void(void)>>();
|
||||
std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>* contextMenuHandlers = new std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>();
|
||||
|
||||
int dragStartHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(void)>>* dragStartHandlers = new std::unordered_map<int, std::function<void(void)>>();
|
||||
std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>* dragStartHandlers = new std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>();
|
||||
|
||||
int dragEndHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(void)>>* dragEndHandlers = new std::unordered_map<int, std::function<void(void)>>();
|
||||
std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>* dragEndHandlers = new std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>();
|
||||
|
||||
int dropHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(void)>>* dropHandlers = new std::unordered_map<int, std::function<void(void)>>();
|
||||
|
||||
std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>* dropHandlers = new std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>();
|
||||
|
||||
int wheelHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(Crafter::WheelEvent)>>* wheelHandlers = new std::unordered_map<int, std::function<void(Crafter::WheelEvent)>>();
|
||||
|
||||
int dragOverHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>* dragOverHandlers = new std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>();
|
||||
|
||||
int dragEnterHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>* dragEnterHandlers = new std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>();
|
||||
|
||||
int dragLeaveHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>* dragLeaveHandlers = new std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>();
|
||||
|
||||
__attribute__((import_module("env"), import_name("freeJs"))) void FreeJs(void* ptr);
|
||||
__attribute__((import_module("env"), import_name("getElementById"))) void* GetElementById(const char* id, std::size_t idLenght);
|
||||
void* GetElementById(const std::string_view id) {
|
||||
|
|
@ -105,6 +118,12 @@ export namespace Crafter::CppDOM::Bindings {
|
|||
__attribute__((import_module("env"), import_name("addMouseMoveListener"))) void AddMouseMoveListener(void* ptr, int id);
|
||||
__attribute__((import_module("env"), import_name("removeMouseMoveListener"))) void RemoveMouseMoveListener(void* ptr, int id);
|
||||
|
||||
__attribute__((import_module("env"), import_name("addMouseDownListener"))) void AddMouseDownListener(void* ptr, int id);
|
||||
__attribute__((import_module("env"), import_name("removeMouseDownListener"))) void RemoveMouseDownListener(void* ptr, int id);
|
||||
|
||||
__attribute__((import_module("env"), import_name("addMouseUpListener"))) void AddMouseUpListener(void* ptr, int id);
|
||||
__attribute__((import_module("env"), import_name("removeMouseUpListener"))) void RemoveMouseUpListener(void* ptr, int id);
|
||||
|
||||
__attribute__((import_module("env"), import_name("addFocusListener"))) void AddFocusListener(void* ptr, int id);
|
||||
__attribute__((import_module("env"), import_name("removeFocusListener"))) void RemoveFocusListener(void* ptr, int id);
|
||||
|
||||
|
|
@ -129,12 +148,6 @@ export namespace Crafter::CppDOM::Bindings {
|
|||
__attribute__((import_module("env"), import_name("addInputListener"))) void AddInputListener(void* ptr, int id);
|
||||
__attribute__((import_module("env"), import_name("removeInputListener"))) void RemoveInputListener(void* ptr, int id);
|
||||
|
||||
__attribute__((import_module("env"), import_name("addLoadListener"))) void AddLoadListener(void* ptr, int id);
|
||||
__attribute__((import_module("env"), import_name("removeLoadListener"))) void RemoveLoadListener(void* ptr, int id);
|
||||
|
||||
__attribute__((import_module("env"), import_name("addErrorListener"))) void AddErrorListener(void* ptr, int id);
|
||||
__attribute__((import_module("env"), import_name("removeErrorListener"))) void RemoveErrorListener(void* ptr, int id);
|
||||
|
||||
__attribute__((import_module("env"), import_name("addResizeListener"))) void AddResizeListener(void* ptr, int id);
|
||||
__attribute__((import_module("env"), import_name("removeResizeListener"))) void RemoveResizeListener(void* ptr, int id);
|
||||
|
||||
|
|
@ -152,86 +165,217 @@ export namespace Crafter::CppDOM::Bindings {
|
|||
|
||||
__attribute__((import_module("env"), import_name("addDropListener"))) void AddDropListener(void* ptr, int id);
|
||||
__attribute__((import_module("env"), import_name("removeDropListener"))) void RemoveDropListener(void* ptr, int id);
|
||||
|
||||
__attribute__((import_module("env"), import_name("addWheelListener"))) void AddWheelListener(void* ptr, int id);
|
||||
__attribute__((import_module("env"), import_name("removeWheelListener"))) void RemoveWheelListener(void* ptr, int id);
|
||||
|
||||
__attribute__((import_module("env"), import_name("addDragOverListener"))) void AddDragOverListener(void* ptr, int id);
|
||||
__attribute__((import_module("env"), import_name("removeDragOverListener"))) void RemoveDragOverListener(void* ptr, int id);
|
||||
|
||||
__attribute__((import_module("env"), import_name("addDragEnterListener"))) void AddDragEnterListener(void* ptr, int id);
|
||||
__attribute__((import_module("env"), import_name("removeDragEnterListener"))) void RemoveDragEnterListener(void* ptr, int id);
|
||||
|
||||
__attribute__((import_module("env"), import_name("addDragLeaveListener"))) void AddDragLeaveListener(void* ptr, int id);
|
||||
__attribute__((import_module("env"), import_name("removeDragLeaveListener"))) void RemoveDragLeaveListener(void* ptr, int id);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
__attribute__((export_name("ExecuteClickHandler"))) void ExecuteClickHandler(int a) {
|
||||
Crafter::CppDOM::Bindings::clickHandlers->find(static_cast<int>(a))->second();
|
||||
__attribute__((export_name("WasmAlloc"))) void* WasmAlloc(std::int32_t size) {
|
||||
std::cout << std::format("Alloc: {}", size) << std::endl;
|
||||
return std::malloc(size);
|
||||
}
|
||||
|
||||
__attribute__((export_name("WasmFree"))) void WasmFree(void* ptr) {
|
||||
std::free(ptr);
|
||||
}
|
||||
|
||||
__attribute__((export_name("ExecuteClickHandler"))) void ExecuteClickHandler(std::int32_t handlerID) {
|
||||
Crafter::CppDOMBindings::clickHandlers->find(handlerID)->second();
|
||||
}
|
||||
|
||||
__attribute__((export_name("ExecuteMouseOverHandler"))) void ExecuteMouseOverHandler(int a) {
|
||||
Crafter::CppDOM::Bindings::mouseOverHandlers->find(static_cast<int>(a))->second();
|
||||
__attribute__((export_name("ExecuteMouseOverHandler"))) void ExecuteMouseOverHandler(std::int32_t handlerID) {
|
||||
Crafter::CppDOMBindings::mouseOverHandlers->find(handlerID)->second();
|
||||
}
|
||||
|
||||
__attribute__((export_name("ExecuteMouseOutHandler"))) void ExecuteMouseOutHandler(int a) {
|
||||
Crafter::CppDOM::Bindings::mouseOutHandlers->find(static_cast<int>(a))->second();
|
||||
__attribute__((export_name("ExecuteMouseOutHandler"))) void ExecuteMouseOutHandler(std::int32_t handlerID) {
|
||||
Crafter::CppDOMBindings::mouseOutHandlers->find(handlerID)->second();
|
||||
}
|
||||
|
||||
__attribute__((export_name("ExecuteMouseMoveHandler"))) void ExecuteMouseMoveHandler(int a) {
|
||||
Crafter::CppDOM::Bindings::mouseMoveHandlers->find(static_cast<int>(a))->second();
|
||||
__attribute__((export_name("ExecuteMouseMoveHandler"))) void ExecuteMouseMoveHandler(std::int32_t handlerID) {
|
||||
Crafter::CppDOMBindings::mouseMoveHandlers->find(handlerID)->second();
|
||||
}
|
||||
|
||||
__attribute__((export_name("ExecuteFocusHandler"))) void ExecuteFocusHandler(int a) {
|
||||
Crafter::CppDOM::Bindings::focusHandlers->find(static_cast<int>(a))->second();
|
||||
__attribute__((export_name("ExecuteMouseDownHandler"))) void ExecuteMouseDownHandler(std::int32_t handlerID) {
|
||||
Crafter::CppDOMBindings::mouseDownHandlers->find(handlerID)->second();
|
||||
}
|
||||
|
||||
__attribute__((export_name("ExecuteBlurHandler"))) void ExecuteBlurHandler(int a) {
|
||||
Crafter::CppDOM::Bindings::blurHandlers->find(static_cast<int>(a))->second();
|
||||
__attribute__((export_name("ExecuteMouseUpHandler"))) void ExecuteMouseUpHandler(std::int32_t handlerID) {
|
||||
Crafter::CppDOMBindings::mouseUpHandlers->find(handlerID)->second();
|
||||
}
|
||||
|
||||
__attribute__((export_name("ExecuteKeyDownHandler"))) void ExecuteKeyDownHandler(int a, const char* key, const char* code, int keyCode) {
|
||||
Crafter::CppDOM::Bindings::keyDownHandlers->find(static_cast<int>(a))->second();
|
||||
__attribute__((export_name("ExecuteFocusHandler"))) void ExecuteFocusHandler(std::int32_t handlerID) {
|
||||
Crafter::CppDOMBindings::focusHandlers->find(handlerID)->second();
|
||||
}
|
||||
|
||||
__attribute__((export_name("ExecuteKeyUpHandler"))) void ExecuteKeyUpHandler(int a, const char* key, const char* code, int keyCode) {
|
||||
Crafter::CppDOM::Bindings::keyUpHandlers->find(static_cast<int>(a))->second();
|
||||
__attribute__((export_name("ExecuteBlurHandler"))) void ExecuteBlurHandler(std::int32_t handlerID) {
|
||||
Crafter::CppDOMBindings::blurHandlers->find(handlerID)->second();
|
||||
}
|
||||
|
||||
__attribute__((export_name("ExecuteKeyPressHandler"))) void ExecuteKeyPressHandler(int a, const char* key, const char* code, int keyCode) {
|
||||
Crafter::CppDOM::Bindings::keyPressHandlers->find(static_cast<int>(a))->second();
|
||||
__attribute__((export_name("ExecuteKeyDownHandler"))) void ExecuteKeyDownHandler(std::int32_t handlerID, const char* key, std::int32_t keyCode, bool altKey, bool ctrlKey, bool shiftKey, bool metaKey) {
|
||||
Crafter::CppDOMBindings::keyDownHandlers->find(handlerID)->second(Crafter::KeyboardEvent(key, keyCode, altKey, ctrlKey, shiftKey, metaKey));
|
||||
}
|
||||
|
||||
__attribute__((export_name("ExecuteChangeHandler"))) void ExecuteChangeHandler(int a) {
|
||||
Crafter::CppDOM::Bindings::changeHandlers->find(static_cast<int>(a))->second();
|
||||
__attribute__((export_name("ExecuteKeyUpHandler"))) void ExecuteKeyUpHandler(std::int32_t handlerID, const char* key, std::int32_t keyCode, bool altKey, bool ctrlKey, bool shiftKey, bool metaKey) {
|
||||
Crafter::CppDOMBindings::keyUpHandlers->find(handlerID)->second(Crafter::KeyboardEvent(key, keyCode, altKey, ctrlKey, shiftKey, metaKey));
|
||||
}
|
||||
|
||||
__attribute__((export_name("ExecuteSubmitHandler"))) void ExecuteSubmitHandler(int a) {
|
||||
Crafter::CppDOM::Bindings::submitHandlers->find(static_cast<int>(a))->second();
|
||||
__attribute__((export_name("ExecuteKeyPressHandler"))) void ExecuteKeyPressHandler(std::int32_t handlerID, const char* key, std::int32_t keyCode, bool altKey, bool ctrlKey, bool shiftKey, bool metaKey) {
|
||||
Crafter::CppDOMBindings::keyPressHandlers->find(handlerID)->second(Crafter::KeyboardEvent(key, keyCode, altKey, ctrlKey, shiftKey, metaKey));
|
||||
}
|
||||
|
||||
__attribute__((export_name("ExecuteInputHandler"))) void ExecuteInputHandler(int a) {
|
||||
Crafter::CppDOM::Bindings::inputHandlers->find(static_cast<int>(a))->second();
|
||||
__attribute__((export_name("ExecuteChangeHandler"))) void ExecuteChangeHandler(std::int32_t handlerID, const char* value) {
|
||||
Crafter::ChangeEvent event;
|
||||
event.value = value;
|
||||
Crafter::CppDOMBindings::changeHandlers->find(handlerID)->second(event);
|
||||
}
|
||||
|
||||
__attribute__((export_name("ExecuteLoadHandler"))) void ExecuteLoadHandler(int a) {
|
||||
Crafter::CppDOM::Bindings::loadHandlers->find(static_cast<int>(a))->second();
|
||||
__attribute__((export_name("ExecuteSubmitHandler"))) void ExecuteSubmitHandler(std::int32_t handlerID) {
|
||||
Crafter::CppDOMBindings::submitHandlers->find(handlerID)->second();
|
||||
}
|
||||
|
||||
__attribute__((export_name("ExecuteErrorHandler"))) void ExecuteErrorHandler(int a) {
|
||||
Crafter::CppDOM::Bindings::errorHandlers->find(static_cast<int>(a))->second();
|
||||
__attribute__((export_name("ExecuteInputHandler"))) void ExecuteInputHandler(std::int32_t handlerID, const char* data, bool isComposing) {
|
||||
Crafter::InputEvent event;
|
||||
event.data = data;
|
||||
event.isComposing = isComposing;
|
||||
Crafter::CppDOMBindings::inputHandlers->find(handlerID)->second(event);
|
||||
}
|
||||
|
||||
__attribute__((export_name("ExecuteResizeHandler"))) void ExecuteResizeHandler(int a) {
|
||||
Crafter::CppDOM::Bindings::resizeHandlers->find(static_cast<int>(a))->second();
|
||||
__attribute__((export_name("ExecuteResizeHandler"))) void ExecuteResizeHandler(std::int32_t handlerID, unsigned int width, unsigned int height) {
|
||||
Crafter::ResizeEvent event;
|
||||
event.width = width;
|
||||
event.height = height;
|
||||
Crafter::CppDOMBindings::resizeHandlers->find(handlerID)->second(event);
|
||||
}
|
||||
|
||||
__attribute__((export_name("ExecuteScrollHandler"))) void ExecuteScrollHandler(int a) {
|
||||
Crafter::CppDOM::Bindings::scrollHandlers->find(static_cast<int>(a))->second();
|
||||
__attribute__((export_name("ExecuteScrollHandler"))) void ExecuteScrollHandler(std::int32_t handlerID, double scrollX, double scrollY) {
|
||||
Crafter::ScrollEvent event;
|
||||
event.scrollX = scrollX;
|
||||
event.scrollY = scrollY;
|
||||
Crafter::CppDOMBindings::scrollHandlers->find(handlerID)->second(event);
|
||||
}
|
||||
|
||||
__attribute__((export_name("ExecuteContextMenuHandler"))) void ExecuteContextMenuHandler(int a) {
|
||||
Crafter::CppDOM::Bindings::contextMenuHandlers->find(static_cast<int>(a))->second();
|
||||
__attribute__((export_name("ExecuteContextMenuHandler"))) void ExecuteContextMenuHandler(std::int32_t handlerID, double clientX, double clientY, double screenX, double screenY, int button, bool altKey, bool ctrlKey, bool shiftKey, bool metaKey) {
|
||||
Crafter::MouseEvent event;
|
||||
event.clientX = clientX;
|
||||
event.clientY = clientY;
|
||||
event.screenX = screenX;
|
||||
event.screenY = screenY;
|
||||
event.button = button;
|
||||
event.altKey = altKey;
|
||||
event.ctrlKey = ctrlKey;
|
||||
event.shiftKey = shiftKey;
|
||||
event.metaKey = metaKey;
|
||||
Crafter::CppDOMBindings::contextMenuHandlers->find(handlerID)->second(event);
|
||||
}
|
||||
|
||||
__attribute__((export_name("ExecuteDragStartHandler"))) void ExecuteDragStartHandler(int a) {
|
||||
Crafter::CppDOM::Bindings::dragStartHandlers->find(static_cast<int>(a))->second();
|
||||
__attribute__((export_name("ExecuteDragStartHandler"))) void ExecuteDragStartHandler(std::int32_t handlerID, double clientX, double clientY, double screenX, double screenY, int button, bool altKey, bool ctrlKey, bool shiftKey, bool metaKey) {
|
||||
Crafter::MouseEvent event;
|
||||
event.clientX = clientX;
|
||||
event.clientY = clientY;
|
||||
event.screenX = screenX;
|
||||
event.screenY = screenY;
|
||||
event.button = button;
|
||||
event.altKey = altKey;
|
||||
event.ctrlKey = ctrlKey;
|
||||
event.shiftKey = shiftKey;
|
||||
event.metaKey = metaKey;
|
||||
Crafter::CppDOMBindings::dragStartHandlers->find(handlerID)->second(event);
|
||||
}
|
||||
|
||||
__attribute__((export_name("ExecuteDragEndHandler"))) void ExecuteDragEndHandler(int a) {
|
||||
Crafter::CppDOM::Bindings::dragEndHandlers->find(static_cast<int>(a))->second();
|
||||
__attribute__((export_name("ExecuteDragEndHandler"))) void ExecuteDragEndHandler(std::int32_t handlerID, double clientX, double clientY, double screenX, double screenY, int button, bool altKey, bool ctrlKey, bool shiftKey, bool metaKey) {
|
||||
Crafter::MouseEvent event;
|
||||
event.clientX = clientX;
|
||||
event.clientY = clientY;
|
||||
event.screenX = screenX;
|
||||
event.screenY = screenY;
|
||||
event.button = button;
|
||||
event.altKey = altKey;
|
||||
event.ctrlKey = ctrlKey;
|
||||
event.shiftKey = shiftKey;
|
||||
event.metaKey = metaKey;
|
||||
Crafter::CppDOMBindings::dragEndHandlers->find(handlerID)->second(event);
|
||||
}
|
||||
|
||||
__attribute__((export_name("ExecuteDropHandler"))) void ExecuteDropHandler(int a) {
|
||||
Crafter::CppDOM::Bindings::dropHandlers->find(static_cast<int>(a))->second();
|
||||
__attribute__((export_name("ExecuteDropHandler"))) void ExecuteDropHandler(std::int32_t handlerID, double clientX, double clientY, double screenX, double screenY, int button, bool altKey, bool ctrlKey, bool shiftKey, bool metaKey) {
|
||||
Crafter::MouseEvent event;
|
||||
event.clientX = clientX;
|
||||
event.clientY = clientY;
|
||||
event.screenX = screenX;
|
||||
event.screenY = screenY;
|
||||
event.button = button;
|
||||
event.altKey = altKey;
|
||||
event.ctrlKey = ctrlKey;
|
||||
event.shiftKey = shiftKey;
|
||||
event.metaKey = metaKey;
|
||||
Crafter::CppDOMBindings::dropHandlers->find(handlerID)->second(event);
|
||||
}
|
||||
|
||||
__attribute__((export_name("ExecuteWheelHandler"))) void ExecuteWheelHandler(std::int32_t handlerID, double deltaX, double deltaY, double deltaZ, int deltaMode, double clientX, double clientY, double screenX, double screenY, int button, bool altKey, bool ctrlKey, bool shiftKey, bool metaKey) {
|
||||
Crafter::WheelEvent event;
|
||||
event.deltaX = deltaX;
|
||||
event.deltaY = deltaY;
|
||||
event.deltaZ = deltaZ;
|
||||
event.clientX = clientX;
|
||||
event.clientY = clientY;
|
||||
event.screenX = screenX;
|
||||
event.screenY = screenY;
|
||||
event.button = button;
|
||||
event.altKey = altKey;
|
||||
event.ctrlKey = ctrlKey;
|
||||
event.shiftKey = shiftKey;
|
||||
event.metaKey = metaKey;
|
||||
Crafter::CppDOMBindings::wheelHandlers->find(handlerID)->second(event);
|
||||
}
|
||||
|
||||
__attribute__((export_name("ExecuteDragOverHandler"))) void ExecuteDragOverHandler(std::int32_t handlerID, double clientX, double clientY, double screenX, double screenY, int button, bool altKey, bool ctrlKey, bool shiftKey, bool metaKey) {
|
||||
Crafter::MouseEvent event;
|
||||
event.clientX = clientX;
|
||||
event.clientY = clientY;
|
||||
event.screenX = screenX;
|
||||
event.screenY = screenY;
|
||||
event.button = button;
|
||||
event.altKey = altKey;
|
||||
event.ctrlKey = ctrlKey;
|
||||
event.shiftKey = shiftKey;
|
||||
event.metaKey = metaKey;
|
||||
Crafter::CppDOMBindings::dragOverHandlers->find(handlerID)->second(event);
|
||||
}
|
||||
|
||||
__attribute__((export_name("ExecuteDragEnterHandler"))) void ExecuteDragEnterHandler(std::int32_t handlerID, double clientX, double clientY, double screenX, double screenY, int button, bool altKey, bool ctrlKey, bool shiftKey, bool metaKey) {
|
||||
Crafter::MouseEvent event;
|
||||
event.clientX = clientX;
|
||||
event.clientY = clientY;
|
||||
event.screenX = screenX;
|
||||
event.screenY = screenY;
|
||||
event.button = button;
|
||||
event.altKey = altKey;
|
||||
event.ctrlKey = ctrlKey;
|
||||
event.shiftKey = shiftKey;
|
||||
event.metaKey = metaKey;
|
||||
Crafter::CppDOMBindings::dragEnterHandlers->find(handlerID)->second(event);
|
||||
}
|
||||
|
||||
__attribute__((export_name("ExecuteDragLeaveHandler"))) void ExecuteDragLeaveHandler(std::int32_t handlerID, double clientX, double clientY, double screenX, double screenY, int button, bool altKey, bool ctrlKey, bool shiftKey, bool metaKey) {
|
||||
Crafter::MouseEvent event;
|
||||
event.clientX = clientX;
|
||||
event.clientY = clientY;
|
||||
event.screenX = screenX;
|
||||
event.screenY = screenY;
|
||||
event.button = button;
|
||||
event.altKey = altKey;
|
||||
event.ctrlKey = ctrlKey;
|
||||
event.shiftKey = shiftKey;
|
||||
event.metaKey = metaKey;
|
||||
Crafter::CppDOMBindings::dragLeaveHandlers->find(handlerID)->second(event);
|
||||
}
|
||||
}
|
||||
73
interfaces/Crafter.CppDOM-EventTypes.cppm
Normal file
73
interfaces/Crafter.CppDOM-EventTypes.cppm
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
Crafter.CppDOM
|
||||
Copyright (C) 2025 Catcrafts
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
export module Crafter.CppDOM:EventTypes;
|
||||
import std;
|
||||
|
||||
export namespace Crafter {
|
||||
struct KeyboardEvent {
|
||||
std::string key;
|
||||
std::uint_fast8_t keyCode;
|
||||
bool altKey;
|
||||
bool ctrlKey;
|
||||
bool shiftKey;
|
||||
bool metaKey;
|
||||
KeyboardEvent(const char* key, std::int32_t keyCode, bool altKey, bool ctrlKey, bool shiftKey, bool metaKey) : key(key), keyCode(keyCode), altKey(altKey), ctrlKey(ctrlKey), shiftKey(shiftKey), metaKey(metaKey) {}
|
||||
};
|
||||
|
||||
// Mouse event structure
|
||||
struct MouseEvent {
|
||||
double clientX;
|
||||
double clientY;
|
||||
double screenX;
|
||||
double screenY;
|
||||
std::uint_fast32_t button;
|
||||
std::uint_fast32_t buttons;
|
||||
bool altKey;
|
||||
bool ctrlKey;
|
||||
bool shiftKey;
|
||||
bool metaKey;
|
||||
};
|
||||
|
||||
struct InputEvent {
|
||||
std::string data;
|
||||
bool isComposing;
|
||||
};
|
||||
|
||||
struct WheelEvent : public MouseEvent {
|
||||
double deltaX;
|
||||
double deltaY;
|
||||
double deltaZ;
|
||||
};
|
||||
|
||||
struct ResizeEvent {
|
||||
std::uint_fast32_t width;
|
||||
std::uint_fast32_t height;
|
||||
};
|
||||
|
||||
struct ScrollEvent {
|
||||
double scrollX;
|
||||
double scrollY;
|
||||
};
|
||||
|
||||
struct ChangeEvent {
|
||||
std::string value;
|
||||
};
|
||||
}
|
||||
|
|
@ -21,311 +21,375 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
export module Crafter.CppDOM:HtmlElement;
|
||||
import std;
|
||||
import :Bindings;
|
||||
import :EventTypes;
|
||||
|
||||
namespace Crafter {
|
||||
export class HtmlElement {
|
||||
public:
|
||||
void* const ptr;
|
||||
std::vector<int> handlers;
|
||||
HtmlElement(const std::string_view id): ptr(CppDOM::Bindings::GetElementById(id)) {
|
||||
std::vector<std::int32_t> handlers;
|
||||
HtmlElement(const std::string_view id): ptr(CppDOMBindings::GetElementById(id)) {
|
||||
|
||||
}
|
||||
HtmlElement(const std::string_view id, const std::string_view html): ptr(CppDOM::Bindings::GetElementById(id)) {
|
||||
CppDOM::Bindings::SetInnerHTML(ptr, html);
|
||||
HtmlElement(const std::string_view id, const std::string_view html): ptr(CppDOMBindings::GetElementById(id)) {
|
||||
CppDOMBindings::SetInnerHTML(ptr, html);
|
||||
}
|
||||
void SetInnerHTML(const std::string_view& html) {
|
||||
CppDOM::Bindings::SetInnerHTML(ptr, html);
|
||||
void SetInnerHTML(const std::string_view html) {
|
||||
CppDOMBindings::SetInnerHTML(ptr, html);
|
||||
}
|
||||
|
||||
// Event handling methods
|
||||
int AddClickListener(std::function<void(void)> callback) {
|
||||
int id = CppDOM::Bindings::clickHandlerMaxId++;
|
||||
// Event handling methods with event data
|
||||
|
||||
// Mouse Events
|
||||
std::int32_t AddClickListener(std::function<void(void)> callback) {
|
||||
std::int32_t id = CppDOMBindings::clickHandlerMaxId++;
|
||||
handlers.push_back(id);
|
||||
CppDOM::Bindings::clickHandlers->insert({id, callback});
|
||||
CppDOM::Bindings::AddClickListener(ptr, id);
|
||||
CppDOMBindings::clickHandlers->insert({id, callback});
|
||||
CppDOMBindings::AddClickListener(ptr, id);
|
||||
return id;
|
||||
}
|
||||
|
||||
void RemoveClickListener(int id) {
|
||||
void RemoveClickListener(std::int32_t id) {
|
||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
||||
CppDOM::Bindings::clickHandlers->erase(id);
|
||||
CppDOM::Bindings::RemoveClickListener(ptr, id);
|
||||
CppDOMBindings::clickHandlers->erase(id);
|
||||
CppDOMBindings::RemoveClickListener(ptr, id);
|
||||
}
|
||||
|
||||
int AddMouseOverListener(std::function<void(void)> callback) {
|
||||
int id = CppDOM::Bindings::mouseOverHandlerMaxId++;
|
||||
std::int32_t AddMouseOverListener(std::function<void(void)> callback) {
|
||||
std::int32_t id = CppDOMBindings::mouseOverHandlerMaxId++;
|
||||
handlers.push_back(id);
|
||||
CppDOM::Bindings::mouseOverHandlers->insert({id, callback});
|
||||
CppDOM::Bindings::AddMouseOverListener(ptr, id);
|
||||
CppDOMBindings::mouseOverHandlers->insert({id, callback});
|
||||
CppDOMBindings::AddMouseOverListener(ptr, id);
|
||||
return id;
|
||||
}
|
||||
|
||||
void RemoveMouseOverListener(int id) {
|
||||
void RemoveMouseOverListener(std::int32_t id) {
|
||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
||||
CppDOM::Bindings::mouseOverHandlers->erase(id);
|
||||
CppDOM::Bindings::RemoveMouseOverListener(ptr, id);
|
||||
CppDOMBindings::mouseOverHandlers->erase(id);
|
||||
CppDOMBindings::RemoveMouseOverListener(ptr, id);
|
||||
}
|
||||
|
||||
int AddMouseOutListener(std::function<void(void)> callback) {
|
||||
int id = CppDOM::Bindings::mouseOutHandlerMaxId++;
|
||||
std::int32_t AddMouseOutListener(std::function<void(void)> callback) {
|
||||
std::int32_t id = CppDOMBindings::mouseOutHandlerMaxId++;
|
||||
handlers.push_back(id);
|
||||
CppDOM::Bindings::mouseOutHandlers->insert({id, callback});
|
||||
CppDOM::Bindings::AddMouseOutListener(ptr, id);
|
||||
CppDOMBindings::mouseOutHandlers->insert({id, callback});
|
||||
CppDOMBindings::AddMouseOutListener(ptr, id);
|
||||
return id;
|
||||
}
|
||||
|
||||
void RemoveMouseOutListener(int id) {
|
||||
void RemoveMouseOutListener(std::int32_t id) {
|
||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
||||
CppDOM::Bindings::mouseOutHandlers->erase(id);
|
||||
CppDOM::Bindings::RemoveMouseOutListener(ptr, id);
|
||||
CppDOMBindings::mouseOutHandlers->erase(id);
|
||||
CppDOMBindings::RemoveMouseOutListener(ptr, id);
|
||||
}
|
||||
|
||||
int AddMouseMoveListener(std::function<void(void)> callback) {
|
||||
int id = CppDOM::Bindings::mouseMoveHandlerMaxId++;
|
||||
std::int32_t AddMouseMoveListener(std::function<void(void)> callback) {
|
||||
std::int32_t id = CppDOMBindings::mouseMoveHandlerMaxId++;
|
||||
handlers.push_back(id);
|
||||
CppDOM::Bindings::mouseMoveHandlers->insert({id, callback});
|
||||
CppDOM::Bindings::AddMouseMoveListener(ptr, id);
|
||||
CppDOMBindings::mouseMoveHandlers->insert({id, callback});
|
||||
CppDOMBindings::AddMouseMoveListener(ptr, id);
|
||||
return id;
|
||||
}
|
||||
|
||||
void RemoveMouseMoveListener(int id) {
|
||||
void RemoveMouseMoveListener(std::int32_t id) {
|
||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
||||
CppDOM::Bindings::mouseMoveHandlers->erase(id);
|
||||
CppDOM::Bindings::RemoveMouseMoveListener(ptr, id);
|
||||
CppDOMBindings::mouseMoveHandlers->erase(id);
|
||||
CppDOMBindings::RemoveMouseMoveListener(ptr, id);
|
||||
}
|
||||
|
||||
int AddFocusListener(std::function<void(void)> callback) {
|
||||
int id = CppDOM::Bindings::focusHandlerMaxId++;
|
||||
std::int32_t AddMouseDownListener(std::function<void(void)> callback) {
|
||||
std::int32_t id = CppDOMBindings::mouseDownHandlerMaxId++;
|
||||
handlers.push_back(id);
|
||||
CppDOM::Bindings::focusHandlers->insert({id, callback});
|
||||
CppDOM::Bindings::AddFocusListener(ptr, id);
|
||||
CppDOMBindings::mouseDownHandlers->insert({id, callback});
|
||||
CppDOMBindings::AddMouseDownListener(ptr, id);
|
||||
return id;
|
||||
}
|
||||
|
||||
void RemoveFocusListener(int id) {
|
||||
void RemoveMouseDownListener(std::int32_t id) {
|
||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
||||
CppDOM::Bindings::focusHandlers->erase(id);
|
||||
CppDOM::Bindings::RemoveFocusListener(ptr, id);
|
||||
CppDOMBindings::mouseDownHandlers->erase(id);
|
||||
CppDOMBindings::RemoveMouseDownListener(ptr, id);
|
||||
}
|
||||
|
||||
int AddBlurListener(std::function<void(void)> callback) {
|
||||
int id = CppDOM::Bindings::blurHandlerMaxId++;
|
||||
std::int32_t AddMouseUpListener(std::function<void(void)> callback) {
|
||||
std::int32_t id = CppDOMBindings::mouseUpHandlerMaxId++;
|
||||
handlers.push_back(id);
|
||||
CppDOM::Bindings::blurHandlers->insert({id, callback});
|
||||
CppDOM::Bindings::AddBlurListener(ptr, id);
|
||||
CppDOMBindings::mouseUpHandlers->insert({id, callback});
|
||||
CppDOMBindings::AddMouseUpListener(ptr, id);
|
||||
return id;
|
||||
}
|
||||
|
||||
void RemoveBlurListener(int id) {
|
||||
void RemoveMouseUpListener(std::int32_t id) {
|
||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
||||
CppDOM::Bindings::blurHandlers->erase(id);
|
||||
CppDOM::Bindings::RemoveBlurListener(ptr, id);
|
||||
CppDOMBindings::mouseUpHandlers->erase(id);
|
||||
CppDOMBindings::RemoveMouseUpListener(ptr, id);
|
||||
}
|
||||
|
||||
int AddKeyDownListener(std::function<void(void)> callback) {
|
||||
int id = CppDOM::Bindings::keyDownHandlerMaxId++;
|
||||
// Focus Events
|
||||
std::int32_t AddFocusListener(std::function<void(void)> callback) {
|
||||
std::int32_t id = CppDOMBindings::focusHandlerMaxId++;
|
||||
handlers.push_back(id);
|
||||
CppDOM::Bindings::keyDownHandlers->insert({id, callback});
|
||||
CppDOM::Bindings::AddKeyDownListener(ptr, id);
|
||||
CppDOMBindings::focusHandlers->insert({id, callback});
|
||||
CppDOMBindings::AddFocusListener(ptr, id);
|
||||
return id;
|
||||
}
|
||||
|
||||
void RemoveKeyDownListener(int id) {
|
||||
void RemoveFocusListener(std::int32_t id) {
|
||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
||||
CppDOM::Bindings::keyDownHandlers->erase(id);
|
||||
CppDOM::Bindings::RemoveKeyDownListener(ptr, id);
|
||||
CppDOMBindings::focusHandlers->erase(id);
|
||||
CppDOMBindings::RemoveFocusListener(ptr, id);
|
||||
}
|
||||
|
||||
int AddKeyUpListener(std::function<void(void)> callback) {
|
||||
int id = CppDOM::Bindings::keyUpHandlerMaxId++;
|
||||
std::int32_t AddBlurListener(std::function<void(void)> callback) {
|
||||
std::int32_t id = CppDOMBindings::blurHandlerMaxId++;
|
||||
handlers.push_back(id);
|
||||
CppDOM::Bindings::keyUpHandlers->insert({id, callback});
|
||||
CppDOM::Bindings::AddKeyUpListener(ptr, id);
|
||||
CppDOMBindings::blurHandlers->insert({id, callback});
|
||||
CppDOMBindings::AddBlurListener(ptr, id);
|
||||
return id;
|
||||
}
|
||||
|
||||
void RemoveKeyUpListener(int id) {
|
||||
void RemoveBlurListener(std::int32_t id) {
|
||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
||||
CppDOM::Bindings::keyUpHandlers->erase(id);
|
||||
CppDOM::Bindings::RemoveKeyUpListener(ptr, id);
|
||||
CppDOMBindings::blurHandlers->erase(id);
|
||||
CppDOMBindings::RemoveBlurListener(ptr, id);
|
||||
}
|
||||
|
||||
int AddKeyPressListener(std::function<void(void)> callback) {
|
||||
int id = CppDOM::Bindings::keyPressHandlerMaxId++;
|
||||
// Keyboard Events
|
||||
std::int32_t AddKeyDownListener(std::function<void(KeyboardEvent)> callback) {
|
||||
std::int32_t id = CppDOMBindings::keyDownHandlerMaxId++;
|
||||
handlers.push_back(id);
|
||||
CppDOM::Bindings::keyPressHandlers->insert({id, callback});
|
||||
CppDOM::Bindings::AddKeyPressListener(ptr, id);
|
||||
CppDOMBindings::keyDownHandlers->insert({id, callback});
|
||||
CppDOMBindings::AddKeyDownListener(ptr, id);
|
||||
return id;
|
||||
}
|
||||
|
||||
void RemoveKeyPressListener(int id) {
|
||||
void RemoveKeyDownListener(std::int32_t id) {
|
||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
||||
CppDOM::Bindings::keyPressHandlers->erase(id);
|
||||
CppDOM::Bindings::RemoveKeyPressListener(ptr, id);
|
||||
CppDOMBindings::keyDownHandlers->erase(id);
|
||||
CppDOMBindings::RemoveKeyDownListener(ptr, id);
|
||||
}
|
||||
|
||||
int AddChangeListener(std::function<void(void)> callback) {
|
||||
int id = CppDOM::Bindings::changeHandlerMaxId++;
|
||||
std::int32_t AddKeyUpListener(std::function<void(KeyboardEvent)> callback) {
|
||||
std::int32_t id = CppDOMBindings::keyUpHandlerMaxId++;
|
||||
handlers.push_back(id);
|
||||
CppDOM::Bindings::changeHandlers->insert({id, callback});
|
||||
CppDOM::Bindings::AddChangeListener(ptr, id);
|
||||
CppDOMBindings::keyUpHandlers->insert({id, callback});
|
||||
CppDOMBindings::AddKeyUpListener(ptr, id);
|
||||
return id;
|
||||
}
|
||||
|
||||
void RemoveChangeListener(int id) {
|
||||
void RemoveKeyUpListener(std::int32_t id) {
|
||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
||||
CppDOM::Bindings::changeHandlers->erase(id);
|
||||
CppDOM::Bindings::RemoveChangeListener(ptr, id);
|
||||
CppDOMBindings::keyUpHandlers->erase(id);
|
||||
CppDOMBindings::RemoveKeyUpListener(ptr, id);
|
||||
}
|
||||
|
||||
int AddSubmitListener(std::function<void(void)> callback) {
|
||||
int id = CppDOM::Bindings::submitHandlerMaxId++;
|
||||
std::int32_t AddKeyPressListener(std::function<void(KeyboardEvent)> callback) {
|
||||
std::int32_t id = CppDOMBindings::keyPressHandlerMaxId++;
|
||||
handlers.push_back(id);
|
||||
CppDOM::Bindings::submitHandlers->insert({id, callback});
|
||||
CppDOM::Bindings::AddSubmitListener(ptr, id);
|
||||
CppDOMBindings::keyPressHandlers->insert({id, callback});
|
||||
CppDOMBindings::AddKeyPressListener(ptr, id);
|
||||
return id;
|
||||
}
|
||||
|
||||
void RemoveSubmitListener(int id) {
|
||||
void RemoveKeyPressListener(std::int32_t id) {
|
||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
||||
CppDOM::Bindings::submitHandlers->erase(id);
|
||||
CppDOM::Bindings::RemoveSubmitListener(ptr, id);
|
||||
CppDOMBindings::keyPressHandlers->erase(id);
|
||||
CppDOMBindings::RemoveKeyPressListener(ptr, id);
|
||||
}
|
||||
|
||||
int AddInputListener(std::function<void(void)> callback) {
|
||||
int id = CppDOM::Bindings::inputHandlerMaxId++;
|
||||
// Form Events
|
||||
std::int32_t AddChangeListener(std::function<void(ChangeEvent)> callback) {
|
||||
std::int32_t id = CppDOMBindings::changeHandlerMaxId++;
|
||||
handlers.push_back(id);
|
||||
CppDOM::Bindings::inputHandlers->insert({id, callback});
|
||||
CppDOM::Bindings::AddInputListener(ptr, id);
|
||||
CppDOMBindings::changeHandlers->insert({id, callback});
|
||||
CppDOMBindings::AddChangeListener(ptr, id);
|
||||
return id;
|
||||
}
|
||||
|
||||
void RemoveInputListener(int id) {
|
||||
void RemoveChangeListener(std::int32_t id) {
|
||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
||||
CppDOM::Bindings::inputHandlers->erase(id);
|
||||
CppDOM::Bindings::RemoveInputListener(ptr, id);
|
||||
CppDOMBindings::changeHandlers->erase(id);
|
||||
CppDOMBindings::RemoveChangeListener(ptr, id);
|
||||
}
|
||||
|
||||
int AddLoadListener(std::function<void(void)> callback) {
|
||||
int id = CppDOM::Bindings::loadHandlerMaxId++;
|
||||
std::int32_t AddSubmitListener(std::function<void(void)> callback) {
|
||||
std::int32_t id = CppDOMBindings::submitHandlerMaxId++;
|
||||
handlers.push_back(id);
|
||||
CppDOM::Bindings::loadHandlers->insert({id, callback});
|
||||
CppDOM::Bindings::AddLoadListener(ptr, id);
|
||||
CppDOMBindings::submitHandlers->insert({id, callback});
|
||||
CppDOMBindings::AddSubmitListener(ptr, id);
|
||||
return id;
|
||||
}
|
||||
|
||||
void RemoveLoadListener(int id) {
|
||||
void RemoveSubmitListener(std::int32_t id) {
|
||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
||||
CppDOM::Bindings::loadHandlers->erase(id);
|
||||
CppDOM::Bindings::RemoveLoadListener(ptr, id);
|
||||
CppDOMBindings::submitHandlers->erase(id);
|
||||
CppDOMBindings::RemoveSubmitListener(ptr, id);
|
||||
}
|
||||
|
||||
int AddErrorListener(std::function<void(void)> callback) {
|
||||
int id = CppDOM::Bindings::errorHandlerMaxId++;
|
||||
std::int32_t AddInputListener(std::function<void(InputEvent)> callback) {
|
||||
std::int32_t id = CppDOMBindings::inputHandlerMaxId++;
|
||||
handlers.push_back(id);
|
||||
CppDOM::Bindings::errorHandlers->insert({id, callback});
|
||||
CppDOM::Bindings::AddErrorListener(ptr, id);
|
||||
CppDOMBindings::inputHandlers->insert({id, callback});
|
||||
CppDOMBindings::AddInputListener(ptr, id);
|
||||
return id;
|
||||
}
|
||||
|
||||
void RemoveErrorListener(int id) {
|
||||
void RemoveInputListener(std::int32_t id) {
|
||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
||||
CppDOM::Bindings::errorHandlers->erase(id);
|
||||
CppDOM::Bindings::RemoveErrorListener(ptr, id);
|
||||
CppDOMBindings::inputHandlers->erase(id);
|
||||
CppDOMBindings::RemoveInputListener(ptr, id);
|
||||
}
|
||||
|
||||
int AddResizeListener(std::function<void(void)> callback) {
|
||||
int id = CppDOM::Bindings::resizeHandlerMaxId++;
|
||||
std::int32_t AddResizeListener(std::function<void(ResizeEvent)> callback) {
|
||||
std::int32_t id = CppDOMBindings::resizeHandlerMaxId++;
|
||||
handlers.push_back(id);
|
||||
CppDOM::Bindings::resizeHandlers->insert({id, callback});
|
||||
CppDOM::Bindings::AddResizeListener(ptr, id);
|
||||
CppDOMBindings::resizeHandlers->insert({id, callback});
|
||||
CppDOMBindings::AddResizeListener(ptr, id);
|
||||
return id;
|
||||
}
|
||||
|
||||
void RemoveResizeListener(int id) {
|
||||
void RemoveResizeListener(std::int32_t id) {
|
||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
||||
CppDOM::Bindings::resizeHandlers->erase(id);
|
||||
CppDOM::Bindings::RemoveResizeListener(ptr, id);
|
||||
CppDOMBindings::resizeHandlers->erase(id);
|
||||
CppDOMBindings::RemoveResizeListener(ptr, id);
|
||||
}
|
||||
|
||||
int AddScrollListener(std::function<void(void)> callback) {
|
||||
int id = CppDOM::Bindings::scrollHandlerMaxId++;
|
||||
std::int32_t AddScrollListener(std::function<void(ScrollEvent)> callback) {
|
||||
std::int32_t id = CppDOMBindings::scrollHandlerMaxId++;
|
||||
handlers.push_back(id);
|
||||
CppDOM::Bindings::scrollHandlers->insert({id, callback});
|
||||
CppDOM::Bindings::AddScrollListener(ptr, id);
|
||||
CppDOMBindings::scrollHandlers->insert({id, callback});
|
||||
CppDOMBindings::AddScrollListener(ptr, id);
|
||||
return id;
|
||||
}
|
||||
|
||||
void RemoveScrollListener(int id) {
|
||||
void RemoveScrollListener(std::int32_t id) {
|
||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
||||
CppDOM::Bindings::scrollHandlers->erase(id);
|
||||
CppDOM::Bindings::RemoveScrollListener(ptr, id);
|
||||
CppDOMBindings::scrollHandlers->erase(id);
|
||||
CppDOMBindings::RemoveScrollListener(ptr, id);
|
||||
}
|
||||
|
||||
int AddContextMenuListener(std::function<void(void)> callback) {
|
||||
int id = CppDOM::Bindings::contextMenuHandlerMaxId++;
|
||||
// Context Menu Events
|
||||
std::int32_t AddContextMenuListener(std::function<void(MouseEvent)> callback) {
|
||||
std::int32_t id = CppDOMBindings::contextMenuHandlerMaxId++;
|
||||
handlers.push_back(id);
|
||||
CppDOM::Bindings::contextMenuHandlers->insert({id, callback});
|
||||
CppDOM::Bindings::AddContextMenuListener(ptr, id);
|
||||
CppDOMBindings::contextMenuHandlers->insert({id, callback});
|
||||
CppDOMBindings::AddContextMenuListener(ptr, id);
|
||||
return id;
|
||||
}
|
||||
|
||||
void RemoveContextMenuListener(int id) {
|
||||
void RemoveContextMenuListener(std::int32_t id) {
|
||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
||||
CppDOM::Bindings::contextMenuHandlers->erase(id);
|
||||
CppDOM::Bindings::RemoveContextMenuListener(ptr, id);
|
||||
CppDOMBindings::contextMenuHandlers->erase(id);
|
||||
CppDOMBindings::RemoveContextMenuListener(ptr, id);
|
||||
}
|
||||
|
||||
int AddDragStartListener(std::function<void(void)> callback) {
|
||||
int id = CppDOM::Bindings::dragStartHandlerMaxId++;
|
||||
// Drag and Drop Events
|
||||
std::int32_t AddDragStartListener(std::function<void(MouseEvent)> callback) {
|
||||
std::int32_t id = CppDOMBindings::dragStartHandlerMaxId++;
|
||||
handlers.push_back(id);
|
||||
CppDOM::Bindings::dragStartHandlers->insert({id, callback});
|
||||
CppDOM::Bindings::AddDragStartListener(ptr, id);
|
||||
CppDOMBindings::dragStartHandlers->insert({id, callback});
|
||||
CppDOMBindings::AddDragStartListener(ptr, id);
|
||||
return id;
|
||||
}
|
||||
|
||||
void RemoveDragStartListener(int id) {
|
||||
void RemoveDragStartListener(std::int32_t id) {
|
||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
||||
CppDOM::Bindings::dragStartHandlers->erase(id);
|
||||
CppDOM::Bindings::RemoveDragStartListener(ptr, id);
|
||||
CppDOMBindings::dragStartHandlers->erase(id);
|
||||
CppDOMBindings::RemoveDragStartListener(ptr, id);
|
||||
}
|
||||
|
||||
int AddDragEndListener(std::function<void(void)> callback) {
|
||||
int id = CppDOM::Bindings::dragEndHandlerMaxId++;
|
||||
std::int32_t AddDragEndListener(std::function<void(MouseEvent)> callback) {
|
||||
std::int32_t id = CppDOMBindings::dragEndHandlerMaxId++;
|
||||
handlers.push_back(id);
|
||||
CppDOM::Bindings::dragEndHandlers->insert({id, callback});
|
||||
CppDOM::Bindings::AddDragEndListener(ptr, id);
|
||||
CppDOMBindings::dragEndHandlers->insert({id, callback});
|
||||
CppDOMBindings::AddDragEndListener(ptr, id);
|
||||
return id;
|
||||
}
|
||||
|
||||
void RemoveDragEndListener(int id) {
|
||||
void RemoveDragEndListener(std::int32_t id) {
|
||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
||||
CppDOM::Bindings::dragEndHandlers->erase(id);
|
||||
CppDOM::Bindings::RemoveDragEndListener(ptr, id);
|
||||
CppDOMBindings::dragEndHandlers->erase(id);
|
||||
CppDOMBindings::RemoveDragEndListener(ptr, id);
|
||||
}
|
||||
|
||||
int AddDropListener(std::function<void(void)> callback) {
|
||||
int id = CppDOM::Bindings::dropHandlerMaxId++;
|
||||
std::int32_t AddDropListener(std::function<void(MouseEvent)> callback) {
|
||||
std::int32_t id = CppDOMBindings::dropHandlerMaxId++;
|
||||
handlers.push_back(id);
|
||||
CppDOM::Bindings::dropHandlers->insert({id, callback});
|
||||
CppDOM::Bindings::AddDropListener(ptr, id);
|
||||
CppDOMBindings::dropHandlers->insert({id, callback});
|
||||
CppDOMBindings::AddDropListener(ptr, id);
|
||||
return id;
|
||||
}
|
||||
|
||||
void RemoveDropListener(int id) {
|
||||
void RemoveDropListener(std::int32_t id) {
|
||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
||||
CppDOM::Bindings::dropHandlers->erase(id);
|
||||
CppDOM::Bindings::RemoveDropListener(ptr, id);
|
||||
CppDOMBindings::dropHandlers->erase(id);
|
||||
CppDOMBindings::RemoveDropListener(ptr, id);
|
||||
}
|
||||
|
||||
// Additional Drag Events
|
||||
std::int32_t AddDragOverListener(std::function<void(MouseEvent)> callback) {
|
||||
std::int32_t id = CppDOMBindings::dragOverHandlerMaxId++;
|
||||
handlers.push_back(id);
|
||||
CppDOMBindings::dragOverHandlers->insert({id, callback});
|
||||
CppDOMBindings::AddDragOverListener(ptr, id);
|
||||
return id;
|
||||
}
|
||||
|
||||
void RemoveDragOverListener(std::int32_t id) {
|
||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
||||
CppDOMBindings::dragOverHandlers->erase(id);
|
||||
CppDOMBindings::RemoveDragOverListener(ptr, id);
|
||||
}
|
||||
|
||||
std::int32_t AddDragEnterListener(std::function<void(MouseEvent)> callback) {
|
||||
std::int32_t id = CppDOMBindings::dragEnterHandlerMaxId++;
|
||||
handlers.push_back(id);
|
||||
CppDOMBindings::dragEnterHandlers->insert({id, callback});
|
||||
CppDOMBindings::AddDragEnterListener(ptr, id);
|
||||
return id;
|
||||
}
|
||||
|
||||
void RemoveDragEnterListener(std::int32_t id) {
|
||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
||||
CppDOMBindings::dragEnterHandlers->erase(id);
|
||||
CppDOMBindings::RemoveDragEnterListener(ptr, id);
|
||||
}
|
||||
|
||||
std::int32_t AddDragLeaveListener(std::function<void(MouseEvent)> callback) {
|
||||
std::int32_t id = CppDOMBindings::dragLeaveHandlerMaxId++;
|
||||
handlers.push_back(id);
|
||||
CppDOMBindings::dragLeaveHandlers->insert({id, callback});
|
||||
CppDOMBindings::AddDragLeaveListener(ptr, id);
|
||||
return id;
|
||||
}
|
||||
|
||||
void RemoveDragLeaveListener(std::int32_t id) {
|
||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
||||
CppDOMBindings::dragLeaveHandlers->erase(id);
|
||||
CppDOMBindings::RemoveDragLeaveListener(ptr, id);
|
||||
}
|
||||
|
||||
// Wheel Event
|
||||
std::int32_t AddWheelListener(std::function<void(WheelEvent)> callback) {
|
||||
std::int32_t id = CppDOMBindings::wheelHandlerMaxId++;
|
||||
handlers.push_back(id);
|
||||
CppDOMBindings::wheelHandlers->insert({id, callback});
|
||||
CppDOMBindings::AddWheelListener(ptr, id);
|
||||
return id;
|
||||
}
|
||||
|
||||
void RemoveWheelListener(std::int32_t id) {
|
||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
||||
CppDOMBindings::wheelHandlers->erase(id);
|
||||
CppDOMBindings::RemoveWheelListener(ptr, id);
|
||||
}
|
||||
|
||||
~HtmlElement(){
|
||||
for(int handler : handlers) {
|
||||
// Clean up all handlers based on type - this is a simplified approach
|
||||
// In practice, you'd want to track handler types to clean them properly
|
||||
CppDOM::Bindings::clickHandlers->erase(handler);
|
||||
CppDOM::Bindings::RemoveClickListener(ptr, handler);
|
||||
for(std::int32_t handler : handlers) {
|
||||
CppDOMBindings::clickHandlers->erase(handler);
|
||||
CppDOMBindings::RemoveClickListener(ptr, handler);
|
||||
}
|
||||
CppDOM::Bindings::FreeJs(ptr);
|
||||
CppDOMBindings::FreeJs(ptr);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -20,4 +20,5 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
|
||||
export module Crafter.CppDOM;
|
||||
export import :Bindings;
|
||||
export import :HtmlElement;
|
||||
export import :HtmlElement;
|
||||
export import :EventTypes;
|
||||
Loading…
Add table
Add a link
Reference in a new issue