diff --git a/examples/CompleteEventHandling/README.md b/examples/CompleteEventHandling/README.md
deleted file mode 100644
index 175741a..0000000
--- a/examples/CompleteEventHandling/README.md
+++ /dev/null
@@ -1,84 +0,0 @@
-# Complete Event Handling Example
-
-This example demonstrates comprehensive event handling capabilities in Crafter.CppDOM.
-
-## Features
-
-- Shows how to handle various types of DOM events using C++
-- Demonstrates mouse, keyboard, form, and window events
-- Illustrates proper event listener attachment and callback handling
-- Shows real-time interaction with UI elements
-
-## Event Types Demonstrated
-
-### Mouse Events
-- Click events
-- Mouse over/out events
-- Mouse move events
-
-### Focus Events
-- Focus and blur events
-
-### Keyboard Events
-- Key down, up, and press events
-
-### Form Events
-- Change, submit, and input events
-
-### Window Events
-- Load, error, resize, and scroll events
-
-### Context Menu Events
-- Context menu events
-
-### Drag and Drop Events
-- Drag start, end, and drop events
-
-## Usage
-
-```cpp
-import Crafter.CppDOM;
-using namespace Crafter::CppDOM;
-
-int main(){
- // Create UI elements
- HtmlElement body("body");
- body.SetInnerHTML("
Complete Event Handling Demo
"
- ""
- ""
- "Events will appear here
");
-
- // Handle click event
- HtmlElement button("myButton");
- button.AddClickListener([]() {
- HtmlElement output("output");
- output.SetInnerHTML("Button was clicked!");
- });
-
- // Handle keyboard events
- HtmlElement input("textInput");
- input.AddInputListener([]() {
- HtmlElement output("output");
- output.SetInnerHTML("Input changed!");
- });
-
- // Handle form events
- input.AddChangeListener([]() {
- HtmlElement output("output");
- output.SetInnerHTML("Form value changed!");
- });
-
- return 0;
-}
-```
-
-## Building and Running
-
-```bash
-crafter-build build executable
-run.sh
-```
-
-Then navigate to `http://localhost:8080/` in your browser.
-
-If caddy is not installed, you can use your favorite static file server instead.
\ No newline at end of file
diff --git a/examples/CompleteEventHandling/main.cpp b/examples/CompleteEventHandling/main.cpp
deleted file mode 100644
index 396477d..0000000
--- a/examples/CompleteEventHandling/main.cpp
+++ /dev/null
@@ -1,75 +0,0 @@
-import Crafter.CppDOM;
-using namespace Crafter;
-
-HtmlElement* body = new HtmlElement("body", "");
-HtmlElement* button = new HtmlElement("myButton");
-HtmlElement* input = new HtmlElement("textInput");
-HtmlElement* output = new HtmlElement("output");
-
-int main(){
- // Click event
- button->AddClickListener([&]() {
- output->SetInnerHTML("Button was clicked!");
- });
-
- // Mouse events
- button->AddMouseOverListener([&]() {
- output->SetInnerHTML("Mouse over button!");
- });
-
- button->AddMouseOutListener([&]() {
- output->SetInnerHTML("Mouse left button!");
- });
-
- // Focus/Blur events
- input->AddFocusListener([&]() {
- output->SetInnerHTML("Input focused!");
- });
-
- input->AddBlurListener([&]() {
- output->SetInnerHTML("Input blurred!");
- });
-
- // Keyboard events
- input->AddKeyDownListener([&]() {
- output->SetInnerHTML("Key pressed in input!");
- });
-
- input->AddKeyUpListener([&]() {
- output->SetInnerHTML("Key released in input!");
- });
-
- // Input/change events
- input->AddInputListener([&]() {
- output->SetInnerHTML("Input value changed!");
- });
-
- input->AddChangeListener([&]() {
- output->SetInnerHTML("Input value changed and lost focus!");
- });
-
- // Context menu
- button->AddContextMenuListener([&]() {
- output->SetInnerHTML("Context menu opened!");
- });
-
- // Scroll event on body
- body->AddScrollListener([&]() {
- output->SetInnerHTML("Page scrolled!");
- });
-
- // Resize event
- body->AddResizeListener([&]() {
- output->SetInnerHTML("Window resized!");
- });
-
- // Load event
- body->AddLoadListener([&]() {
- output->SetInnerHTML("Page loaded!");
- });
-
- // Error event
- body->AddErrorListener([&]() {
- output->SetInnerHTML("An error occurred!");
- });
-}
\ No newline at end of file
diff --git a/examples/CompleteEventHandling/project.json b/examples/CompleteEventHandling/project.json
deleted file mode 100644
index 9750e20..0000000
--- a/examples/CompleteEventHandling/project.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
- "name": "main",
- "configurations": [
- {
- "name": "executable",
- "implementations": ["main"],
- "target": "wasm32-wasi",
- "debug" : true,
- "dependencies": [
- {
- "path":"../../project.json",
- "configuration":"lib-debug"
- }
- ]
- }
- ]
-}
\ No newline at end of file
diff --git a/examples/CompleteEventHandling/run.sh b/examples/CompleteEventHandling/run.sh
deleted file mode 100755
index e706621..0000000
--- a/examples/CompleteEventHandling/run.sh
+++ /dev/null
@@ -1 +0,0 @@
-caddy file-server --listen :8080 --root bin/executable
\ No newline at end of file
diff --git a/examples/EnhancedEventHandling/main.cpp b/examples/EnhancedEventHandling/main.cpp
index 8d7d864..fb89730 100644
--- a/examples/EnhancedEventHandling/main.cpp
+++ b/examples/EnhancedEventHandling/main.cpp
@@ -4,30 +4,13 @@ import std;
HtmlElement* body = new HtmlElement("body", ""
"
Enhanced Event Handling Demo
"
- "
"
- "
"
"
"
- "
"
"
"
"
");
-HtmlElement* clickButton = new HtmlElement("clickButton");
-HtmlElement* mouseButton = new HtmlElement("mouseButton");
HtmlElement* keyInput = new HtmlElement("keyInput");
-HtmlElement* changeInput = new HtmlElement("changeInput");
HtmlElement* output = new HtmlElement("output");
int main(){
- // Click event - simple handler
- clickButton->AddClickListener([&]() {
- output->SetInnerHTML("Simple click event triggered!
");
- });
-
- // Mouse events with position data
- // mouseButton->AddMouseMoveListener([&](MouseEvent event) {
- // output->SetInnerHTML("Mouse moved to: (" + std::to_string(event.clientX) + ", " + std::to_string(event.clientY) + ")
");
- // });
-
- // Keyboard events with rich data
keyInput->AddKeyDownListener([&](KeyboardEvent event) {
std::string keyInfo = std::format("Key pressed: {}
", event.key);
if (event.ctrlKey) keyInfo += "Ctrl key pressed
";
@@ -35,29 +18,4 @@ int main(){
if (event.altKey) keyInfo += "Alt key pressed
";
output->SetInnerHTML(keyInfo);
});
-
- // // Input event with data
- // keyInput->AddInputListener([&](InputEvent event) {
- // output->SetInnerHTML(std::format("Input data: {} (composing: {})
", event.data, event.isComposing));
- // });
-
- // Change event with value
- changeInput->AddChangeListener([&](ChangeEvent event) {
- output->SetInnerHTML("Input value changed to: '" + event.value + "'
");
- });
-
- // Context menu with position
- mouseButton->AddContextMenuListener([&](MouseEvent event) {
- output->SetInnerHTML("Context menu at: (" + std::to_string(event.clientX) + ", " + std::to_string(event.clientY) + ")
");
- });
-
- // Resize event
- body->AddResizeListener([&](ResizeEvent event) {
- output->SetInnerHTML("Window resized to: " + std::to_string(event.width) + "x" + std::to_string(event.height) + "
");
- });
-
- // Scroll event
- body->AddScrollListener([&](ScrollEvent event) {
- output->SetInnerHTML("Scrolled to: (" + std::to_string(event.scrollX) + ", " + std::to_string(event.scrollY) + ")
");
- });
}
\ No newline at end of file
diff --git a/interfaces/Crafter.CppDOM-Bindings.cppm b/interfaces/Crafter.CppDOM-BindingsExport.cppm
similarity index 54%
rename from interfaces/Crafter.CppDOM-Bindings.cppm
rename to interfaces/Crafter.CppDOM-BindingsExport.cppm
index 3c76173..7ebe266 100644
--- a/interfaces/Crafter.CppDOM-Bindings.cppm
+++ b/interfaces/Crafter.CppDOM-BindingsExport.cppm
@@ -18,7 +18,7 @@ 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:Bindings;
+export module Crafter.CppDOM:BindingsExport;
import std;
import :EventTypes;
@@ -94,89 +94,6 @@ export namespace Crafter::CppDOMBindings {
int dragLeaveHandlerMaxId = 0;
std::unordered_map>* dragLeaveHandlers = new std::unordered_map>();
-
- __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) {
- return GetElementById(id.data(), id.size());
- }
- __attribute__((import_module("env"), import_name("setInnerHTML"))) void SetInnerHTML(void* ptr, const char* html, std::size_t htmlLenght);
- void SetInnerHTML(void* ptr, const std::string_view html) {
- SetInnerHTML(ptr, html.data(), html.size());
- }
-
- // Event handling functions
- __attribute__((import_module("env"), import_name("addClickListener"))) void AddClickListener(void* ptr, int id);
- __attribute__((import_module("env"), import_name("removeClickListener"))) void RemoveClickListener(void* ptr, int id);
-
- __attribute__((import_module("env"), import_name("addMouseOverListener"))) void AddMouseOverListener(void* ptr, int id);
- __attribute__((import_module("env"), import_name("removeMouseOverListener"))) void RemoveMouseOverListener(void* ptr, int id);
-
- __attribute__((import_module("env"), import_name("addMouseOutListener"))) void AddMouseOutListener(void* ptr, int id);
- __attribute__((import_module("env"), import_name("removeMouseOutListener"))) void RemoveMouseOutListener(void* ptr, int id);
-
- __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);
-
- __attribute__((import_module("env"), import_name("addBlurListener"))) void AddBlurListener(void* ptr, int id);
- __attribute__((import_module("env"), import_name("removeBlurListener"))) void RemoveBlurListener(void* ptr, int id);
-
- __attribute__((import_module("env"), import_name("addKeyDownListener"))) void AddKeyDownListener(void* ptr, int id);
- __attribute__((import_module("env"), import_name("removeKeyDownListener"))) void RemoveKeyDownListener(void* ptr, int id);
-
- __attribute__((import_module("env"), import_name("addKeyUpListener"))) void AddKeyUpListener(void* ptr, int id);
- __attribute__((import_module("env"), import_name("removeKeyUpListener"))) void RemoveKeyUpListener(void* ptr, int id);
-
- __attribute__((import_module("env"), import_name("addKeyPressListener"))) void AddKeyPressListener(void* ptr, int id);
- __attribute__((import_module("env"), import_name("removeKeyPressListener"))) void RemoveKeyPressListener(void* ptr, int id);
-
- __attribute__((import_module("env"), import_name("addChangeListener"))) void AddChangeListener(void* ptr, int id);
- __attribute__((import_module("env"), import_name("removeChangeListener"))) void RemoveChangeListener(void* ptr, int id);
-
- __attribute__((import_module("env"), import_name("addSubmitListener"))) void AddSubmitListener(void* ptr, int id);
- __attribute__((import_module("env"), import_name("removeSubmitListener"))) void RemoveSubmitListener(void* ptr, int id);
-
- __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("addResizeListener"))) void AddResizeListener(void* ptr, int id);
- __attribute__((import_module("env"), import_name("removeResizeListener"))) void RemoveResizeListener(void* ptr, int id);
-
- __attribute__((import_module("env"), import_name("addScrollListener"))) void AddScrollListener(void* ptr, int id);
- __attribute__((import_module("env"), import_name("removeScrollListener"))) void RemoveScrollListener(void* ptr, int id);
-
- __attribute__((import_module("env"), import_name("addContextMenuListener"))) void AddContextMenuListener(void* ptr, int id);
- __attribute__((import_module("env"), import_name("removeContextMenuListener"))) void RemoveContextMenuListener(void* ptr, int id);
-
- __attribute__((import_module("env"), import_name("addDragStartListener"))) void AddDragStartListener(void* ptr, int id);
- __attribute__((import_module("env"), import_name("removeDragStartListener"))) void RemoveDragStartListener(void* ptr, int id);
-
- __attribute__((import_module("env"), import_name("addDragEndListener"))) void AddDragEndListener(void* ptr, int id);
- __attribute__((import_module("env"), import_name("removeDragEndListener"))) void RemoveDragEndListener(void* ptr, int id);
-
- __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" {
@@ -234,9 +151,7 @@ extern "C" {
}
__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);
+ Crafter::CppDOMBindings::changeHandlers->find(handlerID)->second(Crafter::ChangeEvent(value));
}
__attribute__((export_name("ExecuteSubmitHandler"))) void ExecuteSubmitHandler(std::int32_t handlerID) {
@@ -244,138 +159,46 @@ extern "C" {
}
__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);
+ Crafter::CppDOMBindings::inputHandlers->find(handlerID)->second(Crafter::InputEvent(data, isComposing));
}
__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);
+ Crafter::CppDOMBindings::resizeHandlers->find(handlerID)->second(Crafter::ResizeEvent(width, height));
}
__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);
+ Crafter::CppDOMBindings::scrollHandlers->find(handlerID)->second(Crafter::ScrollEvent(scrollX, scrollY));
}
__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);
+ Crafter::CppDOMBindings::contextMenuHandlers->find(handlerID)->second(Crafter::MouseEvent(clientX, clientY, screenX, screenY, button, 0, altKey, ctrlKey, shiftKey, metaKey));
}
__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);
+ Crafter::CppDOMBindings::dragStartHandlers->find(handlerID)->second(Crafter::MouseEvent(clientX, clientY, screenX, screenY, button, 0, altKey, ctrlKey, shiftKey, metaKey));
}
__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);
+ Crafter::CppDOMBindings::dragEndHandlers->find(handlerID)->second(Crafter::MouseEvent(clientX, clientY, screenX, screenY, button, 0, altKey, ctrlKey, shiftKey, metaKey));
}
__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);
+ Crafter::CppDOMBindings::dropHandlers->find(handlerID)->second(Crafter::MouseEvent(clientX, clientY, screenX, screenY, button, 0, altKey, ctrlKey, shiftKey, metaKey));
}
__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);
+ Crafter::CppDOMBindings::wheelHandlers->find(handlerID)->second(Crafter::WheelEvent(clientX, clientY, screenX, screenY, button, 0, altKey, ctrlKey, shiftKey, metaKey, deltaX, deltaY, deltaZ));
}
__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);
+ Crafter::CppDOMBindings::dragOverHandlers->find(handlerID)->second(Crafter::MouseEvent(clientX, clientY, screenX, screenY, button, 0, altKey, ctrlKey, shiftKey, metaKey));
}
__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);
+ Crafter::CppDOMBindings::dragEnterHandlers->find(handlerID)->second(Crafter::MouseEvent(clientX, clientY, screenX, screenY, button, 0, altKey, ctrlKey, shiftKey, metaKey));
}
__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);
+ Crafter::CppDOMBindings::dragLeaveHandlers->find(handlerID)->second(Crafter::MouseEvent(clientX, clientY, screenX, screenY, button, 0, altKey, ctrlKey, shiftKey, metaKey));
}
}
\ No newline at end of file
diff --git a/interfaces/Crafter.CppDOM-BindingsImport.cppm b/interfaces/Crafter.CppDOM-BindingsImport.cppm
new file mode 100644
index 0000000..32ea9ec
--- /dev/null
+++ b/interfaces/Crafter.CppDOM-BindingsImport.cppm
@@ -0,0 +1,108 @@
+/*
+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:BindingsImport;
+import std;
+import :EventTypes;
+
+export namespace Crafter::CppDOMBindings {
+ __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) {
+ return GetElementById(id.data(), id.size());
+ }
+ __attribute__((import_module("env"), import_name("setInnerHTML"))) void SetInnerHTML(void* ptr, const char* html, std::size_t htmlLenght);
+ void SetInnerHTML(void* ptr, const std::string_view html) {
+ SetInnerHTML(ptr, html.data(), html.size());
+ }
+
+ // Event handling functions
+ __attribute__((import_module("env"), import_name("addClickListener"))) void AddClickListener(void* ptr, int id);
+ __attribute__((import_module("env"), import_name("removeClickListener"))) void RemoveClickListener(void* ptr, int id);
+
+ __attribute__((import_module("env"), import_name("addMouseOverListener"))) void AddMouseOverListener(void* ptr, int id);
+ __attribute__((import_module("env"), import_name("removeMouseOverListener"))) void RemoveMouseOverListener(void* ptr, int id);
+
+ __attribute__((import_module("env"), import_name("addMouseOutListener"))) void AddMouseOutListener(void* ptr, int id);
+ __attribute__((import_module("env"), import_name("removeMouseOutListener"))) void RemoveMouseOutListener(void* ptr, int id);
+
+ __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);
+
+ __attribute__((import_module("env"), import_name("addBlurListener"))) void AddBlurListener(void* ptr, int id);
+ __attribute__((import_module("env"), import_name("removeBlurListener"))) void RemoveBlurListener(void* ptr, int id);
+
+ __attribute__((import_module("env"), import_name("addKeyDownListener"))) void AddKeyDownListener(void* ptr, int id);
+ __attribute__((import_module("env"), import_name("removeKeyDownListener"))) void RemoveKeyDownListener(void* ptr, int id);
+
+ __attribute__((import_module("env"), import_name("addKeyUpListener"))) void AddKeyUpListener(void* ptr, int id);
+ __attribute__((import_module("env"), import_name("removeKeyUpListener"))) void RemoveKeyUpListener(void* ptr, int id);
+
+ __attribute__((import_module("env"), import_name("addKeyPressListener"))) void AddKeyPressListener(void* ptr, int id);
+ __attribute__((import_module("env"), import_name("removeKeyPressListener"))) void RemoveKeyPressListener(void* ptr, int id);
+
+ __attribute__((import_module("env"), import_name("addChangeListener"))) void AddChangeListener(void* ptr, int id);
+ __attribute__((import_module("env"), import_name("removeChangeListener"))) void RemoveChangeListener(void* ptr, int id);
+
+ __attribute__((import_module("env"), import_name("addSubmitListener"))) void AddSubmitListener(void* ptr, int id);
+ __attribute__((import_module("env"), import_name("removeSubmitListener"))) void RemoveSubmitListener(void* ptr, int id);
+
+ __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("addResizeListener"))) void AddResizeListener(void* ptr, int id);
+ __attribute__((import_module("env"), import_name("removeResizeListener"))) void RemoveResizeListener(void* ptr, int id);
+
+ __attribute__((import_module("env"), import_name("addScrollListener"))) void AddScrollListener(void* ptr, int id);
+ __attribute__((import_module("env"), import_name("removeScrollListener"))) void RemoveScrollListener(void* ptr, int id);
+
+ __attribute__((import_module("env"), import_name("addContextMenuListener"))) void AddContextMenuListener(void* ptr, int id);
+ __attribute__((import_module("env"), import_name("removeContextMenuListener"))) void RemoveContextMenuListener(void* ptr, int id);
+
+ __attribute__((import_module("env"), import_name("addDragStartListener"))) void AddDragStartListener(void* ptr, int id);
+ __attribute__((import_module("env"), import_name("removeDragStartListener"))) void RemoveDragStartListener(void* ptr, int id);
+
+ __attribute__((import_module("env"), import_name("addDragEndListener"))) void AddDragEndListener(void* ptr, int id);
+ __attribute__((import_module("env"), import_name("removeDragEndListener"))) void RemoveDragEndListener(void* ptr, int id);
+
+ __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);
+}
\ No newline at end of file
diff --git a/interfaces/Crafter.CppDOM-EventTypes.cppm b/interfaces/Crafter.CppDOM-EventTypes.cppm
index 745138b..ad92c2f 100644
--- a/interfaces/Crafter.CppDOM-EventTypes.cppm
+++ b/interfaces/Crafter.CppDOM-EventTypes.cppm
@@ -44,30 +44,36 @@ export namespace Crafter {
bool ctrlKey;
bool shiftKey;
bool metaKey;
+ 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) : clientX(clientX), clientY(clientY), screenX(screenX), screenY(screenY), button(button), buttons(buttons), altKey(altKey), ctrlKey(ctrlKey), shiftKey(shiftKey), metaKey(metaKey) {}
};
struct InputEvent {
std::string data;
bool isComposing;
+ InputEvent(const char* data, bool isComposing) : data(data), isComposing(isComposing) {}
};
struct WheelEvent : public MouseEvent {
double deltaX;
double deltaY;
double deltaZ;
+ WheelEvent(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, double deltaX, double deltaY, double deltaZ): MouseEvent(clientX, clientY, screenX, screenY, button, buttons, altKey, ctrlKey, shiftKey, metaKey), deltaX(deltaX), deltaY(deltaY), deltaZ(deltaZ) {}
};
struct ResizeEvent {
std::uint_fast32_t width;
std::uint_fast32_t height;
+ ResizeEvent(std::uint_fast32_t width, std::uint_fast32_t height) : width(width), height(height) {}
};
struct ScrollEvent {
double scrollX;
double scrollY;
+ ScrollEvent(double scrollX, double scrollY) : scrollX(scrollX), scrollY(scrollY) {}
};
struct ChangeEvent {
std::string value;
+ ChangeEvent(const char* value) : value(value) {}
};
}
\ No newline at end of file
diff --git a/interfaces/Crafter.CppDOM-HtmlElement.cppm b/interfaces/Crafter.CppDOM-HtmlElement.cppm
index 6364e4c..8411b2c 100644
--- a/interfaces/Crafter.CppDOM-HtmlElement.cppm
+++ b/interfaces/Crafter.CppDOM-HtmlElement.cppm
@@ -20,14 +20,39 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
export module Crafter.CppDOM:HtmlElement;
import std;
-import :Bindings;
+import :BindingsExport;
+import :BindingsImport;
import :EventTypes;
namespace Crafter {
export class HtmlElement {
public:
void* const ptr;
- std::vector handlers;
+ std::vector clickHandlers;
+ std::vector mouseOverHandlers;
+ std::vector mouseOutHandlers;
+ std::vector mouseMoveHandlers;
+ std::vector mouseDownHandlers;
+ std::vector mouseUpHandlers;
+ std::vector focusHandlers;
+ std::vector blurHandlers;
+ std::vector keyDownHandlers;
+ std::vector keyUpHandlers;
+ std::vector keyPressHandlers;
+ std::vector changeHandlers;
+ std::vector submitHandlers;
+ std::vector inputHandlers;
+ std::vector resizeHandlers;
+ std::vector scrollHandlers;
+ std::vector contextMenuHandlers;
+ std::vector dragStartHandlers;
+ std::vector dragEndHandlers;
+ std::vector dropHandlers;
+ std::vector dragOverHandlers;
+ std::vector dragEnterHandlers;
+ std::vector dragLeaveHandlers;
+ std::vector wheelHandlers;
+
HtmlElement(const std::string_view id): ptr(CppDOMBindings::GetElementById(id)) {
}
@@ -38,89 +63,86 @@ namespace Crafter {
CppDOMBindings::SetInnerHTML(ptr, html);
}
- // Event handling methods with event data
-
- // Mouse Events
std::int32_t AddClickListener(std::function callback) {
std::int32_t id = CppDOMBindings::clickHandlerMaxId++;
- handlers.push_back(id);
+ clickHandlers.push_back(id);
CppDOMBindings::clickHandlers->insert({id, callback});
CppDOMBindings::AddClickListener(ptr, id);
return id;
}
void RemoveClickListener(std::int32_t id) {
- handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
+ clickHandlers.erase(std::remove(clickHandlers.begin(), clickHandlers.end(), id), clickHandlers.end());
CppDOMBindings::clickHandlers->erase(id);
CppDOMBindings::RemoveClickListener(ptr, id);
}
std::int32_t AddMouseOverListener(std::function callback) {
std::int32_t id = CppDOMBindings::mouseOverHandlerMaxId++;
- handlers.push_back(id);
+ mouseOverHandlers.push_back(id);
CppDOMBindings::mouseOverHandlers->insert({id, callback});
CppDOMBindings::AddMouseOverListener(ptr, id);
return id;
}
void RemoveMouseOverListener(std::int32_t id) {
- handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
+ mouseOverHandlers.erase(std::remove(mouseOverHandlers.begin(), mouseOverHandlers.end(), id), mouseOverHandlers.end());
CppDOMBindings::mouseOverHandlers->erase(id);
CppDOMBindings::RemoveMouseOverListener(ptr, id);
}
std::int32_t AddMouseOutListener(std::function callback) {
std::int32_t id = CppDOMBindings::mouseOutHandlerMaxId++;
- handlers.push_back(id);
+ mouseOutHandlers.push_back(id);
CppDOMBindings::mouseOutHandlers->insert({id, callback});
CppDOMBindings::AddMouseOutListener(ptr, id);
return id;
}
void RemoveMouseOutListener(std::int32_t id) {
- handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
+ mouseOutHandlers.erase(std::remove(mouseOutHandlers.begin(), mouseOutHandlers.end(), id), mouseOutHandlers.end());
CppDOMBindings::mouseOutHandlers->erase(id);
CppDOMBindings::RemoveMouseOutListener(ptr, id);
}
std::int32_t AddMouseMoveListener(std::function callback) {
std::int32_t id = CppDOMBindings::mouseMoveHandlerMaxId++;
- handlers.push_back(id);
+ mouseMoveHandlers.push_back(id);
CppDOMBindings::mouseMoveHandlers->insert({id, callback});
CppDOMBindings::AddMouseMoveListener(ptr, id);
return id;
}
void RemoveMouseMoveListener(std::int32_t id) {
- handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
+ mouseMoveHandlers.erase(std::remove(mouseMoveHandlers.begin(), mouseMoveHandlers.end(), id), mouseMoveHandlers.end());
CppDOMBindings::mouseMoveHandlers->erase(id);
CppDOMBindings::RemoveMouseMoveListener(ptr, id);
}
std::int32_t AddMouseDownListener(std::function callback) {
std::int32_t id = CppDOMBindings::mouseDownHandlerMaxId++;
- handlers.push_back(id);
+ mouseDownHandlers.push_back(id);
CppDOMBindings::mouseDownHandlers->insert({id, callback});
CppDOMBindings::AddMouseDownListener(ptr, id);
return id;
}
void RemoveMouseDownListener(std::int32_t id) {
- handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
+ mouseDownHandlers.erase(std::remove(mouseDownHandlers.begin(), mouseDownHandlers.end(), id), mouseDownHandlers.end());
CppDOMBindings::mouseDownHandlers->erase(id);
CppDOMBindings::RemoveMouseDownListener(ptr, id);
}
std::int32_t AddMouseUpListener(std::function callback) {
std::int32_t id = CppDOMBindings::mouseUpHandlerMaxId++;
- handlers.push_back(id);
+ mouseUpHandlers.push_back(id);
CppDOMBindings::mouseUpHandlers->insert({id, callback});
CppDOMBindings::AddMouseUpListener(ptr, id);
return id;
}
void RemoveMouseUpListener(std::int32_t id) {
- handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
+ mouseUpHandlers.erase(std::remove(mouseUpHandlers.begin(), mouseUpHandlers.end(), id), mouseUpHandlers.end());
CppDOMBindings::mouseUpHandlers->erase(id);
CppDOMBindings::RemoveMouseUpListener(ptr, id);
}
@@ -128,28 +150,28 @@ namespace Crafter {
// Focus Events
std::int32_t AddFocusListener(std::function callback) {
std::int32_t id = CppDOMBindings::focusHandlerMaxId++;
- handlers.push_back(id);
+ focusHandlers.push_back(id);
CppDOMBindings::focusHandlers->insert({id, callback});
CppDOMBindings::AddFocusListener(ptr, id);
return id;
}
void RemoveFocusListener(std::int32_t id) {
- handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
+ focusHandlers.erase(std::remove(focusHandlers.begin(), focusHandlers.end(), id), focusHandlers.end());
CppDOMBindings::focusHandlers->erase(id);
CppDOMBindings::RemoveFocusListener(ptr, id);
}
std::int32_t AddBlurListener(std::function callback) {
std::int32_t id = CppDOMBindings::blurHandlerMaxId++;
- handlers.push_back(id);
+ blurHandlers.push_back(id);
CppDOMBindings::blurHandlers->insert({id, callback});
CppDOMBindings::AddBlurListener(ptr, id);
return id;
}
void RemoveBlurListener(std::int32_t id) {
- handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
+ blurHandlers.erase(std::remove(blurHandlers.begin(), blurHandlers.end(), id), blurHandlers.end());
CppDOMBindings::blurHandlers->erase(id);
CppDOMBindings::RemoveBlurListener(ptr, id);
}
@@ -157,42 +179,42 @@ namespace Crafter {
// Keyboard Events
std::int32_t AddKeyDownListener(std::function callback) {
std::int32_t id = CppDOMBindings::keyDownHandlerMaxId++;
- handlers.push_back(id);
+ keyDownHandlers.push_back(id);
CppDOMBindings::keyDownHandlers->insert({id, callback});
CppDOMBindings::AddKeyDownListener(ptr, id);
return id;
}
void RemoveKeyDownListener(std::int32_t id) {
- handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
+ keyDownHandlers.erase(std::remove(keyDownHandlers.begin(), keyDownHandlers.end(), id), keyDownHandlers.end());
CppDOMBindings::keyDownHandlers->erase(id);
CppDOMBindings::RemoveKeyDownListener(ptr, id);
}
std::int32_t AddKeyUpListener(std::function callback) {
std::int32_t id = CppDOMBindings::keyUpHandlerMaxId++;
- handlers.push_back(id);
+ keyUpHandlers.push_back(id);
CppDOMBindings::keyUpHandlers->insert({id, callback});
CppDOMBindings::AddKeyUpListener(ptr, id);
return id;
}
void RemoveKeyUpListener(std::int32_t id) {
- handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
+ keyUpHandlers.erase(std::remove(keyUpHandlers.begin(), keyUpHandlers.end(), id), keyUpHandlers.end());
CppDOMBindings::keyUpHandlers->erase(id);
CppDOMBindings::RemoveKeyUpListener(ptr, id);
}
std::int32_t AddKeyPressListener(std::function callback) {
std::int32_t id = CppDOMBindings::keyPressHandlerMaxId++;
- handlers.push_back(id);
+ keyPressHandlers.push_back(id);
CppDOMBindings::keyPressHandlers->insert({id, callback});
CppDOMBindings::AddKeyPressListener(ptr, id);
return id;
}
void RemoveKeyPressListener(std::int32_t id) {
- handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
+ keyPressHandlers.erase(std::remove(keyPressHandlers.begin(), keyPressHandlers.end(), id), keyPressHandlers.end());
CppDOMBindings::keyPressHandlers->erase(id);
CppDOMBindings::RemoveKeyPressListener(ptr, id);
}
@@ -200,70 +222,70 @@ namespace Crafter {
// Form Events
std::int32_t AddChangeListener(std::function callback) {
std::int32_t id = CppDOMBindings::changeHandlerMaxId++;
- handlers.push_back(id);
+ changeHandlers.push_back(id);
CppDOMBindings::changeHandlers->insert({id, callback});
CppDOMBindings::AddChangeListener(ptr, id);
return id;
}
void RemoveChangeListener(std::int32_t id) {
- handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
+ changeHandlers.erase(std::remove(changeHandlers.begin(), changeHandlers.end(), id), changeHandlers.end());
CppDOMBindings::changeHandlers->erase(id);
CppDOMBindings::RemoveChangeListener(ptr, id);
}
std::int32_t AddSubmitListener(std::function callback) {
std::int32_t id = CppDOMBindings::submitHandlerMaxId++;
- handlers.push_back(id);
+ submitHandlers.push_back(id);
CppDOMBindings::submitHandlers->insert({id, callback});
CppDOMBindings::AddSubmitListener(ptr, id);
return id;
}
void RemoveSubmitListener(std::int32_t id) {
- handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
+ submitHandlers.erase(std::remove(submitHandlers.begin(), submitHandlers.end(), id), submitHandlers.end());
CppDOMBindings::submitHandlers->erase(id);
CppDOMBindings::RemoveSubmitListener(ptr, id);
}
std::int32_t AddInputListener(std::function callback) {
std::int32_t id = CppDOMBindings::inputHandlerMaxId++;
- handlers.push_back(id);
+ inputHandlers.push_back(id);
CppDOMBindings::inputHandlers->insert({id, callback});
CppDOMBindings::AddInputListener(ptr, id);
return id;
}
void RemoveInputListener(std::int32_t id) {
- handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
+ inputHandlers.erase(std::remove(inputHandlers.begin(), inputHandlers.end(), id), inputHandlers.end());
CppDOMBindings::inputHandlers->erase(id);
CppDOMBindings::RemoveInputListener(ptr, id);
}
std::int32_t AddResizeListener(std::function callback) {
std::int32_t id = CppDOMBindings::resizeHandlerMaxId++;
- handlers.push_back(id);
+ resizeHandlers.push_back(id);
CppDOMBindings::resizeHandlers->insert({id, callback});
CppDOMBindings::AddResizeListener(ptr, id);
return id;
}
void RemoveResizeListener(std::int32_t id) {
- handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
+ resizeHandlers.erase(std::remove(resizeHandlers.begin(), resizeHandlers.end(), id), resizeHandlers.end());
CppDOMBindings::resizeHandlers->erase(id);
CppDOMBindings::RemoveResizeListener(ptr, id);
}
std::int32_t AddScrollListener(std::function callback) {
std::int32_t id = CppDOMBindings::scrollHandlerMaxId++;
- handlers.push_back(id);
+ scrollHandlers.push_back(id);
CppDOMBindings::scrollHandlers->insert({id, callback});
CppDOMBindings::AddScrollListener(ptr, id);
return id;
}
void RemoveScrollListener(std::int32_t id) {
- handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
+ scrollHandlers.erase(std::remove(scrollHandlers.begin(), scrollHandlers.end(), id), scrollHandlers.end());
CppDOMBindings::scrollHandlers->erase(id);
CppDOMBindings::RemoveScrollListener(ptr, id);
}
@@ -271,14 +293,14 @@ namespace Crafter {
// Context Menu Events
std::int32_t AddContextMenuListener(std::function callback) {
std::int32_t id = CppDOMBindings::contextMenuHandlerMaxId++;
- handlers.push_back(id);
+ contextMenuHandlers.push_back(id);
CppDOMBindings::contextMenuHandlers->insert({id, callback});
CppDOMBindings::AddContextMenuListener(ptr, id);
return id;
}
void RemoveContextMenuListener(std::int32_t id) {
- handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
+ contextMenuHandlers.erase(std::remove(contextMenuHandlers.begin(), contextMenuHandlers.end(), id), contextMenuHandlers.end());
CppDOMBindings::contextMenuHandlers->erase(id);
CppDOMBindings::RemoveContextMenuListener(ptr, id);
}
@@ -286,42 +308,42 @@ namespace Crafter {
// Drag and Drop Events
std::int32_t AddDragStartListener(std::function callback) {
std::int32_t id = CppDOMBindings::dragStartHandlerMaxId++;
- handlers.push_back(id);
+ dragStartHandlers.push_back(id);
CppDOMBindings::dragStartHandlers->insert({id, callback});
CppDOMBindings::AddDragStartListener(ptr, id);
return id;
}
void RemoveDragStartListener(std::int32_t id) {
- handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
+ dragStartHandlers.erase(std::remove(dragStartHandlers.begin(), dragStartHandlers.end(), id), dragStartHandlers.end());
CppDOMBindings::dragStartHandlers->erase(id);
CppDOMBindings::RemoveDragStartListener(ptr, id);
}
std::int32_t AddDragEndListener(std::function callback) {
std::int32_t id = CppDOMBindings::dragEndHandlerMaxId++;
- handlers.push_back(id);
+ dragEndHandlers.push_back(id);
CppDOMBindings::dragEndHandlers->insert({id, callback});
CppDOMBindings::AddDragEndListener(ptr, id);
return id;
}
void RemoveDragEndListener(std::int32_t id) {
- handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
+ dragEndHandlers.erase(std::remove(dragEndHandlers.begin(), dragEndHandlers.end(), id), dragEndHandlers.end());
CppDOMBindings::dragEndHandlers->erase(id);
CppDOMBindings::RemoveDragEndListener(ptr, id);
}
std::int32_t AddDropListener(std::function callback) {
std::int32_t id = CppDOMBindings::dropHandlerMaxId++;
- handlers.push_back(id);
+ dropHandlers.push_back(id);
CppDOMBindings::dropHandlers->insert({id, callback});
CppDOMBindings::AddDropListener(ptr, id);
return id;
}
void RemoveDropListener(std::int32_t id) {
- handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
+ dropHandlers.erase(std::remove(dropHandlers.begin(), dropHandlers.end(), id), dropHandlers.end());
CppDOMBindings::dropHandlers->erase(id);
CppDOMBindings::RemoveDropListener(ptr, id);
}
@@ -329,42 +351,42 @@ namespace Crafter {
// Additional Drag Events
std::int32_t AddDragOverListener(std::function callback) {
std::int32_t id = CppDOMBindings::dragOverHandlerMaxId++;
- handlers.push_back(id);
+ dragOverHandlers.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());
+ dragOverHandlers.erase(std::remove(dragOverHandlers.begin(), dragOverHandlers.end(), id), dragOverHandlers.end());
CppDOMBindings::dragOverHandlers->erase(id);
CppDOMBindings::RemoveDragOverListener(ptr, id);
}
std::int32_t AddDragEnterListener(std::function callback) {
std::int32_t id = CppDOMBindings::dragEnterHandlerMaxId++;
- handlers.push_back(id);
+ dragEnterHandlers.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());
+ dragEnterHandlers.erase(std::remove(dragEnterHandlers.begin(), dragEnterHandlers.end(), id), dragEnterHandlers.end());
CppDOMBindings::dragEnterHandlers->erase(id);
CppDOMBindings::RemoveDragEnterListener(ptr, id);
}
std::int32_t AddDragLeaveListener(std::function callback) {
std::int32_t id = CppDOMBindings::dragLeaveHandlerMaxId++;
- handlers.push_back(id);
+ dragLeaveHandlers.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());
+ dragLeaveHandlers.erase(std::remove(dragLeaveHandlers.begin(), dragLeaveHandlers.end(), id), dragLeaveHandlers.end());
CppDOMBindings::dragLeaveHandlers->erase(id);
CppDOMBindings::RemoveDragLeaveListener(ptr, id);
}
@@ -372,23 +394,116 @@ namespace Crafter {
// Wheel Event
std::int32_t AddWheelListener(std::function callback) {
std::int32_t id = CppDOMBindings::wheelHandlerMaxId++;
- handlers.push_back(id);
+ wheelHandlers.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());
+ wheelHandlers.erase(std::remove(wheelHandlers.begin(), wheelHandlers.end(), id), wheelHandlers.end());
CppDOMBindings::wheelHandlers->erase(id);
CppDOMBindings::RemoveWheelListener(ptr, id);
}
~HtmlElement(){
- for(std::int32_t handler : handlers) {
+ // Clean up all handlers by type
+ for(std::int32_t handler : clickHandlers) {
CppDOMBindings::clickHandlers->erase(handler);
CppDOMBindings::RemoveClickListener(ptr, handler);
}
+ for(std::int32_t handler : mouseOverHandlers) {
+ CppDOMBindings::mouseOverHandlers->erase(handler);
+ CppDOMBindings::RemoveMouseOverListener(ptr, handler);
+ }
+ for(std::int32_t handler : mouseOutHandlers) {
+ CppDOMBindings::mouseOutHandlers->erase(handler);
+ CppDOMBindings::RemoveMouseOutListener(ptr, handler);
+ }
+ for(std::int32_t handler : mouseMoveHandlers) {
+ CppDOMBindings::mouseMoveHandlers->erase(handler);
+ CppDOMBindings::RemoveMouseMoveListener(ptr, handler);
+ }
+ for(std::int32_t handler : mouseDownHandlers) {
+ CppDOMBindings::mouseDownHandlers->erase(handler);
+ CppDOMBindings::RemoveMouseDownListener(ptr, handler);
+ }
+ for(std::int32_t handler : mouseUpHandlers) {
+ CppDOMBindings::mouseUpHandlers->erase(handler);
+ CppDOMBindings::RemoveMouseUpListener(ptr, handler);
+ }
+ for(std::int32_t handler : focusHandlers) {
+ CppDOMBindings::focusHandlers->erase(handler);
+ CppDOMBindings::RemoveFocusListener(ptr, handler);
+ }
+ for(std::int32_t handler : blurHandlers) {
+ CppDOMBindings::blurHandlers->erase(handler);
+ CppDOMBindings::RemoveBlurListener(ptr, handler);
+ }
+ for(std::int32_t handler : keyDownHandlers) {
+ CppDOMBindings::keyDownHandlers->erase(handler);
+ CppDOMBindings::RemoveKeyDownListener(ptr, handler);
+ }
+ for(std::int32_t handler : keyUpHandlers) {
+ CppDOMBindings::keyUpHandlers->erase(handler);
+ CppDOMBindings::RemoveKeyUpListener(ptr, handler);
+ }
+ for(std::int32_t handler : keyPressHandlers) {
+ CppDOMBindings::keyPressHandlers->erase(handler);
+ CppDOMBindings::RemoveKeyPressListener(ptr, handler);
+ }
+ for(std::int32_t handler : changeHandlers) {
+ CppDOMBindings::changeHandlers->erase(handler);
+ CppDOMBindings::RemoveChangeListener(ptr, handler);
+ }
+ for(std::int32_t handler : submitHandlers) {
+ CppDOMBindings::submitHandlers->erase(handler);
+ CppDOMBindings::RemoveSubmitListener(ptr, handler);
+ }
+ for(std::int32_t handler : inputHandlers) {
+ CppDOMBindings::inputHandlers->erase(handler);
+ CppDOMBindings::RemoveInputListener(ptr, handler);
+ }
+ for(std::int32_t handler : resizeHandlers) {
+ CppDOMBindings::resizeHandlers->erase(handler);
+ CppDOMBindings::RemoveResizeListener(ptr, handler);
+ }
+ for(std::int32_t handler : scrollHandlers) {
+ CppDOMBindings::scrollHandlers->erase(handler);
+ CppDOMBindings::RemoveScrollListener(ptr, handler);
+ }
+ for(std::int32_t handler : contextMenuHandlers) {
+ CppDOMBindings::contextMenuHandlers->erase(handler);
+ CppDOMBindings::RemoveContextMenuListener(ptr, handler);
+ }
+ for(std::int32_t handler : dragStartHandlers) {
+ CppDOMBindings::dragStartHandlers->erase(handler);
+ CppDOMBindings::RemoveDragStartListener(ptr, handler);
+ }
+ for(std::int32_t handler : dragEndHandlers) {
+ CppDOMBindings::dragEndHandlers->erase(handler);
+ CppDOMBindings::RemoveDragEndListener(ptr, handler);
+ }
+ for(std::int32_t handler : dropHandlers) {
+ CppDOMBindings::dropHandlers->erase(handler);
+ CppDOMBindings::RemoveDropListener(ptr, handler);
+ }
+ for(std::int32_t handler : dragOverHandlers) {
+ CppDOMBindings::dragOverHandlers->erase(handler);
+ CppDOMBindings::RemoveDragOverListener(ptr, handler);
+ }
+ for(std::int32_t handler : dragEnterHandlers) {
+ CppDOMBindings::dragEnterHandlers->erase(handler);
+ CppDOMBindings::RemoveDragEnterListener(ptr, handler);
+ }
+ for(std::int32_t handler : dragLeaveHandlers) {
+ CppDOMBindings::dragLeaveHandlers->erase(handler);
+ CppDOMBindings::RemoveDragLeaveListener(ptr, handler);
+ }
+ for(std::int32_t handler : wheelHandlers) {
+ CppDOMBindings::wheelHandlers->erase(handler);
+ CppDOMBindings::RemoveWheelListener(ptr, handler);
+ }
CppDOMBindings::FreeJs(ptr);
}
};
diff --git a/interfaces/Crafter.CppDOM.cppm b/interfaces/Crafter.CppDOM.cppm
index d129ff2..1662b4f 100644
--- a/interfaces/Crafter.CppDOM.cppm
+++ b/interfaces/Crafter.CppDOM.cppm
@@ -19,6 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
export module Crafter.CppDOM;
-export import :Bindings;
export import :HtmlElement;
-export import :EventTypes;
\ No newline at end of file
+export import :EventTypes;
+export import :BindingsExport;
+export import :BindingsImport;
\ No newline at end of file
diff --git a/project.json b/project.json
index a56145a..dea2085 100644
--- a/project.json
+++ b/project.json
@@ -3,7 +3,7 @@
"configurations": [
{
"name": "lib",
- "interfaces": ["interfaces/Crafter.CppDOM-HtmlElement", "interfaces/Crafter.CppDOM", "interfaces/Crafter.CppDOM-Bindings", "interfaces/Crafter.CppDOM-EventTypes"],
+ "interfaces": ["interfaces/Crafter.CppDOM-HtmlElement", "interfaces/Crafter.CppDOM", "interfaces/Crafter.CppDOM-BindingsExport", "interfaces/Crafter.CppDOM-BindingsImport", "interfaces/Crafter.CppDOM-EventTypes"],
"additional_files": ["additional/env.js"],
"type":"library",
"target":"wasm32-wasi"